This patch contains the following commits: avtools: Use the new channel layout API in libavfilter
af_aformat: convert to new channel layout API Signed-off-by: Vittorio Giovara <[email protected]> af_amix: convert to new channel layout API Signed-off-by: Vittorio Giovara <[email protected]> af_ashowinfo: convert to new channel layout API Signed-off-by: Vittorio Giovara <[email protected]> af_asyncts: convert to new channel layout API Signed-off-by: Vittorio Giovara <[email protected]> af_atrim: convert to new channel layout API Signed-off-by: Vittorio Giovara <[email protected]> af_channelmap: convert to new channel layout API Signed-off-by: Vittorio Giovara <[email protected]> af_channelsplit: convert to new channel layout API Signed-off-by: Vittorio Giovara <[email protected]> af_compand: convert to new channel layout API Signed-off-by: Vittorio Giovara <[email protected]> af_hdcd: convert to new channel layout API af_join: convert to new channel layout API af_resample: convert to new channel layout API af_volume: convert to new channel layout --- avtools/avconv.c | 2 +- avtools/avconv_filter.c | 4 +- libavfilter/af_aformat.c | 10 ++++- libavfilter/af_amix.c | 11 ++++-- libavfilter/af_ashowinfo.c | 12 +++--- libavfilter/af_asyncts.c | 6 +-- libavfilter/af_channelmap.c | 92 ++++++++++++++++++++++++------------------- libavfilter/af_channelsplit.c | 38 +++++++++--------- libavfilter/af_compand.c | 8 ++-- libavfilter/af_hdcd.c | 2 +- libavfilter/af_join.c | 84 ++++++++++++++++++--------------------- libavfilter/af_resample.c | 33 +++++++++------- libavfilter/af_volume.c | 2 +- libavfilter/trim.c | 3 +- 14 files changed, 163 insertions(+), 144 deletions(-) diff --git a/avtools/avconv.c b/avtools/avconv.c index 42cbfef592..a1427e0cb4 100644 --- a/avtools/avconv.c +++ b/avtools/avconv.c @@ -1998,7 +1998,7 @@ static int init_output_stream_encode(OutputStream *ost) case AVMEDIA_TYPE_AUDIO: enc_ctx->sample_fmt = ost->filter->filter->inputs[0]->format; enc_ctx->sample_rate = ost->filter->filter->inputs[0]->sample_rate; - enc_ctx->channel_layout = ost->filter->filter->inputs[0]->channel_layout; + enc_ctx->channel_layout = ost->filter->filter->inputs[0]->ch_layout.u.mask; enc_ctx->channels = av_get_channel_layout_nb_channels(enc_ctx->channel_layout); enc_ctx->time_base = (AVRational){ 1, enc_ctx->sample_rate }; break; diff --git a/avtools/avconv_filter.c b/avtools/avconv_filter.c index e719c06658..7df64c647a 100644 --- a/avtools/avconv_filter.c +++ b/avtools/avconv_filter.c @@ -591,7 +591,7 @@ static int configure_input_audio_filter(FilterGraph *fg, InputFilter *ifilter, par->time_base = (AVRational){ 1, ifilter->sample_rate }; par->sample_rate = ifilter->sample_rate; par->format = ifilter->format; - par->channel_layout = ifilter->channel_layout; + av_channel_layout_from_mask(&par->ch_layout, ifilter->channel_layout); ret = av_buffersrc_parameters_set(ifilter->filter, par); av_freep(&par); @@ -758,7 +758,7 @@ int configure_filtergraph(FilterGraph *fg) ofilter->height = link->h; ofilter->sample_rate = link->sample_rate; - ofilter->channel_layout = link->channel_layout; + ofilter->channel_layout = link->ch_layout.u.mask; } for (i = 0; i < fg->nb_inputs; i++) { diff --git a/libavfilter/af_aformat.c b/libavfilter/af_aformat.c index f0746737dc..c5aa4f7148 100644 --- a/libavfilter/af_aformat.c +++ b/libavfilter/af_aformat.c @@ -94,6 +94,13 @@ static int get_sample_rate(const char *samplerate) return FFMAX(ret, 0); } +static int get_channel_layout(const char *channel_layout) +{ + AVChannelLayout ch_layout = {0}; + av_channel_layout_from_string(&ch_layout, channel_layout); + return ch_layout.u.mask; +} + static av_cold int init(AVFilterContext *ctx) { AFormatContext *s = ctx->priv; @@ -103,8 +110,7 @@ static av_cold int init(AVFilterContext *ctx) 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, av_get_channel_layout, 0, - "channel layout"); + ff_add_channel_layout, get_channel_layout, 0, "channel layout"); return 0; } diff --git a/libavfilter/af_amix.c b/libavfilter/af_amix.c index bfba1504ea..a35e04530f 100644 --- a/libavfilter/af_amix.c +++ b/libavfilter/af_amix.c @@ -226,7 +226,7 @@ static int config_output(AVFilterLink *outlink) AVFilterContext *ctx = outlink->src; MixContext *s = ctx->priv; int i; - char buf[64]; + char *chlstr; s->planar = av_sample_fmt_is_planar(outlink->format); s->sample_rate = outlink->sample_rate; @@ -241,7 +241,7 @@ static int config_output(AVFilterLink *outlink) if (!s->fifos) return AVERROR(ENOMEM); - s->nb_channels = av_get_channel_layout_nb_channels(outlink->channel_layout); + s->nb_channels = outlink->ch_layout.nb_channels; for (i = 0; i < s->nb_inputs; i++) { s->fifos[i] = av_audio_fifo_alloc(outlink->format, s->nb_channels, 1024); if (!s->fifos[i]) @@ -260,11 +260,14 @@ static int config_output(AVFilterLink *outlink) s->scale_norm = s->active_inputs; calculate_scales(s, 0); - av_get_channel_layout_string(buf, sizeof(buf), -1, outlink->channel_layout); + chlstr = av_channel_layout_describe(&outlink->ch_layout); + if (!chlstr) + return AVERROR(ENOMEM); av_log(ctx, AV_LOG_VERBOSE, "inputs:%d fmt:%s srate:%d cl:%s\n", s->nb_inputs, - av_get_sample_fmt_name(outlink->format), outlink->sample_rate, buf); + av_get_sample_fmt_name(outlink->format), outlink->sample_rate, chlstr); + av_free(chlstr); return 0; } diff --git a/libavfilter/af_ashowinfo.c b/libavfilter/af_ashowinfo.c index 5f0e2549ff..dd25c64d69 100644 --- a/libavfilter/af_ashowinfo.c +++ b/libavfilter/af_ashowinfo.c @@ -57,7 +57,7 @@ typedef struct AShowInfoContext { static int config_input(AVFilterLink *inlink) { AShowInfoContext *s = inlink->dst->priv; - int channels = av_get_channel_layout_nb_channels(inlink->channel_layout); + int channels = inlink->ch_layout.nb_channels; s->plane_checksums = av_malloc(channels * sizeof(*s->plane_checksums)); if (!s->plane_checksums) return AVERROR(ENOMEM); @@ -192,9 +192,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf) { AVFilterContext *ctx = inlink->dst; AShowInfoContext *s = ctx->priv; - char chlayout_str[128]; + char *chlayout_str; uint32_t checksum = 0; - int channels = av_get_channel_layout_nb_channels(buf->channel_layout); + int channels = buf->ch_layout.nb_channels; int planar = av_sample_fmt_is_planar(buf->format); int block_align = av_get_bytes_per_sample(buf->format) * (planar ? 1 : channels); int data_size = buf->nb_samples * block_align; @@ -209,8 +209,9 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf) s->plane_checksums[0]; } - av_get_channel_layout_string(chlayout_str, sizeof(chlayout_str), -1, - buf->channel_layout); + chlayout_str = av_channel_layout_describe(&buf->ch_layout); + if (!chlayout_str) + return AVERROR(ENOMEM); av_log(ctx, AV_LOG_INFO, "n:%"PRIu64" pts:%"PRId64" pts_time:%f " @@ -220,6 +221,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf) av_get_sample_fmt_name(buf->format), chlayout_str, buf->sample_rate, buf->nb_samples, checksum); + av_free(chlayout_str); av_log(ctx, AV_LOG_INFO, "plane_checksums: [ "); for (i = 0; i < planes; i++) diff --git a/libavfilter/af_asyncts.c b/libavfilter/af_asyncts.c index 862b7a8cbd..ac983edca9 100644 --- a/libavfilter/af_asyncts.c +++ b/libavfilter/af_asyncts.c @@ -99,8 +99,8 @@ static int config_props(AVFilterLink *link) if (!s->avr) return AVERROR(ENOMEM); - av_opt_set_int(s->avr, "in_channel_layout", link->channel_layout, 0); - av_opt_set_int(s->avr, "out_channel_layout", link->channel_layout, 0); + av_opt_set_channel_layout(s->avr, "in_ch_layout", &link->ch_layout, 0); + av_opt_set_channel_layout(s->avr, "out_ch_layout", &link->ch_layout, 0); av_opt_set_int(s->avr, "in_sample_fmt", link->format, 0); av_opt_set_int(s->avr, "out_sample_fmt", link->format, 0); av_opt_set_int(s->avr, "in_sample_rate", link->sample_rate, 0); @@ -183,7 +183,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf) AVFilterContext *ctx = inlink->dst; ASyncContext *s = ctx->priv; AVFilterLink *outlink = ctx->outputs[0]; - int nb_channels = av_get_channel_layout_nb_channels(buf->channel_layout); + int nb_channels = buf->ch_layout.nb_channels; int64_t pts = (buf->pts == AV_NOPTS_VALUE) ? buf->pts : av_rescale_q(buf->pts, inlink->time_base, outlink->time_base); int out_size, ret; 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); } } diff --git a/libavfilter/af_channelsplit.c b/libavfilter/af_channelsplit.c index 5b410fd87c..41b3051c8c 100644 --- a/libavfilter/af_channelsplit.c +++ b/libavfilter/af_channelsplit.c @@ -36,14 +36,14 @@ typedef struct ChannelSplitContext { const AVClass *class; - uint64_t channel_layout; - char *channel_layout_str; + AVChannelLayout ch_layout; } ChannelSplitContext; #define OFFSET(x) offsetof(ChannelSplitContext, x) #define A AV_OPT_FLAG_AUDIO_PARAM static const AVOption options[] = { - { "channel_layout", "Input channel layout.", OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, { .str = "stereo" }, .flags = A }, + { "channel_layout", "Input channel layout.", OFFSET(ch_layout), + AV_OPT_TYPE_CHANNEL_LAYOUT, { .str = "stereo" }, .flags = A }, { NULL }, }; @@ -57,23 +57,17 @@ static const AVClass channelsplit_class = { static av_cold int init(AVFilterContext *ctx) { ChannelSplitContext *s = ctx->priv; - int nb_channels; + int nb_channels = s->ch_layout.nb_channels; int ret = 0, i; - if (!(s->channel_layout = av_get_channel_layout(s->channel_layout_str))) { - av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout '%s'.\n", - s->channel_layout_str); - ret = AVERROR(EINVAL); - goto fail; - } - - nb_channels = av_get_channel_layout_nb_channels(s->channel_layout); for (i = 0; i < nb_channels; i++) { - uint64_t channel = av_channel_layout_extract_channel(s->channel_layout, i); AVFilterPad pad = { 0 }; + ret = av_channel_layout_get_channel(&s->ch_layout, i); + if (ret < 0) + goto fail; pad.type = AVMEDIA_TYPE_AUDIO; - pad.name = av_get_channel_name(channel); + pad.name = av_channel_name(ret); ff_insert_outpad(ctx, i, &pad); } @@ -91,14 +85,16 @@ static int query_formats(AVFilterContext *ctx) ff_set_common_formats (ctx, ff_planar_sample_fmts()); ff_set_common_samplerates(ctx, ff_all_samplerates()); - ff_add_channel_layout(&in_layouts, s->channel_layout); + ff_add_channel_layout(&in_layouts, s->ch_layout.u.mask); ff_channel_layouts_ref(in_layouts, &ctx->inputs[0]->out_channel_layouts); for (i = 0; i < ctx->nb_outputs; i++) { AVFilterChannelLayouts *out_layouts = NULL; - uint64_t channel = av_channel_layout_extract_channel(s->channel_layout, i); + int ret = av_channel_layout_get_channel(&s->ch_layout, i); + if (ret < 0) + return ret; - ff_add_channel_layout(&out_layouts, channel); + ff_add_channel_layout(&out_layouts, 1ULL << ret); ff_channel_layouts_ref(out_layouts, &ctx->outputs[i]->in_channel_layouts); } @@ -112,15 +108,17 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *buf) for (i = 0; i < ctx->nb_outputs; i++) { AVFrame *buf_out = av_frame_clone(buf); + enum AVChannel channel; if (!buf_out) { ret = AVERROR(ENOMEM); break; } - buf_out->data[0] = buf_out->extended_data[0] = buf_out->extended_data[i]; - buf_out->channel_layout = - av_channel_layout_extract_channel(buf->channel_layout, i); + channel = av_channel_layout_get_channel(&buf->ch_layout, i); + + av_channel_layout_uninit(&buf_out->ch_layout); + av_channel_layout_from_mask(&buf_out->ch_layout, 1 << channel); ret = ff_filter_frame(ctx->outputs[i], buf_out); if (ret < 0) diff --git a/libavfilter/af_compand.c b/libavfilter/af_compand.c index f21c861e06..cc743e3e6d 100644 --- a/libavfilter/af_compand.c +++ b/libavfilter/af_compand.c @@ -342,8 +342,7 @@ static int config_output(AVFilterLink *outlink) const int sample_rate = outlink->sample_rate; double radius = s->curve_dB * M_LN10 / 20.0; const char *p; - const int channels = - av_get_channel_layout_nb_channels(outlink->channel_layout); + const int channels = outlink->ch_layout.nb_channels; int nb_attacks, nb_decays, nb_points; int new_nb_items, num; int i; @@ -547,7 +546,10 @@ static int config_output(AVFilterLink *outlink) s->delay_frame->format = outlink->format; s->delay_frame->nb_samples = s->delay_samples; - s->delay_frame->channel_layout = outlink->channel_layout; + err = av_channel_layout_copy(&s->delay_frame->ch_layout, + &outlink->ch_layout); + if (err < 0) + return err; err = av_frame_get_buffer(s->delay_frame, 32); if (err) diff --git a/libavfilter/af_hdcd.c b/libavfilter/af_hdcd.c index b9dadecca4..78cc1e74c8 100644 --- a/libavfilter/af_hdcd.c +++ b/libavfilter/af_hdcd.c @@ -76,7 +76,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) const int16_t *in_data; int32_t *out_data; int n, result; - int channel_count = av_get_channel_layout_nb_channels(in->channel_layout); + int channel_count = in->ch_layout.nb_channels; out = ff_get_audio_buffer(outlink, in->nb_samples); if (!out) { diff --git a/libavfilter/af_join.c b/libavfilter/af_join.c index b61033f7a2..6c000b9257 100644 --- a/libavfilter/af_join.c +++ b/libavfilter/af_join.c @@ -37,8 +37,8 @@ typedef struct ChannelMap { int input; ///< input stream index int in_channel_idx; ///< index of in_channel in the input stream data - uint64_t in_channel; ///< layout describing the input channel - uint64_t out_channel; ///< layout describing the output channel + enum AVChannel in_channel; ///< input channel + enum AVChannel out_channel; ///< output channel } ChannelMap; typedef struct JoinContext { @@ -46,8 +46,7 @@ typedef struct JoinContext { int inputs; char *map; - char *channel_layout_str; - uint64_t channel_layout; + AVChannelLayout ch_layout; int nb_channels; ChannelMap *channels; @@ -68,7 +67,7 @@ typedef struct JoinContext { static const AVOption join_options[] = { { "inputs", "Number of input streams.", OFFSET(inputs), AV_OPT_TYPE_INT, { .i64 = 2 }, 1, INT_MAX, A }, { "channel_layout", "Channel layout of the " - "output stream.", OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0, A }, + "output stream.", OFFSET(ch_layout), AV_OPT_TYPE_CHANNEL_LAYOUT, {.str = "stereo"}, 0, 0, A }, { "map", "A comma-separated list of channels maps in the format " "'input_stream.input_channel-output_channel.", OFFSET(map), AV_OPT_TYPE_STRING, .flags = A }, @@ -106,7 +105,7 @@ static int parse_maps(AVFilterContext *ctx) while (cur && *cur) { char *sep, *next, *p; - uint64_t in_channel = 0, out_channel = 0; + enum AVChannel in_channel = -1, out_channel; int input_idx, out_ch_idx, in_ch_idx; next = strchr(cur, separator); @@ -122,26 +121,22 @@ static int parse_maps(AVFilterContext *ctx) *sep++ = 0; #define PARSE_CHANNEL(str, var, inout) \ - if (!(var = av_get_channel_layout(str))) { \ + var = av_channel_from_string(str); \ + if ((int) var < 0) { \ av_log(ctx, AV_LOG_ERROR, "Invalid " inout " channel: %s.\n", str);\ return AVERROR(EINVAL); \ } \ - if (av_get_channel_layout_nb_channels(var) != 1) { \ - av_log(ctx, AV_LOG_ERROR, "Channel map describes more than one " \ - inout " channel.\n"); \ - return AVERROR(EINVAL); \ - } /* parse output channel */ PARSE_CHANNEL(sep, out_channel, "output"); - if (!(out_channel & s->channel_layout)) { + + out_ch_idx = av_channel_layout_channel_index(&s->ch_layout, + out_channel); + if (out_ch_idx < 0) { av_log(ctx, AV_LOG_ERROR, "Output channel '%s' is not present in " "requested channel layout.\n", sep); return AVERROR(EINVAL); } - - out_ch_idx = av_get_channel_layout_channel_index(s->channel_layout, - out_channel); if (s->channels[out_ch_idx].input >= 0) { av_log(ctx, AV_LOG_ERROR, "Multiple maps for output channel " "'%s'.\n", sep); @@ -167,7 +162,7 @@ static int parse_maps(AVFilterContext *ctx) } s->channels[out_ch_idx].input = input_idx; - if (in_channel) + if ((int) in_channel >= 0) s->channels[out_ch_idx].in_channel = in_channel; else s->channels[out_ch_idx].in_channel_idx = in_ch_idx; @@ -182,14 +177,7 @@ static av_cold int join_init(AVFilterContext *ctx) JoinContext *s = ctx->priv; int ret, i; - if (!(s->channel_layout = av_get_channel_layout(s->channel_layout_str))) { - av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout '%s'.\n", - s->channel_layout_str); - ret = AVERROR(EINVAL); - goto fail; - } - - s->nb_channels = av_get_channel_layout_nb_channels(s->channel_layout); + s->nb_channels = s->ch_layout.nb_channels; s->channels = av_mallocz(sizeof(*s->channels) * s->nb_channels); s->buffers = av_mallocz(sizeof(*s->buffers) * s->nb_channels); s->input_frames = av_mallocz(sizeof(*s->input_frames) * s->inputs); @@ -199,7 +187,7 @@ static av_cold int join_init(AVFilterContext *ctx) } for (i = 0; i < s->nb_channels; i++) { - s->channels[i].out_channel = av_channel_layout_extract_channel(s->channel_layout, i); + s->channels[i].out_channel = av_channel_layout_get_channel(&s->ch_layout, i); s->channels[i].input = -1; } @@ -246,7 +234,7 @@ static int join_query_formats(AVFilterContext *ctx) AVFilterChannelLayouts *layouts = NULL; int i; - ff_add_channel_layout(&layouts, s->channel_layout); + ff_add_channel_layout(&layouts, s->ch_layout.u.mask); ff_channel_layouts_ref(layouts, &ctx->outputs[0]->in_channel_layouts); for (i = 0; i < ctx->nb_inputs; i++) @@ -267,11 +255,11 @@ static void guess_map_matching(AVFilterContext *ctx, ChannelMap *ch, for (i = 0; i < ctx->nb_inputs; i++) { AVFilterLink *link = ctx->inputs[i]; - if (ch->out_channel & link->channel_layout && - !(ch->out_channel & inputs[i])) { + if (av_channel_layout_channel_index(&link->ch_layout, ch->out_channel) >= 0 && + !((1ULL << ch->out_channel) & inputs[i])) { ch->input = i; ch->in_channel = ch->out_channel; - inputs[i] |= ch->out_channel; + inputs[i] |= 1ULL << ch->out_channel; return; } } @@ -285,12 +273,14 @@ static void guess_map_any(AVFilterContext *ctx, ChannelMap *ch, for (i = 0; i < ctx->nb_inputs; i++) { AVFilterLink *link = ctx->inputs[i]; - if ((inputs[i] & link->channel_layout) != link->channel_layout) { - uint64_t unused = link->channel_layout & ~inputs[i]; + if ((inputs[i] & link->ch_layout.u.mask) != link->ch_layout.u.mask) { + uint64_t unused = link->ch_layout.u.mask & ~inputs[i]; + AVChannelLayout layout = {0}; + av_channel_layout_from_mask(&layout, unused); ch->input = i; - ch->in_channel = av_channel_layout_extract_channel(unused, 0); - inputs[i] |= ch->in_channel; + ch->in_channel = av_channel_layout_get_channel(&layout, 0); + inputs[i] |= 1ULL << ch->in_channel; return; } } @@ -315,19 +305,19 @@ static int join_config_output(AVFilterLink *outlink) inlink = ctx->inputs[ch->input]; - if (!ch->in_channel) - ch->in_channel = av_channel_layout_extract_channel(inlink->channel_layout, - ch->in_channel_idx); + if ((int) ch->in_channel < 0) + ch->in_channel = av_channel_layout_get_channel(&inlink->ch_layout, + ch->in_channel_idx); - if (!(ch->in_channel & inlink->channel_layout)) { + if ((int) ch->in_channel < 0) { av_log(ctx, AV_LOG_ERROR, "Requested channel %s is not present in " - "input stream #%d.\n", av_get_channel_name(ch->in_channel), + "input stream #%d.\n", av_channel_name(ch->in_channel), ch->input); ret = AVERROR(EINVAL); goto fail; } - inputs[ch->input] |= ch->in_channel; + inputs[ch->input] |= 1ULL << ch->in_channel; } /* guess channel maps when not explicitly defined */ @@ -349,12 +339,12 @@ static int join_config_output(AVFilterLink *outlink) if (ch->input < 0) { av_log(ctx, AV_LOG_ERROR, "Could not find input channel for " "output channel '%s'.\n", - av_get_channel_name(ch->out_channel)); + av_channel_name(ch->out_channel)); goto fail; } - ch->in_channel_idx = av_get_channel_layout_channel_index(ctx->inputs[ch->input]->channel_layout, - ch->in_channel); + ch->in_channel_idx = av_channel_layout_channel_index(&ctx->inputs[ch->input]->ch_layout, + ch->in_channel); } /* print mappings */ @@ -362,8 +352,8 @@ static int join_config_output(AVFilterLink *outlink) for (i = 0; i < s->nb_channels; i++) { ChannelMap *ch = &s->channels[i]; av_log(ctx, AV_LOG_VERBOSE, "%d.%s => %s ", ch->input, - av_get_channel_name(ch->in_channel), - av_get_channel_name(ch->out_channel)); + av_channel_name(ch->in_channel), + av_channel_name(ch->out_channel)); } av_log(ctx, AV_LOG_VERBOSE, "\n"); @@ -469,7 +459,9 @@ static int join_request_frame(AVFilterLink *outlink) } frame->nb_samples = nb_samples; - frame->channel_layout = outlink->channel_layout; + ret = av_channel_layout_copy(&frame->ch_layout, &outlink->ch_layout); + if (ret < 0) + goto fail; frame->sample_rate = outlink->sample_rate; frame->format = outlink->format; frame->pts = s->input_frames[0]->pts; diff --git a/libavfilter/af_resample.c b/libavfilter/af_resample.c index 413b6634cc..09984b8a7e 100644 --- a/libavfilter/af_resample.c +++ b/libavfilter/af_resample.c @@ -65,8 +65,8 @@ static av_cold int init(AVFilterContext *ctx, AVDictionary **opts) av_dict_set(opts, e->key, NULL, 0); /* do not allow the user to override basic format options */ - av_dict_set(&s->options, "in_channel_layout", NULL, 0); - av_dict_set(&s->options, "out_channel_layout", NULL, 0); + av_dict_set(&s->options, "in_ch_layout", NULL, 0); + av_dict_set(&s->options, "out_ch_layout", NULL, 0); av_dict_set(&s->options, "in_sample_fmt", NULL, 0); av_dict_set(&s->options, "out_sample_fmt", NULL, 0); av_dict_set(&s->options, "in_sample_rate", NULL, 0); @@ -115,7 +115,7 @@ static int config_output(AVFilterLink *outlink) AVFilterContext *ctx = outlink->src; AVFilterLink *inlink = ctx->inputs[0]; ResampleContext *s = ctx->priv; - char buf1[64], buf2[64]; + char *inchlstr, *outchlstr; int ret; int64_t resampling_forced; @@ -125,11 +125,11 @@ static int config_output(AVFilterLink *outlink) avresample_free(&s->avr); } - if (inlink->channel_layout == outlink->channel_layout && + if (!av_channel_layout_compare(&inlink->ch_layout, &outlink->ch_layout) && inlink->sample_rate == outlink->sample_rate && (inlink->format == outlink->format || - (av_get_channel_layout_nb_channels(inlink->channel_layout) == 1 && - av_get_channel_layout_nb_channels(outlink->channel_layout) == 1 && + (inlink->ch_layout.nb_channels == 1 && + outlink->ch_layout.nb_channels == 1 && av_get_planar_sample_fmt(inlink->format) == av_get_planar_sample_fmt(outlink->format)))) return 0; @@ -148,8 +148,8 @@ static int config_output(AVFilterLink *outlink) return ret; } - av_opt_set_int(s->avr, "in_channel_layout", inlink ->channel_layout, 0); - av_opt_set_int(s->avr, "out_channel_layout", outlink->channel_layout, 0); + av_opt_set_channel_layout(s->avr, "in_ch_layout", &inlink->ch_layout, 0); + av_opt_set_channel_layout(s->avr, "out_ch_layout", &outlink->ch_layout, 0); av_opt_set_int(s->avr, "in_sample_fmt", inlink ->format, 0); av_opt_set_int(s->avr, "out_sample_fmt", outlink->format, 0); av_opt_set_int(s->avr, "in_sample_rate", inlink ->sample_rate, 0); @@ -168,14 +168,19 @@ static int config_output(AVFilterLink *outlink) } else outlink->time_base = inlink->time_base; - av_get_channel_layout_string(buf1, sizeof(buf1), - -1, inlink ->channel_layout); - av_get_channel_layout_string(buf2, sizeof(buf2), - -1, outlink->channel_layout); + inchlstr = av_channel_layout_describe(&inlink->ch_layout); + outchlstr = av_channel_layout_describe(&outlink->ch_layout); + if (!inchlstr || !outchlstr) { + av_free(inchlstr); + av_free(outchlstr); + return AVERROR(ENOMEM); + } av_log(ctx, AV_LOG_VERBOSE, "fmt:%s srate:%d cl:%s -> fmt:%s srate:%d cl:%s\n", - av_get_sample_fmt_name(inlink ->format), inlink ->sample_rate, buf1, - av_get_sample_fmt_name(outlink->format), outlink->sample_rate, buf2); + av_get_sample_fmt_name(inlink ->format), inlink ->sample_rate, inchlstr, + av_get_sample_fmt_name(outlink->format), outlink->sample_rate, outchlstr); + av_free(inchlstr); + av_free(outchlstr); return 0; } diff --git a/libavfilter/af_volume.c b/libavfilter/af_volume.c index 0ec42b031e..bbadd87d47 100644 --- a/libavfilter/af_volume.c +++ b/libavfilter/af_volume.c @@ -228,7 +228,7 @@ static int config_output(AVFilterLink *outlink) AVFilterLink *inlink = ctx->inputs[0]; vol->sample_fmt = inlink->format; - vol->channels = av_get_channel_layout_nb_channels(inlink->channel_layout); + vol->channels = inlink->ch_layout.nb_channels; vol->planes = av_sample_fmt_is_planar(inlink->format) ? vol->channels : 1; volume_init(vol); diff --git a/libavfilter/trim.c b/libavfilter/trim.c index 2b57540460..df054aa606 100644 --- a/libavfilter/trim.c +++ b/libavfilter/trim.c @@ -336,8 +336,7 @@ static int atrim_filter_frame(AVFilterLink *inlink, AVFrame *frame) av_frame_copy_props(out, frame); av_samples_copy(out->extended_data, frame->extended_data, 0, start_sample, - out->nb_samples, av_get_channel_layout_nb_channels(frame->channel_layout), - frame->format); + out->nb_samples, frame->ch_layout.nb_channels, frame->format); if (out->pts != AV_NOPTS_VALUE) out->pts += av_rescale_q(start_sample, (AVRational){ 1, out->sample_rate }, inlink->time_base); -- 2.13.1 _______________________________________________ libav-devel mailing list [email protected] https://lists.libav.org/mailman/listinfo/libav-devel
