[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 20 - (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 20 uint8_t matrix[64];
337 : Isibaar 4 bs_get_matrix(bs, matrix);
338 :     set_intra_matrix(matrix);
339 : Isibaar 3 }
340 : Isibaar 20 else
341 :     set_intra_matrix(get_default_intra_matrix());
342 : Isibaar 4
343 : Isibaar 3 if (BitstreamGetBit(bs)) // load_inter_quant_mat
344 :     {
345 : Isibaar 20 uint8_t matrix[64];
346 : Isibaar 4 bs_get_matrix(bs, matrix);
347 :     set_inter_matrix(matrix);
348 : Isibaar 3 }
349 : Isibaar 20 else
350 :     set_inter_matrix(get_default_inter_matrix());
351 : Isibaar 3
352 :     if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE)
353 :     {
354 :     // TODO
355 :     DEBUG("TODO: grayscale matrix stuff");
356 :     return -1;
357 :     }
358 : Isibaar 4
359 : Isibaar 3 }
360 :    
361 :    
362 :     if (vol_ver_id != 1)
363 :     {
364 :     dec->quarterpel = BitstreamGetBit(bs); // quarter_sampe
365 :     if (dec->quarterpel)
366 :     {
367 :     DEBUG("IGNORED/TODO: quarter_sample");
368 :     }
369 :     }
370 :     else
371 :     {
372 :     dec->quarterpel = 0;
373 :     }
374 :    
375 :     if (!BitstreamGetBit(bs)) // complexity_estimation_disable
376 :     {
377 :     DEBUG("TODO: complexity_estimation header");
378 :     // TODO
379 :     return -1;
380 :     }
381 :    
382 :     if (!BitstreamGetBit(bs)) // resync_marker_disable
383 :     {
384 :     DEBUG("IGNORED/TODO: !resync_marker_disable");
385 :     // TODO
386 :     }
387 :    
388 :     if (BitstreamGetBit(bs)) // data_partitioned
389 :     {
390 :     DEBUG("+ data_partitioned");
391 :     BitstreamSkip(bs, 1); // reversible_vlc
392 :     }
393 :    
394 :     if (vol_ver_id != 1)
395 :     {
396 :     if (BitstreamGetBit(bs)) // newpred_enable
397 :     {
398 :     DEBUG("+ newpred_enable");
399 :     BitstreamSkip(bs, 2); // requested_upstream_message_type
400 :     BitstreamSkip(bs, 1); // newpred_segment_type
401 :     }
402 :     if (BitstreamGetBit(bs)) // reduced_resolution_vop_enable
403 :     {
404 :     DEBUG("TODO: reduced_resolution_vop_enable");
405 :     // TODO
406 :     return -1;
407 :     }
408 :     }
409 :    
410 :     if (BitstreamGetBit(bs)) // scalability
411 :     {
412 :     // TODO
413 :     DEBUG("TODO: scalability");
414 :     return -1;
415 :     }
416 :     }
417 :     else // dec->shape == BINARY_ONLY
418 :     {
419 :     if (vol_ver_id != 1)
420 :     {
421 :     if (BitstreamGetBit(bs)) // scalability
422 :     {
423 :     // TODO
424 :     DEBUG("TODO: scalability");
425 :     return -1;
426 :     }
427 :     }
428 :     BitstreamSkip(bs, 1); // resync_marker_disable
429 :    
430 :     }
431 :    
432 :     }
433 :     else if (start_code == GRPOFVOP_START_CODE)
434 :     {
435 :     // DEBUG("group_of_vop");
436 :     BitstreamSkip(bs, 32);
437 :     {
438 :     int hours, minutes, seconds;
439 :     hours = BitstreamGetBits(bs, 5);
440 :     minutes = BitstreamGetBits(bs, 6);
441 :     READ_MARKER();
442 :     seconds = BitstreamGetBits(bs, 6);
443 :     // DEBUG3("hms", hours, minutes, seconds);
444 :     }
445 :     BitstreamSkip(bs, 1); // closed_gov
446 :     BitstreamSkip(bs, 1); // broken_link
447 :     }
448 :     else if (start_code == VOP_START_CODE)
449 :     {
450 :     // DEBUG("vop_start_code");
451 :     BitstreamSkip(bs, 32); // vop_start_code
452 :    
453 :     coding_type = BitstreamGetBits(bs, 2); // vop_coding_type
454 :     //DEBUG1("coding_type", coding_type);
455 :    
456 :     while (BitstreamGetBit(bs) != 0) ; // time_base
457 :    
458 :     READ_MARKER();
459 :    
460 :     //DEBUG1("time_inc_bits", dec->time_inc_bits);
461 :     //DEBUG1("vop_time_incr", BitstreamShowBits(bs, dec->time_inc_bits));
462 :     if (dec->time_inc_bits)
463 :     {
464 :     BitstreamSkip(bs, dec->time_inc_bits); // vop_time_increment
465 :     }
466 :    
467 :     READ_MARKER();
468 :    
469 :     if (!BitstreamGetBit(bs)) // vop_coded
470 :     {
471 :     return N_VOP;
472 :     }
473 :    
474 :     /* if (newpred_enable)
475 :     {
476 :     }
477 :     */
478 :    
479 :     if (coding_type != I_VOP)
480 :     {
481 :     *rounding = BitstreamGetBit(bs); // rounding_type
482 :     //DEBUG1("rounding", *rounding);
483 :     }
484 :    
485 :     /* if (reduced_resolution_enable)
486 :     {
487 :     }
488 :     */
489 :    
490 :     if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR)
491 :     {
492 :     uint32_t width, height;
493 :     uint32_t horiz_mc_ref, vert_mc_ref;
494 :    
495 :     width = BitstreamGetBits(bs, 13);
496 :     READ_MARKER();
497 :     height = BitstreamGetBits(bs, 13);
498 :     READ_MARKER();
499 :     horiz_mc_ref = BitstreamGetBits(bs, 13);
500 :     READ_MARKER();
501 :     vert_mc_ref = BitstreamGetBits(bs, 13);
502 :     READ_MARKER();
503 :    
504 :     // DEBUG2("vop_width/height", width, height);
505 :     // DEBUG2("ref ", horiz_mc_ref, vert_mc_ref);
506 :    
507 :     BitstreamSkip(bs, 1); // change_conv_ratio_disable
508 :     if (BitstreamGetBit(bs)) // vop_constant_alpha
509 :     {
510 :     BitstreamSkip(bs, 8); // vop_constant_alpha_value
511 :     }
512 :     }
513 :    
514 :    
515 :     if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY)
516 :     {
517 :     // intra_dc_vlc_threshold
518 :     *intra_dc_threshold = intra_dc_threshold_table[ BitstreamGetBits(bs,3) ];
519 :    
520 :     /* if (interlaced)
521 :     {
522 :     BitstreamSkip(bs, 1); // top_field_first
523 :     BitstreamSkip(bs, 1); // alternative_vertical_scan_flag
524 :     */
525 :     }
526 :    
527 :     *quant = BitstreamGetBits(bs, dec->quant_bits); // vop_quant
528 :     //DEBUG1("quant", *quant);
529 :    
530 :     if (coding_type != I_VOP)
531 :     {
532 :     *fcode = BitstreamGetBits(bs, 3); // fcode_forward
533 :     }
534 :    
535 :     if (coding_type == B_VOP)
536 :     {
537 :     // *fcode_backward = BitstreamGetBits(bs, 3); // fcode_backward
538 :     }
539 :     return coding_type;
540 :     }
541 :     else if (start_code == USERDATA_START_CODE)
542 :     {
543 :     // DEBUG("user_data");
544 :     BitstreamSkip(bs, 32); // user_data_start_code
545 :     }
546 :     else // start_code == ?
547 :     {
548 :     if (BitstreamShowBits(bs, 24) == 0x000001)
549 :     {
550 :     DEBUG1("*** WARNING: unknown start_code", BitstreamShowBits(bs, 32));
551 :     }
552 :     BitstreamSkip(bs, 8);
553 :     }
554 :     }
555 :     while ((BitstreamPos(bs) >> 3) < bs->length);
556 :    
557 :     DEBUG("*** WARNING: no vop_start_code found");
558 :     return -1; /* ignore it */
559 :     }
560 :    
561 :    
562 :     /* write custom quant matrix */
563 :    
564 : Isibaar 4 static void bs_put_matrix(Bitstream * bs, const int16_t *matrix)
565 : Isibaar 3 {
566 :     int i, j;
567 :     const int last = matrix[scan_tables[0][63]];
568 :    
569 :     for (j = 63; j >= 0 && matrix[scan_tables[0][j - 1]] == last; j--) ;
570 :    
571 :     for (i = 0; i <= j; i++)
572 :     {
573 :     BitstreamPutBits(bs, matrix[scan_tables[0][i]], 8);
574 :     }
575 :    
576 :     if (j < 63)
577 :     {
578 :     BitstreamPutBits(bs, 0, 8);
579 :     }
580 :     }
581 :    
582 :    
583 :     /*
584 :     write vol header
585 :     */
586 :     void BitstreamWriteVolHeader(Bitstream * const bs,
587 :     const int width,
588 :     const int height,
589 :     const int quant_type)
590 :     {
591 :     // video object_start_code & vo_id
592 :     BitstreamPad(bs);
593 :     BitstreamPutBits(bs, VO_START_CODE, 27);
594 :     BitstreamPutBits(bs, 0, 5);
595 :    
596 :     // video_object_layer_start_code & vol_id
597 :     BitstreamPutBits(bs, VOL_START_CODE, 28);
598 :     BitstreamPutBits(bs, 0, 4);
599 :    
600 :     BitstreamPutBit(bs, 0); // random_accessible_vol
601 :     BitstreamPutBits(bs, 0, 8); // video_object_type_indication
602 :     BitstreamPutBit(bs, 0); // is_object_layer_identified (0=not given)
603 :     BitstreamPutBits(bs, 1, 4); // aspect_ratio_info (1=1:1)
604 :     BitstreamPutBit(bs, 0); // vol_control_parameters (0=not given)
605 :     BitstreamPutBits(bs, 0, 2); // video_object_layer_shape (0=rectangular)
606 :    
607 :     WRITE_MARKER();
608 :    
609 :     /* time_increment_resolution; ignored by current decore versions
610 :     eg. 2fps res=2 inc=1
611 :     25fps res=25 inc=1
612 :     29.97fps res=30000 inc=1001
613 :     */
614 :     BitstreamPutBits(bs, 2, 16);
615 :    
616 :     WRITE_MARKER();
617 :    
618 :     // fixed_vop_rate
619 :     BitstreamPutBit(bs, 0);
620 :    
621 :     // fixed_time_increment: value=nth_of_sec, nbits = log2(resolution)
622 :     // BitstreamPutBits(bs, 0, 15);
623 :    
624 :     WRITE_MARKER();
625 :     BitstreamPutBits(bs, width, 13); // width
626 :     WRITE_MARKER();
627 :     BitstreamPutBits(bs, height, 13); // height
628 :     WRITE_MARKER();
629 :    
630 :     BitstreamPutBit(bs, 0); // interlace
631 :     BitstreamPutBit(bs, 1); // obmc_disable (overlapped block motion compensation)
632 :     BitstreamPutBit(bs, 0); // sprite_enable
633 :     BitstreamPutBit(bs, 0); // not_in_bit
634 :    
635 :     // quant_type 0=h.263 1=mpeg4(quantizer tables)
636 :     BitstreamPutBit(bs, quant_type);
637 : Isibaar 4
638 : Isibaar 3 if (quant_type)
639 :     {
640 : Isibaar 4 BitstreamPutBit(bs, get_intra_matrix_status()); // load_intra_quant_mat
641 :     if (get_intra_matrix_status())
642 : Isibaar 3 {
643 : Isibaar 4 bs_put_matrix(bs, get_intra_matrix());
644 : Isibaar 3 }
645 :    
646 : Isibaar 4 BitstreamPutBit(bs, get_inter_matrix_status()); // load_inter_quant_mat
647 :     if (get_inter_matrix_status())
648 : Isibaar 3 {
649 : Isibaar 4 bs_put_matrix(bs, get_inter_matrix());
650 : Isibaar 3 }
651 :    
652 :     }
653 :    
654 :     BitstreamPutBit(bs, 1); // complexity_estimation_disable
655 :     BitstreamPutBit(bs, 1); // resync_marker_disable
656 :     BitstreamPutBit(bs, 0); // data_partitioned
657 :     BitstreamPutBit(bs, 0); // scalability
658 :     }
659 :    
660 :    
661 :     /*
662 :     write vop header
663 :    
664 :     NOTE: doesnt handle bother with time_base & time_inc
665 :     time_base = n seconds since last resync (eg. last iframe)
666 :     time_inc = nth of a second since last resync
667 :     (decoder uses these values to determine precise time since last resync)
668 :     */
669 :     void BitstreamWriteVopHeader(Bitstream * const bs,
670 :     VOP_TYPE prediction_type,
671 :     const int rounding_type,
672 :     const uint32_t quant,
673 :     const uint32_t fcode)
674 :     {
675 :     BitstreamPad(bs);
676 :     BitstreamPutBits(bs, VOP_START_CODE, 32);
677 :    
678 :     BitstreamPutBits(bs, prediction_type, 2);
679 :    
680 :     // time_base = 0 write n x PutBit(1), PutBit(0)
681 :     BitstreamPutBits(bs, 0, 1);
682 :    
683 :     WRITE_MARKER();
684 :    
685 :     // time_increment: value=nth_of_sec, nbits = log2(resolution)
686 :     BitstreamPutBits(bs, 1, 1);
687 :    
688 :     WRITE_MARKER();
689 :    
690 :     BitstreamPutBits(bs, 1, 1); // vop_coded
691 :    
692 :     if (prediction_type != I_VOP)
693 :     BitstreamPutBits(bs, rounding_type, 1);
694 :    
695 :     BitstreamPutBits(bs, 0, 3); // intra_dc_vlc_threshold
696 :    
697 :     BitstreamPutBits(bs, quant, 5); // quantizer
698 :    
699 :     if (prediction_type != I_VOP)
700 :     BitstreamPutBits(bs, fcode, 3); // fixed_code = [1,4]
701 :     }

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