📄 odf_command.c
字号:
if (!desc) return GF_OK; switch (desc->tag) { case GF_ODF_ESD_TAG: case GF_ODF_ESD_REF_TAG: return gf_list_add(esdUp->ESDescriptors, desc); default: gf_odf_delete_descriptor(desc); return GF_OK; }}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 gf_odf_size_esd_update(GF_ESDUpdate *esdUp, u32 *outSize){ u32 i, BitSize, tmpSize; GF_Descriptor *tmp; if (!esdUp) return GF_BAD_PARAM; *outSize = 0; BitSize = 10; i=0; while ((tmp = (GF_Descriptor *)gf_list_enum(esdUp->ESDescriptors, &i))) { gf_odf_size_descriptor(tmp, &tmpSize); BitSize += ( tmpSize + gf_odf_size_field_size(tmpSize) ) * 8; } while ((s32) BitSize > 0) { BitSize -= 8; *outSize += 1; } return GF_OK;}GF_Err gf_odf_write_esd_update(GF_BitStream *bs, GF_ESDUpdate *esdUp){ GF_Descriptor *tmp; GF_Err e; u32 size, i; if (! esdUp) return GF_BAD_PARAM; e = gf_odf_size_esd_update(esdUp, &size); if (e) return e; e = gf_odf_write_base_descriptor(bs, esdUp->tag, size); if (e) return e; gf_bs_write_int(bs, esdUp->ODID, 10); i=0; while ((tmp = (GF_Descriptor *)gf_list_enum(esdUp->ESDescriptors, &i))) { e = gf_odf_write_descriptor(bs, tmp); if (e) return e; } //OD commands are aligned gf_bs_align(bs); return GF_OK;}GF_ODCom *gf_odf_new_esd_remove(){ GF_ESDRemove *newCom = (GF_ESDRemove *) malloc(sizeof(GF_ESDRemove)); if (!newCom) return NULL; newCom->NbESDs = 0; newCom->ES_ID = NULL; newCom->tag = GF_ODF_ESD_REMOVE_TAG; return (GF_ODCom *)newCom;}GF_Err gf_odf_del_esd_remove(GF_ESDRemove *ESDRemove){ if (! ESDRemove) return GF_BAD_PARAM; if (ESDRemove->ES_ID) free(ESDRemove->ES_ID); free(ESDRemove); return GF_OK;}GF_Err gf_odf_read_esd_remove(GF_BitStream *bs, GF_ESDRemove *esdRem, u32 gf_odf_size_command){ u32 i = 0, aligned, nbBits; 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 *) 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;}GF_Err gf_odf_size_esd_remove(GF_ESDRemove *esdRem, u32 *outSize){ if (!esdRem) return GF_BAD_PARAM; *outSize = 2 + 2 * esdRem->NbESDs; return GF_OK;}GF_Err gf_odf_write_esd_remove(GF_BitStream *bs, GF_ESDRemove *esdRem){ GF_Err e; u32 size, i; if (! esdRem) return GF_BAD_PARAM; e = gf_odf_size_esd_remove(esdRem, &size); if (e) return e; e = gf_odf_write_base_descriptor(bs, esdRem->tag, size); if (e) return e; gf_bs_write_int(bs, esdRem->ODID, 10); gf_bs_write_int(bs, 0, 6); //aligned for (i = 0; i < esdRem->NbESDs ; i++) { gf_bs_write_int(bs, esdRem->ES_ID[i], 16); } //OD commands are aligned (but we are already aligned.... gf_bs_align(bs); return GF_OK;}GF_ODCom *gf_odf_new_ipmp_remove(){ GF_IPMPRemove *newCom = (GF_IPMPRemove *) malloc(sizeof(GF_IPMPRemove)); if (!newCom) return NULL; newCom->IPMPDescID =NULL; newCom->NbIPMPDs = 0; newCom->tag = GF_ODF_IPMP_REMOVE_TAG; return (GF_ODCom *)newCom;}GF_Err gf_odf_del_ipmp_remove(GF_IPMPRemove *IPMPDRemove){ if (! IPMPDRemove) return GF_BAD_PARAM; if (IPMPDRemove->IPMPDescID) free(IPMPDRemove->IPMPDescID); free(IPMPDRemove); return GF_OK;}GF_Err gf_odf_read_ipmp_remove(GF_BitStream *bs, GF_IPMPRemove *ipmpRem, u32 gf_odf_size_command){ u32 i; if (! ipmpRem) return GF_BAD_PARAM; //we have gf_odf_size_command bytes left, and this is our IPMPD_ID[1...255] //this works because OD commands are aligned if (!gf_odf_size_command) return GF_OK; ipmpRem->NbIPMPDs = gf_odf_size_command; ipmpRem->IPMPDescID = (u8 *) malloc(sizeof(u8) * ipmpRem->NbIPMPDs); if (! ipmpRem->IPMPDescID) return GF_OUT_OF_MEM; for (i = 0; i < ipmpRem->NbIPMPDs; i++) { ipmpRem->IPMPDescID[i] = gf_bs_read_int(bs, 8); } //OD commands are aligned gf_bs_align(bs); return GF_OK;}GF_Err gf_odf_size_ipmp_remove(GF_IPMPRemove *ipmpRem, u32 *outSize){ if (!ipmpRem) return GF_BAD_PARAM; *outSize = ipmpRem->NbIPMPDs; return GF_OK;}GF_Err gf_odf_write_ipmp_remove(GF_BitStream *bs, GF_IPMPRemove *ipmpRem){ GF_Err e; u32 size, i; if (! ipmpRem) return GF_BAD_PARAM; e = gf_odf_size_ipmp_remove(ipmpRem, &size); if (e) return e; e = gf_odf_write_base_descriptor(bs, ipmpRem->tag, size); if (e) return e; for (i = 0; i < ipmpRem->NbIPMPDs; i++) { gf_bs_write_int(bs, ipmpRem->IPMPDescID[i], 8); } //OD commands are aligned gf_bs_align(bs); return GF_OK;}GF_ODCom *gf_odf_new_ipmp_update(){ GF_IPMPUpdate *newCom = (GF_IPMPUpdate *) malloc(sizeof(GF_IPMPUpdate)); if (!newCom) return NULL; newCom->IPMPDescList = gf_list_new(); if (! newCom->IPMPDescList) { free(newCom); return NULL; } newCom->tag = GF_ODF_IPMP_UPDATE_TAG; return (GF_ODCom *)newCom;}GF_Err gf_odf_del_ipmp_update(GF_IPMPUpdate *IPMPDUpdate){ GF_Err e; if (! IPMPDUpdate) return GF_BAD_PARAM; while (gf_list_count(IPMPDUpdate->IPMPDescList)) { GF_Descriptor *tmp = (GF_Descriptor*)gf_list_get(IPMPDUpdate->IPMPDescList, 0); e = gf_odf_delete_descriptor(tmp); e = gf_list_rem(IPMPDUpdate->IPMPDescList, 0); } gf_list_del(IPMPDUpdate->IPMPDescList); free(IPMPDUpdate); return GF_OK;}GF_Err AddToIPMPDUpdate(GF_IPMPUpdate *ipmpUp, GF_Descriptor *desc){ if (! ipmpUp) return GF_BAD_PARAM; if (!desc) return GF_OK; switch (desc->tag) { case GF_ODF_IPMP_TAG: return gf_list_add(ipmpUp->IPMPDescList, desc); default: gf_odf_delete_descriptor(desc); return GF_OK; }}GF_Err gf_odf_read_ipmp_update(GF_BitStream *bs, GF_IPMPUpdate *ipmpUp, u32 gf_odf_size_command){ GF_Descriptor *tmp; u32 tmpSize = 0, nbBytes = 0; GF_Err e = GF_OK; if (! ipmpUp) return GF_BAD_PARAM; while (nbBytes < gf_odf_size_command) { e = gf_odf_parse_descriptor(bs, &tmp, &tmpSize); if (e) return e; e = AddToIPMPDUpdate(ipmpUp, tmp); if (e) return e; nbBytes += tmpSize + gf_odf_size_field_size(tmpSize); } //OD commands are aligned gf_bs_align(bs); if (nbBytes != gf_odf_size_command) return GF_ODF_INVALID_COMMAND; return e;}GF_Err gf_odf_size_ipmp_update(GF_IPMPUpdate *ipmpUp, u32 *outSize){ GF_Descriptor *tmp; u32 i, tmpSize; if (!ipmpUp) return GF_BAD_PARAM; *outSize = 0; i=0; while ((tmp = (GF_Descriptor *)gf_list_enum(ipmpUp->IPMPDescList, &i))) { gf_odf_size_descriptor(tmp, &tmpSize); *outSize += tmpSize + gf_odf_size_field_size(tmpSize); } return GF_OK;}GF_Err gf_odf_write_ipmp_update(GF_BitStream *bs, GF_IPMPUpdate *ipmpUp){ GF_Err e; GF_Descriptor *tmp; u32 size, i; if (! ipmpUp) return GF_BAD_PARAM; e = gf_odf_size_ipmp_update(ipmpUp, &size); if (e) return e; e = gf_odf_write_base_descriptor(bs, ipmpUp->tag, size); if (e) return e; i=0; while ((tmp = (GF_Descriptor *)gf_list_enum(ipmpUp->IPMPDescList, &i))) { e = gf_odf_write_descriptor(bs, tmp); if (e) return e; } //OD commands are aligned gf_bs_align(bs); return GF_OK;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -