comparison mpegvideo.h @ 745:25d7fb7c89be libavcodec

better/cleaner error resilience (done in a 2nd pass after decoding) h263/mpeg4 out of order slice decoding
author michaelni
date Sun, 13 Oct 2002 13:16:04 +0000
parents a91203b34e71
children 3d4377531f6c
comparison
equal deleted inserted replaced
744:2f7da29ede37 745:25d7fb7c89be
320 int skip_count; 320 int skip_count;
321 int misc_bits; // cbp, mb_type 321 int misc_bits; // cbp, mb_type
322 int last_bits; //temp var used for calculating the above vars 322 int last_bits; //temp var used for calculating the above vars
323 323
324 /* error concealment / resync */ 324 /* error concealment / resync */
325 UINT8 *error_status_table; /* table of the error status of each MB */
326 #define VP_START 1 /* current MB is the first after a resync marker */
327 #define AC_ERROR 2
328 #define DC_ERROR 4
329 #define MV_ERROR 8
330 #define AC_END 16
331 #define DC_END 32
332 #define MV_END 64
333 //FIXME some prefix?
334
325 int resync_mb_x; /* x position of last resync marker */ 335 int resync_mb_x; /* x position of last resync marker */
326 int resync_mb_y; /* y position of last resync marker */ 336 int resync_mb_y; /* y position of last resync marker */
327 int mb_num_left; /* number of MBs left in this video packet */ 337 GetBitContext last_resync_gb; /* used to serach for the next resync marker */
328 GetBitContext next_resync_gb; /* starts at the next resync marker */ 338 int mb_num_left; /* number of MBs left in this video packet (for partitioned Slices only)*/
329 int next_resync_qscale; /* qscale of next resync marker */
330 int next_resync_pos; /* bitstream position of next resync marker */
331 #define DECODING_AC_LOST -1
332 #define DECODING_ACDC_LOST -2
333 #define DECODING_DESYNC -3
334 int decoding_error;
335 int next_p_frame_damaged; /* set if the next p frame is damaged, to avoid showing trashed b frames */ 339 int next_p_frame_damaged; /* set if the next p frame is damaged, to avoid showing trashed b frames */
336 int error_resilience; 340 int error_resilience;
337 341
338 /* H.263 specific */ 342 /* H.263 specific */
339 int gob_number; 343 int gob_number;
379 int aspect_ratio_info; 383 int aspect_ratio_info;
380 int aspected_width; 384 int aspected_width;
381 int aspected_height; 385 int aspected_height;
382 int sprite_warping_accuracy; 386 int sprite_warping_accuracy;
383 int low_latency_sprite; 387 int low_latency_sprite;
384 int data_partitioning; 388 int data_partitioning; /* data partitioning flag from header */
389 int partitioned_frame; /* is current frame partitioned */
385 int rvlc; /* reversible vlc */ 390 int rvlc; /* reversible vlc */
386 int resync_marker; /* could this stream contain resync markers*/ 391 int resync_marker; /* could this stream contain resync markers*/
387 int low_delay; /* no reordering needed / has no b-frames */ 392 int low_delay; /* no reordering needed / has no b-frames */
388 int vo_type; 393 int vo_type;
389 int vol_control_parameters; /* does the stream contain the low_delay flag, used to workaround buggy encoders */ 394 int vol_control_parameters; /* does the stream contain the low_delay flag, used to workaround buggy encoders */
405 int divx_build; 410 int divx_build;
406 #define BITSTREAM_BUFFER_SIZE 1024*256 411 #define BITSTREAM_BUFFER_SIZE 1024*256
407 UINT8 *bitstream_buffer; //Divx 5.01 puts several frames in a single one, this is used to reorder them 412 UINT8 *bitstream_buffer; //Divx 5.01 puts several frames in a single one, this is used to reorder them
408 int bitstream_buffer_size; 413 int bitstream_buffer_size;
409 414
415 /* lavc specific stuff, used to workaround bugs in libavcodec */
416 int ffmpeg_version;
417 int lavc_build;
418
410 /* RV10 specific */ 419 /* RV10 specific */
411 int rv10_version; /* RV10 version: 0 or 3 */ 420 int rv10_version; /* RV10 version: 0 or 3 */
412 int rv10_first_dc_coded[3]; 421 int rv10_first_dc_coded[3];
413 422
414 /* MJPEG specific */ 423 /* MJPEG specific */
473 UINT8 *ptr_last_mb_line; 482 UINT8 *ptr_last_mb_line;
474 UINT32 mb_line_avgsize; 483 UINT32 mb_line_avgsize;
475 484
476 DCTELEM (*block)[64]; /* points to one of the following blocks */ 485 DCTELEM (*block)[64]; /* points to one of the following blocks */
477 DCTELEM blocks[2][6][64] __align8; // for HQ mode we need to keep the best block 486 DCTELEM blocks[2][6][64] __align8; // for HQ mode we need to keep the best block
487 int (*decode_mb)(struct MpegEncContext *s, DCTELEM block[6][64]); // used by some codecs to avoid a switch()
488 #define SLICE_OK 0
489 #define SLICE_ERROR -1
490 #define SLICE_END -2 //end marker found
491 #define SLICE_NOEND -3 //no end marker or error found but mb count exceeded
492
478 void (*dct_unquantize_mpeg1)(struct MpegEncContext *s, 493 void (*dct_unquantize_mpeg1)(struct MpegEncContext *s,
479 DCTELEM *block, int n, int qscale); 494 DCTELEM *block, int n, int qscale);
480 void (*dct_unquantize_mpeg2)(struct MpegEncContext *s, 495 void (*dct_unquantize_mpeg2)(struct MpegEncContext *s,
481 DCTELEM *block, int n, int qscale); 496 DCTELEM *block, int n, int qscale);
482 void (*dct_unquantize_h263)(struct MpegEncContext *s, 497 void (*dct_unquantize_h263)(struct MpegEncContext *s,
486 int (*dct_quantize)(struct MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow); 501 int (*dct_quantize)(struct MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow);
487 void (*fdct)(DCTELEM *block/* align 16*/); 502 void (*fdct)(DCTELEM *block/* align 16*/);
488 void (*idct_put)(UINT8 *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/); 503 void (*idct_put)(UINT8 *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
489 void (*idct_add)(UINT8 *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/); 504 void (*idct_add)(UINT8 *dest/*align 8*/, int line_size, DCTELEM *block/*align 16*/);
490 } MpegEncContext; 505 } MpegEncContext;
506
491 507
492 int DCT_common_init(MpegEncContext *s); 508 int DCT_common_init(MpegEncContext *s);
493 int MPV_common_init(MpegEncContext *s); 509 int MPV_common_init(MpegEncContext *s);
494 void MPV_common_end(MpegEncContext *s); 510 void MPV_common_end(MpegEncContext *s);
495 void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64]); 511 void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64]);
510 extern void (*draw_edges)(UINT8 *buf, int wrap, int width, int height, int w); 526 extern void (*draw_edges)(UINT8 *buf, int wrap, int width, int height, int w);
511 void ff_conceal_past_errors(MpegEncContext *s, int conceal_all); 527 void ff_conceal_past_errors(MpegEncContext *s, int conceal_all);
512 void ff_copy_bits(PutBitContext *pb, UINT8 *src, int length); 528 void ff_copy_bits(PutBitContext *pb, UINT8 *src, int length);
513 void ff_clean_intra_table_entries(MpegEncContext *s); 529 void ff_clean_intra_table_entries(MpegEncContext *s);
514 void ff_init_scantable(MpegEncContext *s, ScanTable *st, const UINT8 *src_scantable); 530 void ff_init_scantable(MpegEncContext *s, ScanTable *st, const UINT8 *src_scantable);
531 void ff_error_resilience(MpegEncContext *s);
532 void ff_draw_horiz_band(MpegEncContext *s);
515 533
516 extern int ff_bit_exact; 534 extern int ff_bit_exact;
535
536 static inline void ff_init_block_index(MpegEncContext *s){
537 s->block_index[0]= s->block_wrap[0]*(s->mb_y*2 + 1) - 1 + s->mb_x*2;
538 s->block_index[1]= s->block_wrap[0]*(s->mb_y*2 + 1) + s->mb_x*2;
539 s->block_index[2]= s->block_wrap[0]*(s->mb_y*2 + 2) - 1 + s->mb_x*2;
540 s->block_index[3]= s->block_wrap[0]*(s->mb_y*2 + 2) + s->mb_x*2;
541 s->block_index[4]= s->block_wrap[4]*(s->mb_y + 1) + s->block_wrap[0]*(s->mb_height*2 + 2) + s->mb_x;
542 s->block_index[5]= s->block_wrap[4]*(s->mb_y + 1 + s->mb_height + 2) + s->block_wrap[0]*(s->mb_height*2 + 2) + s->mb_x;
543 }
544
545 static inline void ff_update_block_index(MpegEncContext *s){
546 s->block_index[0]+=2;
547 s->block_index[1]+=2;
548 s->block_index[2]+=2;
549 s->block_index[3]+=2;
550 s->block_index[4]++;
551 s->block_index[5]++;
552 }
553
517 554
518 /* motion_est.c */ 555 /* motion_est.c */
519 void ff_estimate_p_frame_motion(MpegEncContext * s, 556 void ff_estimate_p_frame_motion(MpegEncContext * s,
520 int mb_x, int mb_y); 557 int mb_x, int mb_y);
521 void ff_estimate_b_frame_motion(MpegEncContext * s, 558 void ff_estimate_b_frame_motion(MpegEncContext * s,
522 int mb_x, int mb_y); 559 int mb_x, int mb_y);
523 int ff_get_best_fcode(MpegEncContext * s, int16_t (*mv_table)[2], int type); 560 int ff_get_best_fcode(MpegEncContext * s, int16_t (*mv_table)[2], int type);
524 void ff_fix_long_p_mvs(MpegEncContext * s); 561 void ff_fix_long_p_mvs(MpegEncContext * s);
525 void ff_fix_long_b_mvs(MpegEncContext * s, int16_t (*mv_table)[2], int f_code, int type); 562 void ff_fix_long_b_mvs(MpegEncContext * s, int16_t (*mv_table)[2], int f_code, int type);
526 563
564
527 /* mpeg12.c */ 565 /* mpeg12.c */
528 extern const INT16 ff_mpeg1_default_intra_matrix[64]; 566 extern const INT16 ff_mpeg1_default_intra_matrix[64];
529 extern const INT16 ff_mpeg1_default_non_intra_matrix[64]; 567 extern const INT16 ff_mpeg1_default_non_intra_matrix[64];
530 extern UINT8 ff_mpeg1_dc_scale_table[128]; 568 extern UINT8 ff_mpeg1_dc_scale_table[128];
531 569
532 void mpeg1_encode_picture_header(MpegEncContext *s, int picture_number); 570 void mpeg1_encode_picture_header(MpegEncContext *s, int picture_number);
533 void mpeg1_encode_mb(MpegEncContext *s, 571 void mpeg1_encode_mb(MpegEncContext *s,
534 DCTELEM block[6][64], 572 DCTELEM block[6][64],
535 int motion_x, int motion_y); 573 int motion_x, int motion_y);
536 void ff_mpeg1_encode_init(MpegEncContext *s); 574 void ff_mpeg1_encode_init(MpegEncContext *s);
575
537 576
538 /* h263enc.c */ 577 /* h263enc.c */
539 typedef struct RLTable { 578 typedef struct RLTable {
540 int n; /* number of entries of table_vlc minus 1 */ 579 int n; /* number of entries of table_vlc minus 1 */
541 int last; /* number of values for last = 0 */ 580 int last; /* number of values for last = 0 */
565 604
566 extern UINT8 ff_mpeg4_y_dc_scale_table[32]; 605 extern UINT8 ff_mpeg4_y_dc_scale_table[32];
567 extern UINT8 ff_mpeg4_c_dc_scale_table[32]; 606 extern UINT8 ff_mpeg4_c_dc_scale_table[32];
568 extern const INT16 ff_mpeg4_default_intra_matrix[64]; 607 extern const INT16 ff_mpeg4_default_intra_matrix[64];
569 extern const INT16 ff_mpeg4_default_non_intra_matrix[64]; 608 extern const INT16 ff_mpeg4_default_non_intra_matrix[64];
570
571 void h263_encode_mb(MpegEncContext *s, 609 void h263_encode_mb(MpegEncContext *s,
572 DCTELEM block[6][64], 610 DCTELEM block[6][64],
573 int motion_x, int motion_y); 611 int motion_x, int motion_y);
574 void mpeg4_encode_mb(MpegEncContext *s, 612 void mpeg4_encode_mb(MpegEncContext *s,
575 DCTELEM block[6][64], 613 DCTELEM block[6][64],
581 void mpeg4_pred_ac(MpegEncContext * s, INT16 *block, int n, 619 void mpeg4_pred_ac(MpegEncContext * s, INT16 *block, int n,
582 int dir); 620 int dir);
583 void ff_set_mpeg4_time(MpegEncContext * s, int picture_number); 621 void ff_set_mpeg4_time(MpegEncContext * s, int picture_number);
584 void mpeg4_encode_picture_header(MpegEncContext *s, int picture_number); 622 void mpeg4_encode_picture_header(MpegEncContext *s, int picture_number);
585 void h263_encode_init(MpegEncContext *s); 623 void h263_encode_init(MpegEncContext *s);
586
587 void h263_decode_init_vlc(MpegEncContext *s); 624 void h263_decode_init_vlc(MpegEncContext *s);
588 int h263_decode_picture_header(MpegEncContext *s); 625 int h263_decode_picture_header(MpegEncContext *s);
589 int h263_decode_gob_header(MpegEncContext *s); 626 int ff_h263_decode_gob_header(MpegEncContext *s);
590 int mpeg4_decode_picture_header(MpegEncContext * s); 627 int mpeg4_decode_picture_header(MpegEncContext * s);
591 int intel_h263_decode_picture_header(MpegEncContext *s); 628 int intel_h263_decode_picture_header(MpegEncContext *s);
592 int h263_decode_mb(MpegEncContext *s, 629 int ff_h263_decode_mb(MpegEncContext *s,
593 DCTELEM block[6][64]); 630 DCTELEM block[6][64]);
594 int h263_get_picture_format(int width, int height); 631 int h263_get_picture_format(int width, int height);
595 int ff_mpeg4_decode_video_packet_header(MpegEncContext *s);
596 int ff_mpeg4_resync(MpegEncContext *s);
597 void ff_mpeg4_encode_video_packet_header(MpegEncContext *s); 632 void ff_mpeg4_encode_video_packet_header(MpegEncContext *s);
598 void ff_mpeg4_clean_buffers(MpegEncContext *s); 633 void ff_mpeg4_clean_buffers(MpegEncContext *s);
599 void ff_mpeg4_stuffing(PutBitContext * pbc); 634 void ff_mpeg4_stuffing(PutBitContext * pbc);
600 void ff_mpeg4_init_partitions(MpegEncContext *s); 635 void ff_mpeg4_init_partitions(MpegEncContext *s);
601 void ff_mpeg4_merge_partitions(MpegEncContext *s); 636 void ff_mpeg4_merge_partitions(MpegEncContext *s);
602 extern inline int ff_mpeg4_pred_dc(MpegEncContext * s, int n, UINT16 **dc_val_ptr, int *dir_ptr);
603 void ff_clean_mpeg4_qscales(MpegEncContext *s); 637 void ff_clean_mpeg4_qscales(MpegEncContext *s);
604 void ff_clean_h263_qscales(MpegEncContext *s); 638 void ff_clean_h263_qscales(MpegEncContext *s);
639 int ff_mpeg4_decode_partitions(MpegEncContext *s);
640 int ff_mpeg4_get_video_packet_prefix_length(MpegEncContext *s);
641 int ff_h263_resync(MpegEncContext *s);
642 int ff_h263_get_gob_height(MpegEncContext *s);
643
605 644
606 /* rv10.c */ 645 /* rv10.c */
607 void rv10_encode_picture_header(MpegEncContext *s, int picture_number); 646 void rv10_encode_picture_header(MpegEncContext *s, int picture_number);
608 int rv_decode_dc(MpegEncContext *s, int n); 647 int rv_decode_dc(MpegEncContext *s, int n);
648
609 649
610 /* msmpeg4.c */ 650 /* msmpeg4.c */
611 void msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number); 651 void msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number);
612 void msmpeg4_encode_ext_header(MpegEncContext * s); 652 void msmpeg4_encode_ext_header(MpegEncContext * s);
613 void msmpeg4_encode_mb(MpegEncContext * s, 653 void msmpeg4_encode_mb(MpegEncContext * s,
614 DCTELEM block[6][64], 654 DCTELEM block[6][64],
615 int motion_x, int motion_y); 655 int motion_x, int motion_y);
616 int msmpeg4_decode_picture_header(MpegEncContext * s); 656 int msmpeg4_decode_picture_header(MpegEncContext * s);
617 int msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size); 657 int msmpeg4_decode_ext_header(MpegEncContext * s, int buf_size);
618 int msmpeg4_decode_mb(MpegEncContext *s,
619 DCTELEM block[6][64]);
620 int ff_msmpeg4_decode_init(MpegEncContext *s); 658 int ff_msmpeg4_decode_init(MpegEncContext *s);
621 void ff_msmpeg4_encode_init(MpegEncContext *s); 659 void ff_msmpeg4_encode_init(MpegEncContext *s);
622 660
661
623 /* mjpegenc.c */ 662 /* mjpegenc.c */
624
625 int mjpeg_init(MpegEncContext *s); 663 int mjpeg_init(MpegEncContext *s);
626 void mjpeg_close(MpegEncContext *s); 664 void mjpeg_close(MpegEncContext *s);
627 void mjpeg_encode_mb(MpegEncContext *s, 665 void mjpeg_encode_mb(MpegEncContext *s,
628 DCTELEM block[6][64]); 666 DCTELEM block[6][64]);
629 void mjpeg_picture_header(MpegEncContext *s); 667 void mjpeg_picture_header(MpegEncContext *s);
630 void mjpeg_picture_trailer(MpegEncContext *s); 668 void mjpeg_picture_trailer(MpegEncContext *s);
669
631 670
632 /* rate control */ 671 /* rate control */
633 int ff_rate_control_init(MpegEncContext *s); 672 int ff_rate_control_init(MpegEncContext *s);
634 float ff_rate_estimate_qscale(MpegEncContext *s); 673 float ff_rate_estimate_qscale(MpegEncContext *s);
635 void ff_write_pass1_stats(MpegEncContext *s); 674 void ff_write_pass1_stats(MpegEncContext *s);