GF_Err gf_odf_read_esd_remove(GF_BitStream *bs, GF_ESDRemove *esdRem, u32 gf_odf_size_command) { u32 i = 0; if (!esdRem) return GF_BAD_PARAM; esdRem->ODID = gf_bs_read_int(bs, 10); /*aligned = */gf_bs_read_int(bs, 6); //aligned //we have gf_odf_size_command - 2 bytes left, and this is our ES_ID[1...255] //this works because OD commands are aligned if (gf_odf_size_command < 2) return GF_ODF_INVALID_DESCRIPTOR; if (gf_odf_size_command == 2) { esdRem->NbESDs = 0; esdRem->ES_ID = NULL; return GF_OK; } esdRem->NbESDs = (gf_odf_size_command - 2) / 2; esdRem->ES_ID = (u16 *)gf_malloc(sizeof(u16) * esdRem->NbESDs); if (!esdRem->ES_ID) return GF_OUT_OF_MEM; for (i = 0; i < esdRem->NbESDs; i++) { esdRem->ES_ID[i] = gf_bs_read_int(bs, 16); } //OD commands are aligned (but we should already be aligned.... /*nbBits = */gf_bs_align(bs); return GF_OK; }
static Bool bit_out_psc_layer(GF_AADecoder *dec) { s32 v; if (gf_bs_bits_available(dec->bs) ) { v = gf_bs_read_int(dec->bs, 1) ? 1 : 0; dec->read_bits++; } else { v = (dec->zero_run == AAM_MAX_FREQ) ? 1 : 0; dec->skip_bits++; } if (dec->zero_run == AAM_ZEROMAX) { if (!v) return 0; v = gf_bs_read_int(dec->bs, 1) ? 1 : 0; dec->zero_run = 0; dec->read_bits++; dec->used_bits++; } dec->Bit = v; dec->needs_flush = 1; if (!dec->Bit) dec->zero_run++; else dec->zero_run = 0; return 1; }
GF_Err tenc_Read(GF_Box *s, GF_BitStream *bs) { GF_Err e; GF_TrackEncryptionBox *ptr = (GF_TrackEncryptionBox*)s; e = gf_isom_full_box_read(s, bs); if (e) return e; gf_bs_read_u8(bs); //reserved if (!ptr->version) { gf_bs_read_u8(bs); //reserved } else { ptr->crypt_byte_block = gf_bs_read_int(bs, 4); ptr->skip_byte_block = gf_bs_read_int(bs, 4); } ptr->isProtected = gf_bs_read_u8(bs); ptr->Per_Sample_IV_Size = gf_bs_read_u8(bs); gf_bs_read_data(bs, (char *)ptr->KID, 16); ptr->size -= 20; if ((ptr->isProtected == 1) && !ptr->Per_Sample_IV_Size) { ptr->constant_IV_size = gf_bs_read_u8(bs); gf_bs_read_data(bs, (char *)ptr->constant_IV, ptr->constant_IV_size); ptr->size -= 1 + ptr->constant_IV_size; } return GF_OK; }
void SFS_SwitchStatement(ScriptParser *parser) { u32 numBits, caseValue; if (parser->codec->LastError) return; SFS_AddString(parser, "switch ("); SFS_CompoundExpression(parser); SFS_AddString(parser, ")"); SFS_AddString(parser, "{"); SFS_Line(parser); numBits = gf_bs_read_int(parser->bs, 5); do { SFS_Indent(parser); SFS_AddString(parser, "case "); caseValue = gf_bs_read_int(parser->bs, numBits); SFS_AddInt(parser, caseValue); SFS_AddString(parser, ":"); SFS_Line(parser); SFS_Indent(parser); SFS_StatementBlock(parser, 0); SFS_Line(parser); } while (gf_bs_read_int(parser->bs, 1)); //default if (gf_bs_read_int(parser->bs, 1)) { SFS_AddString(parser, "default:"); SFS_Line(parser); SFS_StatementBlock(parser, 0); } SFS_AddString(parser, "}"); }
void SFS_StatementBlock(ScriptParser *parser, Bool funcBody) { if (parser->codec->LastError) return; if (gf_bs_read_int(parser->bs, 1)) { SFS_AddString(parser, "{"); SFS_IncIndent(parser); while (gf_bs_read_int(parser->bs, 1)) { SFS_Line(parser); SFS_Indent(parser); SFS_Statement(parser); } SFS_DecIndent(parser); SFS_Line(parser); SFS_Indent(parser); SFS_AddString(parser, "}"); } else if (funcBody) { SFS_AddString(parser, "{"); SFS_Statement(parser); SFS_AddString(parser, "}"); } else { SFS_Statement(parser); } }
GF_Err tenc_Read(GF_Box *s, GF_BitStream *bs) { GF_TrackEncryptionBox *ptr = (GF_TrackEncryptionBox*)s; gf_bs_read_u8(bs); //reserved if (!ptr->version) { gf_bs_read_u8(bs); //reserved } else { ptr->crypt_byte_block = gf_bs_read_int(bs, 4); ptr->skip_byte_block = gf_bs_read_int(bs, 4); } ptr->isProtected = gf_bs_read_u8(bs); ptr->Per_Sample_IV_Size = gf_bs_read_u8(bs); gf_bs_read_data(bs, (char *) ptr->KID, 16); ISOM_DECREASE_SIZE(ptr, 20); if ((ptr->isProtected == 1) && !ptr->Per_Sample_IV_Size) { ptr->constant_IV_size = gf_bs_read_u8(bs); gf_bs_read_data(bs, (char *) ptr->constant_IV, ptr->constant_IV_size); ISOM_DECREASE_SIZE(ptr, (1 + ptr->constant_IV_size) ); } return GF_OK; }
void SFS_GetNumber(ScriptParser *parser) { u32 val, nbBits; if (parser->codec->LastError) return; // integer if (gf_bs_read_int(parser->bs, 1)) { nbBits = gf_bs_read_int(parser->bs, 5); val = gf_bs_read_int(parser->bs, nbBits); SFS_AddInt(parser, val); return; } // real number val = gf_bs_read_int(parser->bs, 4); while ( val != 15) { if (val<=9) { SFS_AddChar(parser, (char) (val + '0') ); } else if (val==10) { SFS_AddChar(parser, '.'); } else if (val==11) { SFS_AddChar(parser, 'E'); } else if (val==12){ SFS_AddChar(parser, '-'); } val = gf_bs_read_int(parser->bs, 4); } }
GF_Err avcc_Read(GF_Box *s, GF_BitStream *bs) { u32 i, count; GF_AVCConfigurationBox *ptr = (GF_AVCConfigurationBox *)s; if (ptr->config) gf_odf_avc_cfg_del(ptr->config); ptr->config = gf_odf_avc_cfg_new(); ptr->config->configurationVersion = gf_bs_read_u8(bs); ptr->config->AVCProfileIndication = gf_bs_read_u8(bs); ptr->config->profile_compatibility = gf_bs_read_u8(bs); ptr->config->AVCLevelIndication = gf_bs_read_u8(bs); gf_bs_read_int(bs, 6); ptr->config->nal_unit_size = 1 + gf_bs_read_int(bs, 2); gf_bs_read_int(bs, 3); count = gf_bs_read_int(bs, 5); for (i=0; i<count; i++) { GF_AVCConfigSlot *sl = (GF_AVCConfigSlot *) malloc(sizeof(GF_AVCConfigSlot)); sl->size = gf_bs_read_u16(bs); sl->data = (char *)malloc(sizeof(char) * sl->size); gf_bs_read_data(bs, sl->data, sl->size); gf_list_add(ptr->config->sequenceParameterSets, sl); } count = gf_bs_read_u8(bs); for (i=0; i<count; i++) { GF_AVCConfigSlot *sl = (GF_AVCConfigSlot *)malloc(sizeof(GF_AVCConfigSlot)); sl->size = gf_bs_read_u16(bs); sl->data = (char *)malloc(sizeof(char) * sl->size); gf_bs_read_data(bs, sl->data, sl->size); gf_list_add(ptr->config->pictureParameterSets, sl); } return GF_OK; }
GF_Err BM_ParseDelete(GF_BifsDecoder *codec, GF_BitStream *bs, GF_List *com_list) { u8 type; u32 ID; GF_Command *com; GF_Node *n; type = gf_bs_read_int(bs, 2); switch (type) { case 0: ID = 1+gf_bs_read_int(bs, codec->info->config.NodeIDBits); n = gf_sg_find_node(codec->current_graph, ID); if (!n) return GF_OK; com = gf_sg_command_new(codec->current_graph, GF_SG_NODE_DELETE); BM_SetCommandNode(com, n); gf_list_add(com_list, com); return GF_OK; case 2: return BM_ParseIndexDelete(codec, bs, com_list); case 3: com = gf_sg_command_new(codec->current_graph, GF_SG_ROUTE_DELETE); com->RouteID = 1+gf_bs_read_int(bs, codec->info->config.RouteIDBits); gf_list_add(com_list, com); return GF_OK; default: return GF_NON_COMPLIANT_BITSTREAM; } return GF_OK; }
//SFRotation and SFVec3f are quantized as normalized vectors ,mapped on a cube //in the UnitSphere (R=1.0) GF_Err Q_DecCoordOnUnitSphere(GF_BifsDecoder *codec, GF_BitStream *bs, u32 NbBits, u32 NbComp, Fixed *m_ft) { u32 i, orient, sign; s32 value; Fixed tang[4], delta; s32 dir; if (NbComp != 2 && NbComp != 3) return GF_BAD_PARAM; //only 2 or 3 comp in the quantized version dir = 1; if(NbComp == 2) dir -= 2 * gf_bs_read_int(bs, 1); orient = gf_bs_read_int(bs, 2); for(i=0; i<NbComp; i++) { value = gf_bs_read_int(bs, NbBits) - (1 << (NbBits-1) ); sign = (value >= 0) ? 1 : -1; m_ft[i] = sign * Q_InverseQuantize(0, 1, NbBits-1, sign*value); } delta = 1; for (i=0; i<NbComp; i++) { tang[i] = gf_tan(gf_mulfix(GF_PI/4, m_ft[i]) ); delta += gf_mulfix(tang[i], tang[i]); } delta = gf_divfix(INT2FIX(dir), gf_sqrt(delta) ); m_ft[orient] = delta; for (i=0; i<NbComp; i++) { m_ft[ (orient + i+1) % (NbComp+1) ] = gf_mulfix(tang[i], delta); } return GF_OK; }
GF_Err BM_ParseIndexValueReplace(GF_BifsDecoder *codec, GF_BitStream *bs, GF_List *com_list) { u32 NodeID, ind, field_ind, NumBits; s32 type, pos; GF_Command *com; GF_Node *node; GF_Err e; GF_FieldInfo field, sffield; GF_CommandField *inf; /*get the node*/ NodeID = 1 + gf_bs_read_int(bs, codec->info->config.NodeIDBits); node = gf_sg_find_node(codec->current_graph, NodeID); if (!node) return GF_NON_COMPLIANT_BITSTREAM; NumBits = gf_get_bit_size(gf_node_get_num_fields_in_mode(node, GF_SG_FIELD_CODING_IN)-1); ind = gf_bs_read_int(bs, NumBits); e = gf_bifs_get_field_index(node, ind, GF_SG_FIELD_CODING_IN, &field_ind); if (e) return e; e = gf_node_get_field(node, field_ind, &field); if (gf_sg_vrml_is_sf_field(field.fieldType)) return GF_NON_COMPLIANT_BITSTREAM; type = gf_bs_read_int(bs, 2); switch (type) { case 0: pos = gf_bs_read_int(bs, 16); break; case 2: pos = 0; break; case 3: pos = ((GenMFField *) field.far_ptr)->count - 1; break; default: return GF_NON_COMPLIANT_BITSTREAM; } com = gf_sg_command_new(codec->current_graph, GF_SG_INDEXED_REPLACE); BM_SetCommandNode(com, node); inf = gf_sg_command_field_new(com); inf->fieldIndex = field.fieldIndex; inf->pos = pos; if (field.fieldType == GF_SG_VRML_MFNODE) { inf->fieldType = GF_SG_VRML_SFNODE; inf->new_node = gf_bifs_dec_node(codec, bs, field.NDTtype); inf->field_ptr = &inf->new_node; if (inf->new_node) gf_node_register(inf->new_node, NULL); } else { memcpy(&sffield, &field, sizeof(GF_FieldInfo)); sffield.fieldType = gf_sg_vrml_get_sf_type(field.fieldType); inf->fieldType = sffield.fieldType; sffield.far_ptr = inf->field_ptr = gf_sg_vrml_field_pointer_new(sffield.fieldType); codec->LastError = gf_bifs_dec_sf_field(codec, bs, node, &sffield, 1); } gf_list_add(com_list, com); return codec->LastError; }
GF_Err gf_bifs_dec_field(GF_BifsDecoder * codec, GF_BitStream *bs, GF_Node *node, GF_FieldInfo *field, Bool is_mem_com) { GF_Err e; u8 flag; // if (codec->LastError) return codec->LastError; assert(node); // if (field->fieldType == GF_SG_VRML_UNKNOWN) return GF_NON_COMPLIANT_BITSTREAM; if (gf_sg_vrml_is_sf_field(field->fieldType)) { e = gf_bifs_dec_sf_field(codec, bs, node, field, is_mem_com); if (e) return e; } else { /*clean up the eventIn field if not done*/ if (field->eventType == GF_SG_EVENT_IN) { if (field->fieldType == GF_SG_VRML_MFNODE) { gf_node_unregister_children(node, * (GF_ChildNodeItem **)field->far_ptr); * (GF_ChildNodeItem **)field->far_ptr = NULL; } else { //remove all items of the MFField gf_sg_vrml_mf_reset(field->far_ptr, field->fieldType); } } /*predictiveMFField*/ if (codec->info->config.UsePredictiveMFField) { flag = gf_bs_read_int(bs, 1); if (flag) { GF_LOG(GF_LOG_WARNING, GF_LOG_CODING, ("[BIFS] Stream uses Predictive Field Coding!\n")); #ifdef GPAC_ENABLE_BIFS_PMF return gf_bifs_dec_pred_mf_field(codec, bs, node, field); #else return GF_NOT_SUPPORTED; #endif } } /*reserved*/ flag = gf_bs_read_int(bs, 1); if (!flag) { /*destroy the field content...*/ if (field->fieldType != GF_SG_VRML_MFNODE) { e = gf_sg_vrml_mf_reset(field->far_ptr, field->fieldType); if (e) return e; } /*List description - alloc is dynamic*/ flag = gf_bs_read_int(bs, 1); if (flag) { e = BD_DecMFFieldList(codec, bs, node, field, is_mem_com); } else { e = BD_DecMFFieldVec(codec, bs, node, field, is_mem_com); } if (e) return e; } } return GF_OK; }
GF_Err iSFM_Read(GF_Box *s, GF_BitStream *bs) { GF_ISMASampleFormatBox *ptr = (GF_ISMASampleFormatBox *)s; ptr->selective_encryption = gf_bs_read_int(bs, 1); gf_bs_read_int(bs, 7); ptr->key_indicator_length = gf_bs_read_u8(bs); ptr->IV_length = gf_bs_read_u8(bs); return GF_OK; }
GF_Err Q_DecFloat(GF_BifsDecoder *codec, GF_BitStream *bs, u32 FieldType, SFVec3f BMin, SFVec3f BMax, u32 NbBits, void *field_ptr) { switch (FieldType) { case GF_SG_VRML_SFINT32: return GF_NON_COMPLIANT_BITSTREAM; case GF_SG_VRML_SFFLOAT: *((SFFloat *)field_ptr) = Q_InverseQuantize(BMin.x, BMax.x, NbBits, gf_bs_read_int(bs, NbBits)); return GF_OK; case GF_SG_VRML_SFVEC2F: ((SFVec2f *)field_ptr)->x = Q_InverseQuantize(BMin.x, BMax.x, NbBits, gf_bs_read_int(bs, NbBits)); ((SFVec2f *)field_ptr)->y = Q_InverseQuantize(BMin.y, BMax.y, NbBits, gf_bs_read_int(bs, NbBits)); return GF_OK; case GF_SG_VRML_SFVEC3F: ((SFVec3f *)field_ptr)->x = Q_InverseQuantize(BMin.x, BMax.x, NbBits, gf_bs_read_int(bs, NbBits)); ((SFVec3f *)field_ptr)->y = Q_InverseQuantize(BMin.y, BMax.y, NbBits, gf_bs_read_int(bs, NbBits)); ((SFVec3f *)field_ptr)->z = Q_InverseQuantize(BMin.z, BMax.z, NbBits, gf_bs_read_int(bs, NbBits)); return GF_OK; case GF_SG_VRML_SFCOLOR: ((SFColor *)field_ptr)->red = Q_InverseQuantize(BMin.x, BMax.x, NbBits, gf_bs_read_int(bs, NbBits)); ((SFColor *)field_ptr)->green = Q_InverseQuantize(BMin.y, BMax.y, NbBits, gf_bs_read_int(bs, NbBits)); ((SFColor *)field_ptr)->blue = Q_InverseQuantize(BMin.z, BMax.z, NbBits, gf_bs_read_int(bs, NbBits)); return GF_OK; case GF_SG_VRML_SFROTATION: //forbidden in this Q mode return GF_NON_COMPLIANT_BITSTREAM; } return GF_OK; }
void SFS_Params(ScriptParser *parser) { u32 val; if (parser->codec->LastError) return; val = gf_bs_read_int(parser->bs, 1); while (val) { SFS_Expression(parser); val = gf_bs_read_int(parser->bs, 1); if(val) SFS_AddString(parser, ","); } }
GF_Err iSFM_Read(GF_Box *s, GF_BitStream *bs) { GF_Err e; GF_ISMASampleFormatBox *ptr = (GF_ISMASampleFormatBox *)s; if (ptr == NULL) return GF_BAD_PARAM; e = gf_isom_full_box_read(s, bs); if (e) return e; ptr->selective_encryption = gf_bs_read_int(bs, 1); gf_bs_read_int(bs, 7); ptr->key_indicator_length = gf_bs_read_u8(bs); ptr->IV_length = gf_bs_read_u8(bs); return GF_OK; }
GF_ISMASample *gf_isom_ismacryp_sample_from_data(char *data, u32 dataLength, Bool use_selective_encryption, u8 KI_length, u8 IV_length) { GF_ISMASample *s; GF_BitStream *bs; /*empty text sample*/ if (!data || !dataLength) { return gf_isom_ismacryp_new_sample(); } s = gf_isom_ismacryp_new_sample(); /*empty sample*/ if (!data || !dataLength) return s; bs = gf_bs_new(data, dataLength, GF_BITSTREAM_READ); s->dataLength = dataLength; s->IV_length = IV_length; s->KI_length = KI_length; if (use_selective_encryption) { s->flags = GF_ISOM_ISMA_USE_SEL_ENC; if (s->dataLength < 1) goto exit; if (gf_bs_read_int(bs, 1)) s->flags |= GF_ISOM_ISMA_IS_ENCRYPTED; gf_bs_read_int(bs, 7); s->dataLength -= 1; } else { s->flags = GF_ISOM_ISMA_IS_ENCRYPTED; } if (s->flags & GF_ISOM_ISMA_IS_ENCRYPTED) { if (IV_length != 0) { if (s->dataLength < IV_length) goto exit; s->IV = gf_bs_read_long_int(bs, 8*IV_length); s->dataLength -= IV_length; } if (KI_length) { if (s->dataLength < KI_length) goto exit; s->key_indicator = (u8 *)malloc(KI_length); gf_bs_read_data(bs, (char*)s->key_indicator, KI_length); s->dataLength -= KI_length; } } s->data = (char*)malloc(sizeof(char)*s->dataLength); gf_bs_read_data(bs, s->data, s->dataLength); gf_bs_del(bs); return s; exit: gf_isom_ismacryp_delete_sample(s); return NULL; }
GF_Err gf_bifs_dec_node_mask(GF_BifsDecoder * codec, GF_BitStream *bs, GF_Node *node, Bool is_proto) { u32 i, numFields, numProtoFields, index, flag, nbBits; GF_Err e; GF_FieldInfo field; //proto coding if (codec->pCurrentProto) { numFields = gf_node_get_num_fields_in_mode(node, GF_SG_FIELD_CODING_ALL); numProtoFields = gf_sg_proto_get_field_count(codec->pCurrentProto); nbBits = gf_get_bit_size(numProtoFields-1); for (i=0; i<numFields; i++) { flag = gf_bs_read_int(bs, 1); if (!flag) continue; flag = gf_bs_read_int(bs, 1); //IS'ed field, create route for binding to Proto declaration if (flag) { //reference index of our IS'ed proto field flag = gf_bs_read_int(bs, nbBits); e = gf_node_get_field(node, i, &field); if (e) return e; e = BD_SetProtoISed(codec, flag, node, i); } //regular field, parse it (nb: no contextual coding for protos in maskNode, //all node fields are coded else { e = gf_node_get_field(node, i, &field); if (e) return e; e = gf_bifs_dec_field(codec, bs, node, &field, 0); } if (e) return e; } } //regular coding else { numFields = gf_node_get_num_fields_in_mode(node, GF_SG_FIELD_CODING_DEF); for (i=0; i<numFields; i++) { flag = gf_bs_read_int(bs, 1); if (!flag) continue; gf_bifs_get_field_index(node, i, GF_SG_FIELD_CODING_DEF, &index); e = gf_node_get_field(node, index, &field); if (e) return e; e = gf_bifs_dec_field(codec, bs, node, &field, 0); if (e) return e; if (is_proto) gf_sg_proto_mark_field_loaded(node, &field); } } return GF_OK; }
void SFS_Arguments(ScriptParser *parser, Bool is_var) { u32 val; if (parser->codec->LastError) return; if (!is_var) SFS_AddString(parser, "("); val = gf_bs_read_int(parser->bs, 1); while (val) { SFS_Identifier(parser); val = gf_bs_read_int(parser->bs, 1); if (val) SFS_AddString(parser, ","); } if (!is_var) SFS_AddString(parser, ")"); }
GF_Err gf_odf_read_esd_update(GF_BitStream *bs, GF_ESDUpdate *esdUp, u32 gf_odf_size_command) { GF_Descriptor *tmp; u32 tmpSize = 0, nbBits = 0; GF_Err e = GF_OK; if (!esdUp) return GF_BAD_PARAM; esdUp->ODID = gf_bs_read_int(bs, 10); nbBits += 10; //very tricky, we're at the bit level here... while (1) { e = gf_odf_parse_descriptor(bs, &tmp, &tmpSize); if (e) return e; e = AddToESDUpdate(esdUp, tmp); if (e) return e; nbBits += (tmpSize + gf_odf_size_field_size(tmpSize)) * 8; //our com is aligned, so nbBits is between (gf_odf_size_command-1)*8 and gf_odf_size_command*8 if (((nbBits >(gf_odf_size_command - 1) * 8) && (nbBits <= gf_odf_size_command * 8)) || (nbBits > gf_odf_size_command * 8)) { //this one is a security break break; } } if (nbBits > gf_odf_size_command * 8) return GF_ODF_INVALID_COMMAND; //Align our bitstream nbBits += gf_bs_align(bs); if (nbBits != gf_odf_size_command * 8) return GF_ODF_INVALID_COMMAND; return e; }
GF_Err piff_psec_Read(GF_Box *s, GF_BitStream *bs) { //u32 sample_count; GF_SampleEncryptionBox *ptr = (GF_SampleEncryptionBox *)s; if (ptr->size<4) return GF_ISOM_INVALID_FILE; ptr->version = gf_bs_read_u8(bs); ptr->flags = gf_bs_read_u24(bs); ISOM_DECREASE_SIZE(ptr, 4); if (ptr->flags & 1) { ptr->AlgorithmID = gf_bs_read_int(bs, 24); ptr->IV_size = gf_bs_read_u8(bs); gf_bs_read_data(bs, (char *) ptr->KID, 16); ISOM_DECREASE_SIZE(ptr, 20); } if (ptr->IV_size == 0) ptr->IV_size = 8; //default to 8 ptr->bs_offset = gf_bs_get_position(bs); /*sample_count = */gf_bs_read_u32(bs); ISOM_DECREASE_SIZE(ptr, 4); if (ptr->IV_size != 8 && ptr->IV_size != 16) { GF_LOG(GF_LOG_WARNING, GF_LOG_CONTAINER, ("[iso file] PIFF PSEC box incorrect IV size: %u - shall be 8 or 16\n", ptr->IV_size)); return GF_BAD_PARAM; } //as for senc, we skip parsing of the box until we have all saiz/saio info ptr->size = 0; return GF_OK; }
// // Reader // GF_Err gf_odf_read_qos(GF_BitStream *bs, GF_QoS_Descriptor *qos, u32 DescSize) { GF_Err e; GF_QoS_Default *tmp; u32 tmp_size, nbBytes = 0; if (!qos) return GF_BAD_PARAM; qos->predefined = gf_bs_read_int(bs, 8); nbBytes += 1; if (qos->predefined) { if (nbBytes != DescSize) return GF_ODF_INVALID_DESCRIPTOR; return GF_OK; } while (nbBytes < DescSize) { tmp = NULL; e = gf_odf_parse_qos(bs, &tmp, &tmp_size); if (!tmp) return GF_ODF_INVALID_DESCRIPTOR; e = gf_list_add(qos->QoS_Qualifiers, tmp); if (e) return e; nbBytes += tmp_size; } if (nbBytes != DescSize) return GF_ODF_INVALID_DESCRIPTOR; return GF_OK; }
void SFS_OptionalExpression(ScriptParser *parser) { if (parser->codec->LastError) return; if (gf_bs_read_int(parser->bs, 1)) { SFS_CompoundExpression(parser); } }
void SFS_Statement(ScriptParser *parser) { u32 val; if (parser->codec->LastError) return; val = gf_bs_read_int(parser->bs, NUMBITS_STATEMENT); switch (val) { case ST_IF: SFS_IfStatement(parser); break; case ST_FOR: SFS_ForStatement(parser); break; case ST_WHILE: SFS_WhileStatement(parser); break; case ST_RETURN: SFS_ReturnStatement(parser); break; case ST_BREAK: SFS_AddString(parser, "break;"); break; case ST_CONTINUE: SFS_AddString(parser, "continue;"); break; case ST_COMPOUND_EXPR: SFS_CompoundExpression(parser); SFS_AddString(parser, ";"); break; case ST_SWITCH: SFS_SwitchStatement(parser); break; } }
void SFS_CompoundExpression(ScriptParser *parser) { if (parser->codec->LastError) return; SFS_Expression(parser); if (! gf_bs_read_int(parser->bs, 1)) return; SFS_AddString(parser, ","); SFS_CompoundExpression(parser); }
GF_Err BM_ParseIndexDelete(GF_BifsDecoder *codec, GF_BitStream *bs, GF_List *com_list) { u32 NodeID, NumBits, ind, field_ind; s32 pos; GF_Command *com; u8 type; GF_Node *node; GF_Err e; GF_CommandField *inf; GF_FieldInfo field; NodeID = 1 + gf_bs_read_int(bs, codec->info->config.NodeIDBits); node = gf_sg_find_node(codec->current_graph, NodeID); if (!node) return GF_NON_COMPLIANT_BITSTREAM; NumBits = gf_get_bit_size(gf_node_get_num_fields_in_mode(node, GF_SG_FIELD_CODING_IN) - 1); ind = gf_bs_read_int(bs, NumBits); type = gf_bs_read_int(bs, 2); switch (type) { case 0: pos = (u32) gf_bs_read_int(bs, 16); break; case 2: pos = 0; break; case 3: pos = -1; break; default: return GF_NON_COMPLIANT_BITSTREAM; } e = gf_bifs_get_field_index(node, ind, GF_SG_FIELD_CODING_IN, &field_ind); if (e) return e; e = gf_node_get_field(node, field_ind, &field); if (e) return e; if (gf_sg_vrml_is_sf_field(field.fieldType)) return GF_NON_COMPLIANT_BITSTREAM; com = gf_sg_command_new(codec->current_graph, GF_SG_INDEXED_DELETE); BM_SetCommandNode(com, node); inf = gf_sg_command_field_new(com); inf->pos = pos; inf->fieldIndex = field.fieldIndex; inf->fieldType = gf_sg_vrml_get_sf_type(field.fieldType); gf_list_add(com_list, com); return codec->LastError; }
static GF_Err BM_ParseProtoDelete(GF_BifsDecoder *codec, GF_BitStream *bs, GF_List *com_list) { u32 flag, count; GF_Command *com = gf_sg_command_new(codec->current_graph, GF_SG_PROTO_DELETE); flag = gf_bs_read_int(bs, 1); if (flag) { count = 0; flag = gf_bs_read_int(bs, 1); while (flag) { com->del_proto_list = (u32*)gf_realloc(com->del_proto_list, sizeof(u32) * (com->del_proto_list_size+1)); com->del_proto_list[count] = gf_bs_read_int(bs, codec->info->config.ProtoIDBits); com->del_proto_list_size++; flag = gf_bs_read_int(bs, 1); } } else { flag = gf_bs_read_int(bs, 5); com->del_proto_list_size = gf_bs_read_int(bs, flag); com->del_proto_list = (u32*)gf_realloc(com->del_proto_list, sizeof(u32) * (com->del_proto_list_size)); flag = 0; while (flag<com->del_proto_list_size) { com->del_proto_list[flag] = gf_bs_read_int(bs, codec->info->config.ProtoIDBits); flag++; } } gf_list_add(com_list, com); return GF_OK; }
static GF_Err BM_ParseExtendedUpdates(GF_BifsDecoder *codec, GF_BitStream *bs, GF_List *com_list) { u32 type = gf_bs_read_int(bs, 8); GF_Err e; switch (type) { case 0: { GF_Command *com = gf_sg_command_new(codec->current_graph, GF_SG_PROTO_INSERT); e = gf_bifs_dec_proto_list(codec, bs, com->new_proto_list); if (e) gf_sg_command_del(com); else gf_list_add(com_list, com); } return e; case 1: return BM_ParseProtoDelete(codec, bs, com_list); case 2: { GF_Command *com = gf_sg_command_new(codec->current_graph, GF_SG_PROTO_DELETE_ALL); return gf_list_add(com_list, com); } case 3: return BM_ParseMultipleIndexedReplace(codec, bs, com_list); case 4: return BM_ParseMultipleReplace(codec, bs, com_list); case 5: return BM_ParseGlobalQuantizer(codec, bs, com_list); case 6: { GF_Command *com; u32 ID = 1 + gf_bs_read_int(bs, codec->info->config.NodeIDBits); GF_Node *n = gf_sg_find_node(codec->current_graph, ID); if (!n) return GF_OK; com = gf_sg_command_new(codec->current_graph, GF_SG_NODE_DELETE_EX); BM_SetCommandNode(com, n); gf_list_add(com_list, com); } return GF_OK; case 7: return BM_XReplace(codec, bs, com_list); default: return GF_BIFS_UNKNOWN_VERSION; } }
void SFS_GetBoolean(ScriptParser *parser) { if (parser->codec->LastError) return; if (gf_bs_read_int(parser->bs, 1)) { SFS_AddString(parser, "true"); } else { SFS_AddString(parser, "false"); } }
/*inserts a node in a container (node.children)*/ GF_Err BM_ParseNodeInsert(GF_BifsDecoder *codec, GF_BitStream *bs, GF_List *com_list) { u32 NodeID, NDT; GF_Command *com; GF_CommandField *inf; s32 type, pos; GF_Node *node, *def; NodeID = 1 + gf_bs_read_int(bs, codec->info->config.NodeIDBits); def = gf_sg_find_node(codec->current_graph, NodeID); if (!def) return GF_NON_COMPLIANT_BITSTREAM; NDT = gf_bifs_get_child_table(def); if (!NDT) return GF_NON_COMPLIANT_BITSTREAM; type = gf_bs_read_int(bs, 2); switch (type) { case 0: pos = gf_bs_read_int(bs, 8); break; case 2: pos = 0; break; case 3: /*-1 means append*/ pos = -1; break; default: return GF_NON_COMPLIANT_BITSTREAM; } node = gf_bifs_dec_node(codec, bs, NDT); if (!codec->LastError) { com = gf_sg_command_new(codec->current_graph, GF_SG_NODE_INSERT); BM_SetCommandNode(com, def); inf = gf_sg_command_field_new(com); inf->pos = pos; inf->new_node = node; inf->field_ptr = &inf->new_node; inf->fieldType = GF_SG_VRML_SFNODE; gf_list_add(com_list, com); /*register*/ gf_node_register(node, NULL); } return codec->LastError; }