41 |
* * |
* * |
42 |
* Revision history: * |
* Revision history: * |
43 |
* * |
* * |
44 |
|
* 19.06.2002 Fix a little bug in use custom quant matrix * |
45 |
|
* MinChen <chenm001@163.com> * |
46 |
|
* 08.05.2002 add low_delay support for B_VOP decode * |
47 |
|
* MinChen <chenm001@163.com> * |
48 |
|
* 06.05.2002 low_delay * |
49 |
* 06.05.2002 fixed fincr/fbase error * |
* 06.05.2002 fixed fincr/fbase error * |
50 |
* 01.05.2002 added BVOP support to BitstreamWriteVopHeader * |
* 01.05.2002 added BVOP support to BitstreamWriteVopHeader * |
51 |
* 15.04.2002 rewrite log2bin use asm386 By MinChen <chenm001@163.com> * |
* 15.04.2002 rewrite log2bin use asm386 By MinChen <chenm001@163.com> * |
55 |
* 30.02.2002 intra_dc_threshold support * |
* 30.02.2002 intra_dc_threshold support * |
56 |
* 04.12.2001 support for additional headers * |
* 04.12.2001 support for additional headers * |
57 |
* 16.12.2001 inital version * |
* 16.12.2001 inital version * |
58 |
* * |
* |
59 |
******************************************************************************/ |
******************************************************************************/ |
60 |
|
|
61 |
|
|
64 |
#include "../quant/quant_matrix.h" |
#include "../quant/quant_matrix.h" |
65 |
|
|
66 |
|
|
67 |
static uint32_t __inline log2bin(uint32_t value) |
static uint32_t __inline |
68 |
|
log2bin(uint32_t value) |
69 |
{ |
{ |
70 |
/* Changed by Chenm001 */ |
/* Changed by Chenm001 */ |
71 |
#ifndef WIN32 |
#ifndef WIN32 |
72 |
int n = 0; |
int n = 0; |
73 |
while (value) |
|
74 |
{ |
while (value) { |
75 |
value >>= 1; |
value >>= 1; |
76 |
n++; |
n++; |
77 |
} |
} |
85 |
} |
} |
86 |
|
|
87 |
|
|
88 |
static const uint32_t intra_dc_threshold_table[] = |
static const uint32_t intra_dc_threshold_table[] = { |
|
{ |
|
89 |
32, /* never use */ |
32, /* never use */ |
90 |
13, |
13, |
91 |
15, |
15, |
97 |
}; |
}; |
98 |
|
|
99 |
|
|
100 |
void bs_get_matrix(Bitstream * bs, uint8_t * matrix) |
void |
101 |
|
bs_get_matrix(Bitstream * bs, |
102 |
|
uint8_t * matrix) |
103 |
{ |
{ |
104 |
int i = 0; |
int i = 0; |
105 |
int last, value = 0; |
int last, value = 0; |
106 |
|
|
107 |
do |
do { |
|
{ |
|
108 |
last = value; |
last = value; |
109 |
value = BitstreamGetBits(bs, 8); |
value = BitstreamGetBits(bs, 8); |
110 |
matrix[ scan_tables[0][i++] ] = value; |
matrix[ scan_tables[0][i++] ] = value; |
111 |
} |
} |
112 |
while (value != 0 && i < 64); |
while (value != 0 && i < 64); |
113 |
|
i--; // fix little bug at coeff not full |
114 |
|
|
115 |
while (i < 64) |
while (i < 64) { |
|
{ |
|
116 |
matrix[ scan_tables[0][i++] ] = last; |
matrix[ scan_tables[0][i++] ] = last; |
117 |
} |
} |
118 |
} |
} |
122 |
returns coding_type, or -1 if error |
returns coding_type, or -1 if error |
123 |
*/ |
*/ |
124 |
|
|
125 |
int BitstreamReadHeaders(Bitstream * bs, DECODER * dec, uint32_t * rounding, uint32_t * quant, uint32_t * fcode_forward, uint32_t * fcode_backward, uint32_t * intra_dc_threshold) |
int |
126 |
|
BitstreamReadHeaders(Bitstream * bs, |
127 |
|
DECODER * dec, |
128 |
|
uint32_t * rounding, |
129 |
|
uint32_t * quant, |
130 |
|
uint32_t * fcode_forward, |
131 |
|
uint32_t * fcode_backward, |
132 |
|
uint32_t * intra_dc_threshold) |
133 |
{ |
{ |
134 |
uint32_t vol_ver_id; |
uint32_t vol_ver_id; |
135 |
static uint32_t time_increment_resolution; |
static uint32_t time_increment_resolution; |
138 |
uint32_t time_incr=0; |
uint32_t time_incr=0; |
139 |
int32_t time_increment; |
int32_t time_increment; |
140 |
|
|
141 |
do |
do { |
|
{ |
|
142 |
BitstreamByteAlign(bs); |
BitstreamByteAlign(bs); |
143 |
start_code = BitstreamShowBits(bs, 32); |
start_code = BitstreamShowBits(bs, 32); |
144 |
|
|
145 |
if (start_code == VISOBJSEQ_START_CODE) |
if (start_code == VISOBJSEQ_START_CODE) { |
|
{ |
|
146 |
// DEBUG("visual_object_sequence"); |
// DEBUG("visual_object_sequence"); |
147 |
BitstreamSkip(bs, 32); // visual_object_sequence_start_code |
BitstreamSkip(bs, 32); // visual_object_sequence_start_code |
148 |
BitstreamSkip(bs, 8); // profile_and_level_indication |
BitstreamSkip(bs, 8); // profile_and_level_indication |
149 |
} |
} else if (start_code == VISOBJSEQ_STOP_CODE) { |
|
else if (start_code == VISOBJSEQ_STOP_CODE) |
|
|
{ |
|
150 |
BitstreamSkip(bs, 32); // visual_object_sequence_stop_code |
BitstreamSkip(bs, 32); // visual_object_sequence_stop_code |
151 |
} |
} else if (start_code == VISOBJ_START_CODE) { |
|
else if (start_code == VISOBJ_START_CODE) |
|
|
{ |
|
152 |
// DEBUG("visual_object"); |
// DEBUG("visual_object"); |
153 |
BitstreamSkip(bs,32); // visual_object_start_code |
BitstreamSkip(bs,32); // visual_object_start_code |
154 |
if (BitstreamGetBit(bs)) // is_visual_object_identified |
if (BitstreamGetBit(bs)) // is_visual_object_identified |
155 |
{ |
{ |
156 |
vol_ver_id = BitstreamGetBits(bs,4); // visual_object_ver_id |
vol_ver_id = BitstreamGetBits(bs,4); // visual_object_ver_id |
157 |
BitstreamSkip(bs, 3); // visual_object_priority |
BitstreamSkip(bs, 3); // visual_object_priority |
158 |
} |
} else { |
|
else |
|
|
{ |
|
159 |
vol_ver_id = 1; |
vol_ver_id = 1; |
160 |
} |
} |
161 |
|
|
181 |
BitstreamSkip(bs, 8); // matrix_coefficients |
BitstreamSkip(bs, 8); // matrix_coefficients |
182 |
} |
} |
183 |
} |
} |
184 |
} |
} else if ((start_code & ~0x1f) == VIDOBJ_START_CODE) { |
|
else if ((start_code & ~0x1f) == VIDOBJ_START_CODE) |
|
|
{ |
|
185 |
BitstreamSkip(bs, 32); // video_object_start_code |
BitstreamSkip(bs, 32); // video_object_start_code |
186 |
} |
} else if ((start_code & ~0xf) == VIDOBJLAY_START_CODE) { |
|
else if ((start_code & ~0xf) == VIDOBJLAY_START_CODE) |
|
|
{ |
|
187 |
// DEBUG("video_object_layer"); |
// DEBUG("video_object_layer"); |
188 |
BitstreamSkip(bs, 32); // video_object_layer_start_code |
BitstreamSkip(bs, 32); // video_object_layer_start_code |
189 |
|
|
190 |
BitstreamSkip(bs, 1); // random_accessible_vol |
BitstreamSkip(bs, 1); // random_accessible_vol |
191 |
|
|
192 |
// video_object_type_indication |
// video_object_type_indication |
193 |
if (BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_SIMPLE && |
if (BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_SIMPLE && BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_CORE && BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_MAIN && BitstreamShowBits(bs, 8) != 0) // BUGGY DIVX |
|
BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_CORE && |
|
|
BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_MAIN && |
|
|
BitstreamShowBits(bs, 8) != 0) // BUGGY DIVX |
|
194 |
{ |
{ |
195 |
DEBUG1("video_object_type_indication not supported", BitstreamShowBits(bs, 8)); |
DEBUG1("video_object_type_indication not supported", |
196 |
|
BitstreamShowBits(bs, 8)); |
197 |
return -1; |
return -1; |
198 |
} |
} |
199 |
BitstreamSkip(bs, 8); |
BitstreamSkip(bs, 8); |
204 |
DEBUG("+ is_object_layer_identifier"); |
DEBUG("+ is_object_layer_identifier"); |
205 |
vol_ver_id = BitstreamGetBits(bs,4); // video_object_layer_verid |
vol_ver_id = BitstreamGetBits(bs,4); // video_object_layer_verid |
206 |
BitstreamSkip(bs, 3); // video_object_layer_priority |
BitstreamSkip(bs, 3); // video_object_layer_priority |
207 |
} |
} else { |
|
else |
|
|
{ |
|
208 |
vol_ver_id = 1; |
vol_ver_id = 1; |
209 |
} |
} |
210 |
//DEBUGI("vol_ver_id", vol_ver_id); |
//DEBUGI("vol_ver_id", vol_ver_id); |
220 |
{ |
{ |
221 |
DEBUG("+ vol_control_parameters"); |
DEBUG("+ vol_control_parameters"); |
222 |
BitstreamSkip(bs, 2); // chroma_format |
BitstreamSkip(bs, 2); // chroma_format |
223 |
BitstreamSkip(bs, 1); // low_delay |
dec->low_delay = BitstreamGetBit(bs); // low_delay |
224 |
if (BitstreamGetBit(bs)) // vbv_parameters |
if (BitstreamGetBit(bs)) // vbv_parameters |
225 |
{ |
{ |
226 |
DEBUG("+ vbv_parameters"); |
DEBUG("+ vbv_parameters"); |
242 |
dec->shape = BitstreamGetBits(bs, 2); // video_object_layer_shape |
dec->shape = BitstreamGetBits(bs, 2); // video_object_layer_shape |
243 |
// DEBUG1("shape", dec->shape); |
// DEBUG1("shape", dec->shape); |
244 |
|
|
245 |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE && vol_ver_id != 1) |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE && vol_ver_id != 1) { |
|
{ |
|
246 |
BitstreamSkip(bs, 4); // video_object_layer_shape_extension |
BitstreamSkip(bs, 4); // video_object_layer_shape_extension |
247 |
} |
} |
248 |
|
|
252 |
time_increment_resolution = BitstreamGetBits(bs, 16); // vop_time_increment_resolution |
time_increment_resolution = BitstreamGetBits(bs, 16); // vop_time_increment_resolution |
253 |
time_increment_resolution--; |
time_increment_resolution--; |
254 |
//DEBUG1("time_increment_resolution=",time_increment_resolution); |
//DEBUG1("time_increment_resolution=",time_increment_resolution); |
255 |
if (time_increment_resolution > 0) |
if (time_increment_resolution > 0) { |
|
{ |
|
256 |
dec->time_inc_bits = log2bin(time_increment_resolution); |
dec->time_inc_bits = log2bin(time_increment_resolution); |
257 |
} |
} else { |
|
else |
|
|
{ |
|
258 |
// dec->time_inc_bits = 0; |
// dec->time_inc_bits = 0; |
259 |
|
|
260 |
// for "old" xvid compatibility, set time_inc_bits = 1 |
// for "old" xvid compatibility, set time_inc_bits = 1 |
268 |
BitstreamSkip(bs, dec->time_inc_bits); // fixed_vop_time_increment |
BitstreamSkip(bs, dec->time_inc_bits); // fixed_vop_time_increment |
269 |
} |
} |
270 |
|
|
271 |
if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) |
if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) { |
|
{ |
|
272 |
|
|
273 |
if (dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR) |
if (dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR) { |
|
{ |
|
274 |
uint32_t width, height; |
uint32_t width, height; |
275 |
|
|
276 |
READ_MARKER(); |
READ_MARKER(); |
281 |
//DEBUGI("height", height); |
//DEBUGI("height", height); |
282 |
READ_MARKER(); |
READ_MARKER(); |
283 |
|
|
284 |
if (width != dec->width || height != dec->height) |
if (width != dec->width || height != dec->height) { |
|
{ |
|
285 |
DEBUG("FATAL: video dimension discrepancy ***"); |
DEBUG("FATAL: video dimension discrepancy ***"); |
286 |
DEBUG2("bitstream width/height", width, height); |
DEBUG2("bitstream width/height", width, height); |
287 |
DEBUG2("param width/height", dec->width, dec->height); |
DEBUG2("param width/height", dec->width, dec->height); |
290 |
|
|
291 |
} |
} |
292 |
|
|
293 |
if ((dec->interlacing = BitstreamGetBit(bs))) |
if ((dec->interlacing = BitstreamGetBit(bs))) { |
|
{ |
|
294 |
DEBUG("vol: interlacing"); |
DEBUG("vol: interlacing"); |
295 |
} |
} |
296 |
|
|
307 |
return -1; |
return -1; |
308 |
} |
} |
309 |
|
|
310 |
if (vol_ver_id != 1 && dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) |
if (vol_ver_id != 1 && |
311 |
{ |
dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) { |
312 |
BitstreamSkip(bs, 1); // sadct_disable |
BitstreamSkip(bs, 1); // sadct_disable |
313 |
} |
} |
314 |
|
|
317 |
DEBUG("+ not_8_bit [IGNORED/TODO]"); |
DEBUG("+ not_8_bit [IGNORED/TODO]"); |
318 |
dec->quant_bits = BitstreamGetBits(bs, 4); // quant_precision |
dec->quant_bits = BitstreamGetBits(bs, 4); // quant_precision |
319 |
BitstreamSkip(bs, 4); // bits_per_pixel |
BitstreamSkip(bs, 4); // bits_per_pixel |
320 |
} |
} else { |
|
else |
|
|
{ |
|
321 |
dec->quant_bits = 5; |
dec->quant_bits = 5; |
322 |
} |
} |
323 |
|
|
324 |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) { |
|
{ |
|
325 |
BitstreamSkip(bs, 1); // no_gray_quant_update |
BitstreamSkip(bs, 1); // no_gray_quant_update |
326 |
BitstreamSkip(bs, 1); // composition_method |
BitstreamSkip(bs, 1); // composition_method |
327 |
BitstreamSkip(bs, 1); // linear_composition |
BitstreamSkip(bs, 1); // linear_composition |
330 |
dec->quant_type = BitstreamGetBit(bs); // quant_type |
dec->quant_type = BitstreamGetBit(bs); // quant_type |
331 |
// DEBUG1("**** quant_type", dec->quant_type); |
// DEBUG1("**** quant_type", dec->quant_type); |
332 |
|
|
333 |
if (dec->quant_type) |
if (dec->quant_type) { |
|
{ |
|
334 |
if (BitstreamGetBit(bs)) // load_intra_quant_mat |
if (BitstreamGetBit(bs)) // load_intra_quant_mat |
335 |
{ |
{ |
336 |
uint8_t matrix[64]; |
uint8_t matrix[64]; |
337 |
|
|
338 |
bs_get_matrix(bs, matrix); |
bs_get_matrix(bs, matrix); |
339 |
set_intra_matrix(matrix); |
set_intra_matrix(matrix); |
340 |
} |
} else |
|
else |
|
341 |
set_intra_matrix(get_default_intra_matrix()); |
set_intra_matrix(get_default_intra_matrix()); |
342 |
|
|
343 |
if (BitstreamGetBit(bs)) // load_inter_quant_mat |
if (BitstreamGetBit(bs)) // load_inter_quant_mat |
344 |
{ |
{ |
345 |
uint8_t matrix[64]; |
uint8_t matrix[64]; |
346 |
|
|
347 |
bs_get_matrix(bs, matrix); |
bs_get_matrix(bs, matrix); |
348 |
set_inter_matrix(matrix); |
set_inter_matrix(matrix); |
349 |
} |
} else |
|
else |
|
350 |
set_inter_matrix(get_default_inter_matrix()); |
set_inter_matrix(get_default_inter_matrix()); |
351 |
|
|
352 |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) { |
|
{ |
|
353 |
// TODO |
// TODO |
354 |
DEBUG("TODO: grayscale matrix stuff"); |
DEBUG("TODO: grayscale matrix stuff"); |
355 |
return -1; |
return -1; |
358 |
} |
} |
359 |
|
|
360 |
|
|
361 |
if (vol_ver_id != 1) |
if (vol_ver_id != 1) { |
|
{ |
|
362 |
dec->quarterpel = BitstreamGetBit(bs); // quarter_sampe |
dec->quarterpel = BitstreamGetBit(bs); // quarter_sampe |
363 |
if (dec->quarterpel) |
if (dec->quarterpel) { |
|
{ |
|
364 |
DEBUG("IGNORED/TODO: quarter_sample"); |
DEBUG("IGNORED/TODO: quarter_sample"); |
365 |
} |
} |
366 |
} |
} else { |
|
else |
|
|
{ |
|
367 |
dec->quarterpel = 0; |
dec->quarterpel = 0; |
368 |
} |
} |
369 |
|
|
386 |
BitstreamSkip(bs, 1); // reversible_vlc |
BitstreamSkip(bs, 1); // reversible_vlc |
387 |
} |
} |
388 |
|
|
389 |
if (vol_ver_id != 1) |
if (vol_ver_id != 1) { |
|
{ |
|
390 |
if (BitstreamGetBit(bs)) // newpred_enable |
if (BitstreamGetBit(bs)) // newpred_enable |
391 |
{ |
{ |
392 |
DEBUG("+ newpred_enable"); |
DEBUG("+ newpred_enable"); |
407 |
DEBUG("TODO: scalability"); |
DEBUG("TODO: scalability"); |
408 |
return -1; |
return -1; |
409 |
} |
} |
410 |
} |
} else // dec->shape == BINARY_ONLY |
|
else // dec->shape == BINARY_ONLY |
|
|
{ |
|
|
if (vol_ver_id != 1) |
|
411 |
{ |
{ |
412 |
|
if (vol_ver_id != 1) { |
413 |
if (BitstreamGetBit(bs)) // scalability |
if (BitstreamGetBit(bs)) // scalability |
414 |
{ |
{ |
415 |
// TODO |
// TODO |
421 |
|
|
422 |
} |
} |
423 |
|
|
424 |
} |
} else if (start_code == GRPOFVOP_START_CODE) { |
|
else if (start_code == GRPOFVOP_START_CODE) |
|
|
{ |
|
425 |
// DEBUG("group_of_vop"); |
// DEBUG("group_of_vop"); |
426 |
BitstreamSkip(bs, 32); |
BitstreamSkip(bs, 32); |
427 |
{ |
{ |
428 |
int hours, minutes, seconds; |
int hours, minutes, seconds; |
429 |
|
|
430 |
hours = BitstreamGetBits(bs, 5); |
hours = BitstreamGetBits(bs, 5); |
431 |
minutes = BitstreamGetBits(bs, 6); |
minutes = BitstreamGetBits(bs, 6); |
432 |
READ_MARKER(); |
READ_MARKER(); |
435 |
} |
} |
436 |
BitstreamSkip(bs, 1); // closed_gov |
BitstreamSkip(bs, 1); // closed_gov |
437 |
BitstreamSkip(bs, 1); // broken_link |
BitstreamSkip(bs, 1); // broken_link |
438 |
} |
} else if (start_code == VOP_START_CODE) { |
|
else if (start_code == VOP_START_CODE) |
|
|
{ |
|
439 |
// DEBUG("vop_start_code"); |
// DEBUG("vop_start_code"); |
440 |
BitstreamSkip(bs, 32); // vop_start_code |
BitstreamSkip(bs, 32); // vop_start_code |
441 |
|
|
450 |
|
|
451 |
//DEBUG1("time_inc_bits", dec->time_inc_bits); |
//DEBUG1("time_inc_bits", dec->time_inc_bits); |
452 |
//DEBUG1("vop_time_incr", BitstreamShowBits(bs, dec->time_inc_bits)); |
//DEBUG1("vop_time_incr", BitstreamShowBits(bs, dec->time_inc_bits)); |
453 |
if (dec->time_inc_bits) |
if (dec->time_inc_bits) { |
|
{ |
|
454 |
//BitstreamSkip(bs, dec->time_inc_bits); // vop_time_increment |
//BitstreamSkip(bs, dec->time_inc_bits); // vop_time_increment |
455 |
time_increment = (BitstreamGetBits(bs, dec->time_inc_bits)); // vop_time_increment |
time_increment = (BitstreamGetBits(bs, dec->time_inc_bits)); // vop_time_increment |
456 |
} |
} |
457 |
if(coding_type != B_VOP){ |
if(coding_type != B_VOP){ |
458 |
dec->last_time_base = dec->time_base; |
dec->last_time_base = dec->time_base; |
459 |
dec->time_base += time_incr; |
dec->time_base += time_incr; |
460 |
dec->time = dec->time_base*time_increment_resolution + time_increment; |
dec->time = |
461 |
|
dec->time_base * time_increment_resolution + |
462 |
|
time_increment; |
463 |
dec->time_pp= (uint32_t)(dec->time - dec->last_non_b_time); |
dec->time_pp= (uint32_t)(dec->time - dec->last_non_b_time); |
464 |
dec->last_non_b_time= dec->time; |
dec->last_non_b_time= dec->time; |
465 |
}else{ |
}else{ |
466 |
dec->time = (dec->last_time_base + time_incr)*time_increment_resolution + time_increment; |
dec->time = |
467 |
|
(dec->last_time_base + |
468 |
|
time_incr) * time_increment_resolution + time_increment; |
469 |
dec->time_bp= (uint32_t)(dec->last_non_b_time - dec->time); |
dec->time_bp= (uint32_t)(dec->last_non_b_time - dec->time); |
470 |
} |
} |
471 |
//DEBUG1("time_increment=",time_increment); |
//DEBUG1("time_increment=",time_increment); |
483 |
*/ |
*/ |
484 |
|
|
485 |
// fix a little bug by MinChen <chenm002@163.com> |
// fix a little bug by MinChen <chenm002@163.com> |
486 |
if ((dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) && (coding_type == P_VOP)) |
if ((dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) && |
487 |
{ |
(coding_type == P_VOP)) { |
488 |
*rounding = BitstreamGetBit(bs); // rounding_type |
*rounding = BitstreamGetBit(bs); // rounding_type |
489 |
//DEBUG1("rounding", *rounding); |
//DEBUG1("rounding", *rounding); |
490 |
} |
} |
494 |
} |
} |
495 |
*/ |
*/ |
496 |
|
|
497 |
if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) |
if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) { |
|
{ |
|
498 |
uint32_t width, height; |
uint32_t width, height; |
499 |
uint32_t horiz_mc_ref, vert_mc_ref; |
uint32_t horiz_mc_ref, vert_mc_ref; |
500 |
|
|
518 |
} |
} |
519 |
|
|
520 |
|
|
521 |
if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) |
if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) { |
|
{ |
|
522 |
// intra_dc_vlc_threshold |
// intra_dc_vlc_threshold |
523 |
*intra_dc_threshold = intra_dc_threshold_table[ BitstreamGetBits(bs,3) ]; |
*intra_dc_threshold = |
524 |
|
intra_dc_threshold_table[BitstreamGetBits(bs, 3)]; |
525 |
|
|
526 |
if (dec->interlacing) |
if (dec->interlacing) { |
527 |
{ |
if ((dec->top_field_first = BitstreamGetBit(bs))) { |
|
if ((dec->top_field_first = BitstreamGetBit(bs))) |
|
|
{ |
|
528 |
DEBUG("vop: top_field_first"); |
DEBUG("vop: top_field_first"); |
529 |
} |
} |
530 |
if ((dec->alternate_vertical_scan = BitstreamGetBit(bs))) |
if ((dec->alternate_vertical_scan = BitstreamGetBit(bs))) { |
|
{ |
|
531 |
DEBUG("vop: alternate_vertical_scan"); |
DEBUG("vop: alternate_vertical_scan"); |
532 |
} |
} |
533 |
} |
} |
538 |
|
|
539 |
//DEBUG1("quant", *quant); |
//DEBUG1("quant", *quant); |
540 |
|
|
541 |
if (coding_type != I_VOP) |
if (coding_type != I_VOP) { |
|
{ |
|
542 |
*fcode_forward = BitstreamGetBits(bs, 3); // fcode_forward |
*fcode_forward = BitstreamGetBits(bs, 3); // fcode_forward |
543 |
} |
} |
544 |
|
|
545 |
if (coding_type == B_VOP) |
if (coding_type == B_VOP) { |
|
{ |
|
546 |
*fcode_backward = BitstreamGetBits(bs, 3); // fcode_backward |
*fcode_backward = BitstreamGetBits(bs, 3); // fcode_backward |
547 |
} |
} |
548 |
if (!dec->scalability){ |
if (!dec->scalability){ |
549 |
if ((dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) && (coding_type != I_VOP)){ |
if ((dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) && |
550 |
|
(coding_type != I_VOP)) { |
551 |
BitstreamSkip(bs, 1); // vop_shape_coding_type |
BitstreamSkip(bs, 1); // vop_shape_coding_type |
552 |
} |
} |
553 |
} |
} |
554 |
return coding_type; |
return coding_type; |
555 |
} |
} else if (start_code == USERDATA_START_CODE) { |
|
else if (start_code == USERDATA_START_CODE) |
|
|
{ |
|
556 |
// DEBUG("user_data"); |
// DEBUG("user_data"); |
557 |
BitstreamSkip(bs, 32); // user_data_start_code |
BitstreamSkip(bs, 32); // user_data_start_code |
558 |
} |
} else // start_code == ? |
|
else // start_code == ? |
|
|
{ |
|
|
if (BitstreamShowBits(bs, 24) == 0x000001) |
|
559 |
{ |
{ |
560 |
DEBUG1("*** WARNING: unknown start_code", BitstreamShowBits(bs, 32)); |
if (BitstreamShowBits(bs, 24) == 0x000001) { |
561 |
|
DEBUG1("*** WARNING: unknown start_code", |
562 |
|
BitstreamShowBits(bs, 32)); |
563 |
} |
} |
564 |
BitstreamSkip(bs, 8); |
BitstreamSkip(bs, 8); |
565 |
} |
} |
573 |
|
|
574 |
/* write custom quant matrix */ |
/* write custom quant matrix */ |
575 |
|
|
576 |
static void bs_put_matrix(Bitstream * bs, const int16_t *matrix) |
static void |
577 |
|
bs_put_matrix(Bitstream * bs, |
578 |
|
const int16_t * matrix) |
579 |
{ |
{ |
580 |
int i, j; |
int i, j; |
581 |
const int last = matrix[scan_tables[0][63]]; |
const int last = matrix[scan_tables[0][63]]; |
582 |
|
|
583 |
for (j = 63; j >= 0 && matrix[scan_tables[0][j - 1]] == last; j--) ; |
for (j = 63; j >= 0 && matrix[scan_tables[0][j - 1]] == last; j--) ; |
584 |
|
|
585 |
for (i = 0; i <= j; i++) |
for (i = 0; i <= j; i++) { |
|
{ |
|
586 |
BitstreamPutBits(bs, matrix[scan_tables[0][i]], 8); |
BitstreamPutBits(bs, matrix[scan_tables[0][i]], 8); |
587 |
} |
} |
588 |
|
|
589 |
if (j < 63) |
if (j < 63) { |
|
{ |
|
590 |
BitstreamPutBits(bs, 0, 8); |
BitstreamPutBits(bs, 0, 8); |
591 |
} |
} |
592 |
} |
} |
595 |
/* |
/* |
596 |
write vol header |
write vol header |
597 |
*/ |
*/ |
598 |
void BitstreamWriteVolHeader(Bitstream * const bs, |
void |
599 |
const MBParam * pParam, const FRAMEINFO * frame) |
BitstreamWriteVolHeader(Bitstream * const bs, |
600 |
|
const MBParam * pParam, |
601 |
|
const FRAMEINFO * frame) |
602 |
{ |
{ |
603 |
// video object_start_code & vo_id |
// video object_start_code & vo_id |
604 |
BitstreamPad(bs); |
BitstreamPad(bs); |
613 |
BitstreamPutBits(bs, 0, 8); // video_object_type_indication |
BitstreamPutBits(bs, 0, 8); // video_object_type_indication |
614 |
BitstreamPutBit(bs, 0); // is_object_layer_identified (0=not given) |
BitstreamPutBit(bs, 0); // is_object_layer_identified (0=not given) |
615 |
BitstreamPutBits(bs, 1, 4); // aspect_ratio_info (1=1:1) |
BitstreamPutBits(bs, 1, 4); // aspect_ratio_info (1=1:1) |
616 |
BitstreamPutBit(bs, 0); // vol_control_parameters (0=not given) |
|
617 |
|
#ifdef BFRAMES |
618 |
|
if (pParam->max_bframes > 0) { |
619 |
|
dprintf("low_delay=1"); |
620 |
|
BitstreamPutBit(bs, 1); // vol_control_parameters |
621 |
|
BitstreamPutBits(bs, 1, 2); // chroma_format 1="4:2:0" |
622 |
|
BitstreamPutBit(bs, 0); // low_delay |
623 |
|
BitstreamPutBit(bs, 0); // vbv_parameters (0=not given) |
624 |
|
} else |
625 |
|
#endif |
626 |
|
{ |
627 |
|
BitstreamPutBits(bs, 0, 1); // vol_control_parameters (0=not given) |
628 |
|
} |
629 |
|
|
630 |
|
|
631 |
BitstreamPutBits(bs, 0, 2); // video_object_layer_shape (0=rectangular) |
BitstreamPutBits(bs, 0, 2); // video_object_layer_shape (0=rectangular) |
632 |
|
|
633 |
WRITE_MARKER(); |
WRITE_MARKER(); |
665 |
// quant_type 0=h.263 1=mpeg4(quantizer tables) |
// quant_type 0=h.263 1=mpeg4(quantizer tables) |
666 |
BitstreamPutBit(bs, pParam->m_quant_type); |
BitstreamPutBit(bs, pParam->m_quant_type); |
667 |
|
|
668 |
if (pParam->m_quant_type) |
if (pParam->m_quant_type) { |
|
{ |
|
669 |
BitstreamPutBit(bs, get_intra_matrix_status()); // load_intra_quant_mat |
BitstreamPutBit(bs, get_intra_matrix_status()); // load_intra_quant_mat |
670 |
if (get_intra_matrix_status()) |
if (get_intra_matrix_status()) { |
|
{ |
|
671 |
bs_put_matrix(bs, get_intra_matrix()); |
bs_put_matrix(bs, get_intra_matrix()); |
672 |
} |
} |
673 |
|
|
674 |
BitstreamPutBit(bs, get_inter_matrix_status()); // load_inter_quant_mat |
BitstreamPutBit(bs, get_inter_matrix_status()); // load_inter_quant_mat |
675 |
if (get_inter_matrix_status()) |
if (get_inter_matrix_status()) { |
|
{ |
|
676 |
bs_put_matrix(bs, get_inter_matrix()); |
bs_put_matrix(bs, get_inter_matrix()); |
677 |
} |
} |
678 |
|
|
693 |
time_inc = nth of a second since last resync |
time_inc = nth of a second since last resync |
694 |
(decoder uses these values to determine precise time since last resync) |
(decoder uses these values to determine precise time since last resync) |
695 |
*/ |
*/ |
696 |
void BitstreamWriteVopHeader(Bitstream * const bs, |
void |
697 |
|
BitstreamWriteVopHeader(Bitstream * const bs, |
698 |
const MBParam * pParam, |
const MBParam * pParam, |
699 |
const FRAMEINFO * frame) |
const FRAMEINFO * frame) |
700 |
{ |
{ |
708 |
|
|
709 |
// time_base = 0 write n x PutBit(1), PutBit(0) |
// time_base = 0 write n x PutBit(1), PutBit(0) |
710 |
#ifdef BFRAMES |
#ifdef BFRAMES |
711 |
for (i = 0; i < frame->seconds; i++) |
for (i = 0; i < frame->seconds; i++) { |
|
{ |
|
712 |
BitstreamPutBit(bs, 1); |
BitstreamPutBit(bs, 1); |
713 |
} |
} |
714 |
BitstreamPutBit(bs, 0); |
BitstreamPutBit(bs, 0); |
721 |
// time_increment: value=nth_of_sec, nbits = log2(resolution) |
// time_increment: value=nth_of_sec, nbits = log2(resolution) |
722 |
#ifdef BFRAMES |
#ifdef BFRAMES |
723 |
BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase)); |
BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase)); |
724 |
dprintf("[%i:%i] %c\n", frame->seconds, frame->ticks, frame->coding_type == I_VOP ? 'I' : frame->coding_type == P_VOP ? 'P' : 'B'); |
dprintf("[%i:%i] %c\n", frame->seconds, frame->ticks, |
725 |
|
frame->coding_type == I_VOP ? 'I' : frame->coding_type == |
726 |
|
P_VOP ? 'P' : 'B'); |
727 |
#else |
#else |
728 |
BitstreamPutBits(bs, 1, 1); |
BitstreamPutBits(bs, 1, 1); |
729 |
#endif |
#endif |
737 |
|
|
738 |
BitstreamPutBits(bs, 0, 3); // intra_dc_vlc_threshold |
BitstreamPutBits(bs, 0, 3); // intra_dc_vlc_threshold |
739 |
|
|
740 |
if (frame->global_flags & XVID_INTERLACING) |
if (frame->global_flags & XVID_INTERLACING) { |
|
{ |
|
741 |
BitstreamPutBit(bs, 1); // top field first |
BitstreamPutBit(bs, 1); // top field first |
742 |
BitstreamPutBit(bs, 0); // alternate vertical scan |
BitstreamPutBit(bs, 0); // alternate vertical scan |
743 |
} |
} |