640 |
{ |
{ |
641 |
if (dec->fixed_dimensions) |
if (dec->fixed_dimensions) |
642 |
{ |
{ |
643 |
DPRINTF(DPRINTF_ERROR, "decoder width/height does not match bitstream"); |
DPRINTF(DPRINTF_ERROR, "XVID_DEC_PARAM width/height does not match bitstream"); |
644 |
return -1; |
return -1; |
645 |
} |
} |
646 |
resize = 1; |
resize = 1; |
1068 |
BitstreamSkip(bs, 8); |
BitstreamSkip(bs, 8); |
1069 |
} |
} |
1070 |
|
|
1071 |
DPRINTF(DPRINTF_STARTCODE, "<user_data>: %s", 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); |
1129 |
*/ |
*/ |
1130 |
void |
void |
1131 |
BitstreamWriteVolHeader(Bitstream * const bs, |
BitstreamWriteVolHeader(Bitstream * const bs, |
1132 |
const MBParam * pParam) |
const MBParam * pParam, |
1133 |
|
const FRAMEINFO * const frame) |
1134 |
{ |
{ |
1135 |
static const unsigned int vo_id = 0; |
static const unsigned int vo_id = 0; |
1136 |
static const unsigned int vol_id = 0; |
static const unsigned int vol_id = 0; |
1137 |
int vol_ver_id=1; |
int vol_ver_id=1; |
1138 |
int profile = 0x03; /* simple profile/level 3 */ |
int profile = 0x03; /* simple profile/level 3 */ |
1139 |
|
|
1140 |
if ( (pParam->vol_flags & XVID_QUARTERPEL) || |
if ( pParam->m_quarterpel || (frame->global_flags & XVID_GMC) || |
1141 |
(pParam->vol_flags & XVID_GMC) || |
(pParam->global & XVID_GLOBAL_REDUCED)) |
|
(pParam->vol_flags & XVID_REDUCED_ENABLE)) |
|
1142 |
vol_ver_id = 2; |
vol_ver_id = 2; |
1143 |
|
|
1144 |
if ((pParam->vol_flags & XVID_REDUCED_ENABLE)) |
if ((pParam->global & XVID_GLOBAL_REDUCED)) |
1145 |
profile = 0x93; /* advanced realtime simple profile/level 3 */ |
profile = 0x93; /* advanced realtime simple profile/level 3 */ |
1146 |
|
|
1147 |
if ((pParam->vol_flags & XVID_QUARTERPEL) || |
if (pParam->m_quarterpel || (frame->global_flags & XVID_GMC)) |
|
(pParam->vol_flags & XVID_GMC)) |
|
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 |
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 |
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) |
1212 |
|
|
1213 |
WRITE_MARKER(); |
WRITE_MARKER(); |
1214 |
|
|
|
if (pParam->fincr>0) { |
|
1215 |
BitstreamPutBit(bs, 1); // fixed_vop_rate = 1 |
BitstreamPutBit(bs, 1); // fixed_vop_rate = 1 |
1216 |
BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase)); // fixed_vop_time_increment |
BitstreamPutBits(bs, pParam->fincr, log2bin(pParam->fbase)); // fixed_vop_time_increment |
|
}else{ |
|
|
BitstreamPutBit(bs, 0); // fixed_vop_rate = 0 |
|
|
} |
|
1217 |
|
|
1218 |
WRITE_MARKER(); |
WRITE_MARKER(); |
1219 |
BitstreamPutBits(bs, pParam->width, 13); // width |
BitstreamPutBits(bs, pParam->width, 13); // width |
1221 |
BitstreamPutBits(bs, pParam->height, 13); // height |
BitstreamPutBits(bs, pParam->height, 13); // height |
1222 |
WRITE_MARKER(); |
WRITE_MARKER(); |
1223 |
|
|
1224 |
BitstreamPutBit(bs, pParam->vol_flags & XVID_INTERLACING); // interlace |
BitstreamPutBit(bs, frame->global_flags & XVID_INTERLACING); // interlace |
1225 |
BitstreamPutBit(bs, 1); // obmc_disable (overlapped block motion compensation) |
BitstreamPutBit(bs, 1); // obmc_disable (overlapped block motion compensation) |
1226 |
|
|
1227 |
if (vol_ver_id != 1) |
if (vol_ver_id != 1) |
1228 |
{ if ((pParam->vol_flags & XVID_GMC)) |
{ if (frame->global_flags & XVID_GMC) |
1229 |
{ BitstreamPutBits(bs, 2, 2); // sprite_enable=='GMC' |
{ BitstreamPutBits(bs, 2, 2); // sprite_enable=='GMC' |
1230 |
BitstreamPutBits(bs, 2, 6); // no_of_sprite_warping_points |
BitstreamPutBits(bs, 2, 6); // no_of_sprite_warping_points |
1231 |
BitstreamPutBits(bs, 3, 2); // sprite_warping_accuracy 0==1/2, 1=1/4, 2=1/8, 3=1/16 |
BitstreamPutBits(bs, 3, 2); // sprite_warping_accuracy 0==1/2, 1=1/4, 2=1/8, 3=1/16 |
1243 |
BitstreamPutBit(bs, 0); // not_8_bit |
BitstreamPutBit(bs, 0); // not_8_bit |
1244 |
|
|
1245 |
// quant_type 0=h.263 1=mpeg4(quantizer tables) |
// quant_type 0=h.263 1=mpeg4(quantizer tables) |
1246 |
BitstreamPutBit(bs, pParam->vol_flags & XVID_MPEGQUANT); |
BitstreamPutBit(bs, pParam->m_quant_type); |
1247 |
|
|
1248 |
if ((pParam->vol_flags & XVID_MPEGQUANT)) { |
if (pParam->m_quant_type) { |
1249 |
BitstreamPutBit(bs, get_intra_matrix_status()); // load_intra_quant_mat |
BitstreamPutBit(bs, get_intra_matrix_status()); // load_intra_quant_mat |
1250 |
if (get_intra_matrix_status()) { |
if (get_intra_matrix_status()) { |
1251 |
bs_put_matrix(bs, get_intra_matrix()); |
bs_put_matrix(bs, get_intra_matrix()); |
1259 |
} |
} |
1260 |
|
|
1261 |
if (vol_ver_id != 1) { |
if (vol_ver_id != 1) { |
1262 |
if ((pParam->vol_flags & XVID_QUARTERPEL)) |
if (pParam->m_quarterpel) |
1263 |
BitstreamPutBit(bs, 1); // quarterpel |
BitstreamPutBit(bs, 1); // quarterpel |
1264 |
else |
else |
1265 |
BitstreamPutBit(bs, 0); // no quarterpel |
BitstreamPutBit(bs, 0); // no quarterpel |
1273 |
{ |
{ |
1274 |
BitstreamPutBit(bs, 0); // newpred_enable |
BitstreamPutBit(bs, 0); // newpred_enable |
1275 |
|
|
1276 |
BitstreamPutBit(bs, (pParam->vol_flags & XVID_REDUCED_ENABLE)?1:0); |
BitstreamPutBit(bs, (pParam->global & XVID_GLOBAL_REDUCED)?1:0); |
1277 |
/* reduced_resolution_vop_enabled */ |
/* reduced_resolution_vop_enabled */ |
1278 |
} |
} |
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 */ |
/* fake divx5 id, to ensure compatibility with divx5 decoder */ |
1285 |
#define DIVX5_ID "DivX000b000p" |
#define DIVX5_ID "DivX501b481p" |
1286 |
if (pParam->max_bframes > 0 && (pParam->global_flags & XVID_PACKED)) { |
if (pParam->max_bframes > 0 && (pParam->global & XVID_GLOBAL_PACKED)) { |
1287 |
BitstreamWriteUserData(bs, DIVX5_ID, strlen(DIVX5_ID)); |
BitstreamWriteUserData(bs, DIVX5_ID, strlen(DIVX5_ID)); |
1288 |
} |
} |
1289 |
|
|
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 |
|
|
1348 |
if ( (frame->coding_type == P_VOP) || (frame->coding_type == S_VOP) ) |
if ( (frame->coding_type == P_VOP) || (frame->coding_type == S_VOP) ) |
1349 |
BitstreamPutBits(bs, frame->rounding_type, 1); |
BitstreamPutBits(bs, frame->rounding_type, 1); |
1350 |
|
|
1351 |
if ((frame->vol_flags & XVID_REDUCED_ENABLE)) |
if ((pParam->global & XVID_GLOBAL_REDUCED)) |
1352 |
BitstreamPutBit(bs, (frame->vop_flags & XVID_REDUCED)?1:0); |
BitstreamPutBit(bs, (frame->global_flags & XVID_REDUCED)?1:0); |
1353 |
|
|
1354 |
BitstreamPutBits(bs, 0, 3); // intra_dc_vlc_threshold |
BitstreamPutBits(bs, 0, 3); // intra_dc_vlc_threshold |
1355 |
|
|
1356 |
if ((frame->vol_flags & XVID_INTERLACING)) { |
if (frame->global_flags & XVID_INTERLACING) { |
1357 |
BitstreamPutBit(bs, (frame->vop_flags & XVID_TOPFIELDFIRST)); |
BitstreamPutBit(bs, (frame->global_flags & XVID_TOPFIELDFIRST)); |
1358 |
BitstreamPutBit(bs, (frame->vop_flags & XVID_ALTERNATESCAN)); |
BitstreamPutBit(bs, (frame->global_flags & XVID_ALTERNATESCAN)); |
1359 |
} |
} |
1360 |
|
|
1361 |
if (frame->coding_type == S_VOP) { |
if (frame->coding_type == S_VOP) { |
1369 |
bs_put_spritetrajectory(bs, frame->warp.duv[k].y ); // dv[k] |
bs_put_spritetrajectory(bs, frame->warp.duv[k].y ); // dv[k] |
1370 |
WRITE_MARKER(); |
WRITE_MARKER(); |
1371 |
|
|
1372 |
if ((frame->vol_flags & XVID_QUARTERPEL)) |
if (pParam->m_quarterpel) |
1373 |
{ |
{ |
1374 |
DPRINTF(DPRINTF_HEADER,"sprite_warping_point[%i] xy=(%i,%i) *QPEL*", k, frame->warp.duv[k].x/2, frame->warp.duv[k].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 |
} |
} |