[FFmpeg-devel] [PATCH 2/6] avcodec/vorbisenc: Apply dynamic frame lengths

Tomas Härdin tjoppen at acc.umu.se
Wed Aug 23 11:31:58 EEST 2017


On 2017-08-22 03:23, Tyler Jones wrote:
> +static int create_residues(vorbis_enc_context *venc)
> +{
> +    int res, ret;
> +    vorbis_enc_residue *rc;
> +
> +    venc->nresidues = 2;
> +    venc->residues  = av_malloc(sizeof(vorbis_enc_residue) * venc->nresidues);

av_malloc_array()? Applies to most av_malloc() in there


> -    // single mapping
> -    mc = &venc->mappings[0];
> -    mc->submaps = 1;
> -    mc->mux     = av_malloc(sizeof(int) * venc->channels);
> -    if (!mc->mux)
> -        return AVERROR(ENOMEM);
> -    for (i = 0; i < venc->channels; i++)
> -        mc->mux[i] = 0;
> -    mc->floor   = av_malloc(sizeof(int) * mc->submaps);
> -    mc->residue = av_malloc(sizeof(int) * mc->submaps);
> -    if (!mc->floor || !mc->residue)
> -        return AVERROR(ENOMEM);
> -    for (i = 0; i < mc->submaps; i++) {
> -        mc->floor[i]   = 0;
> -        mc->residue[i] = 0;
> -    }
> -    mc->coupling_steps = venc->channels == 2 ? 1 : 0;
> -    mc->magnitude      = av_malloc(sizeof(int) * mc->coupling_steps);
> -    mc->angle          = av_malloc(sizeof(int) * mc->coupling_steps);
> -    if (!mc->magnitude || !mc->angle)
> -        return AVERROR(ENOMEM);
> -    if (mc->coupling_steps) {
> -        mc->magnitude[0] = 0;
> -        mc->angle[0]     = 1;
> +    for (map = 0; map < venc->nmappings; map++) {
> +        mc = &venc->mappings[map];
> +        mc->submaps = 1;
> +        mc->mux     = av_malloc(sizeof(int) * venc->channels);
> +        if (!mc->mux)
> +            return AVERROR(ENOMEM);
> +        for (i = 0; i < venc->channels; i++)
> +            mc->mux[i] = 0;
> +        mc->floor   = av_malloc(sizeof(int) * mc->submaps);
> +        mc->residue = av_malloc(sizeof(int) * mc->submaps);
> +        if (!mc->floor || !mc->residue)
> +            return AVERROR(ENOMEM);
> +        for (i = 0; i < mc->submaps; i++) {
> +            mc->floor[i]   = map;
> +            mc->residue[i] = map;
> +        }
> +        mc->coupling_steps = venc->channels == 2 ? 1 : 0;
> +        mc->magnitude      = av_malloc(sizeof(int) * mc->coupling_steps);
> +        mc->angle          = av_malloc(sizeof(int) * mc->coupling_steps);
> +        if (!mc->magnitude || !mc->angle)
> +            return AVERROR(ENOMEM);
> +        if (mc->coupling_steps) {
> +            mc->magnitude[0] = 0;
> +            mc->angle[0]     = 1;
> +        }
>       }

Maybe nitpicking, but it would be clearer what the changes are if you 
put the indentation change in a separate commit


> -    move_audio(venc, avctx->frame_size);
> +    if (venc->transient < 0) {
> +        move_audio(venc, avctx->frame_size);
>   
> -    for (ch = 0; ch < venc->channels; ch++) {
> -        float *scratch = venc->scratch + 2 * ch * frame_size + frame_size;
> +        for (ch = 0; ch < venc->channels; ch++) {
> +            float *scratch = venc->scratch + 2 * ch * long_win + long_win;
>   
> -        if (!ff_psy_vorbis_block_frame(&venc->vpctx, scratch, ch,
> -                                       frame_size, block_size))
> -            curr_win = 0;
> +            if (!ff_psy_vorbis_block_frame(&venc->vpctx, scratch, ch,
> +                                           long_win, short_win))
> +                next_win = 0;
> +        }
>       }

Same here

/Tomas



More information about the ffmpeg-devel mailing list