in applications/generators/MPEG4/main.c [813:1348]
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");
fprintf(f, "\n#ifndef GPAC_DISABLE_VRML\n");
for (k=0; k<gf_list_count(BNodes); k++) {
Bool is_parent = 0;
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")) {
is_parent = 1;
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")) {
//this is a POINTER to a node
if (strstr(bf->familly, "SF")) {
fprintf(f, "\tgf_node_unregister((GF_Node *) p->%s, (GF_Node *) p);\t\n", bf->name);
} else {
//this is a POINTER to a chain
fprintf(f, "\tgf_node_unregister_children((GF_Node *) p, p->%s);\t\n", bf->name);
}
}
}
if (!strcmp(n->name, "CacheTexture")) {
fprintf(f, "\tif (p->data) gf_free(p->data);\n");
}
if (is_parent) fprintf(f, "\tgf_sg_vrml_parent_destroy((GF_Node *) p);\t\n");
fprintf(f, "\tgf_node_free((GF_Node *) p);\n}\n\n");
//node fields
WriteNodeFields(f, n);
WriteNodeQuant(f, n);
//
// Constructor
//
fprintf(f, "\n\nGF_Node *%s_Create()\n{\n\tM_%s *p;\n\tGF_SAFEALLOC(p, M_%s);\n", n->name, n->name, n->name);
fprintf(f, "\tif(!p) return NULL;\n");
fprintf(f, "\tgf_node_setup((GF_Node *)p, TAG_MPEG4_%s);\n", n->name);
for (i=0; i<gf_list_count(n->Fields); i++) {
bf = gf_list_get(n->Fields, i);
//setup all children node
if (!strcmp(bf->name, "children") && stricmp(n->name, "audioBuffer")) {
fprintf(f, "\tgf_sg_vrml_parent_setup((GF_Node *) p);\n");
break;
}
else if ( strstr(bf->familly, "Node") && strncmp(bf->type, "event", 5) ) {
#if 0
//this is a POINTER to a node
if (strstr(bf->familly, "MF")) {
//this is a POINTER to a chain
fprintf(f, "\tp->%s = gf_list_new();\t\n", bf->name);
}
#endif
}
/*special case for SFCommandBuffer: we also create a command list*/
if (!stricmp(bf->familly, "SFCommandBuffer")) {
fprintf(f, "\tp->%s.commandList = gf_list_new();\t\n", bf->name);
}
}
//check if we have a child node
for (i=0; i<gf_list_count(n->Fields); i++) {
bf = gf_list_get(n->Fields, i);
if ( !strcmp(bf->name, "children") ||
( !strstr(bf->type, "event") && strstr(bf->familly, "MF") && strstr(bf->familly, "Node")) ) {
sprintf(n->Child_NDT_Name, "NDT_SF%s", bf->familly+2);
break;
}
}
fprintf(f, "\n\t/*default field values*/\n");
for (i=0; i<gf_list_count(n->Fields); i++) {
bf = gf_list_get(n->Fields, i);
//nothing on eventIn or Out
if (!strcmp(bf->type, "eventIn")) continue;
if (!strcmp(bf->type, "eventOut")) continue;
if (!strcmp(bf->def, "")) continue;
//no default on nodes
if (strstr(bf->familly, "Node")) continue;
//extract default falue
//
// SF Fields
//
//SFBool
if (!strcmp(bf->familly, "SFBool")) {
if (!strcmp(bf->def, "1") || !strcmp(bf->def, "TRUE"))
fprintf(f, "\tp->%s = 1;\n", bf->name);
}
//SFFloat
else if (!strcmp(bf->familly, "SFFloat")) {
fprintf(f, "\tp->%s = %s;\n", bf->name, GetFixedPrintout(bf->def));
}
//SFTime
else if (!strcmp(bf->familly, "SFTime")) {
fprintf(f, "\tp->%s = %s;\n", bf->name, bf->def);
}
//SFInt32
else if (!strcmp(bf->familly, "SFInt32")) {
fprintf(f, "\tp->%s = %s;\n", bf->name, bf->def);
}
//SFURL
else if (!strcmp(bf->familly, "SFURL")) {
if (strcmp(bf->def, "NULL"))
fprintf(f, "\tp->%s = %s;\n", bf->name, bf->def);
}
//SFColor
else if (!strcmp(bf->familly, "SFColor")) {
CurrentLine = bf->def;
GetNextToken(token, " ");
TranslateToken(token);
fprintf(f, "\tp->%s.red = %s;\n", bf->name, GetFixedPrintout(token));
GetNextToken(token, " ");
fprintf(f, "\tp->%s.green = %s;\n", bf->name, GetFixedPrintout(token));
GetNextToken(token, " ");
fprintf(f, "\tp->%s.blue = %s;\n", bf->name, GetFixedPrintout(token));
}
//SFVec2f
else if (!strcmp(bf->familly, "SFVec2f")) {
CurrentLine = bf->def;
GetNextToken(token, " ");
TranslateToken(token);
fprintf(f, "\tp->%s.x = %s;\n", bf->name, GetFixedPrintout(token));
GetNextToken(token, " ");
TranslateToken(token);
fprintf(f, "\tp->%s.y = %s;\n", bf->name, GetFixedPrintout(token));
}
//SFVec3f
else if (!strcmp(bf->familly, "SFVec3f")) {
CurrentLine = bf->def;
GetNextToken(token, " ");
TranslateToken(token);
fprintf(f, "\tp->%s.x = %s;\n", bf->name, GetFixedPrintout(token));
GetNextToken(token, " ");
TranslateToken(token);
fprintf(f, "\tp->%s.y = %s;\n", bf->name, GetFixedPrintout(token));
GetNextToken(token, " ");
TranslateToken(token);
fprintf(f, "\tp->%s.z = %s;\n", bf->name, GetFixedPrintout(token));
}
//SFVec4f & SFRotation
else if (!strcmp(bf->familly, "SFVec4f") || !strcmp(bf->familly, "SFRotation")) {
CurrentLine = bf->def;
GetNextToken(token, " ");
TranslateToken(token);
fprintf(f, "\tp->%s.x = %s;\n", bf->name, GetFixedPrintout(token));
GetNextToken(token, " ");
TranslateToken(token);
fprintf(f, "\tp->%s.y = %s;\n", bf->name, GetFixedPrintout(token));
GetNextToken(token, " ");
TranslateToken(token);
fprintf(f, "\tp->%s.z = %s;\n", bf->name, GetFixedPrintout(token));
GetNextToken(token, " ");
TranslateToken(token);
fprintf(f, "\tp->%s.q = %s;\n", bf->name, GetFixedPrintout(token));
}
//SFString
else if (!strcmp(bf->familly, "SFString")) {
fprintf(f, "\tp->%s.buffer = (char*)gf_malloc(sizeof(char) * %d);\n", bf->name, strlen(bf->def)+1);
fprintf(f, "\tstrcpy(p->%s.buffer, \"%s\");\n", bf->name, bf->def);
}
//
// MF Fields
//
//MFFloat
else if (!strcmp(bf->familly, "MFFloat")) {
j = 0;
CurrentLine = bf->def;
while (GetNextToken(token, " ,")) j++;
j+=1;
fprintf(f, "\tp->%s.vals = (SFFloat*)gf_malloc(sizeof(SFFloat)*%d);\n", bf->name, j);
fprintf(f, "\tp->%s.count = %d;\n", bf->name, j);
j = 0;
go = 1;
CurrentLine = bf->def;
while (go) {
if (!GetNextToken(token, " ,")) go = 0;
TranslateToken(token);
fprintf(f, "\tp->%s.vals[%d] = %s;\n", bf->name, j, GetFixedPrintout(token));
j+=1;
}
}
//MFVec2f
else if (!strcmp(bf->familly, "MFVec2f")) {
j = 0;
CurrentLine = bf->def;
while (GetNextToken(token, ",")) j++;
j+=1;
fprintf(f, "\tp->%s.vals = (SFVec2f*)gf_malloc(sizeof(SFVec2f)*%d);\n", bf->name, j);
fprintf(f, "\tp->%s.count = %d;\n", bf->name, j);
j = 0;
go = 1;
CurrentLine = bf->def;
while (go) {
if (!GetNextToken(token, ",")) go = 0;
store = CurrentLine;
CurrentLine = token;
GetNextToken(tok, " ");
TranslateToken(tok);
fprintf(f, "\tp->%s.vals[%d].x = %s;\n", bf->name, j, GetFixedPrintout(tok));
GetNextToken(tok, " ");
TranslateToken(tok);
fprintf(f, "\tp->%s.vals[%d].y = %s;\n", bf->name, j, GetFixedPrintout(tok));
j+=1;
CurrentLine = store;
}
}
//MFVec3f
else if (!strcmp(bf->familly, "MFVec3f")) {
j = 0;
CurrentLine = bf->def;
while (GetNextToken(token, ",")) j++;
j+=1;
fprintf(f, "\tp->%s.vals = (SFVec3f *)gf_malloc(sizeof(SFVec3f)*%d);\n", bf->name, j);
fprintf(f, "\tp->%s.count = %d;\n", bf->name, j);
j = 0;
go = 1;
CurrentLine = bf->def;
while (go) {
if (!GetNextToken(token, ",")) go = 0;
store = CurrentLine;
CurrentLine = token;
GetNextToken(tok, " ");
TranslateToken(tok);
fprintf(f, "\tp->%s.vals[%d].x = %s;\n", bf->name, j, GetFixedPrintout(tok));
GetNextToken(tok, " ");
TranslateToken(tok);
fprintf(f, "\tp->%s.vals[%d].y = %s;\n", bf->name, j, GetFixedPrintout(tok));
GetNextToken(tok, " ");
TranslateToken(tok);
fprintf(f, "\tp->%s.vals[%d].z = %s;\n", bf->name, j, GetFixedPrintout(tok));
j+=1;
CurrentLine = store;
}
}
//MFVec4f
else if (!strcmp(bf->familly, "MFVec4f") || !strcmp(bf->familly, "MFRotation")) {
j = 0;
CurrentLine = bf->def;
while (GetNextToken(token, ",")) j++;
j+=1;
fprintf(f, "\tp->%s.vals = (GF_Vec4*)gf_malloc(sizeof(GF_Vec4)*%d);\n", bf->name, j);
fprintf(f, "\tp->%s.count = %d;\n", bf->name, j);
j = 0;
go = 1;
CurrentLine = bf->def;
while (go) {
if (!GetNextToken(token, ",")) go = 0;
store = CurrentLine;
CurrentLine = token;
GetNextToken(tok, " ");
TranslateToken(tok);
fprintf(f, "\tp->%s.vals[%d].x = %s;\n", bf->name, j, GetFixedPrintout(tok));
GetNextToken(tok, " ");
TranslateToken(tok);
fprintf(f, "\tp->%s.vals[%d].y = %s;\n", bf->name, j, GetFixedPrintout(tok));
GetNextToken(tok, " ");
TranslateToken(tok);
fprintf(f, "\tp->%s.vals[%d].z = %s;\n", bf->name, j, GetFixedPrintout(tok));
GetNextToken(tok, " ");
TranslateToken(tok);
fprintf(f, "\tp->%s.vals[%d].q = %s;\n", bf->name, j, GetFixedPrintout(tok));
j+=1;
CurrentLine = store;
}
}
//MFInt32
else if (!strcmp(bf->familly, "MFInt32")) {
j = 0;
CurrentLine = bf->def;
while (GetNextToken(token, ",")) j++;
j+=1;
fprintf(f, "\tp->%s.vals = (SFInt32*)gf_malloc(sizeof(SFInt32)*%d);\n", bf->name, j);
fprintf(f, "\tp->%s.count = %d;\n", bf->name, j);
j = 0;
go = 1;
CurrentLine = bf->def;
while (go) {
if (!GetNextToken(token, ",")) go = 0;
store = CurrentLine;
CurrentLine = token;
GetNextToken(tok, " ");
fprintf(f, "\tp->%s.vals[%d] = %s;\n", bf->name, j, tok);
j+=1;
CurrentLine = store;
}
}
//MFColor
else if (!strcmp(bf->familly, "MFColor")) {
j = 0;
CurrentLine = bf->def;
while (GetNextToken(token, ",")) j++;
j+=1;
fprintf(f, "\tp->%s.vals = (SFColor*)gf_malloc(sizeof(SFColor)*%d);\n", bf->name, j);
fprintf(f, "\tp->%s.count = %d;\n", bf->name, j);
j = 0;
go = 1;
CurrentLine = bf->def;
while (go) {
if (!GetNextToken(token, ",")) go = 0;
store = CurrentLine;
CurrentLine = token;
GetNextToken(tok, " ");
fprintf(f, "\tp->%s.vals[%d].red = %s;\n", bf->name, j, GetFixedPrintout(tok));
GetNextToken(tok, " ");
fprintf(f, "\tp->%s.vals[%d].green = %s;\n", bf->name, j, GetFixedPrintout(tok));
GetNextToken(tok, " ");
fprintf(f, "\tp->%s.vals[%d].blue = %s;\n", bf->name, j, GetFixedPrintout(tok));
j+=1;
CurrentLine = store;
}
}
//MFString
else if (!strcmp(bf->familly, "MFString")) {
j = 0;
CurrentLine = bf->def;
while (GetNextToken(token, ",")) j++;
j+=1;
fprintf(f, "\tp->%s.vals = (char**)gf_malloc(sizeof(SFString)*%d);\n", bf->name, j);
fprintf(f, "\tp->%s.count = %d;\n", bf->name, j);
j = 0;
go = 1;
CurrentLine = bf->def;
while (go) {
if (!GetNextToken(token, ",")) go = 0;
store = CurrentLine;
CurrentLine = token;
GetNextToken(tok, " \"");
fprintf(f, "\tp->%s.vals[%d] = (char*)gf_malloc(sizeof(char) * %d);\n", bf->name, j, strlen(tok)+1);
fprintf(f, "\tstrcpy(p->%s.vals[%d], \"%s\");\n", bf->name, j, tok);
j+=1;
CurrentLine = store;
}
}
//MFTime
else if (!strcmp(bf->familly, "MFTime")) {
j = 0;
CurrentLine = bf->def;
while (GetNextToken(token, ",")) j++;
j+=1;
fprintf(f, "\tp->%s.vals = (SFTime*)gf_malloc(sizeof(SFTime)*%d);\n", bf->name, j);
fprintf(f, "\tp->%s.count = %d;\n", bf->name, j);
j = 0;
go = 1;
CurrentLine = bf->def;
while (go) {
if (!GetNextToken(token, ",")) go = 0;
store = CurrentLine;
CurrentLine = token;
GetNextToken(tok, " \"");
TranslateToken(tok);
fprintf(f, "\tp->%s.vals[%d] = %s;\n", bf->name, j, tok);
j+=1;
CurrentLine = store;
}
}
//other nodes
else if (!strcmp(bf->familly, "SFImage")) {
//we currently only have SFImage, with NO texture so do nothing
}
//unknown init (for debug)
else {
fprintf(f, "UNKNOWN FIELD (%s);\n", bf->familly);
}
}
fprintf(f, "\treturn (GF_Node *)p;\n}\n\n");
}
fprintf(f, "\n\n\n");
//creator function
fprintf(f, "GF_Node *gf_sg_mpeg4_node_new(u32 NodeTag)\n{\n\tswitch (NodeTag) {\n");
for (i=0; i<gf_list_count(BNodes); i++) {
n = gf_list_get(BNodes, i);
if (!n->skip_impl) {
fprintf(f, "\tcase TAG_MPEG4_%s:\n\t\treturn %s_Create();\n", n->name, n->name);
}
}
fprintf(f, "\tdefault:\n\t\treturn NULL;\n\t}\n}\n\n");
fprintf(f, "const char *gf_sg_mpeg4_node_get_class_name(u32 NodeTag)\n{\n\tswitch (NodeTag) {\n");
for (i=0; i<gf_list_count(BNodes); i++) {
n = gf_list_get(BNodes, i);
if (!n->skip_impl) fprintf(f, "\tcase TAG_MPEG4_%s:\n\t\treturn \"%s\";\n", n->name, n->name);
}
fprintf(f, "\tdefault:\n\t\treturn \"Unknown Node\";\n\t}\n}\n\n");
fprintf(f, "void gf_sg_mpeg4_node_del(GF_Node *node)\n{\n\tswitch (node->sgprivate->tag) {\n");
for (i=0; i<gf_list_count(BNodes); i++) {
n = gf_list_get(BNodes, i);
if (!n->skip_impl) {
fprintf(f, "\tcase TAG_MPEG4_%s:\n\t\t%s_Del(node); return;\n", n->name, n->name);
}
}
fprintf(f, "\tdefault:\n\t\treturn;\n\t}\n}\n\n");
fprintf(f, "u32 gf_sg_mpeg4_node_get_field_count(GF_Node *node, u8 code_mode)\n{\n\tswitch (node->sgprivate->tag) {\n");
for (i=0; i<gf_list_count(BNodes); i++) {
n = gf_list_get(BNodes, i);
if (!n->skip_impl) {
fprintf(f, "\tcase TAG_MPEG4_%s:return %s_get_field_count(node, code_mode);\n", n->name, n->name);
}
}
fprintf(f, "\tdefault:\n\t\treturn 0;\n\t}\n}\n\n");
fprintf(f, "GF_Err gf_sg_mpeg4_node_get_field(GF_Node *node, GF_FieldInfo *field)\n{\n\tswitch (node->sgprivate->tag) {\n");
for (i=0; i<gf_list_count(BNodes); i++) {
n = gf_list_get(BNodes, i);
if (!n->skip_impl) {
fprintf(f, "\tcase TAG_MPEG4_%s: return %s_get_field(node, field);\n", n->name, n->name);
}
}
fprintf(f, "\tdefault:\n\t\treturn GF_BAD_PARAM;\n\t}\n}\n\n");
fprintf(f, "GF_Err gf_sg_mpeg4_node_get_field_index(GF_Node *node, u32 inField, u8 code_mode, u32 *fieldIndex)\n{\n\tswitch (node->sgprivate->tag) {\n");
for (i=0; i<gf_list_count(BNodes); i++) {
n = gf_list_get(BNodes, i);
if (!n->skip_impl) {
fprintf(f, "\tcase TAG_MPEG4_%s: return %s_get_field_index(node, inField, code_mode, fieldIndex);\n", n->name, n->name);
}
}
fprintf(f, "\tdefault:\n\t\treturn GF_BAD_PARAM;\n\t}\n}\n\n");
fprintf(f, "Bool gf_sg_mpeg4_node_get_aq_info(GF_Node *node, u32 FieldIndex, u8 *QType, u8 *AType, Fixed *b_min, Fixed *b_max, u32 *QT13_bits)\n{\n\tswitch (node->sgprivate->tag) {\n");
for (i=0; i<gf_list_count(BNodes); i++) {
n = gf_list_get(BNodes, i);
if (!n->skip_impl) {
fprintf(f, "\tcase TAG_MPEG4_%s: return %s_get_aq_info(node, FieldIndex, QType, AType, b_min, b_max, QT13_bits);\n", n->name, n->name);
}
}
fprintf(f, "\tdefault:\n\t\treturn 0;\n\t}\n}\n\n");
fprintf(f, "u32 gf_sg_mpeg4_node_get_child_ndt(GF_Node *node)\n{\n\tswitch (node->sgprivate->tag) {\n");
for (i=0; i<gf_list_count(BNodes); i++) {
n = gf_list_get(BNodes, i);
if (!n->skip_impl && strlen(n->Child_NDT_Name) ) {
fprintf(f, "\tcase TAG_MPEG4_%s: return %s;\n", n->name, n->Child_NDT_Name);
}
}
fprintf(f, "\tdefault:\n\t\treturn 0;\n\t}\n}\n\n");
fprintf(f, "\nu32 gf_node_mpeg4_type_by_class_name(const char *node_name)\n{\n\tif(!node_name) return 0;\n");
for (i=0; i<gf_list_count(BNodes); i++) {
n = gf_list_get(BNodes, i);
if (n->skip_impl) continue;
fprintf(f, "\tif (!strcmp(node_name, \"%s\")) return TAG_MPEG4_%s;\n", n->name, n->name);
}
fprintf(f, "\treturn 0;\n}\n\n");
fprintf(f, "s32 gf_sg_mpeg4_node_get_field_index_by_name(GF_Node *node, char *name)\n{\n\tswitch (node->sgprivate->tag) {\n");
for (i=0; i<gf_list_count(BNodes); i++) {
n = gf_list_get(BNodes, i);
if (!n->skip_impl) {
fprintf(f, "\tcase TAG_MPEG4_%s: return %s_get_field_index_by_name(name);\n", n->name, n->name);
}
}
fprintf(f, "\tdefault:\n\t\treturn -1;\n\t}\n}\n\n");
fprintf(f, "\n#endif /*GPAC_DISABLE_VRML*/\n");
EndFile(f, "", 1);
}