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