[FFmpeg-cvslog] avfilter/formats: Don't set samplerate or channel count on video links

Andreas Rheinhardt git at videolan.org
Fri Aug 20 15:33:05 EEST 2021


ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Sun Aug 15 10:15:09 2021 +0200| [4f46c3cf5c78cac303bf4c9877e8544f0e512449] | committer: Andreas Rheinhardt

avfilter/formats: Don't set samplerate or channel count on video links

This currently happens by accident in a few filters that use
ff_set_common_(samplerates|channel_layouts) like afir (if the response
option is set) or agraphmonitor (due to the default code in
avfiltergraph.c). So change those functions to make sure it does no
longer happen.

Reviewed-by: Nicolas George <george at nsup.org>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=4f46c3cf5c78cac303bf4c9877e8544f0e512449
---

 libavfilter/formats.c | 16 ++++++++++------
 libavfilter/formats.h |  6 +++---
 2 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/libavfilter/formats.c b/libavfilter/formats.c
index 8a92ff0d57..1bf7d36195 100644
--- a/libavfilter/formats.c
+++ b/libavfilter/formats.c
@@ -622,14 +622,16 @@ void ff_formats_changeref(AVFilterFormats **oldref, AVFilterFormats **newref)
     FORMATS_CHANGEREF(oldref, newref);
 }
 
-#define SET_COMMON_FORMATS(ctx, fmts, ref_fn, unref_fn)             \
+#define SET_COMMON_FORMATS(ctx, fmts, media_type, ref_fn, unref_fn) \
     int i;                                                          \
                                                                     \
     if (!fmts)                                                      \
         return AVERROR(ENOMEM);                                     \
                                                                     \
     for (i = 0; i < ctx->nb_inputs; i++) {                          \
-        if (ctx->inputs[i] && !ctx->inputs[i]->outcfg.fmts) {       \
+        AVFilterLink *const link = ctx->inputs[i];                  \
+        if (link && !link->outcfg.fmts &&                           \
+            (media_type == AVMEDIA_TYPE_UNKNOWN || link->type == media_type)) { \
             int ret = ref_fn(fmts, &ctx->inputs[i]->outcfg.fmts);   \
             if (ret < 0) {                                          \
                 return ret;                                         \
@@ -637,7 +639,9 @@ void ff_formats_changeref(AVFilterFormats **oldref, AVFilterFormats **newref)
         }                                                           \
     }                                                               \
     for (i = 0; i < ctx->nb_outputs; i++) {                         \
-        if (ctx->outputs[i] && !ctx->outputs[i]->incfg.fmts) {      \
+        AVFilterLink *const link = ctx->outputs[i];                 \
+        if (link && !link->incfg.fmts &&                            \
+            (media_type == AVMEDIA_TYPE_UNKNOWN || link->type == media_type)) { \
             int ret = ref_fn(fmts, &ctx->outputs[i]->incfg.fmts);   \
             if (ret < 0) {                                          \
                 return ret;                                         \
@@ -653,7 +657,7 @@ void ff_formats_changeref(AVFilterFormats **oldref, AVFilterFormats **newref)
 int ff_set_common_channel_layouts(AVFilterContext *ctx,
                                   AVFilterChannelLayouts *channel_layouts)
 {
-    SET_COMMON_FORMATS(ctx, channel_layouts,
+    SET_COMMON_FORMATS(ctx, channel_layouts, AVMEDIA_TYPE_AUDIO,
                        ff_channel_layouts_ref, ff_channel_layouts_unref);
 }
 
@@ -671,7 +675,7 @@ int ff_set_common_all_channel_counts(AVFilterContext *ctx)
 int ff_set_common_samplerates(AVFilterContext *ctx,
                               AVFilterFormats *samplerates)
 {
-    SET_COMMON_FORMATS(ctx, samplerates,
+    SET_COMMON_FORMATS(ctx, samplerates, AVMEDIA_TYPE_AUDIO,
                        ff_formats_ref, ff_formats_unref);
 }
 
@@ -693,7 +697,7 @@ int ff_set_common_all_samplerates(AVFilterContext *ctx)
  */
 int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
 {
-    SET_COMMON_FORMATS(ctx, formats,
+    SET_COMMON_FORMATS(ctx, formats, AVMEDIA_TYPE_UNKNOWN,
                        ff_formats_ref, ff_formats_unref);
 }
 
diff --git a/libavfilter/formats.h b/libavfilter/formats.h
index 7c8258ed08..471cb42bc4 100644
--- a/libavfilter/formats.h
+++ b/libavfilter/formats.h
@@ -129,9 +129,9 @@ av_warn_unused_result
 AVFilterChannelLayouts *ff_make_format64_list(const int64_t *fmts);
 
 /**
- * A helper for query_formats() which sets all links to the same list of channel
- * layouts/sample rates. If there are no links hooked to this filter, the list
- * is freed.
+ * Helpers for query_formats() which set all free audio links to the same list
+ * of channel layouts/sample rates. If there are no links hooked to this list,
+ * the list is freed.
  */
 av_warn_unused_result
 int ff_set_common_channel_layouts(AVFilterContext *ctx,



More information about the ffmpeg-cvslog mailing list