[FFmpeg-cvslog] avcodec/mpeg12: Avoid temporary stack VLC array during RL VLC init
Andreas Rheinhardt
git at videolan.org
Mon Mar 17 04:40:14 EET 2025
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Fri Mar 7 16:37:43 2025 +0100| [3869862b0098bd19a4decf8bd5a0ae49ac1e9a43] | committer: Andreas Rheinhardt
avcodec/mpeg12: Avoid temporary stack VLC array during RL VLC init
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=3869862b0098bd19a4decf8bd5a0ae49ac1e9a43
---
libavcodec/mpeg12.c | 27 ++++++++++++---------------
1 file changed, 12 insertions(+), 15 deletions(-)
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index 0d4a36be04..3056c53c7c 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -28,7 +28,6 @@
#define UNCHECKED_BITSTREAM_READER 1
#include "libavutil/attributes.h"
-#include "libavutil/avassert.h"
#include "libavutil/thread.h"
#include "mpegvideo.h"
@@ -90,15 +89,13 @@ av_cold void ff_init_2d_vlc_rl(const uint16_t table_vlc[][2], RL_VLC_ELEM rl_vlc
const int8_t table_run[], const uint8_t table_level[],
int n, unsigned static_size, int flags)
{
- int i;
- VLCElem table[680] = { 0 };
- VLC vlc = { .table = table, .table_allocated = static_size };
- av_assert0(static_size <= FF_ARRAY_ELEMS(table));
- vlc_init(&vlc, TEX_VLC_BITS, n + 2, &table_vlc[0][1], 4, 2, &table_vlc[0][0], 4, 2, VLC_INIT_USE_STATIC | flags);
-
- for (i = 0; i < vlc.table_size; i++) {
- int code = vlc.table[i].sym;
- int len = vlc.table[i].len;
+ ff_vlc_init_table_sparse(rl_vlc, static_size, TEX_VLC_BITS, n + 2,
+ &table_vlc[0][1], 4, 2, &table_vlc[0][0], 4, 2,
+ NULL, 0, 0, flags);
+
+ for (unsigned i = 0; i < static_size; i++) {
+ int idx = rl_vlc[i].sym;
+ int len = rl_vlc[i].len;
int level, run;
if (len == 0) { // illegal code
@@ -106,17 +103,17 @@ av_cold void ff_init_2d_vlc_rl(const uint16_t table_vlc[][2], RL_VLC_ELEM rl_vlc
level = MAX_LEVEL;
} else if (len<0) { //more bits needed
run = 0;
- level = code;
+ level = idx;
} else {
- if (code == n) { //esc
+ if (idx == n) { //esc
run = 65;
level = 0;
- } else if (code == n + 1) { //eob
+ } else if (idx == n + 1) { //eob
run = 0;
level = 127;
} else {
- run = table_run [code] + 1;
- level = table_level[code];
+ run = table_run [idx] + 1;
+ level = table_level[idx];
}
}
rl_vlc[i].len8 = len;
More information about the ffmpeg-cvslog
mailing list