int main(int argc, char **argv) { int ret = 0; if (argc < 2) { fprintf(stderr, "USAGE: %s file1 [file2 ... filen]\n", argv[0]); ret = 1; goto exit; } #ifdef GPAC_MEMORY_TRACKING gf_sys_init(GF_TRUE); #else gf_sys_init(GF_FALSE); #endif gf_log_set_tool_level(GF_LOG_ALL, GF_LOG_WARNING); if (!player_foreach(argc, argv)) { ret = 1; goto exit; } exit: gf_sys_close(); return ret; }
/*parse TS2HDS arguments*/ static GFINLINE GF_Err parse_args(int argc, char **argv, char **input, char **output, u64 *curr_time, u32 *segnum) { Bool input_found=0, output_found=0; char *arg = NULL, *error_msg = "no argument found"; s32 i; for (i=1; i<argc; i++) { arg = argv[i]; if (!strnicmp(arg, "-h", 2) || strstr(arg, "-help")) { usage(argv[0]); return GF_EOS; } else if (!strnicmp(arg, "-input", 6)) { CHECK_NEXT_ARG *input = argv[++i]; input_found = 1; } else if (!strnicmp(arg, "-output", 6)) { CHECK_NEXT_ARG *output = argv[++i]; output_found = 1; } else if (!strnicmp(arg, "-segnum", 6)) { CHECK_NEXT_ARG *segnum = atoi(argv[++i]); } else if (!strnicmp(arg, "-mem-track", 10)) { #ifdef GPAC_MEMORY_TRACKING gf_sys_close(); gf_sys_init(GF_MemTrackerSimple); gf_log_set_tool_level(GF_LOG_MEMORY, GF_LOG_INFO); #else fprintf(stderr, "WARNING - GPAC not compiled with Memory Tracker - ignoring \"-mem-track\"\n"); #endif } else { error_msg = "unknown option \"%s\""; goto error; } } /*syntax is correct; now testing the presence of mandatory arguments*/ if (input_found && output_found) { return GF_OK; } else { if (!input_found) fprintf(stderr, "Error: input argument not found\n\n"); if (!output_found) fprintf(stderr, "Error: output argument not found\n\n"); return GF_BAD_PARAM; } error: if (!arg) { fprintf(stderr, "Error: %s\n\n", error_msg); } else { fprintf(stderr, "Error: %s \"%s\"\n\n", error_msg, arg); } return GF_BAD_PARAM; }
/// <summary> /// Entry point for the application /// </summary> /// <param name="hInstance">handle to the application instance</param> /// <param name="hPrevInstance">always 0</param> /// <param name="lpCmdLine">command line arguments</param> /// <param name="nCmdShow">whether to display minimized, maximized, or normally</param> /// <returns>status</returns> int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow) { CColorBasics application; //params: DASHout *dasher; loook_opt *options; #ifdef _DEBUG RedirectIOToConsole(); #endif options = loook_init(); gf_sys_init(GF_MemTrackerNone); #ifdef USE_GPAC_LOG gf_log_set_tool_level(GF_LOG_DASH, GF_LOG_DEBUG); if (gf_log_tool_level_on(GF_LOG_DASH, GF_LOG_DEBUG)) { printf("log on"); } else { printf("log off"); } gf_log_set_callback(NULL, on_gpac_log); #endif dasher = muxer_init(options); if(!dasher){ return 1; } application.setDasher(dasher); application.Run(hInstance, nCmdShow, dasher); /* KinectSensor sensor; foreach (var potentialSensor in KinectSensor.KinectSensors) { if (potentialSensor.Status == KinectStatus.Connected) { this.sensor = potentialSensor; break; } }*/ }
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); }
BOOL COsmo4::InitInstance() { Bool first_load = 0; if (!AfxSocketInit()) { AfxMessageBox(IDP_SOCKETS_INIT_FAILED); return FALSE; } gf_sys_init(); SetRegistryKey(_T("GPAC")); m_prev_batt_bl = m_prev_ac_bl = 0; m_screen_width = GetSystemMetrics(SM_CXSCREEN); m_screen_height = GetSystemMetrics(SM_CYSCREEN); m_menu_height = GetSystemMetrics(SM_CYMENU); m_scene_width = m_scene_height = 0; CMainFrame* pFrame = new CMainFrame; m_pMainWnd = pFrame; pFrame->LoadFrame(IDR_MAINFRAME, WS_VISIBLE, NULL, NULL); pFrame->ShowWindow(m_nCmdShow); pFrame->UpdateWindow(); TCHAR w_config_path[MAX_PATH]; char config_path[MAX_PATH]; GetModuleFileName(NULL, w_config_path, MAX_PATH); CE_WideToChar((u16 *) w_config_path, (char *) config_path); while (config_path[strlen((char *) config_path)-1] != '\\') config_path[strlen((char *) config_path)-1] = 0; /*setup user*/ memset(&m_user, 0, sizeof(GF_User)); /*init config and plugins*/ m_user.config = gf_cfg_init(NULL, &first_load); if (!m_user.config) { MessageBox(NULL, _T("GPAC Configuration file not found"), _T("Fatal Error"), MB_OK); m_pMainWnd->PostMessage(WM_CLOSE); } const char *str = gf_cfg_get_key(m_user.config, "General", "LogLevel"); EnableLogs((str && !strcmp(str, "debug")) ? 1 : 0); if (first_load) { /*first launch, register all files ext*/ u32 i; for (i=0; i<gf_modules_get_count(m_user.modules); i++) { GF_InputService *ifce = (GF_InputService *) gf_modules_load_interface(m_user.modules, i, GF_NET_CLIENT_INTERFACE); if (!ifce) continue; if (ifce) { ifce->CanHandleURL(ifce, "test.test"); gf_modules_close_interface((GF_BaseInterface *)ifce); } } ::MessageBox(NULL, _T("Osmo4/GPAC Setup complete"), _T("Initial launch"), MB_OK); } str = gf_cfg_get_key(m_user.config, "General", "ModulesDirectory"); m_user.modules = gf_modules_new(str, m_user.config); if (!m_user.modules || ! gf_modules_get_count(m_user.modules) ) { MessageBox(NULL, _T("No plugins available - system cannot work"), _T("Fatal Error"), MB_OK); m_pMainWnd->PostMessage(WM_QUIT); return FALSE; } m_user.config = m_user.config; m_user.modules = m_user.modules; m_user.EventProc = Osmo4CE_EventProc; m_user.opaque = this; m_user.os_window_handler = pFrame->m_wndView.m_hWnd; m_term = gf_term_new(&m_user); if (! m_term) { MessageBox(NULL, _T("Cannot load MPEG-4 Terminal"), _T("Fatal Error"), MB_OK); m_pMainWnd->PostMessage(WM_QUIT); } m_stopped = 0; m_open = 0; m_can_seek = 0; m_DoResume = 0; SetOptions(); pFrame->SendMessage(WM_SETSIZE, 0, 0); ShowTaskBar(0); CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); if (! cmdInfo.m_strFileName.IsEmpty()) { m_filename = cmdInfo.m_strFileName; m_pMainWnd->PostMessage(WM_OPENURL); } else { str = gf_cfg_get_key(m_user.config, "General", "StartupFile"); if (str) gf_term_connect(m_term, str); } return TRUE; }
int main (int argc, char **argv) { Double fps_dump; u32 i; char rad[500]; s32 frameID, h, m, s, f; Float fps; u32 dump_type; s32 dump_time; u32 dump_w, dump_h; Bool copy; char szConfigFile[4096]; char *dump_out; char *inName, *arg; GF_ISOFile *file; if (argc < 2) { PrintUsage(); return 0; } dump_type = 0; fps_dump = 0.0f; dump_w = dump_h = 0; dump_out = NULL; inName = NULL; frameID = -1; dump_time = -1; szConfigFile[0] = 0; for (i = 1; i < (u32) argc ; i++) { arg = argv[i]; if (arg[0] != '-') { inName = arg; break; } if (!stricmp(arg, "-h")) { PrintUsage(); return 0; } else if (!stricmp(arg, "-version")) { PrintVersion(); return 0; } else if (!stricmp(arg, "-size")) { sscanf(argv[i+1], "%dx%d", &dump_w, &dump_h); i++; } else if (!stricmp(arg, "-raw")) { dump_type = 2; if ((i+1<(u32)argc) && (argv[i+1][0]!='-')) { if (strstr(argv[i+1], "T")) { if (strstr(argv[i+1], "F")) { sscanf(argv[i+1], "T%d:%d:%d:%dF%f", &h, &m, &s, &f, &fps); dump_time = (s32) ((3600*h + 60*m + s)*1000 + 1000*f/fps); } else { sscanf(argv[i+1], "T%d:%d:%d", &h, &m, &s); dump_time = (s32) ((3600*h + 60*m + s)*1000); } } else { frameID = atoi(argv[i+1]); } i++; } } else if (!stricmp(arg, "-bmp")) { dump_type = 1; if ((i+1<(u32)argc) && (argv[i+1][0]!='-')) { if (strstr(argv[i+1], "T")) { if (strstr(argv[i+1], "F")) { sscanf(argv[i+1], "T%d:%d:%d:%dF%f", &h, &m, &s, &f, &fps); dump_time = (s32) ((3600*h + 60*m + s)*1000 + 1000*f/fps); } else { sscanf(argv[i+1], "T%d:%d:%d", &h, &m, &s); dump_time = (s32) ((3600*h + 60*m + s)*1000); } } else { frameID = atoi(argv[i+1]); } i++; } } else if (!stricmp(arg, "-3d")) { dump_type = 3; } else if (!stricmp(arg, "-outpath")) { dump_out = argv[i+1]; i++; } else if (!stricmp(arg, "-fps")) { fps_dump = atof(argv[i+1]); i++; } else if (!stricmp(arg, "-copy")) { copy = 1; } else if (!stricmp(arg, "-cfg")) { strcpy(szConfigFile, argv[i+1]); i += 1; } else { PrintUsage(); return (0); } } if (!inName) { PrintUsage(); return 0; } gf_sys_init(); file = gf_isom_open(inName, GF_ISOM_OPEN_READ, NULL); if (!file) { printf("Error opening file: %s\n", gf_error_to_string(gf_isom_last_error(NULL))); return 0; } if (dump_out) { arg = strrchr(inName, GF_PATH_SEPARATOR); if (arg) { strcpy(rad, arg + 1); } else { strcpy(rad, inName); } } else { strcpy(rad, inName); } while (rad[strlen(rad)-1] != '.') rad[strlen(rad)-1] = 0; rad[strlen(rad)-1] = 0; if (dump_type == 3) { bifs3d_viewpoints_merger(file, szConfigFile, dump_w, dump_h, rad, dump_type, dump_out, fps_dump, frameID, dump_time); } else bifs_to_vid(file, szConfigFile, dump_w, dump_h, rad, dump_type, dump_out, fps_dump, frameID, dump_time); printf("\ndone\n"); gf_isom_delete(file); return 0; }
//------------------------------- // dir should end with / int CNativeWrapper::init(JNIEnv * env, void * bitmap, jobject * callback, int width, int height, const char * cfg_dir, const char * modules_dir, const char * cache_dir, const char * font_dir, const char * gui_dir, const char * urlToLoad) { LOGI("Initializing GPAC with URL=%s...", urlToLoad); strcpy(m_modules_dir, modules_dir); strcpy(m_cache_dir, cache_dir); strcpy(m_font_dir, font_dir); if (cfg_dir) strcpy(m_cfg_dir, cfg_dir); char m_cfg_filename[GF_MAX_PATH]; if (m_cfg_dir) { LOGI("GPAC.cfg found in %s, force using it.\n", m_cfg_dir); strcpy(m_cfg_filename, m_cfg_dir); strcat(m_cfg_filename, "GPAC.cfg"); } int m_Width = width; int m_Height = height; int first_launch = 0; const char *opt; m_window = env; m_session = bitmap; if (!mainJavaEnv) mainJavaEnv = (JavaEnvTh *) gf_malloc(sizeof(JavaEnvTh)); memset(mainJavaEnv, 0, sizeof(JavaEnvTh)); setJavaEnv(mainJavaEnv, env, env->NewGlobalRef(*callback)); if (pthread_setspecific( jni_thread_env_key, mainJavaEnv)) { LOGE("Failed to set specific thread data to jni_thread_env_key=%d for main thread !", jni_thread_env_key); } m_mx = gf_mx_new("Osmo4"); //load config file LOGI("Loading User Config %s...", "GPAC.cfg"); m_user.config = gf_cfg_init(m_cfg_dir ? m_cfg_filename : NULL, NULL); gf_set_progress_callback(this, Osmo4_progress_cbk); opt = gf_cfg_get_key(m_user.config, "General", "ModulesDirectory"); LOGI("loading modules in directory %s...", opt); m_user.modules = gf_modules_new(opt, m_user.config); if (!m_user.modules || !gf_modules_get_count(m_user.modules)) { LOGE("No modules found in directory %s !", opt); if (m_user.modules) gf_modules_del(m_user.modules); gf_cfg_del(m_user.config); m_user.config = NULL; return Quit(KErrGeneral); } /*we don't thread the visual compositor to be able to minimize the app and still have audio running*/ m_user.init_flags = GF_TERM_NO_COMPOSITOR_THREAD; m_user.opaque = this; m_user.os_window_handler = m_window; m_user.os_display = m_session; m_user.EventProc = GPAC_EventProc; if (!javaVM) { LOGE("NO JAVA VM FOUND, m_user=%p !!!!\n", &m_user); return Quit(KErrGeneral); } LOGD("Loading GPAC terminal, m_user=%p...", &m_user); gf_sys_init(GF_MemTrackerNone); gf_fm_request_set_callback(this, on_fm_request); SetupLogs(); m_term = gf_term_new(&m_user); if (!m_term) { LOGE("Cannot load GPAC Terminal with m_user=%p", &m_user); MessageBox("Cannot load GPAC terminal", "Fatal Error", GF_SERVICE_ERROR); gf_modules_del(m_user.modules); m_user.modules = NULL; gf_cfg_del(m_user.config); m_user.config = NULL; return Quit(KErrGeneral); } /*force fullscreen*/ gf_term_set_option(m_term, GF_OPT_FULLSCREEN, 1); //setAudioEnvironment(javaVM); LOGD("Setting term size m_user=%p...", &m_user); gf_term_set_size(m_term, m_Width, m_Height); opt = gf_cfg_get_key(m_user.config, "General", "StartupFile"); LOGD("File loaded at startup=%s.", opt); if (!urlToLoad) urlToLoad = opt; if (urlToLoad) { LOGI("Connecting to %s...", urlToLoad); gf_term_connect(m_term, urlToLoad); } debug_log("init end"); LOGD("Saving config file...\n"); gf_cfg_save(m_user.config); LOGI("Initialization complete, config file saved.\n"); return 0; }
int main(int argc, char **argv) { /* The ISO progressive reader */ ISOProgressiveReader reader; /* Error indicator */ GF_Err e; /* input file to be read in the data buffer */ FILE *input; /* number of bytes read from the file at each read operation */ u32 read_bytes; /* number of bytes read from the file (total) */ u64 total_read_bytes; /* size of the input file */ u64 file_size; /* number of bytes required to finish the current ISO Box reading (not used here)*/ u64 missing_bytes; /* Thread used to run the ISO parsing in */ GF_Thread *reading_thread; /* Return value for the program */ int ret = 0; /* Usage */ if (argc != 2) { fprintf(stdout, "Usage: %s filename\n", argv[0]); return 1; } /* Initializing GPAC framework */ /* Enables GPAC memory tracking in debug mode only */ #if defined(DEBUG) || defined(_DEBUG) gf_sys_init(GF_MemTrackerSimple); gf_log_set_tool_level(GF_LOG_ALL, GF_LOG_WARNING); gf_log_set_tool_level(GF_LOG_MEMORY, GF_LOG_INFO); #else gf_sys_init(GF_MemTrackerNone); gf_log_set_tool_level(GF_LOG_ALL, GF_LOG_WARNING); #endif /* This is an input file to read data from. Could be replaced by any other method to retrieve the data (e.g. JavaScript, socket, ...)*/ input = gf_fopen(argv[1], "rb"); if (!input) { fprintf(stdout, "Could not open file %s for reading.\n", argv[1]); gf_sys_close(); return 1; } gf_fseek(input, 0, SEEK_END); file_size = gf_ftell(input); gf_fseek(input, 0, SEEK_SET); /* Initializing the progressive reader */ memset(&reader, 0, sizeof(ISOProgressiveReader)); reading_thread = gf_th_new("ISO reading thread"); reader.mutex = gf_mx_new("ISO Segment"); reader.do_run = GF_TRUE; /* we want to parse the first track */ reader.track_id = 1; /* start the async parsing */ gf_th_run(reading_thread, iso_progressive_read_thread, &reader); /* start the data reading */ reader.data_size = BUFFER_BLOCK_SIZE; reader.data = (u8 *)gf_malloc(reader.data_size); reader.valid_data_size = 0; total_read_bytes = 0; while (1) { /* block the parser until we are done manipulating the data buffer */ gf_mx_p(reader.mutex); if (reader.valid_data_size + BUFFER_BLOCK_SIZE > MAX_BUFFER_SIZE) { /* regulate the reader to limit the max buffer size and let some time to the parser to release buffer data */ fprintf(stdout, "Buffer full (%d/%d)- waiting to read next data \r", reader.valid_data_size, reader.data_size); gf_mx_v(reader.mutex); //gf_sleep(10); } else { /* make sure we have enough space in the buffer to read the next bloc of data */ if (reader.valid_data_size + BUFFER_BLOCK_SIZE > reader.data_size) { reader.data = (u8 *)gf_realloc(reader.data, reader.data_size + BUFFER_BLOCK_SIZE); reader.data_size += BUFFER_BLOCK_SIZE; } /* read the next bloc of data and update the data buffer url */ read_bytes = fread(reader.data+reader.valid_data_size, 1, BUFFER_BLOCK_SIZE, input); total_read_bytes += read_bytes; fprintf(stdout, "Read "LLD" bytes of "LLD" bytes from input file %s (buffer status: %5d/%5d)\r", total_read_bytes, file_size, argv[1], reader.valid_data_size, reader.data_size); if (read_bytes) { reader.valid_data_size += read_bytes; sprintf(reader.data_url, "gmem://%d@%p", reader.valid_data_size, reader.data); } else { /* end of file we can quit */ gf_mx_v(reader.mutex); break; } /* if the file is not yet opened (no movie), open it in progressive mode (to update its data later on) */ if (!reader.movie) { /* let's initialize the parser */ e = gf_isom_open_progressive(reader.data_url, 0, 0, &reader.movie, &missing_bytes); if (reader.movie) { gf_isom_set_single_moof_mode(reader.movie, GF_TRUE); } /* we can let parser try to work now */ gf_mx_v(reader.mutex); if ((e == GF_OK || e == GF_ISOM_INCOMPLETE_FILE) && reader.movie) { /* nothing to do, this is normal */ } else { fprintf(stdout, "Error opening fragmented mp4 in progressive mode: %s (missing "LLD" bytes)\n", gf_error_to_string(e), missing_bytes); ret = 1; goto exit; } } else { /* let inform the parser that the buffer has been updated with new data */ e = gf_isom_refresh_fragmented(reader.movie, &missing_bytes, reader.data_url); /* we can let parser try to work now */ gf_mx_v(reader.mutex); if (e != GF_OK && e != GF_ISOM_INCOMPLETE_FILE) { fprintf(stdout, "Error refreshing fragmented mp4: %s (missing "LLD" bytes)\n", gf_error_to_string(e), missing_bytes); ret = 1; goto exit; } } //gf_sleep(1); } } exit: /* stop the parser */ reader.do_run = GF_FALSE; gf_th_stop(reading_thread); /* clean structures */ gf_th_del(reading_thread); gf_mx_del(reader.mutex); gf_free(reader.data); gf_isom_close(reader.movie); gf_fclose(input); gf_sys_close(); return ret; }
BOOL COsmo4::InitInstance() { if (!AfxSocketInit()) { AfxMessageBox(IDP_SOCKETS_INIT_FAILED); return FALSE; } gf_sys_init(); SetRegistryKey(_T("GPAC")); m_prev_batt_bl = m_prev_ac_bl = 0; m_screen_width = GetSystemMetrics(SM_CXSCREEN); m_screen_height = GetSystemMetrics(SM_CYSCREEN); m_menu_height = GetSystemMetrics(SM_CYMENU); m_scene_width = m_scene_height = 0; CMainFrame* pFrame = new CMainFrame; m_pMainWnd = pFrame; pFrame->LoadFrame(IDR_MAINFRAME, WS_VISIBLE, NULL, NULL); pFrame->ShowWindow(m_nCmdShow); pFrame->UpdateWindow(); char config_path[MAX_PATH]; CE_WideToChar((unsigned short *) (LPCTSTR) AfxGetApp()->m_pszHelpFilePath, (char *) config_path); while (config_path[strlen((char *) config_path)-1] != '\\') config_path[strlen((char *) config_path)-1] = 0; /*setup user*/ memset(&m_user, 0, sizeof(GF_User)); /*init config and plugins*/ m_user.config = gf_cfg_new((const char *) config_path, "GPAC.cfg"); if (!m_user.config) { /*create blank config file in the exe dir*/ unsigned char config_file[MAX_PATH]; strcpy((char *) config_file, (const char *) config_path); strcat((char *) config_file, "GPAC.cfg"); FILE *ft = fopen((const char *) config_file, "wt"); fclose(ft); m_user.config = gf_cfg_new((const char *) config_path, "GPAC.cfg"); if (!m_user.config) { MessageBox(NULL, _T("GPAC Configuration file not found"), _T("Fatal Error"), MB_OK); m_pMainWnd->PostMessage(WM_CLOSE); } } const char *str = gf_cfg_get_key(m_user.config, "General", "LogLevel"); EnableLogs((str && !strcmp(str, "debug")) ? 1 : 0); str = gf_cfg_get_key(m_user.config, "General", "ModulesDirectory"); m_user.modules = gf_modules_new(str, m_user.config); if (!m_user.modules) { unsigned char str_path[MAX_PATH]; const char *sOpt; /*inital launch*/ m_user.modules = gf_modules_new(config_path, m_user.config); if (m_user.modules) { gf_cfg_set_key(m_user.config, "General", "ModulesDirectory", (const char *) config_path); gf_cfg_set_key(m_user.config, "Rendering", "RendererName", "GPAC 2D Renderer"); sOpt = gf_cfg_get_key(m_user.config, "Rendering", "Raster2D"); if (!sOpt) gf_cfg_set_key(m_user.config, "Rendering", "Raster2D", "GPAC 2D Raster"); sOpt = gf_cfg_get_key(m_user.config, "General", "CacheDirectory"); if (!sOpt) { sprintf((char *) str_path, "%scache", config_path); gf_cfg_set_key(m_user.config, "General", "CacheDirectory", (const char *) str_path); } /*setup UDP traffic autodetect*/ gf_cfg_set_key(m_user.config, "Network", "AutoReconfigUDP", "yes"); gf_cfg_set_key(m_user.config, "Network", "UDPNotAvailable", "no"); gf_cfg_set_key(m_user.config, "Network", "UDPTimeout", "10000"); gf_cfg_set_key(m_user.config, "Network", "BufferLength", "3000"); /*first launch, register all files ext*/ u32 i; for (i=0; i<gf_modules_get_count(m_user.modules); i++) { GF_InputService *ifce = (GF_InputService *) gf_modules_load_interface(m_user.modules, i, GF_NET_CLIENT_INTERFACE); if (!ifce) continue; if (ifce) { ifce->CanHandleURL(ifce, "test.test"); gf_modules_close_interface((GF_BaseInterface *)ifce); } } } /*check audio config on windows, force config*/ sOpt = gf_cfg_get_key(m_user.config, "Audio", "ForceConfig"); if (!sOpt) { gf_cfg_set_key(m_user.config, "Audio", "ForceConfig", "yes"); gf_cfg_set_key(m_user.config, "Audio", "NumBuffers", "2"); gf_cfg_set_key(m_user.config, "Audio", "TotalDuration", "200"); } /*by default use GDIplus, much faster than freetype on font loading*/ gf_cfg_set_key(m_user.config, "FontEngine", "DriverName", "ft_font"); sprintf((char *) str_path, "%sgpac.mp4", config_path); gf_cfg_set_key(m_user.config, "General", "StartupFile", (const char *) str_path); ::MessageBox(NULL, _T("Osmo4/GPAC Setup complete"), _T("Initial launch"), MB_OK); } if (! gf_modules_get_count(m_user.modules) ) { MessageBox(NULL, _T("No plugins available - system cannot work"), _T("Fatal Error"), MB_OK); m_pMainWnd->PostMessage(WM_QUIT); } /*setup font dir*/ str = gf_cfg_get_key(m_user.config, "FontEngine", "FontDirectory"); if (!str || !strlen(str) ) { strcpy((char *) config_path, "\\Windows"); gf_cfg_set_key(m_user.config, "FontEngine", "FontDirectory", (const char *) config_path); } /*work with iPaq's default fonts ...*/ str = gf_cfg_get_key(m_user.config, "FontEngine", "FontSerif"); if (!str) gf_cfg_set_key(m_user.config, "FontEngine", "FontSerif", "Tahoma"); str = gf_cfg_get_key(m_user.config, "FontEngine", "FontSans"); if (!str) gf_cfg_set_key(m_user.config, "FontEngine", "FontSans", "Frutiger"); str = gf_cfg_get_key(m_user.config, "FontEngine", "FontFixed"); if (!str) gf_cfg_set_key(m_user.config, "FontEngine", "FontFixed", "Courier New"); /*check video driver, if none or raw_out use dx_hw by default*/ str = gf_cfg_get_key(m_user.config, "Video", "DriverName"); if (!str || !stricmp(str, "raw_out")) { gf_cfg_set_key(m_user.config, "Video", "DriverName", "gapi"); } m_user.config = m_user.config; m_user.modules = m_user.modules; m_user.EventProc = Osmo4CE_EventProc; m_user.opaque = this; m_user.os_window_handler = pFrame->m_wndView.m_hWnd; m_term = gf_term_new(&m_user); if (! m_term) { MessageBox(NULL, _T("Cannot load MPEG-4 Terminal"), _T("Fatal Error"), MB_OK); m_pMainWnd->PostMessage(WM_QUIT); } m_stoped = 0; m_open = 0; m_can_seek = 0; m_DoResume = 0; SetOptions(); pFrame->SendMessage(WM_SETSIZE, 0, 0); ShowTaskBar(0); CCommandLineInfo cmdInfo; ParseCommandLine(cmdInfo); if (! cmdInfo.m_strFileName.IsEmpty()) { m_filename = cmdInfo.m_strFileName; m_pMainWnd->PostMessage(WM_OPENURL); } else { str = gf_cfg_get_key(m_user.config, "General", "StartupFile"); if (str) gf_term_connect(m_term, str); } return TRUE; }
int live_session(int argc, char **argv) { GF_Err e; int i; char *filename = NULL; char *dst = NULL; char *ifce_addr = NULL; char *sdp_name = "session.sdp"; u16 dst_port = 7000; u32 load_type=0; u32 check; u32 ttl = 1; u32 path_mtu = 1450; s32 next_time; u64 last_src_modif, mod_time; char *src_name = NULL; Bool run, has_carousel, no_rap; Bool udp = 0; u16 sk_port=0; GF_Socket *sk = NULL; LiveSession livesess; RTPChannel *ch; char *update_buffer = NULL; u32 update_buffer_size = 0; u16 aggregate_on_stream; Bool adjust_carousel_time, force_rap, aggregate_au, discard_pending, signal_rap, version_inc; Bool update_context; u32 period, ts_delta, signal_critical; u16 es_id; e = GF_OK; aggregate_au = 1; es_id = 0; no_rap = 0; gf_sys_init(0); memset(&livesess, 0, sizeof(LiveSession)); gf_log_set_tool_level(GF_LOG_ALL, GF_LOG_INFO); for (i=1; i<argc; i++) { char *arg = argv[i]; if (arg[0] != '-') filename = arg; else if (!strnicmp(arg, "-dst=", 5)) dst = arg+5; else if (!strnicmp(arg, "-port=", 6)) dst_port = atoi(arg+6); else if (!strnicmp(arg, "-sdp=", 5)) sdp_name = arg+5; else if (!strnicmp(arg, "-mtu=", 5)) path_mtu = atoi(arg+5); else if (!strnicmp(arg, "-ttl=", 5)) ttl = atoi(arg+5); else if (!strnicmp(arg, "-ifce=", 6)) ifce_addr = arg+6; else if (!strnicmp(arg, "-no-rap", 7)) no_rap = 1; else if (!strnicmp(arg, "-dims", 5)) load_type = GF_SM_LOAD_DIMS; else if (!strnicmp(arg, "-src=", 5)) src_name = arg+5; else if (!strnicmp(arg, "-udp=", 5)) { sk_port = atoi(arg+5); udp = 1; } else if (!strnicmp(arg, "-tcp=", 5)) { sk_port = atoi(arg+5); udp = 0; } } if (!filename) { fprintf(stderr, "Missing filename\n"); PrintLiveUsage(); return 1; } if (dst_port && dst) livesess.streams = gf_list_new(); livesess.seng = gf_seng_init(&livesess, filename, load_type, NULL, (load_type == GF_SM_LOAD_DIMS) ? 1 : 0); if (!livesess.seng) { fprintf(stderr, "Cannot create scene engine\n"); return 1; } if (livesess.streams) live_session_setup(&livesess, dst, dst_port, path_mtu, ttl, ifce_addr, sdp_name); has_carousel = 0; last_src_modif = src_name ? gf_file_modification_time(src_name) : 0; if (sk_port) { sk = gf_sk_new(udp ? GF_SOCK_TYPE_UDP : GF_SOCK_TYPE_TCP); if (udp) { e = gf_sk_bind(sk, NULL, sk_port, NULL, 0, 0); if (e != GF_OK) { if (sk) gf_sk_del(sk); sk = NULL; } } else { } } for (i=0; i<argc; i++) { char *arg = argv[i]; if (!strnicmp(arg, "-rap=", 5)) { u32 period, id, j; RTPChannel *ch; period = id = 0; if (strchr(arg, ':')) { sscanf(arg, "-rap=ESID=%u:%u", &id, &period); e = gf_seng_enable_aggregation(livesess.seng, id, 1); if (e) { fprintf(stderr, "Cannot enable aggregation on stream %u: %s\n", id, gf_error_to_string(e)); goto exit; } } else { sscanf(arg, "-rap=%u", &period); } j=0; while (NULL != (ch = gf_list_enum(livesess.streams, &j))) { if (!id || (ch->ESID==id)) ch->carousel_period = period; } has_carousel = 1; } } i=0; while (NULL != (ch = gf_list_enum(livesess.streams, &i))) { if (ch->carousel_period) { has_carousel = 1; break; } } update_context = 0; if (has_carousel || !no_rap) { livesess.carousel_generation = 1; gf_seng_encode_context(livesess.seng, live_session_callback); livesess.carousel_generation = 0; } live_session_send_carousel(&livesess, NULL); check = 10; run = 1; while (run) { check--; if (!check) { check = 10; if (gf_prompt_has_input()) { char c = gf_prompt_get_char(); switch (c) { case 'q': run=0; break; case 'U': livesess.critical = 1; case 'u': { GF_Err e; char szCom[8192]; fprintf(stderr, "Enter command to send:\n"); szCom[0] = 0; if (1 > scanf("%[^\t\n]", szCom)){ fprintf(stderr, "No command entered properly, aborting.\n"); break; } /*stdin flush bug*/ while (getchar()!='\n') {} e = gf_seng_encode_from_string(livesess.seng, 0, 0, szCom, live_session_callback); if (e) fprintf(stderr, "Processing command failed: %s\n", gf_error_to_string(e)); e = gf_seng_aggregate_context(livesess.seng, 0); livesess.critical = 0; update_context = 1; } break; case 'E': livesess.critical = 1; case 'e': { GF_Err e; char szCom[8192]; fprintf(stderr, "Enter command to send:\n"); szCom[0] = 0; if (1 > scanf("%[^\t\n]", szCom)){ printf("No command entered properly, aborting.\n"); break; } /*stdin flush bug*/ while (getchar()!='\n') {} e = gf_seng_encode_from_string(livesess.seng, 0, 1, szCom, live_session_callback); if (e) fprintf(stderr, "Processing command failed: %s\n", gf_error_to_string(e)); livesess.critical = 0; e = gf_seng_aggregate_context(livesess.seng, 0); } break; case 'p': { char rad[GF_MAX_PATH]; fprintf(stderr, "Enter output file name - \"std\" for stderr: "); if (1 > scanf("%s", rad)){ fprintf(stderr, "No ouput file name entered, aborting.\n"); break; } e = gf_seng_save_context(livesess.seng, !strcmp(rad, "std") ? NULL : rad); fprintf(stderr, "Dump done (%s)\n", gf_error_to_string(e)); } break; case 'F': update_context = 1; case 'f': livesess.force_carousel = 1; break; } e = GF_OK; } } /*process updates from file source*/ if (src_name) { mod_time = gf_file_modification_time(src_name); if (mod_time != last_src_modif) { FILE *srcf; char flag_buf[201], *flag; fprintf(stderr, "Update file modified - processing\n"); last_src_modif = mod_time; srcf = gf_f64_open(src_name, "rt"); if (!srcf) continue; /*checks if we have a broadcast config*/ if (!fgets(flag_buf, 200, srcf)) flag_buf[0] = '\0'; fclose(srcf); aggregate_on_stream = (u16) -1; adjust_carousel_time = force_rap = discard_pending = signal_rap = signal_critical = 0; aggregate_au = version_inc = 1; period = -1; ts_delta = 0; es_id = 0; /*find our keyword*/ flag = strstr(flag_buf, "gpac_broadcast_config "); if (flag) { flag += strlen("gpac_broadcast_config "); /*move to next word*/ while (flag && (flag[0]==' ')) flag++; while (1) { char *sep = strchr(flag, ' '); if (sep) sep[0] = 0; if (!strnicmp(flag, "esid=", 5)) es_id = atoi(flag+5); else if (!strnicmp(flag, "period=", 7)) period = atoi(flag+7); else if (!strnicmp(flag, "ts=", 3)) ts_delta = atoi(flag+3); else if (!strnicmp(flag, "carousel=", 9)) aggregate_on_stream = atoi(flag+9); else if (!strnicmp(flag, "restamp=", 8)) adjust_carousel_time = atoi(flag+8); else if (!strnicmp(flag, "discard=", 8)) discard_pending = atoi(flag+8); else if (!strnicmp(flag, "aggregate=", 10)) aggregate_au = atoi(flag+10); else if (!strnicmp(flag, "force_rap=", 10)) force_rap = atoi(flag+10); else if (!strnicmp(flag, "rap=", 4)) signal_rap = atoi(flag+4); else if (!strnicmp(flag, "critical=", 9)) signal_critical = atoi(flag+9); else if (!strnicmp(flag, "vers_inc=", 9)) version_inc = atoi(flag+9); if (sep) { sep[0] = ' '; flag = sep+1; } else { break; } } set_broadcast_params(&livesess, es_id, period, ts_delta, aggregate_on_stream, adjust_carousel_time, force_rap, aggregate_au, discard_pending, signal_rap, signal_critical, version_inc); } e = gf_seng_encode_from_file(livesess.seng, es_id, aggregate_au ? 0 : 1, src_name, live_session_callback); if (e) fprintf(stderr, "Processing command failed: %s\n", gf_error_to_string(e)); e = gf_seng_aggregate_context(livesess.seng, 0); update_context = no_rap ? 0 : 1; } } /*process updates from socket source*/ if (sk) { char buffer[2049]; u32 bytes_read; u32 update_length; u32 bytes_received; e = gf_sk_receive(sk, buffer, 2048, 0, &bytes_read); if (e == GF_OK) { u32 hdr_length = 0; u8 cmd_type = buffer[0]; bytes_received = 0; switch (cmd_type) { case 0: { GF_BitStream *bs = gf_bs_new(buffer, bytes_read, GF_BITSTREAM_READ); gf_bs_read_u8(bs); es_id = gf_bs_read_u16(bs); aggregate_on_stream = gf_bs_read_u16(bs); if (aggregate_on_stream==0xFFFF) aggregate_on_stream = -1; adjust_carousel_time = gf_bs_read_int(bs, 1); force_rap = gf_bs_read_int(bs, 1); aggregate_au = gf_bs_read_int(bs, 1); discard_pending = gf_bs_read_int(bs, 1); signal_rap = gf_bs_read_int(bs, 1); signal_critical = gf_bs_read_int(bs, 1); version_inc = gf_bs_read_int(bs, 1); gf_bs_read_int(bs, 1); period = gf_bs_read_u16(bs); if (period==0xFFFF) period = -1; ts_delta = gf_bs_read_u16(bs); update_length = gf_bs_read_u32(bs); hdr_length = 12; gf_bs_del(bs); } set_broadcast_params(&livesess, es_id, period, ts_delta, aggregate_on_stream, adjust_carousel_time, force_rap, aggregate_au, discard_pending, signal_rap, signal_critical, version_inc); break; default: update_length = 0; break; } if (update_buffer_size <= update_length) { update_buffer = gf_realloc(update_buffer, update_length+1); update_buffer_size = update_length+1; } if (update_length && (bytes_read>hdr_length) ) { memcpy(update_buffer, buffer+hdr_length, bytes_read-hdr_length); bytes_received = bytes_read-hdr_length; } while (bytes_received<update_length) { e = gf_sk_receive(sk, buffer, 2048, 0, &bytes_read); switch (e) { case GF_IP_NETWORK_EMPTY: break; case GF_OK: memcpy(update_buffer+bytes_received, buffer, bytes_read); bytes_received += bytes_read; break; default: fprintf(stderr, "Error with UDP socket : %s\n", gf_error_to_string(e)); break; } } update_buffer[update_length] = 0; if (update_length) { e = gf_seng_encode_from_string(livesess.seng, es_id, aggregate_au ? 0 : 1, update_buffer, live_session_callback); if (e) fprintf(stderr, "Processing command failed: %s\n", gf_error_to_string(e)); e = gf_seng_aggregate_context(livesess.seng, 0); update_context = 1; } } } if (update_context) { livesess.carousel_generation=1; e = gf_seng_encode_context(livesess.seng, live_session_callback ); livesess.carousel_generation=0; update_context = 0; } if (livesess.force_carousel) { live_session_send_carousel(&livesess, NULL); livesess.force_carousel = 0; continue; } if (!has_carousel) { gf_sleep(10); continue; } ch = next_carousel(&livesess, &next_time); if ((ch==NULL) || (next_time > 20)) { gf_sleep(20); continue; } if (next_time) gf_sleep(next_time); live_session_send_carousel(&livesess, ch); } exit: live_session_shutdown(&livesess); if (update_buffer) gf_free(update_buffer); if (sk) gf_sk_del(sk); gf_sys_close(); return e ? 1 : 0; }
int main(int argc, char **argv) { /********************/ /* declarations */ /********************/ char *input, *output, tmpstr[GF_MAX_PATH]; GF_ISOFile *isom_file_in; GF_MediaImporter import; AdobeHDSCtx ctx; GF_Err e; u32 i; /*****************/ /* gpac init */ /*****************/ gf_sys_init(GF_MemTrackerNone); gf_log_set_tool_level(GF_LOG_ALL, GF_LOG_WARNING); /***********************/ /* initialisations */ /***********************/ input = NULL; output = NULL; isom_file_in = NULL; memset(&import, 0, sizeof(GF_MediaImporter)); e = GF_OK; memset(&ctx, 0, sizeof(ctx)); ctx.curr_time = 0; ctx.segnum = 1; /*********************************************/ /* parse arguments and build HDS context */ /*********************************************/ if (GF_OK != parse_args(argc, argv, &input, &output, &ctx.curr_time, &ctx.segnum)) { usage(argv[0]); goto exit; } ctx.multirate_manifest = adobe_alloc_multirate_manifest(output); #if 0 /*'moov' conversion tests*/ { char metamoov64[GF_MAX_PATH]; u32 metamoov64_len; unsigned char metamoov[GF_MAX_PATH]; u32 metamoov_len=GF_MAX_PATH; FILE *f = gf_fopen("metamoov64"/*input*/, "rt"); gf_fseek(f, 0, SEEK_END); metamoov64_len = (u32)gf_ftell(f); gf_fseek(f, 0, SEEK_SET); fread(metamoov64, metamoov64_len, 1, f); metamoov_len = gf_base64_decode(metamoov64, metamoov64_len, metamoov, metamoov_len); gf_fclose(f); f = gf_fopen("metamoov", "wb"); fwrite(metamoov, metamoov_len, 1, f); gf_fclose(f); return 0; } #endif #if 0 /*'abst'conversion tests*/ { char bootstrap64[GF_MAX_PATH]; u32 bootstrap64_len; unsigned char bootstrap[GF_MAX_PATH]; u32 bootstrap_len=GF_MAX_PATH; GF_AdobeBootstrapInfoBox *abst = (GF_AdobeBootstrapInfoBox *)abst_New(); GF_BitStream *bs; #if 1 //64 FILE *f = gf_fopen("bootstrap64"/*input*/, "rt"); gf_fseek(f, 0, SEEK_END); bootstrap64_len = (u32)gf_ftell(f); gf_fseek(f, 0, SEEK_SET); fread(bootstrap64, bootstrap64_len, 1, f); bootstrap_len = gf_base64_decode(bootstrap64, bootstrap64_len, bootstrap, bootstrap_len); #else //binary bootstrap FILE *f = gf_fopen("bootstrap.bin"/*input*/, "rb"); gf_fseek(f, 0, SEEK_END); bootstrap_len = (u32)gf_ftell(f); gf_fseek(f, 0, SEEK_SET); fread(bootstrap, bootstrap_len, 1, f); #endif bs = gf_bs_new(bootstrap+8, bootstrap_len-8, GF_BITSTREAM_READ); abst->size = bootstrap[2]*256+bootstrap[3]; assert(abst->size<GF_MAX_PATH); abst_Read((GF_Box*)abst, bs); gf_bs_del(bs); //then rewrite with just one 'afrt' memset(bootstrap, 0, bootstrap_len); bs = gf_bs_new(bootstrap, bootstrap_len, GF_BITSTREAM_WRITE); abst_Write((GF_Box*)abst, bs); bootstrap_len = (u32)gf_bs_get_position(bs); gf_bs_del(bs); gf_fclose(f); f = gf_fopen("bootstrap", "wt"); bootstrap64_len = gf_base64_encode(bootstrap, bootstrap_len, bootstrap64, GF_MAX_PATH); fwrite(bootstrap64, bootstrap64_len, 1, f); fprintf(f, "\n\n"); abst_dump((GF_Box*)abst, f); gf_fclose(f); abst_del((GF_Box*)abst); return 0; } #endif /*****************/ /* main loop */ /*****************/ import.trackID = 0; import.in_name = input; import.flags = GF_IMPORT_PROBE_ONLY; //create output or open when recovering from a saved state sprintf(tmpstr, "%s_import.mp4", input); isom_file_in = gf_isom_open(tmpstr, GF_ISOM_WRITE_EDIT, NULL); if (!isom_file_in) { fprintf(stderr, "Error opening output file %s: %s\n", tmpstr, gf_error_to_string(e)); assert(0); goto exit; } import.dest = isom_file_in; //probe input e = gf_media_import(&import); if (e) { fprintf(stderr, "Error while importing input file %s: %s\n", input, gf_error_to_string(e)); assert(0); goto exit; } //import input data import.flags = 0; for (i=0; i<import.nb_tracks; i++) { import.trackID = import.tk_info[i].track_num; e = gf_media_import(&import); if (e) { fprintf(stderr, "Error while importing track number %u, input file %s: %s\n", import.trackID, input, gf_error_to_string(e)); assert(0); goto exit; } } //Adobe specific stuff e = adobize_segment(isom_file_in, &ctx); if (e) { fprintf(stderr, "Couldn't turn the ISOM fragmented file into an Adobe f4v segment: %s\n", gf_error_to_string(e)); assert(0); goto exit; } //interleave data and remove imported file //FIXME: set multiple fragments: sprintf(tmpstr, "%s_HD_100_Seg%u-Frag1", output, ctx.segnum); //FIXME: "HD", "100" and fragnum: pass as arg //e = gf_media_fragment_file(isom_file_in, tmpstr, 1.0); e = gf_media_fragment_file(isom_file_in, tmpstr, 1.0+gf_isom_get_duration(isom_file_in)/gf_isom_get_timescale(isom_file_in)); if (e) { fprintf(stderr, "Error while fragmenting file to output %s: %s\n", output, gf_error_to_string(e)); assert(0); goto exit; } gf_isom_delete(isom_file_in); isom_file_in = NULL; e = adobe_gen_multirate_manifest(ctx.multirate_manifest, ctx.bootstrap, ctx.bootstrap_size); if (e) { fprintf(stderr, "Couldn't generate Adobe f4m manifest: %s\n", gf_error_to_string(e)); assert(0); goto exit; } exit: //delete intermediate mp4 file if (isom_file_in) gf_isom_delete(isom_file_in); if (ctx.multirate_manifest) adobe_free_multirate_manifest(ctx.multirate_manifest); if (ctx.bootstrap) { gf_free(ctx.bootstrap); //ctx.bootstrap = NULL; //ctx.bootstrap_size = 0; } gf_sys_close(); return !e ? 0 : 1; }
BOOL Osmo4::InitInstance() { CCommandLineInfo cmdInfo; m_logs = NULL; m_term = NULL; memset(&m_user, 0, sizeof(GF_User)); /*get Osmo4.exe path*/ strcpy((char *) szApplicationPath, AfxGetApp()->m_pszHelpFilePath); while (szApplicationPath[strlen((char *) szApplicationPath)-1] != '\\') szApplicationPath[strlen((char *) szApplicationPath)-1] = 0; if (szApplicationPath[strlen((char *) szApplicationPath)-1] != '\\') strcat(szApplicationPath, "\\"); gf_sys_init(0); /*setup user*/ memset(&m_user, 0, sizeof(GF_User)); Bool first_launch = 0; /*init config and modules*/ m_user.config = gf_cfg_init(NULL, &first_launch); if (!m_user.config) { MessageBox(NULL, "GPAC Configuration file not found", "Fatal Error", MB_OK); m_pMainWnd->PostMessage(WM_CLOSE); } char *name = gf_cfg_get_filename(m_user.config); char *sep = strrchr(name, '\\'); if (sep) sep[0] = 0; strcpy(szUserPath, name); if (sep) sep[0] = '\\'; gf_free(name); const char *opt = gf_cfg_get_key(m_user.config, "General", "SingleInstance"); m_SingleInstance = (opt && !stricmp(opt, "yes")) ? 1 : 0; m_hMutex = NULL; if (m_SingleInstance) { m_hMutex = CreateMutex(NULL, FALSE, "Osmo4_GPAC_INSTANCE"); if ( GetLastError() == ERROR_ALREADY_EXISTS ) { char szDIR[1024]; if (m_hMutex) CloseHandle(m_hMutex); m_hMutex = NULL; if (!static_gpac_hwnd || !IsWindow(static_gpac_hwnd) ) { ::MessageBox(NULL, "Osmo4 ghost process detected", "Error at last shutdown" , MB_OK); } else { ::SetForegroundWindow(static_gpac_hwnd); if (m_lpCmdLine && strlen(m_lpCmdLine)) { DWORD res; u32 len; char *the_url, *cmd; GetCurrentDirectory(1024, szDIR); if (szDIR[strlen(szDIR)-1] != '\\') strcat(szDIR, "\\"); cmd = (char *)(const char *) m_lpCmdLine; strcpy(static_szCmdLine, ""); if (cmd[0]=='"') cmd+=1; if (!strnicmp(cmd, "-queue ", 7)) { strcat(static_szCmdLine, "-queue "); cmd += 7; } the_url = gf_url_concatenate(szDIR, cmd); if (!the_url) { strcat(static_szCmdLine, cmd); } else { strcat(static_szCmdLine, the_url); gf_free(the_url); } while ( (len = strlen(static_szCmdLine)) ) { char s = static_szCmdLine[len-1]; if ((s==' ') || (s=='"')) static_szCmdLine[len-1]=0; else break; } ::SendMessageTimeout(static_gpac_hwnd, WM_NEWINSTANCE, 0, 0, 0, 1000, &res); } } return FALSE; } } #if 0 // Standard initialization #ifdef _AFXDLL Enable3dControls(); // Call this when using MFC in a shared DLL #else Enable3dControlsStatic(); // Call this when linking to MFC statically #endif #endif SetRegistryKey(_T("GPAC")); CMainFrame* pFrame = new CMainFrame; m_pMainWnd = pFrame; pFrame->LoadFrame(IDR_MAINFRAME, WS_OVERLAPPEDWINDOW | FWS_ADDTOTITLE, NULL, NULL); m_pMainWnd->DragAcceptFiles(); if (m_SingleInstance) static_gpac_hwnd = m_pMainWnd->m_hWnd; const char *str = gf_cfg_get_key(m_user.config, "General", "ModulesDirectory"); m_user.modules = gf_modules_new(str, m_user.config); if (!m_user.modules || ! gf_modules_get_count(m_user.modules) ) { MessageBox(NULL, "No modules available - system cannot work", "Fatal Error", MB_OK); m_pMainWnd->PostMessage(WM_CLOSE); } else if (first_launch) { /*first launch, register all files ext*/ u32 i; for (i=0; i<gf_modules_get_count(m_user.modules); i++) { GF_InputService *ifce = (GF_InputService *) gf_modules_load_interface(m_user.modules, i, GF_NET_CLIENT_INTERFACE); if (!ifce) continue; if (ifce) { ifce->CanHandleURL(ifce, "test.test"); gf_modules_close_interface((GF_BaseInterface *)ifce); } } /*set some shortcuts*/ gf_cfg_set_key(m_user.config, "Shortcuts", "VolumeUp", "ctrl+Up"); gf_cfg_set_key(m_user.config, "Shortcuts", "VolumeDown", "ctrl+Down"); gf_cfg_set_key(m_user.config, "Shortcuts", "FastRewind", "ctrl+Left"); gf_cfg_set_key(m_user.config, "Shortcuts", "FastForward", "ctrl+Right"); gf_cfg_set_key(m_user.config, "Shortcuts", "Play", "ctrl+ "); } /*check log file*/ str = gf_cfg_get_key(m_user.config, "General", "LogFile"); if (str) { m_logs = gf_f64_open(str, "wt"); gf_log_set_callback(m_logs, osmo4_do_log); } else m_logs = NULL; /*set log level*/ if (gf_log_set_tools_levels(gf_cfg_get_key(m_user.config, "General", "Logs")) != GF_OK) fprintf(stdout, "osmo4: invalid log level specified\n"); m_user.opaque = this; m_user.os_window_handler = pFrame->m_pWndView->m_hWnd; m_user.EventProc = Osmo4_EventProc; m_reset = 0; orig_width = 320; orig_height = 240; gf_set_progress_callback(this, Osmo4_progress_cbk); m_term = gf_term_new(&m_user); if (! m_term) { MessageBox(NULL, "Cannot load GPAC Terminal", "Fatal Error", MB_OK); m_pMainWnd->PostMessage(WM_CLOSE); return TRUE; } SetOptions(); UpdateRenderSwitch(); pFrame->SendMessage(WM_SETSIZE, orig_width, orig_height); pFrame->m_Address.ReloadURLs(); pFrame->m_Sliders.SetVolume(); m_reconnect_time = 0; ParseCommandLine(cmdInfo); start_mode = 0; if (! cmdInfo.m_strFileName.IsEmpty()) { pFrame->m_pPlayList->QueueURL(cmdInfo.m_strFileName); pFrame->m_pPlayList->RefreshList(); pFrame->m_pPlayList->PlayNext(); } else { char sPL[MAX_PATH]; strcpy((char *) sPL, szUserPath); strcat(sPL, "gpac_pl.m3u"); pFrame->m_pPlayList->OpenPlayList(sPL); const char *sOpt = gf_cfg_get_key(GetApp()->m_user.config, "General", "PLEntry"); if (sOpt) { s32 count = (s32)gf_list_count(pFrame->m_pPlayList->m_entries); pFrame->m_pPlayList->m_cur_entry = atoi(sOpt); if (pFrame->m_pPlayList->m_cur_entry>=count) pFrame->m_pPlayList->m_cur_entry = count-1; } else { pFrame->m_pPlayList->m_cur_entry = -1; } #if 0 if (pFrame->m_pPlayList->m_cur_entry>=0) { start_mode = 1; pFrame->m_pPlayList->Play(); } #endif sOpt = gf_cfg_get_key(GetApp()->m_user.config, "General", "StartupFile"); if (sOpt) gf_term_connect(m_term, sOpt); } pFrame->SetFocus(); pFrame->SetForegroundWindow(); return TRUE; }
int main(int argc, char **argv) { /* The ISO progressive reader */ GF_ISOFile *movie; /* Error indicator */ GF_Err e; /* Number of bytes required to finish the current ISO Box reading */ u64 missing_bytes; /* Return value for the program */ int ret = 0; /* Maximum index of the segments*/ u32 seg_max = argc-2; /* Number of the segment being processed*/ u32 seg_curr = 0; u32 track_id = 1; u32 sample_index = 1; /* Usage */ if (argc < 2) { fprintf(stdout, "Usage: %s filename0 [filename1 filename2 ...]\n", argv[0]); return 1; } #if defined(DEBUG) || defined(_DEBUG) /* Enables GPAC memory tracking in debug mode only */ gf_sys_init(GF_TRUE); gf_log_set_tool_level(GF_LOG_CONTAINER, GF_LOG_INFO); gf_log_set_tool_level(GF_LOG_MEMORY, GF_LOG_INFO); #endif /* First or init segment */ fprintf(stdout, "Process segment %5d/%5d: %s\n", seg_curr, seg_max, argv[seg_curr+1]); e = gf_isom_open_progressive(argv[seg_curr+1], 0, 0, &movie, &missing_bytes); if ((e != GF_OK && e != GF_ISOM_INCOMPLETE_FILE) || movie == NULL) { fprintf(stdout, "Could not open file %s for reading (%s).\n", argv[seg_curr+1], gf_error_to_string(e)); return 1; } process_samples_from_track(movie, track_id, &sample_index); seg_curr++; /* Process segments */ while (seg_curr <= seg_max) { fprintf(stdout, "Process segment %5d/%5d: %s\n", seg_curr, seg_max, argv[seg_curr+1]); /* Open the segment */ e = gf_isom_open_segment(movie, argv[seg_curr+1], 0, 0, GF_FALSE); if (e != GF_OK) { fprintf(stdout, "Could not open segment %s for reading (%s).\n", argv[seg_curr+1], gf_error_to_string(e)); ret = 1; goto exit; } /* Process the segment */ process_samples_from_track(movie, track_id, &sample_index); /* Release the segment */ gf_isom_release_segment(movie, 1); seg_curr++; } exit: fprintf(stdout, "Total nb Samples: %d\n", gf_isom_get_sample_count(movie, gf_isom_get_track_by_id(movie, track_id) ) ); gf_isom_release_segment(movie, 1); gf_isom_close(movie); #if defined(DEBUG) || defined(_DEBUG) /* Closes GPAC memory tracking in debug mode only */ gf_sys_close(); #endif return ret; }
int main(int argc, char **argv) { u32 i; char *arg; GF_LoadCompare lc; Bool single = 0; char *out = NULL; char in[256] = "."; fprintf(stdout, "LASeR and SVG Comparison tool\n"); memset(&lc, 0, sizeof(GF_LoadCompare)); lc.nbloads = 1; lc.out = stdout; for (i = 1; i < (u32) argc ; i++) { arg = argv[i]; if (!stricmp(arg, "-out")) { out = argv[i+1]; i++; } else if (!stricmp(arg, "-single")) { single = 1; strcpy(in, argv[i+1]); i++; } else if (!stricmp(arg, "-dir")) { strcpy(in, argv[i+1]); i++; } else if (!stricmp(arg, "-nloads")) { lc.nbloads = (u32)atoi(argv[i+1]); i++; } else if (!stricmp(arg, "-regenerate")) { lc.regenerate = 1; } else if (!stricmp(arg, "-xmt")) { lc.type = XMT; } else if (!stricmp(arg, "-svg")) { lc.type = SVG; } else if (!stricmp(arg, "-spread_repeat")) { lc.spread_repeat = 1; } else if (!stricmp(arg, "-verbose")) { lc.verbose = (u32)atoi(argv[i+1]); i++; } else { usage(); return -1; } } gf_sys_init(); if (out) lc.out = fopen(out, "wt"); if (!lc.out) { fprintf(stderr, "Cannot open output file %s\n", out); return -1; } if (lc.type == SVG) { fprintf(lc.out,"File Name\tSVG Size\tSVG Load Time\tLibXML Load Time\tSVGZ Size\tSVGZ Load Time\tLibXML GZ Load Time\tMP4 Size\tMP4 Load Time\tDecoded SVG Size\tDecoded SVG Load Time\n"); } else if (lc.type == XMT) { fprintf(lc.out,"File Name\tXMT Size\tXMT Load Time\tBT Size\tBT Load Time\n"); } lc.data = gf_list_new(); if (single) { LoadData *ld; char *tmp = strrchr(in, GF_PATH_SEPARATOR); loadcompare_one(&lc, tmp+1, in); ld = gf_list_get(lc.data, 0); print_load_data(&lc, ld); gf_free(ld); } else { if (lc.spread_repeat) { for (lc.repeat_index = 0; lc.repeat_index < lc.nbloads; lc.repeat_index ++) { if (lc.verbose) fprintf(stdout, "Loop %d\n", lc.repeat_index); if (lc.type == SVG) { gf_enum_directory(in, 0, loadcompare_one, &lc, "svg"); } else if (lc.type == XMT) { gf_enum_directory(in, 0, loadcompare_one, &lc, "xmt"); } } for (i=0; i<gf_list_count(lc.data); i++) { LoadData *ld = gf_list_get(lc.data, i); print_load_data(&lc, ld); gf_free(ld); } } else { if (lc.type == SVG) { gf_enum_directory(in, 0, loadcompare_one, &lc, "svg"); } else if (lc.type == XMT) { gf_enum_directory(in, 0, loadcompare_one, &lc, "xmt"); } } } gf_list_del(lc.data); if (lc.out) fclose(lc.out); gf_sys_close(); return 0; }
//------------------------------- // dir should end with / int CNativeWrapper::init(JNIEnv * env, void * bitmap, jobject * callback, int width, int height, const char * cfg_dir, const char * modules_dir, const char * cache_dir, const char * font_dir, const char * urlToLoad) { LOGI("Initializing GPAC with URL=%s...", urlToLoad); strcpy(m_cfg_dir, cfg_dir); strcpy(m_modules_dir, modules_dir); strcpy(m_cache_dir, cache_dir); strcpy(m_font_dir, font_dir); char m_cfg_filename[GF_MAX_PATH]; strcpy(m_cfg_filename, m_cfg_dir); strcat(m_cfg_filename, "GPAC.cfg"); int m_Width = width; int m_Height = height; int first_launch = 0; const char *opt; m_window = env; m_session = bitmap; if (!mainJavaEnv) mainJavaEnv = (JavaEnvTh *) gf_malloc(sizeof(JavaEnvTh)); memset(mainJavaEnv, 0, sizeof(JavaEnvTh)); setJavaEnv(mainJavaEnv, env, env->NewGlobalRef(*callback)); if (pthread_setspecific( jni_thread_env_key, mainJavaEnv)) { LOGE("Failed to set specific thread data to jni_thread_env_key=%p for main thread !", jni_thread_env_key); } m_mx = gf_mx_new("Osmo4"); //load config file LOGI("Loading User Config %s...", "GPAC.cfg"); m_user.config = gf_cfg_force_new(cfg_dir, "GPAC.cfg"); gf_set_progress_callback(this, Osmo4_progress_cbk); opt = gf_cfg_get_key(m_user.config, "General", "ModulesDirectory"); if (!opt) { FILE * fstart; char msg[256]; LOGI("First launch, initializing new Config %s...", "GPAC.cfg"); /*hardcode module directory*/ gf_cfg_set_key(m_user.config, "Downloader", "CleanCache", "yes"); /*startup file*/ snprintf(msg, 256, "%sgui/gui.bt", cfg_dir); fstart = fopen(msg, "r"); if (fstart) { fclose(fstart); gf_cfg_set_key(m_user.config, "General", "StartupFile", msg); } else { gf_cfg_set_key(m_user.config, "General", "#StartupFile", msg); } gf_cfg_set_key(m_user.config, "GUI", "UnhideControlPlayer", "1"); /*setup UDP traffic autodetect*/ gf_cfg_set_key(m_user.config, "Network", "AutoReconfigUDP", "yes"); gf_cfg_set_key(m_user.config, "Network", "UDPTimeout", "10000"); gf_cfg_set_key(m_user.config, "Network", "BufferLength", "3000"); gf_cfg_set_key(m_user.config, "Compositor", "TextureTextMode", "Default"); //gf_cfg_set_key(m_user.config, "Compositor", "FrameRate", "30"); gf_cfg_set_key(m_user.config, "Audio", "ForceConfig", "no"); gf_cfg_set_key(m_user.config, "Audio", "NumBuffers", "1"); gf_cfg_set_key(m_user.config, "FontEngine", "FontReader", "ft_font"); } /* All of this has to be done for every instance */ gf_cfg_set_key(m_user.config, "General", "ModulesDirectory", modules_dir ? modules_dir : GPAC_MODULES_DIR); gf_cfg_set_key(m_user.config, "General", "CacheDirectory", cache_dir ? cache_dir : GPAC_CACHE_DIR); gf_cfg_set_key(m_user.config, "General", "LastWorkingDir", cfg_dir); gf_cfg_set_key(m_user.config, "FontEngine", "FontDirectory", GPAC_FONT_DIR); gf_cfg_set_key(m_user.config, "Video", "DriverName", "Android Video Output"); gf_cfg_set_key(m_user.config, "Audio", "DriverName", "Android Audio Output"); opt = gf_cfg_get_key(m_user.config, "General", "ModulesDirectory"); LOGI("loading modules in directory %s...", opt); m_user.modules = gf_modules_new(opt, m_user.config); if (!m_user.modules || !gf_modules_get_count(m_user.modules)) { LOGE("No modules found in directory %s !", opt); if (m_user.modules) gf_modules_del(m_user.modules); gf_cfg_del(m_user.config); m_user.config = NULL; return Quit(KErrGeneral); } /*we don't thread the visual compositor to be able to minimize the app and still have audio running*/ m_user.init_flags = GF_TERM_NO_COMPOSITOR_THREAD; m_user.opaque = this; m_user.os_window_handler = m_window; m_user.os_display = m_session; m_user.EventProc = GPAC_EventProc; if (!javaVM) { LOGE("NO JAVA VM FOUND, m_user=%p !!!!\n", &m_user); return Quit(KErrGeneral); } LOGD("Loading GPAC terminal, m_user=%p...", &m_user); gf_sys_init(GF_FALSE); gf_fm_request_set_callback(this, on_fm_request); SetupLogs(); m_term = gf_term_new(&m_user); if (!m_term) { LOGE("Cannot load GPAC Terminal with m_user=%p", m_user); MessageBox("Cannot load GPAC terminal", "Fatal Error", GF_SERVICE_ERROR); gf_modules_del(m_user.modules); m_user.modules = NULL; gf_cfg_del(m_user.config); m_user.config = NULL; return Quit(KErrGeneral); } //setAudioEnvironment(javaVM); LOGD("Setting term size m_user=%p...", &m_user); gf_term_set_size(m_term, m_Width, m_Height); opt = gf_cfg_get_key(m_user.config, "General", "StartupFile"); LOGD("File loaded at startup=%s.", opt); if (!urlToLoad) urlToLoad = opt; if (urlToLoad) { LOGI("Connecting to %s...", urlToLoad); gf_term_connect(m_term, urlToLoad); } debug_log("init end"); LOGD("Saving config file %s...\n", m_cfg_filename); gf_cfg_save(m_user.config); LOGI("Initialization complete, config file saved as %s.\n", m_cfg_filename); return 0; }
int dc_parse_command(int argc, char **argv, CmdData *cmd_data) { Bool use_mem_track = GF_FALSE; int i; const char *command_usage = "Usage: DashCast [options]\n" "\n" "General options:\n" " -log-file filename set output log file. Also works with -lf\n" " -logs LOGS set log tools and levels, formatted as a ':'-separated list of toolX[:toolZ]@levelX\n" #ifdef GPAC_MEMORY_TRACKING " -mem-track enable the memory tracker\n" #endif " -conf filename set the configuration file name (default: dashcast.conf)\n" " -switch-source filename set the configuration file name for source switching\n" "\n" "Live options:\n" " -live system is live and input is a camera\n" " -live-media system is live and input is a media file\n" " -no-loop system does not loop on the input media file when live\n" " -dynamic-ast changes segment availability start time at each MPD generation (old behaviour but not allowed in most profiles)\n" " -insert-utc inserts UTC clock at the start of each segment\n" "\n" "Source options:\n" " -npts use frame counting for timestamps (not error-free) instead of source timing (default)\n" " -av string set the source name for a multiplexed audio and video input\n" " - if this option is present, neither '-a' nor '-v' shall be present\n" "* Video options:\n" " -v string set the source name for a video input\n" " - if input is from a webcam, use \"/dev/video[x]\" \n" " where x is the video device number\n" " - if input is the screen video, use \":0.0+[x],[y]\" \n" " which captures from upper-left at x,y\n" " - if input is from stdin, use \"pipe:\"\n" " -vf string set the input video format\n" #ifdef WIN32 " - to capture from a VfW webcam, set vfwcap\n" " - to capture from a directshow device, set dshow\n" #else " - to capture from a webcam, set video4linux2\n" " - to capture the screen, set x11grab\n" " -v4l2f inv4l2f inv4l2f is the input format for webcam acquisition\n" " - it can be mjpeg, yuyv422, etc.\n" #endif " -pixf FMT set the input pixel format\n" " -vfr N force the input video framerate\n" " -vres WxH force the video resolution (e.g. 640x480)\n" " -vcrop XxY crop the source video from X pixels left and Y pixels top. Must be used with -vres.\n" " -gdr use Gradual Decoder Refresh feature for video encoding (h264 codec only)\n" "* Audio options:\n" " -a string set the source name for an audio input\n" " - if input is from microphone, use \"plughw:[x],[y]\"\n" " where x is the card number and y is the device number\n" " -af string set the input audio format\n" "\n" "Output options:\n" "* Video encoding options:\n" " -vcodec string set the output video codec (default: h264)\n" #if 0 //TODO: bind to option and params - test first how it binds to current input parameters " -vb int set the output video bitrate (in bits)\n" #endif " -vcustom string send custom parameters directly to the audio encoder\n" "* Audio encoding options:\n" " -acodec string set the output audio codec (default: aac)\n" #if 0 //TODO: bind to option and params - test first how it binds to current input parameters " -ab int set the output audio bitrate in bits (default: 192000)\n" " -as int set the sample rate (default: 44100)\n" " -ach int set the number of output audio channels (default: 2)\n" #endif " -acustom string send custom parameters directly to the audio encoder\n" "\n" "DASH options:\n" " -seg-dur dur:int set the segment duration in millisecond (default value: 1000)\n" " -frag-dur dur:int set the fragment duration in millisecond (default value: 1000)\n" " -seg-marker marker:str add a marker box named marker at the end of DASH segment\n" " -out outdir:str outdir is the output data directory (default: output)\n" " -mpd mpdname:str mpdname is the MPD file name (default: dashcast.mpd)\n" " -ast-offset dur:int dur is the MPD availabilityStartTime shift in milliseconds (default value: 1000)\n" " -mpd-refresh dur:int dur is the MPD minimumUpdatePeriod in seconds\n" " -time-shift dur:int dur is the MPD TimeShiftBufferDepth in seconds\n" " - the default value is 10. Specify -1 to keep all files.\n" " -min-buffer dur:float dur is the MPD minBufferTime in seconds (default value: 1.0)\n" " -base-url baseurl:str baseurl is the MPD BaseURL\n" "\n" "\n" "Examples:\n" "\n" " DashCast -av test.avi -live-media\n" " DashCast -a test_audio.mp3 -v test_audio.mp4 -live-media\n" #ifdef WIN32 " DashCast -vf vfwcap -vres 1280x720 -vfr 24 -v 0 -live\n" " DashCast -vf dshow -vres 1280x720 -vfr 24 -v video=\"screen-capture-recorder\" -live (please install http://screencapturer.sf.net/)\n" " DashCast -vf dshow -vres 1280x720 -vfr 24 -v video=\"YOUR-WEBCAM\" -pixf yuv420p -live\n" #else " DashCast -vf video4linux2 -vres 1280x720 -vfr 24 -v4l2f mjpeg -v /dev/video0 -af alsa -a plughw:1,0 -live\n" " DashCast -vf x11grab -vres 800x600 -vfr 25 -v :0.0 -live\n" #endif "\n"; const char *command_error = "\33[31mUnknown option or missing mandatory argument.\33[0m\n"; if (argc == 1) { fprintf(stderr, "%s", command_usage); return -2; } #ifdef GPAC_MEMORY_TRACKING i = 1; while (i < argc) { if (strcmp(argv[i], "-mem-track") == 0) { use_mem_track = GF_TRUE; break; } i++; } #endif gf_sys_init(use_mem_track); if (use_mem_track) { gf_log_set_tool_level(GF_LOG_MEMORY, GF_LOG_INFO); } /* Initialize command data */ dc_cmd_data_init(cmd_data); i = 1; while (i < argc) { if (strcmp(argv[i], "-a") == 0 || strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "-av") == 0) { DASHCAST_CHECK_NEXT_ARG if (strcmp(argv[i - 1], "-a") == 0 || strcmp(argv[i - 1], "-av") == 0) { if (strcmp(cmd_data->audio_data_conf.filename, "") != 0) { fprintf(stderr, "Audio source has already been specified.\n"); fprintf(stderr, "%s", command_usage); return -1; } strcpy(cmd_data->audio_data_conf.filename, argv[i]); } if (strcmp(argv[i - 1], "-v") == 0 || strcmp(argv[i - 1], "-av") == 0) { if (strcmp(cmd_data->video_data_conf.filename, "") != 0) { fprintf(stderr, "Video source has already been specified.\n"); fprintf(stderr, "%s", command_usage); return -1; } strcpy(cmd_data->video_data_conf.filename, argv[i]); } i++; } else if (strcmp(argv[i], "-af") == 0 || strcmp(argv[i], "-vf") == 0) {
int main(int argc, char **argv) { GF_Err e; VariantPlaylist * pl = NULL; char *url = argv[1]; //char *cache_m3u8_file; u32 i, count; FILE *fmpd; Bool verbose = 0; u32 update_interval = 0; char *m3u8_local_name = "file.m3u8"; Bool is_local = 0; gf_sys_init(0); gf_log_set_tool_level(GF_LOG_NETWORK, verbose ? GF_LOG_DEBUG : GF_LOG_INFO); while (1) { if (gf_url_is_local(url)) { m3u8_local_name = url; is_local = 1; } else { e = gf_dm_wget(url, m3u8_local_name, 0, 0); if (e != GF_OK) return -1; } e = parse_root_playlist(m3u8_local_name, &pl, "."); if (e != GF_OK) return -1; fmpd = fopen(argv[2], "wt"); fprintf(fmpd, "<MPD type=\"Live\" xmlns=\"urn:3GPP:ns:PSS:AdaptiveHTTPStreamingMPD:2009\">\n"); fprintf(fmpd, " <ProgramInformation moreInformationURL=\"http://gpac.sourceforge.net\">\n"); fprintf(fmpd, " <Title>Media Presentation Description for file %s</Title>\n", url); fprintf(fmpd, " <Source>Generated by GPAC %s</Source>\n", GPAC_FULL_VERSION); fprintf(fmpd, " </ProgramInformation>\n"); fprintf(fmpd, " <Period start=\"PT0S\">\n"); count = gf_list_count(pl->programs); for (i=0; i<count; i++) { u32 j, count2; Program *prog = gf_list_get(pl->programs, i); count2 = gf_list_count(prog->bitrates); for (j = 0; j<count2; j++) { PlaylistElement *pe = gf_list_get(prog->bitrates, j); fprintf(stdout, "%d, %d, %s, %s, %d\n", pe->durationInfo, pe->bandwidth, pe->title, pe->url, pe->elementType); if (pe->elementType == TYPE_PLAYLIST) { u32 k, count3; char *tmp; char c; char baseURL[GF_MAX_PATH]; tmp = strrchr(url, '/'); if (tmp) { tmp++; c = tmp[0]; tmp[0] = 0; strcpy(baseURL, url); tmp[0] = c; } else { baseURL[0] = 0; } fprintf(fmpd, " <Representation mimeType=\"video/mp2t\">\n"); fprintf(fmpd, " <SegmentInfo duration=\"PT%dS\"", pe->durationInfo); if (baseURL[0]) fprintf(fmpd, "baseURL=\"%s\"", baseURL); fprintf(fmpd, ">\n"); count3 = gf_list_count(pe->element.playlist.elements); update_interval = (count3 - 1) * pe->durationInfo * 1000; for (k=0; k<count3; k++) { PlaylistElement *elt = gf_list_get(pe->element.playlist.elements, k); if (k) fprintf(fmpd, " <Url sourceURL=\"%s\"/>\n", elt->url); else fprintf(fmpd, " <InitialisationSegmentURL sourceURL=\"%s\"/>\n", elt->url); } fprintf(fmpd, " </SegmentInfo>\n"); fprintf(fmpd, " </Representation>\n"); } else if (pe->elementType == TYPE_STREAM) { fprintf(stdout, "Stream\n"); } } } fprintf(fmpd, " </Period>\n"); fprintf(fmpd, "</MPD>"); fclose(fmpd); variant_playlist_del(pl); if (is_local) break; gf_sleep(update_interval); } gf_sys_close(); return 0; }
int stream_file_rtp(int argc, char **argv) { GF_ISOMRTPStreamer *file_streamer; char *sdp_file = "session.sdp"; char *ip_dest = "127.0.0.1"; char *ifce_addr = NULL; char *inName = NULL; char *logs=NULL; FILE *logfile=NULL; u16 port = 7000; u32 ttl = 1; Bool loop = 1; Bool mem_track = 0; Bool force_mpeg4 = 0; u32 path_mtu = 1450; u32 i; for (i = 1; i < (u32) argc ; i++) { char *arg = argv[i]; if (arg[0] != '-') { if (inName) { fprintf(stderr, "Error - 2 input names specified, please check usage\n"); return 1; } inName = arg; } else if (!stricmp(arg, "-noloop")) loop = 0; else if (!stricmp(arg, "-mpeg4")) force_mpeg4 = 1; else if (!strnicmp(arg, "-port=", 6)) port = atoi(arg+6); else if (!strnicmp(arg, "-mtu=", 5)) path_mtu = atoi(arg+5); else if (!strnicmp(arg, "-dst=", 5)) ip_dest = arg+5; else if (!strnicmp(arg, "-ttl=", 5)) ttl = atoi(arg+5); else if (!strnicmp(arg, "-ifce=", 6)) ifce_addr = arg+6; else if (!strnicmp(arg, "-sdp=", 5)) sdp_file = arg+5; else if (!stricmp(arg, "-mem-track")) mem_track = 1; else if (!strnicmp(arg, "-logs=", 6)) logs = arg+6; else if (!strnicmp(arg, "-lf=", 4)) logfile = gf_f64_open(arg+4, "wt"); } gf_sys_init(mem_track); if (logs) gf_log_set_tools_levels(logs); else gf_log_set_tool_level(GF_LOG_RTP, GF_LOG_INFO); //set to debug to have packet list if (logfile) { gf_log_set_callback(logfile, on_logs); } if (!gf_isom_probe_file(inName)) { fprintf(stderr, "File %s is not a valid ISO Media file and cannot be streamed\n", inName); if (logfile) fclose(logfile); gf_sys_close(); return 1; } file_streamer = gf_isom_streamer_new(inName, ip_dest, port, loop, force_mpeg4, path_mtu, ttl, ifce_addr); if (!file_streamer) { fprintf(stderr, "Cannot create file streamer\n"); } else { u32 check = 50; fprintf(stderr, "Starting streaming %s to %s:%d\n", inName, ip_dest, port); gf_isom_streamer_write_sdp(file_streamer, sdp_file); while (1) { gf_isom_streamer_send_next_packet(file_streamer, 0, 0); check--; if (!check) { if (gf_prompt_has_input()) { char c = (char) gf_prompt_get_char(); if (c=='q') break; } check = 50; } } gf_isom_streamer_del(file_streamer); } if (logfile) fclose(logfile); gf_sys_close(); return 0; }
int main (const int argc, const char** argv) { GF_Err e; Bool run; /* location of the configuration file: 0 wait for config on a socket, 1 use the given file */ u32 config_flag; char config_file_name[MAX_BUF]; int dest_port; unsigned short tcp_port = 0; /* Should be fine on WIFI network */ unsigned short mtu_size = 1492; int debug = 0; TCP_Input *tcp_conf = NULL; GF_Thread *tcp_thread; GF_Err th_err_tcp; GF_Err th_err_rap; RAP_Input *rap_conf; GF_Thread *rap_thread; CONF_Data *conf; GF_Config *gf_config_file; GF_Err res; GF_Socket *UDP_feedback_socket; u32 socketType_for_updates; PNC_CallbackData * data; GF_RTPChannel * chan; GF_RTPHeader hdr; u32 timer = -1; GF_Mutex *carrousel_mutex; char sdp_fmt[5000]; tcp_thread = NULL; /* init gpac lib */ gf_sys_init(); gf_log_set_level(GF_LOG_ERROR); gf_log_set_tools(GF_LOG_NETWORK|GF_LOG_RTP|GF_LOG_SCENE|GF_LOG_PARSER|GF_LOG_AUTHOR|GF_LOG_CODING|GF_LOG_SCRIPT); GF_SAFEALLOC(conf, CONF_Data); tcp_port = config_flag = 0; socketType_for_updates = GF_SOCK_TYPE_UDP; if (command_line_parsing(argc, argv, &tcp_port, config_file_name, (int *) &config_flag, &mtu_size, &debug, &socketType_for_updates)){ print_usage(); return -1; } setDebugMode( debug ); gf_config_file = NULL; if (config_flag == 1) { char *cfg_path; char *cfg_fname; char *tmp; cfg_fname = config_file_name; cfg_path = config_file_name; tmp = strrchr(cfg_fname, GF_PATH_SEPARATOR); if (tmp) { cfg_fname = tmp+1; tmp[0] = 0; } else { cfg_path = "."; } gf_config_file = gf_cfg_new(cfg_path, cfg_fname); if (!gf_config_file) { fprintf(stderr, "Cannot open config file %s\n", config_file_name); return -1; } else { dprintf(DEBUG_broadcaster, "Using config file %s.\n", config_file_name); } if (parse_config(gf_config_file, conf, debug)) return -1; tcp_port = atoi(conf->config_input_port); } else { GF_SAFEALLOC(tcp_conf, TCP_Input); tcp_conf->config_flag = &config_flag; tcp_conf->RAPtimer = &timer; tcp_conf->port = tcp_port; tcp_conf->config = conf; tcp_thread = gf_th_new("TCPInterface"); /* Starting the thread which will write the received config in a temporary file */ th_err_tcp = gf_th_run(tcp_thread, tcp_server, tcp_conf); fprintf(stdout, "Waiting for configuration on port %d...\n", tcp_conf->port); while(config_flag == 0) { gf_sleep(1000); } fprintf(stdout, "Configuration File received. Starting Streaming ...\n"); } timer = atoi(conf->rap_timer); dest_port = atoi(conf->dest_port); res = PNC_InitRTP(&chan, (char *)conf->dest_ip, dest_port, mtu_size); if (res != 0) { fprintf(stderr, "Cannot initialize RTP output (error: %d)\n", res); exit(1); } carrousel_mutex = gf_mx_new("Carrousel"); data = PNC_Init_SceneGenerator(chan, &hdr, (char *) conf->scene_init_file, socketType_for_updates, (u16) atoi(conf->modif_input_port), debug); if (!data) { fprintf(stderr, "Cannot initialize Scene Generator\n"); exit(1); } data->carrousel_mutex = carrousel_mutex; data->RAPsent = 1; UDP_feedback_socket = gf_sk_new(GF_SOCK_TYPE_UDP); e = gf_sk_bind(UDP_feedback_socket, NULL, (u16)atoi(conf->feedback_port), (char*)conf->feedback_ip, (u16)atoi(conf->feedback_port), 0); if (e) { fprintf(stderr, "Cannot bind socket for bitrate feedback information (%s)\n", gf_error_to_string(e)); } else { e = gf_sk_set_block_mode(UDP_feedback_socket, 1); if (e) { fprintf(stderr, "Cannot set feedback socket block mode (%s)\n", gf_error_to_string(e)); } } data->feedback_socket = UDP_feedback_socket; PNC_InitPacketiser(data, sdp_fmt, mtu_size); PNC_SendInitScene(data); GF_SAFEALLOC(rap_conf, RAP_Input); rap_conf->RAPtimer = &timer; rap_conf->carrousel_mutex = carrousel_mutex; rap_conf->data = data; rap_thread = gf_th_new("RAPGenerator"); th_err_rap = gf_th_run(rap_thread, RAP_send, rap_conf); sdp_generator(data, (char *)conf->dest_ip, sdp_fmt); run = 1; while (run) { GF_Err e = PNC_processBIFSGenerator(data); if (e) { fprintf(stderr, "Cannot Process BIFS data (%s)\n", gf_error_to_string(e)); break; } if (has_input()) { char c = get_a_char(); switch (c) { case 'q': run = 0; break; } } gf_sleep(10); } /* waiting for termination of the RAP thread */ rap_conf->status = 0; while (rap_conf->status != 2) gf_sleep(0); gf_free(rap_conf); gf_th_del(rap_thread); /* waiting for termination of the TCP listening thread */ if (tcp_conf) { tcp_conf->status = 0; while (tcp_conf->status != 2) gf_sleep(0); gf_free(tcp_conf); gf_th_del(tcp_thread); } PNC_Close_SceneGenerator(data); gf_free(conf); if (gf_config_file) gf_cfg_del(gf_config_file); gf_mx_del(carrousel_mutex); gf_sys_close(); return 0; }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, #ifdef _WIN32_WCE LPWSTR lpCmdLine, #else LPSTR lpCmdLine, #endif int nShowCmd ) { MSG msg; #ifdef _WIN32_WCE TCHAR wzExePath[GF_MAX_PATH]; #endif HWND hwndOld = NULL; const char *str; Bool initial_launch = 0; if (hwndOld = FindWindow(_T("Osmophone"), NULL)) { SetForegroundWindow(hwndOld); return 0; } memset(&user, 0, sizeof(GF_User)); term = NULL; g_hinst = hInstance; screen_w = GetSystemMetrics(SM_CXSCREEN); screen_h = GetSystemMetrics(SM_CYSCREEN); /*are we in low res or high res*/ RawFrameBufferInfo Info; HDC DC = GetDC(NULL); ExtEscape(DC, GETRAWFRAMEBUFFER, 0, NULL, sizeof(RawFrameBufferInfo), (char*)&Info); ReleaseDC(NULL,DC); if (Info.pFramePointer) { recompute_res(Info.cxPixels, Info.cyPixels); } else { recompute_res(screen_w, screen_h); } #ifdef _WIN32_WCE TCHAR szBuf[MAX_PATH]; SystemParametersInfo(SPI_GETPLATFORMTYPE, MAX_PATH, szBuf, 0); if (! lstrcmp(szBuf, __TEXT("PocketPC"))) is_ppc = 1; else if (! lstrcmp(szBuf, __TEXT("Palm PC2"))) is_ppc = 1; #endif user.config = gf_cfg_init(NULL, &initial_launch); if (!user.config) { MessageBox(NULL, _T("Couldn't locate GPAC config file"), _T("Fatal Error"), MB_OK); return 0; } str = gf_cfg_get_key(user.config, "Compositor", "ScreenWidth"); if (str) screen_w = atoi(str); str = gf_cfg_get_key(user.config, "Compositor", "ScreenHeight"); if (str) screen_h = atoi(str); disp_w = screen_w; #ifdef _WIN32_WCE disp_h = screen_h - menu_h /*- caption_h*/; #else disp_h = screen_h; #endif str = gf_cfg_get_key(user.config, "General", "ModulesDirectory"); if (!str) { gf_cfg_del(user.config); MessageBox(NULL, _T("Couldn't locate GPAC plugins"), _T("Fatal Error"), MB_OK); return 0; } gf_sys_init(0); user.modules = gf_modules_new(str, user.config); if (!gf_modules_get_count(user.modules)) { MessageBox(GetForegroundWindow(), _T("No modules found"), _T("GPAC Init Error"), MB_OK); gf_modules_del(user.modules); gf_cfg_del(user.config); memset(&user, 0, sizeof(GF_User)); gf_sys_close(); return 0; } /*first launch, register all files ext*/ if (initial_launch) { /*FFMPEG registration - FFMPEG DLLs compiled with CEGCC cannot be loaded directly under WM 6.1 cf http://cegcc.sourceforge.net/docs/faq.html#DllDoesNotWorkWithWindowsMobile6.1 */ HKEY hKey = NULL; DWORD dwSize; DWORD dwValue; RegCreateKeyEx(HKEY_LOCAL_MACHINE, _T("System\\Loader\\LoadModuleLow"), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey, &dwSize); dwSize = 4; dwValue = 1; LONG res = RegSetValueEx(hKey, _T("avcodec-52.dll"), NULL, REG_DWORD, (unsigned char *)&dwValue, dwSize); res = RegSetValueEx(hKey, _T("avformat-52.dll"), NULL, REG_DWORD, (unsigned char *)&dwValue, dwSize); res = RegSetValueEx(hKey, _T("avutil-50.dll"), NULL, REG_DWORD, (unsigned char *)&dwValue, dwSize); res = RegSetValueEx(hKey, _T("swscale-0.dll"), NULL, REG_DWORD, (unsigned char *)&dwValue, dwSize); RegCloseKey(hKey); u32 i; for (i=0; i<gf_modules_get_count(user.modules); i++) { GF_InputService *ifce = (GF_InputService *) gf_modules_load_interface(user.modules, i, GF_NET_CLIENT_INTERFACE); if (!ifce) continue; if (ifce) { ifce->CanHandleURL(ifce, "test.test"); gf_modules_close_interface((GF_BaseInterface *)ifce); } } MessageBox(NULL, _T("Thank you for installing GPAC"), _T("Initial setup done"), MB_OK); } str = gf_cfg_get_key(user.config, "General", "Loop"); loop = (!str || !stricmp(str, "yes")) ? 1 : 0; str = gf_cfg_get_key(user.config, "SAXLoader", "Progressive"); use_svg_prog = (str && !strcmp(str, "yes")) ? 1 : 0; str = gf_cfg_get_key(user.config, "General", "RTIRefreshPeriod"); if (str) { rti_update_time_ms = atoi(str); } else { gf_cfg_set_key(user.config, "General", "RTIRefreshPeriod", "200"); } str = gf_cfg_get_key(user.config, "General", "ShowStatusBar"); show_status = (str && !strcmp(str, "yes")) ? 1 : 0; #ifdef _WIN32_WCE if (is_ppc) GXOpenInput(); #endif if (InitInstance(nShowCmd)) { SetForegroundWindow(g_hwnd); show_taskbar(0); force_2d_gl = gf_term_get_option(term, GF_OPT_USE_OPENGL); while (GetMessage(&msg, NULL, 0,0) == TRUE) { TranslateMessage (&msg); DispatchMessage (&msg); if (playlist_act) { switch_playlist(playlist_act-1); playlist_act = 0; } } show_taskbar(1); } #ifdef _WIN32_WCE if (is_ppc) GXCloseInput(); #endif /*and destroy*/ if (term) gf_term_del(term); if (user.modules) gf_modules_del(user.modules); if (user.config) gf_cfg_del(user.config); if (backlight_off) set_backlight_state(0); gf_sys_close(); if (log_file) fclose(log_file); return 0; }
//Create window message fuction. when the window is created, also initialize a instance of //GPAC player instance. LRESULT CGPAXPlugin::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { if (m_term) return 0; const char *str; if (m_hWnd==NULL) return 0; gf_sys_init(0); //Create a structure m_user for initialize the terminal. the parameters to set: //1)config file path //2)Modules file path //3)window handler //4)EventProc memset(&m_user, 0, sizeof(m_user)); gf_log_set_tool_level(GF_LOG_ALL, GF_LOG_ERROR); m_user.config = gf_cfg_init(NULL, NULL); if(!m_user.config) { #ifdef _WIN32_WCE ::MessageBox(NULL, _T("GPAC Configuration file not found"), _T("Fatal Error"), MB_OK); #else ::MessageBox(NULL, "GPAC Configuration file not found", "Fatal Error", MB_OK); #endif goto err_exit; } /*check log file*/ str = gf_cfg_get_key(m_user.config, "General", "LogFile"); if (str) { m_pLogs = gf_f64_open(str, "wt"); if (m_pLogs) gf_log_set_callback(m_pLogs, gpax_do_log); } /*if logs are specified, use them*/ gf_log_set_tools_levels( gf_cfg_get_key(m_user.config, "General", "Logs") ); str = gf_cfg_get_key(m_user.config, "General", "ModulesDirectory"); m_user.modules = gf_modules_new(str, m_user.config); if(!gf_modules_get_count(m_user.modules)) goto err_exit; m_user.os_window_handler = m_hWnd; m_user.opaque = this; m_user.EventProc = GPAX_EventProc; //create a terminal m_term = gf_term_new(&m_user); if (!m_term) goto err_exit; gf_term_set_option(m_term, GF_OPT_AUDIO_VOLUME, 100); LoadDATAUrl(); RECT rc; ::GetWindowRect(m_hWnd, &rc); m_width = rc.right-rc.left; m_height = rc.bottom-rc.top; if (m_bAutoStart && strlen(m_url)) Play(); return 0; //Error Processing err_exit: if(m_user.modules) gf_modules_del(m_user.modules); m_user.modules = NULL; if(m_user.config) gf_cfg_del(m_user.config); m_user.config = NULL; gf_sys_close(); return 1; }