[FFmpeg-devel] [PATCH] avcodec: add native Speex decoder

James Almer jamrial at gmail.com
Tue Sep 21 02:03:55 EEST 2021


On 9/20/2021 7:33 PM, Paul B Mahol wrote:
> +static int speex_decode_frame(AVCodecContext *avctx, void *data,
> +                              int *got_frame_ptr, AVPacket *avpkt)
> +{
> +    SpeexContext *s = avctx->priv_data;
> +    AVFrame *frame = data;
> +    const float scale = 1.f / 32768.f;
> +    int buf_size = avpkt->size;
> +    float *dst;
> +    int ret;
> +
> +    if (s->pkt_size && avpkt->size == 62)
> +        buf_size = s->pkt_size;
> +    if ((ret = init_get_bits8(&s->gb, avpkt->data, buf_size)) < 0)
> +        return ret;
> +
> +    frame->nb_samples = s->frame_size * s->frames_per_packet;
> +    if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
> +        return ret;
> +
> +    dst = (float *)frame->extended_data[0];
> +    for (int i = 0; i < s->frames_per_packet; i++) {
> +        ret = speex_modes[s->mode]->decode(avctx, &s->st[s->mode], &s->gb, dst + i * s->frame_size);
> +        if (ret < 0)
> +            return ret;
> +        if (avctx->channels == 2)
> +            speex_decode_stereo(dst + i * s->frame_size, s->frame_size, &s->stereo);
> +    }
> +
> +    dst = (float *)frame->extended_data[0];
> +    for (int n = 0; n < frame->nb_samples * avctx->channels; n++)
> +        dst[n] *= scale;

Does this buffer fulfill the constrains of AVFloatDSPContext's 
vector_fmul_scalar()? Alignment wise i know it does because it's an 
AVFrame buffer, but the length?
If not, you could maybe FFALIGN frame->nb_samples before the 
ff_get_buffer() call, then restore the original value afterwards.

> +
> +    *got_frame_ptr = 1;
> +
> +    return buf_size;
> +}



More information about the ffmpeg-devel mailing list