comparison mpegvideo.c @ 1668:30746f429df6 libavcodec

move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>) cleanups & fixes by me
author michael
date Tue, 09 Dec 2003 01:49:56 +0000
parents 64c370fe6e88
children 072666f04bca
comparison
equal deleted inserted replaced
1667:720c073661a1 1668:30746f429df6
314 for(i=0; i<2; i++){ 314 for(i=0; i<2; i++){
315 CHECKED_ALLOCZ(pic->motion_val_base[i], 2 * (b4_array_size+1) * sizeof(uint16_t)) 315 CHECKED_ALLOCZ(pic->motion_val_base[i], 2 * (b4_array_size+1) * sizeof(uint16_t))
316 pic->motion_val[i]= pic->motion_val_base[i]+1; 316 pic->motion_val[i]= pic->motion_val_base[i]+1;
317 CHECKED_ALLOCZ(pic->ref_index[i] , b8_array_size * sizeof(uint8_t)) 317 CHECKED_ALLOCZ(pic->ref_index[i] , b8_array_size * sizeof(uint8_t))
318 } 318 }
319 }else if(s->out_format == FMT_H263){ 319 }else if(s->out_format == FMT_H263 || s->encoding || (s->avctx->debug&(FF_DEBUG_VIS_MV|FF_DEBUG_MV))){
320 for(i=0; i<2; i++){ 320 for(i=0; i<2; i++){
321 CHECKED_ALLOCZ(pic->motion_val_base[i], 2 * (b8_array_size+1) * sizeof(uint16_t)) 321 CHECKED_ALLOCZ(pic->motion_val_base[i], 2 * (b8_array_size+1) * sizeof(uint16_t)*2) //FIXME
322 pic->motion_val[i]= pic->motion_val_base[i]+1; 322 pic->motion_val[i]= pic->motion_val_base[i]+1;
323 } 323 }
324 } 324 }
325 pic->qstride= s->mb_stride; 325 pic->qstride= s->mb_stride;
326 CHECKED_ALLOCZ(pic->pan_scan , 1 * sizeof(AVPanScan)) 326 CHECKED_ALLOCZ(pic->pan_scan , 1 * sizeof(AVPanScan))
487 487
488 CHECKED_ALLOCZ(s->picture, MAX_PICTURE_COUNT * sizeof(Picture)) 488 CHECKED_ALLOCZ(s->picture, MAX_PICTURE_COUNT * sizeof(Picture))
489 489
490 CHECKED_ALLOCZ(s->error_status_table, mb_array_size*sizeof(uint8_t)) 490 CHECKED_ALLOCZ(s->error_status_table, mb_array_size*sizeof(uint8_t))
491 491
492 if (s->out_format == FMT_H263 || s->encoding || (s->avctx->debug&FF_DEBUG_VIS_MV)) {
493 int size;
494
495 /* MV prediction */
496 size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2);
497 CHECKED_ALLOCZ(s->motion_val, size * 2 * sizeof(int16_t));
498 }
499
500 if(s->codec_id==CODEC_ID_MPEG4){ 492 if(s->codec_id==CODEC_ID_MPEG4){
501 /* interlaced direct mode decoding tables */ 493 /* interlaced direct mode decoding tables */
502 CHECKED_ALLOCZ(s->field_mv_table, mb_array_size*2*2 * sizeof(int16_t)) 494 CHECKED_ALLOCZ(s->field_mv_table, mb_array_size*2*2 * sizeof(int16_t))
503 CHECKED_ALLOCZ(s->field_select_table, mb_array_size*2* sizeof(int8_t)) 495 CHECKED_ALLOCZ(s->field_select_table, mb_array_size*2* sizeof(int8_t))
504 } 496 }
579 s->b_back_mv_table= NULL; 571 s->b_back_mv_table= NULL;
580 s->b_bidir_forw_mv_table= NULL; 572 s->b_bidir_forw_mv_table= NULL;
581 s->b_bidir_back_mv_table= NULL; 573 s->b_bidir_back_mv_table= NULL;
582 s->b_direct_mv_table= NULL; 574 s->b_direct_mv_table= NULL;
583 575
584 av_freep(&s->motion_val);
585 av_freep(&s->dc_val[0]); 576 av_freep(&s->dc_val[0]);
586 av_freep(&s->ac_val[0]); 577 av_freep(&s->ac_val[0]);
587 av_freep(&s->coded_block); 578 av_freep(&s->coded_block);
588 av_freep(&s->mbintra_table); 579 av_freep(&s->mbintra_table);
589 av_freep(&s->cbp_table); 580 av_freep(&s->cbp_table);
1415 // av_log(s->avctx, AV_LOG_DEBUG, " "); 1406 // av_log(s->avctx, AV_LOG_DEBUG, " ");
1416 } 1407 }
1417 av_log(s->avctx, AV_LOG_DEBUG, "\n"); 1408 av_log(s->avctx, AV_LOG_DEBUG, "\n");
1418 } 1409 }
1419 } 1410 }
1420 1411
1421 if((s->avctx->debug&FF_DEBUG_VIS_MV) && s->motion_val){ 1412 if((s->avctx->debug&FF_DEBUG_VIS_MV) && pict->motion_val){
1422 const int shift= 1 + s->quarter_sample; 1413 const int shift= 1 + s->quarter_sample;
1423 int mb_y; 1414 int mb_y;
1424 uint8_t *ptr= pict->data[0]; 1415 uint8_t *ptr= pict->data[0];
1425 s->low_delay=0; //needed to see the vectors without trashing the buffers 1416 s->low_delay=0; //needed to see the vectors without trashing the buffers
1426 1417
1427 for(mb_y=0; mb_y<s->mb_height; mb_y++){ 1418 for(mb_y=0; mb_y<s->mb_height; mb_y++){
1428 int mb_x; 1419 int mb_x;
1429 for(mb_x=0; mb_x<s->mb_width; mb_x++){ 1420 for(mb_x=0; mb_x<s->mb_width; mb_x++){
1430 const int mb_index= mb_x + mb_y*s->mb_stride; 1421 const int mb_index= mb_x + mb_y*s->mb_stride;
1431 if(IS_8X8(s->current_picture.mb_type[mb_index])){ 1422 if(IS_8X8(pict->mb_type[mb_index])){
1432 int i; 1423 int i;
1433 for(i=0; i<4; i++){ 1424 for(i=0; i<4; i++){
1434 int sx= mb_x*16 + 4 + 8*(i&1); 1425 int sx= mb_x*16 + 4 + 8*(i&1);
1435 int sy= mb_y*16 + 4 + 8*(i>>1); 1426 int sy= mb_y*16 + 4 + 8*(i>>1);
1436 int xy= 1 + mb_x*2 + (i&1) + (mb_y*2 + 1 + (i>>1))*(s->mb_width*2 + 2); 1427 int xy= 1 + mb_x*2 + (i&1) + (mb_y*2 + 1 + (i>>1))*(s->mb_width*2 + 2);
1437 int mx= (s->motion_val[xy][0]>>shift) + sx; 1428 int mx= (pict->motion_val[0][xy][0]>>shift) + sx;
1438 int my= (s->motion_val[xy][1]>>shift) + sy; 1429 int my= (pict->motion_val[0][xy][1]>>shift) + sy;
1439 draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100); 1430 draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100);
1440 } 1431 }
1441 }else if(IS_16X8(s->current_picture.mb_type[mb_index])){ 1432 }else if(IS_16X8(pict->mb_type[mb_index])){
1442 int i; 1433 int i;
1443 for(i=0; i<2; i++){ 1434 for(i=0; i<2; i++){
1444 int sx=mb_x*16 + 8; 1435 int sx=mb_x*16 + 8;
1445 int sy=mb_y*16 + 4 + 8*i; 1436 int sy=mb_y*16 + 4 + 8*i;
1446 int xy=1 + mb_x*2 + (mb_y*2 + 1 + i)*(s->mb_width*2 + 2); 1437 int xy=1 + mb_x*2 + (mb_y*2 + 1 + i)*(s->mb_width*2 + 2);
1447 int mx=(s->motion_val[xy][0]>>shift) + sx; 1438 int mx=(pict->motion_val[0][xy][0]>>shift) + sx;
1448 int my=(s->motion_val[xy][1]>>shift) + sy; 1439 int my=(pict->motion_val[0][xy][1]>>shift) + sy;
1449 draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100); 1440 draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100);
1450 } 1441 }
1451 }else{ 1442 }else{
1452 int sx= mb_x*16 + 8; 1443 int sx= mb_x*16 + 8;
1453 int sy= mb_y*16 + 8; 1444 int sy= mb_y*16 + 8;
1454 int xy= 1 + mb_x*2 + (mb_y*2 + 1)*(s->mb_width*2 + 2); 1445 int xy= 1 + mb_x*2 + (mb_y*2 + 1)*(s->mb_width*2 + 2);
1455 int mx= (s->motion_val[xy][0]>>shift) + sx; 1446 int mx= (pict->motion_val[0][xy][0]>>shift) + sx;
1456 int my= (s->motion_val[xy][1]>>shift) + sy; 1447 int my= (pict->motion_val[0][xy][1]>>shift) + sy;
1457 draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100); 1448 draw_arrow(ptr, sx, sy, mx, my, s->width, s->height, s->linesize, 100);
1458 } 1449 }
1459 s->mbskip_table[mb_index]=0; 1450 s->mbskip_table[mb_index]=0;
1460 } 1451 }
1461 } 1452 }
2381 const int mot_stride= s->mb_width*2 + 2; 2372 const int mot_stride= s->mb_width*2 + 2;
2382 const int mot_xy= 1 + mb_x*2 + (mb_y*2 + 1)*mot_stride; 2373 const int mot_xy= 1 + mb_x*2 + (mb_y*2 + 1)*mot_stride;
2383 2374
2384 assert(!s->mb_skiped); 2375 assert(!s->mb_skiped);
2385 2376
2386 memcpy(mv_cache[1][1], s->motion_val[mot_xy ], sizeof(int16_t)*4); 2377 memcpy(mv_cache[1][1], s->current_picture.motion_val[0][mot_xy ], sizeof(int16_t)*4);
2387 memcpy(mv_cache[2][1], s->motion_val[mot_xy+mot_stride], sizeof(int16_t)*4); 2378 memcpy(mv_cache[2][1], s->current_picture.motion_val[0][mot_xy+mot_stride], sizeof(int16_t)*4);
2388 memcpy(mv_cache[3][1], s->motion_val[mot_xy+mot_stride], sizeof(int16_t)*4); 2379 memcpy(mv_cache[3][1], s->current_picture.motion_val[0][mot_xy+mot_stride], sizeof(int16_t)*4);
2389 2380
2390 if(mb_y==0 || IS_INTRA(s->current_picture.mb_type[xy-s->mb_stride])){ 2381 if(mb_y==0 || IS_INTRA(s->current_picture.mb_type[xy-s->mb_stride])){
2391 memcpy(mv_cache[0][1], mv_cache[1][1], sizeof(int16_t)*4); 2382 memcpy(mv_cache[0][1], mv_cache[1][1], sizeof(int16_t)*4);
2392 }else{ 2383 }else{
2393 memcpy(mv_cache[0][1], s->motion_val[mot_xy-mot_stride], sizeof(int16_t)*4); 2384 memcpy(mv_cache[0][1], s->current_picture.motion_val[0][mot_xy-mot_stride], sizeof(int16_t)*4);
2394 } 2385 }
2395 2386
2396 if(mb_x==0 || IS_INTRA(s->current_picture.mb_type[xy-1])){ 2387 if(mb_x==0 || IS_INTRA(s->current_picture.mb_type[xy-1])){
2397 *(int32_t*)mv_cache[1][0]= *(int32_t*)mv_cache[1][1]; 2388 *(int32_t*)mv_cache[1][0]= *(int32_t*)mv_cache[1][1];
2398 *(int32_t*)mv_cache[2][0]= *(int32_t*)mv_cache[2][1]; 2389 *(int32_t*)mv_cache[2][0]= *(int32_t*)mv_cache[2][1];
2399 }else{ 2390 }else{
2400 *(int32_t*)mv_cache[1][0]= *(int32_t*)s->motion_val[mot_xy-1]; 2391 *(int32_t*)mv_cache[1][0]= *(int32_t*)s->current_picture.motion_val[0][mot_xy-1];
2401 *(int32_t*)mv_cache[2][0]= *(int32_t*)s->motion_val[mot_xy-1+mot_stride]; 2392 *(int32_t*)mv_cache[2][0]= *(int32_t*)s->current_picture.motion_val[0][mot_xy-1+mot_stride];
2402 } 2393 }
2403 2394
2404 if(mb_x+1>=s->mb_width || IS_INTRA(s->current_picture.mb_type[xy+1])){ 2395 if(mb_x+1>=s->mb_width || IS_INTRA(s->current_picture.mb_type[xy+1])){
2405 *(int32_t*)mv_cache[1][3]= *(int32_t*)mv_cache[1][2]; 2396 *(int32_t*)mv_cache[1][3]= *(int32_t*)mv_cache[1][2];
2406 *(int32_t*)mv_cache[2][3]= *(int32_t*)mv_cache[2][2]; 2397 *(int32_t*)mv_cache[2][3]= *(int32_t*)mv_cache[2][2];
2407 }else{ 2398 }else{
2408 *(int32_t*)mv_cache[1][3]= *(int32_t*)s->motion_val[mot_xy+2]; 2399 *(int32_t*)mv_cache[1][3]= *(int32_t*)s->current_picture.motion_val[0][mot_xy+2];
2409 *(int32_t*)mv_cache[2][3]= *(int32_t*)s->motion_val[mot_xy+2+mot_stride]; 2400 *(int32_t*)mv_cache[2][3]= *(int32_t*)s->current_picture.motion_val[0][mot_xy+2+mot_stride];
2410 } 2401 }
2411 2402
2412 mx = 0; 2403 mx = 0;
2413 my = 0; 2404 my = 0;
2414 for(i=0;i<4;i++) { 2405 for(i=0;i<4;i++) {
3692 } 3683 }
3693 } 3684 }
3694 }else /* if(s->pict_type == I_TYPE) */{ 3685 }else /* if(s->pict_type == I_TYPE) */{
3695 /* I-Frame */ 3686 /* I-Frame */
3696 //FIXME do we need to zero them? 3687 //FIXME do we need to zero them?
3697 memset(s->motion_val[0], 0, sizeof(int16_t)*(s->mb_width*2 + 2)*(s->mb_height*2 + 2)*2); 3688 memset(s->current_picture.motion_val[0][0], 0, sizeof(int16_t)*(s->mb_width*2 + 2)*(s->mb_height*2 + 2)*2);
3698 memset(s->p_mv_table , 0, sizeof(int16_t)*(s->mb_stride)*s->mb_height*2); 3689 memset(s->p_mv_table , 0, sizeof(int16_t)*(s->mb_stride)*s->mb_height*2);
3699 memset(s->mb_type , MB_TYPE_INTRA, sizeof(uint8_t)*s->mb_stride*s->mb_height); 3690 memset(s->mb_type , MB_TYPE_INTRA, sizeof(uint8_t)*s->mb_stride*s->mb_height);
3700 3691
3701 if(!s->fixed_qscale){ 3692 if(!s->fixed_qscale){
3702 /* finding spatial complexity for I-frame rate control */ 3693 /* finding spatial complexity for I-frame rate control */
3996 if(mb_type&MB_TYPE_INTER4V){ 3987 if(mb_type&MB_TYPE_INTER4V){
3997 s->mv_dir = MV_DIR_FORWARD; 3988 s->mv_dir = MV_DIR_FORWARD;
3998 s->mv_type = MV_TYPE_8X8; 3989 s->mv_type = MV_TYPE_8X8;
3999 s->mb_intra= 0; 3990 s->mb_intra= 0;
4000 for(i=0; i<4; i++){ 3991 for(i=0; i<4; i++){
4001 s->mv[0][i][0] = s->motion_val[s->block_index[i]][0]; 3992 s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0];
4002 s->mv[0][i][1] = s->motion_val[s->block_index[i]][1]; 3993 s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1];
4003 } 3994 }
4004 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_INTER4V, pb, pb2, tex_pb, 3995 encode_mb_hq(s, &backup_s, &best_s, MB_TYPE_INTER4V, pb, pb2, tex_pb,
4005 &dmin, &next_block, 0, 0); 3996 &dmin, &next_block, 0, 0);
4006 } 3997 }
4007 if(mb_type&MB_TYPE_FORWARD){ 3998 if(mb_type&MB_TYPE_FORWARD){
4168 case MB_TYPE_INTER4V: 4159 case MB_TYPE_INTER4V:
4169 s->mv_dir = MV_DIR_FORWARD; 4160 s->mv_dir = MV_DIR_FORWARD;
4170 s->mv_type = MV_TYPE_8X8; 4161 s->mv_type = MV_TYPE_8X8;
4171 s->mb_intra= 0; 4162 s->mb_intra= 0;
4172 for(i=0; i<4; i++){ 4163 for(i=0; i<4; i++){
4173 s->mv[0][i][0] = s->motion_val[s->block_index[i]][0]; 4164 s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0];
4174 s->mv[0][i][1] = s->motion_val[s->block_index[i]][1]; 4165 s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1];
4175 } 4166 }
4176 motion_x= motion_y= 0; 4167 motion_x= motion_y= 0;
4177 break; 4168 break;
4178 case MB_TYPE_DIRECT: 4169 case MB_TYPE_DIRECT:
4179 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; 4170 s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT;