📄 odf_code.c
字号:
u32 tmp_size, nbBytes = 0; if (! iod) return GF_BAD_PARAM; iod->objectDescriptorID = gf_bs_read_int(bs, 10); urlflag = gf_bs_read_int(bs, 1); iod->inlineProfileFlag = gf_bs_read_int(bs, 1); reserved = gf_bs_read_int(bs, 4); nbBytes += 2; if (urlflag) { e = gf_odf_read_url_string(bs, & iod->URLString, &read); if (e) return e; nbBytes += read; } else { iod->OD_profileAndLevel = gf_bs_read_int(bs, 8); iod->scene_profileAndLevel = gf_bs_read_int(bs, 8); iod->audio_profileAndLevel = gf_bs_read_int(bs, 8); iod->visual_profileAndLevel = gf_bs_read_int(bs, 8); iod->graphics_profileAndLevel = gf_bs_read_int(bs, 8); nbBytes += 5; } while (nbBytes < DescSize) { GF_Descriptor *tmp = NULL; e = gf_odf_parse_descriptor(bs, &tmp, &tmp_size); if (e) return e; if (!tmp) return GF_ODF_INVALID_DESCRIPTOR; e = AddDescriptorToIOD(iod, tmp); if (e) return e; nbBytes += tmp_size + gf_odf_size_field_size(tmp_size); } if (DescSize != nbBytes) return GF_ODF_INVALID_DESCRIPTOR; return GF_OK;}GF_Err gf_odf_size_iod(GF_InitialObjectDescriptor *iod, u32 *outSize){ GF_Err e; if (! iod) return GF_BAD_PARAM; *outSize = 0; *outSize += 2; if (iod->URLString) { *outSize += gf_odf_size_url_string(iod->URLString); } else { *outSize += 5; e = gf_odf_size_descriptor_list(iod->ESDescriptors, outSize); if (e) return e; e = gf_odf_size_descriptor_list(iod->OCIDescriptors, outSize); if (e) return e; e = gf_odf_size_descriptor_list(iod->IPMP_Descriptors, outSize); if (e) return e; } e = gf_odf_size_descriptor_list(iod->extensionDescriptors, outSize); if (e) return e; if (iod->IPMPToolList) { u32 tmpSize; e = gf_odf_size_descriptor((GF_Descriptor *) iod->IPMPToolList, &tmpSize); if (e) return e; *outSize += tmpSize + gf_odf_size_field_size(tmpSize); } return GF_OK;}GF_Err gf_odf_write_iod(GF_BitStream *bs, GF_InitialObjectDescriptor *iod){ GF_Err e; u32 size; if (! iod) return GF_BAD_PARAM; e = gf_odf_size_descriptor((GF_Descriptor *)iod, &size); if (e) return e; e = gf_odf_write_base_descriptor(bs, iod->tag, size); if (e) return e; gf_bs_write_int(bs, iod->objectDescriptorID, 10); gf_bs_write_int(bs, iod->URLString != NULL ? 1 : 0, 1); gf_bs_write_int(bs, iod->inlineProfileFlag, 1); gf_bs_write_int(bs, 15, 4); //reserved: 0b1111 == 15 if (iod->URLString) { gf_odf_write_url_string(bs, iod->URLString); } else { gf_bs_write_int(bs, iod->OD_profileAndLevel, 8); gf_bs_write_int(bs, iod->scene_profileAndLevel, 8); gf_bs_write_int(bs, iod->audio_profileAndLevel, 8); gf_bs_write_int(bs, iod->visual_profileAndLevel, 8); gf_bs_write_int(bs, iod->graphics_profileAndLevel, 8); e = gf_odf_write_descriptor_list(bs, iod->ESDescriptors); if (e) return e; e = gf_odf_write_descriptor_list(bs, iod->OCIDescriptors); if (e) return e; e = gf_odf_write_descriptor_list_filter(bs, iod->IPMP_Descriptors, GF_ODF_IPMP_PTR_TAG); if (e) return e; e = gf_odf_write_descriptor_list_filter(bs, iod->IPMP_Descriptors, GF_ODF_IPMP_TAG); if (e) return e; if (iod->IPMPToolList) { e = gf_odf_write_descriptor(bs, (GF_Descriptor *) iod->IPMPToolList); if (e) return e; } } e = gf_odf_write_descriptor_list(bs, iod->extensionDescriptors); return GF_OK;}GF_Descriptor *gf_odf_new_od(){ GF_ObjectDescriptor *newDesc = (GF_ObjectDescriptor *) malloc(sizeof(GF_ObjectDescriptor)); if (!newDesc) return NULL; newDesc->URLString = NULL; newDesc->ESDescriptors = gf_list_new(); newDesc->OCIDescriptors = gf_list_new(); newDesc->IPMP_Descriptors = gf_list_new(); newDesc->extensionDescriptors = gf_list_new(); newDesc->objectDescriptorID = 0; newDesc->tag = GF_ODF_OD_TAG; return (GF_Descriptor *) newDesc;}GF_Err gf_odf_del_od(GF_ObjectDescriptor *od){ GF_Err e; if (!od) return GF_BAD_PARAM; if (od->URLString) free(od->URLString); e = gf_odf_delete_descriptor_list(od->ESDescriptors); if (e) return e; e = gf_odf_delete_descriptor_list(od->OCIDescriptors); if (e) return e; e = gf_odf_delete_descriptor_list(od->IPMP_Descriptors); if (e) return e; e = gf_odf_delete_descriptor_list(od->extensionDescriptors); if (e) return e; free(od); return GF_OK;}GF_Err AddDescriptorToOD(GF_ObjectDescriptor *od, GF_Descriptor *desc){ if (!od || !desc) return GF_BAD_PARAM; //check if we can handle ContentClassif tags if ( (desc->tag >= GF_ODF_OCI_BEGIN_TAG) && (desc->tag <= GF_ODF_OCI_END_TAG) ) { return gf_list_add(od->OCIDescriptors, desc); } //or extensions if ( (desc->tag >= GF_ODF_EXT_BEGIN_TAG) && (desc->tag <= GF_ODF_EXT_END_TAG) ) { return gf_list_add(od->extensionDescriptors, desc); } //to cope with envivio switch (desc->tag) { case GF_ODF_ESD_TAG: case GF_ODF_ESD_REF_TAG: return gf_list_add(od->ESDescriptors, desc); //we use the same struct for v1 and v2 IPMP DPs case GF_ODF_IPMP_PTR_TAG: case GF_ODF_IPMP_TAG: return gf_list_add(od->IPMP_Descriptors, desc); default: return GF_BAD_PARAM; }}GF_Err gf_odf_read_od(GF_BitStream *bs, GF_ObjectDescriptor *od, u32 DescSize){ GF_Err e; u32 reserved, urlflag; u32 tmpSize, nbBytes = 0; if (! od) return GF_BAD_PARAM; od->objectDescriptorID = gf_bs_read_int(bs, 10); urlflag = gf_bs_read_int(bs, 1); reserved = gf_bs_read_int(bs, 5); nbBytes += 2; if (urlflag) { u32 read; e = gf_odf_read_url_string(bs, & od->URLString, &read); if (e) return e; nbBytes += read; } while (nbBytes < DescSize) { GF_Descriptor *tmp = NULL; e = gf_odf_parse_descriptor(bs, &tmp, &tmpSize); if (e) return e; if (!tmp) return GF_ODF_INVALID_DESCRIPTOR; e = AddDescriptorToOD(od, tmp); if (e) return e; nbBytes += tmpSize + gf_odf_size_field_size(tmpSize); } if (nbBytes != DescSize) return GF_ODF_INVALID_DESCRIPTOR; return GF_OK;}GF_Err gf_odf_size_od(GF_ObjectDescriptor *od, u32 *outSize){ GF_Err e; if (! od) return GF_BAD_PARAM; *outSize = 2; if (od->URLString) { *outSize += gf_odf_size_url_string(od->URLString); } else { e = gf_odf_size_descriptor_list(od->ESDescriptors, outSize); if (e) return e; e = gf_odf_size_descriptor_list(od->OCIDescriptors, outSize); if (e) return e; e = gf_odf_size_descriptor_list(od->IPMP_Descriptors, outSize); if (e) return e; } return gf_odf_size_descriptor_list(od->extensionDescriptors, outSize);}GF_Err gf_odf_write_od(GF_BitStream *bs, GF_ObjectDescriptor *od){ GF_Err e; u32 size; if (! od) return GF_BAD_PARAM; e = gf_odf_size_descriptor((GF_Descriptor *)od, &size); if (e) return e; e = gf_odf_write_base_descriptor(bs, od->tag, size); if (e) return e; gf_bs_write_int(bs, od->objectDescriptorID, 10); gf_bs_write_int(bs, od->URLString != NULL ? 1 : 0, 1); gf_bs_write_int(bs, 31, 5); //reserved: 0b1111.1 == 31 if (od->URLString) { gf_odf_write_url_string(bs, od->URLString); } else { e = gf_odf_write_descriptor_list(bs, od->ESDescriptors); if (e) return e; e = gf_odf_write_descriptor_list(bs, od->OCIDescriptors); if (e) return e; e = gf_odf_write_descriptor_list_filter(bs, od->IPMP_Descriptors, GF_ODF_IPMP_PTR_TAG); if (e) return e; e = gf_odf_write_descriptor_list_filter(bs, od->IPMP_Descriptors, GF_ODF_IPMP_TAG); if (e) return e; } e = gf_odf_write_descriptor_list(bs, od->extensionDescriptors); return GF_OK;}GF_Descriptor *gf_odf_new_isom_iod(){ GF_IsomInitialObjectDescriptor *newDesc = (GF_IsomInitialObjectDescriptor *) malloc(sizeof(GF_IsomInitialObjectDescriptor)); if (!newDesc) return NULL; memset(newDesc, 0, sizeof(GF_IsomInitialObjectDescriptor)); newDesc->ES_ID_IncDescriptors = gf_list_new(); newDesc->ES_ID_RefDescriptors = gf_list_new(); newDesc->OCIDescriptors = gf_list_new(); newDesc->IPMP_Descriptors = gf_list_new(); newDesc->extensionDescriptors = gf_list_new(); newDesc->tag = GF_ODF_ISOM_IOD_TAG; //by default create an IOD with no inline and no capabilities newDesc->audio_profileAndLevel = 0xFF; newDesc->graphics_profileAndLevel = 0xFF; newDesc->scene_profileAndLevel = 0xFF; newDesc->OD_profileAndLevel = 0xFF; newDesc->visual_profileAndLevel = 0xFF; return (GF_Descriptor *) newDesc;}GF_Err gf_odf_del_isom_iod(GF_IsomInitialObjectDescriptor *iod){ GF_Err e; if (!iod) return GF_BAD_PARAM; if (iod->URLString) free(iod->URLString); e = gf_odf_delete_descriptor_list(iod->ES_ID_IncDescriptors); if (e) return e; e = gf_odf_delete_descriptor_list(iod->ES_ID_RefDescriptors); if (e) return e; e = gf_odf_delete_descriptor_list(iod->OCIDescriptors); if (e) return e; e = gf_odf_delete_descriptor_list(iod->IPMP_Descriptors); if (e) return e; e = gf_odf_delete_descriptor_list(iod->extensionDescriptors); if (e) return e; if (iod->IPMPToolList) gf_odf_delete_descriptor((GF_Descriptor *) iod->IPMPToolList); free(iod); return GF_OK;}GF_Err AddDescriptorToIsomIOD(GF_IsomInitialObjectDescriptor *iod, GF_Descriptor *desc){ if (!iod || !desc) return GF_BAD_PARAM; switch (desc->tag) { case GF_ODF_ESD_TAG: return GF_ODF_FORBIDDEN_DESCRIPTOR; case GF_ODF_ESD_INC_TAG: //there shouldn't be ref if inc if (gf_list_count(iod->ES_ID_RefDescriptors)) return GF_ODF_FORBIDDEN_DESCRIPTOR; return gf_list_add(iod->ES_ID_IncDescriptors, desc); case GF_ODF_ESD_REF_TAG: //there shouldn't be inc if ref if (gf_list_count(iod->ES_ID_IncDescriptors)) return GF_ODF_FORBIDDEN_DESCRIPTOR; return gf_list_add(iod->ES_ID_RefDescriptors, desc); //we use the same struct for v1 and v2 IPMP DPs case GF_ODF_IPMP_PTR_TAG: case GF_ODF_IPMP_TAG: return gf_list_add(iod->IPMP_Descriptors, desc); /*IPMPX*/ case GF_ODF_IPMP_TL_TAG: if (iod->IPMPToolList) gf_odf_desc_del((GF_Descriptor *)iod->IPMPToolList); iod->IPMPToolList = (GF_IPMP_ToolList *)desc; return GF_OK; default: break; } //check if we can handle ContentClassif tags if ( (desc->tag >= GF_ODF_OCI_BEGIN_TAG) && (desc->tag <= GF_ODF_OCI_END_TAG) ) return gf_list_add(iod->OCIDescriptors, desc); //or extensions if ( (desc->tag >= GF_ODF_EXT_BEGIN_TAG) && (desc->tag <= GF_ODF_EXT_END_TAG) ) return gf_list_add(iod->extensionDescriptors, desc); return GF_BAD_PARAM;}GF_Err gf_odf_read_isom_iod(GF_BitStream *bs, GF_IsomInitialObjectDescriptor *iod, u32 DescSize){ u32 nbBytes = 0, tmpSize; u32 reserved, urlflag; GF_Err e; if (! iod) return GF_BAD_PARAM; iod->objectDescriptorID = gf_bs_read_int(bs, 10); urlflag = gf_bs_read_int(bs, 1); iod->inlineProfileFlag = gf_bs_read_int(bs, 1); reserved = gf_bs_read_int(bs, 4); nbBytes += 2; if (urlflag) { u32 read; e = gf_odf_read_url_string(bs, & iod->URLString, &read); if (e) return e; nbBytes += read; } else { iod->OD_profileAndLevel = gf_bs_read_int(bs, 8); iod->scene_profileAndLevel = gf_bs_read_int(bs, 8); iod->audio_profileAndLevel = gf_bs_read_int(bs, 8); iod->visual_profileAndLevel = gf_bs_read_int(bs, 8); iod->graphics_profileAndLevel = gf_bs_read_int(bs, 8); nbBytes += 5; } while (nbBytes < DescSize) { GF_Descriptor *tmp = NULL; e = gf_odf_parse_descriptor(bs, &tmp, &tmpSize); if (e) return e; if (!tmp) return GF_ODF_INVALID_DESCRIPTOR; e = AddDescriptorToIsomIOD(iod, tmp); if (e) return e; nbBytes += tmpSize + gf_odf_size_field_size(tmpSize); } if (DescSize != nbBytes) return GF_ODF_INVALID_DESCRIPTOR; return GF_OK;}GF_Err gf_odf_size_isom_iod(GF_IsomInitialObjectDescriptor *iod, u32 *outSize){ GF_Err e; if (! iod) return GF_BAD_PARAM; *outSize = 2; if (iod->URLString) { *outSize += gf_odf_size_url_string(iod->URLString); } else { *outSize += 5; e = gf_odf_size_descriptor_list(iod->ES_ID_IncDescriptors, outSize); if (e) return e; e = gf_odf_size_descriptor_list(iod->ES_ID_RefDescriptors, outSize); if (e) return e; e = gf_odf_size_descriptor_list(iod->OCIDescriptors, outSize); if (e) return e; e = gf_odf_size_descriptor_list(iod->IPMP_Descriptors, outSize); if (e) return e; } if (iod->IPMPToolList) { u32 tmpSize; e = gf_odf_size_descriptor((GF_Descriptor *) iod->IPMPToolList, &tmpSize); if (e) return e; *outSize += tmpSize + gf_odf_size_field_size(tmpSize); } return gf_odf_size_descriptor_list(iod->extensionDescriptors, outSize);}GF_Err gf_odf_write_isom_iod(GF_BitStream *bs, GF_IsomInitialObjectDescriptor *iod){ GF_Err e; u32 size; if (! iod) return GF_BAD_PARAM; e = gf_odf_size_descriptor((GF_Descriptor *)iod, &size); if (e) return e; e = gf_odf_write_base_descriptor(bs, iod->tag, size); if (e) return e; gf_bs_write_int(bs, iod->objectDescriptorID, 10); gf_bs_write_int(bs, iod->URLString != NULL ? 1 : 0, 1); gf_bs_write_int(bs, iod->inlineProfileFlag, 1); gf_bs_write_int(bs, 15, 4); //reserved: 0b1111 == 15 if (iod->URLString) { gf_odf_write_url_string(bs, iod->URLString); } else { gf_bs_write_int(bs, iod->OD_profileAndLevel, 8); gf_bs_write_int(bs, iod->scene_profileAndLevel, 8); gf_bs_write_int(bs, iod->audio_profileAndLevel, 8); gf_bs_write_int(bs, iod->visual_profileAndLevel, 8); gf_bs_write_int(bs, iod->graphics_profileAndLevel, 8); e = gf_odf_write_descriptor_list(bs, iod->ES_ID_IncDescriptors); if (e) return e; e = gf_odf_write_descriptor_list(bs, iod->ES_ID_RefDescriptors); if (e) return e; e = gf_odf_write_descriptor_list(bs, iod->OCIDescriptors); if (e) return e; e = gf_odf_write_descriptor_list_filter(bs, iod->IPMP_Descriptors, GF_ODF_IPMP_PTR_TAG); if (e) return e; e = gf_odf_write_descriptor_list_filter(bs, iod->IPMP_Descriptors, GF_ODF_IPMP_TAG); if (e) return e; if (iod->IPMPToolList) { e = gf_odf_write_descriptor(bs, (GF_Descriptor *) iod->IPMPToolList); if (e) return e; } } e = gf_odf_write_descriptor_list(bs, iod->extensionDescriptors); if (e) return e; return GF_OK;}GF_Descriptor *gf_odf_new_isom_od(){ GF_IsomObjectDescriptor *newDesc = (GF_IsomObjectDescriptor *) malloc(sizeof(GF_IsomObjectDescriptor)); if (!newDesc) return NULL; newDesc->URLString = NULL; newDesc->ES_ID_IncDescriptors = gf_list_new(); newDesc->ES_ID_RefDescriptors = gf_list_new(); newDesc->OCIDescriptors = gf_list_new(); newDesc->IPMP_Descriptors = gf_list_new(); newDesc->extensionDescriptors = gf_list_new(); newDesc->objectDescriptorID = 0; newDesc->tag = GF_ODF_ISOM_OD_TAG; return (GF_Descriptor *) newDesc;}GF_Err gf_odf_del_isom_od(GF_IsomObjectDescriptor *od){ GF_Err e; if (!od) return GF_BAD_PARAM; if (od->URLString) free(od->URLString); e = gf_odf_delete_descriptor_list(od->ES_ID_IncDescriptors); if (e) return e; e = gf_odf_delete_descriptor_list(od->ES_ID_RefDescriptors); if (e) return e;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -