Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Subject: [FFmpeg-devel] [PATCH 12/20] avcodec/h2645_sei: Attach AVStereo3D side data generically
Date: Sun,  3 Jul 2022 00:21:52 +0200
Message-ID: <DB6PR0101MB2214C44597DC0C9F65DFC1298FBC9@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com> (raw)
In-Reply-To: <DB6PR0101MB2214F50F230E6F64A2428AED8FBC9@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com>

There are only slight differences between H.264 and HEVC
for this side data, so it makes sense to share the code.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/h2645_sei.c  | 64 +++++++++++++++++++++++++++++++++++++++++
 libavcodec/h264_slice.c | 47 ------------------------------
 libavcodec/hevcdec.c    | 36 -----------------------
 3 files changed, 64 insertions(+), 83 deletions(-)

diff --git a/libavcodec/h2645_sei.c b/libavcodec/h2645_sei.c
index 6c7a6ea291..3575846f9a 100644
--- a/libavcodec/h2645_sei.c
+++ b/libavcodec/h2645_sei.c
@@ -28,6 +28,7 @@
 #include "libavutil/display.h"
 #include "libavutil/film_grain_params.h"
 #include "libavutil/pixdesc.h"
+#include "libavutil/stereo3d.h"
 
 #include "atsc_a53.h"
 #include "avcodec.h"
@@ -419,10 +420,73 @@ int ff_h2645_sei_ctx_replace(H2645SEI *dst, const H2645SEI *src)
     return 0;
 }
 
