41 |
* * |
* * |
42 |
* Revision history: * |
* Revision history: * |
43 |
* * |
* * |
44 |
* 28.10.2002 GMC support - gruel * |
* 05.01.2003 GMC support - gruel * |
45 |
* 04.10.2002 qpel support - Isibaar * |
* 04.10.2002 qpel support - Isibaar * |
46 |
* 11.07.2002 add VOP width & height return to dec when dec->width * |
* 11.07.2002 add VOP width & height return to dec when dec->width * |
47 |
* or dec->height is 0 (for use in examples/ex1.c) * |
* or dec->height is 0 (for use in examples/ex1.c) * |
230 |
if (coding_type == B_VOP && fcode_backward) |
if (coding_type == B_VOP && fcode_backward) |
231 |
{ |
{ |
232 |
*fcode_backward = BitstreamGetBits(bs, 3); |
*fcode_backward = BitstreamGetBits(bs, 3); |
233 |
DPRINTF(DPRINTF_HEADER,"fcode_backward %i", fcode_backward); |
DPRINTF(DPRINTF_HEADER,"fcode_backward %i", *fcode_backward); |
234 |
} |
} |
235 |
} |
} |
236 |
|
|
432 |
uint32_t * fcode_forward, |
uint32_t * fcode_forward, |
433 |
uint32_t * fcode_backward, |
uint32_t * fcode_backward, |
434 |
uint32_t * intra_dc_threshold, |
uint32_t * intra_dc_threshold, |
435 |
VECTOR * gmc_mv) |
WARPPOINTS *gmc_warp) |
436 |
{ |
{ |
437 |
uint32_t vol_ver_id; |
uint32_t vol_ver_id; |
438 |
uint32_t coding_type; |
uint32_t coding_type; |
439 |
uint32_t start_code; |
uint32_t start_code; |
440 |
uint32_t time_incr = 0; |
uint32_t time_incr = 0; |
441 |
int32_t time_increment; |
int32_t time_increment = 0; |
442 |
int resize = 0; |
int resize = 0; |
443 |
|
|
444 |
do { |
do { |
472 |
if (BitstreamGetBit(bs)) // is_visual_object_identified |
if (BitstreamGetBit(bs)) // is_visual_object_identified |
473 |
{ |
{ |
474 |
visobj_ver_id = BitstreamGetBits(bs, 4); // visual_object_ver_id |
visobj_ver_id = BitstreamGetBits(bs, 4); // visual_object_ver_id |
475 |
DPRINTF(DPRINTF_HEADER,"ver_id %i", vol_ver_id); |
DPRINTF(DPRINTF_HEADER,"visobj_ver_id %i", visobj_ver_id); |
476 |
BitstreamSkip(bs, 3); // visual_object_priority |
BitstreamSkip(bs, 3); // visual_object_priority |
477 |
} else { |
} else { |
478 |
visobj_ver_id = 1; |
visobj_ver_id = 1; |
558 |
DPRINTF(DPRINTF_HEADER, "low_delay %i", dec->low_delay); |
DPRINTF(DPRINTF_HEADER, "low_delay %i", dec->low_delay); |
559 |
if (BitstreamGetBit(bs)) // vbv_parameters |
if (BitstreamGetBit(bs)) // vbv_parameters |
560 |
{ |
{ |
561 |
|
unsigned int bitrate; |
562 |
|
unsigned int buffer_size; |
563 |
|
unsigned int occupancy; |
564 |
|
|
565 |
DPRINTF(DPRINTF_HEADER,"+ vbv_parameters"); |
DPRINTF(DPRINTF_HEADER,"+ vbv_parameters"); |
566 |
BitstreamSkip(bs, 15); // first_half_bitrate |
|
567 |
|
bitrate = BitstreamGetBits(bs,15) << 15; // first_half_bit_rate |
568 |
READ_MARKER(); |
READ_MARKER(); |
569 |
BitstreamSkip(bs, 15); // latter_half_bitrate |
bitrate |= BitstreamGetBits(bs,15); // latter_half_bit_rate |
570 |
READ_MARKER(); |
READ_MARKER(); |
571 |
BitstreamSkip(bs, 15); // first_half_vbv_buffer_size |
|
572 |
|
buffer_size = BitstreamGetBits(bs, 15) << 3; // first_half_vbv_buffer_size |
573 |
READ_MARKER(); |
READ_MARKER(); |
574 |
BitstreamSkip(bs, 3); // latter_half_vbv_buffer_size |
buffer_size |= BitstreamGetBits(bs, 3); // latter_half_vbv_buffer_size |
575 |
BitstreamSkip(bs, 11); // first_half_vbv_occupancy |
|
576 |
|
occupancy = BitstreamGetBits(bs, 11) << 15; // first_half_vbv_occupancy |
577 |
READ_MARKER(); |
READ_MARKER(); |
578 |
BitstreamSkip(bs, 15); // latter_half_vbv_occupancy |
occupancy |= BitstreamGetBits(bs, 15); // latter_half_vbv_occupancy |
579 |
READ_MARKER(); |
READ_MARKER(); |
580 |
|
|
581 |
|
DPRINTF(DPRINTF_HEADER,"bitrate %d (unit=400 bps)", bitrate); |
582 |
|
DPRINTF(DPRINTF_HEADER,"buffer_size %d (unit=16384 bits)", buffer_size); |
583 |
|
DPRINTF(DPRINTF_HEADER,"occupancy %d (unit=64 bits)", occupancy); |
584 |
} |
} |
585 |
}else{ |
}else{ |
586 |
dec->low_delay = dec->low_delay_default; |
dec->low_delay = dec->low_delay_default; |
838 |
READ_MARKER(); |
READ_MARKER(); |
839 |
seconds = BitstreamGetBits(bs, 6); |
seconds = BitstreamGetBits(bs, 6); |
840 |
|
|
841 |
DPRINTF(DPRINTF_HEADER, "time %ih%im%is", hours); |
DPRINTF(DPRINTF_HEADER, "time %ih%im%is", hours,minutes,seconds); |
842 |
} |
} |
843 |
BitstreamSkip(bs, 1); // closed_gov |
BitstreamSkip(bs, 1); // closed_gov |
844 |
BitstreamSkip(bs, 1); // broken_link |
BitstreamSkip(bs, 1); // broken_link |
1012 |
} |
} |
1013 |
READ_MARKER(); |
READ_MARKER(); |
1014 |
|
|
1015 |
gmc_mv[i].x = x; |
gmc_warp->duv[i].x = x; |
1016 |
gmc_mv[i].y = y; |
gmc_warp->duv[i].y = y; |
1017 |
|
|
1018 |
DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i)", i, x, y); |
DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i)", i, x, y); |
1019 |
} |
} |
1070 |
|
|
1071 |
DPRINTF(DPRINTF_STARTCODE, "<user_data>: %s\n", tmp); |
DPRINTF(DPRINTF_STARTCODE, "<user_data>: %s\n", tmp); |
1072 |
|
|
1073 |
|
/* read xvid bitstream version */ |
1074 |
|
if(strncmp(tmp, "XviD", 4) == 0) { |
1075 |
|
sscanf(tmp, "XviD%d", &dec->bs_version); |
1076 |
|
DPRINTF(DPRINTF_HEADER, "xvid bitstream version=%i", dec->bs_version); |
1077 |
|
} |
1078 |
|
|
1079 |
/* divx detection */ |
/* divx detection */ |
1080 |
i = sscanf(tmp, "DivX%dBuild%d%c", &version, &build, &packed); |
i = sscanf(tmp, "DivX%dBuild%d%c", &version, &build, &packed); |
1081 |
if (i < 2) |
if (i < 2) |
1148 |
profile = 0xf3; /* advanced simple profile/level 2 */ |
profile = 0xf3; /* advanced simple profile/level 2 */ |
1149 |
|
|
1150 |
// visual_object_sequence_start_code |
// visual_object_sequence_start_code |
1151 |
BitstreamPad(bs); |
// BitstreamPad(bs); |
1152 |
|
/* no padding here, anymore. You have to make sure that you are |
1153 |
|
byte aligned, and that always 1-8 padding bits have been written */ |
1154 |
|
|
1155 |
BitstreamPutBits(bs, VISOBJSEQ_START_CODE, 32); |
BitstreamPutBits(bs, VISOBJSEQ_START_CODE, 32); |
1156 |
BitstreamPutBits(bs, profile, 8); |
BitstreamPutBits(bs, profile, 8); |
1157 |
|
|
1159 |
BitstreamPad(bs); |
BitstreamPad(bs); |
1160 |
BitstreamPutBits(bs, VISOBJ_START_CODE, 32); |
BitstreamPutBits(bs, VISOBJ_START_CODE, 32); |
1161 |
BitstreamPutBits(bs, 0, 1); // is_visual_object_identifier |
BitstreamPutBits(bs, 0, 1); // is_visual_object_identifier |
1162 |
|
|
1163 |
|
/* Video type */ |
1164 |
BitstreamPutBits(bs, VISOBJ_TYPE_VIDEO, 4); // visual_object_type |
BitstreamPutBits(bs, VISOBJ_TYPE_VIDEO, 4); // visual_object_type |
1165 |
|
BitstreamPutBit(bs, 0); /* video_signal_type */ |
1166 |
|
|
1167 |
// video object_start_code & vo_id |
// video object_start_code & vo_id |
1168 |
BitstreamPad(bs); |
BitstreamPadAlways(bs); // next_start_code() |
1169 |
BitstreamPutBits(bs, VIDOBJ_START_CODE|(vo_id&0x5), 32); |
BitstreamPutBits(bs, VIDOBJ_START_CODE|(vo_id&0x5), 32); |
1170 |
|
|
1171 |
// video_object_layer_start_code & vol_id |
// video_object_layer_start_code & vol_id |
1172 |
|
BitstreamPad(bs); |
1173 |
BitstreamPutBits(bs, VIDOBJLAY_START_CODE|(vol_id&0x4), 32); |
BitstreamPutBits(bs, VIDOBJLAY_START_CODE|(vol_id&0x4), 32); |
1174 |
|
|
1175 |
BitstreamPutBit(bs, 0); // random_accessible_vol |
BitstreamPutBit(bs, 0); // random_accessible_vol |
1183 |
{ |
{ |
1184 |
BitstreamPutBit(bs, 1); // is_object_layer_identified |
BitstreamPutBit(bs, 1); // is_object_layer_identified |
1185 |
BitstreamPutBits(bs, vol_ver_id, 4); // vol_ver_id == 2 |
BitstreamPutBits(bs, vol_ver_id, 4); // vol_ver_id == 2 |
1186 |
BitstreamPutBits(bs, 4, 3); // vol_ver_priority (1==lowest, 7==highest) ?? |
BitstreamPutBits(bs, 4, 3); // vol_ver_priority (1==highest, 7==lowest) |
1187 |
} |
} |
1188 |
|
|
1189 |
BitstreamPutBits(bs, 1, 4); // aspect_ratio_info (1=1:1) |
BitstreamPutBits(bs, 1, 4); // aspect_ratio_info (1=1:1) |
1279 |
|
|
1280 |
BitstreamPutBit(bs, 0); // scalability |
BitstreamPutBit(bs, 0); // scalability |
1281 |
|
|
1282 |
|
BitstreamPadAlways(bs); // next_start_code() |
1283 |
|
|
1284 |
|
/* fake divx5 id, to ensure compatibility with divx5 decoder */ |
1285 |
|
#define DIVX5_ID "DivX501b481p" |
1286 |
|
if (pParam->max_bframes > 0 && (pParam->global & XVID_GLOBAL_PACKED)) { |
1287 |
|
BitstreamWriteUserData(bs, DIVX5_ID, strlen(DIVX5_ID)); |
1288 |
|
} |
1289 |
|
|
1290 |
|
/* xvid id */ |
1291 |
|
#define XVID_ID "XviD" XVID_BS_VERSION |
1292 |
|
BitstreamWriteUserData(bs, XVID_ID, strlen(XVID_ID)); |
1293 |
} |
} |
1294 |
|
|
1295 |
|
|
1305 |
{ |
{ |
1306 |
uint32_t i; |
uint32_t i; |
1307 |
|
|
1308 |
BitstreamPad(bs); |
// BitstreamPad(bs); |
1309 |
|
/* no padding here, anymore. You have to make sure that you are |
1310 |
|
byte aligned, and that always 1-8 padding bits have been written */ |
1311 |
|
|
1312 |
BitstreamPutBits(bs, VOP_START_CODE, 32); |
BitstreamPutBits(bs, VOP_START_CODE, 32); |
1313 |
|
|
1314 |
BitstreamPutBits(bs, frame->coding_type, 2); |
BitstreamPutBits(bs, frame->coding_type, 2); |
1332 |
|
|
1333 |
if (!vop_coded) { |
if (!vop_coded) { |
1334 |
BitstreamPutBits(bs, 0, 1); |
BitstreamPutBits(bs, 0, 1); |
1335 |
|
#if 0 |
1336 |
|
BitstreamPadAlways(bs); /* next_start_code() */ |
1337 |
|
#endif |
1338 |
|
/* NB: It's up to the function caller to write the next_start_code(). |
1339 |
|
* At the moment encoder.c respects that requisite because a VOP |
1340 |
|
* always ends with a next_start_code either if it's coded or not |
1341 |
|
* and encoder.c terminates a frame with a next_start_code in whatever |
1342 |
|
* case */ |
1343 |
return; |
return; |
1344 |
} |
} |
1345 |
|
|
1359 |
} |
} |
1360 |
|
|
1361 |
if (frame->coding_type == S_VOP) { |
if (frame->coding_type == S_VOP) { |
1362 |
if (1) { // no_of_sprite_warping_points>=1 |
if (1) { // no_of_sprite_warping_points>=1 (we use 2!) |
1363 |
if (pParam->m_quarterpel) |
int k; |
1364 |
bs_put_spritetrajectory(bs, frame->GMC_MV.x/2 ); // du[0] |
for (k=0;k<2;k++) |
1365 |
else |
{ |
1366 |
bs_put_spritetrajectory(bs, frame->GMC_MV.x ); // du[0] |
bs_put_spritetrajectory(bs, frame->warp.duv[k].x ); // du[k] |
1367 |
WRITE_MARKER(); |
WRITE_MARKER(); |
1368 |
|
|
1369 |
if (pParam->m_quarterpel) |
bs_put_spritetrajectory(bs, frame->warp.duv[k].y ); // dv[k] |
|
bs_put_spritetrajectory(bs, frame->GMC_MV.y/2 ); // dv[0] |
|
|
else |
|
|
bs_put_spritetrajectory(bs, frame->GMC_MV.y ); // dv[0] |
|
1370 |
WRITE_MARKER(); |
WRITE_MARKER(); |
1371 |
|
|
|
|
|
1372 |
if (pParam->m_quarterpel) |
if (pParam->m_quarterpel) |
1373 |
{ |
{ |
1374 |
DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i) *QPEL*", 0, frame->GMC_MV.x/2, frame->GMC_MV.y/2); |
DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i) *QPEL*", k, frame->warp.duv[k].x/2, frame->warp.duv[k].y/2); |
1375 |
} |
} |
1376 |
else |
else |
1377 |
{ |
{ |
1378 |
DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i)", 0, frame->GMC_MV.x, frame->GMC_MV.y); |
DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i)", k, frame->warp.duv[k].x, frame->warp.duv[k].y); |
1379 |
} |
} |
|
|
|
1380 |
} |
} |
|
/* GMC is halfpel in bitstream, even though GMC_MV was pseudo-qpel (2*halfpel) */ |
|
|
|
|
|
if (2) { // no_of_sprite_warping_points>=2 (for DivX5 compat) |
|
|
bs_put_spritetrajectory(bs, 0 ); |
|
|
WRITE_MARKER(); |
|
|
bs_put_spritetrajectory(bs, 0 ); |
|
|
WRITE_MARKER(); |
|
1381 |
} |
} |
|
// no support for brightness_change! |
|
1382 |
} |
} |
1383 |
|
|
1384 |
|
|