src/3rdparty/phonon/mmf/mediaobject.cpp
changeset 7 f7bc934e204c
parent 3 41300fa6a67c
equal deleted inserted replaced
3:41300fa6a67c 7:f7bc934e204c
    20 #include "audioplayer.h"
    20 #include "audioplayer.h"
    21 #include "defs.h"
    21 #include "defs.h"
    22 #include "dummyplayer.h"
    22 #include "dummyplayer.h"
    23 #include "utils.h"
    23 #include "utils.h"
    24 #include "utils.h"
    24 #include "utils.h"
    25 #include "mmf_videoplayer.h"
    25 
       
    26 #ifdef PHONON_MMF_VIDEO_SURFACES
       
    27 #include "videoplayer_surface.h"
       
    28 #else
       
    29 #include "videoplayer_dsa.h"
       
    30 #endif
       
    31 
    26 #include "videowidget.h"
    32 #include "videowidget.h"
    27 
    33 
    28 #include "mediaobject.h"
    34 #include "mediaobject.h"
    29 
    35 
    30 #include <QDir>
    36 #include <QDir>
    43 // Constructor / destructor
    49 // Constructor / destructor
    44 //-----------------------------------------------------------------------------
    50 //-----------------------------------------------------------------------------
    45 
    51 
    46 MMF::MediaObject::MediaObject(QObject *parent) : MMF::MediaNode::MediaNode(parent)
    52 MMF::MediaObject::MediaObject(QObject *parent) : MMF::MediaNode::MediaNode(parent)
    47                                                , m_recognizerOpened(false)
    53                                                , m_recognizerOpened(false)
       
    54                                                , m_nextSourceSet(false)
    48 {
    55 {
    49     m_player.reset(new DummyPlayer());
    56     m_player.reset(new DummyPlayer());
    50 
    57 
    51     TRACE_CONTEXT(MediaObject::MediaObject, EAudioApi);
    58     TRACE_CONTEXT(MediaObject::MediaObject, EAudioApi);
    52     TRACE_ENTRY_0();
    59     TRACE_ENTRY_0();
   209     return m_player->totalTime();
   216     return m_player->totalTime();
   210 }
   217 }
   211 
   218 
   212 MediaSource MMF::MediaObject::source() const
   219 MediaSource MMF::MediaObject::source() const
   213 {
   220 {
   214     return m_player->source();
   221     return m_source;
   215 }
   222 }
   216 
   223 
   217 void MMF::MediaObject::setSource(const MediaSource &source)
   224 void MMF::MediaObject::setSource(const MediaSource &source)
   218 {
   225 {
       
   226     switchToSource(source);
       
   227 }
       
   228 
       
   229 void MMF::MediaObject::switchToSource(const MediaSource &source)
       
   230 {
   219     createPlayer(source);
   231     createPlayer(source);
   220 
   232     m_source = source;
   221     // This is a hack to work around KErrInUse from MMF client utility
   233     m_player->open(m_source, m_file);
   222     // OpenFileL calls
   234     emit currentSourceChanged(m_source);
   223     m_player->setFileSource(source, m_file);
       
   224 
       
   225     emit currentSourceChanged(source);
       
   226 }
   235 }
   227 
   236 
   228 void MMF::MediaObject::createPlayer(const MediaSource &source)
   237 void MMF::MediaObject::createPlayer(const MediaSource &source)
   229 {
   238 {
   230     TRACE_CONTEXT(MediaObject::createPlayer, EAudioApi);
   239     TRACE_CONTEXT(MediaObject::createPlayer, EAudioApi);
   236     AbstractPlayer* oldPlayer = m_player.data();
   245     AbstractPlayer* oldPlayer = m_player.data();
   237 
   246 
   238     const bool oldPlayerHasVideo = oldPlayer->hasVideo();
   247     const bool oldPlayerHasVideo = oldPlayer->hasVideo();
   239     const bool oldPlayerSeekable = oldPlayer->isSeekable();
   248     const bool oldPlayerSeekable = oldPlayer->isSeekable();
   240 
   249 
   241     Phonon::ErrorType error = NoError;
       
   242     QString errorMessage;
   250     QString errorMessage;
   243 
   251 
   244     // Determine media type
   252     // Determine media type
   245     switch (source.type()) {
   253     switch (source.type()) {
   246     case MediaSource::LocalFile:
   254     case MediaSource::LocalFile:
   252             const QUrl url(source.url());
   260             const QUrl url(source.url());
   253             if (url.scheme() == QLatin1String("file")) {
   261             if (url.scheme() == QLatin1String("file")) {
   254                 mediaType = fileMediaType(url.toLocalFile());
   262                 mediaType = fileMediaType(url.toLocalFile());
   255             }
   263             }
   256             else {
   264             else {
   257                 errorMessage = QLatin1String("Network streaming not supported yet");
   265                 // Streaming playback is generally not supported by the implementation
   258                 error = NormalError;
   266                 // of the audio player API, so we use CVideoPlayerUtility for both
       
   267                 // audio and video streaming.
       
   268                 mediaType = MediaTypeVideo;
   259             }
   269             }
   260         }
   270         }
   261         break;
   271         break;
   262 
   272 
   263     case MediaSource::Invalid:
   273     case MediaSource::Invalid:
   264     case MediaSource::Disc:
   274     case MediaSource::Disc:
   265     case MediaSource::Stream:
   275     case MediaSource::Stream:
   266         TRACE_0("Unsupported media type");
   276         errorMessage = tr("Error opening source: type not supported");
   267         error = NormalError;
       
   268         break;
   277         break;
   269 
   278 
   270     case MediaSource::Empty:
   279     case MediaSource::Empty:
   271         TRACE_0("Empty media source");
   280         TRACE_0("Empty media source");
   272         break;
   281         break;
   279     // been set on oldPlayer.
   288     // been set on oldPlayer.
   280 
   289 
   281     switch (mediaType) {
   290     switch (mediaType) {
   282     case MediaTypeUnknown:
   291     case MediaTypeUnknown:
   283         TRACE_0("Media type could not be determined");
   292         TRACE_0("Media type could not be determined");
   284         if (oldPlayer) {
   293         newPlayer = new DummyPlayer(oldPlayer);
   285             newPlayer = new DummyPlayer(*oldPlayer);
   294         errorMessage = tr("Error opening source: media type could not be determined");
   286         } else {
       
   287             newPlayer = new DummyPlayer();
       
   288         }
       
   289 
       
   290         error = NormalError;
       
   291         errorMessage = tr("Media type could not be determined");
       
   292         break;
   295         break;
   293 
   296 
   294     case MediaTypeAudio:
   297     case MediaTypeAudio:
   295         if (oldPlayer) {
   298         newPlayer = new AudioPlayer(this, oldPlayer);
   296             newPlayer = new AudioPlayer(*oldPlayer);
       
   297         } else {
       
   298             newPlayer = new AudioPlayer();
       
   299         }
       
   300         break;
   299         break;
   301 
   300 
   302     case MediaTypeVideo:
   301     case MediaTypeVideo:
   303         if (oldPlayer) {
   302 #ifdef PHONON_MMF_VIDEO_SURFACES
   304             newPlayer = new VideoPlayer(*oldPlayer);
   303         newPlayer = SurfaceVideoPlayer::create(this, oldPlayer);
   305         } else {
   304 #else
   306             newPlayer = new VideoPlayer();
   305         newPlayer = DsaVideoPlayer::create(this, oldPlayer);
   307         }
   306 #endif
   308         break;
   307         break;
   309     }
   308     }
   310 
   309 
       
   310     if (oldPlayer)
       
   311         emit abstractPlayerChanged(0);
   311     m_player.reset(newPlayer);
   312     m_player.reset(newPlayer);
       
   313     emit abstractPlayerChanged(newPlayer);
   312 
   314 
   313     if (oldPlayerHasVideo != hasVideo()) {
   315     if (oldPlayerHasVideo != hasVideo()) {
   314         emit hasVideoChanged(hasVideo());
   316         emit hasVideoChanged(hasVideo());
   315     }
   317     }
   316 
   318 
   320 
   322 
   321     connect(m_player.data(), SIGNAL(totalTimeChanged(qint64)), SIGNAL(totalTimeChanged(qint64)));
   323     connect(m_player.data(), SIGNAL(totalTimeChanged(qint64)), SIGNAL(totalTimeChanged(qint64)));
   322     connect(m_player.data(), SIGNAL(stateChanged(Phonon::State,Phonon::State)), SIGNAL(stateChanged(Phonon::State,Phonon::State)));
   324     connect(m_player.data(), SIGNAL(stateChanged(Phonon::State,Phonon::State)), SIGNAL(stateChanged(Phonon::State,Phonon::State)));
   323     connect(m_player.data(), SIGNAL(finished()), SIGNAL(finished()));
   325     connect(m_player.data(), SIGNAL(finished()), SIGNAL(finished()));
   324     connect(m_player.data(), SIGNAL(tick(qint64)), SIGNAL(tick(qint64)));
   326     connect(m_player.data(), SIGNAL(tick(qint64)), SIGNAL(tick(qint64)));
       
   327     connect(m_player.data(), SIGNAL(bufferStatus(int)), SIGNAL(bufferStatus(int)));
   325     connect(m_player.data(), SIGNAL(metaDataChanged(QMultiMap<QString,QString>)), SIGNAL(metaDataChanged(QMultiMap<QString,QString>)));
   328     connect(m_player.data(), SIGNAL(metaDataChanged(QMultiMap<QString,QString>)), SIGNAL(metaDataChanged(QMultiMap<QString,QString>)));
       
   329     connect(m_player.data(), SIGNAL(aboutToFinish()), SIGNAL(aboutToFinish()));
       
   330     connect(m_player.data(), SIGNAL(prefinishMarkReached(qint32)), SIGNAL(tick(qint32)));
   326 
   331 
   327     // We need to call setError() after doing the connects, otherwise the
   332     // We need to call setError() after doing the connects, otherwise the
   328     // error won't be received.
   333     // error won't be received.
   329     if (error != NoError) {
   334     if (!errorMessage.isEmpty()) {
   330         Q_ASSERT(m_player);
   335         Q_ASSERT(m_player);
   331         m_player->setError(error, errorMessage);
   336         m_player->setError(errorMessage);
   332     }
   337     }
   333 
   338 
   334     TRACE_EXIT_0();
   339     TRACE_EXIT_0();
   335 }
   340 }
   336 
   341 
   337 void MMF::MediaObject::setNextSource(const MediaSource &source)
   342 void MMF::MediaObject::setNextSource(const MediaSource &source)
   338 {
   343 {
   339     m_player->setNextSource(source);
   344     m_nextSource = source;
       
   345     m_nextSourceSet = true;
   340 }
   346 }
   341 
   347 
   342 qint32 MMF::MediaObject::prefinishMark() const
   348 qint32 MMF::MediaObject::prefinishMark() const
   343 {
   349 {
   344     return m_player->prefinishMark();
   350     return m_player->prefinishMark();
   363 {
   369 {
   364     m_player->volumeChanged(volume);
   370     m_player->volumeChanged(volume);
   365 }
   371 }
   366 
   372 
   367 //-----------------------------------------------------------------------------
   373 //-----------------------------------------------------------------------------
       
   374 // MediaNode
       
   375 //-----------------------------------------------------------------------------
       
   376 
       
   377 void MMF::MediaObject::connectMediaObject(MediaObject * /*mediaObject*/)
       
   378 {
       
   379     // This function should never be called - see MediaNode::setMediaObject()
       
   380     Q_ASSERT_X(false, Q_FUNC_INFO,
       
   381         "Connection of MediaObject to MediaObject");
       
   382 }
       
   383 
       
   384 void MMF::MediaObject::disconnectMediaObject(MediaObject * /*mediaObject*/)
       
   385 {
       
   386     // This function should never be called - see MediaNode::setMediaObject()
       
   387     Q_ASSERT_X(false, Q_FUNC_INFO,
       
   388         "Disconnection of MediaObject from MediaObject");
       
   389 }
       
   390 
       
   391 
       
   392 //-----------------------------------------------------------------------------
   368 // Video output
   393 // Video output
   369 //-----------------------------------------------------------------------------
   394 //-----------------------------------------------------------------------------
   370 
   395 
   371 void MMF::MediaObject::setVideoOutput(VideoOutput* videoOutput)
   396 void MMF::MediaObject::setVideoOutput(AbstractVideoOutput* videoOutput)
   372 {
   397 {
   373     m_player->setVideoOutput(videoOutput);
   398     m_player->setVideoOutput(videoOutput);
   374 }
   399 }
   375 
   400 
   376 
   401 
   377 AbstractPlayer *MMF::MediaObject::abstractPlayer() const
   402 AbstractPlayer *MMF::MediaObject::abstractPlayer() const
   378 {
   403 {
   379     return m_player.data();
   404     return m_player.data();
   380 }
   405 }
   381 
   406 
   382 bool MMF::MediaObject::activateOnMediaObject(MediaObject *)
   407 //-----------------------------------------------------------------------------
   383 {
   408 // Playlist support
   384     // Guess what, we do nothing.
   409 //-----------------------------------------------------------------------------
   385     return true;
   410 
       
   411 void MMF::MediaObject::switchToNextSource()
       
   412 {
       
   413     if (m_nextSourceSet) {
       
   414         m_nextSourceSet = false;
       
   415         switchToSource(m_nextSource);
       
   416         play();
       
   417     }
   386 }
   418 }
   387 
   419 
   388 QT_END_NAMESPACE
   420 QT_END_NAMESPACE
   389 
   421