Author: Niall Creech Description: Replace libvlc_exception and lib_media_player_set_drawable related code and to build against vlc 1.1 Ubuntu-Bug: https://bugs.edge.launchpad.net/ubuntu/+source/kamoso/+bug/642705 Index: kamoso-1.0.5/src/webcamwidget.cpp =================================================================== --- kamoso-1.0.5.orig/src/webcamwidget.cpp 2010-09-21 11:16:16.785538890 +0100 +++ kamoso-1.0.5/src/webcamwidget.cpp 2010-09-21 11:16:27.009198079 +0100 @@ -44,10 +44,8 @@ struct WebcamWidget::Private { - bool raise(libvlc_exception_t * ex); bool _isPlaying; QByteArray videoTmpPath; - libvlc_exception_t _vlcexcep; libvlc_instance_t *_vlcinstance; libvlc_media_player_t *m_mp; libvlc_media_t *_m; @@ -58,37 +56,41 @@ { //preparation of the vlc command const char * const vlc_args[] = { - "-I", "dummy", /* Don't use any interface */ - "--ignore-config", /* Don't use VLC's config */ - "--extraintf=logger", //log anything - "--verbose=0" //be much more verbose then normal for debugging purpose - }; + "--intf=dummy", + "--ignore-config", + "--reset-plugins-cache", + "--no-media-library", + "--no-one-instance", + "--no-osd", + "--no-stats", + "--no-video-title-show", + "--album-art=0", + "-vv" + }; + d->_isPlaying=false; - //Initialize an instance of vlc - //a structure for the exception is neede for this initalization - libvlc_exception_init(&d->_vlcexcep); - - //create a new libvlc instance - d->_vlcinstance=libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args,&d->_vlcexcep); //tricky calculation of the char space used - d->raise(&d->_vlcexcep); - + //create a new libvlc instance + d->_vlcinstance = libvlc_new(sizeof(vlc_args) / sizeof(vlc_args[0]), vlc_args); + if(!d->_vlcinstance) + qDebug() << "libvlc exception:" << libvlc_errmsg(); + // Create a media player playing environement - d->m_mp = libvlc_media_player_new (d->_vlcinstance, &d->_vlcexcep); - d->raise(&d->_vlcexcep); + d->m_mp = libvlc_media_player_new (d->_vlcinstance); + if(!d->m_mp) + qDebug() << "libvlc exception:" << libvlc_errmsg(); } //desctructor WebcamWidget::~WebcamWidget() { /* Stop playing */ - libvlc_media_player_stop (d->m_mp, &d->_vlcexcep); + libvlc_media_player_stop (d->m_mp); /* Free the media_player */ libvlc_media_player_release (d->m_mp); libvlc_release (d->_vlcinstance); - d->raise(&d->_vlcexcep); delete d; } @@ -99,30 +101,23 @@ mrl.append(file.toAscii()); mrl.append(":caching=100"); /* Create a new LibVLC media descriptor */ - d->_m = libvlc_media_new (d->_vlcinstance, mrl, &d->_vlcexcep); - d->raise(&d->_vlcexcep); - - libvlc_media_add_option(d->_m,"v4l2-controls-reset",&d->_vlcexcep); - - libvlc_media_player_set_media (d->m_mp, d->_m, &d->_vlcexcep); - d->raise(&d->_vlcexcep); + d->_m = libvlc_media_new_location (d->_vlcinstance, mrl); + libvlc_media_add_option(d->_m,"v4l2-controls-reset"); + libvlc_media_player_set_media (d->m_mp, d->_m); /* Get our media instance to use our window */ #if defined(Q_OS_WIN) - libvlc_media_player_set_drawable(_mp, reinterpret_cast(this->winId()), &_vlcexcep ); - //libvlc_media_player_set_hwnd(_mp, _videoWidget->winId(), &_vlcexcep ); // for vlc 1.0 + libvlc_media_player_set_hwnd(_mp, _videoWidget->winId() ); #elif defined(Q_OS_MAC) - libvlc_media_player_set_drawable(_mp, this->winId(), &_vlcexcep ); - //libvlc_media_player_set_agl (_mp, _videoWidget->winId(), &_vlcexcep); // for vlc 1.0 + libvlc_media_player_set_agl (_mp, _videoWidget->winId()); #else //Linux - libvlc_media_player_set_drawable(d->m_mp, this->winId(), &d->_vlcexcep ); + libvlc_media_player_set_xwindow(d->m_mp, this->winId() ); //libvlc_media_player_set_xwindow(_mp, _videoWidget->winId(), &_vlcexcep ); // for vlc 1.0 #endif - d->raise(&d->_vlcexcep); /* Play */ - libvlc_media_player_play (d->m_mp, &d->_vlcexcep ); - d->raise(&d->_vlcexcep); + if (!libvlc_media_player_play (d->m_mp)) + qDebug() << "libvlc exception:" << libvlc_errmsg(); d->_isPlaying=true; } @@ -137,13 +132,17 @@ path=KStandardDirs::locateLocal("appdata","last.png"); } - libvlc_video_take_snapshot(d->m_mp, path.toAscii().data(),640,480, &d->_vlcexcep); - if(d->raise(&d->_vlcexcep) && !dest.isLocalFile()) { - KIO::CopyJob* job=KIO::move(KUrl(path), dest); - job->setAutoDelete(true); - job->start(); - } - return d->raise(&d->_vlcexcep); + int result = libvlc_video_take_snapshot(d->m_mp, 0, path.toAscii().data(),640,480); + if (!result) + qDebug() << "Take snapshot error, video not found"; + + if(!dest.isLocalFile()) { + KIO::CopyJob* job=KIO::move(KUrl(path), dest); + job->setAutoDelete(true); + job->start(); + } + + return true; } void WebcamWidget::recordVideo(bool sound) @@ -154,27 +153,35 @@ if(sound == true){ QByteArray inputAlsa("input-slave=alsa://"); inputAlsa.append(phononCaptureDevice()); - libvlc_media_add_option(d->_m,inputAlsa,&d->_vlcexcep); - libvlc_media_add_option(d->_m,"alsa-caching=100",&d->_vlcexcep); + libvlc_media_add_option(d->_m,inputAlsa); + libvlc_media_add_option(d->_m,"alsa-caching=100"); } #warning shouldnt we raise all these exceptions? - libvlc_media_add_option(d->_m,"sout-display-delay=40",&d->_vlcexcep); - libvlc_media_add_option(d->_m,option,&d->_vlcexcep); - libvlc_media_player_stop(d->m_mp,&d->_vlcexcep); - d->m_mp = libvlc_media_player_new_from_media(d->_m,&d->_vlcexcep); - libvlc_media_player_set_drawable(d->m_mp, this->winId(), &d->_vlcexcep ); - libvlc_media_player_play (d->m_mp, &d->_vlcexcep ); + libvlc_media_add_option(d->_m,"sout-display-delay=40"); + libvlc_media_add_option(d->_m,option); + libvlc_media_player_stop(d->m_mp); + d->m_mp = libvlc_media_player_new_from_media(d->_m); + if(!d->m_mp) + qDebug() << "libvlc exception:" << libvlc_errmsg(); + + libvlc_media_player_set_xwindow(d->m_mp, this->winId() ); + + if (!libvlc_media_player_play (d->m_mp )) + qDebug() << "libvlc exception:" << libvlc_errmsg(); + } void WebcamWidget::stopRecording(const KUrl &destUrl) { - libvlc_media_player_stop(d->m_mp,&d->_vlcexcep); - if(d->raise(&d->_vlcexcep)) { - KIO::CopyJob* job=KIO::move(KUrl(d->videoTmpPath), destUrl); - job->setAutoDelete(true); - job->start(); - } + libvlc_media_player_stop(d->m_mp); + libvlc_media_release(d->_m); + + KIO::CopyJob* job=KIO::move(KUrl(d->videoTmpPath), destUrl); + connect(job,SIGNAL(result(KJob *)),this, SLOT(fileSaved(KJob *))); + job->setAutoDelete(true); + job->start(); + } QString WebcamWidget::phononCaptureDevice() @@ -191,12 +198,3 @@ return QString(); } -bool WebcamWidget::Private::raise(libvlc_exception_t * ex) -{ - if (libvlc_exception_raised (ex)) - { - qDebug() << "error: %s\n" << libvlc_exception_get_message(ex); - return false; - } - return true; -}