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

James Almer jamrial at gmail.com
Sat Sep 18 01:06:59 EEST 2021


On 9/17/2021 5:54 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;
> +    float *dst;
> +    int ret;
> +
> +    if ((ret = init_get_bits8(&s->gb, avpkt->data, avpkt->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 = s->out;
> +    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] = s->out[n] / 32768.f;

This loop is a huge bottleneck. No way to merge this with the actual 
decoding? Does s->out need to remain untouched to be used for future frames?

> +
> +    *got_frame_ptr = 1;
> +
> +    return avpkt->size;
> +}



More information about the ffmpeg-devel mailing list