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 664274 - [API] codecparsers: add gst_mpeg_video_parse_slice() and gst_mpeg_video_parse_sequence_scalable_extension()
[API] codecparsers: add gst_mpeg_video_parse_slice() and gst_mpeg_video_parse...
Status: RESOLVED FIXED
Product: GStreamer
Classification: Platform
Component: gst-plugins-bad
git master
Other Linux
: Normal enhancement
: 1.1.2
Assigned To: GStreamer Maintainers
GStreamer Maintainers
Depends on: 692933
Blocks:
 
 
Reported: 2011-11-17 14:19 UTC by sreerenj
Modified: 2013-07-08 09:16 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
MpegVideo Slice parser API (5.22 KB, patch)
2011-11-17 14:19 UTC, sreerenj
none Details | Review
mpegvideoparser: Add Sequence Scalable Extension parsing API (7.75 KB, patch)
2013-01-25 13:58 UTC, sreerenj
none Details | Review
mpegvideoparse: Add Slice Header parsing API. (7.42 KB, patch)
2013-01-29 12:49 UTC, sreerenj
none Details | Review
codecparsers: mpegvideo: Add Slice Header parsing API. (7.38 KB, patch)
2013-01-30 15:04 UTC, sreerenj
none Details | Review
codecparsers:mpegvideo : optimise the slice:mb_row calculation. (1.53 KB, patch)
2013-01-31 12:40 UTC, sreerenj
reviewed Details | Review
codecparsers: mpegvideo: Add Sequence scalable extension parsing API (9.05 KB, patch)
2013-07-05 13:15 UTC, sreerenj
none Details | Review
codecparsers: mpegvideo: Add Slice Header parsing API. (8.16 KB, patch)
2013-07-05 13:16 UTC, sreerenj
none Details | Review
codecparsers: mpeg2: add sequence scalable extension parsing API (8.44 KB, patch)
2013-07-05 13:41 UTC, Gwenole Beauchesne
committed Details | Review
codecparsers: mpeg2: add slice header parsing API (8.08 KB, patch)
2013-07-05 13:41 UTC, Gwenole Beauchesne
none Details | Review
codecparsers: mpeg2: add slice header parsing API (8.08 KB, patch)
2013-07-05 14:20 UTC, Gwenole Beauchesne
committed Details | Review

Description sreerenj 2011-11-17 14:19:13 UTC
Created attachment 201593 [details] [review]
MpegVideo Slice parser API

Adding gst_mpeg_video_parse_slice() method to gstmpegvideoparser, in bitstream parser library.
The SliceHdr fileds are needed to integrate the vaapi mpeg decoder.
Comment 1 Tim-Philipp Müller 2013-01-03 00:02:50 UTC
Hrm, sorry for the long wait. So what's up with the

 /*Fixme: Not checking for 'Data Partitioning Mode' of Sequence Scalable Extension */

? Isn't that API-relevant?

