VideoOutput: release video frames when the video surface is stopped.

It's necessary to release video frames during media pipeline shutdown
or reconfiguration.

Change-Id: I386ad4d173b8731f257ec9272ef8c46a27769bd0
Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
This commit is contained in:
Dmytro Poplavskiy
2011-11-18 13:23:21 +10:00
committed by Qt by Nokia
parent 0e021ea4d1
commit 290523bc4c
3 changed files with 24 additions and 0 deletions

View 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...";

View 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

View 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;