20 |
* along with this program ; if not, write to the Free Software |
* along with this program ; if not, write to the Free Software |
21 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
22 |
* |
* |
23 |
* $Id: bitstream.c,v 1.55 2005-11-22 10:23:01 suxen_drol Exp $ |
* $Id$ |
24 |
* |
* |
25 |
****************************************************************************/ |
****************************************************************************/ |
26 |
|
|
153 |
READ_MARKER(); |
READ_MARKER(); |
154 |
if (dec->time_inc_bits) |
if (dec->time_inc_bits) |
155 |
time_increment = (BitstreamGetBits(bs, dec->time_inc_bits)); /* vop_time_increment */ |
time_increment = (BitstreamGetBits(bs, dec->time_inc_bits)); /* vop_time_increment */ |
156 |
|
else |
157 |
|
time_increment = 0; |
158 |
READ_MARKER(); |
READ_MARKER(); |
159 |
DPRINTF(XVID_DEBUG_HEADER,"time %i:%i\n", time_base, time_increment); |
DPRINTF(XVID_DEBUG_HEADER,"time %i:%i\n", time_base, time_increment); |
160 |
|
|
425 |
DPRINTF(XVID_DEBUG_STARTCODE, "</visual_object_sequence>\n"); |
DPRINTF(XVID_DEBUG_STARTCODE, "</visual_object_sequence>\n"); |
426 |
|
|
427 |
} else if (start_code == VISOBJ_START_CODE) { |
} else if (start_code == VISOBJ_START_CODE) { |
|
int visobj_ver_id; |
|
428 |
|
|
429 |
DPRINTF(XVID_DEBUG_STARTCODE, "<visual_object>\n"); |
DPRINTF(XVID_DEBUG_STARTCODE, "<visual_object>\n"); |
430 |
|
|
431 |
BitstreamSkip(bs, 32); /* visual_object_start_code */ |
BitstreamSkip(bs, 32); /* visual_object_start_code */ |
432 |
if (BitstreamGetBit(bs)) /* is_visual_object_identified */ |
if (BitstreamGetBit(bs)) /* is_visual_object_identified */ |
433 |
{ |
{ |
434 |
visobj_ver_id = BitstreamGetBits(bs, 4); /* visual_object_ver_id */ |
dec->ver_id = BitstreamGetBits(bs, 4); /* visual_object_ver_id */ |
435 |
DPRINTF(XVID_DEBUG_HEADER,"visobj_ver_id %i\n", visobj_ver_id); |
DPRINTF(XVID_DEBUG_HEADER,"visobj_ver_id %i\n", dec->ver_id); |
436 |
BitstreamSkip(bs, 3); /* visual_object_priority */ |
BitstreamSkip(bs, 3); /* visual_object_priority */ |
437 |
} else { |
} else { |
438 |
visobj_ver_id = 1; |
dec->ver_id = 1; |
439 |
} |
} |
440 |
|
|
441 |
if (BitstreamShowBits(bs, 4) != VISOBJ_TYPE_VIDEO) /* visual_object_type */ |
if (BitstreamShowBits(bs, 4) != VISOBJ_TYPE_VIDEO) /* visual_object_type */ |
484 |
DPRINTF(XVID_DEBUG_HEADER,"ver_id %i\n", vol_ver_id); |
DPRINTF(XVID_DEBUG_HEADER,"ver_id %i\n", vol_ver_id); |
485 |
BitstreamSkip(bs, 3); /* video_object_layer_priority */ |
BitstreamSkip(bs, 3); /* video_object_layer_priority */ |
486 |
} else { |
} else { |
487 |
vol_ver_id = 1; |
vol_ver_id = dec->ver_id; |
488 |
} |
} |
489 |
|
|
490 |
dec->aspect_ratio = BitstreamGetBits(bs, 4); |
dec->aspect_ratio = BitstreamGetBits(bs, 4); |
822 |
dec->time = (dec->last_time_base + time_incr)*dec->time_inc_resolution + time_increment; |
dec->time = (dec->last_time_base + time_incr)*dec->time_inc_resolution + time_increment; |
823 |
dec->time_bp = dec->time_pp - (int32_t)(dec->last_non_b_time - dec->time); |
dec->time_bp = dec->time_pp - (int32_t)(dec->last_non_b_time - dec->time); |
824 |
} |
} |
825 |
|
if (dec->time_pp <= 0) dec->time_pp = 1; |
826 |
DPRINTF(XVID_DEBUG_HEADER,"time_pp=%i\n", dec->time_pp); |
DPRINTF(XVID_DEBUG_HEADER,"time_pp=%i\n", dec->time_pp); |
827 |
DPRINTF(XVID_DEBUG_HEADER,"time_bp=%i\n", dec->time_bp); |
DPRINTF(XVID_DEBUG_HEADER,"time_bp=%i\n", dec->time_bp); |
828 |
|
|
862 |
dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR && |
dec->shape == VIDOBJLAY_SHAPE_RECTANGULAR && |
863 |
(coding_type == P_VOP || coding_type == I_VOP)) { |
(coding_type == P_VOP || coding_type == I_VOP)) { |
864 |
|
|
865 |
if (BitstreamGetBit(bs)); |
if (BitstreamGetBit(bs)) { |
866 |
DPRINTF(XVID_DEBUG_ERROR, "RRV not supported (anymore)\n"); |
DPRINTF(XVID_DEBUG_ERROR, "RRV not supported (anymore)\n"); |
867 |
} |
} |
868 |
|
} |
869 |
|
|
870 |
if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) { |
if (dec->shape != VIDOBJLAY_SHAPE_RECTANGULAR) { |
871 |
if(!(dec->sprite_enable == SPRITE_STATIC && coding_type == I_VOP)) { |
if(!(dec->sprite_enable == SPRITE_STATIC && coding_type == I_VOP)) { |
1027 |
version, build, dec->packed_mode); |
version, build, dec->packed_mode); |
1028 |
} |
} |
1029 |
|
|
1030 |
|
if ((dec->bs_version == 0) && (build > 0) && |
1031 |
|
(build != 1393)) { /* non-xvid stream with xvid fourcc */ |
1032 |
|
dec->bs_version = 0xffff; |
1033 |
|
} |
1034 |
|
|
1035 |
} else /* start_code == ? */ |
} else /* start_code == ? */ |
1036 |
{ |
{ |
1037 |
if (BitstreamShowBits(bs, 24) == 0x000001) { |
if (BitstreamShowBits(bs, 24) == 0x000001) { |
1075 |
void |
void |
1076 |
BitstreamWriteVolHeader(Bitstream * const bs, |
BitstreamWriteVolHeader(Bitstream * const bs, |
1077 |
const MBParam * pParam, |
const MBParam * pParam, |
1078 |
const FRAMEINFO * const frame) |
const FRAMEINFO * const frame, |
1079 |
|
const int num_slices) |
1080 |
{ |
{ |
1081 |
static const unsigned int vo_id = 0; |
static const unsigned int vo_id = 0; |
1082 |
static const unsigned int vol_id = 0; |
static const unsigned int vol_id = 0; |
1241 |
} |
} |
1242 |
|
|
1243 |
BitstreamPutBit(bs, 1); /* complexity_estimation_disable */ |
BitstreamPutBit(bs, 1); /* complexity_estimation_disable */ |
1244 |
BitstreamPutBit(bs, 1); /* resync_marker_disable */ |
|
1245 |
|
if (num_slices > 1) |
1246 |
|
BitstreamPutBit(bs, 0); /* resync_marker_enabled */ |
1247 |
|
else |
1248 |
|
BitstreamPutBit(bs, 1); /* resync_marker_disabled */ |
1249 |
|
|
1250 |
BitstreamPutBit(bs, 0); /* data_partitioned */ |
BitstreamPutBit(bs, 0); /* data_partitioned */ |
1251 |
|
|
1252 |
if (vol_ver_id != 1) { |
if (vol_ver_id != 1) { |
1261 |
/* divx5 userdata string */ |
/* divx5 userdata string */ |
1262 |
#define DIVX5_ID ((char *)"DivX503b1393") |
#define DIVX5_ID ((char *)"DivX503b1393") |
1263 |
if ((pParam->global_flags & XVID_GLOBAL_DIVX5_USERDATA)) { |
if ((pParam->global_flags & XVID_GLOBAL_DIVX5_USERDATA)) { |
1264 |
BitstreamWriteUserData(bs, DIVX5_ID, strlen(DIVX5_ID)); |
BitstreamWriteUserData(bs, DIVX5_ID, (uint32_t) strlen(DIVX5_ID)); |
1265 |
if (pParam->max_bframes > 0 && (pParam->global_flags & XVID_GLOBAL_PACKED)) |
if (pParam->max_bframes > 0 && (pParam->global_flags & XVID_GLOBAL_PACKED)) |
1266 |
BitstreamPutBits(bs, 'p', 8); |
BitstreamPutBits(bs, 'p', 8); |
1267 |
} |
} |
1274 |
xvid_user_format, |
xvid_user_format, |
1275 |
XVID_BS_VERSION, |
XVID_BS_VERSION, |
1276 |
(frame->vop_flags & XVID_VOP_CARTOON)?'C':'\0'); |
(frame->vop_flags & XVID_VOP_CARTOON)?'C':'\0'); |
1277 |
BitstreamWriteUserData(bs, xvid_user_data, strlen(xvid_user_data)); |
BitstreamWriteUserData(bs, xvid_user_data, (uint32_t) strlen(xvid_user_data)); |
1278 |
} |
} |
1279 |
} |
} |
1280 |
|
|
1395 |
const char *data, |
const char *data, |
1396 |
const unsigned int length) |
const unsigned int length) |
1397 |
{ |
{ |
1398 |
int i; |
unsigned int i; |
1399 |
|
|
1400 |
BitstreamPad(bs); |
BitstreamPad(bs); |
1401 |
BitstreamPutBits(bs, USERDATA_START_CODE, 32); |
BitstreamPutBits(bs, USERDATA_START_CODE, 32); |
1455 |
|
|
1456 |
if (frame->coding_type == I_VOP) |
if (frame->coding_type == I_VOP) |
1457 |
nbitsresyncmarker = NUMBITS_VP_RESYNC_MARKER; /* 16 zeros followed by a 1. */ |
nbitsresyncmarker = NUMBITS_VP_RESYNC_MARKER; /* 16 zeros followed by a 1. */ |
1458 |
else if (frame->coding_type == P_VOP) |
else if (frame->coding_type == B_VOP) /* B_VOP */ |
1459 |
nbitsresyncmarker = NUMBITS_VP_RESYNC_MARKER-1 + frame->fcode; |
nbitsresyncmarker = MAX(NUMBITS_VP_RESYNC_MARKER+1, NUMBITS_VP_RESYNC_MARKER + MAX(frame->fcode, frame->bcode) - 1); |
1460 |
else /* B_VOP */ |
else /*(frame->coding_type == P_VOP)*/ |
1461 |
nbitsresyncmarker = MAX(NUMBITS_VP_RESYNC_MARKER, NUMBITS_VP_RESYNC_MARKER-1 + MAX(frame->fcode, frame->bcode)); |
nbitsresyncmarker = NUMBITS_VP_RESYNC_MARKER + frame->fcode - 1; |
1462 |
|
|
|
BitstreamPadAlways(bs); |
|
1463 |
BitstreamPutBits(bs, RESYNC_MARKER, nbitsresyncmarker); |
BitstreamPutBits(bs, RESYNC_MARKER, nbitsresyncmarker); |
1464 |
BitstreamPutBits(bs, mbnum, mbnum_bits); |
BitstreamPutBits(bs, mbnum, mbnum_bits); |
1465 |
BitstreamPutBits(bs, frame->quant, 5); |
BitstreamPutBits(bs, frame->quant, 5); |