If I'm reading the spec right we'd need to pass an additional parameter with the sequence_scalable_extension (even if we don't have a struct for that yet or actually parse it).
Comment 2 sreerenj 2013-01-25 13:25:29 UTC
(In reply to comment #1)
> Hrm, sorry for the long wait. So what's up with the
> 
>  /*Fixme: Not checking for 'Data Partitioning Mode' of Sequence Scalable
> Extension */
> 
> ? Isn't that API-relevant?
> 
> If I'm reading the spec right we'd need to pass an additional parameter with
> the sequence_scalable_extension (even if we don't have a struct for that yet or
> actually parse it).

I have a patch for Sequence Scalable Extension parsing. Do I need to file a separate bug for that or is it enough to add the patch here.?

How about changing the API 
    gst_mpeg_video_parse_slice(Slice, 
                               Seq, SeqExt, SeqScalExt, 
                               data, size, offset); 

to

   gst_mpeg_video_parse_slice(Slice,
                              vertical_size, SeqScalExt,
                              data, size, offset);


Because now the mpegparser has gst_mpeg_video_finalise_mpeg2_sequence_header() api which is calculating the vertical_size also.
Comment 3 Tim-Philipp Müller 2013-01-25 13:31:27 UTC
Adding it here is fine, thanks!
Comment 4 sreerenj 2013-01-25 13:58:38 UTC
Created attachment 234396 [details] [review]
 mpegvideoparser: Add Sequence Scalable Extension parsing API
Comment 5 sreerenj 2013-01-25 14:02:52 UTC
(In reply to comment #3)
> Adding it here is fine, thanks!

Done..
What do you think about the gst_mpeg_video_parse_slice() API ?
Comment 6 Gwenole Beauchesne 2013-01-25 14:38:26 UTC
(In reply to comment #5)
> (In reply to comment #3)
> > Adding it here is fine, thanks!
> 
> Done..
> What do you think about the gst_mpeg_video_parse_slice() API ?

I prefer the following data structure:

struct _GstMpegVideoSliceHdr {
    guint16 slice_horizontal_position;
    guint16 slice_vertical_position;
    guint8 quantiser_scale_code;
    guint8 intra_slice;

    /* Size of the slice() header in bits */
    guint header_size;
};

i.e. the macroblock_address needs to be correctly calculated, otherwise it's useless for gst-vaapi purposes. Please have a look at the current gstvaapidecoder_mpeg2.c:parse_slice() for a more correct implementation.

My copy of the MPEG-2 standard does not mention the picture_id, but if you see a need for it, just add it then. :)
Comment 7 sreerenj 2013-01-25 15:01:03 UTC
(In reply to comment #6)
> (In reply to comment #5)
> > (In reply to comment #3)
> > > Adding it here is fine, thanks!
> > 
> > Done..
> > What do you think about the gst_mpeg_video_parse_slice() API ?
> 
> I prefer the following data structure:
> 
> struct _GstMpegVideoSliceHdr {
>     guint16 slice_horizontal_position;
>     guint16 slice_vertical_position;
>     guint8 quantiser_scale_code;
>     guint8 intra_slice;
> 
>     /* Size of the slice() header in bits */
>     guint header_size;
> };
> 
> i.e. the macroblock_address needs to be correctly calculated, otherwise it's
> useless for gst-vaapi purposes. Please have a look at the current
> gstvaapidecoder_mpeg2.c:parse_slice() for a more correct implementation.
> 
> My copy of the MPEG-2 standard does not mention the picture_id, but if you see
> a need for it, just add it then. :)

I will check that..thanks :)
So what do you think about the API parameters change I mentioned in comment2 ?

or if you guys prefer to do slice_parsing in deocoders itself(with out having a separate API) , then we can do it like that. I have no objection :)
Comment 8 Gwenole Beauchesne 2013-01-25 15:26:59 UTC
(In reply to comment #7)
> So what do you think about the API parameters change I mentioned in comment2 ?

A seqhdr is probably better than vertical_size since, as you mentioned, vertical_size is already available there and this makes the parameters more uniform with other parsers.

> or if you guys prefer to do slice_parsing in deocoders itself(with out having a
> separate API) , then we can do it like that. I have no objection :)

Yes, I'd like to move GstMpegVideoSliceHdr from gst-vaapi to gst-plugins-bad codecparsers. So, the structure I described is the minimal one I need. :)
Comment 9 sreerenj 2013-01-25 15:43:18 UTC
(In reply to comment #8)
> (In reply to comment #7)
> > So what do you think about the API parameters change I mentioned in comment2 ?
> 
> A seqhdr is probably better than vertical_size since, as you mentioned,
> vertical_size is already available there and this makes the parameters more
> uniform with other parsers.
> 
> > or if you guys prefer to do slice_parsing in deocoders itself(with out having a
> > separate API) , then we can do it like that. I have no objection :)
> 
> Yes, I'd like to move GstMpegVideoSliceHdr from gst-vaapi to gst-plugins-bad
> codecparsers. So, the structure I described is the minimal one I need. :)

Yup, you are right. Doesn't need to pass the SeqExt to slice_parse() since seq_hdr has the vertical size..
Thanks..
Comment 10 sreerenj 2013-01-29 12:49:55 UTC
Created attachment 234723 [details] [review]
mpegvideoparse: Add Slice Header parsing API.
Comment 11 Gwenole Beauchesne 2013-01-29 13:36:44 UTC
Review of attachment 234723 [details] [review]:

Hi,
- it seems that gst_mpeg_video_parse_slice_header() args are not vertically aligned with the other functions;
- slice_vertical_position_extension is useless since it depends on seqhdr values, i.e. it may not convey meaningful value from within the same data structure;
- slice_picture_id has no comment on what it means;
- I really want header_size to be the last field with the following comment: /* Size of the slice() header in bits */
- Missing leading space in /* Calculated values */
- I prefer mb_x, mb_y to mb_row, mb_column even if the latter comes from the specs terminology.

Thanks,
Gwenole.
Comment 12 sreerenj 2013-01-29 13:51:51 UTC
(In reply to comment #11)
> Review of attachment 234723 [details] [review]:
> 
> Hi,
> - it seems that gst_mpeg_video_parse_slice_header() args are not vertically
> aligned with the other functions;

we need the start_code to get the type which is needed to calcuate mb_x/mb_row..
otherwise we have to pass the slice_no as the next argument..(we already have 6 arguments :))

> - slice_vertical_position_extension is useless since it depends on seqhdr
> values, i.e. it may not convey meaningful value from within the same data
> structure;

have no objection to avoid that field :)

> - slice_picture_id has no comment on what it means;

just kept that field since it might need for some once else even though it is not using for decoding.But i don't know whether someone is using that or not...Is it an overhead?
As per the spec,

"slice_picture_id is intended to aid recovery on severe bursts of
errors for certain types of applications. For example, the application may increment slice_picture_id with each transmitted picture, so that in case of severe burst error, when several slices are lost, the decoder can know if the slice following the burst error belongs to the current picture or to another picture, which may be the case if at least a picture
header has been lost."


> - I really want header_size to be the last field with the following comment: /*
> Size of the slice() header in bits */

Sorry i didn't get it.Does the calculation is wrong? remember the data is starting from the start_code.

> - Missing leading space in /* Calculated values */
> - I prefer mb_x, mb_y to mb_row, mb_column even if the latter comes from the
> specs terminology.

no objection .  

> Thanks,
> Gwenole.
Comment 13 sreerenj 2013-01-30 15:04:15 UTC
Created attachment 234829 [details] [review]
codecparsers: mpegvideo: Add Slice Header parsing API.

Based on comment11 and comment12,
--fixed the white space warning
--add comment for slice_picture_id
--removed the slice_vertical_position_extension field from the header
--but retained the mb_row/mb_colum because otherwise it will be a confusion for someone else who is checking with the spec.
Comment 14 Gwenole Beauchesne 2013-01-30 22:13:09 UTC
Review of attachment 234829 [details] [review]:

Hi, on second thought, the slice API is not fully consistent with the rest (seq_hdr, pic_hdr, et al.). In particular, the offset for slice() is relative to the start-code prefix, whereas it is relative to the actual data (after the start code + type) for others. I suggest we globally change the MPEG-2 video parser API to take a const GstMpegVideoPacket * instead of multiple arguments like data, size, offset. That way, the slice API would also know about the type to calculate slice_vertical_position without parsing it again.

Besides, this would also simplify a bit client applications since they usually know about the GstMpegVideoPacket to use and would just need to pass it along to the parser, instead of propagating all its fields as multiple arguments.

That's on Tim's call now. :)

BTW, you don't need to check for height > 2800 again if slice_vertical_position is already initialized to zero, before hand. i.e. shift + add is probably cheaper than a mispredicted branch in the common case. Not that this is really important, just something that came to my mind. :)
Comment 15 Gwenole Beauchesne 2013-01-31 05:07:33 UTC
Review of attachment 234829 [details] [review]:

If we want to preserve ABI, the better alternative is to add gst_mpeg_video_packet_parse_*() functions, which now hold the default implementations. Others are marked are deprecated and they call into the new gst_mpeg_video_packet_*() functions. I will probably provide a patch later today.
Comment 16 sreerenj 2013-01-31 09:14:21 UTC
(In reply to comment #14)
> Review of attachment 234829 [details] [review]:
> 
> Hi, on second thought, the slice API is not fully consistent with the rest
> (seq_hdr, pic_hdr, et al.). In particular, the offset for slice() is relative
> to the start-code prefix, whereas it is relative to the actual data (after the
> start code + type) for others. I suggest we globally change the MPEG-2 video
> parser API to take a const GstMpegVideoPacket * instead of multiple arguments
> like data, size, offset. That way, the slice API would also know about the type
> to calculate slice_vertical_position without parsing it again.
> 
> Besides, this would also simplify a bit client applications since they usually
> know about the GstMpegVideoPacket to use and would just need to pass it along
> to the parser, instead of propagating all its fields as multiple arguments.
> 

Seems fine...We might be able to do the same with RBDU in vc1,,,

> That's on Tim's call now. :)
> 
> BTW, you don't need to check for height > 2800 again if slice_vertical_position
> is already initialized to zero, before hand. i.e. shift + add is probably
> cheaper than a mispredicted branch in the common case. Not that this is really
> important, just something that came to my mind. :)

Hm,,second if() check is already an extra branching since it is possible to do the mb_row calculation in first if() check itself..
What you said might be more optimized...
Thanks for the catch..
Do i need to update it like that?? Or will you do it together with your proposed gst_mpeg_video_packet_parse_*() patch?Just asked because you mentioned that you might come up with the patch later today itself :)
Comment 17 sreerenj 2013-01-31 12:40:03 UTC
Created attachment 234906 [details] [review]
codecparsers:mpegvideo : optimise the slice:mb_row calculation.
Comment 18 Gwenole Beauchesne 2013-02-01 08:54:17 UTC
(In reply to comment #16)
> (In reply to comment #14)
> > Besides, this would also simplify a bit client applications since they usually
> > know about the GstMpegVideoPacket to use and would just need to pass it along
> > to the parser, instead of propagating all its fields as multiple arguments.
> > 
> 
> Seems fine...We might be able to do the same with RBDU in vc1,,,

Maybe, but I have other plans for the VC-1 parser. :)

> > That's on Tim's call now. :)
> > 
> > BTW, you don't need to check for height > 2800 again if slice_vertical_position
> > is already initialized to zero, before hand. i.e. shift + add is probably
> > cheaper than a mispredicted branch in the common case. Not that this is really
> > important, just something that came to my mind. :)
> 
> Hm,,second if() check is already an extra branching since it is possible to do
> the mb_row calculation in first if() check itself..
> What you said might be more optimized...
> Thanks for the catch..
> Do i need to update it like that?? Or will you do it together with your
> proposed gst_mpeg_video_packet_parse_*() patch?Just asked because you mentioned
> that you might come up with the patch later today itself :)

