50 |
* exception also makes it possible to release a modified version which |
* exception also makes it possible to release a modified version which |
51 |
* carries forward this exception. |
* carries forward this exception. |
52 |
* |
* |
53 |
* $Id: bitstream.c,v 1.35 2002-11-17 00:57:56 edgomez Exp $ |
* $Id: bitstream.c,v 1.37 2002-12-15 01:21:12 edgomez Exp $ |
54 |
* |
* |
55 |
****************************************************************************/ |
****************************************************************************/ |
56 |
|
|
108 |
matrix[scan_tables[0][i++]] = value; |
matrix[scan_tables[0][i++]] = value; |
109 |
} |
} |
110 |
while (value != 0 && i < 64); |
while (value != 0 && i < 64); |
111 |
i--; // fix little bug at coeff not full |
i--; /* fix little bug at coeff not full */ |
112 |
|
|
113 |
while (i < 64) { |
while (i < 64) { |
114 |
matrix[scan_tables[0][i++]] = last; |
matrix[scan_tables[0][i++]] = last; |
117 |
|
|
118 |
|
|
119 |
|
|
120 |
// for PVOP addbits == fcode - 1 |
/* for PVOP addbits == fcode - 1 */ |
121 |
// for BVOP addbits == max(fcode,bcode) - 1 |
/* for BVOP addbits == max(fcode,bcode) - 1 */ |
122 |
// returns mbpos |
/* returns mbpos */ |
123 |
int |
int |
124 |
read_video_packet_header(Bitstream *bs, const int addbits, int * quant) |
read_video_packet_header(Bitstream *bs, const int addbits, int * quant) |
125 |
{ |
{ |
134 |
|
|
135 |
DPRINTF(DPRINTF_STARTCODE, "<video_packet_header>"); |
DPRINTF(DPRINTF_STARTCODE, "<video_packet_header>"); |
136 |
|
|
137 |
// if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) { |
/* if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) { */ |
138 |
// hec |
/* hec */ |
139 |
// vop_width |
/* vop_width */ |
140 |
// marker_bit |
/* marker_bit */ |
141 |
// vop_height |
/* vop_height */ |
142 |
// marker_bit |
/* marker_bit */ |
143 |
|
|
144 |
//} |
/*} */ |
145 |
|
|
146 |
mbnum = BitstreamGetBits(bs, 9); |
mbnum = BitstreamGetBits(bs, 9); |
147 |
DPRINTF(DPRINTF_HEADER, "mbnum %i", mbnum); |
DPRINTF(DPRINTF_HEADER, "mbnum %i", mbnum); |
148 |
|
|
149 |
// if (dec->shape != VIDOBJLAY_SHAPE_BINARYONLY) |
/* if (dec->shape != VIDOBJLAY_SHAPE_BINARYONLY) */ |
150 |
*quant = BitstreamGetBits(bs, 5); |
*quant = BitstreamGetBits(bs, 5); |
151 |
DPRINTF(DPRINTF_HEADER, "quant %i", *quant); |
DPRINTF(DPRINTF_HEADER, "quant %i", *quant); |
152 |
|
|
153 |
// if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) |
/* if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) */ |
154 |
hec = BitstreamGetBit(bs); |
hec = BitstreamGetBit(bs); |
155 |
DPRINTF(DPRINTF_HEADER, "header_extension_code %i", hec); |
DPRINTF(DPRINTF_HEADER, "header_extension_code %i", hec); |
156 |
// if (hec) |
/* if (hec) */ |
157 |
// .. decoder hec-header ... |
/* .. decoder hec-header ... */ |
158 |
|
|
159 |
return mbnum; |
return mbnum; |
160 |
} |
} |
195 |
|
|
196 |
DPRINTF(DPRINTF_STARTCODE, "<visual_object_sequence>"); |
DPRINTF(DPRINTF_STARTCODE, "<visual_object_sequence>"); |
197 |
|
|
198 |
BitstreamSkip(bs, 32); // visual_object_sequence_start_code |
BitstreamSkip(bs, 32); /* visual_object_sequence_start_code */ |
199 |
profile = BitstreamGetBits(bs, 8); // profile_and_level_indication |
profile = BitstreamGetBits(bs, 8); /* profile_and_level_indication */ |
200 |
|
|
201 |
DPRINTF(DPRINTF_HEADER, "profile_and_level_indication %i", profile); |
DPRINTF(DPRINTF_HEADER, "profile_and_level_indication %i", profile); |
202 |
|
|
203 |
} else if (start_code == VISOBJSEQ_STOP_CODE) { |
} else if (start_code == VISOBJSEQ_STOP_CODE) { |
204 |
|
|
205 |
BitstreamSkip(bs, 32); // visual_object_sequence_stop_code |
BitstreamSkip(bs, 32); /* visual_object_sequence_stop_code */ |
206 |
|
|
207 |
DPRINTF(DPRINTF_STARTCODE, "</visual_object_sequence>"); |
DPRINTF(DPRINTF_STARTCODE, "</visual_object_sequence>"); |
208 |
|
|
210 |
|
|
211 |
DPRINTF(DPRINTF_STARTCODE, "<visual_object>"); |
DPRINTF(DPRINTF_STARTCODE, "<visual_object>"); |
212 |
|
|
213 |
BitstreamSkip(bs, 32); // visual_object_start_code |
BitstreamSkip(bs, 32); /* visual_object_start_code */ |
214 |
if (BitstreamGetBit(bs)) // is_visual_object_identified |
if (BitstreamGetBit(bs)) /* is_visual_object_identified */ |
215 |
{ |
{ |
216 |
vol_ver_id = BitstreamGetBits(bs, 4); // visual_object_ver_id |
vol_ver_id = BitstreamGetBits(bs, 4); /* visual_object_ver_id */ |
217 |
DPRINTF(DPRINTF_HEADER,"ver_id %i", vol_ver_id); |
DPRINTF(DPRINTF_HEADER,"ver_id %i", vol_ver_id); |
218 |
BitstreamSkip(bs, 3); // visual_object_priority |
BitstreamSkip(bs, 3); /* visual_object_priority */ |
219 |
} else { |
} else { |
220 |
vol_ver_id = 1; |
vol_ver_id = 1; |
221 |
} |
} |
222 |
|
|
223 |
if (BitstreamShowBits(bs, 4) != VISOBJ_TYPE_VIDEO) // visual_object_type |
if (BitstreamShowBits(bs, 4) != VISOBJ_TYPE_VIDEO) /* visual_object_type */ |
224 |
{ |
{ |
225 |
DPRINTF(DPRINTF_ERROR, "visual_object_type != video"); |
DPRINTF(DPRINTF_ERROR, "visual_object_type != video"); |
226 |
return -1; |
return -1; |
227 |
} |
} |
228 |
BitstreamSkip(bs, 4); |
BitstreamSkip(bs, 4); |
229 |
|
|
230 |
// video_signal_type |
/* video_signal_type */ |
231 |
|
|
232 |
if (BitstreamGetBit(bs)) // video_signal_type |
if (BitstreamGetBit(bs)) /* video_signal_type */ |
233 |
{ |
{ |
234 |
DPRINTF(DPRINTF_HEADER,"+ video_signal_type"); |
DPRINTF(DPRINTF_HEADER,"+ video_signal_type"); |
235 |
BitstreamSkip(bs, 3); // video_format |
BitstreamSkip(bs, 3); /* video_format */ |
236 |
BitstreamSkip(bs, 1); // video_range |
BitstreamSkip(bs, 1); /* video_range */ |
237 |
if (BitstreamGetBit(bs)) // color_description |
if (BitstreamGetBit(bs)) /* color_description */ |
238 |
{ |
{ |
239 |
DPRINTF(DPRINTF_HEADER,"+ color_description"); |
DPRINTF(DPRINTF_HEADER,"+ color_description"); |
240 |
BitstreamSkip(bs, 8); // color_primaries |
BitstreamSkip(bs, 8); /* color_primaries */ |
241 |
BitstreamSkip(bs, 8); // transfer_characteristics |
BitstreamSkip(bs, 8); /* transfer_characteristics */ |
242 |
BitstreamSkip(bs, 8); // matrix_coefficients |
BitstreamSkip(bs, 8); /* matrix_coefficients */ |
243 |
} |
} |
244 |
} |
} |
245 |
} else if ((start_code & ~VIDOBJ_START_CODE_MASK) == VIDOBJ_START_CODE) { |
} else if ((start_code & ~VIDOBJ_START_CODE_MASK) == VIDOBJ_START_CODE) { |
247 |
DPRINTF(DPRINTF_STARTCODE, "<video_object>"); |
DPRINTF(DPRINTF_STARTCODE, "<video_object>"); |
248 |
DPRINTF(DPRINTF_HEADER, "vo id %i", start_code & VIDOBJ_START_CODE_MASK); |
DPRINTF(DPRINTF_HEADER, "vo id %i", start_code & VIDOBJ_START_CODE_MASK); |
249 |
|
|
250 |
BitstreamSkip(bs, 32); // video_object_start_code |
BitstreamSkip(bs, 32); /* video_object_start_code */ |
251 |
|
|
252 |
} else if ((start_code & ~VIDOBJLAY_START_CODE_MASK) == VIDOBJLAY_START_CODE) { |
} else if ((start_code & ~VIDOBJLAY_START_CODE_MASK) == VIDOBJLAY_START_CODE) { |
253 |
|
|
254 |
DPRINTF(DPRINTF_STARTCODE, "<video_object_layer>"); |
DPRINTF(DPRINTF_STARTCODE, "<video_object_layer>"); |
255 |
DPRINTF(DPRINTF_HEADER, "vol id %i", start_code & VIDOBJLAY_START_CODE_MASK); |
DPRINTF(DPRINTF_HEADER, "vol id %i", start_code & VIDOBJLAY_START_CODE_MASK); |
256 |
|
|
257 |
BitstreamSkip(bs, 32); // video_object_layer_start_code |
BitstreamSkip(bs, 32); /* video_object_layer_start_code */ |
258 |
|
|
259 |
BitstreamSkip(bs, 1); // random_accessible_vol |
BitstreamSkip(bs, 1); /* random_accessible_vol */ |
260 |
|
|
261 |
// video_object_type_indication |
/* video_object_type_indication */ |
262 |
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 */ |
263 |
{ |
{ |
264 |
DPRINTF(DPRINTF_ERROR,"video_object_type_indication %i not supported ", |
DPRINTF(DPRINTF_ERROR,"video_object_type_indication %i not supported ", |
265 |
BitstreamShowBits(bs, 8)); |
BitstreamShowBits(bs, 8)); |
268 |
BitstreamSkip(bs, 8); |
BitstreamSkip(bs, 8); |
269 |
|
|
270 |
|
|
271 |
if (BitstreamGetBit(bs)) // is_object_layer_identifier |
if (BitstreamGetBit(bs)) /* is_object_layer_identifier */ |
272 |
{ |
{ |
273 |
DPRINTF(DPRINTF_HEADER, "+ is_object_layer_identifier"); |
DPRINTF(DPRINTF_HEADER, "+ is_object_layer_identifier"); |
274 |
vol_ver_id = BitstreamGetBits(bs, 4); // video_object_layer_verid |
vol_ver_id = BitstreamGetBits(bs, 4); /* video_object_layer_verid */ |
275 |
DPRINTF(DPRINTF_HEADER,"ver_id %i", vol_ver_id); |
DPRINTF(DPRINTF_HEADER,"ver_id %i", vol_ver_id); |
276 |
BitstreamSkip(bs, 3); // video_object_layer_priority |
BitstreamSkip(bs, 3); /* video_object_layer_priority */ |
277 |
} else { |
} else { |
278 |
vol_ver_id = 1; |
vol_ver_id = 1; |
279 |
} |
} |
280 |
|
|
281 |
if (BitstreamGetBits(bs, 4) == VIDOBJLAY_AR_EXTPAR) // aspect_ratio_info |
if (BitstreamGetBits(bs, 4) == VIDOBJLAY_AR_EXTPAR) /* aspect_ratio_info */ |
282 |
{ |
{ |
283 |
DPRINTF(DPRINTF_HEADER, "+ aspect_ratio_info"); |
DPRINTF(DPRINTF_HEADER, "+ aspect_ratio_info"); |
284 |
BitstreamSkip(bs, 8); // par_width |
BitstreamSkip(bs, 8); /* par_width */ |
285 |
BitstreamSkip(bs, 8); // par_height |
BitstreamSkip(bs, 8); /* par_height */ |
286 |
} |
} |
287 |
|
|
288 |
if (BitstreamGetBit(bs)) // vol_control_parameters |
if (BitstreamGetBit(bs)) /* vol_control_parameters */ |
289 |
{ |
{ |
290 |
DPRINTF(DPRINTF_HEADER, "+ vol_control_parameters"); |
DPRINTF(DPRINTF_HEADER, "+ vol_control_parameters"); |
291 |
BitstreamSkip(bs, 2); // chroma_format |
BitstreamSkip(bs, 2); /* chroma_format */ |
292 |
dec->low_delay = BitstreamGetBit(bs); // low_delay |
dec->low_delay = (uint8_t)BitstreamGetBit(bs); /* low_delay */ |
293 |
DPRINTF(DPRINTF_HEADER, "low_delay %i", dec->low_delay); |
DPRINTF(DPRINTF_HEADER, "low_delay %i", dec->low_delay); |
294 |
if (BitstreamGetBit(bs)) // vbv_parameters |
if (BitstreamGetBit(bs)) /* vbv_parameters */ |
295 |
{ |
{ |
296 |
DPRINTF(DPRINTF_HEADER,"+ vbv_parameters"); |
DPRINTF(DPRINTF_HEADER,"+ vbv_parameters"); |
297 |
BitstreamSkip(bs, 15); // first_half_bitrate |
BitstreamSkip(bs, 15); /* first_half_bitrate */ |
298 |
READ_MARKER(); |
READ_MARKER(); |
299 |
BitstreamSkip(bs, 15); // latter_half_bitrate |
BitstreamSkip(bs, 15); /* latter_half_bitrate */ |
300 |
READ_MARKER(); |
READ_MARKER(); |
301 |
BitstreamSkip(bs, 15); // first_half_vbv_buffer_size |
BitstreamSkip(bs, 15); /* first_half_vbv_buffer_size */ |
302 |
READ_MARKER(); |
READ_MARKER(); |
303 |
BitstreamSkip(bs, 3); // latter_half_vbv_buffer_size |
BitstreamSkip(bs, 3); /* latter_half_vbv_buffer_size */ |
304 |
BitstreamSkip(bs, 11); // first_half_vbv_occupancy |
BitstreamSkip(bs, 11); /* first_half_vbv_occupancy */ |
305 |
READ_MARKER(); |
READ_MARKER(); |
306 |
BitstreamSkip(bs, 15); // latter_half_vbv_occupancy |
BitstreamSkip(bs, 15); /* latter_half_vbv_occupancy */ |
307 |
READ_MARKER(); |
READ_MARKER(); |
308 |
|
|
309 |
} |
} |
310 |
} |
} |
311 |
|
|
312 |
dec->shape = BitstreamGetBits(bs, 2); // video_object_layer_shape |
dec->shape = BitstreamGetBits(bs, 2); /* video_object_layer_shape */ |
313 |
DPRINTF(DPRINTF_HEADER, "shape %i", dec->shape); |
DPRINTF(DPRINTF_HEADER, "shape %i", dec->shape); |
314 |
|
|
315 |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE && vol_ver_id != 1) { |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE && vol_ver_id != 1) { |
316 |
BitstreamSkip(bs, 4); // video_object_layer_shape_extension |
BitstreamSkip(bs, 4); /* video_object_layer_shape_extension */ |
317 |
} |
} |
318 |
|
|
319 |
READ_MARKER(); |
READ_MARKER(); |
320 |
|
|
321 |
// *************************** for decode B-frame time *********************** |
/* *************************** for decode B-frame time *********************** */ |
322 |
time_increment_resolution = BitstreamGetBits(bs, 16); // vop_time_increment_resolution |
time_increment_resolution = BitstreamGetBits(bs, 16); /* vop_time_increment_resolution */ |
323 |
|
|
324 |
DPRINTF(DPRINTF_HEADER,"vop_time_increment_resolution %i", time_increment_resolution); |
DPRINTF(DPRINTF_HEADER,"vop_time_increment_resolution %i", time_increment_resolution); |
325 |
|
|
326 |
// time_increment_resolution--; |
/* time_increment_resolution--; */ |
327 |
|
|
328 |
if (time_increment_resolution > 0) { |
if (time_increment_resolution > 0) { |
329 |
dec->time_inc_bits = log2bin(time_increment_resolution-1); |
dec->time_inc_bits = log2bin(time_increment_resolution-1); |
330 |
} else { |
} else { |
331 |
// dec->time_inc_bits = 0; |
/* dec->time_inc_bits = 0; */ |
332 |
// for "old" xvid compatibility, set time_inc_bits = 1 |
/* for "old" xvid compatibility, set time_inc_bits = 1 */ |
333 |
dec->time_inc_bits = 1; |
dec->time_inc_bits = 1; |
334 |
} |
} |
335 |
|
|
336 |
READ_MARKER(); |
READ_MARKER(); |
337 |
|
|
338 |
if (BitstreamGetBit(bs)) // fixed_vop_rate |
if (BitstreamGetBit(bs)) /* fixed_vop_rate */ |
339 |
{ |
{ |
340 |
DPRINTF(DPRINTF_HEADER, "+ fixed_vop_rate"); |
DPRINTF(DPRINTF_HEADER, "+ fixed_vop_rate"); |
341 |
BitstreamSkip(bs, dec->time_inc_bits); // fixed_vop_time_increment |
BitstreamSkip(bs, dec->time_inc_bits); /* fixed_vop_time_increment */ |
342 |
} |
} |
343 |
|
|
344 |
if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) { |
if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) { |
347 |
uint32_t width, height; |
uint32_t width, height; |
348 |
|
|
349 |
READ_MARKER(); |
READ_MARKER(); |
350 |
width = BitstreamGetBits(bs, 13); // video_object_layer_width |
width = BitstreamGetBits(bs, 13); /* video_object_layer_width */ |
351 |
READ_MARKER(); |
READ_MARKER(); |
352 |
height = BitstreamGetBits(bs, 13); // video_object_layer_height |
height = BitstreamGetBits(bs, 13); /* video_object_layer_height */ |
353 |
READ_MARKER(); |
READ_MARKER(); |
354 |
|
|
355 |
DPRINTF(DPRINTF_HEADER, "width %i", width); |
DPRINTF(DPRINTF_HEADER, "width %i", width); |
356 |
DPRINTF(DPRINTF_HEADER, "height %i", height); |
DPRINTF(DPRINTF_HEADER, "height %i", height); |
357 |
|
|
358 |
// for auto set width & height |
/* for auto set width & height */ |
359 |
if (dec->width == 0) |
if (dec->width == 0) |
360 |
dec->width = width; |
dec->width = width; |
361 |
if (dec->height == 0) |
if (dec->height == 0) |
371 |
dec->interlacing = BitstreamGetBit(bs); |
dec->interlacing = BitstreamGetBit(bs); |
372 |
DPRINTF(DPRINTF_HEADER, "interlace", dec->interlacing); |
DPRINTF(DPRINTF_HEADER, "interlace", dec->interlacing); |
373 |
|
|
374 |
if (!BitstreamGetBit(bs)) // obmc_disable |
if (!BitstreamGetBit(bs)) /* obmc_disable */ |
375 |
{ |
{ |
376 |
DPRINTF(DPRINTF_ERROR, "obmc_disabled==false not supported"); |
DPRINTF(DPRINTF_ERROR, "obmc_disabled==false not supported"); |
377 |
// TODO |
/* TODO */ |
378 |
// fucking divx4.02 has this enabled |
/* fucking divx4.02 has this enabled */ |
379 |
} |
} |
380 |
|
|
381 |
if (BitstreamGetBits(bs, (vol_ver_id == 1 ? 1 : 2))) // sprite_enable |
if (BitstreamGetBits(bs, (vol_ver_id == 1 ? 1 : 2))) /* sprite_enable */ |
382 |
{ |
{ |
383 |
DPRINTF(DPRINTF_ERROR, "spriate_enabled not supported"); |
DPRINTF(DPRINTF_ERROR, "spriate_enabled not supported"); |
384 |
return -1; |
return -1; |
386 |
|
|
387 |
if (vol_ver_id != 1 && |
if (vol_ver_id != 1 && |
388 |
dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) { |
dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) { |
389 |
BitstreamSkip(bs, 1); // sadct_disable |
BitstreamSkip(bs, 1); /* sadct_disable */ |
390 |
} |
} |
391 |
|
|
392 |
if (BitstreamGetBit(bs)) // not_8_bit |
if (BitstreamGetBit(bs)) /* not_8_bit */ |
393 |
{ |
{ |
394 |
DPRINTF(DPRINTF_HEADER, "not_8_bit==true (ignored)"); |
DPRINTF(DPRINTF_HEADER, "not_8_bit==true (ignored)"); |
395 |
dec->quant_bits = BitstreamGetBits(bs, 4); // quant_precision |
dec->quant_bits = BitstreamGetBits(bs, 4); /* quant_precision */ |
396 |
BitstreamSkip(bs, 4); // bits_per_pixel |
BitstreamSkip(bs, 4); /* bits_per_pixel */ |
397 |
} else { |
} else { |
398 |
dec->quant_bits = 5; |
dec->quant_bits = 5; |
399 |
} |
} |
400 |
|
|
401 |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) { |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) { |
402 |
BitstreamSkip(bs, 1); // no_gray_quant_update |
BitstreamSkip(bs, 1); /* no_gray_quant_update */ |
403 |
BitstreamSkip(bs, 1); // composition_method |
BitstreamSkip(bs, 1); /* composition_method */ |
404 |
BitstreamSkip(bs, 1); // linear_composition |
BitstreamSkip(bs, 1); /* linear_composition */ |
405 |
} |
} |
406 |
|
|
407 |
dec->quant_type = BitstreamGetBit(bs); // quant_type |
dec->quant_type = BitstreamGetBit(bs); /* quant_type */ |
408 |
DPRINTF(DPRINTF_HEADER, "quant_type %i", dec->quant_type); |
DPRINTF(DPRINTF_HEADER, "quant_type %i", dec->quant_type); |
409 |
|
|
410 |
if (dec->quant_type) { |
if (dec->quant_type) { |
411 |
if (BitstreamGetBit(bs)) // load_intra_quant_mat |
if (BitstreamGetBit(bs)) /* load_intra_quant_mat */ |
412 |
{ |
{ |
413 |
uint8_t matrix[64]; |
uint8_t matrix[64]; |
414 |
|
|
419 |
} else |
} else |
420 |
set_intra_matrix(get_default_intra_matrix()); |
set_intra_matrix(get_default_intra_matrix()); |
421 |
|
|
422 |
if (BitstreamGetBit(bs)) // load_inter_quant_mat |
if (BitstreamGetBit(bs)) /* load_inter_quant_mat */ |
423 |
{ |
{ |
424 |
uint8_t matrix[64]; |
uint8_t matrix[64]; |
425 |
|
|
440 |
|
|
441 |
if (vol_ver_id != 1) { |
if (vol_ver_id != 1) { |
442 |
DPRINTF(DPRINTF_DEBUG, "QUARTERPEL BITSTREAM"); |
DPRINTF(DPRINTF_DEBUG, "QUARTERPEL BITSTREAM"); |
443 |
dec->quarterpel = BitstreamGetBit(bs); // quarter_sample |
dec->quarterpel = BitstreamGetBit(bs); /* quarter_sample */ |
444 |
} |
} |
445 |
else |
else |
446 |
dec->quarterpel = 0; |
dec->quarterpel = 0; |
447 |
|
|
448 |
|
|
449 |
if (!BitstreamGetBit(bs)) // complexity_estimation_disable |
if (!BitstreamGetBit(bs)) /* complexity_estimation_disable */ |
450 |
{ |
{ |
451 |
DPRINTF(DPRINTF_ERROR, "complexity_estimation not supported"); |
DPRINTF(DPRINTF_ERROR, "complexity_estimation not supported"); |
452 |
return -1; |
return -1; |
453 |
} |
} |
454 |
|
|
455 |
BitstreamSkip(bs, 1); // resync_marker_disable |
BitstreamSkip(bs, 1); /* resync_marker_disable */ |
456 |
|
|
457 |
if (BitstreamGetBit(bs)) // data_partitioned |
if (BitstreamGetBit(bs)) /* data_partitioned */ |
458 |
{ |
{ |
459 |
DPRINTF(DPRINTF_ERROR, "data_partitioned not supported"); |
DPRINTF(DPRINTF_ERROR, "data_partitioned not supported"); |
460 |
BitstreamSkip(bs, 1); // reversible_vlc |
BitstreamSkip(bs, 1); /* reversible_vlc */ |
461 |
} |
} |
462 |
|
|
463 |
if (vol_ver_id != 1) { |
if (vol_ver_id != 1) { |
464 |
if (BitstreamGetBit(bs)) // newpred_enable |
if (BitstreamGetBit(bs)) /* newpred_enable */ |
465 |
{ |
{ |
466 |
DPRINTF(DPRINTF_HEADER, "+ newpred_enable"); |
DPRINTF(DPRINTF_HEADER, "+ newpred_enable"); |
467 |
BitstreamSkip(bs, 2); // requested_upstream_message_type |
BitstreamSkip(bs, 2); /* requested_upstream_message_type */ |
468 |
BitstreamSkip(bs, 1); // newpred_segment_type |
BitstreamSkip(bs, 1); /* newpred_segment_type */ |
469 |
} |
} |
470 |
if (BitstreamGetBit(bs)) // reduced_resolution_vop_enable |
if (BitstreamGetBit(bs)) /* reduced_resolution_vop_enable */ |
471 |
{ |
{ |
472 |
DPRINTF(DPRINTF_ERROR, "reduced_resolution_vop not supported"); |
DPRINTF(DPRINTF_ERROR, "reduced_resolution_vop not supported"); |
473 |
return -1; |
return -1; |
474 |
} |
} |
475 |
} |
} |
476 |
|
|
477 |
if ((dec->scalability = BitstreamGetBit(bs))) // scalability |
if ((dec->scalability = (int8_t)BitstreamGetBit(bs))) /* scalability */ |
478 |
{ |
{ |
479 |
DPRINTF(DPRINTF_ERROR, "scalability not supported"); |
DPRINTF(DPRINTF_ERROR, "scalability not supported"); |
480 |
return -1; |
return -1; |
481 |
} |
} |
482 |
} else // dec->shape == BINARY_ONLY |
} else /* dec->shape == BINARY_ONLY */ |
483 |
{ |
{ |
484 |
if (vol_ver_id != 1) { |
if (vol_ver_id != 1) { |
485 |
if (BitstreamGetBit(bs)) // scalability |
if (BitstreamGetBit(bs)) /* scalability */ |
486 |
{ |
{ |
487 |
DPRINTF(DPRINTF_ERROR, "scalability not supported"); |
DPRINTF(DPRINTF_ERROR, "scalability not supported"); |
488 |
return -1; |
return -1; |
489 |
} |
} |
490 |
} |
} |
491 |
BitstreamSkip(bs, 1); // resync_marker_disable |
BitstreamSkip(bs, 1); /* resync_marker_disable */ |
492 |
|
|
493 |
} |
} |
494 |
|
|
507 |
|
|
508 |
DPRINTF(DPRINTF_HEADER, "time %ih%im%is", hours); |
DPRINTF(DPRINTF_HEADER, "time %ih%im%is", hours); |
509 |
} |
} |
510 |
BitstreamSkip(bs, 1); // closed_gov |
BitstreamSkip(bs, 1); /* closed_gov */ |
511 |
BitstreamSkip(bs, 1); // broken_link |
BitstreamSkip(bs, 1); /* broken_link */ |
512 |
|
|
513 |
} else if (start_code == VOP_START_CODE) { |
} else if (start_code == VOP_START_CODE) { |
514 |
|
|
515 |
DPRINTF(DPRINTF_STARTCODE, "<vop>"); |
DPRINTF(DPRINTF_STARTCODE, "<vop>"); |
516 |
|
|
517 |
BitstreamSkip(bs, 32); // vop_start_code |
BitstreamSkip(bs, 32); /* vop_start_code */ |
518 |
|
|
519 |
coding_type = BitstreamGetBits(bs, 2); // vop_coding_type |
coding_type = BitstreamGetBits(bs, 2); /* vop_coding_type */ |
520 |
DPRINTF(DPRINTF_HEADER, "coding_type %i", coding_type); |
DPRINTF(DPRINTF_HEADER, "coding_type %i", coding_type); |
521 |
|
|
522 |
// *************************** for decode B-frame time *********************** |
/* *************************** for decode B-frame time *********************** */ |
523 |
while (BitstreamGetBit(bs) != 0) // time_base |
while (BitstreamGetBit(bs) != 0) /* time_base */ |
524 |
time_incr++; |
time_incr++; |
525 |
|
|
526 |
READ_MARKER(); |
READ_MARKER(); |
527 |
|
|
528 |
if (dec->time_inc_bits) { |
if (dec->time_inc_bits) { |
529 |
time_increment = (BitstreamGetBits(bs, dec->time_inc_bits)); // vop_time_increment |
time_increment = (BitstreamGetBits(bs, dec->time_inc_bits)); /* vop_time_increment */ |
530 |
} |
} |
531 |
|
|
532 |
DPRINTF(DPRINTF_HEADER, "time_base %i", time_incr); |
DPRINTF(DPRINTF_HEADER, "time_base %i", time_incr); |
558 |
|
|
559 |
READ_MARKER(); |
READ_MARKER(); |
560 |
|
|
561 |
if (!BitstreamGetBit(bs)) // vop_coded |
if (!BitstreamGetBit(bs)) /* vop_coded */ |
562 |
{ |
{ |
563 |
DPRINTF(DPRINTF_HEADER, "vop_coded==false"); |
DPRINTF(DPRINTF_HEADER, "vop_coded==false"); |
564 |
return N_VOP; |
return N_VOP; |
569 |
} |
} |
570 |
*/ |
*/ |
571 |
|
|
572 |
// fix a little bug by MinChen <chenm002@163.com> |
/* fix a little bug by MinChen <chenm002@163.com> */ |
573 |
if ((dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) && |
if ((dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) && |
574 |
(coding_type == P_VOP)) { |
(coding_type == P_VOP)) { |
575 |
*rounding = BitstreamGetBit(bs); // rounding_type |
*rounding = BitstreamGetBit(bs); /* rounding_type */ |
576 |
DPRINTF(DPRINTF_HEADER, "rounding %i", *rounding); |
DPRINTF(DPRINTF_HEADER, "rounding %i", *rounding); |
577 |
} |
} |
578 |
|
|
599 |
DPRINTF(DPRINTF_HEADER, "horiz_mc_ref %i", horiz_mc_ref); |
DPRINTF(DPRINTF_HEADER, "horiz_mc_ref %i", horiz_mc_ref); |
600 |
DPRINTF(DPRINTF_HEADER, "vert_mc_ref %i", vert_mc_ref); |
DPRINTF(DPRINTF_HEADER, "vert_mc_ref %i", vert_mc_ref); |
601 |
|
|
602 |
BitstreamSkip(bs, 1); // change_conv_ratio_disable |
BitstreamSkip(bs, 1); /* change_conv_ratio_disable */ |
603 |
if (BitstreamGetBit(bs)) // vop_constant_alpha |
if (BitstreamGetBit(bs)) /* vop_constant_alpha */ |
604 |
{ |
{ |
605 |
BitstreamSkip(bs, 8); // vop_constant_alpha_value |
BitstreamSkip(bs, 8); /* vop_constant_alpha_value */ |
606 |
} |
} |
607 |
} |
} |
608 |
|
|
609 |
|
|
610 |
if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) { |
if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) { |
611 |
// intra_dc_vlc_threshold |
/* intra_dc_vlc_threshold */ |
612 |
*intra_dc_threshold = |
*intra_dc_threshold = |
613 |
intra_dc_threshold_table[BitstreamGetBits(bs, 3)]; |
intra_dc_threshold_table[BitstreamGetBits(bs, 3)]; |
614 |
|
|
621 |
} |
} |
622 |
} |
} |
623 |
|
|
624 |
if ((*quant = BitstreamGetBits(bs, dec->quant_bits)) < 1) // vop_quant |
if ((*quant = BitstreamGetBits(bs, dec->quant_bits)) < 1) /* vop_quant */ |
625 |
*quant = 1; |
*quant = 1; |
626 |
|
|
627 |
DPRINTF(DPRINTF_HEADER, "quant %i", *quant); |
DPRINTF(DPRINTF_HEADER, "quant %i", *quant); |
628 |
|
|
629 |
if (coding_type != I_VOP) { |
if (coding_type != I_VOP) { |
630 |
*fcode_forward = BitstreamGetBits(bs, 3); // fcode_forward |
*fcode_forward = BitstreamGetBits(bs, 3); /* fcode_forward */ |
631 |
DPRINTF(DPRINTF_HEADER, "fcode_forward %i", *fcode_forward); |
DPRINTF(DPRINTF_HEADER, "fcode_forward %i", *fcode_forward); |
632 |
} |
} |
633 |
|
|
634 |
if (coding_type == B_VOP) { |
if (coding_type == B_VOP) { |
635 |
*fcode_backward = BitstreamGetBits(bs, 3); // fcode_backward |
*fcode_backward = BitstreamGetBits(bs, 3); /* fcode_backward */ |
636 |
DPRINTF(DPRINTF_HEADER, "fcode_backward %i", *fcode_backward); |
DPRINTF(DPRINTF_HEADER, "fcode_backward %i", *fcode_backward); |
637 |
} |
} |
638 |
if (!dec->scalability) { |
if (!dec->scalability) { |
639 |
if ((dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) && |
if ((dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) && |
640 |
(coding_type != I_VOP)) { |
(coding_type != I_VOP)) { |
641 |
BitstreamSkip(bs, 1); // vop_shape_coding_type |
BitstreamSkip(bs, 1); /* vop_shape_coding_type */ |
642 |
} |
} |
643 |
} |
} |
644 |
return coding_type; |
return coding_type; |
647 |
|
|
648 |
DPRINTF(DPRINTF_STARTCODE, "<user_data>"); |
DPRINTF(DPRINTF_STARTCODE, "<user_data>"); |
649 |
|
|
650 |
BitstreamSkip(bs, 32); // user_data_start_code |
BitstreamSkip(bs, 32); /* user_data_start_code */ |
651 |
|
|
652 |
} else // start_code == ? |
} else /* start_code == ? */ |
653 |
{ |
{ |
654 |
if (BitstreamShowBits(bs, 24) == 0x000001) { |
if (BitstreamShowBits(bs, 24) == 0x000001) { |
655 |
DPRINTF(DPRINTF_STARTCODE, "<unknown: %x>", BitstreamShowBits(bs, 32)); |
DPRINTF(DPRINTF_STARTCODE, "<unknown: %x>", BitstreamShowBits(bs, 32)); |
659 |
} |
} |
660 |
while ((BitstreamPos(bs) >> 3) < bs->length); |
while ((BitstreamPos(bs) >> 3) < bs->length); |
661 |
|
|
662 |
//DPRINTF("*** WARNING: no vop_start_code found"); |
/*DPRINTF("*** WARNING: no vop_start_code found"); */ |
663 |
return -1; /* ignore it */ |
return -1; /* ignore it */ |
664 |
} |
} |
665 |
|
|
693 |
const MBParam * pParam, |
const MBParam * pParam, |
694 |
const FRAMEINFO * frame) |
const FRAMEINFO * frame) |
695 |
{ |
{ |
696 |
// video object_start_code & vo_id |
/* video object_start_code & vo_id */ |
697 |
BitstreamPad(bs); |
BitstreamPad(bs); |
698 |
BitstreamPutBits(bs, VO_START_CODE, 27); |
BitstreamPutBits(bs, VO_START_CODE, 27); |
699 |
BitstreamPutBits(bs, 0, 5); |
BitstreamPutBits(bs, 0, 5); |
700 |
|
|
701 |
// video_object_layer_start_code & vol_id |
/* video_object_layer_start_code & vol_id */ |
702 |
BitstreamPutBits(bs, VOL_START_CODE, 28); |
BitstreamPutBits(bs, VOL_START_CODE, 28); |
703 |
BitstreamPutBits(bs, 0, 4); |
BitstreamPutBits(bs, 0, 4); |
704 |
|
|
705 |
BitstreamPutBit(bs, 0); // random_accessible_vol |
BitstreamPutBit(bs, 0); /* random_accessible_vol */ |
706 |
BitstreamPutBits(bs, 0, 8); // video_object_type_indication |
BitstreamPutBits(bs, 0, 8); /* video_object_type_indication */ |
707 |
BitstreamPutBit(bs, 0); // is_object_layer_identified (0=not given) |
BitstreamPutBit(bs, 0); /* is_object_layer_identified (0=not given) */ |
708 |
BitstreamPutBits(bs, 1, 4); // aspect_ratio_info (1=1:1) |
BitstreamPutBits(bs, 1, 4); /* aspect_ratio_info (1=1:1) */ |
709 |
|
|
710 |
BitstreamPutBit(bs, 1); // vol_control_parameters |
BitstreamPutBit(bs, 1); /* vol_control_parameters */ |
711 |
BitstreamPutBits(bs, 1, 2); // chroma_format 1="4:2:0" |
BitstreamPutBits(bs, 1, 2); /* chroma_format 1="4:2:0" */ |
712 |
|
|
713 |
BitstreamPutBit(bs, 1); // low_delay |
BitstreamPutBit(bs, 1); /* low_delay */ |
714 |
|
|
715 |
BitstreamPutBit(bs, 0); // vbv_parameters (0=not given) |
BitstreamPutBit(bs, 0); /* vbv_parameters (0=not given) */ |
716 |
|
|
717 |
BitstreamPutBits(bs, 0, 2); // video_object_layer_shape (0=rectangular) |
BitstreamPutBits(bs, 0, 2); /* video_object_layer_shape (0=rectangular) */ |
718 |
|
|
719 |
WRITE_MARKER(); |
WRITE_MARKER(); |
720 |
|
|
729 |
|
|
730 |
WRITE_MARKER(); |
WRITE_MARKER(); |
731 |
|
|
732 |
BitstreamPutBit(bs, 1); // fixed_vop_rate = 1 |
BitstreamPutBit(bs, 1); /* fixed_vop_rate = 1 */ |
733 |
BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase)); // fixed_vop_time_increment |
BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase)); /* fixed_vop_time_increment */ |
734 |
|
|
735 |
WRITE_MARKER(); |
WRITE_MARKER(); |
736 |
BitstreamPutBits(bs, pParam->width, 13); // width |
BitstreamPutBits(bs, pParam->width, 13); /* width */ |
737 |
WRITE_MARKER(); |
WRITE_MARKER(); |
738 |
BitstreamPutBits(bs, pParam->height, 13); // height |
BitstreamPutBits(bs, pParam->height, 13); /* height */ |
739 |
WRITE_MARKER(); |
WRITE_MARKER(); |
740 |
|
|
741 |
BitstreamPutBit(bs, frame->global_flags & XVID_INTERLACING); // interlace |
BitstreamPutBit(bs, frame->global_flags & XVID_INTERLACING); /* interlace */ |
742 |
BitstreamPutBit(bs, 1); // obmc_disable (overlapped block motion compensation) |
BitstreamPutBit(bs, 1); /* obmc_disable (overlapped block motion compensation) */ |
743 |
BitstreamPutBit(bs, 0); // sprite_enable |
BitstreamPutBit(bs, 0); /* sprite_enable */ |
744 |
BitstreamPutBit(bs, 0); // not_in_bit |
BitstreamPutBit(bs, 0); /* not_in_bit */ |
745 |
|
|
746 |
// quant_type 0=h.263 1=mpeg4(quantizer tables) |
/* quant_type 0=h.263 1=mpeg4(quantizer tables) */ |
747 |
BitstreamPutBit(bs, pParam->m_quant_type); |
BitstreamPutBit(bs, pParam->m_quant_type); |
748 |
|
|
749 |
if (pParam->m_quant_type) { |
if (pParam->m_quant_type) { |
750 |
BitstreamPutBit(bs, get_intra_matrix_status()); // load_intra_quant_mat |
BitstreamPutBit(bs, get_intra_matrix_status()); /* load_intra_quant_mat */ |
751 |
if (get_intra_matrix_status()) { |
if (get_intra_matrix_status()) { |
752 |
bs_put_matrix(bs, get_intra_matrix()); |
bs_put_matrix(bs, get_intra_matrix()); |
753 |
} |
} |
754 |
|
|
755 |
BitstreamPutBit(bs, get_inter_matrix_status()); // load_inter_quant_mat |
BitstreamPutBit(bs, get_inter_matrix_status()); /* load_inter_quant_mat */ |
756 |
if (get_inter_matrix_status()) { |
if (get_inter_matrix_status()) { |
757 |
bs_put_matrix(bs, get_inter_matrix()); |
bs_put_matrix(bs, get_inter_matrix()); |
758 |
} |
} |
759 |
|
|
760 |
} |
} |
761 |
|
|
762 |
BitstreamPutBit(bs, 1); // complexity_estimation_disable |
BitstreamPutBit(bs, 1); /* complexity_estimation_disable */ |
763 |
BitstreamPutBit(bs, 1); // resync_marker_disable |
BitstreamPutBit(bs, 1); /* resync_marker_disable */ |
764 |
BitstreamPutBit(bs, 0); // data_partitioned |
BitstreamPutBit(bs, 0); /* data_partitioned */ |
765 |
BitstreamPutBit(bs, 0); // scalability |
BitstreamPutBit(bs, 0); /* scalability */ |
766 |
} |
} |
767 |
|
|
768 |
|
|
787 |
|
|
788 |
BitstreamPutBits(bs, frame->coding_type, 2); |
BitstreamPutBits(bs, frame->coding_type, 2); |
789 |
|
|
790 |
// time_base = 0 write n x PutBit(1), PutBit(0) |
/* time_base = 0 write n x PutBit(1), PutBit(0) */ |
791 |
for (i = 0; i < frame->seconds; i++) { |
for (i = 0; i < frame->seconds; i++) { |
792 |
BitstreamPutBit(bs, 1); |
BitstreamPutBit(bs, 1); |
793 |
} |
} |
795 |
|
|
796 |
WRITE_MARKER(); |
WRITE_MARKER(); |
797 |
|
|
798 |
// time_increment: value=nth_of_sec, nbits = log2(resolution) |
/* time_increment: value=nth_of_sec, nbits = log2(resolution) */ |
799 |
BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase)); |
BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase)); |
800 |
|
|
801 |
WRITE_MARKER(); |
WRITE_MARKER(); |
805 |
return; |
return; |
806 |
} |
} |
807 |
|
|
808 |
BitstreamPutBits(bs, 1, 1); // vop_coded |
BitstreamPutBits(bs, 1, 1); /* vop_coded */ |
809 |
|
|
810 |
if (frame->coding_type == P_VOP) |
if (frame->coding_type == P_VOP) |
811 |
BitstreamPutBits(bs, frame->rounding_type, 1); |
BitstreamPutBits(bs, frame->rounding_type, 1); |
812 |
|
|
813 |
BitstreamPutBits(bs, 0, 3); // intra_dc_vlc_threshold |
BitstreamPutBits(bs, 0, 3); /* intra_dc_vlc_threshold */ |
814 |
|
|
815 |
if (frame->global_flags & XVID_INTERLACING) { |
if (frame->global_flags & XVID_INTERLACING) { |
816 |
BitstreamPutBit(bs, 1); // top field first |
BitstreamPutBit(bs, 1); /* top field first */ |
817 |
BitstreamPutBit(bs, 0); // alternate vertical scan |
BitstreamPutBit(bs, 0); /* alternate vertical scan */ |
818 |
} |
} |
819 |
|
|
820 |
BitstreamPutBits(bs, frame->quant, 5); // quantizer |
BitstreamPutBits(bs, frame->quant, 5); /* quantizer */ |
821 |
|
|
822 |
if (frame->coding_type != I_VOP) |
if (frame->coding_type != I_VOP) |
823 |
BitstreamPutBits(bs, frame->fcode, 3); // forward_fixed_code |
BitstreamPutBits(bs, frame->fcode, 3); /* forward_fixed_code */ |
824 |
|
|
825 |
if (frame->coding_type == B_VOP) |
if (frame->coding_type == B_VOP) |
826 |
BitstreamPutBits(bs, frame->bcode, 3); // backward_fixed_code |
BitstreamPutBits(bs, frame->bcode, 3); /* backward_fixed_code */ |
827 |
|
|
828 |
} |
} |