After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 660260 - isomp4: Add support for GstForceKeyUnit events
isomp4: Add support for GstForceKeyUnit events
Status: RESOLVED OBSOLETE
Product: GStreamer
Classification: Platform
Component: gst-plugins-good
git master
Other Linux
: Normal enhancement
: git master
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on: 607742
Blocks: 668091 668094
 
 
Reported: 2011-09-27 16:56 UTC by Andoni Morales
Modified: 2018-11-03 14:44 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
0002-Add-support-for-GstForceKeyUnit-events.patch (9.55 KB, patch)
2011-09-27 16:56 UTC, Andoni Morales
none Details | Review
Fix smooth muxer for live streams (2.64 KB, patch)
2011-11-07 10:46 UTC, Andoni Morales
none Details | Review
Make sure event fragments starts with a key frame (1.31 KB, patch)
2011-11-08 10:43 UTC, Andoni Morales
none Details | Review
Add support for GstForceKeyUnit events (9.81 KB, patch)
2011-12-01 18:07 UTC, Andoni Morales
needs-work Details | Review
Make sure fragments start with a keyframe (1.53 KB, patch)
2011-12-02 10:36 UTC, Andoni Morales
needs-work Details | Review
mp4mux: Add support for GstForceKeyUnit events (15.91 KB, patch)
2013-08-21 15:32 UTC, Andoni Morales
none Details | Review
mp4mux: Add support for GstForceKeyUnit events (15.85 KB, patch)
2013-08-22 13:59 UTC, Andoni Morales
reviewed Details | Review
mp4mux: Add support for GstForceKeyUnit events (15.65 KB, patch)
2013-11-06 09:51 UTC, Andoni Morales
none Details | Review
mp4mux: Add support for GstForceKeyUnit events (15.60 KB, patch)
2013-11-06 09:56 UTC, Andoni Morales
reviewed Details | Review
mp4mux: Add support for GstForceKeyUnit events (16.99 KB, patch)
2013-11-14 00:53 UTC, Andoni Morales
none Details | Review
mp4mux: Add support for GstForceKeyUnit events (15.97 KB, patch)
2013-11-14 01:18 UTC, Andoni Morales
needs-work Details | Review
mp4mux: deprecate the fragment-duration property for regular MP4 (3.44 KB, patch)
2013-11-14 01:18 UTC, Andoni Morales
needs-work Details | Review

Description Andoni Morales 2011-09-27 16:56:37 UTC
Created attachment 197584 [details] [review]
0002-Add-support-for-GstForceKeyUnit-events.patch

The flowing patch adds support for GstForceKeyUnit events to ismlmux.

I have added a new property called 'fragment-method':
 * NONE: do not fragment (default value for muxers that are not the ismlmux)
 * TIME: fragment by time, set in the fragment-duration property (default value for the ismlmux, keeping the old behaviour)
 * EVENT: Uses the GstForceKeyUnit event to generate fragments.

This muxer is different from the other ones (webm or mpegts) in the sense that it can mux several video qualities and the audio track is packed in a separate fragment. So to make it work the audio pad should be receiving GstForceKeyUnits too.

I have tested this patch using Flumotion's smooth streamer[1] with a pipeline similar to:
vsource ! keyunitsscheduler ! tee name=t  ! h264enc ! ismlmux name=mux ! streamer
                                       t. ! h264enc ! mux.
                                       t. ! h264enc ! mux.
asource ! keyunitsscheduler               ! aacenc  ! mux.


This patch relies in the new API for GstForceKeyUnit events

[1] https://code.flumotion.com/cgit/flumotion-fragmented-streaming/
Comment 1 Andoni Morales 2011-11-07 10:46:07 UTC
Created attachment 200872 [details] [review]
Fix smooth muxer for live streams

The muxer rewrites timestamps from 0, so the timestamp check is not valid.
Comment 2 Andoni Morales 2011-11-08 10:43:41 UTC
Created attachment 200971 [details] [review]
Make sure event fragments starts with a key frame

Make sure that fragments for GstForceKeyUnit event starts with a keyframe.
Comment 3 Andoni Morales 2011-12-01 18:07:12 UTC
Created attachment 202539 [details] [review]
Add support for GstForceKeyUnit events

Updated patch that applies with current master
Comment 4 Andoni Morales 2011-12-02 10:36:58 UTC
Created attachment 202582 [details] [review]
Make sure fragments start with a keyframe

And make sure fragments start with a keyframe
Comment 5 Sebastian Dröge (slomo) 2013-07-26 09:49:13 UTC
Review of attachment 202539 [details] [review]:

Generally looks good but:

::: gst/isomp4/gstqtmux.c
@@ +2014,3 @@
+  pad_sync = qtmux->fragment_method != FRAGMENT_METHOD_EVENT && (sync
+      && pad->sync);
+  event_sync = pad->forcekeyunit_event != NULL && pad->sync;

