diff --git a/docs/engine/gst-mse-patches.md b/docs/engine/gst-mse-patches.md index 8f7e2dd..5ed768f 100644 --- a/docs/engine/gst-mse-patches.md +++ b/docs/engine/gst-mse-patches.md @@ -144,7 +144,9 @@ appsrc, which then reached the track buffers and msesrc. Patch 6 made abort drop **Fix.** End of stream (no error) marks every track buffer of every source buffer EOS (`gst_source_buffer_set_eos`, under TRACKS_LOCK); `gst_media_source_open()` clears it again when the state was ENDED (a new append reopens the -source; new `gst_media_source_track_buffer_clear_eos`). **Test:** mse-player smoke case `ended`. +source; new `gst_media_source_track_buffer_clear_eos`). `gst_source_buffer_append_buffer()` drops its own TRACKS_LOCK +around that reopen (it held it, and the clear takes it again: a deadlock that hung the script thread). **Test:** +mse-player smoke case `ended`; C test `/mse/reopen-append`. ## 11. Coded frames shrink a duration the page set (S028) diff --git a/tests/gst-mse/mse-fixes.c b/tests/gst-mse/mse-fixes.c index c6b03f7..d5af3e8 100644 --- a/tests/gst-mse/mse-fixes.c +++ b/tests/gst-mse/mse-fixes.c @@ -15,6 +15,8 @@ * end-of-stream into the append pipeline, so every later append failed); * again after the init segment was parsed (the reset left the old appsinks * in the pipeline and the next one crashed on a name clash) + * /mse/reopen-append an append after endOfStream() reopens the source and completes (patch 10's + * reopen took the appending buffer's tracks lock twice: a deadlock) * * Built and run by `tools/gst-mse.sh test` against target/gst-mse (GST_PLUGIN_PATH, own registry). * Clips in data/ (TESTS_DATA_DIR), made with ffmpeg: @@ -466,6 +468,50 @@ test_split_audio_video (void) } } +static void +test_reopen_append (void) +{ + if (!g_test_subprocess ()) { + /* A deadlock would hang the test: run it in a child with a time limit. */ + g_test_trap_subprocess (NULL, 20 * G_USEC_PER_SEC, + G_TEST_SUBPROCESS_INHERIT_STDERR); + g_test_trap_assert_passed (); + return; + } + Lone lone; + Counter c; + counter_init (&c); + lone_setup (&lone, AUDIO_TYPE); + watch (lone.buffer, &c); + + GstBuffer *whole = clip ("audio-aac.mp4"); + g_assert_true (gst_source_buffer_append_buffer (lone.buffer, + gst_buffer_copy_region (whole, GST_BUFFER_COPY_ALL, 0, + gst_buffer_get_size (whole) / 2), NULL)); + g_assert_true (wait_update_ends (&c, 1, 10)); + guint n; + gdouble half = buffered_span (lone.buffer, &n); + GError *error = NULL; + g_assert_true (gst_media_source_end_of_stream (lone.source, + GST_MEDIA_SOURCE_EOS_ERROR_NONE, &error)); + g_assert_no_error (error); + g_assert_cmpint (gst_media_source_get_ready_state (lone.source), ==, + GST_MEDIA_SOURCE_READY_STATE_ENDED); + + g_assert_true (gst_source_buffer_append_buffer (lone.buffer, whole, NULL)); + g_assert_cmpint (gst_media_source_get_ready_state (lone.source), ==, + GST_MEDIA_SOURCE_READY_STATE_OPEN); + g_assert_true (wait_update_ends (&c, 2, 10)); + g_assert_cmpint (c.errors, ==, 0); + /* The rest of the clip is buffered too. */ + gdouble full = buffered_span (lone.buffer, &n); + g_test_message ("buffered after half %.2f s, after reopen %.2f s", half, full); + g_assert_cmpfloat (full, >, half + 1); + + lone_teardown (&lone); + counter_clear (&c); +} + int main (int argc, char **argv) { @@ -475,6 +521,7 @@ main (int argc, char **argv) g_test_add_func ("/mse/no-idle-updates", test_no_idle_updates); g_test_add_func ("/mse/remove", test_remove); g_test_add_func ("/mse/abort-then-append", test_abort_then_append); + g_test_add_func ("/mse/reopen-append", test_reopen_append); g_test_add_func ("/mse/split-audio-video", test_split_audio_video); return g_test_run (); } diff --git a/tests/smoke/pages/mse-spec.html b/tests/smoke/pages/mse-spec.html index cec86aa..155c3b3 100644 --- a/tests/smoke/pages/mse-spec.html +++ b/tests/smoke/pages/mse-spec.html @@ -211,7 +211,9 @@ const cases = { async reopen(v, mp4) { const ms = await open(v); const sb = ms.addSourceBuffer(MP4); - await append(sb, mp4.slice(0, 60000)); + // The first two fragments (ftyp, moov, 2 x moof+mdat end at byte 43652): endOfStream() doesn't reset the + // parser, so a cut inside a box would make the next append continue that box (an append error). + await append(sb, mp4.slice(0, 43652)); ms.endOfStream(); check(ms.readyState === 'ended', 'not ended'); check(throwsName(() => ms.endOfStream()) === 'InvalidStateError', 'endOfStream twice'); diff --git a/vendor/gst-mse/gst-libs/gst/mse/gstsourcebuffer.c b/vendor/gst-mse/gst-libs/gst/mse/gstsourcebuffer.c index 34e0f50..503e8ac 100644 --- a/vendor/gst-mse/gst-libs/gst/mse/gstsourcebuffer.c +++ b/vendor/gst-mse/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); diff --git a/vendor/gst-mse/nacre.patch b/vendor/gst-mse/nacre.patch index 318abf5..fc1dd85 100644 --- a/vendor/gst-mse/nacre.patch +++ b/vendor/gst-mse/nacre.patch @@ -563,3 +563,22 @@ index dc06b01..34e0f50 100644 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);