AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int perms,

                                                     enum AVSampleFormat sample_fmt, int size,

                                                     int64_t channel_layout, int planar)

{

    AVFilterBuffer *samples = av_mallocz(sizeof(AVFilterBuffer));

    AVFilterBufferRef *ref = NULL;

    int i, sample_size, chans_nb, bufsize, per_channel_size, step_size = 0;

    char *buf;



    if (!samples || !(ref = av_mallocz(sizeof(AVFilterBufferRef))))

        goto fail;



    ref->buf                   = samples;

    ref->format                = sample_fmt;



    ref->audio = av_mallocz(sizeof(AVFilterBufferRefAudioProps));

    if (!ref->audio)

        goto fail;



    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;



    samples->refcount   = 1;

    samples->free       = ff_avfilter_default_free_buffer;



    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;



    /* 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 < chans_nb; i++)

        samples->linesize[i] = planar > 0 ? per_channel_size : sample_size;

    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;

    buf = av_malloc(bufsize);

    if (!buf)

        goto fail;



    /* 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

     */

    samples->data[0] = buf;

    if (buf && planar) {

        for (i = 1; i < chans_nb; i++) {

            step_size += per_channel_size;

            samples->data[i] = buf + step_size;

        }

    } else {

        for (i = 1; i < chans_nb; i++)

            samples->data[i] = buf;

    }



    memset(&samples->data[chans_nb], 0, (8-chans_nb) * sizeof(samples->data[0]));



    memcpy(ref->data,     samples->data,     sizeof(ref->data));

    memcpy(ref->linesize, samples->linesize, sizeof(ref->linesize));



    return ref;



fail:

    av_free(buf);

    if (ref && ref->audio)

        av_free(ref->audio);

    av_free(ref);

    av_free(samples);

    return NULL;

}

AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int perms,

                                                     enum AVSampleFormat sample_fmt, int size,

                                                     int64_t channel_layout, int planar)

{

    AVFilterBuffer *samples = av_mallocz(sizeof(AVFilterBuffer));

    AVFilterBufferRef *ref = NULL;

    int i, sample_size, chans_nb, bufsize, per_channel_size, step_size = 0;

    char *buf;



    if (!samples || !(ref = av_mallocz(sizeof(AVFilterBufferRef))))

        goto fail;



    ref->buf                   = samples;

    ref->format                = sample_fmt;



    ref->audio = av_mallocz(sizeof(AVFilterBufferRefAudioProps));

    if (!ref->audio)

        goto fail;



    ref->audio->channel_layout = channel_layout;

    ref->audio->size           = size;

    ref->audio->planar         = planar;



    

    ref->perms = perms | AV_PERM_READ;



    samples->refcount   = 1;

    samples->free       = ff_avfilter_default_free_buffer;



    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;



    







    for (i = 0; i < chans_nb; i++)

        samples->linesize[i] = planar > 0 ? per_channel_size : sample_size;

    memset(&samples->linesize[chans_nb], 0, (8-chans_nb) * sizeof(samples->linesize[0]));



    

    bufsize = (size + 15)&~15;

    buf = av_malloc(bufsize);

    if (!buf)

        goto fail;



    





    samples->data[0] = buf;

    if (buf && planar) {

        for (i = 1; i < chans_nb; i++) {

            step_size += per_channel_size;

            samples->data[i] = buf + step_size;

        }

    } else {

        for (i = 1; i < chans_nb; i++)

            samples->data[i] = buf;

    }



    memset(&samples->data[chans_nb], 0, (8-chans_nb) * sizeof(samples->data[0]));



    memcpy(ref->data,     samples->data,     sizeof(ref->data));

    memcpy(ref->linesize, samples->linesize, sizeof(ref->linesize));



    return ref;



fail:

    av_free(buf);

    if (ref && ref->audio)

        av_free(ref->audio);

    av_free(ref);

    av_free(samples);

    return NULL;

}

    av_free(buf);
AVFilterBufferRef *FUNC_0(AVFilterLink *link, int perms,

                                                     enum AVSampleFormat sample_fmt, int size,

                                                     int64_t channel_layout, int planar)