+static int is_frame_packing_type_valid(SEIFpaType type, enum AVCodecID codec_id)
+{
+    if (IS_H264(codec_id))
+        return type <= SEI_FPA_H264_TYPE_2D &&
+               type >= SEI_FPA_H264_TYPE_CHECKERBOARD;
+    else
+        return type <= SEI_FPA_TYPE_INTERLEAVE_TEMPORAL &&
+               type >= SEI_FPA_TYPE_SIDE_BY_SIDE;
+}
+
 int ff_h2645_sei_to_frame(AVFrame *frame, H2645SEI *sei,
                           enum AVCodecID codec_id,
                           AVCodecContext *avctx)
 {
+    H2645SEIFramePacking *fp = &sei->frame_packing;
+
+    if (fp->present &&
+        is_frame_packing_type_valid(fp->arrangement_type, codec_id) &&
+        fp->content_interpretation_type > 0 &&
+        fp->content_interpretation_type < 3) {
+        AVStereo3D *stereo = av_stereo3d_create_side_data(frame);
+
+        if (!stereo)
+            return AVERROR(ENOMEM);
+
+        switch (fp->arrangement_type) {
+#if CONFIG_H264_SEI
+        case SEI_FPA_H264_TYPE_CHECKERBOARD:
+            stereo->type = AV_STEREO3D_CHECKERBOARD;
+            break;
+        case SEI_FPA_H264_TYPE_INTERLEAVE_COLUMN:
+            stereo->type = AV_STEREO3D_COLUMNS;
+            break;
+        case SEI_FPA_H264_TYPE_INTERLEAVE_ROW:
+            stereo->type = AV_STEREO3D_LINES;
+            break;
+#endif
+        case SEI_FPA_TYPE_SIDE_BY_SIDE:
+            if (fp->quincunx_sampling_flag)
+                stereo->type = AV_STEREO3D_SIDEBYSIDE_QUINCUNX;
+            else
+                stereo->type = AV_STEREO3D_SIDEBYSIDE;
+            break;
+        case SEI_FPA_TYPE_TOP_BOTTOM:
+            stereo->type = AV_STEREO3D_TOPBOTTOM;
+            break;
+        case SEI_FPA_TYPE_INTERLEAVE_TEMPORAL:
+            stereo->type = AV_STEREO3D_FRAMESEQUENCE;
+            break;
+#if CONFIG_H264_SEI
+        case SEI_FPA_H264_TYPE_2D:
+            stereo->type = AV_STEREO3D_2D;
+            break;
+#endif
+        }
+
+        if (fp->content_interpretation_type == 2)
+            stereo->flags = AV_STEREO3D_FLAG_INVERT;
+
+        if (fp->arrangement_type == SEI_FPA_TYPE_INTERLEAVE_TEMPORAL) {
+            if (fp->current_frame_is_frame0_flag)
+                stereo->view = AV_STEREO3D_VIEW_LEFT;
+            else
+                stereo->view = AV_STEREO3D_VIEW_RIGHT;
+        }
+    }
+
     if (sei->display_orientation.present &&
         (sei->display_orientation.anticlockwise_rotation ||
          sei->display_orientation.hflip ||
diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c
index cd9f9bfa27..cc8bec8d9b 100644
--- a/libavcodec/h264_slice.c
+++ b/libavcodec/h264_slice.c
@@ -31,7 +31,6 @@
 #include "libavutil/display.h"
 #include "libavutil/film_grain_params.h"
 #include "libavutil/pixdesc.h"
-#include "libavutil/stereo3d.h"
 #include "libavutil/timecode.h"
 #include "internal.h"
 #include "cabac.h"
@@ -1226,52 +1225,6 @@ static int h264_export_frame_props(H264Context *h)
         }
     }
 
-    if (h->sei.common.frame_packing.present &&
-        h->sei.common.frame_packing.arrangement_type <= 6 &&
-        h->sei.common.frame_packing.content_interpretation_type > 0 &&
-        h->sei.common.frame_packing.content_interpretation_type < 3) {
-        H2645SEIFramePacking *fp = &h->sei.common.frame_packing;
-        AVStereo3D *stereo = av_stereo3d_create_side_data(out);
-        if (stereo) {
-        switch (fp->arrangement_type) {
-        case SEI_FPA_H264_TYPE_CHECKERBOARD:
-            stereo->type = AV_STEREO3D_CHECKERBOARD;
-            break;
-        case SEI_FPA_H264_TYPE_INTERLEAVE_COLUMN:
-            stereo->type = AV_STEREO3D_COLUMNS;
-            break;
-        case SEI_FPA_H264_TYPE_INTERLEAVE_ROW:
-            stereo->type = AV_STEREO3D_LINES;
-            break;
-        case SEI_FPA_TYPE_SIDE_BY_SIDE:
-            if (fp->quincunx_sampling_flag)
-                stereo->type = AV_STEREO3D_SIDEBYSIDE_QUINCUNX;
-            else
-                stereo->type = AV_STEREO3D_SIDEBYSIDE;
-            break;
-        case SEI_FPA_TYPE_TOP_BOTTOM:
-            stereo->type = AV_STEREO3D_TOPBOTTOM;
-            break;
-        case SEI_FPA_TYPE_INTERLEAVE_TEMPORAL:
-            stereo->type = AV_STEREO3D_FRAMESEQUENCE;
-            break;
-        case SEI_FPA_H264_TYPE_2D:
-            stereo->type = AV_STEREO3D_2D;
-            break;
-        }
-
-        if (fp->content_interpretation_type == 2)
-            stereo->flags = AV_STEREO3D_FLAG_INVERT;
-
-        if (fp->arrangement_type == SEI_FPA_TYPE_INTERLEAVE_TEMPORAL) {
-            if (fp->current_frame_is_frame0_flag)
-                stereo->view = AV_STEREO3D_VIEW_LEFT;
-            else
-                stereo->view = AV_STEREO3D_VIEW_RIGHT;
-        }
-        }
-    }
-
     if (h->sei.common.afd.present) {
         AVFrameSideData *sd = av_frame_new_side_data(out, AV_FRAME_DATA_AFD,
                                                      sizeof(uint8_t));
diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index 465015069c..fdb8de5b15 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -34,7 +34,6 @@
 #include "libavutil/md5.h"
 #include "libavutil/opt.h"
 #include "libavutil/pixdesc.h"
-#include "libavutil/stereo3d.h"
 #include "libavutil/timecode.h"
 
 #include "bswapdsp.h"
@@ -2731,41 +2730,6 @@ static int set_side_data(HEVCContext *s)
     AVFrame *out = s->ref->frame;
     int ret;
 
-    if (s->sei.common.frame_packing.present &&
-        s->sei.common.frame_packing.arrangement_type >= 3 &&
-        s->sei.common.frame_packing.arrangement_type <= 5 &&
-        s->sei.common.frame_packing.content_interpretation_type > 0 &&
-        s->sei.common.frame_packing.content_interpretation_type < 3) {
-        AVStereo3D *stereo = av_stereo3d_create_side_data(out);
-        if (!stereo)
-            return AVERROR(ENOMEM);
-
-        switch (s->sei.common.frame_packing.arrangement_type) {
-        case 3:
-            if (s->sei.common.frame_packing.quincunx_sampling_flag)
-                stereo->type = AV_STEREO3D_SIDEBYSIDE_QUINCUNX;
-            else
-                stereo->type = AV_STEREO3D_SIDEBYSIDE;
-            break;
-        case 4:
-            stereo->type = AV_STEREO3D_TOPBOTTOM;
-            break;
-        case 5:
-            stereo->type = AV_STEREO3D_FRAMESEQUENCE;
-            break;
-        }
-
-        if (s->sei.common.frame_packing.content_interpretation_type == 2)
-            stereo->flags = AV_STEREO3D_FLAG_INVERT;
-
-        if (s->sei.common.frame_packing.arrangement_type == 5) {
-            if (s->sei.common.frame_packing.current_frame_is_frame0_flag)
-                stereo->view = AV_STEREO3D_VIEW_LEFT;
-            else
-                stereo->view = AV_STEREO3D_VIEW_RIGHT;
-        }
-    }
-
     // Decrement the mastering display flag when IRAP frame has no_rasl_output_flag=1
     // so the side data persists for the entire coded video sequence.
     if (s->sei.mastering_display.present > 0 &&
-- 
2.34.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

  parent reply	other threads:[~2022-07-02 22:23 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-02 22:20 [FFmpeg-devel] [PATCH 01/20] avcodec/hevc_sei: Use proper type for NALU type Andreas Rheinhardt
2022-07-02 22:21 ` [FFmpeg-devel] [PATCH 02/20] avcodec/h264_sei: Don't use GetBit-API for byte-aligned reads Andreas Rheinhardt
2022-07-02 22:21 ` [FFmpeg-devel] [PATCH 03/20] configure: Add (h264|hevc)_sei subsystems Andreas Rheinhardt
2022-07-02 22:21 ` [FFmpeg-devel] [PATCH 04/20] avcodec/sei: Add tag to SEI enumeration Andreas Rheinhardt
2022-07-02 22:21 ` [FFmpeg-devel] [PATCH 05/20] fftools/ffprobe: Improve description of AFD side data Andreas Rheinhardt
2022-07-02 22:21 ` [FFmpeg-devel] [PATCH 06/20] fate/h264: Add Active Format Descriptor test Andreas Rheinhardt
2022-07-02 22:21 ` [FFmpeg-devel] [PATCH 07/20] avcodec/h2645_sei: Factor parsing common SEI messages out Andreas Rheinhardt
2022-07-02 22:21 ` [FFmpeg-devel] [PATCH 08/20] avcodec/h2645_sei: Factor updating H.2645 SEIs out Andreas Rheinhardt
2022-07-02 22:21 ` [FFmpeg-devel] [PATCH 09/20] avcodec/h2645_sei: Factor out freeing common SEI parts Andreas Rheinhardt
2022-07-02 22:21 ` [FFmpeg-devel] [PATCH 10/20] avcodec/h2645_sei: Factor out applying SEIs to frames Andreas Rheinhardt
2022-07-02 22:21 ` [FFmpeg-devel] [PATCH 11/20] avcodec/h264_sei, sei: Make H264_SEI_FpaType generic Andreas Rheinhardt
2022-07-02 22:21 ` Andreas Rheinhardt [this message]
2022-07-02 22:21 ` [FFmpeg-devel] [PATCH 13/20] avcodec/h2645_sei: Also support Active Format Descriptor for HEVC Andreas Rheinhardt
2022-07-02 22:21 ` [FFmpeg-devel] [PATCH 14/20] avcodec/h264_ps: Don't error out on unknown aspect ratio Andreas Rheinhardt
2022-07-02 22:21 ` [FFmpeg-devel] [PATCH 15/20] avcodec/h264data: Deduplicate H.26[45] aspect ratio table Andreas Rheinhardt
2022-07-02 22:21 ` [FFmpeg-devel] [PATCH 16/20] avcodec/hevc_ps: Fix wrong copyright years Andreas Rheinhardt
2022-07-02 22:21 ` [FFmpeg-devel] [PATCH 17/20] avcodec/h264_ps: Don't output invalid chroma location Andreas Rheinhardt
2022-07-02 22:21 ` [FFmpeg-devel] [PATCH 18/20] avcodec/h26[45]_metadata_bsf: Fix range of chroma_sample_loc_type Andreas Rheinhardt
2022-07-02 22:21 ` [FFmpeg-devel] [PATCH 19/20] avcodec/(h264|hevc)_ps: Factor common VUI code out Andreas Rheinhardt
2022-07-02 22:22 ` [FFmpeg-devel] [PATCH 20/20] avcodec/h2645_sei: Factor attaching film grain side-data to frame out Andreas Rheinhardt
2022-07-02 23:28 ` [FFmpeg-devel] [PATCH 01/20] avcodec/hevc_sei: Use proper type for NALU type Soft Works
2022-11-23  3:19   ` Andreas Rheinhardt
2022-11-23  4:15     ` Soft Works
2022-11-23  5:05     ` Soft Works

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DB6PR0101MB2214C44597DC0C9F65DFC1298FBC9@DB6PR0101MB2214.eurprd01.prod.exchangelabs.com \
    --to=andreas.rheinhardt@outlook.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git