diff mbox series

[FFmpeg-devel,v2,02/18] cbs_h264: Add support for frame packing arrangement SEI messages

Message ID 20210221195125.1901683-2-sw@jkqxz.net
State New
Headers show
Series [FFmpeg-devel,v2,01/18] cbs_sei: Delete SEI NAL units containing no messages
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Mark Thompson Feb. 21, 2021, 7:51 p.m. UTC
---
 libavcodec/cbs_h264.h                 | 23 ++++++++++++++++
 libavcodec/cbs_h2645.c                |  6 +++++
 libavcodec/cbs_h264_syntax_template.c | 39 +++++++++++++++++++++++++++
 3 files changed, 68 insertions(+)

Comments

James Almer Feb. 23, 2021, 4:39 p.m. UTC | #1
On 2/21/2021 4:51 PM, Mark Thompson wrote:
> ---
>   libavcodec/cbs_h264.h                 | 23 ++++++++++++++++
>   libavcodec/cbs_h2645.c                |  6 +++++
>   libavcodec/cbs_h264_syntax_template.c | 39 +++++++++++++++++++++++++++
>   3 files changed, 68 insertions(+)
> 
> diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h
> index 9eb97eae24..1466ed12fa 100644
> --- a/libavcodec/cbs_h264.h
> +++ b/libavcodec/cbs_h264.h
> @@ -282,6 +282,29 @@ typedef struct H264RawSEIRecoveryPoint {
>       uint8_t changing_slice_group_idc;
>   } H264RawSEIRecoveryPoint;
>   
> +typedef struct H264RawSEIFramePackingArrangement {
> +    uint32_t frame_packing_arrangement_id;
> +    uint8_t  frame_packing_arrangement_cancel_flag;
> +
> +    uint8_t  frame_packing_arrangement_type;
> +    uint8_t  quincunx_sampling_flag;
> +    uint8_t  content_interpretation_type;
> +    uint8_t  spatial_flipping_flag;
> +    uint8_t  frame0_flipped_flag;
> +    uint8_t  field_views_flag;
> +    uint8_t  current_frame_is_frame0_flag;
> +    uint8_t  frame0_self_contained_flag;
> +    uint8_t  frame1_self_contained_flag;
> +    uint8_t  frame0_grid_position_x;
> +    uint8_t  frame0_grid_position_y;
> +    uint8_t  frame1_grid_position_x;
> +    uint8_t  frame1_grid_position_y;
> +    uint8_t  frame_packing_arrangement_reserved_byte;
> +    uint16_t frame_packing_arrangement_repetition_period;
> +
> +    uint8_t  frame_packing_arrangement_extension_flag;
> +} H264RawSEIFramePackingArrangement;
> +
>   typedef struct H264RawSEIDisplayOrientation {
>       uint8_t display_orientation_cancel_flag;
>       uint8_t hor_flip;
> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
> index 6005d46e0d..0c591871d4 100644
> --- a/libavcodec/cbs_h2645.c
> +++ b/libavcodec/cbs_h2645.c
> @@ -1570,6 +1570,12 @@ static const SEIMessageTypeDescriptor cbs_sei_h264_types[] = {
>           sizeof(H264RawSEIRecoveryPoint),
>           SEI_MESSAGE_RW(h264, sei_recovery_point),
>       },
> +    {
> +        SEI_TYPE_FRAME_PACKING_ARRANGEMENT,
> +        1, 0,
> +        sizeof(H264RawSEIFramePackingArrangement),
> +        SEI_MESSAGE_RW(h264, sei_frame_packing_arrangement),
> +    },
>       {
>           SEI_TYPE_DISPLAY_ORIENTATION,
>           1, 0,
> diff --git a/libavcodec/cbs_h264_syntax_template.c b/libavcodec/cbs_h264_syntax_template.c
> index 9587f33985..e03d41e47a 100644
> --- a/libavcodec/cbs_h264_syntax_template.c
> +++ b/libavcodec/cbs_h264_syntax_template.c
> @@ -719,6 +719,45 @@ static int FUNC(sei_recovery_point)(CodedBitstreamContext *ctx, RWContext *rw,
>       return 0;
>   }
>   
> +
> +
> +static int FUNC(sei_frame_packing_arrangement)
> +    (CodedBitstreamContext *ctx, RWContext *rw,
> +     H264RawSEIFramePackingArrangement *current, SEIMessageState *sei)
> +{
> +    int err;
> +
> +    HEADER("Frame Packing Arrangement");
> +
> +    ue(frame_packing_arrangement_id, 0, UINT32_MAX - 1);
> +    flag(frame_packing_arrangement_cancel_flag);
> +
> +    if (!current->frame_packing_arrangement_cancel_flag) {
> +        u(7, frame_packing_arrangement_type, 0, 7);
> +        flag(quincunx_sampling_flag);
> +        u(6, content_interpretation_type, 0, 2);
> +        flag(spatial_flipping_flag);
> +        flag(frame0_flipped_flag);
> +        flag(field_views_flag);
> +        flag(current_frame_is_frame0_flag);
> +        flag(frame0_self_contained_flag);
> +        flag(frame1_self_contained_flag);
> +        if (!current->quincunx_sampling_flag &&
> +            current->frame_packing_arrangement_type != 5) {

nit: maybe H264_SEI_FPA_TYPE_INTERLEAVE_TEMPORAL instead of 5.

> +            ub(4, frame0_grid_position_x);
> +            ub(4, frame0_grid_position_y);
> +            ub(4, frame1_grid_position_x);
> +            ub(4, frame1_grid_position_y);
> +        }
> +        u(8, frame_packing_arrangement_reserved_byte, 0, 0);
> +        ue(frame_packing_arrangement_repetition_period, 0, 16384);
> +    }
> +
> +    flag(frame_packing_arrangement_extension_flag);
> +
> +    return 0;
> +}
> +
>   static int FUNC(sei_display_orientation)(CodedBitstreamContext *ctx, RWContext *rw,
>                                            H264RawSEIDisplayOrientation *current,
>                                            SEIMessageState *sei)
> 

LGTM.
Mark Thompson March 12, 2021, 10:56 p.m. UTC | #2
On 23/02/2021 16:39, James Almer wrote:
> On 2/21/2021 4:51 PM, Mark Thompson wrote:
>> ---
>>   libavcodec/cbs_h264.h                 | 23 ++++++++++++++++
>>   libavcodec/cbs_h2645.c                |  6 +++++
>>   libavcodec/cbs_h264_syntax_template.c | 39 +++++++++++++++++++++++++++
>>   3 files changed, 68 insertions(+)
>>
>> ...
>> diff --git a/libavcodec/cbs_h264_syntax_template.c b/libavcodec/cbs_h264_syntax_template.c
>> index 9587f33985..e03d41e47a 100644
>> --- a/libavcodec/cbs_h264_syntax_template.c
>> +++ b/libavcodec/cbs_h264_syntax_template.c
>> @@ -719,6 +719,45 @@ static int FUNC(sei_recovery_point)(CodedBitstreamContext *ctx, RWContext *rw,
>>       return 0;
>>   }
>> +
>> +
>> +static int FUNC(sei_frame_packing_arrangement)
>> +    (CodedBitstreamContext *ctx, RWContext *rw,
>> +     H264RawSEIFramePackingArrangement *current, SEIMessageState *sei)
>> +{
>> +    int err;
>> +
>> +    HEADER("Frame Packing Arrangement");
>> +
>> +    ue(frame_packing_arrangement_id, 0, UINT32_MAX - 1);
>> +    flag(frame_packing_arrangement_cancel_flag);
>> +
>> +    if (!current->frame_packing_arrangement_cancel_flag) {
>> +        u(7, frame_packing_arrangement_type, 0, 7);
>> +        flag(quincunx_sampling_flag);
>> +        u(6, content_interpretation_type, 0, 2);
>> +        flag(spatial_flipping_flag);
>> +        flag(frame0_flipped_flag);
>> +        flag(field_views_flag);
>> +        flag(current_frame_is_frame0_flag);
>> +        flag(frame0_self_contained_flag);
>> +        flag(frame1_self_contained_flag);
>> +        if (!current->quincunx_sampling_flag &&
>> +            current->frame_packing_arrangement_type != 5) {
> 
> nit: maybe H264_SEI_FPA_TYPE_INTERLEAVE_TEMPORAL instead of 5.

The standard does say exactly "!= 5", so I prefer to keep to that.  (It would be nice if the H.2(6[456]|74) specs made better use of enum constants, but we are stuck with what they actually do.)

- Mark
Nuo Mi March 13, 2021, 2:20 a.m. UTC | #3
On Mon, Feb 22, 2021 at 3:53 AM Mark Thompson <sw@jkqxz.net> wrote:

> ---
>  libavcodec/cbs_h264.h                 | 23 ++++++++++++++++
>  libavcodec/cbs_h2645.c                |  6 +++++
>  libavcodec/cbs_h264_syntax_template.c | 39 +++++++++++++++++++++++++++
>  3 files changed, 68 insertions(+)
>
> diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h
> index 9eb97eae24..1466ed12fa 100644
> --- a/libavcodec/cbs_h264.h
> +++ b/libavcodec/cbs_h264.h
> @@ -282,6 +282,29 @@ typedef struct H264RawSEIRecoveryPoint {
>      uint8_t changing_slice_group_idc;
>  } H264RawSEIRecoveryPoint;
>
> +typedef struct H264RawSEIFramePackingArrangement {
> +    uint32_t frame_packing_arrangement_id;
> +    uint8_t  frame_packing_arrangement_cancel_flag;
> +
> +    uint8_t  frame_packing_arrangement_type;
> +    uint8_t  quincunx_sampling_flag;
> +    uint8_t  content_interpretation_type;
> +    uint8_t  spatial_flipping_flag;
> +    uint8_t  frame0_flipped_flag;
> +    uint8_t  field_views_flag;
> +    uint8_t  current_frame_is_frame0_flag;
> +    uint8_t  frame0_self_contained_flag;
> +    uint8_t  frame1_self_contained_flag;
> +    uint8_t  frame0_grid_position_x;
> +    uint8_t  frame0_grid_position_y;
> +    uint8_t  frame1_grid_position_x;
> +    uint8_t  frame1_grid_position_y;
> +    uint8_t  frame_packing_arrangement_reserved_byte;
> +    uint16_t frame_packing_arrangement_repetition_period;
> +
> +    uint8_t  frame_packing_arrangement_extension_flag;
> +} H264RawSEIFramePackingArrangement;
> +
>  typedef struct H264RawSEIDisplayOrientation {
>      uint8_t display_orientation_cancel_flag;
>      uint8_t hor_flip;
> diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
> index 6005d46e0d..0c591871d4 100644
> --- a/libavcodec/cbs_h2645.c
> +++ b/libavcodec/cbs_h2645.c
> @@ -1570,6 +1570,12 @@ static const SEIMessageTypeDescriptor
> cbs_sei_h264_types[] = {
>          sizeof(H264RawSEIRecoveryPoint),
>          SEI_MESSAGE_RW(h264, sei_recovery_point),
>      },
> +    {
> +        SEI_TYPE_FRAME_PACKING_ARRANGEMENT,
> +        1, 0,
> +        sizeof(H264RawSEIFramePackingArrangement),
> +        SEI_MESSAGE_RW(h264, sei_frame_packing_arrangement),
> +    },
>      {
>          SEI_TYPE_DISPLAY_ORIENTATION,
>          1, 0,
> diff --git a/libavcodec/cbs_h264_syntax_template.c
> b/libavcodec/cbs_h264_syntax_template.c
> index 9587f33985..e03d41e47a 100644
> --- a/libavcodec/cbs_h264_syntax_template.c
> +++ b/libavcodec/cbs_h264_syntax_template.c
> @@ -719,6 +719,45 @@ static int
> FUNC(sei_recovery_point)(CodedBitstreamContext *ctx, RWContext *rw,
>      return 0;
>  }
>
> +
> +
> +static int FUNC(sei_frame_packing_arrangement)
> +    (CodedBitstreamContext *ctx, RWContext *rw,
> +     H264RawSEIFramePackingArrangement *current, SEIMessageState *sei)
> +{
> +    int err;
> +
> +    HEADER("Frame Packing Arrangement");
> +
> +    ue(frame_packing_arrangement_id, 0, UINT32_MAX - 1);
> +    flag(frame_packing_arrangement_cancel_flag);
> +
> +    if (!current->frame_packing_arrangement_cancel_flag) {
> +        u(7, frame_packing_arrangement_type, 0, 7);
> +        flag(quincunx_sampling_flag);
> +        u(6, content_interpretation_type, 0, 2);

>2 is reserved, should we use ub(6,  content_interpretation_type)?

>



+        flag(spatial_flipping_flag);
> +        flag(frame0_flipped_flag);
> +        flag(field_views_flag);
> +        flag(current_frame_is_frame0_flag);
> +        flag(frame0_self_contained_flag);
> +        flag(frame1_self_contained_flag);
> +        if (!current->quincunx_sampling_flag &&
> +            current->frame_packing_arrangement_type != 5) {
> +            ub(4, frame0_grid_position_x);
> +            ub(4, frame0_grid_position_y);
> +            ub(4, frame1_grid_position_x);
> +            ub(4, frame1_grid_position_y);
> +        }
> +        u(8, frame_packing_arrangement_reserved_byte, 0, 0);
>
ub for reserved bytes?

> +        ue(frame_packing_arrangement_repetition_period, 0, 16384);
> +    }
> +
> +    flag(frame_packing_arrangement_extension_flag);
> +
> +    return 0;
> +}
> +
>  static int FUNC(sei_display_orientation)(CodedBitstreamContext *ctx,
> RWContext *rw,
>                                           H264RawSEIDisplayOrientation
> *current,
>                                           SEIMessageState *sei)
> --
> 2.30.0
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
James Almer April 3, 2021, 2:10 p.m. UTC | #4
On 3/12/2021 7:56 PM, Mark Thompson wrote:
> On 23/02/2021 16:39, James Almer wrote:
>> On 2/21/2021 4:51 PM, Mark Thompson wrote:
>>> ---
>>>   libavcodec/cbs_h264.h                 | 23 ++++++++++++++++
>>>   libavcodec/cbs_h2645.c                |  6 +++++
>>>   libavcodec/cbs_h264_syntax_template.c | 39 +++++++++++++++++++++++++++
>>>   3 files changed, 68 insertions(+)
>>>
>>> ...
>>> diff --git a/libavcodec/cbs_h264_syntax_template.c 
>>> b/libavcodec/cbs_h264_syntax_template.c
>>> index 9587f33985..e03d41e47a 100644
>>> --- a/libavcodec/cbs_h264_syntax_template.c
>>> +++ b/libavcodec/cbs_h264_syntax_template.c
>>> @@ -719,6 +719,45 @@ static int 
>>> FUNC(sei_recovery_point)(CodedBitstreamContext *ctx, RWContext *rw,
>>>       return 0;
>>>   }
>>> +
>>> +
>>> +static int FUNC(sei_frame_packing_arrangement)
>>> +    (CodedBitstreamContext *ctx, RWContext *rw,
>>> +     H264RawSEIFramePackingArrangement *current, SEIMessageState *sei)
>>> +{
>>> +    int err;
>>> +
>>> +    HEADER("Frame Packing Arrangement");
>>> +
>>> +    ue(frame_packing_arrangement_id, 0, UINT32_MAX - 1);
>>> +    flag(frame_packing_arrangement_cancel_flag);
>>> +
>>> +    if (!current->frame_packing_arrangement_cancel_flag) {
>>> +        u(7, frame_packing_arrangement_type, 0, 7);
>>> +        flag(quincunx_sampling_flag);
>>> +        u(6, content_interpretation_type, 0, 2);
>>> +        flag(spatial_flipping_flag);
>>> +        flag(frame0_flipped_flag);
>>> +        flag(field_views_flag);
>>> +        flag(current_frame_is_frame0_flag);
>>> +        flag(frame0_self_contained_flag);
>>> +        flag(frame1_self_contained_flag);
>>> +        if (!current->quincunx_sampling_flag &&
>>> +            current->frame_packing_arrangement_type != 5) {
>>
>> nit: maybe H264_SEI_FPA_TYPE_INTERLEAVE_TEMPORAL instead of 5.
> 
> The standard does say exactly "!= 5", so I prefer to keep to that.  (It 
> would be nice if the H.2(6[456]|74) specs made better use of enum 
> constants, but we are stuck with what they actually do.)

Ok, LGTM then.

> 
> - Mark
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> 
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h
index 9eb97eae24..1466ed12fa 100644
--- a/libavcodec/cbs_h264.h
+++ b/libavcodec/cbs_h264.h
@@ -282,6 +282,29 @@  typedef struct H264RawSEIRecoveryPoint {
     uint8_t changing_slice_group_idc;
 } H264RawSEIRecoveryPoint;
 
+typedef struct H264RawSEIFramePackingArrangement {
+    uint32_t frame_packing_arrangement_id;
+    uint8_t  frame_packing_arrangement_cancel_flag;
+
+    uint8_t  frame_packing_arrangement_type;
+    uint8_t  quincunx_sampling_flag;
+    uint8_t  content_interpretation_type;
+    uint8_t  spatial_flipping_flag;
+    uint8_t  frame0_flipped_flag;
+    uint8_t  field_views_flag;
+    uint8_t  current_frame_is_frame0_flag;
+    uint8_t  frame0_self_contained_flag;
+    uint8_t  frame1_self_contained_flag;
+    uint8_t  frame0_grid_position_x;
+    uint8_t  frame0_grid_position_y;
+    uint8_t  frame1_grid_position_x;
+    uint8_t  frame1_grid_position_y;
+    uint8_t  frame_packing_arrangement_reserved_byte;
+    uint16_t frame_packing_arrangement_repetition_period;
+
+    uint8_t  frame_packing_arrangement_extension_flag;
+} H264RawSEIFramePackingArrangement;
+
 typedef struct H264RawSEIDisplayOrientation {
     uint8_t display_orientation_cancel_flag;
     uint8_t hor_flip;
diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 6005d46e0d..0c591871d4 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -1570,6 +1570,12 @@  static const SEIMessageTypeDescriptor cbs_sei_h264_types[] = {
         sizeof(H264RawSEIRecoveryPoint),
         SEI_MESSAGE_RW(h264, sei_recovery_point),
     },
+    {
+        SEI_TYPE_FRAME_PACKING_ARRANGEMENT,
+        1, 0,
+        sizeof(H264RawSEIFramePackingArrangement),
+        SEI_MESSAGE_RW(h264, sei_frame_packing_arrangement),
+    },
     {
         SEI_TYPE_DISPLAY_ORIENTATION,
         1, 0,
diff --git a/libavcodec/cbs_h264_syntax_template.c b/libavcodec/cbs_h264_syntax_template.c
index 9587f33985..e03d41e47a 100644
--- a/libavcodec/cbs_h264_syntax_template.c
+++ b/libavcodec/cbs_h264_syntax_template.c
@@ -719,6 +719,45 @@  static int FUNC(sei_recovery_point)(CodedBitstreamContext *ctx, RWContext *rw,
     return 0;
 }
 
+
+
+static int FUNC(sei_frame_packing_arrangement)
+    (CodedBitstreamContext *ctx, RWContext *rw,
+     H264RawSEIFramePackingArrangement *current, SEIMessageState *sei)
+{
+    int err;
+
+    HEADER("Frame Packing Arrangement");
+
+    ue(frame_packing_arrangement_id, 0, UINT32_MAX - 1);
+    flag(frame_packing_arrangement_cancel_flag);
+
+    if (!current->frame_packing_arrangement_cancel_flag) {
+        u(7, frame_packing_arrangement_type, 0, 7);
+        flag(quincunx_sampling_flag);
+        u(6, content_interpretation_type, 0, 2);
+        flag(spatial_flipping_flag);
+        flag(frame0_flipped_flag);
+        flag(field_views_flag);
+        flag(current_frame_is_frame0_flag);
+        flag(frame0_self_contained_flag);
+        flag(frame1_self_contained_flag);
+        if (!current->quincunx_sampling_flag &&
+            current->frame_packing_arrangement_type != 5) {
+            ub(4, frame0_grid_position_x);
+            ub(4, frame0_grid_position_y);
+            ub(4, frame1_grid_position_x);
+            ub(4, frame1_grid_position_y);
+        }
+        u(8, frame_packing_arrangement_reserved_byte, 0, 0);
+        ue(frame_packing_arrangement_repetition_period, 0, 16384);
+    }
+
+    flag(frame_packing_arrangement_extension_flag);
+
+    return 0;
+}
+
 static int FUNC(sei_display_orientation)(CodedBitstreamContext *ctx, RWContext *rw,
                                          H264RawSEIDisplayOrientation *current,
                                          SEIMessageState *sei)