[FFmpeg-cvslog] lavfi: add a channels field to AVFilterLink.

Nicolas George git at videolan.org
Thu Dec 20 13:11:39 CET 2012


ffmpeg | branch: master | Nicolas George <nicolas.george at normalesup.org> | Sun Dec  2 16:31:15 2012 +0100| [238edd2fe33da8281b3774196c3de503ea64b745] | committer: Nicolas George

lavfi: add a channels field to AVFilterLink.

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

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=238edd2fe33da8281b3774196c3de503ea64b745
---

 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 03c8f01..8606119 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 5047245..5234a66 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -699,6 +699,11 @@ struct AVFilterLink {
      * filter.
      */
     int closed;
+
+    /**
+     * Number of channels.
+     */
+    int channels;
 };
 
 /**
@@ -719,6 +724,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);



More information about the ffmpeg-cvslog mailing list