void CNativeWrapper::setGpacPreference( const char * category, const char * name, const char * value) { if (m_user.config) { gf_cfg_set_key(m_user.config, category, name, value); gf_cfg_save(m_user.config); } }
GF_EXPORT void gf_cfg_del(GF_Config *iniFile) { if (!iniFile) return; gf_cfg_save(iniFile); gf_cfg_clear(iniFile); gf_free(iniFile); }
GF_Err gf_cache_flush_disk_cache ( const DownloadedCacheEntry entry ) { char buff[100]; CHECK_ENTRY; if ( !entry->properties) return GF_OK; GF_LOG(GF_LOG_DEBUG, GF_LOG_NETWORK, ("[CACHE] gf_cache_flush_disk_cache:%d for entry=%p\n", __LINE__, entry)); gf_cfg_set_key(entry->properties, CACHE_SECTION_NAME, CACHE_SECTION_NAME_URL, entry->url); sprintf(buff, LLD"-"LLD, entry->range_start, entry->range_end); gf_cfg_set_key(entry->properties, CACHE_SECTION_NAME, CACHE_SECTION_NAME_RANGE, buff); if (entry->mimeType) gf_cfg_set_key(entry->properties, CACHE_SECTION_NAME, CACHE_SECTION_NAME_MIME_TYPE, entry->mimeType); if (entry->diskETag) gf_cfg_set_key(entry->properties, CACHE_SECTION_NAME, CACHE_SECTION_NAME_ETAG, entry->diskETag); if (entry->diskLastModified) gf_cfg_set_key(entry->properties, CACHE_SECTION_NAME, CACHE_SECTION_NAME_LAST_MODIFIED, entry->diskLastModified); { snprintf(buff, 16, "%d", entry->contentLength); gf_cfg_set_key(entry->properties, CACHE_SECTION_NAME, CACHE_SECTION_NAME_CONTENT_SIZE, buff); } return gf_cfg_save ( entry->properties ); }
//------------------------------- // 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; }
//------------------------------- // 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; }