diff options
author | Oliver Wolff <oliver.wolff@qt.io> | 2017-09-21 14:36:54 +0200 |
---|---|---|
committer | Oliver Wolff <oliver.wolff@qt.io> | 2017-09-25 10:36:07 +0000 |
commit | 020e7b4c198f5e74dd83da7fa8e64a02b14af2f9 (patch) | |
tree | 9b4b7bf67e8201d75fcab9c4d6014ea78363e7e9 /src/plugins/winrt/qwinrtcameracontrol.cpp | |
parent | f6838120ead0361463c800c25a711b799fae29ee (diff) | |
download | qtmultimedia-020e7b4c198f5e74dd83da7fa8e64a02b14af2f9.tar.gz |
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/plugins/winrt/qwinrtcameracontrol.cpp')
-rw-r--r-- | src/plugins/winrt/qwinrtcameracontrol.cpp | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/plugins/winrt/qwinrtcameracontrol.cpp b/src/plugins/winrt/qwinrtcameracontrol.cpp index a28d57219..e44f81666 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; |