summaryrefslogtreecommitdiff
path: root/pjsip-apps/src/symsndtest/app_main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'pjsip-apps/src/symsndtest/app_main.cpp')
-rw-r--r--pjsip-apps/src/symsndtest/app_main.cpp110
1 files changed, 56 insertions, 54 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;
}