I think we should first settle with the new GstMpegVideoPacket based API first, then you can update your patches after that.
Comment 19 sreerenj 2013-02-18 08:58:26 UTC
Any  chance to push these patches??
I will add necessary patches to https://bugzilla.gnome.org/show_bug.cgi?id=692933 after that...
Comment 20 Tim-Philipp Müller 2013-02-18 10:58:20 UTC
Comment on attachment 234906 [details] [review]
codecparsers:mpegvideo : optimise the slice:mb_row calculation.

I don't really have an opinion on this patch, it seems like a micro-optimisation that surely is not going to really make a difference? If in doubt, I tend to prefer clear code (but again, here it hardly matters). Anyway, I'll leave it to Gwenole to decide.

If you do push it, please fix up the commit message (weird space placement in subject line, and coparison->comparison) and the comments in the code (use '*' in each comment line, and also coparison->comparison).
Comment 21 Tim-Philipp Müller 2013-02-18 11:09:27 UTC
The other two look fine to me if Gwenole is happy with them too.

I think bug #692933 should be done first though?

(In reply to comment #15)
> Review of attachment 234829 [details] [review]:
> 
> If we want to preserve ABI, the better alternative is to add
> gst_mpeg_video_packet_parse_*() functions, which now hold the default
> implementations. Others are marked are deprecated and they call into the new
> gst_mpeg_video_packet_*() functions. I will probably provide a patch later
> today.

FWIW, I don't mind breaking ABI here, as long as there's a good reason to change it. If there is, the sooner the better IMHO (and please also update the video parser then).
Comment 22 sreerenj 2013-02-18 12:40:06 UTC
Applying the patch in https://bugzilla.gnome.org/show_bug.cgi?id=692933 to the current git master of plugin-bad is failing. Something has been changed in git master i think....
I will wait for Gwenole to push those patches then...
Comment 23 sreerenj 2013-06-13 07:43:56 UTC
I would like to use the "GstMpegVideoMeta" from plugins-bad for gstreamer-vaapi also. For that we need to get this API in. Otherwise the gstreamer-vaapi needs to parse the data again to get the slice_hdr details.
Comment 24 Tim-Philipp Müller 2013-06-13 09:44:17 UTC
I'm waiting for feedback from Gwenole. My comment #20 and comment #21 still apply :)

Milestoning as 1.1.x though, to re-visit before 1.2 hopefully.
Comment 25 sreerenj 2013-06-27 08:39:08 UTC
Hi Gwenole, Could you please have a look into this?
Comment 26 Gwenole Beauchesne 2013-07-05 09:57:32 UTC
(In reply to comment #25)
> Hi Gwenole, Could you please have a look into this?

Ah, sorry, I thought you only needed me to review the dependency.

OK, so for the slice_hdr parser, you can now use GstMpegVideoPacket interface. Don't bother with adding the gst_mpeg_video_parse_slice_header() into the deprecated namespace, the args would not match other functions. i.e. only add a gst_mpeg_video_packet_parse_slice_header() function, the slice_vertical_position would come from the packet->type. Thanks.

Otherwise, that looks fine, assuming it still works with gstreamer-vaapi. :)
Comment 27 sreerenj 2013-07-05 13:15:28 UTC
Created attachment 248452 [details] [review]
codecparsers: mpegvideo: Add Sequence scalable extension parsing API
Comment 28 sreerenj 2013-07-05 13:16:06 UTC
Created attachment 248453 [details] [review]
codecparsers: mpegvideo: Add Slice Header parsing API.
Comment 29 sreerenj 2013-07-05 13:17:09 UTC
Updated the patches on top of Gwenole's patches in https://bugzilla.gnome.org/show_bug.cgi?id=692933
Comment 30 Gwenole Beauchesne 2013-07-05 13:38:50 UTC
Review of attachment 248452 [details] [review]:

::: gst-libs/gst/codecparsers/gstmpegvideoparser.h
@@ +124,1 @@
 } GstMpegVideoLevel;

