comparison h263.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 b76ab3c968ab
children d6f2520c0c43
comparison
equal deleted inserted replaced
1667:720c073661a1 1668:30746f429df6
524 524
525 if(IS_8X8(colocated_mb_type)){ 525 if(IS_8X8(colocated_mb_type)){
526 s->mv_type = MV_TYPE_8X8; 526 s->mv_type = MV_TYPE_8X8;
527 for(i=0; i<4; i++){ 527 for(i=0; i<4; i++){
528 xy= s->block_index[i]; 528 xy= s->block_index[i];
529 s->mv[0][i][0] = s->motion_val[xy][0]*time_pb/time_pp + mx; 529 s->mv[0][i][0] = s->next_picture.motion_val[0][xy][0]*time_pb/time_pp + mx;
530 s->mv[0][i][1] = s->motion_val[xy][1]*time_pb/time_pp + my; 530 s->mv[0][i][1] = s->next_picture.motion_val[0][xy][1]*time_pb/time_pp + my;
531 s->mv[1][i][0] = mx ? s->mv[0][i][0] - s->motion_val[xy][0] 531 s->mv[1][i][0] = mx ? s->mv[0][i][0] - s->next_picture.motion_val[0][xy][0]
532 : s->motion_val[xy][0]*(time_pb - time_pp)/time_pp; 532 : s->next_picture.motion_val[0][xy][0]*(time_pb - time_pp)/time_pp;
533 s->mv[1][i][1] = my ? s->mv[0][i][1] - s->motion_val[xy][1] 533 s->mv[1][i][1] = my ? s->mv[0][i][1] - s->next_picture.motion_val[0][xy][1]
534 : s->motion_val[xy][1]*(time_pb - time_pp)/time_pp; 534 : s->next_picture.motion_val[0][xy][1]*(time_pb - time_pp)/time_pp;
535 } 535 }
536 return MB_TYPE_DIRECT2 | MB_TYPE_8x8 | MB_TYPE_L0L1; 536 return MB_TYPE_DIRECT2 | MB_TYPE_8x8 | MB_TYPE_L0L1;
537 } else if(IS_INTERLACED(colocated_mb_type)){ 537 } else if(IS_INTERLACED(colocated_mb_type)){
538 s->mv_type = MV_TYPE_FIELD; 538 s->mv_type = MV_TYPE_FIELD;
539 for(i=0; i<2; i++){ 539 for(i=0; i<2; i++){
551 s->mv[1][i][1] = my ? s->mv[0][i][1] - s->field_mv_table[mb_index][i][1] 551 s->mv[1][i][1] = my ? s->mv[0][i][1] - s->field_mv_table[mb_index][i][1]
552 : s->field_mv_table[mb_index][i][1]*(time_pb - time_pp)/time_pp; 552 : s->field_mv_table[mb_index][i][1]*(time_pb - time_pp)/time_pp;
553 } 553 }
554 return MB_TYPE_DIRECT2 | MB_TYPE_16x8 | MB_TYPE_L0L1 | MB_TYPE_INTERLACED; 554 return MB_TYPE_DIRECT2 | MB_TYPE_16x8 | MB_TYPE_L0L1 | MB_TYPE_INTERLACED;
555 }else{ 555 }else{
556 s->mv[0][0][0] = s->mv[0][1][0] = s->mv[0][2][0] = s->mv[0][3][0] = s->motion_val[xy][0]*time_pb/time_pp + mx; 556 s->mv[0][0][0] = s->mv[0][1][0] = s->mv[0][2][0] = s->mv[0][3][0] = s->next_picture.motion_val[0][xy][0]*time_pb/time_pp + mx;
557 s->mv[0][0][1] = s->mv[0][1][1] = s->mv[0][2][1] = s->mv[0][3][1] = s->motion_val[xy][1]*time_pb/time_pp + my; 557 s->mv[0][0][1] = s->mv[0][1][1] = s->mv[0][2][1] = s->mv[0][3][1] = s->next_picture.motion_val[0][xy][1]*time_pb/time_pp + my;
558 s->mv[1][0][0] = s->mv[1][1][0] = s->mv[1][2][0] = s->mv[1][3][0] = mx ? s->mv[0][0][0] - s->motion_val[xy][0] 558 s->mv[1][0][0] = s->mv[1][1][0] = s->mv[1][2][0] = s->mv[1][3][0] = mx ? s->mv[0][0][0] - s->next_picture.motion_val[0][xy][0]
559 : s->motion_val[xy][0]*(time_pb - time_pp)/time_pp; 559 : s->next_picture.motion_val[0][xy][0]*(time_pb - time_pp)/time_pp;
560 s->mv[1][0][1] = s->mv[1][1][1] = s->mv[1][2][1] = s->mv[1][3][1] = my ? s->mv[0][0][1] - s->motion_val[xy][1] 560 s->mv[1][0][1] = s->mv[1][1][1] = s->mv[1][2][1] = s->mv[1][3][1] = my ? s->mv[0][0][1] - s->next_picture.motion_val[0][xy][1]
561 : s->motion_val[xy][1]*(time_pb - time_pp)/time_pp; 561 : s->next_picture.motion_val[0][xy][1]*(time_pb - time_pp)/time_pp;
562 if((s->avctx->workaround_bugs & FF_BUG_DIRECT_BLOCKSIZE) || !s->quarter_sample) 562 if((s->avctx->workaround_bugs & FF_BUG_DIRECT_BLOCKSIZE) || !s->quarter_sample)
563 s->mv_type= MV_TYPE_16X16; 563 s->mv_type= MV_TYPE_16X16;
564 else 564 else
565 s->mv_type= MV_TYPE_8X8; 565 s->mv_type= MV_TYPE_8X8;
566 return MB_TYPE_DIRECT2 | MB_TYPE_16x16 | MB_TYPE_L0L1; //Note see prev line 566 return MB_TYPE_DIRECT2 | MB_TYPE_16x16 | MB_TYPE_L0L1; //Note see prev line
594 s->field_select_table[mb_xy][i]= s->field_select[0][i]; 594 s->field_select_table[mb_xy][i]= s->field_select[0][i];
595 } 595 }
596 } 596 }
597 597
598 /* no update if 8X8 because it has been done during parsing */ 598 /* no update if 8X8 because it has been done during parsing */
599 s->motion_val[xy][0] = motion_x; 599 s->current_picture.motion_val[0][xy][0] = motion_x;
600 s->motion_val[xy][1] = motion_y; 600 s->current_picture.motion_val[0][xy][1] = motion_y;
601 s->motion_val[xy + 1][0] = motion_x; 601 s->current_picture.motion_val[0][xy + 1][0] = motion_x;
602 s->motion_val[xy + 1][1] = motion_y; 602 s->current_picture.motion_val[0][xy + 1][1] = motion_y;
603 s->motion_val[xy + wrap][0] = motion_x; 603 s->current_picture.motion_val[0][xy + wrap][0] = motion_x;
604 s->motion_val[xy + wrap][1] = motion_y; 604 s->current_picture.motion_val[0][xy + wrap][1] = motion_y;
605 s->motion_val[xy + 1 + wrap][0] = motion_x; 605 s->current_picture.motion_val[0][xy + 1 + wrap][0] = motion_x;
606 s->motion_val[xy + 1 + wrap][1] = motion_y; 606 s->current_picture.motion_val[0][xy + 1 + wrap][1] = motion_y;
607 } 607 }
608 608
609 if(s->encoding){ //FIXME encoding MUST be cleaned up 609 if(s->encoding){ //FIXME encoding MUST be cleaned up
610 if (s->mv_type == MV_TYPE_8X8) 610 if (s->mv_type == MV_TYPE_8X8)
611 s->current_picture.mb_type[mb_xy]= MB_TYPE_L0 | MB_TYPE_8x8; 611 s->current_picture.mb_type[mb_xy]= MB_TYPE_L0 | MB_TYPE_8x8;
949 949
950 for(i=0; i<4; i++){ 950 for(i=0; i<4; i++){
951 /* motion vectors: 8x8 mode*/ 951 /* motion vectors: 8x8 mode*/
952 h263_pred_motion(s, i, &pred_x, &pred_y); 952 h263_pred_motion(s, i, &pred_x, &pred_y);
953 953
954 h263_encode_motion(s, s->motion_val[ s->block_index[i] ][0] - pred_x, s->f_code); 954 h263_encode_motion(s, s->current_picture.motion_val[0][ s->block_index[i] ][0] - pred_x, s->f_code);
955 h263_encode_motion(s, s->motion_val[ s->block_index[i] ][1] - pred_y, s->f_code); 955 h263_encode_motion(s, s->current_picture.motion_val[0][ s->block_index[i] ][1] - pred_y, s->f_code);
956 } 956 }
957 } 957 }
958 958
959 if(interleaved_stats){ 959 if(interleaved_stats){
960 s->mv_bits+= get_bits_diff(s); 960 s->mv_bits+= get_bits_diff(s);
1122 1122
1123 for(i=0; i<4; i++){ 1123 for(i=0; i<4; i++){
1124 /* motion vectors: 8x8 mode*/ 1124 /* motion vectors: 8x8 mode*/
1125 h263_pred_motion(s, i, &pred_x, &pred_y); 1125 h263_pred_motion(s, i, &pred_x, &pred_y);
1126 1126
1127 motion_x= s->motion_val[ s->block_index[i] ][0]; 1127 motion_x= s->current_picture.motion_val[0][ s->block_index[i] ][0];
1128 motion_y= s->motion_val[ s->block_index[i] ][1]; 1128 motion_y= s->current_picture.motion_val[0][ s->block_index[i] ][1];
1129 if (!s->umvplus) { 1129 if (!s->umvplus) {
1130 h263_encode_motion(s, motion_x - pred_x, 1); 1130 h263_encode_motion(s, motion_x - pred_x, 1);
1131 h263_encode_motion(s, motion_y - pred_y, 1); 1131 h263_encode_motion(s, motion_y - pred_y, 1);
1132 } 1132 }
1133 else { 1133 else {
1478 static const int off[4]= {2, 1, 1, -1}; 1478 static const int off[4]= {2, 1, 1, -1};
1479 1479
1480 wrap = s->block_wrap[0]; 1480 wrap = s->block_wrap[0];
1481 xy = s->block_index[block]; 1481 xy = s->block_index[block];
1482 1482
1483 mot_val = s->motion_val[xy]; 1483 mot_val = s->current_picture.motion_val[0][xy];
1484 1484
1485 A = s->motion_val[xy - 1]; 1485 A = s->current_picture.motion_val[0][xy - 1];
1486 /* special case for first (slice) line */ 1486 /* special case for first (slice) line */
1487 if (s->first_slice_line && block<3) { 1487 if (s->first_slice_line && block<3) {
1488 // we cant just change some MVs to simulate that as we need them for the B frames (and ME) 1488 // we cant just change some MVs to simulate that as we need them for the B frames (and ME)
1489 // and if we ever support non rectangular objects than we need to do a few ifs here anyway :( 1489 // and if we ever support non rectangular objects than we need to do a few ifs here anyway :(
1490 if(block==0){ //most common case 1490 if(block==0){ //most common case
1491 if(s->mb_x == s->resync_mb_x){ //rare 1491 if(s->mb_x == s->resync_mb_x){ //rare
1492 *px= *py = 0; 1492 *px= *py = 0;
1493 }else if(s->mb_x + 1 == s->resync_mb_x && s->h263_pred){ //rare 1493 }else if(s->mb_x + 1 == s->resync_mb_x && s->h263_pred){ //rare
1494 C = s->motion_val[xy + off[block] - wrap]; 1494 C = s->current_picture.motion_val[0][xy + off[block] - wrap];
1495 if(s->mb_x==0){ 1495 if(s->mb_x==0){
1496 *px = C[0]; 1496 *px = C[0];
1497 *py = C[1]; 1497 *py = C[1];
1498 }else{ 1498 }else{
1499 *px = mid_pred(A[0], 0, C[0]); 1499 *px = mid_pred(A[0], 0, C[0]);
1503 *px = A[0]; 1503 *px = A[0];
1504 *py = A[1]; 1504 *py = A[1];
1505 } 1505 }
1506 }else if(block==1){ 1506 }else if(block==1){
1507 if(s->mb_x + 1 == s->resync_mb_x && s->h263_pred){ //rare 1507 if(s->mb_x + 1 == s->resync_mb_x && s->h263_pred){ //rare
1508 C = s->motion_val[xy + off[block] - wrap]; 1508 C = s->current_picture.motion_val[0][xy + off[block] - wrap];
1509 *px = mid_pred(A[0], 0, C[0]); 1509 *px = mid_pred(A[0], 0, C[0]);
1510 *py = mid_pred(A[1], 0, C[1]); 1510 *py = mid_pred(A[1], 0, C[1]);
1511 }else{ 1511 }else{
1512 *px = A[0]; 1512 *px = A[0];
1513 *py = A[1]; 1513 *py = A[1];
1514 } 1514 }
1515 }else{ /* block==2*/ 1515 }else{ /* block==2*/
1516 B = s->motion_val[xy - wrap]; 1516 B = s->current_picture.motion_val[0][xy - wrap];
1517 C = s->motion_val[xy + off[block] - wrap]; 1517 C = s->current_picture.motion_val[0][xy + off[block] - wrap];
1518 if(s->mb_x == s->resync_mb_x) //rare 1518 if(s->mb_x == s->resync_mb_x) //rare
1519 A[0]=A[1]=0; 1519 A[0]=A[1]=0;
1520 1520
1521 *px = mid_pred(A[0], B[0], C[0]); 1521 *px = mid_pred(A[0], B[0], C[0]);
1522 *py = mid_pred(A[1], B[1], C[1]); 1522 *py = mid_pred(A[1], B[1], C[1]);
1523 } 1523 }
1524 } else { 1524 } else {
1525 B = s->motion_val[xy - wrap]; 1525 B = s->current_picture.motion_val[0][xy - wrap];
1526 C = s->motion_val[xy + off[block] - wrap]; 1526 C = s->current_picture.motion_val[0][xy + off[block] - wrap];
1527 *px = mid_pred(A[0], B[0], C[0]); 1527 *px = mid_pred(A[0], B[0], C[0]);
1528 *py = mid_pred(A[1], B[1], C[1]); 1528 *py = mid_pred(A[1], B[1], C[1]);
1529 } 1529 }
1530 return mot_val; 1530 return mot_val;
1531 } 1531 }
1539 static const int off[4]= {2, 1, 1, -1}; 1539 static const int off[4]= {2, 1, 1, -1};
1540 1540
1541 wrap = s->b8_stride; 1541 wrap = s->b8_stride;
1542 xy = s->mb_x + s->mb_y * wrap; 1542 xy = s->mb_x + s->mb_y * wrap;
1543 1543
1544 mot_val = s->current_picture.motion_val[dir] + xy; 1544 mot_val = s->current_picture.motion_val[0][dir] + xy;
1545 1545
1546 A = mot_val[ - 1]; 1546 A = mot_val[ - 1];
1547 /* special case for first (slice) line */ 1547 /* special case for first (slice) line */
1548 if (s->first_slice_line && block<3) { 1548 if (s->first_slice_line && block<3) {
1549 // we cant just change some MVs to simulate that as we need them for the B frames (and ME) 1549 // we cant just change some MVs to simulate that as we need them for the B frames (and ME)
3269 if(dc_pred_dir) dir|=1; 3269 if(dc_pred_dir) dir|=1;
3270 } 3270 }
3271 s->pred_dir_table[xy]= dir; 3271 s->pred_dir_table[xy]= dir;
3272 }else{ /* P/S_TYPE */ 3272 }else{ /* P/S_TYPE */
3273 int mx, my, pred_x, pred_y, bits; 3273 int mx, my, pred_x, pred_y, bits;
3274 int16_t * const mot_val= s->motion_val[s->block_index[0]]; 3274 int16_t * const mot_val= s->current_picture.motion_val[0][s->block_index[0]];
3275 const int stride= s->block_wrap[0]*2; 3275 const int stride= s->block_wrap[0]*2;
3276 3276
3277 // do{ //FIXME 3277 // do{ //FIXME
3278 bits= show_bits(&s->gb, 17); 3278 bits= show_bits(&s->gb, 17);
3279 if(bits==MOTION_MARKER){ 3279 if(bits==MOTION_MARKER){
3527 } 3527 }
3528 3528
3529 if (s->pict_type == P_TYPE || s->pict_type==S_TYPE) { 3529 if (s->pict_type == P_TYPE || s->pict_type==S_TYPE) {
3530 int i; 3530 int i;
3531 for(i=0; i<4; i++){ 3531 for(i=0; i<4; i++){
3532 s->mv[0][i][0] = s->motion_val[ s->block_index[i] ][0]; 3532 s->mv[0][i][0] = s->current_picture.motion_val[0][ s->block_index[i] ][0];
3533 s->mv[0][i][1] = s->motion_val[ s->block_index[i] ][1]; 3533 s->mv[0][i][1] = s->current_picture.motion_val[0][ s->block_index[i] ][1];
3534 } 3534 }
3535 s->mb_intra = IS_INTRA(mb_type); 3535 s->mb_intra = IS_INTRA(mb_type);
3536 3536
3537 if (IS_SKIP(mb_type)) { 3537 if (IS_SKIP(mb_type)) {
3538 /* skip mb */ 3538 /* skip mb */
3614 assert(s->pict_type == P_TYPE); 3614 assert(s->pict_type == P_TYPE);
3615 3615
3616 do{ 3616 do{
3617 if (get_bits1(&s->gb)) { 3617 if (get_bits1(&s->gb)) {
3618 /* skip mb */ 3618 /* skip mb */
3619 mot_val = s->motion_val[ s->block_index[0] ]; 3619 mot_val = s->current_picture.motion_val[0][ s->block_index[0] ];
3620 mot_val[0 ]= mot_val[2 ]= 3620 mot_val[0 ]= mot_val[2 ]=
3621 mot_val[0+stride]= mot_val[2+stride]= 0; 3621 mot_val[0+stride]= mot_val[2+stride]= 0;
3622 mot_val[1 ]= mot_val[3 ]= 3622 mot_val[1 ]= mot_val[3 ]=
3623 mot_val[1+stride]= mot_val[3+stride]= 0; 3623 mot_val[1+stride]= mot_val[3+stride]= 0;
3624 3624