[FFmpeg-devel] [PATCH 10/11] cbs_mpeg2: Fix parsing of picture headers

Mark Thompson sw at jkqxz.net
Sun Jun 2 20:13:08 EEST 2019


On 29/05/2019 05:54, Andreas Rheinhardt wrote:
> Mark Thompson:
>> On 22/05/2019 02:04, Andreas Rheinhardt wrote:
>>> MPEG-2 picture and slice headers can contain optional extra information;
>>> both use the same syntax for their extra information. And cbs_mpeg2's
>>> implementations of both were buggy until recently; the one for the
>>> picture headers still is and this is fixed in this commit.
>>>
>>> The extra information in picture headers has simply been forgotten.
>>> This meant that if this extra information was present, it was discarded
>>> during reading; and unfortunately writing created invalid bitstreams in
>>> this case (an extra_bit_picture - the last set bit of the whole unit -
>>> indicated that there would be a further byte of data, although the output
>>> didn't contain said data).
>>>
>>> This has been fixed; both types of extra information are now
>>> parsed via the same code and essentially passed through.
>>>
>>> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
>>> ---
>>>  libavcodec/cbs_mpeg2.c                 | 31 +++++++-----
>>>  libavcodec/cbs_mpeg2.h                 | 12 +++--
>>>  libavcodec/cbs_mpeg2_syntax_template.c | 66 +++++++++++++++-----------
>>>  3 files changed, 66 insertions(+), 43 deletions(-)
>>>
>>> diff --git a/libavcodec/cbs_mpeg2.c b/libavcodec/cbs_mpeg2.c
>>> index 97425aa706..2354f665cd 100644
>>> --- a/libavcodec/cbs_mpeg2.c
>>> +++ b/libavcodec/cbs_mpeg2.c
>>> @@ -41,18 +41,18 @@
>>>  #define SUBSCRIPTS(subs, ...) (subs > 0 ? ((int[subs + 1]){ subs, __VA_ARGS__ }) : NULL)
>>>  
>>>  #define ui(width, name) \
>>> -        xui(width, name, current->name, 0, MAX_UINT_BITS(width), 0)
>>> +        xui(width, #name, current->name, 0, MAX_UINT_BITS(width), 0)
>>>  #define uir(width, name) \
>>> -        xui(width, name, current->name, 1, MAX_UINT_BITS(width), 0)
>>> +        xui(width, #name, current->name, 1, MAX_UINT_BITS(width), 0)
>>>  #define uis(width, name, subs, ...) \
>>> -        xui(width, name, current->name, 0, MAX_UINT_BITS(width), subs, __VA_ARGS__)
>>> +        xui(width, #name, current->name, 0, MAX_UINT_BITS(width), subs, __VA_ARGS__)
>>>  #define uirs(width, name, subs, ...) \
>>> -        xui(width, name, current->name, 1, MAX_UINT_BITS(width), subs, __VA_ARGS__)
>>> +        xui(width, #name, current->name, 1, MAX_UINT_BITS(width), subs, __VA_ARGS__)
>>>  #define sis(width, name, subs, ...) \
>>> -        xsi(width, name, current->name, subs, __VA_ARGS__)
>>> +        xsi(width, #name, current->name, subs, __VA_ARGS__)
>>>  
>>>  #define marker_bit() \
>>> -        bit(marker_bit, 1)
>>> +        bit("marker_bit", 1)
>>>  #define bit(name, value) do { \
>>>          av_unused uint32_t bit = value; \
>>>          xui(1, name, bit, value, value, 0); \
>>> @@ -65,7 +65,7 @@
>>>  
>>>  #define xui(width, name, var, range_min, range_max, subs, ...) do { \
>>>          uint32_t value; \
>>> -        CHECK(ff_cbs_read_unsigned(ctx, rw, width, #name, \
>>> +        CHECK(ff_cbs_read_unsigned(ctx, rw, width, name, \
>>>                                     SUBSCRIPTS(subs, __VA_ARGS__), \
>>>                                     &value, range_min, range_max)); \
>>>          var = value; \
>>> @@ -73,7 +73,7 @@
>>>  
>>>  #define xsi(width, name, var, subs, ...) do { \
>>>          int32_t value; \
>>> -        CHECK(ff_cbs_read_signed(ctx, rw, width, #name, \
>>> +        CHECK(ff_cbs_read_signed(ctx, rw, width, name, \
>>>                                   SUBSCRIPTS(subs, __VA_ARGS__), &value, \
>>>                                   MIN_INT_BITS(width), \
>>>                                   MAX_INT_BITS(width))); \
>>> @@ -104,13 +104,13 @@
>>>  #define RWContext PutBitContext
>>>  
>>>  #define xui(width, name, var, range_min, range_max, subs, ...) do { \
>>> -        CHECK(ff_cbs_write_unsigned(ctx, rw, width, #name, \
>>> +        CHECK(ff_cbs_write_unsigned(ctx, rw, width, name, \
>>>                                      SUBSCRIPTS(subs, __VA_ARGS__), \
>>>                                      var, range_min, range_max)); \
>>>      } while (0)
>>>  
>>>  #define xsi(width, name, var, subs, ...) do { \
>>> -        CHECK(ff_cbs_write_signed(ctx, rw, width, #name, \
>>> +        CHECK(ff_cbs_write_signed(ctx, rw, width, name, \
>>>                                    SUBSCRIPTS(subs, __VA_ARGS__), var, \
>>>                                    MIN_INT_BITS(width), \
>>>                                    MAX_INT_BITS(width))); \
>>
>> Calling the inner functions directly in extra_information feels like it would be cleaner?  This part makes the intermediate macros for mpeg2 act in a way which is subtly different to all the other codecs.
>>
> Agreed. The rationale I did it the way I did is of course that there
> turned out to be exactly one call to xui in the mpeg2-syntax-template.
> Or maybe one should add a new macro that is the macro actually calling
> the inner functions directly and gets used by xui? If we hadn't used
> the 's' for subscripts, xuis would be the obvious choice for this.

This last suggestion seems nicest, though I'm not sure how to actually implement it without duplication (the subscript varargs are hard to pass through without using something like the ,## extension).

If you have a clean way to do it then that sounds good to me.

Thanks,

- Mark


More information about the ffmpeg-devel mailing list