Logo
  • Main Page
  • Related Pages
  • Modules
  • Classes
  • Files

mmsvideo.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005-2007 Stefan Schwarzer, Jens Schneider,             *
00003  *                           Matthias Hardt, Guido Madaus                  *
00004  *                                                                         *
00005  *   Copyright (C) 2007-2008 BerLinux Solutions GbR                        *
00006  *                           Stefan Schwarzer & Guido Madaus               *
00007  *                                                                         *
00008  *   Copyright (C) 2009-2013 BerLinux Solutions GmbH                       *
00009  *                                                                         *
00010  *   Authors:                                                              *
00011  *      Stefan Schwarzer   <stefan.schwarzer@diskohq.org>,                 *
00012  *      Matthias Hardt     <matthias.hardt@diskohq.org>,                   *
00013  *      Jens Schneider     <jens.schneider@diskohq.org>,                   *
00014  *      Guido Madaus       <guido.madaus@diskohq.org>,                     *
00015  *      Patrick Helterhoff <patrick.helterhoff@diskohq.org>,               *
00016  *      René Bählkow       <rene.baehlkow@diskohq.org>                     *
00017  *                                                                         *
00018  *   This library is free software; you can redistribute it and/or         *
00019  *   modify it under the terms of the GNU Lesser General Public            *
00020  *   License version 2.1 as published by the Free Software Foundation.     *
00021  *                                                                         *
00022  *   This library is distributed in the hope that it will be useful,       *
00023  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00024  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00025  *   Lesser General Public License for more details.                       *
00026  *                                                                         *
00027  *   You should have received a copy of the GNU Lesser General Public      *
00028  *   License along with this library; if not, write to the                 *
00029  *   Free Software Foundation, Inc.,                                       *
00030  *   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA            *
00031  **************************************************************************/
00032 
00033 #include "mmsmedia/mmsvideo.h"
00034 
00035 MMS_CREATEERROR(MMSVideoError);
00036 
00037 #ifdef __HAVE_GSTREAMER__
00038 #endif
00039 #ifdef __HAVE_XINE__
00040 /**
00041  * Callback, that will be called if xine sends event messages.
00042  *
00043  * @param   userData    [in/out]    pointer to the MMSVideo object
00044  * @param   event       [in]        pointer to event structure
00045  */
00046 static void queue_cb(void *userData, const xine_event_t *event) {
00047     MMSVideo               *mmsvideo = (MMSVideo*)userData;
00048 
00049     switch(event->type) {
00050         case XINE_EVENT_UI_MESSAGE: {
00051             xine_ui_message_data_t *msg      = (xine_ui_message_data_t*)event->data;
00052             if(msg->explanation)
00053                 mmsvideo->onError->emit(string((char*)msg + msg->parameters));
00054             break;
00055         }
00056         case XINE_EVENT_MRL_REFERENCE_EXT: {
00057             xine_mrl_reference_data_ext_t *mrl_ref = (xine_mrl_reference_data_ext_t*)event->data;
00058             DEBUGMSG("MMSVideo", "new mrl: %s\n", mrl_ref->mrl);
00059             mmsvideo->add2Playlist(mrl_ref->mrl);
00060             break;
00061         }
00062         case XINE_EVENT_PROGRESS: {
00063             xine_progress_data_t *prog = (xine_progress_data_t*)event->data;
00064             DEBUGMSG("MMSVideo", "event: %s (%d%%)", prog->description, prog->percent);
00065             if(mmsvideo) mmsvideo->onProgressChange.emit(prog->percent);
00066             break;
00067         }
00068         case XINE_EVENT_UI_PLAYBACK_FINISHED:
00069             try {
00070                 mmsvideo->playNext();
00071             } catch(MMSError &e) {
00072                 DEBUGMSG("MMSVideo", "Error playing stream: " + e.getMessage());
00073                 mmsvideo->onError->emit(e.getMessage());
00074             }
00075             break;
00076         default:
00077             DEBUGMSG("MMSVideo", "Unhandled event: %d", event->type);
00078             break;
00079     }
00080 }
00081 #endif
00082 
00083 /**
00084  * Initializes everything that is needed by MMSVideo.
00085  *
00086  * @param   window  [in]    main window for video playback
00087  * @param   verbose [in]    if true the xine engine writes debug messages to stdout
00088  *
00089  * @see MMSAV::MMSAV()
00090  * @see MMSAV::initialize()
00091  */
00092 MMSVideo::MMSVideo(MMSWindow *window, const bool verbose) {
00093     MMSAV::initialize(verbose, window);
00094 }
00095 
00096 /**
00097  * Destructor of MMSVideo class.
00098  */
00099 MMSVideo::~MMSVideo() {
00100 }
00101 
00102 #ifdef __HAVE_GSTREAMER__
00103 #endif
00104 #ifdef __HAVE_XINE__
00105 /**
00106  * Calls MMSAV::open() with the queue_cb callback.
00107  */
00108 void MMSVideo::xineOpen() {
00109     MMSAV::xineOpen(queue_cb, (void*)this);
00110 }
00111 #endif
00112 
00113 /**
00114  * Starts playing.
00115  *
00116  * If the continue flag is set it tries to continue
00117  * at the position where it was stopped before.
00118  *
00119  * @param   file    file to play
00120  * @param   cont    if true it tries to continue at a position stopped before
00121  *
00122  * @exception   MMSAVError stream could not be opened
00123  */
00124 void MMSVideo::startPlaying(const string file, const bool cont) {
00125 //   this->open();
00126 #ifdef __HAVE_XINE__
00127   this->xineOpen();
00128 #endif
00129 
00130 
00131    string::size_type loc = file.find( "://", 0 );
00132    if( loc != string::npos ) {
00133        /* we found a mrl, so we play file directly */
00134        MMSAV::startPlaying(file, cont);
00135    }
00136    else {
00137        /* we found no mrl type, it seems to be a file */
00138        MMSAV::startPlaying("file://" + file, cont);
00139    }
00140 }
00141 
00142 /**
00143  * Adds a file to the internal playlist.
00144  *
00145  * @param   file    file to add
00146  */
00147 void MMSVideo::add2Playlist(const string file) {
00148        playlist.push(file);
00149 }
00150 
00151 /**
00152  * Starts playing the next file from the playlist.
00153  *
00154  * @exception   MMSAVError stream could not be opened
00155  */
00156 void MMSVideo::playNext() {
00157     if(!playlist.empty()) {
00158         string file = playlist.front();
00159         playlist.pop();
00160         startPlaying(file, false);
00161     }
00162 }

Generated by doxygen