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