[FFmpeg-devel] [PATCH] lavfi: prefer nb_samples over size in AVFilterBufferRefAudioProps
Stefano Sabatini
stefano.sabatini-lala at poste.it
Mon May 23 00:14:27 CEST 2011
Remove AVFilterBufferRefAudioProps.size, and use nb_samples in
avfilter_get_audio_buffer() and avfilter_default_get_audio_buffer() in
place of size.
This is required as the size in the audio buffer may be aligned, so it
may not contain a well defined number of samples.
---
libavfilter/avfilter.c | 15 ++++++++-------
libavfilter/avfilter.h | 11 +++++------
libavfilter/defaults.c | 11 +++++------
3 files changed, 18 insertions(+), 19 deletions(-)
diff --git a/libavfilter/avfilter.c b/libavfilter/avfilter.c
index 72e0a87..79326a0 100644
--- a/libavfilter/avfilter.c
+++ b/libavfilter/avfilter.c
@@ -280,10 +280,9 @@ static void ff_dlog_ref(void *ctx, AVFilterBufferRef *ref, int end)
av_get_picture_type_char(ref->video->pict_type));
}
if (ref->audio) {
- av_dlog(ctx, " cl:%"PRId64"d sn:%d s:%d sr:%d p:%d",
+ av_dlog(ctx, " cl:%"PRId64"d n:%d r:%d p:%d",
ref->audio->channel_layout,
ref->audio->nb_samples,
- ref->audio->size,
ref->audio->sample_rate,
ref->audio->planar);
}
@@ -380,16 +379,16 @@ fail:
}
AVFilterBufferRef *avfilter_get_audio_buffer(AVFilterLink *link, int perms,
- enum AVSampleFormat sample_fmt, int size,
+ enum AVSampleFormat sample_fmt, int nb_samples,
int64_t channel_layout, int planar)
{
AVFilterBufferRef *ret = NULL;
if (link->dstpad->get_audio_buffer)
- ret = link->dstpad->get_audio_buffer(link, perms, sample_fmt, size, channel_layout, planar);
+ ret = link->dstpad->get_audio_buffer(link, perms, sample_fmt, nb_samples, channel_layout, planar);
if (!ret)
- ret = avfilter_default_get_audio_buffer(link, perms, sample_fmt, size, channel_layout, planar);
+ ret = avfilter_default_get_audio_buffer(link, perms, sample_fmt, nb_samples, channel_layout, planar);
if (ret)
ret->type = AVMEDIA_TYPE_AUDIO;
@@ -520,6 +519,7 @@ void avfilter_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
{
void (*filter_samples)(AVFilterLink *, AVFilterBufferRef *);
AVFilterPad *dst = link->dstpad;
+ int i;
FF_DPRINTF_START(NULL, filter_samples); ff_dlog_link(NULL, link, 1);
@@ -536,14 +536,15 @@ void avfilter_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
link->cur_buf = avfilter_default_get_audio_buffer(link, dst->min_perms,
samplesref->format,
- samplesref->audio->size,
+ samplesref->audio->nb_samples,
samplesref->audio->channel_layout,
samplesref->audio->planar);
link->cur_buf->pts = samplesref->pts;
link->cur_buf->audio->sample_rate = samplesref->audio->sample_rate;
/* Copy actual data into new samples buffer */
- memcpy(link->cur_buf->data[0], samplesref->data[0], samplesref->audio->size);
+ for (i = 0; samplesref->data[i]; i++)
+ memcpy(link->cur_buf->data[i], samplesref->data[i], samplesref->linesize[0]);
avfilter_unref_buffer(samplesref);
} else
diff --git a/libavfilter/avfilter.h b/libavfilter/avfilter.h
index cee5bbc..6c7c103 100644
--- a/libavfilter/avfilter.h
+++ b/libavfilter/avfilter.h
@@ -98,8 +98,7 @@ typedef struct AVFilterBuffer {
*/
typedef struct AVFilterBufferRefAudioProps {
int64_t channel_layout; ///< channel layout of audio buffer
- int nb_samples; ///< number of audio samples
- int size; ///< audio buffer size
+ int nb_samples; ///< number of audio samples per channel
uint32_t sample_rate; ///< audio buffer sample rate
int planar; ///< audio buffer - planar or packed
} AVFilterBufferRefAudioProps;
@@ -372,7 +371,7 @@ struct AVFilterPad {
* Input audio pads only.
*/
AVFilterBufferRef *(*get_audio_buffer)(AVFilterLink *link, int perms,
- enum AVSampleFormat sample_fmt, int size,
+ enum AVSampleFormat sample_fmt, int nb_samples,
int64_t channel_layout, int planar);
/**
@@ -461,7 +460,7 @@ AVFilterBufferRef *avfilter_default_get_video_buffer(AVFilterLink *link,
/** default handler for get_audio_buffer() for audio inputs */
AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int perms,
- enum AVSampleFormat sample_fmt, int size,
+ enum AVSampleFormat sample_fmt, int nb_samples,
int64_t channel_layout, int planar);
/**
@@ -679,14 +678,14 @@ avfilter_get_video_buffer_ref_from_arrays(uint8_t *data[4], int linesize[4], int
* be requested
* @param perms the required access permissions
* @param sample_fmt the format of each sample in the buffer to allocate
- * @param size the buffer size in bytes
+ * @param nb_samples the number of samples per channel
* @param channel_layout the number and type of channels per sample in the buffer to allocate
* @param planar audio data layout - planar or packed
* @return A reference to the samples. This must be unreferenced with
* avfilter_unref_buffer when you are finished with it.
*/
AVFilterBufferRef *avfilter_get_audio_buffer(AVFilterLink *link, int perms,
- enum AVSampleFormat sample_fmt, int size,
+ enum AVSampleFormat sample_fmt, int nb_samples,
int64_t channel_layout, int planar);
/**
diff --git a/libavfilter/defaults.c b/libavfilter/defaults.c
index 9ee23e5..854a105 100644
--- a/libavfilter/defaults.c
+++ b/libavfilter/defaults.c
@@ -79,7 +79,7 @@ AVFilterBufferRef *avfilter_default_get_video_buffer(AVFilterLink *link, int per
}
AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int perms,
- enum AVSampleFormat sample_fmt, int size,
+ enum AVSampleFormat sample_fmt, int nb_samples,
int64_t channel_layout, int planar)
{
AVFilterBuffer *samples = av_mallocz(sizeof(AVFilterBuffer));
@@ -98,7 +98,7 @@ AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int per
goto fail;
ref->audio->channel_layout = channel_layout;
- ref->audio->size = size;
+ ref->audio->nb_samples = nb_samples;
ref->audio->planar = planar;
/* make sure the buffer gets read permission or it's useless for output */
@@ -110,8 +110,7 @@ AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int per
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;
+ per_channel_size = nb_samples * 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.
@@ -122,7 +121,7 @@ AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int per
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;
+ bufsize = (nb_samples * chans_nb * sample_size + 15)&~15;
buf = av_malloc(bufsize);
if (!buf)
goto fail;
@@ -210,7 +209,7 @@ void avfilter_default_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *sa
if (outlink) {
outlink->out_buf = avfilter_default_get_audio_buffer(inlink, AV_PERM_WRITE, samplesref->format,
- samplesref->audio->size,
+ samplesref->audio->nb_samples,
samplesref->audio->channel_layout,
samplesref->audio->planar);
outlink->out_buf->pts = samplesref->pts;
--
1.7.2.3
More information about the ffmpeg-devel
mailing list