| @@ -50,21 +50,27 @@ · 49 unmodified lines |
| 50 | 50 | |
| 51 | 51 | static uint8_t rl_length[NB_RL_TABLES][MAX_LEVEL+1][MAX_RUN+1][2]; |
| 52 | 52 | |
| 53 | +// The lowest 8 bits of each entry are length, the other bits are the code. |
| 54 | +// The index of the (mx, my) entry is (mx * 64) + my. |
| 55 | +static uint32_t mv_vector_tables[2][4096]; |
| 56 | + |
| 53 | 57 | /* build the table which associate a (x,y) motion vector to a vlc */ |
| 54 | | −static av_cold void init_mv_table(MVTable *tab, uint16_t table_mv_index[4096]) |
| 58 | +static av_cold void init_mv_table(const MVTable *tab, uint32_t mv_vector_table[4096], |
| 59 | + unsigned escape_code, int escape_length) |
| 55 | 60 | { |
| 56 | 61 | int i, x, y; |
| 57 | 62 | |
| 58 | | − tab->table_mv_index = table_mv_index; |
| 59 | | − |
| 60 | | − /* mark all entries as not used */ |
| 61 | | − for(i=0;i<4096;i++) |
| 62 | | − tab->table_mv_index[i] = MSMPEG4_MV_TABLES_NB_ELEMS; |
| 63 | + for (int i = 0; i < 4096; i++) { |
| 64 | + // Initialize to the table to "escaped". This code is equivalent to |
| 65 | + // the following double loop (with x and y ranging over 0..63): |
| 66 | + // tab[x * 64 + y] = (esc_code << 20) | (x << 14) | (y << 8) | esc_length |
| 67 | + mv_vector_table[i] = (escape_code << 20) | (i << 8) | escape_length; |
| 68 | + } |
| 63 | 69 | |
| 64 | 70 | for (i = 0; i < MSMPEG4_MV_TABLES_NB_ELEMS; i++) { |
| 65 | 71 | x = tab->table_mvx[i]; |
| 66 | 72 | y = tab->table_mvy[i]; |
| 67 | | − tab->table_mv_index[(x << 6) | y] = i; |
| 73 | + mv_vector_table[(x << 6) | y] = (tab->table_mv_code[i] << 8) | tab->table_mv_bits[i]; |
| 68 | 74 | } |
| 69 | 75 | } |
| 70 | 76 | |
| @@ -122,9 +128,8 @@ static int get_size_of_code(const RLTable *rl, int last, int run, · 51 unmodified lines |
| 122 | 128 | |
| 123 | 129 | static av_cold void msmpeg4_encode_init_static(void) |
| 124 | 130 | { |
| 125 | | − static uint16_t mv_index_tables[2][4096]; |
| 126 | | − init_mv_table(&ff_mv_tables[0], mv_index_tables[0]); |
| 127 | | − init_mv_table(&ff_mv_tables[1], mv_index_tables[1]); |
| 131 | + init_mv_table(&ff_mv_tables[0], mv_vector_tables[0], 0x0000, 8 + 12); |
| 132 | + init_mv_table(&ff_mv_tables[1], mv_vector_tables[1], 0x000b, 4 + 12); |
| 128 | 133 | |
| 129 | 134 | for (int i = 0; i < NB_RL_TABLES; i++) { |
| 130 | 135 | for (int level = 1; level <= MAX_LEVEL; level++) { |
| @@ -300,8 +305,8 @@ FF_ENABLE_DEPRECATION_WARNINGS · 169 unmodified lines |
| 300 | 305 | void ff_msmpeg4_encode_motion(MpegEncContext * s, |
| 301 | 306 | int mx, int my) |
| 302 | 307 | { |
| 303 | | − int code; |
| 304 | | − MVTable *mv; |
| 308 | + const uint32_t *const mv_vector_table = mv_vector_tables[s->mv_table_index]; |
| 309 | + uint32_t code; |
| 305 | 310 | |
| 306 | 311 | /* modulo encoding */ |
| 307 | 312 | /* WARNING : you cannot reach all the MVs even with the modulo |
| @@ -317,17 +322,9 @@ void ff_msmpeg4_encode_motion(MpegEncContext * s, · 9 unmodified lines |
| 317 | 322 | |
| 318 | 323 | mx += 32; |
| 319 | 324 | my += 32; |
| 320 | | − mv = &ff_mv_tables[s->mv_table_index]; |
| 321 | | − |
| 322 | | − code = mv->table_mv_index[(mx << 6) | my]; |
| 323 | | − put_bits(&s->pb, |
| 324 | | − mv->table_mv_bits[code], |
| 325 | | − mv->table_mv_code[code]); |
| 326 | | − if (code == MSMPEG4_MV_TABLES_NB_ELEMS) { |
| 327 | | − /* escape : code literally */ |
| 328 | | − put_bits(&s->pb, 6, mx); |
| 329 | | − put_bits(&s->pb, 6, my); |
| 330 | | − } |
| 325 | + |
| 326 | + code = mv_vector_table[(mx << 6) | my]; |
| 327 | + put_bits(&s->pb, code & 0xff, code >> 8); |
| 331 | 328 | } |
| 332 | 329 | |
| 333 | 330 | void ff_msmpeg4_handle_slices(MpegEncContext *s){ |