diff options
author | Val Doroshchuk <valentyn.doroshchuk@qt.io> | 2017-10-11 17:05:53 +0200 |
---|---|---|
committer | VaL Doroshchuk <valentyn.doroshchuk@qt.io> | 2017-11-10 10:11:34 +0000 |
commit | 4a214b199337a02e8cab77aa0cdca0c2805fb6a2 (patch) | |
tree | 9aab076dd062790a6f6d4704997d5edbb64c77b8 | |
parent | b0c352054e64b0fc64e547bf54dad1bdeaee283a (diff) |
Fix deadlock when a new url is set in loading state
Setting a new url while QMediaPlayer is in loading state
can result in a deadlock between the GUI and worker thread.
Because main thread is waiting when worker realeses m_graph
but worker cleared all pending tasks and is waiting for new tasks
from main thread.
Task-number: QTBUG-53534
Change-Id: I296ecdf866c5d85efc7121d3e7936334d6b700fd
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Reviewed-by: Maurice Kalinowski <maurice.kalinowski@qt.io>
Reviewed-by: Christian Stromme <christian.stromme@qt.io>
-rw-r--r-- | src/plugins/directshow/player/directshowplayerservice.cpp | 3 | ||||
-rw-r--r-- | tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp | 11 |
2 files changed, 11 insertions, 3 deletions
diff --git a/src/plugins/directshow/player/directshowplayerservice.cpp b/src/plugins/directshow/player/directshowplayerservice.cpp index 9cbb62969..8ee5d67a1 100644 --- a/src/plugins/directshow/player/directshowplayerservice.cpp +++ b/src/plugins/directshow/player/directshowplayerservice.cpp @@ -402,7 +402,6 @@ void DirectShowPlayerService::doSetUrlSource(QMutexLocker *locker) } else if (!m_resources.isEmpty()) { m_pendingTasks |= SetUrlSource; } else { - m_pendingTasks = 0; m_graphStatus = InvalidMedia; switch (hr) { @@ -1688,8 +1687,6 @@ void DirectShowPlayerService::run() QMutexLocker locker(&m_mutex); for (;;) { - ::ResetEvent(m_taskHandle); - while (m_pendingTasks == 0) { DWORD result = 0; diff --git a/tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp b/tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp index 5a703f2e1..9fe0a39ec 100644 --- a/tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp +++ b/tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp @@ -59,6 +59,7 @@ private slots: void construction(); void loadMedia(); void unloadMedia(); + void loadMediaInLoadingState(); void playPauseStop(); void processEOS(); void deleteLaterAtEOS(); @@ -325,6 +326,16 @@ void tst_QMediaPlayerBackend::unloadMedia() QVERIFY(!positionSpy.isEmpty()); } +void tst_QMediaPlayerBackend::loadMediaInLoadingState() +{ + const QUrl url("http://unavailable.media/"); + QMediaPlayer player; + player.setMedia(QMediaContent(url)); + player.play(); + // Sets new media while old has not been finished. + player.setMedia(QMediaContent(url)); + QTRY_COMPARE(player.mediaStatus(), QMediaPlayer::InvalidMedia); +} void tst_QMediaPlayerBackend::playPauseStop() { |