00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00030 #include "avcodec.h"
00031 #include "dsputil.h"
00032 #include "mpegvideo.h"
00033 #include "msmpeg4.h"
00034 #include "libavutil/x86_cpu.h"
00035 #include "h263.h"
00036 #include "mpeg4video.h"
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047 #define DC_VLC_BITS 9
00048 #define V2_INTRA_CBPC_VLC_BITS 3
00049 #define V2_MB_TYPE_VLC_BITS 7
00050 #define MV_VLC_BITS 9
00051 #define V2_MV_VLC_BITS 9
00052 #define TEX_VLC_BITS 9
00053
00054 #define II_BITRATE 128*1024
00055 #define MBAC_BITRATE 50*1024
00056
00057 #define DEFAULT_INTER_INDEX 3
00058
00059 static uint32_t v2_dc_lum_table[512][2];
00060 static uint32_t v2_dc_chroma_table[512][2];
00061
00062
00063 extern const uint8_t wmv3_dc_scale_table[32];
00064
00065 #ifdef DEBUG
00066 int frame_count = 0;
00067 #endif
00068
00069 #include "msmpeg4data.h"
00070
00071 #if CONFIG_ENCODERS //strangely gcc includes this even if it is not referenced
00072 static uint8_t rl_length[NB_RL_TABLES][MAX_LEVEL+1][MAX_RUN+1][2];
00073 #endif //CONFIG_ENCODERS
00074
00075 static uint8_t static_rl_table_store[NB_RL_TABLES][2][2*MAX_RUN + MAX_LEVEL + 3];
00076
00077
00078
00079 static av_cold void init_h263_dc_for_msmpeg4(void)
00080 {
00081 int level, uni_code, uni_len;
00082
00083 for(level=-256; level<256; level++){
00084 int size, v, l;
00085
00086 size = 0;
00087 v = abs(level);
00088 while (v) {
00089 v >>= 1;
00090 size++;
00091 }
00092
00093 if (level < 0)
00094 l= (-level) ^ ((1 << size) - 1);
00095 else
00096 l= level;
00097
00098
00099 uni_code= ff_mpeg4_DCtab_lum[size][0];
00100 uni_len = ff_mpeg4_DCtab_lum[size][1];
00101 uni_code ^= (1<<uni_len)-1;
00102
00103 if (size > 0) {
00104 uni_code<<=size; uni_code|=l;
00105 uni_len+=size;
00106 if (size > 8){
00107 uni_code<<=1; uni_code|=1;
00108 uni_len++;
00109 }
00110 }
00111 v2_dc_lum_table[level+256][0]= uni_code;
00112 v2_dc_lum_table[level+256][1]= uni_len;
00113
00114
00115 uni_code= ff_mpeg4_DCtab_chrom[size][0];
00116 uni_len = ff_mpeg4_DCtab_chrom[size][1];
00117 uni_code ^= (1<<uni_len)-1;
00118
00119 if (size > 0) {
00120 uni_code<<=size; uni_code|=l;
00121 uni_len+=size;
00122 if (size > 8){
00123 uni_code<<=1; uni_code|=1;
00124 uni_len++;
00125 }
00126 }
00127 v2_dc_chroma_table[level+256][0]= uni_code;
00128 v2_dc_chroma_table[level+256][1]= uni_len;
00129
00130 }
00131 }
00132
00133 static av_cold void common_init(MpegEncContext * s)
00134 {
00135 static int initialized=0;
00136
00137 switch(s->msmpeg4_version){
00138 case 1:
00139 case 2:
00140 s->y_dc_scale_table=
00141 s->c_dc_scale_table= ff_mpeg1_dc_scale_table;
00142 break;
00143 case 3:
00144 if(s->workaround_bugs){
00145 s->y_dc_scale_table= old_ff_y_dc_scale_table;
00146 s->c_dc_scale_table= wmv1_c_dc_scale_table;
00147 } else{
00148 s->y_dc_scale_table= ff_mpeg4_y_dc_scale_table;
00149 s->c_dc_scale_table= ff_mpeg4_c_dc_scale_table;
00150 }
00151 break;
00152 case 4:
00153 case 5:
00154 s->y_dc_scale_table= wmv1_y_dc_scale_table;
00155 s->c_dc_scale_table= wmv1_c_dc_scale_table;
00156 break;
00157 #if CONFIG_VC1_DECODER
00158 case 6:
00159 s->y_dc_scale_table= wmv3_dc_scale_table;
00160 s->c_dc_scale_table= wmv3_dc_scale_table;
00161 break;
00162 #endif
00163
00164 }
00165
00166
00167 if(s->msmpeg4_version>=4){
00168 ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , wmv1_scantable[1]);
00169 ff_init_scantable(s->dsp.idct_permutation, &s->intra_h_scantable, wmv1_scantable[2]);
00170 ff_init_scantable(s->dsp.idct_permutation, &s->intra_v_scantable, wmv1_scantable[3]);
00171 ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , wmv1_scantable[0]);
00172 }
00173
00174
00175 if(!initialized){
00176 initialized=1;
00177
00178 init_h263_dc_for_msmpeg4();
00179 }
00180 }
00181
00182 #if CONFIG_ENCODERS
00183
00184
00185 static void init_mv_table(MVTable *tab)
00186 {
00187 int i, x, y;
00188
00189 tab->table_mv_index = av_malloc(sizeof(uint16_t) * 4096);
00190
00191 for(i=0;i<4096;i++)
00192 tab->table_mv_index[i] = tab->n;
00193
00194 for(i=0;i<tab->n;i++) {
00195 x = tab->table_mvx[i];
00196 y = tab->table_mvy[i];
00197 tab->table_mv_index[(x << 6) | y] = i;
00198 }
00199 }
00200
00201 void ff_msmpeg4_code012(PutBitContext *pb, int n)
00202 {
00203 if (n == 0) {
00204 put_bits(pb, 1, 0);
00205 } else {
00206 put_bits(pb, 1, 1);
00207 put_bits(pb, 1, (n >= 2));
00208 }
00209 }
00210
00211 static int get_size_of_code(MpegEncContext * s, RLTable *rl, int last, int run, int level, int intra){
00212 int size=0;
00213 int code;
00214 int run_diff= intra ? 0 : 1;
00215
00216 code = get_rl_index(rl, last, run, level);
00217 size+= rl->table_vlc[code][1];
00218 if (code == rl->n) {
00219 int level1, run1;
00220
00221 level1 = level - rl->max_level[last][run];
00222 if (level1 < 1)
00223 goto esc2;
00224 code = get_rl_index(rl, last, run, level1);
00225 if (code == rl->n) {
00226 esc2:
00227 size++;
00228 if (level > MAX_LEVEL)
00229 goto esc3;
00230 run1 = run - rl->max_run[last][level] - run_diff;
00231 if (run1 < 0)
00232 goto esc3;
00233 code = get_rl_index(rl, last, run1, level);
00234 if (code == rl->n) {
00235 esc3:
00236
00237 size+=1+1+6+8;
00238 } else {
00239
00240 size+= 1+1+ rl->table_vlc[code][1];
00241 }
00242 } else {
00243
00244 size+= 1+1+ rl->table_vlc[code][1];
00245 }
00246 } else {
00247 size++;
00248 }
00249 return size;
00250 }
00251
00252 av_cold void ff_msmpeg4_encode_init(MpegEncContext *s)
00253 {
00254 static int init_done=0;
00255 int i;
00256
00257 common_init(s);
00258 if(s->msmpeg4_version>=4){
00259 s->min_qcoeff= -255;
00260 s->max_qcoeff= 255;
00261 }
00262
00263 if (!init_done) {
00264
00265 init_done = 1;
00266 init_mv_table(&mv_tables[0]);
00267 init_mv_table(&mv_tables[1]);
00268 for(i=0;i<NB_RL_TABLES;i++)
00269 init_rl(&rl_table[i], static_rl_table_store[i]);
00270
00271 for(i=0; i<NB_RL_TABLES; i++){
00272 int level;
00273 for(level=0; level<=MAX_LEVEL; level++){
00274 int run;
00275 for(run=0; run<=MAX_RUN; run++){
00276 int last;
00277 for(last=0; last<2; last++){
00278 rl_length[i][level][run][last]= get_size_of_code(s, &rl_table[ i], last, run, level, 0);
00279 }
00280 }
00281 }
00282 }
00283 }
00284 }
00285
00286 static void find_best_tables(MpegEncContext * s)
00287 {
00288 int i;
00289 int best =-1, best_size =9999999;
00290 int chroma_best=-1, best_chroma_size=9999999;
00291
00292 for(i=0; i<3; i++){
00293 int level;
00294 int chroma_size=0;
00295 int size=0;
00296
00297 if(i>0){
00298 size++;
00299 chroma_size++;
00300 }
00301 for(level=0; level<=MAX_LEVEL; level++){
00302 int run;
00303 for(run=0; run<=MAX_RUN; run++){
00304 int last;
00305 const int last_size= size + chroma_size;
00306 for(last=0; last<2; last++){
00307 int inter_count = s->ac_stats[0][0][level][run][last] + s->ac_stats[0][1][level][run][last];
00308 int intra_luma_count = s->ac_stats[1][0][level][run][last];
00309 int intra_chroma_count= s->ac_stats[1][1][level][run][last];
00310
00311 if(s->pict_type==FF_I_TYPE){
00312 size += intra_luma_count *rl_length[i ][level][run][last];
00313 chroma_size+= intra_chroma_count*rl_length[i+3][level][run][last];
00314 }else{
00315 size+= intra_luma_count *rl_length[i ][level][run][last]
00316 +intra_chroma_count*rl_length[i+3][level][run][last]
00317 +inter_count *rl_length[i+3][level][run][last];
00318 }
00319 }
00320 if(last_size == size+chroma_size) break;
00321 }
00322 }
00323 if(size<best_size){
00324 best_size= size;
00325 best= i;
00326 }
00327 if(chroma_size<best_chroma_size){
00328 best_chroma_size= chroma_size;
00329 chroma_best= i;
00330 }
00331 }
00332
00333
00334
00335
00336 if(s->pict_type==FF_P_TYPE) chroma_best= best;
00337
00338 memset(s->ac_stats, 0, sizeof(int)*(MAX_LEVEL+1)*(MAX_RUN+1)*2*2*2);
00339
00340 s->rl_table_index = best;
00341 s->rl_chroma_table_index= chroma_best;
00342
00343 if(s->pict_type != s->last_non_b_pict_type){
00344 s->rl_table_index= 2;
00345 if(s->pict_type==FF_I_TYPE)
00346 s->rl_chroma_table_index= 1;
00347 else
00348 s->rl_chroma_table_index= 2;
00349 }
00350
00351 }
00352
00353
00354 void msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number)
00355 {
00356 find_best_tables(s);
00357
00358 align_put_bits(&s->pb);
00359 put_bits(&s->pb, 2, s->pict_type - 1);
00360
00361 put_bits(&s->pb, 5, s->qscale);
00362 if(s->msmpeg4_version<=2){
00363 s->rl_table_index = 2;
00364 s->rl_chroma_table_index = 2;
00365 }
00366
00367 s->dc_table_index = 1;
00368 s->mv_table_index = 1;
00369 s->use_skip_mb_code = 1;
00370 s->per_mb_rl_table = 0;
00371 if(s->msmpeg4_version==4)
00372 s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE && s->pict_type==FF_P_TYPE);
00373
00374
00375 if (s->pict_type == FF_I_TYPE) {
00376 s->slice_height= s->mb_height/1;
00377 put_bits(&s->pb, 5, 0x16 + s->mb_height/s->slice_height);
00378
00379 if(s->msmpeg4_version==4){
00380 msmpeg4_encode_ext_header(s);
00381 if(s->bit_rate>MBAC_BITRATE)
00382 put_bits(&s->pb, 1, s->per_mb_rl_table);
00383 }
00384
00385 if(s->msmpeg4_version>2){
00386 if(!s->per_mb_rl_table){
00387 ff_msmpeg4_code012(&s->pb, s->rl_chroma_table_index);
00388 ff_msmpeg4_code012(&s->pb, s->rl_table_index);
00389 }
00390
00391 put_bits(&s->pb, 1, s->dc_table_index);
00392 }
00393 } else {
00394 put_bits(&s->pb, 1, s->use_skip_mb_code);
00395
00396 if(s->msmpeg4_version==4 && s->bit_rate>MBAC_BITRATE)
00397 put_bits(&s->pb, 1, s->per_mb_rl_table);
00398
00399 if(s->msmpeg4_version>2){
00400 if(!s->per_mb_rl_table)
00401 ff_msmpeg4_code012(&s->pb, s->rl_table_index);
00402
00403 put_bits(&s->pb, 1, s->dc_table_index);
00404
00405 put_bits(&s->pb, 1, s->mv_table_index);
00406 }
00407 }
00408
00409 s->esc3_level_length= 0;
00410 s->esc3_run_length= 0;
00411 }
00412
00413 void msmpeg4_encode_ext_header(MpegEncContext * s)
00414 {
00415 put_bits(&s->pb, 5, s->avctx->time_base.den / s->avctx->time_base.num);
00416
00417 put_bits(&s->pb, 11, FFMIN(s->bit_rate/1024, 2047));
00418
00419 if(s->msmpeg4_version>=3)
00420 put_bits(&s->pb, 1, s->flipflop_rounding);
00421 else
00422 assert(s->flipflop_rounding==0);
00423 }
00424
00425 #endif //CONFIG_ENCODERS
00426
00427
00428 int ff_msmpeg4_coded_block_pred(MpegEncContext * s, int n, uint8_t **coded_block_ptr)
00429 {
00430 int xy, wrap, pred, a, b, c;
00431
00432 xy = s->block_index[n];
00433 wrap = s->b8_stride;
00434
00435
00436
00437
00438 a = s->coded_block[xy - 1 ];
00439 b = s->coded_block[xy - 1 - wrap];
00440 c = s->coded_block[xy - wrap];
00441
00442 if (b == c) {
00443 pred = a;
00444 } else {
00445 pred = c;
00446 }
00447
00448
00449 *coded_block_ptr = &s->coded_block[xy];
00450
00451 return pred;
00452 }
00453
00454 #if CONFIG_ENCODERS
00455
00456 void ff_msmpeg4_encode_motion(MpegEncContext * s,
00457 int mx, int my)
00458 {
00459 int code;
00460 MVTable *mv;
00461
00462
00463
00464
00465 if (mx <= -64)
00466 mx += 64;
00467 else if (mx >= 64)
00468 mx -= 64;
00469 if (my <= -64)
00470 my += 64;
00471 else if (my >= 64)
00472 my -= 64;
00473
00474 mx += 32;
00475 my += 32;
00476 #if 0
00477 if ((unsigned)mx >= 64 ||
00478 (unsigned)my >= 64)
00479 av_log(s->avctx, AV_LOG_ERROR, "error mx=%d my=%d\n", mx, my);
00480 #endif
00481 mv = &mv_tables[s->mv_table_index];
00482
00483 code = mv->table_mv_index[(mx << 6) | my];
00484 put_bits(&s->pb,
00485 mv->table_mv_bits[code],
00486 mv->table_mv_code[code]);
00487 if (code == mv->n) {
00488
00489 put_bits(&s->pb, 6, mx);
00490 put_bits(&s->pb, 6, my);
00491 }
00492 }
00493
00494 void ff_msmpeg4_handle_slices(MpegEncContext *s){
00495 if (s->mb_x == 0) {
00496 if (s->slice_height && (s->mb_y % s->slice_height) == 0) {
00497 if(s->msmpeg4_version < 4){
00498 ff_mpeg4_clean_buffers(s);
00499 }
00500 s->first_slice_line = 1;
00501 } else {
00502 s->first_slice_line = 0;
00503 }
00504 }
00505 }
00506
00507 static void msmpeg4v2_encode_motion(MpegEncContext * s, int val)
00508 {
00509 int range, bit_size, sign, code, bits;
00510
00511 if (val == 0) {
00512
00513 code = 0;
00514 put_bits(&s->pb, mvtab[code][1], mvtab[code][0]);
00515 } else {
00516 bit_size = s->f_code - 1;
00517 range = 1 << bit_size;
00518 if (val <= -64)
00519 val += 64;
00520 else if (val >= 64)
00521 val -= 64;
00522
00523 if (val >= 0) {
00524 sign = 0;
00525 } else {
00526 val = -val;
00527 sign = 1;
00528 }
00529 val--;
00530 code = (val >> bit_size) + 1;
00531 bits = val & (range - 1);
00532
00533 put_bits(&s->pb, mvtab[code][1] + 1, (mvtab[code][0] << 1) | sign);
00534 if (bit_size > 0) {
00535 put_bits(&s->pb, bit_size, bits);
00536 }
00537 }
00538 }
00539
00540 void msmpeg4_encode_mb(MpegEncContext * s,
00541 DCTELEM block[6][64],
00542 int motion_x, int motion_y)
00543 {
00544 int cbp, coded_cbp, i;
00545 int pred_x, pred_y;
00546 uint8_t *coded_block;
00547
00548 ff_msmpeg4_handle_slices(s);
00549
00550 if (!s->mb_intra) {
00551
00552 cbp = 0;
00553 for (i = 0; i < 6; i++) {
00554 if (s->block_last_index[i] >= 0)
00555 cbp |= 1 << (5 - i);
00556 }
00557 if (s->use_skip_mb_code && (cbp | motion_x | motion_y) == 0) {
00558
00559 put_bits(&s->pb, 1, 1);
00560 s->last_bits++;
00561 s->misc_bits++;
00562 s->skip_count++;
00563
00564 return;
00565 }
00566 if (s->use_skip_mb_code)
00567 put_bits(&s->pb, 1, 0);
00568
00569 if(s->msmpeg4_version<=2){
00570 put_bits(&s->pb,
00571 v2_mb_type[cbp&3][1],
00572 v2_mb_type[cbp&3][0]);
00573 if((cbp&3) != 3) coded_cbp= cbp ^ 0x3C;
00574 else coded_cbp= cbp;
00575
00576 put_bits(&s->pb,
00577 ff_h263_cbpy_tab[coded_cbp>>2][1],
00578 ff_h263_cbpy_tab[coded_cbp>>2][0]);
00579
00580 s->misc_bits += get_bits_diff(s);
00581
00582 h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
00583 msmpeg4v2_encode_motion(s, motion_x - pred_x);
00584 msmpeg4v2_encode_motion(s, motion_y - pred_y);
00585 }else{
00586 put_bits(&s->pb,
00587 table_mb_non_intra[cbp + 64][1],
00588 table_mb_non_intra[cbp + 64][0]);
00589
00590 s->misc_bits += get_bits_diff(s);
00591
00592
00593 h263_pred_motion(s, 0, 0, &pred_x, &pred_y);
00594 ff_msmpeg4_encode_motion(s, motion_x - pred_x,
00595 motion_y - pred_y);
00596 }
00597
00598 s->mv_bits += get_bits_diff(s);
00599
00600 for (i = 0; i < 6; i++) {
00601 ff_msmpeg4_encode_block(s, block[i], i);
00602 }
00603 s->p_tex_bits += get_bits_diff(s);
00604 } else {
00605
00606 cbp = 0;
00607 coded_cbp = 0;
00608 for (i = 0; i < 6; i++) {
00609 int val, pred;
00610 val = (s->block_last_index[i] >= 1);
00611 cbp |= val << (5 - i);
00612 if (i < 4) {
00613
00614 pred = ff_msmpeg4_coded_block_pred(s, i, &coded_block);
00615 *coded_block = val;
00616 val = val ^ pred;
00617 }
00618 coded_cbp |= val << (5 - i);
00619 }
00620 #if 0
00621 if (coded_cbp)
00622 printf("cbp=%x %x\n", cbp, coded_cbp);
00623 #endif
00624
00625 if(s->msmpeg4_version<=2){
00626 if (s->pict_type == FF_I_TYPE) {
00627 put_bits(&s->pb,
00628 v2_intra_cbpc[cbp&3][1], v2_intra_cbpc[cbp&3][0]);
00629 } else {
00630 if (s->use_skip_mb_code)
00631 put_bits(&s->pb, 1, 0);
00632 put_bits(&s->pb,
00633 v2_mb_type[(cbp&3) + 4][1],
00634 v2_mb_type[(cbp&3) + 4][0]);
00635 }
00636 put_bits(&s->pb, 1, 0);
00637 put_bits(&s->pb,
00638 ff_h263_cbpy_tab[cbp>>2][1],
00639 ff_h263_cbpy_tab[cbp>>2][0]);
00640 }else{
00641 if (s->pict_type == FF_I_TYPE) {
00642 put_bits(&s->pb,
00643 ff_msmp4_mb_i_table[coded_cbp][1], ff_msmp4_mb_i_table[coded_cbp][0]);
00644 } else {
00645 if (s->use_skip_mb_code)
00646 put_bits(&s->pb, 1, 0);
00647 put_bits(&s->pb,
00648 table_mb_non_intra[cbp][1],
00649 table_mb_non_intra[cbp][0]);
00650 }
00651 put_bits(&s->pb, 1, 0);
00652 if(s->inter_intra_pred){
00653 s->h263_aic_dir=0;
00654 put_bits(&s->pb, table_inter_intra[s->h263_aic_dir][1], table_inter_intra[s->h263_aic_dir][0]);
00655 }
00656 }
00657 s->misc_bits += get_bits_diff(s);
00658
00659 for (i = 0; i < 6; i++) {
00660 ff_msmpeg4_encode_block(s, block[i], i);
00661 }
00662 s->i_tex_bits += get_bits_diff(s);
00663 s->i_count++;
00664 }
00665 }
00666
00667 #endif //CONFIG_ENCODERS
00668
00669 static inline int msmpeg4v1_pred_dc(MpegEncContext * s, int n,
00670 int32_t **dc_val_ptr)
00671 {
00672 int i;
00673
00674 if (n < 4) {
00675 i= 0;
00676 } else {
00677 i= n-3;
00678 }
00679
00680 *dc_val_ptr= &s->last_dc[i];
00681 return s->last_dc[i];
00682 }
00683
00684 static int get_dc(uint8_t *src, int stride, int scale)
00685 {
00686 int y;
00687 int sum=0;
00688 for(y=0; y<8; y++){
00689 int x;
00690 for(x=0; x<8; x++){
00691 sum+=src[x + y*stride];
00692 }
00693 }
00694 return FASTDIV((sum + (scale>>1)), scale);
00695 }
00696
00697
00698 static inline int msmpeg4_pred_dc(MpegEncContext * s, int n,
00699 int16_t **dc_val_ptr, int *dir_ptr)
00700 {
00701 int a, b, c, wrap, pred, scale;
00702 int16_t *dc_val;
00703
00704
00705 if (n < 4) {
00706 scale = s->y_dc_scale;
00707 } else {
00708 scale = s->c_dc_scale;
00709 }
00710
00711 wrap = s->block_wrap[n];
00712 dc_val= s->dc_val[0] + s->block_index[n];
00713
00714
00715
00716
00717 a = dc_val[ - 1];
00718 b = dc_val[ - 1 - wrap];
00719 c = dc_val[ - wrap];
00720
00721 if(s->first_slice_line && (n&2)==0 && s->msmpeg4_version<4){
00722 b=c=1024;
00723 }
00724
00725
00726
00727
00728
00729 #if ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE
00730 __asm__ volatile(
00731 "movl %3, %%eax \n\t"
00732 "shrl $1, %%eax \n\t"
00733 "addl %%eax, %2 \n\t"
00734 "addl %%eax, %1 \n\t"
00735 "addl %0, %%eax \n\t"
00736 "mull %4 \n\t"
00737 "movl %%edx, %0 \n\t"
00738 "movl %1, %%eax \n\t"
00739 "mull %4 \n\t"
00740 "movl %%edx, %1 \n\t"
00741 "movl %2, %%eax \n\t"
00742 "mull %4 \n\t"
00743 "movl %%edx, %2 \n\t"
00744 : "+b" (a), "+c" (b), "+D" (c)
00745 : "g" (scale), "S" (ff_inverse[scale])
00746 : "%eax", "%edx"
00747 );
00748 #else
00749
00750
00751
00752
00753 if (scale == 8) {
00754 a = (a + (8 >> 1)) / 8;
00755 b = (b + (8 >> 1)) / 8;
00756 c = (c + (8 >> 1)) / 8;
00757 } else {
00758 a = FASTDIV((a + (scale >> 1)), scale);
00759 b = FASTDIV((b + (scale >> 1)), scale);
00760 c = FASTDIV((c + (scale >> 1)), scale);
00761 }
00762 #endif
00763
00764
00765 if(s->msmpeg4_version>3){
00766 if(s->inter_intra_pred){
00767 uint8_t *dest;
00768 int wrap;
00769
00770 if(n==1){
00771 pred=a;
00772 *dir_ptr = 0;
00773 }else if(n==2){
00774 pred=c;
00775 *dir_ptr = 1;
00776 }else if(n==3){
00777 if (abs(a - b) < abs(b - c)) {
00778 pred = c;
00779 *dir_ptr = 1;
00780 } else {
00781 pred = a;
00782 *dir_ptr = 0;
00783 }
00784 }else{
00785 if(n<4){
00786 wrap= s->linesize;
00787 dest= s->current_picture.data[0] + (((n>>1) + 2*s->mb_y) * 8* wrap ) + ((n&1) + 2*s->mb_x) * 8;
00788 }else{
00789 wrap= s->uvlinesize;
00790 dest= s->current_picture.data[n-3] + (s->mb_y * 8 * wrap) + s->mb_x * 8;
00791 }
00792 if(s->mb_x==0) a= (1024 + (scale>>1))/scale;
00793 else a= get_dc(dest-8, wrap, scale*8);
00794 if(s->mb_y==0) c= (1024 + (scale>>1))/scale;
00795 else c= get_dc(dest-8*wrap, wrap, scale*8);
00796
00797 if (s->h263_aic_dir==0) {
00798 pred= a;
00799 *dir_ptr = 0;
00800 }else if (s->h263_aic_dir==1) {
00801 if(n==0){
00802 pred= c;
00803 *dir_ptr = 1;
00804 }else{
00805 pred= a;
00806 *dir_ptr = 0;
00807 }
00808 }else if (s->h263_aic_dir==2) {
00809 if(n==0){
00810 pred= a;
00811 *dir_ptr = 0;
00812 }else{
00813 pred= c;
00814 *dir_ptr = 1;
00815 }
00816 } else {
00817 pred= c;
00818 *dir_ptr = 1;
00819 }
00820 }
00821 }else{
00822 if (abs(a - b) < abs(b - c)) {
00823 pred = c;
00824 *dir_ptr = 1;
00825 } else {
00826 pred = a;
00827 *dir_ptr = 0;
00828 }
00829 }
00830 }else{
00831 if (abs(a - b) <= abs(b - c)) {
00832 pred = c;
00833 *dir_ptr = 1;
00834 } else {
00835 pred = a;
00836 *dir_ptr = 0;
00837 }
00838 }
00839
00840
00841 *dc_val_ptr = &dc_val[0];
00842 return pred;
00843 }
00844
00845 #define DC_MAX 119
00846
00847 static void msmpeg4_encode_dc(MpegEncContext * s, int level, int n, int *dir_ptr)
00848 {
00849 int sign, code;
00850 int pred, extquant;
00851 int extrabits = 0;
00852
00853 if(s->msmpeg4_version==1){
00854 int32_t *dc_val;
00855 pred = msmpeg4v1_pred_dc(s, n, &dc_val);
00856
00857
00858 *dc_val= level;
00859 }else{
00860 int16_t *dc_val;
00861 pred = msmpeg4_pred_dc(s, n, &dc_val, dir_ptr);
00862
00863
00864 if (n < 4) {
00865 *dc_val = level * s->y_dc_scale;
00866 } else {
00867 *dc_val = level * s->c_dc_scale;
00868 }
00869 }
00870
00871
00872 level -= pred;
00873
00874 if(s->msmpeg4_version<=2){
00875 if (n < 4) {
00876 put_bits(&s->pb,
00877 v2_dc_lum_table[level+256][1],
00878 v2_dc_lum_table[level+256][0]);
00879 }else{
00880 put_bits(&s->pb,
00881 v2_dc_chroma_table[level+256][1],
00882 v2_dc_chroma_table[level+256][0]);
00883 }
00884 }else{
00885 sign = 0;
00886 if (level < 0) {
00887 level = -level;
00888 sign = 1;
00889 }
00890 code = level;
00891 if (code > DC_MAX)
00892 code = DC_MAX;
00893 else if( s->msmpeg4_version>=6 ) {
00894 if( s->qscale == 1 ) {
00895 extquant = (level + 3) & 0x3;
00896 code = ((level+3)>>2);
00897 } else if( s->qscale == 2 ) {
00898 extquant = (level + 1) & 0x1;
00899 code = ((level+1)>>1);
00900 }
00901 }
00902
00903 if (s->dc_table_index == 0) {
00904 if (n < 4) {
00905 put_bits(&s->pb, ff_table0_dc_lum[code][1], ff_table0_dc_lum[code][0]);
00906 } else {
00907 put_bits(&s->pb, ff_table0_dc_chroma[code][1], ff_table0_dc_chroma[code][0]);
00908 }
00909 } else {
00910 if (n < 4) {
00911 put_bits(&s->pb, ff_table1_dc_lum[code][1], ff_table1_dc_lum[code][0]);
00912 } else {
00913 put_bits(&s->pb, ff_table1_dc_chroma[code][1], ff_table1_dc_chroma[code][0]);
00914 }
00915 }
00916
00917 if(s->msmpeg4_version>=6 && s->qscale<=2)
00918 extrabits = 3 - s->qscale;
00919
00920 if (code == DC_MAX)
00921 put_bits(&s->pb, 8 + extrabits, level);
00922 else if(extrabits > 0)
00923 put_bits(&s->pb, extrabits, extquant);
00924
00925 if (level != 0) {
00926 put_bits(&s->pb, 1, sign);
00927 }
00928 }
00929 }
00930
00931
00932
00933
00934 void ff_msmpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n)
00935 {
00936 int level, run, last, i, j, last_index;
00937 int last_non_zero, sign, slevel;
00938 int code, run_diff, dc_pred_dir;
00939 const RLTable *rl;
00940 const uint8_t *scantable;
00941
00942 if (s->mb_intra) {
00943 msmpeg4_encode_dc(s, block[0], n, &dc_pred_dir);
00944 i = 1;
00945 if (n < 4) {
00946 rl = &rl_table[s->rl_table_index];
00947 } else {
00948 rl = &rl_table[3 + s->rl_chroma_table_index];
00949 }
00950 run_diff = s->msmpeg4_version>=4;
00951 scantable= s->intra_scantable.permutated;
00952 } else {
00953 i = 0;
00954 rl = &rl_table[3 + s->rl_table_index];
00955 if(s->msmpeg4_version<=2)
00956 run_diff = 0;
00957 else
00958 run_diff = 1;
00959 scantable= s->inter_scantable.permutated;
00960 }
00961
00962
00963 if(s->msmpeg4_version>=4 && s->msmpeg4_version<6 && s->block_last_index[n]>0){
00964 for(last_index=63; last_index>=0; last_index--){
00965 if(block[scantable[last_index]]) break;
00966 }
00967 s->block_last_index[n]= last_index;
00968 }else
00969 last_index = s->block_last_index[n];
00970
00971 last_non_zero = i - 1;
00972 for (; i <= last_index; i++) {
00973 j = scantable[i];
00974 level = block[j];
00975 if (level) {
00976 run = i - last_non_zero - 1;
00977 last = (i == last_index);
00978 sign = 0;
00979 slevel = level;
00980 if (level < 0) {
00981 sign = 1;
00982 level = -level;
00983 }
00984
00985 if(level<=MAX_LEVEL && run<=MAX_RUN){
00986 s->ac_stats[s->mb_intra][n>3][level][run][last]++;
00987 }
00988 #if 0
00989 else
00990 s->ac_stats[s->mb_intra][n>3][40][63][0]++;
00991 #endif
00992 code = get_rl_index(rl, last, run, level);
00993 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
00994 if (code == rl->n) {
00995 int level1, run1;
00996
00997 level1 = level - rl->max_level[last][run];
00998 if (level1 < 1)
00999 goto esc2;
01000 code = get_rl_index(rl, last, run, level1);
01001 if (code == rl->n) {
01002 esc2:
01003 put_bits(&s->pb, 1, 0);
01004 if (level > MAX_LEVEL)
01005 goto esc3;
01006 run1 = run - rl->max_run[last][level] - run_diff;
01007 if (run1 < 0)
01008 goto esc3;
01009 code = get_rl_index(rl, last, run1+1, level);
01010 if (s->msmpeg4_version == 4 && code == rl->n)
01011 goto esc3;
01012 code = get_rl_index(rl, last, run1, level);
01013 if (code == rl->n) {
01014 esc3:
01015
01016 put_bits(&s->pb, 1, 0);
01017 put_bits(&s->pb, 1, last);
01018 if(s->msmpeg4_version>=4){
01019 if(s->esc3_level_length==0){
01020 s->esc3_level_length=8;
01021 s->esc3_run_length= 6;
01022
01023 if(s->qscale<8)
01024 put_bits(&s->pb, 6 + (s->msmpeg4_version>=6), 3);
01025 else
01026 put_bits(&s->pb, 8, 3);
01027 }
01028 put_bits(&s->pb, s->esc3_run_length, run);
01029 put_bits(&s->pb, 1, sign);
01030 put_bits(&s->pb, s->esc3_level_length, level);
01031 }else{
01032 put_bits(&s->pb, 6, run);
01033 put_sbits(&s->pb, 8, slevel);
01034 }
01035 } else {
01036
01037 put_bits(&s->pb, 1, 1);
01038 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
01039 put_bits(&s->pb, 1, sign);
01040 }
01041 } else {
01042
01043 put_bits(&s->pb, 1, 1);
01044 put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]);
01045 put_bits(&s->pb, 1, sign);
01046 }
01047 } else {
01048 put_bits(&s->pb, 1, sign);
01049 }
01050 last_non_zero = i;
01051 }
01052 }
01053 }
01054
01055
01056
01057
01058 VLC ff_mb_non_intra_vlc[4];
01059 static VLC v2_dc_lum_vlc;
01060 static VLC v2_dc_chroma_vlc;
01061 static VLC v2_intra_cbpc_vlc;
01062 static VLC v2_mb_type_vlc;
01063 static VLC v2_mv_vlc;
01064 VLC ff_inter_intra_vlc;
01065
01066
01067 static int msmpeg4v2_decode_motion(MpegEncContext * s, int pred, int f_code)
01068 {
01069 int code, val, sign, shift;
01070
01071 code = get_vlc2(&s->gb, v2_mv_vlc.table, V2_MV_VLC_BITS, 2);
01072
01073 if (code < 0)
01074 return 0xffff;
01075
01076 if (code == 0)
01077 return pred;
01078 sign = get_bits1(&s->gb);
01079 shift = f_code - 1;
01080 val = code;
01081 if (shift) {
01082 val = (val - 1) << shift;
01083 val |= get_bits(&s->gb, shift);
01084 val++;
01085 }
01086 if (sign)
01087 val = -val;
01088
01089 val += pred;
01090 if (val <= -64)
01091 val += 64;
01092 else if (val >= 64)
01093 val -= 64;
01094
01095 return val;
01096 }
01097
01098 static int msmpeg4v12_decode_mb(MpegEncContext *s, DCTELEM block[6][64])
01099 {
01100 int cbp, code, i;
01101
01102 if (s->pict_type == FF_P_TYPE) {
01103 if (s->use_skip_mb_code) {
01104 if (get_bits1(&s->gb)) {
01105
01106 s->mb_intra = 0;
01107 for(i=0;i<6;i++)
01108 s->block_last_index[i] = -1;
01109 s->mv_dir = MV_DIR_FORWARD;
01110 s->mv_type = MV_TYPE_16X16;
01111 s->mv[0][0][0] = 0;
01112 s->mv[0][0][1] = 0;
01113 s->mb_skipped = 1;
01114 return 0;
01115 }
01116 }
01117
01118 if(s->msmpeg4_version==2)
01119 code = get_vlc2(&s->gb, v2_mb_type_vlc.table, V2_MB_TYPE_VLC_BITS, 1);
01120 else
01121 code = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2);
01122 if(code<0 || code>7){
01123 av_log(s->avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n", code, s->mb_x, s->mb_y);
01124 return -1;
01125 }
01126
01127 s->mb_intra = code >>2;
01128
01129 cbp = code & 0x3;
01130 } else {
01131 s->mb_intra = 1;
01132 if(s->msmpeg4_version==2)
01133 cbp= get_vlc2(&s->gb, v2_intra_cbpc_vlc.table, V2_INTRA_CBPC_VLC_BITS, 1);
01134 else
01135 cbp= get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 1);
01136 if(cbp<0 || cbp>3){
01137 av_log(s->avctx, AV_LOG_ERROR, "cbpc %d invalid at %d %d\n", cbp, s->mb_x, s->mb_y);
01138 return -1;
01139 }
01140 }
01141
01142 if (!s->mb_intra) {
01143 int mx, my, cbpy;
01144
01145 cbpy= get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1);
01146 if(cbpy<0){
01147 av_log(s->avctx, AV_LOG_ERROR, "cbpy %d invalid at %d %d\n", cbp, s->mb_x, s->mb_y);
01148 return -1;
01149 }
01150
01151 cbp|= cbpy<<2;
01152 if(s->msmpeg4_version==1 || (cbp&3) != 3) cbp^= 0x3C;
01153
01154 h263_pred_motion(s, 0, 0, &mx, &my);
01155 mx= msmpeg4v2_decode_motion(s, mx, 1);
01156 my= msmpeg4v2_decode_motion(s, my, 1);
01157
01158 s->mv_dir = MV_DIR_FORWARD;
01159 s->mv_type = MV_TYPE_16X16;
01160 s->mv[0][0][0] = mx;
01161 s->mv[0][0][1] = my;
01162 } else {
01163 if(s->msmpeg4_version==2){
01164 s->ac_pred = get_bits1(&s->gb);
01165 cbp|= get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1)<<2;
01166 } else{
01167 s->ac_pred = 0;
01168 cbp|= get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1)<<2;
01169 if(s->pict_type==FF_P_TYPE) cbp^=0x3C;
01170 }
01171 }
01172
01173 s->dsp.clear_blocks(s->block[0]);
01174 for (i = 0; i < 6; i++) {
01175 if (ff_msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
01176 {
01177 av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n", s->mb_x, s->mb_y, i);
01178 return -1;
01179 }
01180 }
01181 return 0;
01182 }
01183
01184 static int msmpeg4v34_decode_mb(MpegEncContext *s, DCTELEM block[6][64])
01185 {
01186 int cbp, code, i;
01187 uint8_t *coded_val;
01188 uint32_t * const mb_type_ptr= &s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ];
01189
01190 if (s->pict_type == FF_P_TYPE) {
01191 if (s->use_skip_mb_code) {
01192 if (get_bits1(&s->gb)) {
01193
01194 s->mb_intra = 0;
01195 for(i=0;i<6;i++)
01196 s->block_last_index[i] = -1;
01197 s->mv_dir = MV_DIR_FORWARD;
01198 s->mv_type = MV_TYPE_16X16;
01199 s->mv[0][0][0] = 0;
01200 s->mv[0][0][1] = 0;
01201 s->mb_skipped = 1;
01202 *mb_type_ptr = MB_TYPE_SKIP | MB_TYPE_L0 | MB_TYPE_16x16;
01203
01204 return 0;
01205 }
01206 }
01207
01208 code = get_vlc2(&s->gb, ff_mb_non_intra_vlc[DEFAULT_INTER_INDEX].table, MB_NON_INTRA_VLC_BITS, 3);
01209 if (code < 0)
01210 return -1;
01211
01212 s->mb_intra = (~code & 0x40) >> 6;
01213
01214 cbp = code & 0x3f;
01215 } else {
01216 s->mb_intra = 1;
01217 code = get_vlc2(&s->gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2);
01218 if (code < 0)
01219 return -1;
01220
01221 cbp = 0;
01222 for(i=0;i<6;i++) {
01223 int val = ((code >> (5 - i)) & 1);
01224 if (i < 4) {
01225 int pred = ff_msmpeg4_coded_block_pred(s, i, &coded_val);
01226 val = val ^ pred;
01227 *coded_val = val;
01228 }
01229 cbp |= val << (5 - i);
01230 }
01231 }
01232
01233 if (!s->mb_intra) {
01234 int mx, my;
01235
01236 if(s->per_mb_rl_table && cbp){
01237 s->rl_table_index = decode012(&s->gb);
01238 s->rl_chroma_table_index = s->rl_table_index;
01239 }
01240 h263_pred_motion(s, 0, 0, &mx, &my);
01241 if (ff_msmpeg4_decode_motion(s, &mx, &my) < 0)
01242 return -1;
01243 s->mv_dir = MV_DIR_FORWARD;
01244 s->mv_type = MV_TYPE_16X16;
01245 s->mv[0][0][0] = mx;
01246 s->mv[0][0][1] = my;
01247 *mb_type_ptr = MB_TYPE_L0 | MB_TYPE_16x16;
01248 } else {
01249
01250 s->ac_pred = get_bits1(&s->gb);
01251 *mb_type_ptr = MB_TYPE_INTRA;
01252 if(s->inter_intra_pred){
01253 s->h263_aic_dir= get_vlc2(&s->gb, ff_inter_intra_vlc.table, INTER_INTRA_VLC_BITS, 1);
01254
01255 }
01256 if(s->per_mb_rl_table && cbp){
01257 s->rl_table_index = decode012(&s->gb);
01258 s->rl_chroma_table_index = s->rl_table_index;
01259 }
01260 }
01261
01262 s->dsp.clear_blocks(s->block[0]);
01263 for (i = 0; i < 6; i++) {
01264 if (ff_msmpeg4_decode_block(s, block[i], i, (cbp >> (5 - i)) & 1, NULL) < 0)
01265 {
01266 av_log(s->avctx, AV_LOG_ERROR, "\nerror while decoding block: %d x %d (%d)\n", s->mb_x, s->mb_y, i);
01267 return -1;
01268 }
01269 }
01270
01271 return 0;
01272 }
01273
01274
01275 av_cold int ff_msmpeg4_decode_init(AVCodecContext *avctx)
01276 {
01277 MpegEncContext *s = avctx->priv_data;
01278 static int done = 0;
01279 int i;
01280 MVTable *mv;
01281
01282 ff_h263_decode_init(avctx);
01283
01284 common_init(s);
01285
01286 if (!done) {
01287 done = 1;
01288
01289 for(i=0;i<NB_RL_TABLES;i++) {
01290 init_rl(&rl_table[i], static_rl_table_store[i]);
01291 }
01292 INIT_VLC_RL(rl_table[0], 642);
01293 INIT_VLC_RL(rl_table[1], 1104);
01294 INIT_VLC_RL(rl_table[2], 554);
01295 INIT_VLC_RL(rl_table[3], 940);
01296 INIT_VLC_RL(rl_table[4], 962);
01297 INIT_VLC_RL(rl_table[5], 554);
01298
01299 mv = &mv_tables[0];
01300 INIT_VLC_STATIC(&mv->vlc, MV_VLC_BITS, mv->n + 1,
01301 mv->table_mv_bits, 1, 1,
01302 mv->table_mv_code, 2, 2, 3714);
01303 mv = &mv_tables[1];
01304 INIT_VLC_STATIC(&mv->vlc, MV_VLC_BITS, mv->n + 1,
01305 mv->table_mv_bits, 1, 1,
01306 mv->table_mv_code, 2, 2, 2694);
01307
01308 INIT_VLC_STATIC(&ff_msmp4_dc_luma_vlc[0], DC_VLC_BITS, 120,
01309 &ff_table0_dc_lum[0][1], 8, 4,
01310 &ff_table0_dc_lum[0][0], 8, 4, 1158);
01311 INIT_VLC_STATIC(&ff_msmp4_dc_chroma_vlc[0], DC_VLC_BITS, 120,
01312 &ff_table0_dc_chroma[0][1], 8, 4,
01313 &ff_table0_dc_chroma[0][0], 8, 4, 1118);
01314 INIT_VLC_STATIC(&ff_msmp4_dc_luma_vlc[1], DC_VLC_BITS, 120,
01315 &ff_table1_dc_lum[0][1], 8, 4,
01316 &ff_table1_dc_lum[0][0], 8, 4, 1476);
01317 INIT_VLC_STATIC(&ff_msmp4_dc_chroma_vlc[1], DC_VLC_BITS, 120,
01318 &ff_table1_dc_chroma[0][1], 8, 4,
01319 &ff_table1_dc_chroma[0][0], 8, 4, 1216);
01320
01321 INIT_VLC_STATIC(&v2_dc_lum_vlc, DC_VLC_BITS, 512,
01322 &v2_dc_lum_table[0][1], 8, 4,
01323 &v2_dc_lum_table[0][0], 8, 4, 1472);
01324 INIT_VLC_STATIC(&v2_dc_chroma_vlc, DC_VLC_BITS, 512,
01325 &v2_dc_chroma_table[0][1], 8, 4,
01326 &v2_dc_chroma_table[0][0], 8, 4, 1506);
01327
01328 INIT_VLC_STATIC(&v2_intra_cbpc_vlc, V2_INTRA_CBPC_VLC_BITS, 4,
01329 &v2_intra_cbpc[0][1], 2, 1,
01330 &v2_intra_cbpc[0][0], 2, 1, 8);
01331 INIT_VLC_STATIC(&v2_mb_type_vlc, V2_MB_TYPE_VLC_BITS, 8,
01332 &v2_mb_type[0][1], 2, 1,
01333 &v2_mb_type[0][0], 2, 1, 128);
01334 INIT_VLC_STATIC(&v2_mv_vlc, V2_MV_VLC_BITS, 33,
01335 &mvtab[0][1], 2, 1,
01336 &mvtab[0][0], 2, 1, 538);
01337
01338 INIT_VLC_STATIC(&ff_mb_non_intra_vlc[0], MB_NON_INTRA_VLC_BITS, 128,
01339 &wmv2_inter_table[0][0][1], 8, 4,
01340 &wmv2_inter_table[0][0][0], 8, 4, 1636);
01341 INIT_VLC_STATIC(&ff_mb_non_intra_vlc[1], MB_NON_INTRA_VLC_BITS, 128,
01342 &wmv2_inter_table[1][0][1], 8, 4,
01343 &wmv2_inter_table[1][0][0], 8, 4, 2648);
01344 INIT_VLC_STATIC(&ff_mb_non_intra_vlc[2], MB_NON_INTRA_VLC_BITS, 128,
01345 &wmv2_inter_table[2][0][1], 8, 4,
01346 &wmv2_inter_table[2][0][0], 8, 4, 1532);
01347 INIT_VLC_STATIC(&ff_mb_non_intra_vlc[3], MB_NON_INTRA_VLC_BITS, 128,
01348 &wmv2_inter_table[3][0][1], 8, 4,
01349 &wmv2_inter_table[3][0][0], 8, 4, 2488);
01350
01351 INIT_VLC_STATIC(&ff_msmp4_mb_i_vlc, MB_INTRA_VLC_BITS, 64,
01352 &ff_msmp4_mb_i_table[0][1], 4, 2,
01353 &ff_msmp4_mb_i_table[0][0], 4, 2, 536);
01354
01355 INIT_VLC_STATIC(&ff_inter_intra_vlc, INTER_INTRA_VLC_BITS, 4,
01356 &table_inter_intra[0][1], 2, 1,
01357 &table_inter_intra[0][0], 2, 1, 8);
01358 }
01359
01360 switch(s->msmpeg4_version){
01361 case 1:
01362 case 2:
01363 s->decode_mb= msmpeg4v12_decode_mb;
01364 break;
01365 case 3:
01366 case 4:
01367 s->decode_mb= msmpeg4v34_decode_mb;
01368 break;
01369 case 5:
01370 if (CONFIG_WMV2_DECODER)
01371 s->decode_mb= ff_wmv2_decode_mb;
01372 case 6:
01373
01374 break;
01375 }
01376
01377 s->slice_height= s->mb_height;
01378
01379 return 0;
01380 }
01381
01382 int msmpeg4_decode_picture_header(MpegEncContext * s)
01383 {
01384 int code;
01385
01386 #if 0
01387 {
01388 int i;
01389 for(i=0; i<s->gb.size_in_bits; i++)
01390 av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb));
01391
01392 av_log(s->avctx, AV_LOG_DEBUG, "END\n");
01393 return -1;
01394 }
01395 #endif
01396
01397 if(s->msmpeg4_version==1){
01398 int start_code;
01399 start_code = (get_bits(&s->gb, 16)<<16) | get_bits(&s->gb, 16);
01400 if(start_code!=0x00000100){
01401 av_log(s->avctx, AV_LOG_ERROR, "invalid startcode\n");
01402 return -1;
01403 }
01404
01405 skip_bits(&s->gb, 5);
01406 }
01407
01408 s->pict_type = get_bits(&s->gb, 2) + 1;
01409 if (s->pict_type != FF_I_TYPE &&
01410 s->pict_type != FF_P_TYPE){
01411 av_log(s->avctx, AV_LOG_ERROR, "invalid picture type\n");
01412 return -1;
01413 }
01414 #if 0
01415 {
01416 static int had_i=0;
01417 if(s->pict_type == FF_I_TYPE) had_i=1;
01418 if(!had_i) return -1;
01419 }
01420 #endif
01421 s->chroma_qscale= s->qscale = get_bits(&s->gb, 5);
01422 if(s->qscale==0){
01423 av_log(s->avctx, AV_LOG_ERROR, "invalid qscale\n");
01424 return -1;
01425 }
01426
01427 if (s->pict_type == FF_I_TYPE) {
01428 code = get_bits(&s->gb, 5);
01429 if(s->msmpeg4_version==1){
01430 if(code==0 || code>s->mb_height){
01431 av_log(s->avctx, AV_LOG_ERROR, "invalid slice height %d\n", code);
01432 return -1;
01433 }
01434
01435 s->slice_height = code;
01436 }else{
01437
01438 if (code < 0x17){
01439 av_log(s->avctx, AV_LOG_ERROR, "error, slice code was %X\n", code);
01440 return -1;
01441 }
01442
01443 s->slice_height = s->mb_height / (code - 0x16);
01444 }
01445
01446 switch(s->msmpeg4_version){
01447 case 1:
01448 case 2:
01449 s->rl_chroma_table_index = 2;
01450 s->rl_table_index = 2;
01451
01452 s->dc_table_index = 0;
01453 break;
01454 case 3:
01455 s->rl_chroma_table_index = decode012(&s->gb);
01456 s->rl_table_index = decode012(&s->gb);
01457
01458 s->dc_table_index = get_bits1(&s->gb);
01459 break;
01460 case 4:
01461 msmpeg4_decode_ext_header(s, (2+5+5+17+7)/8);
01462
01463 if(s->bit_rate > MBAC_BITRATE) s->per_mb_rl_table= get_bits1(&s->gb);
01464 else s->per_mb_rl_table= 0;
01465
01466 if(!s->per_mb_rl_table){
01467 s->rl_chroma_table_index = decode012(&s->gb);
01468 s->rl_table_index = decode012(&s->gb);
01469 }
01470
01471 s->dc_table_index = get_bits1(&s->gb);
01472 s->inter_intra_pred= 0;
01473 break;
01474 }
01475 s->no_rounding = 1;
01476 if(s->avctx->debug&FF_DEBUG_PICT_INFO)
01477 av_log(s->avctx, AV_LOG_DEBUG, "qscale:%d rlc:%d rl:%d dc:%d mbrl:%d slice:%d \n",
01478 s->qscale,
01479 s->rl_chroma_table_index,
01480 s->rl_table_index,
01481 s->dc_table_index,
01482 s->per_mb_rl_table,
01483 s->slice_height);
01484 } else {
01485 switch(s->msmpeg4_version){
01486 case 1:
01487 case 2:
01488 if(s->msmpeg4_version==1)
01489 s->use_skip_mb_code = 1;
01490 else
01491 s->use_skip_mb_code = get_bits1(&s->gb);
01492 s->rl_table_index = 2;
01493 s->rl_chroma_table_index = s->rl_table_index;
01494 s->dc_table_index = 0;
01495 s->mv_table_index = 0;
01496 break;
01497 case 3:
01498 s->use_skip_mb_code = get_bits1(&s->gb);
01499 s->rl_table_index = decode012(&s->gb);
01500 s->rl_chroma_table_index = s->rl_table_index;
01501
01502 s->dc_table_index = get_bits1(&s->gb);
01503
01504 s->mv_table_index = get_bits1(&s->gb);
01505 break;
01506 case 4:
01507 s->use_skip_mb_code = get_bits1(&s->gb);
01508
01509 if(s->bit_rate > MBAC_BITRATE) s->per_mb_rl_table= get_bits1(&s->gb);
01510 else s->per_mb_rl_table= 0;
01511
01512 if(!s->per_mb_rl_table){
01513 s->rl_table_index = decode012(&s->gb);
01514 s->rl_chroma_table_index = s->rl_table_index;
01515 }
01516
01517 s->dc_table_index = get_bits1(&s->gb);
01518
01519 s->mv_table_index = get_bits1(&s->gb);
01520 s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE);
01521 break;
01522 }
01523
01524 if(s->avctx->debug&FF_DEBUG_PICT_INFO)
01525 av_log(s->avctx, AV_LOG_DEBUG, "skip:%d rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d \n",
01526 s->use_skip_mb_code,
01527 s->rl_table_index,
01528 s->rl_chroma_table_index,
01529 s->dc_table_index,
01530 s->mv_table_index,
01531 s->per_mb_rl_table,
01532 s->qscale);
01533
01534 if(s->flipflop_rounding){
01535 s->no_rounding ^= 1;
01536 }else{
01537 s->no_rounding = 0;
01538 }
01539 }
01540
01541
01542 s->esc3_level_length= 0;
01543 s->esc3_run_length= 0;
01544
01545 return 0;
01546 }
01547
01548 int msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size)
01549 {
01550 int left= buf_size*8 - get_bits_count(&s->gb);
01551 int length= s->msmpeg4_version>=3 ? 17 : 16;
01552
01553 if(left>=length && left<length+8)
01554 {
01555 int fps;
01556
01557 fps= get_bits(&s->gb, 5);
01558 s->bit_rate= get_bits(&s->gb, 11)*1024;
01559 if(s->msmpeg4_version>=3)
01560 s->flipflop_rounding= get_bits1(&s->gb);
01561 else
01562 s->flipflop_rounding= 0;
01563
01564
01565 }
01566 else if(left<length+8)
01567 {
01568 s->flipflop_rounding= 0;
01569 if(s->msmpeg4_version != 2)
01570 av_log(s->avctx, AV_LOG_ERROR, "ext header missing, %d left\n", left);
01571 }
01572 else
01573 {
01574 av_log(s->avctx, AV_LOG_ERROR, "I frame too long, ignoring ext header\n");
01575 }
01576
01577 return 0;
01578 }
01579
01580 static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr)
01581 {
01582 int level, pred;
01583
01584 if(s->msmpeg4_version<=2){
01585 if (n < 4) {
01586 level = get_vlc2(&s->gb, v2_dc_lum_vlc.table, DC_VLC_BITS, 3);
01587 } else {
01588 level = get_vlc2(&s->gb, v2_dc_chroma_vlc.table, DC_VLC_BITS, 3);
01589 }
01590 if (level < 0)
01591 return -1;
01592 level-=256;
01593 }else{
01594 if (n < 4) {
01595 level = get_vlc2(&s->gb, ff_msmp4_dc_luma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
01596 } else {
01597 level = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3);
01598 }
01599 if (level < 0){
01600 av_log(s->avctx, AV_LOG_ERROR, "illegal dc vlc\n");
01601 return -1;
01602 }
01603
01604 if (level == DC_MAX) {
01605 level = get_bits(&s->gb, 8);
01606 if (get_bits1(&s->gb))
01607 level = -level;
01608 } else if (level != 0) {
01609 if (get_bits1(&s->gb))
01610 level = -level;
01611 }
01612 }
01613
01614 if(s->msmpeg4_version==1){
01615 int32_t *dc_val;
01616 pred = msmpeg4v1_pred_dc(s, n, &dc_val);
01617 level += pred;
01618
01619
01620 *dc_val= level;
01621 }else{
01622 int16_t *dc_val;
01623 pred = msmpeg4_pred_dc(s, n, &dc_val, dir_ptr);
01624 level += pred;
01625
01626
01627 if (n < 4) {
01628 *dc_val = level * s->y_dc_scale;
01629 } else {
01630 *dc_val = level * s->c_dc_scale;
01631 }
01632 }
01633
01634 return level;
01635 }
01636
01637
01638 int ff_msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block,
01639 int n, int coded, const uint8_t *scan_table)
01640 {
01641 int level, i, last, run, run_diff;
01642 int av_uninit(dc_pred_dir);
01643 RLTable *rl;
01644 RL_VLC_ELEM *rl_vlc;
01645 int qmul, qadd;
01646
01647 if (s->mb_intra) {
01648 qmul=1;
01649 qadd=0;
01650
01651
01652 level = msmpeg4_decode_dc(s, n, &dc_pred_dir);
01653
01654 if (level < 0){
01655 av_log(s->avctx, AV_LOG_ERROR, "dc overflow- block: %d qscale: %d//\n", n, s->qscale);
01656 if(s->inter_intra_pred) level=0;
01657 else return -1;
01658 }
01659 if (n < 4) {
01660 rl = &rl_table[s->rl_table_index];
01661 if(level > 256*s->y_dc_scale){
01662 av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ L qscale: %d//\n", s->qscale);
01663 if(!s->inter_intra_pred) return -1;
01664 }
01665 } else {
01666 rl = &rl_table[3 + s->rl_chroma_table_index];
01667 if(level > 256*s->c_dc_scale){
01668 av_log(s->avctx, AV_LOG_ERROR, "dc overflow+ C qscale: %d//\n", s->qscale);
01669 if(!s->inter_intra_pred) return -1;
01670 }
01671 }
01672 block[0] = level;
01673
01674 run_diff = s->msmpeg4_version >= 4;
01675 i = 0;
01676 if (!coded) {
01677 goto not_coded;
01678 }
01679 if (s->ac_pred) {
01680 if (dc_pred_dir == 0)
01681 scan_table = s->intra_v_scantable.permutated;
01682 else
01683 scan_table = s->intra_h_scantable.permutated;
01684 } else {
01685 scan_table = s->intra_scantable.permutated;
01686 }
01687 rl_vlc= rl->rl_vlc[0];
01688 } else {
01689 qmul = s->qscale << 1;
01690 qadd = (s->qscale - 1) | 1;
01691 i = -1;
01692 rl = &rl_table[3 + s->rl_table_index];
01693
01694 if(s->msmpeg4_version==2)
01695 run_diff = 0;
01696 else
01697 run_diff = 1;
01698
01699 if (!coded) {
01700 s->block_last_index[n] = i;
01701 return 0;
01702 }
01703 if(!scan_table)
01704 scan_table = s->inter_scantable.permutated;
01705 rl_vlc= rl->rl_vlc[s->qscale];
01706 }
01707 {
01708 OPEN_READER(re, &s->gb);
01709 for(;;) {
01710 UPDATE_CACHE(re, &s->gb);
01711 GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 0);
01712 if (level==0) {
01713 int cache;
01714 cache= GET_CACHE(re, &s->gb);
01715
01716 if (s->msmpeg4_version==1 || (cache&0x80000000)==0) {
01717 if (s->msmpeg4_version==1 || (cache&0x40000000)==0) {
01718
01719 if(s->msmpeg4_version!=1) LAST_SKIP_BITS(re, &s->gb, 2);
01720 UPDATE_CACHE(re, &s->gb);
01721 if(s->msmpeg4_version<=3){
01722 last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1);
01723 run= SHOW_UBITS(re, &s->gb, 6); SKIP_CACHE(re, &s->gb, 6);
01724 level= SHOW_SBITS(re, &s->gb, 8); LAST_SKIP_CACHE(re, &s->gb, 8);
01725 SKIP_COUNTER(re, &s->gb, 1+6+8);
01726 }else{
01727 int sign;
01728 last= SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1);
01729 if(!s->esc3_level_length){
01730 int ll;
01731
01732 if(s->qscale<8){
01733 ll= SHOW_UBITS(re, &s->gb, 3); SKIP_BITS(re, &s->gb, 3);
01734 if(ll==0){
01735 ll= 8+SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1);
01736 }
01737 }else{
01738 ll=2;
01739 while(ll<8 && SHOW_UBITS(re, &s->gb, 1)==0){
01740 ll++;
01741 SKIP_BITS(re, &s->gb, 1);
01742 }
01743 if(ll<8) SKIP_BITS(re, &s->gb, 1);
01744 }
01745
01746 s->esc3_level_length= ll;
01747 s->esc3_run_length= SHOW_UBITS(re, &s->gb, 2) + 3; SKIP_BITS(re, &s->gb, 2);
01748
01749 UPDATE_CACHE(re, &s->gb);
01750 }
01751 run= SHOW_UBITS(re, &s->gb, s->esc3_run_length);
01752 SKIP_BITS(re, &s->gb, s->esc3_run_length);
01753
01754 sign= SHOW_UBITS(re, &s->gb, 1);
01755 SKIP_BITS(re, &s->gb, 1);
01756
01757 level= SHOW_UBITS(re, &s->gb, s->esc3_level_length);
01758 SKIP_BITS(re, &s->gb, s->esc3_level_length);
01759 if(sign) level= -level;
01760 }
01761
01762 #if 0 // waste of time / this will detect very few errors
01763 {
01764 const int abs_level= FFABS(level);
01765 const int run1= run - rl->max_run[last][abs_level] - run_diff;
01766 if(abs_level<=MAX_LEVEL && run<=MAX_RUN){
01767 if(abs_level <= rl->max_level[last][run]){
01768 av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, vlc encoding possible\n");
01769 return DECODING_AC_LOST;
01770 }
01771 if(abs_level <= rl->max_level[last][run]*2){
01772 av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 1 encoding possible\n");
01773 return DECODING_AC_LOST;
01774 }
01775 if(run1>=0 && abs_level <= rl->max_level[last][run1]){
01776 av_log(s->avctx, AV_LOG_ERROR, "illegal 3. esc, esc 2 encoding possible\n");
01777 return DECODING_AC_LOST;
01778 }
01779 }
01780 }
01781 #endif
01782
01783 if (level>0) level= level * qmul + qadd;
01784 else level= level * qmul - qadd;
01785 #if 0 // waste of time too :(
01786 if(level>2048 || level<-2048){
01787 av_log(s->avctx, AV_LOG_ERROR, "|level| overflow in 3. esc\n");
01788 return DECODING_AC_LOST;
01789 }
01790 #endif
01791 i+= run + 1;
01792 if(last) i+=192;
01793 #ifdef ERROR_DETAILS
01794 if(run==66)
01795 av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC3 level=%d\n", level);
01796 else if((i>62 && i<192) || i>192+63)
01797 av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC3 i=%d run=%d level=%d\n", i, run, level);
01798 #endif
01799 } else {
01800
01801 #if MIN_CACHE_BITS < 23
01802 LAST_SKIP_BITS(re, &s->gb, 2);
01803 UPDATE_CACHE(re, &s->gb);
01804 #else
01805 SKIP_BITS(re, &s->gb, 2);
01806 #endif
01807 GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
01808 i+= run + rl->max_run[run>>7][level/qmul] + run_diff;
01809 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
01810 LAST_SKIP_BITS(re, &s->gb, 1);
01811 #ifdef ERROR_DETAILS
01812 if(run==66)
01813 av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC2 level=%d\n", level);
01814 else if((i>62 && i<192) || i>192+63)
01815 av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC2 i=%d run=%d level=%d\n", i, run, level);
01816 #endif
01817 }
01818 } else {
01819
01820 #if MIN_CACHE_BITS < 22
01821 LAST_SKIP_BITS(re, &s->gb, 1);
01822 UPDATE_CACHE(re, &s->gb);
01823 #else
01824 SKIP_BITS(re, &s->gb, 1);
01825 #endif
01826 GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2, 1);
01827 i+= run;
01828 level = level + rl->max_level[run>>7][(run-1)&63] * qmul;
01829 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
01830 LAST_SKIP_BITS(re, &s->gb, 1);
01831 #ifdef ERROR_DETAILS
01832 if(run==66)
01833 av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code in ESC1 level=%d\n", level);
01834 else if((i>62 && i<192) || i>192+63)
01835 av_log(s->avctx, AV_LOG_ERROR, "run overflow in ESC1 i=%d run=%d level=%d\n", i, run, level);
01836 #endif
01837 }
01838 } else {
01839 i+= run;
01840 level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1);
01841 LAST_SKIP_BITS(re, &s->gb, 1);
01842 #ifdef ERROR_DETAILS
01843 if(run==66)
01844 av_log(s->avctx, AV_LOG_ERROR, "illegal vlc code level=%d\n", level);
01845 else if((i>62 && i<192) || i>192+63)
01846 av_log(s->avctx, AV_LOG_ERROR, "run overflow i=%d run=%d level=%d\n", i, run, level);
01847 #endif
01848 }
01849 if (i > 62){
01850 i-= 192;
01851 if(i&(~63)){
01852 const int left= get_bits_left(&s->gb);
01853 if(((i+192 == 64 && level/qmul==-1) || s->error_recognition<=1) && left>=0){
01854 av_log(s->avctx, AV_LOG_ERROR, "ignoring overflow at %d %d\n", s->mb_x, s->mb_y);
01855 break;
01856 }else{
01857 av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y);
01858 return -1;
01859 }
01860 }
01861
01862 block[scan_table[i]] = level;
01863 break;
01864 }
01865
01866 block[scan_table[i]] = level;
01867 }
01868 CLOSE_READER(re, &s->gb);
01869 }
01870 not_coded:
01871 if (s->mb_intra) {
01872 mpeg4_pred_ac(s, block, n, dc_pred_dir);
01873 if (s->ac_pred) {
01874 i = 63;
01875 }
01876 }
01877 if(s->msmpeg4_version>=4 && i>0) i=63;
01878 s->block_last_index[n] = i;
01879
01880 return 0;
01881 }
01882
01883 int ff_msmpeg4_decode_motion(MpegEncContext * s,
01884 int *mx_ptr, int *my_ptr)
01885 {
01886 MVTable *mv;
01887 int code, mx, my;
01888
01889 mv = &mv_tables[s->mv_table_index];
01890
01891 code = get_vlc2(&s->gb, mv->vlc.table, MV_VLC_BITS, 2);
01892 if (code < 0){
01893 av_log(s->avctx, AV_LOG_ERROR, "illegal MV code at %d %d\n", s->mb_x, s->mb_y);
01894 return -1;
01895 }
01896 if (code == mv->n) {
01897
01898 mx = get_bits(&s->gb, 6);
01899 my = get_bits(&s->gb, 6);
01900 } else {
01901 mx = mv->table_mvx[code];
01902 my = mv->table_mvy[code];
01903 }
01904
01905 mx += *mx_ptr - 32;
01906 my += *my_ptr - 32;
01907
01908 if (mx <= -64)
01909 mx += 64;
01910 else if (mx >= 64)
01911 mx -= 64;
01912
01913 if (my <= -64)
01914 my += 64;
01915 else if (my >= 64)
01916 my -= 64;
01917 *mx_ptr = mx;
01918 *my_ptr = my;
01919 return 0;
01920 }
01921
01922 AVCodec msmpeg4v1_decoder = {
01923 "msmpeg4v1",
01924 AVMEDIA_TYPE_VIDEO,
01925 CODEC_ID_MSMPEG4V1,
01926 sizeof(MpegEncContext),
01927 ff_msmpeg4_decode_init,
01928 NULL,
01929 ff_h263_decode_end,
01930 ff_h263_decode_frame,
01931 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
01932 .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 1"),
01933 .pix_fmts= ff_pixfmt_list_420,
01934 };
01935
01936 AVCodec msmpeg4v2_decoder = {
01937 "msmpeg4v2",
01938 AVMEDIA_TYPE_VIDEO,
01939 CODEC_ID_MSMPEG4V2,
01940 sizeof(MpegEncContext),
01941 ff_msmpeg4_decode_init,
01942 NULL,
01943 ff_h263_decode_end,
01944 ff_h263_decode_frame,
01945 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
01946 .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 2"),
01947 .pix_fmts= ff_pixfmt_list_420,
01948 };
01949
01950 AVCodec msmpeg4v3_decoder = {
01951 "msmpeg4",
01952 AVMEDIA_TYPE_VIDEO,
01953 CODEC_ID_MSMPEG4V3,
01954 sizeof(MpegEncContext),
01955 ff_msmpeg4_decode_init,
01956 NULL,
01957 ff_h263_decode_end,
01958 ff_h263_decode_frame,
01959 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
01960 .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 3"),
01961 .pix_fmts= ff_pixfmt_list_420,
01962 };
01963
01964 AVCodec wmv1_decoder = {
01965 "wmv1",
01966 AVMEDIA_TYPE_VIDEO,
01967 CODEC_ID_WMV1,
01968 sizeof(MpegEncContext),
01969 ff_msmpeg4_decode_init,
01970 NULL,
01971 ff_h263_decode_end,
01972 ff_h263_decode_frame,
01973 CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1,
01974 .long_name= NULL_IF_CONFIG_SMALL("Windows Media Video 7"),
01975 .pix_fmts= ff_pixfmt_list_420,
01976 };