Fix playback problem with RTSP streaming for QMediaPlayer(gstreamer)
authorLing Hu <ling.hu@nokia.com>
Tue, 28 Jun 2011 03:49:57 +0000 (13:49 +1000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 5 Jul 2011 04:50:04 +0000 (06:50 +0200)
Change-Id: Ie920cbb5a377e810aee3e106bb50deb46365ce3b
Reviewed-by:Michael Goddard
(cherry picked from commit 05841ae6a9e0ffac623f9b00565bf33a52a22ecd)
Reviewed-on: http://codereview.qt.nokia.com/983
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
src/plugins/gstreamer/mediaplayer/qgstreamerplayercontrol.cpp
src/plugins/gstreamer/mediaplayer/qgstreamerplayersession.cpp
src/plugins/gstreamer/mediaplayer/qgstreamerplayersession.h

index f36dd08..6c18fed 100644 (file)
@@ -551,7 +551,7 @@ void QGstreamerPlayerControl::setBufferProgress(int progress)
                 m_session->state() != QMediaPlayer::PlayingState)
             m_session->play();
 
-        if (m_bufferProgress < 100 &&
+        if (!m_session->isLiveSource() && m_bufferProgress < 100 &&
                 (m_session->state() == QMediaPlayer::PlayingState ||
                  m_session->pendingState() == QMediaPlayer::PlayingState))
             m_session->pause();
index ccb84d1..4bb9675 100644 (file)
@@ -47,6 +47,7 @@
 #include "qgstutils.h"
 
 #include <gst/gstvalue.h>
+#include <gst/base/gstbasesrc.h>
 
 #include <QtCore/qdatetime.h>
 #include <QtCore/qdebug.h>
@@ -103,7 +104,8 @@ QGstreamerPlayerSession::QGstreamerPlayerSession(QObject *parent)
      m_duration(-1),
      m_durationQueries(0),
      m_everPlayed(false) ,
-     m_sourceType(UnknownSrc)
+     m_sourceType(UnknownSrc),
+     m_isLiveSource(false)
 {
 #ifdef USE_PLAYBIN2
     m_playbin = gst_element_factory_make("playbin2", NULL);
@@ -1421,22 +1423,47 @@ void QGstreamerPlayerSession::playbinNotifySource(GObject *o, GParamSpec *p, gpo
     const int timeout = 30;
     if (qstrcmp(G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(source)), "GstUDPSrc") == 0) {
         //udpsrc timeout unit = microsecond
+        //The udpsrc is always a live source.
         g_object_set(G_OBJECT(source), "timeout", G_GUINT64_CONSTANT(timeout*1000000), NULL);
         self->m_sourceType = UDPSrc;
+        self->m_isLiveSource = true;
     } else if (qstrcmp(G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(source)), "GstSoupHTTPSrc") == 0) {
         //souphttpsrc timeout unit = second
         g_object_set(G_OBJECT(source), "timeout", guint(timeout), NULL);
         self->m_sourceType = SoupHTTPSrc;
+        //since gst_base_src_is_live is not reliable, so we check the source property directly
+        gboolean isLive = false;
+        g_object_get(G_OBJECT(source), "is-live", &isLive, NULL);
+        self->m_isLiveSource = isLive;
     } else if (qstrcmp(G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(source)), "GstMMSSrc") == 0) {
         self->m_sourceType = MMSSrc;
+        self->m_isLiveSource = gst_base_src_is_live(GST_BASE_SRC(source));
         g_object_set(G_OBJECT(source), "tcp-timeout", G_GUINT64_CONSTANT(timeout*1000000), NULL);
+    } else if (qstrcmp(G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(source)), "GstRTSPSrc") == 0) {
+        //rtspsrc acts like a live source and will therefore only generate data in the PLAYING state.
+        self->m_sourceType = RTSPSrc;
+        self->m_isLiveSource = true;
     } else {
         self->m_sourceType = UnknownSrc;
+        self->m_isLiveSource = gst_base_src_is_live(GST_BASE_SRC(source));
     }
 
+#ifdef DEBUG_PLAYBIN
+    if (self->m_isLiveSource)
+        qDebug() << "Current source is a live source";
+    else
+        qDebug() << "Current source is a non-live source";
+#endif
+
+
     gst_object_unref(source);
 }
 
+bool QGstreamerPlayerSession::isLiveSource() const
+{
+    return m_isLiveSource;
+}
+
 void QGstreamerPlayerSession::handleVolumeChange(GObject *o, GParamSpec *p, gpointer d)
 {
     Q_UNUSED(o);
index e6fa996..26b027a 100644 (file)
@@ -112,6 +112,8 @@ public:
     static void configureAppSrcElement(GObject*, GObject*, GParamSpec*,QGstreamerPlayerSession* _this);
 #endif
 
+    bool isLiveSource() const;
+
 public slots:
     void loadFromUri(const QNetworkRequest &url);
     void loadFromStream(const QNetworkRequest &url, QIODevice *stream);
@@ -208,10 +210,12 @@ private:
         UnknownSrc,
         SoupHTTPSrc,
         UDPSrc,
-        MMSSrc
+        MMSSrc,
+        RTSPSrc,
     };
     SourceType m_sourceType;
     bool m_everPlayed;
+    bool m_isLiveSource;
 };
 
 #endif // QGSTREAMERPLAYERSESSION_H