Unrelated changes, maybe due to gst-indent?

@@ +316,3 @@
+  guint8 vertical_subsampling_factor_n;
+
+  /*if temporal scalability*/

/* if ... */ -- missing spaces.
Comment 31 Gwenole Beauchesne 2013-07-05 13:40:27 UTC
Review of attachment 248453 [details] [review]:

::: gst-libs/gst/codecparsers/gstmpegvideoparser.c
@@ +960,3 @@
+  guint height;
+  guint mb_inc;
+  guint8 bits = 0, extra_bits = 0;

Junk bytes don't need to be initialized.

@@ +961,3 @@
+  guint mb_inc;
+  guint8 bits = 0, extra_bits = 0;
+  guint8 vertical_position = 0, vertical_position_extension = 0;

Only vertical_position_extension needs to be zero-initialized, not vertical_position.

@@ +972,3 @@
+
+  SKIP (&br, 24);
+  vertical_position = gst_bit_reader_get_bits_uint8_unchecked (&br, 8);

I don't think this will work since the offset is relative to the actual slice header start, without the start_code_prefix.
Comment 32 Gwenole Beauchesne 2013-07-05 13:41:31 UTC
Created attachment 248456 [details] [review]
codecparsers: mpeg2: add sequence scalable extension parsing API

Actually, I was also working on updating the patches. :)
Comment 33 Gwenole Beauchesne 2013-07-05 13:41:59 UTC
Created attachment 248457 [details] [review]
codecparsers: mpeg2: add slice header parsing API
Comment 34 sreerenj 2013-07-05 13:47:59 UTC
(In reply to comment #30)
> Review of attachment 248452 [details] [review]:
> 
> ::: gst-libs/gst/codecparsers/gstmpegvideoparser.h
> @@ +124,1 @@
>  } GstMpegVideoLevel;
> 
> Unrelated changes, maybe due to gst-indent?
> 
> @@ +316,3 @@
> +  guint8 vertical_subsampling_factor_n;
> +
> +  /*if temporal scalability*/
> 
> /* if ... */ -- missing spaces.

