⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 osmo4.cpp

📁 一个用于智能手机的多媒体库适合S60 WinCE的跨平台开发库
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// Osmo4.cpp : Defines the class behaviors for the application.//#include "stdafx.h"#include "Osmo4.h"#include <gpac/options.h>#include <gpac/modules/service.h>#include "MainFrm.h"#include "OpenDlg.h"#include "Options.h"#include <gx.h>#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// COsmo4BEGIN_MESSAGE_MAP(COsmo4, CWinApp)	//{{AFX_MSG_MAP(COsmo4)	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)	ON_COMMAND(IDD_CONFIGURE, OnConfigure)	ON_COMMAND(ID_OPEN_FILE, OnOpenFile)	ON_COMMAND(ID_OPEN_URL, OnOpenUrl)	ON_COMMAND(ID_SHORTCUTS, OnShortcuts)	//}}AFX_MSG_MAPEND_MESSAGE_MAP()Bool Osmo4CE_EventProc(void *priv, GF_Event *event){	u32 dur;	COsmo4 *app = (COsmo4 *) priv;	CMainFrame *pFrame = (CMainFrame *) app->m_pMainWnd;	/*shutdown*/	if (!pFrame) return 0;	switch (event->type) {	case GF_EVENT_MESSAGE:		if (event->message.error!=GF_OK) {			if (event->message.error<GF_OK) {				pFrame->console_err = event->message.error;				pFrame->console_message = event->message.message;				pFrame->PostMessage(WM_CONSOLEMSG, 0, 0);			}			return 0;		}		if (1) return 0;		/*process user message*/		pFrame->console_err = GF_OK;		pFrame->console_message = event->message.message;		pFrame->PostMessage(WM_CONSOLEMSG, 0, 0);		break;	case GF_EVENT_SIZE:		break;	case GF_EVENT_SCENE_SIZE:		app->m_scene_width = event->size.width;		app->m_scene_height = event->size.height;		if (!pFrame->m_full_screen) 			pFrame->PostMessage(WM_SETSIZE, event->size.width, event->size.height);		break;	case GF_EVENT_CONNECT:		app->m_open = event->connect.is_connected;		break;	case GF_EVENT_DURATION:		dur = (u32) (1000 * event->duration.duration);		if (dur<2000) dur = 0;		app->m_duration = dur;		app->m_can_seek = event->duration.can_seek && dur;		pFrame->m_progBar.m_range_invalidated = 1;		/*by default, don't display timing if not seekable and vice-versa*/		if (app->m_can_seek != pFrame->m_view_timing) {			pFrame->m_view_timing = app->m_can_seek;			if (!pFrame->m_full_screen) 				pFrame->PostMessage(WM_SETSIZE, 0, 0);		}		break;	case GF_EVENT_NAVIGATE:		/*store URL since it may be destroyed, and post message*/		app->m_navigate_url = event->navigate.to_url;		pFrame->PostMessage(WM_NAVIGATE, NULL, NULL);		return 1;	case GF_EVENT_QUIT:		pFrame->PostMessage(WM_CLOSE, 0L, 0L);		break;	/*ipaq keys*/	case GF_EVENT_KEYDOWN:		switch (event->key.key_code) {		case GF_KEY_F1: 			pFrame->PostMessage(WM_COMMAND, ID_FILE_OPEN); 			break;		case GF_KEY_F2:			pFrame->PostMessage(WM_QUIT); 			break;		case GF_KEY_F3:			pFrame->PostMessage(WM_COMMAND, ID_FILE_RESTART);			break;		case GF_KEY_F5:			pFrame->PostMessage(WM_COMMAND, ID_VIEW_FULLSCREEN);			break;		case GF_KEY_ENTER:			pFrame->PostMessage(WM_COMMAND, ID_FILE_PAUSE);			break;		case GF_KEY_LEFT:			if (app->m_duration>=2000) {				s32 res = gf_term_get_time_in_ms(app->m_term) - 5*app->m_duration/100;				if (res<0) res=0;				gf_term_play_from_time(app->m_term, res, 0);			}			break;		case GF_KEY_RIGHT:			if (app->m_duration>=2000) {				u32 res = gf_term_get_time_in_ms(app->m_term) + 5*app->m_duration/100;				if (res>=app->m_duration) res = 0;				gf_term_play_from_time(app->m_term, res, 0);			}			break;		case GF_KEY_UP:			if (app->m_duration>=2000) pFrame->PostMessage(WM_COMMAND, ID_FILE_STEP);				break;		case GF_KEY_DOWN:			gf_term_set_option(app->m_term, GF_OPT_REFRESH, 0);			break;		}		break;	case GF_EVENT_MOUSEDOUBLECLICK:		pFrame->PostMessage(WM_COMMAND, ID_VIEW_FULLSCREEN);		return 0;	}		return 0;}COsmo4::COsmo4()	: CWinApp(){	// TODO: add construction code here,	// Place all significant initialization in InitInstance	m_logs = NULL;}/////////////////////////////////////////////////////////////////////////////// The one and only COsmo4 objectCOsmo4 theApp;static void osmo4_do_log(void *cbk, u32 level, u32 tool, const char *fmt, va_list list){	FILE *logs = (FILE *) cbk;	if (logs) {	    vfprintf(logs, fmt, list);		fflush(logs);	}}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");	}}/////////////////////////////////////////////////////////////////////////////// COsmo4 initializationBOOL 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);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -