diff options
author | Nicolas George <nicolas.george@normalesup.org> | 2012-12-26 16:49:16 +0100 |
---|---|---|
committer | Nicolas George <nicolas.george@normalesup.org> | 2013-01-26 11:15:38 +0100 |
commit | 19506af788b64c509dad76f37e0a0da63ef34e44 (patch) | |
tree | 6ce4056232fc4a1f8d8cd5910f4752c6f2394314 /libavfilter | |
parent | b6b2f3433c217b01c75729df0e316d525cd8d804 (diff) | |
download | ffmpeg-streaming-19506af788b64c509dad76f37e0a0da63ef34e44.zip ffmpeg-streaming-19506af788b64c509dad76f37e0a0da63ef34e44.tar.gz |
lavfi/sink_buffer: accept unknown channel layouts.
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.
The fail_enomem path is unneeded because filters are uninited
on failure.
Diffstat (limited to 'libavfilter')
-rw-r--r-- | libavfilter/buffersink.h | 2 | ||||
-rw-r--r-- | libavfilter/sink_buffer.c | 63 |
2 files changed, 44 insertions, 21 deletions
diff --git a/libavfilter/buffersink.h b/libavfilter/buffersink.h index a401937..825a36a 100644 --- a/libavfilter/buffersink.h +++ b/libavfilter/buffersink.h @@ -46,6 +46,8 @@ 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 *channel_counts; ///< list of allowed channel counts, terminated by -1 + int all_channel_counts; ///< if not 0, accept any channel count or layout } AVABufferSinkParams; /** diff --git a/libavfilter/sink_buffer.c b/libavfilter/sink_buffer.c index a34cb24..0edf9c5 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_mallocz(sizeof(AVABufferSinkParams)); if (!params) return NULL; - - params->sample_fmts = sample_fmts; - params->channel_layouts = channel_layouts; return params; } @@ -66,6 +61,7 @@ typedef struct { /* only used for audio */ enum AVSampleFormat *sample_fmts; ///< list of accepted sample formats, terminated by AV_SAMPLE_FMT_NONE int64_t *channel_layouts; ///< list of accepted channel layouts, terminated by -1 + int all_channel_counts; } BufferSinkContext; #define FIFO_INIT_SIZE 8 @@ -276,6 +272,27 @@ AVFilter avfilter_vsink_buffersink = { .outputs = NULL, }; +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] = FF_COUNT2LAYOUT(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; @@ -284,20 +301,22 @@ static av_cold int asink_init(AVFilterContext *ctx, const char *args, void *opaq if (params && params->sample_fmts) { buf->sample_fmts = ff_copy_int_list (params->sample_fmts); if (!buf->sample_fmts) - goto fail_enomem; + return AVERROR(ENOMEM); } - if (params && params->channel_layouts) { - buf->channel_layouts = ff_copy_int64_list(params->channel_layouts); + if (params && (params->channel_layouts || params->channel_counts)) { + if (params->all_channel_counts) { + av_log(ctx, AV_LOG_ERROR, + "Conflicting all_channel_counts and list in parameters\n"); + return AVERROR(EINVAL); + } + buf->channel_layouts = concat_channels_lists(params->channel_layouts, + params->channel_counts); if (!buf->channel_layouts) - goto fail_enomem; + return AVERROR(ENOMEM); } - if (!common_init(ctx)) - return 0; - -fail_enomem: - av_freep(&buf->sample_fmts); - av_freep(&buf->channel_layouts); - return AVERROR(ENOMEM); + if (params) + buf->all_channel_counts = params->all_channel_counts; + return common_init(ctx); } static av_cold void asink_uninit(AVFilterContext *ctx) @@ -321,10 +340,12 @@ static int asink_query_formats(AVFilterContext *ctx) ff_set_common_formats(ctx, formats); } - if (buf->channel_layouts) { - if (!(layouts = avfilter_make_format64_list(buf->channel_layouts))) - return AVERROR(ENOMEM); - ff_set_common_channel_layouts(ctx, layouts); + if (buf->channel_layouts || buf->all_channel_counts) { + layouts = buf->all_channel_counts ? ff_all_channel_counts() : + avfilter_make_format64_list(buf->channel_layouts); + if (!layouts) + return AVERROR(ENOMEM); + ff_set_common_channel_layouts(ctx, layouts); } return 0; |