{

    AVFilterBuffer *samples = av_mallocz(sizeof(AVFilterBuffer));

    AVFilterBufferRef *ref = NULL;

    int VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5 = 0;

    char *VAR_6;



    if (!samples || !(ref = av_mallocz(sizeof(AVFilterBufferRef))))

        goto fail;



    ref->VAR_6                   = samples;

    ref->format                = sample_fmt;



    ref->audio = av_mallocz(sizeof(AVFilterBufferRefAudioProps));

    if (!ref->audio)

        goto fail;



    ref->audio->channel_layout = channel_layout;

    ref->audio->size           = size;

    ref->audio->planar         = planar;



    

    ref->perms = perms | AV_PERM_READ;



    samples->refcount   = 1;

    samples->free       = ff_avfilter_default_free_buffer;



    VAR_1 = av_get_bits_per_sample_fmt(sample_fmt) >>3;

    VAR_2 = av_get_channel_layout_nb_channels(channel_layout);



    VAR_4 = size/VAR_2;

    ref->audio->nb_samples = VAR_4/VAR_1;



    







    for (VAR_0 = 0; VAR_0 < VAR_2; VAR_0++)

        samples->linesize[VAR_0] = planar > 0 ? VAR_4 : VAR_1;

    memset(&samples->linesize[VAR_2], 0, (8-VAR_2) * sizeof(samples->linesize[0]));



    

    VAR_3 = (size + 15)&~15;

    VAR_6 = av_malloc(VAR_3);

    if (!VAR_6)

        goto fail;



    





    samples->data[0] = VAR_6;

    if (VAR_6 && planar) {

        for (VAR_0 = 1; VAR_0 < VAR_2; VAR_0++) {

            VAR_5 += VAR_4;

            samples->data[VAR_0] = VAR_6 + VAR_5;

        }

    } else {

        for (VAR_0 = 1; VAR_0 < VAR_2; VAR_0++)

            samples->data[VAR_0] = VAR_6;

    }



    memset(&samples->data[VAR_2], 0, (8-VAR_2) * sizeof(samples->data[0]));



    memcpy(ref->data,     samples->data,     sizeof(ref->data));

    memcpy(ref->linesize, samples->linesize, sizeof(ref->linesize));



    return ref;



fail:

    av_free(VAR_6);

    if (ref && ref->audio)

        av_free(ref->audio);

    av_free(ref);

    av_free(samples);

    return NULL;

}

AVFilterBufferRef *FUNC_0(AVFilterLink *link, int perms,
enum AVSampleFormat sample_fmt, int size,
int64_t channel_layout, int planar)
{ AVFilterBuffer *samples = av_mallocz(sizeof(AVFilterBuffer)); AVFilterBufferRef *ref = NULL; int VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5 = 0; char *VAR_6; if (!samples || !(ref = av_mallocz(sizeof(AVFilterBufferRef))))
goto fail; ref->VAR_6                   = samples; ref->format                = sample_fmt; ref->audio = av_mallocz(sizeof(AVFilterBufferRefAudioProps)); if (!ref->audio)
goto fail; ref->audio->channel_layout = channel_layout; ref->audio->size           = size; ref->audio->planar         = planar; ref->perms = perms | AV_PERM_READ; samples->refcount   = 1; samples->free       = ff_avfilter_default_free_buffer; VAR_1 = av_get_bits_per_sample_fmt(sample_fmt) >>3; VAR_2 = av_get_channel_layout_nb_channels(channel_layout); VAR_4 = size/VAR_2; ref->audio->nb_samples = VAR_4/VAR_1; for (VAR_0 = 0; VAR_0 < VAR_2; VAR_0++) samples->linesize[VAR_0] = planar > 0 ? VAR_4 : VAR_1; memset(&samples->linesize[VAR_2], 0, (8-VAR_2) * sizeof(samples->linesize[0])); VAR_3 = (size + 15)&~15; VAR_6 = av_malloc(VAR_3); if (!VAR_6)
goto fail; samples->data[0] = VAR_6; if (VAR_6 && planar) { for (VAR_0 = 1; VAR_0 < VAR_2; VAR_0++) { VAR_5 += VAR_4; samples->data[VAR_0] = VAR_6 + VAR_5; } } else { for (VAR_0 = 1; VAR_0 < VAR_2; VAR_0++) samples->data[VAR_0] = VAR_6; } memset(&samples->data[VAR_2], 0, (8-VAR_2) * sizeof(samples->data[0])); memcpy(ref->data,     samples->data,     sizeof(ref->data)); memcpy(ref->linesize, samples->linesize, sizeof(ref->linesize)); return ref; fail:
av_free(VAR_6); if (ref && ref->audio)
av_free(ref->audio); av_free(ref); av_free(samples); return NULL; }