History

avcodec/msmpeg4enc: Use LUT to write motion vectors

Andreas Rheinhardt committed 1 year ago

Commit 82a856e1 parent 6d47d562 files · +20 −24Browse files

Unified · Split

2 files
  1. libavcodec/msmpeg4data.h +0 −1
  2. libavcodec/msmpeg4enc.c +20 −23
libavcodec/msmpeg4data.h+0−1
@@ -43,7 +43,6 @@ typedef struct MVTable { · 42 unmodified lines
43 const uint8_t *table_mv_bits;43 const uint8_t *table_mv_bits;
44 const uint8_t *table_mvx;44 const uint8_t *table_mvx;
45 const uint8_t *table_mvy;45 const uint8_t *table_mvy;
46 uint16_t *table_mv_index; /* encoding: convert mv to index in table_mv */
47 const VLCElem *vlc; /* decoding: vlc */46 const VLCElem *vlc; /* decoding: vlc */
48} MVTable;47} MVTable;
49 48
libavcodec/msmpeg4enc.c+20−23
@@ -50,21 +50,27 @@ · 49 unmodified lines
50 50
51static uint8_t rl_length[NB_RL_TABLES][MAX_LEVEL+1][MAX_RUN+1][2];51static 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.
55static uint32_t mv_vector_tables[2][4096];
56
53/* build the table which associate a (x,y) motion vector to a vlc */57/* build the table which associate a (x,y) motion vector to a vlc */
54static av_cold void init_mv_table(MVTable *tab, uint16_t table_mv_index[4096])58static 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 int i, x, y;61 int i, x, y;
57 62
58 tab->table_mv_index = table_mv_index;63 for (int i = 0; i < 4096; i++) {
59 64 // Initialize to the table to "escaped". This code is equivalent to
60 /* mark all entries as not used */65 // the following double loop (with x and y ranging over 0..63):
61 for(i=0;i<4096;i++)66 // tab[x * 64 + y] = (esc_code << 20) | (x << 14) | (y << 8) | esc_length
62 tab->table_mv_index[i] = MSMPEG4_MV_TABLES_NB_ELEMS;67 mv_vector_table[i] = (escape_code << 20) | (i << 8) | escape_length;
68 }
63 69
64 for (i = 0; i < MSMPEG4_MV_TABLES_NB_ELEMS; i++) {70 for (i = 0; i < MSMPEG4_MV_TABLES_NB_ELEMS; i++) {
65 x = tab->table_mvx[i];71 x = tab->table_mvx[i];
66 y = tab->table_mvy[i];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
123static av_cold void msmpeg4_encode_init_static(void)129static av_cold void msmpeg4_encode_init_static(void)
124{130{
125 static uint16_t mv_index_tables[2][4096];131 init_mv_table(&ff_mv_tables[0], mv_vector_tables[0], 0x0000, 8 + 12);
126 init_mv_table(&ff_mv_tables[0], mv_index_tables[0]);132 init_mv_table(&ff_mv_tables[1], mv_vector_tables[1], 0x000b, 4 + 12);
127 init_mv_table(&ff_mv_tables[1], mv_index_tables[1]);
128 133
129 for (int i = 0; i < NB_RL_TABLES; i++) {134 for (int i = 0; i < NB_RL_TABLES; i++) {
130 for (int level = 1; level <= MAX_LEVEL; level++) {135 for (int level = 1; level <= MAX_LEVEL; level++) {
@@ -300,8 +305,8 @@ FF_ENABLE_DEPRECATION_WARNINGS · 169 unmodified lines
300void ff_msmpeg4_encode_motion(MpegEncContext * s,305void ff_msmpeg4_encode_motion(MpegEncContext * s,
301 int mx, int my)306 int mx, int my)
302{307{
303 int code;308 const uint32_t *const mv_vector_table = mv_vector_tables[s->mv_table_index];
304 MVTable *mv;309 uint32_t code;
305 310
306 /* modulo encoding */311 /* modulo encoding */
307 /* WARNING : you cannot reach all the MVs even with the modulo312 /* 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 mx += 32;323 mx += 32;
319 my += 32;324 my += 32;
320 mv = &ff_mv_tables[s->mv_table_index];325
321 326 code = mv_vector_table[(mx << 6) | my];
322 code = mv->table_mv_index[(mx << 6) | my];327 put_bits(&s->pb, code & 0xff, code >> 8);
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 }
331}328}
332 329
333void ff_msmpeg4_handle_slices(MpegEncContext *s){330void ff_msmpeg4_handle_slices(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