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 657343 - [patch] small changes to mpegtsmux
[patch] small changes to mpegtsmux
Status: RESOLVED OBSOLETE
Product: GStreamer
Classification: Platform
Component: gst-plugins-bad
git master
Other Linux
: Normal enhancement
: git master
Assigned To: GStreamer Maintainers
GStreamer Maintainers
: 506902 (view as bug list)
Depends on:
Blocks: 661163
 
 
Reported: 2011-08-25 15:45 UTC by Stas Sergeev
Modified: 2018-11-03 13:08 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
PES supporting plugins (154.91 KB, patch)
2011-08-25 15:45 UTC, Stas Sergeev
none Details | Review
do not use same arg for input and output (3.43 KB, patch)
2011-08-26 12:03 UTC, Stas Sergeev
rejected Details | Review
patch [2/4] (44.50 KB, patch)
2011-08-26 12:03 UTC, Stas Sergeev
none Details | Review
tsmux: delimit max size of pes packets (3.99 KB, patch)
2011-08-26 12:03 UTC, Stas Sergeev
none Details | Review
patch [4/4] (23.93 KB, patch)
2011-08-26 12:04 UTC, Stas Sergeev
none Details | Review
patch [2/4] (53.17 KB, patch)
2011-08-26 18:36 UTC, Stas Sergeev
none Details | Review
patch [2/4] (54.34 KB, patch)
2011-08-26 21:50 UTC, Stas Sergeev
none Details | Review
fix pes startcodes in gstmpegdefs.h (4.77 KB, patch)
2011-08-31 17:00 UTC, Stas Sergeev
rejected Details | Review
fix parsing pes extension field (2.00 KB, patch)
2011-09-15 15:17 UTC, Stas Sergeev
needs-work Details | Review
tsmux: use sequential stream ids for pes (1.66 KB, patch)
2011-10-05 17:07 UTC, Stas Sergeev
none Details | Review
[mpegtsmux] allow re-using prepare funcs from other plugins (12.03 KB, patch)
2011-10-10 17:02 UTC, Stas Sergeev
none Details | Review
fix parsing pes extension field (2.40 KB, patch)
2013-01-03 17:50 UTC, Stas Sergeev
none Details | Review
fix parsing pes extension field (2.36 KB, patch)
2013-01-03 18:02 UTC, Stas Sergeev
rejected Details | Review

Description Stas Sergeev 2011-08-25 15:45:19 UTC
Created attachment 194709 [details] [review]
PES supporting plugins

Hi.

I'd like to present the PES support plugins: payloader, depayloader and parser.
The work is just started, I am going to do more things about the
PES support in gstreamer, but these 3 plugins already seem to work,
so the comments are welcome. :)
Comment 1 Sebastian Dröge (slomo) 2011-08-25 15:54:08 UTC
I didn't look closely yet but you're reusing a lot of code from the mpeg ts demuxer. Would it be possible to put the plugin into the mpeg ts demuxer plugin and share the code instead of copying it?
Comment 2 Sebastian Dröge (slomo) 2011-08-25 15:55:14 UTC
*** Bug 506902 has been marked as a duplicate of this bug. ***
Comment 3 Stas Sergeev 2011-08-25 16:02:30 UTC
That would be nice in general, but there are a few problems:
1. Small changes here and there will have to be merged and accepted
by the maintainer. Since I am a newcomer here, I have no idea how
difficult is that.
2. I am reusing the code from two plugins: mpegtsmux(fluendo) and
mpegtsdemux(Edward Hervey), so it is not possible to move them
into a single place and avoid duplication.

Is there any place for the common code shared between several plugins?
Comment 4 Stas Sergeev 2011-08-25 16:30:40 UTC
I guess there is an option to move the depayloader and
parser to demux, and payloader - to muxer, as that's the
way the code was reused.
I'll take a look into that possibility.
Comment 5 Sebastian Dröge (slomo) 2011-08-26 08:12:48 UTC
The best would probably be to have all code in the new mpegts demuxer plugin, I think most of the PES related changes will apply to the ts demuxer too.
Comment 6 Stas Sergeev 2011-08-26 08:30:22 UTC
That will mean still the duplication of the mpegtsmux code though.
But I'll go that way because I wanted to keep all the PES plugins
in a single place.
Will post the patch soon.
Comment 7 Sebastian Dröge (slomo) 2011-08-26 08:36:39 UTC
Oh sorry, ignore what I said. Putting the parser and depayloader into the tsdemux plugin and the payloader into the tsmux plugin absolutely makes sense
Comment 8 Stas Sergeev 2011-08-26 12:03:08 UTC
Created attachment 194815 [details] [review]
do not use same arg for input and output
Comment 9 Stas Sergeev 2011-08-26 12:03:30 UTC
Created attachment 194816 [details] [review]
patch [2/4]
Comment 10 Stas Sergeev 2011-08-26 12:03:46 UTC
Created attachment 194817 [details] [review]
tsmux: delimit max size of pes packets
Comment 11 Stas Sergeev 2011-08-26 12:04:06 UTC
Created attachment 194818 [details] [review]
patch [4/4]
Comment 12 Stas Sergeev 2011-08-26 12:04:40 UTC
Done, please take a look.
Comment 13 Stas Sergeev 2011-08-26 18:36:52 UTC
Created attachment 194875 [details] [review]
patch [2/4]