Note that there can be multiple forcekeyunit events (on different pads but also on the same), and that they can also contain a timestamp when this should happen. Also you should probably handle upstream forcekeyunit events too here
Comment 6 Andoni Morales 2013-08-08 16:47:10 UTC
Thanks for the comments, I will work on queuing multiple events
Comment 7 Andoni Morales 2013-08-21 15:32:14 UTC
Created attachment 252611 [details] [review]
mp4mux: Add support for GstForceKeyUnit events
Comment 8 Sebastian Dröge (slomo) 2013-08-21 17:19:15 UTC
Thiago, what do you think?
Comment 9 Andoni Morales 2013-08-21 17:49:25 UTC
It needs just a few small corrections, I am finishing the last tests.
Comment 10 Andoni Morales 2013-08-22 13:59:43 UTC
Created attachment 252750 [details] [review]
mp4mux: Add support for GstForceKeyUnit events
Comment 11 Andoni Morales 2013-08-22 14:04:47 UTC
The muxer has been test in the following scnenario:
x264enc ! qtmux ! dashsink name=sink lamemp3enc ! qtmux ! sink.

Which is, with encoders that forwards back the event downstream, like the video one, and encoders that don't, like the audio one.
This is important because events must be queued both in the src and sinkpads and there is some logic to handle duplicates based in the event "count".
It has also been tested with the sink sending a burst of GstForceKeyUnit events (min-cached-fragments >= 1) at the start to test that queueing is done properly too.
Comment 12 Thiago Sousa Santos 2013-09-26 23:08:49 UTC
Review of attachment 252750 [details] [review]:

Looks good overall, a few questions below.

::: gst/isomp4/gstqtmux.c
@@ +391,1 @@
 

Does this need to be available for all muxers? Isn't it better to register it only for the ones that actually can fragment? I don't think we have any specific properties right now but shouldn't it make sense to have?

@@ +2082,3 @@
 
