Mercurial > libavcodec.hg
comparison msmpeg4.c @ 601:76e9b51cccda libavcodec
faster vlc table selection
author | michaelni |
---|---|
date | Fri, 09 Aug 2002 00:13:54 +0000 |
parents | 01da62a51ce8 |
children | e65798d228ea |
comparison
equal
deleted
inserted
replaced
600:b684f0f9ff72 | 601:76e9b51cccda |
---|---|
58 static int msmpeg4_decode_motion(MpegEncContext * s, | 58 static int msmpeg4_decode_motion(MpegEncContext * s, |
59 int *mx_ptr, int *my_ptr); | 59 int *mx_ptr, int *my_ptr); |
60 static void msmpeg4v2_encode_motion(MpegEncContext * s, int val); | 60 static void msmpeg4v2_encode_motion(MpegEncContext * s, int val); |
61 static void init_h263_dc_for_msmpeg4(void); | 61 static void init_h263_dc_for_msmpeg4(void); |
62 static inline void msmpeg4_memsetw(short *tab, int val, int n); | 62 static inline void msmpeg4_memsetw(short *tab, int val, int n); |
63 | 63 static int get_size_of_code(MpegEncContext * s, RLTable *rl, int last, int run, int level, int intra); |
64 | 64 |
65 | 65 |
66 extern UINT32 inverse[256]; | 66 extern UINT32 inverse[256]; |
67 | |
67 | 68 |
68 #ifdef DEBUG | 69 #ifdef DEBUG |
69 int intra_count = 0; | 70 int intra_count = 0; |
70 int frame_count = 0; | 71 int frame_count = 0; |
71 #endif | 72 #endif |
72 | 73 |
73 #include "msmpeg4data.h" | 74 #include "msmpeg4data.h" |
75 | |
76 static int rl_length[2][NB_RL_TABLES][MAX_LEVEL+1][MAX_RUN+1][2]; | |
74 | 77 |
75 #ifdef STATS | 78 #ifdef STATS |
76 | 79 |
77 const char *st_names[ST_NB] = { | 80 const char *st_names[ST_NB] = { |
78 "unknown", | 81 "unknown", |
185 for(k=0;k<64;k++) { | 188 for(k=0;k<64;k++) { |
186 int j = wmv1_scantable[i][k]; | 189 int j = wmv1_scantable[i][k]; |
187 wmv1_scantable[i][k]= block_permute_op(j); | 190 wmv1_scantable[i][k]= block_permute_op(j); |
188 } | 191 } |
189 } | 192 } |
190 | |
191 } | 193 } |
192 } | 194 } |
193 | 195 |
194 /* build the table which associate a (x,y) motion vector to a vlc */ | 196 /* build the table which associate a (x,y) motion vector to a vlc */ |
195 static void init_mv_table(MVTable *tab) | 197 static void init_mv_table(MVTable *tab) |
234 init_done = 1; | 236 init_done = 1; |
235 init_mv_table(&mv_tables[0]); | 237 init_mv_table(&mv_tables[0]); |
236 init_mv_table(&mv_tables[1]); | 238 init_mv_table(&mv_tables[1]); |
237 for(i=0;i<NB_RL_TABLES;i++) | 239 for(i=0;i<NB_RL_TABLES;i++) |
238 init_rl(&rl_table[i]); | 240 init_rl(&rl_table[i]); |
241 | |
242 for(i=0; i<NB_RL_TABLES; i++){ | |
243 int level; | |
244 for(level=0; level<=MAX_LEVEL; level++){ | |
245 int run; | |
246 for(run=0; run<=MAX_RUN; run++){ | |
247 int last; | |
248 for(last=0; last<2; last++){ | |
249 rl_length[0][i][level][run][last]= get_size_of_code(s, &rl_table[ i], last, run, level,0); | |
250 rl_length[1][i][level][run][last]= get_size_of_code(s, &rl_table[ i], last, run, level,1); | |
251 } | |
252 } | |
253 } | |
254 } | |
239 } | 255 } |
240 } | 256 } |
241 | 257 |
242 static int get_size_of_code(MpegEncContext * s, RLTable *rl, int last, int run, int level, int intra){ | 258 static int get_size_of_code(MpegEncContext * s, RLTable *rl, int last, int run, int level, int intra){ |
243 int size=0; | 259 int size=0; |
283 static void find_best_tables(MpegEncContext * s) | 299 static void find_best_tables(MpegEncContext * s) |
284 { | 300 { |
285 int i; | 301 int i; |
286 int best =-1, best_size =9999999; | 302 int best =-1, best_size =9999999; |
287 int chroma_best=-1, best_chroma_size=9999999; | 303 int chroma_best=-1, best_chroma_size=9999999; |
288 int last_size=0; | 304 |
289 | |
290 for(i=0; i<3; i++){ | 305 for(i=0; i<3; i++){ |
291 int level; | 306 int level; |
292 int chroma_size=0; | 307 int chroma_size=0; |
293 int size=0; | 308 int size=0; |
294 | 309 |
298 } | 313 } |
299 for(level=0; level<=MAX_LEVEL; level++){ | 314 for(level=0; level<=MAX_LEVEL; level++){ |
300 int run; | 315 int run; |
301 for(run=0; run<=MAX_RUN; run++){ | 316 for(run=0; run<=MAX_RUN; run++){ |
302 int last; | 317 int last; |
318 const int last_size= size + chroma_size; | |
303 for(last=0; last<2; last++){ | 319 for(last=0; last<2; last++){ |
304 int inter_count = s->ac_stats[0][0][level][run][last] + s->ac_stats[0][1][level][run][last]; | 320 int inter_count = s->ac_stats[0][0][level][run][last] + s->ac_stats[0][1][level][run][last]; |
305 int intra_luma_count = s->ac_stats[1][0][level][run][last]; | 321 int intra_luma_count = s->ac_stats[1][0][level][run][last]; |
306 int intra_chroma_count= s->ac_stats[1][1][level][run][last]; | 322 int intra_chroma_count= s->ac_stats[1][1][level][run][last]; |
307 | 323 |
308 if(s->pict_type==I_TYPE){ | 324 if(s->pict_type==I_TYPE){ |
309 size += intra_luma_count *get_size_of_code(s, &rl_table[ i], last, run, level,1); | 325 size += intra_luma_count *rl_length[1][i ][level][run][last]; |
310 chroma_size+= intra_chroma_count*get_size_of_code(s, &rl_table[3+i], last, run, level,1); | 326 chroma_size+= intra_chroma_count*rl_length[1][i+3][level][run][last]; |
311 }else{ | 327 }else{ |
312 size+= intra_luma_count *get_size_of_code(s, &rl_table[ i], last, run, level,1) | 328 size+= intra_luma_count *rl_length[1][i ][level][run][last] |
313 +intra_chroma_count*get_size_of_code(s, &rl_table[3+i], last, run, level,1) | 329 +intra_chroma_count*rl_length[1][i+3][level][run][last] |
314 +inter_count *get_size_of_code(s, &rl_table[3+i], last, run, level,0); | 330 +inter_count *rl_length[0][i+3][level][run][last]; |
315 } | 331 } |
316 } | 332 } |
333 if(last_size == size+chroma_size) break; | |
317 } | 334 } |
318 } | 335 } |
319 if(size<best_size){ | 336 if(size<best_size){ |
320 best_size= size; | 337 best_size= size; |
321 best= i; | 338 best= i; |
323 if(chroma_size<best_chroma_size){ | 340 if(chroma_size<best_chroma_size){ |
324 best_chroma_size= chroma_size; | 341 best_chroma_size= chroma_size; |
325 chroma_best= i; | 342 chroma_best= i; |
326 } | 343 } |
327 } | 344 } |
345 | |
328 // printf("type:%d, best:%d, qp:%d, var:%d, mcvar:%d, size:%d //\n", | 346 // printf("type:%d, best:%d, qp:%d, var:%d, mcvar:%d, size:%d //\n", |
329 // s->pict_type, best, s->qscale, s->mb_var_sum, s->mc_mb_var_sum, best_size); | 347 // s->pict_type, best, s->qscale, s->mb_var_sum, s->mc_mb_var_sum, best_size); |
330 | 348 |
331 if(s->pict_type==P_TYPE) chroma_best= best; | 349 if(s->pict_type==P_TYPE) chroma_best= best; |
332 | 350 |
950 slevel = level; | 968 slevel = level; |
951 if (level < 0) { | 969 if (level < 0) { |
952 sign = 1; | 970 sign = 1; |
953 level = -level; | 971 level = -level; |
954 } | 972 } |
973 | |
955 if(level<=MAX_LEVEL && run<=MAX_RUN){ | 974 if(level<=MAX_LEVEL && run<=MAX_RUN){ |
956 s->ac_stats[s->mb_intra][n>3][level][run][last]++; | 975 s->ac_stats[s->mb_intra][n>3][level][run][last]++; |
957 } | 976 } |
958 #if 0 | 977 #if 0 |
959 else | 978 else |