41 |
* * |
* * |
42 |
* Revision history: * |
* Revision history: * |
43 |
* * |
* * |
44 |
|
* 22.05.2002 bs_put_matrix fix |
45 |
|
* 20.05.2002 added BitstreamWriteUserData * |
46 |
|
* 19.06.2002 Fix a little bug in use custom quant matrix * |
47 |
|
* MinChen <chenm001@163.com> * |
48 |
* 08.05.2002 add low_delay support for B_VOP decode * |
* 08.05.2002 add low_delay support for B_VOP decode * |
49 |
* MinChen <chenm001@163.com> * |
* MinChen <chenm001@163.com> * |
50 |
* 06.05.2002 low_delay * |
* 06.05.2002 low_delay * |
57 |
* 30.02.2002 intra_dc_threshold support * |
* 30.02.2002 intra_dc_threshold support * |
58 |
* 04.12.2001 support for additional headers * |
* 04.12.2001 support for additional headers * |
59 |
* 16.12.2001 inital version * |
* 16.12.2001 inital version * |
60 |
* * |
* |
61 |
******************************************************************************/ |
******************************************************************************/ |
62 |
|
|
63 |
|
|
112 |
matrix[scan_tables[0][i++]] = value; |
matrix[scan_tables[0][i++]] = value; |
113 |
} |
} |
114 |
while (value != 0 && i < 64); |
while (value != 0 && i < 64); |
115 |
|
i--; // fix little bug at coeff not full |
116 |
|
|
117 |
while (i < 64) { |
while (i < 64) { |
118 |
matrix[scan_tables[0][i++]] = last; |
matrix[scan_tables[0][i++]] = last; |
119 |
} |
} |
120 |
} |
} |
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
// for PVOP addbits == fcode - 1 |
125 |
|
// for BVOP addbits == max(fcode,bcode) - 1 |
126 |
|
// returns mbpos |
127 |
|
int |
128 |
|
read_video_packet_header(Bitstream *bs, int addbits) |
129 |
|
{ |
130 |
|
int nbits; |
131 |
|
int mbnum; |
132 |
|
int quant; |
133 |
|
int hec; |
134 |
|
|
135 |
|
nbits = NUMBITS_VP_RESYNC_MARKER; |
136 |
|
|
137 |
|
BitstreamSkip(bs, BitstreamNumBitsToByteAlign(bs)); |
138 |
|
BitstreamSkip(bs, nbits); |
139 |
|
|
140 |
|
// if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) { |
141 |
|
// hec |
142 |
|
// vop_width |
143 |
|
// marker_bit |
144 |
|
// vop_height |
145 |
|
// marker_bit |
146 |
|
|
147 |
|
//} |
148 |
|
|
149 |
|
mbnum = BitstreamGetBits(bs, 9); |
150 |
|
//printf("mbnum %i [%i,%i]\n", mbnum, mbnum % dec->mb_width, mbnum / dec->mb_width); |
151 |
|
|
152 |
|
// if (dec->shape != VIDOBJLAY_SHAPE_BINARYONLY) |
153 |
|
quant = BitstreamGetBits(bs, 5); |
154 |
|
|
155 |
|
// if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) |
156 |
|
hec = BitstreamGetBit(bs); |
157 |
|
// if (hec) |
158 |
|
// .. decoder hec-header ... |
159 |
|
|
160 |
|
return mbnum; |
161 |
|
} |
162 |
|
|
163 |
|
|
164 |
|
|
165 |
/* |
/* |
166 |
decode headers |
decode headers |
167 |
returns coding_type, or -1 if error |
returns coding_type, or -1 if error |
188 |
start_code = BitstreamShowBits(bs, 32); |
start_code = BitstreamShowBits(bs, 32); |
189 |
|
|
190 |
if (start_code == VISOBJSEQ_START_CODE) { |
if (start_code == VISOBJSEQ_START_CODE) { |
191 |
// DEBUG("visual_object_sequence"); |
// DPRINTF("visual_object_sequence"); |
192 |
BitstreamSkip(bs, 32); // visual_object_sequence_start_code |
BitstreamSkip(bs, 32); // visual_object_sequence_start_code |
193 |
BitstreamSkip(bs, 8); // profile_and_level_indication |
BitstreamSkip(bs, 8); // profile_and_level_indication |
194 |
} else if (start_code == VISOBJSEQ_STOP_CODE) { |
} else if (start_code == VISOBJSEQ_STOP_CODE) { |
195 |
BitstreamSkip(bs, 32); // visual_object_sequence_stop_code |
BitstreamSkip(bs, 32); // visual_object_sequence_stop_code |
196 |
} else if (start_code == VISOBJ_START_CODE) { |
} else if (start_code == VISOBJ_START_CODE) { |
197 |
// DEBUG("visual_object"); |
//DPRINTF("visual_object"); |
198 |
BitstreamSkip(bs, 32); // visual_object_start_code |
BitstreamSkip(bs, 32); // visual_object_start_code |
199 |
if (BitstreamGetBit(bs)) // is_visual_object_identified |
if (BitstreamGetBit(bs)) // is_visual_object_identified |
200 |
{ |
{ |
206 |
|
|
207 |
if (BitstreamShowBits(bs, 4) != VISOBJ_TYPE_VIDEO) // visual_object_type |
if (BitstreamShowBits(bs, 4) != VISOBJ_TYPE_VIDEO) // visual_object_type |
208 |
{ |
{ |
209 |
DEBUG("visual_object_type != video"); |
//DPRINTF("visual_object_type != video"); |
210 |
return -1; |
return -1; |
211 |
} |
} |
212 |
BitstreamSkip(bs, 4); |
BitstreamSkip(bs, 4); |
215 |
|
|
216 |
if (BitstreamGetBit(bs)) // video_signal_type |
if (BitstreamGetBit(bs)) // video_signal_type |
217 |
{ |
{ |
218 |
DEBUG("+ video_signal_type"); |
//DPRINTF("+ video_signal_type"); |
219 |
BitstreamSkip(bs, 3); // video_format |
BitstreamSkip(bs, 3); // video_format |
220 |
BitstreamSkip(bs, 1); // video_range |
BitstreamSkip(bs, 1); // video_range |
221 |
if (BitstreamGetBit(bs)) // color_description |
if (BitstreamGetBit(bs)) // color_description |
222 |
{ |
{ |
223 |
DEBUG("+ color_description"); |
//DPRINTF("+ color_description"); |
224 |
BitstreamSkip(bs, 8); // color_primaries |
BitstreamSkip(bs, 8); // color_primaries |
225 |
BitstreamSkip(bs, 8); // transfer_characteristics |
BitstreamSkip(bs, 8); // transfer_characteristics |
226 |
BitstreamSkip(bs, 8); // matrix_coefficients |
BitstreamSkip(bs, 8); // matrix_coefficients |
229 |
} else if ((start_code & ~0x1f) == VIDOBJ_START_CODE) { |
} else if ((start_code & ~0x1f) == VIDOBJ_START_CODE) { |
230 |
BitstreamSkip(bs, 32); // video_object_start_code |
BitstreamSkip(bs, 32); // video_object_start_code |
231 |
} else if ((start_code & ~0xf) == VIDOBJLAY_START_CODE) { |
} else if ((start_code & ~0xf) == VIDOBJLAY_START_CODE) { |
232 |
// DEBUG("video_object_layer"); |
//DPRINTF("video_object_layer"); |
233 |
BitstreamSkip(bs, 32); // video_object_layer_start_code |
BitstreamSkip(bs, 32); // video_object_layer_start_code |
234 |
|
|
235 |
BitstreamSkip(bs, 1); // random_accessible_vol |
BitstreamSkip(bs, 1); // random_accessible_vol |
237 |
// video_object_type_indication |
// video_object_type_indication |
238 |
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 |
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 |
239 |
{ |
{ |
240 |
DEBUG1("video_object_type_indication not supported", |
//DPRINTF("video_object_type_indication %i not supported ", |
241 |
BitstreamShowBits(bs, 8)); |
// BitstreamShowBits(bs, 8)); |
242 |
return -1; |
return -1; |
243 |
} |
} |
244 |
BitstreamSkip(bs, 8); |
BitstreamSkip(bs, 8); |
246 |
|
|
247 |
if (BitstreamGetBit(bs)) // is_object_layer_identifier |
if (BitstreamGetBit(bs)) // is_object_layer_identifier |
248 |
{ |
{ |
249 |
DEBUG("+ is_object_layer_identifier"); |
//DPRINTF("+ is_object_layer_identifier"); |
250 |
vol_ver_id = BitstreamGetBits(bs, 4); // video_object_layer_verid |
vol_ver_id = BitstreamGetBits(bs, 4); // video_object_layer_verid |
251 |
BitstreamSkip(bs, 3); // video_object_layer_priority |
BitstreamSkip(bs, 3); // video_object_layer_priority |
252 |
} else { |
} else { |
253 |
vol_ver_id = 1; |
vol_ver_id = 1; |
254 |
} |
} |
255 |
//DEBUGI("vol_ver_id", vol_ver_id); |
//DPRINTF("vol_ver_id %i", vol_ver_id); |
256 |
|
|
257 |
if (BitstreamGetBits(bs, 4) == VIDOBJLAY_AR_EXTPAR) // aspect_ratio_info |
if (BitstreamGetBits(bs, 4) == VIDOBJLAY_AR_EXTPAR) // aspect_ratio_info |
258 |
{ |
{ |
259 |
DEBUG("+ aspect_ratio_info"); |
//DPRINTF("+ aspect_ratio_info"); |
260 |
BitstreamSkip(bs, 8); // par_width |
BitstreamSkip(bs, 8); // par_width |
261 |
BitstreamSkip(bs, 8); // par_height |
BitstreamSkip(bs, 8); // par_height |
262 |
} |
} |
263 |
|
|
264 |
if (BitstreamGetBit(bs)) // vol_control_parameters |
if (BitstreamGetBit(bs)) // vol_control_parameters |
265 |
{ |
{ |
266 |
DEBUG("+ vol_control_parameters"); |
//DPRINTF("+ vol_control_parameters"); |
267 |
BitstreamSkip(bs, 2); // chroma_format |
BitstreamSkip(bs, 2); // chroma_format |
268 |
dec->low_delay = BitstreamGetBit(bs); // low_delay |
dec->low_delay = BitstreamGetBit(bs); // low_delay |
269 |
if (BitstreamGetBit(bs)) // vbv_parameters |
if (BitstreamGetBit(bs)) // vbv_parameters |
270 |
{ |
{ |
271 |
DEBUG("+ vbv_parameters"); |
//DPRINTF("+ vbv_parameters"); |
272 |
BitstreamSkip(bs, 15); // first_half_bitrate |
BitstreamSkip(bs, 15); // first_half_bitrate |
273 |
READ_MARKER(); |
READ_MARKER(); |
274 |
BitstreamSkip(bs, 15); // latter_half_bitrate |
BitstreamSkip(bs, 15); // latter_half_bitrate |
285 |
} |
} |
286 |
|
|
287 |
dec->shape = BitstreamGetBits(bs, 2); // video_object_layer_shape |
dec->shape = BitstreamGetBits(bs, 2); // video_object_layer_shape |
288 |
// DEBUG1("shape", dec->shape); |
//DPRINTF("shape %i", dec->shape); |
289 |
|
|
290 |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE && vol_ver_id != 1) { |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE && vol_ver_id != 1) { |
291 |
BitstreamSkip(bs, 4); // video_object_layer_shape_extension |
BitstreamSkip(bs, 4); // video_object_layer_shape_extension |
296 |
// *************************** for decode B-frame time *********************** |
// *************************** for decode B-frame time *********************** |
297 |
time_increment_resolution = BitstreamGetBits(bs, 16); // vop_time_increment_resolution |
time_increment_resolution = BitstreamGetBits(bs, 16); // vop_time_increment_resolution |
298 |
time_increment_resolution--; |
time_increment_resolution--; |
299 |
//DEBUG1("time_increment_resolution=",time_increment_resolution); |
//DPRINTF("time_increment_resolution = %i",time_increment_resolution); |
300 |
if (time_increment_resolution > 0) { |
if (time_increment_resolution > 0) { |
301 |
dec->time_inc_bits = log2bin(time_increment_resolution); |
dec->time_inc_bits = log2bin(time_increment_resolution); |
302 |
} else { |
} else { |
320 |
|
|
321 |
READ_MARKER(); |
READ_MARKER(); |
322 |
width = BitstreamGetBits(bs, 13); // video_object_layer_width |
width = BitstreamGetBits(bs, 13); // video_object_layer_width |
323 |
//DEBUGI("width", width); |
//DPRINTF("width %i", width); |
324 |
READ_MARKER(); |
READ_MARKER(); |
325 |
height = BitstreamGetBits(bs, 13); // video_object_layer_height |
height = BitstreamGetBits(bs, 13); // video_object_layer_height |
326 |
//DEBUGI("height", height); |
//DPRINTF("height %i", height); |
327 |
READ_MARKER(); |
READ_MARKER(); |
328 |
|
|
329 |
if (width != dec->width || height != dec->height) { |
if (width != dec->width || height != dec->height) { |
330 |
DEBUG("FATAL: video dimension discrepancy ***"); |
//DPRINTF("FATAL: video dimension discrepancy ***"); |
331 |
DEBUG2("bitstream width/height", width, height); |
//DPRINTF("bitstream width/height %i x %i", width, height); |
332 |
DEBUG2("param width/height", dec->width, dec->height); |
//DPRINTF("param width/height %i x %i", dec->width, dec->height); |
333 |
return -1; |
return -1; |
334 |
} |
} |
335 |
|
|
336 |
} |
} |
337 |
|
|
338 |
if ((dec->interlacing = BitstreamGetBit(bs))) { |
if ((dec->interlacing = BitstreamGetBit(bs))) { |
339 |
DEBUG("vol: interlacing"); |
//DPRINTF("vol: interlacing"); |
340 |
} |
} |
341 |
|
|
342 |
if (!BitstreamGetBit(bs)) // obmc_disable |
if (!BitstreamGetBit(bs)) // obmc_disable |
343 |
{ |
{ |
344 |
DEBUG("IGNORED/TODO: !obmc_disable"); |
//DPRINTF("IGNORED/TODO: !obmc_disable"); |
345 |
// TODO |
// TODO |
346 |
// fucking divx4.02 has this enabled |
// fucking divx4.02 has this enabled |
347 |
} |
} |
348 |
|
|
349 |
if (BitstreamGetBits(bs, (vol_ver_id == 1 ? 1 : 2))) // sprite_enable |
if (BitstreamGetBits(bs, (vol_ver_id == 1 ? 1 : 2))) // sprite_enable |
350 |
{ |
{ |
351 |
DEBUG("sprite_enable; not supported"); |
//DPRINTF("sprite_enable; not supported"); |
352 |
return -1; |
return -1; |
353 |
} |
} |
354 |
|
|
359 |
|
|
360 |
if (BitstreamGetBit(bs)) // not_8_bit |
if (BitstreamGetBit(bs)) // not_8_bit |
361 |
{ |
{ |
362 |
DEBUG("+ not_8_bit [IGNORED/TODO]"); |
//DPRINTF("+ not_8_bit [IGNORED/TODO]"); |
363 |
dec->quant_bits = BitstreamGetBits(bs, 4); // quant_precision |
dec->quant_bits = BitstreamGetBits(bs, 4); // quant_precision |
364 |
BitstreamSkip(bs, 4); // bits_per_pixel |
BitstreamSkip(bs, 4); // bits_per_pixel |
365 |
} else { |
} else { |
373 |
} |
} |
374 |
|
|
375 |
dec->quant_type = BitstreamGetBit(bs); // quant_type |
dec->quant_type = BitstreamGetBit(bs); // quant_type |
376 |
// DEBUG1("**** quant_type", dec->quant_type); |
//DPRINTF("**** quant_type %i", dec->quant_type); |
377 |
|
|
378 |
if (dec->quant_type) { |
if (dec->quant_type) { |
379 |
if (BitstreamGetBit(bs)) // load_intra_quant_mat |
if (BitstreamGetBit(bs)) // load_intra_quant_mat |
396 |
|
|
397 |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) { |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) { |
398 |
// TODO |
// TODO |
399 |
DEBUG("TODO: grayscale matrix stuff"); |
//DPRINTF("TODO: grayscale matrix stuff"); |
400 |
return -1; |
return -1; |
401 |
} |
} |
402 |
|
|
406 |
if (vol_ver_id != 1) { |
if (vol_ver_id != 1) { |
407 |
dec->quarterpel = BitstreamGetBit(bs); // quarter_sampe |
dec->quarterpel = BitstreamGetBit(bs); // quarter_sampe |
408 |
if (dec->quarterpel) { |
if (dec->quarterpel) { |
409 |
DEBUG("IGNORED/TODO: quarter_sample"); |
//DPRINTF("IGNORED/TODO: quarter_sample"); |
410 |
} |
} |
411 |
} else { |
} else { |
412 |
dec->quarterpel = 0; |
dec->quarterpel = 0; |
414 |
|
|
415 |
if (!BitstreamGetBit(bs)) // complexity_estimation_disable |
if (!BitstreamGetBit(bs)) // complexity_estimation_disable |
416 |
{ |
{ |
417 |
DEBUG("TODO: complexity_estimation header"); |
//DPRINTF("TODO: complexity_estimation header"); |
418 |
// TODO |
// TODO |
419 |
return -1; |
return -1; |
420 |
} |
} |
421 |
|
|
422 |
if (!BitstreamGetBit(bs)) // resync_marker_disable |
if (!BitstreamGetBit(bs)) // resync_marker_disable |
423 |
{ |
{ |
424 |
DEBUG("IGNORED/TODO: !resync_marker_disable"); |
//DPRINTF("IGNORED/TODO: !resync_marker_disable"); |
425 |
// TODO |
// TODO |
426 |
} |
} |
427 |
|
|
428 |
if (BitstreamGetBit(bs)) // data_partitioned |
if (BitstreamGetBit(bs)) // data_partitioned |
429 |
{ |
{ |
430 |
DEBUG("+ data_partitioned"); |
//DPRINTF("+ data_partitioned"); |
431 |
BitstreamSkip(bs, 1); // reversible_vlc |
BitstreamSkip(bs, 1); // reversible_vlc |
432 |
} |
} |
433 |
|
|
434 |
if (vol_ver_id != 1) { |
if (vol_ver_id != 1) { |
435 |
if (BitstreamGetBit(bs)) // newpred_enable |
if (BitstreamGetBit(bs)) // newpred_enable |
436 |
{ |
{ |
437 |
DEBUG("+ newpred_enable"); |
//DPRINTF("+ newpred_enable"); |
438 |
BitstreamSkip(bs, 2); // requested_upstream_message_type |
BitstreamSkip(bs, 2); // requested_upstream_message_type |
439 |
BitstreamSkip(bs, 1); // newpred_segment_type |
BitstreamSkip(bs, 1); // newpred_segment_type |
440 |
} |
} |
441 |
if (BitstreamGetBit(bs)) // reduced_resolution_vop_enable |
if (BitstreamGetBit(bs)) // reduced_resolution_vop_enable |
442 |
{ |
{ |
443 |
DEBUG("TODO: reduced_resolution_vop_enable"); |
//DPRINTF("TODO: reduced_resolution_vop_enable"); |
444 |
// TODO |
// TODO |
445 |
return -1; |
return -1; |
446 |
} |
} |
449 |
if ((dec->scalability = BitstreamGetBit(bs))) // scalability |
if ((dec->scalability = BitstreamGetBit(bs))) // scalability |
450 |
{ |
{ |
451 |
// TODO |
// TODO |
452 |
DEBUG("TODO: scalability"); |
//DPRINTF("TODO: scalability"); |
453 |
return -1; |
return -1; |
454 |
} |
} |
455 |
} else // dec->shape == BINARY_ONLY |
} else // dec->shape == BINARY_ONLY |
458 |
if (BitstreamGetBit(bs)) // scalability |
if (BitstreamGetBit(bs)) // scalability |
459 |
{ |
{ |
460 |
// TODO |
// TODO |
461 |
DEBUG("TODO: scalability"); |
//DPRINTF("TODO: scalability"); |
462 |
return -1; |
return -1; |
463 |
} |
} |
464 |
} |
} |
467 |
} |
} |
468 |
|
|
469 |
} else if (start_code == GRPOFVOP_START_CODE) { |
} else if (start_code == GRPOFVOP_START_CODE) { |
470 |
// DEBUG("group_of_vop"); |
//DPRINTF("group_of_vop"); |
471 |
BitstreamSkip(bs, 32); |
BitstreamSkip(bs, 32); |
472 |
{ |
{ |
473 |
int hours, minutes, seconds; |
int hours, minutes, seconds; |
476 |
minutes = BitstreamGetBits(bs, 6); |
minutes = BitstreamGetBits(bs, 6); |
477 |
READ_MARKER(); |
READ_MARKER(); |
478 |
seconds = BitstreamGetBits(bs, 6); |
seconds = BitstreamGetBits(bs, 6); |
479 |
// DEBUG3("hms", hours, minutes, seconds); |
//DPRINTF("%ih %im %is", hours, minutes, seconds); |
480 |
} |
} |
481 |
BitstreamSkip(bs, 1); // closed_gov |
BitstreamSkip(bs, 1); // closed_gov |
482 |
BitstreamSkip(bs, 1); // broken_link |
BitstreamSkip(bs, 1); // broken_link |
483 |
} else if (start_code == VOP_START_CODE) { |
} else if (start_code == VOP_START_CODE) { |
484 |
// DEBUG("vop_start_code"); |
//DPRINTF("vop_start_code"); |
485 |
BitstreamSkip(bs, 32); // vop_start_code |
BitstreamSkip(bs, 32); // vop_start_code |
486 |
|
|
487 |
coding_type = BitstreamGetBits(bs, 2); // vop_coding_type |
coding_type = BitstreamGetBits(bs, 2); // vop_coding_type |
488 |
//DEBUG1("coding_type", coding_type); |
//DPRINTF("coding_type %i", coding_type); |
489 |
|
|
490 |
// *************************** for decode B-frame time *********************** |
// *************************** for decode B-frame time *********************** |
491 |
while (BitstreamGetBit(bs) != 0) // time_base |
while (BitstreamGetBit(bs) != 0) // time_base |
493 |
|
|
494 |
READ_MARKER(); |
READ_MARKER(); |
495 |
|
|
|
//DEBUG1("time_inc_bits", dec->time_inc_bits); |
|
|
//DEBUG1("vop_time_incr", BitstreamShowBits(bs, dec->time_inc_bits)); |
|
496 |
if (dec->time_inc_bits) { |
if (dec->time_inc_bits) { |
|
//BitstreamSkip(bs, dec->time_inc_bits); // vop_time_increment |
|
497 |
time_increment = (BitstreamGetBits(bs, dec->time_inc_bits)); // vop_time_increment |
time_increment = (BitstreamGetBits(bs, dec->time_inc_bits)); // vop_time_increment |
498 |
} |
} |
499 |
|
|
500 |
|
/* |
501 |
|
DPRINTF("%c %i:%i", |
502 |
|
coding_type == I_VOP ? 'I' : coding_type == P_VOP ? 'P' : 'B', |
503 |
|
time_incr, time_increment); |
504 |
|
*/ |
505 |
|
|
506 |
if (coding_type != B_VOP) { |
if (coding_type != B_VOP) { |
507 |
dec->last_time_base = dec->time_base; |
dec->last_time_base = dec->time_base; |
508 |
dec->time_base += time_incr; |
dec->time_base += time_incr; |
517 |
time_incr) * time_increment_resolution + time_increment; |
time_incr) * time_increment_resolution + time_increment; |
518 |
dec->time_bp = (uint32_t) (dec->last_non_b_time - dec->time); |
dec->time_bp = (uint32_t) (dec->last_non_b_time - dec->time); |
519 |
} |
} |
520 |
//DEBUG1("time_increment=",time_increment); |
//DPRINTF("time_increment %i",time_increment); |
521 |
|
|
522 |
READ_MARKER(); |
READ_MARKER(); |
523 |
|
|
524 |
if (!BitstreamGetBit(bs)) // vop_coded |
if (!BitstreamGetBit(bs)) // vop_coded |
525 |
{ |
{ |
526 |
|
//DPRINTF("**NOT CODED**"); |
527 |
return N_VOP; |
return N_VOP; |
528 |
} |
} |
529 |
|
|
536 |
if ((dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) && |
if ((dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) && |
537 |
(coding_type == P_VOP)) { |
(coding_type == P_VOP)) { |
538 |
*rounding = BitstreamGetBit(bs); // rounding_type |
*rounding = BitstreamGetBit(bs); // rounding_type |
539 |
//DEBUG1("rounding", *rounding); |
//DPRINTF("rounding %i", *rounding); |
540 |
} |
} |
541 |
|
|
542 |
/* if (reduced_resolution_enable) |
/* if (reduced_resolution_enable) |
557 |
vert_mc_ref = BitstreamGetBits(bs, 13); |
vert_mc_ref = BitstreamGetBits(bs, 13); |
558 |
READ_MARKER(); |
READ_MARKER(); |
559 |
|
|
560 |
// DEBUG2("vop_width/height", width, height); |
//DPRINTF("vop_width/height %i x %i", width, height); |
561 |
// DEBUG2("ref ", horiz_mc_ref, vert_mc_ref); |
//DPRINTF("ref %i x %i", horiz_mc_ref, vert_mc_ref); |
562 |
|
|
563 |
BitstreamSkip(bs, 1); // change_conv_ratio_disable |
BitstreamSkip(bs, 1); // change_conv_ratio_disable |
564 |
if (BitstreamGetBit(bs)) // vop_constant_alpha |
if (BitstreamGetBit(bs)) // vop_constant_alpha |
575 |
|
|
576 |
if (dec->interlacing) { |
if (dec->interlacing) { |
577 |
if ((dec->top_field_first = BitstreamGetBit(bs))) { |
if ((dec->top_field_first = BitstreamGetBit(bs))) { |
578 |
DEBUG("vop: top_field_first"); |
//DPRINTF("vop: top_field_first"); |
579 |
} |
} |
580 |
if ((dec->alternate_vertical_scan = BitstreamGetBit(bs))) { |
if ((dec->alternate_vertical_scan = BitstreamGetBit(bs))) { |
581 |
DEBUG("vop: alternate_vertical_scan"); |
//DPRINTF("vop: alternate_vertical_scan"); |
582 |
} |
} |
583 |
} |
} |
584 |
} |
} |
586 |
if ((*quant = BitstreamGetBits(bs, dec->quant_bits)) < 1) // vop_quant |
if ((*quant = BitstreamGetBits(bs, dec->quant_bits)) < 1) // vop_quant |
587 |
*quant = 1; |
*quant = 1; |
588 |
|
|
589 |
//DEBUG1("quant", *quant); |
//DPRINTF("quant %i", *quant); |
590 |
|
|
591 |
if (coding_type != I_VOP) { |
if (coding_type != I_VOP) { |
592 |
*fcode_forward = BitstreamGetBits(bs, 3); // fcode_forward |
*fcode_forward = BitstreamGetBits(bs, 3); // fcode_forward |
603 |
} |
} |
604 |
return coding_type; |
return coding_type; |
605 |
} else if (start_code == USERDATA_START_CODE) { |
} else if (start_code == USERDATA_START_CODE) { |
606 |
// DEBUG("user_data"); |
//DPRINTF("user_data"); |
607 |
BitstreamSkip(bs, 32); // user_data_start_code |
BitstreamSkip(bs, 32); // user_data_start_code |
608 |
} else // start_code == ? |
} else // start_code == ? |
609 |
{ |
{ |
610 |
if (BitstreamShowBits(bs, 24) == 0x000001) { |
if (BitstreamShowBits(bs, 24) == 0x000001) { |
611 |
DEBUG1("*** WARNING: unknown start_code", |
//DPRINTF("*** WARNING: unknown start_code %x", |
612 |
BitstreamShowBits(bs, 32)); |
// BitstreamShowBits(bs, 32)); |
613 |
} |
} |
614 |
BitstreamSkip(bs, 8); |
BitstreamSkip(bs, 8); |
615 |
} |
} |
616 |
} |
} |
617 |
while ((BitstreamPos(bs) >> 3) < bs->length); |
while ((BitstreamPos(bs) >> 3) < bs->length); |
618 |
|
|
619 |
DEBUG("*** WARNING: no vop_start_code found"); |
//DPRINTF("*** WARNING: no vop_start_code found"); |
620 |
return -1; /* ignore it */ |
return -1; /* ignore it */ |
621 |
} |
} |
622 |
|
|
630 |
int i, j; |
int i, j; |
631 |
const int last = matrix[scan_tables[0][63]]; |
const int last = matrix[scan_tables[0][63]]; |
632 |
|
|
633 |
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--); |
634 |
|
|
635 |
for (i = 0; i <= j; i++) { |
for (i = 0; i <= j; i++) { |
636 |
BitstreamPutBits(bs, matrix[scan_tables[0][i]], 8); |
BitstreamPutBits(bs, matrix[scan_tables[0][i]], 8); |
666 |
|
|
667 |
#ifdef BFRAMES |
#ifdef BFRAMES |
668 |
if (pParam->max_bframes > 0) { |
if (pParam->max_bframes > 0) { |
669 |
dprintf("low_delay=1"); |
//DPRINTF("low_delay=1"); |
670 |
BitstreamPutBit(bs, 1); // vol_control_parameters |
BitstreamPutBit(bs, 1); // vol_control_parameters |
671 |
BitstreamPutBits(bs, 1, 2); // chroma_format 1="4:2:0" |
BitstreamPutBits(bs, 1, 2); // chroma_format 1="4:2:0" |
672 |
BitstreamPutBit(bs, 0); // low_delay |
BitstreamPutBit(bs, 0); // low_delay |
695 |
|
|
696 |
WRITE_MARKER(); |
WRITE_MARKER(); |
697 |
|
|
698 |
// fixed_vop_rate |
#ifdef BFRAMES |
699 |
BitstreamPutBit(bs, 0); |
BitstreamPutBit(bs, 1); // fixed_vop_rate = 1 |
700 |
|
BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase)); // fixed_vop_time_increment |
701 |
// fixed_time_increment: value=nth_of_sec, nbits = log2(resolution) |
#else |
702 |
// BitstreamPutBits(bs, 0, 15); |
BitstreamPutBit(bs, 0); // fixed_vop_rate = 0 |
703 |
|
#endif |
704 |
|
|
705 |
WRITE_MARKER(); |
WRITE_MARKER(); |
706 |
BitstreamPutBits(bs, pParam->width, 13); // width |
BitstreamPutBits(bs, pParam->width, 13); // width |
747 |
void |
void |
748 |
BitstreamWriteVopHeader(Bitstream * const bs, |
BitstreamWriteVopHeader(Bitstream * const bs, |
749 |
const MBParam * pParam, |
const MBParam * pParam, |
750 |
const FRAMEINFO * frame) |
const FRAMEINFO * frame, |
751 |
|
int vop_coded) |
752 |
{ |
{ |
753 |
#ifdef BFRAMES |
#ifdef BFRAMES |
754 |
uint32_t i; |
uint32_t i; |
773 |
// time_increment: value=nth_of_sec, nbits = log2(resolution) |
// time_increment: value=nth_of_sec, nbits = log2(resolution) |
774 |
#ifdef BFRAMES |
#ifdef BFRAMES |
775 |
BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase)); |
BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase)); |
776 |
dprintf("[%i:%i] %c\n", frame->seconds, frame->ticks, |
DPRINTF("[%i:%i] %c\n", frame->seconds, frame->ticks, |
777 |
frame->coding_type == I_VOP ? 'I' : frame->coding_type == |
frame->coding_type == I_VOP ? 'I' : frame->coding_type == |
778 |
P_VOP ? 'P' : 'B'); |
P_VOP ? 'P' : 'B'); |
779 |
#else |
#else |
782 |
|
|
783 |
WRITE_MARKER(); |
WRITE_MARKER(); |
784 |
|
|
785 |
|
if (!vop_coded) { |
786 |
|
BitstreamPutBits(bs, 0, 1); |
787 |
|
return; |
788 |
|
} |
789 |
|
|
790 |
BitstreamPutBits(bs, 1, 1); // vop_coded |
BitstreamPutBits(bs, 1, 1); // vop_coded |
791 |
|
|
792 |
if (frame->coding_type == P_VOP) |
if (frame->coding_type == P_VOP) |
808 |
BitstreamPutBits(bs, frame->bcode, 3); // backward_fixed_code |
BitstreamPutBits(bs, frame->bcode, 3); // backward_fixed_code |
809 |
|
|
810 |
} |
} |
811 |
|
|
812 |
|
|
813 |
|
void |
814 |
|
BitstreamWriteUserData(Bitstream * const bs, |
815 |
|
uint8_t * data, |
816 |
|
const int length) |
817 |
|
{ |
818 |
|
int i; |
819 |
|
|
820 |
|
BitstreamPad(bs); |
821 |
|
BitstreamPutBits(bs, USERDATA_START_CODE, 32); |
822 |
|
|
823 |
|
for (i = 0; i < length; i++) { |
824 |
|
BitstreamPutBits(bs, data[i], 8); |
825 |
|
} |
826 |
|
|
827 |
|
} |