+    if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT)) {
+      GST_WARNING ("Next fragment will not start with a keyframe");

Does this make sense at all? Shouldn't we wait for a keyframe to start the next fragment?

@@ -3086,0 +3169,42 @@
+static gint
+_sort_fku_events (GstEvent * e1, GstEvent * e2)
+{
... 39 more ...

Took me some time to realize that this function will enqueue on all pads if NULL is passed as the pad. Maybe add a comment about it? Otherwise quickly reading this may look like the loop is kind of useless.

Is this useful somehow? I don't see any code passing NULL as the pad. If it should always enqueue to a pad I'd prefer to have the loop only to search for the correct sinkpad and have the actual enqueueing outside of the loop. What do you think?

@@ +3294,3 @@
+          gst_qt_mux_enqueue_force_key_unit_event (qtmux,
+              gst_event_ref (event), qtpad);
+        }

How does this work exactly? Isn't enqueueing only done for sink pads?
Comment 13 Andoni Morales 2013-09-27 09:08:18 UTC
Review of attachment 252750 [details] [review]:

::: gst/isomp4/gstqtmux.c
@@ +391,1 @@
 

The patch needs to be rebased. This property is now deprecated for regular mp4 muxers.

@@ +2082,3 @@
 
+    if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT)) {
+      GST_WARNING ("Next fragment will not start with a keyframe");

I would leave it there just to make sure that everything is ok, I found it very useful for debugging (maybe make it GST_DEBUG instead of GST_WARNING?)

@@ -3086,0 +3169,42 @@
+static gint
+_sort_fku_events (GstEvent * e1, GstEvent * e2)
+{
... 39 more ...

This code tries to handle the scenario in which the muxer is muxing several tracks (it does not happen in DASH were you have a single track but it's a valid FMP4 use case).
If the event is an upstream FKU (hence commming from the src pad), it enqueues the event in each sink pad, the first pad to reach the fragment limit creates the new fragment and the event is dequeued from the all the pads.
If it's a downstream event its only queued in the corresponding sink pad.
It could probably be documented in a better way :)
Comment 14 Andoni Morales 2013-09-27 09:08:20 UTC
Review of attachment 252750 [details] [review]:

::: gst/isomp4/gstqtmux.c
@@ +391,1 @@
 

The patch needs to be rebased. This property is now deprecated for regular mp4 muxers.

@@ +2082,3 @@
 
+    if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT)) {
+      GST_WARNING ("Next fragment will not start with a keyframe");

I would leave it there just to make sure that everything is ok, I found it very useful for debugging (maybe make it GST_DEBUG instead of GST_WARNING?)

@@ -3086,0 +3169,42 @@
+static gint
+_sort_fku_events (GstEvent * e1, GstEvent * e2)
+{
... 39 more ...

This code tries to handle the scenario in which the muxer is muxing several tracks (it does not happen in DASH were you have a single track but it's a valid FMP4 use case).
If the event is an upstream FKU (hence commming from the src pad), it enqueues the event in each sink pad, the first pad to reach the fragment limit creates the new fragment and the event is dequeued from the all the pads.
If it's a downstream event its only queued in the corresponding sink pad.
It could probably be documented in a better way :)
Comment 15 Andoni Morales 2013-09-27 09:08:20 UTC
Review of attachment 252750 [details] [review]:

::: gst/isomp4/gstqtmux.c
@@ +391,1 @@
 

The patch needs to be rebased. This property is now deprecated for regular mp4 muxers.

@@ +2082,3 @@
 
+    if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT)) {
+      GST_WARNING ("Next fragment will not start with a keyframe");

I would leave it there just to make sure that everything is ok, I found it very useful for debugging (maybe make it GST_DEBUG instead of GST_WARNING?)

@@ -3086,0 +3169,42 @@
+static gint
+_sort_fku_events (GstEvent * e1, GstEvent * e2)
+{
... 39 more ...

This code tries to handle the scenario in which the muxer is muxing several tracks (it does not happen in DASH were you have a single track but it's a valid FMP4 use case).
If the event is an upstream FKU (hence commming from the src pad), it enqueues the event in each sink pad, the first pad to reach the fragment limit creates the new fragment and the event is dequeued from the all the pads.
If it's a downstream event its only queued in the corresponding sink pad.
It could probably be documented in a better way :)
Comment 16 Andoni Morales 2013-09-27 09:08:21 UTC
Review of attachment 252750 [details] [review]:

::: gst/isomp4/gstqtmux.c
@@ +391,1 @@
 

The patch needs to be rebased. This property is now deprecated for regular mp4 muxers.

@@ +2082,3 @@
 
+    if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT)) {
+      GST_WARNING ("Next fragment will not start with a keyframe");

I would leave it there just to make sure that everything is ok, I found it very useful for debugging (maybe make it GST_DEBUG instead of GST_WARNING?)

@@ -3086,0 +3169,42 @@
+static gint
+_sort_fku_events (GstEvent * e1, GstEvent * e2)
+{
... 39 more ...

This code tries to handle the scenario in which the muxer is muxing several tracks (it does not happen in DASH were you have a single track but it's a valid FMP4 use case).
If the event is an upstream FKU (hence commming from the src pad), it enqueues the event in each sink pad, the first pad to reach the fragment limit creates the new fragment and the event is dequeued from the all the pads.
If it's a downstream event its only queued in the corresponding sink pad.
It could probably be documented in a better way :)
Comment 17 Andoni Morales 2013-09-27 09:08:21 UTC
Review of attachment 252750 [details] [review]:

::: gst/isomp4/gstqtmux.c
@@ +391,1 @@
 

The patch needs to be rebased. This property is now deprecated for regular mp4 muxers.

@@ +2082,3 @@
 
+    if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT)) {
+      GST_WARNING ("Next fragment will not start with a keyframe");

I would leave it there just to make sure that everything is ok, I found it very useful for debugging (maybe make it GST_DEBUG instead of GST_WARNING?)

@@ -3086,0 +3169,42 @@
+static gint
+_sort_fku_events (GstEvent * e1, GstEvent * e2)
+{
... 39 more ...

This code tries to handle the scenario in which the muxer is muxing several tracks (it does not happen in DASH were you have a single track but it's a valid FMP4 use case).
If the event is an upstream FKU (hence commming from the src pad), it enqueues the event in each sink pad, the first pad to reach the fragment limit creates the new fragment and the event is dequeued from the all the pads.
If it's a downstream event its only queued in the corresponding sink pad.
It could probably be documented in a better way :)
Comment 18 Andoni Morales 2013-09-27 09:08:22 UTC
Review of attachment 252750 [details] [review]:

::: gst/isomp4/gstqtmux.c
@@ +391,1 @@
 

The patch needs to be rebased. This property is now deprecated for regular mp4 muxers.

@@ +2082,3 @@
 
+    if (GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DELTA_UNIT)) {
+      GST_WARNING ("Next fragment will not start with a keyframe");

I would leave it there just to make sure that everything is ok, I found it very useful for debugging (maybe make it GST_DEBUG instead of GST_WARNING?)

@@ -3086,0 +3169,42 @@
+static gint
+_sort_fku_events (GstEvent * e1, GstEvent * e2)
+{
... 39 more ...

This code tries to handle the scenario in which the muxer is muxing several tracks (it does not happen in DASH were you have a single track but it's a valid FMP4 use case).
If the event is an upstream FKU (hence commming from the src pad), it enqueues the event in each sink pad, the first pad to reach the fragment limit creates the new fragment and the event is dequeued from the all the pads.
If it's a downstream event its only queued in the corresponding sink pad.
It could probably be documented in a better way :)
Comment 19 Andoni Morales 2013-09-27 09:10:33 UTC
What happened??? the review got posted 4 times :(
Comment 20 Thiago Sousa Santos 2013-09-30 19:27:38 UTC
Review of attachment 252750 [details] [review]:

::: gst/isomp4/gstqtmux.c
@@ -3086,0 +3169,42 @@
+static gint
+_sort_fku_events (GstEvent * e1, GstEvent * e2)
+{
... 39 more ...

My point here is that I see that the enqueue done in the srcpad event handler doesn't pass null, but passes the src pad itself. Shouldn't it be passing null, instead?
Comment 21 Andoni Morales 2013-11-06 09:50:07 UTC
Branch finally updated, rebased with master and passing NULL for the source pad (it was already implicitly passing NULL call gst_pad_get_element_private on the src pad). Could you please give a quick review?
Comment 22 Andoni Morales 2013-11-06 09:51:32 UTC
Created attachment 259059 [details] [review]
mp4mux: Add support for GstForceKeyUnit events
Comment 23 Andoni Morales 2013-11-06 09:56:21 UTC
Created attachment 259061 [details] [review]
mp4mux: Add support for GstForceKeyUnit events
Comment 24 Thiago Sousa Santos 2013-11-07 02:33:25 UTC
Review of attachment 259061 [details] [review]:

Patch looks good overall, just a few simple remarks below.

::: gst/isomp4/gstqtmux.c
@@ +385,3 @@
       g_param_spec_uint ("fragment-duration", "Fragment duration",
+          "Fragment durations in ms (used when the fragment-method='time')",
+          0, G_MAXUINT32, 2000,

Use the DEFAULT_FRAGMENT_DURATION here?

@@ +398,3 @@
+          GST_QT_MUX_FORMAT_ISML ? FRAGMENT_METHOD_TIME :
+          DEFAULT_FRAGMENT_METHOD,
+          G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS));

Can't we install properties conditionally so we only get those fragmented options on formats that accept fragmented output?

@@ +2142,3 @@
     }
 
+    gst_qt_mux_dequeue_force_key_unit_event (qtmux, pad);

Why is it always removed? Can't it happen that some scenario other than the event caused the new fragment? Any scenario with a force=True?

Additionally it causes a GST_WARNING when no events are queued, maybe only call if we know there is an event or if the event caused the fragment?
Comment 25 Sebastian Dröge (slomo) 2013-11-11 18:01:07 UTC
Andoni?
Comment 26 Andoni Morales 2013-11-11 18:03:52 UTC
I have the patches ready, but I have to spend all the day in Windows, so I won't have access until later tonight
Comment 27 Andoni Morales 2013-11-14 00:53:52 UTC
Created attachment 259773 [details] [review]
mp4mux: Add support for GstForceKeyUnit events
Comment 28 Andoni Morales 2013-11-14 01:18:05 UTC
Created attachment 259775 [details] [review]
mp4mux: Add support for GstForceKeyUnit events
Comment 29 Andoni Morales 2013-11-14 01:18:52 UTC
Created attachment 259776 [details] [review]
mp4mux: deprecate the fragment-duration property for regular MP4
Comment 30 Andoni Morales 2013-11-14 01:25:38 UTC
I think I have addressed all the issues now:
 * fragment-method property is only installed for fragmented formats
 * fragment-duration is deprecated for the other formats

>Why is it always removed? Can't it happen that some scenario other than the
event caused the new fragment? Any scenario with a force=True?

With FRAGMENT_METHOD_EVENT, it can only happen with force=True, in which case we have been passed a null buffer, which I think only happens in some conditions with the first buffer.
Comment 31 Thiago Sousa Santos 2013-11-14 20:40:18 UTC
Review of attachment 259775 [details] [review]:

Thanks for the updates!
Comment 32 Thiago Sousa Santos 2013-11-14 20:59:50 UTC
Review of attachment 259776 [details] [review]:

Looks good
Comment 33 Sebastian Dröge (slomo) 2014-01-06 09:26:54 UTC
Andoni?
Comment 34 Brendan Long 2014-11-13 23:52:58 UTC
Is this still in progress?
Comment 35 Nicolas Dufresne (ndufresne) 2015-04-02 21:59:24 UTC
These patches won't apply any-more. Please rebase and resubmit.
Comment 36 Andoni Morales 2015-04-04 11:11:28 UTC
I think thiagoss rebased everything here 
https://bugzilla.gnome.org/show_bug.cgi?id=668094
Comment 37 Sebastian Dröge (slomo) 2018-05-04 09:50:04 UTC
What should we do with this? Is anybody going to move it forward or should we just close it?
Comment 38 GStreamer system administrator 2018-11-03 14:44:51 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/gstreamer/gst-plugins-good/issues/50.