From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> To: ffmpeg-devel@ffmpeg.org Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Subject: [FFmpeg-devel] [PATCH 5/9] avcodec/dvdec: Avoid stack buffers Date: Sun, 4 Sep 2022 23:58:47 +0200 Message-ID: <AS8P250MB07445E61F3BA307146337ED28F7C9@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> (raw) In-Reply-To: <AS8P250MB07446C8541237B01350DEAB78F7C9@AS8P250MB0744.EURP250.PROD.OUTLOOK.COM> Instead reuse the destination RL VLC as scratch space. This is possible, because the (implicit) codes here are already ordered from left-to-right in the tree and because the codelengths are increasing, which implies that mapping from VLC entries to the corresponding entries used to initialize the VLC is monotonically increasing. This means that one can reuse the right end of the destination RL VLC to store the tables used to initialize the VLC with. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/dvdata.h | 2 ++ libavcodec/dvdec.c | 26 +++++++++++++------------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/libavcodec/dvdata.h b/libavcodec/dvdata.h index ae104096ad..31191a8475 100644 --- a/libavcodec/dvdata.h +++ b/libavcodec/dvdata.h @@ -27,6 +27,8 @@ extern const uint8_t ff_dv_quant_shifts[22][4]; extern const uint8_t ff_dv_quant_offset[4]; #define NB_DV_VLC 409 +/* The number of entries with value zero in ff_dv_vlc_level. */ +#define NB_DV_ZERO_LEVEL_ENTRIES 72 extern const uint8_t ff_dv_vlc_len[NB_DV_VLC]; extern const uint8_t ff_dv_vlc_run[NB_DV_VLC]; diff --git a/libavcodec/dvdec.c b/libavcodec/dvdec.c index 3857ed1266..32085a3ba6 100644 --- a/libavcodec/dvdec.c +++ b/libavcodec/dvdec.c @@ -137,31 +137,30 @@ static av_cold void dv_init_static(void) { VLCElem vlc_buf[FF_ARRAY_ELEMS(dv_rl_vlc)] = { 0 }; VLC dv_vlc = { .table = vlc_buf, .table_allocated = FF_ARRAY_ELEMS(vlc_buf) }; - uint8_t new_dv_vlc_len[NB_DV_VLC * 2]; - uint8_t new_dv_vlc_run[NB_DV_VLC * 2]; - int16_t new_dv_vlc_level[NB_DV_VLC * 2]; + const unsigned offset = FF_ARRAY_ELEMS(dv_rl_vlc) - (2 * NB_DV_VLC - NB_DV_ZERO_LEVEL_ENTRIES); + RL_VLC_ELEM *tmp = dv_rl_vlc + offset; int i, j; /* it's faster to include sign bit in a generic VLC parsing scheme */ for (i = 0, j = 0; i < NB_DV_VLC; i++, j++) { - new_dv_vlc_len[j] = ff_dv_vlc_len[i]; - new_dv_vlc_run[j] = ff_dv_vlc_run[i]; - new_dv_vlc_level[j] = ff_dv_vlc_level[i]; + tmp[j].len = ff_dv_vlc_len[i]; + tmp[j].run = ff_dv_vlc_run[i]; + tmp[j].level = ff_dv_vlc_level[i]; if (ff_dv_vlc_level[i]) { - new_dv_vlc_len[j]++; + tmp[j].len++; j++; - new_dv_vlc_len[j] = ff_dv_vlc_len[i] + 1; - new_dv_vlc_run[j] = ff_dv_vlc_run[i]; - new_dv_vlc_level[j] = -ff_dv_vlc_level[i]; + tmp[j].len = ff_dv_vlc_len[i] + 1; + tmp[j].run = ff_dv_vlc_run[i]; + tmp[j].level = -ff_dv_vlc_level[i]; } } /* NOTE: as a trick, we use the fact the no codes are unused * to accelerate the parsing of partial codes */ ff_init_vlc_from_lengths(&dv_vlc, TEX_VLC_BITS, j, - new_dv_vlc_len, 1, + &tmp[0].len, sizeof(tmp[0]), NULL, 0, 0, 0, INIT_VLC_USE_NEW_STATIC, NULL); av_assert1(dv_vlc.table_size == 1664); @@ -174,8 +173,9 @@ static av_cold void dv_init_static(void) run = 0; level = code; } else { - run = new_dv_vlc_run[code] + 1; - level = new_dv_vlc_level[code]; + av_assert1(i <= code + offset); + run = tmp[code].run + 1; + level = tmp[code].level; } dv_rl_vlc[i].len = len; dv_rl_vlc[i].level = level; -- 2.34.1 _______________________________________________ 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".
next prev parent reply other threads:[~2022-09-04 21:59 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-09-04 21:54 [FFmpeg-devel] [PATCH 1/9] avcodec/dvdata: Order code table by codes Andreas Rheinhardt 2022-09-04 21:58 ` [FFmpeg-devel] [PATCH 2/9] avcodec/dvdec: Use ff_init_vlc_from_lengths() Andreas Rheinhardt 2022-09-04 21:58 ` [FFmpeg-devel] [PATCH 3/9] avcodec/dv_tablegen, dvdata: Remove ff_dv_vlc_bits Andreas Rheinhardt 2022-09-04 21:58 ` [FFmpeg-devel] [PATCH 4/9] avcodec/dvdec: Mark dv_init_static() as av_cold Andreas Rheinhardt 2022-09-04 21:58 ` Andreas Rheinhardt [this message] 2022-09-04 21:58 ` [FFmpeg-devel] [PATCH 6/9] avcodec/wmavoice: Avoid code table Andreas Rheinhardt 2022-09-04 21:58 ` [FFmpeg-devel] [PATCH 7/9] avcodec/wmaprodec: Use ff_init_vlc_from_lengths() instead of init_vlc Andreas Rheinhardt 2022-09-04 21:58 ` [FFmpeg-devel] [PATCH 8/9] avcodec/wmaprodec: Move applying offset to VLC creation Andreas Rheinhardt 2022-09-04 21:58 ` [FFmpeg-devel] [PATCH 9/9] avcodec/wmaprodec: Use symbol table more efficiently Andreas Rheinhardt 2022-09-06 1:33 ` [FFmpeg-devel] [PATCH 1/9] avcodec/dvdata: Order code table by codes Andreas Rheinhardt
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=AS8P250MB07445E61F3BA307146337ED28F7C9@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