41 |
* * |
* * |
42 |
* Revision history: * |
* Revision history: * |
43 |
* * |
* * |
44 |
|
* 22.05.2002 bs_put_matrix fix |
45 |
|
* 20.05.2002 added BitstreamWriteUserData * |
46 |
|
* 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 |
|
* MinChen <chenm001@163.com> * |
50 |
|
* 06.05.2002 low_delay * |
51 |
* 06.05.2002 fixed fincr/fbase error * |
* 06.05.2002 fixed fincr/fbase error * |
52 |
* 01.05.2002 added BVOP support to BitstreamWriteVopHeader * |
* 01.05.2002 added BVOP support to BitstreamWriteVopHeader * |
53 |
* 15.04.2002 rewrite log2bin use asm386 By MinChen <chenm001@163.com> * |
* 15.04.2002 rewrite log2bin use asm386 By MinChen <chenm001@163.com> * |
57 |
* 30.02.2002 intra_dc_threshold support * |
* 30.02.2002 intra_dc_threshold support * |
58 |
* 04.12.2001 support for additional headers * |
* 04.12.2001 support for additional headers * |
59 |
* 16.12.2001 inital version * |
* 16.12.2001 inital version * |
60 |
* * |
* |
61 |
******************************************************************************/ |
******************************************************************************/ |
62 |
|
|
63 |
|
|
66 |
#include "../quant/quant_matrix.h" |
#include "../quant/quant_matrix.h" |
67 |
|
|
68 |
|
|
69 |
static uint32_t __inline log2bin(uint32_t value) |
static uint32_t __inline |
70 |
|
log2bin(uint32_t value) |
71 |
{ |
{ |
72 |
/* Changed by Chenm001 */ |
/* Changed by Chenm001 */ |
73 |
#ifndef WIN32 |
#ifndef WIN32 |
74 |
int n = 0; |
int n = 0; |
75 |
while (value) |
|
76 |
{ |
while (value) { |
77 |
value >>= 1; |
value >>= 1; |
78 |
n++; |
n++; |
79 |
} |
} |
87 |
} |
} |
88 |
|
|
89 |
|
|
90 |
static const uint32_t intra_dc_threshold_table[] = |
static const uint32_t intra_dc_threshold_table[] = { |
|
{ |
|
91 |
32, /* never use */ |
32, /* never use */ |
92 |
13, |
13, |
93 |
15, |
15, |
99 |
}; |
}; |
100 |
|
|
101 |
|
|
102 |
void bs_get_matrix(Bitstream * bs, uint8_t * matrix) |
void |
103 |
|
bs_get_matrix(Bitstream * bs, |
104 |
|
uint8_t * matrix) |
105 |
{ |
{ |
106 |
int i = 0; |
int i = 0; |
107 |
int last, value = 0; |
int last, value = 0; |
108 |
|
|
109 |
do |
do { |
|
{ |
|
110 |
last = value; |
last = value; |
111 |
value = BitstreamGetBits(bs, 8); |
value = BitstreamGetBits(bs, 8); |
112 |
matrix[ scan_tables[0][i++] ] = value; |
matrix[ scan_tables[0][i++] ] = value; |
113 |
} |
} |
114 |
while (value != 0 && i < 64); |
while (value != 0 && i < 64); |
115 |
|
i--; // fix little bug at coeff not full |
116 |
|
|
117 |
while (i < 64) |
while (i < 64) { |
|
{ |
|
118 |
matrix[ scan_tables[0][i++] ] = last; |
matrix[ scan_tables[0][i++] ] = last; |
119 |
} |
} |
120 |
} |
} |
121 |
|
|
122 |
|
|
123 |
|
|
124 |
|
// for PVOP addbits == fcode - 1 |
125 |
|
// for BVOP addbits == max(fcode,bcode) - 1 |
126 |
|
// returns mbpos |
127 |
|
int |
128 |
|
read_video_packet_header(Bitstream *bs, const int addbits, int * quant) |
129 |
|
{ |
130 |
|
int nbits; |
131 |
|
int mbnum; |
132 |
|
int hec; |
133 |
|
|
134 |
|
nbits = NUMBITS_VP_RESYNC_MARKER + addbits; |
135 |
|
|
136 |
|
BitstreamSkip(bs, BitstreamNumBitsToByteAlign(bs)); |
137 |
|
BitstreamSkip(bs, nbits); |
138 |
|
|
139 |
|
DPRINTF(DPRINTF_STARTCODE, "<video_packet_header>"); |
140 |
|
|
141 |
|
// 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 |
|
DPRINTF(DPRINTF_HEADER, "mbnum %i", mbnum); |
152 |
|
|
153 |
|
// if (dec->shape != VIDOBJLAY_SHAPE_BINARYONLY) |
154 |
|
*quant = BitstreamGetBits(bs, 5); |
155 |
|
DPRINTF(DPRINTF_HEADER, "quant %i", *quant); |
156 |
|
|
157 |
|
// if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) |
158 |
|
hec = BitstreamGetBit(bs); |
159 |
|
DPRINTF(DPRINTF_HEADER, "header_extension_code %i", hec); |
160 |
|
// if (hec) |
161 |
|
// .. decoder hec-header ... |
162 |
|
|
163 |
|
return mbnum; |
164 |
|
} |
165 |
|
|
166 |
|
|
167 |
|
|
168 |
/* |
/* |
169 |
decode headers |
decode headers |
170 |
returns coding_type, or -1 if error |
returns coding_type, or -1 if error |
171 |
*/ |
*/ |
172 |
|
|
173 |
int BitstreamReadHeaders(Bitstream * bs, DECODER * dec, uint32_t * rounding, uint32_t * quant, uint32_t * fcode_forward, uint32_t * fcode_backward, uint32_t * intra_dc_threshold) |
#define VIDOBJ_START_CODE_MASK 0x0000001f |
174 |
|
#define VIDOBJLAY_START_CODE_MASK 0x0000000f |
175 |
|
|
176 |
|
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 |
{ |
{ |
185 |
uint32_t vol_ver_id; |
uint32_t vol_ver_id; |
186 |
static uint32_t time_increment_resolution; |
static uint32_t time_increment_resolution; |
189 |
uint32_t time_incr=0; |
uint32_t time_incr=0; |
190 |
int32_t time_increment; |
int32_t time_increment; |
191 |
|
|
192 |
do |
do { |
|
{ |
|
193 |
BitstreamByteAlign(bs); |
BitstreamByteAlign(bs); |
194 |
start_code = BitstreamShowBits(bs, 32); |
start_code = BitstreamShowBits(bs, 32); |
195 |
|
|
196 |
if (start_code == VISOBJSEQ_START_CODE) |
if (start_code == VISOBJSEQ_START_CODE) { |
197 |
{ |
|
198 |
// DEBUG("visual_object_sequence"); |
int profile; |
199 |
|
|
200 |
|
DPRINTF(DPRINTF_STARTCODE, "<visual_object_sequence>"); |
201 |
|
|
202 |
BitstreamSkip(bs, 32); // visual_object_sequence_start_code |
BitstreamSkip(bs, 32); // visual_object_sequence_start_code |
203 |
BitstreamSkip(bs, 8); // profile_and_level_indication |
profile = BitstreamGetBits(bs, 8); // profile_and_level_indication |
204 |
} |
|
205 |
else if (start_code == VISOBJSEQ_STOP_CODE) |
DPRINTF(DPRINTF_HEADER, "profile_and_level_indication %i", profile); |
206 |
{ |
|
207 |
|
} else if (start_code == VISOBJSEQ_STOP_CODE) { |
208 |
|
|
209 |
BitstreamSkip(bs, 32); // visual_object_sequence_stop_code |
BitstreamSkip(bs, 32); // visual_object_sequence_stop_code |
210 |
} |
|
211 |
else if (start_code == VISOBJ_START_CODE) |
DPRINTF(DPRINTF_STARTCODE, "</visual_object_sequence>"); |
212 |
{ |
|
213 |
// DEBUG("visual_object"); |
} else if (start_code == VISOBJ_START_CODE) { |
214 |
|
|
215 |
|
DPRINTF(DPRINTF_STARTCODE, "<visual_object>"); |
216 |
|
|
217 |
BitstreamSkip(bs,32); // visual_object_start_code |
BitstreamSkip(bs,32); // visual_object_start_code |
218 |
if (BitstreamGetBit(bs)) // is_visual_object_identified |
if (BitstreamGetBit(bs)) // is_visual_object_identified |
219 |
{ |
{ |
220 |
vol_ver_id = BitstreamGetBits(bs,4); // visual_object_ver_id |
vol_ver_id = BitstreamGetBits(bs,4); // visual_object_ver_id |
221 |
|
DPRINTF(DPRINTF_HEADER,"ver_id %i", vol_ver_id); |
222 |
BitstreamSkip(bs, 3); // visual_object_priority |
BitstreamSkip(bs, 3); // visual_object_priority |
223 |
} |
} else { |
|
else |
|
|
{ |
|
224 |
vol_ver_id = 1; |
vol_ver_id = 1; |
225 |
} |
} |
226 |
|
|
227 |
if (BitstreamShowBits(bs, 4) != VISOBJ_TYPE_VIDEO) // visual_object_type |
if (BitstreamShowBits(bs, 4) != VISOBJ_TYPE_VIDEO) // visual_object_type |
228 |
{ |
{ |
229 |
DEBUG("visual_object_type != video"); |
DPRINTF(DPRINTF_ERROR, "visual_object_type != video"); |
230 |
return -1; |
return -1; |
231 |
} |
} |
232 |
BitstreamSkip(bs, 4); |
BitstreamSkip(bs, 4); |
235 |
|
|
236 |
if (BitstreamGetBit(bs)) // video_signal_type |
if (BitstreamGetBit(bs)) // video_signal_type |
237 |
{ |
{ |
238 |
DEBUG("+ video_signal_type"); |
DPRINTF(DPRINTF_HEADER,"+ video_signal_type"); |
239 |
BitstreamSkip(bs, 3); // video_format |
BitstreamSkip(bs, 3); // video_format |
240 |
BitstreamSkip(bs, 1); // video_range |
BitstreamSkip(bs, 1); // video_range |
241 |
if (BitstreamGetBit(bs)) // color_description |
if (BitstreamGetBit(bs)) // color_description |
242 |
{ |
{ |
243 |
DEBUG("+ color_description"); |
DPRINTF(DPRINTF_HEADER,"+ color_description"); |
244 |
BitstreamSkip(bs, 8); // color_primaries |
BitstreamSkip(bs, 8); // color_primaries |
245 |
BitstreamSkip(bs, 8); // transfer_characteristics |
BitstreamSkip(bs, 8); // transfer_characteristics |
246 |
BitstreamSkip(bs, 8); // matrix_coefficients |
BitstreamSkip(bs, 8); // matrix_coefficients |
247 |
} |
} |
248 |
} |
} |
249 |
} |
} else if ((start_code & ~VIDOBJ_START_CODE_MASK) == VIDOBJ_START_CODE) { |
250 |
else if ((start_code & ~0x1f) == VIDOBJ_START_CODE) |
|
251 |
{ |
DPRINTF(DPRINTF_STARTCODE, "<video_object>"); |
252 |
|
DPRINTF(DPRINTF_HEADER, "vo id %i", start_code & VIDOBJ_START_CODE_MASK); |
253 |
|
|
254 |
BitstreamSkip(bs, 32); // video_object_start_code |
BitstreamSkip(bs, 32); // video_object_start_code |
255 |
} |
|
256 |
else if ((start_code & ~0xf) == VIDOBJLAY_START_CODE) |
} else if ((start_code & ~VIDOBJLAY_START_CODE_MASK) == VIDOBJLAY_START_CODE) { |
257 |
{ |
|
258 |
// DEBUG("video_object_layer"); |
DPRINTF(DPRINTF_STARTCODE, "<video_object_layer>"); |
259 |
|
DPRINTF(DPRINTF_HEADER, "vol id %i", start_code & VIDOBJLAY_START_CODE_MASK); |
260 |
|
|
261 |
BitstreamSkip(bs, 32); // video_object_layer_start_code |
BitstreamSkip(bs, 32); // video_object_layer_start_code |
262 |
|
|
263 |
BitstreamSkip(bs, 1); // random_accessible_vol |
BitstreamSkip(bs, 1); // random_accessible_vol |
264 |
|
|
265 |
// video_object_type_indication |
// video_object_type_indication |
266 |
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 |
|
267 |
{ |
{ |
268 |
DEBUG1("video_object_type_indication not supported", BitstreamShowBits(bs, 8)); |
DPRINTF(DPRINTF_ERROR,"video_object_type_indication %i not supported ", |
269 |
|
BitstreamShowBits(bs, 8)); |
270 |
return -1; |
return -1; |
271 |
} |
} |
272 |
BitstreamSkip(bs, 8); |
BitstreamSkip(bs, 8); |
274 |
|
|
275 |
if (BitstreamGetBit(bs)) // is_object_layer_identifier |
if (BitstreamGetBit(bs)) // is_object_layer_identifier |
276 |
{ |
{ |
277 |
DEBUG("+ is_object_layer_identifier"); |
DPRINTF(DPRINTF_HEADER, "+ is_object_layer_identifier"); |
278 |
vol_ver_id = BitstreamGetBits(bs,4); // video_object_layer_verid |
vol_ver_id = BitstreamGetBits(bs,4); // video_object_layer_verid |
279 |
|
DPRINTF(DPRINTF_HEADER,"ver_id %i", vol_ver_id); |
280 |
BitstreamSkip(bs, 3); // video_object_layer_priority |
BitstreamSkip(bs, 3); // video_object_layer_priority |
281 |
} |
} else { |
|
else |
|
|
{ |
|
282 |
vol_ver_id = 1; |
vol_ver_id = 1; |
283 |
} |
} |
|
//DEBUGI("vol_ver_id", vol_ver_id); |
|
284 |
|
|
285 |
if (BitstreamGetBits(bs, 4) == VIDOBJLAY_AR_EXTPAR) // aspect_ratio_info |
if (BitstreamGetBits(bs, 4) == VIDOBJLAY_AR_EXTPAR) // aspect_ratio_info |
286 |
{ |
{ |
287 |
DEBUG("+ aspect_ratio_info"); |
DPRINTF(DPRINTF_HEADER, "+ aspect_ratio_info"); |
288 |
BitstreamSkip(bs, 8); // par_width |
BitstreamSkip(bs, 8); // par_width |
289 |
BitstreamSkip(bs, 8); // par_height |
BitstreamSkip(bs, 8); // par_height |
290 |
} |
} |
291 |
|
|
292 |
if (BitstreamGetBit(bs)) // vol_control_parameters |
if (BitstreamGetBit(bs)) // vol_control_parameters |
293 |
{ |
{ |
294 |
DEBUG("+ vol_control_parameters"); |
DPRINTF(DPRINTF_HEADER, "+ vol_control_parameters"); |
295 |
BitstreamSkip(bs, 2); // chroma_format |
BitstreamSkip(bs, 2); // chroma_format |
296 |
BitstreamSkip(bs, 1); // low_delay |
dec->low_delay = BitstreamGetBit(bs); // low_delay |
297 |
|
DPRINTF(DPRINTF_HEADER, "low_delay %i", dec->low_delay); |
298 |
if (BitstreamGetBit(bs)) // vbv_parameters |
if (BitstreamGetBit(bs)) // vbv_parameters |
299 |
{ |
{ |
300 |
DEBUG("+ vbv_parameters"); |
DPRINTF(DPRINTF_HEADER,"+ vbv_parameters"); |
301 |
BitstreamSkip(bs, 15); // first_half_bitrate |
BitstreamSkip(bs, 15); // first_half_bitrate |
302 |
READ_MARKER(); |
READ_MARKER(); |
303 |
BitstreamSkip(bs, 15); // latter_half_bitrate |
BitstreamSkip(bs, 15); // latter_half_bitrate |
314 |
} |
} |
315 |
|
|
316 |
dec->shape = BitstreamGetBits(bs, 2); // video_object_layer_shape |
dec->shape = BitstreamGetBits(bs, 2); // video_object_layer_shape |
317 |
// DEBUG1("shape", dec->shape); |
DPRINTF(DPRINTF_HEADER, "shape %i", dec->shape); |
318 |
|
|
319 |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE && vol_ver_id != 1) |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE && vol_ver_id != 1) { |
|
{ |
|
320 |
BitstreamSkip(bs, 4); // video_object_layer_shape_extension |
BitstreamSkip(bs, 4); // video_object_layer_shape_extension |
321 |
} |
} |
322 |
|
|
324 |
|
|
325 |
// *************************** for decode B-frame time *********************** |
// *************************** for decode B-frame time *********************** |
326 |
time_increment_resolution = BitstreamGetBits(bs, 16); // vop_time_increment_resolution |
time_increment_resolution = BitstreamGetBits(bs, 16); // vop_time_increment_resolution |
327 |
|
|
328 |
|
DPRINTF(DPRINTF_HEADER,"vop_time_increment_resolution %i", time_increment_resolution); |
329 |
|
|
330 |
time_increment_resolution--; |
time_increment_resolution--; |
331 |
//DEBUG1("time_increment_resolution=",time_increment_resolution); |
|
332 |
if (time_increment_resolution > 0) |
if (time_increment_resolution > 0) { |
|
{ |
|
333 |
dec->time_inc_bits = log2bin(time_increment_resolution); |
dec->time_inc_bits = log2bin(time_increment_resolution); |
334 |
} |
} else { |
|
else |
|
|
{ |
|
335 |
// dec->time_inc_bits = 0; |
// dec->time_inc_bits = 0; |
|
|
|
336 |
// for "old" xvid compatibility, set time_inc_bits = 1 |
// for "old" xvid compatibility, set time_inc_bits = 1 |
337 |
dec->time_inc_bits = 1; |
dec->time_inc_bits = 1; |
338 |
} |
} |
341 |
|
|
342 |
if (BitstreamGetBit(bs)) // fixed_vop_rate |
if (BitstreamGetBit(bs)) // fixed_vop_rate |
343 |
{ |
{ |
344 |
|
DPRINTF(DPRINTF_HEADER, "+ fixed_vop_rate"); |
345 |
BitstreamSkip(bs, dec->time_inc_bits); // fixed_vop_time_increment |
BitstreamSkip(bs, dec->time_inc_bits); // fixed_vop_time_increment |
346 |
} |
} |
347 |
|
|
348 |
if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) |
if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) { |
|
{ |
|
349 |
|
|
350 |
if (dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR) |
if (dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR) { |
|
{ |
|
351 |
uint32_t width, height; |
uint32_t width, height; |
352 |
|
|
353 |
READ_MARKER(); |
READ_MARKER(); |
354 |
width = BitstreamGetBits(bs, 13); // video_object_layer_width |
width = BitstreamGetBits(bs, 13); // video_object_layer_width |
|
//DEBUGI("width", width); |
|
355 |
READ_MARKER(); |
READ_MARKER(); |
356 |
height = BitstreamGetBits(bs, 13); // video_object_layer_height |
height = BitstreamGetBits(bs, 13); // video_object_layer_height |
|
//DEBUGI("height", height); |
|
357 |
READ_MARKER(); |
READ_MARKER(); |
358 |
|
|
359 |
if (width != dec->width || height != dec->height) |
DPRINTF(DPRINTF_HEADER, "width %i", width); |
360 |
{ |
DPRINTF(DPRINTF_HEADER, "height %i", height); |
361 |
DEBUG("FATAL: video dimension discrepancy ***"); |
|
362 |
DEBUG2("bitstream width/height", width, height); |
if (width != dec->width || height != dec->height) { |
363 |
DEBUG2("param width/height", dec->width, dec->height); |
DPRINTF(DPRINTF_ERROR, "XVID_DEC_PARAM width/height does not match bitstream"); |
364 |
return -1; |
return -1; |
365 |
} |
} |
366 |
|
|
367 |
} |
} |
368 |
|
|
369 |
if ((dec->interlacing = BitstreamGetBit(bs))) |
dec->interlacing = BitstreamGetBit(bs); |
370 |
{ |
DPRINTF(DPRINTF_HEADER, "interlace", dec->interlacing); |
|
DEBUG("vol: interlacing"); |
|
|
} |
|
371 |
|
|
372 |
if (!BitstreamGetBit(bs)) // obmc_disable |
if (!BitstreamGetBit(bs)) // obmc_disable |
373 |
{ |
{ |
374 |
DEBUG("IGNORED/TODO: !obmc_disable"); |
DPRINTF(DPRINTF_ERROR, "obmc_disabled==false not supported"); |
375 |
// TODO |
// TODO |
376 |
// fucking divx4.02 has this enabled |
// fucking divx4.02 has this enabled |
377 |
} |
} |
378 |
|
|
379 |
if (BitstreamGetBits(bs, (vol_ver_id == 1 ? 1 : 2))) // sprite_enable |
if (BitstreamGetBits(bs, (vol_ver_id == 1 ? 1 : 2))) // sprite_enable |
380 |
{ |
{ |
381 |
DEBUG("sprite_enable; not supported"); |
DPRINTF(DPRINTF_ERROR, "spriate_enabled not supported"); |
382 |
return -1; |
return -1; |
383 |
} |
} |
384 |
|
|
385 |
if (vol_ver_id != 1 && dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) |
if (vol_ver_id != 1 && |
386 |
{ |
dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) { |
387 |
BitstreamSkip(bs, 1); // sadct_disable |
BitstreamSkip(bs, 1); // sadct_disable |
388 |
} |
} |
389 |
|
|
390 |
if (BitstreamGetBit(bs)) // not_8_bit |
if (BitstreamGetBit(bs)) // not_8_bit |
391 |
{ |
{ |
392 |
DEBUG("+ not_8_bit [IGNORED/TODO]"); |
DPRINTF(DPRINTF_HEADER, "not_8_bit==true (ignored)"); |
393 |
dec->quant_bits = BitstreamGetBits(bs, 4); // quant_precision |
dec->quant_bits = BitstreamGetBits(bs, 4); // quant_precision |
394 |
BitstreamSkip(bs, 4); // bits_per_pixel |
BitstreamSkip(bs, 4); // bits_per_pixel |
395 |
} |
} else { |
|
else |
|
|
{ |
|
396 |
dec->quant_bits = 5; |
dec->quant_bits = 5; |
397 |
} |
} |
398 |
|
|
399 |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) { |
|
{ |
|
400 |
BitstreamSkip(bs, 1); // no_gray_quant_update |
BitstreamSkip(bs, 1); // no_gray_quant_update |
401 |
BitstreamSkip(bs, 1); // composition_method |
BitstreamSkip(bs, 1); // composition_method |
402 |
BitstreamSkip(bs, 1); // linear_composition |
BitstreamSkip(bs, 1); // linear_composition |
403 |
} |
} |
404 |
|
|
405 |
dec->quant_type = BitstreamGetBit(bs); // quant_type |
dec->quant_type = BitstreamGetBit(bs); // quant_type |
406 |
// DEBUG1("**** quant_type", dec->quant_type); |
DPRINTF(DPRINTF_HEADER, "quant_type %i", dec->quant_type); |
407 |
|
|
408 |
if (dec->quant_type) |
if (dec->quant_type) { |
|
{ |
|
409 |
if (BitstreamGetBit(bs)) // load_intra_quant_mat |
if (BitstreamGetBit(bs)) // load_intra_quant_mat |
410 |
{ |
{ |
411 |
uint8_t matrix[64]; |
uint8_t matrix[64]; |
412 |
|
|
413 |
|
DPRINTF(DPRINTF_HEADER, "load_intra_quant_mat"); |
414 |
|
|
415 |
bs_get_matrix(bs, matrix); |
bs_get_matrix(bs, matrix); |
416 |
set_intra_matrix(matrix); |
set_intra_matrix(matrix); |
417 |
} |
} else |
|
else |
|
418 |
set_intra_matrix(get_default_intra_matrix()); |
set_intra_matrix(get_default_intra_matrix()); |
419 |
|
|
420 |
if (BitstreamGetBit(bs)) // load_inter_quant_mat |
if (BitstreamGetBit(bs)) // load_inter_quant_mat |
421 |
{ |
{ |
422 |
uint8_t matrix[64]; |
uint8_t matrix[64]; |
423 |
|
|
424 |
|
DPRINTF(DPRINTF_HEADER, "load_inter_quant_mat"); |
425 |
|
|
426 |
bs_get_matrix(bs, matrix); |
bs_get_matrix(bs, matrix); |
427 |
set_inter_matrix(matrix); |
set_inter_matrix(matrix); |
428 |
} |
} else |
|
else |
|
429 |
set_inter_matrix(get_default_inter_matrix()); |
set_inter_matrix(get_default_inter_matrix()); |
430 |
|
|
431 |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) |
if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) { |
432 |
{ |
DPRINTF(DPRINTF_ERROR, "greyscale matrix not supported"); |
|
// TODO |
|
|
DEBUG("TODO: grayscale matrix stuff"); |
|
433 |
return -1; |
return -1; |
434 |
} |
} |
435 |
|
|
436 |
} |
} |
437 |
|
|
438 |
|
|
439 |
if (vol_ver_id != 1) |
if (vol_ver_id != 1) { |
|
{ |
|
440 |
dec->quarterpel = BitstreamGetBit(bs); // quarter_sampe |
dec->quarterpel = BitstreamGetBit(bs); // quarter_sampe |
441 |
if (dec->quarterpel) |
if (dec->quarterpel) { |
442 |
{ |
DPRINTF(DPRINTF_ERROR, "quarter_sample not supported"); |
|
DEBUG("IGNORED/TODO: quarter_sample"); |
|
|
} |
|
443 |
} |
} |
444 |
else |
} else { |
|
{ |
|
445 |
dec->quarterpel = 0; |
dec->quarterpel = 0; |
446 |
} |
} |
447 |
|
|
448 |
if (!BitstreamGetBit(bs)) // complexity_estimation_disable |
if (!BitstreamGetBit(bs)) // complexity_estimation_disable |
449 |
{ |
{ |
450 |
DEBUG("TODO: complexity_estimation header"); |
DPRINTF(DPRINTF_ERROR, "complexity_estimation not supported"); |
|
// TODO |
|
451 |
return -1; |
return -1; |
452 |
} |
} |
453 |
|
|
454 |
if (!BitstreamGetBit(bs)) // resync_marker_disable |
BitstreamSkip(bs, 1); // resync_marker_disable |
|
{ |
|
|
DEBUG("IGNORED/TODO: !resync_marker_disable"); |
|
|
// TODO |
|
|
} |
|
455 |
|
|
456 |
if (BitstreamGetBit(bs)) // data_partitioned |
if (BitstreamGetBit(bs)) // data_partitioned |
457 |
{ |
{ |
458 |
DEBUG("+ data_partitioned"); |
DPRINTF(DPRINTF_ERROR, "data_partitioned not supported"); |
459 |
BitstreamSkip(bs, 1); // reversible_vlc |
BitstreamSkip(bs, 1); // reversible_vlc |
460 |
} |
} |
461 |
|
|
462 |
if (vol_ver_id != 1) |
if (vol_ver_id != 1) { |
|
{ |
|
463 |
if (BitstreamGetBit(bs)) // newpred_enable |
if (BitstreamGetBit(bs)) // newpred_enable |
464 |
{ |
{ |
465 |
DEBUG("+ newpred_enable"); |
DPRINTF(DPRINTF_HEADER, "+ newpred_enable"); |
466 |
BitstreamSkip(bs, 2); // requested_upstream_message_type |
BitstreamSkip(bs, 2); // requested_upstream_message_type |
467 |
BitstreamSkip(bs, 1); // newpred_segment_type |
BitstreamSkip(bs, 1); // newpred_segment_type |
468 |
} |
} |
469 |
if (BitstreamGetBit(bs)) // reduced_resolution_vop_enable |
if (BitstreamGetBit(bs)) // reduced_resolution_vop_enable |
470 |
{ |
{ |
471 |
DEBUG("TODO: reduced_resolution_vop_enable"); |
DPRINTF(DPRINTF_ERROR, "reduced_resolution_vop not supported"); |
|
// TODO |
|
472 |
return -1; |
return -1; |
473 |
} |
} |
474 |
} |
} |
475 |
|
|
476 |
if ((dec->scalability=BitstreamGetBit(bs))) // scalability |
if ((dec->scalability=BitstreamGetBit(bs))) // scalability |
477 |
{ |
{ |
478 |
// TODO |
DPRINTF(DPRINTF_ERROR, "scalability not supported"); |
|
DEBUG("TODO: scalability"); |
|
479 |
return -1; |
return -1; |
480 |
} |
} |
481 |
} |
} else // dec->shape == BINARY_ONLY |
|
else // dec->shape == BINARY_ONLY |
|
|
{ |
|
|
if (vol_ver_id != 1) |
|
482 |
{ |
{ |
483 |
|
if (vol_ver_id != 1) { |
484 |
if (BitstreamGetBit(bs)) // scalability |
if (BitstreamGetBit(bs)) // scalability |
485 |
{ |
{ |
486 |
// TODO |
DPRINTF(DPRINTF_ERROR, "scalability not supported"); |
|
DEBUG("TODO: scalability"); |
|
487 |
return -1; |
return -1; |
488 |
} |
} |
489 |
} |
} |
491 |
|
|
492 |
} |
} |
493 |
|
|
494 |
} |
} else if (start_code == GRPOFVOP_START_CODE) { |
495 |
else if (start_code == GRPOFVOP_START_CODE) |
|
496 |
{ |
DPRINTF(DPRINTF_STARTCODE, "<group_of_vop>"); |
497 |
// DEBUG("group_of_vop"); |
|
498 |
BitstreamSkip(bs, 32); |
BitstreamSkip(bs, 32); |
499 |
{ |
{ |
500 |
int hours, minutes, seconds; |
int hours, minutes, seconds; |
501 |
|
|
502 |
hours = BitstreamGetBits(bs, 5); |
hours = BitstreamGetBits(bs, 5); |
503 |
minutes = BitstreamGetBits(bs, 6); |
minutes = BitstreamGetBits(bs, 6); |
504 |
READ_MARKER(); |
READ_MARKER(); |
505 |
seconds = BitstreamGetBits(bs, 6); |
seconds = BitstreamGetBits(bs, 6); |
506 |
// DEBUG3("hms", hours, minutes, seconds); |
|
507 |
|
DPRINTF(DPRINTF_HEADER, "time %ih%im%is", hours); |
508 |
} |
} |
509 |
BitstreamSkip(bs, 1); // closed_gov |
BitstreamSkip(bs, 1); // closed_gov |
510 |
BitstreamSkip(bs, 1); // broken_link |
BitstreamSkip(bs, 1); // broken_link |
511 |
} |
|
512 |
else if (start_code == VOP_START_CODE) |
} else if (start_code == VOP_START_CODE) { |
513 |
{ |
|
514 |
// DEBUG("vop_start_code"); |
DPRINTF(DPRINTF_STARTCODE, "<vop>"); |
515 |
|
|
516 |
BitstreamSkip(bs, 32); // vop_start_code |
BitstreamSkip(bs, 32); // vop_start_code |
517 |
|
|
518 |
coding_type = BitstreamGetBits(bs, 2); // vop_coding_type |
coding_type = BitstreamGetBits(bs, 2); // vop_coding_type |
519 |
//DEBUG1("coding_type", coding_type); |
DPRINTF(DPRINTF_HEADER, "coding_type %i", coding_type); |
520 |
|
|
521 |
// *************************** for decode B-frame time *********************** |
// *************************** for decode B-frame time *********************** |
522 |
while (BitstreamGetBit(bs) != 0) // time_base |
while (BitstreamGetBit(bs) != 0) // time_base |
524 |
|
|
525 |
READ_MARKER(); |
READ_MARKER(); |
526 |
|
|
527 |
//DEBUG1("time_inc_bits", dec->time_inc_bits); |
if (dec->time_inc_bits) { |
|
//DEBUG1("vop_time_incr", BitstreamShowBits(bs, dec->time_inc_bits)); |
|
|
if (dec->time_inc_bits) |
|
|
{ |
|
|
//BitstreamSkip(bs, dec->time_inc_bits); // vop_time_increment |
|
528 |
time_increment = (BitstreamGetBits(bs, dec->time_inc_bits)); // vop_time_increment |
time_increment = (BitstreamGetBits(bs, dec->time_inc_bits)); // vop_time_increment |
529 |
} |
} |
530 |
|
|
531 |
|
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 |
|
coding_type == I_VOP ? 'I' : coding_type == P_VOP ? 'P' : 'B', |
536 |
|
time_incr, time_increment); |
537 |
|
|
538 |
if(coding_type != B_VOP){ |
if(coding_type != B_VOP){ |
539 |
dec->last_time_base = dec->time_base; |
dec->last_time_base = dec->time_base; |
540 |
dec->time_base += time_incr; |
dec->time_base += time_incr; |
541 |
dec->time = dec->time_base*time_increment_resolution + time_increment; |
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); |
dec->time_pp= (uint32_t)(dec->time - dec->last_non_b_time); |
545 |
dec->last_non_b_time= dec->time; |
dec->last_non_b_time= dec->time; |
546 |
}else{ |
}else{ |
547 |
dec->time = (dec->last_time_base + time_incr)*time_increment_resolution + time_increment; |
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); |
dec->time_bp= (uint32_t)(dec->last_non_b_time - dec->time); |
551 |
} |
} |
|
//DEBUG1("time_increment=",time_increment); |
|
552 |
|
|
553 |
READ_MARKER(); |
READ_MARKER(); |
554 |
|
|
555 |
if (!BitstreamGetBit(bs)) // vop_coded |
if (!BitstreamGetBit(bs)) // vop_coded |
556 |
{ |
{ |
557 |
|
DPRINTF(DPRINTF_HEADER, "vop_coded==false"); |
558 |
return N_VOP; |
return N_VOP; |
559 |
} |
} |
560 |
|
|
564 |
*/ |
*/ |
565 |
|
|
566 |
// fix a little bug by MinChen <chenm002@163.com> |
// fix a little bug by MinChen <chenm002@163.com> |
567 |
if ((dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) && (coding_type == P_VOP)) |
if ((dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) && |
568 |
{ |
(coding_type == P_VOP)) { |
569 |
*rounding = BitstreamGetBit(bs); // rounding_type |
*rounding = BitstreamGetBit(bs); // rounding_type |
570 |
//DEBUG1("rounding", *rounding); |
DPRINTF(DPRINTF_HEADER, "rounding %i", *rounding); |
571 |
} |
} |
572 |
|
|
573 |
/* if (reduced_resolution_enable) |
/* if (reduced_resolution_enable) |
575 |
} |
} |
576 |
*/ |
*/ |
577 |
|
|
578 |
if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) |
if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) { |
|
{ |
|
579 |
uint32_t width, height; |
uint32_t width, height; |
580 |
uint32_t horiz_mc_ref, vert_mc_ref; |
uint32_t horiz_mc_ref, vert_mc_ref; |
581 |
|
|
588 |
vert_mc_ref = BitstreamGetBits(bs, 13); |
vert_mc_ref = BitstreamGetBits(bs, 13); |
589 |
READ_MARKER(); |
READ_MARKER(); |
590 |
|
|
591 |
// DEBUG2("vop_width/height", width, height); |
DPRINTF(DPRINTF_HEADER, "width %i", width); |
592 |
// DEBUG2("ref ", horiz_mc_ref, vert_mc_ref); |
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 |
|
|
596 |
BitstreamSkip(bs, 1); // change_conv_ratio_disable |
BitstreamSkip(bs, 1); // change_conv_ratio_disable |
597 |
if (BitstreamGetBit(bs)) // vop_constant_alpha |
if (BitstreamGetBit(bs)) // vop_constant_alpha |
601 |
} |
} |
602 |
|
|
603 |
|
|
604 |
if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) |
if (dec->shape != VIDOBJLAY_SHAPE_BINARY_ONLY) { |
|
{ |
|
605 |
// intra_dc_vlc_threshold |
// intra_dc_vlc_threshold |
606 |
*intra_dc_threshold = intra_dc_threshold_table[ BitstreamGetBits(bs,3) ]; |
*intra_dc_threshold = |
607 |
|
intra_dc_threshold_table[BitstreamGetBits(bs, 3)]; |
608 |
|
|
609 |
|
if (dec->interlacing) { |
610 |
|
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 |
|
|
|
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"); |
|
|
} |
|
615 |
} |
} |
616 |
} |
} |
617 |
|
|
618 |
if((*quant = BitstreamGetBits(bs, dec->quant_bits)) < 1) // vop_quant |
if((*quant = BitstreamGetBits(bs, dec->quant_bits)) < 1) // vop_quant |
619 |
*quant = 1; |
*quant = 1; |
620 |
|
|
621 |
//DEBUG1("quant", *quant); |
DPRINTF(DPRINTF_HEADER, "quant %i", *quant); |
622 |
|
|
623 |
if (coding_type != I_VOP) |
if (coding_type != I_VOP) { |
|
{ |
|
624 |
*fcode_forward = BitstreamGetBits(bs, 3); // fcode_forward |
*fcode_forward = BitstreamGetBits(bs, 3); // fcode_forward |
625 |
|
DPRINTF(DPRINTF_HEADER, "fcode_forward %i", *fcode_forward); |
626 |
} |
} |
627 |
|
|
628 |
if (coding_type == B_VOP) |
if (coding_type == B_VOP) { |
|
{ |
|
629 |
*fcode_backward = BitstreamGetBits(bs, 3); // fcode_backward |
*fcode_backward = BitstreamGetBits(bs, 3); // fcode_backward |
630 |
|
DPRINTF(DPRINTF_HEADER, "fcode_backward %i", *fcode_backward); |
631 |
} |
} |
632 |
if (!dec->scalability){ |
if (!dec->scalability){ |
633 |
if ((dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) && (coding_type != I_VOP)){ |
if ((dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) && |
634 |
|
(coding_type != I_VOP)) { |
635 |
BitstreamSkip(bs, 1); // vop_shape_coding_type |
BitstreamSkip(bs, 1); // vop_shape_coding_type |
636 |
} |
} |
637 |
} |
} |
638 |
return coding_type; |
return coding_type; |
639 |
} |
|
640 |
else if (start_code == USERDATA_START_CODE) |
} else if (start_code == USERDATA_START_CODE) { |
641 |
{ |
|
642 |
// DEBUG("user_data"); |
DPRINTF(DPRINTF_STARTCODE, "<user_data>"); |
643 |
|
|
644 |
BitstreamSkip(bs, 32); // user_data_start_code |
BitstreamSkip(bs, 32); // user_data_start_code |
645 |
} |
|
646 |
else // start_code == ? |
} else // start_code == ? |
|
{ |
|
|
if (BitstreamShowBits(bs, 24) == 0x000001) |
|
647 |
{ |
{ |
648 |
DEBUG1("*** WARNING: unknown start_code", BitstreamShowBits(bs, 32)); |
if (BitstreamShowBits(bs, 24) == 0x000001) { |
649 |
|
DPRINTF(DPRINTF_STARTCODE, "<unknown: %x>", BitstreamShowBits(bs, 32)); |
650 |
} |
} |
651 |
BitstreamSkip(bs, 8); |
BitstreamSkip(bs, 8); |
652 |
} |
} |
653 |
} |
} |
654 |
while ((BitstreamPos(bs) >> 3) < bs->length); |
while ((BitstreamPos(bs) >> 3) < bs->length); |
655 |
|
|
656 |
DEBUG("*** WARNING: no vop_start_code found"); |
//DPRINTF("*** WARNING: no vop_start_code found"); |
657 |
return -1; /* ignore it */ |
return -1; /* ignore it */ |
658 |
} |
} |
659 |
|
|
660 |
|
|
661 |
/* write custom quant matrix */ |
/* write custom quant matrix */ |
662 |
|
|
663 |
static void bs_put_matrix(Bitstream * bs, const int16_t *matrix) |
static void |
664 |
|
bs_put_matrix(Bitstream * bs, |
665 |
|
const int16_t * matrix) |
666 |
{ |
{ |
667 |
int i, j; |
int i, j; |
668 |
const int last = matrix[scan_tables[0][63]]; |
const int last = matrix[scan_tables[0][63]]; |
669 |
|
|
670 |
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--); |
671 |
|
|
672 |
for (i = 0; i <= j; i++) |
for (i = 0; i <= j; i++) { |
|
{ |
|
673 |
BitstreamPutBits(bs, matrix[scan_tables[0][i]], 8); |
BitstreamPutBits(bs, matrix[scan_tables[0][i]], 8); |
674 |
} |
} |
675 |
|
|
676 |
if (j < 63) |
if (j < 63) { |
|
{ |
|
677 |
BitstreamPutBits(bs, 0, 8); |
BitstreamPutBits(bs, 0, 8); |
678 |
} |
} |
679 |
} |
} |
682 |
/* |
/* |
683 |
write vol header |
write vol header |
684 |
*/ |
*/ |
685 |
void BitstreamWriteVolHeader(Bitstream * const bs, |
void |
686 |
const MBParam * pParam, const FRAMEINFO * frame) |
BitstreamWriteVolHeader(Bitstream * const bs, |
687 |
|
const MBParam * pParam, |
688 |
|
const FRAMEINFO * frame) |
689 |
{ |
{ |
690 |
// video object_start_code & vo_id |
// video object_start_code & vo_id |
691 |
BitstreamPad(bs); |
BitstreamPad(bs); |
700 |
BitstreamPutBits(bs, 0, 8); // video_object_type_indication |
BitstreamPutBits(bs, 0, 8); // video_object_type_indication |
701 |
BitstreamPutBit(bs, 0); // is_object_layer_identified (0=not given) |
BitstreamPutBit(bs, 0); // is_object_layer_identified (0=not given) |
702 |
BitstreamPutBits(bs, 1, 4); // aspect_ratio_info (1=1:1) |
BitstreamPutBits(bs, 1, 4); // aspect_ratio_info (1=1:1) |
703 |
BitstreamPutBit(bs, 0); // vol_control_parameters (0=not given) |
|
704 |
|
#ifdef BFRAMES |
705 |
|
if (pParam->max_bframes > 0) { |
706 |
|
//DPRINTF("low_delay=1"); |
707 |
|
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 |
|
#endif |
713 |
|
{ |
714 |
|
BitstreamPutBits(bs, 0, 1); // vol_control_parameters (0=not given) |
715 |
|
} |
716 |
|
|
717 |
|
|
718 |
BitstreamPutBits(bs, 0, 2); // video_object_layer_shape (0=rectangular) |
BitstreamPutBits(bs, 0, 2); // video_object_layer_shape (0=rectangular) |
719 |
|
|
720 |
WRITE_MARKER(); |
WRITE_MARKER(); |
732 |
|
|
733 |
WRITE_MARKER(); |
WRITE_MARKER(); |
734 |
|
|
735 |
// fixed_vop_rate |
#ifdef BFRAMES |
736 |
BitstreamPutBit(bs, 0); |
BitstreamPutBit(bs, 1); // fixed_vop_rate = 1 |
737 |
|
BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase)); // fixed_vop_time_increment |
738 |
// fixed_time_increment: value=nth_of_sec, nbits = log2(resolution) |
#else |
739 |
// BitstreamPutBits(bs, 0, 15); |
BitstreamPutBit(bs, 0); // fixed_vop_rate = 0 |
740 |
|
#endif |
741 |
|
|
742 |
WRITE_MARKER(); |
WRITE_MARKER(); |
743 |
BitstreamPutBits(bs, pParam->width, 13); // width |
BitstreamPutBits(bs, pParam->width, 13); // width |
753 |
// quant_type 0=h.263 1=mpeg4(quantizer tables) |
// quant_type 0=h.263 1=mpeg4(quantizer tables) |
754 |
BitstreamPutBit(bs, pParam->m_quant_type); |
BitstreamPutBit(bs, pParam->m_quant_type); |
755 |
|
|
756 |
if (pParam->m_quant_type) |
if (pParam->m_quant_type) { |
|
{ |
|
757 |
BitstreamPutBit(bs, get_intra_matrix_status()); // load_intra_quant_mat |
BitstreamPutBit(bs, get_intra_matrix_status()); // load_intra_quant_mat |
758 |
if (get_intra_matrix_status()) |
if (get_intra_matrix_status()) { |
|
{ |
|
759 |
bs_put_matrix(bs, get_intra_matrix()); |
bs_put_matrix(bs, get_intra_matrix()); |
760 |
} |
} |
761 |
|
|
762 |
BitstreamPutBit(bs, get_inter_matrix_status()); // load_inter_quant_mat |
BitstreamPutBit(bs, get_inter_matrix_status()); // load_inter_quant_mat |
763 |
if (get_inter_matrix_status()) |
if (get_inter_matrix_status()) { |
|
{ |
|
764 |
bs_put_matrix(bs, get_inter_matrix()); |
bs_put_matrix(bs, get_inter_matrix()); |
765 |
} |
} |
766 |
|
|
781 |
time_inc = nth of a second since last resync |
time_inc = nth of a second since last resync |
782 |
(decoder uses these values to determine precise time since last resync) |
(decoder uses these values to determine precise time since last resync) |
783 |
*/ |
*/ |
784 |
void BitstreamWriteVopHeader(Bitstream * const bs, |
void |
785 |
|
BitstreamWriteVopHeader(Bitstream * const bs, |
786 |
const MBParam * pParam, |
const MBParam * pParam, |
787 |
const FRAMEINFO * frame) |
const FRAMEINFO * frame, |
788 |
|
int vop_coded) |
789 |
{ |
{ |
790 |
#ifdef BFRAMES |
#ifdef BFRAMES |
791 |
uint32_t i; |
uint32_t i; |
797 |
|
|
798 |
// time_base = 0 write n x PutBit(1), PutBit(0) |
// time_base = 0 write n x PutBit(1), PutBit(0) |
799 |
#ifdef BFRAMES |
#ifdef BFRAMES |
800 |
for (i = 0; i < frame->seconds; i++) |
for (i = 0; i < frame->seconds; i++) { |
|
{ |
|
801 |
BitstreamPutBit(bs, 1); |
BitstreamPutBit(bs, 1); |
802 |
} |
} |
803 |
BitstreamPutBit(bs, 0); |
BitstreamPutBit(bs, 0); |
810 |
// time_increment: value=nth_of_sec, nbits = log2(resolution) |
// time_increment: value=nth_of_sec, nbits = log2(resolution) |
811 |
#ifdef BFRAMES |
#ifdef BFRAMES |
812 |
BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase)); |
BitstreamPutBits(bs, frame->ticks, log2bin(pParam->fbase)); |
813 |
dprintf("[%i:%i] %c\n", frame->seconds, frame->ticks, frame->coding_type == I_VOP ? 'I' : frame->coding_type == P_VOP ? 'P' : 'B'); |
/*DPRINTF("[%i:%i] %c\n", frame->seconds, frame->ticks, |
814 |
|
frame->coding_type == I_VOP ? 'I' : frame->coding_type == |
815 |
|
P_VOP ? 'P' : 'B');*/ |
816 |
#else |
#else |
817 |
BitstreamPutBits(bs, 1, 1); |
BitstreamPutBits(bs, 1, 1); |
818 |
#endif |
#endif |
819 |
|
|
820 |
WRITE_MARKER(); |
WRITE_MARKER(); |
821 |
|
|
822 |
|
if (!vop_coded) { |
823 |
|
BitstreamPutBits(bs, 0, 1); |
824 |
|
return; |
825 |
|
} |
826 |
|
|
827 |
BitstreamPutBits(bs, 1, 1); // vop_coded |
BitstreamPutBits(bs, 1, 1); // vop_coded |
828 |
|
|
829 |
if (frame->coding_type == P_VOP) |
if (frame->coding_type == P_VOP) |
831 |
|
|
832 |
BitstreamPutBits(bs, 0, 3); // intra_dc_vlc_threshold |
BitstreamPutBits(bs, 0, 3); // intra_dc_vlc_threshold |
833 |
|
|
834 |
if (frame->global_flags & XVID_INTERLACING) |
if (frame->global_flags & XVID_INTERLACING) { |
|
{ |
|
835 |
BitstreamPutBit(bs, 1); // top field first |
BitstreamPutBit(bs, 1); // top field first |
836 |
BitstreamPutBit(bs, 0); // alternate vertical scan |
BitstreamPutBit(bs, 0); // alternate vertical scan |
837 |
} |
} |
845 |
BitstreamPutBits(bs, frame->bcode, 3); // backward_fixed_code |
BitstreamPutBits(bs, frame->bcode, 3); // backward_fixed_code |
846 |
|
|
847 |
} |
} |
848 |
|
|
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 |
|
} |