//GPAC player Event Handler. not yet implemented, just dummies here Bool 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_DBLCLICK: 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 = (BSTR) w_szTar; } } sz_ptr = & evt->navigate.to_url; gf_utf8_mbstowcs(w_szURL, 1024, (const char **)sz_ptr); m_pBrowser->Navigate((BSTR) w_szURL, &flags, &target, NULL, NULL);; return 1; } #endif break; } return 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(0); 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; }