[FFmpeg-devel] [PATCH 1/2] avcodec/cbs_sei: add support for Frame Packing Arrangement SEI parsing

James Almer jamrial at gmail.com
Thu Jun 27 02:12:57 EEST 2024


Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavcodec/cbs_h264.h                 | 20 ++++++++++++++++
 libavcodec/cbs_h2645.c                | 22 +++++++++++++----
 libavcodec/cbs_h264_syntax_template.c | 34 +++++++++++++++++++++++++++
 libavcodec/cbs_sei.h                  | 20 ++++++++++++++++
 libavcodec/cbs_sei_syntax_template.c  | 34 +++++++++++++++++++++++++++
 5 files changed, 125 insertions(+), 5 deletions(-)

diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h
index db91231337..3763f2492b 100644
--- a/libavcodec/cbs_h264.h
+++ b/libavcodec/cbs_h264.h
@@ -293,6 +293,26 @@ typedef struct H264RawFilmGrainCharacteristics {
     uint8_t      film_grain_characteristics_repetition_period;
 } H264RawFilmGrainCharacteristics;
 
+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;
+    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 e2389f124e..283925f937 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -2128,6 +2128,12 @@ static const SEIMessageTypeDescriptor cbs_sei_common_types[] = {
         sizeof(SEIRawUserDataUnregistered),
         SEI_MESSAGE_RW(sei, user_data_unregistered),
     },
+    {
+        SEI_TYPE_FRAME_PACKING_ARRANGEMENT,
+        1, 0,
+        sizeof(SEIRawFramePackingArrangement),
+        SEI_MESSAGE_RW(sei, frame_packing_arrangement),
+    },
     {
         SEI_TYPE_MASTERING_DISPLAY_COLOUR_VOLUME,
         1, 0,
@@ -2186,6 +2192,12 @@ static const SEIMessageTypeDescriptor cbs_sei_h264_types[] = {
         sizeof(H264RawFilmGrainCharacteristics),
         SEI_MESSAGE_RW(h264, film_grain_characteristics),
     },
+    {
+        SEI_TYPE_FRAME_PACKING_ARRANGEMENT,
+        1, 0,
+        sizeof(H264RawSEIFramePackingArrangement),
+        SEI_MESSAGE_RW(h264, sei_frame_packing_arrangement),
+    },
     {
         SEI_TYPE_DISPLAY_ORIENTATION,
         1, 0,
@@ -2275,11 +2287,6 @@ const SEIMessageTypeDescriptor *ff_cbs_sei_find_type(CodedBitstreamContext *ctx,
     const SEIMessageTypeDescriptor *codec_list;
     int i;
 
-    for (i = 0; cbs_sei_common_types[i].type >= 0; i++) {
-        if (cbs_sei_common_types[i].type == payload_type)
-            return &cbs_sei_common_types[i];
-    }
-
     switch (ctx->codec->codec_id) {
     case AV_CODEC_ID_H264:
         codec_list = cbs_sei_h264_types;
@@ -2299,5 +2306,10 @@ const SEIMessageTypeDescriptor *ff_cbs_sei_find_type(CodedBitstreamContext *ctx,
             return &codec_list[i];
     }
 
+    for (i = 0; cbs_sei_common_types[i].type >= 0; i++) {
+        if (cbs_sei_common_types[i].type == payload_type)
+            return &cbs_sei_common_types[i];
+    }
+
     return NULL;
 }
diff --git a/libavcodec/cbs_h264_syntax_template.c b/libavcodec/cbs_h264_syntax_template.c
index 4d2d303722..9d0386c24d 100644
--- a/libavcodec/cbs_h264_syntax_template.c
+++ b/libavcodec/cbs_h264_syntax_template.c
@@ -801,6 +801,40 @@ SEI_FUNC(film_grain_characteristics, (CodedBitstreamContext *ctx, RWContext *rw,
     return 0;
 }
 
+SEI_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, MAX_UINT_BITS(31));
+    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);
+        }
+        fixed(8, frame_packing_arrangement_reserved_byte, 0);
+        ue(frame_packing_arrangement_repetition_period, 0, 16384);
+    }
+    flag(frame_packing_arrangement_extension_flag);
+
+    return 0;
+}
+
 SEI_FUNC(sei_display_orientation, (CodedBitstreamContext *ctx, RWContext *rw,
                                    H264RawSEIDisplayOrientation *current,
                                    SEIMessageState *sei))
diff --git a/libavcodec/cbs_sei.h b/libavcodec/cbs_sei.h
index ec7cdb62f0..cc7d6f797d 100644
--- a/libavcodec/cbs_sei.h
+++ b/libavcodec/cbs_sei.h
@@ -43,6 +43,26 @@ typedef struct SEIRawUserDataUnregistered {
     size_t       data_length;
 } SEIRawUserDataUnregistered;
 
+typedef struct SEIRawFramePackingArrangement {
+    uint32_t fp_arrangement_id;
+    uint8_t fp_arrangement_cancel_flag;
+    uint8_t fp_arrangement_type;
+    uint8_t fp_quincunx_sampling_flag;
+    uint8_t fp_content_interpretation_type;
+    uint8_t fp_spatial_flipping_flag;
+    uint8_t fp_frame0_flipped_flag;
+    uint8_t fp_field_views_flag;
+    uint8_t fp_current_frame_is_frame0_flag;
+    uint8_t fp_frame0_self_contained_flag;
+    uint8_t fp_frame1_self_contained_flag;
+    uint8_t fp_frame0_grid_position_x;
+    uint8_t fp_frame0_grid_position_y;
+    uint8_t fp_frame1_grid_position_x;
+    uint8_t fp_frame1_grid_position_y;
+    uint8_t fp_arrangement_persistence_flag;
+    uint8_t fp_upsampled_aspect_ratio_flag;
+} SEIRawFramePackingArrangement;
+
 typedef struct SEIRawMasteringDisplayColourVolume {
     uint16_t display_primaries_x[3];
     uint16_t display_primaries_y[3];
diff --git a/libavcodec/cbs_sei_syntax_template.c b/libavcodec/cbs_sei_syntax_template.c
index 81448ef3f2..03ef9ab473 100644
--- a/libavcodec/cbs_sei_syntax_template.c
+++ b/libavcodec/cbs_sei_syntax_template.c
@@ -94,6 +94,40 @@ SEI_FUNC(user_data_unregistered, (CodedBitstreamContext *ctx, RWContext *rw,
     return 0;
 }
 
+SEI_FUNC(frame_packing_arrangement, (CodedBitstreamContext *ctx, RWContext *rw,
+                                     SEIRawFramePackingArrangement *current,
+                                     SEIMessageState *unused))
+{
+    int err;
+
+    HEADER("Frame Packing Arrangement");
+
+    ue(fp_arrangement_id, 0, MAX_UINT_BITS(31));
+    flag(fp_arrangement_cancel_flag);
+    if (!current->fp_arrangement_cancel_flag) {
+        u(7, fp_arrangement_type, 3, 5);
+        flag(fp_quincunx_sampling_flag);
+        u(6, fp_content_interpretation_type, 0, 2);
+        flag(fp_spatial_flipping_flag);
+        flag(fp_frame0_flipped_flag);
+        flag(fp_field_views_flag);
+        flag(fp_current_frame_is_frame0_flag);
+        flag(fp_frame0_self_contained_flag);
+        flag(fp_frame1_self_contained_flag);
+        if (!current->fp_quincunx_sampling_flag && current->fp_arrangement_type != 5) {
+            ub(4, fp_frame0_grid_position_x);
+            ub(4, fp_frame0_grid_position_y);
+            ub(4, fp_frame1_grid_position_x);
+            ub(4, fp_frame1_grid_position_y);
+        }
+        fixed(8, fp_arrangement_reserved_byte, 0);
+        flag(fp_arrangement_persistence_flag);
+    }
+    flag(fp_upsampled_aspect_ratio_flag);
+
+    return 0;
+}
+
 SEI_FUNC(mastering_display_colour_volume,
          (CodedBitstreamContext *ctx, RWContext *rw,
           SEIRawMasteringDisplayColourVolume *current,
-- 
2.45.2



More information about the ffmpeg-devel mailing list