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 684790 - isomp4/qtdemux: Whenever a moov atom is found, restart the demuxer
isomp4/qtdemux: Whenever a moov atom is found, restart the demuxer
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-good
git master
Other All
: Normal enhancement
: 1.15.1
Assigned To: GStreamer Maintainers
GStreamer Maintainers
: 782519 (view as bug list)
Depends on:
Blocks: 795993
 
 
Reported: 2012-09-25 15:52 UTC by Jorge Zapata
Modified: 2018-10-04 02:29 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch (3.92 KB, patch)
2013-01-28 10:45 UTC, Jorge Zapata
rejected Details | Review
qtdemux: Re-expose streams per moov box, if needed (6.96 KB, patch)
2016-11-19 09:15 UTC, Seungha Yang
none Details | Review
qtdemux: Unref oldpad using g_slist_free_full() (1.53 KB, patch)
2016-11-20 12:42 UTC, Seungha Yang
none Details | Review
qtdemux: Expose srcpad whenever new stream is found for fragmented stream (3.04 KB, patch)
2016-11-20 12:43 UTC, Seungha Yang
none Details | Review
qtdemux: Expose only activated streams which belong to current moov (4.48 KB, patch)
2016-11-20 12:44 UTC, Seungha Yang
none Details | Review
qtdemux: Parsing trex again with new moov (1019 bytes, patch)
2016-11-20 12:45 UTC, Seungha Yang
none Details | Review
qtdemux: Use GList to manage QtDemuxStream (34.47 KB, patch)
2016-12-23 10:49 UTC, Seungha Yang
none Details | Review
qtdemux: Switch id for managing streams to stream-id (8.33 KB, patch)
2016-12-23 10:51 UTC, Seungha Yang
none Details | Review
qtdemux: Create stream whenever got new moov (4.78 KB, patch)
2016-12-23 10:53 UTC, Seungha Yang
none Details | Review
qtdemux: Try to expose whenever got new moov or new stream-start (12.70 KB, patch)
2016-12-23 10:54 UTC, Seungha Yang
none Details | Review
qtdemux: Switch id for managing streams to stream-id (8.32 KB, patch)
2017-01-01 10:44 UTC, Seungha Yang
none Details | Review
qtdemux: Try to expose whenever got new moov or new (10.26 KB, patch)
2017-01-01 10:49 UTC, Seungha Yang
none Details | Review
qtdemux: Use GList to manage QtDemuxStream (35.04 KB, patch)
2017-04-16 13:45 UTC, Seungha Yang
none Details | Review
qtdemux: Use track-id and upstream-id to manage streams (8.16 KB, patch)
2017-04-16 13:45 UTC, Seungha Yang
none Details | Review
qtdemux: Create stream whenever got new moov (4.88 KB, patch)
2017-04-16 13:46 UTC, Seungha Yang
none Details | Review
qtdemux: Try to expose whenever got new moov or new stream-start (9.78 KB, patch)
2017-04-16 13:47 UTC, Seungha Yang
none Details | Review
tests: qtdemux: Add test for stream change (74.52 KB, patch)
2017-04-16 13:47 UTC, Seungha Yang
none Details | Review
qtdemux: Add parentheses in macro (791 bytes, patch)
2017-04-19 09:55 UTC, Seungha Yang
none Details | Review
qtdemux: Adjust the number of args of some functions (8.55 KB, patch)
2017-04-19 09:55 UTC, Seungha Yang
none Details | Review
qtdemux: Use GList to manage QtDemuxStream (32.72 KB, patch)
2017-04-19 09:56 UTC, Seungha Yang
none Details | Review
qtdemux: Store stream-id to manage streams (5.15 KB, patch)
2017-04-19 09:58 UTC, Seungha Yang
none Details | Review
qtdemux: Create stream whenever got new moov (5.53 KB, patch)
2017-04-19 09:58 UTC, Seungha Yang
none Details | Review
qtdemux: Remove duplication of initializing member variables (3.32 KB, patch)
2017-04-19 09:59 UTC, Seungha Yang
none Details | Review
qtdemux: Try to expose whenever got new moov or new stream-start (12.12 KB, patch)
2017-04-19 09:59 UTC, Seungha Yang
none Details | Review
qtdemux: Create stream whenever got new moov (5.35 KB, patch)
2017-04-19 13:20 UTC, Seungha Yang
none Details | Review
qtdemux: Try to expose whenever got new moov or new stream-start (12.12 KB, patch)
2017-04-19 13:22 UTC, Seungha Yang
none Details | Review
[1/7] qtdemux: Add parentheses in macro (791 bytes, patch)
2017-05-14 04:39 UTC, Seungha Yang
none Details | Review
[2/7] qtdemux: Adjust the number of args of some functions (8.55 KB, patch)
2017-05-14 04:40 UTC, Seungha Yang
none Details | Review
[3/7] qtdemux: Use GList to manage QtDemuxStream (33.04 KB, patch)
2017-05-14 04:40 UTC, Seungha Yang
none Details | Review
[4/7] qtdemux: Store stream-id to manage streams (5.20 KB, patch)
2017-05-14 04:41 UTC, Seungha Yang
none Details | Review
[5/7] qtdemux: Create stream whenever got new moov (5.35 KB, patch)
2017-05-14 04:41 UTC, Seungha Yang
none Details | Review
[6/7] qtdemux: Remove duplication of initializing member variables (3.32 KB, patch)
2017-05-14 04:42 UTC, Seungha Yang
none Details | Review
[7/7] qtdemux: Try to expose whenever got new moov or new stream-start (12.14 KB, patch)
2017-05-14 04:43 UTC, Seungha Yang
none Details | Review
[8/8] qtdemux: Protect _expose_streams() from flush event (4.18 KB, patch)
2017-07-03 07:40 UTC, Seungha Yang
none Details | Review
[1/9] qtdemux: Add parentheses in macro (801 bytes, patch)
2018-05-08 12:18 UTC, Seungha Yang
committed Details | Review
[2/9] qtdemux: Adjust the number of args of some functions (8.49 KB, patch)
2018-05-08 12:18 UTC, Seungha Yang
none Details | Review
[3/9] qtdemux: Use GList to manage QtDemuxStream (36.00 KB, patch)
2018-05-08 12:19 UTC, Seungha Yang
none Details | Review
[4/9] qtdemux: Store stream-id to manage streams (5.14 KB, patch)
2018-05-08 12:19 UTC, Seungha Yang
none Details | Review
[5/9] qtdemux: Create stream whenever got new moov (5.27 KB, patch)
2018-05-08 12:20 UTC, Seungha Yang
committed Details | Review
[6/9] qtdemux: Remove duplication of initializing member variables (3.33 KB, patch)
2018-05-08 12:21 UTC, Seungha Yang
committed Details | Review
[7/9] qtdemux: Try to expose whenever got new moov or new stream-start (12.14 KB, patch)
2018-05-08 12:21 UTC, Seungha Yang
none Details | Review
[8/9] qtdemux: Protect _expose_streams() from flush event (4.20 KB, patch)
2018-05-08 12:22 UTC, Seungha Yang
committed Details | Review
[9/9] tests: qtdemux: Add test for stream change (74.53 KB, patch)
2018-05-08 12:22 UTC, Seungha Yang
committed Details | Review
[10/10] qtdemux: Update pending segment in _expose_streams() only for push mode (1.74 KB, patch)
2018-05-09 10:45 UTC, Seungha Yang
none Details | Review
[2/9] qtdemux: Adjust the number of args of some functions (9.62 KB, patch)
2018-05-09 14:43 UTC, Seungha Yang
committed Details | Review
[3/9] qtdemux: Use GList to manage QtDemuxStream (44.55 KB, patch)
2018-05-09 14:44 UTC, Seungha Yang
committed Details | Review
[4/9] qtdemux: Store stream-id to manage streams (5.34 KB, patch)
2018-05-09 14:50 UTC, Seungha Yang
committed Details | Review
[7/9] qtdemux: Try to expose whenever got new moov or new stream-start (12.33 KB, patch)
2018-05-09 14:54 UTC, Seungha Yang
committed Details | Review