depayloader v2
Comment 14 Stas Sergeev 2011-08-26 21:50:07 UTC
Created attachment 194887 [details] [review]
patch [2/4]
Comment 15 Stas Sergeev 2011-08-31 17:00:22 UTC
Created attachment 195325 [details] [review]
fix pes startcodes in gstmpegdefs.h

The pesparse.c has this code line:
 res->stream_id = val32 & 0x000000ff;
but gstmpegdefs.h defines stream IDs and start codes
with the 16th bit set. This probably came from the
fluendo demuxer code, which reads start code as a full
(not masked) 32bit value.
Currently, these defines are not used in mpegtsdemux code,
so the fix is needed only for the further development of
the PES parser.
Comment 16 Stas Sergeev 2011-09-15 15:17:01 UTC
Created attachment 196643 [details] [review]
fix parsing pes extension field

It seems there is some confusion in the pesparser code of
tsdemux plugin... I don't know what this part was supposed
to do at all:
---
      flags = *data++;
      /* Only valid if stream_id_extension_flag == 0x0 */
      if (!(flags & 0x80)) {
        res->stream_id_extension = flags & 0x7f;
---
If bit 7 is not set (!(flags & 0x80)), there is no use of
doing flags & 0x7f on the next line, is it?
Moreover, I failed to track that to the description of the
pes header format, and in fact mpegtsmux can write different
values there: 0x60, 0x71, 0x80 and 0x82 to specify the media
type, so the 0x7f mask cannot be applied.
So the code looks totally wrong and misplaced, probably a
copy/paste bug.
the attached patch removes the code in question, allowing my
plugin to get the media type.

I am removing the plugins implementation for now: will re-upload
when they are finished. Let's see if at least the fixes can be
processed and applied to that date.
Comment 17 Edward Hervey 2011-09-19 08:31:36 UTC
Review of attachment 196643 [details] [review]:

::: gst/mpegtsdemux/pesparse.c
@@ +337,2 @@
     if (res->extension_field_length) {
+      res->stream_id_extension_data = data;

There seems to be something missing here.

The original code does:
* read and advance data by 1 byte
* advance data by res->extension_field_length

Your code does:
* read data byte
* advance data by res->extension_field_length
Comment 18 Edward Hervey 2011-09-19 08:33:17 UTC
Review of attachment 195325 [details] [review]:

Seems acceptable. I'm even wondering if we shouldn't just convert those values to 8 bit values if we're only going to be using the lower eight bits.
Comment 19 Stas Sergeev 2011-09-19 10:12:31 UTC
Based on comment 18, should I disregard comment 17?
If not - please clarify what I need to do. :)
You marked the patch as needs-work, so the question.
(yes, the original code was reading an extra byte)
Comment 20 Stas Sergeev 2011-10-05 17:07:23 UTC
Created attachment 198356 [details] [review]
tsmux: use sequential stream ids for pes

There is a /* FIXME: Assign sequential IDs? */ in code.
This patch does exactly that.
Comment 21 Stas Sergeev 2011-10-10 17:02:23 UTC
Created attachment 198725 [details] [review]
[mpegtsmux] allow re-using prepare funcs from other plugins

This patch allows to re-use mpegtsmux_prepare_aac() and
mpegtsmux_prepare_h264() from other plugins, like mpegpespay.
Comment 22 Stas Sergeev 2013-01-03 17:41:10 UTC
(In reply to comment #17)
> Review of attachment 196643 [details] [review]:
Sorry, I haven't answered this one because of some
confusion with another comment...

> ::: gst/mpegtsdemux/pesparse.c
> @@ +337,2 @@
>      if (res->extension_field_length) {
> +      res->stream_id_extension_data = data;
> 
> There seems to be something missing here.
> 
> The original code does:
> * read and advance data by 1 byte
> * advance data by res->extension_field_length
Yes.

> Your code does:
> * read data byte
The extension_data[0] byte.

> * advance data by res->extension_field_length
Yes, because the res->extension_field_length==1 usually.
And if it is >1, then this code is still correct: all it
does is to bypass the extension_data bytes. The byte we
read above, is just the extension_data[0] byte, so it doesn't
require an extra increment. We read first byte of an array
and then skip the entire array, so that is fine.

But I can see the line:
---
     length -= res->extension_field_length + 1;
---
which would need to remove +1 then...
I'll upload the patch with this fixed.
Comment 23 Stas Sergeev 2013-01-03 17:50:07 UTC
Created attachment 232654 [details] [review]
fix parsing pes extension field

Hopefully a better version of the patch.
Comment 24 Stas Sergeev 2013-01-03 18:00:17 UTC
(In reply to comment #22)
> > Your code does:
> > * read data byte
> The extension_data[0] byte.
Grr, wrong! I've forgot that code entirely.
It doesn't read the byte:
---
res->stream_id_extension_data = data;
---
it just puts a pointer to extenstion_data into
res->stream_id_extension_data.
So now I added a wrong comment into a patch, will re-upload again...
Comment 25 Stas Sergeev 2013-01-03 18:02:50 UTC
Created attachment 232657 [details] [review]
fix parsing pes extension field
Comment 26 Edward Hervey 2013-06-12 06:45:39 UTC
With the new 1.0, I think we should handle PES in a different way (i.e. not a new caps type).

We should have a well-know GstMeta for PES (GstPESMeta ?) which:
* includes parsed header structure
* points to actual PES header data in the underlying GstBuffer GstMemory

The memory of the buffers created by PES-aware elements should:
* Contain all the data (including PES header)
* have the offset point to the actual data (i.e. memory offset == size(PES header).

This would:
* allow non-pes aware elements to still work as expected (no special path)
* pes-aware elements to make usage of the PES information
Comment 27 Sebastian Dröge (slomo) 2013-06-12 07:18:35 UTC
Then we would still need a "pesparse" element that can create such buffers, otherwise sounds like a good idea :)
Comment 28 Stas Sergeev 2013-06-12 07:59:16 UTC
But the small fixes that are sitting here
for 2 years already, have nothing to do with
the way you are going to handle PESes.
So why not to apply them?
Comment 29 Tim-Philipp Müller 2013-06-12 09:00:14 UTC
If they have nothing to do with adding PES support, they should probably go into another bug :-)
Comment 30 Stas Sergeev 2013-06-12 09:21:22 UTC
That's what was done: the PES-supporting
patch went to 661163 from here, and I left only the
"unrelated" fixes here.
Comment 31 Stas Sergeev 2013-06-12 10:30:14 UTC
(In reply to comment #29)
> If they have nothing to do with adding PES support, they should probably go
> into another bug :-)
Done: entry renamed.
Comment 32 Edward Hervey 2013-08-14 08:28:53 UTC
Comment on attachment 195325 [details] [review]
fix pes startcodes in gstmpegdefs.h

we no longer have those ids.
Comment 33 Edward Hervey 2013-08-14 08:36:18 UTC
Comment on attachment 194815 [details] [review]
do not use same arg for input and output

Thanks for pointing this out. I ended up pushing a variant which just completely removes the offset argument (we always used it with offset == 0)

commit 5208b8a05074ebdb0da835c29b95f8eb6001cb0e
Author: Edward Hervey <edward@collabora.com>
Date:   Wed Aug 14 10:33:14 2013 +0200

    pesparse: Remove unused argument
    
    We always provided 0 as the offset and never used the returned value.
    
    Based on feedback from Stas Sergeev <stsp@list.ru>
    
    https://bugzilla.gnome.org/show_bug.cgi?id=657343
Comment 34 Edward Hervey 2013-08-14 08:43:13 UTC
Comment on attachment 232657 [details] [review]
fix parsing pes extension field

We actually want to keep the extension data around.

I did take into account the length check fix in this commit:

commit ddee83ef0bc13ce888a890f29650454e2c7ec496
Author: Edward Hervey <edward@collabora.com>
Date:   Wed Aug 14 10:39:46 2013 +0200

    pesparse: Fix pes extension data length check
    
    And remove length/data updates (we use the header size just below to
    properly set them).
    
    Based on feedback from Stas Sergeev <stsp@list.ru>
    
    https://bugzilla.gnome.org/show_bug.cgi?id=657343
Comment 35 Edward Hervey 2013-08-14 08:43:43 UTC
Only mpegtsmux patches remain.
Comment 36 Stas Sergeev 2013-08-14 08:57:31 UTC
(In reply to comment #34)
> (From update of attachment 232657 [details] [review])
> We actually want to keep the extension data around.
I don't understand.
My patch also kept the data around, but it also fixed
the bug.
Could you please answer to Comment 16?
Comment 37 Stas Sergeev 2013-08-14 09:02:19 UTC
../../gst-libs/gst/mpegts/mpegts.h:32:44: fatal error: gst/mpegts/gstmpegts-enumtypes.h: No such file or directory

Where is this file? The code doesn't compile for me.
Comment 38 Tim-Philipp Müller 2013-08-14 10:27:28 UTC
Run 'make' from the top-level directory. the -enumtypes.[ch] files are generated at build time using glib-mkenum.
Comment 39 Edward Hervey 2013-08-14 11:20:25 UTC
(In reply to comment #16)
> It seems there is some confusion in the pesparser code of
> tsdemux plugin... I don't know what this part was supposed
> to do at all:
> ---
>       flags = *data++;
>       /* Only valid if stream_id_extension_flag == 0x0 */
>       if (!(flags & 0x80)) {
>         res->stream_id_extension = flags & 0x7f;
> ---
> If bit 7 is not set (!(flags & 0x80)), there is no use of
> doing flags & 0x7f on the next line, is it?

  Correct, fixed that locally.

  The usage of PES_extension_field_length was also still a bit weird. The docs are a bit conflicting (the field description says it's the number of bytes after *that* field, but the PES packet table (2-21) is stating something else).

> Moreover, I failed to track that to the description of the
> pes header format, and in fact mpegtsmux can write different
> values there: 0x60, 0x71, 0x80 and 0x82 to specify the media
> type, so the 0x7f mask cannot be applied.

  mpegtsmux is doing something wrong if it's setting a stream_id_extension with the highest bit set. That needs fixing. tsdemux/pesparse is doing the expected thing.
Comment 40 Stas Sergeev 2013-08-14 11:32:53 UTC
Please see tsmux_stream_new().
It writes the correct values to stream->id_extended, some
of these values have bit 7 set, and that looks fine.
What is not fine, is that your parser expects some kind
of "flags" at that point, but there is simply no any flags.
Or if there are - what spec says that?
My patch simply removes the parsing of a non-existent flags.
Otherwise you don't get stream->id_extended from tsmux.
Comment 41 Edward Hervey 2013-08-14 11:50:02 UTC
http://www.itu.int/rec/T-REC-H.222.0-201206-I/en  (Latest public specifications June 2012)

Not cool really. I was expecting you were relying on specifications instead of guessing what's going on based on misc code.

If you want to discuss such details => IRC or mailing list.

In the meantime I just pushed a cleanup for tsdemux.

commit 21ebc7708d27fc42dcbcc4f802052c46c0229735
Author: Edward Hervey <edward@collabora.com>
Date:   Wed Aug 14 13:41:37 2013 +0200

    pesparse: Refactory secondary PES extension handling
    
    Some streams had wrong values for the stream_id_extension, make sure
    we only remember the valid ones.
    
    For streams with PES_extension_field_length == 0, assume there's nothing
    else.
    
    For streams that state they have a TREF extension but don't have enough
    data to store it, just assume it was produced by a non-compliant muxer
    and skip the remaining data.
    
    Only store remaining data in stream_id_extension_data instead of storing
    data we already parse.
Comment 42 Stas Sergeev 2013-08-14 12:15:47 UTC
(In reply to comment #41)
> Not cool really. I was expecting you were relying on specifications instead of
> guessing what's going on based on misc code.
Do you really expect me to remember the specification 2
years after I made the patch?

Anyway, the iso13818-1 says this:
---
if ( PES_extension_flag_2 == '1') {
  marker_bit
  PES_extension_field_length
  for (i = 0; i < PES_extension_field_length; i++) {
    reserved
  }
}
---

But the document you point to, says this:
---
if ( PES_extension_flag_2 == '1') {
  marker_bit
  PES_extension_field_length
  stream_id_extension_flag
  If ( stream_id_extension_flag == '0') {
    stream_id_extension
  }
  else {
---

It is up to you to decide what document is right, but
accusing me in guessing on a misc code is not correct.
This "misc code" is from your git, and the standard is
from ISO.

Note that your document is messed up in that point.
It has this a few lines below:
---
    for (i = 0; i < PES_extension_field_length; i++) {
      reserved
    }
}
      }
---
Here, the closing brackets are messed (page 35), so I
wouldn't trust that part at all.
Comment 43 Sebastian Dröge (slomo) 2013-08-23 11:16:07 UTC
Edward, what should be done here?
Comment 44 GStreamer system administrator 2018-11-03 13:08:31 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-bad/issues/44.