Bool player(char *fn)
{
	Bool ret = GF_FALSE;
	GF_Err e;
	GF_User user;
	GF_Terminal *term = NULL;
	GF_Config *cfg_file;
	memset(&user, 0, sizeof(user));
	cfg_file = gf_cfg_init(NULL, NULL);
	user.modules = gf_modules_new(NULL, cfg_file);
	e = manually_register_opengl_shared_module(user.modules);
	if (e != GF_OK) goto exit;
	set_cfg_option(cfg_file, "Video:DriverName=" OPENGL_SHARED_MODULE_NAME_STR);
	user.config = cfg_file;
	user.opaque = &user;
	user.EventProc = event_proc;
	term = gf_term_new(&user);
	if (!term) goto exit;

	gf_term_connect(term, fn);
	while (!connected) gf_sleep(1);
	while ( connected) {
		gf_term_process_step(term);
		check_keyboard(term);
	}
	ret = GF_TRUE;

exit:
	gf_term_disconnect(term);
	gf_term_del(term);
	gf_modules_del(user.modules);
	gf_cfg_del(cfg_file);

	return ret;
}
Esempio n. 2
0
static Bool player_foreach(int argc, char **argv)
{
	int i;
	GF_User user;
	GF_Terminal *term;
	GF_Config *cfg_file;
	cfg_file = gf_cfg_init("GPAC.cfg", NULL);
	user.modules = gf_modules_new(NULL, cfg_file);
	user.config = cfg_file;
	user.EventProc = GPAC_EventProc;
	term = gf_term_new(&user);
	if (!term)
		return GF_FALSE;

	for (i=0; i<argc; ++i) {
		Bool res = play_pause_seek_gettime(term, argv[i]);
		if (res == GF_FALSE) {
			fprintf(stderr, "Failure with input %d: \"%s\"\n", i, argv[i]);
			return GF_FALSE;
		}
	}

	gf_term_disconnect(term);
	gf_term_del(term);
	gf_modules_del(user.modules);
	gf_cfg_del(cfg_file);

	return GF_TRUE;
}
Esempio n. 3
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;


	//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));

    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;
	}

    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;
	return 1;
}
Esempio n. 4
0
Bool LoadTerminal()
{
	/*by default use current dir*/
	strcpy(the_url, ".");

	setup_logs();

	g_hwnd_disp = CreateWindow(TEXT("STATIC"), NULL, WS_CHILD | WS_VISIBLE , 0, 0, disp_w, disp_h, g_hwnd, NULL, g_hinst, NULL);

	user.EventProc = GPAC_EventProc;
	/*dummy in this case (global vars) but MUST be non-NULL*/
	user.opaque = user.modules;
	user.os_window_handler = g_hwnd_disp;
#ifdef TERM_NOT_THREADED
	user.init_flags = GF_TERM_NO_DECODER_THREAD | GF_TERM_NO_COMPOSITOR_THREAD | GF_TERM_NO_REGULATION;
#endif

	term = gf_term_new(&user);
	if (!term) {
		gf_modules_del(user.modules);
		gf_cfg_del(user.config);
		memset(&user, 0, sizeof(GF_User));
		return 0;
	}

#ifdef _WIN32_WCE
	screen_w = term->compositor->video_out->max_screen_width;
	screen_h = term->compositor->video_out->max_screen_height;
	disp_w = screen_w;
	disp_h = screen_h - menu_h /*- caption_h*/;
#endif

#ifdef TERM_NOT_THREADED
	::SetTimer(g_hwnd, GPAC_TIMER_ID, GPAC_TIMER_DUR, NULL);
#endif

	const char *str = gf_cfg_get_key(user.config, "General", "StartupFile");
	if (str) {
		do_layout(1);
		strcpy(the_url, str);
		gf_term_connect(term, str);
	}
	return 1;
}
Esempio n. 5
0
// -----------------------------------------------------------------------------
// COsmo4AppView::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void COsmo4AppView::ConstructL( const TRect& aRect )
{
	const char *opt;
	Bool first_launch = 0;

#if defined(__SERIES60_3X__)
	selector = CRemConInterfaceSelector::NewL();
	target = CRemConCoreApiTarget::NewL(*selector, *this);
	selector->OpenTargetL();
#endif

    // Create a window for this application view
    CreateWindowL();
    // Set the windows size
    SetRect( aRect );
	//draw
    ActivateL();

#ifndef GPAC_GUI_ONLY
	m_window = Window();
	m_session = CEikonEnv::Static()->WsSession();

	m_mx = gf_mx_new("Osmo4");

	//load config file
	m_user.config = gf_cfg_init(NULL, &first_launch);
	if (!m_user.config) {
		MessageBox("Cannot create GPAC Config file", "Fatal Error");
		User::Leave(KErrGeneral);
	}
	if (first_launch) {
		MessageBox("Osmo4", "Thank you for Installing");
	}

	/*load modules*/
	opt = gf_cfg_get_key(m_user.config, "General", "ModulesDirectory");
	m_user.modules = gf_modules_new(opt, m_user.config);
	if (!m_user.modules || !gf_modules_get_count(m_user.modules)) {
		MessageBox(m_user.modules ? "No modules available" : "Cannot create module manager", "Fatal Error");
		if (m_user.modules) gf_modules_del(m_user.modules);
		gf_cfg_del(m_user.config);
		User::Leave(KErrGeneral);
	}

	if (first_launch) {
		/*first launch, register all files ext*/
		for (u32 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);
			}
		}
	}

	/*we don't thread the terminal, ie appart from the audio renderer, media decoding and visual rendering is
	handled by the app process*/
	m_user.init_flags = GF_TERM_NO_VISUAL_THREAD | GF_TERM_NO_REGULATION;
	m_user.EventProc = GPAC_EventProc;
	m_user.opaque = this;
	m_user.os_window_handler = (void *) &m_window;
	m_user.os_display = (void *) &m_session;

	m_term = gf_term_new(&m_user);
	if (!m_term) {
		MessageBox("Cannot load GPAC terminal", "Fatal Error");
		gf_modules_del(m_user.modules);
		gf_cfg_del(m_user.config);
		User::Leave(KErrGeneral);
	}
	//MessageBox("GPAC terminal loaded", "Success !");

	/*ok set output size*/
	TSize s = m_window.Size();
	gf_term_set_size(m_term, s.iWidth, s.iHeight);


	/*start our callback (every ms)*/
	const TInt KTickInterval = 33000;
	m_pTimer = CPeriodic::NewL(CActive::EPriorityStandard);
	m_pTimer->Start(KTickInterval, KTickInterval, TCallBack(myTick, this));

	opt = gf_cfg_get_key(m_user.config, "General", "StartupFile");
	if (opt) gf_term_connect(m_term, opt);

