aboutsummaryrefslogtreecommitdiffstats
path: root/libavfilter/audio.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2012-11-28 08:41:07 +0100
committerAnton Khirnov <anton@khirnov.net>2013-03-08 07:37:18 +0100
commit7e350379f87e7f74420b4813170fe808e2313911 (patch)
tree031201839361d40af8b4c829f9c9f179e7d9f58d /libavfilter/audio.c
parent77b2cd7b41d7ec8008b6fac753c04f77824c514c (diff)
downloadffmpeg-7e350379f87e7f74420b4813170fe808e2313911.tar.gz
lavfi: switch to AVFrame.
Deprecate AVFilterBuffer/AVFilterBufferRef and everything related to it and use AVFrame instead.
Diffstat (limited to 'libavfilter/audio.c')
-rw-r--r--libavfilter/audio.c68
1 files changed, 37 insertions, 31 deletions
diff --git a/libavfilter/audio.c b/libavfilter/audio.c
index bbe12b211b..5295423e44 100644
--- a/libavfilter/audio.c
+++ b/libavfilter/audio.c
@@ -23,60 +23,65 @@
#include "avfilter.h"
#include "internal.h"
-AVFilterBufferRef *ff_null_get_audio_buffer(AVFilterLink *link, int perms,
- int nb_samples)
+AVFrame *ff_null_get_audio_buffer(AVFilterLink *link, int nb_samples)
{
- return ff_get_audio_buffer(link->dst->outputs[0], perms, nb_samples);
+ return ff_get_audio_buffer(link->dst->outputs[0], nb_samples);
}
-AVFilterBufferRef *ff_default_get_audio_buffer(AVFilterLink *link, int perms,
- int nb_samples)
+AVFrame *ff_default_get_audio_buffer(AVFilterLink *link, int nb_samples)
{
- AVFilterBufferRef *samplesref = NULL;
- uint8_t **data;
- int planar = av_sample_fmt_is_planar(link->format);
- int nb_channels = av_get_channel_layout_nb_channels(link->channel_layout);
- int planes = planar ? nb_channels : 1;
- int linesize;
-
- if (!(data = av_mallocz(sizeof(*data) * planes)))
+ AVFrame *frame = av_frame_alloc();
+ int channels = av_get_channel_layout_nb_channels(link->channel_layout);
+ int buf_size, 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;
- if (av_samples_alloc(data, &linesize, nb_channels, nb_samples, link->format, 0) < 0)
+ frame->buf[0] = av_buffer_alloc(buf_size);
+ if (!frame->buf[0])
goto fail;
- samplesref = avfilter_get_audio_buffer_ref_from_arrays(data, linesize, perms,
- nb_samples, link->format,
- link->channel_layout);
- if (!samplesref)
+ 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_freep(&data);
+ 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;
+
+ return frame;
fail:
- if (data)
- av_freep(&data[0]);
- av_freep(&data);
- return samplesref;
+ av_buffer_unref(&frame->buf[0]);
+ av_frame_free(&frame);
+ return NULL;
}
-AVFilterBufferRef *ff_get_audio_buffer(AVFilterLink *link, int perms,
- int nb_samples)
+AVFrame *ff_get_audio_buffer(AVFilterLink *link, int nb_samples)
{
- AVFilterBufferRef *ret = NULL;
+ AVFrame *ret = NULL;
if (link->dstpad->get_audio_buffer)
- ret = link->dstpad->get_audio_buffer(link, perms, nb_samples);
+ ret = link->dstpad->get_audio_buffer(link, nb_samples);
if (!ret)
- ret = ff_default_get_audio_buffer(link, perms, nb_samples);
-
- if (ret)
- ret->type = AVMEDIA_TYPE_AUDIO;
+ ret = ff_default_get_audio_buffer(link, nb_samples);
return ret;
}
+#if FF_API_AVFILTERBUFFER
AVFilterBufferRef* avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data,
int linesize,int perms,
int nb_samples,
@@ -146,3 +151,4 @@ fail:
av_freep(&samples);
return NULL;
}
+#endif