summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOliver Wolff <oliver.wolff@qt.io>2017-09-21 14:36:54 +0200
committerOliver Wolff <oliver.wolff@qt.io>2017-09-25 10:36:07 +0000
commit020e7b4c198f5e74dd83da7fa8e64a02b14af2f9 (patch)
tree9b4b7bf67e8201d75fcab9c4d6014ea78363e7e9 /src
parentf6838120ead0361463c800c25a711b799fae29ee (diff)
winrt: Use QMutex instead of criticalSections
critical sections are really unpredictable when it comes to order of activation. It was possible that the loop in QWinRTAbstractVideoRendererControl's syncAndRender blocked its setBlitMode for up to 30 seconds on application start. During this time the camera screen just stayed black. The whole approach seems to work a lot better when QMutexes are used. Task-number: QTBUG-63015 Change-Id: Ib1b0fa1da35fe299896068146254e4cf1d9616fb Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/plugins/winrt/qwinrtabstractvideorenderercontrol.cpp14
-rw-r--r--src/plugins/winrt/qwinrtabstractvideorenderercontrol.h16
-rw-r--r--src/plugins/winrt/qwinrtcameracontrol.cpp18
3 files changed, 15 insertions, 33 deletions
diff --git a/src/plugins/winrt/qwinrtabstractvideorenderercontrol.cpp b/src/plugins/winrt/qwinrtabstractvideorenderercontrol.cpp
index b3fd1111..79545f6e 100644
--- a/src/plugins/winrt/qwinrtabstractvideorenderercontrol.cpp
+++ b/src/plugins/winrt/qwinrtabstractvideorenderercontrol.cpp
@@ -43,6 +43,7 @@
#include <QtCore/QGlobalStatic>
#include <QtCore/QLoggingCategory>
#include <QtCore/QMetaMethod>
+#include <QtCore/QMutexLocker>
#include <QtCore/QPointer>
#include <QtGui/QOpenGLContext>
#include <QtGui/QOpenGLTexture>
@@ -198,7 +199,7 @@ public:
QThread renderThread;
bool active;
QWinRTAbstractVideoRendererControl::BlitMode blitMode;
- CRITICAL_SECTION mutex;
+ QMutex mutex;
};
ID3D11Device *QWinRTAbstractVideoRendererControl::d3dDevice()
@@ -232,7 +233,6 @@ QWinRTAbstractVideoRendererControl::QWinRTAbstractVideoRendererControl(const QSi
d->eglSurface = EGL_NO_SURFACE;
d->active = false;
d->blitMode = DirectVideo;
- InitializeCriticalSectionEx(&d->mutex, 0, 0);
connect(&d->renderThread, &QThread::started,
this, &QWinRTAbstractVideoRendererControl::syncAndRender,
@@ -243,9 +243,9 @@ QWinRTAbstractVideoRendererControl::~QWinRTAbstractVideoRendererControl()
{
qCDebug(lcMMVideoRender) << __FUNCTION__;
Q_D(QWinRTAbstractVideoRendererControl);
- CriticalSectionLocker locker(&d->mutex);
+ QMutexLocker locker(&d->mutex);
shutdown();
- DeleteCriticalSection(&d->mutex);
+ locker.unlock();
eglDestroySurface(d->eglDisplay, d->eglSurface);
}
@@ -272,7 +272,7 @@ void QWinRTAbstractVideoRendererControl::syncAndRender()
if (currentThread->isInterruptionRequested())
break;
{
- CriticalSectionLocker lock(&d->mutex);
+ QMutexLocker lock(&d->mutex);
HRESULT hr;
if (d->dirtyState == TextureDirty) {
CD3D11_TEXTURE2D_DESC desc(DXGI_FORMAT_B8G8R8A8_UNORM, d->format.frameWidth(), d->format.frameHeight(), 1, 1);
@@ -359,7 +359,7 @@ void QWinRTAbstractVideoRendererControl::setActive(bool active)
// This only happens for quick restart scenarios, for instance
// when switching cameras.
if (d->renderThread.isRunning() && d->renderThread.isInterruptionRequested()) {
- CriticalSectionLocker lock(&d->mutex);
+ QMutexLocker lock(&d->mutex);
d->renderThread.wait();
}
@@ -385,7 +385,7 @@ QWinRTAbstractVideoRendererControl::BlitMode QWinRTAbstractVideoRendererControl:
void QWinRTAbstractVideoRendererControl::setBlitMode(QWinRTAbstractVideoRendererControl::BlitMode mode)
{
Q_D(QWinRTAbstractVideoRendererControl);
- CriticalSectionLocker lock(&d->mutex);
+ QMutexLocker lock(&d->mutex);
if (d->blitMode == mode)
return;
diff --git a/src/plugins/winrt/qwinrtabstractvideorenderercontrol.h b/src/plugins/winrt/qwinrtabstractvideorenderercontrol.h
index a7ba2998..53dcb6b9 100644
--- a/src/plugins/winrt/qwinrtabstractvideorenderercontrol.h
+++ b/src/plugins/winrt/qwinrtabstractvideorenderercontrol.h
@@ -96,22 +96,6 @@ private:
Q_DECLARE_PRIVATE(QWinRTAbstractVideoRendererControl)
};
-class CriticalSectionLocker
-{
-public:
- CriticalSectionLocker(CRITICAL_SECTION *section)
- : m_section(section)
- {
- EnterCriticalSection(m_section);
- }
- ~CriticalSectionLocker()
- {
- LeaveCriticalSection(m_section);
- }
-private:
- CRITICAL_SECTION *m_section;
-};
-
QT_END_NAMESPACE
#endif // QWINRTABSTRACTVIDEORENDERERCONTROL_H
diff --git a/src/plugins/winrt/qwinrtcameracontrol.cpp b/src/plugins/winrt/qwinrtcameracontrol.cpp
index a28d5721..e44f8166 100644
--- a/src/plugins/winrt/qwinrtcameracontrol.cpp
+++ b/src/plugins/winrt/qwinrtcameracontrol.cpp
@@ -47,6 +47,7 @@
#include "qwinrtcameralockscontrol.h"
#include <QtCore/qfunctions_winrt.h>
+#include <QtCore/QMutex>
#include <QtCore/QPointer>
#include <QtGui/QGuiApplication>
#include <private/qeventdispatcher_winrt_p.h>
@@ -227,8 +228,6 @@ public:
{
Q_ASSERT(m_videoRenderer);
- InitializeCriticalSectionEx(&m_mutex, 0, 0);
-
HRESULT hr;
hr = MFCreateEventQueue(&m_eventQueue);
Q_ASSERT_SUCCEEDED(hr);
@@ -238,9 +237,8 @@ public:
~MediaStream()
{
- CriticalSectionLocker locker(&m_mutex);
+ QMutexLocker locker(&m_mutex);
m_eventQueue->Shutdown();
- DeleteCriticalSection(&m_mutex);
}
HRESULT RequestSample()
@@ -254,30 +252,30 @@ public:
HRESULT __stdcall GetEvent(DWORD flags, IMFMediaEvent **event) Q_DECL_OVERRIDE
{
- EnterCriticalSection(&m_mutex);
+ QMutexLocker locker(&m_mutex);
// Create an extra reference to avoid deadlock
ComPtr<IMFMediaEventQueue> eventQueue = m_eventQueue;
- LeaveCriticalSection(&m_mutex);
+ locker.unlock();
return eventQueue->GetEvent(flags, event);
}
HRESULT __stdcall BeginGetEvent(IMFAsyncCallback *callback, IUnknown *state) Q_DECL_OVERRIDE
{
- CriticalSectionLocker locker(&m_mutex);
+ QMutexLocker locker(&m_mutex);
HRESULT hr = m_eventQueue->BeginGetEvent(callback, state);
return hr;
}
HRESULT __stdcall EndGetEvent(IMFAsyncResult *result, IMFMediaEvent **event) Q_DECL_OVERRIDE
{
- CriticalSectionLocker locker(&m_mutex);
+ QMutexLocker locker(&m_mutex);
return m_eventQueue->EndGetEvent(result, event);
}
HRESULT __stdcall QueueEvent(MediaEventType eventType, const GUID &extendedType, HRESULT status, const PROPVARIANT *value) Q_DECL_OVERRIDE
{
- CriticalSectionLocker locker(&m_mutex);
+ QMutexLocker locker(&m_mutex);
return m_eventQueue->QueueEventParamVar(eventType, extendedType, status, value);
}
@@ -372,7 +370,7 @@ public:
}
private:
- CRITICAL_SECTION m_mutex;
+ QMutex m_mutex;
ComPtr<IMFMediaType> m_type;
IMFMediaSink *m_sink;
ComPtr<IMFMediaEventQueue> m_eventQueue;