diff mbox series

[FFmpeg-devel] avformat: add a disposition field to AVStreamGroup

Message ID 20240212130535.4528-1-jamrial@gmail.com
State New
Headers show
Series [FFmpeg-devel] avformat: add a disposition field to AVStreamGroup | expand

Checks

Context Check Description
andriy/commit_msg_x86 warning Please wrap lines in the body of the commit message between 60 and 72 characters.
andriy/make_x86 fail Make failed
yinshiyou/commit_msg_loongarch64 warning Please wrap lines in the body of the commit message between 60 and 72 characters.

Commit Message

James Almer Feb. 12, 2024, 1:05 p.m. UTC
The existing (and upcoming) available group types are meant to combine several
streams for presentation, with the result being treated as if it was a stream
itself.
For example, a file could export two stream groups of the same type with one of
them as the "default".

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavformat/avformat.h | 10 +++++
 libavformat/dump.c     | 85 +++++++++++++++++++++++-------------------
 libavformat/options.c  | 45 +++++++++++-----------
 3 files changed, 81 insertions(+), 59 deletions(-)
diff mbox series

Patch

diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 5d0fe82250..e3daf4a107 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -1093,6 +1093,16 @@  typedef struct AVStreamGroup {
      * Freed by libavformat in avformat_free_context().
      */
     AVStream **streams;
+
+    /**
+     * Stream group disposition - a combination of AV_DISPOSITION_* flags.
+     * This field currently applies to all defined AVStreamGroupParamsType.
+     *
+     * - demuxing: set by libavformat when creating the group or in
+     *             avformat_find_stream_info().
+     * - muxing: may be set by the caller before avformat_write_header().
+     */
+    int disposition;
 } AVStreamGroup;
 
 struct AVCodecParserContext *av_stream_get_parser(const AVStream *s);
diff --git a/libavformat/dump.c b/libavformat/dump.c
index 9d37179bb7..9bf1695d96 100644
--- a/libavformat/dump.c
+++ b/libavformat/dump.c
@@ -538,6 +538,46 @@  static void dump_sidedata(void *ctx, const AVStream *st, const char *indent,
     }
 }
 
