📄 gpaxplugin.cpp
字号:
/* * GPAC - Multimedia Framework C SDK * * Authors: Y.XI, X. ZHAO, J. Le Feuvre * Copyright (c) ENST 2006-200x * All rights reserved * * This file is part of GPAC / ActiveX control * * GPAC is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2, or (at your option) * any later version. * * GPAC is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; see the file COPYING. If not, write to * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * */#include "stdafx.h"#include "GPAX.h"#include "GPAXPlugin.h"#include <gpac/network.h>#include <gpac/utf.h>/////////////////////////////////////////////////////////////////////////////// CGPAXPlugin#if 0static print_err(char *msg, char *title){ u16 w_msg[1024], w_title[1024]; CE_CharToWide(msg, w_msg); CE_CharToWide(title, w_title); ::MessageBox(NULL, w_msg, w_title, MB_OK);}#endifvoid CGPAXPlugin::SetStatusText(char *msg){#ifndef _WIN32_WCE if (m_pBrowser) { if (msg) { u16 w_msg[1024]; gf_utf8_mbstowcs(w_msg, 1024, (const char **)&msg); m_pBrowser->put_StatusText(w_msg); } else { m_pBrowser->put_StatusText(L""); } }#endif}//GPAC player Event Handler. not yet implemented, just dummies hereBool CGPAXPlugin::EventProc(GF_Event *evt){ char msg[1024]; if (!m_term) return 0; switch (evt->type) { case GF_EVENT_MESSAGE: if (evt->message.error) { sprintf(msg, "(GPAC) %s (%s)", evt->message.message, gf_error_to_string(evt->message.error)); } else { sprintf(msg, "(GPAC) %s", evt->message.message); } SetStatusText(msg); break; case GF_EVENT_PROGRESS: if (evt->progress.done == evt->progress.total) { SetStatusText(NULL); } else { char *szTitle = ""; if (evt->progress.progress_type==0) szTitle = "Buffer "; else if (evt->progress.progress_type==1) szTitle = "Download "; else if (evt->progress.progress_type==2) szTitle = "Import "; sprintf(msg, "(GPAC) %s: %02.2f", szTitle, (100.0*evt->progress.done) / evt->progress.total); SetStatusText(msg); } break; case GF_EVENT_CONNECT: m_bIsConnected = evt->connect.is_connected; break; /*IGNORE any scene size, just work with the size allocated in the parent doc*/ case GF_EVENT_SCENE_SIZE: gf_term_set_size(m_term, m_width, m_height); break; /*window has been resized (full-screen plugin), resize*/ case GF_EVENT_SIZE: m_width = evt->size.width; m_height = evt->size.height; gf_term_set_size(m_term, m_width, m_height); break; case GF_EVENT_MOUSEDOUBLECLICK: gf_term_set_option(m_term, GF_OPT_FULLSCREEN, !gf_term_get_option(m_term, GF_OPT_FULLSCREEN)); break; case GF_EVENT_KEYDOWN: if ((evt->key.flags & GF_KEY_MOD_ALT)) { } else { switch (evt->key.key_code) { case GF_KEY_HOME: gf_term_set_option(m_term, GF_OPT_NAVIGATION_TYPE, 1); break; case GF_KEY_ESCAPE: gf_term_set_option(m_term, GF_OPT_FULLSCREEN, !gf_term_get_option(m_term, GF_OPT_FULLSCREEN)); break; } } break; case GF_EVENT_NAVIGATE_INFO: strcpy(msg, evt->navigate.to_url); SetStatusText(msg); break; case GF_EVENT_NAVIGATE: if (gf_term_is_supported_url(m_term, evt->navigate.to_url, 1, 1)) { gf_term_navigate_to(m_term, evt->navigate.to_url); return 1; } #ifndef _WIN32_WCE else if (m_pBrowser) { u32 i; const char **sz_ptr; u16 w_szTar[1024], w_szURL[1024]; VARIANT target, flags; flags.intVal = 0; target.bstrVal = L"_SELF"; for (i=0; i<evt->navigate.param_count; i++) { if (!strcmp(evt->navigate.parameters[i], "_parent")) target.bstrVal = L"_PARENT"; else if (!strcmp(evt->navigate.parameters[i], "_blank")) target.bstrVal = L"_BLANK"; else if (!strcmp(evt->navigate.parameters[i], "_top")) target.bstrVal = L"_TOP"; else if (!strcmp(evt->navigate.parameters[i], "_new")) flags.intVal |= navOpenInNewWindow; else if (!strnicmp(evt->navigate.parameters[i], "_target=", 8)) { sz_ptr = & evt->navigate.parameters[i]+8; gf_utf8_mbstowcs(w_szTar, 1024, (const char **)sz_ptr); target.bstrVal = w_szTar; } } sz_ptr = & evt->navigate.to_url; gf_utf8_mbstowcs(w_szURL, 1024, (const char **)sz_ptr); m_pBrowser->Navigate(w_szURL, &flags, &target, NULL, NULL);; return 1; }#endif break; } return 0;}Bool GPAX_EventProc(void *ptr, GF_Event *evt){ CGPAXPlugin *_this = (CGPAXPlugin *)ptr; return _this->EventProc(evt);}//Read Parameters from pPropBag given by MSIEBool CGPAXPlugin::ReadParamString(LPPROPERTYBAG pPropBag, LPERRORLOG pErrorLog, WCHAR *name, char *buf, int bufsize){ VARIANT v; HRESULT hr; Bool retval=0; v.vt = VT_EMPTY; v.bstrVal = NULL; hr = pPropBag->Read(name, &v, pErrorLog); if(SUCCEEDED(hr)) { if(v.vt==VT_BSTR && v.bstrVal) {// USES_CONVERSION;// lstrcpyn(buf,OLE2T(v.bstrVal),bufsize); const u16 *srcp = v.bstrVal; u32 len = gf_utf8_wcstombs(buf, bufsize, &srcp); if (len>=0) { buf[len] = 0; retval=1; } } VariantClear(&v); } return retval;}//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; unsigned char config_path[GF_MAX_PATH]; char *gpac_cfg; const char *str; if (m_hWnd==NULL) return 0; gpac_cfg = "GPAC.cfg";#if defined(_DEBUG) && !defined(_WIN32_WCE) strcpy((char *) config_path, "D:\\cvs\\gpac\\bin\\w32_deb\\");#else //Here we retrieve GPAC config file in the install diractory, which is indicated in the //Registry HKEY hKey = NULL; DWORD dwSize;#ifdef _WIN32_WCE u16 w_path[1024]; RegOpenKeyEx(HKEY_CLASSES_ROOT, TEXT("GPAC"), 0, KEY_READ, &hKey); DWORD dwType = REG_SZ; dwSize = GF_MAX_PATH; RegQueryValueEx(hKey, TEXT("InstallDir"), 0, &dwType, (LPBYTE) w_path, &dwSize); CE_WideToChar(w_path, (char *)config_path); RegCloseKey(hKey);#else RegOpenKeyEx(HKEY_CLASSES_ROOT, "GPAC", 0, KEY_READ, &hKey); dwSize = GF_MAX_PATH; RegQueryValueEx(hKey, "InstallDir", NULL, NULL, (unsigned char*) config_path, &dwSize); RegCloseKey(hKey);#endif#endif //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_new((const char*) config_path, gpac_cfg); if(!m_user.config) { char cfg_file[MAX_PATH]; /*create a blank config*/ sprintf(cfg_file, "%s\\%s", config_path, gpac_cfg); FILE *test = fopen(cfg_file, "wt"); if (test) fclose(test); m_user.config = gf_cfg_new((const char *) config_path, gpac_cfg); 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; } gf_cfg_set_key(m_user.config, "General", "ModulesDirectory", (const char *) config_path); gf_cfg_set_key(m_user.config, "Rendering", "Raster2D", "GPAC 2D Raster"); sprintf((char *) cfg_file, "%s\\cache", config_path); gf_cfg_set_key(m_user.config, "General", "CacheDirectory", (const char *) cfg_file); gf_cfg_set_key(m_user.config, "Network", "AutoReconfigUDP", "no"); gf_cfg_set_key(m_user.config, "Network", "UDPNotAvailable", "no"); gf_cfg_set_key(m_user.config, "Network", "BufferLength", "0"); 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", "120"); gf_cfg_set_key(m_user.config, "Video", "DriverName", "dx_hw"); gf_cfg_set_key(m_user.config, "Video", "UseHardwareMemory", "yes");#ifdef _WIN32_WCE strcpy((char*)cfg_file, "\\windows");#else ::GetWindowsDirectory((char*)cfg_file, MAX_PATH);#endif if (cfg_file[strlen((char*)cfg_file)-1] != '\\') strcat((char*)cfg_file, "\\"); strcat((char *)cfg_file, "Fonts"); gf_cfg_set_key(m_user.config, "FontEngine", "FontDirectory", (const char *) cfg_file); } 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; if (strstr(m_url, ".wrl") || strstr(m_url, ".x3d") || strstr(m_url, ".x3dv")) { gf_cfg_set_key(m_user.config, "Rendering", "RendererName", "GPAC 3D Renderer"); } else { gf_cfg_set_key(m_user.config, "Rendering", "RendererName", m_bUse3D ? "GPAC 3D Renderer" : "GPAC 2D Renderer"); } //create a terminal m_term = gf_term_new(&m_user); if (!m_term) goto err_exit;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -