📄 osmo4_appview.cpp
字号:
/* * GPAC - Multimedia Framework C SDK * * Copyright (c) ENST 2006-200X * Authors: Jean Le Feuvre * All rights reserved * * This file is part of GPAC / Symbian GUI player * * 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 FILES#include <coemain.h>#include <eikenv.h>#include "osmo4_AppView.h"#include "osmo4_appui.h"#include <gpac/options.h>/*for initial setup*/#include <gpac/modules/service.h>// ============================ MEMBER FUNCTIONS ===============================// -----------------------------------------------------------------------------// Cosmo4AppView::NewL()// Two-phased constructor.// -----------------------------------------------------------------------------//COsmo4AppView* COsmo4AppView::NewL( const TRect& aRect ){ COsmo4AppView* self = COsmo4AppView::NewLC( aRect ); CleanupStack::Pop( self ); return self;}// -----------------------------------------------------------------------------// COsmo4AppView::NewLC()// Two-phased constructor.// -----------------------------------------------------------------------------//COsmo4AppView* COsmo4AppView::NewLC( const TRect& aRect ){ COsmo4AppView* self = new ( ELeave ) COsmo4AppView; CleanupStack::PushL( self ); self->ConstructL( aRect ); return self;}// -----------------------------------------------------------------------------// COsmo4AppView::COsmo4AppView()// C++ default constructor can NOT contain any code, that might leave.// -----------------------------------------------------------------------------//COsmo4AppView::COsmo4AppView(){ // No implementation required m_pTimer = NULL; memset(&m_user, 0, sizeof(GF_User)); m_term = NULL; m_mx = NULL; last_title_update = 0; show_rti = 0; memset(&m_rti, 0, sizeof(GF_SystemRTInfo)); selector = NULL; target = NULL;}// -----------------------------------------------------------------------------// COsmo4AppView::~COsmo4AppView()// Destructor.// -----------------------------------------------------------------------------//COsmo4AppView::~COsmo4AppView(){ Shutdown(); if (m_mx) gf_mx_del(m_mx); if (selector) delete selector; //if (target) delete target;}void COsmo4AppView::Shutdown(){// MessageBox("Osmo4 shutdown request", ""); if (m_pTimer) { m_pTimer->Cancel(); delete m_pTimer; m_pTimer = NULL; } if (m_term) { GF_Terminal *t = m_term; m_term = NULL; gf_term_del(t); } if (m_user.config) { gf_cfg_del(m_user.config); m_user.config = NULL; } if (m_user.modules) { gf_modules_del(m_user.modules); m_user.modules = NULL; }// MessageBox("Osmo4 shutdown OK", "");}void COsmo4AppView::MessageBox(const char *text, const char *title){ HBufC *msg1, *msg2; TInt length = User::StringLength( ( TUint8* ) text) + 1; msg1 = HBufC::NewL( length ); msg1->Des().Copy( TPtrC8(( TText8* ) text) ); length = User::StringLength( ( TUint8* ) title) + 1; msg2 = HBufC::NewL( length ); msg2->Des().Copy( TPtrC8(( TText8* ) title) ); CEikonEnv::Static()->InfoWinL(*msg2, *msg1); delete msg1; delete msg2;}TInt myTick(TAny* aObject){ return ((COsmo4AppView*)aObject)->OnTick();}TInt COsmo4AppView::OnTick(){ if (m_term) gf_term_process_step(m_term); /*check RTI display*/ if (show_rti && gf_sys_get_rti(500, &m_rti, 0)) DisplayRTI(); /*never stop...*/ return 1;}void COsmo4AppView::DisplayRTI(){ COsmo4AppUi *app = (COsmo4AppUi *) CEikonEnv::Static()->AppUi(); char szInfo[20]; sprintf(szInfo, "CPU %02d FPS %02.2f", m_rti.process_cpu_usage, gf_term_get_framerate(m_term, 0)); app->SetInfo(szInfo);}//GPAC log functionstatic void on_gpac_log(void *cbk, u32 ll, u32 lm, const char *fmt, va_list list){ char szMsg[2048]; COsmo4AppView *app = (COsmo4AppView *)cbk; gf_mx_p(app->m_mx); if (app->do_log) { FILE *logs = fopen("\\data\\gpac_logs.txt", "a+t"); if (logs) { vfprintf(logs, fmt, list); fclose(logs); } } else { vsprintf(szMsg, fmt, list); app->MessageBox(szMsg, "Error:"); } gf_mx_v(app->m_mx);}static Bool GPAC_EventProc(void *ptr, GF_Event *evt){ COsmo4AppView *app = (COsmo4AppView *)ptr; return app->EventProc(evt);}Bool COsmo4AppView::EventProc(GF_Event *evt){ TRect r; switch (evt->type) { case GF_EVENT_MESSAGE: if (!evt->message.message) return 0; if (evt->message.error) { char err[1024]; sprintf(err, "Error: %s", gf_error_to_string(evt->message.error)); MessageBox(evt->message.message, err); } else { MessageBox(evt->message.message, "Info"); } break; case GF_EVENT_SCENE_SIZE: r = Rect(); gf_term_set_size(m_term, r.Width(), r.Height()); break; } return 0;}void COsmo4AppView::SetupLogs(){ const char *opt; gf_mx_p(m_mx); if (do_log) { gf_log_set_level(0); do_log = 0; } /*setup GPAC logs: log all errors*/ opt = gf_cfg_get_key(m_user.config, "General", "LogLevel"); if ((opt && !stricmp(opt, "debug")) /*|| 1*/) { FILE *logs = fopen("\\data\\gpac_logs.txt", "wt"); if (!logs) { MessageBox("Cannot open log file - disabling logs", "Warning !"); } else { MessageBox("Debug log enabled in \\data\\gpac_logs.txt", "Info"); fclose(logs); do_log = 1; gf_log_set_level(GF_LOG_DEBUG); gf_log_set_tools(0xFFFFFFFF); } } if (!do_log) { gf_log_set_level(GF_LOG_ERROR); gf_log_set_tools(0xFFFFFFFF); } gf_log_set_callback(this, on_gpac_log); gf_mx_v(m_mx); GF_LOG(GF_LOG_DEBUG, GF_LOG_CORE, ("Osmo4 logs initialized\n"));}static void Osmo4_progress_cbk(void *usr, char *title, u32 done, u32 total){ COsmo4AppView *view = (COsmo4AppView *) usr; COsmo4AppUi *app = (COsmo4AppUi *) CEikonEnv::Static()->AppUi(); if (done==total) { app->SetInfo(NULL); } else if (view->last_title_update + 500 < gf_sys_clock()) { char szName[1024]; view->last_title_update = gf_sys_clock(); sprintf(szName, "%s %02d %%", title, (done*100 / total) ); app->SetInfo(szName); }}// -----------------------------------------------------------------------------// COsmo4AppView::ConstructL()// Symbian 2nd phase constructor can leave.// -----------------------------------------------------------------------------//void COsmo4AppView::ConstructL( const TRect& aRect ){ const char *opt; Bool first_launch = 0; selector = CRemConInterfaceSelector::NewL(); target = CRemConCoreApiTarget::NewL(*selector, *this); selector->OpenTargetL(); // Create a window for this application view CreateWindowL(); // Set the windows size SetRect( aRect ); //draw ActivateL();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -