lavfi: switch ff_default_get_audio_buffer() to av_frame_get_buffer()
authorAnton Khirnov <anton@khirnov.net>
Wed, 29 May 2013 19:03:20 +0000 (21:03 +0200)
committerAnton Khirnov <anton@khirnov.net>
Tue, 18 Jun 2013 09:21:16 +0000 (11:21 +0200)
This simplifies the code and avoids using libavcodec-specific
avcodec_fill_audio_frame().

libavfilter/audio.c

index 5295423..b332e9e 100644 (file)
@@ -32,40 +32,26 @@ AVFrame *ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples)
 {
     AVFrame *frame = av_frame_alloc();
     int channels = av_get_channel_layout_nb_channels(link->channel_layout);
-    int buf_size, ret;
+    int ret;
 
     if (!frame)
         return NULL;
 
-    buf_size = av_samples_get_buffer_size(NULL, channels, nb_samples,
-                                          link->format, 0);
-    if (buf_size < 0)
-        goto fail;
-
-    frame->buf[0] = av_buffer_alloc(buf_size);
-    if (!frame->buf[0])
-        goto fail;
-
-    frame->nb_samples = nb_samples;
-    ret = avcodec_fill_audio_frame(frame, channels, link->format,
-                                   frame->buf[0]->data, buf_size, 0);
-    if (ret < 0)
-        goto fail;
-
-    av_samples_set_silence(frame->extended_data, 0, nb_samples, channels,
-                           link->format);
-
     frame->nb_samples     = nb_samples;
     frame->format         = link->format;
     frame->channel_layout = link->channel_layout;
     frame->sample_rate    = link->sample_rate;
+    ret = av_frame_get_buffer(frame, 0);
+    if (ret < 0) {
+        av_frame_free(&frame);
+        return NULL;
+    }
 
-    return frame;
+    av_samples_set_silence(frame->extended_data, 0, nb_samples, channels,
+                           link->format);
 
-fail:
-    av_buffer_unref(&frame->buf[0]);
-    av_frame_free(&frame);
-    return NULL;
+
+    return frame;
 }
 
 AVFrame *ff_get_audio_buffer(AVFilterLink *link, int nb_samples)