GF_EXPORT GF_Err gf_term_dump_scene(GF_Terminal *term, char *rad_name, char **filename, Bool xml_dump, Bool skip_protos, GF_ObjectManager *scene_od) { #ifndef GPAC_DISABLE_SCENE_DUMP GF_SceneGraph *sg; GF_ObjectManager *odm; GF_SceneDumper *dumper; u32 mode; char szExt[20], *ext; GF_Err e; if (!term || !term->root_scene) return GF_BAD_PARAM; if (!scene_od) { if (!term->root_scene) return GF_BAD_PARAM; odm = term->root_scene->root_od; } else { odm = scene_od; if (!gf_term_check_odm(term, scene_od)) odm = term->root_scene->root_od; } if (odm->subscene) { if (!odm->subscene->graph) return GF_IO_ERR; sg = odm->subscene->graph; } else { if (!odm->parentscene->graph) return GF_IO_ERR; sg = odm->parentscene->graph; } mode = xml_dump ? GF_SM_DUMP_AUTO_XML : GF_SM_DUMP_AUTO_TXT; /*figure out best dump format based on extension*/ ext = odm->net_service ? strrchr(odm->net_service->url, '.') : NULL; if (ext) { strcpy(szExt, ext); strlwr(szExt); if (!strcmp(szExt, ".wrl")) mode = xml_dump ? GF_SM_DUMP_X3D_XML : GF_SM_DUMP_VRML; else if(!strncmp(szExt, ".x3d", 4) || !strncmp(szExt, ".x3dv", 5) ) mode = xml_dump ? GF_SM_DUMP_X3D_XML : GF_SM_DUMP_X3D_VRML; else if(!strncmp(szExt, ".bt", 3) || !strncmp(szExt, ".xmt", 4) || !strncmp(szExt, ".mp4", 4) ) mode = xml_dump ? GF_SM_DUMP_XMTA : GF_SM_DUMP_BT; } dumper = gf_sm_dumper_new(sg, rad_name, ' ', mode); if (!dumper) return GF_IO_ERR; e = gf_sm_dump_graph(dumper, skip_protos, 0); if (filename) *filename = gf_strdup(gf_sm_dump_get_name(dumper)); gf_sm_dumper_del(dumper); return e; #else return GF_NOT_SUPPORTED; #endif }
int main(int argc, char **argv) { SVG2BIFS_Converter *converter; GF_SceneDumper *dump; char *tmp; gf_sys_init(); GF_SAFEALLOC(converter, SVG2BIFS_Converter); converter->sax_parser = gf_xml_sax_new(svg2bifs_node_start, svg2bifs_node_end, svg2bifs_text_content, converter); converter->force_transform = 1; converter->svg_sg = gf_sg_new(); gf_svg_properties_init_pointers(&converter->svg_props); converter->bifs_sg = gf_sg_new(); fprintf(stdout, "Parsing SVG File\n"); gf_xml_sax_parse_file(converter->sax_parser, argv[1], NULL); fprintf(stdout, "Dumping BIFS scenegraph\n"); tmp = strchr(argv[1], '.'); tmp[0] = 0; dump = gf_sm_dumper_new(converter->bifs_sg, argv[1], ' ', GF_SM_DUMP_XMTA); tmp[0] = '.'; gf_sm_dump_graph(dump, 1, 0); gf_sm_dumper_del(dump); gf_svg_properties_reset_pointers(&converter->svg_props); gf_sg_del(converter->svg_sg); // gf_sg_del(converter->bifs_sg); gf_xml_sax_del(converter->sax_parser); gf_free(converter); }
static GF_Err gf_seng_encode_dims_au(GF_SceneEngine *seng, u16 ESID, GF_List *commands, char **data, u32 *size) { #ifndef GPAC_DISABLE_SCENE_DUMP GF_SceneDumper *dumper = NULL; #endif GF_Err e; char rad_name[4096]; char file_name[4096]; FILE *file = NULL; u64 fsize; char *buffer = NULL; GF_BitStream *bs = NULL; u8 dims_header; Bool compress_dims; #ifdef DUMP_DIMS_LOG_WITH_TIME u32 do_dump_with_time = 1; #endif u32 buffer_len; char *cache_dir, *dump_name; if (!data) return GF_BAD_PARAM; e = GF_OK; if (!seng->dump_path) cache_dir = gf_get_default_cache_directory(); else cache_dir = seng->dump_path; dump_name = "gpac_scene_engine_dump"; compress_dims = 1; #ifdef DUMP_DIMS_LOG_WITH_TIME start: #endif if (commands && gf_list_count(commands)) { sprintf(rad_name, "%s%c%s%s", cache_dir, GF_PATH_SEPARATOR, dump_name, "_update"); } else { #ifndef DUMP_DIMS_LOG_WITH_TIME sprintf(rad_name, "%s%c%s%s", cache_dir, GF_PATH_SEPARATOR, "rap_", dump_name); #else char date_str[100], time_str[100]; time_t now; struct tm *tm_tot; now = time(NULL); tm_tot = localtime(&now); strftime(date_str, 100, "%Yy%mm%dd", tm_tot); strftime(time_str, 100, "%Hh%Mm%Ss", tm_tot); sprintf(rad_name, "%s%c%s-%s-%s%s", cache_dir, GF_PATH_SEPARATOR, date_str, time_str, "rap_", dump_name); #endif } #ifndef GPAC_DISABLE_SCENE_DUMP dumper = gf_sm_dumper_new(seng->ctx->scene_graph, rad_name, ' ', GF_SM_DUMP_SVG); if (!dumper) { GF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, ("[SceneEngine] Cannot create SVG dumper for %s.svg\n", rad_name)); e = GF_IO_ERR; goto exit; } if (commands && gf_list_count(commands)) { e = gf_sm_dump_command_list(dumper, commands, 0, 0); } else { e = gf_sm_dump_graph(dumper, 0, 0); } gf_sm_dumper_del(dumper); if(seng->dump_rap){ GF_SceneDumper *dumper = NULL; sprintf(rad_name, "%s%c%s%s", cache_dir, GF_PATH_SEPARATOR, "rap_", dump_name); dumper = gf_sm_dumper_new(seng->ctx->scene_graph, rad_name, ' ', GF_SM_DUMP_SVG); if (!dumper) { GF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, ("[SceneEngine] Cannot create SVG dumper for %s.svg\n", rad_name)); e = GF_IO_ERR; goto exit; } e = gf_sm_dump_graph(dumper, 0, 0); gf_sm_dumper_del(dumper); } if (e) { GF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, ("[SceneEngine] Cannot dump DIMS Commands\n")); goto exit; } #endif #ifdef DUMP_DIMS_LOG_WITH_TIME if (do_dump_with_time) { do_dump_with_time = 0; goto start; } #endif sprintf(file_name, "%s.svg", rad_name); file = gf_f64_open(file_name, "rb"); if (!file) { GF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, ("[SceneEngine] Cannot open SVG dump file %s\n", file_name)); e = GF_IO_ERR; goto exit; } gf_f64_seek(file, 0, SEEK_END); fsize = gf_f64_tell(file); if (fsize == 0) { GF_LOG(GF_LOG_ERROR, GF_LOG_CONTAINER, ("[SceneEngine] SVG dump %s is empty\n", file_name)); goto exit; } /* First, read the dump in a buffer */ buffer = gf_malloc((size_t)fsize * sizeof(char)); gf_f64_seek(file, 0, SEEK_SET); fsize = fread(buffer, sizeof(char), (size_t)fsize, file); fclose(file); file = NULL; /* Then, set DIMS unit header - TODO: notify redundant units*/ dims_header = 0; if (commands && gf_list_count(commands)) { dims_header = GF_DIMS_UNIT_P; /* streamer->all_non_rap_critical ? 0 : GF_DIMS_UNIT_P;*/ } else { /*redundant RAP with complete scene*/ dims_header = GF_DIMS_UNIT_M | GF_DIMS_UNIT_S | GF_DIMS_UNIT_I | GF_DIMS_UNIT_P; } /* Then, if compression is asked, we do it */ buffer_len = (u32)fsize; assert(fsize < 1<<31); GF_LOG(GF_LOG_DEBUG, GF_LOG_CONTAINER, ("[SceneEngine] Sending DIMS data - sizes: raw (%d)", buffer_len)); if (compress_dims) { dims_header |= GF_DIMS_UNIT_C; e = gf_gz_compress_payload(&buffer, buffer_len, &buffer_len); GF_LOG(GF_LOG_DEBUG, GF_LOG_CONTAINER, ("/ compressed (%d)", buffer_len)); if (e) goto exit; } GF_LOG(GF_LOG_DEBUG, GF_LOG_CONTAINER, ("\n")); /* Then, prepare the DIMS data using a bitstream instead of direct manipulation for endianness The new bitstream size should be: the size of the (compressed) data + 1 bytes for the header + 2 bytes for the size + 4 bytes if the size is greater than 65535 */ bs = gf_bs_new(NULL, 0, GF_BITSTREAM_WRITE); if (buffer_len > 65535) { GF_LOG(GF_LOG_WARNING, GF_LOG_CONTAINER, ("[SceneEngine] Warning: DIMS Unit size too big !!!\n")); gf_bs_write_u16(bs, 0); /* internal GPAC hack to indicate that the size is larger than 65535 */ gf_bs_write_u32(bs, buffer_len+1); } else { gf_bs_write_u16(bs, buffer_len+1); } gf_bs_write_u8(bs, dims_header); gf_bs_write_data(bs, buffer, buffer_len); gf_free(buffer); buffer = NULL; gf_bs_get_content(bs, data, size); gf_bs_del(bs); exit: if (!seng->dump_path) gf_free(cache_dir); if (buffer) gf_free(buffer); if (file) fclose(file); return e; }