VideoOutput: release video frames when the video surface is stopped.
authorDmytro Poplavskiy <dmytro.poplavskiy@nokia.com>
Fri, 18 Nov 2011 03:23:21 +0000 (13:23 +1000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 22 Nov 2011 04:27:48 +0000 (05:27 +0100)
It's necessary to release video frames during media pipeline shutdown
or reconfiguration.

Change-Id: I386ad4d173b8731f257ec9272ef8c46a27769bd0
Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
src/imports/multimedia/qdeclarativevideooutput.cpp
src/imports/multimedia/qdeclarativevideooutput_p.h
src/imports/multimedia/qsgvideonode_rgb.cpp

index 82c7da034d973c76a9af869399e643394fb821d7..0d65becf371e2c3aa3c207ef98a33019661cb7ae 100644 (file)
@@ -95,6 +95,12 @@ public:
         return QAbstractVideoSurface::start(format);
     }
 
+    void stop()
+    {
+        m_item->stop();
+        QAbstractVideoSurface::stop();
+    }
+
     virtual bool present(const QVideoFrame &frame)
     {
         if (!frame.isValid()) {
@@ -272,10 +278,18 @@ void QDeclarativeVideoOutput::_q_updateMediaObject()
 
 void QDeclarativeVideoOutput::present(const QVideoFrame &frame)
 {
+    m_frameMutex.lock();
     m_frame = frame;
+    m_frameMutex.unlock();
+
     update();
 }
 
+void QDeclarativeVideoOutput::stop()
+{
+    present(QVideoFrame());
+}
+
 /*!
     \qmlproperty enumeration VideoOutput::fillMode
 
@@ -353,6 +367,8 @@ QSGNode *QDeclarativeVideoOutput::updatePaintNode(QSGNode *oldNode, UpdatePaintN
 {
     QSGVideoNode *videoNode = static_cast<QSGVideoNode *>(oldNode);
 
+    QMutexLocker lock(&m_frameMutex);
+
     if (videoNode && videoNode->pixelFormat() != m_frame.pixelFormat()) {
 #ifdef DEBUG_VIDEOITEM
         qDebug() << "updatePaintNode: deleting old video node because frame format changed...";
index d15c164e8deef444fab17d3a38757dd25137489a..2c63fc9e467a50ff9869569a70a90d4fbc044bb8 100644 (file)
@@ -48,6 +48,7 @@
 #include <QtMultimedia/qmediaobject.h>
 
 #include <QtCore/qsharedpointer.h>
+#include <QtCore/qmutex.h>
 
 #include "qsgvideonode_p.h"
 
@@ -103,6 +104,7 @@ private:
     };
 
     void present(const QVideoFrame &frame);
+    void stop();
 
     friend class QSGVideoItemSurface;
 
@@ -120,6 +122,8 @@ private:
     QSize m_nativeSize;
     QRectF m_boundingRect;
     QRectF m_sourceRect;
+
+    QMutex m_frameMutex;
 };
 
 QT_END_NAMESPACE
index 41d778ed0ff193f26121667f8dda52090f805034..71ca71994eed093760b336c52d1c6713372fdc23 100644 (file)
@@ -41,6 +41,7 @@
 #include "qsgvideonode_rgb.h"
 #include <QtDeclarative/qsgtexturematerial.h>
 #include <QtDeclarative/qsgmaterial.h>
+#include <QtCore/qmutex.h>
 #include <QtGui/QOpenGLContext>
 #include <QtGui/QOpenGLFunctions>
 #include <QtOpenGL/qglshaderprogram.h>
@@ -187,6 +188,7 @@ public:
     }
 
     void setVideoFrame(const QVideoFrame &frame) {
+        QMutexLocker lock(&m_frameMutex);
         m_frame = frame;
     }
 
@@ -194,6 +196,7 @@ public:
     {
         QOpenGLFunctions *functions = QOpenGLContext::currentContext()->functions();
 
+        QMutexLocker lock(&m_frameMutex);
         if (m_frame.isValid() && m_frame.map(QAbstractVideoBuffer::ReadOnly)) {
             if (m_textureSize != m_frame.size()) {
                 if (!m_textureSize.isEmpty())
@@ -230,6 +233,7 @@ public:
     }
 
     QVideoFrame m_frame;
+    QMutex m_frameMutex;
     QSize m_textureSize;
     QVideoSurfaceFormat m_format;
     GLuint m_textureId;