+static void dump_disposition(int disposition, int log_level)
+{
+    if (disposition & AV_DISPOSITION_DEFAULT)
+        av_log(NULL, log_level, " (default)");
+    if (disposition & AV_DISPOSITION_DUB)
+        av_log(NULL, log_level, " (dub)");
+    if (disposition & AV_DISPOSITION_ORIGINAL)
+        av_log(NULL, log_level, " (original)");
+    if (disposition & AV_DISPOSITION_COMMENT)
+        av_log(NULL, log_level, " (comment)");
+    if (disposition & AV_DISPOSITION_LYRICS)
+        av_log(NULL, log_level, " (lyrics)");
+    if (disposition & AV_DISPOSITION_KARAOKE)
+        av_log(NULL, log_level, " (karaoke)");
+    if (disposition & AV_DISPOSITION_FORCED)
+        av_log(NULL, log_level, " (forced)");
+    if (disposition & AV_DISPOSITION_HEARING_IMPAIRED)
+        av_log(NULL, log_level, " (hearing impaired)");
+    if (disposition & AV_DISPOSITION_VISUAL_IMPAIRED)
+        av_log(NULL, log_level, " (visual impaired)");
+    if (disposition & AV_DISPOSITION_CLEAN_EFFECTS)
+        av_log(NULL, log_level, " (clean effects)");
+    if (disposition & AV_DISPOSITION_ATTACHED_PIC)
+        av_log(NULL, log_level, " (attached pic)");
+    if (disposition & AV_DISPOSITION_TIMED_THUMBNAILS)
+        av_log(NULL, log_level, " (timed thumbnails)");
+    if (disposition & AV_DISPOSITION_CAPTIONS)
+        av_log(NULL, log_level, " (captions)");
+    if (disposition & AV_DISPOSITION_DESCRIPTIONS)
+        av_log(NULL, log_level, " (descriptions)");
+    if (disposition & AV_DISPOSITION_METADATA)
+        av_log(NULL, log_level, " (metadata)");
+    if (disposition & AV_DISPOSITION_DEPENDENT)
+        av_log(NULL, log_level, " (dependent)");
+    if (disposition & AV_DISPOSITION_STILL_IMAGE)
+        av_log(NULL, log_level, " (still image)");
+    if (disposition & AV_DISPOSITION_NON_DIEGETIC)
+        av_log(NULL, log_level, " (non-diegetic)");
+}
+
 /* "user interface" functions */
 static void dump_stream_format(const AVFormatContext *ic, int i,
                                int group_index, int index, int is_output,
@@ -620,42 +660,7 @@  static void dump_stream_format(const AVFormatContext *ic, int i,
             print_fps(1 / av_q2d(st->time_base), "tbn", log_level);
     }
 
-    if (st->disposition & AV_DISPOSITION_DEFAULT)
-        av_log(NULL, log_level, " (default)");
-    if (st->disposition & AV_DISPOSITION_DUB)
-        av_log(NULL, log_level, " (dub)");
-    if (st->disposition & AV_DISPOSITION_ORIGINAL)
-        av_log(NULL, log_level, " (original)");
-    if (st->disposition & AV_DISPOSITION_COMMENT)
-        av_log(NULL, log_level, " (comment)");
-    if (st->disposition & AV_DISPOSITION_LYRICS)
-        av_log(NULL, log_level, " (lyrics)");
-    if (st->disposition & AV_DISPOSITION_KARAOKE)
-        av_log(NULL, log_level, " (karaoke)");
-    if (st->disposition & AV_DISPOSITION_FORCED)
-        av_log(NULL, log_level, " (forced)");
-    if (st->disposition & AV_DISPOSITION_HEARING_IMPAIRED)
-        av_log(NULL, log_level, " (hearing impaired)");
-    if (st->disposition & AV_DISPOSITION_VISUAL_IMPAIRED)
-        av_log(NULL, log_level, " (visual impaired)");
-    if (st->disposition & AV_DISPOSITION_CLEAN_EFFECTS)
-        av_log(NULL, log_level, " (clean effects)");
-    if (st->disposition & AV_DISPOSITION_ATTACHED_PIC)
-        av_log(NULL, log_level, " (attached pic)");
-    if (st->disposition & AV_DISPOSITION_TIMED_THUMBNAILS)
-        av_log(NULL, log_level, " (timed thumbnails)");
-    if (st->disposition & AV_DISPOSITION_CAPTIONS)
-        av_log(NULL, log_level, " (captions)");
-    if (st->disposition & AV_DISPOSITION_DESCRIPTIONS)
-        av_log(NULL, log_level, " (descriptions)");
-    if (st->disposition & AV_DISPOSITION_METADATA)
-        av_log(NULL, log_level, " (metadata)");
-    if (st->disposition & AV_DISPOSITION_DEPENDENT)
-        av_log(NULL, log_level, " (dependent)");
-    if (st->disposition & AV_DISPOSITION_STILL_IMAGE)
-        av_log(NULL, log_level, " (still image)");
-    if (st->disposition & AV_DISPOSITION_NON_DIEGETIC)
-        av_log(NULL, log_level, " (non-diegetic)");
+    dump_disposition(st->disposition, log_level);
     av_log(NULL, log_level, "\n");
 
     dump_metadata(NULL, st->metadata, extra_indent, log_level);
@@ -679,7 +684,9 @@  static void dump_stream_group(const AVFormatContext *ic, uint8_t *printed,
     switch (stg->type) {
     case AV_STREAM_GROUP_PARAMS_IAMF_AUDIO_ELEMENT: {
         const AVIAMFAudioElement *audio_element = stg->params.iamf_audio_element;
-        av_log(NULL, AV_LOG_INFO, " IAMF Audio Element\n");
+        av_log(NULL, AV_LOG_INFO, " IAMF Audio Element:");
+        dump_disposition(st->disposition, log_level);
+        av_log(NULL, AV_LOG_INFO, "\n");
         dump_metadata(NULL, stg->metadata, "    ", AV_LOG_INFO);
         for (int j = 0; j < audio_element->nb_layers; j++) {
             const AVIAMFLayer *layer = audio_element->layers[j];
@@ -700,7 +707,9 @@  static void dump_stream_group(const AVFormatContext *ic, uint8_t *printed,
     }
     case AV_STREAM_GROUP_PARAMS_IAMF_MIX_PRESENTATION: {
         const AVIAMFMixPresentation *mix_presentation = stg->params.iamf_mix_presentation;
-        av_log(NULL, AV_LOG_INFO, " IAMF Mix Presentation\n");
+        av_log(NULL, AV_LOG_INFO, " IAMF Mix Presentation:");
+        dump_disposition(st->disposition, log_level);
+        av_log(NULL, AV_LOG_INFO, "\n");
         dump_metadata(NULL, stg->metadata, "    ", AV_LOG_INFO);
         dump_dictionary(NULL, mix_presentation->annotations, "Annotations", "    ", AV_LOG_INFO);
         for (int j = 0; j < mix_presentation->nb_submixes; j++) {
diff --git a/libavformat/options.c b/libavformat/options.c
index 03e6a2a7ff..f54a3c97b5 100644
--- a/libavformat/options.c
+++ b/libavformat/options.c
@@ -208,28 +208,30 @@  const AVClass *avformat_get_class(void)
     return &av_format_context_class;
 }
 
-static const AVOption stream_options[] = {
-    { "disposition", NULL, offsetof(AVStream, disposition), AV_OPT_TYPE_FLAGS, { .i64 = 0 },
-        .flags = AV_OPT_FLAG_ENCODING_PARAM, .unit = "disposition" },
-        { "default",            .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DEFAULT           },    .unit = "disposition" },
-        { "dub",                .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DUB               },    .unit = "disposition" },
-        { "original",           .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_ORIGINAL          },    .unit = "disposition" },
-        { "comment",            .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_COMMENT           },    .unit = "disposition" },
-        { "lyrics",             .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_LYRICS            },    .unit = "disposition" },
-        { "karaoke",            .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_KARAOKE           },    .unit = "disposition" },
-        { "forced",             .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_FORCED            },    .unit = "disposition" },
-        { "hearing_impaired",   .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_HEARING_IMPAIRED  },    .unit = "disposition" },
-        { "visual_impaired",    .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_VISUAL_IMPAIRED   },    .unit = "disposition" },
-        { "clean_effects",      .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_CLEAN_EFFECTS     },    .unit = "disposition" },
-        { "attached_pic",       .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_ATTACHED_PIC      },    .unit = "disposition" },
-        { "timed_thumbnails",   .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_TIMED_THUMBNAILS  },    .unit = "disposition" },
-        { "non_diegetic",       .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_NON_DIEGETIC      },    .unit = "disposition" },
-        { "captions",           .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_CAPTIONS          },    .unit = "disposition" },
-        { "descriptions",       .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DESCRIPTIONS      },    .unit = "disposition" },
-        { "metadata",           .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_METADATA          },    .unit = "disposition" },
-        { "dependent",          .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DEPENDENT         },    .unit = "disposition" },
-        { "still_image",        .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_STILL_IMAGE       },    .unit = "disposition" },
+#define DISPOSITION_OPT(ctx)                                                                                                        \
+    { "disposition", NULL, offsetof(ctx, disposition), AV_OPT_TYPE_FLAGS, { .i64 = 0 },                                             \
+        .flags = AV_OPT_FLAG_ENCODING_PARAM, .unit = "disposition" },                                                               \
+        { "default",            .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DEFAULT           },    .unit = "disposition" }, \
+        { "dub",                .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DUB               },    .unit = "disposition" }, \
+        { "original",           .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_ORIGINAL          },    .unit = "disposition" }, \
+        { "comment",            .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_COMMENT           },    .unit = "disposition" }, \
+        { "lyrics",             .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_LYRICS            },    .unit = "disposition" }, \
+        { "karaoke",            .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_KARAOKE           },    .unit = "disposition" }, \
+        { "forced",             .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_FORCED            },    .unit = "disposition" }, \
+        { "hearing_impaired",   .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_HEARING_IMPAIRED  },    .unit = "disposition" }, \
+        { "visual_impaired",    .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_VISUAL_IMPAIRED   },    .unit = "disposition" }, \
+        { "clean_effects",      .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_CLEAN_EFFECTS     },    .unit = "disposition" }, \
+        { "attached_pic",       .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_ATTACHED_PIC      },    .unit = "disposition" }, \
+        { "timed_thumbnails",   .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_TIMED_THUMBNAILS  },    .unit = "disposition" }, \
+        { "non_diegetic",       .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_NON_DIEGETIC      },    .unit = "disposition" }, \
+        { "captions",           .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_CAPTIONS          },    .unit = "disposition" }, \
+        { "descriptions",       .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DESCRIPTIONS      },    .unit = "disposition" }, \
+        { "metadata",           .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_METADATA          },    .unit = "disposition" }, \
+        { "dependent",          .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_DEPENDENT         },    .unit = "disposition" }, \
+        { "still_image",        .type = AV_OPT_TYPE_CONST, { .i64 = AV_DISPOSITION_STILL_IMAGE       },    .unit = "disposition" }
 
+static const AVOption stream_options[] = {
+    DISPOSITION_OPT(AVStream),
     { "discard", NULL, offsetof(AVStream, discard), AV_OPT_TYPE_INT, { .i64 = AVDISCARD_DEFAULT }, INT_MIN, INT_MAX,
         .flags = AV_OPT_FLAG_DECODING_PARAM, .unit = "avdiscard" },
         { "none",               .type = AV_OPT_TYPE_CONST, {.i64 = AVDISCARD_NONE     }, .unit = "avdiscard" },
@@ -380,6 +382,7 @@  static const AVClass *stream_group_child_iterate(void **opaque)
 }
 
 static const AVOption stream_group_options[] = {
+    DISPOSITION_OPT(AVStreamGroup),
     {"id", "Set group id", offsetof(AVStreamGroup, id), AV_OPT_TYPE_INT64, {.i64 = 0}, 0, INT64_MAX, AV_OPT_FLAG_ENCODING_PARAM },
     { NULL }
 };