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

📄 com_enc.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 / BIFS codec 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/bifs_dev.h>#include <gpac/internal/scenegraph_dev.h>#include "quant.h" GF_Err BE_EncProtoList(GF_BifsEncoder *codec, GF_List *protoList, GF_BitStream *bs);void gf_bifs_enc_name(GF_BifsEncoder *codec, GF_BitStream *bs, char *name){	u32 i = 0;	while (name[i]) {		gf_bs_write_int(bs, name[i], 8);		i++;	}	gf_bs_write_int(bs, 0, 8);	GF_LOG(GF_LOG_DEBUG, GF_LOG_CODING, ("[BIFS] DEF\t\t%d\t\t%s\n", 8*i, name));}static GF_Err BE_MultipleIndexedReplace(GF_BifsEncoder * codec, GF_Command *com, GF_BitStream *bs){	u32 i,nbBits, count, maxPos, nbBitsPos;	GF_FieldInfo field;	GF_Err e;	GF_CommandField *inf;	if (!gf_list_count(com->command_fields)) return GF_OK; 	inf = (GF_CommandField *)gf_list_get(com->command_fields, 0);		gf_bs_write_int(bs, gf_node_get_id(com->node)-1, codec->info->config.NodeIDBits);	nbBits = gf_get_bit_size(gf_node_get_num_fields_in_mode(com->node, GF_SG_FIELD_CODING_IN)-1);	gf_bifs_field_index_by_mode(com->node, inf->fieldIndex, GF_SG_FIELD_CODING_IN, &i);	GF_BIFS_WRITE_INT(codec, bs, i, nbBits, "field", NULL);	gf_node_get_field(com->node, inf->fieldIndex, &field);	field.fieldType = inf->fieldType;	count = gf_list_count(com->command_fields);	maxPos = 0;	for (i=0; i<count; i++) {		inf = (GF_CommandField *)gf_list_get(com->command_fields, i);		if (maxPos < (u32) inf->pos) maxPos = inf->pos;	}	nbBitsPos = gf_get_bit_size(maxPos);	GF_BIFS_WRITE_INT(codec, bs, nbBitsPos, 5, "nbBitsPos", NULL);		nbBits = gf_get_bit_size(count);	GF_BIFS_WRITE_INT(codec, bs, nbBits, 5, "nbBits", NULL);	GF_BIFS_WRITE_INT(codec, bs, count, nbBits, "count", NULL);	for (i=0; i<count; i++) {		inf = (GF_CommandField *)gf_list_get(com->command_fields, i);		GF_BIFS_WRITE_INT(codec, bs, inf->pos, nbBitsPos, "idx", NULL);		field.far_ptr = inf->field_ptr;		e = gf_bifs_enc_field(codec, bs, com->node, &field);		if (e) return e;	}	return GF_OK;}static GF_Err BE_MultipleReplace(GF_BifsEncoder * codec, GF_Command *com, GF_BitStream *bs){	u32 i, j, nbBits, count, numFields, allField;	Bool use_list;	GF_FieldInfo field;	GF_Err e;	gf_bs_write_int(bs, gf_node_get_id(com->node)-1, codec->info->config.NodeIDBits);	count = gf_list_count(com->command_fields);	use_list = 1;	numFields = gf_node_get_num_fields_in_mode(com->node, GF_SG_FIELD_CODING_DEF);	nbBits = gf_get_bit_size(numFields - 1);	if (count < 1+count*(1+nbBits)) use_list = 0;	GF_BIFS_WRITE_INT(codec, bs, use_list ? 0 : 1, 1, "isMask", NULL);	for (i=0; i<numFields; i++) {		GF_CommandField *inf = NULL;		gf_bifs_get_field_index(com->node, i, GF_SG_FIELD_CODING_DEF, &allField);		for (j=0; j<count; j++) {			inf = (GF_CommandField *)gf_list_get(com->command_fields, j);			if (inf->fieldIndex==allField) break;			inf = NULL;		}		if (!inf) {			if (!use_list) GF_BIFS_WRITE_INT(codec, bs, 0, 1, "Mask", NULL);			continue;		}		/*common case*/		gf_node_get_field(com->node, inf->fieldIndex, &field);		if (use_list) {			/*not end flag*/			GF_BIFS_WRITE_INT(codec, bs, 0, 1, "end", NULL);		} else {			/*mask flag*/			GF_BIFS_WRITE_INT(codec, bs, 1, 1, "Mask", NULL);		}		if (use_list) GF_BIFS_WRITE_INT(codec, bs, i, nbBits, "field", (char*)field.name);		field.far_ptr = inf->field_ptr;		e = gf_bifs_enc_field(codec, bs, com->node, &field);		if (e) return e;	}	/*end flag*/	if (use_list) GF_BIFS_WRITE_INT(codec, bs, 1, 1, "end", NULL);	return GF_OK;}static GF_Err BE_GlobalQuantizer(GF_BifsEncoder * codec, GF_Command *com, GF_BitStream *bs){	GF_Err e;	GF_CommandField *inf;	if (!gf_list_count(com->command_fields)) return GF_OK;	inf = (GF_CommandField *)gf_list_get(com->command_fields, 0);	if (inf->new_node) ((M_QuantizationParameter *)inf->new_node)->isLocal = 0;	e = gf_bifs_enc_node(codec, inf->new_node, NDT_SFWorldNode, bs);	if (e) return e;	/*reset global QP*/	if (codec->GlobalQP) gf_node_unregister((GF_Node *) codec->GlobalQP, NULL);	codec->GlobalQP = codec->ActiveQP = NULL;		/*no QP*/	if (!inf->new_node) return GF_OK;	/*register global QP*/	codec->GlobalQP = codec->ActiveQP = (M_QuantizationParameter *) inf->new_node;	codec->GlobalQP->isLocal = 0;	gf_node_register(inf->new_node, NULL);	return GF_OK;}static GF_Err BE_EncProtoDelete(GF_BifsEncoder * codec, GF_Command *com, GF_BitStream *bs){	u32 nbBits, i;	Bool use_list = 0;	nbBits = gf_get_bit_size(com->del_proto_list_size);	if (nbBits+5>com->del_proto_list_size) use_list = 1;	GF_BIFS_WRITE_INT(codec, bs, use_list, 1, "isList", NULL);	if (!use_list) {		GF_BIFS_WRITE_INT(codec, bs, nbBits, 5, "len", NULL);		GF_BIFS_WRITE_INT(codec, bs, com->del_proto_list_size, nbBits, "len", NULL);	}	for (i=0; i<com->del_proto_list_size; i++) {		if (use_list) GF_BIFS_WRITE_INT(codec, bs, 1, 1, "moreProto", NULL);		GF_BIFS_WRITE_INT(codec, bs, com->del_proto_list[i], codec->info->config.ProtoIDBits, "protoID", NULL);	}	if (use_list) GF_BIFS_WRITE_INT(codec, bs, 0, 1, "moreProto", NULL);	return GF_OK;}static GF_Err BE_ExtendedUpdate(GF_BifsEncoder * codec, GF_Command *com, GF_BitStream *bs){	GF_BIFS_WRITE_INT(codec, bs, 0, 2, "Insert", NULL);	GF_BIFS_WRITE_INT(codec, bs, 1, 2, "ExtendedUpdate", NULL);	switch (com->tag) {	case GF_SG_PROTO_INSERT:		GF_BIFS_WRITE_INT(codec, bs, 0, 8, "MultipleReplace", NULL);		return BE_EncProtoList(codec, com->new_proto_list, bs);	case GF_SG_PROTO_DELETE:		GF_BIFS_WRITE_INT(codec, bs, 1, 8, "ProtoDelete", NULL);		return BE_EncProtoDelete(codec, com, bs);	case GF_SG_PROTO_DELETE_ALL:		GF_BIFS_WRITE_INT(codec, bs, 2, 8, "DeleteAllProtos", NULL);		return GF_OK;	case GF_SG_MULTIPLE_INDEXED_REPLACE:		GF_BIFS_WRITE_INT(codec, bs, 3, 8, "MultipleReplace", NULL);		return BE_MultipleIndexedReplace(codec, com, bs);	case GF_SG_MULTIPLE_REPLACE:		GF_BIFS_WRITE_INT(codec, bs, 4, 8, "MultipleReplace", NULL);		return BE_MultipleReplace(codec, com, bs);	case GF_SG_GLOBAL_QUANTIZER:		GF_BIFS_WRITE_INT(codec, bs, 5, 8, "GlobalQuantizer", NULL);		return BE_GlobalQuantizer(codec, com, bs);	case GF_SG_NODE_DELETE_EX:		GF_BIFS_WRITE_INT(codec, bs, 6, 8, "MultipleReplace", NULL);		GF_BIFS_WRITE_INT(codec, bs, gf_node_get_id(com->node) - 1, codec->info->config.NodeIDBits, "NodeID", NULL);		return GF_OK;	default:		return GF_BAD_PARAM;	}}/*inserts a node in a container (node.children)*/GF_Err BE_NodeInsert(GF_BifsEncoder *codec, GF_Command *com, GF_BitStream *bs){	u32 NDT;	GF_CommandField *inf;	if (!gf_list_count(com->command_fields)) return GF_OK;	inf = (GF_CommandField *)gf_list_get(com->command_fields, 0);	GF_BIFS_WRITE_INT(codec, bs, gf_node_get_id(com->node) - 1, codec->info->config.NodeIDBits, "NodeID", NULL);	NDT = gf_bifs_get_child_table(com->node);	switch (inf->pos) {	case 0:		GF_BIFS_WRITE_INT(codec, bs, 2, 2, "FIRST", "idx");		break;	case -1:		GF_BIFS_WRITE_INT(codec, bs, 3, 2, "LAST", "idx");		break;	default:		GF_BIFS_WRITE_INT(codec, bs, 0, 2, "pos", "idx");		GF_BIFS_WRITE_INT(codec, bs, inf->pos, 8, "pos", NULL);		break;	}	return gf_bifs_enc_node(codec, inf->new_node, NDT, bs);}GF_Err BE_IndexInsert(GF_BifsEncoder *codec, GF_Command *com, GF_BitStream *bs){	GF_Err e;	u32 NumBits, ind;	GF_FieldInfo field, sffield;	GF_CommandField *inf;	if (!gf_list_count(com->command_fields)) return GF_OK;	inf = (GF_CommandField *)gf_list_get(com->command_fields, 0);	GF_BIFS_WRITE_INT(codec, bs, gf_node_get_id(com->node) - 1, codec->info->config.NodeIDBits, "NodeID", NULL);	/*index insertion uses IN mode for field index*/	NumBits = gf_get_bit_size(gf_node_get_num_fields_in_mode(com->node, GF_SG_FIELD_CODING_IN)-1);	gf_bifs_field_index_by_mode(com->node, inf->fieldIndex, GF_SG_FIELD_CODING_IN, &ind);	GF_BIFS_WRITE_INT(codec, bs, ind, NumBits, "field", NULL);	switch (inf->pos) {	case 0:		GF_BIFS_WRITE_INT(codec, bs, 2, 2, "FIRST", "idx");		break;	case -1:		GF_BIFS_WRITE_INT(codec, bs, 3, 2, "LAST", "idx");		break;	default:		GF_BIFS_WRITE_INT(codec, bs, 0, 2, "pos", "idx");		GF_BIFS_WRITE_INT(codec, bs, inf->pos, 16, "pos", NULL);		break;	}	e = gf_node_get_field(com->node, inf->fieldIndex, &field);	if (e) return e;	if (gf_sg_vrml_is_sf_field(field.fieldType)) 		return GF_NON_COMPLIANT_BITSTREAM;	memcpy(&sffield, &field, sizeof(GF_FieldInfo));	sffield.fieldType = gf_sg_vrml_get_sf_type(field.fieldType);	sffield.far_ptr = inf->field_ptr;	/*rescale the MFField and parse the SFField*/	if (field.fieldType==GF_SG_VRML_MFNODE) {		return gf_bifs_enc_node(codec, inf->new_node, field.NDTtype, bs);	} else {		return gf_bifs_enc_sf_field(codec, bs, com->node, &sffield);	}}GF_Err BE_IndexDelete(GF_BifsEncoder *codec, GF_Command *com, GF_BitStream *bs){	u32 NumBits, ind;	GF_Err e;	GF_CommandField *inf;	if (!gf_list_count(com->command_fields)) return GF_OK;	inf = (GF_CommandField *)gf_list_get(com->command_fields, 0);	GF_BIFS_WRITE_INT(codec, bs, gf_node_get_id(com->node) - 1, codec->info->config.NodeIDBits, "NodeID", NULL);	NumBits = gf_get_bit_size(gf_node_get_num_fields_in_mode(com->node, GF_SG_FIELD_CODING_IN) - 1);	e = gf_bifs_field_index_by_mode(com->node, inf->fieldIndex, GF_SG_FIELD_CODING_IN, &ind);	if (e) return e;	GF_BIFS_WRITE_INT(codec, bs, ind, NumBits, "field", NULL);	switch (inf->pos) {	case 0:		GF_BIFS_WRITE_INT(codec, bs, 2, 2, "FIRST", "idw");		break;	case -1:		GF_BIFS_WRITE_INT(codec, bs, 3, 2, "LAST", "idx");		break;	default:		GF_BIFS_WRITE_INT(codec, bs, 0, 2, "pos", "idx");		GF_BIFS_WRITE_INT(codec, bs, inf->pos, 16, "pos", NULL);		break;	}	return GF_OK;}GF_Err BE_NodeReplace(GF_BifsEncoder *codec, GF_Command *com, GF_BitStream *bs){	GF_CommandField *inf;	if (!gf_list_count(com->command_fields)) return GF_OK;	inf = (GF_CommandField *)gf_list_get(com->command_fields, 0);	GF_BIFS_WRITE_INT(codec, bs, gf_node_get_id(com->node) - 1, codec->info->config.NodeIDBits, "NodeID", NULL);	return gf_bifs_enc_node(codec, inf->new_node, NDT_SFWorldNode, bs);}GF_Err BE_FieldReplace(GF_BifsEncoder *codec, GF_Command *com, GF_BitStream *bs){	GF_Err e;	u32 ind, NumBits;	GF_FieldInfo field;	GF_CommandField *inf;	if (!gf_list_count(com->command_fields)) return GF_OK;	inf = (GF_CommandField *)gf_list_get(com->command_fields, 0);	GF_BIFS_WRITE_INT(codec, bs, gf_node_get_id(com->node) - 1, codec->info->config.NodeIDBits, "NodeID", NULL);	NumBits = gf_get_bit_size(gf_node_get_num_fields_in_mode(com->node, GF_SG_FIELD_CODING_IN)-1);	gf_bifs_field_index_by_mode(com->node, inf->fieldIndex, GF_SG_FIELD_CODING_IN, &ind);	GF_BIFS_WRITE_INT(codec, bs, ind, NumBits, "field", NULL);	e = gf_node_get_field(com->node, inf->fieldIndex, &field);	if (e) return e;	field.far_ptr = inf->field_ptr;		/* Warning: To be changed when proper solution is found */	if (gf_sg_vrml_get_sf_type(field.fieldType) == GF_SG_VRML_SFSCRIPT) codec->is_encoding_command = 1;	e = gf_bifs_enc_field(codec, bs, com->node, &field);	codec->is_encoding_command = 0;	return e;}GF_Err BE_IndexFieldReplace(GF_BifsEncoder *codec, GF_Command *com, GF_BitStream *bs){	u32 ind, NumBits;	GF_Err e;	GF_FieldInfo field, sffield;	GF_CommandField *inf;	if (!gf_list_count(com->command_fields)) return GF_OK;	inf = (GF_CommandField *)gf_list_get(com->command_fields, 0);	GF_BIFS_WRITE_INT(codec, bs, gf_node_get_id(com->node) - 1, codec->info->config.NodeIDBits, "NodeID", NULL);	NumBits = gf_get_bit_size(gf_node_get_num_fields_in_mode(com->node, GF_SG_FIELD_CODING_IN)-1);	gf_bifs_field_index_by_mode(com->node, inf->fieldIndex, GF_SG_FIELD_CODING_IN, &ind);	GF_BIFS_WRITE_INT(codec, bs, ind, NumBits, "field", NULL);	e = gf_node_get_field(com->node, inf->fieldIndex, &field);	if (gf_sg_vrml_is_sf_field(field.fieldType)) 		return GF_NON_COMPLIANT_BITSTREAM;		switch (inf->pos) {	case 0:		GF_BIFS_WRITE_INT(codec, bs, 2, 2, "FIRST", "idx");		break;	case -1:		GF_BIFS_WRITE_INT(codec, bs, 3, 2, "LAST", "idx");		break;	default:		GF_BIFS_WRITE_INT(codec, bs, 0, 2, "pos", "idx");		GF_BIFS_WRITE_INT(codec, bs, inf->pos, 16, "pos", NULL);		break;	}		if (field.fieldType == GF_SG_VRML_MFNODE) {		e = gf_bifs_enc_node(codec, inf->new_node, field.NDTtype, bs);	} else {		memcpy(&sffield, &field, sizeof(GF_FieldInfo));		sffield.fieldType = gf_sg_vrml_get_sf_type(field.fieldType);		sffield.far_ptr = inf->field_ptr;		e = gf_bifs_enc_sf_field(codec, bs, com->node, &sffield);	}	return e;}GF_Err BE_RouteReplace(GF_BifsEncoder *codec, GF_Command *com, GF_BitStream *bs, Bool isInsert){	GF_Err e;	GF_Node *n;	u32 numBits, ind;	if (isInsert) {		GF_BIFS_WRITE_INT(codec, bs, com->RouteID ? 1 : 0, 1, "isDEF", NULL);		if (com->RouteID) {			GF_BIFS_WRITE_INT(codec, bs, com->RouteID-1, codec->info->config.RouteIDBits, "RouteID", NULL);			if (codec->info->UseName) gf_bifs_enc_name(codec, bs, com->def_name);		}	} else {		GF_BIFS_WRITE_INT(codec, bs, com->RouteID - 1, codec->info->config.RouteIDBits, "RouteID", NULL);	}	/*origin*/	GF_BIFS_WRITE_INT(codec, bs, com->fromNodeID - 1, codec->info->config.NodeIDBits, "outNodeID", NULL);	n = gf_bifs_enc_find_node(codec, com->fromNodeID);	numBits = gf_node_get_num_fields_in_mode(n, GF_SG_FIELD_CODING_OUT) - 1;	numBits = gf_get_bit_size(numBits);	e = gf_bifs_field_index_by_mode(n, com->fromFieldIndex, GF_SG_FIELD_CODING_OUT, &ind);	if (e) return e;	GF_BIFS_WRITE_INT(codec, bs, ind, numBits, "outField", NULL);	/*target*/	GF_BIFS_WRITE_INT(codec, bs, com->toNodeID - 1, codec->info->config.NodeIDBits, "inNodeID", NULL);	n = gf_bifs_enc_find_node(codec, com->toNodeID);	numBits = gf_node_get_num_fields_in_mode(n, GF_SG_FIELD_CODING_IN) - 1;	numBits = gf_get_bit_size(numBits);	e = gf_bifs_field_index_by_mode(n, com->toFieldIndex, GF_SG_FIELD_CODING_IN, &ind);	GF_BIFS_WRITE_INT(codec, bs, ind, numBits, "inField", NULL);	return e;}GF_Err BE_EncProtoList(GF_BifsEncoder *codec, GF_List *protoList, GF_BitStream *bs){	u8 useQuant, useAnim;	u32 i, j, nbRoutes, nbBits, numProtos, numFields, count;	GF_Node *node;	GF_ProtoFieldInterface *proto_field;	GF_Proto *proto, *prev_proto;	GF_Route *r;	GF_Err e;	GF_SceneGraph *rootSG;

⌨️ 快捷键说明

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