History

avcodec/h261enc: Use LUT to write motion vector differences

Andreas Rheinhardt committed 2 years ago

Commit ebf0d341 parent d1ed5c01 file · +19 −14Browse files

Showing the changes to libavcodec (1 of 1 file). Show all

Unified · Split

libavcodec/h261enc.c+19−14
@@ -39,6 +39,7 @@ · 38 unmodified lines
39#define H261_MAX_RUN 2639#define H261_MAX_RUN 26
40#define H261_MAX_LEVEL 1540#define H261_MAX_LEVEL 15
41#define H261_ESC_LEN (6 + 6 + 8)41#define H261_ESC_LEN (6 + 6 + 8)
42#define MV_TAB_OFFSET 32
42 43
43static struct VLCLUT {44static struct VLCLUT {
44 uint8_t len;45 uint8_t len;
@@ -47,6 +48,7 @@ static struct VLCLUT { · 2 unmodified lines
47 48
48static uint8_t uni_h261_rl_len [64 * 128];49static uint8_t uni_h261_rl_len [64 * 128];
49static uint8_t uni_h261_rl_len_last[64 * 128];50static uint8_t uni_h261_rl_len_last[64 * 128];
51static uint8_t h261_mv_codes[64][2];
50 52
51typedef struct H261EncContext {53typedef struct H261EncContext {
52 MpegEncContext s;54 MpegEncContext s;
@@ -140,20 +142,8 @@ void ff_h261_reorder_mb_index(MpegEncContext *s) · 87 unmodified lines
140 142
141static void h261_encode_motion(PutBitContext *pb, int val)143static void h261_encode_motion(PutBitContext *pb, int val)
142{144{
143 int sign, code;145 put_bits(pb, h261_mv_codes[MV_TAB_OFFSET + val][1],
144 if (val == 0) {146 h261_mv_codes[MV_TAB_OFFSET + val][0]);
145 // Corresponds to ff_h261_mv_tab[0]
146 put_bits(pb, 1, 1);
147 } else {
148 if (val > 15)
149 val -= 32;
150 if (val < -16)
151 val += 32;
152 sign = val < 0;
153 code = sign ? -val : val;
154 put_bits(pb, ff_h261_mv_tab[code][1], ff_h261_mv_tab[code][0]);
155 put_bits(pb, 1, sign);
156 }
157}147}
158 148
159static inline int get_cbp(MpegEncContext *s, int16_t block[6][64])149static inline int get_cbp(MpegEncContext *s, int16_t block[6][64])
@@ -323,6 +313,7 @@ void ff_h261_encode_mb(MpegEncContext *s, int16_t block[6][64], · 163 unmodified lines
323 313
324static av_cold void h261_encode_init_static(void)314static av_cold void h261_encode_init_static(void)
325{315{
316 uint8_t (*const mv_codes)[2] = h261_mv_codes + MV_TAB_OFFSET;
326 memset(uni_h261_rl_len, H261_ESC_LEN, sizeof(uni_h261_rl_len));317 memset(uni_h261_rl_len, H261_ESC_LEN, sizeof(uni_h261_rl_len));
327 memset(uni_h261_rl_len_last, H261_ESC_LEN + 2 /* EOB */, sizeof(uni_h261_rl_len_last));318 memset(uni_h261_rl_len_last, H261_ESC_LEN + 2 /* EOB */, sizeof(uni_h261_rl_len_last));
328 319
@@ -341,6 +332,20 @@ static av_cold void h261_encode_init_static(void) · 12 unmodified lines
341 uni_h261_rl_len_last[UNI_AC_ENC_INDEX(run, 64 + level)] = len + 2;332 uni_h261_rl_len_last[UNI_AC_ENC_INDEX(run, 64 + level)] = len + 2;
342 uni_h261_rl_len_last[UNI_AC_ENC_INDEX(run, 64 - level)] = len + 2;333 uni_h261_rl_len_last[UNI_AC_ENC_INDEX(run, 64 - level)] = len + 2;
343 }334 }
335
336 for (size_t i = 1;; i++) {
337 // sign-one MV codes; diff -16..-1, 16..31
338 mv_codes[32 - i][0] = mv_codes[-i][0] = (ff_h261_mv_tab[i][0] << 1) | 1 /* sign */;
339 mv_codes[32 - i][1] = mv_codes[-i][1] = ff_h261_mv_tab[i][1] + 1;
340 if (i == 16)
341 break;
342 // sign-zero MV codes: diff -31..-17, 1..15
343 mv_codes[i][0] = mv_codes[i - 32][0] = ff_h261_mv_tab[i][0] << 1;
344 mv_codes[i][1] = mv_codes[i - 32][1] = ff_h261_mv_tab[i][1] + 1;
345 }
346 // MV code for difference zero; has no sign
347 mv_codes[0][0] = 1;
348 mv_codes[0][1] = 1;
344}349}
345 350
346av_cold int ff_h261_encode_init(MpegEncContext *s)351av_cold int ff_h261_encode_init(MpegEncContext *s)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t