131 |
// for BVOP addbits == max(fcode,bcode) - 1 |
// for BVOP addbits == max(fcode,bcode) - 1 |
132 |
// returns mbpos |
// returns mbpos |
133 |
int |
int |
134 |
read_video_packet_header(Bitstream *bs, const int addbits, int * quant) |
read_video_packet_header(Bitstream *bs, |
135 |
|
DECODER * dec, |
136 |
|
const int addbits, |
137 |
|
int * quant, |
138 |
|
int * fcode_forward, |
139 |
|
int * fcode_backward, |
140 |
|
int * intra_dc_threshold) |
141 |
{ |
{ |
142 |
int nbits; |
int startcode_bits = NUMBITS_VP_RESYNC_MARKER + addbits; |
143 |
|
int mbnum_bits = log2bin(dec->mb_width * dec->mb_height - 1); |
144 |
int mbnum; |
int mbnum; |
145 |
int hec; |
int hec = 0; |
|
|
|
|
nbits = NUMBITS_VP_RESYNC_MARKER + addbits; |
|
146 |
|
|
147 |
BitstreamSkip(bs, BitstreamNumBitsToByteAlign(bs)); |
BitstreamSkip(bs, BitstreamNumBitsToByteAlign(bs)); |
148 |
BitstreamSkip(bs, nbits); |
BitstreamSkip(bs, startcode_bits); |
149 |
|
|
150 |
DPRINTF(DPRINTF_STARTCODE, "<video_packet_header>"); |
DPRINTF(DPRINTF_STARTCODE, "<video_packet_header>"); |
151 |
|
|
152 |
// if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) { |
if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) |
153 |
// hec |
{ |
154 |
// vop_width |
hec = BitstreamGetBit(bs); /* header_extension_code */ |
155 |
// marker_bit |
if (hec && !(dec->sprite_enable == SPRITE_STATIC /* && current_coding_type = I_VOP */)) |
156 |
// vop_height |
{ |
157 |
// marker_bit |
BitstreamSkip(bs, 13); /* vop_width */ |
158 |
|
READ_MARKER(); |
159 |
//} |
BitstreamSkip(bs, 13); /* vop_height */ |
160 |
|
READ_MARKER(); |
161 |
|
BitstreamSkip(bs, 13); /* vop_horizontal_mc_spatial_ref */ |
162 |
|
READ_MARKER(); |
163 |
|
BitstreamSkip(bs, 13); /* vop_vertical_mc_spatial_ref */ |
164 |
|
READ_MARKER(); |
165 |
|
} |
166 |
|
} |
167 |
|
|
168 |
mbnum = BitstreamGetBits(bs, 9); |
mbnum = BitstreamGetBits(bs, mbnum_bits); /* macroblock_number */ |
169 |
DPRINTF(DPRINTF_HEADER, "mbnum %i", mbnum); |
DPRINTF(DPRINTF_HEADER, "mbnum %i", mbnum); |
170 |
|
|
171 |
// if (dec->shape != VIDOBJLAY_SHAPE_BINARYONLY) |
if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) |
172 |
*quant = BitstreamGetBits(bs, 5); |
{ |
173 |
|
*quant = BitstreamGetBits(bs, 5); /* quant_scale */ |
174 |
DPRINTF(DPRINTF_HEADER, "quant %i", *quant); |
DPRINTF(DPRINTF_HEADER, "quant %i", *quant); |
175 |
|
} |
176 |
|
|
177 |
|
if (dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR) |
178 |
|
hec = BitstreamGetBit(bs); /* header_extension_code */ |
179 |
|
|
180 |
|
|
|
// if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) |
|
|
hec = BitstreamGetBit(bs); |
|
181 |
DPRINTF(DPRINTF_HEADER, "header_extension_code %i", hec); |
DPRINTF(DPRINTF_HEADER, "header_extension_code %i", hec); |
182 |
// if (hec) |
if (hec) |
183 |
// .. decoder hec-header ... |
{ |
184 |
|
int time_base; |
185 |
|
int time_increment; |
186 |
|
int coding_type; |
187 |
|
|
188 |
|
for (time_base=0; BitstreamGetBit(bs)!=0; time_base++); /* modulo_time_base */ |
189 |
|
READ_MARKER(); |
190 |
|
if (dec->time_inc_bits) |
191 |
|
time_increment = (BitstreamGetBits(bs, dec->time_inc_bits)); /* vop_time_increment */ |
192 |
|
READ_MARKER(); |
193 |
|
DPRINTF(DPRINTF_HEADER,"time %i:%i", time_base, time_increment); |
194 |
|
|
195 |
|
coding_type = BitstreamGetBits(bs, 2); |
196 |
|
DPRINTF(DPRINTF_HEADER,"coding_type %i", coding_type); |
197 |
|
|
198 |
|
if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) |
199 |
|
{ |
200 |
|
BitstreamSkip(bs, 1); /* change_conv_ratio_disable */ |
201 |
|
if (coding_type != I_VOP) |
202 |
|
BitstreamSkip(bs, 1); /* vop_shape_coding_type */ |
203 |
|
} |
204 |
|
|
205 |
|
if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) |
206 |
|
{ |
207 |
|
*intra_dc_threshold = intra_dc_threshold_table[BitstreamGetBits(bs, 3)]; |
208 |
|
|
209 |
|
if (dec->sprite_enable == SPRITE_GMC && coding_type == S_VOP && |
210 |
|
dec->sprite_warping_points > 0) |
211 |
|
{ |
212 |
|
// TODO: sprite trajectory |
213 |
|
} |
214 |
|
if (dec->reduced_resolution_enable && |
215 |
|
dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR && |
216 |
|
(coding_type == P_VOP || coding_type == I_VOP)) |
217 |
|
{ |
218 |
|
BitstreamSkip(bs, 1); /* vop_reduced_resolution */ |
219 |
|
} |
220 |
|
|
221 |
|
if (coding_type != I_VOP && fcode_forward) |
222 |
|
{ |
223 |
|
*fcode_forward = BitstreamGetBits(bs, 3); |
224 |
|
DPRINTF(DPRINTF_HEADER,"fcode_forward %i", *fcode_forward); |
225 |
|
} |
226 |
|
|
227 |
|
if (coding_type == B_VOP && fcode_backward) |
228 |
|
{ |
229 |
|
*fcode_backward = BitstreamGetBits(bs, 3); |
230 |
|
DPRINTF(DPRINTF_HEADER,"fcode_backward %i", fcode_backward); |
231 |
|
} |
232 |
|
} |
233 |
|
|
234 |
|
} |
235 |
|
|
236 |
|
if (dec->newpred_enable) |
237 |
|
{ |
238 |
|
int vop_id; |
239 |
|
int vop_id_for_prediction; |
240 |
|
|
241 |
|
vop_id = BitstreamGetBits(bs, MIN(dec->time_inc_bits + 3, 15)); |
242 |
|
DPRINTF(DPRINTF_HEADER, "vop_id %i", vop_id); |
243 |
|
if (BitstreamGetBit(bs)) /* vop_id_for_prediction_indication */ |
244 |
|
{ |
245 |
|
vop_id_for_prediction = BitstreamGetBits(bs, MIN(dec->time_inc_bits + 3, 15)); |
246 |
|
DPRINTF(DPRINTF_HEADER, "vop_id_for_prediction %i", vop_id_for_prediction); |
247 |
|
} |
248 |
|
READ_MARKER(); |
249 |
|
} |
250 |
|
|
251 |
return mbnum; |
return mbnum; |
252 |
} |
} |
265 |
BitstreamReadHeaders(Bitstream * bs, |
BitstreamReadHeaders(Bitstream * bs, |
266 |
DECODER * dec, |
DECODER * dec, |
267 |
uint32_t * rounding, |
uint32_t * rounding, |
268 |
|
uint32_t * reduced_resolution, |
269 |
uint32_t * quant, |
uint32_t * quant, |
270 |
uint32_t * fcode_forward, |
uint32_t * fcode_forward, |
271 |
uint32_t * fcode_backward, |
uint32_t * fcode_backward, |
272 |
uint32_t * intra_dc_threshold) |
uint32_t * intra_dc_threshold, |
273 |
|
VECTOR * gmc_mv) |
274 |
{ |
{ |
275 |
uint32_t vol_ver_id; |
uint32_t vol_ver_id; |
|
static uint32_t time_increment_resolution; |
|
276 |
uint32_t coding_type; |
uint32_t coding_type; |
277 |
uint32_t start_code; |
uint32_t start_code; |
278 |
uint32_t time_incr = 0; |
uint32_t time_incr = 0; |
279 |
int32_t time_increment; |
int32_t time_increment; |
280 |
|
int resize = 0; |
281 |
|
|
282 |
do { |
do { |
283 |
|
|
284 |
BitstreamByteAlign(bs); |
BitstreamByteAlign(bs); |
285 |
start_code = BitstreamShowBits(bs, 32); |
start_code = BitstreamShowBits(bs, 32); |
286 |
|
|
354 |
BitstreamSkip(bs, 1); // random_accessible_vol |
BitstreamSkip(bs, 1); // random_accessible_vol |
355 |
|
|
356 |
// video_object_type_indication |
// video_object_type_indication |
357 |
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 && |
358 |
|
BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_CORE && |
359 |
|
BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_MAIN && |
360 |
|
BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_ACE && |
361 |
|
BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_ART_SIMPLE && |
362 |
|
BitstreamShowBits(bs, 8) != 0) // BUGGY DIVX |
363 |
{ |
{ |
364 |
DPRINTF(DPRINTF_ERROR,"video_object_type_indication %i not supported ", |
DPRINTF(DPRINTF_ERROR,"video_object_type_indication %i not supported ", |
365 |
BitstreamShowBits(bs, 8)); |
BitstreamShowBits(bs, 8)); |
378 |
vol_ver_id = 1; |
vol_ver_id = 1; |
379 |
} |
} |
380 |
|
|
381 |
if (BitstreamGetBits(bs, 4) == VIDOBJLAY_AR_EXTPAR) // aspect_ratio_info |
dec->aspect_ratio = BitstreamGetBits(bs, 4); |
382 |
|
|
383 |
|
if (dec->aspect_ratio == VIDOBJLAY_AR_EXTPAR) // aspect_ratio_info |
384 |
{ |
{ |
385 |
DPRINTF(DPRINTF_HEADER, "+ aspect_ratio_info"); |
DPRINTF(DPRINTF_HEADER, "+ aspect_ratio_info"); |
386 |
BitstreamSkip(bs, 8); // par_width |
dec->par_width = BitstreamGetBits(bs, 8); // par_width |
387 |
BitstreamSkip(bs, 8); // par_height |
dec->par_height = BitstreamGetBits(bs, 8); // par_height |
388 |
} |
} |
389 |
|
|
390 |
if (BitstreamGetBit(bs)) // vol_control_parameters |
if (BitstreamGetBit(bs)) // vol_control_parameters |
407 |
READ_MARKER(); |
READ_MARKER(); |
408 |
BitstreamSkip(bs, 15); // latter_half_vbv_occupancy |
BitstreamSkip(bs, 15); // latter_half_vbv_occupancy |
409 |
READ_MARKER(); |
READ_MARKER(); |
|
|
|
410 |
} |
} |
411 |
} |
} |
412 |
|
|
413 |
dec->shape = BitstreamGetBits(bs, 2); // video_object_layer_shape |
dec->shape = BitstreamGetBits(bs, 2); // video_object_layer_shape |
414 |
|
|
415 |
DPRINTF(DPRINTF_HEADER, "shape %i", dec->shape); |
DPRINTF(DPRINTF_HEADER, "shape %i", dec->shape); |
416 |
|
if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) |
417 |
|
{ |
418 |
|
DPRINTF(DPRINTF_ERROR,"non-rectangular shapes are not supported"); |
419 |
|
} |
420 |
|
|
421 |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE && vol_ver_id != 1) { |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE && vol_ver_id != 1) { |
422 |
BitstreamSkip(bs, 4); // video_object_layer_shape_extension |
BitstreamSkip(bs, 4); // video_object_layer_shape_extension |
425 |
READ_MARKER(); |
READ_MARKER(); |
426 |
|
|
427 |
// *************************** for decode B-frame time *********************** |
// *************************** for decode B-frame time *********************** |
428 |
time_increment_resolution = BitstreamGetBits(bs, 16); // vop_time_increment_resolution |
dec->time_inc_resolution = BitstreamGetBits(bs, 16); // vop_time_increment_resolution |
429 |
|
DPRINTF(DPRINTF_HEADER,"vop_time_increment_resolution %i", dec->time_inc_resolution); |
430 |
|
|
431 |
DPRINTF(DPRINTF_HEADER,"vop_time_increment_resolution %i", time_increment_resolution); |
// dec->time_inc_resolution--; |
432 |
|
|
433 |
// time_increment_resolution--; |
if (dec->time_inc_resolution > 0) { |
434 |
|
dec->time_inc_bits = log2bin(dec->time_inc_resolution-1); |
|
if (time_increment_resolution > 0) { |
|
|
dec->time_inc_bits = log2bin(time_increment_resolution-1); |
|
435 |
} else { |
} else { |
436 |
// dec->time_inc_bits = 0; |
// dec->time_inc_bits = 0; |
437 |
// for "old" xvid compatibility, set time_inc_bits = 1 |
// for "old" xvid compatibility, set time_inc_bits = 1 |
460 |
DPRINTF(DPRINTF_HEADER, "width %i", width); |
DPRINTF(DPRINTF_HEADER, "width %i", width); |
461 |
DPRINTF(DPRINTF_HEADER, "height %i", height); |
DPRINTF(DPRINTF_HEADER, "height %i", height); |
462 |
|
|
463 |
// for auto set width & height |
if (dec->width != width || dec->height != height) |
464 |
if (dec->width == 0) |
{ |
465 |
dec->width = width; |
if (dec->fixed_dimensions) |
466 |
if (dec->height == 0) |
{ |
|
dec->height = height; |
|
|
|
|
|
if (width != dec->width || height != dec->height) { |
|
467 |
DPRINTF(DPRINTF_ERROR, "XVID_DEC_PARAM width/height does not match bitstream"); |
DPRINTF(DPRINTF_ERROR, "XVID_DEC_PARAM width/height does not match bitstream"); |
468 |
return -1; |
return -1; |
469 |
} |
} |
470 |
|
resize = 1; |
471 |
|
dec->width = width; |
472 |
|
dec->height = height; |
473 |
|
} |
474 |
} |
} |
475 |
|
|
476 |
dec->interlacing = BitstreamGetBit(bs); |
dec->interlacing = BitstreamGetBit(bs); |
477 |
DPRINTF(DPRINTF_HEADER, "interlace", dec->interlacing); |
DPRINTF(DPRINTF_HEADER, "interlacing %i", dec->interlacing); |
478 |
|
|
479 |
if (!BitstreamGetBit(bs)) // obmc_disable |
if (!BitstreamGetBit(bs)) // obmc_disable |
480 |
{ |
{ |
483 |
// fucking divx4.02 has this enabled |
// fucking divx4.02 has this enabled |
484 |
} |
} |
485 |
|
|
486 |
if (BitstreamGetBits(bs, (vol_ver_id == 1 ? 1 : 2))) // sprite_enable |
dec->sprite_enable = BitstreamGetBits(bs, (vol_ver_id == 1 ? 1 : 2)); // sprite_enable |
487 |
|
|
488 |
|
if (dec->sprite_enable == SPRITE_STATIC || dec->sprite_enable == SPRITE_GMC) |
489 |
{ |
{ |
490 |
DPRINTF(DPRINTF_ERROR, "spriate_enabled not supported"); |
int low_latency_sprite_enable; |
491 |
return -1; |
|
492 |
|
if (dec->sprite_enable != SPRITE_GMC) |
493 |
|
{ |
494 |
|
int sprite_width; |
495 |
|
int sprite_height; |
496 |
|
int sprite_left_coord; |
497 |
|
int sprite_top_coord; |
498 |
|
sprite_width = BitstreamGetBits(bs, 13); // sprite_width |
499 |
|
READ_MARKER(); |
500 |
|
sprite_height = BitstreamGetBits(bs, 13); // sprite_height |
501 |
|
READ_MARKER(); |
502 |
|
sprite_left_coord = BitstreamGetBits(bs, 13); // sprite_left_coordinate |
503 |
|
READ_MARKER(); |
504 |
|
sprite_top_coord = BitstreamGetBits(bs, 13); // sprite_top_coordinate |
505 |
|
READ_MARKER(); |
506 |
|
} |
507 |
|
dec->sprite_warping_points = BitstreamGetBits(bs, 6); // no_of_sprite_warping_points |
508 |
|
dec->sprite_warping_accuracy = BitstreamGetBits(bs, 2); // sprite_warping_accuracy |
509 |
|
dec->sprite_brightness_change = BitstreamGetBits(bs, 1); // brightness_change |
510 |
|
if (dec->sprite_enable != SPRITE_GMC) |
511 |
|
{ |
512 |
|
low_latency_sprite_enable = BitstreamGetBits(bs, 1); // low_latency_sprite_enable |
513 |
|
} |
514 |
} |
} |
515 |
|
|
516 |
if (vol_ver_id != 1 && |
if (vol_ver_id != 1 && |
568 |
|
|
569 |
|
|
570 |
if (vol_ver_id != 1) { |
if (vol_ver_id != 1) { |
|
DEBUG("QUARTERPEL BITSTREAM"); |
|
571 |
dec->quarterpel = BitstreamGetBit(bs); // quarter_sample |
dec->quarterpel = BitstreamGetBit(bs); // quarter_sample |
572 |
|
DPRINTF(DPRINTF_HEADER,"quarterpel %i", dec->quarterpel); |
573 |
} |
} |
574 |
else |
else |
575 |
dec->quarterpel = 0; |
dec->quarterpel = 0; |
590 |
} |
} |
591 |
|
|
592 |
if (vol_ver_id != 1) { |
if (vol_ver_id != 1) { |
593 |
if (BitstreamGetBit(bs)) // newpred_enable |
dec->newpred_enable = BitstreamGetBit(bs); |
594 |
|
if (dec->newpred_enable) // newpred_enable |
595 |
{ |
{ |
596 |
DPRINTF(DPRINTF_HEADER, "+ newpred_enable"); |
DPRINTF(DPRINTF_HEADER, "+ newpred_enable"); |
597 |
BitstreamSkip(bs, 2); // requested_upstream_message_type |
BitstreamSkip(bs, 2); // requested_upstream_message_type |
598 |
BitstreamSkip(bs, 1); // newpred_segment_type |
BitstreamSkip(bs, 1); // newpred_segment_type |
599 |
} |
} |
600 |
if (BitstreamGetBit(bs)) // reduced_resolution_vop_enable |
dec->reduced_resolution_enable = BitstreamGetBit(bs); |
601 |
|
if (dec->reduced_resolution_enable) // reduced_resolution_vop_enable |
602 |
{ |
{ |
603 |
DPRINTF(DPRINTF_ERROR, "reduced_resolution_vop not supported"); |
DPRINTF(DPRINTF_ERROR, "reduced_resolution_vop not supported"); |
604 |
return -1; |
//return -1; |
605 |
|
} |
606 |
} |
} |
607 |
|
else |
608 |
|
{ |
609 |
|
dec->newpred_enable = 0; |
610 |
|
dec->reduced_resolution_enable = 0; |
611 |
} |
} |
612 |
|
|
613 |
if ((dec->scalability = BitstreamGetBit(bs))) // scalability |
if ((dec->scalability = BitstreamGetBit(bs))) // scalability |
628 |
|
|
629 |
} |
} |
630 |
|
|
631 |
|
return (resize ? -3 : -2 ); /* VOL */ |
632 |
|
|
633 |
} else if (start_code == GRPOFVOP_START_CODE) { |
} else if (start_code == GRPOFVOP_START_CODE) { |
634 |
|
|
635 |
DPRINTF(DPRINTF_STARTCODE, "<group_of_vop>"); |
DPRINTF(DPRINTF_STARTCODE, "<group_of_vop>"); |
671 |
DPRINTF(DPRINTF_HEADER, "time_increment %i", time_increment); |
DPRINTF(DPRINTF_HEADER, "time_increment %i", time_increment); |
672 |
|
|
673 |
DPRINTF(DPRINTF_TIMECODE, "%c %i:%i", |
DPRINTF(DPRINTF_TIMECODE, "%c %i:%i", |
674 |
coding_type == I_VOP ? 'I' : coding_type == P_VOP ? 'P' : 'B', |
coding_type == I_VOP ? 'I' : coding_type == P_VOP ? 'P' : coding_type == B_VOP ? 'B' : 'S', |
675 |
time_incr, time_increment); |
time_incr, time_increment); |
676 |
|
|
677 |
if (coding_type != B_VOP) { |
if (coding_type != B_VOP) { |
679 |
dec->time_base += time_incr; |
dec->time_base += time_incr; |
680 |
dec->time = time_increment; |
dec->time = time_increment; |
681 |
|
|
682 |
/* dec->time_base * time_increment_resolution + |
/* dec->time_base * dec->time_inc_resolution + |
683 |
time_increment; |
time_increment; |
684 |
*/ dec->time_pp = (uint32_t) |
*/ dec->time_pp = (uint32_t) |
685 |
(time_increment_resolution + dec->time - dec->last_non_b_time)%time_increment_resolution; |
(dec->time_inc_resolution + dec->time - dec->last_non_b_time)%dec->time_inc_resolution; |
686 |
dec->last_non_b_time = dec->time; |
dec->last_non_b_time = dec->time; |
687 |
} else { |
} else { |
688 |
dec->time = time_increment; |
dec->time = time_increment; |
689 |
/* |
/* |
690 |
(dec->last_time_base + |
(dec->last_time_base + |
691 |
time_incr) * time_increment_resolution + time_increment; |
time_incr) * dec->time_inc_resolution + time_increment; |
692 |
*/ |
*/ |
693 |
dec->time_bp = (uint32_t) |
dec->time_bp = (uint32_t) |
694 |
(time_increment_resolution + dec->last_non_b_time - dec->time)%time_increment_resolution; |
(dec->time_inc_resolution + dec->last_non_b_time - dec->time)%dec->time_inc_resolution; |
695 |
} |
} |
696 |
|
|
697 |
READ_MARKER(); |
READ_MARKER(); |
702 |
return N_VOP; |
return N_VOP; |
703 |
} |
} |
704 |
|
|
705 |
/* if (newpred_enable) |
if (dec->newpred_enable) |
706 |
|
{ |
707 |
|
int vop_id; |
708 |
|
int vop_id_for_prediction; |
709 |
|
|
710 |
|
vop_id = BitstreamGetBits(bs, MIN(dec->time_inc_bits + 3, 15)); |
711 |
|
DPRINTF(DPRINTF_HEADER, "vop_id %i", vop_id); |
712 |
|
if (BitstreamGetBit(bs)) /* vop_id_for_prediction_indication */ |
713 |
{ |
{ |
714 |
|
vop_id_for_prediction = BitstreamGetBits(bs, MIN(dec->time_inc_bits + 3, 15)); |
715 |
|
DPRINTF(DPRINTF_HEADER, "vop_id_for_prediction %i", vop_id_for_prediction); |
716 |
} |
} |
717 |
*/ |
READ_MARKER(); |
718 |
|
} |
719 |
|
|
720 |
|
|
721 |
|
|
722 |
// fix a little bug by MinChen <chenm002@163.com> |
// fix a little bug by MinChen <chenm002@163.com> |
723 |
if ((dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) && |
if ((dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) && |
724 |
( (coding_type == P_VOP) || (coding_type == S_VOP) ) ) { |
( (coding_type == P_VOP) || (coding_type == S_VOP && dec->sprite_enable == SPRITE_GMC) ) ) { |
725 |
*rounding = BitstreamGetBit(bs); // rounding_type |
*rounding = BitstreamGetBit(bs); // rounding_type |
726 |
DPRINTF(DPRINTF_HEADER, "rounding %i", *rounding); |
DPRINTF(DPRINTF_HEADER, "rounding %i", *rounding); |
727 |
} |
} |
728 |
|
|
729 |
/* if (reduced_resolution_enable) |
if (dec->reduced_resolution_enable && |
730 |
|
dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR && |
731 |
|
(coding_type == P_VOP || coding_type == I_VOP)) { |
732 |
|
|
733 |
|
*reduced_resolution = BitstreamGetBit(bs); |
734 |
|
} |
735 |
|
else |
736 |
{ |
{ |
737 |
|
*reduced_resolution = 0; |
738 |
} |
} |
|
*/ |
|
739 |
|
|
740 |
if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) { |
if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) { |
741 |
|
if(!(dec->sprite_enable == SPRITE_STATIC && coding_type == I_VOP)) { |
742 |
|
|
743 |
uint32_t width, height; |
uint32_t width, height; |
744 |
uint32_t horiz_mc_ref, vert_mc_ref; |
uint32_t horiz_mc_ref, vert_mc_ref; |
745 |
|
|
756 |
DPRINTF(DPRINTF_HEADER, "height %i", height); |
DPRINTF(DPRINTF_HEADER, "height %i", height); |
757 |
DPRINTF(DPRINTF_HEADER, "horiz_mc_ref %i", horiz_mc_ref); |
DPRINTF(DPRINTF_HEADER, "horiz_mc_ref %i", horiz_mc_ref); |
758 |
DPRINTF(DPRINTF_HEADER, "vert_mc_ref %i", vert_mc_ref); |
DPRINTF(DPRINTF_HEADER, "vert_mc_ref %i", vert_mc_ref); |
759 |
|
} |
760 |
|
|
761 |
BitstreamSkip(bs, 1); // change_conv_ratio_disable |
BitstreamSkip(bs, 1); // change_conv_ratio_disable |
762 |
if (BitstreamGetBit(bs)) // vop_constant_alpha |
if (BitstreamGetBit(bs)) // vop_constant_alpha |
765 |
} |
} |
766 |
} |
} |
767 |
|
|
|
|
|
768 |
if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) { |
if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) { |
769 |
// intra_dc_vlc_threshold |
// intra_dc_vlc_threshold |
770 |
*intra_dc_threshold = |
*intra_dc_threshold = |
782 |
} |
} |
783 |
} |
} |
784 |
|
|
785 |
|
if ((dec->sprite_enable == SPRITE_STATIC || dec->sprite_enable== SPRITE_GMC) && coding_type == S_VOP) { |
786 |
|
|
787 |
|
int i; |
788 |
|
|
789 |
|
for (i = 0 ; i < dec->sprite_warping_points; i++) |
790 |
|
{ |
791 |
|
int length; |
792 |
|
int x = 0, y = 0; |
793 |
|
|
794 |
|
/* sprite code borowed from ffmpeg; thx Michael Niedermayer <michaelni@gmx.at> */ |
795 |
|
length = bs_get_spritetrajectory(bs); |
796 |
|
if(length){ |
797 |
|
x= BitstreamGetBits(bs, length); |
798 |
|
if ((x >> (length - 1)) == 0) /* if MSB not set it is negative*/ |
799 |
|
x = - (x ^ ((1 << length) - 1)); |
800 |
|
} |
801 |
|
READ_MARKER(); |
802 |
|
|
803 |
|
length = bs_get_spritetrajectory(bs); |
804 |
|
if(length){ |
805 |
|
y = BitstreamGetBits(bs, length); |
806 |
|
if ((y >> (length - 1)) == 0) /* if MSB not set it is negative*/ |
807 |
|
y = - (y ^ ((1 << length) - 1)); |
808 |
|
} |
809 |
|
READ_MARKER(); |
810 |
|
|
811 |
|
gmc_mv[i].x = x; |
812 |
|
gmc_mv[i].y = y; |
813 |
|
|
814 |
|
DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i)", i, x, y); |
815 |
|
} |
816 |
|
|
817 |
|
if (dec->sprite_brightness_change) |
818 |
|
{ |
819 |
|
// XXX: brightness_change_factor() |
820 |
|
} |
821 |
|
if (dec->sprite_enable == SPRITE_STATIC) |
822 |
|
{ |
823 |
|
// XXX: todo |
824 |
|
} |
825 |
|
|
826 |
|
} |
827 |
|
|
828 |
if ((*quant = BitstreamGetBits(bs, dec->quant_bits)) < 1) // vop_quant |
if ((*quant = BitstreamGetBits(bs, dec->quant_bits)) < 1) // vop_quant |
829 |
*quant = 1; |
*quant = 1; |
|
|
|
830 |
DPRINTF(DPRINTF_HEADER, "quant %i", *quant); |
DPRINTF(DPRINTF_HEADER, "quant %i", *quant); |
831 |
|
|
832 |
if (coding_type != I_VOP) { |
if (coding_type != I_VOP) { |
941 |
|
|
942 |
WRITE_MARKER(); |
WRITE_MARKER(); |
943 |
|
|
944 |
/* time_increment_resolution; ignored by current decore versions |
/* time_inc_resolution; ignored by current decore versions |
945 |
eg. 2fps res=2 inc=1 |
eg. 2fps res=2 inc=1 |
946 |
25fps res=25 inc=1 |
25fps res=25 inc=1 |
947 |
29.97fps res=30000 inc=1001 |
29.97fps res=30000 inc=1001 |
1033 |
BitstreamPutBits(bs, VOP_START_CODE, 32); |
BitstreamPutBits(bs, VOP_START_CODE, 32); |
1034 |
|
|
1035 |
BitstreamPutBits(bs, frame->coding_type, 2); |
BitstreamPutBits(bs, frame->coding_type, 2); |
1036 |
|
DPRINTF(DPRINTF_HEADER, "coding_type = %i", frame->coding_type); |
1037 |
|
|
1038 |
for (i = 0; i < frame->seconds; i++) { |
for (i = 0; i < frame->seconds; i++) { |
1039 |
BitstreamPutBit(bs, 1); |
BitstreamPutBit(bs, 1); |
1045 |
// time_increment: value=nth_of_sec, nbits = log2(resolution) |
// time_increment: value=nth_of_sec, nbits = log2(resolution) |
1046 |
|
|
1047 |
BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase)); |
BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase)); |
1048 |
/*DPRINTF("[%i:%i] %c\n", frame->seconds, frame->ticks, |
/*DPRINTF("[%i:%i] %c", frame->seconds, frame->ticks, |
1049 |
frame->coding_type == I_VOP ? 'I' : frame->coding_type == |
frame->coding_type == I_VOP ? 'I' : frame->coding_type == |
1050 |
P_VOP ? 'P' : 'B');*/ |
P_VOP ? 'P' : 'B');*/ |
1051 |
|
|
1081 |
else |
else |
1082 |
bs_put_spritetrajectory(bs, frame->GMC_MV.y ); // dv[0] |
bs_put_spritetrajectory(bs, frame->GMC_MV.y ); // dv[0] |
1083 |
WRITE_MARKER(); |
WRITE_MARKER(); |
1084 |
|
|
1085 |
|
|
1086 |
|
if (pParam->m_quarterpel) |
1087 |
|
{ |
1088 |
|
DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i) *QPEL*", 0, frame->GMC_MV.x/2, frame->GMC_MV.y/2); |
1089 |
|
} |
1090 |
|
else |
1091 |
|
{ |
1092 |
|
DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i)", 0, frame->GMC_MV.x, frame->GMC_MV.y); |
1093 |
|
} |
1094 |
|
|
1095 |
} |
} |
1096 |
/* GMC is halfpel in bitstream, even though GMC_MV was pseudo-qpel (2*halfpel) */ |
/* GMC is halfpel in bitstream, even though GMC_MV was pseudo-qpel (2*halfpel) */ |
1097 |
|
|