Revision 1f0cd30f libavcodec/mpegvideo.c
libavcodec/mpegvideo.c  

1393  1393  
1394  1394 
static void copy_bits(PutBitContext *pb, UINT8 *src, int length) 
1395  1395 
{ 
1396 
#if 1 

1397 
int bytes= length>>4; 

1398 
int bits= length&15; 

1399 
int i; 

1400  
1401 
for(i=0; i<bytes; i++) put_bits(pb, 16, be2me_16(((uint16_t*)src)[i])); 

1402 
put_bits(pb, bits, be2me_16(((uint16_t*)src)[i])>>(16bits)); 

1403 
#else 

1396  1404 
int bytes= length>>3; 
1397  1405 
int bits= length&7; 
1398  1406 
int i; 
1399  1407  
1400  1408 
for(i=0; i<bytes; i++) put_bits(pb, 8, src[i]); 
1401  1409 
put_bits(pb, bits, src[i]>>(8bits)); 
1410 
#endif 

1402  1411 
} 
1403  1412  
1413 
static void copy_context_before_encode(MpegEncContext *d, MpegEncContext *s, int type){ 

1414 
int i; 

1415  
1416 
memcpy(d>last_mv, s>last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster then a loop? 

1417  
1418 
/* mpeg1 */ 

1419 
d>mb_incr= s>mb_incr; 

1420 
for(i=0; i<3; i++) 

1421 
d>last_dc[i]= s>last_dc[i]; 

1422 


1423 
/* statistics */ 

1424 
d>mv_bits= s>mv_bits; 

1425 
d>i_tex_bits= s>i_tex_bits; 

1426 
d>p_tex_bits= s>p_tex_bits; 

1427 
d>i_count= s>i_count; 

1428 
d>p_count= s>p_count; 

1429 
d>skip_count= s>skip_count; 

1430 
d>misc_bits= s>misc_bits; 

1431 
d>last_bits= s>last_bits; 

1432 
} 

1433  
1434 
static void copy_context_after_encode(MpegEncContext *d, MpegEncContext *s, int type){ 

1435 
int i; 

1436  
1437 
memcpy(d>mv, s>mv, 2*4*2*sizeof(int)); 

1438 
memcpy(d>last_mv, s>last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster then a loop? 

1439 


1440 
/* mpeg1 */ 

1441 
d>mb_incr= s>mb_incr; 

1442 
for(i=0; i<3; i++) 

1443 
d>last_dc[i]= s>last_dc[i]; 

1444 


1445 
/* statistics */ 

1446 
d>mv_bits= s>mv_bits; 

1447 
d>i_tex_bits= s>i_tex_bits; 

1448 
d>p_tex_bits= s>p_tex_bits; 

1449 
d>i_count= s>i_count; 

1450 
d>p_count= s>p_count; 

1451 
d>skip_count= s>skip_count; 

1452 
d>misc_bits= s>misc_bits; 

1453 
d>last_bits= s>last_bits; 

1454  
1455 
d>mb_intra= s>mb_intra; 

1456 
d>mv_type= s>mv_type; 

1457 
d>mv_dir= s>mv_dir; 

1458 
d>pb= s>pb; 

1459 
d>block= s>block; 

1460 
for(i=0; i<6; i++) 

1461 
d>block_last_index[i]= s>block_last_index[i]; 

1462 
} 

1463  
1464  
1404  1465 
static void encode_picture(MpegEncContext *s, int picture_number) 
1405  1466 
{ 
1406  1467 
int mb_x, mb_y, last_gob, pdif = 0; 
1407  1468 
int i; 
1408  1469 
int bits; 
1409 
MpegEncContext best_s; 

1470 
MpegEncContext best_s, backup_s;


1410  1471 
UINT8 bit_buf[4][3000]; //FIXME check that this is ALLWAYS large enogh for a MB 
1411  1472  
1412  1473 
s>picture_number = picture_number; 
...  ...  
1585  1646 
s>block_index[3]+=2; 
1586  1647 
s>block_index[4]++; 
1587  1648 
s>block_index[5]++; 
1588  
1589  1649 
if(mb_type & (mb_type1)){ // more than 1 MB type possible 
1590  1650 
pb= s>pb; 
1591  1651 
s>mv_dir = MV_DIR_FORWARD; 
1652  
1653 
copy_context_before_encode(&backup_s, s, 1); 

1654  
1592  1655 
if(mb_type&MB_TYPE_INTER){ 
1593  1656 
int xy= (mb_y+1) * (s>mb_width+2) + mb_x + 1; 
1594  1657 
s>mv_type = MV_TYPE_16X16; 
...  ...  
1603  1666 
if(d<dmin){ 
1604  1667 
flush_put_bits(&s>pb); 
1605  1668 
dmin=d; 
1606 
best_s.mv[0][0][0]= s>mv[0][0][0]; 

1607 
best_s.mv[0][0][1]= s>mv[0][0][1]; 

1608 
best_s.mb_intra= 0; 

1609 
best_s.mv_type = MV_TYPE_16X16; 

1610 
best_s.pb=s>pb; 

1611 
best_s.block= s>block; 

1669 
copy_context_after_encode(&best_s, s, MB_TYPE_INTER); 

1612  1670 
best=1; 
1613 
for(i=0; i<6; i++) 

1614 
best_s.block_last_index[i]= s>block_last_index[i]; 

1615  1671 
} 
1616  1672 
} 
1617 
if(mb_type&MB_TYPE_INTER4V){ 

1673 
if(mb_type&MB_TYPE_INTER4V){ 

1674 
copy_context_before_encode(s, &backup_s, MB_TYPE_INTER4V); 

1618  1675 
s>mv_type = MV_TYPE_8X8; 
1619  1676 
s>mb_intra= 0; 
1620  1677 
for(i=0; i<4; i++){ 
...  ...  
1629  1686 
if(d<dmin && 0){ 
1630  1687 
flush_put_bits(&s>pb); 
1631  1688 
dmin=d; 
1632 
for(i=0; i<4; i++){ 

1633 
best_s.mv[0][i][0] = s>mv[0][i][0]; 

1634 
best_s.mv[0][i][1] = s>mv[0][i][1]; 

1635 
} 

1636 
best_s.mb_intra= 0; 

1637 
best_s.mv_type = MV_TYPE_8X8; 

1638 
best_s.pb=s>pb; 

1639 
best_s.block= s>block; 

1689 
copy_context_after_encode(&best_s, s, MB_TYPE_INTER4V); 

1640  1690 
best=2; 
1641 
for(i=0; i<6; i++) 

1642 
best_s.block_last_index[i]= s>block_last_index[i]; 

1643  1691 
} 
1644  1692 
} 
1645  1693 
if(mb_type&MB_TYPE_INTRA){ 
1694 
copy_context_before_encode(s, &backup_s, MB_TYPE_INTRA); 

1646  1695 
s>mv_type = MV_TYPE_16X16; 
1647  1696 
s>mb_intra= 1; 
1648  1697 
s>mv[0][0][0] = 0; 
...  ...  
1655  1704 
if(d<dmin){ 
1656  1705 
flush_put_bits(&s>pb); 
1657  1706 
dmin=d; 
1658 
best_s.mv[0][0][0]= 0; 

1659 
best_s.mv[0][0][1]= 0; 

1660 
best_s.mb_intra= 1; 

1661 
best_s.mv_type = MV_TYPE_16X16; 

1662 
best_s.pb=s>pb; 

1663 
best_s.block= s>block; 

1664 
for(i=0; i<6; i++) 

1665 
best_s.block_last_index[i]= s>block_last_index[i]; 

1707 
copy_context_after_encode(&best_s, s, MB_TYPE_INTRA); 

1666  1708 
best=0; 
1667  1709 
} 
1668 
/* force cleaning of ac/dc if needed ... */ 

1669 
s>mbintra_table[mb_x + mb_y*s>mb_width]=1; 

1670 
} 

1671 
for(i=0; i<4; i++){ 

1672 
s>mv[0][i][0] = best_s.mv[0][i][0]; 

1673 
s>mv[0][i][1] = best_s.mv[0][i][1]; 

1710 
/* force cleaning of ac/dc pred stuff if needed ... */ 

1711 
if(s>h263_pred  s>h263_aic) 

1712 
s>mbintra_table[mb_x + mb_y*s>mb_width]=1; 

1674  1713 
} 
1675 
s>mb_intra= best_s.mb_intra; 

1676 
s>mv_type= best_s.mv_type; 

1677 
for(i=0; i<6; i++) 

1678 
s>block_last_index[i]= best_s.block_last_index[i]; 

1714 
copy_context_after_encode(s, &best_s, 1); 

1679  1715 
copy_bits(&pb, bit_buf[best], dmin); 
1680 
s>block= best_s.block; 

1681  1716 
s>pb= pb; 
1682  1717 
} else { 
1683  1718 
int motion_x, motion_y; 
Also available in: Unified diff