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

📄 odf_command.c

📁 一个用于智能手机的多媒体库适合S60 WinCE的跨平台开发库
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *			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>GF_Err gf_odf_parse_command(GF_BitStream *bs, GF_ODCom **com, u32 *com_size){	u32 val, size, sizeHeader;	u8 tag;	GF_Err err;	GF_ODCom *newCom;	if (!bs) return GF_BAD_PARAM;	*com_size = 0;	//tag	tag = gf_bs_read_int(bs, 8);	sizeHeader = 1;		//size	size = 0;	do {		val = gf_bs_read_int(bs, 8);		sizeHeader++;		size <<= 7;		size |= val & 0x7F;	} while ( val & 0x80 );	*com_size = size;	newCom = gf_odf_create_command(tag);	if (! newCom) {		*com = NULL;		return GF_OUT_OF_MEM;	}	newCom->tag = tag;	err = gf_odf_read_command(bs, newCom, *com_size);	//little trick to handle lazy bitstreams that encode 	//SizeOfInstance on a fix number of bytes	//This nb of bytes is added in Read methods	*com_size += sizeHeader - gf_odf_size_field_size(*com_size);	*com = newCom;	if (err) {		gf_odf_delete_command(newCom);		*com = NULL;	}	return err;}GF_ODCom *gf_odf_new_base_command(){	GF_BaseODCom *newCom = (GF_BaseODCom *) malloc(sizeof(GF_BaseODCom));	if (!newCom) return NULL;	newCom->dataSize = 0;	newCom->data = NULL;	return (GF_ODCom *)newCom;}GF_Err gf_odf_del_base_command(GF_BaseODCom *bcRemove){	if (! bcRemove) return GF_BAD_PARAM;	if (bcRemove->data) free(bcRemove->data);	free(bcRemove);	return GF_OK;}GF_Err gf_odf_read_base_command(GF_BitStream *bs, GF_BaseODCom *bcRem, u32 gf_odf_size_command){	if (! bcRem) return GF_BAD_PARAM;	bcRem->dataSize = gf_odf_size_command;	bcRem->data = (char *) malloc(sizeof(char) * bcRem->dataSize);	if (! bcRem->data) return GF_OUT_OF_MEM;	gf_bs_read_data(bs, bcRem->data, bcRem->dataSize);	return GF_OK;}GF_Err gf_odf_size_base_command(GF_BaseODCom *bcRem, u32 *outSize){	if (!bcRem) return GF_BAD_PARAM;	*outSize = bcRem->dataSize;	return GF_OK;}GF_Err gf_odf_write_base_command(GF_BitStream *bs, GF_BaseODCom *bcRem){	u32 size;	GF_Err e;	if (! bcRem) return GF_BAD_PARAM;	e = gf_odf_size_base_command(bcRem, &size);	if (e) return e;	e = gf_odf_write_base_descriptor(bs, bcRem->tag, size);	if (e) return e;	gf_bs_write_data(bs, bcRem->data, bcRem->dataSize);	return GF_OK;}GF_ODCom *gf_odf_new_od_remove(){	GF_ODRemove *newCom = (GF_ODRemove *) malloc(sizeof(GF_ODRemove));	if (!newCom) return NULL;	newCom->NbODs = 0;	newCom->OD_ID = NULL;	newCom->tag = GF_ODF_OD_REMOVE_TAG;	return (GF_ODCom *)newCom;}GF_Err gf_odf_del_od_remove(GF_ODRemove *ODRemove){	if (! ODRemove) return GF_BAD_PARAM;	if (ODRemove->OD_ID) free(ODRemove->OD_ID);	free(ODRemove);	return GF_OK;}GF_Err gf_odf_read_od_remove(GF_BitStream *bs, GF_ODRemove *odRem, u32 gf_odf_size_command){	u32 i = 0, nbBits;	if (! odRem) return GF_BAD_PARAM;	odRem->NbODs = (u32 ) (gf_odf_size_command * 8) / 10;	odRem->OD_ID = (u16 *) malloc(sizeof(u16) * odRem->NbODs);	if (! odRem->OD_ID) return GF_OUT_OF_MEM;	for (i = 0; i < odRem->NbODs ; i++) {		odRem->OD_ID[i] = gf_bs_read_int(bs, 10);	}	nbBits = odRem->NbODs * 10;	//now we need to align !!!	nbBits += gf_bs_align(bs);	if (nbBits != (gf_odf_size_command * 8)) return GF_ODF_INVALID_COMMAND;	return GF_OK;}GF_Err gf_odf_size_od_remove(GF_ODRemove *odRem, u32 *outSize){	u32 size;	if (!odRem) return GF_BAD_PARAM;		size = 10 * odRem->NbODs;	*outSize = 0;	*outSize = size/8;	if (*outSize * 8 != size) *outSize += 1;	return GF_OK;}GF_Err gf_odf_write_od_remove(GF_BitStream *bs, GF_ODRemove *odRem){	GF_Err e;	u32 size, i;	if (! odRem) return GF_BAD_PARAM;	e = gf_odf_size_od_remove(odRem, &size);	e = gf_odf_write_base_descriptor(bs, odRem->tag, size);	for (i = 0; i < odRem->NbODs; i++) {		gf_bs_write_int(bs, odRem->OD_ID[i], 10);	}	//OD commands are aligned	gf_bs_align(bs);	return GF_OK;}GF_ODCom *gf_odf_new_od_update(){	GF_ODUpdate *newCom = (GF_ODUpdate *) malloc(sizeof(GF_ODUpdate));	if (!newCom) return NULL;		newCom->objectDescriptors = gf_list_new();	if (! newCom->objectDescriptors) {		free(newCom);		return NULL;	}	newCom->tag = GF_ODF_OD_UPDATE_TAG;	return (GF_ODCom *)newCom;}GF_Err gf_odf_del_od_update(GF_ODUpdate *ODUpdate){	GF_Err e;	if (! ODUpdate) return GF_BAD_PARAM;	while (gf_list_count(ODUpdate->objectDescriptors)) {		GF_Descriptor *tmp = (GF_Descriptor*)gf_list_get(ODUpdate->objectDescriptors, 0);		e = gf_odf_delete_descriptor(tmp);		if (e) return e;		e = gf_list_rem(ODUpdate->objectDescriptors, 0);		if (e) return e;	}	gf_list_del(ODUpdate->objectDescriptors);	free(ODUpdate);	return GF_OK;}GF_Err AddToODUpdate(GF_ODUpdate *odUp, GF_Descriptor *desc){	if (! odUp) return GF_BAD_PARAM;	if (! desc) return GF_OK;	switch (desc->tag) {	case GF_ODF_OD_TAG:	case GF_ODF_IOD_TAG:	case GF_ODF_ISOM_IOD_TAG:	case GF_ODF_ISOM_OD_TAG:		return gf_list_add(odUp->objectDescriptors, desc);	default:		gf_odf_delete_descriptor(desc);		return GF_OK;	}}GF_Err gf_odf_read_od_update(GF_BitStream *bs, GF_ODUpdate *odUp, u32 gf_odf_size_command){	GF_Descriptor *tmp;	GF_Err e = GF_OK;	u32 tmpSize = 0, nbBytes = 0;	if (! odUp) return GF_BAD_PARAM;	while (nbBytes < gf_odf_size_command) {		e = gf_odf_parse_descriptor(bs, &tmp, &tmpSize);		if (e) return e;		e = AddToODUpdate(odUp, tmp);		if (e) return e;		nbBytes += tmpSize + gf_odf_size_field_size(tmpSize);	}	//OD commands are aligned	gf_bs_align(bs);	if (nbBytes != gf_odf_size_command) return GF_ODF_INVALID_COMMAND;	return e;}GF_Err gf_odf_size_od_update(GF_ODUpdate *odUp, u32 *outSize){	GF_Descriptor *tmp;	u32 i, tmpSize;	if (!odUp) return GF_BAD_PARAM;	*outSize = 0;	i=0;	while ((tmp = (GF_Descriptor *)gf_list_enum(odUp->objectDescriptors, &i))) {		gf_odf_size_descriptor(tmp, &tmpSize);		*outSize += tmpSize + gf_odf_size_field_size(tmpSize);	}	return GF_OK;}GF_Err gf_odf_write_od_update(GF_BitStream *bs, GF_ODUpdate *odUp){	GF_Err e;	GF_Descriptor *tmp;	u32 size, i;	if (! odUp) return GF_BAD_PARAM;	e = gf_odf_size_od_update(odUp, &size);	if (e) return e;	gf_odf_write_base_descriptor(bs, odUp->tag, size);	if (e) return e;	i=0;	while ((tmp = (GF_Descriptor *)gf_list_enum(odUp->objectDescriptors, &i))) {		e = gf_odf_write_descriptor(bs, tmp);		if (e) return e;	}	//OD commands are aligned	gf_bs_align(bs);	return GF_OK;}GF_ODCom *gf_odf_new_esd_update(){	GF_ESDUpdate *newCom = (GF_ESDUpdate *) malloc(sizeof(GF_ESDUpdate));	if (!newCom) return NULL;		newCom->ESDescriptors = gf_list_new();	if (! newCom->ESDescriptors) {		free(newCom);		return NULL;	}	newCom->tag = GF_ODF_ESD_UPDATE_TAG;	return (GF_ODCom *)newCom;}GF_Err gf_odf_del_esd_update(GF_ESDUpdate *ESDUpdate){	GF_Err e;	if (! ESDUpdate) return GF_BAD_PARAM;	while (gf_list_count(ESDUpdate->ESDescriptors)) {		GF_Descriptor *tmp = (GF_Descriptor*)gf_list_get(ESDUpdate->ESDescriptors, 0);		e = gf_odf_delete_descriptor(tmp);		if (e) return e;		e = gf_list_rem(ESDUpdate->ESDescriptors, 0);		if (e) return e;	}	gf_list_del(ESDUpdate->ESDescriptors);	free(ESDUpdate);	return GF_OK;}GF_Err AddToESDUpdate(GF_ESDUpdate *esdUp, GF_Descriptor *desc){	if (! esdUp) return GF_BAD_PARAM;

⌨️ 快捷键说明

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