From 222001bc136c63470a8097cecd086de22c2bbddb Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Sun, 11 Aug 2024 14:52:00 +0200 Subject: [PATCH] GstEnginePipeline: Fix buffering --- src/engine/gstenginepipeline.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/engine/gstenginepipeline.cpp b/src/engine/gstenginepipeline.cpp index e17cf10f0..06caae8fa 100644 --- a/src/engine/gstenginepipeline.cpp +++ b/src/engine/gstenginepipeline.cpp @@ -1132,6 +1132,7 @@ void GstEnginePipeline::PadAddedCallback(GstElement *element, GstPad *pad, gpoin instance->pipeline_connected_ = true; if (instance->pending_seek_nanosec_ != -1 && instance->pipeline_active_) { QMetaObject::invokeMethod(instance, "Seek", Qt::QueuedConnection, Q_ARG(qint64, instance->pending_seek_nanosec_)); + instance->pending_seek_nanosec_ = -1; } } @@ -1676,9 +1677,10 @@ void GstEnginePipeline::StateChangedMessageReceived(GstMessage *msg) { } } - if (pipeline_active_) { + if (pipeline_active_ && !buffering_) { if (pending_seek_nanosec_ != -1 && new_state == GST_STATE_PAUSED) { SeekAsync(pending_seek_nanosec_); + pending_seek_nanosec_ = -1; } else if (pending_state_ != GST_STATE_NULL) { SetStateAsync(pending_state_); @@ -1704,19 +1706,29 @@ void GstEnginePipeline::BufferingMessageReceived(GstMessage *msg) { const GstState current_state = state(); - if (percent == 0 && current_state == GST_STATE_PLAYING && !buffering_) { + if (percent < 100 && !buffering_) { qLog(Debug) << "Buffering started"; buffering_ = true; emit BufferingStarted(); - - SetStateAsync(GST_STATE_PAUSED); + if (current_state == GST_STATE_PLAYING) { + SetStateAsync(GST_STATE_PAUSED); + if (pending_state_ == GST_STATE_NULL) { + pending_state_ = current_state; + } + } } else if (percent == 100 && buffering_) { qLog(Debug) << "Buffering finished"; buffering_ = false; emit BufferingFinished(); - - SetStateAsync(GST_STATE_PLAYING); + if (pending_seek_nanosec_ != -1) { + SeekAsync(pending_seek_nanosec_); + pending_seek_nanosec_ = -1; + } + else if (pending_state_ != GST_STATE_NULL) { + SetStateAsync(pending_state_); + pending_state_ = GST_STATE_NULL; + } } else if (buffering_) { emit BufferingProgress(percent);