121 |
matrix[scan_tables[0][i++]] = value; |
matrix[scan_tables[0][i++]] = value; |
122 |
} |
} |
123 |
while (value != 0 && i < 64); |
while (value != 0 && i < 64); |
124 |
i--; // fix little bug at coeff not full |
i--; /* fix little bug at coeff not full */ |
125 |
|
|
126 |
while (i < 64) { |
while (i < 64) { |
127 |
matrix[scan_tables[0][i++]] = last; |
matrix[scan_tables[0][i++]] = last; |
130 |
|
|
131 |
|
|
132 |
|
|
133 |
// for PVOP addbits == fcode - 1 |
/* |
134 |
// for BVOP addbits == max(fcode,bcode) - 1 |
* for PVOP addbits == fcode - 1 |
135 |
// returns mbpos |
* for BVOP addbits == max(fcode,bcode) - 1 |
136 |
|
* returns mbpos |
137 |
|
*/ |
138 |
int |
int |
139 |
read_video_packet_header(Bitstream *bs, |
read_video_packet_header(Bitstream *bs, |
140 |
DECODER * dec, |
DECODER * dec, |
214 |
if (dec->sprite_enable == SPRITE_GMC && coding_type == S_VOP && |
if (dec->sprite_enable == SPRITE_GMC && coding_type == S_VOP && |
215 |
dec->sprite_warping_points > 0) |
dec->sprite_warping_points > 0) |
216 |
{ |
{ |
217 |
// TODO: sprite trajectory |
/* TODO: sprite trajectory */ |
218 |
} |
} |
219 |
if (dec->reduced_resolution_enable && |
if (dec->reduced_resolution_enable && |
220 |
dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR && |
dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR && |
454 |
|
|
455 |
DPRINTF(XVID_DEBUG_STARTCODE, "<visual_object_sequence>\n"); |
DPRINTF(XVID_DEBUG_STARTCODE, "<visual_object_sequence>\n"); |
456 |
|
|
457 |
BitstreamSkip(bs, 32); // visual_object_sequence_start_code |
BitstreamSkip(bs, 32); /* visual_object_sequence_start_code */ |
458 |
profile = BitstreamGetBits(bs, 8); // profile_and_level_indication |
profile = BitstreamGetBits(bs, 8); /* profile_and_level_indication */ |
459 |
|
|
460 |
DPRINTF(XVID_DEBUG_HEADER, "profile_and_level_indication %i\n", profile); |
DPRINTF(XVID_DEBUG_HEADER, "profile_and_level_indication %i\n", profile); |
461 |
|
|
462 |
} else if (start_code == VISOBJSEQ_STOP_CODE) { |
} else if (start_code == VISOBJSEQ_STOP_CODE) { |
463 |
|
|
464 |
BitstreamSkip(bs, 32); // visual_object_sequence_stop_code |
BitstreamSkip(bs, 32); /* visual_object_sequence_stop_code */ |
465 |
|
|
466 |
DPRINTF(XVID_DEBUG_STARTCODE, "</visual_object_sequence>\n"); |
DPRINTF(XVID_DEBUG_STARTCODE, "</visual_object_sequence>\n"); |
467 |
|
|
470 |
|
|
471 |
DPRINTF(XVID_DEBUG_STARTCODE, "<visual_object>\n"); |
DPRINTF(XVID_DEBUG_STARTCODE, "<visual_object>\n"); |
472 |
|
|
473 |
BitstreamSkip(bs, 32); // visual_object_start_code |
BitstreamSkip(bs, 32); /* visual_object_start_code */ |
474 |
if (BitstreamGetBit(bs)) // is_visual_object_identified |
if (BitstreamGetBit(bs)) /* is_visual_object_identified */ |
475 |
{ |
{ |
476 |
visobj_ver_id = BitstreamGetBits(bs, 4); // visual_object_ver_id |
visobj_ver_id = BitstreamGetBits(bs, 4); /* visual_object_ver_id */ |
477 |
DPRINTF(XVID_DEBUG_HEADER,"visobj_ver_id %i\n", visobj_ver_id); |
DPRINTF(XVID_DEBUG_HEADER,"visobj_ver_id %i\n", visobj_ver_id); |
478 |
BitstreamSkip(bs, 3); // visual_object_priority |
BitstreamSkip(bs, 3); /* visual_object_priority */ |
479 |
} else { |
} else { |
480 |
visobj_ver_id = 1; |
visobj_ver_id = 1; |
481 |
} |
} |
482 |
|
|
483 |
if (BitstreamShowBits(bs, 4) != VISOBJ_TYPE_VIDEO) // visual_object_type |
if (BitstreamShowBits(bs, 4) != VISOBJ_TYPE_VIDEO) /* visual_object_type */ |
484 |
{ |
{ |
485 |
DPRINTF(XVID_DEBUG_ERROR, "visual_object_type != video\n"); |
DPRINTF(XVID_DEBUG_ERROR, "visual_object_type != video\n"); |
486 |
return -1; |
return -1; |
487 |
} |
} |
488 |
BitstreamSkip(bs, 4); |
BitstreamSkip(bs, 4); |
489 |
|
|
490 |
// video_signal_type |
/* video_signal_type */ |
491 |
|
|
492 |
if (BitstreamGetBit(bs)) // video_signal_type |
if (BitstreamGetBit(bs)) /* video_signal_type */ |
493 |
{ |
{ |
494 |
DPRINTF(XVID_DEBUG_HEADER,"+ video_signal_type\n"); |
DPRINTF(XVID_DEBUG_HEADER,"+ video_signal_type\n"); |
495 |
BitstreamSkip(bs, 3); // video_format |
BitstreamSkip(bs, 3); /* video_format */ |
496 |
BitstreamSkip(bs, 1); // video_range |
BitstreamSkip(bs, 1); /* video_range */ |
497 |
if (BitstreamGetBit(bs)) // color_description |
if (BitstreamGetBit(bs)) /* color_description */ |
498 |
{ |
{ |
499 |
DPRINTF(XVID_DEBUG_HEADER,"+ color_description"); |
DPRINTF(XVID_DEBUG_HEADER,"+ color_description"); |
500 |
BitstreamSkip(bs, 8); // color_primaries |
BitstreamSkip(bs, 8); /* color_primaries */ |
501 |
BitstreamSkip(bs, 8); // transfer_characteristics |
BitstreamSkip(bs, 8); /* transfer_characteristics */ |
502 |
BitstreamSkip(bs, 8); // matrix_coefficients |
BitstreamSkip(bs, 8); /* matrix_coefficients */ |
503 |
} |
} |
504 |
} |
} |
505 |
} else if ((start_code & ~VIDOBJ_START_CODE_MASK) == VIDOBJ_START_CODE) { |
} else if ((start_code & ~VIDOBJ_START_CODE_MASK) == VIDOBJ_START_CODE) { |
507 |
DPRINTF(XVID_DEBUG_STARTCODE, "<video_object>\n"); |
DPRINTF(XVID_DEBUG_STARTCODE, "<video_object>\n"); |
508 |
DPRINTF(XVID_DEBUG_HEADER, "vo id %i\n", start_code & VIDOBJ_START_CODE_MASK); |
DPRINTF(XVID_DEBUG_HEADER, "vo id %i\n", start_code & VIDOBJ_START_CODE_MASK); |
509 |
|
|
510 |
BitstreamSkip(bs, 32); // video_object_start_code |
BitstreamSkip(bs, 32); /* video_object_start_code */ |
511 |
|
|
512 |
} else if ((start_code & ~VIDOBJLAY_START_CODE_MASK) == VIDOBJLAY_START_CODE) { |
} else if ((start_code & ~VIDOBJLAY_START_CODE_MASK) == VIDOBJLAY_START_CODE) { |
513 |
|
|
514 |
DPRINTF(XVID_DEBUG_STARTCODE, "<video_object_layer>\n"); |
DPRINTF(XVID_DEBUG_STARTCODE, "<video_object_layer>\n"); |
515 |
DPRINTF(XVID_DEBUG_HEADER, "vol id %i\n", start_code & VIDOBJLAY_START_CODE_MASK); |
DPRINTF(XVID_DEBUG_HEADER, "vol id %i\n", start_code & VIDOBJLAY_START_CODE_MASK); |
516 |
|
|
517 |
BitstreamSkip(bs, 32); // video_object_layer_start_code |
BitstreamSkip(bs, 32); /* video_object_layer_start_code */ |
518 |
BitstreamSkip(bs, 1); // random_accessible_vol |
BitstreamSkip(bs, 1); /* random_accessible_vol */ |
519 |
|
|
520 |
BitstreamSkip(bs, 8); // video_object_type_indication |
BitstreamSkip(bs, 8); /* video_object_type_indication */ |
521 |
|
|
522 |
if (BitstreamGetBit(bs)) // is_object_layer_identifier |
if (BitstreamGetBit(bs)) /* is_object_layer_identifier */ |
523 |
{ |
{ |
524 |
DPRINTF(XVID_DEBUG_HEADER, "+ is_object_layer_identifier\n"); |
DPRINTF(XVID_DEBUG_HEADER, "+ is_object_layer_identifier\n"); |
525 |
vol_ver_id = BitstreamGetBits(bs, 4); // video_object_layer_verid |
vol_ver_id = BitstreamGetBits(bs, 4); /* video_object_layer_verid */ |
526 |
DPRINTF(XVID_DEBUG_HEADER,"ver_id %i\n", vol_ver_id); |
DPRINTF(XVID_DEBUG_HEADER,"ver_id %i\n", vol_ver_id); |
527 |
BitstreamSkip(bs, 3); // video_object_layer_priority |
BitstreamSkip(bs, 3); /* video_object_layer_priority */ |
528 |
} else { |
} else { |
529 |
vol_ver_id = 1; |
vol_ver_id = 1; |
530 |
} |
} |
531 |
|
|
532 |
dec->aspect_ratio = BitstreamGetBits(bs, 4); |
dec->aspect_ratio = BitstreamGetBits(bs, 4); |
533 |
|
|
534 |
if (dec->aspect_ratio == VIDOBJLAY_AR_EXTPAR) // aspect_ratio_info |
if (dec->aspect_ratio == VIDOBJLAY_AR_EXTPAR) /* aspect_ratio_info */ |
535 |
{ |
{ |
536 |
DPRINTF(XVID_DEBUG_HEADER, "+ aspect_ratio_info\n"); |
DPRINTF(XVID_DEBUG_HEADER, "+ aspect_ratio_info\n"); |
537 |
dec->par_width = BitstreamGetBits(bs, 8); // par_width |
dec->par_width = BitstreamGetBits(bs, 8); /* par_width */ |
538 |
dec->par_height = BitstreamGetBits(bs, 8); // par_height |
dec->par_height = BitstreamGetBits(bs, 8); /* par_height */ |
539 |
} |
} |
540 |
|
|
541 |
if (BitstreamGetBit(bs)) // vol_control_parameters |
if (BitstreamGetBit(bs)) /* vol_control_parameters */ |
542 |
{ |
{ |
543 |
DPRINTF(XVID_DEBUG_HEADER, "+ vol_control_parameters\n"); |
DPRINTF(XVID_DEBUG_HEADER, "+ vol_control_parameters\n"); |
544 |
BitstreamSkip(bs, 2); // chroma_format |
BitstreamSkip(bs, 2); /* chroma_format */ |
545 |
dec->low_delay = BitstreamGetBit(bs); // low_delay |
dec->low_delay = BitstreamGetBit(bs); /* low_delay */ |
546 |
DPRINTF(XVID_DEBUG_HEADER, "low_delay %i\n", dec->low_delay); |
DPRINTF(XVID_DEBUG_HEADER, "low_delay %i\n", dec->low_delay); |
547 |
if (BitstreamGetBit(bs)) // vbv_parameters |
if (BitstreamGetBit(bs)) /* vbv_parameters */ |
548 |
{ |
{ |
549 |
unsigned int bitrate; |
unsigned int bitrate; |
550 |
unsigned int buffer_size; |
unsigned int buffer_size; |
552 |
|
|
553 |
DPRINTF(XVID_DEBUG_HEADER,"+ vbv_parameters\n"); |
DPRINTF(XVID_DEBUG_HEADER,"+ vbv_parameters\n"); |
554 |
|
|
555 |
bitrate = BitstreamGetBits(bs,15) << 15; // first_half_bit_rate |
bitrate = BitstreamGetBits(bs,15) << 15; /* first_half_bit_rate */ |
556 |
READ_MARKER(); |
READ_MARKER(); |
557 |
bitrate |= BitstreamGetBits(bs,15); // latter_half_bit_rate |
bitrate |= BitstreamGetBits(bs,15); /* latter_half_bit_rate */ |
558 |
READ_MARKER(); |
READ_MARKER(); |
559 |
|
|
560 |
buffer_size = BitstreamGetBits(bs, 15) << 3; // first_half_vbv_buffer_size |
buffer_size = BitstreamGetBits(bs, 15) << 3; /* first_half_vbv_buffer_size */ |
561 |
READ_MARKER(); |
READ_MARKER(); |
562 |
buffer_size |= BitstreamGetBits(bs, 3); // latter_half_vbv_buffer_size |
buffer_size |= BitstreamGetBits(bs, 3); /* latter_half_vbv_buffer_size */ |
563 |
|
|
564 |
occupancy = BitstreamGetBits(bs, 11) << 15; // first_half_vbv_occupancy |
occupancy = BitstreamGetBits(bs, 11) << 15; /* first_half_vbv_occupancy */ |
565 |
READ_MARKER(); |
READ_MARKER(); |
566 |
occupancy |= BitstreamGetBits(bs, 15); // latter_half_vbv_occupancy |
occupancy |= BitstreamGetBits(bs, 15); /* latter_half_vbv_occupancy */ |
567 |
READ_MARKER(); |
READ_MARKER(); |
568 |
|
|
569 |
DPRINTF(XVID_DEBUG_HEADER,"bitrate %d (unit=400 bps)\n", bitrate); |
DPRINTF(XVID_DEBUG_HEADER,"bitrate %d (unit=400 bps)\n", bitrate); |
574 |
dec->low_delay = dec->low_delay_default; |
dec->low_delay = dec->low_delay_default; |
575 |
} |
} |
576 |
|
|
577 |
dec->shape = BitstreamGetBits(bs, 2); // video_object_layer_shape |
dec->shape = BitstreamGetBits(bs, 2); /* video_object_layer_shape */ |
578 |
|
|
579 |
DPRINTF(XVID_DEBUG_HEADER, "shape %i\n", dec->shape); |
DPRINTF(XVID_DEBUG_HEADER, "shape %i\n", dec->shape); |
580 |
if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) |
if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) |
583 |
} |
} |
584 |
|
|
585 |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE && vol_ver_id != 1) { |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE && vol_ver_id != 1) { |
586 |
BitstreamSkip(bs, 4); // video_object_layer_shape_extension |
BitstreamSkip(bs, 4); /* video_object_layer_shape_extension */ |
587 |
} |
} |
588 |
|
|
589 |
READ_MARKER(); |
READ_MARKER(); |
590 |
|
|
591 |
// *************************** for decode B-frame time *********************** |
/********************** for decode B-frame time ***********************/ |
592 |
dec->time_inc_resolution = BitstreamGetBits(bs, 16); // vop_time_increment_resolution |
dec->time_inc_resolution = BitstreamGetBits(bs, 16); /* vop_time_increment_resolution */ |
593 |
DPRINTF(XVID_DEBUG_HEADER,"vop_time_increment_resolution %i\n", dec->time_inc_resolution); |
DPRINTF(XVID_DEBUG_HEADER,"vop_time_increment_resolution %i\n", dec->time_inc_resolution); |
594 |
|
|
595 |
// dec->time_inc_resolution--; |
#if 0 |
596 |
|
dec->time_inc_resolution--; |
597 |
|
#endif |
598 |
|
|
599 |
if (dec->time_inc_resolution > 0) { |
if (dec->time_inc_resolution > 0) { |
600 |
dec->time_inc_bits = log2bin(dec->time_inc_resolution-1); |
dec->time_inc_bits = log2bin(dec->time_inc_resolution-1); |
601 |
} else { |
} else { |
602 |
// dec->time_inc_bits = 0; |
#if 0 |
603 |
// for "old" xvid compatibility, set time_inc_bits = 1 |
dec->time_inc_bits = 0; |
604 |
|
#endif |
605 |
|
/* for "old" xvid compatibility, set time_inc_bits = 1 */ |
606 |
dec->time_inc_bits = 1; |
dec->time_inc_bits = 1; |
607 |
} |
} |
608 |
|
|
609 |
READ_MARKER(); |
READ_MARKER(); |
610 |
|
|
611 |
if (BitstreamGetBit(bs)) // fixed_vop_rate |
if (BitstreamGetBit(bs)) /* fixed_vop_rate */ |
612 |
{ |
{ |
613 |
DPRINTF(XVID_DEBUG_HEADER, "+ fixed_vop_rate\n"); |
DPRINTF(XVID_DEBUG_HEADER, "+ fixed_vop_rate\n"); |
614 |
BitstreamSkip(bs, dec->time_inc_bits); // fixed_vop_time_increment |
BitstreamSkip(bs, dec->time_inc_bits); /* fixed_vop_time_increment */ |
615 |
} |
} |
616 |
|
|
617 |
if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) { |
if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) { |
620 |
uint32_t width, height; |
uint32_t width, height; |
621 |
|
|
622 |
READ_MARKER(); |
READ_MARKER(); |
623 |
width = BitstreamGetBits(bs, 13); // video_object_layer_width |
width = BitstreamGetBits(bs, 13); /* video_object_layer_width */ |
624 |
READ_MARKER(); |
READ_MARKER(); |
625 |
height = BitstreamGetBits(bs, 13); // video_object_layer_height |
height = BitstreamGetBits(bs, 13); /* video_object_layer_height */ |
626 |
READ_MARKER(); |
READ_MARKER(); |
627 |
|
|
628 |
DPRINTF(XVID_DEBUG_HEADER, "width %i\n", width); |
DPRINTF(XVID_DEBUG_HEADER, "width %i\n", width); |
644 |
dec->interlacing = BitstreamGetBit(bs); |
dec->interlacing = BitstreamGetBit(bs); |
645 |
DPRINTF(XVID_DEBUG_HEADER, "interlacing %i\n", dec->interlacing); |
DPRINTF(XVID_DEBUG_HEADER, "interlacing %i\n", dec->interlacing); |
646 |
|
|
647 |
if (!BitstreamGetBit(bs)) // obmc_disable |
if (!BitstreamGetBit(bs)) /* obmc_disable */ |
648 |
{ |
{ |
649 |
DPRINTF(XVID_DEBUG_ERROR, "obmc_disabled==false not supported\n"); |
DPRINTF(XVID_DEBUG_ERROR, "obmc_disabled==false not supported\n"); |
650 |
// TODO |
/* TODO */ |
651 |
// fucking divx4.02 has this enabled |
/* fucking divx4.02 has this enabled */ |
652 |
} |
} |
653 |
|
|
654 |
dec->sprite_enable = BitstreamGetBits(bs, (vol_ver_id == 1 ? 1 : 2)); // sprite_enable |
dec->sprite_enable = BitstreamGetBits(bs, (vol_ver_id == 1 ? 1 : 2)); /* sprite_enable */ |
655 |
|
|
656 |
if (dec->sprite_enable == SPRITE_STATIC || dec->sprite_enable == SPRITE_GMC) |
if (dec->sprite_enable == SPRITE_STATIC || dec->sprite_enable == SPRITE_GMC) |
657 |
{ |
{ |
663 |
int sprite_height; |
int sprite_height; |
664 |
int sprite_left_coord; |
int sprite_left_coord; |
665 |
int sprite_top_coord; |
int sprite_top_coord; |
666 |
sprite_width = BitstreamGetBits(bs, 13); // sprite_width |
sprite_width = BitstreamGetBits(bs, 13); /* sprite_width */ |
667 |
READ_MARKER(); |
READ_MARKER(); |
668 |
sprite_height = BitstreamGetBits(bs, 13); // sprite_height |
sprite_height = BitstreamGetBits(bs, 13); /* sprite_height */ |
669 |
READ_MARKER(); |
READ_MARKER(); |
670 |
sprite_left_coord = BitstreamGetBits(bs, 13); // sprite_left_coordinate |
sprite_left_coord = BitstreamGetBits(bs, 13); /* sprite_left_coordinate */ |
671 |
READ_MARKER(); |
READ_MARKER(); |
672 |
sprite_top_coord = BitstreamGetBits(bs, 13); // sprite_top_coordinate |
sprite_top_coord = BitstreamGetBits(bs, 13); /* sprite_top_coordinate */ |
673 |
READ_MARKER(); |
READ_MARKER(); |
674 |
} |
} |
675 |
dec->sprite_warping_points = BitstreamGetBits(bs, 6); // no_of_sprite_warping_points |
dec->sprite_warping_points = BitstreamGetBits(bs, 6); /* no_of_sprite_warping_points */ |
676 |
dec->sprite_warping_accuracy = BitstreamGetBits(bs, 2); // sprite_warping_accuracy |
dec->sprite_warping_accuracy = BitstreamGetBits(bs, 2); /* sprite_warping_accuracy */ |
677 |
dec->sprite_brightness_change = BitstreamGetBits(bs, 1); // brightness_change |
dec->sprite_brightness_change = BitstreamGetBits(bs, 1); /* brightness_change */ |
678 |
if (dec->sprite_enable != SPRITE_GMC) |
if (dec->sprite_enable != SPRITE_GMC) |
679 |
{ |
{ |
680 |
low_latency_sprite_enable = BitstreamGetBits(bs, 1); // low_latency_sprite_enable |
low_latency_sprite_enable = BitstreamGetBits(bs, 1); /* low_latency_sprite_enable */ |
681 |
} |
} |
682 |
} |
} |
683 |
|
|
684 |
if (vol_ver_id != 1 && |
if (vol_ver_id != 1 && |
685 |
dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) { |
dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) { |
686 |
BitstreamSkip(bs, 1); // sadct_disable |
BitstreamSkip(bs, 1); /* sadct_disable */ |
687 |
} |
} |
688 |
|
|
689 |
if (BitstreamGetBit(bs)) // not_8_bit |
if (BitstreamGetBit(bs)) /* not_8_bit */ |
690 |
{ |
{ |
691 |
DPRINTF(XVID_DEBUG_HEADER, "not_8_bit==true (ignored)\n"); |
DPRINTF(XVID_DEBUG_HEADER, "not_8_bit==true (ignored)\n"); |
692 |
dec->quant_bits = BitstreamGetBits(bs, 4); // quant_precision |
dec->quant_bits = BitstreamGetBits(bs, 4); /* quant_precision */ |
693 |
BitstreamSkip(bs, 4); // bits_per_pixel |
BitstreamSkip(bs, 4); /* bits_per_pixel */ |
694 |
} else { |
} else { |
695 |
dec->quant_bits = 5; |
dec->quant_bits = 5; |
696 |
} |
} |
697 |
|
|
698 |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) { |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) { |
699 |
BitstreamSkip(bs, 1); // no_gray_quant_update |
BitstreamSkip(bs, 1); /* no_gray_quant_update */ |
700 |
BitstreamSkip(bs, 1); // composition_method |
BitstreamSkip(bs, 1); /* composition_method */ |
701 |
BitstreamSkip(bs, 1); // linear_composition |
BitstreamSkip(bs, 1); /* linear_composition */ |
702 |
} |
} |
703 |
|
|
704 |
dec->quant_type = BitstreamGetBit(bs); // quant_type |
dec->quant_type = BitstreamGetBit(bs); /* quant_type */ |
705 |
DPRINTF(XVID_DEBUG_HEADER, "quant_type %i\n", dec->quant_type); |
DPRINTF(XVID_DEBUG_HEADER, "quant_type %i\n", dec->quant_type); |
706 |
|
|
707 |
if (dec->quant_type) { |
if (dec->quant_type) { |
708 |
if (BitstreamGetBit(bs)) // load_intra_quant_mat |
if (BitstreamGetBit(bs)) /* load_intra_quant_mat */ |
709 |
{ |
{ |
710 |
uint8_t matrix[64]; |
uint8_t matrix[64]; |
711 |
|
|
716 |
} else |
} else |
717 |
set_intra_matrix(get_default_intra_matrix()); |
set_intra_matrix(get_default_intra_matrix()); |
718 |
|
|
719 |
if (BitstreamGetBit(bs)) // load_inter_quant_mat |
if (BitstreamGetBit(bs)) /* load_inter_quant_mat */ |
720 |
{ |
{ |
721 |
uint8_t matrix[64]; |
uint8_t matrix[64]; |
722 |
|
|
736 |
|
|
737 |
|
|
738 |
if (vol_ver_id != 1) { |
if (vol_ver_id != 1) { |
739 |
dec->quarterpel = BitstreamGetBit(bs); // quarter_sample |
dec->quarterpel = BitstreamGetBit(bs); /* quarter_sample */ |
740 |
DPRINTF(XVID_DEBUG_HEADER,"quarterpel %i\n", dec->quarterpel); |
DPRINTF(XVID_DEBUG_HEADER,"quarterpel %i\n", dec->quarterpel); |
741 |
} |
} |
742 |
else |
else |
749 |
read_vol_complexity_estimation_header(bs, dec); |
read_vol_complexity_estimation_header(bs, dec); |
750 |
} |
} |
751 |
|
|
752 |
BitstreamSkip(bs, 1); // resync_marker_disable |
BitstreamSkip(bs, 1); /* resync_marker_disable */ |
753 |
|
|
754 |
if (BitstreamGetBit(bs)) // data_partitioned |
if (BitstreamGetBit(bs)) /* data_partitioned */ |
755 |
{ |
{ |
756 |
DPRINTF(XVID_DEBUG_ERROR, "data_partitioned not supported\n"); |
DPRINTF(XVID_DEBUG_ERROR, "data_partitioned not supported\n"); |
757 |
BitstreamSkip(bs, 1); // reversible_vlc |
BitstreamSkip(bs, 1); /* reversible_vlc */ |
758 |
} |
} |
759 |
|
|
760 |
if (vol_ver_id != 1) { |
if (vol_ver_id != 1) { |
761 |
dec->newpred_enable = BitstreamGetBit(bs); |
dec->newpred_enable = BitstreamGetBit(bs); |
762 |
if (dec->newpred_enable) // newpred_enable |
if (dec->newpred_enable) /* newpred_enable */ |
763 |
{ |
{ |
764 |
DPRINTF(XVID_DEBUG_HEADER, "+ newpred_enable\n"); |
DPRINTF(XVID_DEBUG_HEADER, "+ newpred_enable\n"); |
765 |
BitstreamSkip(bs, 2); // requested_upstream_message_type |
BitstreamSkip(bs, 2); /* requested_upstream_message_type */ |
766 |
BitstreamSkip(bs, 1); // newpred_segment_type |
BitstreamSkip(bs, 1); /* newpred_segment_type */ |
767 |
} |
} |
768 |
dec->reduced_resolution_enable = BitstreamGetBit(bs); /* reduced_resolution_vop_enable */ |
dec->reduced_resolution_enable = BitstreamGetBit(bs); /* reduced_resolution_vop_enable */ |
769 |
DPRINTF(XVID_DEBUG_HEADER, "reduced_resolution_enable %i\n", dec->reduced_resolution_enable); |
DPRINTF(XVID_DEBUG_HEADER, "reduced_resolution_enable %i\n", dec->reduced_resolution_enable); |
796 |
} |
} |
797 |
return -1; |
return -1; |
798 |
} |
} |
799 |
} else // dec->shape == BINARY_ONLY |
} else /* dec->shape == BINARY_ONLY */ |
800 |
{ |
{ |
801 |
if (vol_ver_id != 1) { |
if (vol_ver_id != 1) { |
802 |
dec->scalability = BitstreamGetBit(bs); /* scalability */ |
dec->scalability = BitstreamGetBit(bs); /* scalability */ |
811 |
return -1; |
return -1; |
812 |
} |
} |
813 |
} |
} |
814 |
BitstreamSkip(bs, 1); // resync_marker_disable |
BitstreamSkip(bs, 1); /* resync_marker_disable */ |
815 |
|
|
816 |
} |
} |
817 |
|
|
832 |
|
|
833 |
DPRINTF(XVID_DEBUG_HEADER, "time %ih%im%is\n", hours,minutes,seconds); |
DPRINTF(XVID_DEBUG_HEADER, "time %ih%im%is\n", hours,minutes,seconds); |
834 |
} |
} |
835 |
BitstreamSkip(bs, 1); // closed_gov |
BitstreamSkip(bs, 1); /* closed_gov */ |
836 |
BitstreamSkip(bs, 1); // broken_link |
BitstreamSkip(bs, 1); /* broken_link */ |
837 |
|
|
838 |
} else if (start_code == VOP_START_CODE) { |
} else if (start_code == VOP_START_CODE) { |
839 |
|
|
840 |
DPRINTF(XVID_DEBUG_STARTCODE, "<vop>\n"); |
DPRINTF(XVID_DEBUG_STARTCODE, "<vop>\n"); |
841 |
|
|
842 |
BitstreamSkip(bs, 32); // vop_start_code |
BitstreamSkip(bs, 32); /* vop_start_code */ |
843 |
|
|
844 |
coding_type = BitstreamGetBits(bs, 2); // vop_coding_type |
coding_type = BitstreamGetBits(bs, 2); /* vop_coding_type */ |
845 |
DPRINTF(XVID_DEBUG_HEADER, "coding_type %i\n", coding_type); |
DPRINTF(XVID_DEBUG_HEADER, "coding_type %i\n", coding_type); |
846 |
|
|
847 |
// *************************** for decode B-frame time *********************** |
/*********************** for decode B-frame time ***********************/ |
848 |
while (BitstreamGetBit(bs) != 0) // time_base |
while (BitstreamGetBit(bs) != 0) /* time_base */ |
849 |
time_incr++; |
time_incr++; |
850 |
|
|
851 |
READ_MARKER(); |
READ_MARKER(); |
852 |
|
|
853 |
if (dec->time_inc_bits) { |
if (dec->time_inc_bits) { |
854 |
time_increment = (BitstreamGetBits(bs, dec->time_inc_bits)); // vop_time_increment |
time_increment = (BitstreamGetBits(bs, dec->time_inc_bits)); /* vop_time_increment */ |
855 |
} |
} |
856 |
|
|
857 |
DPRINTF(XVID_DEBUG_HEADER, "time_base %i\n", time_incr); |
DPRINTF(XVID_DEBUG_HEADER, "time_base %i\n", time_incr); |
866 |
dec->time_base += time_incr; |
dec->time_base += time_incr; |
867 |
dec->time = time_increment; |
dec->time = time_increment; |
868 |
|
|
869 |
/* dec->time_base * dec->time_inc_resolution + |
#if 0 |
870 |
|
dec->time_base * dec->time_inc_resolution + |
871 |
time_increment; |
time_increment; |
872 |
*/ dec->time_pp = (uint32_t) |
#endif |
873 |
|
dec->time_pp = (uint32_t) |
874 |
(dec->time_inc_resolution + dec->time - dec->last_non_b_time)%dec->time_inc_resolution; |
(dec->time_inc_resolution + dec->time - dec->last_non_b_time)%dec->time_inc_resolution; |
875 |
dec->last_non_b_time = dec->time; |
dec->last_non_b_time = dec->time; |
876 |
} else { |
} else { |
877 |
dec->time = time_increment; |
dec->time = time_increment; |
878 |
/* |
#if 0 |
879 |
(dec->last_time_base + |
(dec->last_time_base + |
880 |
time_incr) * dec->time_inc_resolution + time_increment; |
time_incr) * dec->time_inc_resolution + time_increment; |
881 |
*/ |
#endif |
882 |
dec->time_bp = (uint32_t) |
dec->time_bp = (uint32_t) |
883 |
(dec->time_inc_resolution + dec->last_non_b_time - dec->time)%dec->time_inc_resolution; |
(dec->time_inc_resolution + dec->last_non_b_time - dec->time)%dec->time_inc_resolution; |
884 |
} |
} |
887 |
|
|
888 |
READ_MARKER(); |
READ_MARKER(); |
889 |
|
|
890 |
if (!BitstreamGetBit(bs)) // vop_coded |
if (!BitstreamGetBit(bs)) /* vop_coded */ |
891 |
{ |
{ |
892 |
DPRINTF(XVID_DEBUG_HEADER, "vop_coded==false\n"); |
DPRINTF(XVID_DEBUG_HEADER, "vop_coded==false\n"); |
893 |
return N_VOP; |
return N_VOP; |
910 |
|
|
911 |
|
|
912 |
|
|
913 |
// fix a little bug by MinChen <chenm002@163.com> |
/* fix a little bug by MinChen <chenm002@163.com> */ |
914 |
if ((dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) && |
if ((dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) && |
915 |
( (coding_type == P_VOP) || (coding_type == S_VOP && dec->sprite_enable == SPRITE_GMC) ) ) { |
( (coding_type == P_VOP) || (coding_type == S_VOP && dec->sprite_enable == SPRITE_GMC) ) ) { |
916 |
*rounding = BitstreamGetBit(bs); // rounding_type |
*rounding = BitstreamGetBit(bs); /* rounding_type */ |
917 |
DPRINTF(XVID_DEBUG_HEADER, "rounding %i\n", *rounding); |
DPRINTF(XVID_DEBUG_HEADER, "rounding %i\n", *rounding); |
918 |
} |
} |
919 |
|
|
950 |
DPRINTF(XVID_DEBUG_HEADER, "vert_mc_ref %i\n", vert_mc_ref); |
DPRINTF(XVID_DEBUG_HEADER, "vert_mc_ref %i\n", vert_mc_ref); |
951 |
} |
} |
952 |
|
|
953 |
BitstreamSkip(bs, 1); // change_conv_ratio_disable |
BitstreamSkip(bs, 1); /* change_conv_ratio_disable */ |
954 |
if (BitstreamGetBit(bs)) // vop_constant_alpha |
if (BitstreamGetBit(bs)) /* vop_constant_alpha */ |
955 |
{ |
{ |
956 |
BitstreamSkip(bs, 8); // vop_constant_alpha_value |
BitstreamSkip(bs, 8); /* vop_constant_alpha_value */ |
957 |
} |
} |
958 |
} |
} |
959 |
|
|
964 |
read_vop_complexity_estimation_header(bs, dec, coding_type); |
read_vop_complexity_estimation_header(bs, dec, coding_type); |
965 |
} |
} |
966 |
|
|
967 |
// intra_dc_vlc_threshold |
/* intra_dc_vlc_threshold */ |
968 |
*intra_dc_threshold = |
*intra_dc_threshold = |
969 |
intra_dc_threshold_table[BitstreamGetBits(bs, 3)]; |
intra_dc_threshold_table[BitstreamGetBits(bs, 3)]; |
970 |
|
|
1014 |
|
|
1015 |
if (dec->sprite_brightness_change) |
if (dec->sprite_brightness_change) |
1016 |
{ |
{ |
1017 |
// XXX: brightness_change_factor() |
/* XXX: brightness_change_factor() */ |
1018 |
} |
} |
1019 |
if (dec->sprite_enable == SPRITE_STATIC) |
if (dec->sprite_enable == SPRITE_STATIC) |
1020 |
{ |
{ |
1021 |
// XXX: todo |
/* XXX: todo */ |
1022 |
} |
} |
1023 |
|
|
1024 |
} |
} |
1025 |
|
|
1026 |
if ((*quant = BitstreamGetBits(bs, dec->quant_bits)) < 1) // vop_quant |
if ((*quant = BitstreamGetBits(bs, dec->quant_bits)) < 1) /* vop_quant */ |
1027 |
*quant = 1; |
*quant = 1; |
1028 |
DPRINTF(XVID_DEBUG_HEADER, "quant %i\n", *quant); |
DPRINTF(XVID_DEBUG_HEADER, "quant %i\n", *quant); |
1029 |
|
|
1030 |
if (coding_type != I_VOP) { |
if (coding_type != I_VOP) { |
1031 |
*fcode_forward = BitstreamGetBits(bs, 3); // fcode_forward |
*fcode_forward = BitstreamGetBits(bs, 3); /* fcode_forward */ |
1032 |
DPRINTF(XVID_DEBUG_HEADER, "fcode_forward %i\n", *fcode_forward); |
DPRINTF(XVID_DEBUG_HEADER, "fcode_forward %i\n", *fcode_forward); |
1033 |
} |
} |
1034 |
|
|
1035 |
if (coding_type == B_VOP) { |
if (coding_type == B_VOP) { |
1036 |
*fcode_backward = BitstreamGetBits(bs, 3); // fcode_backward |
*fcode_backward = BitstreamGetBits(bs, 3); /* fcode_backward */ |
1037 |
DPRINTF(XVID_DEBUG_HEADER, "fcode_backward %i\n", *fcode_backward); |
DPRINTF(XVID_DEBUG_HEADER, "fcode_backward %i\n", *fcode_backward); |
1038 |
} |
} |
1039 |
if (!dec->scalability) { |
if (!dec->scalability) { |
1040 |
if ((dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) && |
if ((dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) && |
1041 |
(coding_type != I_VOP)) { |
(coding_type != I_VOP)) { |
1042 |
BitstreamSkip(bs, 1); // vop_shape_coding_type |
BitstreamSkip(bs, 1); /* vop_shape_coding_type */ |
1043 |
} |
} |
1044 |
} |
} |
1045 |
return coding_type; |
return coding_type; |
1049 |
int i, version, build; |
int i, version, build; |
1050 |
char packed; |
char packed; |
1051 |
|
|
1052 |
BitstreamSkip(bs, 32); // user_data_start_code |
BitstreamSkip(bs, 32); /* user_data_start_code */ |
1053 |
|
|
1054 |
tmp[0] = BitstreamShowBits(bs, 8); |
tmp[0] = BitstreamShowBits(bs, 8); |
1055 |
|
|
1076 |
version, build, dec->packed_mode); |
version, build, dec->packed_mode); |
1077 |
} |
} |
1078 |
|
|
1079 |
} else // start_code == ? |
} else /* start_code == ? */ |
1080 |
{ |
{ |
1081 |
if (BitstreamShowBits(bs, 24) == 0x000001) { |
if (BitstreamShowBits(bs, 24) == 0x000001) { |
1082 |
DPRINTF(XVID_DEBUG_STARTCODE, "<unknown: %x>\n", BitstreamShowBits(bs, 32)); |
DPRINTF(XVID_DEBUG_STARTCODE, "<unknown: %x>\n", BitstreamShowBits(bs, 32)); |
1086 |
} |
} |
1087 |
while ((BitstreamPos(bs) >> 3) < bs->length); |
while ((BitstreamPos(bs) >> 3) < bs->length); |
1088 |
|
|
1089 |
//DPRINTF("*** WARNING: no vop_start_code found"); |
#if 0 |
1090 |
|
DPRINTF("*** WARNING: no vop_start_code found"); |
1091 |
|
#endif |
1092 |
return -1; /* ignore it */ |
return -1; /* ignore it */ |
1093 |
} |
} |
1094 |
|
|
1140 |
vol_type_ind = VIDOBJLAY_TYPE_ASP; |
vol_type_ind = VIDOBJLAY_TYPE_ASP; |
1141 |
} |
} |
1142 |
|
|
1143 |
// visual_object_sequence_start_code |
/* visual_object_sequence_start_code */ |
1144 |
// BitstreamPad(bs); |
#if 0 |
1145 |
/* no padding here, anymore. You have to make sure that you are |
BitstreamPad(bs); |
1146 |
byte aligned, and that always 1-8 padding bits have been written */ |
#endif |
1147 |
|
|
1148 |
|
/* |
1149 |
|
* no padding here, anymore. You have to make sure that you are |
1150 |
|
* byte aligned, and that always 1-8 padding bits have been written |
1151 |
|
*/ |
1152 |
|
|
1153 |
if (pParam->profile) { |
if (pParam->profile) { |
1154 |
BitstreamPutBits(bs, VISOBJSEQ_START_CODE, 32); |
BitstreamPutBits(bs, VISOBJSEQ_START_CODE, 32); |
1155 |
BitstreamPutBits(bs, pParam->profile, 8); |
BitstreamPutBits(bs, pParam->profile, 8); |
1156 |
} |
} |
1157 |
|
|
1158 |
// visual_object_start_code |
/* visual_object_start_code */ |
1159 |
BitstreamPad(bs); |
BitstreamPad(bs); |
1160 |
BitstreamPutBits(bs, VISOBJ_START_CODE, 32); |
BitstreamPutBits(bs, VISOBJ_START_CODE, 32); |
1161 |
BitstreamPutBits(bs, 0, 1); // is_visual_object_identifier |
BitstreamPutBits(bs, 0, 1); /* is_visual_object_identifier */ |
1162 |
BitstreamPutBits(bs, VISOBJ_TYPE_VIDEO, 4); // visual_object_type |
BitstreamPutBits(bs, VISOBJ_TYPE_VIDEO, 4); /* visual_object_type */ |
1163 |
|
|
1164 |
// video object_start_code & vo_id |
/* video object_start_code & vo_id */ |
1165 |
BitstreamPad(bs); |
BitstreamPad(bs); |
1166 |
BitstreamPutBits(bs, VIDOBJ_START_CODE|(vo_id&0x5), 32); |
BitstreamPutBits(bs, VIDOBJ_START_CODE|(vo_id&0x5), 32); |
1167 |
|
|
1168 |
// video_object_layer_start_code & vol_id |
/* video_object_layer_start_code & vol_id */ |
1169 |
BitstreamPad(bs); |
BitstreamPad(bs); |
1170 |
BitstreamPutBits(bs, VIDOBJLAY_START_CODE|(vol_id&0x4), 32); |
BitstreamPutBits(bs, VIDOBJLAY_START_CODE|(vol_id&0x4), 32); |
1171 |
|
|
1172 |
BitstreamPutBit(bs, 0); // random_accessible_vol |
BitstreamPutBit(bs, 0); /* random_accessible_vol */ |
1173 |
BitstreamPutBits(bs, vol_type_ind, 8); // video_object_type_indication |
BitstreamPutBits(bs, vol_type_ind, 8); /* video_object_type_indication */ |
1174 |
|
|
1175 |
if (vol_ver_id == 1) |
if (vol_ver_id == 1) |
1176 |
{ |
{ |
1177 |
BitstreamPutBit(bs, 0); // is_object_layer_identified (0=not given) |
BitstreamPutBit(bs, 0); /* is_object_layer_identified (0=not given) */ |
1178 |
} |
} |
1179 |
else |
else |
1180 |
{ |
{ |
1181 |
BitstreamPutBit(bs, 1); // is_object_layer_identified |
BitstreamPutBit(bs, 1); /* is_object_layer_identified */ |
1182 |
BitstreamPutBits(bs, vol_ver_id, 4); // vol_ver_id == 2 |
BitstreamPutBits(bs, vol_ver_id, 4); /* vol_ver_id == 2 */ |
1183 |
BitstreamPutBits(bs, 4, 3); // vol_ver_priority (1==lowest, 7==highest) ?? |
BitstreamPutBits(bs, 4, 3); /* vol_ver_priority (1==lowest, 7==highest) ?? */ |
1184 |
} |
} |
1185 |
|
|
1186 |
BitstreamPutBits(bs, 1, 4); // aspect_ratio_info (1=1:1) |
BitstreamPutBits(bs, 1, 4); /* aspect_ratio_info (1=1:1) */ |
1187 |
|
|
1188 |
BitstreamPutBit(bs, 1); // vol_control_parameters |
BitstreamPutBit(bs, 1); /* vol_control_parameters */ |
1189 |
BitstreamPutBits(bs, 1, 2); // chroma_format 1="4:2:0" |
BitstreamPutBits(bs, 1, 2); /* chroma_format 1="4:2:0" */ |
1190 |
|
|
1191 |
if (pParam->max_bframes > 0) { |
if (pParam->max_bframes > 0) { |
1192 |
BitstreamPutBit(bs, 0); // low_delay |
BitstreamPutBit(bs, 0); /* low_delay */ |
1193 |
} else |
} else |
1194 |
{ |
{ |
1195 |
BitstreamPutBit(bs, 1); // low_delay |
BitstreamPutBit(bs, 1); /* low_delay */ |
1196 |
} |
} |
1197 |
BitstreamPutBit(bs, 0); // vbv_parameters (0=not given) |
BitstreamPutBit(bs, 0); /* vbv_parameters (0=not given) */ |
1198 |
|
|
1199 |
BitstreamPutBits(bs, 0, 2); // video_object_layer_shape (0=rectangular) |
BitstreamPutBits(bs, 0, 2); /* video_object_layer_shape (0=rectangular) */ |
1200 |
|
|
1201 |
WRITE_MARKER(); |
WRITE_MARKER(); |
1202 |
|
|
1203 |
/* time_inc_resolution; ignored by current decore versions |
/* |
1204 |
eg. 2fps res=2 inc=1 |
* time_inc_resolution; ignored by current decore versions |
1205 |
25fps res=25 inc=1 |
* eg. 2fps res=2 inc=1 |
1206 |
29.97fps res=30000 inc=1001 |
* 25fps res=25 inc=1 |
1207 |
|
* 29.97fps res=30000 inc=1001 |
1208 |
*/ |
*/ |
1209 |
BitstreamPutBits(bs, pParam->fbase, 16); |
BitstreamPutBits(bs, pParam->fbase, 16); |
1210 |
|
|
1211 |
WRITE_MARKER(); |
WRITE_MARKER(); |
1212 |
|
|
1213 |
if (pParam->fincr>0) { |
if (pParam->fincr>0) { |
1214 |
BitstreamPutBit(bs, 1); // fixed_vop_rate = 1 |
BitstreamPutBit(bs, 1); /* fixed_vop_rate = 1 */ |
1215 |
BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase)); // fixed_vop_time_increment |
BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase)); /* fixed_vop_time_increment */ |
1216 |
}else{ |
}else{ |
1217 |
BitstreamPutBit(bs, 0); // fixed_vop_rate = 0 |
BitstreamPutBit(bs, 0); /* fixed_vop_rate = 0 */ |
1218 |
} |
} |
1219 |
|
|
1220 |
WRITE_MARKER(); |
WRITE_MARKER(); |
1221 |
BitstreamPutBits(bs, pParam->width, 13); // width |
BitstreamPutBits(bs, pParam->width, 13); /* width */ |
1222 |
WRITE_MARKER(); |
WRITE_MARKER(); |
1223 |
BitstreamPutBits(bs, pParam->height, 13); // height |
BitstreamPutBits(bs, pParam->height, 13); /* height */ |
1224 |
WRITE_MARKER(); |
WRITE_MARKER(); |
1225 |
|
|
1226 |
BitstreamPutBit(bs, pParam->vol_flags & XVID_VOL_INTERLACING); // interlace |
BitstreamPutBit(bs, pParam->vol_flags & XVID_VOL_INTERLACING); /* interlace */ |
1227 |
BitstreamPutBit(bs, 1); // obmc_disable (overlapped block motion compensation) |
BitstreamPutBit(bs, 1); /* obmc_disable (overlapped block motion compensation) */ |
1228 |
|
|
1229 |
if (vol_ver_id != 1) |
if (vol_ver_id != 1) |
1230 |
{ if ((pParam->vol_flags & XVID_VOL_GMC)) |
{ if ((pParam->vol_flags & XVID_VOL_GMC)) |
1231 |
{ BitstreamPutBits(bs, 2, 2); // sprite_enable=='GMC' |
{ BitstreamPutBits(bs, 2, 2); /* sprite_enable=='GMC' */ |
1232 |
BitstreamPutBits(bs, 2, 6); // no_of_sprite_warping_points |
BitstreamPutBits(bs, 2, 6); /* no_of_sprite_warping_points */ |
1233 |
BitstreamPutBits(bs, 3, 2); // sprite_warping_accuracy 0==1/2, 1=1/4, 2=1/8, 3=1/16 |
BitstreamPutBits(bs, 3, 2); /* sprite_warping_accuracy 0==1/2, 1=1/4, 2=1/8, 3=1/16 */ |
1234 |
BitstreamPutBit(bs, 0); // sprite_brightness_change (not supported) |
BitstreamPutBit(bs, 0); /* sprite_brightness_change (not supported) */ |
1235 |
|
|
1236 |
/* currently we use no_of_sprite_warping_points==2, sprite_warping_accuracy==3 |
/* |
1237 |
for DivX5 compatability */ |
* currently we use no_of_sprite_warping_points==2, sprite_warping_accuracy==3 |
1238 |
|
* for DivX5 compatability |
1239 |
|
*/ |
1240 |
|
|
1241 |
} else |
} else |
1242 |
BitstreamPutBits(bs, 0, 2); // sprite_enable==off |
BitstreamPutBits(bs, 0, 2); /* sprite_enable==off */ |
1243 |
} |
} |
1244 |
else |
else |
1245 |
BitstreamPutBit(bs, 0); // sprite_enable==off |
BitstreamPutBit(bs, 0); /* sprite_enable==off */ |
1246 |
|
|
1247 |
BitstreamPutBit(bs, 0); // not_8_bit |
BitstreamPutBit(bs, 0); /* not_8_bit */ |
1248 |
|
|
1249 |
// quant_type 0=h.263 1=mpeg4(quantizer tables) |
/* quant_type 0=h.263 1=mpeg4(quantizer tables) */ |
1250 |
BitstreamPutBit(bs, pParam->vol_flags & XVID_VOL_MPEGQUANT); |
BitstreamPutBit(bs, pParam->vol_flags & XVID_VOL_MPEGQUANT); |
1251 |
|
|
1252 |
if ((pParam->vol_flags & XVID_VOL_MPEGQUANT)) { |
if ((pParam->vol_flags & XVID_VOL_MPEGQUANT)) { |
1253 |
BitstreamPutBit(bs, get_intra_matrix_status()); // load_intra_quant_mat |
BitstreamPutBit(bs, get_intra_matrix_status()); /* load_intra_quant_mat */ |
1254 |
if (get_intra_matrix_status()) { |
if (get_intra_matrix_status()) { |
1255 |
bs_put_matrix(bs, get_intra_matrix()); |
bs_put_matrix(bs, get_intra_matrix()); |
1256 |
} |
} |
1257 |
|
|
1258 |
BitstreamPutBit(bs, get_inter_matrix_status()); // load_inter_quant_mat |
BitstreamPutBit(bs, get_inter_matrix_status()); /* load_inter_quant_mat */ |
1259 |
if (get_inter_matrix_status()) { |
if (get_inter_matrix_status()) { |
1260 |
bs_put_matrix(bs, get_inter_matrix()); |
bs_put_matrix(bs, get_inter_matrix()); |
1261 |
} |
} |
1264 |
|
|
1265 |
if (vol_ver_id != 1) { |
if (vol_ver_id != 1) { |
1266 |
if ((pParam->vol_flags & XVID_VOL_QUARTERPEL)) |
if ((pParam->vol_flags & XVID_VOL_QUARTERPEL)) |
1267 |
BitstreamPutBit(bs, 1); // quarterpel |
BitstreamPutBit(bs, 1); /* quarterpel */ |
1268 |
else |
else |
1269 |
BitstreamPutBit(bs, 0); // no quarterpel |
BitstreamPutBit(bs, 0); /* no quarterpel */ |
1270 |
} |
} |
1271 |
|
|
1272 |
BitstreamPutBit(bs, 1); // complexity_estimation_disable |
BitstreamPutBit(bs, 1); /* complexity_estimation_disable */ |
1273 |
BitstreamPutBit(bs, 1); // resync_marker_disable |
BitstreamPutBit(bs, 1); /* resync_marker_disable */ |
1274 |
BitstreamPutBit(bs, 0); // data_partitioned |
BitstreamPutBit(bs, 0); /* data_partitioned */ |
1275 |
|
|
1276 |
if (vol_ver_id != 1) |
if (vol_ver_id != 1) |
1277 |
{ |
{ |
1278 |
BitstreamPutBit(bs, 0); // newpred_enable |
BitstreamPutBit(bs, 0); /* newpred_enable */ |
1279 |
|
|
1280 |
BitstreamPutBit(bs, (pParam->vol_flags & XVID_VOL_REDUCED_ENABLE)?1:0); |
BitstreamPutBit(bs, (pParam->vol_flags & XVID_VOL_REDUCED_ENABLE)?1:0); |
1281 |
/* reduced_resolution_vop_enabled */ |
/* reduced_resolution_vop_enabled */ |
1282 |
} |
} |
1283 |
|
|
1284 |
BitstreamPutBit(bs, 0); // scalability |
BitstreamPutBit(bs, 0); /* scalability */ |
1285 |
|
|
1286 |
/* fake divx5 id, to ensure compatibility with divx5 decoder */ |
/* fake divx5 id, to ensure compatibility with divx5 decoder */ |
1287 |
#define DIVX5_ID "DivX000b000p" |
#define DIVX5_ID "DivX000b000p" |
1307 |
{ |
{ |
1308 |
uint32_t i; |
uint32_t i; |
1309 |
|
|
1310 |
// BitstreamPad(bs); |
#if 0 |
1311 |
/* no padding here, anymore. You have to make sure that you are |
BitstreamPad(bs); |
1312 |
byte aligned, and that always 1-8 padding bits have been written */ |
#endif |
1313 |
|
|
1314 |
|
/* |
1315 |
|
* no padding here, anymore. You have to make sure that you are |
1316 |
|
* byte aligned, and that always 1-8 padding bits have been written |
1317 |
|
*/ |
1318 |
|
|
1319 |
BitstreamPutBits(bs, VOP_START_CODE, 32); |
BitstreamPutBits(bs, VOP_START_CODE, 32); |
1320 |
|
|
1321 |
BitstreamPutBits(bs, frame->coding_type, 2); |
BitstreamPutBits(bs, frame->coding_type, 2); |
1322 |
//DPRINTF(XVID_DEBUG_HEADER, "coding_type = %i\n", frame->coding_type); |
#if 0 |
1323 |
|
DPRINTF(XVID_DEBUG_HEADER, "coding_type = %i\n", frame->coding_type); |
1324 |
|
#endif |
1325 |
|
|
1326 |
for (i = 0; i < frame->seconds; i++) { |
for (i = 0; i < frame->seconds; i++) { |
1327 |
BitstreamPutBit(bs, 1); |
BitstreamPutBit(bs, 1); |
1330 |
|
|
1331 |
WRITE_MARKER(); |
WRITE_MARKER(); |
1332 |
|
|
1333 |
// time_increment: value=nth_of_sec, nbits = log2(resolution) |
/* time_increment: value=nth_of_sec, nbits = log2(resolution) */ |
1334 |
|
|
1335 |
BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase)); |
BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase)); |
1336 |
/*DPRINTF("[%i:%i] %c", frame->seconds, frame->ticks, |
#if 0 |
1337 |
frame->coding_type == I_VOP ? 'I' : frame->coding_type == |
DPRINTF("[%i:%i] %c", |
1338 |
P_VOP ? 'P' : 'B');*/ |
frame->seconds, frame->ticks, |
1339 |
|
frame->coding_type == I_VOP ? 'I' : |
1340 |
|
frame->coding_type == P_VOP ? 'P' : |
1341 |
|
frame->coding_type == S_VOP ? 'S' : 'B'); |
1342 |
|
#endif |
1343 |
|
|
1344 |
WRITE_MARKER(); |
WRITE_MARKER(); |
1345 |
|
|
1348 |
return; |
return; |
1349 |
} |
} |
1350 |
|
|
1351 |
BitstreamPutBits(bs, 1, 1); // vop_coded |
BitstreamPutBits(bs, 1, 1); /* vop_coded */ |
1352 |
|
|
1353 |
if ( (frame->coding_type == P_VOP) || (frame->coding_type == S_VOP) ) |
if ( (frame->coding_type == P_VOP) || (frame->coding_type == S_VOP) ) |
1354 |
BitstreamPutBits(bs, frame->rounding_type, 1); |
BitstreamPutBits(bs, frame->rounding_type, 1); |
1356 |
if ((frame->vol_flags & XVID_VOL_REDUCED_ENABLE)) |
if ((frame->vol_flags & XVID_VOL_REDUCED_ENABLE)) |
1357 |
BitstreamPutBit(bs, (frame->vop_flags & XVID_VOP_REDUCED)?1:0); |
BitstreamPutBit(bs, (frame->vop_flags & XVID_VOP_REDUCED)?1:0); |
1358 |
|
|
1359 |
BitstreamPutBits(bs, 0, 3); // intra_dc_vlc_threshold |
BitstreamPutBits(bs, 0, 3); /* intra_dc_vlc_threshold */ |
1360 |
|
|
1361 |
if ((frame->vol_flags & XVID_VOL_INTERLACING)) { |
if ((frame->vol_flags & XVID_VOL_INTERLACING)) { |
1362 |
BitstreamPutBit(bs, (frame->vop_flags & XVID_VOP_TOPFIELDFIRST)); |
BitstreamPutBit(bs, (frame->vop_flags & XVID_VOP_TOPFIELDFIRST)); |
1364 |
} |
} |
1365 |
|
|
1366 |
if (frame->coding_type == S_VOP) { |
if (frame->coding_type == S_VOP) { |
1367 |
if (1) { // no_of_sprite_warping_points>=1 (we use 2!) |
if (1) { /* no_of_sprite_warping_points>=1 (we use 2!) */ |
1368 |
int k; |
int k; |
1369 |
for (k=0;k<2;k++) |
for (k=0;k<2;k++) |
1370 |
{ |
{ |
1371 |
bs_put_spritetrajectory(bs, frame->warp.duv[k].x ); // du[k] |
bs_put_spritetrajectory(bs, frame->warp.duv[k].x ); /* du[k] */ |
1372 |
WRITE_MARKER(); |
WRITE_MARKER(); |
1373 |
|
|
1374 |
bs_put_spritetrajectory(bs, frame->warp.duv[k].y ); // dv[k] |
bs_put_spritetrajectory(bs, frame->warp.duv[k].y ); /* dv[k] */ |
1375 |
WRITE_MARKER(); |
WRITE_MARKER(); |
1376 |
|
|
1377 |
if ((frame->vol_flags & XVID_VOL_QUARTERPEL)) |
if ((frame->vol_flags & XVID_VOL_QUARTERPEL)) |
1387 |
} |
} |
1388 |
|
|
1389 |
|
|
1390 |
//DPRINTF(XVID_DEBUG_HEADER, "quant = %i\n", frame->quant); |
#if 0 |
1391 |
|
DPRINTF(XVID_DEBUG_HEADER, "quant = %i\n", frame->quant); |
1392 |
|
#endif |
1393 |
|
|
1394 |
BitstreamPutBits(bs, frame->quant, 5); // quantizer |
BitstreamPutBits(bs, frame->quant, 5); /* quantizer */ |
1395 |
|
|
1396 |
if (frame->coding_type != I_VOP) |
if (frame->coding_type != I_VOP) |
1397 |
BitstreamPutBits(bs, frame->fcode, 3); // forward_fixed_code |
BitstreamPutBits(bs, frame->fcode, 3); /* forward_fixed_code */ |
1398 |
|
|
1399 |
if (frame->coding_type == B_VOP) |
if (frame->coding_type == B_VOP) |
1400 |
BitstreamPutBits(bs, frame->bcode, 3); // backward_fixed_code |
BitstreamPutBits(bs, frame->bcode, 3); /* backward_fixed_code */ |
1401 |
|
|
1402 |
} |
} |
1403 |
|
|