diff options
author | Benny Prijono <bennylp@teluu.com> | 2009-03-12 18:11:37 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2009-03-12 18:11:37 +0000 |
commit | 1dacdee696b7591a6dcc0b3c1d0f41573e473168 (patch) | |
tree | 302b09dcd989c0c05cf09f6aebaa63d870b421b9 /pjsip-apps/src/symsndtest | |
parent | ba9d8ca28eb209571c0bd6a080a8bb03d0fa2d33 (diff) |
(Major) Task #737 and #738: integration of APS-Direct and Audiodev from aps-direct branch to trunk.
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@2506 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip-apps/src/symsndtest')
-rw-r--r-- | pjsip-apps/src/symsndtest/app_main.cpp | 110 | ||||
-rw-r--r-- | pjsip-apps/src/symsndtest/main_symbian.cpp | 88 |
2 files changed, 63 insertions, 135 deletions
diff --git a/pjsip-apps/src/symsndtest/app_main.cpp b/pjsip-apps/src/symsndtest/app_main.cpp index 597e7117..056cde10 100644 --- a/pjsip-apps/src/symsndtest/app_main.cpp +++ b/pjsip-apps/src/symsndtest/app_main.cpp @@ -49,7 +49,7 @@ static void log_writer(int level, const char *buf, unsigned len) static wchar_t buf16[PJ_LOG_MAX_SIZE]; PJ_UNUSED_ARG(level); - + pj_ansi_to_unicode(buf, len, buf16, PJ_ARRAY_SIZE(buf16)); TPtrC16 aBuf((const TUint16*)buf16, (TInt)len); @@ -57,24 +57,24 @@ static void log_writer(int level, const char *buf, unsigned len) } /* perror util */ -static void app_perror(const char *title, pj_status_t status) +static void app_perror(const char *title, pj_status_t status) { - char errmsg[PJ_ERR_MSG_SIZE]; + char errmsg[PJ_ERR_MSG_SIZE]; pj_strerror(status, errmsg, sizeof(errmsg)); PJ_LOG(1,(THIS_FILE, "Error: %s: %s", title, errmsg)); } /* Application init */ -static pj_status_t app_init() +static pj_status_t app_init() { unsigned i, count; pj_status_t status; - + /* Redirect log */ pj_log_set_log_func((void (*)(int,const char*,int)) &log_writer); pj_log_set_decor(PJ_LOG_HAS_NEWLINE); pj_log_set_level(3); - + /* Init pjlib */ status = pj_init(); if (status != PJ_SUCCESS) { @@ -83,7 +83,7 @@ static pj_status_t app_init() } pj_caching_pool_init(&cp, NULL, 0); - + /* Init sound subsystem */ status = pjmedia_snd_init(&cp.factory); if (status != PJ_SUCCESS) { @@ -92,16 +92,16 @@ static pj_status_t app_init() pj_shutdown(); return status; } - + count = pjmedia_snd_get_dev_count(); PJ_LOG(3,(THIS_FILE, "Device count: %d", count)); for (i=0; i<count; ++i) { const pjmedia_snd_dev_info *info; - + info = pjmedia_snd_get_dev_info(i); PJ_LOG(3, (THIS_FILE, "%d: %s %d/%d %dHz", i, info->name, info->input_count, info->output_count, - info->default_samples_per_sec)); + info->default_samples_per_sec)); } /* Create pool */ @@ -114,8 +114,8 @@ static pj_status_t app_init() } /* Init delay buffer */ - status = pjmedia_delay_buf_create(pool, THIS_FILE, CLOCK_RATE, - SAMPLES_PER_FRAME, CHANNEL_COUNT, + status = pjmedia_delay_buf_create(pool, THIS_FILE, CLOCK_RATE, + SAMPLES_PER_FRAME, CHANNEL_COUNT, 0, 0, &delaybuf); if (status != PJ_SUCCESS) { app_perror("pjmedia_delay_buf_create()", status); @@ -123,16 +123,16 @@ static pj_status_t app_init() //pj_shutdown(); //return status; } - + return PJ_SUCCESS; } /* Sound capture callback */ -static pj_status_t rec_cb(void *user_data, +static pj_status_t rec_cb(void *user_data, pj_uint32_t timestamp, void *input, - unsigned size) + unsigned size) { PJ_UNUSED_ARG(user_data); PJ_UNUSED_ARG(timestamp); @@ -153,28 +153,28 @@ static pj_status_t rec_cb(void *user_data, static pj_status_t play_cb(void *user_data, pj_uint32_t timestamp, void *output, - unsigned size) + unsigned size) { PJ_UNUSED_ARG(user_data); PJ_UNUSED_ARG(timestamp); PJ_UNUSED_ARG(size); - + pjmedia_delay_buf_get(delaybuf, (pj_int16_t*)output); - + ++play_cnt; - return PJ_SUCCESS; + return PJ_SUCCESS; } /* Start sound */ -static pj_status_t snd_start(unsigned flag) +static pj_status_t snd_start(unsigned flag) { pj_status_t status; - + if (strm != NULL) { app_perror("snd already open", PJ_EINVALIDOP); return PJ_EINVALIDOP; } - + if (flag==PJMEDIA_DIR_CAPTURE_PLAYBACK) status = pjmedia_snd_open(-1, -1, CLOCK_RATE, CHANNEL_COUNT, SAMPLES_PER_FRAME, BITS_PER_SAMPLE, @@ -187,7 +187,7 @@ static pj_status_t snd_start(unsigned flag) status = pjmedia_snd_open_player(-1, CLOCK_RATE, CHANNEL_COUNT, SAMPLES_PER_FRAME, BITS_PER_SAMPLE, &play_cb, NULL, &strm); - + if (status != PJ_SUCCESS) { app_perror("snd open", status); return status; @@ -210,19 +210,23 @@ static pj_status_t snd_start(unsigned flag) } /* Stop sound */ -static pj_status_t snd_stop() +static pj_status_t snd_stop() { pj_time_val now; pj_status_t status; - + if (strm == NULL) { app_perror("snd not open", PJ_EINVALIDOP); return PJ_EINVALIDOP; } - + + status = pjmedia_snd_stream_stop(strm); + if (status != PJ_SUCCESS) { + app_perror("snd failed to stop", status); + } status = pjmedia_snd_stream_close(strm); strm = NULL; - + pj_gettimeofday(&now); PJ_TIME_VAL_SUB(now, t_start); @@ -234,11 +238,11 @@ static pj_status_t snd_stop() } /* Shutdown application */ -static void app_fini() +static void app_fini() { if (strm) snd_stop(); - + pjmedia_snd_deinit(); pjmedia_delay_buf_destroy(delaybuf); pj_pool_release(pool); @@ -253,56 +257,55 @@ static void app_fini() */ #include <e32base.h> -class ConsoleUI : public CActive +class ConsoleUI : public CActive { public: - ConsoleUI(CActiveSchedulerWait *asw, CConsoleBase *con); + ConsoleUI(CConsoleBase *con); // Run console UI void Run(); // Stop void Stop(); - + protected: // Cancel asynchronous read. void DoCancel(); // Implementation: called when read has completed. void RunL(); - + private: - CActiveSchedulerWait *asw_; CConsoleBase *con_; }; -ConsoleUI::ConsoleUI(CActiveSchedulerWait *asw, CConsoleBase *con) -: CActive(EPriorityHigh), asw_(asw), con_(con) +ConsoleUI::ConsoleUI(CConsoleBase *con) +: CActive(EPriorityUserInput), con_(con) { CActiveScheduler::Add(this); } // Run console UI -void ConsoleUI::Run() +void ConsoleUI::Run() { con_->Read(iStatus); SetActive(); } // Stop console UI -void ConsoleUI::Stop() +void ConsoleUI::Stop() { DoCancel(); } // Cancel asynchronous read. -void ConsoleUI::DoCancel() +void ConsoleUI::DoCancel() { con_->ReadCancel(); } -static void PrintMenu() +static void PrintMenu() { PJ_LOG(3, (THIS_FILE, "\n\n" "Menu:\n" @@ -314,14 +317,15 @@ static void PrintMenu() } // Implementation: called when read has completed. -void ConsoleUI::RunL() +void ConsoleUI::RunL() { TKeyCode kc = con_->KeyCode(); pj_bool_t reschedule = PJ_TRUE; - + switch (kc) { case 'w': - asw_->AsyncStop(); + snd_stop(); + CActiveScheduler::Stop(); reschedule = PJ_FALSE; break; case 'a': @@ -343,30 +347,28 @@ void ConsoleUI::RunL() } PrintMenu(); - + if (reschedule) Run(); } //////////////////////////////////////////////////////////////////////////// -int app_main() +int app_main() { if (app_init() != PJ_SUCCESS) return -1; - + // Run the UI - CActiveSchedulerWait *asw = new CActiveSchedulerWait; - ConsoleUI *con = new ConsoleUI(asw, console); - + ConsoleUI *con = new ConsoleUI(console); + con->Run(); - + PrintMenu(); - asw->Start(); - + CActiveScheduler::Start(); + delete con; - delete asw; - + app_fini(); return 0; } diff --git a/pjsip-apps/src/symsndtest/main_symbian.cpp b/pjsip-apps/src/symsndtest/main_symbian.cpp index bc160bd6..a711f092 100644 --- a/pjsip-apps/src/symsndtest/main_symbian.cpp +++ b/pjsip-apps/src/symsndtest/main_symbian.cpp @@ -29,75 +29,12 @@ CConsoleBase* console; // Needed by APS -TPtrC APP_UID = _L("A000000D"); +TPtrC APP_UID = _L("A000000E"); int app_main(); //////////////////////////////////////////////////////////////////////////// -class MyTask : public CActive -{ -public: - static MyTask *NewL(CActiveSchedulerWait *asw); - ~MyTask(); - void Start(); - -protected: - MyTask(CActiveSchedulerWait *asw); - void ConstructL(); - virtual void RunL(); - virtual void DoCancel(); - -private: - RTimer timer_; - CActiveSchedulerWait *asw_; -}; - -MyTask::MyTask(CActiveSchedulerWait *asw) -: CActive(EPriorityNormal), asw_(asw) -{ -} - -MyTask::~MyTask() -{ - timer_.Close(); -} - -void MyTask::ConstructL() -{ - timer_.CreateLocal(); - CActiveScheduler::Add(this); -} - -MyTask *MyTask::NewL(CActiveSchedulerWait *asw) -{ - MyTask *self = new (ELeave) MyTask(asw); - CleanupStack::PushL(self); - - self->ConstructL(); - - CleanupStack::Pop(self); - return self; -} - -void MyTask::Start() -{ - timer_.After(iStatus, 0); - SetActive(); -} - -void MyTask::RunL() -{ - int rc = app_main(); - asw_->AsyncStop(); -} - -void MyTask::DoCancel() -{ - -} - -//////////////////////////////////////////////////////////////////////////// LOCAL_C void DoStartL() { @@ -105,19 +42,8 @@ LOCAL_C void DoStartL() CleanupStack::PushL(scheduler); CActiveScheduler::Install(scheduler); - CActiveSchedulerWait *asw = new CActiveSchedulerWait; - CleanupStack::PushL(asw); - - MyTask *task = MyTask::NewL(asw); - task->Start(); - - asw->Start(); - - delete task; - - CleanupStack::Pop(asw); - delete asw; - + app_main(); + CActiveScheduler::Install(NULL); CleanupStack::Pop(scheduler); delete scheduler; @@ -142,13 +68,13 @@ GLDEF_C TInt E32Main() TRAPD(startError, DoStartL()); - console->Printf(_L("[press any key to close]\n")); - console->Getch(); - + //console->Printf(_L("[press any key to close]\n")); + //console->Getch(); + delete console; delete cleanup; - CloseSTDLIB(); + CloseSTDLIB(); // Mark end of heap usage, detect memory leaks __UHEAP_MARKEND; |