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

📄 com_enc.c

📁 一个用于智能手机的多媒体库适合S60 WinCE的跨平台开发库
💻 C
📖 第 1 页 / 共 2 页
字号:
	GF_FieldInfo field;	e = GF_OK;	if (!protoList || !gf_list_count(protoList)) {		GF_BIFS_WRITE_INT(codec, bs, 0, 1, "moreProto", NULL);		return GF_OK;	}	if (!codec->info->config.ProtoIDBits) 		return GF_NON_COMPLIANT_BITSTREAM;	/*store state*/	rootSG = codec->current_proto_graph;	prev_proto = codec->encoding_proto;	numProtos = gf_list_count(protoList);	for (i=0; i<numProtos; i++) {		proto = (GF_Proto*)gf_list_get(protoList, i);		useQuant = useAnim = 0;		/*set current proto state*/		codec->encoding_proto = proto;		codec->current_proto_graph = proto->sub_graph;		GF_BIFS_WRITE_INT(codec, bs, 1, 1, "moreProto", NULL);		/*1- proto interface declaration*/		GF_BIFS_WRITE_INT(codec, bs, proto->ID, codec->info->config.ProtoIDBits, "protoID", NULL);		if (codec->info->UseName) gf_bifs_enc_name(codec, bs, proto->Name);		numFields = gf_list_count(proto->proto_fields);		for (j=0; j<numFields; j++) {			proto_field = (GF_ProtoFieldInterface*)gf_list_get(proto->proto_fields, j);			GF_BIFS_WRITE_INT(codec, bs, 1, 1, "moreField", NULL);			GF_BIFS_WRITE_INT(codec, bs, proto_field->EventType, 2, "eventType", NULL);			GF_BIFS_WRITE_INT(codec, bs, proto_field->FieldType, 6, "fieldType", NULL);						if (codec->info->UseName) gf_bifs_enc_name(codec, bs, proto_field->FieldName);			switch (proto_field->EventType) {			case GF_SG_EVENT_EXPOSED_FIELD:			case GF_SG_EVENT_FIELD:				gf_sg_proto_field_get_field(proto_field, &field);				if (gf_sg_vrml_is_sf_field(field.fieldType)) {					e = gf_bifs_enc_sf_field(codec, bs, NULL, &field);				} else {					if (codec->info->config.UsePredictiveMFField) GF_BIFS_WRITE_INT(codec, bs, 0, 1, "usePredictive", NULL);					e = gf_bifs_enc_mf_field(codec, bs, NULL, &field);				}				if (e) goto exit;				break;			}			if (proto_field->QP_Type) useQuant = 1;			if (proto_field->Anim_Type) useAnim = 1;		}		GF_BIFS_WRITE_INT(codec, bs, 0, 1, "moreField", NULL);				GF_BIFS_WRITE_INT(codec, bs, proto->ExternProto.count ? 1 : 0, 1, "externProto", NULL);		/*externProto*/		if (proto->ExternProto.count) {			memset(&field, 0, sizeof(GF_FieldInfo));			field.far_ptr = &proto->ExternProto;			field.fieldType = GF_SG_VRML_MFURL;			field.name = "ExternProto";			if (codec->info->config.UsePredictiveMFField) GF_BIFS_WRITE_INT(codec, bs, 0, 1, "usePredictive", NULL);			e = gf_bifs_enc_mf_field(codec, bs, NULL, &field);			if (e) goto exit;		} else {			/*encode sub-proto list*/			e = BE_EncProtoList(codec, proto->sub_graph->protos, bs);			if (e) goto exit;			count = gf_list_count(proto->node_code);			for (j=0; j<count; j++) {				/*parse all nodes in SFWorldNode table*/				node = (GF_Node*)gf_list_get(proto->node_code, j);				e = gf_bifs_enc_node(codec, node, NDT_SFWorldNode, bs);				if (e) goto exit;				GF_BIFS_WRITE_INT(codec, bs, (j+1==count) ? 0 : 1, 1, "moreNodes", NULL);			}						/*encode routes routes*/			nbRoutes = count = gf_list_count(proto->sub_graph->Routes);			for (j=0; j<count; j++) {				r = (GF_Route*)gf_list_get(proto->sub_graph->Routes, j);				if (r->IS_route) nbRoutes--;			}			GF_BIFS_WRITE_INT(codec, bs, nbRoutes ? 1 : 0, 1, "hasRoute", NULL);			if (nbRoutes) {				nbBits = gf_get_bit_size(nbRoutes);				if (nbBits + 5 > nbRoutes) {					GF_BIFS_WRITE_INT(codec, bs, 1, 1, "isList", NULL);					/*list*/					for (j=0; j<count; j++) {						r = (GF_Route*)gf_list_get(proto->sub_graph->Routes, j);						if (r->IS_route) continue;						e = gf_bifs_enc_route(codec, r, bs);						if (e) goto exit;						nbRoutes--;						GF_BIFS_WRITE_INT(codec, bs, nbRoutes ? 1 : 0, 1, "moreRoute", NULL);					}				} else {					GF_BIFS_WRITE_INT(codec, bs, 0, 1, "isList", NULL);					GF_BIFS_WRITE_INT(codec, bs, nbBits, 5, "nbBits", NULL);					GF_BIFS_WRITE_INT(codec, bs, nbRoutes, nbBits, "length", NULL);					for (j=0; j<count; j++) {						r = (GF_Route*)gf_list_get(proto->sub_graph->Routes, j);						if (r->IS_route) continue;						e = gf_bifs_enc_route(codec, r, bs);						if (e) goto exit;					}				}			}		}		/*anim and Quantization stuff*/		GF_BIFS_WRITE_INT(codec, bs, useQuant, 1, "useQuant", NULL);		GF_BIFS_WRITE_INT(codec, bs, useAnim, 1, "useAnim", NULL);		if (!useAnim && !useQuant) continue;		count = gf_sg_proto_get_field_count(proto);		for (j=0; j<count; j++) {			proto_field = gf_sg_proto_field_find(proto, j);			gf_sg_proto_field_get_field(proto_field, &field);			/*quant*/			if (useQuant && ( (field.eventType == GF_SG_EVENT_FIELD) || (field.eventType == GF_SG_EVENT_EXPOSED_FIELD) )) {				GF_BIFS_WRITE_INT(codec, bs, proto_field->QP_Type, 4, "QPType", NULL);				if (proto_field->QP_Type==QC_LINEAR_SCALAR) GF_BIFS_WRITE_INT(codec, bs, proto_field->NumBits, 5, "nbBits", NULL);				GF_BIFS_WRITE_INT(codec, bs, proto_field->hasMinMax, 1, "hasMinMax", NULL);				if (proto_field->hasMinMax) {					field.fieldType = gf_sg_vrml_get_sf_type(field.fieldType);					switch (field.fieldType) {					case GF_SG_VRML_SFINT32:					case GF_SG_VRML_SFTIME:						break;					default:						field.fieldType = GF_SG_VRML_SFFLOAT;						break;					}					field.name = "QPMinValue";					field.far_ptr = proto_field->qp_min_value;					gf_bifs_enc_sf_field(codec, bs, NULL, &field);					field.name = "QPMaxValue";					field.far_ptr = proto_field->qp_max_value;					gf_bifs_enc_sf_field(codec, bs, NULL, &field);				}			}			/*anim - not supported yet*/			if (useAnim && ( (field.eventType == GF_SG_EVENT_IN) || (field.eventType == GF_SG_EVENT_EXPOSED_FIELD) )) {				e = GF_NOT_SUPPORTED;				goto exit;			}		}	}	GF_BIFS_WRITE_INT(codec, bs, 0, 1, "moreProto", NULL);exit:	/*restore scene graph state*/	codec->encoding_proto = prev_proto;	codec->current_proto_graph = rootSG;	return e;}GF_Err gf_bifs_enc_route(GF_BifsEncoder *codec, GF_Route *r, GF_BitStream *bs){	GF_Err e;	u32 numBits, ind;	if (!r) return GF_BAD_PARAM;	GF_BIFS_WRITE_INT(codec, bs, r->ID ? 1: 0, 1, "isDEF", NULL);	/*def'ed route*/	if (r->ID) {		GF_BIFS_WRITE_INT(codec, bs, r->ID-1, codec->info->config.RouteIDBits, "routeID", NULL);		if (codec->info->UseName) gf_bifs_enc_name(codec, bs, r->name);	}	/*origin*/	GF_BIFS_WRITE_INT(codec, bs, gf_node_get_id(r->FromNode) - 1, codec->info->config.NodeIDBits, "outNodeID", NULL);	numBits = gf_node_get_num_fields_in_mode(r->FromNode, GF_SG_FIELD_CODING_OUT) - 1;	numBits = gf_get_bit_size(numBits);	e = gf_bifs_field_index_by_mode(r->FromNode, r->FromField.fieldIndex, 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, gf_node_get_id(r->ToNode) - 1, codec->info->config.NodeIDBits, "inNodeID", NULL);	numBits = gf_node_get_num_fields_in_mode(r->ToNode, GF_SG_FIELD_CODING_IN) - 1;	numBits = gf_get_bit_size(numBits);	e = gf_bifs_field_index_by_mode(r->ToNode, r->ToField.fieldIndex, GF_SG_FIELD_CODING_IN, &ind);	GF_BIFS_WRITE_INT(codec, bs, ind, numBits, "inField", NULL);	return e;}GF_Err BE_SceneReplaceEx(GF_BifsEncoder *codec, GF_Command *com, GF_BitStream *bs, GF_List *routes){	u32 i, nbR, nbBits;	GF_Err e;	/*reserved*/	GF_BIFS_WRITE_INT(codec, bs, 0, 6, "reserved", NULL);	GF_BIFS_WRITE_INT(codec, bs, codec->info->UseName ? 1 : 0, 1, "useName", NULL);	e = BE_EncProtoList(codec, com->new_proto_list, bs);	if (e) goto exit;	/*NULL root is valid for ProtoLibraries*/	e = gf_bifs_enc_node(codec, com->node, NDT_SFTopNode, bs);	if (e || !gf_list_count(routes) ) {		GF_BIFS_WRITE_INT(codec, bs, 0, 1, "hasRoute", NULL);		return codec->LastError = e;	}	GF_BIFS_WRITE_INT(codec, bs, 1, 1, "hasRoute", NULL);	nbR = gf_list_count(routes);	nbBits = gf_get_bit_size(nbR);	if (nbBits + 5 > nbR) {		GF_BIFS_WRITE_INT(codec, bs, 1, 1, "isList", NULL);		/*list*/		for (i=0; i<nbR; i++) {			e = gf_bifs_enc_route(codec, (GF_Route*)gf_list_get(routes, i), bs);			if (e) goto exit;			GF_BIFS_WRITE_INT(codec, bs, (i+1==nbR) ? 0 : 1, 1, "moreRoute", NULL);		}	} else {		GF_BIFS_WRITE_INT(codec, bs, 0, 1, "isList", NULL);		GF_BIFS_WRITE_INT(codec, bs, nbBits, 5, "nbBits", NULL);		GF_BIFS_WRITE_INT(codec, bs, nbR, nbBits, "nbRoutes", NULL);		for (i=0; i<nbR; i++) {			e = gf_bifs_enc_route(codec, (GF_Route*)gf_list_get(routes, i), bs);			if (e) goto exit;		}	}exit:	return codec->LastError = e;}GF_Err BE_SceneReplace(GF_BifsEncoder *codec, GF_SceneGraph *graph, GF_BitStream *bs){	u32 i, nbR, nbBits;	GF_Err e;	/*reserved*/	GF_BIFS_WRITE_INT(codec, bs, 0, 6, "reserved", NULL);	GF_BIFS_WRITE_INT(codec, bs, codec->info->UseName ? 1 : 0, 1, "useName", NULL);	/*assign current graph*/	codec->scene_graph = graph;	e = BE_EncProtoList(codec, codec->scene_graph ? codec->scene_graph->protos : NULL, bs);	if (e) goto exit;	/*NULL root is valid for ProtoLibraries*/	e = gf_bifs_enc_node(codec, graph ? graph->RootNode : NULL, NDT_SFTopNode, bs);	if (e || !graph || !gf_list_count(graph->Routes) ) {		GF_BIFS_WRITE_INT(codec, bs, 0, 1, "hasRoute", NULL);		return codec->LastError = e;	}	GF_BIFS_WRITE_INT(codec, bs, 1, 1, "hasRoute", NULL);	nbR = gf_list_count(graph->Routes);	nbBits = gf_get_bit_size(nbR);	if (nbBits + 5 > nbR) {		GF_BIFS_WRITE_INT(codec, bs, 1, 1, "isList", NULL);		/*list*/		for (i=0; i<nbR; i++) {			e = gf_bifs_enc_route(codec, (GF_Route*)gf_list_get(graph->Routes, i), bs);			if (e) goto exit;			GF_BIFS_WRITE_INT(codec, bs, (i+1==nbR) ? 0 : 1, 1, "moreRoute", NULL);		}	} else {		GF_BIFS_WRITE_INT(codec, bs, 0, 1, "isList", NULL);		GF_BIFS_WRITE_INT(codec, bs, nbBits, 5, "nbBits", NULL);		GF_BIFS_WRITE_INT(codec, bs, nbR, nbBits, "nbRoutes", NULL);		for (i=0; i<nbR; i++) {			e = gf_bifs_enc_route(codec, (GF_Route*)gf_list_get(graph->Routes, i), bs);			if (e) goto exit;		}	}exit:	return codec->LastError = e;}GF_Err gf_bifs_enc_commands(GF_BifsEncoder *codec, GF_List *comList, GF_BitStream *bs){	u32 i;	u32 count;	GF_List *routes;	GF_Err e = GF_OK;	routes = NULL;	codec->LastError = GF_OK;	count = gf_list_count(comList);	for (i=0; i<count; i++) {		GF_Command *com = (GF_Command*)gf_list_get(comList, i);		switch (com->tag) {		case GF_SG_SCENE_REPLACE:		{			/*reset node context*/			while (gf_list_count(codec->encoded_nodes)) gf_list_rem(codec->encoded_nodes, 0);			GF_BIFS_WRITE_INT(codec, bs, 3, 2, "SceneReplace", NULL);					routes = gf_list_new();			/*now the trick: get all following InsertRoutes and convert as routes*/			for (; i<count-1; i++) {				GF_Route *r;				GF_Command *rcom = (GF_Command*)gf_list_get(comList, i+1);				if (rcom->tag!=GF_SG_ROUTE_INSERT) break;				GF_SAFEALLOC(r, GF_Route);				r->FromField.fieldIndex = rcom->fromFieldIndex;				r->FromNode = gf_sg_find_node(codec->scene_graph, rcom->fromNodeID);				r->ToField.fieldIndex = rcom->toFieldIndex;				r->ToNode = gf_sg_find_node(codec->scene_graph, rcom->toNodeID);				r->ID = rcom->RouteID;				r->name = rcom->def_name;				gf_list_add(routes, r);			}			e = BE_SceneReplaceEx(codec, com, bs, routes);		}			break;		/*replace commands*/		case GF_SG_NODE_REPLACE:			GF_BIFS_WRITE_INT(codec, bs, 2, 2, "Replace", NULL);			GF_BIFS_WRITE_INT(codec, bs, 0, 2, "Node", NULL);			e = BE_NodeReplace(codec, com, bs);			break;		case GF_SG_FIELD_REPLACE:			GF_BIFS_WRITE_INT(codec, bs, 2, 2, "Replace", NULL);			GF_BIFS_WRITE_INT(codec, bs, 1, 2, "Field", NULL);			e = BE_FieldReplace(codec, com, bs);			break;		case GF_SG_INDEXED_REPLACE:			GF_BIFS_WRITE_INT(codec, bs, 2, 2, "Replace", NULL);			GF_BIFS_WRITE_INT(codec, bs, 2, 2, "FieldIndex", NULL);			e = BE_IndexFieldReplace(codec, com, bs);			break;		case GF_SG_ROUTE_REPLACE:			GF_BIFS_WRITE_INT(codec, bs, 2, 2, "Replace", NULL);			GF_BIFS_WRITE_INT(codec, bs, 3, 2, "Route", NULL);			e = BE_RouteReplace(codec, com, bs, 0);			break;		case GF_SG_NODE_INSERT:			GF_BIFS_WRITE_INT(codec, bs, 0, 2, "Insert", NULL);			GF_BIFS_WRITE_INT(codec, bs, 0, 2, "Node", NULL);			e = BE_NodeInsert(codec, com, bs);			break;		case GF_SG_INDEXED_INSERT:			GF_BIFS_WRITE_INT(codec, bs, 0, 2, "Insert", NULL);			GF_BIFS_WRITE_INT(codec, bs, 2, 2, "FieldIndex", NULL);			e = BE_IndexInsert(codec, com, bs);			break;		case GF_SG_ROUTE_INSERT:			GF_BIFS_WRITE_INT(codec, bs, 0, 2, "Insert", NULL);			GF_BIFS_WRITE_INT(codec, bs, 3, 2, "Route", NULL);			e = BE_RouteReplace(codec, com, bs, 1);			break;		case GF_SG_NODE_DELETE:			GF_BIFS_WRITE_INT(codec, bs, 1, 2, "Delete", NULL);			GF_BIFS_WRITE_INT(codec, bs, 0, 2, "Node", NULL);			GF_BIFS_WRITE_INT(codec, bs, gf_node_get_id(com->node) - 1, codec->info->config.NodeIDBits, "NodeID", NULL);			break;		case GF_SG_INDEXED_DELETE:			GF_BIFS_WRITE_INT(codec, bs, 1, 2, "Delete", NULL);			GF_BIFS_WRITE_INT(codec, bs, 2, 2, "FieldIndex", NULL);			e = BE_IndexDelete(codec, com, bs);			break;		case GF_SG_ROUTE_DELETE:			GF_BIFS_WRITE_INT(codec, bs, 1, 2, "Delete", NULL);			GF_BIFS_WRITE_INT(codec, bs, 3, 2, "Route", NULL);			GF_BIFS_WRITE_INT(codec, bs, com->RouteID - 1, codec->info->config.RouteIDBits, "RouteID", NULL);			break;		default:			e = BE_ExtendedUpdate(codec, com, bs);			break;		}		if (e) break;		GF_BIFS_WRITE_INT(codec, bs, (i+1==count) ? 0 : 1, 1, "moreCommands", NULL);	}	if (routes) {		while (gf_list_count(routes)) {			GF_Route *r = (GF_Route*)gf_list_get(routes, 0);			gf_list_rem(routes, 0);			free(r);		}		gf_list_del(routes);	}	while (gf_list_count(codec->QPs)) gf_bifs_enc_qp_remove(codec, 1);	return e;}GF_EXPORTGF_Err gf_bifs_encoder_get_rap(GF_BifsEncoder *codec, char **out_data, u32 *out_data_length){	GF_BitStream *bs;	GF_Err e;	GF_List *ctx_bck;	/*reset context for RAP encoding*/	ctx_bck = codec->encoded_nodes;	codec->encoded_nodes = gf_list_new();	if (!codec->info) codec->info = (BIFSStreamInfo*)gf_list_get(codec->streamInfo, 0);	bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE);	GF_BIFS_WRITE_INT(codec, bs, 3, 2, "SceneReplace", NULL);	e = BE_SceneReplace(codec, codec->scene_graph, bs);	if (e == GF_OK) {		GF_BIFS_WRITE_INT(codec, bs, 0, 1, "moreCommands", NULL);		gf_bs_get_content(bs, out_data, out_data_length);	}	gf_bs_del(bs);		/*restore context*/	gf_list_del(codec->encoded_nodes);	codec->encoded_nodes = ctx_bck;	return e;}

⌨️ 快捷键说明

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