Unified · Split
| @@ -39,6 +39,7 @@ · 38 unmodified lines | ||
| 39 | 39 | #define H261_MAX_RUN 26 |
| 40 | 40 | #define H261_MAX_LEVEL 15 |
| 41 | 41 | #define H261_ESC_LEN (6 + 6 + 8) |
| 42 | +#define MV_TAB_OFFSET 32 | |
| 42 | 43 | |
| 43 | 44 | static struct VLCLUT { |
| 44 | 45 | uint8_t len; |
| @@ -47,6 +48,7 @@ static struct VLCLUT { · 2 unmodified lines | ||
| 47 | 48 | |
| 48 | 49 | static uint8_t uni_h261_rl_len [64 * 128]; |
| 49 | 50 | static uint8_t uni_h261_rl_len_last[64 * 128]; |
| 51 | +static uint8_t h261_mv_codes[64][2]; | |
| 50 | 52 | |
| 51 | 53 | typedef struct H261EncContext { |
| 52 | 54 | MpegEncContext s; |
| @@ -140,20 +142,8 @@ void ff_h261_reorder_mb_index(MpegEncContext *s) · 87 unmodified lines | ||
| 140 | 142 | |
| 141 | 143 | static void h261_encode_motion(PutBitContext *pb, int val) |
| 142 | 144 | { |
| 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]); | |
| 157 | 147 | } |
| 158 | 148 | |
| 159 | 149 | 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 | ||
| 323 | 313 | |
| 324 | 314 | static av_cold void h261_encode_init_static(void) |
| 325 | 315 | { |
| 316 | + uint8_t (*const mv_codes)[2] = h261_mv_codes + MV_TAB_OFFSET; | |
| 326 | 317 | memset(uni_h261_rl_len, H261_ESC_LEN, sizeof(uni_h261_rl_len)); |
| 327 | 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 | 332 | uni_h261_rl_len_last[UNI_AC_ENC_INDEX(run, 64 + level)] = len + 2; |
| 342 | 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 | |
| 346 | 351 | av_cold int ff_h261_encode_init(MpegEncContext *s) |