Revision 7bc9090a libavcodec/mpegvideo.c
libavcodec/mpegvideo.c  

136  136 
} 
137  137 
#endif //CONFIG_ENCODERS 
138  138  
139 
// move into common.c perhaps 

140 
#define CHECKED_ALLOCZ(p, size)\ 

141 
{\ 

142 
p= av_mallocz(size);\ 

143 
if(p==NULL){\ 

144 
perror("malloc");\ 

145 
goto fail;\ 

146 
}\ 

147 
} 

148  
149  139 
void ff_init_scantable(MpegEncContext *s, ScanTable *st, const uint8_t *src_scantable){ 
150  140 
int i; 
151  141 
int end; 
...  ...  
227  217 
* The pixels are allocated/set by calling get_buffer() if shared=0 
228  218 
*/ 
229  219 
static int alloc_picture(MpegEncContext *s, Picture *pic, int shared){ 
230 
const int big_mb_num= (s>mb_width+1)*(s>mb_height+1); 

220 
const int big_mb_num= s>mb_stride*(s>mb_height+1) + 1; //the +1 is needed so memset(,,stride*height) doesnt sig11 

221 
const int mb_array_size= s>mb_stride*s>mb_height; 

231  222 
int i; 
232  
223 


233  224 
if(shared){ 
234  225 
assert(pic>data[0]); 
235  226 
assert(pic>type == 0  pic>type == FF_BUFFER_TYPE_SHARED); 
...  ...  
262  253 

263  254 
if(pic>qscale_table==NULL){ 
264  255 
if (s>encoding) { 
265 
CHECKED_ALLOCZ(pic>mb_var , s>mb_num * sizeof(int16_t))


266 
CHECKED_ALLOCZ(pic>mc_mb_var, s>mb_num * sizeof(int16_t))


267 
CHECKED_ALLOCZ(pic>mb_mean , s>mb_num * sizeof(int8_t))


268 
CHECKED_ALLOCZ(pic>mb_cmp_score, s>mb_num * sizeof(int32_t))


256 
CHECKED_ALLOCZ(pic>mb_var , mb_array_size * sizeof(int16_t))


257 
CHECKED_ALLOCZ(pic>mc_mb_var, mb_array_size * sizeof(int16_t))


258 
CHECKED_ALLOCZ(pic>mb_mean , mb_array_size * sizeof(int8_t))


259 
CHECKED_ALLOCZ(pic>mb_cmp_score, mb_array_size * sizeof(int32_t))


269  260 
} 
270  261  
271 
CHECKED_ALLOCZ(pic>mbskip_table , s>mb_num * sizeof(uint8_t)+1) //the +1 is for the slice end check 

272 
CHECKED_ALLOCZ(pic>qscale_table , s>mb_num * sizeof(uint8_t)) 

262 
CHECKED_ALLOCZ(pic>mbskip_table , mb_array_size * sizeof(uint8_t)+2) //the +2 is for the slice end check 

263 
CHECKED_ALLOCZ(pic>qscale_table , mb_array_size * sizeof(uint8_t)) 

264 
CHECKED_ALLOCZ(pic>mb_type_base , big_mb_num * sizeof(int)) 

265 
pic>mb_type= pic>mb_type_base + s>mb_stride+1; 

273  266 
if(s>out_format == FMT_H264){ 
274 
CHECKED_ALLOCZ(pic>mb_type_base , big_mb_num * sizeof(uint16_t)) 

275 
pic>mb_type= pic>mb_type_base + s>mb_width+2; 

276  267 
for(i=0; i<2; i++){ 
277  268 
CHECKED_ALLOCZ(pic>motion_val[i], 2 * 16 * s>mb_num * sizeof(uint16_t)) 
278  269 
CHECKED_ALLOCZ(pic>ref_index[i] , 4 * s>mb_num * sizeof(uint8_t)) 
279  270 
} 
280  271 
} 
281 
pic>qstride= s>mb_width;


272 
pic>qstride= s>mb_stride;


282  273 
} 
283  274  
284  275 
//it might be nicer if the application would keep track of these but it would require a API change 
...  ...  
334  325 
/* init common structure for both encoder and decoder */ 
335  326 
int MPV_common_init(MpegEncContext *s) 
336  327 
{ 
337 
int y_size, c_size, yc_size, i; 

328 
int y_size, c_size, yc_size, i, mb_array_size, x, y;


338  329  
339  330 
dsputil_init(&s>dsp, s>avctx); 
340  331 
DCT_common_init(s); 
...  ...  
343  334  
344  335 
s>mb_width = (s>width + 15) / 16; 
345  336 
s>mb_height = (s>height + 15) / 16; 
337 
s>mb_stride = s>mb_width + 1; 

338 
mb_array_size= s>mb_height * s>mb_stride; 

346  339  
347  340 
/* set default edge pos, will be overriden in decode_header if needed */ 
348  341 
s>h_edge_pos= s>mb_width*16; 
349  342 
s>v_edge_pos= s>mb_height*16; 
350  343  
351  344 
s>mb_num = s>mb_width * s>mb_height; 
345 


346 
s>block_wrap[0]= 

347 
s>block_wrap[1]= 

348 
s>block_wrap[2]= 

349 
s>block_wrap[3]= s>mb_width*2 + 2; 

350 
s>block_wrap[4]= 

351 
s>block_wrap[5]= s>mb_width + 2; 

352  352  
353  353 
y_size = (2 * s>mb_width + 2) * (2 * s>mb_height + 2); 
354  354 
c_size = (s>mb_width + 2) * (s>mb_height + 2); 
...  ...  
365  365  
366  366 
s>avctx>coded_frame= (AVFrame*)&s>current_picture; 
367  367  
368 
CHECKED_ALLOCZ(s>mb_index2xy, (s>mb_num+1)*sizeof(int)) //error ressilience code looks cleaner with this 

369 
for(y=0; y<s>mb_height; y++){ 

370 
for(x=0; x<s>mb_width; x++){ 

371 
s>mb_index2xy[ x + y*s>mb_width ] = x + y*s>mb_stride; 

372 
} 

373 
} 

374 
s>mb_index2xy[ s>mb_height*s>mb_width ] = (s>mb_height1)*s>mb_stride + s>mb_width; //FIXME really needed? 

375 


368  376 
if (s>encoding) { 
369 
int mv_table_size= (s>mb_width+2)*(s>mb_height+2);


377 
int mv_table_size= s>mb_stride * (s>mb_height+2) + 1;


370  378  
371  379 
/* Allocate MV tables */ 
372 
CHECKED_ALLOCZ(s>p_mv_table , mv_table_size * 2 * sizeof(int16_t)) 

373 
CHECKED_ALLOCZ(s>b_forw_mv_table , mv_table_size * 2 * sizeof(int16_t)) 

374 
CHECKED_ALLOCZ(s>b_back_mv_table , mv_table_size * 2 * sizeof(int16_t)) 

375 
CHECKED_ALLOCZ(s>b_bidir_forw_mv_table , mv_table_size * 2 * sizeof(int16_t)) 

376 
CHECKED_ALLOCZ(s>b_bidir_back_mv_table , mv_table_size * 2 * sizeof(int16_t)) 

377 
CHECKED_ALLOCZ(s>b_direct_mv_table , mv_table_size * 2 * sizeof(int16_t)) 

380 
CHECKED_ALLOCZ(s>p_mv_table_base , mv_table_size * 2 * sizeof(int16_t)) 

381 
CHECKED_ALLOCZ(s>b_forw_mv_table_base , mv_table_size * 2 * sizeof(int16_t)) 

382 
CHECKED_ALLOCZ(s>b_back_mv_table_base , mv_table_size * 2 * sizeof(int16_t)) 

383 
CHECKED_ALLOCZ(s>b_bidir_forw_mv_table_base , mv_table_size * 2 * sizeof(int16_t)) 

384 
CHECKED_ALLOCZ(s>b_bidir_back_mv_table_base , mv_table_size * 2 * sizeof(int16_t)) 

385 
CHECKED_ALLOCZ(s>b_direct_mv_table_base , mv_table_size * 2 * sizeof(int16_t)) 

386 
s>p_mv_table = s>p_mv_table_base + s>mb_stride + 1; 

387 
s>b_forw_mv_table = s>b_forw_mv_table_base + s>mb_stride + 1; 

388 
s>b_back_mv_table = s>b_back_mv_table_base + s>mb_stride + 1; 

389 
s>b_bidir_forw_mv_table= s>b_bidir_forw_mv_table_base + s>mb_stride + 1; 

390 
s>b_bidir_back_mv_table= s>b_bidir_back_mv_table_base + s>mb_stride + 1; 

391 
s>b_direct_mv_table = s>b_direct_mv_table_base + s>mb_stride + 1; 

378  392  
379  393 
//FIXME should be linesize instead of s>width*2 but that isnt known before get_buffer() 
380  394 
CHECKED_ALLOCZ(s>me.scratchpad, s>width*2*16*3*sizeof(uint8_t)) 
...  ...  
391  405 
CHECKED_ALLOCZ(s>ac_stats, 2*2*(MAX_LEVEL+1)*(MAX_RUN+1)*2*sizeof(int)); 
392  406 
} 
393  407 
CHECKED_ALLOCZ(s>avctx>stats_out, 256); 
408  
409 
/* Allocate MB type table */ 

410 
CHECKED_ALLOCZ(s>mb_type , mb_array_size * sizeof(uint8_t)) //needed for encoding 

394  411 
} 
395  412 

396 
CHECKED_ALLOCZ(s>error_status_table, s>mb_num*sizeof(uint8_t))


413 
CHECKED_ALLOCZ(s>error_status_table, mb_array_size*sizeof(uint8_t))


397  414 

398  415 
if (s>out_format == FMT_H263  s>encoding) { 
399  416 
int size; 
400 
/* Allocate MB type table */ 

401 
CHECKED_ALLOCZ(s>mb_type , s>mb_num * sizeof(uint8_t)) 

402  417  
403  418 
/* MV prediction */ 
404  419 
size = (2 * s>mb_width + 2) * (2 * s>mb_height + 2); 
...  ...  
407  422  
408  423 
if(s>codec_id==CODEC_ID_MPEG4){ 
409  424 
/* interlaced direct mode decoding tables */ 
410 
CHECKED_ALLOCZ(s>field_mv_table, s>mb_num*2*2 * sizeof(int16_t))


411 
CHECKED_ALLOCZ(s>field_select_table, s>mb_num*2* sizeof(int8_t))


425 
CHECKED_ALLOCZ(s>field_mv_table, mb_array_size*2*2 * sizeof(int16_t))


426 
CHECKED_ALLOCZ(s>field_select_table, mb_array_size*2* sizeof(int8_t))


412  427 
} 
413 
/* 4mv b frame decoding table */ 

414 
//note this is needed for h263 without b frames too (segfault on damaged streams otherwise) 

415 
CHECKED_ALLOCZ(s>co_located_type_table, s>mb_num * sizeof(uint8_t)) 

416  428 
if (s>out_format == FMT_H263) { 
417  429 
/* ac values */ 
418  430 
CHECKED_ALLOCZ(s>ac_val[0], yc_size * sizeof(int16_t) * 16); 
...  ...  
426  438 
CHECKED_ALLOCZ(s>bitstream_buffer, BITSTREAM_BUFFER_SIZE); 
427  439  
428  440 
/* cbp, ac_pred, pred_dir */ 
429 
CHECKED_ALLOCZ(s>cbp_table , s>mb_num * sizeof(uint8_t))


430 
CHECKED_ALLOCZ(s>pred_dir_table, s>mb_num * sizeof(uint8_t))


441 
CHECKED_ALLOCZ(s>cbp_table , mb_array_size * sizeof(uint8_t))


442 
CHECKED_ALLOCZ(s>pred_dir_table, mb_array_size * sizeof(uint8_t))


431  443 
} 
432  444 

433  445 
if (s>h263_pred  s>h263_plus  !s>encoding) { 
...  ...  
441  453 
} 
442  454  
443  455 
/* which mb is a intra block */ 
444 
CHECKED_ALLOCZ(s>mbintra_table, s>mb_num);


445 
memset(s>mbintra_table, 1, s>mb_num);


456 
CHECKED_ALLOCZ(s>mbintra_table, mb_array_size);


457 
memset(s>mbintra_table, 1, mb_array_size);


446  458 

447  459 
/* default structure is frame */ 
448  460 
s>picture_structure = PICT_FRAME; 
449  461 

450  462 
/* init macroblock skip table */ 
451 
CHECKED_ALLOCZ(s>mbskip_table, s>mb_num+1);


463 
CHECKED_ALLOCZ(s>mbskip_table, mb_array_size+2);


452  464 
//Note the +1 is for a quicker mpeg4 slice_end detection 
453  465 
CHECKED_ALLOCZ(s>prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE); 
454  466 

...  ...  
472  484 
int i; 
473  485  
474  486 
av_freep(&s>mb_type); 
475 
av_freep(&s>p_mv_table); 

476 
av_freep(&s>b_forw_mv_table); 

477 
av_freep(&s>b_back_mv_table); 

478 
av_freep(&s>b_bidir_forw_mv_table); 

479 
av_freep(&s>b_bidir_back_mv_table); 

480 
av_freep(&s>b_direct_mv_table); 

487 
av_freep(&s>p_mv_table_base); 

488 
av_freep(&s>b_forw_mv_table_base); 

489 
av_freep(&s>b_back_mv_table_base); 

490 
av_freep(&s>b_bidir_forw_mv_table_base); 

491 
av_freep(&s>b_bidir_back_mv_table_base); 

492 
av_freep(&s>b_direct_mv_table_base); 

493 
s>p_mv_table= NULL; 

494 
s>b_forw_mv_table= NULL; 

495 
s>b_back_mv_table= NULL; 

496 
s>b_bidir_forw_mv_table= NULL; 

497 
s>b_bidir_back_mv_table= NULL; 

498 
s>b_direct_mv_table= NULL; 

499 


481  500 
av_freep(&s>motion_val); 
482  501 
av_freep(&s>dc_val[0]); 
483  502 
av_freep(&s>ac_val[0]); 
...  ...  
495  514 
av_freep(&s>tex_pb_buffer); 
496  515 
av_freep(&s>pb2_buffer); 
497  516 
av_freep(&s>allocated_edge_emu_buffer); s>edge_emu_buffer= NULL; 
498 
av_freep(&s>co_located_type_table); 

499  517 
av_freep(&s>field_mv_table); 
500  518 
av_freep(&s>field_select_table); 
501  519 
av_freep(&s>avctx>stats_out); 
502  520 
av_freep(&s>ac_stats); 
503  521 
av_freep(&s>error_status_table); 
522 
av_freep(&s>mb_index2xy); 

504  523  
505  524 
for(i=0; i<MAX_PICTURE_COUNT; i++){ 
506  525 
free_picture(s, &s>picture[i]); 
...  ...  
925  944  
926  945 
s>current_picture_ptr>pict_type= s>pict_type; 
927  946 
s>current_picture_ptr>quality= s>qscale; 
947 
s>current_picture_ptr>key_frame= s>pict_type == I_TYPE; 

928  948  
929  949 
s>current_picture= *s>current_picture_ptr; 
930  950 

...  ...  
1000  1020 
} 
1001  1021 
assert(i<MAX_PICTURE_COUNT); 
1002  1022 
#endif 
1003 
s>current_picture_ptr>quality= s>qscale; //FIXME get average of qscale_table 

1004 
s>current_picture_ptr>pict_type= s>pict_type; 

1005 
s>current_picture_ptr>key_frame= s>pict_type == I_TYPE; 

1006  1023  
1007  1024 
/* release non refernce frames */ 
1008  1025 
for(i=0; i<MAX_PICTURE_COUNT; i++){ 
1009  1026 
if(s>picture[i].data[0] && !s>picture[i].reference /*&& s>picture[i].type!=FF_BUFFER_TYPE_SHARED*/) 
1010  1027 
s>avctx>release_buffer(s>avctx, (AVFrame*)&s>picture[i]); 
1011  1028 
} 
1012 
if(s>avctx>debug&FF_DEBUG_SKIP){ 

1013 
int x,y; 

1014 
for(y=0; y<s>mb_height; y++){ 

1015 
for(x=0; x<s>mb_width; x++){ 

1016 
int count= s>mbskip_table[x + y*s>mb_width]; 

1017 
if(count>9) count=9; 

1018 
printf(" %1d", count); 

1019 
} 

1020 
printf("\n"); 

1021 
} 

1022 
printf("pict type: %d\n", s>pict_type); 

1023 
} 

1024  
1029 


1025  1030 
// clear copies, to avoid confusion 
1026  1031 
#if 0 
1027  1032 
memset(&s>last_picture, 0, sizeof(Picture)); 
...  ...  
1030  1035 
#endif 
1031  1036 
} 
1032  1037  
1038 
/** 

1039 
* prints debuging info for the given picture. 

1040 
*/ 

1041 
void ff_print_debug_info(MpegEncContext *s, Picture *pict){ 

1042  
1043 
if(!pict  !pict>mb_type) return; 

1044  
1045 
if(s>avctx>debug&(FF_DEBUG_SKIP  FF_DEBUG_QP  FF_DEBUG_MB_TYPE)){ 

1046 
int x,y; 

1047  
1048 
for(y=0; y<s>mb_height; y++){ 

1049 
for(x=0; x<s>mb_width; x++){ 

1050 
if(s>avctx>debug&FF_DEBUG_SKIP){ 

1051 
int count= s>mbskip_table[x + y*s>mb_stride]; 

1052 
if(count>9) count=9; 

1053 
printf("%1d", count); 

1054 
} 

1055 
if(s>avctx>debug&FF_DEBUG_QP){ 

1056 
printf("%2d", pict>qscale_table[x + y*s>mb_stride]); 

1057 
} 

1058 
if(s>avctx>debug&FF_DEBUG_MB_TYPE){ 

1059 
int mb_type= pict>mb_type[x + y*s>mb_stride]; 

1060 


1061 
//Type & MV direction 

1062 
if(IS_PCM(mb_type)) 

1063 
printf("P"); 

1064 
else if(IS_INTRA(mb_type) && IS_ACPRED(mb_type)) 

1065 
printf("A"); 

1066 
else if(IS_INTRA4x4(mb_type)) 

1067 
printf("i"); 

1068 
else if(IS_INTRA16x16(mb_type)) 

1069 
printf("I"); 

1070 
else if(IS_DIRECT(mb_type) && IS_SKIP(mb_type)) 

1071 
printf("d"); 

1072 
else if(IS_DIRECT(mb_type)) 

1073 
printf("D"); 

1074 
else if(IS_GMC(mb_type) && IS_SKIP(mb_type)) 

1075 
printf("g"); 

1076 
else if(IS_GMC(mb_type)) 

1077 
printf("G"); 

1078 
else if(IS_SKIP(mb_type)) 

1079 
printf("S"); 

1080 
else if(!USES_LIST(mb_type, 1)) 

1081 
printf(">"); 

1082 
else if(!USES_LIST(mb_type, 0)) 

1083 
printf("<"); 

1084 
else{ 

1085 
assert(USES_LIST(mb_type, 0) && USES_LIST(mb_type, 1)); 

1086 
printf("X"); 

1087 
} 

1088 


1089 
//segmentation 

1090 
if(IS_8X8(mb_type)) 

1091 
printf("+"); 

1092 
else if(IS_16X8(mb_type)) 

1093 
printf(""); 

1094 
else if(IS_8X16(mb_type)) 

1095 
printf("?"); 

1096 
else if(IS_INTRA(mb_type)  IS_16X16(mb_type)) 

1097 
printf(" "); 

1098 
else 

1099 
printf("?"); 

1100 


1101 


1102 
if(IS_INTERLACED(mb_type) && s>codec_id == CODEC_ID_H264) 

1103 
printf("="); 

1104 
else 

1105 
printf(" "); 

1106 
} 

1107 
// printf(" "); 

1108 
} 

1109 
printf("\n"); 

1110 
} 

1111 
} 

1112 
} 

1113  
1033  1114 
#ifdef CONFIG_ENCODERS 
1034  1115  
1035  1116 
static int get_sae(uint8_t *src, int ref, int stride){ 
...  ...  
2007  2088 
memset(s>ac_val[1][xy], 0, 16 * sizeof(int16_t)); 
2008  2089 
memset(s>ac_val[2][xy], 0, 16 * sizeof(int16_t)); 
2009  2090 

2010 
s>mbintra_table[s>mb_x + s>mb_y*s>mb_width]= 0;


2091 
s>mbintra_table[s>mb_x + s>mb_y*s>mb_stride]= 0;


2011  2092 
} 
2012  2093  
2013  2094 
/* generic function called after a macroblock has been parsed by the 
...  ...  
2023  2104 
void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) 
2024  2105 
{ 
2025  2106 
int mb_x, mb_y; 
2026 
const int mb_xy = s>mb_y * s>mb_width + s>mb_x;


2107 
const int mb_xy = s>mb_y * s>mb_stride + s>mb_x;


2027  2108  
2028  2109 
mb_x = s>mb_x; 
2029  2110 
mb_y = s>mb_y; 
...  ...  
2049  2130 
//FIXME a lot of thet is only needed for !low_delay 
2050  2131 
const int wrap = s>block_wrap[0]; 
2051  2132 
const int xy = s>block_index[0]; 
2052 
const int mb_index= s>mb_x + s>mb_y*s>mb_width; 

2053 
if(s>mv_type == MV_TYPE_8X8){ 

2054 
s>co_located_type_table[mb_index]= CO_LOCATED_TYPE_4MV; 

2055 
} else { 

2133 
if(s>mv_type != MV_TYPE_8X8){ 

2056  2134 
int motion_x, motion_y; 
2057  2135 
if (s>mb_intra) { 
2058  2136 
motion_x = 0; 
2059  2137 
motion_y = 0; 
2060 
if(s>co_located_type_table) 

2061 
s>co_located_type_table[mb_index]= 0; 

2062  2138 
} else if (s>mv_type == MV_TYPE_16X16) { 
2063  2139 
motion_x = s>mv[0][0][0]; 
2064  2140 
motion_y = s>mv[0][0][1]; 
2065 
if(s>co_located_type_table) 

2066 
s>co_located_type_table[mb_index]= 0; 

2067  2141 
} else /*if (s>mv_type == MV_TYPE_FIELD)*/ { 
2068  2142 
int i; 
2069  2143 
motion_x = s>mv[0][0][0] + s>mv[0][1][0]; 
2070  2144 
motion_y = s>mv[0][0][1] + s>mv[0][1][1]; 
2071  2145 
motion_x = (motion_x>>1)  (motion_x&1); 
2072  2146 
for(i=0; i<2; i++){ 
2073 
s>field_mv_table[mb_index][i][0]= s>mv[0][i][0];


2074 
s>field_mv_table[mb_index][i][1]= s>mv[0][i][1];


2075 
s>field_select_table[mb_index][i]= s>field_select[0][i];


2147 
s>field_mv_table[mb_xy][i][0]= s>mv[0][i][0];


2148 
s>field_mv_table[mb_xy][i][1]= s>mv[0][i][1];


2149 
s>field_select_table[mb_xy][i]= s>field_select[0][i];


2076  2150 
} 
2077 
s>co_located_type_table[mb_index]= CO_LOCATED_TYPE_FIELDMV; 

2078  2151 
} 
2152 


2079  2153 
/* no update if 8X8 because it has been done during parsing */ 
2080  2154 
s>motion_val[xy][0] = motion_x; 
2081  2155 
s>motion_val[xy][1] = motion_y; 
...  ...  
2086  2160 
s>motion_val[xy + 1 + wrap][0] = motion_x; 
2087  2161 
s>motion_val[xy + 1 + wrap][1] = motion_y; 
2088  2162 
} 
2163  
2164 
if(s>encoding){ //FIXME encoding MUST be cleaned up 

2165 
if (s>mv_type == MV_TYPE_8X8) 

2166 
s>current_picture.mb_type[mb_xy]= MB_TYPE_L0  MB_TYPE_8x8; 

2167 
else 

2168 
s>current_picture.mb_type[mb_xy]= MB_TYPE_L0  MB_TYPE_16x16; 

2169 
} 

2089  2170 
} 
2090  2171 

2091  2172 
if ((s>flags&CODEC_FLAG_PSNR)  !(s>encoding && (s>intra_only  s>pict_type==B_TYPE))) { //FIXME precalc 
...  ...  
2411  2492 
for(i=0; i<6; i++) skip_dct[i]=0; 
2412  2493 

2413  2494 
if(s>adaptive_quant){ 
2414 
s>dquant= s>current_picture.qscale_table[mb_x + mb_y*s>mb_width]  s>qscale;


2495 
s>dquant= s>current_picture.qscale_table[mb_x + mb_y*s>mb_stride]  s>qscale;


2415  2496  
2416  2497 
if(s>out_format==FMT_H263){ 
2417  2498 
if (s>dquant> 2) s>dquant= 2; 
...  ...  
2562  2643 
s>dsp.diff_pixels(s>block[5], ptr_cr, dest_cr, wrap_c); 
2563  2644 
} 
2564  2645 
/* pre quantization */ 
2565 
if(s>current_picture.mc_mb_var[s>mb_width*mb_y+ mb_x]<2*s>qscale*s>qscale){


2646 
if(s>current_picture.mc_mb_var[s>mb_stride*mb_y+ mb_x]<2*s>qscale*s>qscale){


2566  2647 
//FIXME optimize 
2567  2648 
if(s>dsp.pix_abs8x8(ptr_y , dest_y , wrap_y) < 20*s>qscale) skip_dct[0]= 1; 
2568  2649 
if(s>dsp.pix_abs8x8(ptr_y + 8, dest_y + 8, wrap_y) < 20*s>qscale) skip_dct[1]= 1; 
...  ...  
2593  2674 
{ 
2594  2675 
float adap_parm; 
2595  2676 

2596 
adap_parm = ((s>avg_mb_var << 1) + s>mb_var[s>mb_width*mb_y+mb_x] + 1.0) /


2597 
((s>mb_var[s>mb_width*mb_y+mb_x] << 1) + s>avg_mb_var + 1.0);


2677 
adap_parm = ((s>avg_mb_var << 1) + s>mb_var[s>mb_stride*mb_y+mb_x] + 1.0) /


2678 
((s>mb_var[s>mb_stride*mb_y+mb_x] << 1) + s>avg_mb_var + 1.0);


2598  2679 

2599  2680 
printf("\ntype=%c qscale=%2d adap=%0.2f dquant=%4.2f var=%4d avgvar=%4d", 
2600 
(s>mb_type[s>mb_width*mb_y+mb_x] > 0) ? 'I' : 'P',


2681 
(s>mb_type[s>mb_stride*mb_y+mb_x] > 0) ? 'I' : 'P',


2601  2682 
s>qscale, adap_parm, s>qscale*adap_parm, 
2602 
s>mb_var[s>mb_width*mb_y+mb_x], s>avg_mb_var);


2683 
s>mb_var[s>mb_stride*mb_y+mb_x], s>avg_mb_var);


2603  2684 
} 
2604  2685 
#endif 
2605  2686 
/* DCT & quantize */ 
...  ...  
2837  2918 
} 
2838  2919  
2839  2920 
s>picture_number = picture_number; 
2840  
2841 
s>block_wrap[0]= 

2842 
s>block_wrap[1]= 

2843 
s>block_wrap[2]= 

2844 
s>block_wrap[3]= s>mb_width*2 + 2; 

2845 
s>block_wrap[4]= 

2846 
s>block_wrap[5]= s>mb_width + 2; 

2847  2921 

2848  2922 
/* Reset the average MB variance */ 
2849  2923 
s>current_picture.mb_var_sum = 0; 
...  ...  
2912  2986 
/* IFrame */ 
2913  2987 
//FIXME do we need to zero them? 
2914  2988 
memset(s>motion_val[0], 0, sizeof(int16_t)*(s>mb_width*2 + 2)*(s>mb_height*2 + 2)*2); 
2915 
memset(s>p_mv_table , 0, sizeof(int16_t)*(s>mb_width+2)*(s>mb_height+2)*2);


2916 
memset(s>mb_type , MB_TYPE_INTRA, sizeof(uint8_t)*s>mb_width*s>mb_height);


2989 
memset(s>p_mv_table , 0, sizeof(int16_t)*(s>mb_stride)*s>mb_height*2);


2990 
memset(s>mb_type , MB_TYPE_INTRA, sizeof(uint8_t)*s>mb_stride*s>mb_height);


2917  2991 

2918  2992 
if(!s>fixed_qscale){ 
2919  2993 
/* finding spatial complexity for Iframe rate control */ 
...  ...  
2927  3001 

2928  3002 
varc = (s>dsp.pix_norm1(pix, s>linesize)  (((unsigned)(sum*sum))>>8) + 500 + 128)>>8; 
2929  3003  
2930 
s>current_picture.mb_var [s>mb_width * mb_y + mb_x] = varc;


2931 
s>current_picture.mb_mean[s>mb_width * mb_y + mb_x] = (sum+128)>>8;


3004 
s>current_picture.mb_var [s>mb_stride * mb_y + mb_x] = varc;


3005 
s>current_picture.mb_mean[s>mb_stride * mb_y + mb_x] = (sum+128)>>8;


2932  3006 
s>current_picture.mb_var_sum += varc; 
2933  3007 
} 
2934  3008 
} 
...  ...  
2938  3012  
2939  3013 
if(s>scene_change_score > 0 && s>pict_type == P_TYPE){ 
2940  3014 
s>pict_type= I_TYPE; 
2941 
memset(s>mb_type , MB_TYPE_INTRA, sizeof(uint8_t)*s>mb_width*s>mb_height);


3015 
memset(s>mb_type , MB_TYPE_INTRA, sizeof(uint8_t)*s>mb_stride*s>mb_height);


2942  3016 
//printf("Scene change detected, encoding as I Frame %d %d\n", s>current_picture.mb_var_sum, s>current_picture.mc_mb_var_sum); 
2943  3017 
} 
2944  3018  
...  ...  
3081  3155 
s>block_index[4]= s>block_wrap[4]*(mb_y + 1) + s>block_wrap[0]*(s>mb_height*2 + 2); 
3082  3156 
s>block_index[5]= s>block_wrap[4]*(mb_y + 1 + s>mb_height + 2) + s>block_wrap[0]*(s>mb_height*2 + 2); 
3083  3157 
for(mb_x=0; mb_x < s>mb_width; mb_x++) { 
3084 
int mb_type= s>mb_type[mb_y * s>mb_width + mb_x];


3085 
const int xy= (mb_y+1) * (s>mb_width+2) + mb_x + 1;


3158 
const int xy= mb_y*s>mb_stride + mb_x;


3159 
int mb_type= s>mb_type[xy];


3086  3160 
// int d; 
3087  3161 
int dmin=10000000; 
3088  3162  
...  ...  
3235  3309 
&dmin, &next_block, 0, 0); 
3236  3310 
/* force cleaning of ac/dc pred stuff if needed ... */ 
3237  3311 
if(s>h263_pred  s>h263_aic) 
3238 
s>mbintra_table[mb_x + mb_y*s>mb_width]=1;


3312 
s>mbintra_table[mb_x + mb_y*s>mb_stride]=1;


3239  3313 
} 
3240  3314 
copy_context_after_encode(s, &best_s, 1); 
3241  3315 

...  ...  
3259  3333 
} else { 
3260  3334 
int motion_x, motion_y; 
3261  3335 
int intra_score; 
3262 
int inter_score= s>current_picture.mb_cmp_score[mb_x + mb_y*s>mb_width];


3336 
int inter_score= s>current_picture.mb_cmp_score[mb_x + mb_y*s>mb_stride];


3263  3337 

3264  3338 
if(!(s>flags&CODEC_FLAG_HQ) && s>pict_type==P_TYPE){ 
3265  3339 
/* get luma score */ 
3266  3340 
if((s>avctx>mb_cmp&0xFF)==FF_CMP_SSE){ 
3267 
intra_score= (s>current_picture.mb_var[mb_x + mb_y*s>mb_width]<<8)  500; //FIXME dont scale it down so we dont have to fix it


3341 
intra_score= (s>current_picture.mb_var[mb_x + mb_y*s>mb_stride]<<8)  500; //FIXME dont scale it down so we dont have to fix it


3268  3342 
}else{ 
3269  3343 
uint8_t *dest_y; 
3270  3344  
3271 
int mean= s>current_picture.mb_mean[mb_x + mb_y*s>mb_width]; //FIXME


3345 
int mean= s>current_picture.mb_mean[mb_x + mb_y*s>mb_stride]; //FIXME


3272  3346 
mean*= 0x01010101; 
3273  3347 

3274  3348 
dest_y = s>new_picture.data[0] + (mb_y * 16 * s>linesize ) + mb_x * 16; 
...  ...  
3284  3358 
intra_score= s>dsp.mb_cmp[0](s, s>me.scratchpad, dest_y, s>linesize); 
3285  3359 

3286  3360 
/* printf("intra:%7d inter:%7d var:%7d mc_var.%7d\n", intra_score>>8, inter_score>>8, 
3287 
s>current_picture.mb_var[mb_x + mb_y*s>mb_width],


3288 
s>current_picture.mc_mb_var[mb_x + mb_y*s>mb_width]);*/


3361 
s>current_picture.mb_var[mb_x + mb_y*s>mb_stride],


3362 
s>current_picture.mc_mb_var[mb_x + mb_y*s>mb_stride]);*/


3289  3363 
} 
3290  3364 

3291  3365 
/* get chroma score */ 
...  ...  
3442  3516 
s>current_picture.data[2] + s>mb_x*8 + s>mb_y*s>uvlinesize*8, 
3443  3517 
w>>1, h>>1, s>uvlinesize); 
3444  3518 
} 
3445 
//printf("MB %d %d bits\n", s>mb_x+s>mb_y*s>mb_width, get_bit_count(&s>pb));


3519 
//printf("MB %d %d bits\n", s>mb_x+s>mb_y*s>mb_stride, get_bit_count(&s>pb));


3446  3520 
} 
3447  3521 
} 
3448  3522 
emms_c(); 
Also available in: Unified diff