Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH 01/61] avcodec/vlc: Add functions to init static VLCElem[] without VLC
Date: Tue, 31 Oct 2023 00:08:04 +0100
Message-ID: <AS8P250MB07441A1C6145483675C1E7398FA1A@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <GV1P250MB073754E215A199E7219CC13A8FC3A@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM>

Andreas Rheinhardt:
> For lots of static VLCs, the number of bits is not read from
> VLC.bits, but rather a compile-constant that is hardcoded
> at the callsite of get_vlc2(). Only VLC.table is ever used
> and not using it directly is just an unnecessary indirection.
> 
> This commit adds helper functions and macros to avoid the VLC
> structure when initializing VLC tables; there are 2x2 functions:
> Two choices for init_sparse or from_lengths and two choices
> for "overlong" initialization (as used when multiple VLCs are
> initialized that share the same underlying table).
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavcodec/vlc.c |  68 +++++++++++++++++++++++++++++++
>  libavcodec/vlc.h | 102 +++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 170 insertions(+)
> 
> diff --git a/libavcodec/vlc.c b/libavcodec/vlc.c
> index 21b9fffe27..b5de0bd24e 100644
> --- a/libavcodec/vlc.c
> +++ b/libavcodec/vlc.c
> @@ -350,6 +350,74 @@ fail:
>      return AVERROR_INVALIDDATA;
>  }
>  
> +av_cold void ff_vlc_init_table_from_lengths(VLCElem table[], int table_size,
> +                                            int nb_bits, int nb_codes,
> +                                            const int8_t *lens, int lens_wrap,
> +                                            const void *symbols, int symbols_wrap, int symbols_size,
> +                                            int offset, int flags)
> +{
> +    VLC vlc = { .table = table, .table_allocated = table_size };
> +
> +    ff_vlc_init_from_lengths(&vlc, nb_bits, nb_codes, lens, lens_wrap,
> +                             symbols, symbols_wrap, symbols_size,
> +                             offset, flags | VLC_INIT_USE_STATIC, NULL);
> +}
> +
> +av_cold const VLCElem *ff_vlc_init_tables_from_lengths(VLCInitState *state,
> +                                                       int nb_bits, int nb_codes,
> +                                                       const int8_t *lens, int lens_wrap,
> +                                                       const void *symbols, int symbols_wrap, int symbols_size,
> +                                                       int offset, int flags)
> +{
> +    VLC vlc = { .table = state->table, .table_allocated = state->size };
> +
> +    ff_vlc_init_from_lengths(&vlc, nb_bits, nb_codes, lens, lens_wrap,
> +                             symbols, symbols_wrap, symbols_size,
> +                             offset, flags | VLC_INIT_STATIC_OVERLONG, NULL);
> +
> +    state->table += vlc.table_size;
> +    state->size  -= vlc.table_size;
> +
> +    return vlc.table;
> +}
> +
> +av_cold void ff_vlc_init_table_sparse(VLCElem table[], int table_size,
> +                                      int nb_bits, int nb_codes,
> +                                      const void *bits, int bits_wrap, int bits_size,
> +                                      const void *codes, int codes_wrap, int codes_size,
> +                                      const void *symbols, int symbols_wrap, int symbols_size,
> +                                      int flags)
> +{
> +    VLC vlc = { .table = table, .table_allocated = table_size };
> +
> +    ff_vlc_init_sparse(&vlc, nb_bits, nb_codes,
> +                       bits, bits_wrap, bits_size,
> +                       codes, codes_wrap, codes_size,
> +                       symbols, symbols_wrap, symbols_size,
> +                       flags | VLC_INIT_USE_STATIC);
> +}
> +
> +av_cold const VLCElem *ff_vlc_init_tables_sparse(VLCInitState *state,
> +                                                 int nb_bits, int nb_codes,
> +                                                 const void *bits, int bits_wrap, int bits_size,
> +                                                 const void *codes, int codes_wrap, int codes_size,
> +                                                 const void *symbols, int symbols_wrap, int symbols_size,
> +                                                 int flags)
> +{
> +    VLC vlc = { .table = state->table, .table_allocated = state->size };
> +
> +    ff_vlc_init_sparse(&vlc, nb_bits, nb_codes,
> +                       bits, bits_wrap, bits_size,
> +                       codes, codes_wrap, codes_size,
> +                       symbols, symbols_wrap, symbols_size,
> +                       flags | VLC_INIT_STATIC_OVERLONG);
> +
> +    state->table += vlc.table_size;
> +    state->size  -= vlc.table_size;
> +
> +    return vlc.table;
> +}
> +
>  static void add_level(VLC_MULTI_ELEM *table, const int nb_elems,
>                        const int num, const int numbits,
>                        const VLCcode *buf,
> diff --git a/libavcodec/vlc.h b/libavcodec/vlc.h
> index 3f7c033a78..679666801a 100644
> --- a/libavcodec/vlc.h
> +++ b/libavcodec/vlc.h
> @@ -19,8 +19,11 @@
>  #ifndef AVCODEC_VLC_H
>  #define AVCODEC_VLC_H
>  
> +#include <stddef.h>
>  #include <stdint.h>
>  
> +#include "libavutil/macros.h"
> +
>  #define VLC_MULTI_MAX_SYMBOLS 6
>  
>  // When changing this, be sure to also update tableprint_vlc.h accordingly.
> @@ -223,4 +226,103 @@ void ff_vlc_free(VLC *vlc);
>                                   NULL);                                    \
>      } while (0)
>  
> +/**
> + * For static VLCs, the number of bits can often be hardcoded
> + * at each get_vlc2() callsite. Then using a full VLC would be uneconomical,
> + * because only VLC.table would ever be accessed after initialization.
> + * The following functions provide wrappers around the relevant ff_vlc_init_*
> + * functions suitable for said task.
> + *
> + * The ff_vlc_init_tables_* functions are intended to be used for initializing
> + * a series of VLCs. The user initializes a VLCInitState with the details
> + * about the underlying array of VLCElem; it is automatically updated by
> + * the ff_vlc_init_tables_* functions (i.e. table is incremented and size
> + * decremented by the number of elements of the current table).
> + * The VLC_INIT_STATIC_OVERLONG flag is also automatically added.
> + * These functions return a pointer to the table just initialized,
> + * potentially to be used in arrays of pointer to VLC tables.
> + *
> + * The ff_vlc_init_table_* functions are intended to be used for initializing
> + * a single VLC table, given by table and table_size. The VLC_INIT_USE_STATIC
> + * flag is automatically added.
> + */
> +
> +typedef struct VLCInitState {
> +    VLCElem *table;  ///< points to where the next VLC table will be placed
> +    unsigned size;   ///< remaining number of elements in table
> +} VLCInitState;
> +
> +#define VLC_INIT_STATE(_table) { .table = (_table), .size = FF_ARRAY_ELEMS(_table) }
> +
> +void ff_vlc_init_table_from_lengths(VLCElem table[], int table_size,
> +                                    int nb_bits, int nb_codes,
> +                                    const int8_t *lens, int lens_wrap,
> +                                    const void *symbols, int symbols_wrap, int symbols_size,
> +                                    int offset, int flags);
> +
> +const VLCElem *ff_vlc_init_tables_from_lengths(VLCInitState *state,
> +                                               int nb_bits, int nb_codes,
> +                                               const int8_t *lens, int lens_wrap,
> +                                               const void *symbols, int symbols_wrap, int symbols_size,
> +                                               int offset, int flags);
> +
> +void ff_vlc_init_table_sparse(VLCElem table[], int table_size,
> +                              int nb_bits, int nb_codes,
> +                              const void *bits, int bits_wrap, int bits_size,
> +                              const void *codes, int codes_wrap, int codes_size,
> +                              const void *symbols, int symbols_wrap, int symbols_size,
> +                              int flags);
> +
> +const VLCElem *ff_vlc_init_tables_sparse(VLCInitState *state,
> +                                         int nb_bits, int nb_codes,
> +                                         const void *bits, int bits_wrap, int bits_size,
> +                                         const void *codes, int codes_wrap, int codes_size,
> +                                         const void *symbols, int symbols_wrap, int symbols_size,
> +                                         int flags);
> +
> +static inline
> +const VLCElem *ff_vlc_init_tables(VLCInitState *state,
> +                                  int nb_bits, int nb_codes,
> +                                  const void *bits, int bits_wrap, int bits_size,
> +                                  const void *codes, int codes_wrap, int codes_size,
> +                                  int flags)
> +{
> +    return ff_vlc_init_tables_sparse(state, nb_bits, nb_codes,
> +                                     bits, bits_wrap, bits_size,
> +                                     codes, codes_wrap, codes_size,
> +                                     NULL, 0, 0, flags);
> +}
> +
> +#define VLC_INIT_STATIC_SPARSE_TABLE(vlc_table, nb_bits, nb_codes,         \
> +                                     bits, bits_wrap, bits_size,           \
> +                                     codes, codes_wrap, codes_size,        \
> +                                     symbols, symbols_wrap, symbols_size,  \
> +                                     flags)                                \
> +    ff_vlc_init_table_sparse(vlc_table, FF_ARRAY_ELEMS(vlc_table),         \
> +                             (nb_bits), (nb_codes),                        \
> +                             (bits), (bits_wrap), (bits_size),             \
> +                             (codes), (codes_wrap), (codes_size),          \
> +                             (symbols), (symbols_wrap), (symbols_size),    \
> +                             (flags))
> +
> +#define VLC_INIT_STATIC_TABLE(vlc_table, nb_bits, nb_codes,                \
> +                              bits, bits_wrap, bits_size,                  \
> +                              codes, codes_wrap, codes_size,               \
> +                              flags)                                       \
> +    ff_vlc_init_table_sparse(vlc_table, FF_ARRAY_ELEMS(vlc_table),         \
> +                             (nb_bits), (nb_codes),                        \
> +                             (bits), (bits_wrap), (bits_size),             \
> +                             (codes), (codes_wrap), (codes_size),          \
> +                             NULL, 0, 0, (flags))
> +
> +#define VLC_INIT_STATIC_TABLE_FROM_LENGTHS(vlc_table, nb_bits, nb_codes,   \
> +                                           lens, lens_wrap,                \
> +                                           syms, syms_wrap, syms_size,     \
> +                                           offset, flags)                  \
> +    ff_vlc_init_table_from_lengths(vlc_table, FF_ARRAY_ELEMS(vlc_table),   \
> +                                   (nb_bits), (nb_codes),                  \
> +                                   (lens), (lens_wrap),                    \
> +                                   (syms), (syms_wrap), (syms_size),       \
> +                                   (offset), (flags))
> +
>  #endif /* AVCODEC_VLC_H */

Will apply this patchset tonight (with the mobiclip bug fixed) unless
there are objections.

- Andreas

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

      parent reply	other threads:[~2023-10-30 23:06 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-26 22:12 Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 02/61] avcodec/vp3: Make VLC tables static where possible Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 03/61] avcodec/vp3: Increase some VLC tables Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 04/61] avcodec/h264_cavlc: Avoid superfluous VLC structures Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 05/61] avcodec/h264_cavlc: Avoid indirection for coefficient table VLCs Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 06/61] avcodec/h264_cavlc: Remove code duplication Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 07/61] avcodec/asvdec: Avoid superfluous VLC structures Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 08/61] avcodec/faxcompr: " Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 09/61] avcodec/h261dec: " Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 10/61] avcodec/ituh263dec: " Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 11/61] avcodec/msmpeg4_vc1_data: " Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 12/61] avcodec/svq1dec: " Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 13/61] avcodec/svq1dec: Increase size of VLC Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 14/61] avcodec/rv40: Avoid superfluous VLC structures Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 15/61] avcodec/mpc7: " Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 16/61] avcodec/intrax8: " Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 17/61] avcodec/clearvideo: " Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 18/61] avcodec/atrac9dec: " Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 19/61] avcodec/imc: " Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 20/61] avcodec/refstruct: Add simple API for refcounted objects Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 21/61] avcodec/vp3: Share coefficient VLCs between threads Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 22/61] avcodec/vp3: Avoid complete VLC struct, only use VLCElem* Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 23/61] avcodec/vp3: Reindent after the previous commits Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 24/61] avcodec/rv34: Avoid superfluous VLC structures Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 25/61] avcodec/rv34: Constify pointer to static object Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 26/61] avcodec/wnv1: Avoid unnecessary VLC structure Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 27/61] avcodec/mv30: " Andreas Rheinhardt
