Example #1
0
GF_EXPORT
GF_Config *gf_cfg_init(const char *file, Bool *new_cfg)
{
	GF_Config *cfg;
	char szPath[GF_MAX_PATH];

	if (new_cfg) *new_cfg = GF_FALSE;

	if (file) {
		cfg = gf_cfg_new(NULL, file);
		/*force creation of a new config*/
		if (!cfg) {
			FILE *fcfg = gf_fopen(file, "wt");
			if (fcfg) {
				gf_fclose(fcfg);
				cfg = gf_cfg_new(NULL, file);
				if (new_cfg) *new_cfg = GF_TRUE;
			}
		}
		if (cfg) {
			check_modules_dir(cfg);
			return cfg;
		}
	}

	if (!get_default_install_path(szPath, GF_PATH_CFG)) {
		fprintf(stderr, "Fatal error: Cannot create a configuration file in application or user home directory - no write access\n");
		return NULL;
	}

	cfg = gf_cfg_new(szPath, CFG_FILE_NAME);
	if (!cfg) {
		fprintf(stderr, "GPAC config file %s not found in %s - creating new file\n", CFG_FILE_NAME, szPath);
		cfg = create_default_config(szPath);
	}
	if (!cfg) {
		fprintf(stderr, "\nCannot create config file %s in %s directory\n", CFG_FILE_NAME, szPath);
		return NULL;
	}

#ifndef GPAC_IPHONE
	fprintf(stderr, "Using config file in %s directory\n", szPath);
#endif

	check_modules_dir(cfg);

	if (!gf_cfg_get_key(cfg, "General", "StorageDirectory")) {
		get_default_install_path(szPath, GF_PATH_CFG);
		strcat(szPath, "/Storage");
		if (!gf_dir_exists(szPath)) gf_mkdir(szPath);
		gf_cfg_set_key(cfg, "General", "StorageDirectory", szPath);
	}
    
	if (new_cfg) *new_cfg = GF_TRUE;
	return cfg;
}
Example #2
0
GF_EXPORT
GF_Config *gf_cfg_init(const char *file, Bool *new_cfg)
{
	GF_Config *cfg;
	char szPath[GF_MAX_PATH];

	if (new_cfg) *new_cfg = 0;

	if (file) {
		cfg = gf_cfg_new(NULL, file);
		/*force creation of a new config*/
		if (!cfg) {
			FILE *fcfg = fopen(file, "wt");
			if (fcfg) {
				fclose(fcfg);
				cfg = gf_cfg_new(NULL, file);
				if (new_cfg) *new_cfg = 1;
			}
		}
		if (cfg) {
			check_modules_dir(cfg);
			return cfg;
		}
	}

	if (!get_default_install_path(szPath, GF_PATH_CFG)) {
		fprintf(stderr, "Fatal error: Cannot create a configuration file in application or user home directory - no write access\n");
		return NULL;
	}

	cfg = gf_cfg_new(szPath, CFG_FILE_NAME);
	if (!cfg) {
		fprintf(stderr, "GPAC config file %s not found in %s - creating new file\n", CFG_FILE_NAME, szPath);
		cfg = create_default_config(szPath);
	}
	if (!cfg) {
		fprintf(stderr, "Cannot create config file %s in %s directory\n", CFG_FILE_NAME, szPath);
		return NULL;
	}

#ifndef GPAC_IPHONE
	fprintf(stderr, "Using config file in %s directory\n", szPath);
#endif

	check_modules_dir(cfg);

	if (new_cfg) *new_cfg = 1;
	return cfg;
}
Example #3
0
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;
}
Example #4
0
static GF_Config *create_default_config(char *file_path)
{
	FILE *f;
	GF_Config *cfg;
#if !defined(GPAC_IPHONE) && !defined(GPAC_ANDROID)
	char *cache_dir;
#endif
	char szPath[GF_MAX_PATH];
	char gui_path[GF_MAX_PATH];

	if (! get_default_install_path(file_path, GF_PATH_CFG)) {
		gf_delete_file(szPath);
		return NULL;
	}
	/*Create the config file*/
	sprintf(szPath, "%s%c%s", file_path, GF_PATH_SEPARATOR, CFG_FILE_NAME);
	GF_LOG(GF_LOG_INFO, GF_LOG_CORE, ("Trying to create config file: %s\n", szPath ));
	f = fopen(szPath, "wt");
	if (!f) return NULL;
	fclose(f);

#ifndef GPAC_IPHONE
	if (! get_default_install_path(szPath, GF_PATH_MODULES)) {
		gf_delete_file(szPath);
		GF_LOG(GF_LOG_ERROR, GF_LOG_CORE, ("[Core] default modules not found\n"));
		return NULL;
	}
#else
	get_default_install_path(szPath, GF_PATH_APP);
#endif

	cfg = gf_cfg_new(file_path, CFG_FILE_NAME);
	if (!cfg) return NULL;

	gf_cfg_set_key(cfg, "General", "ModulesDirectory", szPath);

#if defined(GPAC_IPHONE)
	gf_ios_refresh_cache_directory(cfg, file_path);
#elif defined(GPAC_ANDROID)
	if (get_default_install_path(szPath, GF_PATH_APP)) {
		strcat(szPath, "/cache");
		gf_cfg_set_key(cfg, "General", "CacheDirectory", szPath);
	}
#else
    /*get default temporary directoy */
    cache_dir = gf_get_default_cache_directory();
	
	if (cache_dir) {
		gf_cfg_set_key(cfg, "General", "CacheDirectory", cache_dir);
		gf_free(cache_dir);
	}
#endif

#if defined(GPAC_IPHONE)
    gf_cfg_set_key(cfg, "General", "DeviceType", "iOS");
#elif defined(GPAC_ANDROID)
    gf_cfg_set_key(cfg, "General", "DeviceType", "Android");
#else
    gf_cfg_set_key(cfg, "General", "DeviceType", "Desktop");
#endif
    
	gf_cfg_set_key(cfg, "Compositor", "Raster2D", "GPAC 2D Raster");
	gf_cfg_set_key(cfg, "Audio", "ForceConfig", "yes");
	gf_cfg_set_key(cfg, "Audio", "NumBuffers", "2");
	gf_cfg_set_key(cfg, "Audio", "TotalDuration", "120");
	gf_cfg_set_key(cfg, "Audio", "DisableNotification", "no");

	/*Setup font engine to FreeType by default, and locate TrueType font directory on the system*/
	gf_cfg_set_key(cfg, "FontEngine", "FontReader", "FreeType Font Reader");
	gf_cfg_set_key(cfg, "FontEngine", "RescanFonts", "yes");


#if defined(_WIN32_WCE)
	/*FIXME - is this true on all WinCE systems??*/
	strcpy(szPath, "\\Windows");
#elif defined(WIN32)
	GetWindowsDirectory((char*)szPath, MAX_PATH);
	if (szPath[strlen((char*)szPath)-1] != '\\') strcat((char*)szPath, "\\");
	strcat((char *)szPath, "Fonts");
#elif defined(__APPLE__)

#ifdef GPAC_IPHONE
	strcpy(szPath, "/System/Library/Fonts/Cache,/System/Library/Fonts/AppFonts,/System/Library/Fonts/Core,/System/Library/Fonts/Extra");
#else
	strcpy(szPath, "/Library/Fonts");
#endif

#elif defined(GPAC_ANDROID)
	strcpy(szPath, "/system/fonts/");
#else
	strcpy(szPath, "/usr/share/fonts/truetype/");
#endif
	gf_cfg_set_key(cfg, "FontEngine", "FontDirectory", szPath);

	gf_cfg_set_key(cfg, "Downloader", "CleanCache", "yes");
	gf_cfg_set_key(cfg, "Compositor", "AntiAlias", "All");
	gf_cfg_set_key(cfg, "Compositor", "FrameRate", "30.0");
	/*use power-of-2 emulation in OpenGL if no rectangular texture extension*/
	gf_cfg_set_key(cfg, "Compositor", "EmulatePOW2", "yes");
	gf_cfg_set_key(cfg, "Compositor", "ScalableZoom", "yes");

#if defined(_WIN32_WCE)
	gf_cfg_set_key(cfg, "Video", "DriverName", "GAPI Video Output");
#elif defined(WIN32)
	gf_cfg_set_key(cfg, "Video", "DriverName", "DirectX Video Output");
#elif defined(__DARWIN__) || defined(__APPLE__)
	gf_cfg_set_key(cfg, "Video", "DriverName", "SDL Video Output");
#elif defined(GPAC_ANDROID)
	gf_cfg_set_key(cfg, "Video", "DriverName", "Android Video Output");
gf_cfg_set_key(cfg, "Audio", "DriverName", "Android Audio Output");
#else
	gf_cfg_set_key(cfg, "Video", "DriverName", "X11 Video Output");
	gf_cfg_set_key(cfg, "Audio", "DriverName", "SDL Audio Output");
#endif
#ifdef GPAC_IPHONE
	gf_cfg_set_key(cfg, "Compositor", "DisableGLUScale", "yes");
#endif

	gf_cfg_set_key(cfg, "Video", "SwitchResolution", "no");
	gf_cfg_set_key(cfg, "Video", "HardwareMemory", "Auto");
	gf_cfg_set_key(cfg, "Network", "AutoReconfigUDP", "yes");
	gf_cfg_set_key(cfg, "Network", "UDPTimeout", "10000");
	gf_cfg_set_key(cfg, "Network", "BufferLength", "3000");


	/*locate GUI*/
	if ( get_default_install_path(szPath, GF_PATH_GUI) ) {
		char *sep = strrchr(szPath, GF_PATH_SEPARATOR);
		if (!sep) sep = strrchr(szPath, GF_PATH_SEPARATOR);
		sprintf(gui_path, "%s%cgui.bt", szPath, GF_PATH_SEPARATOR);
		f = gf_fopen(gui_path, "rt");
		if (f) {
			gf_fclose(f);
			gf_cfg_set_key(cfg, "General", "StartupFile", gui_path);
		}

		/*shaders are at the same location*/
		assert(sep);
		sep[0] = 0;
		sprintf(gui_path, "%s%cshaders%cvertex.glsl", szPath, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR);
		gf_cfg_set_key(cfg, "Compositor", "VertexShader", gui_path);
		sprintf(gui_path, "%s%cshaders%cfragment.glsl", szPath, GF_PATH_SEPARATOR, GF_PATH_SEPARATOR);
		gf_cfg_set_key(cfg, "Compositor", "FragmentShader", gui_path);
	}

	/*store and reload*/
	gf_cfg_del(cfg);
	return gf_cfg_new(file_path, CFG_FILE_NAME);
}
Example #5
0
static GF_Config *create_default_config(char *file_path)
{
	FILE *f;
	GF_Config *cfg;
	char *cache_dir;
	char szPath[GF_MAX_PATH];
	char gui_path[GF_MAX_PATH];

	if (! get_default_install_path(file_path, GF_PATH_CFG)) {
		gf_delete_file(szPath);
		return NULL;
	}
	/*Create the config file*/
	sprintf(szPath, "%s%c%s", file_path, GF_PATH_SEPARATOR, CFG_FILE_NAME);
	f = gf_f64_open(szPath, "wt");
	if (!f) return NULL;
	fclose(f);

	if (! get_default_install_path(szPath, GF_PATH_MODULES)) {
		gf_delete_file(szPath);
		fprintf(stdout, "default modules not found\n");
		return NULL;
	}

	cfg = gf_cfg_new(file_path, CFG_FILE_NAME);
	if (!cfg) return NULL;

	gf_cfg_set_key(cfg, "General", "ModulesDirectory", szPath);

	/*get default temporary directoy */
	cache_dir = gf_get_default_cache_directory();
	if (cache_dir) {
		gf_cfg_set_key(cfg, "General", "CacheDirectory", cache_dir);
		gf_free(cache_dir);
	}

	gf_cfg_set_key(cfg, "Compositor", "Raster2D", "GPAC 2D Raster");
	gf_cfg_set_key(cfg, "Audio", "ForceConfig", "yes");
	gf_cfg_set_key(cfg, "Audio", "NumBuffers", "2");
	gf_cfg_set_key(cfg, "Audio", "TotalDuration", "120");
	gf_cfg_set_key(cfg, "Audio", "DisableNotification", "no");

	/*Setup font engine to FreeType by default, and locate TrueType font directory on the system*/
	gf_cfg_set_key(cfg, "FontEngine", "FontReader", "ft_font");
	gf_cfg_set_key(cfg, "FontEngine", "RescanFonts", "yes");


#if defined(_WIN32_WCE)
	/*FIXME - is this true on all WinCE systems??*/
	strcpy(szPath, "\\Windows");
#elif defined(WIN32)
	GetWindowsDirectory((char*)szPath, MAX_PATH);
	if (szPath[strlen((char*)szPath)-1] != '\\') strcat((char*)szPath, "\\");
	strcat((char *)szPath, "Fonts");
#elif defined(__APPLE__)

#ifdef GPAC_IPHONE
	strcpy(szPath, "/System/Library/Fonts/Cache");
#else
	strcpy(szPath, "/Library/Fonts");
#endif

#else
	strcpy(szPath, "/usr/share/fonts/truetype/");
#endif
	gf_cfg_set_key(cfg, "FontEngine", "FontDirectory", szPath);

	gf_cfg_set_key(cfg, "Downloader", "CleanCache", "yes");
	gf_cfg_set_key(cfg, "Compositor", "AntiAlias", "All");
	gf_cfg_set_key(cfg, "Compositor", "FrameRate", "30");
	/*use power-of-2 emulation in OpenGL if no rectangular texture extension*/
	gf_cfg_set_key(cfg, "Compositor", "EmulatePOW2", "yes");
	gf_cfg_set_key(cfg, "Compositor", "ScalableZoom", "yes");

#if defined(_WIN32_WCE)
	gf_cfg_set_key(cfg, "Video", "DriverName", "GAPI Video Output");
#elif defined(WIN32)
	gf_cfg_set_key(cfg, "Video", "DriverName", "DirectX Video Output");
#elif defined(__DARWIN__) || defined(__APPLE__)
	gf_cfg_set_key(cfg, "Video", "DriverName", "SDL Video Output");
#else
	gf_cfg_set_key(cfg, "Video", "DriverName", "X11 Video Output");
	gf_cfg_set_key(cfg, "Audio", "DriverName", "SDL Audio Output");
#endif

	gf_cfg_set_key(cfg, "Video", "SwitchResolution", "no");
	gf_cfg_set_key(cfg, "Video", "HardwareMemory", "Auto");
	gf_cfg_set_key(cfg, "Network", "AutoReconfigUDP", "yes");
	gf_cfg_set_key(cfg, "Network", "UDPTimeout", "10000");
	gf_cfg_set_key(cfg, "Network", "BufferLength", "3000");


	/*locate GUI*/
	if ( get_default_install_path(szPath, GF_PATH_GUI) ) {
		sprintf(gui_path, "%s%cgui.bt", szPath, GF_PATH_SEPARATOR);
		f = fopen(gui_path, "rt");
		if (f) {
			fclose(f);
			gf_cfg_set_key(cfg, "General", "StartupFile", gui_path);
		}
	}

	/*store and reload*/
	gf_cfg_del(cfg);
	return gf_cfg_new(file_path, CFG_FILE_NAME);
}
Example #6
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;
}
Example #7
0
u32 tcp_server(void *par)
{
	TCP_Input *input = par;
	u32 *timer = input->RAPtimer;
	char buffer[MAX_BUF];
	unsigned char temp[MAX_BUF];
	FILE *fp;
	u32 byte_read;
	int ret;
	GF_Config *gf_config_file;
	GF_Socket *TCP_socket;
	GF_Socket *conn_socket;
	GF_Err e;
	
	int debug = input->debug;
	input->status = 1;

	TCP_socket = gf_sk_new(GF_SOCK_TYPE_TCP);
	e = gf_sk_bind(TCP_socket, NULL, input->port, NULL, 0, 0);
	e = gf_sk_listen(TCP_socket, 1);
	e = gf_sk_set_block_mode(TCP_socket, 1);
	e = gf_sk_server_mode(TCP_socket, 0);
	
	while(input->status == 1)
	{	
		memset(buffer, 0, sizeof(buffer));	
		e = gf_sk_accept(TCP_socket, &conn_socket);
		if (e == GF_OK) {
			memset(buffer, 0, sizeof(buffer));
			e = gf_sk_receive(conn_socket, buffer, MAX_BUF, 0, &byte_read);
		}

		switch (e) {
			case GF_IP_NETWORK_EMPTY:
				gf_sleep(33);
				continue;
			case GF_OK:					
				break;
			default:
				fprintf(stderr, "Error with TCP socket : %s\n", gf_error_to_string(e));
				exit(1);
				break;
		}

		if((*(input->config_flag)) == 0)
		{
			u32 num_retry;
			fp = fopen("temp.cfg", "w+");
			if (!fp) {
				fprintf(stderr, "Error opening temp file for the configuration\n");
				exit(1);
			}
			ret = fwrite(buffer, 1, byte_read, fp);
			fclose(fp);
			
			/* parsing config info */
			gf_config_file = gf_cfg_new(".", "temp.cfg");
			if (!gf_config_file) {
				fprintf(stderr, "Error opening the config file %s\n", gf_error_to_string(e));
				exit(-1);
			}
			parse_config(gf_config_file, input->config, debug);

			/* Acknowledging the configuration */ 
			gf_sk_send(conn_socket, "OK\n", 3);

			memset(temp, 0, sizeof(temp));
			fp = fopen(input->config->scene_init_file, "w+");
			if (!fp) {
				fprintf(stderr, "Error opening temp file for reception of the initial scene\n");
				exit(1);
			}
			num_retry=10;

			while (1)
			{
				GF_Err e = gf_sk_receive(conn_socket, temp, sizeof(temp), 0, &byte_read);

				if (e == GF_OK) {
					fwrite(temp, 1, byte_read, fp);
				} else if (e==GF_IP_NETWORK_EMPTY) {
					num_retry--;
					if (!num_retry)
						break;
					gf_sleep(1);
				} else {
					fprintf(stderr, "Error receiving initial scene: %s\n", gf_error_to_string(e));
					break;
				}
			}
			fclose(fp);
			*(input->config_flag) = 1;
		}
		/* we only wait now for the config updates */
		if ( (*(input->config_flag)) == 1) {
			ret = sscanf(buffer, "DelaiMax=%d\n", timer);							
			fprintf(stdout, "RAP timer changed, now : %d\n", *timer);
		}
		gf_sk_del(conn_socket);
	}

	input->status = 2;
	return GF_OK;
}