41 |
* * |
* * |
42 |
* Revision history: * |
* Revision history: * |
43 |
* * |
* * |
44 |
|
* 26.03.2002 interlacing support |
45 |
* 03.03.2002 qmatrix writing * |
* 03.03.2002 qmatrix writing * |
46 |
* 03.03.2002 merged BITREADER and BITWRITER * |
* 03.03.2002 merged BITREADER and BITWRITER * |
47 |
* 30.02.2002 intra_dc_threshold support * |
* 30.02.2002 intra_dc_threshold support * |
53 |
|
|
54 |
#include "bitstream.h" |
#include "bitstream.h" |
55 |
#include "zigzag.h" |
#include "zigzag.h" |
56 |
|
#include "../quant/quant_matrix.h" |
57 |
|
|
58 |
static int __inline log2bin(int value) |
static int __inline log2bin(int value) |
59 |
{ |
{ |
80 |
}; |
}; |
81 |
|
|
82 |
|
|
83 |
|
void bs_get_matrix(Bitstream * bs, uint8_t * matrix) |
84 |
|
{ |
85 |
|
int i = 0; |
86 |
|
int last, value = 0; |
87 |
|
|
88 |
|
do |
89 |
|
{ |
90 |
|
last = value; |
91 |
|
value = BitstreamGetBits(bs, 8); |
92 |
|
matrix[ scan_tables[0][i++] ] = value; |
93 |
|
} |
94 |
|
while (value != 0 && i < 64); |
95 |
|
|
96 |
|
while (i < 64) |
97 |
|
{ |
98 |
|
matrix[ scan_tables[0][i++] ] = last; |
99 |
|
} |
100 |
|
} |
101 |
|
|
102 |
/* |
/* |
103 |
decode headers |
decode headers |
104 |
returns coding_type, or -1 if error |
returns coding_type, or -1 if error |
284 |
|
|
285 |
} |
} |
286 |
|
|
287 |
if (BitstreamGetBit(bs)) // interlaced |
if (dec->interlacing = BitstreamGetBit(bs)) |
288 |
{ |
{ |
289 |
DEBUG("TODO: interlaced"); |
DEBUG("vol: interlacing"); |
|
// TODO |
|
|
return -1; |
|
290 |
} |
} |
291 |
|
|
292 |
if (!BitstreamGetBit(bs)) // obmc_disable |
if (!BitstreamGetBit(bs)) // obmc_disable |
332 |
{ |
{ |
333 |
if (BitstreamGetBit(bs)) // load_intra_quant_mat |
if (BitstreamGetBit(bs)) // load_intra_quant_mat |
334 |
{ |
{ |
335 |
DEBUG("TODO: load_intra_quant_mat"); |
uint8_t matrix[64]; |
336 |
// TODO |
bs_get_matrix(bs, matrix); |
337 |
return -1; |
set_intra_matrix(matrix); |
338 |
} |
} |
339 |
|
else |
340 |
|
set_intra_matrix(get_default_intra_matrix()); |
341 |
|
|
342 |
if (BitstreamGetBit(bs)) // load_inter_quant_mat |
if (BitstreamGetBit(bs)) // load_inter_quant_mat |
343 |
{ |
{ |
344 |
DEBUG("TODO: load_inter_quant_mat"); |
uint8_t matrix[64]; |
345 |
// TODO |
bs_get_matrix(bs, matrix); |
346 |
return -1; |
set_inter_matrix(matrix); |
347 |
} |
} |
348 |
|
else |
349 |
|
set_inter_matrix(get_default_inter_matrix()); |
350 |
|
|
351 |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) |
352 |
{ |
{ |
354 |
DEBUG("TODO: grayscale matrix stuff"); |
DEBUG("TODO: grayscale matrix stuff"); |
355 |
return -1; |
return -1; |
356 |
} |
} |
357 |
|
|
358 |
} |
} |
359 |
|
|
360 |
|
|
516 |
// intra_dc_vlc_threshold |
// intra_dc_vlc_threshold |
517 |
*intra_dc_threshold = intra_dc_threshold_table[ BitstreamGetBits(bs,3) ]; |
*intra_dc_threshold = intra_dc_threshold_table[ BitstreamGetBits(bs,3) ]; |
518 |
|
|
519 |
/* if (interlaced) |
if (dec->interlacing) |
520 |
{ |
{ |
521 |
BitstreamSkip(bs, 1); // top_field_first |
if (dec->top_field_first = BitstreamGetBit(bs)) |
522 |
BitstreamSkip(bs, 1); // alternative_vertical_scan_flag |
{ |
523 |
*/ |
DEBUG("vop: top_field_first"); |
524 |
|
} |
525 |
|
if (dec->alternate_vertical_scan = BitstreamGetBit(bs)) |
526 |
|
{ |
527 |
|
DEBUG("vop: alternate_vertical_scan"); |
528 |
|
} |
529 |
|
} |
530 |
} |
} |
531 |
|
|
532 |
*quant = BitstreamGetBits(bs, dec->quant_bits); // vop_quant |
*quant = BitstreamGetBits(bs, dec->quant_bits); // vop_quant |
589 |
write vol header |
write vol header |
590 |
*/ |
*/ |
591 |
void BitstreamWriteVolHeader(Bitstream * const bs, |
void BitstreamWriteVolHeader(Bitstream * const bs, |
592 |
const int width, |
const MBParam * pParam) |
|
const int height, |
|
|
const int quant_type) |
|
593 |
{ |
{ |
594 |
// video object_start_code & vo_id |
// video object_start_code & vo_id |
595 |
BitstreamPad(bs); |
BitstreamPad(bs); |
625 |
// BitstreamPutBits(bs, 0, 15); |
// BitstreamPutBits(bs, 0, 15); |
626 |
|
|
627 |
WRITE_MARKER(); |
WRITE_MARKER(); |
628 |
BitstreamPutBits(bs, width, 13); // width |
BitstreamPutBits(bs, pParam->width, 13); // width |
629 |
WRITE_MARKER(); |
WRITE_MARKER(); |
630 |
BitstreamPutBits(bs, height, 13); // height |
BitstreamPutBits(bs, pParam->height, 13); // height |
631 |
WRITE_MARKER(); |
WRITE_MARKER(); |
632 |
|
|
633 |
BitstreamPutBit(bs, 0); // interlace |
BitstreamPutBit(bs, pParam->global_flags & XVID_INTERLACING); // interlace |
634 |
BitstreamPutBit(bs, 1); // obmc_disable (overlapped block motion compensation) |
BitstreamPutBit(bs, 1); // obmc_disable (overlapped block motion compensation) |
635 |
BitstreamPutBit(bs, 0); // sprite_enable |
BitstreamPutBit(bs, 0); // sprite_enable |
636 |
BitstreamPutBit(bs, 0); // not_in_bit |
BitstreamPutBit(bs, 0); // not_in_bit |
637 |
|
|
638 |
// quant_type 0=h.263 1=mpeg4(quantizer tables) |
// quant_type 0=h.263 1=mpeg4(quantizer tables) |
639 |
BitstreamPutBit(bs, quant_type); |
BitstreamPutBit(bs, pParam->quant_type); |
640 |
/* |
|
641 |
if (quant_type) |
if (pParam->quant_type) |
642 |
{ |
{ |
643 |
BitstreamPutBit(bs, qmatrix->custom_intra); // load_intra_quant_mat |
BitstreamPutBit(bs, get_intra_matrix_status()); // load_intra_quant_mat |
644 |
if (qmatrix->custom_intra) |
if (get_intra_matrix_status()) |
645 |
{ |
{ |
646 |
bs_put_matrix(bs, qmatrix->intra); |
bs_put_matrix(bs, get_intra_matrix()); |
647 |
} |
} |
648 |
|
|
649 |
BitstreamPutBit(bs, qmatrix->custom_inter); // load_inter_quant_mat |
BitstreamPutBit(bs, get_inter_matrix_status()); // load_inter_quant_mat |
650 |
if (qmatrix->custom_inter) |
if (get_inter_matrix_status()) |
651 |
{ |
{ |
652 |
bs_put_matrix(bs, qmatrix->inter); |
bs_put_matrix(bs, get_inter_matrix()); |
653 |
} |
} |
654 |
|
|
655 |
} |
} |
|
*/ |
|
|
if (quant_type) |
|
|
{ |
|
|
BitstreamPutBit(bs, 0); // load_intra_quant_mat |
|
|
BitstreamPutBit(bs, 0); // load_inter_quant_mat |
|
|
} |
|
656 |
|
|
657 |
BitstreamPutBit(bs, 1); // complexity_estimation_disable |
BitstreamPutBit(bs, 1); // complexity_estimation_disable |
658 |
BitstreamPutBit(bs, 1); // resync_marker_disable |
BitstreamPutBit(bs, 1); // resync_marker_disable |
670 |
(decoder uses these values to determine precise time since last resync) |
(decoder uses these values to determine precise time since last resync) |
671 |
*/ |
*/ |
672 |
void BitstreamWriteVopHeader(Bitstream * const bs, |
void BitstreamWriteVopHeader(Bitstream * const bs, |
673 |
VOP_TYPE prediction_type, |
const MBParam * pParam) |
|
const int rounding_type, |
|
|
const uint32_t quant, |
|
|
const uint32_t fcode) |
|
674 |
{ |
{ |
675 |
BitstreamPad(bs); |
BitstreamPad(bs); |
676 |
BitstreamPutBits(bs, VOP_START_CODE, 32); |
BitstreamPutBits(bs, VOP_START_CODE, 32); |
677 |
|
|
678 |
BitstreamPutBits(bs, prediction_type, 2); |
BitstreamPutBits(bs, pParam->coding_type, 2); |
679 |
|
|
680 |
// time_base = 0 write n x PutBit(1), PutBit(0) |
// time_base = 0 write n x PutBit(1), PutBit(0) |
681 |
BitstreamPutBits(bs, 0, 1); |
BitstreamPutBits(bs, 0, 1); |
689 |
|
|
690 |
BitstreamPutBits(bs, 1, 1); // vop_coded |
BitstreamPutBits(bs, 1, 1); // vop_coded |
691 |
|
|
692 |
if (prediction_type != I_VOP) |
if (pParam->coding_type != I_VOP) |
693 |
BitstreamPutBits(bs, rounding_type, 1); |
BitstreamPutBits(bs, pParam->rounding_type, 1); |
694 |
|
|
695 |
BitstreamPutBits(bs, 0, 3); // intra_dc_vlc_threshold |
BitstreamPutBits(bs, 0, 3); // intra_dc_vlc_threshold |
696 |
|
|
697 |
BitstreamPutBits(bs, quant, 5); // quantizer |
if (pParam->global_flags & XVID_INTERLACING) |
698 |
|
{ |
699 |
|
BitstreamPutBit(bs, 1); // top field first |
700 |
|
BitstreamPutBit(bs, 0); // alternate vertical scan |
701 |
|
} |
702 |
|
|
703 |
|
BitstreamPutBits(bs, pParam->quant, 5); // quantizer |
704 |
|
|
705 |
if (prediction_type != I_VOP) |
if (pParam->coding_type != I_VOP) |
706 |
BitstreamPutBits(bs, fcode, 3); // fixed_code = [1,4] |
BitstreamPutBits(bs, pParam->fixed_code, 3); // fixed_code = [1,4] |
707 |
} |
} |