src/3rdparty/phonon/mmf/mediaobject.cpp
changeset 7 f7bc934e204c
parent 3 41300fa6a67c
--- a/src/3rdparty/phonon/mmf/mediaobject.cpp	Tue Feb 02 00:43:10 2010 +0200
+++ b/src/3rdparty/phonon/mmf/mediaobject.cpp	Wed Mar 31 11:06:36 2010 +0300
@@ -22,7 +22,13 @@
 #include "dummyplayer.h"
 #include "utils.h"
 #include "utils.h"
-#include "mmf_videoplayer.h"
+
+#ifdef PHONON_MMF_VIDEO_SURFACES
+#include "videoplayer_surface.h"
+#else
+#include "videoplayer_dsa.h"
+#endif
+
 #include "videowidget.h"
 
 #include "mediaobject.h"
@@ -45,6 +51,7 @@
 
 MMF::MediaObject::MediaObject(QObject *parent) : MMF::MediaNode::MediaNode(parent)
                                                , m_recognizerOpened(false)
+                                               , m_nextSourceSet(false)
 {
     m_player.reset(new DummyPlayer());
 
@@ -211,18 +218,20 @@
 
 MediaSource MMF::MediaObject::source() const
 {
-    return m_player->source();
+    return m_source;
 }
 
 void MMF::MediaObject::setSource(const MediaSource &source)
 {
-    createPlayer(source);
+    switchToSource(source);
+}
 
-    // This is a hack to work around KErrInUse from MMF client utility
-    // OpenFileL calls
-    m_player->setFileSource(source, m_file);
-
-    emit currentSourceChanged(source);
+void MMF::MediaObject::switchToSource(const MediaSource &source)
+{
+    createPlayer(source);
+    m_source = source;
+    m_player->open(m_source, m_file);
+    emit currentSourceChanged(m_source);
 }
 
 void MMF::MediaObject::createPlayer(const MediaSource &source)
@@ -238,7 +247,6 @@
     const bool oldPlayerHasVideo = oldPlayer->hasVideo();
     const bool oldPlayerSeekable = oldPlayer->isSeekable();
 
-    Phonon::ErrorType error = NoError;
     QString errorMessage;
 
     // Determine media type
@@ -254,8 +262,10 @@
                 mediaType = fileMediaType(url.toLocalFile());
             }
             else {
-                errorMessage = QLatin1String("Network streaming not supported yet");
-                error = NormalError;
+                // Streaming playback is generally not supported by the implementation
+                // of the audio player API, so we use CVideoPlayerUtility for both
+                // audio and video streaming.
+                mediaType = MediaTypeVideo;
             }
         }
         break;
@@ -263,8 +273,7 @@
     case MediaSource::Invalid:
     case MediaSource::Disc:
     case MediaSource::Stream:
-        TRACE_0("Unsupported media type");
-        error = NormalError;
+        errorMessage = tr("Error opening source: type not supported");
         break;
 
     case MediaSource::Empty:
@@ -281,34 +290,27 @@
     switch (mediaType) {
     case MediaTypeUnknown:
         TRACE_0("Media type could not be determined");
-        if (oldPlayer) {
-            newPlayer = new DummyPlayer(*oldPlayer);
-        } else {
-            newPlayer = new DummyPlayer();
-        }
-
-        error = NormalError;
-        errorMessage = tr("Media type could not be determined");
+        newPlayer = new DummyPlayer(oldPlayer);
+        errorMessage = tr("Error opening source: media type could not be determined");
         break;
 
     case MediaTypeAudio:
-        if (oldPlayer) {
-            newPlayer = new AudioPlayer(*oldPlayer);
-        } else {
-            newPlayer = new AudioPlayer();
-        }
+        newPlayer = new AudioPlayer(this, oldPlayer);
         break;
 
     case MediaTypeVideo:
-        if (oldPlayer) {
-            newPlayer = new VideoPlayer(*oldPlayer);
-        } else {
-            newPlayer = new VideoPlayer();
-        }
+#ifdef PHONON_MMF_VIDEO_SURFACES
+        newPlayer = SurfaceVideoPlayer::create(this, oldPlayer);
+#else
+        newPlayer = DsaVideoPlayer::create(this, oldPlayer);
+#endif
         break;
     }
 