#endif

}
Esempio n. 6
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;
}
Esempio n. 7
0
bool GPACInit(void *application, GF_Terminal **term, GF_User *user, bool quiet) 
{
	memset(user, 0, sizeof(GF_User));

	/*locate exec dir for cfg file*/
    wxPathList pathList;
	wxString currentDir(wxGetCwd());
    wxString abs_gpac_path = "";
	const char *gpac_cfg;

	if (!quiet) ::wxLogMessage("Looking for GPAC configuration file");

#if defined(__WXMAC__) && !defined(__DARWIN__)
    // On Mac, the current directory is the relevant one when the application starts.
    abs_gpac_path = wxGetCwd();
	gpac_cfg = "GPAC.cfg";
#else

#ifdef WIN32
	V4StudioApp &app = wxGetApp();
	gpac_cfg = "GPAC.cfg";
	/*locate exe*/
    if (wxIsAbsolutePath(app.argv[0])) {
        abs_gpac_path = wxPathOnly(app.argv[0]);
	} else {
		if (currentDir.Last() != wxFILE_SEP_PATH) currentDir += wxFILE_SEP_PATH;
		abs_gpac_path = currentDir + app.argv[0];
		if (wxFileExists(abs_gpac_path)) {
			abs_gpac_path = wxPathOnly(abs_gpac_path);
		} else {
			abs_gpac_path = "";
			pathList.AddEnvList(wxT("PATH"));
			abs_gpac_path = pathList.FindAbsoluteValidPath(app.argv[0]);
			if (!abs_gpac_path.IsEmpty()) {
				abs_gpac_path = wxPathOnly(abs_gpac_path);
			} else {
				/*ask user*/
				wxDirDialog dlg(NULL, "Locate GPAC config file directory");
				if ( dlg.ShowModal() != wxID_OK ) return 0;
				abs_gpac_path = dlg.GetPath();
			}
		}
	}
#else
	gpac_cfg = ".gpacrc";
	char *cfg_dir = getenv("HOME");
	if (cfg_dir) {
		abs_gpac_path = cfg_dir;
	} else {
		/*ask user*/
		wxDirDialog dlg(NULL, "Locate GPAC config file directory");
		if ( dlg.ShowModal() != wxID_OK ) return 0;
		abs_gpac_path = dlg.GetPath();
	}

#endif

#endif

	/*load config*/
	Bool first_launch = 0;
	user->config = gf_cfg_init(NULL, &first_launch);

	if (!user->config) {
		wxMessageDialog(NULL, "Cannot create GPAC config file", "Init error", wxOK).ShowModal();
	}
	if (!quiet) ::wxLogMessage("GPAC configuration file opened - looking for modules");
	const char *str = gf_cfg_get_key(user->config, "General", "ModulesDirectory");
	user->modules = gf_modules_new(str, user->config);

	if (! gf_modules_get_count(user->modules) ) {
		wxMessageDialog(NULL, "No modules available - system cannot work", "Fatal Error", wxOK).ShowModal();
		gf_modules_del(user->modules);
		gf_cfg_del(user->config);
		return 0;
	}

	if (!quiet) ::wxLogMessage("%d modules found:", gf_modules_get_count(user->modules));
	for (u32 i=0; i<gf_modules_get_count(user->modules); i++) {
		if (!quiet) ::wxLogMessage("\t%s", gf_modules_get_file_name(user->modules, i));
	}

	if (!quiet) ::wxLogMessage("Starting GPAC Terminal");
	/*now load terminal*/
	user->opaque = application;
	user->EventProc = V4S_EventProc;
//	user->os_window_handler = ((wxGPACPanel *)application)->GetV4SceneManager()->GetV4StudioFrame()->GetHandle();

	// Forces the renderer to not use a thread and do the rendering by itfe
	gf_cfg_set_key(user->config, "Systems", "NoVisualThread", "No");

	*term = gf_term_new(user);
	if (!*term) {
		wxMessageDialog(NULL, "Fatal Error", "Cannot load GPAC Terminal", wxOK).ShowModal();
		return 0;
	} else {
		if (!quiet) ::wxLogMessage("GPAC Terminal started");
	}

	return 1;
}
Esempio n. 8
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;
}
Esempio n. 9
0
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;
}
Esempio n. 10
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;
}
Esempio n. 11
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*/
	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;
}