[FFmpeg-devel] [PATCH 6/6] avcodec/hevc/hevcdec: export 3D Reference Displays side data

James Almer jamrial at gmail.com
Fri Jan 31 16:00:20 EET 2025


Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavcodec/hevc/hevcdec.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 7d3e844945..91119fbc58 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -36,6 +36,7 @@
 #include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
 #include "libavutil/stereo3d.h"
+#include "libavutil/tdrdi.h"
 #include "libavutil/timecode.h"
 
 #include "aom_film_grain.h"
@@ -416,6 +417,42 @@ FF_ENABLE_DEPRECATION_WARNINGS
         avctx->color_trc = s->sei.common.alternative_transfer.preferred_transfer_characteristics;
     }
 
+    if (s->sei.tdrdi.num_ref_displays) {
+        const HEVCSEITDRDI *sei = &s->sei.tdrdi;
+        size_t size;
+        AV3DReferenceDisplaysInfo *tdrdi = av_tdrdi_alloc(&size);
+
+        if (!tdrdi)
+            return AVERROR(ENOMEM);
+
+        tdrdi->prec_ref_display_width = sei->prec_ref_display_width;
+        tdrdi->ref_viewing_distance_flag = sei->ref_viewing_distance_flag;
+        tdrdi->prec_ref_viewing_dist = sei->prec_ref_viewing_dist;
+        tdrdi->num_ref_displays = sei->num_ref_displays;
+        memcpy(tdrdi->left_view_id,
+                 sei->left_view_id, sizeof(tdrdi->left_view_id));
+        memcpy(tdrdi->right_view_id,
+                 sei->right_view_id, sizeof(tdrdi->right_view_id));
+        memcpy(tdrdi->exponent_ref_display_width,
+                 sei->exponent_ref_display_width, sizeof(tdrdi->exponent_ref_display_width));
+        memcpy(tdrdi->mantissa_ref_display_width,
+                 sei->mantissa_ref_display_width, sizeof(tdrdi->mantissa_ref_display_width));
+        memcpy(tdrdi->exponent_ref_viewing_distance,
+                 sei->exponent_ref_viewing_distance, sizeof(tdrdi->exponent_ref_viewing_distance));
+        memcpy(tdrdi->mantissa_ref_viewing_distance,
+                 sei->mantissa_ref_viewing_distance, sizeof(tdrdi->mantissa_ref_viewing_distance));
+        memcpy(tdrdi->additional_shift_present_flag,
+                 sei->additional_shift_present_flag, sizeof(tdrdi->additional_shift_present_flag));
+        memcpy(tdrdi->num_sample_shift,
+                 sei->num_sample_shift, sizeof(tdrdi->num_sample_shift));
+
+        if (!av_packet_side_data_add(&avctx->coded_side_data, &avctx->nb_coded_side_data,
+                                     AV_PKT_DATA_3D_REFERENCE_DISPLAYS, tdrdi, size, 0)) {
+            av_free(tdrdi);
+            return AVERROR(ENOMEM);
+        }
+    }
+
 #if FF_API_CODEC_PROPS
 FF_DISABLE_DEPRECATION_WARNINGS
     if ((s->sei.common.film_grain_characteristics && s->sei.common.film_grain_characteristics->present) ||
-- 
2.48.1



More information about the ffmpeg-devel mailing list