Changeset 2506 for pjproject/trunk/pjsip-apps/src/symsndtest/app_main.cpp
- Timestamp:
- Mar 12, 2009 6:11:37 PM (16 years ago)
- Location:
- pjproject/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk
-
Property
svn:mergeinfo
set to
False
/pjproject/branches/projects/aps-direct merged eligible
-
Property
svn:mergeinfo
set to
False
-
pjproject/trunk/pjsip-apps/src/symsndtest/app_main.cpp
r2394 r2506 50 50 51 51 PJ_UNUSED_ARG(level); 52 52 53 53 pj_ansi_to_unicode(buf, len, buf16, PJ_ARRAY_SIZE(buf16)); 54 54 … … 58 58 59 59 /* perror util */ 60 static void app_perror(const char *title, pj_status_t status) 61 { 62 char errmsg[PJ_ERR_MSG_SIZE]; 60 static void app_perror(const char *title, pj_status_t status) 61 { 62 char errmsg[PJ_ERR_MSG_SIZE]; 63 63 pj_strerror(status, errmsg, sizeof(errmsg)); 64 64 PJ_LOG(1,(THIS_FILE, "Error: %s: %s", title, errmsg)); … … 66 66 67 67 /* Application init */ 68 static pj_status_t app_init() 68 static pj_status_t app_init() 69 69 { 70 70 unsigned i, count; 71 71 pj_status_t status; 72 72 73 73 /* Redirect log */ 74 74 pj_log_set_log_func((void (*)(int,const char*,int)) &log_writer); 75 75 pj_log_set_decor(PJ_LOG_HAS_NEWLINE); 76 76 pj_log_set_level(3); 77 77 78 78 /* Init pjlib */ 79 79 status = pj_init(); … … 84 84 85 85 pj_caching_pool_init(&cp, NULL, 0); 86 86 87 87 /* Init sound subsystem */ 88 88 status = pjmedia_snd_init(&cp.factory); … … 93 93 return status; 94 94 } 95 95 96 96 count = pjmedia_snd_get_dev_count(); 97 97 PJ_LOG(3,(THIS_FILE, "Device count: %d", count)); 98 98 for (i=0; i<count; ++i) { 99 99 const pjmedia_snd_dev_info *info; 100 100 101 101 info = pjmedia_snd_get_dev_info(i); 102 102 PJ_LOG(3, (THIS_FILE, "%d: %s %d/%d %dHz", 103 103 i, info->name, info->input_count, info->output_count, 104 info->default_samples_per_sec)); 104 info->default_samples_per_sec)); 105 105 } 106 106 … … 115 115 116 116 /* Init delay buffer */ 117 status = pjmedia_delay_buf_create(pool, THIS_FILE, CLOCK_RATE, 118 SAMPLES_PER_FRAME, CHANNEL_COUNT, 117 status = pjmedia_delay_buf_create(pool, THIS_FILE, CLOCK_RATE, 118 SAMPLES_PER_FRAME, CHANNEL_COUNT, 119 119 0, 0, &delaybuf); 120 120 if (status != PJ_SUCCESS) { … … 124 124 //return status; 125 125 } 126 126 127 127 return PJ_SUCCESS; 128 128 } … … 130 130 131 131 /* Sound capture callback */ 132 static pj_status_t rec_cb(void *user_data, 132 static pj_status_t rec_cb(void *user_data, 133 133 pj_uint32_t timestamp, 134 134 void *input, 135 unsigned size) 135 unsigned size) 136 136 { 137 137 PJ_UNUSED_ARG(user_data); … … 154 154 pj_uint32_t timestamp, 155 155 void *output, 156 unsigned size) 156 unsigned size) 157 157 { 158 158 PJ_UNUSED_ARG(user_data); 159 159 PJ_UNUSED_ARG(timestamp); 160 160 PJ_UNUSED_ARG(size); 161 161 162 162 pjmedia_delay_buf_get(delaybuf, (pj_int16_t*)output); 163 163 164 164 ++play_cnt; 165 return PJ_SUCCESS; 165 return PJ_SUCCESS; 166 166 } 167 167 168 168 /* Start sound */ 169 static pj_status_t snd_start(unsigned flag) 169 static pj_status_t snd_start(unsigned flag) 170 170 { 171 171 pj_status_t status; 172 172 173 173 if (strm != NULL) { 174 174 app_perror("snd already open", PJ_EINVALIDOP); 175 175 return PJ_EINVALIDOP; 176 176 } 177 177 178 178 if (flag==PJMEDIA_DIR_CAPTURE_PLAYBACK) 179 179 status = pjmedia_snd_open(-1, -1, CLOCK_RATE, CHANNEL_COUNT, … … 188 188 SAMPLES_PER_FRAME, BITS_PER_SAMPLE, 189 189 &play_cb, NULL, &strm); 190 190 191 191 if (status != PJ_SUCCESS) { 192 192 app_perror("snd open", status); … … 211 211 212 212 /* Stop sound */ 213 static pj_status_t snd_stop() 213 static pj_status_t snd_stop() 214 214 { 215 215 pj_time_val now; 216 216 pj_status_t status; 217 217 218 218 if (strm == NULL) { 219 219 app_perror("snd not open", PJ_EINVALIDOP); 220 220 return PJ_EINVALIDOP; 221 221 } 222 222 223 status = pjmedia_snd_stream_stop(strm); 224 if (status != PJ_SUCCESS) { 225 app_perror("snd failed to stop", status); 226 } 223 227 status = pjmedia_snd_stream_close(strm); 224 228 strm = NULL; 225 229 226 230 pj_gettimeofday(&now); 227 231 PJ_TIME_VAL_SUB(now, t_start); … … 235 239 236 240 /* Shutdown application */ 237 static void app_fini() 241 static void app_fini() 238 242 { 239 243 if (strm) 240 244 snd_stop(); 241 245 242 246 pjmedia_snd_deinit(); 243 247 pjmedia_delay_buf_destroy(delaybuf); … … 254 258 #include <e32base.h> 255 259 256 class ConsoleUI : public CActive 260 class ConsoleUI : public CActive 257 261 { 258 262 public: 259 ConsoleUI(C ActiveSchedulerWait *asw, CConsoleBase *con);263 ConsoleUI(CConsoleBase *con); 260 264 261 265 // Run console UI … … 264 268 // Stop 265 269 void Stop(); 266 270 267 271 protected: 268 272 // Cancel asynchronous read. … … 271 275 // Implementation: called when read has completed. 272 276 void RunL(); 273 277 274 278 private: 275 CActiveSchedulerWait *asw_;276 279 CConsoleBase *con_; 277 280 }; 278 281 279 282 280 ConsoleUI::ConsoleUI(C ActiveSchedulerWait *asw, CConsoleBase *con)281 : CActive(EPriority High), asw_(asw), con_(con)283 ConsoleUI::ConsoleUI(CConsoleBase *con) 284 : CActive(EPriorityUserInput), con_(con) 282 285 { 283 286 CActiveScheduler::Add(this); … … 285 288 286 289 // Run console UI 287 void ConsoleUI::Run() 290 void ConsoleUI::Run() 288 291 { 289 292 con_->Read(iStatus); … … 292 295 293 296 // Stop console UI 294 void ConsoleUI::Stop() 297 void ConsoleUI::Stop() 295 298 { 296 299 DoCancel(); … … 298 301 299 302 // Cancel asynchronous read. 300 void ConsoleUI::DoCancel() 303 void ConsoleUI::DoCancel() 301 304 { 302 305 con_->ReadCancel(); 303 306 } 304 307 305 static void PrintMenu() 308 static void PrintMenu() 306 309 { 307 310 PJ_LOG(3, (THIS_FILE, "\n\n" … … 315 318 316 319 // Implementation: called when read has completed. 317 void ConsoleUI::RunL() 320 void ConsoleUI::RunL() 318 321 { 319 322 TKeyCode kc = con_->KeyCode(); 320 323 pj_bool_t reschedule = PJ_TRUE; 321 324 322 325 switch (kc) { 323 326 case 'w': 324 asw_->AsyncStop(); 327 snd_stop(); 328 CActiveScheduler::Stop(); 325 329 reschedule = PJ_FALSE; 326 330 break; … … 344 348 345 349 PrintMenu(); 346 350 347 351 if (reschedule) 348 352 Run(); … … 351 355 352 356 //////////////////////////////////////////////////////////////////////////// 353 int app_main() 357 int app_main() 354 358 { 355 359 if (app_init() != PJ_SUCCESS) 356 360 return -1; 357 361 358 362 // Run the UI 359 CActiveSchedulerWait *asw = new CActiveSchedulerWait; 360 ConsoleUI *con = new ConsoleUI(asw, console); 361 363 ConsoleUI *con = new ConsoleUI(console); 364 362 365 con->Run(); 363 366 364 367 PrintMenu(); 365 asw->Start();366 368 CActiveScheduler::Start(); 369 367 370 delete con; 368 delete asw; 369 371 370 372 app_fini(); 371 373 return 0;
Note: See TracChangeset
for help on using the changeset viewer.