summaryrefslogtreecommitdiff
path: root/src/plugins/winrt/qwinrtabstractvideorenderercontrol.cpp
diff options
context:
space:
mode:
authorPeng Wu <peng.wu@intopalo.com>2015-07-22 18:34:02 +0300
committerPeng Wu <peng.wu@intopalo.com>2015-07-28 13:12:30 +0000
commit94eb599b6995f8b8e6a132d553620f891e138129 (patch)
tree3f2c5c3c204032b8c903288da5784eff6c77afc1 /src/plugins/winrt/qwinrtabstractvideorenderercontrol.cpp
parentf25034afaf67c32057797ae790505e57a92deffc (diff)
downloadqtmultimedia-94eb599b6995f8b8e6a132d553620f891e138129.tar.gz
qtmultimedia-94eb599b6995f8b8e6a132d553620f891e138129.tar.bz2
qtmultimedia-94eb599b6995f8b8e6a132d553620f891e138129.zip
winrt: Fix crash during certain video operations
The abstract video buffer pointer was being reused and (improperly) deleted when its reference count went to zero. As QVideoFrame utilizes an explicitly shared pointer which also tracks the video buffer, simply reuse the QVideoFrame instance instead. Task-number: QTBUG-47373 Change-Id: Idadae205cb520a0a1d752aa20256c0567b3be699 Reviewed-by: Andrew Knight <andrew.knight@intopalo.com>
Diffstat (limited to 'src/plugins/winrt/qwinrtabstractvideorenderercontrol.cpp')
-rw-r--r--src/plugins/winrt/qwinrtabstractvideorenderercontrol.cpp37
1 files changed, 10 insertions, 27 deletions
diff --git a/src/plugins/winrt/qwinrtabstractvideorenderercontrol.cpp b/src/plugins/winrt/qwinrtabstractvideorenderercontrol.cpp
index aa0f721b..4a225e9c 100644
--- a/src/plugins/winrt/qwinrtabstractvideorenderercontrol.cpp
+++ b/src/plugins/winrt/qwinrtabstractvideorenderercontrol.cpp
@@ -125,21 +125,13 @@ Q_GLOBAL_STATIC(QWinRTVideoRendererControlGlobal, g)
class QWinRTVideoBuffer : public QAbstractVideoBuffer, public QOpenGLTexture
{
public:
- QWinRTVideoBuffer()
+ QWinRTVideoBuffer(const QSize &size, TextureFormat format)
: QAbstractVideoBuffer(QAbstractVideoBuffer::GLTextureHandle)
, QOpenGLTexture(QOpenGLTexture::Target2D)
{
- }
-
- void addRef()
- {
- refCount.ref();
- }
-
- void release() Q_DECL_OVERRIDE
- {
- if (!refCount.deref())
- delete this;
+ setSize(size.width(), size.height());
+ setFormat(format);
+ create();
}
MapMode mapMode() const Q_DECL_OVERRIDE
@@ -163,9 +155,6 @@ public:
{
return QVariant::fromValue(textureId());
}
-
-private:
- QAtomicInt refCount;
};
enum DirtyState {
@@ -189,7 +178,7 @@ public:
EGLConfig eglConfig;
EGLSurface eglSurface;
- QWinRTVideoBuffer *videoBuffer;
+ QVideoFrame presentFrame;
QThread renderThread;
bool active;
@@ -224,8 +213,6 @@ QWinRTAbstractVideoRendererControl::QWinRTAbstractVideoRendererControl(const QSi
d->eglSurface = EGL_NO_SURFACE;
d->active = false;
- d->videoBuffer = new QWinRTVideoBuffer;
-
connect(&d->renderThread, &QThread::started,
this, &QWinRTAbstractVideoRendererControl::syncAndRender,
Qt::DirectConnection);
@@ -390,23 +377,19 @@ void QWinRTAbstractVideoRendererControl::present()
return;
}
- d->videoBuffer->setFormat(QOpenGLTexture::RGBAFormat);
- d->videoBuffer->setSize(d->format.frameWidth(), d->format.frameHeight());
- if (!d->videoBuffer->isCreated())
- d->videoBuffer->create();
+ QWinRTVideoBuffer *videoBuffer = new QWinRTVideoBuffer(d->format.frameSize(), QOpenGLTexture::RGBAFormat);
+ d->presentFrame = QVideoFrame(videoBuffer, d->format.frameSize(), d->format.pixelFormat());
// bind the pbuffer surface to the texture
- d->videoBuffer->bind();
+ videoBuffer->bind();
eglBindTexImage(d->eglDisplay, d->eglSurface, EGL_BACK_BUFFER);
- static_cast<QOpenGLTexture *>(d->videoBuffer)->release();
+ static_cast<QOpenGLTexture *>(videoBuffer)->release();
d->dirtyState = NotDirty;
}
// Present the frame
- d->videoBuffer->addRef();
- QVideoFrame frame(d->videoBuffer, d->format.frameSize(), d->format.pixelFormat());
- d->surface->present(frame);
+ d->surface->present(d->presentFrame);
}
QT_END_NAMESPACE