[FFmpeg-devel] [PATCH] MULTI VLC decoding boost

Michael Niedermayer michael at niedermayer.cc
Fri Sep 15 01:01:34 EEST 2023


On Mon, Aug 28, 2023 at 07:36:17PM +0200, Paul B Mahol wrote:
> Patches attached.
> 
> Thanks for kurosu for pointing unmerged branches.
> 
> The UNCACHED_PATH for x86_32 is broken with this for 2 codecs it touches.
> Fix is trivial, to be fixed later.
[...]

> +int ff_init_vlc_multi_from_lengths(VLC *vlc, VLC_MULTI *multi, int nb_bits, int nb_elems,
> +		                   int nb_codes, const int8_t *lens, int lens_wrap,
> +                                   const void *symbols, int symbols_wrap, int symbols_size,
> +                                   int offset, int flags, void *logctx)
> +{
> +    VLCcode localbuf[LOCALBUF_ELEMS], *buf = localbuf;
> +    uint64_t code;
> +    int ret, j, len_max = FFMIN(32, 3 * nb_bits);
> +
> +    ret = vlc_common_init(vlc, nb_bits, nb_codes, &buf, flags);
> +    if (ret < 0)
> +        return ret;
> +
> +    multi->table = av_malloc(sizeof(*multi->table) << nb_bits);
> +    if (!multi->table)
> +        return AVERROR(ENOMEM);
> +
> +    j = code = 0;
> +    for (int i = 0; i < nb_codes; i++, lens += lens_wrap) {
> +        int len = *lens;
> +        if (len > 0) {
> +            unsigned sym;
> +
> +            buf[j].bits = len;
> +            if (symbols)
> +                GET_DATA(sym, symbols, i, symbols_wrap, symbols_size)
> +            else
> +                sym = i;
> +            buf[j].symbol = sym + offset;
> +            buf[j++].code = code;
> +        } else if (len <  0) {
> +            len = -len;
> +        } else
> +            continue;
> +        if (len > len_max || code & ((1U << (32 - len)) - 1)) {
> +            av_log(logctx, AV_LOG_ERROR, "Invalid VLC (length %u)\n", len);
> +            goto fail;
> +        }
> +        code += 1U << (32 - len);
> +        if (code > UINT32_MAX + 1ULL) {
> +            av_log(logctx, AV_LOG_ERROR, "Overdetermined VLC tree\n");
> +            goto fail;
> +        }
> +    }
> +    ret = vlc_common_end(vlc, nb_bits, j, buf, flags, localbuf);
> +    if (ret < 0)
> +        goto fail;
> +    return vlc_multi_gen(multi->table, vlc, nb_elems, j, nb_bits, buf, logctx);
> +fail:
> +    if (buf != localbuf)
> +        av_free(buf);
> +    return AVERROR_INVALIDDATA;
> +}

this is copy and pasted from

int ff_vlc_init_from_lengths(VLC *vlc, int nb_bits, int nb_codes,

leading to code duplication, it would be better if you could
factor the duplication out

thx

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

"You are 36 times more likely to die in a bathtub than at the hands of a
terrorist. Also, you are 2.5 times more likely to become a president and
2 times more likely to become an astronaut, than to die in a terrorist
attack." -- Thoughty2

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20230915/efbc4836/attachment.sig>


More information about the ffmpeg-devel mailing list