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
4343 const uint8_t *table_mv_bits;
4444 const uint8_t *table_mvx;
4545 const uint8_t *table_mvy;
46− uint16_t *table_mv_index; /* encoding: convert mv to index in table_mv */
4746 const VLCElem *vlc; /* decoding: vlc */
4847 } MVTable;
4948
libavcodec/msmpeg4enc.c+20−23
@@ -50,21 +50,27 @@ · 49 unmodified lines
5050
5151 static uint8_t rl_length[NB_RL_TABLES][MAX_LEVEL+1][MAX_RUN+1][2];
5252
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+
5357 /* 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)
5560 {
5661 int i, x, y;
5762
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+ }
6369
6470 for (i = 0; i < MSMPEG4_MV_TABLES_NB_ELEMS; i++) {
6571 x = tab->table_mvx[i];
6672 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];
6874 }
6975 }
7076
@@ -122,9 +128,8 @@ static int get_size_of_code(const RLTable *rl, int last, int run, · 51 unmodified lines
122128
123129 static av_cold void msmpeg4_encode_init_static(void)
124130 {
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);
128133
129134 for (int i = 0; i < NB_RL_TABLES; i++) {
130135 for (int level = 1; level <= MAX_LEVEL; level++) {
@@ -300,8 +305,8 @@ FF_ENABLE_DEPRECATION_WARNINGS · 169 unmodified lines
300305 void ff_msmpeg4_encode_motion(MpegEncContext * s,
301306 int mx, int my)
302307 {
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;
305310
306311 /* modulo encoding */
307312 /* 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
317322
318323 mx += 32;
319324 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);
331328 }
332329
333330 void 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