⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stbl_write.c

📁 一个用于智能手机的多媒体库适合S60 WinCE的跨平台开发库
💻 C
📖 第 1 页 / 共 4 页
字号:
			ent->sampleCount++;			break;		}		if (DTSs[i+1] - DTSs[i] == ent->sampleDelta) {			ent->sampleCount += 1;		} else {			ent = (GF_SttsEntry*)malloc(sizeof(GF_SttsEntry));			ent->sampleCount = 1;			ent->sampleDelta = (u32) (DTSs[i+1] - DTSs[i]);			gf_list_add(stts->entryList, ent);		}		i++;	}	stts->w_LastDTS = DTSs[stbl->SampleSize->sampleCount - 2];	free(DTSs);	//reset write the cache to the end	stts->w_currentEntry = ent;	stts->w_currentSampleNum = stbl->SampleSize->sampleCount - 1;	//reset read the cache to the begining	stts->r_FirstSampleInEntry = stts->r_currentEntryIndex = 0;	stts->r_CurrentDTS = 0;	return GF_OK;}//always called before removing the sample from SampleSizeGF_Err stbl_RemoveCTS(GF_SampleTableBox *stbl, u32 sampleNumber){	u32 *CTSs;	u32 sampNum, i, j, k, count;	GF_DttsEntry *ent;	GF_CompositionOffsetBox *ctts;	ctts = stbl->CompositionOffset;	//last one...	if (stbl->SampleSize->sampleCount == 1) {		gf_isom_box_del((GF_Box *) ctts);		stbl->CompositionOffset = NULL;		return GF_OK;	}	//the number of entries is NOT ALWAYS the number of samples !	//instead, use the cache	//first case, we're removing a sample that was not added yet	if (sampleNumber > ctts->w_LastSampleNumber) return GF_OK;	//No, the sample was here...	//this is the only one we have.	if (ctts->w_LastSampleNumber == 1) {		gf_isom_box_del((GF_Box *) ctts);		stbl->CompositionOffset = NULL;		return GF_OK;	}	CTSs = (u32*)malloc(sizeof(u32) * (ctts->w_LastSampleNumber - 1));	sampNum = 0;	k = 0;	count = gf_list_count(ctts->entryList);	for (i=0; i<count; i++) {		ent = (GF_DttsEntry*)gf_list_get(ctts->entryList, i);		for (j = 0; j<ent->sampleCount; j++) {			if (sampNum + 1 == sampleNumber) {				k = 1;			} else {				CTSs[sampNum-k] = ent->decodingOffset;			}			sampNum ++;		}	}		//delete the entries	while (gf_list_count(ctts->entryList)) {		ent = (GF_DttsEntry*)gf_list_get(ctts->entryList, 0);		free(ent);		gf_list_rem(ctts->entryList, 0);	}		//rewrite the table	ent = (GF_DttsEntry*)malloc(sizeof(GF_DttsEntry));	ent->sampleCount = 1;	ent->decodingOffset = CTSs[0];	i = 1;	while (1) {		if (i+1 == ctts->w_LastSampleNumber) {			gf_list_add(ctts->entryList, ent);			break;		}		if (CTSs[i] == ent->decodingOffset) {			ent->sampleCount += 1;		} else {			gf_list_add(ctts->entryList, ent);			ent = (GF_DttsEntry*)malloc(sizeof(GF_DttsEntry));			ent->sampleCount = 1;			ent->decodingOffset = CTSs[i];		}		i++;	}	free(CTSs);	//reset the cache to the end	ctts->w_currentEntry = ent;	//we've removed a sample, therefore the last sample (n) has now number n-1	//we cannot use SampleCount because we have probably skipped some samples	//(we're calling AddCTS only if the sample gas a CTSOffset !!!)	ctts->w_LastSampleNumber -= 1;	return GF_OK;}GF_Err stbl_RemoveSize(GF_SampleSizeBox *stsz, u32 sampleNumber){	u32 *newSizes;	u32 i, k, prevSize;	//last sample	if (stsz->sampleCount == 1) {		if (stsz->sizes) free(stsz->sizes);		stsz->sizes = NULL;		stsz->sampleCount = 0;		return GF_OK;	}	//one single size	if (stsz->sampleSize) {		stsz->sampleCount -= 1;		return GF_OK;	}	if (sampleNumber == stsz->sampleCount) {		stsz->sizes = (u32*) realloc(stsz->sizes, sizeof(u32) * (stsz->sampleCount - 1));		stsz->sampleCount--;		return GF_OK;	}	//reallocate and check size by the way...	newSizes = (u32*)malloc(sizeof(u32) * (stsz->sampleCount - 1));	if (sampleNumber == 1) {		prevSize = stsz->sizes[1];	} else {		prevSize = stsz->sizes[0];	}	k=0;	for (i=0; i<stsz->sampleCount; i++) {		if (i+1 == sampleNumber) {			k=1;		} else {			newSizes[i-k] = stsz->sizes[i];		}	}	//only in non-compact mode	free(stsz->sizes);	stsz->sizes = newSizes;	stsz->sampleSize = 0;	stsz->sampleCount -= 1;	return GF_OK;}//always called after removing the sample from SampleSizeGF_Err stbl_RemoveChunk(GF_SampleTableBox *stbl, u32 sampleNumber){	u32 i, k, count;	u32 *offsets;	u64 *Loffsets;	GF_StscEntry *ent;	//remove the entry in SampleToChunk (1 <-> 1 in edit mode)	ent = (GF_StscEntry*)gf_list_get(stbl->SampleToChunk->entryList, sampleNumber - 1);	gf_list_rem(stbl->SampleToChunk->entryList, sampleNumber - 1);	free(ent);	//update the firstchunk info	count=gf_list_count(stbl->SampleToChunk->entryList);	for (i = sampleNumber - 1; i < count; i++) {		ent = (GF_StscEntry*)gf_list_get(stbl->SampleToChunk->entryList, i);		ent->firstChunk -= 1;		ent->nextChunk -= 1;	}	//update the cache	stbl->SampleToChunk->firstSampleInCurrentChunk = 1;	stbl->SampleToChunk->currentEntry = (GF_StscEntry*)gf_list_get(stbl->SampleToChunk->entryList, 0);	stbl->SampleToChunk->currentIndex = 0;	stbl->SampleToChunk->currentChunk = 1;	stbl->SampleToChunk->ghostNumber = 1;	//realloc the chunk offset	if (stbl->ChunkOffset->type == GF_ISOM_BOX_TYPE_STCO) {		if (!stbl->SampleSize->sampleCount) {			free(((GF_ChunkOffsetBox *)stbl->ChunkOffset)->offsets);			((GF_ChunkOffsetBox *)stbl->ChunkOffset)->offsets = NULL;			((GF_ChunkOffsetBox *)stbl->ChunkOffset)->entryCount = 0;			return GF_OK;		}		offsets = (u32*)malloc(sizeof(u32) * (stbl->SampleSize->sampleCount));		k=0;		for (i=0; i<stbl->SampleSize->sampleCount+1; i++) {			if (i+1 == sampleNumber) {				k=1;			} else {				offsets[i-k] = ((GF_ChunkOffsetBox *)stbl->ChunkOffset)->offsets[i];			}		}		free(((GF_ChunkOffsetBox *)stbl->ChunkOffset)->offsets);		((GF_ChunkOffsetBox *)stbl->ChunkOffset)->offsets = offsets;		((GF_ChunkOffsetBox *)stbl->ChunkOffset)->entryCount -= 1;	} else {		if (!stbl->SampleSize->sampleCount) {			free(((GF_ChunkLargeOffsetBox *)stbl->ChunkOffset)->offsets);			((GF_ChunkLargeOffsetBox *)stbl->ChunkOffset)->offsets = NULL;			((GF_ChunkLargeOffsetBox *)stbl->ChunkOffset)->entryCount = 0;			return GF_OK;		}		Loffsets = (u64*)malloc(sizeof(u64) * (stbl->SampleSize->sampleCount));		k=0;		for (i=0; i<stbl->SampleSize->sampleCount+1; i++) {			if (i+1 == sampleNumber) {				k=1;			} else {				Loffsets[i-k] = ((GF_ChunkLargeOffsetBox *)stbl->ChunkOffset)->offsets[i];			}		}		free(((GF_ChunkLargeOffsetBox *)stbl->ChunkOffset)->offsets);		((GF_ChunkLargeOffsetBox *)stbl->ChunkOffset)->offsets = Loffsets;		((GF_ChunkLargeOffsetBox *)stbl->ChunkOffset)->entryCount -= 1;	}	return GF_OK;}GF_Err stbl_RemoveRAP(GF_SampleTableBox *stbl, u32 sampleNumber){	u32 i;	GF_SyncSampleBox *stss = stbl->SyncSample;	//we remove the only one around...	if (stss->entryCount == 1) {		if (stss->sampleNumbers[0] != sampleNumber) return GF_OK;		//free our numbers but don't delete (all samples are NON-sync		free(stss->sampleNumbers);		stss->sampleNumbers = NULL;		stss->r_LastSampleIndex = stss->r_LastSyncSample = 0;		stss->entryCount = 0;		return GF_OK;	}	//the real pain is that we may actually not have to change anything..	for (i=0; i<stss->entryCount; i++) {		if (sampleNumber == stss->sampleNumbers[i]) goto found;	}	//nothing to do	return GF_OK;found:	//a small opt: the sample numbers are in order...	i++;	for (;i<stss->entryCount; i++) {		stss->sampleNumbers[i-1] = stss->sampleNumbers[i];	}	//and just realloc	stss->sampleNumbers = (u32*)realloc(stss->sampleNumbers, sizeof(u32) * (stss->entryCount-1));	stss->entryCount -= 1;	return GF_OK;}GF_Err stbl_RemoveRedundant(GF_SampleTableBox *stbl, u32 SampleNumber){	u32 i;	if (!stbl->SampleDep) return GF_OK;	if (stbl->SampleDep->sampleCount < SampleNumber) return GF_BAD_PARAM;	i = stbl->SampleDep->sampleCount - SampleNumber;	if (i) memmove(&stbl->SampleDep->sample_info[SampleNumber-1], & stbl->SampleDep->sample_info[SampleNumber], sizeof(u8)*i);	stbl->SampleDep->sample_info = (u8*)realloc(stbl->SampleDep->sample_info, sizeof(u8) * (stbl->SampleDep->sampleCount-1));	stbl->SampleDep->sampleCount-=1;	return GF_OK;}GF_Err stbl_RemoveShadow(GF_ShadowSyncBox *stsh, u32 sampleNumber){	u32 i;	GF_StshEntry *ent;	//we loop for the whole chain cause the spec doesn't say if we can have several	//shadows for 1 sample...	i=0;	while ((ent = (GF_StshEntry *)gf_list_enum(stsh->entries, &i))) {		if (ent->shadowedSampleNumber == sampleNumber) {			i--;			gf_list_rem(stsh->entries, i);		}	}	//reset the cache	stsh->r_LastEntryIndex = 0;	stsh->r_LastFoundSample = 0;	return GF_OK;}GF_Err stbl_SetPaddingBits(GF_SampleTableBox *stbl, u32 SampleNumber, u8 bits){	u8 *p;	//make sure the sample is a good one	if (SampleNumber > stbl->SampleSize->sampleCount) return GF_BAD_PARAM;	//create the table	if (!stbl->PaddingBits) stbl->PaddingBits = (GF_PaddingBitsBox *) gf_isom_box_new(GF_ISOM_BOX_TYPE_FADB);	//alloc	if (!stbl->PaddingBits->padbits || !stbl->PaddingBits->SampleCount) {		stbl->PaddingBits->SampleCount = stbl->SampleSize->sampleCount;		stbl->PaddingBits->padbits = (u8*)malloc(sizeof(u8)*stbl->PaddingBits->SampleCount);		if (!stbl->PaddingBits->padbits) return GF_OUT_OF_MEM;		memset(stbl->PaddingBits->padbits, 0, sizeof(u8)*stbl->PaddingBits->SampleCount);	}	//realloc (this is needed in case n out of k samples get padding added)	if (stbl->PaddingBits->SampleCount < stbl->SampleSize->sampleCount) {		p = (u8*)malloc(sizeof(u8) * stbl->SampleSize->sampleCount);		if (!p) return GF_OUT_OF_MEM;		//set everything to 0		memset(p, 0, stbl->SampleSize->sampleCount);		//copy our previous table		memcpy(p, stbl->PaddingBits->padbits, stbl->PaddingBits->SampleCount);		free(stbl->PaddingBits->padbits);		stbl->PaddingBits->padbits = p;		stbl->PaddingBits->SampleCount = stbl->SampleSize->sampleCount;	}	stbl->PaddingBits->padbits[SampleNumber-1] = bits;	return GF_OK;}GF_Err stbl_RemovePaddingBits(GF_SampleTableBox *stbl, u32 SampleNumber){	u8 *p;	u32 i, k;	if (!stbl->PaddingBits) return GF_OK;	if (stbl->PaddingBits->SampleCount < SampleNumber) return GF_BAD_PARAM;	//last sample - remove the table	if (stbl->PaddingBits->SampleCount == 1) {		gf_isom_box_del((GF_Box *) stbl->PaddingBits);		stbl->PaddingBits = NULL;		return GF_OK;	}	//reallocate and check size by the way...	p = (u8 *)malloc(sizeof(u8) * (stbl->PaddingBits->SampleCount - 1));	if (!p) return GF_OUT_OF_MEM;	k=0;	for (i=0; i<stbl->PaddingBits->SampleCount; i++) {		if (i+1 != SampleNumber) {			p[k] = stbl->PaddingBits->padbits[i];			k++;		}	}		stbl->PaddingBits->SampleCount -= 1;	free(stbl->PaddingBits->padbits);	stbl->PaddingBits->padbits = p;	return GF_OK;}GF_Err stbl_AddSampleFragment(GF_SampleTableBox *stbl, u32 sampleNumber, u16 size){	GF_Err e;	u32 i, count;	GF_StsfEntry *ent;	u16 *newSizes;	GF_SampleFragmentBox *stsf;			stsf = stbl->Fragments;	if (!stsf) {		//create table if any		stsf = (GF_SampleFragmentBox *) gf_isom_box_new(GF_ISOM_BOX_TYPE_STSF);		if (!stsf) return GF_OUT_OF_MEM;		e = stbl_AddBox(stbl, (GF_Box *) stsf);		if (e) return e;	}	//check cache	if (!stsf->w_currentEntry || (stsf->w_currentEntry->SampleNumber < sampleNumber)) {		stsf->w_currentEntry = NULL;		stsf->w_currentEntryIndex = 0;	}	i = stsf->w_currentEntryIndex;	count = gf_list_count(stsf->entryList);	for (; i<count; i++) {		ent = (GF_StsfEntry *)gf_list_get(stsf->entryList, i);		if (ent->SampleNumber > sampleNumber) {			ent = (GF_StsfEntry *)malloc(sizeof(GF_StsfEntry));			memset(ent, 0, sizeof(GF_StsfEntry));			ent->SampleNumber = sampleNumber;			gf_list_insert(stsf->entryList, ent, i);			stsf->w_currentEntry = ent;			stsf->w_currentEntryIndex = i;			goto ent_found;		}		else if (ent->SampleNumber == sampleNumber) {			stsf->w_currentEntry = ent;			stsf->w_currentEntryIndex = i;			goto ent_found;		}	}	//if we get here add a new entry	GF_SAFEALLOC(ent, GF_StsfEntry);	ent->SampleNumber = sampleNumber;	gf_list_add(stsf->entryList, ent);	stsf->w_currentEntry = ent;	stsf->w_currentEntryIndex = gf_list_count(stsf->entryList)-1;ent_found:	if (!ent->fragmentCount) {		ent->fragmentCount = 1;		ent->fragmentSizes = (u16*)malloc(sizeof(u16));		ent->fragmentSizes[0] = size;		return GF_OK;	}	newSizes = (u16*)malloc(sizeof(u16) * (ent->fragmentCount+1));	memcpy(newSizes, ent->fragmentSizes, sizeof(u16) * ent->fragmentCount);	newSizes[ent->fragmentCount] = size;	free(ent->fragmentSizes);	ent->fragmentSizes = newSizes;	ent->fragmentCount += 1;	return GF_OK;}GF_Err stbl_RemoveSampleFragments(GF_SampleTableBox *stbl, u32 sampleNumber){	u32 i;	GF_StsfEntry *ent;	GF_SampleFragmentBox *stsf = stbl->Fragments;	i=0;	while ((ent = (GF_StsfEntry *)gf_list_enum(stsf->entryList, &i))) {		if (ent->SampleNumber == sampleNumber) {			gf_list_rem(stsf->entryList, i-1);			if (ent->fragmentSizes) free(ent->fragmentSizes);			free(ent);			goto exit;		}	}exit:	//empty table, remove it	if (!gf_list_count(stsf->entryList)) {		stbl->Fragments = NULL;		gf_isom_box_del((GF_Box *)stsf);	}	return GF_OK;}GF_Err stbl_SampleSizeAppend(GF_SampleSizeBox *stsz, u32 data_size){	u32 i;	if (!stsz || !stsz->sampleCount) return GF_BAD_PARAM;		//we must realloc our table	if (stsz->sampleSize) {		stsz->sizes = (u32*)malloc(sizeof(u32)*stsz->sampleCount);		for (i=0; i<stsz->sampleCount; i++) stsz->sizes[i] = stsz->sampleSize;		stsz->sampleSize = 0;	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -