Parent Directory
|
Revision Log
Revision 156 - (view) (download)
1 : | Isibaar | 3 | /****************************************************************************** |
2 : | * * | ||
3 : | * This file is part of XviD, a free MPEG-4 video encoder/decoder * | ||
4 : | * * | ||
5 : | * XviD is an implementation of a part of one or more MPEG-4 Video tools * | ||
6 : | * as specified in ISO/IEC 14496-2 standard. Those intending to use this * | ||
7 : | * software module in hardware or software products are advised that its * | ||
8 : | * use may infringe existing patents or copyrights, and any such use * | ||
9 : | * would be at such party's own risk. The original developer of this * | ||
10 : | * software module and his/her company, and subsequent editors and their * | ||
11 : | * companies, will have no liability for use of this software or * | ||
12 : | * modifications or derivatives thereof. * | ||
13 : | * * | ||
14 : | * XviD is free software; you can redistribute it and/or modify it * | ||
15 : | * under the terms of the GNU General Public License as published by * | ||
16 : | * the Free Software Foundation; either version 2 of the License, or * | ||
17 : | * (at your option) any later version. * | ||
18 : | * * | ||
19 : | * XviD is distributed in the hope that it will be useful, but * | ||
20 : | * WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
21 : | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
22 : | * GNU General Public License for more details. * | ||
23 : | * * | ||
24 : | * You should have received a copy of the GNU General Public License * | ||
25 : | * along with this program; if not, write to the Free Software * | ||
26 : | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * | ||
27 : | * * | ||
28 : | ******************************************************************************/ | ||
29 : | |||
30 : | /****************************************************************************** | ||
31 : | * * | ||
32 : | * bitstream.c * | ||
33 : | * * | ||
34 : | * Copyright (C) 2001 - Peter Ross <pross@cs.rmit.edu.au> * | ||
35 : | * * | ||
36 : | * For more information visit the XviD homepage: http://www.xvid.org * | ||
37 : | * * | ||
38 : | ******************************************************************************/ | ||
39 : | |||
40 : | /****************************************************************************** | ||
41 : | * * | ||
42 : | * Revision history: * | ||
43 : | chenm001 | 124 | * * |
44 : | suxen_drol | 152 | * 01.05.2002 added BVOP support to BitstreamWriteVopHeader |
45 : | chenm001 | 124 | * 15.04.2002 rewrite log2bin use asm386 By MinChen <chenm001@163.com> * |
46 : | * 26.03.2002 interlacing support * | ||
47 : | Isibaar | 3 | * 03.03.2002 qmatrix writing * |
48 : | * 03.03.2002 merged BITREADER and BITWRITER * | ||
49 : | * 30.02.2002 intra_dc_threshold support * | ||
50 : | * 04.12.2001 support for additional headers * | ||
51 : | * 16.12.2001 inital version * | ||
52 : | * * | ||
53 : | ******************************************************************************/ | ||
54 : | |||
55 : | |||
56 : | #include "bitstream.h" | ||
57 : | #include "zigzag.h" | ||
58 : | Isibaar | 4 | #include "../quant/quant_matrix.h" |
59 : | Isibaar | 3 | |
60 : | chenm001 | 124 | |
61 : | Isibaar | 3 | static int __inline log2bin(int value) |
62 : | { | ||
63 : | chenm001 | 124 | /* Changed by Chenm001 */ |
64 : | #ifndef WIN32 | ||
65 : | Isibaar | 3 | int n = 0; |
66 : | while (value) | ||
67 : | { | ||
68 : | value >>= 1; | ||
69 : | n++; | ||
70 : | } | ||
71 : | return n; | ||
72 : | chenm001 | 124 | #else |
73 : | __asm{ | ||
74 : | bsr eax,value | ||
75 : | inc eax | ||
76 : | } | ||
77 : | #endif | ||
78 : | Isibaar | 3 | } |
79 : | |||
80 : | |||
81 : | static const uint32_t intra_dc_threshold_table[] = | ||
82 : | { | ||
83 : | 32, /* never use */ | ||
84 : | 13, | ||
85 : | 15, | ||
86 : | 17, | ||
87 : | 19, | ||
88 : | 21, | ||
89 : | 23, | ||
90 : | 1, | ||
91 : | }; | ||
92 : | |||
93 : | |||
94 : | Isibaar | 4 | void bs_get_matrix(Bitstream * bs, uint8_t * matrix) |
95 : | { | ||
96 : | int i = 0; | ||
97 : | int last, value = 0; | ||
98 : | |||
99 : | do | ||
100 : | { | ||
101 : | last = value; | ||
102 : | value = BitstreamGetBits(bs, 8); | ||
103 : | matrix[ scan_tables[0][i++] ] = value; | ||
104 : | } | ||
105 : | while (value != 0 && i < 64); | ||
106 : | |||
107 : | while (i < 64) | ||
108 : | { | ||
109 : | matrix[ scan_tables[0][i++] ] = last; | ||
110 : | } | ||
111 : | } | ||
112 : | |||
113 : | Isibaar | 3 | /* |
114 : | decode headers | ||
115 : | returns coding_type, or -1 if error | ||
116 : | */ | ||
117 : | |||
118 : | chenm001 | 156 | int BitstreamReadHeaders(Bitstream * bs, DECODER * dec, uint32_t * rounding, uint32_t * quant, uint32_t * fcode_forward, uint32_t * fcode_backward, uint32_t * intra_dc_threshold) |
119 : | Isibaar | 3 | { |
120 : | uint32_t vol_ver_id; | ||
121 : | chenm001 | 156 | static uint32_t time_increment_resolution; |
122 : | Isibaar | 3 | uint32_t coding_type; |
123 : | uint32_t start_code; | ||
124 : | chenm001 | 156 | uint32_t time_incr=0; |
125 : | int32_t time_increment; | ||
126 : | |||
127 : | Isibaar | 3 | do |
128 : | { | ||
129 : | BitstreamByteAlign(bs); | ||
130 : | start_code = BitstreamShowBits(bs, 32); | ||
131 : | |||
132 : | if (start_code == VISOBJSEQ_START_CODE) | ||
133 : | { | ||
134 : | // DEBUG("visual_object_sequence"); | ||
135 : | BitstreamSkip(bs, 32); // visual_object_sequence_start_code | ||
136 : | BitstreamSkip(bs, 8); // profile_and_level_indication | ||
137 : | } | ||
138 : | else if (start_code == VISOBJSEQ_STOP_CODE) | ||
139 : | { | ||
140 : | BitstreamSkip(bs, 32); // visual_object_sequence_stop_code | ||
141 : | } | ||
142 : | else if (start_code == VISOBJ_START_CODE) | ||
143 : | { | ||
144 : | // DEBUG("visual_object"); | ||
145 : | BitstreamSkip(bs,32); // visual_object_start_code | ||
146 : | if (BitstreamGetBit(bs)) // is_visual_object_identified | ||
147 : | { | ||
148 : | vol_ver_id = BitstreamGetBits(bs,4); // visual_object_ver_id | ||
149 : | BitstreamSkip(bs, 3); // visual_object_priority | ||
150 : | } | ||
151 : | else | ||
152 : | { | ||
153 : | vol_ver_id = 1; | ||
154 : | } | ||
155 : | |||
156 : | if (BitstreamShowBits(bs, 4) != VISOBJ_TYPE_VIDEO) // visual_object_type | ||
157 : | { | ||
158 : | DEBUG("visual_object_type != video"); | ||
159 : | return -1; | ||
160 : | } | ||
161 : | BitstreamSkip(bs, 4); | ||
162 : | |||
163 : | // video_signal_type | ||
164 : | |||
165 : | if (BitstreamGetBit(bs)) // video_signal_type | ||
166 : | { | ||
167 : | DEBUG("+ video_signal_type"); | ||
168 : | BitstreamSkip(bs, 3); // video_format | ||
169 : | BitstreamSkip(bs, 1); // video_range | ||
170 : | if (BitstreamGetBit(bs)) // color_description | ||
171 : | { | ||
172 : | DEBUG("+ color_description"); | ||
173 : | BitstreamSkip(bs, 8); // color_primaries | ||
174 : | BitstreamSkip(bs, 8); // transfer_characteristics | ||
175 : | BitstreamSkip(bs, 8); // matrix_coefficients | ||
176 : | } | ||
177 : | } | ||
178 : | } | ||
179 : | else if ((start_code & ~0x1f) == VIDOBJ_START_CODE) | ||
180 : | { | ||
181 : | BitstreamSkip(bs, 32); // video_object_start_code | ||
182 : | } | ||
183 : | else if ((start_code & ~0xf) == VIDOBJLAY_START_CODE) | ||
184 : | { | ||
185 : | // DEBUG("video_object_layer"); | ||
186 : | BitstreamSkip(bs, 32); // video_object_layer_start_code | ||
187 : | |||
188 : | chenm001 | 156 | BitstreamSkip(bs, 1); // random_accessible_vol |
189 : | Isibaar | 3 | |
190 : | // video_object_type_indication | ||
191 : | if (BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_SIMPLE && | ||
192 : | BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_CORE && | ||
193 : | BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_MAIN && | ||
194 : | BitstreamShowBits(bs, 8) != 0) // BUGGY DIVX | ||
195 : | { | ||
196 : | DEBUG1("video_object_type_indication not supported", BitstreamShowBits(bs, 8)); | ||
197 : | return -1; | ||
198 : | } | ||
199 : | BitstreamSkip(bs, 8); | ||
200 : | |||
201 : | |||
202 : | if (BitstreamGetBit(bs)) // is_object_layer_identifier | ||
203 : | { | ||
204 : | DEBUG("+ is_object_layer_identifier"); | ||
205 : | vol_ver_id = BitstreamGetBits(bs,4); // video_object_layer_verid | ||
206 : | BitstreamSkip(bs, 3); // video_object_layer_priority | ||
207 : | } | ||
208 : | else | ||
209 : | { | ||
210 : | vol_ver_id = 1; | ||
211 : | } | ||
212 : | //DEBUGI("vol_ver_id", vol_ver_id); | ||
213 : | |||
214 : | if (BitstreamGetBits(bs, 4) == VIDOBJLAY_AR_EXTPAR) // aspect_ratio_info | ||
215 : | { | ||
216 : | DEBUG("+ aspect_ratio_info"); | ||
217 : | BitstreamSkip(bs, 8); // par_width | ||
218 : | BitstreamSkip(bs, 8); // par_height | ||
219 : | } | ||
220 : | |||
221 : | chenm001 | 156 | if (BitstreamGetBit(bs)) // vol_control_parameters |
222 : | Isibaar | 3 | { |
223 : | DEBUG("+ vol_control_parameters"); | ||
224 : | BitstreamSkip(bs, 2); // chroma_format | ||
225 : | BitstreamSkip(bs, 1); // low_delay | ||
226 : | if (BitstreamGetBit(bs)) // vbv_parameters | ||
227 : | { | ||
228 : | DEBUG("+ vbv_parameters"); | ||
229 : | BitstreamSkip(bs, 15); // first_half_bitrate | ||
230 : | READ_MARKER(); | ||
231 : | BitstreamSkip(bs, 15); // latter_half_bitrate | ||
232 : | READ_MARKER(); | ||
233 : | BitstreamSkip(bs, 15); // first_half_vbv_buffer_size | ||
234 : | READ_MARKER(); | ||
235 : | BitstreamSkip(bs, 3); // latter_half_vbv_buffer_size | ||
236 : | BitstreamSkip(bs, 11); // first_half_vbv_occupancy | ||
237 : | READ_MARKER(); | ||
238 : | BitstreamSkip(bs, 15); // latter_half_vbv_occupancy | ||
239 : | READ_MARKER(); | ||
240 : | |||
241 : | } | ||
242 : | } | ||
243 : | |||
244 : | dec->shape = BitstreamGetBits(bs, 2); // video_object_layer_shape | ||
245 : | // DEBUG1("shape", dec->shape); | ||
246 : | |||
247 : | if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE && vol_ver_id != 1) | ||
248 : | { | ||
249 : | BitstreamSkip(bs, 4); // video_object_layer_shape_extension | ||
250 : | } | ||
251 : | |||
252 : | READ_MARKER(); | ||
253 : | |||
254 : | chenm001 | 156 | // *************************** for decode B-frame time *********************** |
255 : | time_increment_resolution = BitstreamGetBits(bs, 16); // vop_time_increment_resolution | ||
256 : | time_increment_resolution--; | ||
257 : | //DEBUG1("time_increment_resolution=",time_increment_resolution); | ||
258 : | if (time_increment_resolution > 0) | ||
259 : | Isibaar | 3 | { |
260 : | chenm001 | 156 | dec->time_inc_bits = log2bin(time_increment_resolution); |
261 : | Isibaar | 3 | } |
262 : | else | ||
263 : | { | ||
264 : | // dec->time_inc_bits = 0; | ||
265 : | |||
266 : | // for "old" xvid compatibility, set time_inc_bits = 1 | ||
267 : | dec->time_inc_bits = 1; | ||
268 : | } | ||
269 : | |||
270 : | READ_MARKER(); | ||
271 : | |||
272 : | if (BitstreamGetBit(bs)) // fixed_vop_rate | ||
273 : | { | ||
274 : | BitstreamSkip(bs, dec->time_inc_bits); // fixed_vop_time_increment | ||
275 : | } | ||
276 : | |||
277 : | if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) | ||
278 : | { | ||
279 : | |||
280 : | if (dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR) | ||
281 : | { | ||
282 : | uint32_t width, height; | ||
283 : | |||
284 : | READ_MARKER(); | ||
285 : | width = BitstreamGetBits(bs, 13); // video_object_layer_width | ||
286 : | //DEBUGI("width", width); | ||
287 : | READ_MARKER(); | ||
288 : | height = BitstreamGetBits(bs, 13); // video_object_layer_height | ||
289 : | //DEBUGI("height", height); | ||
290 : | READ_MARKER(); | ||
291 : | |||
292 : | if (width != dec->width || height != dec->height) | ||
293 : | { | ||
294 : | DEBUG("FATAL: video dimension discrepancy ***"); | ||
295 : | DEBUG2("bitstream width/height", width, height); | ||
296 : | DEBUG2("param width/height", dec->width, dec->height); | ||
297 : | return -1; | ||
298 : | } | ||
299 : | |||
300 : | } | ||
301 : | h | 69 | |
302 : | canard | 74 | if ((dec->interlacing = BitstreamGetBit(bs))) |
303 : | Isibaar | 3 | { |
304 : | h | 69 | DEBUG("vol: interlacing"); |
305 : | Isibaar | 3 | } |
306 : | |||
307 : | if (!BitstreamGetBit(bs)) // obmc_disable | ||
308 : | { | ||
309 : | DEBUG("IGNORED/TODO: !obmc_disable"); | ||
310 : | // TODO | ||
311 : | // fucking divx4.02 has this enabled | ||
312 : | } | ||
313 : | |||
314 : | if (BitstreamGetBits(bs, (vol_ver_id == 1 ? 1 : 2))) // sprite_enable | ||
315 : | { | ||
316 : | DEBUG("sprite_enable; not supported"); | ||
317 : | return -1; | ||
318 : | } | ||
319 : | |||
320 : | if (vol_ver_id != 1 && dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) | ||
321 : | { | ||
322 : | BitstreamSkip(bs, 1); // sadct_disable | ||
323 : | } | ||
324 : | |||
325 : | if (BitstreamGetBit(bs)) // not_8_bit | ||
326 : | { | ||
327 : | DEBUG("+ not_8_bit [IGNORED/TODO]"); | ||
328 : | dec->quant_bits = BitstreamGetBits(bs, 4); // quant_precision | ||
329 : | BitstreamSkip(bs, 4); // bits_per_pixel | ||
330 : | } | ||
331 : | else | ||
332 : | { | ||
333 : | dec->quant_bits = 5; | ||
334 : | } | ||
335 : | |||
336 : | if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) | ||
337 : | { | ||
338 : | BitstreamSkip(bs, 1); // no_gray_quant_update | ||
339 : | BitstreamSkip(bs, 1); // composition_method | ||
340 : | BitstreamSkip(bs, 1); // linear_composition | ||
341 : | } | ||
342 : | |||
343 : | dec->quant_type = BitstreamGetBit(bs); // quant_type | ||
344 : | // DEBUG1("**** quant_type", dec->quant_type); | ||
345 : | |||
346 : | if (dec->quant_type) | ||
347 : | { | ||
348 : | if (BitstreamGetBit(bs)) // load_intra_quant_mat | ||
349 : | { | ||
350 : | Isibaar | 20 | uint8_t matrix[64]; |
351 : | Isibaar | 4 | bs_get_matrix(bs, matrix); |
352 : | set_intra_matrix(matrix); | ||
353 : | Isibaar | 3 | } |
354 : | Isibaar | 20 | else |
355 : | set_intra_matrix(get_default_intra_matrix()); | ||
356 : | Isibaar | 4 | |
357 : | Isibaar | 3 | if (BitstreamGetBit(bs)) // load_inter_quant_mat |
358 : | { | ||
359 : | Isibaar | 20 | uint8_t matrix[64]; |
360 : | Isibaar | 4 | bs_get_matrix(bs, matrix); |
361 : | set_inter_matrix(matrix); | ||
362 : | Isibaar | 3 | } |
363 : | Isibaar | 20 | else |
364 : | set_inter_matrix(get_default_inter_matrix()); | ||
365 : | Isibaar | 3 | |
366 : | if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) | ||
367 : | { | ||
368 : | // TODO | ||
369 : | DEBUG("TODO: grayscale matrix stuff"); | ||
370 : | return -1; | ||
371 : | } | ||
372 : | Isibaar | 4 | |
373 : | Isibaar | 3 | } |
374 : | |||
375 : | |||
376 : | if (vol_ver_id != 1) | ||
377 : | { | ||
378 : | dec->quarterpel = BitstreamGetBit(bs); // quarter_sampe | ||
379 : | if (dec->quarterpel) | ||
380 : | { | ||
381 : | DEBUG("IGNORED/TODO: quarter_sample"); | ||
382 : | } | ||
383 : | } | ||
384 : | else | ||
385 : | { | ||
386 : | dec->quarterpel = 0; | ||
387 : | } | ||
388 : | |||
389 : | if (!BitstreamGetBit(bs)) // complexity_estimation_disable | ||
390 : | { | ||
391 : | DEBUG("TODO: complexity_estimation header"); | ||
392 : | // TODO | ||
393 : | return -1; | ||
394 : | } | ||
395 : | |||
396 : | if (!BitstreamGetBit(bs)) // resync_marker_disable | ||
397 : | { | ||
398 : | DEBUG("IGNORED/TODO: !resync_marker_disable"); | ||
399 : | // TODO | ||
400 : | } | ||
401 : | |||
402 : | if (BitstreamGetBit(bs)) // data_partitioned | ||
403 : | { | ||
404 : | DEBUG("+ data_partitioned"); | ||
405 : | BitstreamSkip(bs, 1); // reversible_vlc | ||
406 : | } | ||
407 : | |||
408 : | if (vol_ver_id != 1) | ||
409 : | { | ||
410 : | if (BitstreamGetBit(bs)) // newpred_enable | ||
411 : | { | ||
412 : | DEBUG("+ newpred_enable"); | ||
413 : | BitstreamSkip(bs, 2); // requested_upstream_message_type | ||
414 : | BitstreamSkip(bs, 1); // newpred_segment_type | ||
415 : | } | ||
416 : | if (BitstreamGetBit(bs)) // reduced_resolution_vop_enable | ||
417 : | { | ||
418 : | DEBUG("TODO: reduced_resolution_vop_enable"); | ||
419 : | // TODO | ||
420 : | return -1; | ||
421 : | } | ||
422 : | } | ||
423 : | |||
424 : | chenm001 | 156 | if ((dec->scalability=BitstreamGetBit(bs))) // scalability |
425 : | Isibaar | 3 | { |
426 : | // TODO | ||
427 : | DEBUG("TODO: scalability"); | ||
428 : | return -1; | ||
429 : | } | ||
430 : | } | ||
431 : | else // dec->shape == BINARY_ONLY | ||
432 : | { | ||
433 : | if (vol_ver_id != 1) | ||
434 : | { | ||
435 : | if (BitstreamGetBit(bs)) // scalability | ||
436 : | { | ||
437 : | // TODO | ||
438 : | DEBUG("TODO: scalability"); | ||
439 : | return -1; | ||
440 : | } | ||
441 : | } | ||
442 : | BitstreamSkip(bs, 1); // resync_marker_disable | ||
443 : | |||
444 : | } | ||
445 : | |||
446 : | } | ||
447 : | else if (start_code == GRPOFVOP_START_CODE) | ||
448 : | { | ||
449 : | // DEBUG("group_of_vop"); | ||
450 : | BitstreamSkip(bs, 32); | ||
451 : | { | ||
452 : | int hours, minutes, seconds; | ||
453 : | hours = BitstreamGetBits(bs, 5); | ||
454 : | minutes = BitstreamGetBits(bs, 6); | ||
455 : | READ_MARKER(); | ||
456 : | seconds = BitstreamGetBits(bs, 6); | ||
457 : | // DEBUG3("hms", hours, minutes, seconds); | ||
458 : | } | ||
459 : | BitstreamSkip(bs, 1); // closed_gov | ||
460 : | BitstreamSkip(bs, 1); // broken_link | ||
461 : | } | ||
462 : | else if (start_code == VOP_START_CODE) | ||
463 : | { | ||
464 : | // DEBUG("vop_start_code"); | ||
465 : | BitstreamSkip(bs, 32); // vop_start_code | ||
466 : | |||
467 : | coding_type = BitstreamGetBits(bs, 2); // vop_coding_type | ||
468 : | //DEBUG1("coding_type", coding_type); | ||
469 : | |||
470 : | chenm001 | 156 | // *************************** for decode B-frame time *********************** |
471 : | while (BitstreamGetBit(bs) != 0) // time_base | ||
472 : | time_incr++; | ||
473 : | Isibaar | 3 | |
474 : | READ_MARKER(); | ||
475 : | |||
476 : | //DEBUG1("time_inc_bits", dec->time_inc_bits); | ||
477 : | //DEBUG1("vop_time_incr", BitstreamShowBits(bs, dec->time_inc_bits)); | ||
478 : | if (dec->time_inc_bits) | ||
479 : | { | ||
480 : | chenm001 | 156 | //BitstreamSkip(bs, dec->time_inc_bits); // vop_time_increment |
481 : | time_increment = (BitstreamGetBits(bs, dec->time_inc_bits)); // vop_time_increment | ||
482 : | Isibaar | 3 | } |
483 : | chenm001 | 156 | if(coding_type != B_VOP){ |
484 : | dec->last_time_base = dec->time_base; | ||
485 : | dec->time_base += time_incr; | ||
486 : | dec->time = dec->time_base*time_increment_resolution + time_increment; | ||
487 : | dec->time_pp= (uint32_t)(dec->time - dec->last_non_b_time); | ||
488 : | dec->last_non_b_time= dec->time; | ||
489 : | }else{ | ||
490 : | dec->time = (dec->last_time_base + time_incr)*time_increment_resolution + time_increment; | ||
491 : | dec->time_bp= (uint32_t)(dec->last_non_b_time - dec->time); | ||
492 : | } | ||
493 : | //DEBUG1("time_increment=",time_increment); | ||
494 : | Isibaar | 3 | |
495 : | READ_MARKER(); | ||
496 : | |||
497 : | if (!BitstreamGetBit(bs)) // vop_coded | ||
498 : | { | ||
499 : | return N_VOP; | ||
500 : | } | ||
501 : | |||
502 : | /* if (newpred_enable) | ||
503 : | { | ||
504 : | } | ||
505 : | */ | ||
506 : | |||
507 : | chenm001 | 156 | // fix a little bug by MinChen <chenm002@163.com> |
508 : | if ((dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) && (coding_type == P_VOP)) | ||
509 : | Isibaar | 3 | { |
510 : | *rounding = BitstreamGetBit(bs); // rounding_type | ||
511 : | //DEBUG1("rounding", *rounding); | ||
512 : | } | ||
513 : | |||
514 : | /* if (reduced_resolution_enable) | ||
515 : | { | ||
516 : | } | ||
517 : | */ | ||
518 : | |||
519 : | if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) | ||
520 : | { | ||
521 : | uint32_t width, height; | ||
522 : | uint32_t horiz_mc_ref, vert_mc_ref; | ||
523 : | |||
524 : | width = BitstreamGetBits(bs, 13); | ||
525 : | READ_MARKER(); | ||
526 : | height = BitstreamGetBits(bs, 13); | ||
527 : | READ_MARKER(); | ||
528 : | horiz_mc_ref = BitstreamGetBits(bs, 13); | ||
529 : | READ_MARKER(); | ||
530 : | vert_mc_ref = BitstreamGetBits(bs, 13); | ||
531 : | READ_MARKER(); | ||
532 : | |||
533 : | // DEBUG2("vop_width/height", width, height); | ||
534 : | // DEBUG2("ref ", horiz_mc_ref, vert_mc_ref); | ||
535 : | |||
536 : | BitstreamSkip(bs, 1); // change_conv_ratio_disable | ||
537 : | if (BitstreamGetBit(bs)) // vop_constant_alpha | ||
538 : | { | ||
539 : | BitstreamSkip(bs, 8); // vop_constant_alpha_value | ||
540 : | } | ||
541 : | } | ||
542 : | |||
543 : | |||
544 : | if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) | ||
545 : | { | ||
546 : | // intra_dc_vlc_threshold | ||
547 : | *intra_dc_threshold = intra_dc_threshold_table[ BitstreamGetBits(bs,3) ]; | ||
548 : | |||
549 : | h | 69 | if (dec->interlacing) |
550 : | { | ||
551 : | canard | 74 | if ((dec->top_field_first = BitstreamGetBit(bs))) |
552 : | Isibaar | 3 | { |
553 : | h | 69 | DEBUG("vop: top_field_first"); |
554 : | } | ||
555 : | canard | 74 | if ((dec->alternate_vertical_scan = BitstreamGetBit(bs))) |
556 : | h | 69 | { |
557 : | DEBUG("vop: alternate_vertical_scan"); | ||
558 : | } | ||
559 : | } | ||
560 : | Isibaar | 3 | } |
561 : | |||
562 : | *quant = BitstreamGetBits(bs, dec->quant_bits); // vop_quant | ||
563 : | //DEBUG1("quant", *quant); | ||
564 : | |||
565 : | if (coding_type != I_VOP) | ||
566 : | { | ||
567 : | chenm001 | 156 | *fcode_forward = BitstreamGetBits(bs, 3); // fcode_forward |
568 : | Isibaar | 3 | } |
569 : | |||
570 : | if (coding_type == B_VOP) | ||
571 : | { | ||
572 : | chenm001 | 156 | *fcode_backward = BitstreamGetBits(bs, 3); // fcode_backward |
573 : | Isibaar | 3 | } |
574 : | chenm001 | 156 | if (!dec->scalability){ |
575 : | if ((dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) && (coding_type != I_VOP)){ | ||
576 : | BitstreamSkip(bs, 1); // vop_shape_coding_type | ||
577 : | } | ||
578 : | } | ||
579 : | Isibaar | 3 | return coding_type; |
580 : | } | ||
581 : | else if (start_code == USERDATA_START_CODE) | ||
582 : | { | ||
583 : | // DEBUG("user_data"); | ||
584 : | BitstreamSkip(bs, 32); // user_data_start_code | ||
585 : | } | ||
586 : | else // start_code == ? | ||
587 : | { | ||
588 : | if (BitstreamShowBits(bs, 24) == 0x000001) | ||
589 : | { | ||
590 : | DEBUG1("*** WARNING: unknown start_code", BitstreamShowBits(bs, 32)); | ||
591 : | } | ||
592 : | BitstreamSkip(bs, 8); | ||
593 : | } | ||
594 : | } | ||
595 : | while ((BitstreamPos(bs) >> 3) < bs->length); | ||
596 : | |||
597 : | DEBUG("*** WARNING: no vop_start_code found"); | ||
598 : | return -1; /* ignore it */ | ||
599 : | } | ||
600 : | |||
601 : | |||
602 : | /* write custom quant matrix */ | ||
603 : | |||
604 : | Isibaar | 4 | static void bs_put_matrix(Bitstream * bs, const int16_t *matrix) |
605 : | Isibaar | 3 | { |
606 : | int i, j; | ||
607 : | const int last = matrix[scan_tables[0][63]]; | ||
608 : | |||
609 : | for (j = 63; j >= 0 && matrix[scan_tables[0][j - 1]] == last; j--) ; | ||
610 : | |||
611 : | for (i = 0; i <= j; i++) | ||
612 : | { | ||
613 : | BitstreamPutBits(bs, matrix[scan_tables[0][i]], 8); | ||
614 : | } | ||
615 : | |||
616 : | if (j < 63) | ||
617 : | { | ||
618 : | BitstreamPutBits(bs, 0, 8); | ||
619 : | } | ||
620 : | } | ||
621 : | |||
622 : | |||
623 : | /* | ||
624 : | write vol header | ||
625 : | */ | ||
626 : | void BitstreamWriteVolHeader(Bitstream * const bs, | ||
627 : | suxen_drol | 136 | const MBParam * pParam, const FRAMEINFO * frame) |
628 : | Isibaar | 3 | { |
629 : | // video object_start_code & vo_id | ||
630 : | BitstreamPad(bs); | ||
631 : | BitstreamPutBits(bs, VO_START_CODE, 27); | ||
632 : | BitstreamPutBits(bs, 0, 5); | ||
633 : | |||
634 : | // video_object_layer_start_code & vol_id | ||
635 : | BitstreamPutBits(bs, VOL_START_CODE, 28); | ||
636 : | BitstreamPutBits(bs, 0, 4); | ||
637 : | |||
638 : | BitstreamPutBit(bs, 0); // random_accessible_vol | ||
639 : | BitstreamPutBits(bs, 0, 8); // video_object_type_indication | ||
640 : | BitstreamPutBit(bs, 0); // is_object_layer_identified (0=not given) | ||
641 : | BitstreamPutBits(bs, 1, 4); // aspect_ratio_info (1=1:1) | ||
642 : | BitstreamPutBit(bs, 0); // vol_control_parameters (0=not given) | ||
643 : | BitstreamPutBits(bs, 0, 2); // video_object_layer_shape (0=rectangular) | ||
644 : | |||
645 : | WRITE_MARKER(); | ||
646 : | |||
647 : | /* time_increment_resolution; ignored by current decore versions | ||
648 : | eg. 2fps res=2 inc=1 | ||
649 : | 25fps res=25 inc=1 | ||
650 : | 29.97fps res=30000 inc=1001 | ||
651 : | */ | ||
652 : | BitstreamPutBits(bs, 2, 16); | ||
653 : | |||
654 : | WRITE_MARKER(); | ||
655 : | |||
656 : | // fixed_vop_rate | ||
657 : | BitstreamPutBit(bs, 0); | ||
658 : | |||
659 : | // fixed_time_increment: value=nth_of_sec, nbits = log2(resolution) | ||
660 : | // BitstreamPutBits(bs, 0, 15); | ||
661 : | |||
662 : | WRITE_MARKER(); | ||
663 : | h | 69 | BitstreamPutBits(bs, pParam->width, 13); // width |
664 : | Isibaar | 3 | WRITE_MARKER(); |
665 : | h | 69 | BitstreamPutBits(bs, pParam->height, 13); // height |
666 : | Isibaar | 3 | WRITE_MARKER(); |
667 : | |||
668 : | suxen_drol | 136 | BitstreamPutBit(bs, frame->global_flags & XVID_INTERLACING); // interlace |
669 : | Isibaar | 3 | BitstreamPutBit(bs, 1); // obmc_disable (overlapped block motion compensation) |
670 : | BitstreamPutBit(bs, 0); // sprite_enable | ||
671 : | BitstreamPutBit(bs, 0); // not_in_bit | ||
672 : | |||
673 : | // quant_type 0=h.263 1=mpeg4(quantizer tables) | ||
674 : | suxen_drol | 136 | BitstreamPutBit(bs, pParam->m_quant_type); |
675 : | Isibaar | 4 | |
676 : | suxen_drol | 136 | if (pParam->m_quant_type) |
677 : | Isibaar | 3 | { |
678 : | Isibaar | 4 | BitstreamPutBit(bs, get_intra_matrix_status()); // load_intra_quant_mat |
679 : | if (get_intra_matrix_status()) | ||
680 : | Isibaar | 3 | { |
681 : | Isibaar | 4 | bs_put_matrix(bs, get_intra_matrix()); |
682 : | Isibaar | 3 | } |
683 : | |||
684 : | Isibaar | 4 | BitstreamPutBit(bs, get_inter_matrix_status()); // load_inter_quant_mat |
685 : | if (get_inter_matrix_status()) | ||
686 : | Isibaar | 3 | { |
687 : | Isibaar | 4 | bs_put_matrix(bs, get_inter_matrix()); |
688 : | Isibaar | 3 | } |
689 : | |||
690 : | } | ||
691 : | |||
692 : | BitstreamPutBit(bs, 1); // complexity_estimation_disable | ||
693 : | BitstreamPutBit(bs, 1); // resync_marker_disable | ||
694 : | BitstreamPutBit(bs, 0); // data_partitioned | ||
695 : | BitstreamPutBit(bs, 0); // scalability | ||
696 : | } | ||
697 : | |||
698 : | |||
699 : | /* | ||
700 : | write vop header | ||
701 : | |||
702 : | NOTE: doesnt handle bother with time_base & time_inc | ||
703 : | time_base = n seconds since last resync (eg. last iframe) | ||
704 : | time_inc = nth of a second since last resync | ||
705 : | (decoder uses these values to determine precise time since last resync) | ||
706 : | */ | ||
707 : | void BitstreamWriteVopHeader(Bitstream * const bs, | ||
708 : | suxen_drol | 136 | const MBParam * pParam, |
709 : | const FRAMEINFO * frame) | ||
710 : | Isibaar | 3 | { |
711 : | suxen_drol | 152 | #ifdef BFRAMES |
712 : | uint32_t i; | ||
713 : | #endif | ||
714 : | Isibaar | 3 | BitstreamPad(bs); |
715 : | BitstreamPutBits(bs, VOP_START_CODE, 32); | ||
716 : | |||
717 : | suxen_drol | 136 | BitstreamPutBits(bs, frame->coding_type, 2); |
718 : | Isibaar | 3 | |
719 : | // time_base = 0 write n x PutBit(1), PutBit(0) | ||
720 : | suxen_drol | 152 | #ifdef BFRAMES |
721 : | for (i = 0; i < frame->seconds; i++) | ||
722 : | { | ||
723 : | BitstreamPutBit(bs, 1); | ||
724 : | } | ||
725 : | BitstreamPutBit(bs, 0); | ||
726 : | #else | ||
727 : | Isibaar | 3 | BitstreamPutBits(bs, 0, 1); |
728 : | suxen_drol | 152 | #endif |
729 : | Isibaar | 3 | |
730 : | WRITE_MARKER(); | ||
731 : | |||
732 : | // time_increment: value=nth_of_sec, nbits = log2(resolution) | ||
733 : | suxen_drol | 152 | #ifdef BFRAMES |
734 : | BitstreamPutBits(bs, frame->ticks, 5); | ||
735 : | dprintf("[%i:%i] %c\n", frame->seconds, frame->ticks, frame->coding_type == I_VOP ? 'I' : frame->coding_type == P_VOP ? 'P' : 'B'); | ||
736 : | #else | ||
737 : | Isibaar | 3 | BitstreamPutBits(bs, 1, 1); |
738 : | suxen_drol | 152 | #endif |
739 : | Isibaar | 3 | |
740 : | WRITE_MARKER(); | ||
741 : | |||
742 : | BitstreamPutBits(bs, 1, 1); // vop_coded | ||
743 : | |||
744 : | suxen_drol | 136 | if (frame->coding_type != I_VOP) |
745 : | BitstreamPutBits(bs, frame->rounding_type, 1); | ||
746 : | Isibaar | 3 | |
747 : | BitstreamPutBits(bs, 0, 3); // intra_dc_vlc_threshold | ||
748 : | |||
749 : | suxen_drol | 136 | if (frame->global_flags & XVID_INTERLACING) |
750 : | h | 69 | { |
751 : | BitstreamPutBit(bs, 1); // top field first | ||
752 : | BitstreamPutBit(bs, 0); // alternate vertical scan | ||
753 : | } | ||
754 : | |||
755 : | suxen_drol | 136 | BitstreamPutBits(bs, frame->quant, 5); // quantizer |
756 : | Isibaar | 3 | |
757 : | suxen_drol | 136 | if (frame->coding_type != I_VOP) |
758 : | suxen_drol | 152 | BitstreamPutBits(bs, frame->fcode, 3); // forward_fixed_code |
759 : | |||
760 : | if (frame->coding_type == B_VOP) | ||
761 : | BitstreamPutBits(bs, frame->bcode, 3); // backward_fixed_code | ||
762 : | |||
763 : | Isibaar | 3 | } |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |