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 * |
* 19.06.2002 Fix a little bug in use custom quant matrix * |
47 |
* MinChen <chenm001@163.com> * |
* 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 * |
145 |
start_code = BitstreamShowBits(bs, 32); |
start_code = BitstreamShowBits(bs, 32); |
146 |
|
|
147 |
if (start_code == VISOBJSEQ_START_CODE) { |
if (start_code == VISOBJSEQ_START_CODE) { |
148 |
// DEBUG("visual_object_sequence"); |
// DPRINTF("visual_object_sequence"); |
149 |
BitstreamSkip(bs, 32); // visual_object_sequence_start_code |
BitstreamSkip(bs, 32); // visual_object_sequence_start_code |
150 |
BitstreamSkip(bs, 8); // profile_and_level_indication |
BitstreamSkip(bs, 8); // profile_and_level_indication |
151 |
} else if (start_code == VISOBJSEQ_STOP_CODE) { |
} else if (start_code == VISOBJSEQ_STOP_CODE) { |
152 |
BitstreamSkip(bs, 32); // visual_object_sequence_stop_code |
BitstreamSkip(bs, 32); // visual_object_sequence_stop_code |
153 |
} else if (start_code == VISOBJ_START_CODE) { |
} else if (start_code == VISOBJ_START_CODE) { |
154 |
// DEBUG("visual_object"); |
//DPRINTF("visual_object"); |
155 |
BitstreamSkip(bs, 32); // visual_object_start_code |
BitstreamSkip(bs, 32); // visual_object_start_code |
156 |
if (BitstreamGetBit(bs)) // is_visual_object_identified |
if (BitstreamGetBit(bs)) // is_visual_object_identified |
157 |
{ |
{ |
163 |
|
|
164 |
if (BitstreamShowBits(bs, 4) != VISOBJ_TYPE_VIDEO) // visual_object_type |
if (BitstreamShowBits(bs, 4) != VISOBJ_TYPE_VIDEO) // visual_object_type |
165 |
{ |
{ |
166 |
DEBUG("visual_object_type != video"); |
//DPRINTF("visual_object_type != video"); |
167 |
return -1; |
return -1; |
168 |
} |
} |
169 |
BitstreamSkip(bs, 4); |
BitstreamSkip(bs, 4); |
172 |
|
|
173 |
if (BitstreamGetBit(bs)) // video_signal_type |
if (BitstreamGetBit(bs)) // video_signal_type |
174 |
{ |
{ |
175 |
DEBUG("+ video_signal_type"); |
//DPRINTF("+ video_signal_type"); |
176 |
BitstreamSkip(bs, 3); // video_format |
BitstreamSkip(bs, 3); // video_format |
177 |
BitstreamSkip(bs, 1); // video_range |
BitstreamSkip(bs, 1); // video_range |
178 |
if (BitstreamGetBit(bs)) // color_description |
if (BitstreamGetBit(bs)) // color_description |
179 |
{ |
{ |
180 |
DEBUG("+ color_description"); |
//DPRINTF("+ color_description"); |
181 |
BitstreamSkip(bs, 8); // color_primaries |
BitstreamSkip(bs, 8); // color_primaries |
182 |
BitstreamSkip(bs, 8); // transfer_characteristics |
BitstreamSkip(bs, 8); // transfer_characteristics |
183 |
BitstreamSkip(bs, 8); // matrix_coefficients |
BitstreamSkip(bs, 8); // matrix_coefficients |
186 |
} else if ((start_code & ~0x1f) == VIDOBJ_START_CODE) { |
} else if ((start_code & ~0x1f) == VIDOBJ_START_CODE) { |
187 |
BitstreamSkip(bs, 32); // video_object_start_code |
BitstreamSkip(bs, 32); // video_object_start_code |
188 |
} else if ((start_code & ~0xf) == VIDOBJLAY_START_CODE) { |
} else if ((start_code & ~0xf) == VIDOBJLAY_START_CODE) { |
189 |
// DEBUG("video_object_layer"); |
//DPRINTF("video_object_layer"); |
190 |
BitstreamSkip(bs, 32); // video_object_layer_start_code |
BitstreamSkip(bs, 32); // video_object_layer_start_code |
191 |
|
|
192 |
BitstreamSkip(bs, 1); // random_accessible_vol |
BitstreamSkip(bs, 1); // random_accessible_vol |
194 |
// video_object_type_indication |
// video_object_type_indication |
195 |
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 |
196 |
{ |
{ |
197 |
DEBUG1("video_object_type_indication not supported", |
//DPRINTF("video_object_type_indication %i not supported ", |
198 |
BitstreamShowBits(bs, 8)); |
// BitstreamShowBits(bs, 8)); |
199 |
return -1; |
return -1; |
200 |
} |
} |
201 |
BitstreamSkip(bs, 8); |
BitstreamSkip(bs, 8); |
203 |
|
|
204 |
if (BitstreamGetBit(bs)) // is_object_layer_identifier |
if (BitstreamGetBit(bs)) // is_object_layer_identifier |
205 |
{ |
{ |
206 |
DEBUG("+ is_object_layer_identifier"); |
//DPRINTF("+ is_object_layer_identifier"); |
207 |
vol_ver_id = BitstreamGetBits(bs, 4); // video_object_layer_verid |
vol_ver_id = BitstreamGetBits(bs, 4); // video_object_layer_verid |
208 |
BitstreamSkip(bs, 3); // video_object_layer_priority |
BitstreamSkip(bs, 3); // video_object_layer_priority |
209 |
} else { |
} else { |
210 |
vol_ver_id = 1; |
vol_ver_id = 1; |
211 |
} |
} |
212 |
//DEBUGI("vol_ver_id", vol_ver_id); |
//DPRINTF("vol_ver_id %i", vol_ver_id); |
213 |
|
|
214 |
if (BitstreamGetBits(bs, 4) == VIDOBJLAY_AR_EXTPAR) // aspect_ratio_info |
if (BitstreamGetBits(bs, 4) == VIDOBJLAY_AR_EXTPAR) // aspect_ratio_info |
215 |
{ |
{ |
216 |
DEBUG("+ aspect_ratio_info"); |
//DPRINTF("+ aspect_ratio_info"); |
217 |
BitstreamSkip(bs, 8); // par_width |
BitstreamSkip(bs, 8); // par_width |
218 |
BitstreamSkip(bs, 8); // par_height |
BitstreamSkip(bs, 8); // par_height |
219 |
} |
} |
220 |
|
|
221 |
if (BitstreamGetBit(bs)) // vol_control_parameters |
if (BitstreamGetBit(bs)) // vol_control_parameters |
222 |
{ |
{ |
223 |
DEBUG("+ vol_control_parameters"); |
//DPRINTF("+ vol_control_parameters"); |
224 |
BitstreamSkip(bs, 2); // chroma_format |
BitstreamSkip(bs, 2); // chroma_format |
225 |
dec->low_delay = BitstreamGetBit(bs); // low_delay |
dec->low_delay = BitstreamGetBit(bs); // low_delay |
226 |
if (BitstreamGetBit(bs)) // vbv_parameters |
if (BitstreamGetBit(bs)) // vbv_parameters |
227 |
{ |
{ |
228 |
DEBUG("+ vbv_parameters"); |
//DPRINTF("+ vbv_parameters"); |
229 |
BitstreamSkip(bs, 15); // first_half_bitrate |
BitstreamSkip(bs, 15); // first_half_bitrate |
230 |
READ_MARKER(); |
READ_MARKER(); |
231 |
BitstreamSkip(bs, 15); // latter_half_bitrate |
BitstreamSkip(bs, 15); // latter_half_bitrate |
242 |
} |
} |
243 |
|
|
244 |
dec->shape = BitstreamGetBits(bs, 2); // video_object_layer_shape |
dec->shape = BitstreamGetBits(bs, 2); // video_object_layer_shape |
245 |
// DEBUG1("shape", dec->shape); |
//DPRINTF("shape %i", dec->shape); |
246 |
|
|
247 |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE && vol_ver_id != 1) { |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE && vol_ver_id != 1) { |
248 |
BitstreamSkip(bs, 4); // video_object_layer_shape_extension |
BitstreamSkip(bs, 4); // video_object_layer_shape_extension |
253 |
// *************************** for decode B-frame time *********************** |
// *************************** for decode B-frame time *********************** |
254 |
time_increment_resolution = BitstreamGetBits(bs, 16); // vop_time_increment_resolution |
time_increment_resolution = BitstreamGetBits(bs, 16); // vop_time_increment_resolution |
255 |
time_increment_resolution--; |
time_increment_resolution--; |
256 |
//DEBUG1("time_increment_resolution=",time_increment_resolution); |
//DPRINTF("time_increment_resolution = %i",time_increment_resolution); |
257 |
if (time_increment_resolution > 0) { |
if (time_increment_resolution > 0) { |
258 |
dec->time_inc_bits = log2bin(time_increment_resolution); |
dec->time_inc_bits = log2bin(time_increment_resolution); |
259 |
} else { |
} else { |
277 |
|
|
278 |
READ_MARKER(); |
READ_MARKER(); |
279 |
width = BitstreamGetBits(bs, 13); // video_object_layer_width |
width = BitstreamGetBits(bs, 13); // video_object_layer_width |
280 |
//DEBUGI("width", width); |
//DPRINTF("width %i", width); |
281 |
READ_MARKER(); |
READ_MARKER(); |
282 |
height = BitstreamGetBits(bs, 13); // video_object_layer_height |
height = BitstreamGetBits(bs, 13); // video_object_layer_height |
283 |
//DEBUGI("height", height); |
//DPRINTF("height %i", height); |
284 |
READ_MARKER(); |
READ_MARKER(); |
285 |
|
|
286 |
if (width != dec->width || height != dec->height) { |
if (width != dec->width || height != dec->height) { |
287 |
DEBUG("FATAL: video dimension discrepancy ***"); |
//DPRINTF("FATAL: video dimension discrepancy ***"); |
288 |
DEBUG2("bitstream width/height", width, height); |
//DPRINTF("bitstream width/height %i x %i", width, height); |
289 |
DEBUG2("param width/height", dec->width, dec->height); |
//DPRINTF("param width/height %i x %i", dec->width, dec->height); |
290 |
return -1; |
return -1; |
291 |
} |
} |
292 |
|
|
293 |
} |
} |
294 |
|
|
295 |
if ((dec->interlacing = BitstreamGetBit(bs))) { |
if ((dec->interlacing = BitstreamGetBit(bs))) { |
296 |
DEBUG("vol: interlacing"); |
//DPRINTF("vol: interlacing"); |
297 |
} |
} |
298 |
|
|
299 |
if (!BitstreamGetBit(bs)) // obmc_disable |
if (!BitstreamGetBit(bs)) // obmc_disable |
300 |
{ |
{ |
301 |
DEBUG("IGNORED/TODO: !obmc_disable"); |
//DPRINTF("IGNORED/TODO: !obmc_disable"); |
302 |
// TODO |
// TODO |
303 |
// fucking divx4.02 has this enabled |
// fucking divx4.02 has this enabled |
304 |
} |
} |
305 |
|
|
306 |
if (BitstreamGetBits(bs, (vol_ver_id == 1 ? 1 : 2))) // sprite_enable |
if (BitstreamGetBits(bs, (vol_ver_id == 1 ? 1 : 2))) // sprite_enable |
307 |
{ |
{ |
308 |
DEBUG("sprite_enable; not supported"); |
//DPRINTF("sprite_enable; not supported"); |
309 |
return -1; |
return -1; |
310 |
} |
} |
311 |
|
|
316 |
|
|
317 |
if (BitstreamGetBit(bs)) // not_8_bit |
if (BitstreamGetBit(bs)) // not_8_bit |
318 |
{ |
{ |
319 |
DEBUG("+ not_8_bit [IGNORED/TODO]"); |
//DPRINTF("+ not_8_bit [IGNORED/TODO]"); |
320 |
dec->quant_bits = BitstreamGetBits(bs, 4); // quant_precision |
dec->quant_bits = BitstreamGetBits(bs, 4); // quant_precision |
321 |
BitstreamSkip(bs, 4); // bits_per_pixel |
BitstreamSkip(bs, 4); // bits_per_pixel |
322 |
} else { |
} else { |
330 |
} |
} |
331 |
|
|
332 |
dec->quant_type = BitstreamGetBit(bs); // quant_type |
dec->quant_type = BitstreamGetBit(bs); // quant_type |
333 |
// DEBUG1("**** quant_type", dec->quant_type); |
//DPRINTF("**** quant_type %i", dec->quant_type); |
334 |
|
|
335 |
if (dec->quant_type) { |
if (dec->quant_type) { |
336 |
if (BitstreamGetBit(bs)) // load_intra_quant_mat |
if (BitstreamGetBit(bs)) // load_intra_quant_mat |
353 |
|
|
354 |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) { |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) { |
355 |
// TODO |
// TODO |
356 |
DEBUG("TODO: grayscale matrix stuff"); |
//DPRINTF("TODO: grayscale matrix stuff"); |
357 |
return -1; |
return -1; |
358 |
} |
} |
359 |
|
|
363 |
if (vol_ver_id != 1) { |
if (vol_ver_id != 1) { |
364 |
dec->quarterpel = BitstreamGetBit(bs); // quarter_sampe |
dec->quarterpel = BitstreamGetBit(bs); // quarter_sampe |
365 |
if (dec->quarterpel) { |
if (dec->quarterpel) { |
366 |
DEBUG("IGNORED/TODO: quarter_sample"); |
//DPRINTF("IGNORED/TODO: quarter_sample"); |
367 |
} |
} |
368 |
} else { |
} else { |
369 |
dec->quarterpel = 0; |
dec->quarterpel = 0; |
371 |
|
|
372 |
if (!BitstreamGetBit(bs)) // complexity_estimation_disable |
if (!BitstreamGetBit(bs)) // complexity_estimation_disable |
373 |
{ |
{ |
374 |
DEBUG("TODO: complexity_estimation header"); |
//DPRINTF("TODO: complexity_estimation header"); |
375 |
// TODO |
// TODO |
376 |
return -1; |
return -1; |
377 |
} |
} |
378 |
|
|
379 |
if (!BitstreamGetBit(bs)) // resync_marker_disable |
if (!BitstreamGetBit(bs)) // resync_marker_disable |
380 |
{ |
{ |
381 |
DEBUG("IGNORED/TODO: !resync_marker_disable"); |
//DPRINTF("IGNORED/TODO: !resync_marker_disable"); |
382 |
// TODO |
// TODO |
383 |
} |
} |
384 |
|
|
385 |
if (BitstreamGetBit(bs)) // data_partitioned |
if (BitstreamGetBit(bs)) // data_partitioned |
386 |
{ |
{ |
387 |
DEBUG("+ data_partitioned"); |
//DPRINTF("+ data_partitioned"); |
388 |
BitstreamSkip(bs, 1); // reversible_vlc |
BitstreamSkip(bs, 1); // reversible_vlc |
389 |
} |
} |
390 |
|
|
391 |
if (vol_ver_id != 1) { |
if (vol_ver_id != 1) { |
392 |
if (BitstreamGetBit(bs)) // newpred_enable |
if (BitstreamGetBit(bs)) // newpred_enable |
393 |
{ |
{ |
394 |
DEBUG("+ newpred_enable"); |
//DPRINTF("+ newpred_enable"); |
395 |
BitstreamSkip(bs, 2); // requested_upstream_message_type |
BitstreamSkip(bs, 2); // requested_upstream_message_type |
396 |
BitstreamSkip(bs, 1); // newpred_segment_type |
BitstreamSkip(bs, 1); // newpred_segment_type |
397 |
} |
} |
398 |
if (BitstreamGetBit(bs)) // reduced_resolution_vop_enable |
if (BitstreamGetBit(bs)) // reduced_resolution_vop_enable |
399 |
{ |
{ |
400 |
DEBUG("TODO: reduced_resolution_vop_enable"); |
//DPRINTF("TODO: reduced_resolution_vop_enable"); |
401 |
// TODO |
// TODO |
402 |
return -1; |
return -1; |
403 |
} |
} |
406 |
if ((dec->scalability = BitstreamGetBit(bs))) // scalability |
if ((dec->scalability = BitstreamGetBit(bs))) // scalability |
407 |
{ |
{ |
408 |
// TODO |
// TODO |
409 |
DEBUG("TODO: scalability"); |
//DPRINTF("TODO: scalability"); |
410 |
return -1; |
return -1; |
411 |
} |
} |
412 |
} else // dec->shape == BINARY_ONLY |
} else // dec->shape == BINARY_ONLY |
415 |
if (BitstreamGetBit(bs)) // scalability |
if (BitstreamGetBit(bs)) // scalability |
416 |
{ |
{ |
417 |
// TODO |
// TODO |
418 |
DEBUG("TODO: scalability"); |
//DPRINTF("TODO: scalability"); |
419 |
return -1; |
return -1; |
420 |
} |
} |
421 |
} |
} |
424 |
} |
} |
425 |
|
|
426 |
} else if (start_code == GRPOFVOP_START_CODE) { |
} else if (start_code == GRPOFVOP_START_CODE) { |
427 |
// DEBUG("group_of_vop"); |
//DPRINTF("group_of_vop"); |
428 |
BitstreamSkip(bs, 32); |
BitstreamSkip(bs, 32); |
429 |
{ |
{ |
430 |
int hours, minutes, seconds; |
int hours, minutes, seconds; |
433 |
minutes = BitstreamGetBits(bs, 6); |
minutes = BitstreamGetBits(bs, 6); |
434 |
READ_MARKER(); |
READ_MARKER(); |
435 |
seconds = BitstreamGetBits(bs, 6); |
seconds = BitstreamGetBits(bs, 6); |
436 |
// DEBUG3("hms", hours, minutes, seconds); |
//DPRINTF("%ih %im %is", hours, minutes, seconds); |
437 |
} |
} |
438 |
BitstreamSkip(bs, 1); // closed_gov |
BitstreamSkip(bs, 1); // closed_gov |
439 |
BitstreamSkip(bs, 1); // broken_link |
BitstreamSkip(bs, 1); // broken_link |
440 |
} else if (start_code == VOP_START_CODE) { |
} else if (start_code == VOP_START_CODE) { |
441 |
// DEBUG("vop_start_code"); |
//DPRINTF("vop_start_code"); |
442 |
BitstreamSkip(bs, 32); // vop_start_code |
BitstreamSkip(bs, 32); // vop_start_code |
443 |
|
|
444 |
coding_type = BitstreamGetBits(bs, 2); // vop_coding_type |
coding_type = BitstreamGetBits(bs, 2); // vop_coding_type |
445 |
//DEBUG1("coding_type", coding_type); |
//DPRINTF("coding_type %i", coding_type); |
446 |
|
|
447 |
// *************************** for decode B-frame time *********************** |
// *************************** for decode B-frame time *********************** |
448 |
while (BitstreamGetBit(bs) != 0) // time_base |
while (BitstreamGetBit(bs) != 0) // time_base |
450 |
|
|
451 |
READ_MARKER(); |
READ_MARKER(); |
452 |
|
|
|
//DEBUG1("time_inc_bits", 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) { |
|
//BitstreamSkip(bs, dec->time_inc_bits); // vop_time_increment |
|
454 |
time_increment = (BitstreamGetBits(bs, dec->time_inc_bits)); // vop_time_increment |
time_increment = (BitstreamGetBits(bs, dec->time_inc_bits)); // vop_time_increment |
455 |
} |
} |
456 |
|
|
457 |
|
/* |
458 |
|
DPRINTF("%c %i:%i", |
459 |
|
coding_type == I_VOP ? 'I' : coding_type == P_VOP ? 'P' : 'B', |
460 |
|
time_incr, time_increment); |
461 |
|
*/ |
462 |
|
|
463 |
if (coding_type != B_VOP) { |
if (coding_type != B_VOP) { |
464 |
dec->last_time_base = dec->time_base; |
dec->last_time_base = dec->time_base; |
465 |
dec->time_base += time_incr; |
dec->time_base += time_incr; |
474 |
time_incr) * time_increment_resolution + time_increment; |
time_incr) * time_increment_resolution + time_increment; |
475 |
dec->time_bp = (uint32_t) (dec->last_non_b_time - dec->time); |
dec->time_bp = (uint32_t) (dec->last_non_b_time - dec->time); |
476 |
} |
} |
477 |
//DEBUG1("time_increment=",time_increment); |
//DPRINTF("time_increment %i",time_increment); |
478 |
|
|
479 |
READ_MARKER(); |
READ_MARKER(); |
480 |
|
|
481 |
if (!BitstreamGetBit(bs)) // vop_coded |
if (!BitstreamGetBit(bs)) // vop_coded |
482 |
{ |
{ |
483 |
|
//DPRINTF("**NOT CODED**"); |
484 |
return N_VOP; |
return N_VOP; |
485 |
} |
} |
486 |
|
|
493 |
if ((dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) && |
if ((dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) && |
494 |
(coding_type == P_VOP)) { |
(coding_type == P_VOP)) { |
495 |
*rounding = BitstreamGetBit(bs); // rounding_type |
*rounding = BitstreamGetBit(bs); // rounding_type |
496 |
//DEBUG1("rounding", *rounding); |
//DPRINTF("rounding %i", *rounding); |
497 |
} |
} |
498 |
|
|
499 |
/* if (reduced_resolution_enable) |
/* if (reduced_resolution_enable) |
514 |
vert_mc_ref = BitstreamGetBits(bs, 13); |
vert_mc_ref = BitstreamGetBits(bs, 13); |
515 |
READ_MARKER(); |
READ_MARKER(); |
516 |
|
|
517 |
// DEBUG2("vop_width/height", width, height); |
//DPRINTF("vop_width/height %i x %i", width, height); |
518 |
// DEBUG2("ref ", horiz_mc_ref, vert_mc_ref); |
//DPRINTF("ref %i x %i", horiz_mc_ref, vert_mc_ref); |
519 |
|
|
520 |
BitstreamSkip(bs, 1); // change_conv_ratio_disable |
BitstreamSkip(bs, 1); // change_conv_ratio_disable |
521 |
if (BitstreamGetBit(bs)) // vop_constant_alpha |
if (BitstreamGetBit(bs)) // vop_constant_alpha |
532 |
|
|
533 |
if (dec->interlacing) { |
if (dec->interlacing) { |
534 |
if ((dec->top_field_first = BitstreamGetBit(bs))) { |
if ((dec->top_field_first = BitstreamGetBit(bs))) { |
535 |
DEBUG("vop: top_field_first"); |
//DPRINTF("vop: top_field_first"); |
536 |
} |
} |
537 |
if ((dec->alternate_vertical_scan = BitstreamGetBit(bs))) { |
if ((dec->alternate_vertical_scan = BitstreamGetBit(bs))) { |
538 |
DEBUG("vop: alternate_vertical_scan"); |
//DPRINTF("vop: alternate_vertical_scan"); |
539 |
} |
} |
540 |
} |
} |
541 |
} |
} |
543 |
if ((*quant = BitstreamGetBits(bs, dec->quant_bits)) < 1) // vop_quant |
if ((*quant = BitstreamGetBits(bs, dec->quant_bits)) < 1) // vop_quant |
544 |
*quant = 1; |
*quant = 1; |
545 |
|
|
546 |
//DEBUG1("quant", *quant); |
//DPRINTF("quant %i", *quant); |
547 |
|
|
548 |
if (coding_type != I_VOP) { |
if (coding_type != I_VOP) { |
549 |
*fcode_forward = BitstreamGetBits(bs, 3); // fcode_forward |
*fcode_forward = BitstreamGetBits(bs, 3); // fcode_forward |
560 |
} |
} |
561 |
return coding_type; |
return coding_type; |
562 |
} else if (start_code == USERDATA_START_CODE) { |
} else if (start_code == USERDATA_START_CODE) { |
563 |
// DEBUG("user_data"); |
//DPRINTF("user_data"); |
564 |
BitstreamSkip(bs, 32); // user_data_start_code |
BitstreamSkip(bs, 32); // user_data_start_code |
565 |
} else // start_code == ? |
} else // start_code == ? |
566 |
{ |
{ |
567 |
if (BitstreamShowBits(bs, 24) == 0x000001) { |
if (BitstreamShowBits(bs, 24) == 0x000001) { |
568 |
DEBUG1("*** WARNING: unknown start_code", |
//DPRINTF("*** WARNING: unknown start_code %x", |
569 |
BitstreamShowBits(bs, 32)); |
// BitstreamShowBits(bs, 32)); |
570 |
} |
} |
571 |
BitstreamSkip(bs, 8); |
BitstreamSkip(bs, 8); |
572 |
} |
} |
573 |
} |
} |
574 |
while ((BitstreamPos(bs) >> 3) < bs->length); |
while ((BitstreamPos(bs) >> 3) < bs->length); |
575 |
|
|
576 |
DEBUG("*** WARNING: no vop_start_code found"); |
//DPRINTF("*** WARNING: no vop_start_code found"); |
577 |
return -1; /* ignore it */ |
return -1; /* ignore it */ |
578 |
} |
} |
579 |
|
|
587 |
int i, j; |
int i, j; |
588 |
const int last = matrix[scan_tables[0][63]]; |
const int last = matrix[scan_tables[0][63]]; |
589 |
|
|
590 |
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--); |
591 |
|
|
592 |
for (i = 0; i <= j; i++) { |
for (i = 0; i <= j; i++) { |
593 |
BitstreamPutBits(bs, matrix[scan_tables[0][i]], 8); |
BitstreamPutBits(bs, matrix[scan_tables[0][i]], 8); |
623 |
|
|
624 |
#ifdef BFRAMES |
#ifdef BFRAMES |
625 |
if (pParam->max_bframes > 0) { |
if (pParam->max_bframes > 0) { |
626 |
dprintf("low_delay=1"); |
//DPRINTF("low_delay=1"); |
627 |
BitstreamPutBit(bs, 1); // vol_control_parameters |
BitstreamPutBit(bs, 1); // vol_control_parameters |
628 |
BitstreamPutBits(bs, 1, 2); // chroma_format 1="4:2:0" |
BitstreamPutBits(bs, 1, 2); // chroma_format 1="4:2:0" |
629 |
BitstreamPutBit(bs, 0); // low_delay |
BitstreamPutBit(bs, 0); // low_delay |
652 |
|
|
653 |
WRITE_MARKER(); |
WRITE_MARKER(); |
654 |
|
|
655 |
// fixed_vop_rate |
#ifdef BFRAMES |
656 |
BitstreamPutBit(bs, 0); |
BitstreamPutBit(bs, 1); // fixed_vop_rate = 1 |
657 |
|
BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase)); // fixed_vop_time_increment |
658 |
// fixed_time_increment: value=nth_of_sec, nbits = log2(resolution) |
#else |
659 |
// BitstreamPutBits(bs, 0, 15); |
BitstreamPutBit(bs, 0); // fixed_vop_rate = 0 |
660 |
|
#endif |
661 |
|
|
662 |
WRITE_MARKER(); |
WRITE_MARKER(); |
663 |
BitstreamPutBits(bs, pParam->width, 13); // width |
BitstreamPutBits(bs, pParam->width, 13); // width |
704 |
void |
void |
705 |
BitstreamWriteVopHeader(Bitstream * const bs, |
BitstreamWriteVopHeader(Bitstream * const bs, |
706 |
const MBParam * pParam, |
const MBParam * pParam, |
707 |
const FRAMEINFO * frame) |
const FRAMEINFO * frame, |
708 |
|
int vop_coded) |
709 |
{ |
{ |
710 |
#ifdef BFRAMES |
#ifdef BFRAMES |
711 |
uint32_t i; |
uint32_t i; |
730 |
// time_increment: value=nth_of_sec, nbits = log2(resolution) |
// time_increment: value=nth_of_sec, nbits = log2(resolution) |
731 |
#ifdef BFRAMES |
#ifdef BFRAMES |
732 |
BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase)); |
BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase)); |
733 |
dprintf("[%i:%i] %c\n", frame->seconds, frame->ticks, |
DPRINTF("[%i:%i] %c\n", frame->seconds, frame->ticks, |
734 |
frame->coding_type == I_VOP ? 'I' : frame->coding_type == |
frame->coding_type == I_VOP ? 'I' : frame->coding_type == |
735 |
P_VOP ? 'P' : 'B'); |
P_VOP ? 'P' : 'B'); |
736 |
#else |
#else |
739 |
|
|
740 |
WRITE_MARKER(); |
WRITE_MARKER(); |
741 |
|
|
742 |
|
if (!vop_coded) { |
743 |
|
BitstreamPutBits(bs, 0, 1); |
744 |
|
return; |
745 |
|
} |
746 |
|
|
747 |
BitstreamPutBits(bs, 1, 1); // vop_coded |
BitstreamPutBits(bs, 1, 1); // vop_coded |
748 |
|
|
749 |
if (frame->coding_type == P_VOP) |
if (frame->coding_type == P_VOP) |
765 |
BitstreamPutBits(bs, frame->bcode, 3); // backward_fixed_code |
BitstreamPutBits(bs, frame->bcode, 3); // backward_fixed_code |
766 |
|
|
767 |
} |
} |
768 |
|
|
769 |
|
|
770 |
|
void |
771 |
|
BitstreamWriteUserData(Bitstream * const bs, |
772 |
|
uint8_t * data, |
773 |
|
const int length) |
774 |
|
{ |
775 |
|
int i; |
776 |
|
|
777 |
|
BitstreamPad(bs); |
778 |
|
BitstreamPutBits(bs, USERDATA_START_CODE, 32); |
779 |
|
|
780 |
|
for (i = 0; i < length; i++) { |
781 |
|
BitstreamPutBits(bs, data[i], 8); |
782 |
|
} |
783 |
|
|
784 |
|
} |