void COsmo4::EnableLogs(Bool turn_on) { if (turn_on) { m_logs = fopen("\\gpac_logs.txt", "wt"); if (!m_logs) { MessageBox(NULL, _T("Couldn't open log files at file system root"), _T("Disabling logs"), MB_OK); turn_on = 0; } else { gf_log_set_level(GF_LOG_DEBUG); // gf_log_set_tools(0xFFFFFFFF); gf_log_set_tools(GF_LOG_CORE|GF_LOG_NETWORK|GF_LOG_RTP|GF_LOG_SYNC|GF_LOG_CODEC|GF_LOG_MEDIA|GF_LOG_SERVICE); gf_log_set_callback(m_logs, osmo4_do_log); gf_cfg_set_key(m_user.config, "General", "LogLevel", "debug"); } } if (!turn_on) { if (m_logs) { fclose(m_logs); m_logs = 0; } gf_log_set_level(0); gf_log_set_tools(0); gf_log_set_callback(NULL, NULL); gf_cfg_set_key(m_user.config, "General", "LogLevel", "none"); } }
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; }
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*/ m_log_level = gf_log_parse_level(gf_cfg_get_key(m_user.config, "General", "LogLevel") ); gf_log_set_level(m_log_level); /*set log tools*/ m_log_tools = gf_log_parse_tools(gf_cfg_get_key(m_user.config, "General", "LogTools") ); gf_log_set_tools(m_log_tools); 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; }