Parent Directory
|
Revision Log
Revision 387 - (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 : | chenm001 | 223 | * * |
42 : | Isibaar | 3 | * Revision history: * |
43 : | chenm001 | 223 | * * |
44 : | chenm001 | 294 | * 11.07.2002 add VOP width & height return to dec when dec->width * |
45 : | * or dec->height is 0 (for use in examples/ex1.c) * | ||
46 : | * MinChen <chenm001@163.com> * | ||
47 : | * 22.05.2002 bs_put_matrix fix * | ||
48 : | suxen_drol | 229 | * 20.05.2002 added BitstreamWriteUserData * |
49 : | chenm001 | 223 | * 19.06.2002 Fix a little bug in use custom quant matrix * |
50 : | chenm001 | 168 | * MinChen <chenm001@163.com> * |
51 : | chenm001 | 223 | * 08.05.2002 add low_delay support for B_VOP decode * |
52 : | * MinChen <chenm001@163.com> * | ||
53 : | suxen_drol | 164 | * 06.05.2002 low_delay * |
54 : | suxen_drol | 163 | * 06.05.2002 fixed fincr/fbase error * |
55 : | * 01.05.2002 added BVOP support to BitstreamWriteVopHeader * | ||
56 : | chenm001 | 124 | * 15.04.2002 rewrite log2bin use asm386 By MinChen <chenm001@163.com> * |
57 : | chenm001 | 223 | * 26.03.2002 interlacing support * |
58 : | * 03.03.2002 qmatrix writing * | ||
59 : | * 03.03.2002 merged BITREADER and BITWRITER * | ||
60 : | * 30.02.2002 intra_dc_threshold support * | ||
61 : | * 04.12.2001 support for additional headers * | ||
62 : | * 16.12.2001 inital version * | ||
63 : | * | ||
64 : | Isibaar | 3 | ******************************************************************************/ |
65 : | |||
66 : | |||
67 : | #include "bitstream.h" | ||
68 : | #include "zigzag.h" | ||
69 : | Isibaar | 4 | #include "../quant/quant_matrix.h" |
70 : | Isibaar | 3 | |
71 : | chenm001 | 124 | |
72 : | edgomez | 195 | static uint32_t __inline |
73 : | log2bin(uint32_t value) | ||
74 : | Isibaar | 3 | { |
75 : | chenm001 | 124 | /* Changed by Chenm001 */ |
76 : | #ifndef WIN32 | ||
77 : | Isibaar | 3 | int n = 0; |
78 : | edgomez | 195 | |
79 : | while (value) { | ||
80 : | Isibaar | 3 | value >>= 1; |
81 : | n++; | ||
82 : | } | ||
83 : | return n; | ||
84 : | chenm001 | 124 | #else |
85 : | edgomez | 195 | __asm { |
86 : | suxen_drol | 206 | bsr eax, value |
87 : | inc eax | ||
88 : | } | ||
89 : | chenm001 | 124 | #endif |
90 : | Isibaar | 3 | } |
91 : | |||
92 : | |||
93 : | edgomez | 195 | static const uint32_t intra_dc_threshold_table[] = { |
94 : | 32, /* never use */ | ||
95 : | Isibaar | 3 | 13, |
96 : | 15, | ||
97 : | 17, | ||
98 : | 19, | ||
99 : | 21, | ||
100 : | 23, | ||
101 : | 1, | ||
102 : | }; | ||
103 : | |||
104 : | |||
105 : | edgomez | 195 | void |
106 : | bs_get_matrix(Bitstream * bs, | ||
107 : | uint8_t * matrix) | ||
108 : | { | ||
109 : | int i = 0; | ||
110 : | int last, value = 0; | ||
111 : | Isibaar | 4 | |
112 : | edgomez | 195 | do { |
113 : | last = value; | ||
114 : | value = BitstreamGetBits(bs, 8); | ||
115 : | matrix[scan_tables[0][i++]] = value; | ||
116 : | } | ||
117 : | while (value != 0 && i < 64); | ||
118 : | chenm001 | 223 | i--; // fix little bug at coeff not full |
119 : | edgomez | 195 | |
120 : | while (i < 64) { | ||
121 : | matrix[scan_tables[0][i++]] = last; | ||
122 : | } | ||
123 : | } | ||
124 : | |||
125 : | suxen_drol | 248 | |
126 : | |||
127 : | // for PVOP addbits == fcode - 1 | ||
128 : | // for BVOP addbits == max(fcode,bcode) - 1 | ||
129 : | // returns mbpos | ||
130 : | int | ||
131 : | suxen_drol | 252 | read_video_packet_header(Bitstream *bs, const int addbits, int * quant) |
132 : | suxen_drol | 248 | { |
133 : | int nbits; | ||
134 : | int mbnum; | ||
135 : | int hec; | ||
136 : | |||
137 : | suxen_drol | 252 | nbits = NUMBITS_VP_RESYNC_MARKER + addbits; |
138 : | suxen_drol | 248 | |
139 : | BitstreamSkip(bs, BitstreamNumBitsToByteAlign(bs)); | ||
140 : | BitstreamSkip(bs, nbits); | ||
141 : | |||
142 : | suxen_drol | 252 | DPRINTF(DPRINTF_STARTCODE, "<video_packet_header>"); |
143 : | |||
144 : | suxen_drol | 248 | // if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) { |
145 : | // hec | ||
146 : | // vop_width | ||
147 : | // marker_bit | ||
148 : | // vop_height | ||
149 : | // marker_bit | ||
150 : | |||
151 : | //} | ||
152 : | |||
153 : | mbnum = BitstreamGetBits(bs, 9); | ||
154 : | suxen_drol | 252 | DPRINTF(DPRINTF_HEADER, "mbnum %i", mbnum); |
155 : | suxen_drol | 248 | |
156 : | // if (dec->shape != VIDOBJLAY_SHAPE_BINARYONLY) | ||
157 : | suxen_drol | 252 | *quant = BitstreamGetBits(bs, 5); |
158 : | DPRINTF(DPRINTF_HEADER, "quant %i", *quant); | ||
159 : | suxen_drol | 248 | |
160 : | // if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) | ||
161 : | hec = BitstreamGetBit(bs); | ||
162 : | suxen_drol | 252 | DPRINTF(DPRINTF_HEADER, "header_extension_code %i", hec); |
163 : | suxen_drol | 248 | // if (hec) |
164 : | // .. decoder hec-header ... | ||
165 : | |||
166 : | return mbnum; | ||
167 : | } | ||
168 : | |||
169 : | |||
170 : | |||
171 : | Isibaar | 3 | /* |
172 : | decode headers | ||
173 : | returns coding_type, or -1 if error | ||
174 : | */ | ||
175 : | |||
176 : | suxen_drol | 252 | #define VIDOBJ_START_CODE_MASK 0x0000001f |
177 : | #define VIDOBJLAY_START_CODE_MASK 0x0000000f | ||
178 : | |||
179 : | edgomez | 195 | int |
180 : | BitstreamReadHeaders(Bitstream * bs, | ||
181 : | DECODER * dec, | ||
182 : | uint32_t * rounding, | ||
183 : | uint32_t * quant, | ||
184 : | uint32_t * fcode_forward, | ||
185 : | uint32_t * fcode_backward, | ||
186 : | uint32_t * intra_dc_threshold) | ||
187 : | Isibaar | 3 | { |
188 : | uint32_t vol_ver_id; | ||
189 : | chenm001 | 156 | static uint32_t time_increment_resolution; |
190 : | Isibaar | 3 | uint32_t coding_type; |
191 : | uint32_t start_code; | ||
192 : | edgomez | 195 | uint32_t time_incr = 0; |
193 : | int32_t time_increment; | ||
194 : | chenm001 | 156 | |
195 : | edgomez | 195 | do { |
196 : | Isibaar | 3 | BitstreamByteAlign(bs); |
197 : | start_code = BitstreamShowBits(bs, 32); | ||
198 : | |||
199 : | edgomez | 195 | if (start_code == VISOBJSEQ_START_CODE) { |
200 : | suxen_drol | 252 | |
201 : | int profile; | ||
202 : | |||
203 : | DPRINTF(DPRINTF_STARTCODE, "<visual_object_sequence>"); | ||
204 : | |||
205 : | edgomez | 195 | BitstreamSkip(bs, 32); // visual_object_sequence_start_code |
206 : | suxen_drol | 252 | profile = BitstreamGetBits(bs, 8); // profile_and_level_indication |
207 : | |||
208 : | DPRINTF(DPRINTF_HEADER, "profile_and_level_indication %i", profile); | ||
209 : | |||
210 : | edgomez | 195 | } else if (start_code == VISOBJSEQ_STOP_CODE) { |
211 : | suxen_drol | 252 | |
212 : | edgomez | 195 | BitstreamSkip(bs, 32); // visual_object_sequence_stop_code |
213 : | suxen_drol | 252 | |
214 : | DPRINTF(DPRINTF_STARTCODE, "</visual_object_sequence>"); | ||
215 : | |||
216 : | edgomez | 195 | } else if (start_code == VISOBJ_START_CODE) { |
217 : | suxen_drol | 252 | |
218 : | DPRINTF(DPRINTF_STARTCODE, "<visual_object>"); | ||
219 : | |||
220 : | edgomez | 195 | BitstreamSkip(bs, 32); // visual_object_start_code |
221 : | if (BitstreamGetBit(bs)) // is_visual_object_identified | ||
222 : | Isibaar | 3 | { |
223 : | edgomez | 195 | vol_ver_id = BitstreamGetBits(bs, 4); // visual_object_ver_id |
224 : | suxen_drol | 252 | DPRINTF(DPRINTF_HEADER,"ver_id %i", vol_ver_id); |
225 : | edgomez | 195 | BitstreamSkip(bs, 3); // visual_object_priority |
226 : | } else { | ||
227 : | Isibaar | 3 | vol_ver_id = 1; |
228 : | } | ||
229 : | |||
230 : | if (BitstreamShowBits(bs, 4) != VISOBJ_TYPE_VIDEO) // visual_object_type | ||
231 : | { | ||
232 : | suxen_drol | 252 | DPRINTF(DPRINTF_ERROR, "visual_object_type != video"); |
233 : | Isibaar | 3 | return -1; |
234 : | } | ||
235 : | BitstreamSkip(bs, 4); | ||
236 : | |||
237 : | // video_signal_type | ||
238 : | |||
239 : | edgomez | 195 | if (BitstreamGetBit(bs)) // video_signal_type |
240 : | Isibaar | 3 | { |
241 : | suxen_drol | 252 | DPRINTF(DPRINTF_HEADER,"+ video_signal_type"); |
242 : | edgomez | 195 | BitstreamSkip(bs, 3); // video_format |
243 : | BitstreamSkip(bs, 1); // video_range | ||
244 : | if (BitstreamGetBit(bs)) // color_description | ||
245 : | Isibaar | 3 | { |
246 : | suxen_drol | 252 | DPRINTF(DPRINTF_HEADER,"+ color_description"); |
247 : | edgomez | 195 | BitstreamSkip(bs, 8); // color_primaries |
248 : | BitstreamSkip(bs, 8); // transfer_characteristics | ||
249 : | BitstreamSkip(bs, 8); // matrix_coefficients | ||
250 : | Isibaar | 3 | } |
251 : | } | ||
252 : | suxen_drol | 252 | } else if ((start_code & ~VIDOBJ_START_CODE_MASK) == VIDOBJ_START_CODE) { |
253 : | |||
254 : | DPRINTF(DPRINTF_STARTCODE, "<video_object>"); | ||
255 : | DPRINTF(DPRINTF_HEADER, "vo id %i", start_code & VIDOBJ_START_CODE_MASK); | ||
256 : | |||
257 : | edgomez | 195 | BitstreamSkip(bs, 32); // video_object_start_code |
258 : | suxen_drol | 252 | |
259 : | } else if ((start_code & ~VIDOBJLAY_START_CODE_MASK) == VIDOBJLAY_START_CODE) { | ||
260 : | |||
261 : | DPRINTF(DPRINTF_STARTCODE, "<video_object_layer>"); | ||
262 : | DPRINTF(DPRINTF_HEADER, "vol id %i", start_code & VIDOBJLAY_START_CODE_MASK); | ||
263 : | |||
264 : | edgomez | 195 | BitstreamSkip(bs, 32); // video_object_layer_start_code |
265 : | Isibaar | 3 | |
266 : | edgomez | 195 | BitstreamSkip(bs, 1); // random_accessible_vol |
267 : | Isibaar | 3 | |
268 : | // video_object_type_indication | ||
269 : | edgomez | 195 | if (BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_SIMPLE && BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_CORE && BitstreamShowBits(bs, 8) != VIDOBJLAY_TYPE_MAIN && BitstreamShowBits(bs, 8) != 0) // BUGGY DIVX |
270 : | Isibaar | 3 | { |
271 : | suxen_drol | 252 | DPRINTF(DPRINTF_ERROR,"video_object_type_indication %i not supported ", |
272 : | BitstreamShowBits(bs, 8)); | ||
273 : | Isibaar | 3 | return -1; |
274 : | } | ||
275 : | BitstreamSkip(bs, 8); | ||
276 : | |||
277 : | |||
278 : | edgomez | 195 | if (BitstreamGetBit(bs)) // is_object_layer_identifier |
279 : | Isibaar | 3 | { |
280 : | suxen_drol | 252 | DPRINTF(DPRINTF_HEADER, "+ is_object_layer_identifier"); |
281 : | edgomez | 195 | vol_ver_id = BitstreamGetBits(bs, 4); // video_object_layer_verid |
282 : | suxen_drol | 252 | DPRINTF(DPRINTF_HEADER,"ver_id %i", vol_ver_id); |
283 : | edgomez | 195 | BitstreamSkip(bs, 3); // video_object_layer_priority |
284 : | } else { | ||
285 : | Isibaar | 3 | vol_ver_id = 1; |
286 : | } | ||
287 : | |||
288 : | if (BitstreamGetBits(bs, 4) == VIDOBJLAY_AR_EXTPAR) // aspect_ratio_info | ||
289 : | { | ||
290 : | suxen_drol | 252 | DPRINTF(DPRINTF_HEADER, "+ aspect_ratio_info"); |
291 : | edgomez | 195 | BitstreamSkip(bs, 8); // par_width |
292 : | BitstreamSkip(bs, 8); // par_height | ||
293 : | Isibaar | 3 | } |
294 : | |||
295 : | edgomez | 195 | if (BitstreamGetBit(bs)) // vol_control_parameters |
296 : | Isibaar | 3 | { |
297 : | suxen_drol | 252 | DPRINTF(DPRINTF_HEADER, "+ vol_control_parameters"); |
298 : | edgomez | 195 | BitstreamSkip(bs, 2); // chroma_format |
299 : | dec->low_delay = BitstreamGetBit(bs); // low_delay | ||
300 : | suxen_drol | 252 | DPRINTF(DPRINTF_HEADER, "low_delay %i", dec->low_delay); |
301 : | edgomez | 195 | if (BitstreamGetBit(bs)) // vbv_parameters |
302 : | Isibaar | 3 | { |
303 : | suxen_drol | 252 | DPRINTF(DPRINTF_HEADER,"+ vbv_parameters"); |
304 : | edgomez | 195 | BitstreamSkip(bs, 15); // first_half_bitrate |
305 : | Isibaar | 3 | READ_MARKER(); |
306 : | edgomez | 195 | BitstreamSkip(bs, 15); // latter_half_bitrate |
307 : | Isibaar | 3 | READ_MARKER(); |
308 : | edgomez | 195 | BitstreamSkip(bs, 15); // first_half_vbv_buffer_size |
309 : | Isibaar | 3 | READ_MARKER(); |
310 : | edgomez | 195 | BitstreamSkip(bs, 3); // latter_half_vbv_buffer_size |
311 : | BitstreamSkip(bs, 11); // first_half_vbv_occupancy | ||
312 : | Isibaar | 3 | READ_MARKER(); |
313 : | edgomez | 195 | BitstreamSkip(bs, 15); // latter_half_vbv_occupancy |
314 : | Isibaar | 3 | READ_MARKER(); |
315 : | edgomez | 195 | |
316 : | Isibaar | 3 | } |
317 : | } | ||
318 : | |||
319 : | dec->shape = BitstreamGetBits(bs, 2); // video_object_layer_shape | ||
320 : | suxen_drol | 252 | DPRINTF(DPRINTF_HEADER, "shape %i", dec->shape); |
321 : | edgomez | 195 | |
322 : | if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE && vol_ver_id != 1) { | ||
323 : | BitstreamSkip(bs, 4); // video_object_layer_shape_extension | ||
324 : | Isibaar | 3 | } |
325 : | |||
326 : | READ_MARKER(); | ||
327 : | |||
328 : | chenm001 | 156 | // *************************** for decode B-frame time *********************** |
329 : | time_increment_resolution = BitstreamGetBits(bs, 16); // vop_time_increment_resolution | ||
330 : | suxen_drol | 252 | |
331 : | DPRINTF(DPRINTF_HEADER,"vop_time_increment_resolution %i", time_increment_resolution); | ||
332 : | |||
333 : | chl | 313 | // time_increment_resolution--; |
334 : | suxen_drol | 252 | |
335 : | edgomez | 195 | if (time_increment_resolution > 0) { |
336 : | chl | 313 | dec->time_inc_bits = log2bin(time_increment_resolution-1); |
337 : | edgomez | 195 | } else { |
338 : | Isibaar | 3 | // dec->time_inc_bits = 0; |
339 : | // for "old" xvid compatibility, set time_inc_bits = 1 | ||
340 : | dec->time_inc_bits = 1; | ||
341 : | } | ||
342 : | |||
343 : | READ_MARKER(); | ||
344 : | |||
345 : | edgomez | 195 | if (BitstreamGetBit(bs)) // fixed_vop_rate |
346 : | Isibaar | 3 | { |
347 : | suxen_drol | 252 | DPRINTF(DPRINTF_HEADER, "+ fixed_vop_rate"); |
348 : | Isibaar | 3 | BitstreamSkip(bs, dec->time_inc_bits); // fixed_vop_time_increment |
349 : | } | ||
350 : | |||
351 : | edgomez | 195 | if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) { |
352 : | Isibaar | 3 | |
353 : | edgomez | 195 | if (dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR) { |
354 : | Isibaar | 3 | uint32_t width, height; |
355 : | |||
356 : | READ_MARKER(); | ||
357 : | edgomez | 195 | width = BitstreamGetBits(bs, 13); // video_object_layer_width |
358 : | Isibaar | 3 | READ_MARKER(); |
359 : | edgomez | 195 | height = BitstreamGetBits(bs, 13); // video_object_layer_height |
360 : | Isibaar | 3 | READ_MARKER(); |
361 : | |||
362 : | suxen_drol | 252 | DPRINTF(DPRINTF_HEADER, "width %i", width); |
363 : | DPRINTF(DPRINTF_HEADER, "height %i", height); | ||
364 : | |||
365 : | chenm001 | 294 | // for auto set width & height |
366 : | if (dec->width == 0) | ||
367 : | dec->width = width; | ||
368 : | if (dec->height == 0) | ||
369 : | dec->height = height; | ||
370 : | |||
371 : | edgomez | 195 | if (width != dec->width || height != dec->height) { |
372 : | suxen_drol | 252 | DPRINTF(DPRINTF_ERROR, "XVID_DEC_PARAM width/height does not match bitstream"); |
373 : | Isibaar | 3 | return -1; |
374 : | } | ||
375 : | |||
376 : | } | ||
377 : | h | 69 | |
378 : | suxen_drol | 252 | dec->interlacing = BitstreamGetBit(bs); |
379 : | DPRINTF(DPRINTF_HEADER, "interlace", dec->interlacing); | ||
380 : | Isibaar | 3 | |
381 : | edgomez | 195 | if (!BitstreamGetBit(bs)) // obmc_disable |
382 : | Isibaar | 3 | { |
383 : | suxen_drol | 252 | DPRINTF(DPRINTF_ERROR, "obmc_disabled==false not supported"); |
384 : | Isibaar | 3 | // TODO |
385 : | // fucking divx4.02 has this enabled | ||
386 : | } | ||
387 : | |||
388 : | edgomez | 195 | if (BitstreamGetBits(bs, (vol_ver_id == 1 ? 1 : 2))) // sprite_enable |
389 : | Isibaar | 3 | { |
390 : | suxen_drol | 252 | DPRINTF(DPRINTF_ERROR, "spriate_enabled not supported"); |
391 : | Isibaar | 3 | return -1; |
392 : | } | ||
393 : | edgomez | 195 | |
394 : | if (vol_ver_id != 1 && | ||
395 : | dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) { | ||
396 : | BitstreamSkip(bs, 1); // sadct_disable | ||
397 : | Isibaar | 3 | } |
398 : | |||
399 : | edgomez | 195 | if (BitstreamGetBit(bs)) // not_8_bit |
400 : | Isibaar | 3 | { |
401 : | suxen_drol | 252 | DPRINTF(DPRINTF_HEADER, "not_8_bit==true (ignored)"); |
402 : | Isibaar | 3 | dec->quant_bits = BitstreamGetBits(bs, 4); // quant_precision |
403 : | edgomez | 195 | BitstreamSkip(bs, 4); // bits_per_pixel |
404 : | } else { | ||
405 : | Isibaar | 3 | dec->quant_bits = 5; |
406 : | } | ||
407 : | |||
408 : | edgomez | 195 | if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) { |
409 : | BitstreamSkip(bs, 1); // no_gray_quant_update | ||
410 : | BitstreamSkip(bs, 1); // composition_method | ||
411 : | BitstreamSkip(bs, 1); // linear_composition | ||
412 : | Isibaar | 3 | } |
413 : | |||
414 : | edgomez | 195 | dec->quant_type = BitstreamGetBit(bs); // quant_type |
415 : | suxen_drol | 252 | DPRINTF(DPRINTF_HEADER, "quant_type %i", dec->quant_type); |
416 : | Isibaar | 3 | |
417 : | edgomez | 195 | if (dec->quant_type) { |
418 : | if (BitstreamGetBit(bs)) // load_intra_quant_mat | ||
419 : | Isibaar | 3 | { |
420 : | Isibaar | 20 | uint8_t matrix[64]; |
421 : | edgomez | 195 | |
422 : | suxen_drol | 252 | DPRINTF(DPRINTF_HEADER, "load_intra_quant_mat"); |
423 : | |||
424 : | Isibaar | 4 | bs_get_matrix(bs, matrix); |
425 : | set_intra_matrix(matrix); | ||
426 : | edgomez | 195 | } else |
427 : | Isibaar | 20 | set_intra_matrix(get_default_intra_matrix()); |
428 : | Isibaar | 4 | |
429 : | edgomez | 195 | if (BitstreamGetBit(bs)) // load_inter_quant_mat |
430 : | Isibaar | 3 | { |
431 : | edgomez | 195 | uint8_t matrix[64]; |
432 : | suxen_drol | 252 | |
433 : | DPRINTF(DPRINTF_HEADER, "load_inter_quant_mat"); | ||
434 : | edgomez | 195 | |
435 : | Isibaar | 4 | bs_get_matrix(bs, matrix); |
436 : | set_inter_matrix(matrix); | ||
437 : | edgomez | 195 | } else |
438 : | Isibaar | 20 | set_inter_matrix(get_default_inter_matrix()); |
439 : | Isibaar | 3 | |
440 : | edgomez | 195 | if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) { |
441 : | suxen_drol | 252 | DPRINTF(DPRINTF_ERROR, "greyscale matrix not supported"); |
442 : | Isibaar | 3 | return -1; |
443 : | } | ||
444 : | Isibaar | 4 | |
445 : | Isibaar | 3 | } |
446 : | |||
447 : | edgomez | 195 | |
448 : | if (vol_ver_id != 1) { | ||
449 : | Isibaar | 333 | DEBUG("QUARTERPEL BITSTREAM"); |
450 : | dec->quarterpel = BitstreamGetBit(bs); // quarter_sample | ||
451 : | Isibaar | 3 | } |
452 : | Isibaar | 333 | else |
453 : | dec->quarterpel = 0; | ||
454 : | |||
455 : | Isibaar | 3 | |
456 : | edgomez | 195 | if (!BitstreamGetBit(bs)) // complexity_estimation_disable |
457 : | Isibaar | 3 | { |
458 : | suxen_drol | 252 | DPRINTF(DPRINTF_ERROR, "complexity_estimation not supported"); |
459 : | Isibaar | 3 | return -1; |
460 : | } | ||
461 : | |||
462 : | suxen_drol | 252 | BitstreamSkip(bs, 1); // resync_marker_disable |
463 : | Isibaar | 3 | |
464 : | edgomez | 195 | if (BitstreamGetBit(bs)) // data_partitioned |
465 : | Isibaar | 3 | { |
466 : | suxen_drol | 252 | DPRINTF(DPRINTF_ERROR, "data_partitioned not supported"); |
467 : | edgomez | 195 | BitstreamSkip(bs, 1); // reversible_vlc |
468 : | Isibaar | 3 | } |
469 : | |||
470 : | edgomez | 195 | if (vol_ver_id != 1) { |
471 : | if (BitstreamGetBit(bs)) // newpred_enable | ||
472 : | Isibaar | 3 | { |
473 : | suxen_drol | 252 | DPRINTF(DPRINTF_HEADER, "+ newpred_enable"); |
474 : | edgomez | 195 | BitstreamSkip(bs, 2); // requested_upstream_message_type |
475 : | BitstreamSkip(bs, 1); // newpred_segment_type | ||
476 : | Isibaar | 3 | } |
477 : | edgomez | 195 | if (BitstreamGetBit(bs)) // reduced_resolution_vop_enable |
478 : | Isibaar | 3 | { |
479 : | suxen_drol | 252 | DPRINTF(DPRINTF_ERROR, "reduced_resolution_vop not supported"); |
480 : | Isibaar | 3 | return -1; |
481 : | } | ||
482 : | } | ||
483 : | edgomez | 195 | |
484 : | if ((dec->scalability = BitstreamGetBit(bs))) // scalability | ||
485 : | Isibaar | 3 | { |
486 : | suxen_drol | 252 | DPRINTF(DPRINTF_ERROR, "scalability not supported"); |
487 : | Isibaar | 3 | return -1; |
488 : | } | ||
489 : | edgomez | 195 | } else // dec->shape == BINARY_ONLY |
490 : | Isibaar | 3 | { |
491 : | edgomez | 195 | if (vol_ver_id != 1) { |
492 : | Isibaar | 3 | if (BitstreamGetBit(bs)) // scalability |
493 : | { | ||
494 : | suxen_drol | 252 | DPRINTF(DPRINTF_ERROR, "scalability not supported"); |
495 : | Isibaar | 3 | return -1; |
496 : | } | ||
497 : | } | ||
498 : | edgomez | 195 | BitstreamSkip(bs, 1); // resync_marker_disable |
499 : | Isibaar | 3 | |
500 : | } | ||
501 : | |||
502 : | edgomez | 195 | } else if (start_code == GRPOFVOP_START_CODE) { |
503 : | suxen_drol | 252 | |
504 : | DPRINTF(DPRINTF_STARTCODE, "<group_of_vop>"); | ||
505 : | |||
506 : | Isibaar | 3 | BitstreamSkip(bs, 32); |
507 : | { | ||
508 : | int hours, minutes, seconds; | ||
509 : | edgomez | 195 | |
510 : | Isibaar | 3 | hours = BitstreamGetBits(bs, 5); |
511 : | minutes = BitstreamGetBits(bs, 6); | ||
512 : | READ_MARKER(); | ||
513 : | seconds = BitstreamGetBits(bs, 6); | ||
514 : | suxen_drol | 252 | |
515 : | DPRINTF(DPRINTF_HEADER, "time %ih%im%is", hours); | ||
516 : | Isibaar | 3 | } |
517 : | edgomez | 195 | BitstreamSkip(bs, 1); // closed_gov |
518 : | BitstreamSkip(bs, 1); // broken_link | ||
519 : | suxen_drol | 252 | |
520 : | edgomez | 195 | } else if (start_code == VOP_START_CODE) { |
521 : | suxen_drol | 252 | |
522 : | DPRINTF(DPRINTF_STARTCODE, "<vop>"); | ||
523 : | |||
524 : | edgomez | 195 | BitstreamSkip(bs, 32); // vop_start_code |
525 : | Isibaar | 3 | |
526 : | edgomez | 195 | coding_type = BitstreamGetBits(bs, 2); // vop_coding_type |
527 : | suxen_drol | 252 | DPRINTF(DPRINTF_HEADER, "coding_type %i", coding_type); |
528 : | Isibaar | 3 | |
529 : | chenm001 | 156 | // *************************** for decode B-frame time *********************** |
530 : | edgomez | 195 | while (BitstreamGetBit(bs) != 0) // time_base |
531 : | chenm001 | 156 | time_incr++; |
532 : | edgomez | 195 | |
533 : | Isibaar | 3 | READ_MARKER(); |
534 : | edgomez | 195 | |
535 : | if (dec->time_inc_bits) { | ||
536 : | chenm001 | 156 | time_increment = (BitstreamGetBits(bs, dec->time_inc_bits)); // vop_time_increment |
537 : | Isibaar | 3 | } |
538 : | suxen_drol | 240 | |
539 : | suxen_drol | 252 | DPRINTF(DPRINTF_HEADER, "time_base %i", time_incr); |
540 : | DPRINTF(DPRINTF_HEADER, "time_increment %i", time_increment); | ||
541 : | |||
542 : | DPRINTF(DPRINTF_TIMECODE, "%c %i:%i", | ||
543 : | suxen_drol | 240 | coding_type == I_VOP ? 'I' : coding_type == P_VOP ? 'P' : 'B', |
544 : | time_incr, time_increment); | ||
545 : | |||
546 : | edgomez | 195 | if (coding_type != B_VOP) { |
547 : | dec->last_time_base = dec->time_base; | ||
548 : | chenm001 | 156 | dec->time_base += time_incr; |
549 : | chl | 316 | dec->time = time_increment; |
550 : | |||
551 : | /* dec->time_base * time_increment_resolution + | ||
552 : | edgomez | 195 | time_increment; |
553 : | chl | 316 | */ dec->time_pp = (uint32_t) |
554 : | chl | 313 | (time_increment_resolution + dec->time - dec->last_non_b_time)%time_increment_resolution; |
555 : | edgomez | 195 | dec->last_non_b_time = dec->time; |
556 : | } else { | ||
557 : | chl | 316 | dec->time = time_increment; |
558 : | /* | ||
559 : | edgomez | 195 | (dec->last_time_base + |
560 : | chl | 316 | time_incr) * time_increment_resolution + time_increment; |
561 : | */ | ||
562 : | chl | 313 | dec->time_bp = (uint32_t) |
563 : | (time_increment_resolution + dec->last_non_b_time - dec->time)%time_increment_resolution; | ||
564 : | chenm001 | 156 | } |
565 : | Isibaar | 3 | |
566 : | READ_MARKER(); | ||
567 : | |||
568 : | edgomez | 195 | if (!BitstreamGetBit(bs)) // vop_coded |
569 : | Isibaar | 3 | { |
570 : | suxen_drol | 252 | DPRINTF(DPRINTF_HEADER, "vop_coded==false"); |
571 : | Isibaar | 3 | return N_VOP; |
572 : | } | ||
573 : | |||
574 : | /* if (newpred_enable) | ||
575 : | edgomez | 195 | { |
576 : | } | ||
577 : | */ | ||
578 : | Isibaar | 3 | |
579 : | chenm001 | 156 | // fix a little bug by MinChen <chenm002@163.com> |
580 : | edgomez | 195 | if ((dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) && |
581 : | (coding_type == P_VOP)) { | ||
582 : | Isibaar | 3 | *rounding = BitstreamGetBit(bs); // rounding_type |
583 : | suxen_drol | 252 | DPRINTF(DPRINTF_HEADER, "rounding %i", *rounding); |
584 : | Isibaar | 3 | } |
585 : | |||
586 : | /* if (reduced_resolution_enable) | ||
587 : | edgomez | 195 | { |
588 : | } | ||
589 : | */ | ||
590 : | Isibaar | 3 | |
591 : | edgomez | 195 | if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) { |
592 : | Isibaar | 3 | uint32_t width, height; |
593 : | uint32_t horiz_mc_ref, vert_mc_ref; | ||
594 : | edgomez | 195 | |
595 : | Isibaar | 3 | width = BitstreamGetBits(bs, 13); |
596 : | READ_MARKER(); | ||
597 : | height = BitstreamGetBits(bs, 13); | ||
598 : | READ_MARKER(); | ||
599 : | horiz_mc_ref = BitstreamGetBits(bs, 13); | ||
600 : | READ_MARKER(); | ||
601 : | vert_mc_ref = BitstreamGetBits(bs, 13); | ||
602 : | READ_MARKER(); | ||
603 : | |||
604 : | suxen_drol | 252 | DPRINTF(DPRINTF_HEADER, "width %i", width); |
605 : | DPRINTF(DPRINTF_HEADER, "height %i", height); | ||
606 : | DPRINTF(DPRINTF_HEADER, "horiz_mc_ref %i", horiz_mc_ref); | ||
607 : | DPRINTF(DPRINTF_HEADER, "vert_mc_ref %i", vert_mc_ref); | ||
608 : | Isibaar | 3 | |
609 : | edgomez | 195 | BitstreamSkip(bs, 1); // change_conv_ratio_disable |
610 : | if (BitstreamGetBit(bs)) // vop_constant_alpha | ||
611 : | Isibaar | 3 | { |
612 : | edgomez | 195 | BitstreamSkip(bs, 8); // vop_constant_alpha_value |
613 : | Isibaar | 3 | } |
614 : | } | ||
615 : | |||
616 : | edgomez | 195 | |
617 : | if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) { | ||
618 : | Isibaar | 3 | // intra_dc_vlc_threshold |
619 : | edgomez | 195 | *intra_dc_threshold = |
620 : | intra_dc_threshold_table[BitstreamGetBits(bs, 3)]; | ||
621 : | Isibaar | 3 | |
622 : | edgomez | 195 | if (dec->interlacing) { |
623 : | suxen_drol | 252 | dec->top_field_first = BitstreamGetBit(bs); |
624 : | DPRINTF(DPRINTF_HEADER, "interlace top_field_first %i", dec->top_field_first); | ||
625 : | dec->alternate_vertical_scan = BitstreamGetBit(bs); | ||
626 : | DPRINTF(DPRINTF_HEADER, "interlace alternate_vertical_scan %i", dec->alternate_vertical_scan); | ||
627 : | |||
628 : | h | 69 | } |
629 : | Isibaar | 3 | } |
630 : | edgomez | 195 | |
631 : | if ((*quant = BitstreamGetBits(bs, dec->quant_bits)) < 1) // vop_quant | ||
632 : | Isibaar | 157 | *quant = 1; |
633 : | |||
634 : | suxen_drol | 252 | DPRINTF(DPRINTF_HEADER, "quant %i", *quant); |
635 : | edgomez | 195 | |
636 : | if (coding_type != I_VOP) { | ||
637 : | *fcode_forward = BitstreamGetBits(bs, 3); // fcode_forward | ||
638 : | suxen_drol | 252 | DPRINTF(DPRINTF_HEADER, "fcode_forward %i", *fcode_forward); |
639 : | Isibaar | 3 | } |
640 : | edgomez | 195 | |
641 : | if (coding_type == B_VOP) { | ||
642 : | *fcode_backward = BitstreamGetBits(bs, 3); // fcode_backward | ||
643 : | suxen_drol | 252 | DPRINTF(DPRINTF_HEADER, "fcode_backward %i", *fcode_backward); |
644 : | Isibaar | 3 | } |
645 : | edgomez | 195 | if (!dec->scalability) { |
646 : | if ((dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) && | ||
647 : | (coding_type != I_VOP)) { | ||
648 : | BitstreamSkip(bs, 1); // vop_shape_coding_type | ||
649 : | chenm001 | 156 | } |
650 : | } | ||
651 : | Isibaar | 3 | return coding_type; |
652 : | suxen_drol | 252 | |
653 : | edgomez | 195 | } else if (start_code == USERDATA_START_CODE) { |
654 : | suxen_drol | 252 | |
655 : | DPRINTF(DPRINTF_STARTCODE, "<user_data>"); | ||
656 : | |||
657 : | edgomez | 195 | BitstreamSkip(bs, 32); // user_data_start_code |
658 : | suxen_drol | 252 | |
659 : | edgomez | 195 | } else // start_code == ? |
660 : | Isibaar | 3 | { |
661 : | edgomez | 195 | if (BitstreamShowBits(bs, 24) == 0x000001) { |
662 : | suxen_drol | 252 | DPRINTF(DPRINTF_STARTCODE, "<unknown: %x>", BitstreamShowBits(bs, 32)); |
663 : | Isibaar | 3 | } |
664 : | BitstreamSkip(bs, 8); | ||
665 : | } | ||
666 : | } | ||
667 : | while ((BitstreamPos(bs) >> 3) < bs->length); | ||
668 : | |||
669 : | suxen_drol | 233 | //DPRINTF("*** WARNING: no vop_start_code found"); |
670 : | edgomez | 195 | return -1; /* ignore it */ |
671 : | Isibaar | 3 | } |
672 : | |||
673 : | |||
674 : | /* write custom quant matrix */ | ||
675 : | |||
676 : | edgomez | 195 | static void |
677 : | bs_put_matrix(Bitstream * bs, | ||
678 : | const int16_t * matrix) | ||
679 : | Isibaar | 3 | { |
680 : | int i, j; | ||
681 : | const int last = matrix[scan_tables[0][63]]; | ||
682 : | |||
683 : | suxen_drol | 233 | for (j = 63; j > 0 && matrix[scan_tables[0][j - 1]] == last; j--); |
684 : | Isibaar | 3 | |
685 : | edgomez | 195 | for (i = 0; i <= j; i++) { |
686 : | Isibaar | 3 | BitstreamPutBits(bs, matrix[scan_tables[0][i]], 8); |
687 : | } | ||
688 : | |||
689 : | edgomez | 195 | if (j < 63) { |
690 : | Isibaar | 3 | BitstreamPutBits(bs, 0, 8); |
691 : | } | ||
692 : | } | ||
693 : | |||
694 : | |||
695 : | /* | ||
696 : | write vol header | ||
697 : | */ | ||
698 : | edgomez | 195 | void |
699 : | BitstreamWriteVolHeader(Bitstream * const bs, | ||
700 : | const MBParam * pParam, | ||
701 : | const FRAMEINFO * frame) | ||
702 : | Isibaar | 3 | { |
703 : | // video object_start_code & vo_id | ||
704 : | edgomez | 195 | BitstreamPad(bs); |
705 : | Isibaar | 3 | BitstreamPutBits(bs, VO_START_CODE, 27); |
706 : | edgomez | 195 | BitstreamPutBits(bs, 0, 5); |
707 : | Isibaar | 3 | |
708 : | // video_object_layer_start_code & vol_id | ||
709 : | BitstreamPutBits(bs, VOL_START_CODE, 28); | ||
710 : | BitstreamPutBits(bs, 0, 4); | ||
711 : | |||
712 : | edgomez | 195 | BitstreamPutBit(bs, 0); // random_accessible_vol |
713 : | BitstreamPutBits(bs, 0, 8); // video_object_type_indication | ||
714 : | BitstreamPutBit(bs, 0); // is_object_layer_identified (0=not given) | ||
715 : | BitstreamPutBits(bs, 1, 4); // aspect_ratio_info (1=1:1) | ||
716 : | suxen_drol | 164 | |
717 : | chl | 387 | BitstreamPutBit(bs, 1); // vol_control_parameters |
718 : | BitstreamPutBits(bs, 1, 2); // chroma_format 1="4:2:0" | ||
719 : | |||
720 : | suxen_drol | 164 | #ifdef BFRAMES |
721 : | edgomez | 195 | if (pParam->max_bframes > 0) { |
722 : | BitstreamPutBit(bs, 0); // low_delay | ||
723 : | } else | ||
724 : | suxen_drol | 164 | #endif |
725 : | { | ||
726 : | chl | 386 | BitstreamPutBit(bs, 1); // low_delay |
727 : | suxen_drol | 164 | } |
728 : | chl | 387 | BitstreamPutBit(bs, 0); // vbv_parameters (0=not given) |
729 : | suxen_drol | 164 | |
730 : | edgomez | 195 | BitstreamPutBits(bs, 0, 2); // video_object_layer_shape (0=rectangular) |
731 : | Isibaar | 3 | |
732 : | WRITE_MARKER(); | ||
733 : | edgomez | 195 | |
734 : | Isibaar | 3 | /* time_increment_resolution; ignored by current decore versions |
735 : | edgomez | 195 | eg. 2fps res=2 inc=1 |
736 : | 25fps res=25 inc=1 | ||
737 : | 29.97fps res=30000 inc=1001 | ||
738 : | */ | ||
739 : | suxen_drol | 163 | #ifdef BFRAMES |
740 : | BitstreamPutBits(bs, pParam->fbase, 16); | ||
741 : | #else | ||
742 : | chl | 387 | BitstreamPutBits(bs, pParam->fbase, 16); |
743 : | suxen_drol | 163 | #endif |
744 : | Isibaar | 3 | |
745 : | WRITE_MARKER(); | ||
746 : | |||
747 : | suxen_drol | 241 | #ifdef BFRAMES |
748 : | BitstreamPutBit(bs, 1); // fixed_vop_rate = 1 | ||
749 : | BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase)); // fixed_vop_time_increment | ||
750 : | #else | ||
751 : | chl | 387 | BitstreamPutBit(bs, 1); // fixed_vop_rate = 1 |
752 : | BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase)); // fixed_vop_time_increment | ||
753 : | suxen_drol | 241 | #endif |
754 : | Isibaar | 3 | |
755 : | WRITE_MARKER(); | ||
756 : | edgomez | 195 | BitstreamPutBits(bs, pParam->width, 13); // width |
757 : | Isibaar | 3 | WRITE_MARKER(); |
758 : | edgomez | 195 | BitstreamPutBits(bs, pParam->height, 13); // height |
759 : | Isibaar | 3 | WRITE_MARKER(); |
760 : | edgomez | 195 | |
761 : | BitstreamPutBit(bs, frame->global_flags & XVID_INTERLACING); // interlace | ||
762 : | Isibaar | 3 | BitstreamPutBit(bs, 1); // obmc_disable (overlapped block motion compensation) |
763 : | BitstreamPutBit(bs, 0); // sprite_enable | ||
764 : | BitstreamPutBit(bs, 0); // not_in_bit | ||
765 : | |||
766 : | // quant_type 0=h.263 1=mpeg4(quantizer tables) | ||
767 : | suxen_drol | 136 | BitstreamPutBit(bs, pParam->m_quant_type); |
768 : | edgomez | 195 | |
769 : | if (pParam->m_quant_type) { | ||
770 : | Isibaar | 4 | BitstreamPutBit(bs, get_intra_matrix_status()); // load_intra_quant_mat |
771 : | edgomez | 195 | if (get_intra_matrix_status()) { |
772 : | Isibaar | 4 | bs_put_matrix(bs, get_intra_matrix()); |
773 : | Isibaar | 3 | } |
774 : | |||
775 : | edgomez | 195 | BitstreamPutBit(bs, get_inter_matrix_status()); // load_inter_quant_mat |
776 : | if (get_inter_matrix_status()) { | ||
777 : | Isibaar | 4 | bs_put_matrix(bs, get_inter_matrix()); |
778 : | Isibaar | 3 | } |
779 : | |||
780 : | } | ||
781 : | |||
782 : | BitstreamPutBit(bs, 1); // complexity_estimation_disable | ||
783 : | BitstreamPutBit(bs, 1); // resync_marker_disable | ||
784 : | BitstreamPutBit(bs, 0); // data_partitioned | ||
785 : | BitstreamPutBit(bs, 0); // scalability | ||
786 : | } | ||
787 : | |||
788 : | |||
789 : | /* | ||
790 : | write vop header | ||
791 : | |||
792 : | NOTE: doesnt handle bother with time_base & time_inc | ||
793 : | time_base = n seconds since last resync (eg. last iframe) | ||
794 : | time_inc = nth of a second since last resync | ||
795 : | (decoder uses these values to determine precise time since last resync) | ||
796 : | */ | ||
797 : | edgomez | 195 | void |
798 : | BitstreamWriteVopHeader(Bitstream * const bs, | ||
799 : | const MBParam * pParam, | ||
800 : | suxen_drol | 229 | const FRAMEINFO * frame, |
801 : | int vop_coded) | ||
802 : | Isibaar | 3 | { |
803 : | suxen_drol | 152 | uint32_t i; |
804 : | chl | 387 | |
805 : | edgomez | 195 | BitstreamPad(bs); |
806 : | BitstreamPutBits(bs, VOP_START_CODE, 32); | ||
807 : | Isibaar | 3 | |
808 : | edgomez | 195 | BitstreamPutBits(bs, frame->coding_type, 2); |
809 : | |||
810 : | Isibaar | 3 | // time_base = 0 write n x PutBit(1), PutBit(0) |
811 : | suxen_drol | 152 | #ifdef BFRAMES |
812 : | edgomez | 195 | for (i = 0; i < frame->seconds; i++) { |
813 : | suxen_drol | 152 | BitstreamPutBit(bs, 1); |
814 : | } | ||
815 : | BitstreamPutBit(bs, 0); | ||
816 : | #else | ||
817 : | chl | 387 | for (i = 0; i < frame->seconds; i++) { |
818 : | BitstreamPutBit(bs, 1); | ||
819 : | } | ||
820 : | BitstreamPutBit(bs, 0); | ||
821 : | // BitstreamPutBits(bs, 0, 1); | ||
822 : | suxen_drol | 152 | #endif |
823 : | Isibaar | 3 | |
824 : | WRITE_MARKER(); | ||
825 : | |||
826 : | // time_increment: value=nth_of_sec, nbits = log2(resolution) | ||
827 : | suxen_drol | 152 | #ifdef BFRAMES |
828 : | edgomez | 195 | BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase)); |
829 : | suxen_drol | 252 | /*DPRINTF("[%i:%i] %c\n", frame->seconds, frame->ticks, |
830 : | edgomez | 195 | frame->coding_type == I_VOP ? 'I' : frame->coding_type == |
831 : | suxen_drol | 252 | P_VOP ? 'P' : 'B');*/ |
832 : | suxen_drol | 152 | #else |
833 : | chl | 387 | BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase)); |
834 : | // BitstreamPutBits(bs, 1, 1); | ||
835 : | suxen_drol | 152 | #endif |
836 : | Isibaar | 3 | |
837 : | WRITE_MARKER(); | ||
838 : | |||
839 : | suxen_drol | 229 | if (!vop_coded) { |
840 : | BitstreamPutBits(bs, 0, 1); | ||
841 : | return; | ||
842 : | } | ||
843 : | |||
844 : | edgomez | 195 | BitstreamPutBits(bs, 1, 1); // vop_coded |
845 : | Isibaar | 3 | |
846 : | suxen_drol | 163 | if (frame->coding_type == P_VOP) |
847 : | suxen_drol | 136 | BitstreamPutBits(bs, frame->rounding_type, 1); |
848 : | Isibaar | 3 | |
849 : | edgomez | 195 | BitstreamPutBits(bs, 0, 3); // intra_dc_vlc_threshold |
850 : | |||
851 : | if (frame->global_flags & XVID_INTERLACING) { | ||
852 : | BitstreamPutBit(bs, 1); // top field first | ||
853 : | BitstreamPutBit(bs, 0); // alternate vertical scan | ||
854 : | h | 69 | } |
855 : | |||
856 : | edgomez | 195 | BitstreamPutBits(bs, frame->quant, 5); // quantizer |
857 : | |||
858 : | suxen_drol | 136 | if (frame->coding_type != I_VOP) |
859 : | edgomez | 195 | BitstreamPutBits(bs, frame->fcode, 3); // forward_fixed_code |
860 : | suxen_drol | 152 | |
861 : | if (frame->coding_type == B_VOP) | ||
862 : | edgomez | 195 | BitstreamPutBits(bs, frame->bcode, 3); // backward_fixed_code |
863 : | suxen_drol | 152 | |
864 : | Isibaar | 3 | } |
865 : | suxen_drol | 229 | |
866 : | |||
867 : | void | ||
868 : | BitstreamWriteUserData(Bitstream * const bs, | ||
869 : | uint8_t * data, | ||
870 : | const int length) | ||
871 : | { | ||
872 : | int i; | ||
873 : | |||
874 : | BitstreamPad(bs); | ||
875 : | BitstreamPutBits(bs, USERDATA_START_CODE, 32); | ||
876 : | |||
877 : | for (i = 0; i < length; i++) { | ||
878 : | BitstreamPutBits(bs, data[i], 8); | ||
879 : | } | ||
880 : | |||
881 : | chl | 313 | } |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |