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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

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