diff options
author | James Almer <jamrial@gmail.com> | 2021-08-31 11:03:14 -0300 |
---|---|---|
committer | James Almer <jamrial@gmail.com> | 2022-03-15 09:42:46 -0300 |
commit | 1f96db959c1235bb7079d354e09914a0a2608f62 (patch) | |
tree | 21ac480d5b148c0524761853e6badb3a90a7ca3f /libavfilter/af_aresample.c | |
parent | 8a5896ec1f635ccf0d726f7ba7a06649ebeebf25 (diff) |
avfilter: convert to new channel layout API
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavfilter/af_aresample.c')
-rw-r--r-- | libavfilter/af_aresample.c | 54 |
1 files changed, 31 insertions, 23 deletions
diff --git a/libavfilter/af_aresample.c b/libavfilter/af_aresample.c index 6e1be5b7eb..971c861d0e 100644 --- a/libavfilter/af_aresample.c +++ b/libavfilter/af_aresample.c @@ -65,7 +65,8 @@ static int query_formats(AVFilterContext *ctx) { AResampleContext *aresample = ctx->priv; enum AVSampleFormat out_format; - int64_t out_rate, out_layout; + AVChannelLayout out_layout = { 0 }; + int64_t out_rate; AVFilterLink *inlink = ctx->inputs[0]; AVFilterLink *outlink = ctx->outputs[0]; @@ -79,7 +80,6 @@ static int query_formats(AVFilterContext *ctx) av_opt_set_int(aresample->swr, "osr", aresample->sample_rate_arg, 0); av_opt_get_sample_fmt(aresample->swr, "osf", 0, &out_format); av_opt_get_int(aresample->swr, "osr", 0, &out_rate); - av_opt_get_int(aresample->swr, "ocl", 0, &out_layout); in_formats = ff_all_formats(AVMEDIA_TYPE_AUDIO); if ((ret = ff_formats_ref(in_formats, &inlink->outcfg.formats)) < 0) @@ -111,11 +111,13 @@ static int query_formats(AVFilterContext *ctx) if ((ret = ff_formats_ref(out_formats, &outlink->incfg.formats)) < 0) return ret; - if(out_layout) { - int64_t layout_list[] = { out_layout, -1 }; - out_layouts = ff_make_format64_list(layout_list); + av_opt_get_chlayout(aresample->swr, "ochl", 0, &out_layout); + if (av_channel_layout_check(&out_layout)) { + const AVChannelLayout layout_list[] = { out_layout, { 0 } }; + out_layouts = ff_make_channel_layout_list(layout_list); } else out_layouts = ff_all_channel_counts(); + av_channel_layout_uninit(&out_layout); return ff_channel_layouts_ref(out_layouts, &outlink->incfg.channel_layouts); } @@ -127,42 +129,41 @@ static int config_output(AVFilterLink *outlink) AVFilterContext *ctx = outlink->src; AVFilterLink *inlink = ctx->inputs[0]; AResampleContext *aresample = ctx->priv; - int64_t out_rate, out_layout; + AVChannelLayout out_layout = { 0 }; + int64_t out_rate; enum AVSampleFormat out_format; char inchl_buf[128], outchl_buf[128]; - aresample->swr = swr_alloc_set_opts(aresample->swr, - outlink->channel_layout, outlink->format, outlink->sample_rate, - inlink->channel_layout, inlink->format, inlink->sample_rate, - 0, ctx); - if (!aresample->swr) - return AVERROR(ENOMEM); - if (!inlink->channel_layout) - av_opt_set_int(aresample->swr, "ich", inlink->channels, 0); - if (!outlink->channel_layout) - av_opt_set_int(aresample->swr, "och", outlink->channels, 0); + ret = swr_alloc_set_opts2(&aresample->swr, + &outlink->ch_layout, outlink->format, outlink->sample_rate, + &inlink->ch_layout, inlink->format, inlink->sample_rate, + 0, ctx); + if (ret < 0) + return ret; ret = swr_init(aresample->swr); if (ret < 0) return ret; av_opt_get_int(aresample->swr, "osr", 0, &out_rate); - av_opt_get_int(aresample->swr, "ocl", 0, &out_layout); + av_opt_get_chlayout(aresample->swr, "ochl", 0, &out_layout); av_opt_get_sample_fmt(aresample->swr, "osf", 0, &out_format); outlink->time_base = (AVRational) {1, out_rate}; av_assert0(outlink->sample_rate == out_rate); - av_assert0(outlink->channel_layout == out_layout || !outlink->channel_layout); + av_assert0(!av_channel_layout_compare(&outlink->ch_layout, &out_layout)); av_assert0(outlink->format == out_format); + av_channel_layout_uninit(&out_layout); + aresample->ratio = (double)outlink->sample_rate / inlink->sample_rate; - av_get_channel_layout_string(inchl_buf, sizeof(inchl_buf), inlink ->channels, inlink ->channel_layout); - av_get_channel_layout_string(outchl_buf, sizeof(outchl_buf), outlink->channels, outlink->channel_layout); + av_channel_layout_describe(&inlink ->ch_layout, inchl_buf, sizeof(inchl_buf)); + av_channel_layout_describe(&outlink->ch_layout, outchl_buf, sizeof(outchl_buf)); av_log(ctx, AV_LOG_VERBOSE, "ch:%d chl:%s fmt:%s r:%dHz -> ch:%d chl:%s fmt:%s r:%dHz\n", - inlink ->channels, inchl_buf, av_get_sample_fmt_name(inlink->format), inlink->sample_rate, - outlink->channels, outchl_buf, av_get_sample_fmt_name(outlink->format), outlink->sample_rate); + inlink ->ch_layout.nb_channels, inchl_buf, av_get_sample_fmt_name(inlink->format), inlink->sample_rate, + outlink->ch_layout.nb_channels, outchl_buf, av_get_sample_fmt_name(outlink->format), outlink->sample_rate); return 0; } @@ -189,8 +190,15 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *insamplesref) av_frame_copy_props(outsamplesref, insamplesref); outsamplesref->format = outlink->format; - outsamplesref->channels = outlink->channels; +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + outsamplesref->channels = outlink->ch_layout.nb_channels; outsamplesref->channel_layout = outlink->channel_layout; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + ret = av_channel_layout_copy(&outsamplesref->ch_layout, &outlink->ch_layout); + if (ret < 0) + return ret; outsamplesref->sample_rate = outlink->sample_rate; if(insamplesref->pts != AV_NOPTS_VALUE) { |