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

Anton Khirnov anton at khirnov.net
Tue Aug 27 18:05:15 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 f0e284bdf6..0b3c56b526 100644
--- a/libavcodec/hevc/hevcdec.c
+++ b/libavcodec/hevc/hevcdec.c
@@ -3991,6 +3991,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 dbedd69aa1..a6a7d7b06c 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"
@@ -172,12 +173,30 @@ int ff_hevc_set_new_ref(HEVCContext *s, HEVCLayerContext *l, int poc)
 
     // 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(&ref->f->side_data, &ref->f->nb_side_data,
                                                      AV_FRAME_DATA_VIEW_ID, sizeof(int),
                                                      AV_FRAME_SIDE_DATA_FLAG_REPLACE);
         if (!sd)
             return AVERROR(ENOMEM);
         *(int*)sd->data = view_id;
+
+        if (tdrdi->num_ref_displays) {
+            AVStereo3D *stereo_3d;
+
+            av_frame_remove_side_data(ref->f, AV_FRAME_DATA_STEREO3D);
+            stereo_3d = av_stereo3d_create_side_data(ref->f);
+            if (!stereo_3d)
+                return AVERROR(ENOMEM);
+
+            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