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_channelmap.c | |
parent | 8a5896ec1f635ccf0d726f7ba7a06649ebeebf25 (diff) | |
download | ffmpeg-1f96db959c1235bb7079d354e09914a0a2608f62.tar.gz |
avfilter: convert to new channel layout API
Signed-off-by: James Almer <jamrial@gmail.com>
Diffstat (limited to 'libavfilter/af_channelmap.c')
-rw-r--r-- | libavfilter/af_channelmap.c | 90 |
1 files changed, 55 insertions, 35 deletions
diff --git a/libavfilter/af_channelmap.c b/libavfilter/af_channelmap.c index d3ab77920f..eb173d20c4 100644 --- a/libavfilter/af_channelmap.c +++ b/libavfilter/af_channelmap.c @@ -38,8 +38,8 @@ #include "internal.h" struct ChannelMap { - uint64_t in_channel; - uint64_t out_channel; + int in_channel; + int out_channel; int in_channel_idx; int out_channel_idx; }; @@ -59,7 +59,7 @@ typedef struct ChannelMapContext { const AVClass *class; char *mapping_str; char *channel_layout_str; - uint64_t output_layout; + AVChannelLayout output_layout; struct ChannelMap map[MAX_CH]; int nch; enum MappingMode mode; @@ -105,13 +105,13 @@ static int get_channel_idx(char **map, int *ch, char delim, int max_ch) return 0; } -static int get_channel(char **map, uint64_t *ch, char delim) +static int get_channel(char **map, int *ch, char delim) { char *next = split(*map, delim); if (!next && delim == '-') return AVERROR(EINVAL); - *ch = av_get_channel_layout(*map); - if (av_get_channel_layout_nb_channels(*ch) != 1) + *ch = av_channel_from_string(*map); + if (*ch < 0) return AVERROR(EINVAL); *map = next; return 0; @@ -167,7 +167,7 @@ static av_cold int channelmap_init(AVFilterContext *ctx) for (i = 0; i < map_entries; i++) { int in_ch_idx = -1, out_ch_idx = -1; - uint64_t in_ch = 0, out_ch = 0; + int in_ch = 0, out_ch = 0; static const char err[] = "Failed to parse channel map\n"; switch (mode) { case MAP_ONE_INT: @@ -198,13 +198,13 @@ static av_cold int channelmap_init(AVFilterContext *ctx) case MAP_PAIR_INT_STR: if (get_channel_idx(&mapping, &in_ch_idx, '-', MAX_CH) < 0 || get_channel(&mapping, &out_ch, separator) < 0 || - out_ch & out_ch_mask) { + (1ULL << out_ch) & out_ch_mask) { av_log(ctx, AV_LOG_ERROR, err); return AVERROR(EINVAL); } s->map[i].in_channel_idx = in_ch_idx; s->map[i].out_channel = out_ch; - out_ch_mask |= out_ch; + out_ch_mask |= 1ULL << out_ch; break; case MAP_PAIR_STR_INT: if (get_channel(&mapping, &in_ch, '-') < 0 || @@ -218,42 +218,57 @@ static av_cold int channelmap_init(AVFilterContext *ctx) case MAP_PAIR_STR_STR: if (get_channel(&mapping, &in_ch, '-') < 0 || get_channel(&mapping, &out_ch, separator) < 0 || - out_ch & out_ch_mask) { + (1ULL << out_ch) & out_ch_mask) { av_log(ctx, AV_LOG_ERROR, err); return AVERROR(EINVAL); } s->map[i].in_channel = in_ch; s->map[i].out_channel = out_ch; - out_ch_mask |= out_ch; + out_ch_mask |= 1ULL << out_ch; break; } } s->mode = mode; s->nch = map_entries; - s->output_layout = out_ch_mask ? out_ch_mask : - av_get_default_channel_layout(map_entries); + if (out_ch_mask) + av_channel_layout_from_mask(&s->output_layout, out_ch_mask); + else + av_channel_layout_default(&s->output_layout, map_entries); if (s->channel_layout_str) { - uint64_t fmt; - if ((fmt = av_get_channel_layout(s->channel_layout_str)) == 0) { - av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout: '%s'.\n", + AVChannelLayout fmt = { 0 }; + int ret; + if ((ret = av_channel_layout_from_string(&fmt, s->channel_layout_str)) < 0) { +#if FF_API_OLD_CHANNEL_LAYOUT + uint64_t mask; +FF_DISABLE_DEPRECATION_WARNINGS + if ((mask = av_get_channel_layout(s->channel_layout_str)) == 0) { +#endif + av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout: '%s'.\n", + s->channel_layout_str); + return AVERROR(EINVAL); +#if FF_API_OLD_CHANNEL_LAYOUT + } +FF_ENABLE_DEPRECATION_WARNINGS + av_log(ctx, AV_LOG_WARNING, "Channel layout '%s' uses a deprecated syntax.\n", s->channel_layout_str); - return AVERROR(EINVAL); + av_channel_layout_from_mask(&fmt, mask); +#endif } if (mode == MAP_NONE) { int i; - s->nch = av_get_channel_layout_nb_channels(fmt); + s->nch = fmt.nb_channels; for (i = 0; i < s->nch; i++) { s->map[i].in_channel_idx = i; s->map[i].out_channel_idx = i; } - } else if (out_ch_mask && out_ch_mask != fmt) { - av_get_channel_layout_string(buf, sizeof(buf), 0, out_ch_mask); + } else if (out_ch_mask && av_channel_layout_compare(&s->output_layout, &fmt)) { + av_channel_layout_describe(&s->output_layout, buf, sizeof(buf)); av_log(ctx, AV_LOG_ERROR, "Output channel layout '%s' does not match the list of channel mapped: '%s'.\n", s->channel_layout_str, buf); return AVERROR(EINVAL); - } else if (s->nch != av_get_channel_layout_nb_channels(fmt)) { + } else if (s->nch != fmt.nb_channels) { av_log(ctx, AV_LOG_ERROR, "Output channel layout %s does not match the number of channels mapped %d.\n", s->channel_layout_str, s->nch); @@ -261,7 +276,7 @@ static av_cold int channelmap_init(AVFilterContext *ctx) } s->output_layout = fmt; } - if (!s->output_layout) { + if (!s->output_layout.nb_channels) { av_log(ctx, AV_LOG_ERROR, "Output channel layout is not set and " "cannot be guessed from the maps.\n"); return AVERROR(EINVAL); @@ -269,8 +284,8 @@ static av_cold int channelmap_init(AVFilterContext *ctx) if (mode == MAP_PAIR_INT_STR || mode == MAP_PAIR_STR_STR) { for (i = 0; i < s->nch; i++) { - s->map[i].out_channel_idx = av_get_channel_layout_channel_index( - s->output_layout, s->map[i].out_channel); + s->map[i].out_channel_idx = av_channel_layout_index_from_channel( + &s->output_layout, s->map[i].out_channel); } } @@ -285,7 +300,7 @@ static int channelmap_query_formats(AVFilterContext *ctx) if ((ret = ff_set_common_formats (ctx, ff_planar_sample_fmts())) < 0 || (ret = ff_set_common_all_samplerates(ctx )) < 0 || - (ret = ff_add_channel_layout(&channel_layouts, s->output_layout)) < 0 || + (ret = ff_add_channel_layout(&channel_layouts, &s->output_layout)) < 0 || (ret = ff_channel_layouts_ref(channel_layouts, &ctx->outputs[0]->incfg.channel_layouts)) < 0) return ret; @@ -299,9 +314,9 @@ static int channelmap_filter_frame(AVFilterLink *inlink, AVFrame *buf) AVFilterContext *ctx = inlink->dst; AVFilterLink *outlink = ctx->outputs[0]; const ChannelMapContext *s = ctx->priv; - const int nch_in = inlink->channels; + const int nch_in = inlink->ch_layout.nb_channels; const int nch_out = s->nch; - int ch; + int ch, ret; uint8_t *source_planes[MAX_CH]; memcpy(source_planes, buf->extended_data, @@ -336,8 +351,14 @@ static int channelmap_filter_frame(AVFilterLink *inlink, AVFrame *buf) memcpy(buf->data, buf->extended_data, FFMIN(FF_ARRAY_ELEMS(buf->data), nch_out) * sizeof(buf->data[0])); +#if FF_API_OLD_CHANNEL_LAYOUT +FF_DISABLE_DEPRECATION_WARNINGS + buf->channels = outlink->ch_layout.nb_channels; buf->channel_layout = outlink->channel_layout; - buf->channels = outlink->channels; +FF_ENABLE_DEPRECATION_WARNINGS +#endif + if ((ret = av_channel_layout_copy(&buf->ch_layout, &outlink->ch_layout)) < 0) + return ret; return ff_filter_frame(outlink, buf); } @@ -346,24 +367,23 @@ static int channelmap_config_input(AVFilterLink *inlink) { AVFilterContext *ctx = inlink->dst; ChannelMapContext *s = ctx->priv; - int nb_channels = inlink->channels; + int nb_channels = inlink->ch_layout.nb_channels; int i, err = 0; - const char *channel_name; + char channel_name[64]; char layout_name[256]; for (i = 0; i < s->nch; i++) { struct ChannelMap *m = &s->map[i]; if (s->mode == MAP_PAIR_STR_INT || s->mode == MAP_PAIR_STR_STR) { - m->in_channel_idx = av_get_channel_layout_channel_index( - inlink->channel_layout, m->in_channel); + m->in_channel_idx = av_channel_layout_index_from_channel( + &inlink->ch_layout, m->in_channel); } if (m->in_channel_idx < 0 || m->in_channel_idx >= nb_channels) { - av_get_channel_layout_string(layout_name, sizeof(layout_name), - nb_channels, inlink->channel_layout); + av_channel_layout_describe(&inlink->ch_layout, layout_name, sizeof(layout_name)); if (m->in_channel) { - channel_name = av_get_channel_name(m->in_channel); + av_channel_name(channel_name, sizeof(channel_name), m->in_channel); av_log(ctx, AV_LOG_ERROR, "input channel '%s' not available from input layout '%s'\n", channel_name, layout_name); |