Signed-off-by: Vittorio Giovara <vittorio.giov...@gmail.com> --- libavfilter/af_channelmap.c | 92 +++++++++++++++++++++++++-------------------- 1 file changed, 52 insertions(+), 40 deletions(-)
diff --git a/libavfilter/af_channelmap.c b/libavfilter/af_channelmap.c index e214bdbcc1..939f056d6f 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; + enum AVChannel in_channel; + enum AVChannel 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 ch_layout; struct ChannelMap map[MAX_CH]; int nch; enum MappingMode mode; @@ -106,14 +106,19 @@ 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, enum AVChannel *ch, char delim) { char *next = split(*map, delim); + int ret; + if (!next && delim == '-') return AVERROR(EINVAL); - *ch = av_get_channel_layout(*map); - if (av_get_channel_layout_nb_channels(*ch) != 1) - return AVERROR(EINVAL); + + ret = av_channel_from_string(*map); + if (ret < 0) + return ret; + + *ch = ret; *map = next; return 0; } @@ -123,7 +128,6 @@ static av_cold int channelmap_init(AVFilterContext *ctx) ChannelMapContext *s = ctx->priv; char *mapping, separator = '|'; int map_entries = 0; - char buf[256]; enum MappingMode mode; uint64_t out_ch_mask = 0; int i; @@ -168,7 +172,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; + enum AVChannel in_ch = 0, out_ch = 0; static const char err[] = "Failed to parse channel map\n"; switch (mode) { case MAP_ONE_INT: @@ -199,13 +203,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 || @@ -219,50 +223,59 @@ 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); + + av_channel_layout_uninit(&s->ch_layout); + if (out_ch_mask) + av_channel_layout_from_mask(&s->ch_layout, out_ch_mask); + else + av_channel_layout_default(&s->ch_layout, map_entries); if (s->channel_layout_str) { - uint64_t fmt; - if ((fmt = av_get_channel_layout(s->channel_layout_str)) == 0) { + int ret; + AVChannelLayout fmt = {0}; + ret = av_channel_layout_from_string(&fmt, s->channel_layout_str); + if (ret < 0) { av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout: '%s'.\n", s->channel_layout_str); return AVERROR(EINVAL); } 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->ch_layout, &fmt)) { + char *chlstr = av_channel_layout_describe(&s->ch_layout); 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); + s->channel_layout_str, chlstr); + av_free(chlstr); 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); return AVERROR(EINVAL); } - s->output_layout = fmt; + ret = av_channel_layout_copy(&s->ch_layout, &fmt); + if (ret < 0) + return ret; } - if (!s->output_layout) { + if (!av_channel_layout_check(&s->ch_layout)) { av_log(ctx, AV_LOG_ERROR, "Output channel layout is not set and " "cannot be guessed from the maps.\n"); return AVERROR(EINVAL); @@ -270,8 +283,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_channel_index(&s->ch_layout, s->map[i].out_channel); } } @@ -283,7 +296,7 @@ static int channelmap_query_formats(AVFilterContext *ctx) ChannelMapContext *s = ctx->priv; AVFilterChannelLayouts *channel_layouts = NULL; - ff_add_channel_layout(&channel_layouts, s->output_layout); + ff_add_channel_layout(&channel_layouts, s->ch_layout.u.mask); ff_set_common_formats(ctx, ff_planar_sample_fmts()); ff_set_common_samplerates(ctx, ff_all_samplerates()); @@ -298,9 +311,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 = av_get_channel_layout_nb_channels(inlink->channel_layout); + const int nch_in = inlink->ch_layout.nb_channels; const int nch_out = s->nch; - int ch; + int ret, ch; uint8_t *source_planes[MAX_CH]; memcpy(source_planes, buf->extended_data, @@ -335,7 +348,9 @@ 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])); - buf->channel_layout = outlink->channel_layout; + ret = av_channel_layout_copy(&buf->ch_layout, &outlink->ch_layout); + if (ret < 0) + return ret; return ff_filter_frame(outlink, buf); } @@ -344,33 +359,30 @@ static int channelmap_config_input(AVFilterLink *inlink) { AVFilterContext *ctx = inlink->dst; ChannelMapContext *s = ctx->priv; - int nb_channels = av_get_channel_layout_nb_channels(inlink->channel_layout); + int nb_channels = inlink->ch_layout.nb_channels; int i, err = 0; - const char *channel_name; - 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_channel_index(&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), - 0, inlink->channel_layout); + char *chlstr = av_channel_layout_describe(&inlink->ch_layout); if (m->in_channel) { - channel_name = av_get_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); + av_channel_name(m->in_channel), chlstr); } else { av_log(ctx, AV_LOG_ERROR, "input channel #%d not available from input layout '%s'\n", - m->in_channel_idx, layout_name); + m->in_channel_idx, chlstr); } err = AVERROR(EINVAL); + av_free(chlstr); } } -- 2.12.0 _______________________________________________ libav-devel mailing list libav-devel@libav.org https://lists.libav.org/mailman/listinfo/libav-devel