+    if (oldPlayer)
+        emit abstractPlayerChanged(0);
     m_player.reset(newPlayer);
+    emit abstractPlayerChanged(newPlayer);
 
     if (oldPlayerHasVideo != hasVideo()) {
         emit hasVideoChanged(hasVideo());
@@ -322,13 +324,16 @@
     connect(m_player.data(), SIGNAL(stateChanged(Phonon::State,Phonon::State)), SIGNAL(stateChanged(Phonon::State,Phonon::State)));
     connect(m_player.data(), SIGNAL(finished()), SIGNAL(finished()));
     connect(m_player.data(), SIGNAL(tick(qint64)), SIGNAL(tick(qint64)));
+    connect(m_player.data(), SIGNAL(bufferStatus(int)), SIGNAL(bufferStatus(int)));
     connect(m_player.data(), SIGNAL(metaDataChanged(QMultiMap<QString,QString>)), SIGNAL(metaDataChanged(QMultiMap<QString,QString>)));
+    connect(m_player.data(), SIGNAL(aboutToFinish()), SIGNAL(aboutToFinish()));
+    connect(m_player.data(), SIGNAL(prefinishMarkReached(qint32)), SIGNAL(tick(qint32)));
 
     // We need to call setError() after doing the connects, otherwise the
     // error won't be received.
-    if (error != NoError) {
+    if (!errorMessage.isEmpty()) {
         Q_ASSERT(m_player);
-        m_player->setError(error, errorMessage);
+        m_player->setError(errorMessage);
     }
 
     TRACE_EXIT_0();
@@ -336,7 +341,8 @@
 
 void MMF::MediaObject::setNextSource(const MediaSource &source)
 {
-    m_player->setNextSource(source);
+    m_nextSource = source;
+    m_nextSourceSet = true;
 }
 
 qint32 MMF::MediaObject::prefinishMark() const
@@ -365,10 +371,29 @@
 }
 
 //-----------------------------------------------------------------------------
+// MediaNode
+//-----------------------------------------------------------------------------
+
+void MMF::MediaObject::connectMediaObject(MediaObject * /*mediaObject*/)
+{
+    // This function should never be called - see MediaNode::setMediaObject()
+    Q_ASSERT_X(false, Q_FUNC_INFO,
+        "Connection of MediaObject to MediaObject");
+}
+
+void MMF::MediaObject::disconnectMediaObject(MediaObject * /*mediaObject*/)
+{
+    // This function should never be called - see MediaNode::setMediaObject()
+    Q_ASSERT_X(false, Q_FUNC_INFO,
+        "Disconnection of MediaObject from MediaObject");
+}
+
+
+//-----------------------------------------------------------------------------
 // Video output
 //-----------------------------------------------------------------------------
 
-void MMF::MediaObject::setVideoOutput(VideoOutput* videoOutput)
+void MMF::MediaObject::setVideoOutput(AbstractVideoOutput* videoOutput)
 {
     m_player->setVideoOutput(videoOutput);
 }
@@ -379,10 +404,17 @@
     return m_player.data();
 }
 
-bool MMF::MediaObject::activateOnMediaObject(MediaObject *)
+//-----------------------------------------------------------------------------
+// Playlist support
+//-----------------------------------------------------------------------------
+
+void MMF::MediaObject::switchToNextSource()
 {
-    // Guess what, we do nothing.
-    return true;
+    if (m_nextSourceSet) {
+        m_nextSourceSet = false;
+        switchToSource(m_nextSource);
+        play();
+    }
 }
 
 QT_END_NAMESPACE