diff --git a/libavfilter/af_aresample.c b/libavfilter/af_aresample.c index 03c8f01ef5..86061193a0 100644 --- a/libavfilter/af_aresample.c +++ b/libavfilter/af_aresample.c @@ -184,6 +184,7 @@ static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *insamplesref) avfilter_copy_buffer_ref_props(outsamplesref, insamplesref); outsamplesref->format = outlink->format; + outsamplesref->audio->channels = outlink->channels; outsamplesref->audio->channel_layout = outlink->channel_layout; outsamplesref->audio->sample_rate = outlink->sample_rate; diff --git a/libavfilter/af_pan.c b/libavfilter/af_pan.c index 922025ab88..77ca549167 100644 --- a/libavfilter/af_pan.c +++ b/libavfilter/af_pan.c @@ -364,6 +364,7 @@ static int filter_frame(AVFilterLink *inlink, AVFilterBufferRef *insamples) swr_convert(pan->swr, outsamples->data, n, (void *)insamples->data, n); avfilter_copy_buffer_ref_props(outsamples, insamples); outsamples->audio->channel_layout = outlink->channel_layout; + outsamples->audio->channels = outlink->channels; ret = ff_filter_frame(outlink, outsamples); avfilter_unref_buffer(insamples); diff --git a/libavfilter/audio.c b/libavfilter/audio.c index f157e877cd..565f2e264c 100644 --- a/libavfilter/audio.c +++ b/libavfilter/audio.c @@ -93,6 +93,7 @@ AVFilterBufferRef* avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data, enum AVSampleFormat sample_fmt, uint64_t channel_layout) { + int channels = av_get_channel_layout_nb_channels(channel_layout); int planes; AVFilterBuffer *samples = av_mallocz(sizeof(*samples)); AVFilterBufferRef *samplesref = av_mallocz(sizeof(*samplesref)); @@ -107,9 +108,9 @@ AVFilterBufferRef* avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data, samplesref->audio->nb_samples = nb_samples; samplesref->audio->channel_layout = channel_layout; + samplesref->audio->channels = channels; - planes = av_sample_fmt_is_planar(sample_fmt) ? - av_get_channel_layout_nb_channels(channel_layout) : 1; + planes = av_sample_fmt_is_planar(sample_fmt) ? channels : 1; /* make sure the buffer gets read permission or it's useless for output */ samplesref->perms = perms | AV_PERM_READ; @@ -225,6 +226,7 @@ int ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) int ret = 0; av_assert1(samplesref->format == link->format); + av_assert1(samplesref->audio->channels == link->channels); av_assert1(samplesref->audio->channel_layout == link->channel_layout); av_assert1(samplesref->audio->sample_rate == link->sample_rate); diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c index 31580f6175..392e32df1c 100644 --- a/libavfilter/avfilter.c +++ b/libavfilter/avfilter.c @@ -164,6 +164,11 @@ void avfilter_link_free(AVFilterLink **link) av_freep(link); } +int avfilter_link_get_channels(AVFilterLink *link) +{ + return link->channels; +} + void avfilter_link_set_closed(AVFilterLink *link, int closed) { link->closed = closed; diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h index 50472451bc..5234a66201 100644 --- a/libavfilter/avfilter.h +++ b/libavfilter/avfilter.h @@ -699,6 +699,11 @@ struct AVFilterLink { * filter. */ int closed; + + /** + * Number of channels. + */ + int channels; }; /** @@ -718,6 +723,11 @@ int avfilter_link(AVFilterContext *src, unsigned srcpad, */ void avfilter_link_free(AVFilterLink **link); +/** + * Get the number of channels of a link. + */ +int avfilter_link_get_channels(AVFilterLink *link); + /** * Set the closed field of a link. */ diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c index 52af2adbfc..9164559779 100644 --- a/libavfilter/avfiltergraph.c +++ b/libavfilter/avfiltergraph.c @@ -473,6 +473,7 @@ static int pick_format(AVFilterLink *link, AVFilterLink *ref) } link->in_channel_layouts->nb_channel_layouts = 1; link->channel_layout = link->in_channel_layouts->channel_layouts[0]; + link->channels = av_get_channel_layout_nb_channels(link->channel_layout); } ff_formats_unref(&link->in_formats);