[FFmpeg-devel] [PATCH] lavfi audio framework

Michael Niedermayer michaelni
Wed Aug 11 19:59:10 CEST 2010


On Wed, Aug 11, 2010 at 06:54:59AM -0700, S.N. Hemanth Meenakshisundaram wrote:
[...]
> @@ -66,6 +67,66 @@ AVFilterBufferRef *avfilter_default_get_video_buffer(AVFilterLink *link, int per
>      return ref;
>  }
>  
> +AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int perms,
> +                                                     int size, int64_t channel_layout,
> +                                                     enum SampleFormat sample_fmt, int planar)
> +{
> +    AVFilterBuffer *buffer = av_mallocz(sizeof(AVFilterBuffer));
> +    AVFilterBufferRef *ref = av_mallocz(sizeof(AVFilterBufferRef));
> +    int i, sample_size, num_chans, bufsize, per_channel_size, step_size = 0;
> +    char *buf;
> +
> +    ref->buf                   = buffer;
> +    ref->format                = sample_fmt;
> +    ref->audio                 = av_mallocz(sizeof(AVFilterBufferRefAudioProps));
> +    ref->audio->channel_layout = channel_layout;
> +    ref->audio->size           = size;
> +    ref->audio->planar         = planar;
> +
> +    /* make sure the buffer gets read permission or it's useless for output */
> +    ref->perms = perms | AV_PERM_READ;
> +
> +    buffer->refcount   = 1;
> +    buffer->free       = avfilter_default_free_buffer;
> +
> +    sample_size = av_get_bits_per_sample_format(sample_fmt) >>3;
> +    num_chans = avcodec_channel_layout_num_channels(channel_layout);
> +
> +    per_channel_size     = size/num_chans;
> +    ref->audio->samples_nb = per_channel_size/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.
> +     * For packed, this is the number of samples * sample_size.
> +     */
> +    for (i = 0; i < num_chans; i++)
> +        buffer->linesize[i] = (planar > 0)?(per_channel_size):sample_size;
> +    memset(&buffer->linesize[num_chans], 0, (8-num_chans)*sizeof(buffer->linesize[0]));
> +
> +    /* Calculate total buffer size, round to multiple of 16 to be SIMD friendly */
> +    bufsize = (size + 15)&~15;
> +    buf = av_malloc(bufsize);
> +
> +    /* For planar, set the start point of each channel's data within the buffer
> +     * For packed, set the start point of the entire buffer only
> +     */
> +    buffer->data[0] = buf;
> +    if (planar > 0) {

>0 is unneeded


> +        for (i = 1; i < num_chans; i++) {
> +            step_size += per_channel_size;
> +            buffer->data[i] = buf + step_size;
> +        }
> +    } else
> +        memset(&buffer->data[1], (long)buf, (num_chans-1)*sizeof(buffer->data[0]));

data[x] + y*linesize[x] should be a valid pointer to the specific sample
or something similar

also it would be great if bobby could review this patch


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

No great genius has ever existed without some touch of madness. -- Aristotle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100811/17a58fc9/attachment.pgp>



More information about the ffmpeg-devel mailing list