41 |
* * |
* * |
42 |
* Revision history: * |
* Revision history: * |
43 |
* * |
* * |
44 |
* 28.10.2002 GMC support - gruel * |
* 05.01.2003 GMC support - gruel * |
45 |
* 04.10.2002 qpel support - Isibaar * |
* 04.10.2002 qpel support - Isibaar * |
46 |
* 11.07.2002 add VOP width & height return to dec when dec->width * |
* 11.07.2002 add VOP width & height return to dec when dec->width * |
47 |
* or dec->height is 0 (for use in examples/ex1.c) * |
* or dec->height is 0 (for use in examples/ex1.c) * |
67 |
|
|
68 |
|
|
69 |
#include <string.h> |
#include <string.h> |
70 |
|
#include <stdio.h> |
71 |
|
|
72 |
#include "bitstream.h" |
#include "bitstream.h" |
73 |
#include "zigzag.h" |
#include "zigzag.h" |
74 |
#include "../quant/quant_matrix.h" |
#include "../quant/quant_matrix.h" |
79 |
log2bin(uint32_t value) |
log2bin(uint32_t value) |
80 |
{ |
{ |
81 |
/* Changed by Chenm001 */ |
/* Changed by Chenm001 */ |
82 |
#ifndef WIN32 |
#if !defined(_MSC_VER) |
83 |
int n = 0; |
int n = 0; |
84 |
|
|
85 |
while (value) { |
while (value) { |
173 |
|
|
174 |
if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) |
if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) |
175 |
{ |
{ |
176 |
*quant = BitstreamGetBits(bs, 5); /* quant_scale */ |
*quant = BitstreamGetBits(bs, dec->quant_bits); /* quant_scale */ |
177 |
DPRINTF(DPRINTF_HEADER, "quant %i", *quant); |
DPRINTF(DPRINTF_HEADER, "quant %i", *quant); |
178 |
} |
} |
179 |
|
|
218 |
dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR && |
dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR && |
219 |
(coding_type == P_VOP || coding_type == I_VOP)) |
(coding_type == P_VOP || coding_type == I_VOP)) |
220 |
{ |
{ |
221 |
BitstreamSkip(bs, 1); /* vop_reduced_resolution */ |
BitstreamSkip(bs, 1); /* XXX: vop_reduced_resolution */ |
222 |
} |
} |
223 |
|
|
224 |
if (coding_type != I_VOP && fcode_forward) |
if (coding_type != I_VOP && fcode_forward) |
230 |
if (coding_type == B_VOP && fcode_backward) |
if (coding_type == B_VOP && fcode_backward) |
231 |
{ |
{ |
232 |
*fcode_backward = BitstreamGetBits(bs, 3); |
*fcode_backward = BitstreamGetBits(bs, 3); |
233 |
DPRINTF(DPRINTF_HEADER,"fcode_backward %i", fcode_backward); |
DPRINTF(DPRINTF_HEADER,"fcode_backward %i", *fcode_backward); |
234 |
} |
} |
235 |
} |
} |
236 |
|
|
256 |
|
|
257 |
|
|
258 |
|
|
259 |
|
|
260 |
|
/* vol estimation header */ |
261 |
|
static void |
262 |
|
read_vol_complexity_estimation_header(Bitstream * bs, DECODER * dec) |
263 |
|
{ |
264 |
|
ESTIMATION * e = &dec->estimation; |
265 |
|
|
266 |
|
e->method = BitstreamGetBits(bs, 2); /* estimation_method */ |
267 |
|
DPRINTF(DPRINTF_HEADER,"+ complexity_estimation_header; method=%i", e->method); |
268 |
|
|
269 |
|
if (e->method == 0 || e->method == 1) |
270 |
|
{ |
271 |
|
if (!BitstreamGetBit(bs)) /* shape_complexity_estimation_disable */ |
272 |
|
{ |
273 |
|
e->opaque = BitstreamGetBit(bs); /* opaque */ |
274 |
|
e->transparent = BitstreamGetBit(bs); /* transparent */ |
275 |
|
e->intra_cae = BitstreamGetBit(bs); /* intra_cae */ |
276 |
|
e->inter_cae = BitstreamGetBit(bs); /* inter_cae */ |
277 |
|
e->no_update = BitstreamGetBit(bs); /* no_update */ |
278 |
|
e->upsampling = BitstreamGetBit(bs); /* upsampling */ |
279 |
|
} |
280 |
|
|
281 |
|
if (!BitstreamGetBit(bs)) /* texture_complexity_estimation_set_1_disable */ |
282 |
|
{ |
283 |
|
e->intra_blocks = BitstreamGetBit(bs); /* intra_blocks */ |
284 |
|
e->inter_blocks = BitstreamGetBit(bs); /* inter_blocks */ |
285 |
|
e->inter4v_blocks = BitstreamGetBit(bs); /* inter4v_blocks */ |
286 |
|
e->not_coded_blocks = BitstreamGetBit(bs); /* not_coded_blocks */ |
287 |
|
} |
288 |
|
} |
289 |
|
|
290 |
|
READ_MARKER(); |
291 |
|
|
292 |
|
if (!BitstreamGetBit(bs)) /* texture_complexity_estimation_set_2_disable */ |
293 |
|
{ |
294 |
|
e->dct_coefs = BitstreamGetBit(bs); /* dct_coefs */ |
295 |
|
e->dct_lines = BitstreamGetBit(bs); /* dct_lines */ |
296 |
|
e->vlc_symbols = BitstreamGetBit(bs); /* vlc_symbols */ |
297 |
|
e->vlc_bits = BitstreamGetBit(bs); /* vlc_bits */ |
298 |
|
} |
299 |
|
|
300 |
|
if (!BitstreamGetBit(bs)) /* motion_compensation_complexity_disable */ |
301 |
|
{ |
302 |
|
e->apm = BitstreamGetBit(bs); /* apm */ |
303 |
|
e->npm = BitstreamGetBit(bs); /* npm */ |
304 |
|
e->interpolate_mc_q = BitstreamGetBit(bs); /* interpolate_mc_q */ |
305 |
|
e->forw_back_mc_q = BitstreamGetBit(bs); /* forw_back_mc_q */ |
306 |
|
e->halfpel2 = BitstreamGetBit(bs); /* halfpel2 */ |
307 |
|
e->halfpel4 = BitstreamGetBit(bs); /* halfpel4 */ |
308 |
|
} |
309 |
|
|
310 |
|
READ_MARKER(); |
311 |
|
|
312 |
|
if (e->method == 1) |
313 |
|
{ |
314 |
|
if (!BitstreamGetBit(bs)) /* version2_complexity_estimation_disable */ |
315 |
|
{ |
316 |
|
e->sadct = BitstreamGetBit(bs); /* sadct */ |
317 |
|
e->quarterpel = BitstreamGetBit(bs); /* quarterpel */ |
318 |
|
} |
319 |
|
} |
320 |
|
} |
321 |
|
|
322 |
|
|
323 |
|
/* vop estimation header */ |
324 |
|
static void |
325 |
|
read_vop_complexity_estimation_header(Bitstream * bs, DECODER * dec, int coding_type) |
326 |
|
{ |
327 |
|
ESTIMATION * e = &dec->estimation; |
328 |
|
|
329 |
|
if (e->method == 0 || e->method == 1) |
330 |
|
{ |
331 |
|
if (coding_type == I_VOP) { |
332 |
|
if (e->opaque) BitstreamSkip(bs, 8); /* dcecs_opaque */ |
333 |
|
if (e->transparent) BitstreamSkip(bs, 8); /* */ |
334 |
|
if (e->intra_cae) BitstreamSkip(bs, 8); /* */ |
335 |
|
if (e->inter_cae) BitstreamSkip(bs, 8); /* */ |
336 |
|
if (e->no_update) BitstreamSkip(bs, 8); /* */ |
337 |
|
if (e->upsampling) BitstreamSkip(bs, 8); /* */ |
338 |
|
if (e->intra_blocks) BitstreamSkip(bs, 8); /* */ |
339 |
|
if (e->not_coded_blocks) BitstreamSkip(bs, 8); /* */ |
340 |
|
if (e->dct_coefs) BitstreamSkip(bs, 8); /* */ |
341 |
|
if (e->dct_lines) BitstreamSkip(bs, 8); /* */ |
342 |
|
if (e->vlc_symbols) BitstreamSkip(bs, 8); /* */ |
343 |
|
if (e->vlc_bits) BitstreamSkip(bs, 8); /* */ |
344 |
|
if (e->sadct) BitstreamSkip(bs, 8); /* */ |
345 |
|
} |
346 |
|
|
347 |
|
if (coding_type == P_VOP) { |
348 |
|
if (e->opaque) BitstreamSkip(bs, 8); /* */ |
349 |
|
if (e->transparent) BitstreamSkip(bs, 8); /* */ |
350 |
|
if (e->intra_cae) BitstreamSkip(bs, 8); /* */ |
351 |
|
if (e->inter_cae) BitstreamSkip(bs, 8); /* */ |
352 |
|
if (e->no_update) BitstreamSkip(bs, 8); /* */ |
353 |
|
if (e->upsampling) BitstreamSkip(bs, 8); /* */ |
354 |
|
if (e->intra_blocks) BitstreamSkip(bs, 8); /* */ |
355 |
|
if (e->not_coded_blocks) BitstreamSkip(bs, 8); /* */ |
356 |
|
if (e->dct_coefs) BitstreamSkip(bs, 8); /* */ |
357 |
|
if (e->dct_lines) BitstreamSkip(bs, 8); /* */ |
358 |
|
if (e->vlc_symbols) BitstreamSkip(bs, 8); /* */ |
359 |
|
if (e->vlc_bits) BitstreamSkip(bs, 8); /* */ |
360 |
|
if (e->inter_blocks) BitstreamSkip(bs, 8); /* */ |
361 |
|
if (e->inter4v_blocks) BitstreamSkip(bs, 8); /* */ |
362 |
|
if (e->apm) BitstreamSkip(bs, 8); /* */ |
363 |
|
if (e->npm) BitstreamSkip(bs, 8); /* */ |
364 |
|
if (e->forw_back_mc_q) BitstreamSkip(bs, 8); /* */ |
365 |
|
if (e->halfpel2) BitstreamSkip(bs, 8); /* */ |
366 |
|
if (e->halfpel4) BitstreamSkip(bs, 8); /* */ |
367 |
|
if (e->sadct) BitstreamSkip(bs, 8); /* */ |
368 |
|
if (e->quarterpel) BitstreamSkip(bs, 8); /* */ |
369 |
|
} |
370 |
|
if (coding_type == B_VOP) { |
371 |
|
if (e->opaque) BitstreamSkip(bs, 8); /* */ |
372 |
|
if (e->transparent) BitstreamSkip(bs, 8); /* */ |
373 |
|
if (e->intra_cae) BitstreamSkip(bs, 8); /* */ |
374 |
|
if (e->inter_cae) BitstreamSkip(bs, 8); /* */ |
375 |
|
if (e->no_update) BitstreamSkip(bs, 8); /* */ |
376 |
|
if (e->upsampling) BitstreamSkip(bs, 8); /* */ |
377 |
|
if (e->intra_blocks) BitstreamSkip(bs, 8); /* */ |
378 |
|
if (e->not_coded_blocks) BitstreamSkip(bs, 8); /* */ |
379 |
|
if (e->dct_coefs) BitstreamSkip(bs, 8); /* */ |
380 |
|
if (e->dct_lines) BitstreamSkip(bs, 8); /* */ |
381 |
|
if (e->vlc_symbols) BitstreamSkip(bs, 8); /* */ |
382 |
|
if (e->vlc_bits) BitstreamSkip(bs, 8); /* */ |
383 |
|
if (e->inter_blocks) BitstreamSkip(bs, 8); /* */ |
384 |
|
if (e->inter4v_blocks) BitstreamSkip(bs, 8); /* */ |
385 |
|
if (e->apm) BitstreamSkip(bs, 8); /* */ |
386 |
|
if (e->npm) BitstreamSkip(bs, 8); /* */ |
387 |
|
if (e->forw_back_mc_q) BitstreamSkip(bs, 8); /* */ |
388 |
|
if (e->halfpel2) BitstreamSkip(bs, 8); /* */ |
389 |
|
if (e->halfpel4) BitstreamSkip(bs, 8); /* */ |
390 |
|
if (e->interpolate_mc_q) BitstreamSkip(bs, 8); /* */ |
391 |
|
if (e->sadct) BitstreamSkip(bs, 8); /* */ |
392 |
|
if (e->quarterpel) BitstreamSkip(bs, 8); /* */ |
393 |
|
} |
394 |
|
|
395 |
|
if (coding_type == S_VOP && dec->sprite_enable == SPRITE_STATIC) { |
396 |
|
if (e->intra_blocks) BitstreamSkip(bs, 8); /* */ |
397 |
|
if (e->not_coded_blocks) BitstreamSkip(bs, 8); /* */ |
398 |
|
if (e->dct_coefs) BitstreamSkip(bs, 8); /* */ |
399 |
|
if (e->dct_lines) BitstreamSkip(bs, 8); /* */ |
400 |
|
if (e->vlc_symbols) BitstreamSkip(bs, 8); /* */ |
401 |
|
if (e->vlc_bits) BitstreamSkip(bs, 8); /* */ |
402 |
|
if (e->inter_blocks) BitstreamSkip(bs, 8); /* */ |
403 |
|
if (e->inter4v_blocks) BitstreamSkip(bs, 8); /* */ |
404 |
|
if (e->apm) BitstreamSkip(bs, 8); /* */ |
405 |
|
if (e->npm) BitstreamSkip(bs, 8); /* */ |
406 |
|
if (e->forw_back_mc_q) BitstreamSkip(bs, 8); /* */ |
407 |
|
if (e->halfpel2) BitstreamSkip(bs, 8); /* */ |
408 |
|
if (e->halfpel4) BitstreamSkip(bs, 8); /* */ |
409 |
|
if (e->interpolate_mc_q) BitstreamSkip(bs, 8); /* */ |
410 |
|
} |
411 |
|
} |
412 |
|
} |
413 |
|
|
414 |
|
|
415 |
|
|
416 |
|
|
417 |
|
|
418 |
/* |
/* |
419 |
decode headers |
decode headers |
420 |
returns coding_type, or -1 if error |
returns coding_type, or -1 if error |
432 |
uint32_t * fcode_forward, |
uint32_t * fcode_forward, |
433 |
uint32_t * fcode_backward, |
uint32_t * fcode_backward, |
434 |
uint32_t * intra_dc_threshold, |
uint32_t * intra_dc_threshold, |
435 |
VECTOR * gmc_mv) |
WARPPOINTS *gmc_warp) |
436 |
{ |
{ |
437 |
uint32_t vol_ver_id; |
uint32_t vol_ver_id; |
438 |
uint32_t coding_type; |
uint32_t coding_type; |
439 |
uint32_t start_code; |
uint32_t start_code; |
440 |
uint32_t time_incr = 0; |
uint32_t time_incr = 0; |
441 |
int32_t time_increment; |
int32_t time_increment = 0; |
442 |
int resize = 0; |
int resize = 0; |
443 |
|
|
444 |
do { |
do { |
464 |
DPRINTF(DPRINTF_STARTCODE, "</visual_object_sequence>"); |
DPRINTF(DPRINTF_STARTCODE, "</visual_object_sequence>"); |
465 |
|
|
466 |
} else if (start_code == VISOBJ_START_CODE) { |
} else if (start_code == VISOBJ_START_CODE) { |
467 |
|
int visobj_ver_id; |
468 |
|
|
469 |
DPRINTF(DPRINTF_STARTCODE, "<visual_object>"); |
DPRINTF(DPRINTF_STARTCODE, "<visual_object>"); |
470 |
|
|
471 |
BitstreamSkip(bs, 32); // visual_object_start_code |
BitstreamSkip(bs, 32); // visual_object_start_code |
472 |
if (BitstreamGetBit(bs)) // is_visual_object_identified |
if (BitstreamGetBit(bs)) // is_visual_object_identified |
473 |
{ |
{ |
474 |
vol_ver_id = BitstreamGetBits(bs, 4); // visual_object_ver_id |
visobj_ver_id = BitstreamGetBits(bs, 4); // visual_object_ver_id |
475 |
DPRINTF(DPRINTF_HEADER,"ver_id %i", vol_ver_id); |
DPRINTF(DPRINTF_HEADER,"visobj_ver_id %i", visobj_ver_id); |
476 |
BitstreamSkip(bs, 3); // visual_object_priority |
BitstreamSkip(bs, 3); // visual_object_priority |
477 |
} else { |
} else { |
478 |
vol_ver_id = 1; |
visobj_ver_id = 1; |
479 |
} |
} |
480 |
|
|
481 |
if (BitstreamShowBits(bs, 4) != VISOBJ_TYPE_VIDEO) // visual_object_type |
if (BitstreamShowBits(bs, 4) != VISOBJ_TYPE_VIDEO) // visual_object_type |
558 |
DPRINTF(DPRINTF_HEADER, "low_delay %i", dec->low_delay); |
DPRINTF(DPRINTF_HEADER, "low_delay %i", dec->low_delay); |
559 |
if (BitstreamGetBit(bs)) // vbv_parameters |
if (BitstreamGetBit(bs)) // vbv_parameters |
560 |
{ |
{ |
561 |
|
unsigned int bitrate; |
562 |
|
unsigned int buffer_size; |
563 |
|
unsigned int occupancy; |
564 |
|
|
565 |
DPRINTF(DPRINTF_HEADER,"+ vbv_parameters"); |
DPRINTF(DPRINTF_HEADER,"+ vbv_parameters"); |
566 |
BitstreamSkip(bs, 15); // first_half_bitrate |
|
567 |
|
bitrate = BitstreamGetBits(bs,15) << 15; // first_half_bit_rate |
568 |
READ_MARKER(); |
READ_MARKER(); |
569 |
BitstreamSkip(bs, 15); // latter_half_bitrate |
bitrate |= BitstreamGetBits(bs,15); // latter_half_bit_rate |
570 |
READ_MARKER(); |
READ_MARKER(); |
571 |
BitstreamSkip(bs, 15); // first_half_vbv_buffer_size |
|
572 |
|
buffer_size = BitstreamGetBits(bs, 15) << 3; // first_half_vbv_buffer_size |
573 |
READ_MARKER(); |
READ_MARKER(); |
574 |
BitstreamSkip(bs, 3); // latter_half_vbv_buffer_size |
buffer_size |= BitstreamGetBits(bs, 3); // latter_half_vbv_buffer_size |
575 |
BitstreamSkip(bs, 11); // first_half_vbv_occupancy |
|
576 |
|
occupancy = BitstreamGetBits(bs, 11) << 15; // first_half_vbv_occupancy |
577 |
READ_MARKER(); |
READ_MARKER(); |
578 |
BitstreamSkip(bs, 15); // latter_half_vbv_occupancy |
occupancy |= BitstreamGetBits(bs, 15); // latter_half_vbv_occupancy |
579 |
READ_MARKER(); |
READ_MARKER(); |
580 |
|
|
581 |
|
DPRINTF(DPRINTF_HEADER,"bitrate %d (unit=400 bps)", bitrate); |
582 |
|
DPRINTF(DPRINTF_HEADER,"buffer_size %d (unit=16384 bits)", buffer_size); |
583 |
|
DPRINTF(DPRINTF_HEADER,"occupancy %d (unit=64 bits)", occupancy); |
584 |
} |
} |
585 |
|
}else{ |
586 |
|
dec->low_delay = dec->low_delay_default; |
587 |
} |
} |
588 |
|
|
589 |
dec->shape = BitstreamGetBits(bs, 2); // video_object_layer_shape |
dec->shape = BitstreamGetBits(bs, 2); // video_object_layer_shape |
751 |
dec->quarterpel = 0; |
dec->quarterpel = 0; |
752 |
|
|
753 |
|
|
754 |
if (!BitstreamGetBit(bs)) // complexity_estimation_disable |
dec->complexity_estimation_disable = BitstreamGetBit(bs); /* complexity estimation disable */ |
755 |
|
if (!dec->complexity_estimation_disable) |
756 |
{ |
{ |
757 |
DPRINTF(DPRINTF_ERROR, "complexity_estimation not supported"); |
read_vol_complexity_estimation_header(bs, dec); |
|
return -1; |
|
758 |
} |
} |
759 |
|
|
760 |
BitstreamSkip(bs, 1); // resync_marker_disable |
BitstreamSkip(bs, 1); // resync_marker_disable |
773 |
BitstreamSkip(bs, 2); // requested_upstream_message_type |
BitstreamSkip(bs, 2); // requested_upstream_message_type |
774 |
BitstreamSkip(bs, 1); // newpred_segment_type |
BitstreamSkip(bs, 1); // newpred_segment_type |
775 |
} |
} |
776 |
dec->reduced_resolution_enable = BitstreamGetBit(bs); |
dec->reduced_resolution_enable = BitstreamGetBit(bs); /* reduced_resolution_vop_enable */ |
777 |
if (dec->reduced_resolution_enable) // reduced_resolution_vop_enable |
DPRINTF(DPRINTF_HEADER, "reduced_resolution_enable %i", dec->reduced_resolution_enable); |
|
{ |
|
|
DPRINTF(DPRINTF_ERROR, "reduced_resolution_vop not supported"); |
|
|
//return -1; |
|
|
} |
|
778 |
} |
} |
779 |
else |
else |
780 |
{ |
{ |
782 |
dec->reduced_resolution_enable = 0; |
dec->reduced_resolution_enable = 0; |
783 |
} |
} |
784 |
|
|
785 |
if ((dec->scalability = BitstreamGetBit(bs))) // scalability |
dec->scalability = BitstreamGetBit(bs); /* scalability */ |
786 |
|
if (dec->scalability) |
787 |
{ |
{ |
788 |
DPRINTF(DPRINTF_ERROR, "scalability not supported"); |
DPRINTF(DPRINTF_ERROR, "scalability not supported"); |
789 |
|
BitstreamSkip(bs, 1); /* hierarchy_type */ |
790 |
|
BitstreamSkip(bs, 4); /* ref_layer_id */ |
791 |
|
BitstreamSkip(bs, 1); /* ref_layer_sampling_direc */ |
792 |
|
BitstreamSkip(bs, 5); /* hor_sampling_factor_n */ |
793 |
|
BitstreamSkip(bs, 5); /* hor_sampling_factor_m */ |
794 |
|
BitstreamSkip(bs, 5); /* vert_sampling_factor_n */ |
795 |
|
BitstreamSkip(bs, 5); /* vert_sampling_factor_m */ |
796 |
|
BitstreamSkip(bs, 1); /* enhancement_type */ |
797 |
|
if(dec->shape == VIDOBJLAY_SHAPE_BINARY /* && hierarchy_type==0 */) { |
798 |
|
BitstreamSkip(bs, 1); /* use_ref_shape */ |
799 |
|
BitstreamSkip(bs, 1); /* use_ref_texture */ |
800 |
|
BitstreamSkip(bs, 5); /* shape_hor_sampling_factor_n */ |
801 |
|
BitstreamSkip(bs, 5); /* shape_hor_sampling_factor_m */ |
802 |
|
BitstreamSkip(bs, 5); /* shape_vert_sampling_factor_n */ |
803 |
|
BitstreamSkip(bs, 5); /* shape_vert_sampling_factor_m */ |
804 |
|
} |
805 |
return -1; |
return -1; |
806 |
} |
} |
807 |
} else // dec->shape == BINARY_ONLY |
} else // dec->shape == BINARY_ONLY |
808 |
{ |
{ |
809 |
if (vol_ver_id != 1) { |
if (vol_ver_id != 1) { |
810 |
if (BitstreamGetBit(bs)) // scalability |
dec->scalability = BitstreamGetBit(bs); /* scalability */ |
811 |
|
if (dec->scalability) |
812 |
{ |
{ |
813 |
DPRINTF(DPRINTF_ERROR, "scalability not supported"); |
DPRINTF(DPRINTF_ERROR, "scalability not supported"); |
814 |
|
BitstreamSkip(bs, 4); /* ref_layer_id */ |
815 |
|
BitstreamSkip(bs, 5); /* hor_sampling_factor_n */ |
816 |
|
BitstreamSkip(bs, 5); /* hor_sampling_factor_m */ |
817 |
|
BitstreamSkip(bs, 5); /* vert_sampling_factor_n */ |
818 |
|
BitstreamSkip(bs, 5); /* vert_sampling_factor_m */ |
819 |
return -1; |
return -1; |
820 |
} |
} |
821 |
} |
} |
838 |
READ_MARKER(); |
READ_MARKER(); |
839 |
seconds = BitstreamGetBits(bs, 6); |
seconds = BitstreamGetBits(bs, 6); |
840 |
|
|
841 |
DPRINTF(DPRINTF_HEADER, "time %ih%im%is", hours); |
DPRINTF(DPRINTF_HEADER, "time %ih%im%is", hours,minutes,seconds); |
842 |
} |
} |
843 |
BitstreamSkip(bs, 1); // closed_gov |
BitstreamSkip(bs, 1); // closed_gov |
844 |
BitstreamSkip(bs, 1); // broken_link |
BitstreamSkip(bs, 1); // broken_link |
888 |
dec->time_bp = (uint32_t) |
dec->time_bp = (uint32_t) |
889 |
(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; |
890 |
} |
} |
891 |
|
DPRINTF(DPRINTF_HEADER,"time_pp=%i", dec->time_pp); |
892 |
|
DPRINTF(DPRINTF_HEADER,"time_bp=%i", dec->time_bp); |
893 |
|
|
894 |
READ_MARKER(); |
READ_MARKER(); |
895 |
|
|
928 |
(coding_type == P_VOP || coding_type == I_VOP)) { |
(coding_type == P_VOP || coding_type == I_VOP)) { |
929 |
|
|
930 |
*reduced_resolution = BitstreamGetBit(bs); |
*reduced_resolution = BitstreamGetBit(bs); |
931 |
|
DPRINTF(DPRINTF_HEADER, "reduced_resolution %i", *reduced_resolution); |
932 |
} |
} |
933 |
else |
else |
934 |
{ |
{ |
964 |
} |
} |
965 |
|
|
966 |
if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) { |
if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) { |
967 |
|
|
968 |
|
if (!dec->complexity_estimation_disable) |
969 |
|
{ |
970 |
|
read_vop_complexity_estimation_header(bs, dec, coding_type); |
971 |
|
} |
972 |
|
|
973 |
// intra_dc_vlc_threshold |
// intra_dc_vlc_threshold |
974 |
*intra_dc_threshold = |
*intra_dc_threshold = |
975 |
intra_dc_threshold_table[BitstreamGetBits(bs, 3)]; |
intra_dc_threshold_table[BitstreamGetBits(bs, 3)]; |
1012 |
} |
} |
1013 |
READ_MARKER(); |
READ_MARKER(); |
1014 |
|
|
1015 |
gmc_mv[i].x = x; |
gmc_warp->duv[i].x = x; |
1016 |
gmc_mv[i].y = y; |
gmc_warp->duv[i].y = y; |
1017 |
|
|
1018 |
DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i)", i, x, y); |
DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i)", i, x, y); |
1019 |
} |
} |
1052 |
|
|
1053 |
} else if (start_code == USERDATA_START_CODE) { |
} else if (start_code == USERDATA_START_CODE) { |
1054 |
char tmp[256]; |
char tmp[256]; |
1055 |
int i; |
int i, version, build; |
1056 |
|
char packed; |
1057 |
|
|
1058 |
BitstreamSkip(bs, 32); // user_data_start_code |
BitstreamSkip(bs, 32); // user_data_start_code |
1059 |
|
|
1070 |
|
|
1071 |
DPRINTF(DPRINTF_STARTCODE, "<user_data>: %s\n", tmp); |
DPRINTF(DPRINTF_STARTCODE, "<user_data>: %s\n", tmp); |
1072 |
|
|
1073 |
if(strncmp(tmp, "DivX501b481p", 12) == 0) { |
/* read xvid bitstream version */ |
1074 |
dec->packed_mode = 1; |
if(strncmp(tmp, "XviD", 4) == 0) { |
1075 |
DPRINTF(DPRINTF_STARTCODE, "packed_mode = %d\n", dec->packed_mode); |
sscanf(tmp, "XviD%d", &dec->bs_version); |
1076 |
|
DPRINTF(DPRINTF_HEADER, "xvid bitstream version=%i", dec->bs_version); |
1077 |
|
} |
1078 |
|
|
1079 |
|
/* divx detection */ |
1080 |
|
i = sscanf(tmp, "DivX%dBuild%d%c", &version, &build, &packed); |
1081 |
|
if (i < 2) |
1082 |
|
i = sscanf(tmp, "DivX%db%d%c", &version, &build, &packed); |
1083 |
|
|
1084 |
|
if (i >= 2) |
1085 |
|
{ |
1086 |
|
dec->packed_mode = (i == 3 && packed == 'p'); |
1087 |
|
DPRINTF(DPRINTF_HEADER, "divx version=%i, build=%i packed=%i", |
1088 |
|
version, build, dec->packed_mode); |
1089 |
} |
} |
1090 |
|
|
1091 |
} else // start_code == ? |
} else // start_code == ? |
1092 |
{ |
{ |
1093 |
if (BitstreamShowBits(bs, 24) == 0x000001) { |
if (BitstreamShowBits(bs, 24) == 0x000001) { |
1132 |
const MBParam * pParam, |
const MBParam * pParam, |
1133 |
const FRAMEINFO * const frame) |
const FRAMEINFO * const frame) |
1134 |
{ |
{ |
1135 |
|
static const unsigned int vo_id = 0; |
1136 |
|
static const unsigned int vol_id = 0; |
1137 |
int vol_ver_id=1; |
int vol_ver_id=1; |
1138 |
|
int profile = 0x03; /* simple profile/level 3 */ |
1139 |
|
|
1140 |
if ( (pParam->m_quarterpel) || (frame->global_flags & XVID_GMC) ) |
if ( pParam->m_quarterpel || (frame->global_flags & XVID_GMC) || |
1141 |
|
(pParam->global & XVID_GLOBAL_REDUCED)) |
1142 |
vol_ver_id = 2; |
vol_ver_id = 2; |
1143 |
|
|
1144 |
|
if ((pParam->global & XVID_GLOBAL_REDUCED)) |
1145 |
|
profile = 0x93; /* advanced realtime simple profile/level 3 */ |
1146 |
|
|
1147 |
|
if (pParam->m_quarterpel || (frame->global_flags & XVID_GMC)) |
1148 |
|
profile = 0xf3; /* advanced simple profile/level 2 */ |
1149 |
|
|
1150 |
|
// visual_object_sequence_start_code |
1151 |
|
// BitstreamPad(bs); |
1152 |
|
/* no padding here, anymore. You have to make sure that you are |
1153 |
|
byte aligned, and that always 1-8 padding bits have been written */ |
1154 |
|
|
1155 |
|
BitstreamPutBits(bs, VISOBJSEQ_START_CODE, 32); |
1156 |
|
BitstreamPutBits(bs, profile, 8); |
1157 |
|
|
1158 |
|
// visual_object_start_code |
1159 |
|
BitstreamPad(bs); |
1160 |
|
BitstreamPutBits(bs, VISOBJ_START_CODE, 32); |
1161 |
|
BitstreamPutBits(bs, 0, 1); // is_visual_object_identifier |
1162 |
|
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, VO_START_CODE, 27); |
BitstreamPutBits(bs, VIDOBJ_START_CODE|(vo_id&0x5), 32); |
|
BitstreamPutBits(bs, 0, 5); |
|
1167 |
|
|
1168 |
// video_object_layer_start_code & vol_id |
// video_object_layer_start_code & vol_id |
1169 |
BitstreamPutBits(bs, VOL_START_CODE, 28); |
BitstreamPad(bs); |
1170 |
BitstreamPutBits(bs, 0, 4); |
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, 0, 8); // video_object_type_indication |
BitstreamPutBits(bs, 0, 8); // video_object_type_indication |
1269 |
if (vol_ver_id != 1) |
if (vol_ver_id != 1) |
1270 |
{ |
{ |
1271 |
BitstreamPutBit(bs, 0); // newpred_enable |
BitstreamPutBit(bs, 0); // newpred_enable |
1272 |
BitstreamPutBit(bs, 0); // reduced_resolution_vop_enabled |
|
1273 |
|
BitstreamPutBit(bs, (pParam->global & XVID_GLOBAL_REDUCED)?1:0); |
1274 |
|
/* reduced_resolution_vop_enabled */ |
1275 |
} |
} |
1276 |
|
|
1277 |
BitstreamPutBit(bs, 0); // scalability |
BitstreamPutBit(bs, 0); // scalability |
1278 |
|
|
1279 |
|
/* fake divx5 id, to ensure compatibility with divx5 decoder */ |
1280 |
|
#define DIVX5_ID "DivX501b481p" |
1281 |
|
if (pParam->max_bframes > 0 && (pParam->global & XVID_GLOBAL_PACKED)) { |
1282 |
|
BitstreamWriteUserData(bs, DIVX5_ID, strlen(DIVX5_ID)); |
1283 |
|
} |
1284 |
|
|
1285 |
|
/* xvid id */ |
1286 |
|
#define XVID_ID "XviD" XVID_BS_VERSION |
1287 |
|
BitstreamWriteUserData(bs, XVID_ID, strlen(XVID_ID)); |
1288 |
} |
} |
1289 |
|
|
1290 |
|
|
1292 |
write vop header |
write vop header |
1293 |
*/ |
*/ |
1294 |
void |
void |
1295 |
BitstreamWriteVopHeader(Bitstream * const bs, |
BitstreamWriteVopHeader( |
1296 |
|
Bitstream * const bs, |
1297 |
const MBParam * pParam, |
const MBParam * pParam, |
1298 |
const FRAMEINFO * const frame, |
const FRAMEINFO * const frame, |
1299 |
int vop_coded) |
int vop_coded) |
1300 |
{ |
{ |
1301 |
uint32_t i; |
uint32_t i; |
1302 |
|
|
1303 |
BitstreamPad(bs); |
// BitstreamPad(bs); |
1304 |
|
/* no padding here, anymore. You have to make sure that you are |
1305 |
|
byte aligned, and that always 1-8 padding bits have been written */ |
1306 |
|
|
1307 |
BitstreamPutBits(bs, VOP_START_CODE, 32); |
BitstreamPutBits(bs, VOP_START_CODE, 32); |
1308 |
|
|
1309 |
BitstreamPutBits(bs, frame->coding_type, 2); |
BitstreamPutBits(bs, frame->coding_type, 2); |
1335 |
if ( (frame->coding_type == P_VOP) || (frame->coding_type == S_VOP) ) |
if ( (frame->coding_type == P_VOP) || (frame->coding_type == S_VOP) ) |
1336 |
BitstreamPutBits(bs, frame->rounding_type, 1); |
BitstreamPutBits(bs, frame->rounding_type, 1); |
1337 |
|
|
1338 |
|
if ((pParam->global & XVID_GLOBAL_REDUCED)) |
1339 |
|
BitstreamPutBit(bs, (frame->global_flags & XVID_REDUCED)?1:0); |
1340 |
|
|
1341 |
BitstreamPutBits(bs, 0, 3); // intra_dc_vlc_threshold |
BitstreamPutBits(bs, 0, 3); // intra_dc_vlc_threshold |
1342 |
|
|
1343 |
if (frame->global_flags & XVID_INTERLACING) { |
if (frame->global_flags & XVID_INTERLACING) { |
1346 |
} |
} |
1347 |
|
|
1348 |
if (frame->coding_type == S_VOP) { |
if (frame->coding_type == S_VOP) { |
1349 |
if (1) { // no_of_sprite_warping_points>=1 |
if (1) { // no_of_sprite_warping_points>=1 (we use 2!) |
1350 |
if (pParam->m_quarterpel) |
int k; |
1351 |
bs_put_spritetrajectory(bs, frame->GMC_MV.x/2 ); // du[0] |
for (k=0;k<2;k++) |
1352 |
else |
{ |
1353 |
bs_put_spritetrajectory(bs, frame->GMC_MV.x ); // du[0] |
bs_put_spritetrajectory(bs, frame->warp.duv[k].x ); // du[k] |
1354 |
WRITE_MARKER(); |
WRITE_MARKER(); |
1355 |
|
|
1356 |
if (pParam->m_quarterpel) |
bs_put_spritetrajectory(bs, frame->warp.duv[k].y ); // dv[k] |
|
bs_put_spritetrajectory(bs, frame->GMC_MV.y/2 ); // dv[0] |
|
|
else |
|
|
bs_put_spritetrajectory(bs, frame->GMC_MV.y ); // dv[0] |
|
1357 |
WRITE_MARKER(); |
WRITE_MARKER(); |
1358 |
|
|
|
|
|
1359 |
if (pParam->m_quarterpel) |
if (pParam->m_quarterpel) |
1360 |
{ |
{ |
1361 |
DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i) *QPEL*", 0, frame->GMC_MV.x/2, frame->GMC_MV.y/2); |
DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i) *QPEL*", k, frame->warp.duv[k].x/2, frame->warp.duv[k].y/2); |
1362 |
} |
} |
1363 |
else |
else |
1364 |
{ |
{ |
1365 |
DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i)", 0, frame->GMC_MV.x, frame->GMC_MV.y); |
DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i)", k, frame->warp.duv[k].x, frame->warp.duv[k].y); |
1366 |
} |
} |
|
|
|
1367 |
} |
} |
|
/* GMC is halfpel in bitstream, even though GMC_MV was pseudo-qpel (2*halfpel) */ |
|
|
|
|
|
if (2) { // no_of_sprite_warping_points>=2 (for DivX5 compat) |
|
|
bs_put_spritetrajectory(bs, 0 ); |
|
|
WRITE_MARKER(); |
|
|
bs_put_spritetrajectory(bs, 0 ); |
|
|
WRITE_MARKER(); |
|
1368 |
} |
} |
|
// no support for brightness_change! |
|
1369 |
} |
} |
1370 |
|
|
1371 |
|
|
1372 |
|
DPRINTF(DPRINTF_HEADER, "quant = %i", frame->quant); |
1373 |
|
|
1374 |
BitstreamPutBits(bs, frame->quant, 5); // quantizer |
BitstreamPutBits(bs, frame->quant, 5); // quantizer |
1375 |
|
|
1376 |
if (frame->coding_type != I_VOP) |
if (frame->coding_type != I_VOP) |