2023-09-26 22:16 ` [FFmpeg-devel] [PATCH 28/61] avcodec/vqcdec: " Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 29/61] avcodec/mobiclip: " Andreas Rheinhardt
2023-09-27 23:20   ` Michael Niedermayer
2023-09-27 23:44     ` Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 30/61] avcodec/mimic: " Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 31/61] avcodec/imm4: " Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 32/61] avcodec/lagarith: " Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 33/61] avcodec/speedhqdec: " Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 34/61] avcodec/vc1: Avoid superfluous VLC structures Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 35/61] avcodec/4xm: Avoid unnecessary " Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 36/61] avcodec/indeo2: Avoid unnecessary VLC structure Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 37/61] avcodec/mss4: Partially inline max_depth and nb_bits of VLC Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 38/61] avcodec/mpeg4videodec: Avoid superfluous VLC structures Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 39/61] avcodec/msmpeg4dec: " Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 40/61] avcodec/aacps: Remove unused AVCodecContext* parameter from ff_ps_apply Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 41/61] avcodec/aacps: Pass logctx as void* instead of AVCodecContext* Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 42/61] avcodec/aacdectab: Deduplicate common decoder tables Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 43/61] avcodec/aacdec_template: Deduplicate VLCs Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 44/61] avcodec/aacdec_template: Don't init unused table for fixed-point decoder Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 45/61] avcodec/aactab: Improve included headers Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 46/61] avcodec/aacdec_common: Avoid superfluous VLC structures Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 47/61] avcodec/aacsbr_template: Deduplicate VLCs Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 48/61] avcodec/aacdec_common: Avoid superfluous VLC structures for SBR VLCs Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 49/61] avcodec/aacdec_common: Switch to ff_vlc_init_tables_from_lengths() Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 50/61] avcodec/aacdec_common: Combine huffman tabs Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 51/61] avcodec/aacdec_common: Apply offset for SBR VLCs during init Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 52/61] avcodec/aacps: Move initializing common stuff to aacdec_common.c Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 53/61] avcodec/aacps_common: Avoid superfluous VLC structures Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 54/61] avcodec/aacps_common: Switch to ff_vlc_init_tables_from_lengths() Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 55/61] avcodec/aacps_common: Combine huffman tabels Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 56/61] avcodec/aacps_common: Apply offset for VLCs during init Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 57/61] avcodec/mpegaudiodec_common: Avoid superfluous VLC structures Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 58/61] avcodec/mpeg12: Avoid unnecessary " Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 59/61] avcodec/wmaprodec: Avoid superfluous " Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 60/61] avcodec/wmavoice: Avoid unnecessary VLC structure Andreas Rheinhardt
2023-09-26 22:17 ` [FFmpeg-devel] [PATCH 61/61] avcodec/vlc: Remove unused macros Andreas Rheinhardt
2023-10-30 23:08 ` Andreas Rheinhardt [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AS8P250MB07441A1C6145483675C1E7398FA1A@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM \
    --to=andreas.rheinhardt@outlook.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git