📄 box_code_base.c
字号:
/* * GPAC - Multimedia Framework C SDK * * Copyright (c) Jean Le Feuvre 2000-2005 * All rights reserved * * This file is part of GPAC / ISO Media File Format 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/isomedia_dev.h>void co64_del(GF_Box *s){ GF_ChunkLargeOffsetBox *ptr; ptr = (GF_ChunkLargeOffsetBox *) s; if (ptr == NULL) return; if (ptr->offsets) free(ptr->offsets); free(ptr);}GF_Err co64_Read(GF_Box *s,GF_BitStream *bs){ GF_Err e; u32 entries; GF_ChunkLargeOffsetBox *ptr = (GF_ChunkLargeOffsetBox *) s; e = gf_isom_full_box_read(s, bs); if (e) return e; ptr->entryCount = gf_bs_read_u32(bs); ptr->offsets = (u64 *) malloc(ptr->entryCount * sizeof(u64) ); if (ptr->offsets == NULL) return GF_OUT_OF_MEM; for (entries = 0; entries < ptr->entryCount; entries++) { ptr->offsets[entries] = gf_bs_read_u64(bs); } return GF_OK;}GF_Box *co64_New(){ GF_ChunkLargeOffsetBox *tmp; tmp = (GF_ChunkLargeOffsetBox *) malloc(sizeof(GF_ChunkLargeOffsetBox)); if (tmp == NULL) return NULL; memset(tmp, 0, sizeof(GF_ChunkLargeOffsetBox)); gf_isom_full_box_init((GF_Box *)tmp); tmp->type = GF_ISOM_BOX_TYPE_CO64; return (GF_Box *)tmp;}//from here, for write/edit versions#ifndef GPAC_READ_ONLYGF_Err co64_Write(GF_Box *s, GF_BitStream *bs){ GF_Err e; u32 i; GF_ChunkLargeOffsetBox *ptr = (GF_ChunkLargeOffsetBox *) s; e = gf_isom_full_box_write(s, bs); if (e) return e; gf_bs_write_u32(bs, ptr->entryCount); for (i = 0; i < ptr->entryCount; i++ ) { gf_bs_write_u64(bs, ptr->offsets[i]); } return GF_OK;}GF_Err co64_Size(GF_Box *s){ GF_Err e; GF_ChunkLargeOffsetBox *ptr = (GF_ChunkLargeOffsetBox *) s; e = gf_isom_full_box_get_size(s); if (e) return e; ptr->size += 4 + (8 * ptr->entryCount); return GF_OK;}#endif //GPAC_READ_ONLYvoid cprt_del(GF_Box *s){ GF_CopyrightBox *ptr = (GF_CopyrightBox *) s; if (ptr == NULL) return; if (ptr->notice) free(ptr->notice); free(ptr);}GF_Box *chpl_New(){ GF_ChapterListBox *tmp; tmp = (GF_ChapterListBox *) malloc(sizeof(GF_ChapterListBox)); if (tmp == NULL) return NULL; memset(tmp, 0, sizeof(GF_CopyrightBox)); tmp->list = gf_list_new(); gf_isom_full_box_init((GF_Box *)tmp); tmp->type = GF_ISOM_BOX_TYPE_CHPL; tmp->version = 1; return (GF_Box *)tmp;}void chpl_del(GF_Box *s){ GF_ChapterListBox *ptr = (GF_ChapterListBox *) s; if (ptr == NULL) return; while (gf_list_count(ptr->list)) { GF_ChapterEntry *ce = (GF_ChapterEntry *)gf_list_get(ptr->list, 0); if (ce->name) free(ce->name); free(ce); gf_list_rem(ptr->list, 0); } gf_list_del(ptr->list); free(ptr);}/*this is using chpl format according to some NeroRecode samples*/GF_Err chpl_Read(GF_Box *s,GF_BitStream *bs){ GF_Err e; GF_ChapterEntry *ce; u32 nb_chaps, len, i, count; GF_ChapterListBox *ptr = (GF_ChapterListBox *)s; e = gf_isom_full_box_read(s, bs); if (e) return e; /*reserved or ???*/ gf_bs_read_u32(bs); nb_chaps = gf_bs_read_u8(bs); count = 0; while (nb_chaps) { GF_SAFEALLOC(ce, GF_ChapterEntry); ce->start_time = gf_bs_read_u64(bs); len = gf_bs_read_u8(bs); if (len) { ce->name = (char *)malloc(sizeof(char)*(len+1)); gf_bs_read_data(bs, ce->name, len); ce->name[len] = 0; } else { ce->name = strdup(""); } for (i=0;i<count; i++) { GF_ChapterEntry *ace = (GF_ChapterEntry *) gf_list_get(ptr->list, i); if (ace->start_time >= ce->start_time) { gf_list_insert(ptr->list, ce, i); ce = NULL; break; } } if (ce) gf_list_add(ptr->list, ce); count++; nb_chaps--; } return GF_OK;}#ifndef GPAC_READ_ONLYGF_Err chpl_Write(GF_Box *s, GF_BitStream *bs){ GF_Err e; u32 count, i; GF_ChapterListBox *ptr = (GF_ChapterListBox *) s; e = gf_isom_full_box_write(s, bs); if (e) return e; count = gf_list_count(ptr->list); gf_bs_write_u32(bs, 0); gf_bs_write_u8(bs, count); for (i=0; i<count; i++) { u32 len; GF_ChapterEntry *ce = (GF_ChapterEntry *)gf_list_get(ptr->list, i); gf_bs_write_u64(bs, ce->start_time); if (ce->name) { len = strlen(ce->name); if (len>255) len = 255; gf_bs_write_u8(bs, len); gf_bs_write_data(bs, ce->name, len); } else { gf_bs_write_u8(bs, 0); } } return GF_OK;}GF_Err chpl_Size(GF_Box *s){ GF_Err e; u32 count, i; GF_ChapterListBox *ptr = (GF_ChapterListBox *)s; e = gf_isom_full_box_get_size(s); if (e) return e; ptr->size += 5; count = gf_list_count(ptr->list); for (i=0; i<count; i++) { GF_ChapterEntry *ce = (GF_ChapterEntry *)gf_list_get(ptr->list, i); ptr->size += 9; /*64bit time stamp + 8bit str len*/ if (ce->name) ptr->size += strlen(ce->name); } return GF_OK;}#endifGF_Err cprt_Read(GF_Box *s,GF_BitStream *bs){ GF_Err e; GF_CopyrightBox *ptr = (GF_CopyrightBox *)s; e = gf_isom_full_box_read(s, bs); if (e) return e; gf_bs_read_int(bs, 1); //the spec is unclear here, just says "the value 0 is interpreted as undetermined" ptr->packedLanguageCode[0] = gf_bs_read_int(bs, 5); ptr->packedLanguageCode[1] = gf_bs_read_int(bs, 5); ptr->packedLanguageCode[2] = gf_bs_read_int(bs, 5); ptr->size -= 2; //but before or after compaction ?? We assume before if (ptr->packedLanguageCode[0] || ptr->packedLanguageCode[1] || ptr->packedLanguageCode[2]) { ptr->packedLanguageCode[0] += 0x60; ptr->packedLanguageCode[1] += 0x60; ptr->packedLanguageCode[2] += 0x60; } else { ptr->packedLanguageCode[0] = 'u'; ptr->packedLanguageCode[1] = 'n'; ptr->packedLanguageCode[2] = 'd'; } if (ptr->size) { u32 bytesToRead = (u32) ptr->size; ptr->notice = (char*)malloc(bytesToRead * sizeof(char)); if (ptr->notice == NULL) return GF_OUT_OF_MEM; gf_bs_read_data(bs, ptr->notice, bytesToRead); } return GF_OK;}GF_Box *cprt_New(){ GF_CopyrightBox *tmp; tmp = (GF_CopyrightBox *) malloc(sizeof(GF_CopyrightBox)); if (tmp == NULL) return NULL; memset(tmp, 0, sizeof(GF_CopyrightBox)); gf_isom_full_box_init((GF_Box *)tmp); tmp->type = GF_ISOM_BOX_TYPE_CPRT; tmp->packedLanguageCode[0] = 'u'; tmp->packedLanguageCode[1] = 'n'; tmp->packedLanguageCode[2] = 'd'; return (GF_Box *)tmp;}//from here, for write/edit versions#ifndef GPAC_READ_ONLYGF_Err cprt_Write(GF_Box *s, GF_BitStream *bs){ GF_Err e; GF_CopyrightBox *ptr = (GF_CopyrightBox *) s; e = gf_isom_full_box_write(s, bs); if (e) return e; gf_bs_write_int(bs, 0, 1); if (ptr->packedLanguageCode[0]) { gf_bs_write_int(bs, ptr->packedLanguageCode[0] - 0x60, 5); gf_bs_write_int(bs, ptr->packedLanguageCode[1] - 0x60, 5); gf_bs_write_int(bs, ptr->packedLanguageCode[2] - 0x60, 5); } else { gf_bs_write_int(bs, 0, 15); } if (ptr->notice) { gf_bs_write_data(bs, ptr->notice, (unsigned long)strlen(ptr->notice) + 1); } return GF_OK;}GF_Err cprt_Size(GF_Box *s){ GF_Err e; GF_CopyrightBox *ptr = (GF_CopyrightBox *)s; e = gf_isom_full_box_get_size(s); if (e) return e; ptr->size += 2; if (ptr->notice) ptr->size += strlen(ptr->notice) + 1; return GF_OK;}#endif //GPAC_READ_ONLYvoid ctts_del(GF_Box *s){ u32 entryCount; u32 i; GF_DttsEntry *pe; GF_CompositionOffsetBox *ptr = (GF_CompositionOffsetBox *)s; if (ptr == NULL) return; if (ptr->entryList) { entryCount = gf_list_count(ptr->entryList); for ( i = 0; i < entryCount; i++ ) { pe = (GF_DttsEntry*)gf_list_get(ptr->entryList, i); if (pe) free(pe); } gf_list_del(ptr->entryList); } free(ptr);}GF_Err ctts_Read(GF_Box *s, GF_BitStream *bs){ GF_Err e; u32 entries; u32 entryCount; u32 count, sampleCount; s32 decodingOffset; GF_DttsEntry *p; GF_CompositionOffsetBox *ptr = (GF_CompositionOffsetBox *)s; p = NULL; e = gf_isom_full_box_read(s, bs); if (e) return e; entryCount = gf_bs_read_u32(bs); sampleCount = 0; for ( entries = 0; entries < entryCount; entries++ ) { p = (GF_DttsEntry *) malloc(sizeof(GF_DttsEntry)); if (!p) return GF_OUT_OF_MEM; count = gf_bs_read_u32(bs); decodingOffset = gf_bs_read_u32(bs); p->sampleCount = count; sampleCount += count; p->decodingOffset = decodingOffset; gf_list_add(ptr->entryList, p); }#ifndef GPAC_READ_ONLY ptr->w_currentEntry = p; ptr->w_LastSampleNumber = sampleCount;#endif return GF_OK;}GF_Box *ctts_New(){ GF_CompositionOffsetBox *tmp; tmp = (GF_CompositionOffsetBox *) malloc(sizeof(GF_CompositionOffsetBox)); if (tmp == NULL) return NULL; memset(tmp, 0, sizeof(GF_CompositionOffsetBox)); gf_isom_full_box_init((GF_Box *) tmp); tmp->entryList = gf_list_new(); if (! tmp->entryList) { free(tmp); return NULL; } tmp->type = GF_ISOM_BOX_TYPE_CTTS; return (GF_Box *) tmp;}//from here, for write/edit versions#ifndef GPAC_READ_ONLYGF_Err ctts_Write(GF_Box *s, GF_BitStream *bs){ GF_Err e; u32 i; u32 entryCount; GF_DttsEntry *p; GF_CompositionOffsetBox *ptr = (GF_CompositionOffsetBox *)s; e = gf_isom_full_box_write(s, bs); if (e) return e; entryCount = gf_list_count(ptr->entryList); gf_bs_write_u32(bs, entryCount); for ( i = 0; i < entryCount; i++ ) { p = (GF_DttsEntry*)gf_list_get(ptr->entryList, i); if (p) { gf_bs_write_u32(bs, p->sampleCount); gf_bs_write_u32(bs, p->decodingOffset); } } return GF_OK;}GF_Err ctts_Size(GF_Box *s){ GF_Err e; u32 entryCount; GF_CompositionOffsetBox *ptr = (GF_CompositionOffsetBox *) s; e = gf_isom_full_box_get_size(s); if (e) return e; entryCount = gf_list_count(ptr->entryList); ptr->size += 4 + (8 * entryCount); return GF_OK;}#endif //GPAC_READ_ONLYvoid url_del(GF_Box *s){ GF_DataEntryURLBox *ptr = (GF_DataEntryURLBox *)s; if (ptr == NULL) return; if (ptr->location) free(ptr->location); free(ptr); return;}GF_Err url_Read(GF_Box *s, GF_BitStream *bs){ GF_Err e; GF_DataEntryURLBox *ptr = (GF_DataEntryURLBox *)s; e = gf_isom_full_box_read(s, bs); if (e) return e; if (ptr->size) { ptr->location = (char*)malloc((u32) ptr->size); if (! ptr->location) return GF_OUT_OF_MEM; gf_bs_read_data(bs, ptr->location, (u32)ptr->size); } return GF_OK;}GF_Box *url_New(){ GF_DataEntryURLBox *tmp = (GF_DataEntryURLBox *) malloc(sizeof(GF_DataEntryURLBox)); if (tmp == NULL) return NULL; memset(tmp, 0, sizeof(GF_DataEntryURLBox)); gf_isom_full_box_init((GF_Box *)tmp); tmp->type = GF_ISOM_BOX_TYPE_URL; return (GF_Box *)tmp;}//from here, for write/edit versions#ifndef GPAC_READ_ONLYGF_Err url_Write(GF_Box *s, GF_BitStream *bs){ GF_Err e; GF_DataEntryURLBox *ptr = (GF_DataEntryURLBox *)s; e = gf_isom_full_box_write(s, bs); if (e) return e; //the flag set indicates we have a string (WE HAVE TO for URLs) if ( !(ptr->flags & 1)) { if (ptr->location) { gf_bs_write_data(bs, ptr->location, (u32)strlen(ptr->location) + 1); } } return GF_OK;}GF_Err url_Size(GF_Box *s){ GF_Err e; GF_DataEntryURLBox *ptr = (GF_DataEntryURLBox *)s; e = gf_isom_full_box_get_size(s); if (e) return e; if ( !(ptr->flags & 1)) { if (ptr->location) ptr->size += 1 + strlen(ptr->location); } return GF_OK;}#endif //GPAC_READ_ONLYvoid urn_del(GF_Box *s){ GF_DataEntryURNBox *ptr = (GF_DataEntryURNBox *)s; if (ptr == NULL) return; if (ptr->location) free(ptr->location); if (ptr->nameURN) free(ptr->nameURN); free(ptr);}GF_Err urn_Read(GF_Box *s, GF_BitStream *bs){ GF_Err e; u32 i, to_read; char *tmpName; GF_DataEntryURNBox *ptr = (GF_DataEntryURNBox *)s; e = gf_isom_full_box_read(s, bs); if (e) return e; if (! ptr->size ) return GF_OK; //here we have to handle that in a clever way to_read = (u32) ptr->size; tmpName = (char*)malloc(sizeof(char) * to_read); if (!tmpName) return GF_OUT_OF_MEM; //get the data gf_bs_read_data(bs, tmpName, to_read); //then get the break i = 0; while ( (tmpName[i] != 0) && (i < to_read) ) { i++; } //check the data is consistent if (i == to_read) { free(tmpName); return GF_ISOM_INVALID_FILE; } //no NULL char, URL is not specified if (i == to_read - 1) { ptr->nameURN = tmpName; ptr->location = NULL; return GF_OK; } //OK, this has both URN and URL ptr->nameURN = (char*)malloc(sizeof(char) * (i+1)); if (!ptr->nameURN) { free(tmpName); return GF_OUT_OF_MEM; } ptr->location = (char*)malloc(sizeof(char) * (to_read - i - 1)); if (!ptr->location) { free(tmpName); free(ptr->nameURN); ptr->nameURN = NULL; return GF_OUT_OF_MEM; } memcpy(ptr->nameURN, tmpName, i + 1); memcpy(ptr->location, tmpName + i + 1, (to_read - i - 1)); free(tmpName); return GF_OK;}GF_Box *urn_New(){ GF_DataEntryURNBox *tmp = (GF_DataEntryURNBox *) malloc(sizeof(GF_DataEntryURNBox)); if (tmp == NULL) return NULL; memset(tmp, 0, sizeof(GF_DataEntryURNBox)); gf_isom_full_box_init((GF_Box *)tmp); tmp->type = GF_ISOM_BOX_TYPE_URN; return (GF_Box *)tmp;}//from here, for write/edit versions#ifndef GPAC_READ_ONLYGF_Err urn_Write(GF_Box *s, GF_BitStream *bs){ GF_Err e; GF_DataEntryURNBox *ptr = (GF_DataEntryURNBox *)s; e = gf_isom_full_box_write(s, bs); if (e) return e;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -