summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2021-07-27 16:41:57 +0200
committerLars Knoll <lars.knoll@qt.io>2021-07-28 12:46:25 +0200
commit2d6789e108a845963dd33b89ca3a9b1bb97b7891 (patch)
tree92936ee87b408b306e2e3dcb8829042131ec02e1
parentba25892e0efc547278c2441d47892d0a9595bb2c (diff)
Fix QMediaPlayer::hasAudio/Video() and related signals
Ensure we don't emit the signal more often than required by moving some state logic into the platform independent code and fixing the logic in the gstreamer backend. Fixes: QTBUG-95317 Change-Id: I9fcf581bf3992763c1874723faa7909cee2162f9 Reviewed-by: André de la Rocha <andre.rocha@qt.io>
-rw-r--r--src/multimedia/platform/gstreamer/common/qgstreamermediaplayer.cpp23
-rw-r--r--src/multimedia/platform/gstreamer/common/qgstreamermediaplayer_p.h3
-rw-r--r--src/multimedia/platform/qplatformmediaplayer_p.h20
-rw-r--r--tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp23
4 files changed, 49 insertions, 20 deletions
diff --git a/src/multimedia/platform/gstreamer/common/qgstreamermediaplayer.cpp b/src/multimedia/platform/gstreamer/common/qgstreamermediaplayer.cpp
index c8535b2b0..553098f7c 100644
--- a/src/multimedia/platform/gstreamer/common/qgstreamermediaplayer.cpp
+++ b/src/multimedia/platform/gstreamer/common/qgstreamermediaplayer.cpp
@@ -459,22 +459,29 @@ void QGstreamerMediaPlayer::decoderPadRemoved(const QGstElement &src, const QGst
Q_ASSERT(m_streams[streamType].indexOf(peer) != -1);
m_streams[streamType].removeAll(peer);
- if (m_streams[streamType].size() == 0)
+ if (m_streams[streamType].size() == 0) {
removeOutput(TrackType(streamType));
+ if (streamType == AudioStream)
+ audioAvailableChanged(false);
+ else if (streamType == VideoStream)
+ videoAvailableChanged(false);
+ }
if (!prerolling)
- emit tracksChanged();
+ tracksChanged();
}
void QGstreamerMediaPlayer::removeAllOutputs()
{
for (int i = 0; i < NTrackTypes; ++i) {
removeOutput(TrackType(i));
- for (QGstPad pad : qAsConst(m_streams[i])) {
+ for (const QGstPad &pad : qAsConst(m_streams[i])) {
inputSelector[i].releaseRequestPad(pad);
}
m_streams[i].clear();
}
+ audioAvailableChanged(false);
+ videoAvailableChanged(false);
}
void QGstreamerMediaPlayer::removeOutput(TrackType t)
@@ -748,14 +755,4 @@ void QGstreamerMediaPlayer::setActiveTrack(QPlatformMediaPlayer::TrackType type,
m_requiresSeekOnPlay = true;
}
-bool QGstreamerMediaPlayer::isAudioAvailable() const
-{
- return !m_streams[AudioStream].isEmpty();
-}
-
-bool QGstreamerMediaPlayer::isVideoAvailable() const
-{
- return !m_streams[VideoStream].isEmpty();
-}
-
QT_END_NAMESPACE
diff --git a/src/multimedia/platform/gstreamer/common/qgstreamermediaplayer_p.h b/src/multimedia/platform/gstreamer/common/qgstreamermediaplayer_p.h
index 26a8ca60e..038181f36 100644
--- a/src/multimedia/platform/gstreamer/common/qgstreamermediaplayer_p.h
+++ b/src/multimedia/platform/gstreamer/common/qgstreamermediaplayer_p.h
@@ -84,9 +84,6 @@ public:
float bufferProgress() const override;
- bool isAudioAvailable() const override;
- bool isVideoAvailable() const override;
-
bool isSeekable() const override;
QMediaTimeRange availablePlaybackRanges() const override;
diff --git a/src/multimedia/platform/qplatformmediaplayer_p.h b/src/multimedia/platform/qplatformmediaplayer_p.h
index dc2be4db3..4bbf4da64 100644
--- a/src/multimedia/platform/qplatformmediaplayer_p.h
+++ b/src/multimedia/platform/qplatformmediaplayer_p.h
@@ -77,8 +77,8 @@ public:
virtual float bufferProgress() const = 0;
- virtual bool isAudioAvailable() const = 0;
- virtual bool isVideoAvailable() const = 0;
+ virtual bool isAudioAvailable() const { return m_audioAvailable; }
+ virtual bool isVideoAvailable() const { return m_videoAvailable; }
virtual bool isSeekable() const { return m_seekable; }
@@ -113,8 +113,18 @@ public:
void durationChanged(qint64 duration) { player->durationChanged(duration); }
void positionChanged(qint64 position) { player->positionChanged(position); }
- void audioAvailableChanged(bool audioAvailable) { player->hasAudioChanged(audioAvailable); }
- void videoAvailableChanged(bool videoAvailable) { player->hasVideoChanged(videoAvailable); }
+ void audioAvailableChanged(bool audioAvailable) {
+ if (m_audioAvailable == audioAvailable)
+ return;
+ m_audioAvailable = audioAvailable;
+ player->hasAudioChanged(audioAvailable);
+ }
+ void videoAvailableChanged(bool videoAvailable) {
+ if (m_videoAvailable == videoAvailable)
+ return;
+ m_videoAvailable = videoAvailable;
+ player->hasVideoChanged(videoAvailable);
+ }
void seekableChanged(bool seekable) {
if (m_seekable == seekable)
return;
@@ -140,6 +150,8 @@ private:
QMediaPlayer::MediaStatus m_status = QMediaPlayer::NoMedia;
QMediaPlayer::PlaybackState m_state = QMediaPlayer::StoppedState;
bool m_seekable = true;
+ bool m_videoAvailable = false;
+ bool m_audioAvailable = false;
};
QT_END_NAMESPACE
diff --git a/tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp b/tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp
index 2194f977d..c27e956c7 100644
--- a/tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp
+++ b/tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp
@@ -77,6 +77,7 @@ private slots:
void metadata();
void playerStateAtEOS();
void playFromBuffer();
+ void audioVideoAvailable();
private:
QUrl selectVideoFile(const QStringList& mediaCandidates);
@@ -1085,6 +1086,28 @@ void tst_QMediaPlayerBackend::playFromBuffer()
QVERIFY2(surface.m_totalFrames >= 25, qPrintable(QString("Expected >= 25, got %1").arg(surface.m_totalFrames)));
}
+void tst_QMediaPlayerBackend::audioVideoAvailable()
+{
+ if (localVideoFile.isEmpty())
+ QSKIP("No supported video file");
+
+ TestVideoSink surface(false);
+ QMediaPlayer player;
+ QSignalSpy hasVideoSpy(&player, SIGNAL(hasVideoChanged(bool)));
+ QSignalSpy hasAudioSpy(&player, SIGNAL(hasAudioChanged(bool)));
+ player.setVideoOutput(&surface);
+ player.setSource(localVideoFile);
+ QTRY_VERIFY(player.hasVideo());
+ QTRY_VERIFY(player.hasAudio());
+ QCOMPARE(hasVideoSpy.count(), 1);
+ QCOMPARE(hasAudioSpy.count(), 1);
+ player.setSource(QUrl());
+ QTRY_VERIFY(!player.hasVideo());
+ QTRY_VERIFY(!player.hasAudio());
+ QCOMPARE(hasVideoSpy.count(), 2);
+ QCOMPARE(hasAudioSpy.count(), 2);
+}
+
QTEST_MAIN(tst_QMediaPlayerBackend)
#include "tst_qmediaplayerbackend.moc"