From 516448c651507fc18210108efd68bf6103c570e0 Mon Sep 17 00:00:00 2001 From: VaL Doroshchuk Date: Wed, 6 May 2020 14:28:20 +0200 Subject: GStreamer: Fix reverse playback MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ø --- src/gsttools/qgstreamerplayersession.cpp | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'src/gsttools') 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; -- cgit v1.2.3