On 5/17/17 7:47 PM, Vittorio Giovara wrote:
> Signed-off-by: Vittorio Giovara <[email protected]>
> ---
> libavfilter/af_aformat.c | 28 +++++++++----
> libavfilter/af_channelmap.c | 2 +-
> libavfilter/af_channelsplit.c | 6 ++-
> libavfilter/af_join.c | 2 +-
> libavfilter/avfiltergraph.c | 97
> ++++++++++++++++++++++++++++++-------------
> libavfilter/buffersrc.c | 2 +-
> libavfilter/formats.c | 45 ++++++++++++++++++--
> libavfilter/formats.h | 4 +-
> 8 files changed, 138 insertions(+), 48 deletions(-)
>
It looks fine assuming you put uninit on copy as mentioned before, some
more below:
> static av_cold int init(AVFilterContext *ctx)
> {
> AFormatContext *s = ctx->priv;
> @@ -109,8 +102,25 @@ static av_cold int init(AVFilterContext *ctx)
> ff_add_format, av_get_sample_fmt, AV_SAMPLE_FMT_NONE,
> "sample format");
> PARSE_FORMATS(s->sample_rates_str, int, s->sample_rates, ff_add_format,
> get_sample_rate, 0, "sample rate");
> - PARSE_FORMATS(s->channel_layouts_str, uint64_t, s->channel_layouts,
> - ff_add_channel_layout, get_channel_layout, 0, "channel
> layout");
> + {
make it a function
> + char *next, *cur = s->channel_layouts_str, sep = '|';
> + int ret;
> + while (cur) {
> + AVChannelLayout fmt = {0};
> + next = strchr(cur, sep);
> + if (next)
> + *next++ = 0;
> +
> + ret = av_channel_layout_from_string(&fmt, cur);
> + if (ret < 0) {
> + av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout:
> %s.\n", cur);\
> + return ret;
> + }
> + ff_add_channel_layout(&s->channel_layouts, &fmt);
> +
> + cur = next;
> + }
> + }
>
> return 0;
> ff_formats_unref(&link->in_formats);
> @@ -459,8 +465,40 @@ static int reduce_formats_on_filter(AVFilterContext
> *filter)
> nb_formats, ff_add_format);
> REDUCE_FORMATS(int, AVFilterFormats, samplerates,
> formats,
> nb_formats, ff_add_format);
> - REDUCE_FORMATS(uint64_t, AVFilterChannelLayouts, channel_layouts,
> - channel_layouts, nb_channel_layouts,
> ff_add_channel_layout);
> +
make the following code a function as well
> + for (i = 0; i < filter->nb_inputs; i++) {
> + AVFilterLink *link = filter->inputs[i];
> + AVChannelLayout *fmt;
> +
> + if (!link->out_channel_layouts ||
> link->out_channel_layouts->nb_channel_layouts != 1)
> + continue;
> + fmt = &link->out_channel_layouts->channel_layouts[0];
> +
> + for (j = 0; j < filter->nb_outputs; j++) {
> + AVFilterLink *out_link = filter->outputs[j];
> + AVFilterChannelLayouts *fmts;
> +
> + if (link->type != out_link->type ||
> + out_link->in_channel_layouts->nb_channel_layouts == 1)
> + continue;
> + fmts = out_link->in_channel_layouts;
> +
> + if (!out_link->in_channel_layouts->nb_channel_layouts) {
> + ff_add_channel_layout(&out_link->in_channel_layouts, fmt);
> + break;
> + }
> +
> + for (k = 0; k <
> out_link->in_channel_layouts->nb_channel_layouts; k++)
> + if (!av_channel_layout_compare(&fmts->channel_layouts[k],
> fmt)) {
> + ret = av_channel_layout_copy(&fmts->channel_layouts[0],
> fmt);
> + if (ret < 0)
> + return ret;
> + fmts->nb_channel_layouts = 1;
> + ret = 1;
> + break;
> + }
> + }
> + }
>
> diff --git a/libavfilter/formats.c b/libavfilter/formats.c
> index 7b5a93c325..251df0d721 100644
> --- a/libavfilter/formats.c
> +++ b/libavfilter/formats.c
> @@ -131,8 +131,31 @@ AVFilterChannelLayouts
> *ff_merge_channel_layouts(AVFilterChannelLayouts *a,
> if (a == b) return a;
>
> if (a->nb_channel_layouts && b->nb_channel_layouts) {
> - MERGE_FORMATS(ret, a, b, channel_layouts, nb_channel_layout> -
> AVFilterChannelLayouts, fail);
same thing here
> + int i, j, k = 0, count = FFMIN(a->nb_channel_layouts,
> b->nb_channel_layouts);
> +
> + if (!(ret = av_mallocz(sizeof(*ret))))
> + goto fail;
> +
> + if (count) {
> + if (!(ret->channel_layouts =
> av_malloc(sizeof(*ret->channel_layouts) * count)))
> + goto fail;
> + for (i = 0; i < a->nb_channel_layouts; i++)
> + for (j = 0; j < b->nb_channel_layouts; j++)
> + if (!av_channel_layout_compare(&a->channel_layouts[i],
> + &b->channel_layouts[j]))
> + if
> (av_channel_layout_copy(&ret->channel_layouts[k++],
> + &a->channel_layouts[i]) <
> 0)
> + goto fail;
> +
> + ret->nb_channel_layouts = k;
> + }
> + /* check that there was at least one common format */
> + if (!ret->nb_channel_layouts)
> + goto fail;
> +
> + MERGE_REF(ret, a, channel_layouts, AVFilterChannelLayouts, fail);
> + MERGE_REF(ret, b, channel_layouts, AVFilterChannelLayouts, fail);
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel