[FFmpeg-devel] [PATCH] avformat/framecrcenc: allow setting which side data parameters are printed

James Almer jamrial at gmail.com
Thu Apr 25 17:34:59 EEST 2024


For some side data types, the size is dependent on the arch at runtime, which
is not good for FATE tests.
Add an option to set which parameters may be printed, starting with size.

Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavformat/framecrcenc.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/libavformat/framecrcenc.c b/libavformat/framecrcenc.c
index ce306a6c49..7d0e3978f2 100644
--- a/libavformat/framecrcenc.c
+++ b/libavformat/framecrcenc.c
@@ -23,6 +23,7 @@
 
 #include "libavutil/adler32.h"
 #include "libavutil/avstring.h"
+#include "libavutil/opt.h"
 
 #include "libavcodec/codec_id.h"
 #include "libavcodec/codec_par.h"
@@ -32,6 +33,11 @@
 #include "internal.h"
 #include "mux.h"
 
+struct FrameCRCContext {
+    const AVClass *avclass;
+    int flags;
+};
+
 static int framecrc_write_header(struct AVFormatContext *s)
 {
     int i;
@@ -48,8 +54,11 @@ static int framecrc_write_header(struct AVFormatContext *s)
     return ff_framehash_write_header(s);
 }
 
+#define SD_SIZE 1
+
 static int framecrc_write_packet(struct AVFormatContext *s, AVPacket *pkt)
 {
+    struct FrameCRCContext *c = s->priv_data;
     uint32_t crc = av_adler32_update(0, pkt->data, pkt->size);
     char buf[256];
 
@@ -61,6 +70,7 @@ static int framecrc_write_packet(struct AVFormatContext *s, AVPacket *pkt)
         av_strlcatf(buf, sizeof(buf), ", S=%d", pkt->side_data_elems);
 
         for (int i = 0; i < pkt->side_data_elems; i++) {
+            if (c->flags & SD_SIZE)
             av_strlcatf(buf, sizeof(buf), ", %8"SIZE_SPECIFIER,
                         pkt->side_data[i].size);
         }
@@ -70,11 +80,29 @@ static int framecrc_write_packet(struct AVFormatContext *s, AVPacket *pkt)
     return 0;
 }
 
+#define OFFSET(x) offsetof(struct FrameCRCContext, x)
+#define ENC AV_OPT_FLAG_ENCODING_PARAM
+static const AVOption framecrc_options[] = {
+    { "print_side_data", "set which side data parameters to print", OFFSET(flags),
+        AV_OPT_TYPE_FLAGS, { .i64 = SD_SIZE }, INT_MIN, INT_MAX, ENC, .unit = "flags"},
+    { "size", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = SD_SIZE }, INT_MIN, INT_MAX, ENC, .unit = "flags"},
+    { NULL },
+};
+
+static const AVClass framecrc_class = {
+    .class_name = "framecrc muxer",
+    .item_name  = av_default_item_name,
+    .option     = framecrc_options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
+
 const FFOutputFormat ff_framecrc_muxer = {
     .p.name            = "framecrc",
     .p.long_name       = NULL_IF_CONFIG_SMALL("framecrc testing"),
+    .p.priv_class      = &framecrc_class,
     .p.audio_codec     = AV_CODEC_ID_PCM_S16LE,
     .p.video_codec     = AV_CODEC_ID_RAWVIDEO,
+    .priv_data_size    = sizeof(struct FrameCRCContext),
     .write_header      = framecrc_write_header,
     .write_packet      = framecrc_write_packet,
     .p.flags           = AVFMT_VARIABLE_FPS | AVFMT_TS_NONSTRICT |
-- 
2.44.0



More information about the ffmpeg-devel mailing list