Mercurial > libavcodec.hg
comparison h263.c @ 903:22ee74da2cd3 libavcodec
cleanup
adding AVVideoFrame
moving quality, pict_type, key_frame, qscale_table, ... to AVVideoFrame
removing obsolete variables in AVCodecContext
skiping of MBs in b frames
correctly initalizing AVCodecContext
picture buffer cleanup
| author | michaelni |
|---|---|
| date | Wed, 04 Dec 2002 10:04:03 +0000 |
| parents | 550033bc7e2d |
| children | 2b93dc762f9a |
comparison
equal
deleted
inserted
replaced
| 902:6acc8394960d | 903:22ee74da2cd3 |
|---|---|
| 270 | 270 |
| 271 static inline int decide_ac_pred(MpegEncContext * s, DCTELEM block[6][64], int dir[6]) | 271 static inline int decide_ac_pred(MpegEncContext * s, DCTELEM block[6][64], int dir[6]) |
| 272 { | 272 { |
| 273 int score0=0, score1=0; | 273 int score0=0, score1=0; |
| 274 int i, n; | 274 int i, n; |
| 275 int8_t * const qscale_table= s->current_picture.qscale_table; | |
| 275 | 276 |
| 276 for(n=0; n<6; n++){ | 277 for(n=0; n<6; n++){ |
| 277 INT16 *ac_val, *ac_val1; | 278 INT16 *ac_val, *ac_val1; |
| 278 | 279 |
| 279 ac_val = s->ac_val[0][0] + s->block_index[n] * 16; | 280 ac_val = s->ac_val[0][0] + s->block_index[n] * 16; |
| 280 ac_val1= ac_val; | 281 ac_val1= ac_val; |
| 281 if(dir[n]){ | 282 if(dir[n]){ |
| 282 const int xy= s->mb_x + s->mb_y*s->mb_width - s->mb_width; | 283 const int xy= s->mb_x + s->mb_y*s->mb_width - s->mb_width; |
| 283 /* top prediction */ | 284 /* top prediction */ |
| 284 ac_val-= s->block_wrap[n]*16; | 285 ac_val-= s->block_wrap[n]*16; |
| 285 if(s->mb_y==0 || s->qscale == s->qscale_table[xy] || n==2 || n==3){ | 286 if(s->mb_y==0 || s->qscale == qscale_table[xy] || n==2 || n==3){ |
| 286 /* same qscale */ | 287 /* same qscale */ |
| 287 for(i=1; i<8; i++){ | 288 for(i=1; i<8; i++){ |
| 288 const int level= block[n][s->idct_permutation[i ]]; | 289 const int level= block[n][s->idct_permutation[i ]]; |
| 289 score0+= ABS(level); | 290 score0+= ABS(level); |
| 290 score1+= ABS(level - ac_val[i+8]); | 291 score1+= ABS(level - ac_val[i+8]); |
| 294 }else{ | 295 }else{ |
| 295 /* different qscale, we must rescale */ | 296 /* different qscale, we must rescale */ |
| 296 for(i=1; i<8; i++){ | 297 for(i=1; i<8; i++){ |
| 297 const int level= block[n][s->idct_permutation[i ]]; | 298 const int level= block[n][s->idct_permutation[i ]]; |
| 298 score0+= ABS(level); | 299 score0+= ABS(level); |
| 299 score1+= ABS(level - ROUNDED_DIV(ac_val[i + 8]*s->qscale_table[xy], s->qscale)); | 300 score1+= ABS(level - ROUNDED_DIV(ac_val[i + 8]*qscale_table[xy], s->qscale)); |
| 300 ac_val1[i ]= block[n][s->idct_permutation[i<<3]]; | 301 ac_val1[i ]= block[n][s->idct_permutation[i<<3]]; |
| 301 ac_val1[i+8]= level; | 302 ac_val1[i+8]= level; |
| 302 } | 303 } |
| 303 } | 304 } |
| 304 }else{ | 305 }else{ |
| 305 const int xy= s->mb_x-1 + s->mb_y*s->mb_width; | 306 const int xy= s->mb_x-1 + s->mb_y*s->mb_width; |
| 306 /* left prediction */ | 307 /* left prediction */ |
| 307 ac_val-= 16; | 308 ac_val-= 16; |
| 308 if(s->mb_x==0 || s->qscale == s->qscale_table[xy] || n==1 || n==3){ | 309 if(s->mb_x==0 || s->qscale == qscale_table[xy] || n==1 || n==3){ |
| 309 /* same qscale */ | 310 /* same qscale */ |
| 310 for(i=1; i<8; i++){ | 311 for(i=1; i<8; i++){ |
| 311 const int level= block[n][s->idct_permutation[i<<3]]; | 312 const int level= block[n][s->idct_permutation[i<<3]]; |
| 312 score0+= ABS(level); | 313 score0+= ABS(level); |
| 313 score1+= ABS(level - ac_val[i]); | 314 score1+= ABS(level - ac_val[i]); |
| 317 }else{ | 318 }else{ |
| 318 /* different qscale, we must rescale */ | 319 /* different qscale, we must rescale */ |
| 319 for(i=1; i<8; i++){ | 320 for(i=1; i<8; i++){ |
| 320 const int level= block[n][s->idct_permutation[i<<3]]; | 321 const int level= block[n][s->idct_permutation[i<<3]]; |
| 321 score0+= ABS(level); | 322 score0+= ABS(level); |
| 322 score1+= ABS(level - ROUNDED_DIV(ac_val[i]*s->qscale_table[xy], s->qscale)); | 323 score1+= ABS(level - ROUNDED_DIV(ac_val[i]*qscale_table[xy], s->qscale)); |
| 323 ac_val1[i ]= level; | 324 ac_val1[i ]= level; |
| 324 ac_val1[i+8]= block[n][s->idct_permutation[i ]]; | 325 ac_val1[i+8]= block[n][s->idct_permutation[i ]]; |
| 325 } | 326 } |
| 326 } | 327 } |
| 327 } | 328 } |
| 333 /** | 334 /** |
| 334 * modify qscale so that encoding is acually possible in h263 (limit difference to -2..2) | 335 * modify qscale so that encoding is acually possible in h263 (limit difference to -2..2) |
| 335 */ | 336 */ |
| 336 void ff_clean_h263_qscales(MpegEncContext *s){ | 337 void ff_clean_h263_qscales(MpegEncContext *s){ |
| 337 int i; | 338 int i; |
| 339 int8_t * const qscale_table= s->current_picture.qscale_table; | |
| 338 | 340 |
| 339 for(i=1; i<s->mb_num; i++){ | 341 for(i=1; i<s->mb_num; i++){ |
| 340 if(s->qscale_table[i] - s->qscale_table[i-1] >2) | 342 if(qscale_table[i] - qscale_table[i-1] >2) |
| 341 s->qscale_table[i]= s->qscale_table[i-1]+2; | 343 qscale_table[i]= qscale_table[i-1]+2; |
| 342 } | 344 } |
| 343 for(i=s->mb_num-2; i>=0; i--){ | 345 for(i=s->mb_num-2; i>=0; i--){ |
| 344 if(s->qscale_table[i] - s->qscale_table[i+1] >2) | 346 if(qscale_table[i] - qscale_table[i+1] >2) |
| 345 s->qscale_table[i]= s->qscale_table[i+1]+2; | 347 qscale_table[i]= qscale_table[i+1]+2; |
| 346 } | 348 } |
| 347 } | 349 } |
| 348 | 350 |
| 349 /** | 351 /** |
| 350 * modify mb_type & qscale so that encoding is acually possible in mpeg4 | 352 * modify mb_type & qscale so that encoding is acually possible in mpeg4 |
| 351 */ | 353 */ |
| 352 void ff_clean_mpeg4_qscales(MpegEncContext *s){ | 354 void ff_clean_mpeg4_qscales(MpegEncContext *s){ |
| 353 int i; | 355 int i; |
| 354 | 356 int8_t * const qscale_table= s->current_picture.qscale_table; |
| 357 | |
| 355 ff_clean_h263_qscales(s); | 358 ff_clean_h263_qscales(s); |
| 356 | 359 |
| 357 for(i=1; i<s->mb_num; i++){ | 360 for(i=1; i<s->mb_num; i++){ |
| 358 if(s->qscale_table[i] != s->qscale_table[i-1] && (s->mb_type[i]&MB_TYPE_INTER4V)){ | 361 if(qscale_table[i] != qscale_table[i-1] && (s->mb_type[i]&MB_TYPE_INTER4V)){ |
| 359 s->mb_type[i]&= ~MB_TYPE_INTER4V; | 362 s->mb_type[i]&= ~MB_TYPE_INTER4V; |
| 360 s->mb_type[i]|= MB_TYPE_INTER; | 363 s->mb_type[i]|= MB_TYPE_INTER; |
| 361 } | 364 } |
| 362 } | 365 } |
| 363 | 366 |
| 365 int odd=0; | 368 int odd=0; |
| 366 /* ok, come on, this isnt funny anymore, theres more code for handling this mpeg4 mess than | 369 /* ok, come on, this isnt funny anymore, theres more code for handling this mpeg4 mess than |
| 367 for the actual adaptive quantization */ | 370 for the actual adaptive quantization */ |
| 368 | 371 |
| 369 for(i=0; i<s->mb_num; i++){ | 372 for(i=0; i<s->mb_num; i++){ |
| 370 odd += s->qscale_table[i]&1; | 373 odd += qscale_table[i]&1; |
| 371 } | 374 } |
| 372 | 375 |
| 373 if(2*odd > s->mb_num) odd=1; | 376 if(2*odd > s->mb_num) odd=1; |
| 374 else odd=0; | 377 else odd=0; |
| 375 | 378 |
| 376 for(i=0; i<s->mb_num; i++){ | 379 for(i=0; i<s->mb_num; i++){ |
| 377 if((s->qscale_table[i]&1) != odd) | 380 if((qscale_table[i]&1) != odd) |
| 378 s->qscale_table[i]++; | 381 qscale_table[i]++; |
| 379 if(s->qscale_table[i] > 31) | 382 if(qscale_table[i] > 31) |
| 380 s->qscale_table[i]= 31; | 383 qscale_table[i]= 31; |
| 381 } | 384 } |
| 382 | 385 |
| 383 for(i=1; i<s->mb_num; i++){ | 386 for(i=1; i<s->mb_num; i++){ |
| 384 if(s->qscale_table[i] != s->qscale_table[i-1] && (s->mb_type[i]&MB_TYPE_DIRECT)){ | 387 if(qscale_table[i] != qscale_table[i-1] && (s->mb_type[i]&MB_TYPE_DIRECT)){ |
| 385 s->mb_type[i]&= ~MB_TYPE_DIRECT; | 388 s->mb_type[i]&= ~MB_TYPE_DIRECT; |
| 386 s->mb_type[i]|= MB_TYPE_BIDIR; | 389 s->mb_type[i]|= MB_TYPE_BIDIR; |
| 387 } | 390 } |
| 388 } | 391 } |
| 389 } | 392 } |
| 425 assert(s->dquant>=-2 && s->dquant<=2); | 428 assert(s->dquant>=-2 && s->dquant<=2); |
| 426 assert((s->dquant&1)==0); | 429 assert((s->dquant&1)==0); |
| 427 assert(mb_type>=0); | 430 assert(mb_type>=0); |
| 428 | 431 |
| 429 /* nothing to do if this MB was skiped in the next P Frame */ | 432 /* nothing to do if this MB was skiped in the next P Frame */ |
| 430 if(s->mbskip_table[s->mb_y * s->mb_width + s->mb_x]){ //FIXME avoid DCT & ... | 433 if(s->next_picture.mbskip_table[s->mb_y * s->mb_width + s->mb_x]){ //FIXME avoid DCT & ... |
| 431 s->skip_count++; | 434 s->skip_count++; |
| 432 s->mv[0][0][0]= | 435 s->mv[0][0][0]= |
| 433 s->mv[0][0][1]= | 436 s->mv[0][0][1]= |
| 434 s->mv[1][0][0]= | 437 s->mv[1][0][0]= |
| 435 s->mv[1][0][1]= 0; | 438 s->mv[1][0][1]= 0; |
| 436 s->mv_dir= MV_DIR_FORWARD; //doesnt matter | 439 s->mv_dir= MV_DIR_FORWARD; //doesnt matter |
| 437 s->qscale -= s->dquant; | 440 s->qscale -= s->dquant; |
| 441 // s->mb_skiped=1; | |
| 442 | |
| 438 return; | 443 return; |
| 439 } | 444 } |
| 440 | 445 |
| 441 if ((cbp | motion_x | motion_y | mb_type) ==0) { | 446 if ((cbp | motion_x | motion_y | mb_type) ==0) { |
| 442 /* direct MB with MV={0,0} */ | 447 /* direct MB with MV={0,0} */ |
| 449 s->last_bits++; | 454 s->last_bits++; |
| 450 } | 455 } |
| 451 s->skip_count++; | 456 s->skip_count++; |
| 452 return; | 457 return; |
| 453 } | 458 } |
| 459 | |
| 454 put_bits(&s->pb, 1, 0); /* mb coded modb1=0 */ | 460 put_bits(&s->pb, 1, 0); /* mb coded modb1=0 */ |
| 455 put_bits(&s->pb, 1, cbp ? 0 : 1); /* modb2 */ //FIXME merge | 461 put_bits(&s->pb, 1, cbp ? 0 : 1); /* modb2 */ //FIXME merge |
| 456 put_bits(&s->pb, mb_type+1, 1); // this table is so simple that we dont need it :) | 462 put_bits(&s->pb, mb_type+1, 1); // this table is so simple that we dont need it :) |
| 457 if(cbp) put_bits(&s->pb, 6, cbp); | 463 if(cbp) put_bits(&s->pb, 6, cbp); |
| 458 | 464 |
| 545 y= s->mb_y*16; | 551 y= s->mb_y*16; |
| 546 if(x+16 > s->width) x= s->width-16; | 552 if(x+16 > s->width) x= s->width-16; |
| 547 if(y+16 > s->height) y= s->height-16; | 553 if(y+16 > s->height) y= s->height-16; |
| 548 | 554 |
| 549 offset= x + y*s->linesize; | 555 offset= x + y*s->linesize; |
| 550 p_pic= s->new_picture[0] + offset; | 556 p_pic= s->new_picture.data[0] + offset; |
| 551 | 557 |
| 552 s->mb_skiped=1; | 558 s->mb_skiped=1; |
| 553 for(i=0; i<s->max_b_frames; i++){ | 559 for(i=0; i<s->max_b_frames; i++){ |
| 554 uint8_t *b_pic; | 560 uint8_t *b_pic; |
| 555 int diff; | 561 int diff; |
| 556 | 562 Picture *pic= s->reordered_input_picture[i+1]; |
| 557 if(s->coded_order[i+1].pict_type!=B_TYPE) break; | 563 |
| 558 | 564 if(pic==NULL || pic->pict_type!=B_TYPE) break; |
| 559 b_pic= s->coded_order[i+1].picture[0] + offset; | 565 |
| 566 b_pic= pic->data[0] + offset + 16; //FIXME +16 | |
| 560 diff= s->dsp.pix_abs16x16(p_pic, b_pic, s->linesize); | 567 diff= s->dsp.pix_abs16x16(p_pic, b_pic, s->linesize); |
| 561 if(diff>s->qscale*70){ //FIXME check that 70 is optimal | 568 if(diff>s->qscale*70){ //FIXME check that 70 is optimal |
| 562 s->mb_skiped=0; | 569 s->mb_skiped=0; |
| 563 break; | 570 break; |
| 564 } | 571 } |
| 1491 if(s->time_increment_resolution>=256*256) s->time_increment_resolution= 256*128; | 1498 if(s->time_increment_resolution>=256*256) s->time_increment_resolution= 256*128; |
| 1492 | 1499 |
| 1493 s->time_increment_bits = av_log2(s->time_increment_resolution - 1) + 1; | 1500 s->time_increment_bits = av_log2(s->time_increment_resolution - 1) + 1; |
| 1494 } | 1501 } |
| 1495 | 1502 |
| 1496 if(s->avctx->pts) | 1503 if(s->current_picture.pts) |
| 1497 s->time= (s->avctx->pts*s->time_increment_resolution + 500*1000)/(1000*1000); | 1504 s->time= (s->current_picture.pts*s->time_increment_resolution + 500*1000)/(1000*1000); |
| 1498 else | 1505 else |
| 1499 s->time= picture_number*(INT64)FRAME_RATE_BASE*s->time_increment_resolution/s->frame_rate; | 1506 s->time= picture_number*(INT64)FRAME_RATE_BASE*s->time_increment_resolution/s->frame_rate; |
| 1500 time_div= s->time/s->time_increment_resolution; | 1507 time_div= s->time/s->time_increment_resolution; |
| 1501 time_mod= s->time%s->time_increment_resolution; | 1508 time_mod= s->time%s->time_increment_resolution; |
| 1502 | 1509 |
| 1734 void mpeg4_pred_ac(MpegEncContext * s, INT16 *block, int n, | 1741 void mpeg4_pred_ac(MpegEncContext * s, INT16 *block, int n, |
| 1735 int dir) | 1742 int dir) |
| 1736 { | 1743 { |
| 1737 int i; | 1744 int i; |
| 1738 INT16 *ac_val, *ac_val1; | 1745 INT16 *ac_val, *ac_val1; |
| 1746 int8_t * const qscale_table= s->current_picture.qscale_table; | |
| 1739 | 1747 |
| 1740 /* find prediction */ | 1748 /* find prediction */ |
| 1741 ac_val = s->ac_val[0][0] + s->block_index[n] * 16; | 1749 ac_val = s->ac_val[0][0] + s->block_index[n] * 16; |
| 1742 ac_val1 = ac_val; | 1750 ac_val1 = ac_val; |
| 1743 if (s->ac_pred) { | 1751 if (s->ac_pred) { |
| 1744 if (dir == 0) { | 1752 if (dir == 0) { |
| 1745 const int xy= s->mb_x-1 + s->mb_y*s->mb_width; | 1753 const int xy= s->mb_x-1 + s->mb_y*s->mb_width; |
| 1746 /* left prediction */ | 1754 /* left prediction */ |
| 1747 ac_val -= 16; | 1755 ac_val -= 16; |
| 1748 | 1756 |
| 1749 if(s->mb_x==0 || s->qscale == s->qscale_table[xy] || n==1 || n==3){ | 1757 if(s->mb_x==0 || s->qscale == qscale_table[xy] || n==1 || n==3){ |
| 1750 /* same qscale */ | 1758 /* same qscale */ |
| 1751 for(i=1;i<8;i++) { | 1759 for(i=1;i<8;i++) { |
| 1752 block[s->idct_permutation[i<<3]] += ac_val[i]; | 1760 block[s->idct_permutation[i<<3]] += ac_val[i]; |
| 1753 } | 1761 } |
| 1754 }else{ | 1762 }else{ |
| 1755 /* different qscale, we must rescale */ | 1763 /* different qscale, we must rescale */ |
| 1756 for(i=1;i<8;i++) { | 1764 for(i=1;i<8;i++) { |
| 1757 block[s->idct_permutation[i<<3]] += ROUNDED_DIV(ac_val[i]*s->qscale_table[xy], s->qscale); | 1765 block[s->idct_permutation[i<<3]] += ROUNDED_DIV(ac_val[i]*qscale_table[xy], s->qscale); |
| 1758 } | 1766 } |
| 1759 } | 1767 } |
| 1760 } else { | 1768 } else { |
| 1761 const int xy= s->mb_x + s->mb_y*s->mb_width - s->mb_width; | 1769 const int xy= s->mb_x + s->mb_y*s->mb_width - s->mb_width; |
| 1762 /* top prediction */ | 1770 /* top prediction */ |
| 1763 ac_val -= 16 * s->block_wrap[n]; | 1771 ac_val -= 16 * s->block_wrap[n]; |
| 1764 | 1772 |
| 1765 if(s->mb_y==0 || s->qscale == s->qscale_table[xy] || n==2 || n==3){ | 1773 if(s->mb_y==0 || s->qscale == qscale_table[xy] || n==2 || n==3){ |
| 1766 /* same qscale */ | 1774 /* same qscale */ |
| 1767 for(i=1;i<8;i++) { | 1775 for(i=1;i<8;i++) { |
| 1768 block[s->idct_permutation[i]] += ac_val[i + 8]; | 1776 block[s->idct_permutation[i]] += ac_val[i + 8]; |
| 1769 } | 1777 } |
| 1770 }else{ | 1778 }else{ |
| 1771 /* different qscale, we must rescale */ | 1779 /* different qscale, we must rescale */ |
| 1772 for(i=1;i<8;i++) { | 1780 for(i=1;i<8;i++) { |
| 1773 block[s->idct_permutation[i]] += ROUNDED_DIV(ac_val[i + 8]*s->qscale_table[xy], s->qscale); | 1781 block[s->idct_permutation[i]] += ROUNDED_DIV(ac_val[i + 8]*qscale_table[xy], s->qscale); |
| 1774 } | 1782 } |
| 1775 } | 1783 } |
| 1776 } | 1784 } |
| 1777 } | 1785 } |
| 1778 /* left copy */ | 1786 /* left copy */ |
| 1788 static void mpeg4_inv_pred_ac(MpegEncContext * s, INT16 *block, int n, | 1796 static void mpeg4_inv_pred_ac(MpegEncContext * s, INT16 *block, int n, |
| 1789 int dir) | 1797 int dir) |
| 1790 { | 1798 { |
| 1791 int i; | 1799 int i; |
| 1792 INT16 *ac_val; | 1800 INT16 *ac_val; |
| 1801 int8_t * const qscale_table= s->current_picture.qscale_table; | |
| 1793 | 1802 |
| 1794 /* find prediction */ | 1803 /* find prediction */ |
| 1795 ac_val = s->ac_val[0][0] + s->block_index[n] * 16; | 1804 ac_val = s->ac_val[0][0] + s->block_index[n] * 16; |
| 1796 | 1805 |
| 1797 if (dir == 0) { | 1806 if (dir == 0) { |
| 1798 const int xy= s->mb_x-1 + s->mb_y*s->mb_width; | 1807 const int xy= s->mb_x-1 + s->mb_y*s->mb_width; |
| 1799 /* left prediction */ | 1808 /* left prediction */ |
| 1800 ac_val -= 16; | 1809 ac_val -= 16; |
| 1801 if(s->mb_x==0 || s->qscale == s->qscale_table[xy] || n==1 || n==3){ | 1810 if(s->mb_x==0 || s->qscale == qscale_table[xy] || n==1 || n==3){ |
| 1802 /* same qscale */ | 1811 /* same qscale */ |
| 1803 for(i=1;i<8;i++) { | 1812 for(i=1;i<8;i++) { |
| 1804 block[s->idct_permutation[i<<3]] -= ac_val[i]; | 1813 block[s->idct_permutation[i<<3]] -= ac_val[i]; |
| 1805 } | 1814 } |
| 1806 }else{ | 1815 }else{ |
| 1807 /* different qscale, we must rescale */ | 1816 /* different qscale, we must rescale */ |
| 1808 for(i=1;i<8;i++) { | 1817 for(i=1;i<8;i++) { |
| 1809 block[s->idct_permutation[i<<3]] -= ROUNDED_DIV(ac_val[i]*s->qscale_table[xy], s->qscale); | 1818 block[s->idct_permutation[i<<3]] -= ROUNDED_DIV(ac_val[i]*qscale_table[xy], s->qscale); |
| 1810 } | 1819 } |
| 1811 } | 1820 } |
| 1812 } else { | 1821 } else { |
| 1813 const int xy= s->mb_x + s->mb_y*s->mb_width - s->mb_width; | 1822 const int xy= s->mb_x + s->mb_y*s->mb_width - s->mb_width; |
| 1814 /* top prediction */ | 1823 /* top prediction */ |
| 1815 ac_val -= 16 * s->block_wrap[n]; | 1824 ac_val -= 16 * s->block_wrap[n]; |
| 1816 if(s->mb_y==0 || s->qscale == s->qscale_table[xy] || n==2 || n==3){ | 1825 if(s->mb_y==0 || s->qscale == qscale_table[xy] || n==2 || n==3){ |
| 1817 /* same qscale */ | 1826 /* same qscale */ |
| 1818 for(i=1;i<8;i++) { | 1827 for(i=1;i<8;i++) { |
| 1819 block[s->idct_permutation[i]] -= ac_val[i + 8]; | 1828 block[s->idct_permutation[i]] -= ac_val[i + 8]; |
| 1820 } | 1829 } |
| 1821 }else{ | 1830 }else{ |
| 1822 /* different qscale, we must rescale */ | 1831 /* different qscale, we must rescale */ |
| 1823 for(i=1;i<8;i++) { | 1832 for(i=1;i<8;i++) { |
| 1824 block[s->idct_permutation[i]] -= ROUNDED_DIV(ac_val[i + 8]*s->qscale_table[xy], s->qscale); | 1833 block[s->idct_permutation[i]] -= ROUNDED_DIV(ac_val[i + 8]*qscale_table[xy], s->qscale); |
| 1825 } | 1834 } |
| 1826 } | 1835 } |
| 1827 } | 1836 } |
| 1828 } | 1837 } |
| 1829 | 1838 |
| 2530 s->mb_intra = 1; | 2539 s->mb_intra = 1; |
| 2531 | 2540 |
| 2532 if(cbpc & 4) { | 2541 if(cbpc & 4) { |
| 2533 change_qscale(s, quant_tab[get_bits(&s->gb, 2)]); | 2542 change_qscale(s, quant_tab[get_bits(&s->gb, 2)]); |
| 2534 } | 2543 } |
| 2535 s->qscale_table[xy]= s->qscale; | 2544 s->current_picture.qscale_table[xy]= s->qscale; |
| 2536 | 2545 |
| 2537 s->mbintra_table[xy]= 1; | 2546 s->mbintra_table[xy]= 1; |
| 2538 for(i=0; i<6; i++){ | 2547 for(i=0; i<6; i++){ |
| 2539 int dc_pred_dir; | 2548 int dc_pred_dir; |
| 2540 int dc= mpeg4_decode_dc(s, i, &dc_pred_dir); | 2549 int dc= mpeg4_decode_dc(s, i, &dc_pred_dir); |
| 2702 } | 2711 } |
| 2703 | 2712 |
| 2704 if(s->cbp_table[xy] & 8) { | 2713 if(s->cbp_table[xy] & 8) { |
| 2705 change_qscale(s, quant_tab[get_bits(&s->gb, 2)]); | 2714 change_qscale(s, quant_tab[get_bits(&s->gb, 2)]); |
| 2706 } | 2715 } |
| 2707 s->qscale_table[xy]= s->qscale; | 2716 s->current_picture.qscale_table[xy]= s->qscale; |
| 2708 | 2717 |
| 2709 for(i=0; i<6; i++){ | 2718 for(i=0; i<6; i++){ |
| 2710 int dc_pred_dir; | 2719 int dc_pred_dir; |
| 2711 int dc= mpeg4_decode_dc(s, i, &dc_pred_dir); | 2720 int dc= mpeg4_decode_dc(s, i, &dc_pred_dir); |
| 2712 if(dc < 0){ | 2721 if(dc < 0){ |
| 2719 s->cbp_table[xy]&= 3; //remove dquant | 2728 s->cbp_table[xy]&= 3; //remove dquant |
| 2720 s->cbp_table[xy]|= cbpy<<2; | 2729 s->cbp_table[xy]|= cbpy<<2; |
| 2721 s->pred_dir_table[xy]= dir | (ac_pred<<7); | 2730 s->pred_dir_table[xy]= dir | (ac_pred<<7); |
| 2722 s->error_status_table[xy]&= ~DC_ERROR; | 2731 s->error_status_table[xy]&= ~DC_ERROR; |
| 2723 }else if(s->mb_type[xy]&MB_TYPE_SKIPED){ | 2732 }else if(s->mb_type[xy]&MB_TYPE_SKIPED){ |
| 2724 s->qscale_table[xy]= s->qscale; | 2733 s->current_picture.qscale_table[xy]= s->qscale; |
| 2725 s->cbp_table[xy]= 0; | 2734 s->cbp_table[xy]= 0; |
| 2726 }else{ | 2735 }else{ |
| 2727 int cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); | 2736 int cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); |
| 2728 | 2737 |
| 2729 if(cbpy<0){ | 2738 if(cbpy<0){ |
| 2732 } | 2741 } |
| 2733 | 2742 |
| 2734 if(s->cbp_table[xy] & 8) { | 2743 if(s->cbp_table[xy] & 8) { |
| 2735 change_qscale(s, quant_tab[get_bits(&s->gb, 2)]); | 2744 change_qscale(s, quant_tab[get_bits(&s->gb, 2)]); |
| 2736 } | 2745 } |
| 2737 s->qscale_table[xy]= s->qscale; | 2746 s->current_picture.qscale_table[xy]= s->qscale; |
| 2738 | 2747 |
| 2739 s->cbp_table[xy]&= 3; //remove dquant | 2748 s->cbp_table[xy]&= 3; //remove dquant |
| 2740 s->cbp_table[xy]|= (cbpy^0xf)<<2; | 2749 s->cbp_table[xy]|= (cbpy^0xf)<<2; |
| 2741 } | 2750 } |
| 2742 } | 2751 } |
| 2799 const int xy= s->mb_x + s->mb_y*s->mb_width; | 2808 const int xy= s->mb_x + s->mb_y*s->mb_width; |
| 2800 | 2809 |
| 2801 mb_type= s->mb_type[xy]; | 2810 mb_type= s->mb_type[xy]; |
| 2802 cbp = s->cbp_table[xy]; | 2811 cbp = s->cbp_table[xy]; |
| 2803 | 2812 |
| 2804 if(s->qscale_table[xy] != s->qscale){ | 2813 if(s->current_picture.qscale_table[xy] != s->qscale){ |
| 2805 s->qscale= s->qscale_table[xy]; | 2814 s->qscale= s->current_picture.qscale_table[xy]; |
| 2806 s->y_dc_scale= s->y_dc_scale_table[ s->qscale ]; | 2815 s->y_dc_scale= s->y_dc_scale_table[ s->qscale ]; |
| 2807 s->c_dc_scale= s->c_dc_scale_table[ s->qscale ]; | 2816 s->c_dc_scale= s->c_dc_scale_table[ s->qscale ]; |
| 2808 } | 2817 } |
| 2809 | 2818 |
| 2810 if (s->pict_type == P_TYPE || s->pict_type==S_TYPE) { | 2819 if (s->pict_type == P_TYPE || s->pict_type==S_TYPE) { |
| 3052 s->last_mv[i][1][1]= 0; | 3061 s->last_mv[i][1][1]= 0; |
| 3053 } | 3062 } |
| 3054 } | 3063 } |
| 3055 | 3064 |
| 3056 /* if we skipped it in the future P Frame than skip it now too */ | 3065 /* if we skipped it in the future P Frame than skip it now too */ |
| 3057 s->mb_skiped= s->mbskip_table[s->mb_y * s->mb_width + s->mb_x]; // Note, skiptab=0 if last was GMC | 3066 s->mb_skiped= s->next_picture.mbskip_table[s->mb_y * s->mb_width + s->mb_x]; // Note, skiptab=0 if last was GMC |
| 3058 | 3067 |
| 3059 if(s->mb_skiped){ | 3068 if(s->mb_skiped){ |
| 3060 /* skip mb */ | 3069 /* skip mb */ |
| 3061 for(i=0;i<6;i++) | 3070 for(i=0;i<6;i++) |
| 3062 s->block_last_index[i] = -1; | 3071 s->block_last_index[i] = -1; |
| 3285 end: | 3294 end: |
| 3286 | 3295 |
| 3287 /* per-MB end of slice check */ | 3296 /* per-MB end of slice check */ |
| 3288 if(s->codec_id==CODEC_ID_MPEG4){ | 3297 if(s->codec_id==CODEC_ID_MPEG4){ |
| 3289 if(mpeg4_is_resync(s)){ | 3298 if(mpeg4_is_resync(s)){ |
| 3290 if(s->pict_type==B_TYPE && s->mbskip_table[s->mb_y * s->mb_width + s->mb_x+1]) | 3299 if(s->pict_type==B_TYPE && s->next_picture.mbskip_table[s->mb_y * s->mb_width + s->mb_x+1]) |
| 3291 return SLICE_OK; | 3300 return SLICE_OK; |
| 3292 return SLICE_END; | 3301 return SLICE_END; |
| 3293 } | 3302 } |
| 3294 }else{ | 3303 }else{ |
| 3295 int v= show_bits(&s->gb, 16); | 3304 int v= show_bits(&s->gb, 16); |
| 4439 - ROUNDED_DIV(s->last_non_b_time - s->pp_time, s->t_frame))*2; | 4448 - ROUNDED_DIV(s->last_non_b_time - s->pp_time, s->t_frame))*2; |
| 4440 s->pb_field_time= ( ROUNDED_DIV(s->time, s->t_frame) | 4449 s->pb_field_time= ( ROUNDED_DIV(s->time, s->t_frame) |
| 4441 - ROUNDED_DIV(s->last_non_b_time - s->pp_time, s->t_frame))*2; | 4450 - ROUNDED_DIV(s->last_non_b_time - s->pp_time, s->t_frame))*2; |
| 4442 } | 4451 } |
| 4443 | 4452 |
| 4444 s->avctx->pts= s->time*1000LL*1000LL / s->time_increment_resolution; | 4453 s->current_picture.pts= s->time*1000LL*1000LL / s->time_increment_resolution; |
| 4445 | 4454 |
| 4446 if(check_marker(gb, "before vop_coded")==0 && s->picture_number==0){ | 4455 if(check_marker(gb, "before vop_coded")==0 && s->picture_number==0){ |
| 4447 printf("hmm, seems the headers arnt complete, trying to guess time_increment_bits\n"); | 4456 printf("hmm, seems the headers arnt complete, trying to guess time_increment_bits\n"); |
| 4448 for(s->time_increment_bits++ ;s->time_increment_bits<16; s->time_increment_bits++){ | 4457 for(s->time_increment_bits++ ;s->time_increment_bits<16; s->time_increment_bits++){ |
| 4449 if(get_bits1(gb)) break; | 4458 if(get_bits1(gb)) break; |
