diff mbox series

[FFmpeg-devel,10/12] lavc/encode: map AVCodecContext.decoded_side_data to coded_side_data

Message ID 20240322202841.31730-10-anton@khirnov.net
State New
Headers show
Series [FFmpeg-devel,01/12] tests/fate/ffmpeg: evaluate thread count in fate-run.sh rather than make | expand

Checks

Context Check Description
yinshiyou/make_fate_loongarch64 success Make fate finished
yinshiyou/make_loongarch64 warning New warnings during build
andriy/make_fate_x86 success Make fate finished
andriy/make_x86 warning New warnings during build

Commit Message

Anton Khirnov March 22, 2024, 8:28 p.m. UTC
This way it can be automagically propagated through the encoder to
muxing.
---
 libavcodec/encode.c          | 23 +++++++++++++++++++++++
 tests/ref/fate/libx265-hdr10 | 24 ++++++++++++------------
 2 files changed, 35 insertions(+), 12 deletions(-)

Comments

James Almer March 23, 2024, 2:33 a.m. UTC | #1
On 3/22/2024 5:28 PM, Anton Khirnov wrote:
> This way it can be automagically propagated through the encoder to
> muxing.
> ---
>   libavcodec/encode.c          | 23 +++++++++++++++++++++++
>   tests/ref/fate/libx265-hdr10 | 24 ++++++++++++------------
>   2 files changed, 35 insertions(+), 12 deletions(-)
> 
> diff --git a/libavcodec/encode.c b/libavcodec/encode.c
> index 7fc9737e93..46e46a055e 100644
> --- a/libavcodec/encode.c
> +++ b/libavcodec/encode.c
> @@ -782,6 +782,29 @@ int ff_encode_preinit(AVCodecContext *avctx)
>               return AVERROR(ENOMEM);
>       }
>   
> +    for (int i = 0; ff_sd_global_map[i].packet < AV_PKT_DATA_NB; i++) {
> +        const enum AVPacketSideDataType type_packet = ff_sd_global_map[i].packet;
> +        const enum AVFrameSideDataType  type_frame  = ff_sd_global_map[i].frame;
> +        const AVFrameSideData *sd_frame;
> +        AVPacketSideData      *sd_packet;
> +
> +        sd_frame = av_frame_side_data_get(avctx->decoded_side_data,
> +                                          avctx->nb_decoded_side_data,
> +                                          type_frame);
> +        if (!sd_frame ||
> +            av_packet_side_data_get(avctx->coded_side_data, avctx->nb_coded_side_data,
> +                                    type_packet))
> +
> +            continue;
> +
> +        sd_packet = av_packet_side_data_new(&avctx->coded_side_data, &avctx->nb_coded_side_data,
> +                                            type_packet, sd_frame->size, 0);
> +        if (!sd_packet)
> +            return AVERROR(ENOMEM);
> +
> +        memcpy(sd_packet->data, sd_frame->data, sd_frame->size);
> +    }
> +
>       if (CONFIG_FRAME_THREAD_ENCODER) {
>           ret = ff_frame_thread_encoder_init(avctx);
>           if (ret < 0)
> diff --git a/tests/ref/fate/libx265-hdr10 b/tests/ref/fate/libx265-hdr10
> index 571c837cac..68511202a5 100644
> --- a/tests/ref/fate/libx265-hdr10
> +++ b/tests/ref/fate/libx265-hdr10
> @@ -1,16 +1,16 @@
>   frames.frame.0.side_data_list.side_data.0.side_data_type="H.26[45] User Data Unregistered SEI message"
> -frames.frame.0.side_data_list.side_data.1.side_data_type="H.26[45] User Data Unregistered SEI message"
> -frames.frame.0.side_data_list.side_data.2.side_data_type="Mastering display metadata"
> -frames.frame.0.side_data_list.side_data.2.red_x="13250/50000"
> -frames.frame.0.side_data_list.side_data.2.red_y="34500/50000"
> -frames.frame.0.side_data_list.side_data.2.green_x="7500/50000"
> -frames.frame.0.side_data_list.side_data.2.green_y="3000/50000"
> -frames.frame.0.side_data_list.side_data.2.blue_x="34000/50000"
> -frames.frame.0.side_data_list.side_data.2.blue_y="16000/50000"
> -frames.frame.0.side_data_list.side_data.2.white_point_x="15635/50000"
> -frames.frame.0.side_data_list.side_data.2.white_point_y="16450/50000"
> -frames.frame.0.side_data_list.side_data.2.min_luminance="50/10000"
> -frames.frame.0.side_data_list.side_data.2.max_luminance="10000000/10000"
> +frames.frame.0.side_data_list.side_data.1.side_data_type="Mastering display metadata"
> +frames.frame.0.side_data_list.side_data.1.red_x="13250/50000"
> +frames.frame.0.side_data_list.side_data.1.red_y="34500/50000"
> +frames.frame.0.side_data_list.side_data.1.green_x="7500/50000"
> +frames.frame.0.side_data_list.side_data.1.green_y="3000/50000"
> +frames.frame.0.side_data_list.side_data.1.blue_x="34000/50000"
> +frames.frame.0.side_data_list.side_data.1.blue_y="16000/50000"
> +frames.frame.0.side_data_list.side_data.1.white_point_x="15635/50000"
> +frames.frame.0.side_data_list.side_data.1.white_point_y="16450/50000"
> +frames.frame.0.side_data_list.side_data.1.min_luminance="50/10000"
> +frames.frame.0.side_data_list.side_data.1.max_luminance="10000000/10000"
> +frames.frame.0.side_data_list.side_data.2.side_data_type="H.26[45] User Data Unregistered SEI message"
>   frames.frame.0.side_data_list.side_data.3.side_data_type="Content light level metadata"
>   frames.frame.0.side_data_list.side_data.3.max_content=1000
>   frames.frame.0.side_data_list.side_data.3.max_average=200

Why does this test change? And is it just the order or side data in the 
output frame?
Anton Khirnov March 23, 2024, 7:20 a.m. UTC | #2
Quoting James Almer (2024-03-23 03:33:13)
> Why does this test change? And is it just the order or side data in the 
> output frame?

Yes, just the order. And the test is being removed, so it doesn't matter
either way.
diff mbox series

Patch

diff --git a/libavcodec/encode.c b/libavcodec/encode.c
index 7fc9737e93..46e46a055e 100644
--- a/libavcodec/encode.c
+++ b/libavcodec/encode.c
@@ -782,6 +782,29 @@  int ff_encode_preinit(AVCodecContext *avctx)
             return AVERROR(ENOMEM);
     }
 
+    for (int i = 0; ff_sd_global_map[i].packet < AV_PKT_DATA_NB; i++) {
+        const enum AVPacketSideDataType type_packet = ff_sd_global_map[i].packet;
+        const enum AVFrameSideDataType  type_frame  = ff_sd_global_map[i].frame;
+        const AVFrameSideData *sd_frame;
+        AVPacketSideData      *sd_packet;
+
+        sd_frame = av_frame_side_data_get(avctx->decoded_side_data,
+                                          avctx->nb_decoded_side_data,
+                                          type_frame);
+        if (!sd_frame ||
+            av_packet_side_data_get(avctx->coded_side_data, avctx->nb_coded_side_data,
+                                    type_packet))
+
+            continue;
+
+        sd_packet = av_packet_side_data_new(&avctx->coded_side_data, &avctx->nb_coded_side_data,
+                                            type_packet, sd_frame->size, 0);
+        if (!sd_packet)
+            return AVERROR(ENOMEM);
+
+        memcpy(sd_packet->data, sd_frame->data, sd_frame->size);
+    }
+
     if (CONFIG_FRAME_THREAD_ENCODER) {
         ret = ff_frame_thread_encoder_init(avctx);
         if (ret < 0)
diff --git a/tests/ref/fate/libx265-hdr10 b/tests/ref/fate/libx265-hdr10
index 571c837cac..68511202a5 100644
--- a/tests/ref/fate/libx265-hdr10
+++ b/tests/ref/fate/libx265-hdr10
@@ -1,16 +1,16 @@ 
 frames.frame.0.side_data_list.side_data.0.side_data_type="H.26[45] User Data Unregistered SEI message"
-frames.frame.0.side_data_list.side_data.1.side_data_type="H.26[45] User Data Unregistered SEI message"
-frames.frame.0.side_data_list.side_data.2.side_data_type="Mastering display metadata"
-frames.frame.0.side_data_list.side_data.2.red_x="13250/50000"
-frames.frame.0.side_data_list.side_data.2.red_y="34500/50000"
-frames.frame.0.side_data_list.side_data.2.green_x="7500/50000"
-frames.frame.0.side_data_list.side_data.2.green_y="3000/50000"
-frames.frame.0.side_data_list.side_data.2.blue_x="34000/50000"
-frames.frame.0.side_data_list.side_data.2.blue_y="16000/50000"
-frames.frame.0.side_data_list.side_data.2.white_point_x="15635/50000"
-frames.frame.0.side_data_list.side_data.2.white_point_y="16450/50000"
-frames.frame.0.side_data_list.side_data.2.min_luminance="50/10000"
-frames.frame.0.side_data_list.side_data.2.max_luminance="10000000/10000"
+frames.frame.0.side_data_list.side_data.1.side_data_type="Mastering display metadata"
+frames.frame.0.side_data_list.side_data.1.red_x="13250/50000"
+frames.frame.0.side_data_list.side_data.1.red_y="34500/50000"
+frames.frame.0.side_data_list.side_data.1.green_x="7500/50000"
+frames.frame.0.side_data_list.side_data.1.green_y="3000/50000"
+frames.frame.0.side_data_list.side_data.1.blue_x="34000/50000"
+frames.frame.0.side_data_list.side_data.1.blue_y="16000/50000"
+frames.frame.0.side_data_list.side_data.1.white_point_x="15635/50000"
+frames.frame.0.side_data_list.side_data.1.white_point_y="16450/50000"
+frames.frame.0.side_data_list.side_data.1.min_luminance="50/10000"
+frames.frame.0.side_data_list.side_data.1.max_luminance="10000000/10000"
+frames.frame.0.side_data_list.side_data.2.side_data_type="H.26[45] User Data Unregistered SEI message"
 frames.frame.0.side_data_list.side_data.3.side_data_type="Content light level metadata"
 frames.frame.0.side_data_list.side_data.3.max_content=1000
 frames.frame.0.side_data_list.side_data.3.max_average=200