From 1b5249d1186064cd320b36ef6df7128e2e9937f2 Mon Sep 17 00:00:00 2001 From: Artem Dyomin Date: Fri, 14 Apr 2023 14:25:14 +0200 Subject: Fix threading problems of QVideoSink - change notification signals should be emitted out of the mutex since it causes a deadlock if the user connects directly and call QVideoSink getters. - currentVideoFrame should be under the mutex since frames assignment is not atomic. - minor clean up with moving to cpp file. Pick-to: 6.5 Change-Id: I07a7e54108c100cd18dc71c88acd93a5622bd2f5 Reviewed-by: Qt CI Bot Reviewed-by: Lars Knoll --- .../tst_qmediaplayerbackend.cpp | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'tests') diff --git a/tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp b/tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp index a19ff44a8..a3e005929 100644 --- a/tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp +++ b/tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp @@ -78,6 +78,7 @@ private slots: void seekOnLoops(); void changeLoopsOnTheFly(); void lazyLoadVideo(); + void videoSinkSignals(); private: QUrl selectVideoFile(const QStringList& mediaCandidates); @@ -1883,6 +1884,40 @@ void tst_QMediaPlayerBackend::lazyLoadVideo() QVERIFY(frame.isValid()); } +void tst_QMediaPlayerBackend::videoSinkSignals() +{ + // TODO: come up with custom frames source, + // create the test target tst_QVideoSinkBackend, + // and move the test there + + if (localVideoFile2.isEmpty()) + QSKIP("Video format is not supported"); + + QVideoSink sink; + QMediaPlayer player; + player.setVideoSink(&sink); + + std::atomic videoFrameCounter = 0; + std::atomic videoSizeCounter = 0; + + connect(&sink, &QVideoSink::videoFrameChanged, [&](const QVideoFrame &frame) { + QCOMPARE(sink.videoFrame(), frame); + QCOMPARE(sink.videoSize(), frame.size()); + ++videoFrameCounter; + }); + + connect(&sink, &QVideoSink::videoSizeChanged, [&]() { + QCOMPARE(sink.videoSize(), sink.videoFrame().size()); + ++videoSizeCounter; + }); + + player.setSource(localVideoFile2); + player.play(); + + QTRY_COMPARE_GE(videoFrameCounter, 2); + QCOMPARE(videoSizeCounter, 1); +} + QTEST_MAIN(tst_QMediaPlayerBackend) #include "tst_qmediaplayerbackend.moc" -- cgit v1.2.1