--- bitstream.c 2003/11/19 15:42:38 1.39.2.19 +++ bitstream.c 2003/12/20 11:54:33 1.39.2.23 @@ -20,7 +20,7 @@ * along with this program ; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: bitstream.c,v 1.39.2.19 2003/11/19 15:42:38 syskin Exp $ + * $Id: bitstream.c,v 1.39.2.23 2003/12/20 11:54:33 Isibaar Exp $ * ****************************************************************************/ @@ -662,9 +662,9 @@ DPRINTF(XVID_DEBUG_HEADER, "load_intra_quant_mat\n"); bs_get_matrix(bs, matrix); - set_intra_matrix(matrix); + set_intra_matrix(dec->mpeg_quant_matrices, matrix); } else - set_intra_matrix(get_default_intra_matrix()); + set_intra_matrix(dec->mpeg_quant_matrices, get_default_intra_matrix()); if (BitstreamGetBit(bs)) /* load_inter_quant_mat */ { @@ -673,9 +673,9 @@ DPRINTF(XVID_DEBUG_HEADER, "load_inter_quant_mat\n"); bs_get_matrix(bs, matrix); - set_inter_matrix(matrix); + set_inter_matrix(dec->mpeg_quant_matrices, matrix); } else - set_inter_matrix(get_default_inter_matrix()); + set_inter_matrix(dec->mpeg_quant_matrices, get_default_inter_matrix()); if (dec->shape == VIDOBJLAY_SHAPE_GRAYSCALE) { DPRINTF(XVID_DEBUG_ERROR, "greyscale matrix not supported\n"); @@ -1016,7 +1016,13 @@ /* read xvid bitstream version */ if(strncmp(tmp, "XviD", 4) == 0) { - sscanf(tmp, "XviD%d", &dec->bs_version); + if (tmp[strlen(tmp)-1] == 'C') { + sscanf(tmp, "XviD%dC", &dec->bs_version); + dec->cartoon_mode = 1; + } + else + sscanf(tmp, "XviD%d", &dec->bs_version); + DPRINTF(XVID_DEBUG_HEADER, "xvid bitstream version=%i", dec->bs_version); } @@ -1053,7 +1059,7 @@ static void bs_put_matrix(Bitstream * bs, - const int16_t * matrix) + const uint16_t * matrix) { int i, j; const int last = matrix[scan_tables[0][63]]; @@ -1075,12 +1081,14 @@ */ void BitstreamWriteVolHeader(Bitstream * const bs, - const MBParam * pParam) + const MBParam * pParam, + const FRAMEINFO * const frame) { static const unsigned int vo_id = 0; static const unsigned int vol_id = 0; int vol_ver_id = 1; int vol_type_ind = VIDOBJLAY_TYPE_SIMPLE; + int vol_profile = pParam->profile; if ( (pParam->vol_flags & XVID_VOL_QUARTERPEL) || (pParam->vol_flags & XVID_VOL_GMC) || @@ -1106,10 +1114,26 @@ * byte aligned, and that always 1-8 padding bits have been written */ - if (pParam->profile) { - BitstreamPutBits(bs, VISOBJSEQ_START_CODE, 32); - BitstreamPutBits(bs, pParam->profile, 8); - } + if (!vol_profile) { + /* Profile was not set by client app, use the more permissive profile + * compatible with the vol_type_id */ + switch(vol_type_ind) { + case VIDOBJLAY_TYPE_ASP: + vol_profile = 0xf5; /* ASP level 5 */ + break; + case VIDOBJLAY_TYPE_ART_SIMPLE: + vol_profile = 0x94; /* ARTS level 4 */ + break; + default: + vol_profile = 0x03; /* Simple level 3 */ + break; + } + } + + /* Write the VOS header */ + BitstreamPutBits(bs, VISOBJSEQ_START_CODE, 32); + BitstreamPutBits(bs, vol_profile, 8); /* profile_and_level_indication */ + /* visual_object_start_code */ BitstreamPad(bs); @@ -1211,16 +1235,13 @@ BitstreamPutBit(bs, pParam->vol_flags & XVID_VOL_MPEGQUANT); if ((pParam->vol_flags & XVID_VOL_MPEGQUANT)) { - BitstreamPutBit(bs, get_intra_matrix_status()); /* load_intra_quant_mat */ - if (get_intra_matrix_status()) { - bs_put_matrix(bs, get_intra_matrix()); - } - - BitstreamPutBit(bs, get_inter_matrix_status()); /* load_inter_quant_mat */ - if (get_inter_matrix_status()) { - bs_put_matrix(bs, get_inter_matrix()); - } - + BitstreamPutBit(bs, is_custom_intra_matrix(pParam->mpeg_quant_matrices)); /* load_intra_quant_mat */ + if(is_custom_intra_matrix(pParam->mpeg_quant_matrices)) + bs_put_matrix(bs, get_intra_matrix(pParam->mpeg_quant_matrices)); + + BitstreamPutBit(bs, is_custom_inter_matrix(pParam->mpeg_quant_matrices)); /* load_inter_quant_mat */ + if(is_custom_inter_matrix(pParam->mpeg_quant_matrices)) + bs_put_matrix(bs, get_inter_matrix(pParam->mpeg_quant_matrices)); } if (vol_ver_id != 1) { @@ -1252,7 +1273,16 @@ /* xvid id */ #define XVID_ID "XviD" XVID_BS_VERSION - BitstreamWriteUserData(bs, XVID_ID, strlen(XVID_ID)); + { + char xvid_id_string[100]; + + if (frame->vop_flags & XVID_VOP_CARTOON) + sprintf(xvid_id_string, "%sC", XVID_ID); + else + sprintf(xvid_id_string, "%s", XVID_ID); + + BitstreamWriteUserData(bs, xvid_id_string, strlen(xvid_id_string)); + } }