From 4a214b199337a02e8cab77aa0cdca0c2805fb6a2 Mon Sep 17 00:00:00 2001 From: Val Doroshchuk Date: Wed, 11 Oct 2017 17:05:53 +0200 Subject: 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 Reviewed-by: Maurice Kalinowski Reviewed-by: Christian Stromme --- src/plugins/directshow/player/directshowplayerservice.cpp | 3 --- .../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() { -- cgit v1.2.1