From 07d9206a5640aeaa2217748a90183e90c7742c0c Mon Sep 17 00:00:00 2001 From: TangoCash Date: Sun, 22 Oct 2017 10:46:57 +0200 Subject: [PATCH] armbox: fix gst playback --- libarmbox/playback_gst.cpp | 22 +++++++++------------- libarmbox/playback_gst.h | 2 +- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/libarmbox/playback_gst.cpp b/libarmbox/playback_gst.cpp index dcb5d36..ec16ddd 100644 --- a/libarmbox/playback_gst.cpp +++ b/libarmbox/playback_gst.cpp @@ -376,6 +376,7 @@ cPlayback::cPlayback(int num) playing = false; playstate = STATE_STOP; decoders_closed = false; + first = false; } cPlayback::~cPlayback() @@ -544,6 +545,8 @@ bool cPlayback::Start(char *filename, int /*vpid*/, int /*vtype*/, int /*apid*/, gst_bus_set_sync_handler(bus, Gst_bus_call, NULL, NULL); gst_object_unref(bus); + first = true; + // state playing if(isHTTP) { @@ -629,25 +632,17 @@ bool cPlayback::SetAPid(int pid, bool /*ac3*/) void cPlayback::trickSeek(int ratio) { - bool validposition = false; + GstFormat fmt = GST_FORMAT_TIME; gint64 pos = 0; - int position; - int duration; - - if( GetPosition(position, duration) ) - { - validposition = true; - pos = position*1000000; - } gst_element_set_state(m_gst_playbin, GST_STATE_PLAYING); - if (validposition) + if (gst_element_query_position(m_gst_playbin, fmt, &pos)) { if(ratio >= 0.0) - gst_element_seek(m_gst_playbin, ratio, GST_FORMAT_TIME, (GstSeekFlags)(GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_SKIP), GST_SEEK_TYPE_SET, pos, GST_SEEK_TYPE_SET, -1); + gst_element_seek(m_gst_playbin, ratio, fmt, (GstSeekFlags)(GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_SKIP | GST_SEEK_FLAG_ACCURATE), GST_SEEK_TYPE_SET, pos, GST_SEEK_TYPE_SET, -1); else - gst_element_seek(m_gst_playbin, ratio, GST_FORMAT_TIME, (GstSeekFlags)(GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_SKIP), GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_SET, pos); + gst_element_seek(m_gst_playbin, ratio, fmt, (GstSeekFlags)(GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_SKIP | GST_SEEK_FLAG_ACCURATE), GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_SET, pos); } } @@ -789,9 +784,10 @@ bool cPlayback::SetPosition(int position, bool absolute) { gst_element_get_state(m_gst_playbin, &state, NULL, GST_CLOCK_TIME_NONE); - if ( state == GST_STATE_PAUSED ) + if ( (state == GST_STATE_PAUSED) && first) { init_jump = position; + first = false; return false; } if (!absolute) diff --git a/libarmbox/playback_gst.h b/libarmbox/playback_gst.h index 396989e..a58de78 100644 --- a/libarmbox/playback_gst.h +++ b/libarmbox/playback_gst.h @@ -47,7 +47,7 @@ struct AVFormatContext; class cPlayback { private: - bool playing; + bool playing, first; bool decoders_closed; int mSpeed;