History

avcodec/h261enc: Use LUT to write motion vector differences

Andreas Rheinhardt committed 2 years ago

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

Unified · Split

libavcodec/h261enc.c+19−14
@@ -39,6 +39,7 @@ · 38 unmodified lines
3939 #define H261_MAX_RUN 26
4040 #define H261_MAX_LEVEL 15
4141 #define H261_ESC_LEN (6 + 6 + 8)
42+#define MV_TAB_OFFSET 32
4243
4344 static struct VLCLUT {
4445 uint8_t len;
@@ -47,6 +48,7 @@ static struct VLCLUT { · 2 unmodified lines
4748
4849 static uint8_t uni_h261_rl_len [64 * 128];
4950 static uint8_t uni_h261_rl_len_last[64 * 128];
51+static uint8_t h261_mv_codes[64][2];
5052
5153 typedef struct H261EncContext {
5254 MpegEncContext s;
@@ -140,20 +142,8 @@ void ff_h261_reorder_mb_index(MpegEncContext *s) · 87 unmodified lines
140142
141143 static void h261_encode_motion(PutBitContext *pb, int val)
142144 {
143− int sign, code;
144− if (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− }
145+ put_bits(pb, h261_mv_codes[MV_TAB_OFFSET + val][1],
146+ h261_mv_codes[MV_TAB_OFFSET + val][0]);
157147 }
158148
159149 static 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
323313
324314 static av_cold void h261_encode_init_static(void)
325315 {
316+ uint8_t (*const mv_codes)[2] = h261_mv_codes + MV_TAB_OFFSET;
326317 memset(uni_h261_rl_len, H261_ESC_LEN, sizeof(uni_h261_rl_len));
327318 memset(uni_h261_rl_len_last, H261_ESC_LEN + 2 /* EOB */, sizeof(uni_h261_rl_len_last));
328319
@@ -341,6 +332,20 @@ static av_cold void h261_encode_init_static(void) · 12 unmodified lines
341332 uni_h261_rl_len_last[UNI_AC_ENC_INDEX(run, 64 + level)] = len + 2;
342333 uni_h261_rl_len_last[UNI_AC_ENC_INDEX(run, 64 - level)] = len + 2;
343334 }
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;
344349 }
345350
346351 av_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