No gst-indent for headers. But yes, there was missing space before GStMpegVideoLevel which i have corrected on the way.
Comment 35 sreerenj 2013-07-05 13:49:19 UTC
Thanks for the review :)
Comment 36 Gwenole Beauchesne 2013-07-05 14:20:35 UTC
Created attachment 248461 [details] [review]
codecparsers: mpeg2: add slice header parsing API

Fix off by one error in mb_row calculation. The slice_vertical_position shall start from zero.
Comment 37 Tim-Philipp Müller 2013-07-05 14:37:51 UTC
Comment on attachment 248461 [details] [review]
codecparsers: mpeg2: add slice header parsing API

Looks fine to me, but please add 'Since: 1.2' markers to the gtk-doc chunks for the new function and the new structure.
Comment 38 Tim-Philipp Müller 2013-07-05 15:10:47 UTC
Comment on attachment 248456 [details] [review]
codecparsers: mpeg2: add sequence scalable extension parsing API

Looks fine. Please also add a 'Since 1.2' to the structure doc chunk.
Comment 39 Gwenole Beauchesne 2013-07-05 16:44:17 UTC
Argh, I did not commit the right patch. Fixing now, missing tests/ update. Sorry.
Comment 40 sreerenj 2013-07-08 08:09:05 UTC
All the patches are landed in upstream. Please close this bug.
Comment 41 Gwenole Beauchesne 2013-07-08 08:15:51 UTC
commit 9a2ed785321568dbb568ed485d4310ee12b74008
Author: Sreerenj Balachandran <sreerenj.balachandran@intel.com>
Date:   Wed Jan 30 16:56:15 2013 +0200

    codecparsers: mpeg2: add slice header parsing API.
    
    Add API to parse the Slice header. This also calculates the macroblock
    position as specified in 6.3.16.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=664274
    
    Signed-off-by: Sreerenj Balachandran <sreerenj.balachandran@intel.com>
    Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>

commit 2adfbe36f16cf9d69d91cdf5ee4ecd3a4bbfc858
Author: Sreerenj Balachandran <sreerenj.balachandran@intel.com>
Date:   Fri Jan 25 15:48:58 2013 +0200

    codecparsers: mpeg2: add sequence scalable extension parsing API.
    
    Add API to parse the Sequence Scalable Extension header.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=664274
    
    Signed-off-by: Sreerenj Balachandran <sreerenj.balachandran@intel.com>
    Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>