[PATCH] Use av_samples_fill_arrays() in avfilter_default_get_audio_buffer().

Stefano Sabatini stefano.sabatini-lala
Sat Jan 15 18:48:37 CET 2011


---
 libavfilter/defaults.c |   34 ++++------------------------------
 1 files changed, 4 insertions(+), 30 deletions(-)

diff --git a/libavfilter/defaults.c b/libavfilter/defaults.c
index 36e29f5..da08579 100644
--- a/libavfilter/defaults.c
+++ b/libavfilter/defaults.c
@@ -61,7 +61,7 @@ AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int per
 {
     AVFilterBuffer *samples = av_mallocz(sizeof(AVFilterBuffer));
     AVFilterBufferRef *ref = NULL;
-    int i, sample_size, chans_nb, bufsize, per_channel_size, step_size = 0;
+    int bufsize, nb_channels = av_get_channel_layout_nb_channels(channel_layout);
     char *buf;
 
     if (!samples || !(ref = av_mallocz(sizeof(AVFilterBufferRef))))
@@ -84,41 +84,15 @@ AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int per
     samples->refcount   = 1;
     samples->free       = ff_avfilter_default_free_buffer;
 
-    sample_size = av_get_bits_per_sample_fmt(sample_fmt) >>3;
-    chans_nb = av_get_channel_layout_nb_channels(channel_layout);
-
-    per_channel_size = size/chans_nb;
-    ref->audio->nb_samples = per_channel_size/sample_size;
-
-    /* Set the number of bytes to traverse to reach next sample of a particular channel:
-     * For planar, this is simply the sample size.
-     * For packed, this is the number of channels * sample_size.
-     */
-    for (i = 0; i < chans_nb; i++)
-        samples->linesize[i] = planar ? sample_size : chans_nb * sample_size;
-    memset(&samples->linesize[chans_nb], 0, (8-chans_nb) * sizeof(samples->linesize[0]));
-
     /* Calculate total buffer size, round to multiple of 16 to be SIMD friendly */
     bufsize = (size + 15)&~15;
     buf = av_malloc(bufsize);
     if (!buf)
         goto fail;
 
-    /* For planar, set the start point of each channel's data within the buffer
-     * For packed, set the start point of the entire buffer only
-     */
-    samples->data[0] = buf;
-    if (buf && planar) {
-        for (i = 1; i < chans_nb; i++) {
-            step_size += per_channel_size;
-            samples->data[i] = buf + step_size;
-        }
-    } else {
-        for (i = 1; i < chans_nb; i++)
-            samples->data[i] = buf;
-    }
-
-    memset(&samples->data[chans_nb], 0, (8-chans_nb) * sizeof(samples->data[0]));
+    if (av_samples_fill_arrays(samples->data, samples->linesize,
+                               buf, size, sample_fmt, planar, nb_channels) < 0);
+        goto fail;
 
     memcpy(ref->data,     samples->data,     sizeof(ref->data));
     memcpy(ref->linesize, samples->linesize, sizeof(ref->linesize));
-- 
1.7.2.3


--AhhlLboLdkugWU4S--



More information about the ffmpeg-devel mailing list