Description Jorge Zapata 2012-09-25 15:52:37 UTC
The attached patch provides a way for the qtdemux element to continue working whenever a MOOV atom is received without going through a state change.

Basically, on MPEG DASH, there are files that are not self-initialized, that is, files that in order to be demuxed at any desired segment they first need to send the initialization segment (the segment containing the MOOV atom). With this patch it is now possible for qtdemux to continue working correctly without the need to go the READY state and then back to the PAUSED/PLAYING.
Comment 1 Arnaud Vrac 2013-01-11 17:25:45 UTC
Hi Jorge, no patch is actually attached ;)
Comment 2 Jorge Zapata 2013-01-28 10:45:54 UTC
Created attachment 234599 [details] [review]
Patch
Comment 3 Sebastian Dröge (slomo) 2013-07-25 12:46:08 UTC
Is this still needed, dash works nowadays. If it is, could you please rebase the patch against latest git?
Comment 4 Seungha Yang 2016-11-18 12:28:51 UTC
(In reply to Sebastian Dröge (slomo) from comment #3)
> Is this still needed, dash works nowadays. If it is, could you please rebase
> the patch against latest git?

We really need this kind of approach for DASH. One of examples, qtdemux does not support track_id change in case of MPEGDASH Representation switching. There is no restriction about track_id change on DASH spec., except for the case that bitstreamSwitching attribute was set true.

For that reason, we cannot support this mpd
http://vm2.dashif.org/livesim-dev/testpic2_2s/Manifest.mpd

Not only that case, other boxes such as trex should be parsed again per moov. Since this report is quite old, can I report new patchset on top of the latest code?
Comment 5 Sebastian Dröge (slomo) 2016-11-18 15:56:43 UTC
Sure
Comment 6 Seungha Yang 2016-11-19 09:15:44 UTC
Created attachment 340289 [details] [review]
qtdemux: Re-expose streams per moov box, if needed

New moov box implies incoming streams might have something differences
from that of a previous moov. So, it makes sense that exposing new srcpads
or removing oldpads, if there are something differences per moov.
Comment 7 Sebastian Dröge (slomo) 2016-11-19 09:50:22 UTC
Thiago, what do you think?

This should probably also come with (conditional) GstStreams usage, like in tsdemux whenever a new program is found.
Comment 8 Seungha Yang 2016-11-19 10:15:35 UTC
(In reply to Sebastian Dröge (slomo) from comment #7)
> Thiago, what do you think?
> 
> This should probably also come with (conditional) GstStreams usage, like in
> tsdemux whenever a new program is found.

That's what I really want to do (GstStream usage in qtdemux and demuxer's own streamcollection object). As we know, playbin3 case, demuxer will be reused unlike playbin2 (decodebin2 makes new demuxer whenever period change).
So, qtdemux may need it's own StreamCollection object and updating it based on new stream-start event.

However, because the use of GstStream may cause lots of structure change, the  want to listen maintainer's opinions on that.
Comment 9 Thiago Sousa Santos 2016-11-19 12:19:27 UTC
Review of attachment 340289 [details] [review]:

Took a quick look, overall code looks fine. Will try to run it later today.

Besides DASH track_Id changes, what other cases would be covered here? What should we do with pull-mode?

Should we also test that it works by sending sequentially 2 independent moov files? Just checking what should we add together with this to validate media tests.

This change looks simple enough that we could do it without GstStreams API (as it should work anyway) and do the porting on a separate patch to make reviewing and spotting regressions easier.

::: gst/isomp4/qtdemux.h
@@ +235,3 @@
+
+  /* Whether demux needs to re-expose or remove srcpads */
+  gboolean need_reconfigure;

Reconfigure has a certain meaning in gstreamer related to the RECONFIGURE event, maybe we want something like "has_new_headers" or "has_new_moov"?
Comment 10 Sebastian Dröge (slomo) 2016-11-19 12:54:54 UTC
(In reply to Thiago Sousa Santos from comment #9)

> This change looks simple enough that we could do it without GstStreams API
> (as it should work anyway)

Yes but with GstStreams we could do like tsdemux and only add/remove streams that have actually changed for example. And properly advertise the available streams without relying on decodebin3 to do that.
Comment 11 Seungha Yang 2016-11-19 13:06:01 UTC
(In reply to Thiago Sousa Santos from comment #9)
> Review of attachment 340289 [details] [review] [review]:
> Besides DASH track_Id changes, what other cases would be covered here? What
> should we do with pull-mode?
I expect this will cover all push-mode fragmented format cases. And pull-mode does not considered. Because ISOBMFF spec is saying that only one moov box is allowed, does it makes sense that multi-moov on pull-mode?

> Should we also test that it works by sending sequentially 2 independent moov
> files? Just checking what should we add together with this to validate media
> tests.
In my opinion, any DASH mpd (multi-Representation, Bitrate switching cases) with playbin3 can be a test case for this, because playbin3 reuses demuxer.

> This change looks simple enough that we could do it without GstStreams API
> (as it should work anyway) and do the porting on a separate patch to make
> reviewing and spotting regressions easier.
I'll split patch :)

> Reconfigure has a certain meaning in gstreamer related to the RECONFIGURE
> event, maybe we want something like "has_new_headers" or "has_new_moov"?
Because my intention for the boolean variable was to indicate "exposing new srcpad or removing any oldpads is needed", but not "new moov", I will consider new naming excluding "reconfigure"
Comment 12 Seungha Yang 2016-11-20 12:42:55 UTC
Created attachment 340348 [details] [review]
qtdemux: Unref oldpad using g_slist_free_full()

From only demux point of view, increased pad refcount by this patch
does not seems to make sense. But if we do not it, it causes crash
somewhere in decodebin.
Comment 13 Seungha Yang 2016-11-20 12:43:38 UTC
Created attachment 340349 [details] [review]
qtdemux: Expose srcpad whenever new stream is found for  fragmented stream

Allow stream addition in the new moov. A new stream can be found
in streaming case such as MPEG-DASH, and there is no reason
to ignore the new stream.
Comment 14 Seungha Yang 2016-11-20 12:44:28 UTC
Created attachment 340350 [details] [review]
qtdemux: Expose only activated streams which belong to  current moov

With updated moov, any streams which belong to previous moov (but not current)
shouldn't be exposed.
Comment 15 Seungha Yang 2016-11-20 12:45:03 UTC
Created attachment 340351 [details] [review]
qtdemux: Parsing trex again with new moov

Trex box has default values for sample fragments, and the defaults
have no dependency on previous moov. So, demux needs to parse it per moov.
Comment 16 Seungha Yang 2016-12-23 08:40:21 UTC
Hello Thiago and slomo
I think my previous solution need to be more generalized. That is, not only for new moov box, but also a stream which following new stream-start event should be handled.
Note that when playbin3 is used, there is no specific processing for stream-start event until now, but streams of before/after stream-start must be differentiated.
Comment 17 Sebastian Dröge (slomo) 2016-12-23 10:02:44 UTC
After stream-start there should be a new moov though, no? But basically after stream-start, the demuxer should consider it as if a completely new stream started now.

Why do you think your previous patches are wrong though?
Comment 18 Seungha Yang 2016-12-23 10:46:28 UTC
(In reply to Sebastian Dröge (slomo) from comment #17)
> Why do you think your previous patches are wrong though?
Not wrong, but seems cannot cover both stream-start/new moov case efficiently...
Comment 19 Seungha Yang 2016-12-23 10:49:21 UTC
Created attachment 342412 [details] [review]
qtdemux: Use GList to manage QtDemuxStream
Comment 20 Seungha Yang 2016-12-23 10:51:26 UTC
Created attachment 342413 [details] [review]
qtdemux: Switch id for managing streams to stream-id

To differentiate streams of after/before new stream-start event,
use stream-id with track-id
Comment 21 Seungha Yang 2016-12-23 10:53:02 UTC
Created attachment 342414 [details] [review]
qtdemux: Create stream whenever got new moov

Whenever demux got moov, create new stream.
Check only whether there is duplicated track-id in current moov.
This patch is pre-work for rework of moov handling.
Comment 22 Seungha Yang 2016-12-23 10:54:09 UTC
Created attachment 342415 [details] [review]
qtdemux: Try to expose whenever got new moov or new stream-start

Whenever got new moov or new stream-start, demux will try to expose new pad by following rule.

Demux compare stream-id in the current moov with previous one, then
* If matched stream-id found, reuse existing pad (most common case)
* Although no matching stream-id, if there is a pad can be reused,
  no need to expose pad, but send new stream-start
  (mostly upstream sent new stream-start)
* Otherwise, expose new pad with new stream-start
Comment 23 Seungha Yang 2016-12-23 10:57:10 UTC
Basic idea is, duplication/existence/new stream check will not be done in _parse_trak() function.

Then, whenever got new moov, call _expose_streams() and decides reuse/expose/remove stream in that function.
Comment 24 Seungha Yang 2017-01-01 10:44:28 UTC
Created attachment 342685 [details] [review]
qtdemux: Switch id for managing streams to stream-id

Fix conflict when applying patch
Comment 25 Seungha Yang 2017-01-01 10:49:27 UTC
Created attachment 342686 [details] [review]
qtdemux: Try to expose whenever got new moov or new

Expose pad whenever new stream-id was found.
Previous patch was trying to reuse srcpad, if downstream can accept the caps although stream-id was not patched. But in some cases, parser element does not forward caps event to downstream when caps was not changed. 
To ensure stream-start -> caps -> segment sequence, I changed for demux to make new pad when new steram-id was found in this patch.
Comment 26 Seungha Yang 2017-04-16 13:45:04 UTC
Created attachment 349904 [details] [review]
qtdemux: Use GList to manage QtDemuxStream
Comment 27 Seungha Yang 2017-04-16 13:45:36 UTC
Created attachment 349905 [details] [review]
qtdemux: Use track-id and upstream-id to manage streams
Comment 28 Seungha Yang 2017-04-16 13:46:14 UTC
Created attachment 349906 [details] [review]
qtdemux: Create stream whenever got new moov
Comment 29 Seungha Yang 2017-04-16 13:47:00 UTC
Created attachment 349907 [details] [review]
qtdemux: Try to expose whenever got new moov or new stream-start
Comment 30 Seungha Yang 2017-04-16 13:47:35 UTC
Created attachment 349908 [details] [review]
tests: qtdemux: Add test for stream change

Add test case to verify track-id change and stream change
Comment 31 Seungha Yang 2017-04-16 14:32:19 UTC
Hello slomo, Thiago and Edward

Could you review this patches after GST1.12 code freeze? 
(it's quite a big change...)

Main concept is "trying to make new stream per moov OR per stream-start"
and compare the new stream with that of previous moov, in order to decide whether re-exposing is required or not.

There seems to no regression on playbin/playbin3 usecase with gst-validate
and manually run some multi-period DASH-IF streams.

Note that, in my environment, following TCs are failed only in playbin3 regardless of my patch
[4 / 270] validate.dash.playback.reverse_playback.dash_exMPD_BIP_TC1: Timeout (Application timed out: 240.0 secs)
[8 / 270] validate.dash.playback.seek_with_stop.dash_exMPD_BIP_TC1: Timeout (Application timed out: 240.0 secs)

However, although my patches are applied, stream change does not work in playbin3 because a bug in decodebin3. It was reported in bug #772230 (nobody review it yet) and the patch in bug #772230 could fix stream change issue in playbin3.

I hope this could fix the bug #781270 also.
Comment 32 Edward Hervey 2017-04-17 08:24:06 UTC
Review of attachment 349904 [details] [review]:

::: gst/isomp4/qtdemux.c
@@ +97,3 @@
 #define QTDEMUX_TREE_NODE_FOURCC(n) (QT_FOURCC(((guint8 *) (n)->data) + 4))
 
+#define STREAM_IS_EOS(s) ((s)->time_position == GST_CLOCK_TIME_NONE)

Put as a separate patch.

@@ +102,3 @@
 
+#define QTDEMUX_NTH_STREAM(demux,i) ((QtDemuxStream *)g_list_nth_data(demux->active_streams,i))
+#define QTDEMUX_N_STREAMS(demux) (g_list_length(demux->active_streams))

This summarizes my main "issue" with this patch.

Using a linked list instead of an array doesn't bring much overhead for qtdemux but:
1) We need to avoid using g_list_nth_data() as much as possible
2) We need to avoid using g_list_length() as much as possible

They are both functions that iterate over all/most of the list.

n_streams => Just use/update the n_streams variable, which you update whenever a stream is added/removed

nth_stream => In virtually all scenarios we are either:
* Using the first entry  (just use it directly)
* Using an index which we calculated in the same function while iterating (just remember the stream entry)

@@ +2093,2 @@
   if (hard) {
+    for (iter = qtdemux->active_streams; iter; iter = next) {

Use g_list_free_full()

@@ +2557,2 @@
 static void
 gst_qtdemux_remove_stream (GstQTDemux * qtdemux, int i)

This could just be modified to be (GstQTDemux *demux, GstQTDemuxStream *stream);

And then you can do active_streams = g_list_remove(active_streams, stream);

@@ +2654,3 @@
     return;
 
+  stream = QTDEMUX_NTH_STREAM (qtdemux, 0);

stream = (GstQTDemuxStream*) qtdemux->active_streams->data;

Or make a macro QTDEMUX_FIRST_STREAM() if you want

@@ +3377,3 @@
   }
 
   /* try to get it fast and simple */

This "optimization" needs to go away if we use a linked list, because we can no longer do direct access.

@@ +5732,2 @@
     GST_DEBUG_OBJECT (qtdemux, "we reached the end of our segment.");
+    QTDEMUX_NTH_STREAM (qtdemux, index)->time_position = GST_CLOCK_TIME_NONE;

Remember the stream in the previous iteration instead of using NTH_STREAM

@@ +6125,3 @@
     return -1;
 
+  stream = QTDEMUX_NTH_STREAM (demux, smallidx);

Store the stream object in the previous iteration.

@@ +11616,2 @@
   /* now we are ready to add the stream */
+  if (QTDEMUX_N_STREAMS (qtdemux) >= GST_QTDEMUX_MAX_STREAMS)

We no longer have this limitation by switching to a linked list :D
Comment 33 Edward Hervey 2017-04-17 08:29:52 UTC
Review of attachment 349905 [details] [review]:

Definitely brings in some much needed improvements
Comment 34 Edward Hervey 2017-04-17 08:30:50 UTC
Review of attachment 349906 [details] [review]:

ok
Comment 35 Edward Hervey 2017-04-17 08:36:10 UTC
Review of attachment 349907 [details] [review]:

::: gst/isomp4/qtdemux.c
@@ +2145,3 @@
           g_list_delete_link (qtdemux->active_streams, iter);
     }
+    for (iter = qtdemux->old_streams; iter; iter = next) {

g_list_free_full()

@@ +11929,3 @@
   GST_DEBUG_OBJECT (qtdemux, "exposing streams");
 
+  /* At below, figure out which stream in active_streams has identical stream-id

You can only re-use streams dynamically within elements that support it (parsebin, decodebin3,...).

You need to check for that to do so. Checkout tsdemux for reference.
Comment 36 Seungha Yang 2017-04-17 09:26:33 UTC
(In reply to Edward Hervey from comment #35)
> Review of attachment 349907 [details] [review] [review]:

> You can only re-use streams dynamically within elements that support it
> (parsebin, decodebin3,...).
> 
> You need to check for that to do so. Checkout tsdemux for reference.

Thanks for detailed review

Can I ask some stupid question? :) 
Roughly, my understanding about your suggestion is
- check GST_BIN_FLAG_STREAMS_AWARE to know whether parent bin can support dynamic stream change.

Then,
if it's supported (playbin3 case), re-use reusable streams and expose/remove only necessary streams.
otherwise (playbin case), expose all new streams and remove all the previous streams with no-more-pads signal

Is it correct understanding?
Comment 37 Edward Hervey 2017-04-17 11:29:31 UTC
(In reply to Seungha Yang from comment #36)
> Can I ask some stupid question? :) 
> Roughly, my understanding about your suggestion is
> - check GST_BIN_FLAG_STREAMS_AWARE to know whether parent bin can support
> dynamic stream change.
> 
> Then,
> if it's supported (playbin3 case), re-use reusable streams and expose/remove
> only necessary streams.
> otherwise (playbin case), expose all new streams and remove all the previous
> streams with no-more-pads signal
> 
> Is it correct understanding?

It's not a stupid question, and yes, this is what I meant :)
Comment 38 Seungha Yang 2017-04-19 09:55:03 UTC
Created attachment 350051 [details] [review]
qtdemux: Add parentheses in macro
Comment 39 Seungha Yang 2017-04-19 09:55:34 UTC
Created attachment 350052 [details] [review]
qtdemux: Adjust the number of args of some functions

To be used with g_list_free_full in the next patch
Comment 40 Seungha Yang 2017-04-19 09:56:05 UTC
Created attachment 350053 [details] [review]
qtdemux: Use GList to manage QtDemuxStream

Move to GList from static array
Comment 41 Seungha Yang 2017-04-19 09:58:05 UTC
Created attachment 350054 [details] [review]
qtdemux: Store stream-id to manage streams

In order to figure out stream change such as track-id change or stream-id change,
demux will store stream-id per QtDemuxStream structure.
Comment 42 Seungha Yang 2017-04-19 09:58:35 UTC
Created attachment 350055 [details] [review]
qtdemux: Create stream whenever got new moov

Whenever demux got moov, demux will create new stream. Only exception is
duplicated track-id in a moov box. In that case the first stream
will be accepted. This patch is pre-work for rework of moov handling.
Comment 43 Seungha Yang 2017-04-19 09:59:03 UTC
Created attachment 350056 [details] [review]
qtdemux: Remove duplication of initializing member variables

Most initialization of variables in gst_qtdemux_init() are duplicated in
gst_qtdemux_reset() function.
Comment 44 Seungha Yang 2017-04-19 09:59:41 UTC
Created attachment 350057 [details] [review]
qtdemux: Try to expose whenever got new moov or new stream-start
Comment 45 Edward Hervey 2017-04-19 13:05:57 UTC
Review of attachment 350055 [details] [review]:

::: gst/isomp4/qtdemux.c
@@ +9601,3 @@
+  stream2 = QTDEMUX_STREAM (id2);
+
+  if (stream1->track_id > stream2->track_id) {

Or you could just make the function

_func(QtDemuxStream *stream1, QtDemuxStream *stream2) {
  return stream1->track_id - stream2->track_id;
}

:)
Comment 46 Edward Hervey 2017-04-19 13:11:03 UTC
Review of attachment 350057 [details] [review]:

::: gst/isomp4/qtdemux.c
@@ +11900,3 @@
+
+static gboolean
+qtdemux_reuse_and_configure_steram (GstQTDemux * qtdemux,

s/steram/stream/
Comment 47 Seungha Yang 2017-04-19 13:20:29 UTC
Created attachment 350068 [details] [review]
qtdemux: Create stream whenever got new moov
Comment 48 Seungha Yang 2017-04-19 13:22:26 UTC
Created attachment 350069 [details] [review]
qtdemux: Try to expose whenever got new moov or new stream-start
Comment 49 Seungha Yang 2017-04-19 13:23:09 UTC
(In reply to Edward Hervey from comment #46)
> Review of attachment 350057 [details] [review] [review]:

I'm always thankful for your review :D
Comment 50 Edward Hervey 2017-04-20 04:57:23 UTC
Overall the patches are really good at this point. Let's see if we can get them merged after 1.12 is released.

Thanks !
Comment 51 Seungha Yang 2017-04-20 05:25:08 UTC
(In reply to Edward Hervey from comment #50)
> Overall the patches are really good at this point. Let's see if we can get
> them merged after 1.12 is released.
> 
> Thanks !

Wow!! Thanks for review
Comment 52 Sebastian Dröge (slomo) 2017-05-11 15:29:21 UTC
*** Bug 782519 has been marked as a duplicate of this bug. ***
Comment 53 Edward Hervey 2017-05-13 07:07:55 UTC
Hi Seungha, could you rebase the patches against current master ? Thanks
Comment 54 Seungha Yang 2017-05-14 04:39:17 UTC
Created attachment 351800 [details] [review]
[1/7] qtdemux: Add parentheses in macro
Comment 55 Seungha Yang 2017-05-14 04:40:06 UTC
Created attachment 351801 [details] [review]
[2/7] qtdemux: Adjust the number of args of some functions
Comment 56 Seungha Yang 2017-05-14 04:40:40 UTC
Created attachment 351802 [details] [review]
[3/7] qtdemux: Use GList to manage QtDemuxStream
Comment 57 Seungha Yang 2017-05-14 04:41:28 UTC
Created attachment 351803 [details] [review]
[4/7] qtdemux: Store stream-id to manage streams
Comment 58 Seungha Yang 2017-05-14 04:41:57 UTC
Created attachment 351804 [details] [review]
[5/7] qtdemux: Create stream whenever got new moov
Comment 59 Seungha Yang 2017-05-14 04:42:27 UTC
Created attachment 351805 [details] [review]
[6/7] qtdemux: Remove duplication of initializing member variables
Comment 60 Seungha Yang 2017-05-14 04:43:01 UTC
Created attachment 351806 [details] [review]
[7/7] qtdemux: Try to expose whenever got new moov or new stream-start
Comment 61 Seungha Yang 2017-07-03 07:40:51 UTC
Created attachment 354819 [details] [review]
[8/8] qtdemux: Protect _expose_streams() from flush event

Flush during stream change can break autoplugging or the
flush event could be dropped.
Comment 62 Sebastian Dröge (slomo) 2018-05-07 15:39:32 UTC
Edward, you merge them?
Comment 63 Edward Hervey 2018-05-07 15:42:41 UTC
They don't apply cleanly, so the patches need to be rebased (again)
Comment 64 Seungha Yang 2018-05-08 11:47:14 UTC
(In reply to Edward Hervey from comment #63)
> They don't apply cleanly, so the patches need to be rebased (again)

I'll update rebased patches after regression test (using gst-validate)
Comment 65 Seungha Yang 2018-05-08 12:18:10 UTC
Created attachment 371793 [details] [review]
[1/9] qtdemux: Add parentheses in macro
Comment 66 Seungha Yang 2018-05-08 12:18:41 UTC
Created attachment 371794 [details] [review]
[2/9] qtdemux: Adjust the number of args of some functions
Comment 67 Seungha Yang 2018-05-08 12:19:13 UTC
Created attachment 371795 [details] [review]
[3/9] qtdemux: Use GList to manage QtDemuxStream
Comment 68 Seungha Yang 2018-05-08 12:19:52 UTC
Created attachment 371796 [details] [review]
[4/9] qtdemux: Store stream-id to manage streams
Comment 69 Seungha Yang 2018-05-08 12:20:23 UTC
Created attachment 371797 [details] [review]
[5/9] qtdemux: Create stream whenever got new moov
Comment 70 Seungha Yang 2018-05-08 12:21:01 UTC
Created attachment 371798 [details] [review]
[6/9] qtdemux: Remove duplication of initializing member variables
Comment 71 Seungha Yang 2018-05-08 12:21:48 UTC
Created attachment 371799 [details] [review]
[7/9] qtdemux: Try to expose whenever got new moov or new stream-start
Comment 72 Seungha Yang 2018-05-08 12:22:19 UTC
Created attachment 371800 [details] [review]
[8/9] qtdemux: Protect _expose_streams() from flush event
Comment 73 Seungha Yang 2018-05-08 12:22:55 UTC
Created attachment 371801 [details] [review]
[9/9] tests: qtdemux: Add test for stream change
Comment 74 Seungha Yang 2018-05-08 12:24:08 UTC
I could not find any regression on qtdemux with my patch set (using gst-validate-launch for playbin and playbin3)
Comment 75 Edward Hervey 2018-05-09 07:33:06 UTC
Thanks for that ! Can you also check why the qtmux unit test is failing ? Seems to be caused by those patches. Once that is cleared, I'll push them
Comment 76 Seungha Yang 2018-05-09 10:45:08 UTC
Created attachment 371834 [details] [review]
[10/10] qtdemux: Update pending segment in _expose_streams() only for push mode

New segment will be made in loop function in case of pull mode.
So, if it was set in _expose_streams(), duplicated segment events
can be pushed which cause qtmux unit test failure
Comment 77 Seungha Yang 2018-05-09 10:47:07 UTC
(In reply to Edward Hervey from comment #75)
> Thanks for that ! Can you also check why the qtmux unit test is failing ?
> Seems to be caused by those patches. Once that is cleared, I'll push them

I updated new patch to fix qtmux unit test failure.
Comment 78 Edward Hervey 2018-05-09 11:40:02 UTC
Review of attachment 371794 [details] [review]:

::: gst/isomp4/qtdemux.c
@@ +2573,3 @@
   gst_tag_list_unref (stream->stream_tags);
   if (stream->pad) {
+    GstElement *qtdemux = gst_pad_get_parent_element (stream->pad);

This is inefficient. Just store the qtdemux object in a stream field.

@@ +2575,3 @@
+    GstElement *qtdemux = gst_pad_get_parent_element (stream->pad);
+
+    if (G_UNLIKELY (!qtdemux)) {

This should never happen (and will go away once you store it in the stream)
Comment 79 Edward Hervey 2018-05-09 11:56:14 UTC
Review of attachment 371795 [details] [review]:

::: gst/isomp4/qtdemux.c
@@ +2145,3 @@
     gst_flow_combiner_reset (qtdemux->flowcombiner);
+    for (iter = qtdemux->active_streams; iter; iter = g_list_next (iter)) {
+      gst_qtdemux_stream_clear (QTDEMUX_STREAM (iter->data));

or just g_list_foreach() ?

@@ +2692,3 @@
     return;
 
+  stream = QTDEMUX_FIRST_STREAM (qtdemux);

It would be cleaner if you moved the check before (the n_streams one) to just under with "if (!stream) return;"

@@ +5897,2 @@
   guint size;
   gint index;

Shouldn't stream->track_id be used instead of index in this function and others ? That seems more consistent than a list index where the list/order might potentially change.

@@ +6292,2 @@
   int i;
   int smallidx = -1;

Same comment as before
Comment 80 Edward Hervey 2018-05-09 11:58:50 UTC
Review of attachment 371796 [details] [review]:

::: gst/isomp4/qtdemux.c
@@ +1935,3 @@
 }
 
+/* Copied from mpegtsbase code */

This should no longer be needed now that we have the gst_pad_create_stream_id functions in core.
Comment 81 Edward Hervey 2018-05-09 12:23:12 UTC
Apart from the comments above, this looks good.

Do you think there are any urls from the dashif forum we could add to the "adaptive" gst-validate testsuite ?
Comment 82 Seungha Yang 2018-05-09 12:59:22 UTC
(In reply to Edward Hervey from comment #81)
> Apart from the comments above, this looks good.
I'll update patch again. Thanks for your review :)
 
> Do you think there are any urls from the dashif forum we could add to the
> "adaptive" gst-validate testsuite ?

This url is one of issue streams and this patch set could solve it. (different track-id per representation). I hope the stream will be added to test case.
http://vm2.dashif.org/livesim-dev/testpic2_2s/Manifest.mpd 

Another suggestion is a "multi audio track" dash stream.
http://dash.akamaized.net/dash264/TestCases/10a/1/iis_forest_short_poem_multi_lang_480p_single_adapt_aaclc_sidx.mpd
Comment 83 Seungha Yang 2018-05-09 14:19:15 UTC
(In reply to Edward Hervey from comment #80)
> Review of attachment 371796 [details] [review] [review]:
> 
> ::: gst/isomp4/qtdemux.c
> @@ +1935,3 @@
>  }
>  
> +/* Copied from mpegtsbase code */
> 
> This should no longer be needed now that we have the
> gst_pad_create_stream_id functions in core.

gst_pad_create_stream_id() function seems to be usable only if we have src pad. But I'd like to create stream_id before srcpad is created. (same as mpegtsbase usecase)

Is there new util function for that? Note that mpegtsbase's _get_upstream_id() still exist.
Comment 84 Edward Hervey 2018-05-09 14:31:29 UTC
(In reply to Seungha Yang from comment #83)
> gst_pad_create_stream_id() function seems to be usable only if we have src
> pad. But I'd like to create stream_id before srcpad is created. (same as
> mpegtsbase usecase)
> 
> Is there new util function for that? Note that mpegtsbase's
> _get_upstream_id() still exist.

 Ah, that explains why you weren't using that function (not having the pad). But it's a bit stupid because the only thing the function uses the pad for is ... for the debugging message :) We should maybe have a function that allows creating such stream_id at the element level have the pad use that.
Comment 85 Edward Hervey 2018-05-09 14:39:08 UTC
>  Ah, that explains why you weren't using that function (not having the pad).
> But it's a bit stupid because the only thing the function uses the pad for
> is ... for the debugging message :) We should maybe have a function that
> allows creating such stream_id at the element level have the pad use that.

Create bug #795976 to track that issue.
Comment 86 Seungha Yang 2018-05-09 14:41:44 UTC
(In reply to Edward Hervey from comment #84)
> (In reply to Seungha Yang from comment #83)

Fully agree :)
Comment 87 Seungha Yang 2018-05-09 14:43:15 UTC
Created attachment 371848 [details] [review]
[2/9] qtdemux: Adjust the number of args of some functions
Comment 88 Seungha Yang 2018-05-09 14:44:35 UTC
Created attachment 371849 [details] [review]
[3/9] qtdemux: Use GList to manage QtDemuxStream

* Move to GList from static array
* Logging track-id instead of array index. It's more meaningful.
Comment 89 Seungha Yang 2018-05-09 14:50:09 UTC
Created attachment 371851 [details] [review]
[4/9] qtdemux: Store stream-id to manage streams

Just rebase commit with FIXME comment.
Comment 90 Seungha Yang 2018-05-09 14:54:23 UTC
Created attachment 371852 [details] [review]
[7/9] qtdemux: Try to expose whenever got new moov or new stream-start

the patch for qtmux unit test is merged into this
Comment 91 Edward Hervey 2018-05-10 07:20:21 UTC
And finally in \o/ Thanks !
Comment 92 Sebastian Dröge (slomo) 2018-05-10 07:26:12 UTC
(In reply to Seungha Yang from comment #88)
> Created attachment 371849 [details] [review] [review]
> [3/9] qtdemux: Use GList to manage QtDemuxStream
> 
> * Move to GList from static array
> * Logging track-id instead of array index. It's more meaningful.

Why a GList instead of a GArray or GPtrArray? Unless you need to remove/insert elements in the middle/beginning, the latter is usually more efficient in all regards.
Comment 93 Seungha Yang 2018-05-10 08:04:52 UTC
(In reply to Sebastian Dröge (slomo) from comment #92)
> (In reply to Seungha Yang from comment #88)
> > Created attachment 371849 [details] [review] [review] [review]
> > [3/9] qtdemux: Use GList to manage QtDemuxStream
> > 
> > * Move to GList from static array
> > * Logging track-id instead of array index. It's more meaningful.
> 
> Why a GList instead of a GArray or GPtrArray? Unless you need to
> remove/insert elements in the middle/beginning, the latter is usually more
> efficient in all regards.

Actually qtdemux might need remove any streams in the middle or beginning.
https://cgit.freedesktop.org/gstreamer/gst-plugins-good/tree/gst/isomp4/qtdemux.c#n12197

 I thought that streams in a mp4 file is not bulky and therefore 
GList will not bring much overhead over GPtrArray. If we'd like to change to GPtrArray, I think it's not difficult though.
Comment 94 Nicolas Dufresne (ndufresne) 2018-10-03 16:40:56 UTC
Can someone who worked on this can look at this crash -> https://bugzilla.gnome.org/show_bug.cgi?id=797239

We have a strong impression this is caused by work done for this issue.
Comment 95 Seungha Yang 2018-10-04 02:29:55 UTC
(In reply to Nicolas Dufresne (ndufresne) from comment #94)
> Can someone who worked on this can look at this crash ->
> https://bugzilla.gnome.org/show_bug.cgi?id=797239
> 
> We have a strong impression this is caused by work done for this issue.

I uploaded a patch in bug #797239. When I was working on this bug, MSS usecase was not fully tested, sorry :(