From b50da3eba491dddc668b00ca1af34d4edf8082cd Mon Sep 17 00:00:00 2001 From: Jonas Kvinge Date: Sun, 29 Sep 2024 23:40:09 +0200 Subject: [PATCH] GstEnginePipeline: Add missing end of stream A bug was introduced when I added the mutex locker for the URLs, it did nothing when it was supposed to emit end of stream. Fixes #1568 --- src/engine/gstenginepipeline.cpp | 34 ++++++++++++++++++-------------- src/engine/gstenginepipeline.h | 1 + 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/engine/gstenginepipeline.cpp b/src/engine/gstenginepipeline.cpp index 244e8bb44..9fd408365 100644 --- a/src/engine/gstenginepipeline.cpp +++ b/src/engine/gstenginepipeline.cpp @@ -1305,22 +1305,18 @@ GstPadProbeReturn GstEnginePipeline::BufferProbeCallback(GstPad *pad, GstPadProb // Calculate the end time of this buffer so we can stop playback if it's after the end time of this song. if (instance->end_offset_nanosec_.value() > 0 && end_time > instance->end_offset_nanosec_.value()) { - if (instance->HasNextUrl()) { - QMutexLocker mutex_locker_url(&instance->mutex_url_); - QMutexLocker mutex_locker_next_url(&instance->mutex_next_url_); - if (instance->next_stream_url_ == instance->stream_url_ && instance->next_beginning_offset_nanosec_ == instance->end_offset_nanosec_) { - // The "next" song is actually the next segment of this file - so cheat and keep on playing, but just tell the Engine we've moved on. - instance->end_offset_nanosec_ = instance->next_end_offset_nanosec_; - instance->next_media_url_.clear(); - instance->next_stream_url_.clear(); - instance->next_gst_url_.clear(); - instance->next_beginning_offset_nanosec_ = 0; - instance->next_end_offset_nanosec_ = 0; + if (instance->HasMatchingNextUrl() && instance->next_beginning_offset_nanosec_.value() == instance->end_offset_nanosec_.value()) { + // The "next" song is actually the next segment of this file - so cheat and keep on playing, but just tell the Engine we've moved on. + instance->end_offset_nanosec_ = instance->next_end_offset_nanosec_; + instance->next_media_url_.clear(); + instance->next_stream_url_.clear(); + instance->next_gst_url_.clear(); + instance->next_beginning_offset_nanosec_ = 0; + instance->next_end_offset_nanosec_ = 0; - // GstEngine will try to seek to the start of the new section, but we're already there so ignore it. - instance->ignore_next_seek_ = true; - Q_EMIT instance->EndOfStreamReached(instance->id(), true); - } + // GstEngine will try to seek to the start of the new section, but we're already there so ignore it. + instance->ignore_next_seek_ = true; + Q_EMIT instance->EndOfStreamReached(instance->id(), true); } else { // There's no next song @@ -2070,6 +2066,14 @@ bool GstEnginePipeline::HasNextUrl() const { } +bool GstEnginePipeline::HasMatchingNextUrl() const { + + QMutexLocker mutex_locker_url(&mutex_url_); + QMutexLocker mutex_locker_next_url(&mutex_next_url_); + return next_stream_url_.isValid() && next_stream_url_ == stream_url_; + +} + void GstEnginePipeline::PrepareNextUrl(const QUrl &media_url, const QUrl &stream_url, const QByteArray &gst_url, const qint64 beginning_nanosec, const qint64 end_nanosec) { { diff --git a/src/engine/gstenginepipeline.h b/src/engine/gstenginepipeline.h index b3161d125..9792e526a 100644 --- a/src/engine/gstenginepipeline.h +++ b/src/engine/gstenginepipeline.h @@ -106,6 +106,7 @@ class GstEnginePipeline : public QObject { // If this is set then it will be loaded automatically when playback finishes for gapless playback bool HasNextUrl() const; + bool HasMatchingNextUrl() const; void PrepareNextUrl(const QUrl &media_url, const QUrl &stream_url, const QByteArray &gst_url, const qint64 beginning_nanosec, const qint64 end_nanosec); void SetNextUrl();