lavfi: prefer nb_samples over size in AVFilterBufferRefAudioProps

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.
pull/2/head
Stefano Sabatini 14 years ago
parent 0bc2cca12f
commit 95a0242642
  1. 5
      doc/APIchanges
  2. 15
      libavfilter/avfilter.c
  3. 13
      libavfilter/avfilter.h
  4. 11
      libavfilter/defaults.c

@ -13,6 +13,11 @@ libavutil: 2011-04-18
API changes, most recent first: API changes, most recent first:
2011-06-06 - xxxxxx - lavfi 2.14.0 - AVFilterBufferRefAudioProps
Remove AVFilterBufferRefAudioProps.size, and use nb_samples in
avfilter_get_audio_buffer() and avfilter_default_get_audio_buffer() in
place of size.
2011-06-06 - xxxxxx - lavu 51.6.0 - av_samples_alloc() 2011-06-06 - xxxxxx - lavu 51.6.0 - av_samples_alloc()
Switch nb_channels and nb_samples parameters order in Switch nb_channels and nb_samples parameters order in
av_samples_alloc(). av_samples_alloc().

@ -305,10 +305,9 @@ static void ff_dlog_ref(void *ctx, AVFilterBufferRef *ref, int end)
av_get_picture_type_char(ref->video->pict_type)); av_get_picture_type_char(ref->video->pict_type));
} }
if (ref->audio) { 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->channel_layout,
ref->audio->nb_samples, ref->audio->nb_samples,
ref->audio->size,
ref->audio->sample_rate, ref->audio->sample_rate,
ref->audio->planar); ref->audio->planar);
} }
@ -405,16 +404,16 @@ fail:
} }
AVFilterBufferRef *avfilter_get_audio_buffer(AVFilterLink *link, int perms, 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) int64_t channel_layout, int planar)
{ {
AVFilterBufferRef *ret = NULL; AVFilterBufferRef *ret = NULL;
if (link->dstpad->get_audio_buffer) 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) 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) if (ret)
ret->type = AVMEDIA_TYPE_AUDIO; ret->type = AVMEDIA_TYPE_AUDIO;
@ -545,6 +544,7 @@ void avfilter_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
{ {
void (*filter_samples)(AVFilterLink *, AVFilterBufferRef *); void (*filter_samples)(AVFilterLink *, AVFilterBufferRef *);
AVFilterPad *dst = link->dstpad; AVFilterPad *dst = link->dstpad;
int i;
FF_DPRINTF_START(NULL, filter_samples); ff_dlog_link(NULL, link, 1); FF_DPRINTF_START(NULL, filter_samples); ff_dlog_link(NULL, link, 1);
@ -561,14 +561,15 @@ void avfilter_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
link->cur_buf = avfilter_default_get_audio_buffer(link, dst->min_perms, link->cur_buf = avfilter_default_get_audio_buffer(link, dst->min_perms,
samplesref->format, samplesref->format,
samplesref->audio->size, samplesref->audio->nb_samples,
samplesref->audio->channel_layout, samplesref->audio->channel_layout,
samplesref->audio->planar); samplesref->audio->planar);
link->cur_buf->pts = samplesref->pts; link->cur_buf->pts = samplesref->pts;
link->cur_buf->audio->sample_rate = samplesref->audio->sample_rate; link->cur_buf->audio->sample_rate = samplesref->audio->sample_rate;
/* Copy actual data into new samples buffer */ /* 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); avfilter_unref_buffer(samplesref);
} else } else

@ -26,7 +26,7 @@
#include "libavutil/samplefmt.h" #include "libavutil/samplefmt.h"
#define LIBAVFILTER_VERSION_MAJOR 2 #define LIBAVFILTER_VERSION_MAJOR 2
#define LIBAVFILTER_VERSION_MINOR 13 #define LIBAVFILTER_VERSION_MINOR 14
#define LIBAVFILTER_VERSION_MICRO 0 #define LIBAVFILTER_VERSION_MICRO 0
#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ #define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \
@ -98,8 +98,7 @@ typedef struct AVFilterBuffer {
*/ */
typedef struct AVFilterBufferRefAudioProps { typedef struct AVFilterBufferRefAudioProps {
int64_t channel_layout; ///< channel layout of audio buffer int64_t channel_layout; ///< channel layout of audio buffer
int nb_samples; ///< number of audio samples int nb_samples; ///< number of audio samples per channel
int size; ///< audio buffer size
uint32_t sample_rate; ///< audio buffer sample rate uint32_t sample_rate; ///< audio buffer sample rate
int planar; ///< audio buffer - planar or packed int planar; ///< audio buffer - planar or packed
} AVFilterBufferRefAudioProps; } AVFilterBufferRefAudioProps;
@ -372,7 +371,7 @@ struct AVFilterPad {
* Input audio pads only. * Input audio pads only.
*/ */
AVFilterBufferRef *(*get_audio_buffer)(AVFilterLink *link, int perms, 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); 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 */ /** default handler for get_audio_buffer() for audio inputs */
AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int perms, 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); int64_t channel_layout, int planar);
/** /**
@ -684,14 +683,14 @@ avfilter_get_video_buffer_ref_from_arrays(uint8_t * const data[4], const int lin
* be requested * be requested
* @param perms the required access permissions * @param perms the required access permissions
* @param sample_fmt the format of each sample in the buffer to allocate * @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 channel_layout the number and type of channels per sample in the buffer to allocate
* @param planar audio data layout - planar or packed * @param planar audio data layout - planar or packed
* @return A reference to the samples. This must be unreferenced with * @return A reference to the samples. This must be unreferenced with
* avfilter_unref_buffer when you are finished with it. * avfilter_unref_buffer when you are finished with it.
*/ */
AVFilterBufferRef *avfilter_get_audio_buffer(AVFilterLink *link, int perms, 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); int64_t channel_layout, int planar);
/** /**

@ -81,7 +81,7 @@ AVFilterBufferRef *avfilter_default_get_video_buffer(AVFilterLink *link, int per
} }
AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int perms, 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) int64_t channel_layout, int planar)
{ {
AVFilterBuffer *samples = av_mallocz(sizeof(AVFilterBuffer)); AVFilterBuffer *samples = av_mallocz(sizeof(AVFilterBuffer));
@ -100,7 +100,7 @@ AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int per
goto fail; goto fail;
ref->audio->channel_layout = channel_layout; ref->audio->channel_layout = channel_layout;
ref->audio->size = size; ref->audio->nb_samples = nb_samples;
ref->audio->planar = planar; ref->audio->planar = planar;
/* make sure the buffer gets read permission or it's useless for output */ /* make sure the buffer gets read permission or it's useless for output */
@ -112,8 +112,7 @@ AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int per
sample_size = av_get_bits_per_sample_fmt(sample_fmt) >>3; sample_size = av_get_bits_per_sample_fmt(sample_fmt) >>3;
chans_nb = av_get_channel_layout_nb_channels(channel_layout); chans_nb = av_get_channel_layout_nb_channels(channel_layout);
per_channel_size = size/chans_nb; per_channel_size = nb_samples * sample_size;
ref->audio->nb_samples = per_channel_size/sample_size;
/* Set the number of bytes to traverse to reach next sample of a particular channel: /* Set the number of bytes to traverse to reach next sample of a particular channel:
* For planar, this is simply the sample size. * For planar, this is simply the sample size.
@ -124,7 +123,7 @@ AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int per
memset(&samples->linesize[chans_nb], 0, (8-chans_nb) * sizeof(samples->linesize[0])); 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 */ /* 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); buf = av_malloc(bufsize);
if (!buf) if (!buf)
goto fail; goto fail;
@ -212,7 +211,7 @@ void avfilter_default_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *sa
if (outlink) { if (outlink) {
outlink->out_buf = avfilter_default_get_audio_buffer(inlink, AV_PERM_WRITE, samplesref->format, 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->channel_layout,
samplesref->audio->planar); samplesref->audio->planar);
outlink->out_buf->pts = samplesref->pts; outlink->out_buf->pts = samplesref->pts;

Loading…
Cancel
Save