[cvs] / xvidcore / src / bitstream / bitstream.c Repository:
ViewVC logotype

Annotation of /xvidcore/src/bitstream/bitstream.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (view) (download)

1 : Isibaar 1.1 /******************************************************************************
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 1.6 * *
44 : suxen_drol 1.8 * 01.05.2002 added BVOP support to BitstreamWriteVopHeader
45 : chenm001 1.6 * 15.04.2002 rewrite log2bin use asm386 By MinChen <chenm001@163.com> *
46 :     * 26.03.2002 interlacing support *
47 : Isibaar 1.1 * 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 1.2 #include "../quant/quant_matrix.h"
59 : Isibaar 1.1
60 : chenm001 1.6
61 : Isibaar 1.1 static int __inline log2bin(int value)
62 :     {
63 : chenm001 1.6 /* Changed by Chenm001 */
64 :     #ifndef WIN32
65 : Isibaar 1.1 int n = 0;
66 :     while (value)
67 :     {
68 :     value >>= 1;
69 :     n++;
70 :     }
71 :     return n;
72 : chenm001 1.6 #else
73 :     __asm{
74 :     bsr eax,value
75 :     inc eax
76 :     }
77 :     #endif
78 : Isibaar 1.1 }
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 1.2 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 1.1 /*
114 :     decode headers
115 :     returns coding_type, or -1 if error
116 :     */
117 :    
118 :     int BitstreamReadHeaders(Bitstream * bs, DECODER * dec, uint32_t * rounding, uint32_t * quant, uint32_t * fcode, uint32_t * intra_dc_threshold)
119 :     {
120 :     uint32_t vol_ver_id;
121 :     uint32_t time_inc_resolution;
122 :     uint32_t coding_type;
123 :     uint32_t start_code;
124 :    
125 :     do
126 :     {
127 :     BitstreamByteAlign(bs);
128 :     start_code = BitstreamShowBits(bs, 32);
129 :    
130 :     if (start_code == VISOBJSEQ_START_CODE)
131 :     {
132 :     // DEBUG("visual_object_sequence");
133 :     BitstreamSkip(bs, 32); // visual_object_sequence_start_code
134 :     BitstreamSkip(bs, 8); // profile_and_level_indication
135 :     }
136 :     else if (start_code == VISOBJSEQ_STOP_CODE)
137 :     {
138 :     BitstreamSkip(bs, 32); // visual_object_sequence_stop_code
139 :     }
140 :     else if (start_code == VISOBJ_START_CODE)
141 :     {
142 :     // DEBUG("visual_object");
143 :     BitstreamSkip(bs,32); // visual_object_start_code
144 :     if (BitstreamGetBit(bs)) // is_visual_object_identified
145 :     {
146 :     vol_ver_id = BitstreamGetBits(bs,4); // visual_object_ver_id
147 :     BitstreamSkip(bs, 3); // visual_object_priority
148 :     }
149 :     else
150 :     {
151 :     vol_ver_id = 1;
152 :     }
153 :    
154 :     if (BitstreamShowBits(bs, 4) != VISOBJ_TYPE_VIDEO) // visual_object_type
155 :     {
156 :     DEBUG("visual_object_type != video");
157 :     return -1;
158 :     }
159 :     BitstreamSkip(bs, 4);
160 :    
161 :     // video_signal_type
162 :    
163 :     if (BitstreamGetBit(bs)) // video_signal_type
164 :     {
165 :     DEBUG("+ video_signal_type");
166 :     BitstreamSkip(bs, 3); // video_format
167 :     BitstreamSkip(bs, 1); // video_range
168 :     if (BitstreamGetBit(bs)) // color_description
169 :     {
170 :     DEBUG("+ color_description");
171 :     BitstreamSkip(bs, 8); // color_primaries
172 :     BitstreamSkip(bs, 8); // transfer_characteristics
173 :     BitstreamSkip(bs, 8); // matrix_coefficients
174 :     }
175 :     }
176 :     }
177 :     else if ((start_code & ~0x1f) == VIDOBJ_START_CODE)
178 :     {
179 :     BitstreamSkip(bs, 32); // video_object_start_code
180 :     }
181 :     else if ((start_code & ~0xf) == VIDOBJLAY_START_CODE)
182 :     {
183 :     // DEBUG("video_object_layer");
184 :     BitstreamSkip(bs, 32); // video_object_layer_start_code
185 :    
186 :     BitstreamSkip(bs, 1); // random_accessible_vol
187 :    
188 :     // video_object_type_indication
189 :     if (BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_SIMPLE &&
190 :     BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_CORE &&
191 :     BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_MAIN &&
192 :     BitstreamShowBits(bs, 8) != 0) // BUGGY DIVX
193 :     {
194 :     DEBUG1("video_object_type_indication not supported", BitstreamShowBits(bs, 8));
195 :     return -1;
196 :     }
197 :     BitstreamSkip(bs, 8);
198 :    
199 :    
200 :     if (BitstreamGetBit(bs)) // is_object_layer_identifier
201 :     {
202 :     DEBUG("+ is_object_layer_identifier");
203 :     vol_ver_id = BitstreamGetBits(bs,4); // video_object_layer_verid
204 :     BitstreamSkip(bs, 3); // video_object_layer_priority
205 :     }
206 :     else
207 :     {
208 :     vol_ver_id = 1;
209 :     }
210 :     //DEBUGI("vol_ver_id", vol_ver_id);
211 :    
212 :     if (BitstreamGetBits(bs, 4) == VIDOBJLAY_AR_EXTPAR) // aspect_ratio_info
213 :     {
214 :     DEBUG("+ aspect_ratio_info");
215 :     BitstreamSkip(bs, 8); // par_width
216 :     BitstreamSkip(bs, 8); // par_height
217 :     }
218 :    
219 :     if (BitstreamGetBit(bs)) // vol_control_parameters
220 :     {
221 :     DEBUG("+ vol_control_parameters");
222 :     BitstreamSkip(bs, 2); // chroma_format
223 :     BitstreamSkip(bs, 1); // low_delay
224 :     if (BitstreamGetBit(bs)) // vbv_parameters
225 :     {
226 :     DEBUG("+ vbv_parameters");
227 :     BitstreamSkip(bs, 15); // first_half_bitrate
228 :     READ_MARKER();
229 :     BitstreamSkip(bs, 15); // latter_half_bitrate
230 :     READ_MARKER();
231 :     BitstreamSkip(bs, 15); // first_half_vbv_buffer_size
232 :     READ_MARKER();
233 :     BitstreamSkip(bs, 3); // latter_half_vbv_buffer_size
234 :     BitstreamSkip(bs, 11); // first_half_vbv_occupancy
235 :     READ_MARKER();
236 :     BitstreamSkip(bs, 15); // latter_half_vbv_occupancy
237 :     READ_MARKER();
238 :    
239 :     }
240 :     }
241 :    
242 :     dec->shape = BitstreamGetBits(bs, 2); // video_object_layer_shape
243 :     // DEBUG1("shape", dec->shape);
244 :    
245 :     if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE && vol_ver_id != 1)
246 :     {
247 :     BitstreamSkip(bs, 4); // video_object_layer_shape_extension
248 :     }
249 :    
250 :     READ_MARKER();
251 :    
252 :     time_inc_resolution = BitstreamGetBits(bs, 16); // vop_time_increment_resolution
253 :     time_inc_resolution--;
254 :     if (time_inc_resolution > 0)
255 :     {
256 :     dec->time_inc_bits = log2bin(time_inc_resolution);
257 :     }
258 :     else
259 :     {
260 :     // dec->time_inc_bits = 0;
261 :    
262 :     // for "old" xvid compatibility, set time_inc_bits = 1
263 :     dec->time_inc_bits = 1;
264 :     }
265 :    
266 :     READ_MARKER();
267 :    
268 :     if (BitstreamGetBit(bs)) // fixed_vop_rate
269 :     {
270 :     BitstreamSkip(bs, dec->time_inc_bits); // fixed_vop_time_increment
271 :     }
272 :    
273 :     if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY)
274 :     {
275 :    
276 :     if (dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR)
277 :     {
278 :     uint32_t width, height;
279 :    
280 :     READ_MARKER();
281 :     width = BitstreamGetBits(bs, 13); // video_object_layer_width
282 :     //DEBUGI("width", width);
283 :     READ_MARKER();
284 :     height = BitstreamGetBits(bs, 13); // video_object_layer_height
285 :     //DEBUGI("height", height);
286 :     READ_MARKER();
287 :    
288 :     if (width != dec->width || height != dec->height)
289 :     {
290 :     DEBUG("FATAL: video dimension discrepancy ***");
291 :     DEBUG2("bitstream width/height", width, height);
292 :     DEBUG2("param width/height", dec->width, dec->height);
293 :     return -1;
294 :     }
295 :    
296 :     }
297 : h 1.4
298 : canard 1.5 if ((dec->interlacing = BitstreamGetBit(bs)))
299 : Isibaar 1.1 {
300 : h 1.4 DEBUG("vol: interlacing");
301 : Isibaar 1.1 }
302 :    
303 :     if (!BitstreamGetBit(bs)) // obmc_disable
304 :     {
305 :     DEBUG("IGNORED/TODO: !obmc_disable");
306 :     // TODO
307 :     // fucking divx4.02 has this enabled
308 :     }
309 :    
310 :     if (BitstreamGetBits(bs, (vol_ver_id == 1 ? 1 : 2))) // sprite_enable
311 :     {
312 :     DEBUG("sprite_enable; not supported");
313 :     return -1;
314 :     }
315 :    
316 :     if (vol_ver_id != 1 && dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR)
317 :     {
318 :     BitstreamSkip(bs, 1); // sadct_disable
319 :     }
320 :    
321 :     if (BitstreamGetBit(bs)) // not_8_bit
322 :     {
323 :     DEBUG("+ not_8_bit [IGNORED/TODO]");
324 :     dec->quant_bits = BitstreamGetBits(bs, 4); // quant_precision
325 :     BitstreamSkip(bs, 4); // bits_per_pixel
326 :     }
327 :     else
328 :     {
329 :     dec->quant_bits = 5;
330 :     }
331 :    
332 :     if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE)
333 :     {
334 :     BitstreamSkip(bs, 1); // no_gray_quant_update
335 :     BitstreamSkip(bs, 1); // composition_method
336 :     BitstreamSkip(bs, 1); // linear_composition
337 :     }
338 :    
339 :     dec->quant_type = BitstreamGetBit(bs); // quant_type
340 :     // DEBUG1("**** quant_type", dec->quant_type);
341 :    
342 :     if (dec->quant_type)
343 :     {
344 :     if (BitstreamGetBit(bs)) // load_intra_quant_mat
345 :     {
346 : Isibaar 1.3 uint8_t matrix[64];
347 : Isibaar 1.2 bs_get_matrix(bs, matrix);
348 :     set_intra_matrix(matrix);
349 : Isibaar 1.1 }
350 : Isibaar 1.3 else
351 :     set_intra_matrix(get_default_intra_matrix());
352 : Isibaar 1.2
353 : Isibaar 1.1 if (BitstreamGetBit(bs)) // load_inter_quant_mat
354 :     {
355 : Isibaar 1.3 uint8_t matrix[64];
356 : Isibaar 1.2 bs_get_matrix(bs, matrix);
357 :     set_inter_matrix(matrix);
358 : Isibaar 1.1 }
359 : Isibaar 1.3 else
360 :     set_inter_matrix(get_default_inter_matrix());
361 : Isibaar 1.1
362 :     if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE)
363 :     {
364 :     // TODO
365 :     DEBUG("TODO: grayscale matrix stuff");
366 :     return -1;
367 :     }
368 : Isibaar 1.2
369 : Isibaar 1.1 }
370 :    
371 :    
372 :     if (vol_ver_id != 1)
373 :     {
374 :     dec->quarterpel = BitstreamGetBit(bs); // quarter_sampe
375 :     if (dec->quarterpel)
376 :     {
377 :     DEBUG("IGNORED/TODO: quarter_sample");
378 :     }
379 :     }
380 :     else
381 :     {
382 :     dec->quarterpel = 0;
383 :     }
384 :    
385 :     if (!BitstreamGetBit(bs)) // complexity_estimation_disable
386 :     {
387 :     DEBUG("TODO: complexity_estimation header");
388 :     // TODO
389 :     return -1;
390 :     }
391 :    
392 :     if (!BitstreamGetBit(bs)) // resync_marker_disable
393 :     {
394 :     DEBUG("IGNORED/TODO: !resync_marker_disable");
395 :     // TODO
396 :     }
397 :    
398 :     if (BitstreamGetBit(bs)) // data_partitioned
399 :     {
400 :     DEBUG("+ data_partitioned");
401 :     BitstreamSkip(bs, 1); // reversible_vlc
402 :     }
403 :    
404 :     if (vol_ver_id != 1)
405 :     {
406 :     if (BitstreamGetBit(bs)) // newpred_enable
407 :     {
408 :     DEBUG("+ newpred_enable");
409 :     BitstreamSkip(bs, 2); // requested_upstream_message_type
410 :     BitstreamSkip(bs, 1); // newpred_segment_type
411 :     }
412 :     if (BitstreamGetBit(bs)) // reduced_resolution_vop_enable
413 :     {
414 :     DEBUG("TODO: reduced_resolution_vop_enable");
415 :     // TODO
416 :     return -1;
417 :     }
418 :     }
419 :    
420 :     if (BitstreamGetBit(bs)) // scalability
421 :     {
422 :     // TODO
423 :     DEBUG("TODO: scalability");
424 :     return -1;
425 :     }
426 :     }
427 :     else // dec->shape == BINARY_ONLY
428 :     {
429 :     if (vol_ver_id != 1)
430 :     {
431 :     if (BitstreamGetBit(bs)) // scalability
432 :     {
433 :     // TODO
434 :     DEBUG("TODO: scalability");
435 :     return -1;
436 :     }
437 :     }
438 :     BitstreamSkip(bs, 1); // resync_marker_disable
439 :    
440 :     }
441 :    
442 :     }
443 :     else if (start_code == GRPOFVOP_START_CODE)
444 :     {
445 :     // DEBUG("group_of_vop");
446 :     BitstreamSkip(bs, 32);
447 :     {
448 :     int hours, minutes, seconds;
449 :     hours = BitstreamGetBits(bs, 5);
450 :     minutes = BitstreamGetBits(bs, 6);
451 :     READ_MARKER();
452 :     seconds = BitstreamGetBits(bs, 6);
453 :     // DEBUG3("hms", hours, minutes, seconds);
454 :     }
455 :     BitstreamSkip(bs, 1); // closed_gov
456 :     BitstreamSkip(bs, 1); // broken_link
457 :     }
458 :     else if (start_code == VOP_START_CODE)
459 :     {
460 :     // DEBUG("vop_start_code");
461 :     BitstreamSkip(bs, 32); // vop_start_code
462 :    
463 :     coding_type = BitstreamGetBits(bs, 2); // vop_coding_type
464 :     //DEBUG1("coding_type", coding_type);
465 :    
466 :     while (BitstreamGetBit(bs) != 0) ; // time_base
467 :    
468 :     READ_MARKER();
469 :    
470 :     //DEBUG1("time_inc_bits", dec->time_inc_bits);
471 :     //DEBUG1("vop_time_incr", BitstreamShowBits(bs, dec->time_inc_bits));
472 :     if (dec->time_inc_bits)
473 :     {
474 :     BitstreamSkip(bs, dec->time_inc_bits); // vop_time_increment
475 :     }
476 :    
477 :     READ_MARKER();
478 :    
479 :     if (!BitstreamGetBit(bs)) // vop_coded
480 :     {
481 :     return N_VOP;
482 :     }
483 :    
484 :     /* if (newpred_enable)
485 :     {
486 :     }
487 :     */
488 :    
489 :     if (coding_type != I_VOP)
490 :     {
491 :     *rounding = BitstreamGetBit(bs); // rounding_type
492 :     //DEBUG1("rounding", *rounding);
493 :     }
494 :    
495 :     /* if (reduced_resolution_enable)
496 :     {
497 :     }
498 :     */
499 :    
500 :     if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR)
501 :     {
502 :     uint32_t width, height;
503 :     uint32_t horiz_mc_ref, vert_mc_ref;
504 :    
505 :     width = BitstreamGetBits(bs, 13);
506 :     READ_MARKER();
507 :     height = BitstreamGetBits(bs, 13);
508 :     READ_MARKER();
509 :     horiz_mc_ref = BitstreamGetBits(bs, 13);
510 :     READ_MARKER();
511 :     vert_mc_ref = BitstreamGetBits(bs, 13);
512 :     READ_MARKER();
513 :    
514 :     // DEBUG2("vop_width/height", width, height);
515 :     // DEBUG2("ref ", horiz_mc_ref, vert_mc_ref);
516 :    
517 :     BitstreamSkip(bs, 1); // change_conv_ratio_disable
518 :     if (BitstreamGetBit(bs)) // vop_constant_alpha
519 :     {
520 :     BitstreamSkip(bs, 8); // vop_constant_alpha_value
521 :     }
522 :     }
523 :    
524 :    
525 :     if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY)
526 :     {
527 :     // intra_dc_vlc_threshold
528 :     *intra_dc_threshold = intra_dc_threshold_table[ BitstreamGetBits(bs,3) ];
529 :    
530 : h 1.4 if (dec->interlacing)
531 :     {
532 : canard 1.5 if ((dec->top_field_first = BitstreamGetBit(bs)))
533 : h 1.4 {
534 :     DEBUG("vop: top_field_first");
535 :     }
536 : canard 1.5 if ((dec->alternate_vertical_scan = BitstreamGetBit(bs)))
537 : Isibaar 1.1 {
538 : h 1.4 DEBUG("vop: alternate_vertical_scan");
539 :     }
540 :     }
541 : Isibaar 1.1 }
542 :    
543 :     *quant = BitstreamGetBits(bs, dec->quant_bits); // vop_quant
544 :     //DEBUG1("quant", *quant);
545 :    
546 :     if (coding_type != I_VOP)
547 :     {
548 :     *fcode = BitstreamGetBits(bs, 3); // fcode_forward
549 :     }
550 :    
551 :     if (coding_type == B_VOP)
552 :     {
553 :     // *fcode_backward = BitstreamGetBits(bs, 3); // fcode_backward
554 :     }
555 :     return coding_type;
556 :     }
557 :     else if (start_code == USERDATA_START_CODE)
558 :     {
559 :     // DEBUG("user_data");
560 :     BitstreamSkip(bs, 32); // user_data_start_code
561 :     }
562 :     else // start_code == ?
563 :     {
564 :     if (BitstreamShowBits(bs, 24) == 0x000001)
565 :     {
566 :     DEBUG1("*** WARNING: unknown start_code", BitstreamShowBits(bs, 32));
567 :     }
568 :     BitstreamSkip(bs, 8);
569 :     }
570 :     }
571 :     while ((BitstreamPos(bs) >> 3) < bs->length);
572 :    
573 :     DEBUG("*** WARNING: no vop_start_code found");
574 :     return -1; /* ignore it */
575 :     }
576 :    
577 :    
578 :     /* write custom quant matrix */
579 :    
580 : Isibaar 1.2 static void bs_put_matrix(Bitstream * bs, const int16_t *matrix)
581 : Isibaar 1.1 {
582 :     int i, j;
583 :     const int last = matrix[scan_tables[0][63]];
584 :    
585 :     for (j = 63; j >= 0 && matrix[scan_tables[0][j - 1]] == last; j--) ;
586 :    
587 :     for (i = 0; i <= j; i++)
588 :     {
589 :     BitstreamPutBits(bs, matrix[scan_tables[0][i]], 8);
590 :     }
591 :    
592 :     if (j < 63)
593 :     {
594 :     BitstreamPutBits(bs, 0, 8);
595 :     }
596 :     }
597 :    
598 :    
599 :     /*
600 :     write vol header
601 :     */
602 :     void BitstreamWriteVolHeader(Bitstream * const bs,
603 : suxen_drol 1.7 const MBParam * pParam, const FRAMEINFO * frame)
604 : Isibaar 1.1 {
605 :     // video object_start_code & vo_id
606 :     BitstreamPad(bs);
607 :     BitstreamPutBits(bs, VO_START_CODE, 27);
608 :     BitstreamPutBits(bs, 0, 5);
609 :    
610 :     // video_object_layer_start_code & vol_id
611 :     BitstreamPutBits(bs, VOL_START_CODE, 28);
612 :     BitstreamPutBits(bs, 0, 4);
613 :    
614 :     BitstreamPutBit(bs, 0); // random_accessible_vol
615 :     BitstreamPutBits(bs, 0, 8); // video_object_type_indication
616 :     BitstreamPutBit(bs, 0); // is_object_layer_identified (0=not given)
617 :     BitstreamPutBits(bs, 1, 4); // aspect_ratio_info (1=1:1)
618 :     BitstreamPutBit(bs, 0); // vol_control_parameters (0=not given)
619 :     BitstreamPutBits(bs, 0, 2); // video_object_layer_shape (0=rectangular)
620 :    
621 :     WRITE_MARKER();
622 :    
623 :     /* time_increment_resolution; ignored by current decore versions
624 :     eg. 2fps res=2 inc=1
625 :     25fps res=25 inc=1
626 :     29.97fps res=30000 inc=1001
627 :     */
628 :     BitstreamPutBits(bs, 2, 16);
629 :    
630 :     WRITE_MARKER();
631 :    
632 :     // fixed_vop_rate
633 :     BitstreamPutBit(bs, 0);
634 :    
635 :     // fixed_time_increment: value=nth_of_sec, nbits = log2(resolution)
636 :     // BitstreamPutBits(bs, 0, 15);
637 :    
638 :     WRITE_MARKER();
639 : h 1.4 BitstreamPutBits(bs, pParam->width, 13); // width
640 : Isibaar 1.1 WRITE_MARKER();
641 : h 1.4 BitstreamPutBits(bs, pParam->height, 13); // height
642 : Isibaar 1.1 WRITE_MARKER();
643 :    
644 : suxen_drol 1.7 BitstreamPutBit(bs, frame->global_flags & XVID_INTERLACING); // interlace
645 : Isibaar 1.1 BitstreamPutBit(bs, 1); // obmc_disable (overlapped block motion compensation)
646 :     BitstreamPutBit(bs, 0); // sprite_enable
647 :     BitstreamPutBit(bs, 0); // not_in_bit
648 :    
649 :     // quant_type 0=h.263 1=mpeg4(quantizer tables)
650 : suxen_drol 1.7 BitstreamPutBit(bs, pParam->m_quant_type);
651 : Isibaar 1.2
652 : suxen_drol 1.7 if (pParam->m_quant_type)
653 : Isibaar 1.1 {
654 : Isibaar 1.2 BitstreamPutBit(bs, get_intra_matrix_status()); // load_intra_quant_mat
655 :     if (get_intra_matrix_status())
656 : Isibaar 1.1 {
657 : Isibaar 1.2 bs_put_matrix(bs, get_intra_matrix());
658 : Isibaar 1.1 }
659 :    
660 : Isibaar 1.2 BitstreamPutBit(bs, get_inter_matrix_status()); // load_inter_quant_mat
661 :     if (get_inter_matrix_status())
662 : Isibaar 1.1 {
663 : Isibaar 1.2 bs_put_matrix(bs, get_inter_matrix());
664 : Isibaar 1.1 }
665 :    
666 :     }
667 :    
668 :     BitstreamPutBit(bs, 1); // complexity_estimation_disable
669 :     BitstreamPutBit(bs, 1); // resync_marker_disable
670 :     BitstreamPutBit(bs, 0); // data_partitioned
671 :     BitstreamPutBit(bs, 0); // scalability
672 :     }
673 :    
674 :    
675 :     /*
676 :     write vop header
677 :    
678 :     NOTE: doesnt handle bother with time_base & time_inc
679 :     time_base = n seconds since last resync (eg. last iframe)
680 :     time_inc = nth of a second since last resync
681 :     (decoder uses these values to determine precise time since last resync)
682 :     */
683 :     void BitstreamWriteVopHeader(Bitstream * const bs,
684 : suxen_drol 1.7 const MBParam * pParam,
685 :     const FRAMEINFO * frame)
686 : Isibaar 1.1 {
687 : suxen_drol 1.8 #ifdef BFRAMES
688 :     uint32_t i;
689 :     #endif
690 : Isibaar 1.1 BitstreamPad(bs);
691 :     BitstreamPutBits(bs, VOP_START_CODE, 32);
692 :    
693 : suxen_drol 1.7 BitstreamPutBits(bs, frame->coding_type, 2);
694 : Isibaar 1.1
695 :     // time_base = 0 write n x PutBit(1), PutBit(0)
696 : suxen_drol 1.8 #ifdef BFRAMES
697 :     for (i = 0; i < frame->seconds; i++)
698 :     {
699 :     BitstreamPutBit(bs, 1);
700 :     }
701 :     BitstreamPutBit(bs, 0);
702 :     #else
703 : Isibaar 1.1 BitstreamPutBits(bs, 0, 1);
704 : suxen_drol 1.8 #endif
705 : Isibaar 1.1
706 :     WRITE_MARKER();
707 :    
708 :     // time_increment: value=nth_of_sec, nbits = log2(resolution)
709 : suxen_drol 1.8 #ifdef BFRAMES
710 :     BitstreamPutBits(bs, frame->ticks, 5);
711 :     dprintf("[%i:%i] %c\n", frame->seconds, frame->ticks, frame->coding_type == I_VOP ? 'I' : frame->coding_type == P_VOP ? 'P' : 'B');
712 :     #else
713 : Isibaar 1.1 BitstreamPutBits(bs, 1, 1);
714 : suxen_drol 1.8 #endif
715 : Isibaar 1.1
716 :     WRITE_MARKER();
717 :    
718 :     BitstreamPutBits(bs, 1, 1); // vop_coded
719 :    
720 : suxen_drol 1.7 if (frame->coding_type != I_VOP)
721 :     BitstreamPutBits(bs, frame->rounding_type, 1);
722 : Isibaar 1.1
723 :     BitstreamPutBits(bs, 0, 3); // intra_dc_vlc_threshold
724 :    
725 : suxen_drol 1.7 if (frame->global_flags & XVID_INTERLACING)
726 : h 1.4 {
727 :     BitstreamPutBit(bs, 1); // top field first
728 :     BitstreamPutBit(bs, 0); // alternate vertical scan
729 :     }
730 :    
731 : suxen_drol 1.7 BitstreamPutBits(bs, frame->quant, 5); // quantizer
732 : Isibaar 1.1
733 : suxen_drol 1.7 if (frame->coding_type != I_VOP)
734 : suxen_drol 1.8 BitstreamPutBits(bs, frame->fcode, 3); // forward_fixed_code
735 :    
736 :     if (frame->coding_type == B_VOP)
737 :     BitstreamPutBits(bs, frame->bcode, 3); // backward_fixed_code
738 :    
739 : Isibaar 1.1 }

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4