[FFmpeg-devel] [PATCH 4/4] avcodec/cbs_h265: add support for 3D Reference Displays Information SEI

James Almer jamrial at gmail.com
Sat Jul 13 17:58:46 EEST 2024


Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavcodec/cbs_h2645.c                |  6 ++++
 libavcodec/cbs_h265.h                 | 16 ++++++++++
 libavcodec/cbs_h265_syntax_template.c | 42 +++++++++++++++++++++++++++
 3 files changed, 64 insertions(+)

diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c
index 828e56b8c0..d73d77a985 100644
--- a/libavcodec/cbs_h2645.c
+++ b/libavcodec/cbs_h2645.c
@@ -2275,6 +2275,12 @@ static const SEIMessageTypeDescriptor cbs_sei_h265_types[] = {
         sizeof(H265RawSEIAlphaChannelInfo),
         SEI_MESSAGE_RW(h265, sei_alpha_channel_info),
     },
+    {
+        SEI_TYPE_THREE_DIMENSIONAL_REFERENCE_DISPLAYS_INFO,
+        1, 0,
+        sizeof(H265RawSEI3DReferenceDisplaysInfo),
+        SEI_MESSAGE_RW(h265, sei_3d_reference_displays_info),
+    },
     SEI_MESSAGE_TYPE_END
 };
 
diff --git a/libavcodec/cbs_h265.h b/libavcodec/cbs_h265.h
index afb942ced5..52631f9bfb 100644
--- a/libavcodec/cbs_h265.h
+++ b/libavcodec/cbs_h265.h
@@ -715,6 +715,22 @@ typedef struct H265RawSEIAlphaChannelInfo {
     uint8_t  alpha_channel_clip_type_flag;
 } H265RawSEIAlphaChannelInfo;
 
+typedef struct H265RawSEI3DReferenceDisplaysInfo {
+    uint8_t prec_ref_display_width;
+    uint8_t ref_viewing_distance_flag;
+    uint8_t prec_ref_viewing_dist;
+    uint8_t num_ref_displays_minus1;
+    uint8_t left_view_id[31];
+    uint8_t right_view_id[31];
+    uint8_t exponent_ref_display_width[31];
+    uint8_t mantissa_ref_display_width[31];
+    uint8_t exponent_ref_viewing_distance[31];
+    uint8_t mantissa_ref_viewing_distance[31];
+    uint8_t additional_shift_present_flag[31];
+    uint16_t num_sample_shift_plus512[31];
+    uint8_t three_dimensional_reference_displays_extension_flag;
+} H265RawSEI3DReferenceDisplaysInfo;
+
 typedef struct H265RawSEI {
     H265RawNALUnitHeader nal_unit_header;
     SEIRawMessageList    message_list;
diff --git a/libavcodec/cbs_h265_syntax_template.c b/libavcodec/cbs_h265_syntax_template.c
index 1826950e8e..ee01b5e0d0 100644
--- a/libavcodec/cbs_h265_syntax_template.c
+++ b/libavcodec/cbs_h265_syntax_template.c
@@ -2189,6 +2189,48 @@ SEI_FUNC(sei_alpha_channel_info, (CodedBitstreamContext *ctx, RWContext *rw,
     return 0;
 }
 
+SEI_FUNC(sei_3d_reference_displays_info, (CodedBitstreamContext *ctx, RWContext *rw,
+                                          H265RawSEI3DReferenceDisplaysInfo *current,
+                                          SEIMessageState *sei))
+{
+    int length;
+    int err, i;
+
+    HEADER("Three Dimensional Reference Displays Information");
+
+    ue(prec_ref_display_width, 0, 31);
+    flag(ref_viewing_distance_flag);
+    if (current->ref_viewing_distance_flag)
+        ue(prec_ref_viewing_dist, 0, 31);
+    ue(num_ref_displays_minus1, 0, 31);
+    for (i = 0; i <= current->num_ref_displays_minus1; i++) {
+        ues(left_view_id[i], 0, UINT8_MAX, 1, i);
+        ues(right_view_id[i], 0, UINT8_MAX, 1, i);
+        us(6, exponent_ref_display_width[i], 0, 62, 1, i);
+        if (!current->exponent_ref_display_width[i])
+            length = FFMAX(0, (int)current->prec_ref_display_width - 30);
+        else
+            length = FFMAX(0, (int)current->exponent_ref_display_width[i] +
+                              (int)current->prec_ref_display_width - 31);
+        ubs(length, mantissa_ref_display_width[i], 1, i);
+        if (current->ref_viewing_distance_flag) {
+            us(6, exponent_ref_viewing_distance[i], 0, 62, 1, i);
+            if (!current->exponent_ref_viewing_distance[i])
+                length = FFMAX(0, (int)current->prec_ref_viewing_dist - 30);
+            else
+                length = FFMAX(0, (int)current->exponent_ref_viewing_distance[i] +
+                                  (int)current->prec_ref_viewing_dist - 31);
+            ubs(length, mantissa_ref_viewing_distance[i], 1, i);
+        }
+        flags(additional_shift_present_flag[i], 1, i);
+        if (current->additional_shift_present_flag[i])
+            us(10, num_sample_shift_plus512[i], 0, 1023, 1, i);
+    }
+    flag(three_dimensional_reference_displays_extension_flag);
+
+    return 0;
+}
+
 static int FUNC(sei)(CodedBitstreamContext *ctx, RWContext *rw,
                      H265RawSEI *current, int prefix)
 {
-- 
2.45.2



More information about the ffmpeg-devel mailing list