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

📄 main.c

📁 一个用于智能手机的多媒体库适合S60 WinCE的跨平台开发库
💻 C
📖 第 1 页 / 共 4 页
字号:
{	u32 i, j, first, count;	char *NDTName;	BNode *n;	fprintf(f, "\n\n/* NDT BIFS Version %d */\n\n", Version);	//for all NDTs	for (i=0; i<gf_list_count(NDTs); i++) {		NDTName = gf_list_get(NDTs, i);		count = GetNDTCount(NDTName, BNodes, Version);		if (Version == 2) {			count -= 2;		} else if (Version > 2) {			count -= 1;		}		if (!count) continue;				//numBits		fprintf(f, "#define %s_V%d_NUMBITS\t\t%d\n", NDTName, Version, GetBitsCount(count + ( (Version == 2) ? 1 : 0) ) );		fprintf(f, "#define %s_V%d_Count\t%d\n\n", NDTName, Version, count);				fprintf(f, "static const u32 %s_V%d_TypeToTag[%d] = {\n", NDTName, Version, count);		first = 1;		//browse each node.		for (j=0; j<gf_list_count(BNodes); j++) {			n = gf_list_get(BNodes, j);			if (n->version != Version) continue;			if (!IsNodeInTable(n, NDTName)) continue;						if (first) {				fprintf(f, " TAG_MPEG4_%s", n->name);				first = 0;			} else {				fprintf(f, ", TAG_MPEG4_%s", n->name);			}		}		fprintf(f, "\n};\n\n");	}	fprintf(f, "\nu32 NDT_V%d_GetNumBits(u32 NDT_Tag);\n", Version);	fprintf(f, "u32 NDT_V%d_GetNodeTag(u32 Context_NDT_Tag, u32 NodeType);\n", Version);	fprintf(f, "u32 NDT_V%d_GetNodeType(u32 NDT_Tag, u32 NodeTag);\n", Version);		fprintf(f, "\n\n");}//write the NDTs functions for v1 nodes//all our internal handling is in TAG_MPEG4_#nodename because we need an homogeneous//namespace for all nodes (v1, v2, v3 and v4)//the NDT functions will perform the translation from the NDT value to the absolute//TAG of the nodevoid WriteNDT_Dec(FILE *f, GF_List *BNodes, GF_List *NDTs, u32 Version){	char *NDTName;	u32 i, count;	//NodeTag complete translation	fprintf(f, "\n\n\nu32 NDT_V%d_GetNodeTag(u32 Context_NDT_Tag, u32 NodeType)\n{\n\tif (!NodeType) return 0;\n", Version);	//handle version	fprintf(f, "\t/* adjust according to the table version */\n");	if (Version == 2) {		fprintf(f, "\t/* v2: 0 reserved for extensions, 1 reserved for protos */\n");		fprintf(f, "\tif (NodeType == 1) return 0;\n");		fprintf(f, "\tNodeType -= 2;\n");	} else {		fprintf(f, "\t/* v%d: 0 reserved for extensions */\n", Version);		fprintf(f, "\tNodeType -= 1;\n");	}	fprintf(f, "\tswitch (Context_NDT_Tag) {\n");	for (i=0; i<gf_list_count(NDTs); i++) {		NDTName = gf_list_get(NDTs, i);		count = GetNDTCount(NDTName, BNodes, Version);		if (Version == 2) {			count -= 2;		} else if (Version > 2) {			count -= 1;		}		if (!count) continue;				fprintf(f, "\tcase NDT_%s:\n\t\tif (NodeType >= %s_V%d_Count) return 0;\n", NDTName, NDTName, Version);		fprintf(f, "\t\treturn %s_V%d_TypeToTag[NodeType];\n", NDTName, Version);	}	fprintf(f, "\tdefault:\n\t\treturn 0;\n\t}\n}");	//NDT codec bits	fprintf(f, "\n\n\nu32 NDT_V%d_GetNumBits(u32 NDT_Tag)\n{\n\tswitch (NDT_Tag) {\n", Version);	for (i=0; i<gf_list_count(NDTs); i++) {		NDTName = gf_list_get(NDTs, i);		count = GetNDTCount(NDTName, BNodes, Version);		if (Version == 2) {			count -= 2;		} else if (Version > 2) {			count -= 1;		}		if (!count) continue;				fprintf(f, "\tcase NDT_%s:\n\t\treturn %s_V%d_NUMBITS;\n", NDTName, NDTName, Version);	}	/*all tables have 1 node in v2 for proto coding*/	fprintf(f, "\tdefault:\n\t\treturn %d;\n\t}\n}\n\n", (Version==2) ? 1 : 0);}void WriteNDT_Enc(FILE *f, GF_List *BNodes, GF_List *NDTs, u32 Version){	u32 i, count;	char *NDTName;	fprintf(f, "u32 NDT_V%d_GetNodeType(u32 NDT_Tag, u32 NodeTag)\n{\n\tif(!NDT_Tag || !NodeTag) return 0;\n\tswitch(NDT_Tag) {\n", Version);	for (i=0; i<gf_list_count(NDTs); i++) {		NDTName = gf_list_get(NDTs, i);		count = GetNDTCount(NDTName, BNodes, Version);		if (Version == 2) {			count -= 2;		} else if (Version > 2) {			count -= 1;		}		if (!count) continue;		fprintf(f, "\tcase NDT_%s:\n\t\treturn ALL_GetNodeType(%s_V%d_TypeToTag, %s_V%d_Count, NodeTag, GF_BIFS_V%d);\n", NDTName, NDTName, Version, NDTName, Version, Version);	}	fprintf(f, "\tdefault:\n\t\treturn 0;\n\t}\n}\n\n");}void WriteNodeFields(FILE *f, BNode *n){	u32 i, first;	BField *bf;	u32 NbDef, NbIn, NbOut, NbDyn, hasAQ;	NbDef = NbIn = NbOut = NbDyn = hasAQ = 0;	for (i=0;i<gf_list_count(n->Fields); i++) {		bf = gf_list_get(n->Fields, i);		if (!strcmp(bf->type, "field") || !strcmp(bf->type, "exposedField")) {			NbDef += 1;		}		if (!strcmp(bf->type, "eventIn") || !strcmp(bf->type, "exposedField")) {			NbIn += 1;			//check for anim			if (bf->hasAnim) NbDyn += 1;		}		if (!strcmp(bf->type, "eventOut") || !strcmp(bf->type, "exposedField")) {			NbOut += 1;		}		if (bf->hasAnim || bf->hasQuant) hasAQ = 1;	}	n->hasAQInfo = hasAQ;	//write the def2all table	if (NbDef) {		first = 1;		fprintf(f, "static const u16 %s_Def2All[] = { ", n->name);		for (i=0; i<gf_list_count(n->Fields); i++) {			bf = gf_list_get(n->Fields, i);			if (strcmp(bf->type, "field") && strcmp(bf->type, "exposedField")) continue;			if (first) {				fprintf(f, "%d", i);				first = 0;			} else {				fprintf(f, ", %d", i);			}		}		fprintf(f, "};\n");	}	//write the in2all table	if (NbIn) {		first = 1;		fprintf(f, "static const u16 %s_In2All[] = { ", n->name);		for (i=0; i<gf_list_count(n->Fields); i++) {			bf = gf_list_get(n->Fields, i);			if (strcmp(bf->type, "eventIn") && strcmp(bf->type, "exposedField")) continue;			if (first) {				fprintf(f, "%d", i);				first = 0;			} else {				fprintf(f, ", %d", i);			}		}		fprintf(f, "};\n");	}	//write the out2all table	if (NbOut) {		first = 1;		fprintf(f, "static const u16 %s_Out2All[] = { ", n->name);		for (i=0; i<gf_list_count(n->Fields); i++) {			bf = gf_list_get(n->Fields, i);			if (strcmp(bf->type, "eventOut") && strcmp(bf->type, "exposedField")) continue;			if (first) {				fprintf(f, "%d", i);				first = 0;			} else {				fprintf(f, ", %d", i);			}		}		fprintf(f, "};\n");	}	//then write the dyn2all table	if (NbDyn) {		first = 1;		fprintf(f, "static const u16 %s_Dyn2All[] = { ", n->name);		for (i=0; i<gf_list_count(n->Fields); i++) {			bf = gf_list_get(n->Fields, i);			if (strcmp(bf->type, "eventIn") && strcmp(bf->type, "exposedField")) continue;			if (!bf->hasAnim) continue;			if (first) {				fprintf(f, "%d", i);				first = 0;			} else {				fprintf(f, ", %d", i);			}		}		fprintf(f, "};\n");	}	n->hasDef = NbDef;	n->hasDyn = NbDyn;	n->hasIn = NbIn;	n->hasOut = NbOut;	fprintf(f, "\nstatic u32 %s_get_field_count(GF_Node *node, u8 IndexMode)\n{\n", n->name);	fprintf(f, "\tswitch(IndexMode) {\n");	fprintf(f, "\tcase GF_SG_FIELD_CODING_IN: return %d;\n", NbIn);	fprintf(f, "\tcase GF_SG_FIELD_CODING_DEF: return %d;\n", NbDef);	fprintf(f, "\tcase GF_SG_FIELD_CODING_OUT: return %d;\n", NbOut);	fprintf(f, "\tcase GF_SG_FIELD_CODING_DYN: return %d;\n", NbDyn);	fprintf(f, "\tdefault:\n");	fprintf(f, "\t\treturn %d;\n", gf_list_count(n->Fields));	fprintf(f, "\t}");	fprintf(f, "\n}\n");	fprintf(f, "\nstatic GF_Err %s_get_field_index(GF_Node *n, u32 inField, u8 IndexMode, u32 *allField)\n{\n", n->name);	fprintf(f, "\tswitch(IndexMode) {\n");	if (NbIn) {		fprintf(f, "\tcase GF_SG_FIELD_CODING_IN:\n");		fprintf(f, "\t\t*allField = %s_In2All[inField];\n\t\treturn GF_OK;\n", n->name);	}	if (NbDef) {		fprintf(f, "\tcase GF_SG_FIELD_CODING_DEF:\n");		fprintf(f, "\t\t*allField = %s_Def2All[inField];\n\t\treturn GF_OK;\n", n->name);	}	if (NbOut) {		fprintf(f, "\tcase GF_SG_FIELD_CODING_OUT:\n");		fprintf(f, "\t\t*allField = %s_Out2All[inField];\n\t\treturn GF_OK;\n", n->name);	}	if (NbDyn) {		fprintf(f, "\tcase GF_SG_FIELD_CODING_DYN:\n");		fprintf(f, "\t\t*allField = %s_Dyn2All[inField];\n\t\treturn GF_OK;\n", n->name);	}	fprintf(f, "\tdefault:\n");	fprintf(f, "\t\treturn GF_BAD_PARAM;\n");	fprintf(f, "\t}");	fprintf(f, "\n}\n");	fprintf(f, "static GF_Err %s_get_field(GF_Node *node, GF_FieldInfo *info)\n{\n\tswitch (info->fieldIndex) {\n", n->name);	for (i=0;i<gf_list_count(n->Fields); i++) {		bf = gf_list_get(n->Fields, i);		fprintf(f, "\tcase %d:\n", i);				fprintf(f, "\t\tinfo->name = \"%s\";\n", bf->name);		//skip all eventIn		if (!strcmp(bf->type, "eventIn")) {			fprintf(f, "\t\tinfo->eventType = GF_SG_EVENT_IN;\n");			fprintf(f, "\t\tinfo->on_event_in = ((M_%s *)node)->on_%s;\n", n->name, bf->name);		}		else if (!strcmp(bf->type, "eventOut")) {			fprintf(f, "\t\tinfo->eventType = GF_SG_EVENT_OUT;\n");		}		else if (!strcmp(bf->type, "field")) {			fprintf(f, "\t\tinfo->eventType = GF_SG_EVENT_FIELD;\n");		}		else {			fprintf(f, "\t\tinfo->eventType = GF_SG_EVENT_EXPOSED_FIELD;\n");		}		if (strstr(bf->familly, "Node")) {			if (strstr(bf->familly, "MF")) {				fprintf(f, "\t\tinfo->fieldType = GF_SG_VRML_MFNODE;\n");			} else {				fprintf(f, "\t\tinfo->fieldType = GF_SG_VRML_SFNODE;\n");			}			//always remove the SF or MF, as all NDTs are SFXXX			fprintf(f, "\t\tinfo->NDTtype = NDT_SF%s;\n", bf->familly+2);			fprintf(f, "\t\tinfo->far_ptr = & ((M_%s *)node)->%s;\n", n->name, bf->name);		} else {			char szName[20];			strcpy(szName, bf->familly);			strupr(szName);			//no ext type			fprintf(f, "\t\tinfo->fieldType = GF_SG_VRML_%s;\n", szName);			fprintf(f, "\t\tinfo->far_ptr = & ((M_%s *) node)->%s;\n", n->name, bf->name);		}		fprintf(f, "\t\treturn GF_OK;\n");	}	fprintf(f, "\tdefault:\n\t\treturn GF_BAD_PARAM;\n\t}\n}\n\n");	fprintf(f, "\nstatic s32 %s_get_field_index_by_name(char *name)\n{\n", n->name);	for (i=0;i<gf_list_count(n->Fields); i++) {		bf = gf_list_get(n->Fields, i);		fprintf(f, "\tif (!strcmp(\"%s\", name)) return %d;\n", bf->name, i);	}	fprintf(f, "\treturn -1;\n\t}\n");}//write the Quantization info for each node field(Quant and BIFS-Anim info)void WriteNodeQuant(FILE *f, BNode *n){	u32 i;	BField *bf;	fprintf(f, "static Bool %s_get_aq_info(GF_Node *n, u32 FieldIndex, u8 *QType, u8 *AType, Fixed *b_min, Fixed *b_max, u32 *QT13_bits)\n{\n\tswitch (FieldIndex) {\n", n->name);		for (i=0; i<gf_list_count(n->Fields) ; i++ ) {		bf = gf_list_get(n->Fields, i);		if (!bf->hasAnim && !bf->hasQuant) continue;		fprintf(f, "\tcase %d:\n", i);		//Anim Type		fprintf(f, "\t\t*AType = %d;\n", bf->AnimType);		//Quant Type		fprintf(f, "\t\t*QType = %s;\n", bf->quant_type);		if (!strcmp(bf->quant_type, "13")) 			fprintf(f, "\t\t*QT13_bits = %s;\n", bf->qt13_bits);		//Bounds		if (bf->hasBounds) {			if (!strcmp(bf->b_min, "+I") || !strcmp(bf->b_min, " +I") || !strcmp(bf->b_min, "I")) {				fprintf(f, "\t\t*b_min = FIX_MAX;\n");			} else if (!strcmp(bf->b_min, "-I")) {				fprintf(f, "\t\t*b_min = FIX_MIN;\n");			} else {				fprintf(f, "\t\t*b_min = %s;\n", GetFixedPrintout(bf->b_min));			}			if (!strcmp(bf->b_max, "+I") || !strcmp(bf->b_max, " +I") || !strcmp(bf->b_max, "I")) {				fprintf(f, "\t\t*b_max = FIX_MAX;\n");			} else {				fprintf(f, "\t\t*b_max = %s;\n", GetFixedPrintout(bf->b_max));			}		}		fprintf(f, "\t\treturn 1;\n");	}	fprintf(f, "\tdefault:\n\t\treturn 0;\n\t}\n}\n\n");}void WriteNodeCode(GF_List *BNodes){	FILE *f;	char token[20], tok[20];	char *store;	u32 i, j, k, go;	BField *bf;	BNode *n;	f = BeginFile("mpeg4_nodes", 1);	fprintf(f, "#include <gpac/nodes_mpeg4.h>\n\n");	fprintf(f, "\n#include <gpac/internal/scenegraph_dev.h>\n");	for (k=0; k<gf_list_count(BNodes); k++) {		n = gf_list_get(BNodes, k);		if (n->skip_impl) continue;		fprintf(f, "\n/*\n\t%s Node deletion\n*/\n\n", n->name);		fprintf(f, "static void %s_Del(GF_Node *node)\n{\n\tM_%s *p = (M_%s *) node;\n", n->name, n->name, n->name);		for (i=0; i<gf_list_count(n->Fields); i++) {			bf = gf_list_get(n->Fields, i);			//nothing on child events			if (!strcmp(bf->name, "addChildren")) continue;			if (!strcmp(bf->name, "removeChildren")) continue;						//delete all children node			if (!strcmp(bf->name, "children") && stricmp(n->name, "audioBuffer")) {				fprintf(f, "\tgf_sg_vrml_parent_destroy((GF_Node *) p);\t\n");				continue;			}			//delete ALL fields that must be deleted: this includes eventIn and out since 			//all fields are defined in the node			if (!strcmp(bf->familly, "MFInt")				|| !strcmp(bf->familly, "MFFloat")				|| !strcmp(bf->familly, "MFDouble")				|| !strcmp(bf->familly, "MFBool")				|| !strcmp(bf->familly, "MFInt32")				|| !strcmp(bf->familly, "MFColor")				|| !strcmp(bf->familly, "MFRotation")				|| !strcmp(bf->familly, "MFString")				|| !strcmp(bf->familly, "MFTime")				|| !strcmp(bf->familly, "MFVec2f")				|| !strcmp(bf->familly, "MFVec3f")				|| !strcmp(bf->familly, "MFVec4f")				|| !strcmp(bf->familly, "MFVec2d")				|| !strcmp(bf->familly, "MFVec3d")				|| !strcmp(bf->familly, "MFURL")				|| !strcmp(bf->familly, "MFScript")				|| !strcmp(bf->familly, "SFString")				|| !strcmp(bf->familly, "SFURL")				|| !strcmp(bf->familly, "SFImage")				) {				char szName[500];				strcpy(szName, bf->familly);				strlwr(szName);				fprintf(f, "\tgf_sg_%s_del(p->%s);\n", szName, bf->name);			}			else if (!strcmp(bf->familly, "SFCommandBuffer")) {				fprintf(f, "\tgf_sg_sfcommand_del(p->%s);\n", bf->name);			}			else if (strstr(bf->familly, "Node")) {		

⌨️ 快捷键说明

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