[svn] / branches / dev-api-3 / xvidcore / src / bitstream / bitstream.c Repository:
ViewVC logotype

Annotation of /branches/dev-api-3/xvidcore/src/bitstream/bitstream.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 136 - (view) (download)
Original Path: trunk/xvidcore/src/bitstream/bitstream.c

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

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