📄 odf_parse.c
字号:
/* * GPAC - Multimedia Framework C SDK * * Copyright (c) Jean Le Feuvre 2000-2005 * All rights reserved * * This file is part of GPAC / MPEG-4 ObjectDescriptor sub-project * * GPAC is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * GPAC is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * */#include <gpac/internal/odf_dev.h>#include <gpac/token.h>#include <gpac/constants.h>/*for import flags*/#include <gpac/media_tools.h>/* to complete...*/u32 gf_odf_get_field_type(GF_Descriptor *desc, char *fieldName){ switch (desc->tag) { case GF_ODF_IOD_TAG: case GF_ODF_OD_TAG: if (!stricmp(fieldName, "esDescr")) return GF_ODF_FT_OD_LIST; else if (!stricmp(fieldName, "ociDescr")) return GF_ODF_FT_OD_LIST; else if (!stricmp(fieldName, "ipmpDescrPtr")) return GF_ODF_FT_OD_LIST; else if (!stricmp(fieldName, "ipmpDescr")) return GF_ODF_FT_OD_LIST; else if (!stricmp(fieldName, "extDescr")) return GF_ODF_FT_OD_LIST; else if (!stricmp(fieldName, "toolListDescr")) return GF_ODF_FT_OD; return 0; case GF_ODF_DCD_TAG: if (!stricmp(fieldName, "decSpecificInfo")) return GF_ODF_FT_OD; if (!stricmp(fieldName, "profileLevelIndicationIndexDescr")) return GF_ODF_FT_OD_LIST; return 0; case GF_ODF_ESD_TAG: if (!stricmp(fieldName, "decConfigDescr")) return GF_ODF_FT_OD; if (!stricmp(fieldName, "muxInfo")) return GF_ODF_FT_OD; if (!stricmp(fieldName, "StreamSource")) return GF_ODF_FT_OD; if (!stricmp(fieldName, "slConfigDescr")) return GF_ODF_FT_OD; if (!stricmp(fieldName, "ipiPtr")) return GF_ODF_FT_OD; if (!stricmp(fieldName, "qosDescr")) return GF_ODF_FT_OD; if (!stricmp(fieldName, "regDescr")) return GF_ODF_FT_OD; if (!stricmp(fieldName, "langDescr")) return GF_ODF_FT_OD; if (!stricmp(fieldName, "ipIDS")) return GF_ODF_FT_OD_LIST; if (!stricmp(fieldName, "ipmpDescrPtr")) return GF_ODF_FT_OD_LIST; if (!stricmp(fieldName, "extDescr")) return GF_ODF_FT_OD_LIST; return 0; case GF_ODF_TEXT_CFG_TAG: if (!stricmp(fieldName, "SampleDescriptions")) return GF_ODF_FT_OD_LIST; return 0; case GF_ODF_IPMP_TAG: if (!stricmp(fieldName, "IPMPX_Data")) return GF_ODF_FT_IPMPX_LIST; return 0; case GF_ODF_IPMP_TL_TAG: if (!stricmp(fieldName, "ipmpTool")) return GF_ODF_FT_OD_LIST; return 0; case GF_ODF_IPMP_TOOL_TAG: if (!stricmp(fieldName, "toolParamDesc")) return GF_ODF_FT_IPMPX; return 0; case GF_ODF_BIFS_CFG_TAG: if (!stricmp(fieldName, "elementaryMask")) return GF_ODF_FT_OD_LIST; return 0; } return 0;}u32 gf_odf_get_tag_by_name(char *descName){ if (!stricmp(descName, "ObjectDescriptor")) return GF_ODF_OD_TAG; if (!stricmp(descName, "InitialObjectDescriptor")) return GF_ODF_IOD_TAG; if (!stricmp(descName, "ES_Descriptor")) return GF_ODF_ESD_TAG; if (!stricmp(descName, "DecoderConfigDescriptor")) return GF_ODF_DCD_TAG; if (!stricmp(descName, "DecoderSpecificInfo")) return GF_ODF_DSI_TAG; if (!stricmp(descName, "DecoderSpecificInfoString")) return GF_ODF_DSI_TAG; if (!stricmp(descName, "SLConfigDescriptor")) return GF_ODF_SLC_TAG; if (!stricmp(descName, "ContentIdentification")) return GF_ODF_CI_TAG; if (!stricmp(descName, "SuppContentIdentification")) return GF_ODF_SCI_TAG; if (!stricmp(descName, "IPIPtr")) return GF_ODF_IPI_PTR_TAG; if (!stricmp(descName, "IPMP_DescriptorPointer")) return GF_ODF_IPMP_PTR_TAG; if (!stricmp(descName, "IPMP_Descriptor")) return GF_ODF_IPMP_TAG; if (!stricmp(descName, "IPMP_ToolListDescriptor")) return GF_ODF_IPMP_TL_TAG; if (!stricmp(descName, "IPMP_Tool")) return GF_ODF_IPMP_TOOL_TAG; if (!stricmp(descName, "QoS")) return GF_ODF_QOS_TAG; if (!stricmp(descName, "RegistrationDescriptor")) return GF_ODF_REG_TAG; if (!stricmp(descName, "ExtensionPL")) return GF_ODF_EXT_PL_TAG; if (!stricmp(descName, "PL_IndicationIndex")) return GF_ODF_PL_IDX_TAG; if (!stricmp(descName, "ContentClassification")) return GF_ODF_CC_TAG; if (!stricmp(descName, "KeyWordDescriptor")) return GF_ODF_KW_TAG; if (!stricmp(descName, "RatingDescriptor")) return GF_ODF_RATING_TAG; if (!stricmp(descName, "LanguageDescriptor")) return GF_ODF_LANG_TAG; if (!stricmp(descName, "ShortTextualDescriptor")) return GF_ODF_SHORT_TEXT_TAG; if (!stricmp(descName, "ExpandedTextualDescriptor")) return GF_ODF_TEXT_TAG; if (!stricmp(descName, "ContentCreatorName")) return GF_ODF_CC_NAME_TAG; if (!stricmp(descName, "ContentCreationDate")) return GF_ODF_CC_DATE_TAG; if (!stricmp(descName, "OCI_CreatorName")) return GF_ODF_OCI_NAME_TAG; if (!stricmp(descName, "OCI_CreationDate")) return GF_ODF_OCI_DATE_TAG; if (!stricmp(descName, "SmpteCameraPosition")) return GF_ODF_SMPTE_TAG; if (!stricmp(descName, "SegmentDescriptor")) return GF_ODF_SEGMENT_TAG; if (!stricmp(descName, "MediaTimeDescriptor")) return GF_ODF_MEDIATIME_TAG; if (!stricmp(descName, "MuxInfo")) return GF_ODF_MUXINFO_TAG; if (!stricmp(descName, "StreamSource")) return GF_ODF_MUXINFO_TAG; if (!stricmp(descName, "BIFSConfig") || !stricmp(descName, "BIFSv2Config")) return GF_ODF_BIFS_CFG_TAG; if (!stricmp(descName, "ElementaryMask")) return GF_ODF_ELEM_MASK_TAG; if (!stricmp(descName, "TextConfig")) return GF_ODF_TEXT_CFG_TAG; if (!stricmp(descName, "TextSampleDescriptor")) return GF_ODF_TX3G_TAG; if (!stricmp(descName, "UIConfig")) return GF_ODF_UI_CFG_TAG; if (!stricmp(descName, "ES_ID_Ref")) return GF_ODF_ESD_REF_TAG; if (!stricmp(descName, "ES_ID_Inc")) return GF_ODF_ESD_INC_TAG; if (!stricmp(descName, "DefaultDescriptor")) return GF_ODF_DSI_TAG; return 0;}#define GET_U8(field) { if (strstr(val, "0x")) { ret += sscanf(val, "%x", &d); if (ret) field = (u8) d; } else { ret += sscanf(val, "%d", &d); if (ret) field = (u8) d; } } #define GET_U16(field) { if (strstr(val, "0x")) { ret += sscanf(val, "%x", &d); if (ret) field = (u16) d; } else { ret += sscanf(val, "%d", &d); if (ret) field = (u16) d; } } #define GET_U32(field) { if (strstr(val, "0x")) { ret += sscanf(val, "%x", &d); if (ret) field = (u32) d; } else { ret += sscanf(val, "%d", &d); if (ret) field = (u32) d; } } #define GET_S32(field) { if (strstr(val, "0x")) { ret += sscanf(val, "%x", &d); if (ret) field = (s32) d; } else { ret += sscanf(val, "%d", &d); if (ret) field = (s32) d; } } #define GET_BOOL(field) { ret = 1; field = (!stricmp(val, "true") || !stricmp(val, "1")) ? 1 : 0; }#define GET_DOUBLE(field) { Float v; ret = 1; sscanf(val, "%f", &v); field = (Double) v;}#define GET_STRING(field) { ret = 1; field = strdup(val); if (val[0] == '"') strcpy(field, val+1); if (field[strlen(field)-1] == '"') field[strlen(field)-1] = 0; }void OD_ParseBinData(char *val, char **out_data, u32 *out_data_size){ u32 i, c; char s[3]; u32 len = strlen(val) / 3; if (*out_data) free(*out_data); *out_data_size = len; *out_data = (char*)malloc(sizeof(char) * len); s[2] = 0; for (i=0; i<len; i++) { s[0] = val[3*i+1]; s[1] = val[3*i+2]; sscanf(s, "%02X", &c); (*out_data)[i] = (unsigned char) c; }}void OD_ParseFileData(char *fileName, char **out_data, u32 *out_data_size){ FILE *f; u32 size; if (*out_data) free(*out_data); *out_data = NULL; *out_data_size = 0; f = fopen(fileName, "rb"); if (!f) { GF_LOG(GF_LOG_WARNING, GF_LOG_PARSER, ("[ODF Parse] cannot open data file %s - skipping\n", fileName)); return; } fseek(f, 0, SEEK_END); size = ftell(f); fseek(f, 0, SEEK_SET); *out_data_size = size; *out_data = (char*)malloc(sizeof(char) * size); fread(*out_data, sizeof(char) * size, 1, f); fclose(f);}void OD_ParseBin128(char *val, bin128 *data){ if (!strnicmp(val, "0x", 2)) val+=2; if (strlen(val)<16) { GF_BitStream *bs; u32 int_val = atoi(val); bs = gf_bs_new((char*) (*data), 16, GF_BITSTREAM_WRITE); gf_bs_write_int(bs, 0, 32); gf_bs_write_int(bs, 0, 32); gf_bs_write_int(bs, 0, 32); gf_bs_write_int(bs, int_val, 32); gf_bs_del(bs); } else { u32 i, b; char szB[3]; szB[2] = 0; for (i=0; i<16; i++) { szB[0] = val[2*i]; szB[1] = val[2*i+1]; sscanf(szB, "%x", &b); ((char *)data)[i] = (u8) b; } }}GF_Err gf_odf_set_field(GF_Descriptor *desc, char *fieldName, char *val){ Bool OD_ParseUIConfig(char *val, char **out_data, u32 *out_data_size); u32 d, ret = 0; if (!stricmp(val, "auto")) return GF_OK; else if (!stricmp(val, "unspecified")) return GF_OK; switch (desc->tag) { case GF_ODF_IOD_TAG: { GF_InitialObjectDescriptor *iod = (GF_InitialObjectDescriptor *)desc; if (!stricmp(fieldName, "objectDescriptorID") || !stricmp(fieldName, "binaryID")) ret += sscanf(val, "%hd", &iod->objectDescriptorID); else if (!stricmp(fieldName, "URLString")) { iod->URLString = strdup(val); ret = 1; } else if (!stricmp(fieldName, "includeInlineProfileLevelFlag")) { GET_BOOL(iod->inlineProfileFlag) if (!ret) { iod->inlineProfileFlag = 0; ret = 1; } } else if (!stricmp(fieldName, "ODProfileLevelIndication")) { GET_U8(iod->OD_profileAndLevel) if (!ret) { iod->OD_profileAndLevel = 0xFE; ret = 1; } } else if (!stricmp(fieldName, "sceneProfileLevelIndication")) { GET_U8(iod->scene_profileAndLevel) if (!ret) { iod->scene_profileAndLevel = 0xFE; ret = 1; } } else if (!stricmp(fieldName, "audioProfileLevelIndication")) { GET_U8(iod->audio_profileAndLevel) if (!ret) { iod->audio_profileAndLevel = 0xFE; ret = 1; } } else if (!stricmp(fieldName, "visualProfileLevelIndication")) { GET_U8(iod->visual_profileAndLevel) if (!ret) { iod->visual_profileAndLevel = 0xFE; ret = 1; } } else if (!stricmp(fieldName, "graphicsProfileLevelIndication")) { GET_U8(iod->graphics_profileAndLevel) if (!ret) { iod->graphics_profileAndLevel = 0xFE; ret = 1; } } } break; case GF_ODF_OD_TAG: { GF_ObjectDescriptor *od = (GF_ObjectDescriptor *) desc; if (!stricmp(fieldName, "objectDescriptorID") || !stricmp(fieldName, "binaryID")) ret += sscanf(val, "%hd", &od->objectDescriptorID); else if (!stricmp(fieldName, "URLString")) { od->URLString = strdup(val); ret = 1; } } break; case GF_ODF_DCD_TAG: { GF_DecoderConfig *dcd = (GF_DecoderConfig *)desc; if (!stricmp(fieldName, "objectTypeIndication")) { GET_U8(dcd->objectTypeIndication) /*XMT may use string*/ if (!ret) { if (!stricmp(val, "MPEG4Systems1")) { dcd->objectTypeIndication = 0x01; ret = 1; } else if (!stricmp(val, "MPEG4Systems2")) { dcd->objectTypeIndication = 0x02; ret = 1; } else if (!stricmp(val, "MPEG4Visual")) { dcd->objectTypeIndication = 0x20; ret = 1; } else if (!stricmp(val, "MPEG4Audio")) { dcd->objectTypeIndication = 0x40; ret = 1; } else if (!stricmp(val, "MPEG2VisualSimple")) { dcd->objectTypeIndication = 0x60; ret = 1; } else if (!stricmp(val, "MPEG2VisualMain")) { dcd->objectTypeIndication = 0x61; ret = 1; } else if (!stricmp(val, "MPEG2VisualSNR")) { dcd->objectTypeIndication = 0x62; ret = 1; } else if (!stricmp(val, "MPEG2VisualSpatial")) { dcd->objectTypeIndication = 0x63; ret = 1; } else if (!stricmp(val, "MPEG2VisualHigh")) { dcd->objectTypeIndication = 0x64; ret = 1; } else if (!stricmp(val, "MPEG2Visual422")) { dcd->objectTypeIndication = 0x65; ret = 1; } else if (!stricmp(val, "MPEG2AudioMain")) { dcd->objectTypeIndication = 0x66; ret = 1; } else if (!stricmp(val, "MPEG2AudioLowComplexity")) { dcd->objectTypeIndication = 0x67; ret = 1; } else if (!stricmp(val, "MPEG2AudioScaleableSamplingRate")) { dcd->objectTypeIndication = 0x68; ret = 1; } else if (!stricmp(val, "MPEG2AudioPart3")) { dcd->objectTypeIndication = 0x69; ret = 1; } else if (!stricmp(val, "MPEG1Visual")) { dcd->objectTypeIndication = 0x6A; ret = 1; } else if (!stricmp(val, "MPEG1Audio")) { dcd->objectTypeIndication = 0x6B; ret = 1; } else if (!stricmp(val, "JPEG")) { dcd->objectTypeIndication = 0x6C; ret = 1; } else if (!stricmp(val, "PNG")) { dcd->objectTypeIndication = 0x6D; ret = 1; } } } else if (!stricmp(fieldName, "streamType")) { GET_U8(dcd->streamType) /*XMT may use string*/ if (!ret) { if (!stricmp(val, "ObjectDescriptor")) { dcd->streamType = GF_STREAM_OD; ret = 1; } else if (!stricmp(val, "ClockReference")) { dcd->streamType = GF_STREAM_OCR; ret = 1; } else if (!stricmp(val, "SceneDescription")) { dcd->streamType = GF_STREAM_SCENE; ret = 1; } else if (!stricmp(val, "Visual")) { dcd->streamType = GF_STREAM_VISUAL; ret = 1; } else if (!stricmp(val, "Audio")) { dcd->streamType = GF_STREAM_AUDIO; ret = 1; } else if (!stricmp(val, "MPEG7")) { dcd->streamType = GF_STREAM_MPEG7; ret = 1; } else if (!stricmp(val, "IPMP")) { dcd->streamType = GF_STREAM_IPMP; ret = 1; } else if (!stricmp(val, "OCI")) { dcd->streamType = GF_STREAM_OCI; ret = 1; } else if (!stricmp(val, "MPEGJ")) { dcd->streamType = GF_STREAM_MPEGJ; ret = 1; } } } else if (!stricmp(fieldName, "upStream")) GET_BOOL(dcd->upstream) else if (!stricmp(fieldName, "bufferSizeDB")) ret += sscanf(val, "%d", &dcd->bufferSizeDB); else if (!stricmp(fieldName, "maxBitRate")) ret += sscanf(val, "%d", &dcd->maxBitrate); else if (!stricmp(fieldName, "avgBitRate")) ret += sscanf(val, "%d", &dcd->avgBitrate); } break; case GF_ODF_ESD_TAG: { GF_ESD *esd = (GF_ESD *)desc; if (!stricmp(fieldName, "ES_ID") || !stricmp(fieldName, "binaryID")) { ret += sscanf(val, "%hd", &esd->ESID); } else if (!stricmp(fieldName, "streamPriority")) GET_U8(esd->streamPriority) else if (!stricmp(fieldName, "dependsOn_ES_ID")) ret += sscanf(val, "%hd", &esd->dependsOnESID); else if (!stricmp(fieldName, "OCR_ES_ID")) ret += sscanf(val, "%hd", &esd->OCRESID); else if (!stricmp(fieldName, "URLstring")) { esd->URLString = strdup(val); ret = 1; } /*ignore*/ else if (!stricmp(fieldName, "streamDependenceFlag") || !stricmp(fieldName, "URL_Flag") || !stricmp(fieldName, "OCRstreamFlag") ) ret = 1; } break; case GF_ODF_SLC_TAG: { u32 ts; GF_SLConfig *slc = (GF_SLConfig*)desc; if (!stricmp(fieldName, "predefined")) GET_U8(slc->predefined) else if (!stricmp(fieldName, "useAccessUnitStartFlag")) GET_BOOL(slc->useAccessUnitStartFlag) else if (!stricmp(fieldName, "useAccessUnitEndFlag")) GET_BOOL(slc->useAccessUnitEndFlag) else if (!stricmp(fieldName, "useRandomAccessPointFlag")) GET_BOOL(slc->useRandomAccessPointFlag) else if (!stricmp(fieldName, "hasRandomAccessUnitsOnlyFlag") || !stricmp(fieldName, "useRandomAccessUnitsOnlyFlag")) GET_BOOL(slc->hasRandomAccessUnitsOnlyFlag) else if (!stricmp(fieldName, "usePaddingFlag")) GET_BOOL(slc->usePaddingFlag) else if (!stricmp(fieldName, "useTimeStampsFlag")) GET_BOOL(slc->useTimestampsFlag) else if (!stricmp(fieldName, "useIdleFlag")) GET_BOOL(slc->useIdleFlag) else if (!stricmp(fieldName, "timeStampResolution")) ret += sscanf(val, "%d", &slc->timestampResolution);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -