[FFmpeg-devel] [PATCH 4/9] lavfi/sink_buffer: accept unknown channel layouts.

Nicolas George nicolas.george at normalesup.org
Wed Dec 26 18:28:15 CET 2012


Add a field to the AVBufferSinkParams for a list of accepted
channel counts.
Change the default value for the lists in AVBufferSinkParams
to NULL, to let lavfi fill them with something useful.

Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
 libavfilter/buffersink.h  |    1 +
 libavfilter/sink_buffer.c |   33 +++++++++++++++++++++++++--------
 2 files changed, 26 insertions(+), 8 deletions(-)

diff --git a/libavfilter/buffersink.h b/libavfilter/buffersink.h
index a401937..8fdf113 100644
--- a/libavfilter/buffersink.h
+++ b/libavfilter/buffersink.h
@@ -46,6 +46,7 @@ AVBufferSinkParams *av_buffersink_params_alloc(void);
 typedef struct {
     const enum AVSampleFormat *sample_fmts; ///< list of allowed sample formats, terminated by AV_SAMPLE_FMT_NONE
     const int64_t *channel_layouts;         ///< list of allowed channel layouts, terminated by -1
+    const int *channels;                    ///< list of allowed channel counts, terminated by -1
 } AVABufferSinkParams;
 
 /**
diff --git a/libavfilter/sink_buffer.c b/libavfilter/sink_buffer.c
index 88fefba..693db6f 100644
--- a/libavfilter/sink_buffer.c
+++ b/libavfilter/sink_buffer.c
@@ -44,15 +44,10 @@ AVBufferSinkParams *av_buffersink_params_alloc(void)
 
 AVABufferSinkParams *av_abuffersink_params_alloc(void)
 {
-    static const int sample_fmts[] = { AV_SAMPLE_FMT_NONE };
-    static const int64_t channel_layouts[] = { -1 };
-    AVABufferSinkParams *params = av_malloc(sizeof(AVABufferSinkParams));
+    AVABufferSinkParams *params = av_calloc(1, sizeof(AVABufferSinkParams));
 
     if (!params)
         return NULL;
-
-    params->sample_fmts = sample_fmts;
-    params->channel_layouts = channel_layouts;
     return params;
 }
 
@@ -284,6 +279,27 @@ static int filter_frame(AVFilterLink *link, AVFilterBufferRef *samplesref)
     return 0;
 }
 
+static int64_t *concat_channels_lists(const int64_t *layouts, const int *counts)
+{
+    int nb_layouts = 0, nb_counts = 0, i;
+    int64_t *list;
+
+    if (layouts)
+        for (; layouts[nb_layouts] != -1; nb_layouts++);
+    if (counts)
+        for (; counts[nb_counts] != -1; nb_counts++);
+    if (nb_counts > INT_MAX - 1 - nb_layouts)
+        return NULL;
+    if (!(list = av_calloc(nb_layouts + nb_counts + 1, sizeof(*list))))
+        return NULL;
+    for (i = 0; i < nb_layouts; i++)
+        list[i] = layouts[i];
+    for (i = 0; i < nb_counts; i++)
+        list[nb_layouts + i] = AV_CH_LAYOUT_UNKNOWN | counts[i];
+    list[nb_layouts + nb_counts] = -1;
+    return list;
+}
+
 static av_cold int asink_init(AVFilterContext *ctx, const char *args, void *opaque)
 {
     BufferSinkContext *buf = ctx->priv;
@@ -294,8 +310,9 @@ static av_cold int asink_init(AVFilterContext *ctx, const char *args, void *opaq
         if (!buf->sample_fmts)
             goto fail_enomem;
     }
-    if (params && params->channel_layouts) {
-        buf->channel_layouts = ff_copy_int64_list(params->channel_layouts);
+    if (params && (params->channel_layouts || params->channels)) {
+        buf->channel_layouts = concat_channels_lists(params->channel_layouts,
+                                                     params->channels);
         if (!buf->channel_layouts)
             goto fail_enomem;
     }
-- 
1.7.10.4



More information about the ffmpeg-devel mailing list