From 94eb599b6995f8b8e6a132d553620f891e138129 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Wed, 22 Jul 2015 18:34:02 +0300 Subject: 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 --- .../winrt/qwinrtabstractvideorenderercontrol.cpp | 37 ++++++---------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/src/plugins/winrt/qwinrtabstractvideorenderercontrol.cpp b/src/plugins/winrt/qwinrtabstractvideorenderercontrol.cpp index aa0f721b3..4a225e9ce 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(d->videoBuffer)->release(); + static_cast(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 -- cgit v1.2.3