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