[FFmpeg-devel] [PATCH 16/23] avcodec/hevc/refs: export Stereo 3D side data

Anton Khirnov anton at khirnov.net
Sat Sep 14 13:45:41 EEST 2024


From: James Almer <jamrial at gmail.com>

Use the 3D Reference Displays Info SEI message to link a view_id with
an eye.

Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavcodec/hevc/hevcdec.c |  1 +
 libavcodec/hevc/refs.c    | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/libavcodec/hevc/hevcdec.c b/libavcodec/hevc/hevcdec.c
index 692f19e97e..b784b10bcf 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -3968,6 +3968,7 @@ static int hevc_update_thread_context(AVCodecContext *dst,
     s->sei.common.mastering_display    = s0->sei.common.mastering_display;
     s->sei.common.content_light        = s0->sei.common.content_light;
     s->sei.common.aom_film_grain       = s0->sei.common.aom_film_grain;
+    s->sei.tdrdi                       = s0->sei.tdrdi;
 
     return 0;
 }
diff --git a/libavcodec/hevc/refs.c b/libavcodec/hevc/refs.c
index b9b08ca416..ac1b07a308 100644
--- a/libavcodec/hevc/refs.c
+++ b/libavcodec/hevc/refs.c
@@ -22,6 +22,7 @@
  */
 
 #include "libavutil/mem.h"
+#include "libavutil/stereo3d.h"
 
 #include "container_fifo.h"
 #include "decode.h"
@@ -94,6 +95,7 @@ static HEVCFrame *alloc_frame(HEVCContext *s, HEVCLayerContext *l)
 
         // add view ID side data if it's nontrivial
         if (vps->nb_layers > 1 || view_id) {
+            HEVCSEITDRDI *tdrdi = &s->sei.tdrdi;
             AVFrameSideData *sd = av_frame_side_data_new(&frame->f->side_data,
                                                          &frame->f->nb_side_data,
                                                          AV_FRAME_DATA_VIEW_ID,
@@ -101,6 +103,23 @@ static HEVCFrame *alloc_frame(HEVCContext *s, HEVCLayerContext *l)
             if (!sd)
                 goto fail;
             *(int*)sd->data = view_id;
+
+            if (tdrdi->num_ref_displays) {
+                AVStereo3D *stereo_3d;
+
+                av_frame_remove_side_data(frame->f, AV_FRAME_DATA_STEREO3D);
+                stereo_3d = av_stereo3d_create_side_data(frame->f);
+                if (!stereo_3d)
+                    goto fail;
+
+                stereo_3d->type = AV_STEREO3D_FRAMESEQUENCE;
+                if (tdrdi->left_view_id[0] == view_id)
+                    stereo_3d->view = AV_STEREO3D_VIEW_LEFT;
+                else if (tdrdi->right_view_id[0] == view_id)
+                    stereo_3d->view = AV_STEREO3D_VIEW_RIGHT;
+                else
+                    stereo_3d->view = AV_STEREO3D_VIEW_UNSPEC;
+            }
         }
 
         if (!(s->layers_active_output & (1 << s->cur_layer)))
-- 
2.43.0



More information about the ffmpeg-devel mailing list