diff options
author | VaL Doroshchuk <valentyn.doroshchuk@qt.io> | 2020-05-06 14:28:20 +0200 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2020-05-08 10:11:28 +0000 |
commit | 516448c651507fc18210108efd68bf6103c570e0 (patch) | |
tree | 77e3c723bdff719f5e4a5103941f3d8c9c7c75ed | |
parent | 24a2c57e23fdee0c22b4f957b3b29ddb754b2699 (diff) |
GStreamer: Fix reverse playback
Each gstreamer plugin is responsible for supporting reverse playback
and also might require different start/stop types
(GST_SEEK_TYPE_SET, GST_SEEK_TYPE_NONE, GST_SEEK_TYPE_END).
Some plugins do not support it at all, e.g. wavparse.
if rate > 0:
change rate from current position to duration.
else:
change rate from current position to 0.
Fixed also seeking with a negative rate.
This should work for mp3 or some video formats too.
Fixes: QTBUG-83945
Change-Id: I10a98186b9bc63d908667944aa4459da9e63e343
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
-rw-r--r-- | src/gsttools/qgstreamerplayersession.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/src/gsttools/qgstreamerplayersession.cpp b/src/gsttools/qgstreamerplayersession.cpp index c6d2df810..f7f3b7ca1 100644 --- a/src/gsttools/qgstreamerplayersession.cpp +++ b/src/gsttools/qgstreamerplayersession.cpp @@ -494,10 +494,12 @@ void QGstreamerPlayerSession::setPlaybackRate(qreal rate) if (!qFuzzyCompare(m_playbackRate, rate)) { m_playbackRate = rate; if (m_pipeline && m_seekable) { + qint64 from = rate > 0 ? position() : 0; + qint64 to = rate > 0 ? duration() : position(); gst_element_seek(m_pipeline, rate, GST_FORMAT_TIME, GstSeekFlags(GST_SEEK_FLAG_FLUSH), - GST_SEEK_TYPE_NONE,0, - GST_SEEK_TYPE_END, 0); + GST_SEEK_TYPE_SET, from * 1000000, + GST_SEEK_TYPE_SET, to * 1000000); } emit playbackRateChanged(m_playbackRate); } @@ -1078,15 +1080,13 @@ bool QGstreamerPlayerSession::seek(qint64 ms) //seek locks when the video output sink is changing and pad is blocked if (m_pipeline && !m_pendingVideoSink && m_state != QMediaPlayer::StoppedState && m_seekable) { ms = qMax(ms,qint64(0)); - gint64 position = ms * 1000000; - bool isSeeking = gst_element_seek(m_pipeline, - m_playbackRate, - GST_FORMAT_TIME, + qint64 from = m_playbackRate > 0 ? ms : 0; + qint64 to = m_playbackRate > 0 ? duration() : ms; + + bool isSeeking = gst_element_seek(m_pipeline, m_playbackRate, GST_FORMAT_TIME, GstSeekFlags(GST_SEEK_FLAG_FLUSH), - GST_SEEK_TYPE_SET, - position, - GST_SEEK_TYPE_NONE, - 0); + GST_SEEK_TYPE_SET, from * 1000000, + GST_SEEK_TYPE_SET, to * 1000000); if (isSeeking) m_lastPosition = ms; |