Make gstreamer player backend reserve/release video resource.
authorLing Hu <ling.hu@nokia.com>
Thu, 22 Mar 2012 00:41:50 +0000 (10:41 +1000)
committerQt by Nokia <qt-info@nokia.com>
Fri, 23 Mar 2012 08:53:57 +0000 (09:53 +0100)
Use request/release of various video related controls as an indication for the decision.

Change-Id: I3a2a288c7c46ca62459896745bbdda26961bb181
Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
Reviewed-by: Jonas Rabbe <jonas.rabbe@nokia.com>
src/plugins/gstreamer/mediaplayer/qgstreamerplayerservice.cpp
src/plugins/gstreamer/mediaplayer/qgstreamerplayerservice.h

index 54dedf4..9a6b4b4 100644 (file)
@@ -70,6 +70,7 @@
 
 #include <private/qmediaplaylistnavigator_p.h>
 #include <qmediaplaylist.h>
+#include <private/qmediaresourceset_p.h>
 
 QT_BEGIN_NAMESPACE
 
@@ -81,6 +82,7 @@ QGstreamerPlayerService::QGstreamerPlayerService(QObject *parent):
      , m_videoWindow(0)
      , m_videoWidget(0)
 #endif
+     , m_videoReferenceCount(0)
 {
     m_session = new QGstreamerPlayerSession(this);
     m_control = new QGstreamerPlayerControl(m_session, this);
@@ -125,6 +127,7 @@ QMediaControl *QGstreamerPlayerService::requestControl(const char *name)
     if (qstrcmp(name,QMediaVideoProbeControl_iid) == 0) {
         if (m_session) {
             QGstreamerVideoProbeControl *probe = new QGstreamerVideoProbeControl(this);
+            increaseVideoRef();
             m_session->addProbe(probe);
             return probe;
         }
@@ -151,6 +154,7 @@ QMediaControl *QGstreamerPlayerService::requestControl(const char *name)
 #endif
 
         if (m_videoOutput) {
+            increaseVideoRef();
             m_control->setVideoOutput(m_videoOutput);
             return m_videoOutput;
         }
@@ -164,12 +168,15 @@ void QGstreamerPlayerService::releaseControl(QMediaControl *control)
     if (control == m_videoOutput) {
         m_videoOutput = 0;
         m_control->setVideoOutput(0);
+        decreaseVideoRef();
     }
 
     QGstreamerVideoProbeControl* videoProbe = qobject_cast<QGstreamerVideoProbeControl*>(control);
     if (videoProbe) {
-        if (m_session)
+        if (m_session) {
             m_session->removeProbe(videoProbe);
+            decreaseVideoRef();
+        }
         delete videoProbe;
         return;
     }
@@ -183,4 +190,20 @@ void QGstreamerPlayerService::releaseControl(QMediaControl *control)
     }
 }
 
+void QGstreamerPlayerService::increaseVideoRef()
+{
+    m_videoReferenceCount++;
+    if (m_videoReferenceCount == 1) {
+        m_control->resources()->setVideoEnabled(true);
+    }
+}
+
+void QGstreamerPlayerService::decreaseVideoRef()
+{
+    m_videoReferenceCount--;
+    if (m_videoReferenceCount == 0) {
+        m_control->resources()->setVideoEnabled(false);
+    }
+}
+
 QT_END_NAMESPACE
index 57e023d..e45f3ac 100644 (file)
@@ -86,6 +86,10 @@ private:
     QMediaControl *m_videoWindow;
     QMediaControl *m_videoWidget;
 #endif
+
+    void increaseVideoRef();
+    void decreaseVideoRef();
+    int m_videoReferenceCount;
 };
 
 QT_END_NAMESPACE