When using qtdemux in a pipeline that should only work as a pure demuxer (not
for actual playback), qtdemux shouldn't emit new GstSegments to correct
the start time (jump to the future) to ensure that the user experiences no
playback delay. By doing so, it's generating the wrong segments when an append
of data from the past happens. When that happens, downstream elements such as
parsers (eg: aacparse) may clip those buffers laying before the GstSegment and
create problems on the GStreamer client app (eg: WebKit).
Getting buffers clipped out because of the wrong GstSegments started becoming
a problen when this commit was introduced:
ab6e49e9cc audioparsers: add back segment clipping to parsers that have lost it
This clipping makes test DASH shaka 35 from MVT tests[1] to fail in
WebKitGTK/WPE (at least) and can potentially cause a number of other problems
in the WebKit Media Source Extensions (MSE) code.
Note that this new behaviour of not emitting new GstSegments only makes sense
when qtdemux is being used as a pure demuxer and not as part of a regular
pipeline. This is why the variant field has been added. When equal to
VARIANT_MSE_BYTESTREAM, it will make qtdemux behave differently in push mode,
taking decisions that meet the expectations for an MSE-like processing mode.
This kind of tweaks have been done in the past for MSS streams, for instance.
That code has been refactored to use VARIANT_MSS_FRAGMENTED now, instead of
its own dedicated boolean flag.
Co-authored by: Alicia Boya García <ntrrgc@gmail.com>
...who suggested to use "variant: mse-bytestream" in the caps to identify that
mode, as proposed in her unmerged patch:
https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/-/issues/467
[1] https://github.com/rdkcentral/mvt
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3990>
-Subproject commit bc766cb9a23c38bfc68dda05349a40edd5d06937
+Subproject commit 2ec828b7e76cb3240bcc546990e6b3dedceecb40
validate.test.mp4.qtdemux_change_edit_list.default
validate.test.mp4.qtdemux_reverse_playback_full_gop.reverse_playback_full_gop
validate.test.mp4.redirect.play_15s
+validate.test.mse.segment_future_past_mse.segment_future_past_mse
+validate.test.mse.segment_future_past_mse_edit_lists.segment_future_past_mse_edit_lists
+validate.test.mse.segment_future_past_nomse.segment_future_past_nomse
validate.test.nle.urisource.play
validate.test.playbin.check_active_stream
validate.test.playbin3.ignore_raw_audio_from_demuxer
--- /dev/null
+set-globals, media_dir="$(test_dir)/../../../../medias/fragments/mse.1/"
+meta,
+ seek=false,
+ handles-states=false,
+ args = {
+ "appsrc ! video/quicktime, variant=mse-bytestream ! qtdemux ! fakesink async=false",
+ },
+ configs = {
+ "$(validateflow), pad=fakesink0:sink, record-buffers=false, logged-event-types={segment}",
+ }
+
+# Scenario action types
+checkpoint, text="Mse-bytestream variant"
+checkpoint, text="Init segment is now pushed"
+appsrc-push, target-element-name=appsrc0, file-name="$(media_dir)/segment-mse-first-sample-init.mp4"
+checkpoint, text="Data from the future is now pushed"
+appsrc-push, target-element-name=appsrc0, file-name="$(media_dir)/segment-mse-first-sample-media-future.mp4"
+checkpoint, text="Init segment is now pushed"
+appsrc-push, target-element-name=appsrc0, file-name="$(media_dir)/segment-mse-first-sample-init.mp4"
+checkpoint, text="Data from the past is now pushed"
+appsrc-push, target-element-name=appsrc0, file-name="$(media_dir)/segment-mse-first-sample-media-past.mp4"
+stop
--- /dev/null
+
+CHECKPOINT: Mse-bytestream variant
+
+
+CHECKPOINT: Init segment is now pushed
+
+event segment: format=TIME, start=0:00:00.000000000, offset=0:00:00.000000000, stop=none, time=0:00:00.000000000, base=0:00:00.000000000, position=0:00:00.000000000
+
+CHECKPOINT: Data from the future is now pushed
+
+
+CHECKPOINT: Init segment is now pushed
+
+event segment: format=TIME, start=0:00:00.000000000, offset=0:00:00.000000000, stop=none, time=0:00:00.000000000, base=0:00:00.000000000, position=0:00:00.000000000
+
+CHECKPOINT: Data from the past is now pushed
+
--- /dev/null
+set-globals, media_dir="$(test_dir)/../../../../medias/fragments/"
+meta,
+ seek=false,
+ handles-states=false,
+ args = {
+ "appsrc ! video/quicktime, variant=mse-bytestream ! qtdemux ! fakesink async=false",
+ },
+ configs = {
+ "$(validateflow), pad=fakesink0:sink, record-buffers=false, logged-event-types={segment}",
+ }
+
+# Scenario action types
+checkpoint, text="Mse-bytestream variant"
+checkpoint, text="Init segment is now pushed"
+appsrc-push, target-element-name=appsrc0, file-name="$(media_dir)/car-20120827-86.mp4/init.mp4"
+checkpoint, text="Data from the future is now pushed"
+appsrc-push, target-element-name=appsrc0, file-name="$(media_dir)/car-20120827-86.mp4/media2.mp4"
+checkpoint, text="Init segment is now pushed"
+appsrc-push, target-element-name=appsrc0, file-name="$(media_dir)/car-20120827-86.mp4/init.mp4"
+checkpoint, text="Data from the past is now pushed"
+appsrc-push, target-element-name=appsrc0, file-name="$(media_dir)/car-20120827-86.mp4/media1.mp4"
+stop
--- /dev/null
+
+CHECKPOINT: Mse-bytestream variant
+
+
+CHECKPOINT: Init segment is now pushed
+
+event segment: format=TIME, start=0:00:00.041711111, offset=0:00:00.000000000, stop=none, time=0:00:00.000000000, base=0:00:00.000000000, position=0:00:00.041711111
+
+CHECKPOINT: Data from the future is now pushed
+
+
+CHECKPOINT: Init segment is now pushed
+
+event segment: format=TIME, start=0:00:00.041711111, offset=0:00:00.000000000, stop=none, time=0:00:00.000000000, base=0:00:00.000000000, position=0:00:00.041711111
+
+CHECKPOINT: Data from the past is now pushed
+
--- /dev/null
+set-globals, media_dir="$(test_dir)/../../../../medias/fragments/mse.1/"
+meta,
+ seek=false,
+ handles-states=false,
+ args = {
+ "appsrc ! qtdemux ! fakesink async=false",
+ },
+ configs = {
+ "$(validateflow), pad=fakesink0:sink, record-buffers=false, logged-event-types={segment}",
+ }
+
+# Scenario action types
+checkpoint, text="No mse-bytestream variant"
+checkpoint, text="Init segment is now pushed"
+appsrc-push, target-element-name=appsrc0, file-name="$(media_dir)/segment-mse-first-sample-init.mp4"
+checkpoint, text="Data from the future is now pushed"
+appsrc-push, target-element-name=appsrc0, file-name="$(media_dir)/segment-mse-first-sample-media-future.mp4"
+checkpoint, text="Init segment is now pushed"
+appsrc-push, target-element-name=appsrc0, file-name="$(media_dir)/segment-mse-first-sample-init.mp4"
+checkpoint, text="Data from the past is now pushed"
+appsrc-push, target-element-name=appsrc0, file-name="$(media_dir)/segment-mse-first-sample-media-past.mp4"
+stop
--- /dev/null
+
+CHECKPOINT: No mse-bytestream variant
+
+
+CHECKPOINT: Init segment is now pushed
+
+event segment: format=TIME, start=0:00:00.000000000, offset=0:00:00.000000000, stop=none, time=0:00:00.000000000, base=0:00:00.000000000, position=0:00:00.000000000
+
+CHECKPOINT: Data from the future is now pushed
+
+event segment: format=TIME, start=465162:45:48.010666752, offset=0:00:00.000000000, stop=none, time=465162:45:48.010666666, base=0:00:00.000000000, position=465162:45:48.010666752
+
+CHECKPOINT: Init segment is now pushed
+
+event segment: format=TIME, start=465162:45:48.010666752, offset=0:00:00.000000000, stop=none, time=465162:45:48.010666666, base=0:00:00.000000000, position=465162:45:48.010666752
+
+CHECKPOINT: Data from the past is now pushed
+
structure = gst_caps_get_structure (caps, 0);
variant = gst_structure_get_string (structure, "variant");
+ if (variant && strcmp (variant, "mse-bytestream") == 0) {
+ demux->variant = VARIANT_MSE_BYTESTREAM;
+ }
+
if (variant && strcmp (variant, "mss-fragmented") == 0) {
QtDemuxStream *stream;
const GValue *value;
demux->fragmented = TRUE;
- demux->mss_mode = TRUE;
+ demux->variant = VARIANT_MSS_FRAGMENTED;
if (QTDEMUX_N_STREAMS (demux) > 1) {
/* can't do this, we can only renegotiate for another mss format */
}
}
gst_caps_replace (&demux->media_caps, (GstCaps *) mediacaps);
- } else {
- demux->mss_mode = FALSE;
}
return TRUE;
qtdemux->n_meta_streams = 0;
qtdemux->exposed = FALSE;
qtdemux->fragmented = FALSE;
- qtdemux->mss_mode = FALSE;
+ qtdemux->variant = VARIANT_NONE;
gst_caps_replace (&qtdemux->media_caps, NULL);
qtdemux->timescale = 0;
qtdemux->got_moov = FALSE;
g_free (qtdemux->preferred_protection_system_id);
qtdemux->preferred_protection_system_id = NULL;
}
- } else if (qtdemux->mss_mode) {
+ } else if (qtdemux->variant == VARIANT_MSS_FRAGMENTED) {
gst_flow_combiner_reset (qtdemux->flowcombiner);
g_ptr_array_foreach (qtdemux->active_streams,
(GFunc) gst_qtdemux_stream_clear, NULL);
if (stream->track_id == id)
return stream;
}
- if (qtdemux->mss_mode) {
+ if (qtdemux->variant == VARIANT_MSS_FRAGMENTED) {
/* mss should have only 1 stream anyway */
return QTDEMUX_NTH_STREAM (qtdemux, 0);
}
(*stream)->stsd_sample_description_id = sample_description_index - 1;
}
- if (qtdemux->mss_mode) {
+ if (qtdemux->variant == VARIANT_MSS_FRAGMENTED) {
/* mss has no stsd entry */
(*stream)->stsd_sample_description_id = 0;
}
pssh_node = qtdemux_tree_get_sibling_by_type (pssh_node, FOURCC_pssh);
}
- if (!qtdemux->upstream_format_is_time && !qtdemux->first_moof_already_parsed
+ if (!qtdemux->upstream_format_is_time
+ && qtdemux->variant != VARIANT_MSE_BYTESTREAM
+ && !qtdemux->first_moof_already_parsed
&& !qtdemux->received_seek && GST_CLOCK_TIME_IS_VALID (min_dts)
&& min_dts != 0) {
/* Unless the user has explicitly requested another seek, perform an
}
/* in MSS we need to expose the pads after the first moof as we won't get a moov */
- if (demux->mss_mode && !demux->exposed) {
+ if (demux->variant == VARIANT_MSS_FRAGMENTED && !demux->exposed) {
QTDEMUX_EXPOSE_LOCK (demux);
qtdemux_expose_streams (demux);
QTDEMUX_EXPOSE_UNLOCK (demux);
QTDEMUX_STATE_BUFFER_MDAT /* Buffering the mdat atom */
};
+typedef enum {
+ /* Regular behaviour */
+ VARIANT_NONE,
+
+ /* We're working with a MediaSource Extensions ISO BMFF Bytestream. */
+ VARIANT_MSE_BYTESTREAM,
+
+ /* We're working with a smoothstreaming fragment.
+ * Mss doesn't have 'moov' or any information about the streams format,
+ * requiring qtdemux to expose and create the streams */
+ VARIANT_MSS_FRAGMENTED,
+} Variant;
+
struct _GstQTDemux {
GstElement element;
guint32 segment_seqnum;
- /* flag to indicate that we're working with a smoothstreaming fragment
- * Mss doesn't have 'moov' or any information about the streams format,
- * requiring qtdemux to expose and create the streams */
- gboolean mss_mode;
+ Variant variant;
/* Set to TRUE if the incoming stream is either a MSS stream or
* a Fragmented MP4 (containing the [mvex] atom in the header) */