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_surround.c | |
parent | 8a5896ec1f635ccf0d726f7ba7a06649ebeebf25 (diff) |
avfilter: convert to new channel layout API
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavfilter/af_surround.c')
-rw-r--r-- | libavfilter/af_surround.c | 88 |
1 files changed, 47 insertions, 41 deletions
diff --git a/libavfilter/af_surround.c b/libavfilter/af_surround.c index 9f735e7be6..4599dd1601 100644 --- a/libavfilter/af_surround.c +++ b/libavfilter/af_surround.c @@ -91,8 +91,8 @@ typedef struct AudioSurroundContext { float lowcut; float highcut; - uint64_t out_channel_layout; - uint64_t in_channel_layout; + AVChannelLayout out_channel_layout; + AVChannelLayout in_channel_layout; int nb_in_channels; int nb_out_channels; @@ -170,7 +170,7 @@ static int query_formats(AVFilterContext *ctx) return ret; layouts = NULL; - ret = ff_add_channel_layout(&layouts, s->out_channel_layout); + ret = ff_add_channel_layout(&layouts, &s->out_channel_layout); if (ret) return ret; @@ -179,7 +179,7 @@ static int query_formats(AVFilterContext *ctx) return ret; layouts = NULL; - ret = ff_add_channel_layout(&layouts, s->in_channel_layout); + ret = ff_add_channel_layout(&layouts, &s->in_channel_layout); if (ret) return ret; @@ -196,12 +196,12 @@ static int config_input(AVFilterLink *inlink) AudioSurroundContext *s = ctx->priv; int ch; - s->rdft = av_calloc(inlink->channels, sizeof(*s->rdft)); + s->rdft = av_calloc(inlink->ch_layout.nb_channels, sizeof(*s->rdft)); if (!s->rdft) return AVERROR(ENOMEM); - s->nb_in_channels = inlink->channels; + s->nb_in_channels = inlink->ch_layout.nb_channels; - for (ch = 0; ch < inlink->channels; ch++) { + for (ch = 0; ch < inlink->ch_layout.nb_channels; ch++) { float scale = 1.f; av_tx_init(&s->rdft[ch], &s->tx_fn, AV_TX_FLOAT_RDFT, 0, s->buf_size, &scale, 0); @@ -213,31 +213,31 @@ static int config_input(AVFilterLink *inlink) return AVERROR(ENOMEM); for (ch = 0; ch < s->nb_in_channels; ch++) s->input_levels[ch] = s->level_in; - ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_FRONT_CENTER); + ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_FRONT_CENTER); if (ch >= 0) s->input_levels[ch] *= s->fc_in; - ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_FRONT_LEFT); + ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_FRONT_LEFT); if (ch >= 0) s->input_levels[ch] *= s->fl_in; - ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_FRONT_RIGHT); + ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_FRONT_RIGHT); if (ch >= 0) s->input_levels[ch] *= s->fr_in; - ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_SIDE_LEFT); + ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_SIDE_LEFT); if (ch >= 0) s->input_levels[ch] *= s->sl_in; - ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_SIDE_RIGHT); + ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_SIDE_RIGHT); if (ch >= 0) s->input_levels[ch] *= s->sr_in; - ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_BACK_LEFT); + ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_BACK_LEFT); if (ch >= 0) s->input_levels[ch] *= s->bl_in; - ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_BACK_RIGHT); + ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_BACK_RIGHT); if (ch >= 0) s->input_levels[ch] *= s->br_in; - ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_BACK_CENTER); + ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_BACK_CENTER); if (ch >= 0) s->input_levels[ch] *= s->bc_in; - ch = av_get_channel_layout_channel_index(inlink->channel_layout, AV_CH_LOW_FREQUENCY); + ch = av_channel_layout_index_from_channel(&inlink->ch_layout, AV_CHAN_LOW_FREQUENCY); if (ch >= 0) s->input_levels[ch] *= s->lfe_in; @@ -265,12 +265,12 @@ static int config_output(AVFilterLink *outlink) AudioSurroundContext *s = ctx->priv; int ch; - s->irdft = av_calloc(outlink->channels, sizeof(*s->irdft)); + s->irdft = av_calloc(outlink->ch_layout.nb_channels, sizeof(*s->irdft)); if (!s->irdft) return AVERROR(ENOMEM); - s->nb_out_channels = outlink->channels; + s->nb_out_channels = outlink->ch_layout.nb_channels; - for (ch = 0; ch < outlink->channels; ch++) { + for (ch = 0; ch < outlink->ch_layout.nb_channels; ch++) { float iscale = 1.f; av_tx_init(&s->irdft[ch], &s->itx_fn, AV_TX_FLOAT_RDFT, 1, s->buf_size, &iscale, 0); @@ -282,31 +282,31 @@ static int config_output(AVFilterLink *outlink) return AVERROR(ENOMEM); for (ch = 0; ch < s->nb_out_channels; ch++) s->output_levels[ch] = s->level_out; - ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_FRONT_CENTER); + ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_FRONT_CENTER); if (ch >= 0) s->output_levels[ch] *= s->fc_out; - ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_FRONT_LEFT); + ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_FRONT_LEFT); if (ch >= 0) s->output_levels[ch] *= s->fl_out; - ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_FRONT_RIGHT); + ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_FRONT_RIGHT); if (ch >= 0) s->output_levels[ch] *= s->fr_out; - ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_SIDE_LEFT); + ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_SIDE_LEFT); if (ch >= 0) s->output_levels[ch] *= s->sl_out; - ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_SIDE_RIGHT); + ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_SIDE_RIGHT); if (ch >= 0) s->output_levels[ch] *= s->sr_out; - ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_BACK_LEFT); + ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_BACK_LEFT); if (ch >= 0) s->output_levels[ch] *= s->bl_out; - ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_BACK_RIGHT); + ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_BACK_RIGHT); if (ch >= 0) s->output_levels[ch] *= s->br_out; - ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_BACK_CENTER); + ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_BACK_CENTER); if (ch >= 0) s->output_levels[ch] *= s->bc_out; - ch = av_get_channel_layout_channel_index(outlink->channel_layout, AV_CH_LOW_FREQUENCY); + ch = av_channel_layout_index_from_channel(&outlink->ch_layout, AV_CHAN_LOW_FREQUENCY); if (ch >= 0) s->output_levels[ch] *= s->lfe_out; @@ -1381,15 +1381,16 @@ static av_cold int init(AVFilterContext *ctx) { AudioSurroundContext *s = ctx->priv; float overlap; - int i; + int64_t in_channel_layout, out_channel_layout; + int i, ret; - if (!(s->out_channel_layout = av_get_channel_layout(s->out_channel_layout_str))) { + if ((ret = av_channel_layout_from_string(&s->out_channel_layout, s->out_channel_layout_str)) < 0) { av_log(ctx, AV_LOG_ERROR, "Error parsing output channel layout '%s'.\n", s->out_channel_layout_str); - return AVERROR(EINVAL); + return ret; } - if (!(s->in_channel_layout = av_get_channel_layout(s->in_channel_layout_str))) { + if ((ret = av_channel_layout_from_string(&s->in_channel_layout, s->in_channel_layout_str)) < 0) { av_log(ctx, AV_LOG_ERROR, "Error parsing input channel layout '%s'.\n", s->in_channel_layout_str); return AVERROR(EINVAL); @@ -1401,10 +1402,15 @@ static av_cold int init(AVFilterContext *ctx) return AVERROR(EINVAL); } - switch (s->in_channel_layout) { + in_channel_layout = s->in_channel_layout.order == AV_CHANNEL_ORDER_NATIVE ? + s->in_channel_layout.u.mask : 0; + out_channel_layout = s->out_channel_layout.order == AV_CHANNEL_ORDER_NATIVE ? + s->out_channel_layout.u.mask : 0; + + switch (in_channel_layout) { case AV_CH_LAYOUT_STEREO: s->filter = filter_stereo; - switch (s->out_channel_layout) { + switch (out_channel_layout) { case AV_CH_LAYOUT_MONO: s->upmix_stereo = upmix_1_0; break; @@ -1450,7 +1456,7 @@ static av_cold int init(AVFilterContext *ctx) break; case AV_CH_LAYOUT_2POINT1: s->filter = filter_2_1; - switch (s->out_channel_layout) { + switch (out_channel_layout) { case AV_CH_LAYOUT_5POINT1_BACK: s->upmix_2_1 = upmix_5_1_back_2_1; break; @@ -1460,7 +1466,7 @@ static av_cold int init(AVFilterContext *ctx) break; case AV_CH_LAYOUT_SURROUND: s->filter = filter_surround; - switch (s->out_channel_layout) { + switch (out_channel_layout) { case AV_CH_LAYOUT_3POINT1: s->upmix_3_0 = upmix_3_1_surround; break; @@ -1473,7 +1479,7 @@ static av_cold int init(AVFilterContext *ctx) break; case AV_CH_LAYOUT_5POINT0: s->filter = filter_5_0_side; - switch (s->out_channel_layout) { + switch (out_channel_layout) { case AV_CH_LAYOUT_7POINT1: s->upmix_5_0 = upmix_7_1_5_0_side; break; @@ -1483,7 +1489,7 @@ static av_cold int init(AVFilterContext *ctx) break; case AV_CH_LAYOUT_5POINT1: s->filter = filter_5_1_side; - switch (s->out_channel_layout) { + switch (out_channel_layout) { case AV_CH_LAYOUT_7POINT1: s->upmix_5_1 = upmix_7_1_5_1; break; @@ -1493,7 +1499,7 @@ static av_cold int init(AVFilterContext *ctx) break; case AV_CH_LAYOUT_5POINT1_BACK: s->filter = filter_5_1_back; - switch (s->out_channel_layout) { + switch (out_channel_layout) { case AV_CH_LAYOUT_7POINT1: s->upmix_5_1 = upmix_7_1_5_1; break; @@ -1590,7 +1596,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) AudioSurroundContext *s = ctx->priv; AVFrame *out; - ff_filter_execute(ctx, fft_channel, in, NULL, inlink->channels); + ff_filter_execute(ctx, fft_channel, in, NULL, inlink->ch_layout.nb_channels); s->filter(ctx); @@ -1598,7 +1604,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) if (!out) return AVERROR(ENOMEM); - ff_filter_execute(ctx, ifft_channel, out, NULL, outlink->channels); + ff_filter_execute(ctx, ifft_channel, out, NULL, outlink->ch_layout.nb_channels); out->pts = in->pts; out->nb_samples = in->nb_samples; |