[FFmpeg-devel] [PATCH 1/4] lavfi: add a channels field to AVFilterLink.

Nicolas George nicolas.george at normalesup.org
Sun Dec 2 18:39:10 CET 2012


Also: fix af_pan and af_aresample, that forgot to update
audio->channels.

TODO: apichanges entry

Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
 libavfilter/af_aresample.c  |    1 +
 libavfilter/af_pan.c        |    1 +
 libavfilter/audio.c         |    6 ++++--
 libavfilter/avfilter.c      |    5 +++++
 libavfilter/avfilter.h      |   10 ++++++++++
 libavfilter/avfiltergraph.c |    1 +
 6 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/libavfilter/af_aresample.c b/libavfilter/af_aresample.c
index 2dcfd69..f21d0dc 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 922025a..77ca549 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 f157e87..565f2e2 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 31580f6..392e32d 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 f194d33..9c69c3d 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -688,6 +688,11 @@ struct AVFilterLink {
      * filter.
      */
     int closed;
+
+    /**
+     * Number of channels.
+     */
+    int channels;
 };
 
 /**
@@ -708,6 +713,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.
  */
 void avfilter_link_set_closed(AVFilterLink *link, int closed);
diff --git a/libavfilter/avfiltergraph.c b/libavfilter/avfiltergraph.c
index 52af2ad..9164559 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);
-- 
1.7.10.4



More information about the ffmpeg-devel mailing list