Nacre/vendor/gst-mse/nacre.patch

624 lines
23 KiB
Diff

Nacre patches to gst-plugins-bad 1.28.9 gst-libs/gst/mse (docs/engine/gst-mse-patches.md).
Base: https://sources.debian.org/src/gst-plugins-bad1.0/1.28.9-1/ . Apply with patch -p1 in gst-plugins-bad.
--- a/gst-libs/gst/mse/gstappendpipeline.c
+++ b/gst-libs/gst/mse/gstappendpipeline.c
@@ -95,6 +95,14 @@
gboolean encountered_error;
+ /* Nacre patch: appends pushed and appends whose end-of-append marker the
+ * background task has handled (samples handed to the source buffer), so
+ * gst_append_pipeline_append() can return only once its data is parsed. */
+ GMutex append_lock;
+ GCond append_cond;
+ guint64 appends_sent;
+ guint64 appends_done;
+
BackgroundTask *task;
Callbacks callbacks;
@@ -108,6 +116,21 @@
static void process_init_segment (GstAppendPipeline *);
+/* Nacre patch: one more append is fully processed, or (all) every append is
+ * settled because the pipeline stopped, failed or was reset. */
+static void
+finish_appends (GstAppendPipeline * self, gboolean all)
+{
+ g_mutex_lock (&self->append_lock);
+ if (all) {
+ self->appends_done = self->appends_sent;
+ } else if (self->appends_done < self->appends_sent) {
+ self->appends_done++;
+ }
+ g_cond_broadcast (&self->append_cond);
+ g_mutex_unlock (&self->append_lock);
+}
+
static gboolean
send_abort (GstAppendPipeline * self)
{
@@ -313,12 +336,14 @@
call_eos (self, track->mse_track);
}
call_eos (self, NULL);
+ finish_appends (self, TRUE);
}
static void
handle_abort (BackgroundTask * task)
{
gst_task_stop (task->task);
+ finish_appends (task->pipeline, TRUE);
}
static void
@@ -332,6 +357,7 @@
if (gst_message_has_name (message, END_OF_APPEND)) {
GST_TRACE_OBJECT (self, "end of append");
consume_all_samples (self);
+ finish_appends (self, FALSE);
goto done;
}
if (gst_message_has_name (message, SHUTDOWN)) {
@@ -742,6 +768,11 @@
self->encountered_error = FALSE;
self->tracks = new_tracks_array ();
init_segment_init (&self->init_segment);
+
+ g_mutex_init (&self->append_lock);
+ g_cond_init (&self->append_cond);
+ self->appends_sent = 0;
+ self->appends_done = 0;
}
static void
@@ -770,6 +801,9 @@
g_array_free (self->tracks, TRUE);
gst_clear_object (&self->streams);
+ g_mutex_clear (&self->append_lock);
+ g_cond_clear (&self->append_cond);
+
G_OBJECT_CLASS (gst_append_pipeline_parent_class)->finalize (object);
}
@@ -815,19 +849,48 @@
return NULL;
}
+/* Nacre patch: an append that never settles (a stuck parser) would leave the
+ * source buffer updating forever; give up waiting after this long. */
+#define APPEND_TIMEOUT (10 * G_TIME_SPAN_SECOND)
+
+/* Nacre patch: blocks until the background task has handled this append's
+ * end-of-append marker, i.e. every sample parsed from @buffer has been handed
+ * to the source buffer (consume_all_samples), so `buffered` is current when the
+ * caller signals update-end. Upstream returned once the bytes were queued in
+ * appsrc. Must be called without locks the new-sample callback takes. */
GstFlowReturn
gst_append_pipeline_append (GstAppendPipeline * self, GstBuffer * buffer)
{
g_return_val_if_fail (GST_IS_APPEND_PIPELINE (self), GST_FLOW_ERROR);
+
+ g_mutex_lock (&self->append_lock);
+ guint64 ticket = ++self->appends_sent;
+ g_mutex_unlock (&self->append_lock);
+
GstFlowReturn push_result = gst_app_src_push_buffer (self->src, buffer);
- if (push_result != GST_FLOW_OK)
+ if (push_result != GST_FLOW_OK) {
+ finish_appends (self, FALSE);
return push_result;
+ }
if (!gst_element_send_event (GST_ELEMENT_CAST (self->src),
new_end_of_append_event ())) {
GST_ERROR_OBJECT (self, "failed to push end-of-append event");
+ finish_appends (self, FALSE);
return GST_FLOW_ERROR;
}
+
+ gint64 deadline = g_get_monotonic_time () + APPEND_TIMEOUT;
+ g_mutex_lock (&self->append_lock);
+ while (self->appends_done < ticket) {
+ if (!g_cond_wait_until (&self->append_cond, &self->append_lock, deadline)) {
+ GST_WARNING_OBJECT (self, "append %" G_GUINT64_FORMAT " not processed "
+ "after %" G_GINT64_FORMAT " s, giving up waiting", ticket,
+ APPEND_TIMEOUT / G_TIME_SPAN_SECOND);
+ break;
+ }
+ }
+ g_mutex_unlock (&self->append_lock);
return GST_FLOW_OK;
}
@@ -875,6 +938,18 @@
background_task_stop (self->task);
+ /* Nacre patch: take the old tracks' appsinks out of the pipeline. Upstream
+ * left them in, so the next initialization segment's appsink ("video-0")
+ * clashed by name, gst_bin_add() dropped it and add_track() used it after
+ * it was freed (a crash on every append after abort() or changeType()). */
+ for (guint i = 0; i < self->tracks->len; i++) {
+ Track *track = &g_array_index (self->tracks, Track, i);
+ if (track->sink != NULL) {
+ gst_element_set_state (GST_ELEMENT (track->sink), GST_STATE_NULL);
+ gst_bin_remove (GST_BIN (self->pipeline), GST_ELEMENT (track->sink));
+ }
+ }
+
init_segment_finalize (&self->init_segment);
gst_clear_object (&self->streams);
g_array_free (self->tracks, TRUE);
--- a/gst-libs/gst/mse/gstsourcebuffer.c
+++ b/gst-libs/gst/mse/gstsourcebuffer.c
@@ -155,6 +155,10 @@
gsize size;
GstBuffer *pending_data;
GCond pending_data_cond;
+ /* Nacre patch: abort() during an append waits for it (see gst_source_buffer_abort). */
+ gboolean appending;
+ gboolean abort_requested;
+ GCond append_done_cond;
AppendToBufferTask *append_to_buffer_task;
GstAppendPipeline *append_pipeline;
GstMseEventQueue *event_queue;
@@ -224,6 +228,8 @@
static void schedule_event_unlocked (GstSourceBuffer * self,
SourceBufferEvent event);
static void append_to_buffer_task_func (AppendToBufferTask * task);
+static gsize compute_total_size_unlocked (GstSourceBuffer * self);
+static void reset_parser_state_unlocked (GstSourceBuffer * self);
static void append_to_buffer_task_start (AppendToBufferTask * task);
static void append_to_buffer_task_stop (AppendToBufferTask * task);
static AppendToBufferTask *append_to_buffer_task_new (GstSourceBuffer * parent);
@@ -938,6 +944,7 @@
self->size = 0;
self->pending_data = NULL;
g_cond_init (&self->pending_data_cond);
+ g_cond_init (&self->append_done_cond);
self->processed_init_segment = FALSE;
self->event_queue =
gst_mse_event_queue_new ((GstMseEventQueueCallback) dispatch_event, self);
@@ -947,8 +954,12 @@
(GEqualFunc) track_buffer_equal, NULL, gst_object_unref);
g_mutex_init (&self->tracks_lock);
- self->track_feeds = g_hash_table_new_full (g_direct_hash, g_direct_equal,
- NULL, (GDestroyNotify) clear_track_feed);
+ /* Nacre patch: keyed by track id like track_buffers. After a parser reset
+ * (abort, changeType) the next initialization segment brings new track
+ * objects with the same ids; their samples must reach the existing track
+ * buffers and feeds (and so msesrc's streams), not miss the lookup. */
+ self->track_feeds = g_hash_table_new_full ((GHashFunc) track_buffer_hash,
+ (GEqualFunc) track_buffer_equal, NULL, (GDestroyNotify) clear_track_feed);
self->seek_time = 0;
self->callbacks.callbacks.duration_changed = NULL;
self->callbacks.user_data = NULL;
@@ -1178,7 +1189,9 @@
goto error;
}
- if (!GST_CLOCK_TIME_IS_VALID (start) || start <= self->append_window_end) {
+ /* Nacre patch: upstream refused every start below the end (`<=`). An end of
+ * GST_CLOCK_TIME_NONE is +infinity, which the unsigned compare gets right. */
+ if (!GST_CLOCK_TIME_IS_VALID (start) || start >= self->append_window_end) {
g_set_error (error,
GST_MEDIA_SOURCE_ERROR, GST_MEDIA_SOURCE_ERROR_TYPE,
"append window start must be between zero and append window end");
@@ -1486,6 +1499,41 @@
GstClockTime end, GError ** error)
{
g_return_val_if_fail (GST_IS_SOURCE_BUFFER (self), FALSE);
+
+ /* Nacre patch: upstream 1.28.9 returns here without removing anything.
+ * Remove every coded frame group (key frame to key frame) that lies inside
+ * [start, end); a group that only overlaps the range stays, so playback never
+ * loses the frames a kept frame depends on. Runs synchronously: the caller
+ * reports update and update-end. */
+ if (end == GST_CLOCK_TIME_NONE)
+ end = G_MAXUINT64;
+
+ GST_OBJECT_LOCK (self);
+
+ if (is_removed_unlocked (self) || is_updating (self)) {
+ g_set_error (error,
+ GST_MEDIA_SOURCE_ERROR, GST_MEDIA_SOURCE_ERROR_INVALID_STATE,
+ "source buffer is removed or still updating");
+ GST_OBJECT_UNLOCK (self);
+ return FALSE;
+ }
+
+ if (start >= end) {
+ g_set_error (error,
+ GST_MEDIA_SOURCE_ERROR, GST_MEDIA_SOURCE_ERROR_TYPE,
+ "remove range is empty");
+ GST_OBJECT_UNLOCK (self);
+ return FALSE;
+ }
+
+ GHashTableIter iter;
+ g_hash_table_iter_init (&iter, self->track_buffers);
+ for (gpointer value; g_hash_table_iter_next (&iter, NULL, &value);) {
+ gst_media_source_track_buffer_remove_range (value, start, end);
+ }
+ self->size = compute_total_size_unlocked (self);
+
+ GST_OBJECT_UNLOCK (self);
return TRUE;
}
@@ -1761,13 +1809,36 @@
}
if (!GST_IS_BUFFER (pending_data)) {
+ /* Nacre patch: the wait above times out every second; with nothing
+ * appended there is nothing to report. Upstream signalled update and
+ * update-end here, a spurious pair every second while idle. */
GST_TRACE_OBJECT (self, "no pending data");
- append_successful_unlocked (self, is_ended_unlocked (self));
goto done;
}
- GstFlowReturn result = gst_append_pipeline_append (self->append_pipeline,
- pending_data);
+ /* Nacre patch: the append now waits until its samples reach the track
+ * buffers, and the new-sample callback takes this object's lock, so drop it
+ * meanwhile. `updating` stays set, so no other append can start. */
+ GstAppendPipeline *pipeline = gst_object_ref (self->append_pipeline);
+ self->appending = TRUE;
+ GST_OBJECT_UNLOCK (self);
+ GstFlowReturn result = gst_append_pipeline_append (pipeline, pending_data);
+ gst_object_unref (pipeline);
+ GST_OBJECT_LOCK (self);
+ self->appending = FALSE;
+
+ /* Nacre patch: abort() came in while this append ran. It resets the parser
+ * and owns the events (abort and update-end come from the caller). */
+ if (self->abort_requested) {
+ self->abort_requested = FALSE;
+ g_cond_broadcast (&self->append_done_cond);
+ goto done;
+ }
+
+ if (is_removed_unlocked (self)) {
+ append_successful_unlocked (self, TRUE);
+ goto done;
+ }
if (result != GST_FLOW_OK) {
GST_ERROR_OBJECT (self, "failed to append: %s", gst_flow_get_name (result));
@@ -2009,14 +2080,35 @@
gst_source_buffer_abort (GstSourceBuffer * self, GError ** error)
{
g_return_val_if_fail (GST_IS_SOURCE_BUFFER (self), FALSE);
- if (gst_append_pipeline_eos (self->append_pipeline) == GST_FLOW_OK) {
- return TRUE;
- } else {
+
+ /* Nacre patch: upstream sent end-of-stream into the append pipeline, which
+ * left it unable to take any later append. The spec's abort drops the pending
+ * data, stops a running append and resets the parser state, so the next
+ * append starts fresh (with an initialization segment). An append that is
+ * already inside the pipeline is waited for (it takes milliseconds) and its
+ * result discarded. */
+ GST_OBJECT_LOCK (self);
+
+ if (is_removed_unlocked (self)) {
g_set_error (error,
GST_MEDIA_SOURCE_ERROR, GST_MEDIA_SOURCE_ERROR_INVALID_STATE,
- "failed to abort source buffer");
+ "source buffer is removed");
+ GST_OBJECT_UNLOCK (self);
return FALSE;
}
+
+ clear_pending_data_unlocked (self);
+ if (self->appending) {
+ self->abort_requested = TRUE;
+ while (self->abort_requested) {
+ g_cond_wait (&self->append_done_cond, GST_OBJECT_GET_LOCK (self));
+ }
+ }
+ reset_parser_state_unlocked (self);
+ clear_updating (self);
+
+ GST_OBJECT_UNLOCK (self);
+ return TRUE;
}
gboolean
--- a/gst-libs/gst/mse/gstmsesrc.c
+++ b/gst-libs/gst/mse/gstmsesrc.c
@@ -266,7 +266,7 @@
static GstStateChangeReturn gst_mse_src_change_state (GstElement * element,
GstStateChange transition);
static gboolean gst_mse_src_send_event (GstElement * element, GstEvent * event);
-static void update_ready_state_for_init_segment (GstMseSrc * self);
+static gboolean update_ready_state_for_init_segment (GstMseSrc * self);
static void update_ready_state (GstMseSrc * self);
G_DEFINE_TYPE_WITH_CODE (GstMseSrc, gst_mse_src, GST_TYPE_ELEMENT,
@@ -973,6 +973,21 @@
goto pause;
}
+ /* Nacre patch: urisourcebin links a new pad to a typefind element before it
+ * activates that element, and linking resumes this task. Pushing then gets
+ * FLUSHING, which paused the task for good and dropped the sample it had
+ * popped, so that stream never started (the pad order is the streams hash
+ * table's, so either stream of a split audio/video source could hang). Wait
+ * for the peer to become active before taking data from the track. */
+ GstPad *peer = gst_pad_get_peer (GST_PAD (pad));
+ gboolean peer_inactive = peer != NULL && GST_PAD_IS_FLUSHING (peer);
+ gst_clear_object (&peer);
+ if (peer_inactive) {
+ GST_TRACE_OBJECT (pad, "peer is not active yet");
+ g_usleep (10 * 1000);
+ return;
+ }
+
self = GST_MSE_SRC (gst_pad_get_parent_element (GST_PAD (pad)));
GstMediaSourceTrack *track = pad->track;
@@ -1216,7 +1231,15 @@
GstElement *element = GST_ELEMENT (self);
GstObject *object = GST_OBJECT (self);
- update_ready_state_for_init_segment (self);
+ /* Nacre patch: expose no stream until every SourceBuffer of the attached
+ * MediaSource has received its first init segment (MSE "init segment
+ * received" step 5 / HAVE_METADATA). Exposing the first buffer's tracks alone
+ * made playbin preroll on them and never take the later ones, so separate
+ * audio and video SourceBuffers stalled at HAVE_NOTHING. */
+ if (!update_ready_state_for_init_segment (self)) {
+ GST_DEBUG_OBJECT (self, "waiting for every source buffer's init segment");
+ return;
+ }
STREAMS_LOCK (self);
@@ -1337,9 +1360,15 @@
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_READY_STATE]);
}
-static void
+/* Nacre patch: returns whether every source buffer has received an init
+ * segment (TRUE once past HAVE_NOTHING, or when detached), and no longer leaves
+ * media_source_lock held on the "not yet" path, which deadlocked the ready
+ * state task and anything else taking that lock. */
+static gboolean
update_ready_state_for_init_segment (GstMseSrc * self)
{
+ gboolean all_received_init_segment = TRUE;
+
MEDIA_SOURCE_LOCK (self);
if (self->media_source == NULL) {
@@ -1350,7 +1379,6 @@
}
GstSourceBufferList *buffers = gst_media_source_get_source_buffers
(self->media_source);
- gboolean all_received_init_segment = TRUE;
for (guint i = 0; all_received_init_segment; i++) {
GstSourceBuffer *buf = gst_source_buffer_list_index (buffers, i);
if (buf == NULL) {
@@ -1359,14 +1387,16 @@
all_received_init_segment &= gst_source_buffer_has_init_segment (buf);
gst_object_unref (buf);
}
+ gst_object_unref (buffers);
if (!all_received_init_segment) {
- return;
+ goto done;
}
set_ready_state (self, MAX (self->ready_state,
GST_MSE_SRC_READY_STATE_HAVE_METADATA));
done:
MEDIA_SOURCE_UNLOCK (self);
+ return all_received_init_segment;
}
static gboolean
S028 patches 10-11 (end of stream reaches msesrc; coded frames never shrink the duration):
diff --git a/gst-libs/gst/mse/gstmediasource.c b/gst-libs/gst/mse/gstmediasource.c
index 04a817d..cc58449 100644
--- a/gst-libs/gst/mse/gstmediasource.c
+++ b/gst-libs/gst/mse/gstmediasource.c
@@ -542,10 +542,27 @@ gst_media_source_get_source_element (GstMediaSource * self)
return element;
}
+/* Nacre patch: see gst_source_buffer_set_eos(). */
+static void
+set_all_source_buffers_eos (GstMediaSource * self, gboolean eos)
+{
+ for (guint i = 0;; i++) {
+ GstSourceBuffer *buf = gst_source_buffer_list_index (self->buffers, i);
+ if (buf == NULL) {
+ return;
+ }
+ gst_source_buffer_set_eos (buf, eos);
+ gst_object_unref (buf);
+ }
+}
+
void
gst_media_source_open (GstMediaSource * self)
{
g_return_if_fail (GST_IS_MEDIA_SOURCE (self));
+ if (self->ready_state == GST_MEDIA_SOURCE_READY_STATE_ENDED) {
+ set_all_source_buffers_eos (self, FALSE);
+ }
if (self->ready_state != GST_MEDIA_SOURCE_READY_STATE_OPEN) {
self->ready_state = GST_MEDIA_SOURCE_READY_STATE_OPEN;
schedule_event (self, ON_SOURCE_OPEN);
@@ -755,7 +772,11 @@ on_duration_changed (G_GNUC_UNUSED GstSourceBuffer * source_buffer,
}
gst_object_unref (buf);
}
- if (current == max) {
+ /* Nacre patch: coded frames only extend the duration (MSE coded frame
+ * processing: "the maximum of the current duration and the group end
+ * timestamp"). Upstream also shrank a duration the page had set to the
+ * buffered end, so a seek ahead of the data jumped back. */
+ if (GST_CLOCK_TIME_IS_VALID (current) && max <= current) {
return;
}
GST_DEBUG_OBJECT (self, "updating %" GST_TIMEP_FORMAT "=>%" GST_TIMEP_FORMAT,
@@ -1014,6 +1035,7 @@ gst_media_source_end_of_stream (GstMediaSource * self,
default:
update_duration (self);
abort_all_source_buffers (self);
+ set_all_source_buffers_eos (self, TRUE);
break;
}
diff --git a/gst-libs/gst/mse/gstmediasourcetrackbuffer-private.h b/gst-libs/gst/mse/gstmediasourcetrackbuffer-private.h
index a6beb1a..51cf919 100644
--- a/gst-libs/gst/mse/gstmediasourcetrackbuffer-private.h
+++ b/gst-libs/gst/mse/gstmediasourcetrackbuffer-private.h
@@ -73,6 +73,9 @@ gst_media_source_track_buffer_remove_range (GstMediaSourceTrackBuffer * self,
GST_MSE_PRIVATE
void gst_media_source_track_buffer_eos (GstMediaSourceTrackBuffer * self);
+GST_MSE_PRIVATE
+void gst_media_source_track_buffer_clear_eos (GstMediaSourceTrackBuffer * self);
+
GST_MSE_PRIVATE
gboolean gst_media_source_track_buffer_is_eos (
GstMediaSourceTrackBuffer * self);
diff --git a/gst-libs/gst/mse/gstmediasourcetrackbuffer.c b/gst-libs/gst/mse/gstmediasourcetrackbuffer.c
index f121e64..8830712 100644
--- a/gst-libs/gst/mse/gstmediasourcetrackbuffer.c
+++ b/gst-libs/gst/mse/gstmediasourcetrackbuffer.c
@@ -181,6 +181,15 @@ gst_media_source_track_buffer_eos (GstMediaSourceTrackBuffer * self)
NEW_DATA_UNLOCK (self);
}
+/* Nacre patch: the media source reopened after ending; a feed started later
+ * (by a seek) must wait for new data again instead of ending. */
+void
+gst_media_source_track_buffer_clear_eos (GstMediaSourceTrackBuffer * self)
+{
+ g_return_if_fail (GST_IS_MEDIA_SOURCE_TRACK_BUFFER (self));
+ g_atomic_int_set (&self->eos, FALSE);
+}
+
gboolean
gst_media_source_track_buffer_is_eos (GstMediaSourceTrackBuffer * self)
{
diff --git a/gst-libs/gst/mse/gstsourcebuffer-private.h b/gst-libs/gst/mse/gstsourcebuffer-private.h
index 17ae1af..1e7762b 100644
--- a/gst-libs/gst/mse/gstsourcebuffer-private.h
+++ b/gst-libs/gst/mse/gstsourcebuffer-private.h
@@ -49,6 +49,9 @@ void gst_source_buffer_teardown (GstSourceBuffer * self);
GST_MSE_PRIVATE
gboolean gst_source_buffer_has_init_segment (GstSourceBuffer * self);
+GST_MSE_PRIVATE
+void gst_source_buffer_set_eos (GstSourceBuffer * self, gboolean eos);
+
GST_MSE_PRIVATE
gboolean gst_source_buffer_is_buffered (GstSourceBuffer * self, GstClockTime
time);
diff --git a/gst-libs/gst/mse/gstsourcebuffer.c b/gst-libs/gst/mse/gstsourcebuffer.c
index dc06b01..34e0f50 100644
--- a/gst-libs/gst/mse/gstsourcebuffer.c
+++ b/gst-libs/gst/mse/gstsourcebuffer.c
@@ -2111,6 +2111,29 @@ gst_source_buffer_abort (GstSourceBuffer * self, GError ** error)
return TRUE;
}
+/* Nacre patch: marks every track buffer as ended (the media source ended
+ * without an error: its feeds push EOS once their samples are out, so msesrc
+ * and the player reach end of stream), or no longer ended (it reopened).
+ * Upstream got EOS into the track buffers as a side effect of abort() sending
+ * EOS into the append pipeline, which broke every later append (patch 6). */
+void
+gst_source_buffer_set_eos (GstSourceBuffer * self, gboolean eos)
+{
+ g_return_if_fail (GST_IS_SOURCE_BUFFER (self));
+ TRACKS_LOCK (self);
+ GHashTableIter iter;
+ g_hash_table_iter_init (&iter, self->track_buffers);
+ for (gpointer value; g_hash_table_iter_next (&iter, NULL, &value);) {
+ GstMediaSourceTrackBuffer *buffer = value;
+ if (eos) {
+ gst_media_source_track_buffer_eos (buffer);
+ } else {
+ gst_media_source_track_buffer_clear_eos (buffer);
+ }
+ }
+ TRACKS_UNLOCK (self);
+}
+
gboolean
gst_source_buffer_has_init_segment (GstSourceBuffer * self)
{
S028 patch 10 follow-up (append after endOfStream reopens without taking TRACKS_LOCK twice):
diff --git a/gst-libs/gst/mse/gstsourcebuffer.c b/gst-libs/gst/mse/gstsourcebuffer.c
index 34e0f50..503e8ac 100644
--- a/gst-libs/gst/mse/gstsourcebuffer.c
+++ b/gst-libs/gst/mse/gstsourcebuffer.c
@@ -2024,7 +2024,11 @@ gst_source_buffer_append_buffer (GstSourceBuffer * self, GstBuffer * buf,
}
if (is_ended_unlocked (self)) {
+ /* Nacre patch: reopening clears the end of stream on every source
+ * buffer's tracks (patch 10), which takes this one's tracks lock. */
+ TRACKS_UNLOCK (self);
open_parent_unlocked (self);
+ TRACKS_LOCK (self);
}
GstMediaSource *source = get_media_source_unlocked (self);
S028 patch 12 (coded frames raise the duration to the buffered end):
diff --git a/gst-libs/gst/mse/gstmediasource.c b/gst-libs/gst/mse/gstmediasource.c
index cc58449..1cfcb4b 100644
--- a/gst-libs/gst/mse/gstmediasource.c
+++ b/gst-libs/gst/mse/gstmediasource.c
@@ -770,6 +770,14 @@ on_duration_changed (G_GNUC_UNUSED GstSourceBuffer * source_buffer,
if (GST_CLOCK_TIME_IS_VALID (duration)) {
max = MAX (max, duration);
}
+ /* Nacre patch: the demuxer's duration is 0 or the first fragment's for
+ * fragmented MP4 (empty moov); the buffered end counts too. */
+ GArray *ranges = gst_source_buffer_get_buffered (buf, NULL);
+ if (ranges != NULL && ranges->len > 0) {
+ max = MAX (max, g_array_index (ranges, GstMediaSourceRange,
+ ranges->len - 1).end);
+ }
+ g_clear_pointer (&ranges, g_array_unref);
gst_object_unref (buf);
}
/* Nacre patch: coded frames only extend the duration (MSE coded frame
diff --git a/gst-libs/gst/mse/gstsourcebuffer.c b/gst-libs/gst/mse/gstsourcebuffer.c
index 503e8ac..5c8b8b0 100644
--- a/gst-libs/gst/mse/gstsourcebuffer.c
+++ b/gst-libs/gst/mse/gstsourcebuffer.c
@@ -1846,6 +1846,13 @@ append_to_buffer_task_func (AppendToBufferTask * task)
goto done;
}
+ /* Nacre patch: coded frame processing raises the duration to the highest
+ * end timestamp, before update-end. The media source reads every buffer's
+ * ranges, so call it outside this object's lock; `updating` is still set. */
+ GST_OBJECT_UNLOCK (self);
+ call_duration_changed (self);
+ GST_OBJECT_LOCK (self);
+
append_successful_unlocked (self, is_ended_unlocked (self));
done: