📄 odf_code.c
字号:
GF_Err gf_odf_read_dcd(GF_BitStream *bs, GF_DecoderConfig *dcd, u32 DescSize){ GF_Err e; u32 reserved, tmp_size, nbBytes = 0; if (! dcd) return GF_BAD_PARAM; dcd->objectTypeIndication = gf_bs_read_int(bs, 8); dcd->streamType = gf_bs_read_int(bs, 6); dcd->upstream = gf_bs_read_int(bs, 1); reserved = gf_bs_read_int(bs, 1); dcd->bufferSizeDB = gf_bs_read_int(bs, 24); dcd->maxBitrate = gf_bs_read_int(bs, 32); dcd->avgBitrate = gf_bs_read_int(bs, 32); nbBytes += 13; 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; switch (tmp->tag) { case GF_ODF_DSI_TAG: if (dcd->decoderSpecificInfo) { gf_odf_delete_descriptor(tmp); return GF_ODF_INVALID_DESCRIPTOR; } dcd->decoderSpecificInfo = (GF_DefaultDescriptor *) tmp; break; case GF_ODF_EXT_PL_TAG: e = gf_list_add(dcd->profileLevelIndicationIndexDescriptor, tmp); if (e < GF_OK) { gf_odf_delete_descriptor(tmp); return e; } break; /*iPod fix: delete and aborts, this will create an InvalidDescriptor at the ESD level with a loaded DSI, laoding will abort with a partially valid ESD which is all the matters*/ case GF_ODF_SLC_TAG: gf_odf_delete_descriptor(tmp); return GF_OK; //what the hell is this descriptor ?? Don't know, so delete it ! default: gf_odf_delete_descriptor(tmp); break; } 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_dcd(GF_DecoderConfig *dcd, u32 *outSize){ GF_Err e; u32 tmpSize; if (! dcd) return GF_BAD_PARAM; *outSize = 0; *outSize += 13; if (dcd->decoderSpecificInfo) { //warning: we don't know anything about the structure of a generic DecSpecInfo //we check the tag and size of the descriptor, but we most ofthe time can't parse it //the decSpecInfo is handle as a defaultDescriptor (opaque data, but same structure....) e = gf_odf_size_descriptor((GF_Descriptor *) dcd->decoderSpecificInfo , &tmpSize); if (e) return e; *outSize += tmpSize + gf_odf_size_field_size(tmpSize); } e = gf_odf_size_descriptor_list(dcd->profileLevelIndicationIndexDescriptor, outSize); if (e) return e; return GF_OK;}GF_Err gf_odf_write_dcd(GF_BitStream *bs, GF_DecoderConfig *dcd){ GF_Err e; u32 size; if (! dcd) return GF_BAD_PARAM; e = gf_odf_size_descriptor((GF_Descriptor *)dcd, &size); if (e) return e; e = gf_odf_write_base_descriptor(bs, dcd->tag, size); if (e) return e; gf_bs_write_int(bs, dcd->objectTypeIndication, 8); gf_bs_write_int(bs, dcd->streamType, 6); gf_bs_write_int(bs, dcd->upstream, 1); gf_bs_write_int(bs, 1, 1); //reserved field... gf_bs_write_int(bs, dcd->bufferSizeDB, 24); gf_bs_write_int(bs, dcd->maxBitrate, 32); gf_bs_write_int(bs, dcd->avgBitrate, 32); if (dcd->decoderSpecificInfo) { e = gf_odf_write_descriptor(bs, (GF_Descriptor *) dcd->decoderSpecificInfo); if (e) return e; } e = gf_odf_write_descriptor_list(bs, dcd->profileLevelIndicationIndexDescriptor); return e;}GF_Descriptor *gf_odf_new_default(){ GF_DefaultDescriptor *newDesc = (GF_DefaultDescriptor *) malloc(sizeof(GF_DefaultDescriptor)); if (!newDesc) return NULL; newDesc->dataLength = 0; newDesc->data = NULL; //set it to the Max allowed newDesc->tag = GF_ODF_USER_END_TAG; return (GF_Descriptor *) newDesc;}GF_Err gf_odf_del_default(GF_DefaultDescriptor *dd){ if (!dd) return GF_BAD_PARAM; if (dd->data) free(dd->data); free(dd); return GF_OK;}GF_Err gf_odf_read_default(GF_BitStream *bs, GF_DefaultDescriptor *dd, u32 DescSize){ u32 nbBytes = 0; if (! dd) return GF_BAD_PARAM; dd->dataLength = DescSize; dd->data = NULL; if (DescSize) { dd->data = (char*)malloc(dd->dataLength); if (! dd->data) return GF_OUT_OF_MEM; gf_bs_read_data(bs, dd->data, dd->dataLength); nbBytes += dd->dataLength; } if (nbBytes != DescSize) return GF_ODF_INVALID_DESCRIPTOR; return GF_OK;}GF_Err gf_odf_size_default(GF_DefaultDescriptor *dd, u32 *outSize){ if (! dd) return GF_BAD_PARAM; *outSize = dd->dataLength; return GF_OK;}GF_Err gf_odf_write_default(GF_BitStream *bs, GF_DefaultDescriptor *dd){ GF_Err e; u32 size; if (! dd) return GF_BAD_PARAM; e = gf_odf_size_descriptor((GF_Descriptor *)dd, &size); if (e) return e; e = gf_odf_write_base_descriptor(bs, dd->tag, size); if (e) return e; if (dd->data) { gf_bs_write_data(bs, dd->data, dd->dataLength); } return GF_OK;}GF_Descriptor *gf_odf_new_esd_inc(){ GF_ES_ID_Inc *newDesc = (GF_ES_ID_Inc *) malloc(sizeof(GF_ES_ID_Inc)); if (!newDesc) return NULL; newDesc->tag = GF_ODF_ESD_INC_TAG; newDesc->trackID = 0; return (GF_Descriptor *) newDesc;}GF_Err gf_odf_del_esd_inc(GF_ES_ID_Inc *esd_inc){ if (!esd_inc) return GF_BAD_PARAM; free(esd_inc); return GF_OK;}GF_Err gf_odf_read_esd_inc(GF_BitStream *bs, GF_ES_ID_Inc *esd_inc, u32 DescSize){ u32 nbBytes = 0; if (! esd_inc) return GF_BAD_PARAM; esd_inc->trackID = gf_bs_read_int(bs, 32); nbBytes += 4; if (nbBytes != DescSize) return GF_ODF_INVALID_DESCRIPTOR; return GF_OK;}GF_Err gf_odf_size_esd_inc(GF_ES_ID_Inc *esd_inc, u32 *outSize){ if (! esd_inc) return GF_BAD_PARAM; *outSize = 4; return GF_OK;}GF_Err gf_odf_write_esd_inc(GF_BitStream *bs, GF_ES_ID_Inc *esd_inc){ GF_Err e; u32 size; if (! esd_inc) return GF_BAD_PARAM; e = gf_odf_size_descriptor((GF_Descriptor *)esd_inc, &size); if (e) return e; e = gf_odf_write_base_descriptor(bs, esd_inc->tag, size); if (e) return e; gf_bs_write_int(bs, esd_inc->trackID, 32); return GF_OK;}GF_Descriptor *gf_odf_new_esd_ref(){ GF_ES_ID_Ref *newDesc = (GF_ES_ID_Ref *) malloc(sizeof(GF_ES_ID_Ref)); if (!newDesc) return NULL; newDesc->tag = GF_ODF_ESD_REF_TAG; newDesc->trackRef = 0; return (GF_Descriptor *) newDesc;}GF_Err gf_odf_del_esd_ref(GF_ES_ID_Ref *esd_ref){ if (!esd_ref) return GF_BAD_PARAM; free(esd_ref); return GF_OK;}GF_Err gf_odf_read_esd_ref(GF_BitStream *bs, GF_ES_ID_Ref *esd_ref, u32 DescSize){ u32 nbBytes = 0; if (! esd_ref) return GF_BAD_PARAM; esd_ref->trackRef = gf_bs_read_int(bs, 16); nbBytes += 2; if (nbBytes != DescSize) return GF_ODF_INVALID_DESCRIPTOR; return GF_OK;}GF_Err gf_odf_size_esd_ref(GF_ES_ID_Ref *esd_ref, u32 *outSize){ if (! esd_ref) return GF_BAD_PARAM; *outSize = 2; return GF_OK;}GF_Err gf_odf_write_esd_ref(GF_BitStream *bs, GF_ES_ID_Ref *esd_ref){ GF_Err e; u32 size; if (! esd_ref) return GF_BAD_PARAM; e = gf_odf_size_descriptor((GF_Descriptor *)esd_ref, &size); if (e) return e; e = gf_odf_write_base_descriptor(bs, esd_ref->tag, size); if (e) return e; gf_bs_write_int(bs, esd_ref->trackRef, 16); return GF_OK;}GF_Descriptor *gf_odf_new_exp_text(){ GF_ExpandedTextual *newDesc = (GF_ExpandedTextual *) malloc(sizeof(GF_ExpandedTextual)); if (!newDesc) return NULL; newDesc->itemDescriptionList = gf_list_new(); if (! newDesc->itemDescriptionList) { free(newDesc); return NULL; } newDesc->itemTextList = gf_list_new(); if (! newDesc->itemTextList) { free(newDesc->itemDescriptionList); free(newDesc); return NULL; } newDesc->isUTF8 = 0; newDesc->langCode = 0; newDesc->NonItemText = NULL; newDesc->tag = GF_ODF_TEXT_TAG; return (GF_Descriptor *) newDesc;}GF_Err gf_odf_del_exp_text(GF_ExpandedTextual *etd){ if (!etd) return GF_BAD_PARAM; while (gf_list_count(etd->itemDescriptionList)) { GF_ETD_ItemText *tmp = (GF_ETD_ItemText*)gf_list_get(etd->itemDescriptionList, 0); if (tmp) { if (tmp->text) free(tmp->text); free(tmp); } gf_list_rem(etd->itemDescriptionList, 0); } gf_list_del(etd->itemDescriptionList); while (gf_list_count(etd->itemTextList)) { GF_ETD_ItemText *tmp = (GF_ETD_ItemText*)gf_list_get(etd->itemTextList, 0); if (tmp) { if (tmp->text) free(tmp->text); free(tmp); } gf_list_rem(etd->itemTextList, 0); } gf_list_del(etd->itemTextList); if (etd->NonItemText) free(etd->NonItemText); free(etd); return GF_OK;}GF_Err gf_odf_read_exp_text(GF_BitStream *bs, GF_ExpandedTextual *etd, u32 DescSize){ GF_Err e; u32 nbBytes = 0; u32 i, aligned, len, nonLen, count; if (!etd) return GF_BAD_PARAM; etd->langCode = gf_bs_read_int(bs, 24); etd->isUTF8 = gf_bs_read_int(bs, 1); aligned = gf_bs_read_int(bs, 7); count = gf_bs_read_int(bs, 8); nbBytes += 5; for (i = 0; i< count; i++) { //description GF_ETD_ItemText *description, *Text; description = (GF_ETD_ItemText*)malloc(sizeof(GF_ETD_ItemText)); if (! description) return GF_OUT_OF_MEM; description->text = NULL; e = OD_ReadUTF8String(bs, & description->text, etd->isUTF8, &len); if (e) return e; e = gf_list_add(etd->itemDescriptionList, description); if (e) return e; nbBytes += len; //text Text = (GF_ETD_ItemText*)malloc(sizeof(GF_ETD_ItemText)); if (! Text) return GF_OUT_OF_MEM; Text->text = NULL; e = OD_ReadUTF8String(bs, & Text->text, etd->isUTF8, &len); if (e) return e; e = gf_list_add(etd->itemTextList, Text); if (e) return e; nbBytes += len; } len = gf_bs_read_int(bs, 8); nbBytes += 1; nonLen = 0; while (len == 255) { nonLen += len; len = gf_bs_read_int(bs, 8); nbBytes += 1; } nonLen += len; if (nonLen) { //here we have no choice but do the job ourselves //because the length is not encoded on 8 bits etd->NonItemText = (char *) malloc(sizeof(char) * (1+nonLen) * (etd->isUTF8 ? 1 : 2)); if (! etd->NonItemText) return GF_OUT_OF_MEM; gf_bs_read_data(bs, etd->NonItemText, nonLen * (etd->isUTF8 ? 1 : 2)); nbBytes += nonLen * (etd->isUTF8 ? 1 : 2); } if (nbBytes != DescSize) return GF_ODF_INVALID_DESCRIPTOR; return GF_OK;}GF_Err gf_odf_size_exp_text(GF_ExpandedTextual *etd, u32 *outSize){ u32 i, len, nonLen, lentmp, count; GF_ETD_ItemText *tmp; if (!etd) return GF_BAD_PARAM; *outSize = 5; if (gf_list_count(etd->itemDescriptionList) != gf_list_count(etd->itemTextList)) return GF_ODF_INVALID_DESCRIPTOR; count = gf_list_count(etd->itemDescriptionList); for (i=0; i<count; i++) { tmp = (GF_ETD_ItemText *)gf_list_get(etd->itemDescriptionList, i); *outSize += OD_SizeUTF8String(tmp->text, etd->isUTF8); tmp = (GF_ETD_ItemText*)gf_list_get(etd->itemTextList, i); *outSize += OD_SizeUTF8String(tmp->text, etd->isUTF8); } *outSize += 1; if (etd->NonItemText) { if (etd->isUTF8) { nonLen = strlen((const char*)etd->NonItemText); } else { nonLen = gf_utf8_wcslen((const unsigned short*)etd->NonItemText); } } else { nonLen = 0; } len = 255; lentmp = nonLen; if (lentmp < 255) { len = lentmp; } while (len == 255) { *outSize += 1; lentmp -= 255; if (lentmp < 255) { len = lentmp; } } *outSize += nonLen * (etd->isUTF8 ? 1 : 2); return GF_OK;}GF_Err gf_odf_write_exp_text(GF_BitStream *bs, GF_ExpandedTextual *etd){ GF_Err e; u32 size, i, len, nonLen, lentmp, count; GF_ETD_ItemText *tmp; if (!etd) return GF_BAD_PARAM; if (gf_list_count(etd->itemDescriptionList) != gf_list_count(etd->itemTextList)) return GF_ODF_INVALID_DESCRIPTOR; e = gf_odf_size_descriptor((GF_Descriptor *)etd, &size); if (e) return e; e = gf_odf_write_base_descriptor(bs, etd->tag, size); if (e) return e; gf_bs_write_int(bs, etd->langCode, 24); gf_bs_write_int(bs, etd->isUTF8, 1); gf_bs_write_int(bs, 0, 7); //aligned gf_bs_write_int(bs, gf_list_count(etd->itemDescriptionList), 8); count = gf_list_count(etd->itemDescriptionList); for (i=0; i<count; i++) { tmp = (GF_ETD_ItemText *)gf_list_get(etd->itemDescriptionList, i); OD_WriteUTF8String(bs, tmp->text, etd->isUTF8); tmp = (GF_ETD_ItemText*)gf_list_get(etd->itemTextList, i); OD_WriteUTF8String(bs, tmp->text, etd->isUTF8); } if (etd->NonItemText) { nonLen = strlen((const char*)etd->NonItemText) + 1; if (etd->isUTF8) { nonLen = strlen((const char*)etd->NonItemText); } else { nonLen = gf_utf8_wcslen((const unsigned short*)etd->NonItemText); } } else { nonLen = 0; } lentmp = nonLen; len = lentmp < 255 ? lentmp : 255; while (len == 255) { gf_bs_write_int(bs, len, 8); lentmp -= len; len = lentmp < 255 ? lentmp : 255; } gf_bs_write_int(bs, len, 8); gf_bs_write_data(bs, etd->NonItemText, nonLen * (etd->isUTF8 ? 1 : 2)); return GF_OK;}GF_Descriptor *gf_odf_new_pl_ext(){ GF_PLExt *newDesc = (GF_PLExt *) malloc(sizeof(GF_PLExt)); if (!newDesc) return NULL; newDesc->AudioProfileLevelIndication = 0; newDesc->GraphicsProfileLevelIndication = 0; newDesc->MPEGJProfileLevelIndication = 0; newDesc->ODProfileLevelIndication = 0; newDesc->profileLevelIndicationIndex = 0; newDesc->SceneProfileLevelIndication = 0; newDesc->VisualProfileLevelIndication = 0; newDesc->tag = GF_ODF_EXT_PL_TAG; return (GF_Descriptor *) newDesc;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -