[FFmpeg-devel] [RFC][PATCH 1/3] v210enc: Refactor side data passthrough

Devin Heitmueller devin.heitmueller at ltnglobal.com
Sat Jul 22 00:30:55 EEST 2023


As the number of side-data items we pass through increases, refactor
the values into a table in the same manner as done in decode.c.

In the future it might make sense to make this a shared function
which can be reused by other encoders.  But for now keep it local.

Signed-off-by: Devin Heitmueller <dheitmueller at ltnglobal.com>
---
 libavcodec/v210enc.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/libavcodec/v210enc.c b/libavcodec/v210enc.c
index 2a30ed7..110d7eb 100644
--- a/libavcodec/v210enc.c
+++ b/libavcodec/v210enc.c
@@ -74,6 +74,13 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     AVFrameSideData *side_data;
     int ret;
     uint8_t *dst;
+    static const struct {
+        enum AVPacketSideDataType packet;
+        enum AVFrameSideDataType frame;
+    } sd[] = {
+        { AV_PKT_DATA_A53_CC,                     AV_FRAME_DATA_A53_CC },
+        { AV_PKT_DATA_AFD,                        AV_FRAME_DATA_AFD },
+    };
 
     ret = ff_get_encode_buffer(avctx, pkt, avctx->height * stride, 0);
     if (ret < 0) {
@@ -87,20 +94,14 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
     else if(pic->format == AV_PIX_FMT_YUV422P)
         v210_enc_8(avctx, dst, pic);
 
-    side_data = av_frame_get_side_data(pic, AV_FRAME_DATA_A53_CC);
-    if (side_data && side_data->size) {
-        uint8_t *buf = av_packet_new_side_data(pkt, AV_PKT_DATA_A53_CC, side_data->size);
-        if (!buf)
-            return AVERROR(ENOMEM);
-        memcpy(buf, side_data->data, side_data->size);
-    }
-
-    side_data = av_frame_get_side_data(pic, AV_FRAME_DATA_AFD);
-    if (side_data && side_data->size) {
-        uint8_t *buf = av_packet_new_side_data(pkt, AV_PKT_DATA_AFD, side_data->size);
-        if (!buf)
-            return AVERROR(ENOMEM);
-        memcpy(buf, side_data->data, side_data->size);
+    for (int i = 0; i < FF_ARRAY_ELEMS(sd); i++) {
+        side_data = av_frame_get_side_data(pic, sd[i].frame);
+        if (side_data && side_data->size) {
+            uint8_t *buf = av_packet_new_side_data(pkt, sd[i].packet, side_data->size);
+            if (!buf)
+                return AVERROR(ENOMEM);
+            memcpy(buf, side_data->data, side_data->size);
+        }
     }
 
     *got_packet = 1;
-- 
1.8.3.1



More information about the ffmpeg-devel mailing list