[FFmpeg-devel] [PATCH 01/10] lavfi: add avfilter_get_audio_buffer_ref_from_arrays_channels.
Nicolas George
nicolas.george at normalesup.org
Mon Dec 31 18:57:58 CET 2012
It is the same as avfilter_get_audio_buffer_ref_from_arrays
except it has a "channels" and the channel layout can be 0.
Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
---
libavfilter/audio.c | 34 +++++++++++++++++++++++++---------
libavfilter/avcodec.c | 7 ++++---
libavfilter/avfilter.h | 21 +++++++++++++++++++++
libavfilter/src_buffer.c | 2 ++
4 files changed, 52 insertions(+), 12 deletions(-)
Changed the name.
diff --git a/libavfilter/audio.c b/libavfilter/audio.c
index 3564896..ca076fc 100644
--- a/libavfilter/audio.c
+++ b/libavfilter/audio.c
@@ -58,9 +58,9 @@ AVFilterBufferRef *ff_default_get_audio_buffer(AVFilterLink *link, int perms,
if (av_samples_alloc(data, &linesize, nb_channels, nb_samples, link->format, 0) < 0)
goto fail;
- samplesref = avfilter_get_audio_buffer_ref_from_arrays(data, linesize, full_perms,
- nb_samples, link->format,
- link->channel_layout);
+ samplesref = avfilter_get_audio_buffer_ref_from_arrays_channels(
+ data, linesize, full_perms, nb_samples, link->format,
+ link->channels, link->channel_layout);
if (!samplesref)
goto fail;
@@ -92,13 +92,13 @@ AVFilterBufferRef *ff_get_audio_buffer(AVFilterLink *link, int perms,
return ret;
}
-AVFilterBufferRef* avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data,
- int linesize,int perms,
- int nb_samples,
- enum AVSampleFormat sample_fmt,
- uint64_t channel_layout)
+AVFilterBufferRef* avfilter_get_audio_buffer_ref_from_arrays_channels(uint8_t **data,
+ int linesize,int perms,
+ int nb_samples,
+ enum AVSampleFormat sample_fmt,
+ int channels,
+ 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));
@@ -106,6 +106,10 @@ AVFilterBufferRef* avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data,
if (!samples || !samplesref)
goto fail;
+ av_assert0(channels);
+ av_assert0(channel_layout == 0 ||
+ channels == av_get_channel_layout_nb_channels(channel_layout));
+
samplesref->buf = samples;
samplesref->buf->free = ff_avfilter_default_free_buffer;
if (!(samplesref->audio = av_mallocz(sizeof(*samplesref->audio))))
@@ -163,6 +167,18 @@ fail:
return NULL;
}
+AVFilterBufferRef* avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data,
+ int linesize,int perms,
+ int nb_samples,
+ enum AVSampleFormat sample_fmt,
+ uint64_t channel_layout)
+{
+ int channels = av_get_channel_layout_nb_channels(channel_layout);
+ return avfilter_get_audio_buffer_ref_from_arrays_channels(data, linesize, perms,
+ nb_samples, sample_fmt,
+ channels, channel_layout);
+}
+
static int default_filter_frame(AVFilterLink *link, AVFilterBufferRef *frame)
{
return ff_filter_frame(link->dst->outputs[0], frame);
diff --git a/libavfilter/avcodec.c b/libavfilter/avcodec.c
index 2533bd8..dcd6bb6 100644
--- a/libavfilter/avcodec.c
+++ b/libavfilter/avcodec.c
@@ -93,6 +93,7 @@ AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_frame(const AVFrame *frame
int perms)
{
AVFilterBufferRef *samplesref;
+ int channels = av_frame_get_channels(frame);
int64_t layout = av_frame_get_channel_layout(frame);
if(av_frame_get_channels(frame) > 8) // libavfilter does not suport more than 8 channels FIXME, remove once libavfilter is fixed
@@ -103,9 +104,9 @@ AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_frame(const AVFrame *frame
return NULL;
}
- samplesref = avfilter_get_audio_buffer_ref_from_arrays((uint8_t **)frame->data, frame->linesize[0], perms,
- frame->nb_samples, frame->format,
- av_frame_get_channel_layout(frame));
+ samplesref = avfilter_get_audio_buffer_ref_from_arrays_channels(
+ (uint8_t **)frame->data, frame->linesize[0], perms,
+ frame->nb_samples, frame->format, channels, layout);
if (!samplesref)
return NULL;
if (avfilter_copy_frame_props(samplesref, frame) < 0) {
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index 3849c7b..d7995fc 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -778,6 +778,27 @@ AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data,
int nb_samples,
enum AVSampleFormat sample_fmt,
uint64_t channel_layout);
+/**
+ * Create an audio buffer reference wrapped around an already
+ * allocated samples buffer.
+ *
+ * @param data pointers to the samples plane buffers
+ * @param linesize linesize for the samples plane buffers
+ * @param perms the required access permissions
+ * @param nb_samples number of samples per channel
+ * @param sample_fmt the format of each sample in the buffer to allocate
+ * @param channels the number of channels of the buffer
+ * @param channel_layout the channel layout of the buffer,
+ * must be either 0 or consistent with channels
+ */
+AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_arrays_channels(uint8_t **data,
+ int linesize,
+ int perms,
+ int nb_samples,
+ enum AVSampleFormat sample_fmt,
+ int channels,
+ uint64_t channel_layout);
+
#define AVFILTER_CMD_FLAG_ONE 1 ///< Stop once a filter understood the command (for target=all for example), fast filters are favored automatically
diff --git a/libavfilter/src_buffer.c b/libavfilter/src_buffer.c
index acd490b..a997034 100644
--- a/libavfilter/src_buffer.c
+++ b/libavfilter/src_buffer.c
@@ -81,6 +81,8 @@ int av_asrc_buffer_add_samples(AVFilterContext *ctx,
{
AVFilterBufferRef *samplesref;
+ if (!channel_layout)
+ return AVERROR(EINVAL);
samplesref = avfilter_get_audio_buffer_ref_from_arrays(
data, linesize[0], AV_PERM_WRITE,
nb_samples,
--
1.7.10.4
More information about the ffmpeg-devel
mailing list