| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include <pjmedia-audiodev/audiodev.h> |
| 20 |
#include <pjmedia-audiodev/audiotest.h> |
| 21 |
#include <pjmedia.h> |
| 22 |
#include <pjlib.h> |
| 23 |
#include <pjlib-util.h> |
| 24 |
|
| 25 |
#define THIS_FILE "auddemo.c" |
| 26 |
#define MAX_DEVICES 64 |
| 27 |
#define WAV_FILE "auddemo.wav" |
| 28 |
|
| 29 |
|
| 30 |
static unsigned dev_count; |
| 31 |
static unsigned playback_lat = PJMEDIA_SND_DEFAULT_PLAY_LATENCY; |
| 32 |
static unsigned capture_lat = PJMEDIA_SND_DEFAULT_REC_LATENCY; |
| 33 |
|
| 34 |
static void app_perror(const char *title, pj_status_t status) |
| 35 |
{ |
| 36 |
char errmsg[PJ_ERR_MSG_SIZE]; |
| 37 |
|
| 38 |
pj_strerror(status, errmsg, sizeof(errmsg)); |
| 39 |
printf( "%s: %s (err=%d)\n", |
| 40 |
title, errmsg, status); |
| 41 |
} |
| 42 |
|
| 43 |
static void list_devices(void) |
| 44 |
{ |
| 45 |
unsigned i; |
| 46 |
pj_status_t status; |
| 47 |
|
| 48 |
dev_count = pjmedia_aud_dev_count(); |
| 49 |
if (dev_count == 0) { |
| 50 |
PJ_LOG(3,(THIS_FILE, "No devices found")); |
| 51 |
return; |
| 52 |
} |
| 53 |
|
| 54 |
PJ_LOG(3,(THIS_FILE, "Found %d devices:", dev_count)); |
| 55 |
|
| 56 |
for (i=0; i<dev_count; ++i) { |
| 57 |
pjmedia_aud_dev_info info; |
| 58 |
|
| 59 |
status = pjmedia_aud_dev_get_info(i, &info); |
| 60 |
if (status != PJ_SUCCESS) |
| 61 |
continue; |
| 62 |
|
| 63 |
PJ_LOG(3,(THIS_FILE," %2d: %s [%s] (%d/%d)", |
| 64 |
i, info.driver, info.name, info.input_count, info.output_count)); |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
static const char *decode_caps(unsigned caps) |
| 69 |
{ |
| 70 |
static char text[200]; |
| 71 |
unsigned i; |
| 72 |
|
| 73 |
text[0] = '\0'; |
| 74 |
|
| 75 |
for (i=0; i<31; ++i) { |
| 76 |
if ((1 << i) & caps) { |
| 77 |
const char *capname; |
| 78 |
capname = pjmedia_aud_dev_cap_name((pjmedia_aud_dev_cap)(1 << i), |
| 79 |
NULL); |
| 80 |
pj_ansi_strxcat(text, capname, sizeof(text)); |
| 81 |
pj_ansi_strxcat(text, " ", sizeof(text)); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
return text; |
| 86 |
} |
| 87 |
|
| 88 |
static void show_dev_info(unsigned index) |
| 89 |
{ |
| 90 |
#define H "%-20s" |
| 91 |
pjmedia_aud_dev_info info; |
| 92 |
char formats[200]; |
| 93 |
pj_status_t status; |
| 94 |
|
| 95 |
if (index >= dev_count) { |
| 96 |
PJ_LOG(1,(THIS_FILE, "Error: invalid index %u", index)); |
| 97 |
return; |
| 98 |
} |
| 99 |
|
| 100 |
status = pjmedia_aud_dev_get_info(index, &info); |
| 101 |
if (status != PJ_SUCCESS) { |
| 102 |
app_perror("pjmedia_aud_dev_get_info() error", status); |
| 103 |
return; |
| 104 |
} |
| 105 |
|
| 106 |
PJ_LOG(3, (THIS_FILE, "Device at index %u:", index)); |
| 107 |
PJ_LOG(3, (THIS_FILE, "-------------------------")); |
| 108 |
|
| 109 |
PJ_LOG(3, (THIS_FILE, H": %u (0x%x)", "ID", index, index)); |
| 110 |
PJ_LOG(3, (THIS_FILE, H": %s", "Name", info.name)); |
| 111 |
PJ_LOG(3, (THIS_FILE, H": %s", "Driver", info.driver)); |
| 112 |
PJ_LOG(3, (THIS_FILE, H": %u", "Input channels", info.input_count)); |
| 113 |
PJ_LOG(3, (THIS_FILE, H": %u", "Output channels", info.output_count)); |
| 114 |
PJ_LOG(3, (THIS_FILE, H": %s", "Capabilities", decode_caps(info.caps))); |
| 115 |
|
| 116 |
formats[0] = '\0'; |
| 117 |
if (info.caps & PJMEDIA_AUD_DEV_CAP_EXT_FORMAT) { |
| 118 |
unsigned i; |
| 119 |
|
| 120 |
for (i=0; i<info.ext_fmt_cnt; ++i) { |
| 121 |
char bitrate[32]; |
| 122 |
|
| 123 |
switch (info.ext_fmt[i].id) { |
| 124 |
case PJMEDIA_FORMAT_L16: |
| 125 |
pj_ansi_strxcat(formats, "L16/", sizeof(formats)); |
| 126 |
break; |
| 127 |
case PJMEDIA_FORMAT_PCMA: |
| 128 |
pj_ansi_strxcat(formats, "PCMA/", sizeof(formats)); |
| 129 |
break; |
| 130 |
case PJMEDIA_FORMAT_PCMU: |
| 131 |
pj_ansi_strxcat(formats, "PCMU/", sizeof(formats)); |
| 132 |
break; |
| 133 |
case PJMEDIA_FORMAT_AMR: |
| 134 |
pj_ansi_strxcat(formats, "AMR/", sizeof(formats)); |
| 135 |
break; |
| 136 |
case PJMEDIA_FORMAT_G729: |
| 137 |
pj_ansi_strxcat(formats, "G729/", sizeof(formats)); |
| 138 |
break; |
| 139 |
case PJMEDIA_FORMAT_ILBC: |
| 140 |
pj_ansi_strxcat(formats, "ILBC/", sizeof(formats)); |
| 141 |
break; |
| 142 |
default: |
| 143 |
pj_ansi_strxcat(formats, "unknown/", sizeof(formats)); |
| 144 |
break; |
| 145 |
} |
| 146 |
pj_ansi_snprintf(bitrate, sizeof(bitrate), "%u", |
| 147 |
info.ext_fmt[i].det.aud.avg_bps); |
| 148 |
pj_ansi_strxcat(formats, bitrate, sizeof(formats)); |
| 149 |
pj_ansi_strxcat(formats, " ", sizeof(formats)); |
| 150 |
} |
| 151 |
} |
| 152 |
PJ_LOG(3, (THIS_FILE, H": %s", "Extended formats", formats)); |
| 153 |
|
| 154 |
#undef H |
| 155 |
} |
| 156 |
|
| 157 |
static void test_device(pjmedia_dir dir, unsigned rec_id, unsigned play_id, |
| 158 |
unsigned clock_rate, unsigned ptime, |
| 159 |
unsigned chnum) |
| 160 |
{ |
| 161 |
pjmedia_aud_param param; |
| 162 |
pjmedia_aud_test_results result; |
| 163 |
pj_status_t status; |
| 164 |
|
| 165 |
if (dir & PJMEDIA_DIR_CAPTURE) { |
| 166 |
status = pjmedia_aud_dev_default_param(rec_id, ¶m); |
| 167 |
} else { |
| 168 |
status = pjmedia_aud_dev_default_param(play_id, ¶m); |
| 169 |
} |
| 170 |
|
| 171 |
if (status != PJ_SUCCESS) { |
| 172 |
app_perror("pjmedia_aud_dev_default_param()", status); |
| 173 |
return; |
| 174 |
} |
| 175 |
|
| 176 |
param.dir = dir; |
| 177 |
param.rec_id = rec_id; |
| 178 |
param.play_id = play_id; |
| 179 |
param.clock_rate = clock_rate; |
| 180 |
param.channel_count = chnum; |
| 181 |
param.samples_per_frame = clock_rate * chnum * ptime / 1000; |
| 182 |
|
| 183 |
|
| 184 |
param.flags |= (PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY | |
| 185 |
PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY); |
| 186 |
param.input_latency_ms = capture_lat; |
| 187 |
param.output_latency_ms = playback_lat; |
| 188 |
|
| 189 |
PJ_LOG(3,(THIS_FILE, "Performing test..")); |
| 190 |
|
| 191 |
status = pjmedia_aud_test(¶m, &result); |
| 192 |
if (status != PJ_SUCCESS) { |
| 193 |
app_perror("Test has completed with error", status); |
| 194 |
return; |
| 195 |
} |
| 196 |
|
| 197 |
PJ_LOG(3,(THIS_FILE, "Done. Result:")); |
| 198 |
|
| 199 |
if (dir & PJMEDIA_DIR_CAPTURE) { |
| 200 |
if (result.rec.frame_cnt==0) { |
| 201 |
PJ_LOG(1,(THIS_FILE, "Error: no frames captured!")); |
| 202 |
} else { |
| 203 |
PJ_LOG(3,(THIS_FILE, " %-20s: interval (min/max/avg/dev)=%u/%u/%u/%u, burst=%u", |
| 204 |
"Recording result", |
| 205 |
result.rec.min_interval, |
| 206 |
result.rec.max_interval, |
| 207 |
result.rec.avg_interval, |
| 208 |
result.rec.dev_interval, |
| 209 |
result.rec.max_burst)); |
| 210 |
} |
| 211 |
} |
| 212 |
|
| 213 |
if (dir & PJMEDIA_DIR_PLAYBACK) { |
| 214 |
if (result.play.frame_cnt==0) { |
| 215 |
PJ_LOG(1,(THIS_FILE, "Error: no playback!")); |
| 216 |
} else { |
| 217 |
PJ_LOG(3,(THIS_FILE, " %-20s: interval (min/max/avg/dev)=%u/%u/%u/%u, burst=%u", |
| 218 |
"Playback result", |
| 219 |
result.play.min_interval, |
| 220 |
result.play.max_interval, |
| 221 |
result.play.avg_interval, |
| 222 |
result.play.dev_interval, |
| 223 |
result.play.max_burst)); |
| 224 |
} |
| 225 |
} |
| 226 |
|
| 227 |
if (dir==PJMEDIA_DIR_CAPTURE_PLAYBACK) { |
| 228 |
if (result.rec_drift_per_sec == 0) { |
| 229 |
PJ_LOG(3,(THIS_FILE, " No clock drift detected")); |
| 230 |
} else { |
| 231 |
const char *which = result.rec_drift_per_sec>=0 ? "faster" : "slower"; |
| 232 |
unsigned drift = result.rec_drift_per_sec>=0 ? |
| 233 |
result.rec_drift_per_sec : |
| 234 |
-result.rec_drift_per_sec; |
| 235 |
|
| 236 |
PJ_LOG(3,(THIS_FILE, " Clock drifts detected. Capture device " |
| 237 |
"is running %d samples per second %s " |
| 238 |
"than the playback device", |
| 239 |
drift, which)); |
| 240 |
} |
| 241 |
} |
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
static pj_status_t wav_rec_cb(void *user_data, pjmedia_frame *frame) |
| 246 |
{ |
| 247 |
return pjmedia_port_put_frame((pjmedia_port*)user_data, frame); |
| 248 |
} |
| 249 |
|
| 250 |
static void record(unsigned rec_index, const char *filename) |
| 251 |
{ |
| 252 |
pj_pool_t *pool = NULL; |
| 253 |
pjmedia_port *wav = NULL; |
| 254 |
pjmedia_aud_param param; |
| 255 |
pjmedia_aud_stream *strm = NULL; |
| 256 |
char line[10], *dummy; |
| 257 |
pj_status_t status; |
| 258 |
|
| 259 |
if (filename == NULL) |
| 260 |
filename = WAV_FILE; |
| 261 |
|
| 262 |
pool = pj_pool_create(pjmedia_aud_subsys_get_pool_factory(), "wav", |
| 263 |
1000, 1000, NULL); |
| 264 |
|
| 265 |
status = pjmedia_wav_writer_port_create(pool, filename, 16000, |
| 266 |
1, 320, 16, 0, 0, &wav); |
| 267 |
if (status != PJ_SUCCESS) { |
| 268 |
app_perror("Error creating WAV file", status); |
| 269 |
goto on_return; |
| 270 |
} |
| 271 |
|
| 272 |
status = pjmedia_aud_dev_default_param(rec_index, ¶m); |
| 273 |
if (status != PJ_SUCCESS) { |
| 274 |
app_perror("pjmedia_aud_dev_default_param()", status); |
| 275 |
goto on_return; |
| 276 |
} |
| 277 |
|
| 278 |
param.dir = PJMEDIA_DIR_CAPTURE; |
| 279 |
param.clock_rate = PJMEDIA_PIA_SRATE(&wav->info); |
| 280 |
param.samples_per_frame = PJMEDIA_PIA_SPF(&wav->info); |
| 281 |
param.channel_count = PJMEDIA_PIA_CCNT(&wav->info); |
| 282 |
param.bits_per_sample = PJMEDIA_PIA_BITS(&wav->info); |
| 283 |
|
| 284 |
status = pjmedia_aud_stream_create(¶m, &wav_rec_cb, NULL, wav, |
| 285 |
&strm); |
| 286 |
if (status != PJ_SUCCESS) { |
| 287 |
app_perror("Error opening the sound device", status); |
| 288 |
goto on_return; |
| 289 |
} |
| 290 |
|
| 291 |
status = pjmedia_aud_stream_start(strm); |
| 292 |
if (status != PJ_SUCCESS) { |
| 293 |
app_perror("Error starting the sound device", status); |
| 294 |
goto on_return; |
| 295 |
} |
| 296 |
|
| 297 |
PJ_LOG(3,(THIS_FILE, "Recording started, press ENTER to stop")); |
| 298 |
dummy = fgets(line, sizeof(line), stdin); |
| 299 |
PJ_UNUSED_ARG(dummy); |
| 300 |
|
| 301 |
on_return: |
| 302 |
if (strm) { |
| 303 |
pjmedia_aud_stream_stop(strm); |
| 304 |
pjmedia_aud_stream_destroy(strm); |
| 305 |
} |
| 306 |
if (wav) |
| 307 |
pjmedia_port_destroy(wav); |
| 308 |
if (pool) |
| 309 |
pj_pool_release(pool); |
| 310 |
} |
| 311 |
|
| 312 |
|
| 313 |
static pj_status_t wav_play_cb(void *user_data, pjmedia_frame *frame) |
| 314 |
{ |
| 315 |
return pjmedia_port_get_frame((pjmedia_port*)user_data, frame); |
| 316 |
} |
| 317 |
|
| 318 |
|
| 319 |
static void play_file(unsigned play_index, const char *filename) |
| 320 |
{ |
| 321 |
pj_pool_t *pool = NULL; |
| 322 |
pjmedia_port *wav = NULL; |
| 323 |
pjmedia_aud_param param; |
| 324 |
pjmedia_aud_stream *strm = NULL; |
| 325 |
char line[10], *dummy; |
| 326 |
pj_status_t status; |
| 327 |
|
| 328 |
if (filename == NULL) |
| 329 |
filename = WAV_FILE; |
| 330 |
|
| 331 |
pool = pj_pool_create(pjmedia_aud_subsys_get_pool_factory(), "wav", |
| 332 |
1000, 1000, NULL); |
| 333 |
|
| 334 |
status = pjmedia_wav_player_port_create(pool, filename, 20, 0, 0, &wav); |
| 335 |
if (status != PJ_SUCCESS) { |
| 336 |
app_perror("Error opening WAV file", status); |
| 337 |
goto on_return; |
| 338 |
} |
| 339 |
|
| 340 |
status = pjmedia_aud_dev_default_param(play_index, ¶m); |
| 341 |
if (status != PJ_SUCCESS) { |
| 342 |
app_perror("pjmedia_aud_dev_default_param()", status); |
| 343 |
goto on_return; |
| 344 |
} |
| 345 |
|
| 346 |
param.dir = PJMEDIA_DIR_PLAYBACK; |
| 347 |
param.clock_rate = PJMEDIA_PIA_SRATE(&wav->info); |
| 348 |
param.samples_per_frame = PJMEDIA_PIA_SPF(&wav->info); |
| 349 |
param.channel_count = PJMEDIA_PIA_CCNT(&wav->info); |
| 350 |
param.bits_per_sample = PJMEDIA_PIA_BITS(&wav->info); |
| 351 |
|
| 352 |
status = pjmedia_aud_stream_create(¶m, NULL, &wav_play_cb, wav, |
| 353 |
&strm); |
| 354 |
if (status != PJ_SUCCESS) { |
| 355 |
app_perror("Error opening the sound device", status); |
| 356 |
goto on_return; |
| 357 |
} |
| 358 |
|
| 359 |
status = pjmedia_aud_stream_start(strm); |
| 360 |
if (status != PJ_SUCCESS) { |
| 361 |
app_perror("Error starting the sound device", status); |
| 362 |
goto on_return; |
| 363 |
} |
| 364 |
|
| 365 |
PJ_LOG(3,(THIS_FILE, "Playback started, press ENTER to stop")); |
| 366 |
dummy = fgets(line, sizeof(line), stdin); |
| 367 |
PJ_UNUSED_ARG(dummy); |
| 368 |
|
| 369 |
on_return: |
| 370 |
if (strm) { |
| 371 |
pjmedia_aud_stream_stop(strm); |
| 372 |
pjmedia_aud_stream_destroy(strm); |
| 373 |
} |
| 374 |
if (wav) |
| 375 |
pjmedia_port_destroy(wav); |
| 376 |
if (pool) |
| 377 |
pj_pool_release(pool); |
| 378 |
} |
| 379 |
|
| 380 |
|
| 381 |
static void print_menu(void) |
| 382 |
{ |
| 383 |
puts(""); |
| 384 |
puts("Audio demo menu:"); |
| 385 |
puts("-------------------------------"); |
| 386 |
puts(" l List devices"); |
| 387 |
puts(" R Refresh devices"); |
| 388 |
puts(" i ID Show device info for device ID"); |
| 389 |
puts(" t RID PID CR PTIM [CH] Perform test on the device:"); |
| 390 |
puts(" RID: record device ID (-1 for no)"); |
| 391 |
puts(" PID: playback device ID (-1 for no)"); |
| 392 |
puts(" CR: clock rate"); |
| 393 |
puts(" PTIM: ptime in ms"); |
| 394 |
puts(" CH: # of channels"); |
| 395 |
puts(" r RID [FILE] Record capture device RID to WAV file"); |
| 396 |
puts(" p PID [FILE] Playback WAV file to device ID PID"); |
| 397 |
puts(" d [RLAT PLAT] Get/set sound device latencies (in ms):"); |
| 398 |
puts(" Specify no param to get current latencies setting"); |
| 399 |
puts(" RLAT: record latency (-1 for default)"); |
| 400 |
puts(" PLAT: playback latency (-1 for default)"); |
| 401 |
puts(" v Toggle log verbosity"); |
| 402 |
puts(" q Quit"); |
| 403 |
puts(""); |
| 404 |
printf("Enter selection: "); |
| 405 |
fflush(stdout); |
| 406 |
} |
| 407 |
|
| 408 |
int main() |
| 409 |
{ |
| 410 |
pj_caching_pool cp; |
| 411 |
pj_bool_t done = PJ_FALSE; |
| 412 |
pj_status_t status; |
| 413 |
|
| 414 |
|
| 415 |
status = pj_init(); |
| 416 |
PJ_ASSERT_RETURN(status==PJ_SUCCESS, 1); |
| 417 |
|
| 418 |
pj_log_set_decor(PJ_LOG_HAS_NEWLINE); |
| 419 |
|
| 420 |
|
| 421 |
pj_caching_pool_init(&cp, &pj_pool_factory_default_policy, 0); |
| 422 |
|
| 423 |
status = pjmedia_aud_subsys_init(&cp.factory); |
| 424 |
if (status != PJ_SUCCESS) { |
| 425 |
app_perror("pjmedia_aud_subsys_init()", status); |
| 426 |
pj_caching_pool_destroy(&cp); |
| 427 |
pj_shutdown(); |
| 428 |
return 1; |
| 429 |
} |
| 430 |
|
| 431 |
list_devices(); |
| 432 |
|
| 433 |
while (!done) { |
| 434 |
char line[80]; |
| 435 |
|
| 436 |
print_menu(); |
| 437 |
|
| 438 |
if (fgets(line, sizeof(line), stdin)==NULL) |
| 439 |
break; |
| 440 |
|
| 441 |
switch (line[0]) { |
| 442 |
case 'l': |
| 443 |
list_devices(); |
| 444 |
break; |
| 445 |
|
| 446 |
case 'R': |
| 447 |
pjmedia_aud_dev_refresh(); |
| 448 |
puts("Audio device list refreshed."); |
| 449 |
break; |
| 450 |
|
| 451 |
case 'i': |
| 452 |
{ |
| 453 |
unsigned dev_index; |
| 454 |
if (sscanf(line+2, "%u", &dev_index) != 1) { |
| 455 |
puts("error: device ID required"); |
| 456 |
break; |
| 457 |
} |
| 458 |
show_dev_info(dev_index); |
| 459 |
} |
| 460 |
break; |
| 461 |
|
| 462 |
case 't': |
| 463 |
{ |
| 464 |
pjmedia_dir dir; |
| 465 |
int rec_id, play_id; |
| 466 |
unsigned clock_rate, ptime, chnum; |
| 467 |
int cnt; |
| 468 |
|
| 469 |
cnt = sscanf(line+2, "%d %d %u %u %u", &rec_id, &play_id, |
| 470 |
&clock_rate, &ptime, &chnum); |
| 471 |
if (cnt < 4) { |
| 472 |
puts("error: not enough parameters"); |
| 473 |
break; |
| 474 |
} |
| 475 |
if (clock_rate < 8000 || clock_rate > 128000) { |
| 476 |
puts("error: invalid clock rate"); |
| 477 |
break; |
| 478 |
} |
| 479 |
if (ptime < 10 || ptime > 500) { |
| 480 |
puts("error: invalid ptime"); |
| 481 |
break; |
| 482 |
} |
| 483 |
if (cnt==5) { |
| 484 |
if (chnum < 1 || chnum > 4) { |
| 485 |
puts("error: invalid number of channels"); |
| 486 |
break; |
| 487 |
} |
| 488 |
} else { |
| 489 |
chnum = 1; |
| 490 |
} |
| 491 |
|
| 492 |
if (rec_id >= 0 && rec_id < (int)dev_count) { |
| 493 |
if (play_id >= 0 && play_id < (int)dev_count) |
| 494 |
dir = PJMEDIA_DIR_CAPTURE_PLAYBACK; |
| 495 |
else |
| 496 |
dir = PJMEDIA_DIR_CAPTURE; |
| 497 |
} else if (play_id >= 0 && play_id < (int)dev_count) { |
| 498 |
dir = PJMEDIA_DIR_PLAYBACK; |
| 499 |
} else { |
| 500 |
puts("error: at least one valid device index required"); |
| 501 |
break; |
| 502 |
} |
| 503 |
|
| 504 |
test_device(dir, rec_id, play_id, clock_rate, ptime, chnum); |
| 505 |
|
| 506 |
} |
| 507 |
break; |
| 508 |
|
| 509 |
case 'r': |
| 510 |
|
| 511 |
{ |
| 512 |
int index; |
| 513 |
char filename[80]; |
| 514 |
int count; |
| 515 |
|
| 516 |
count = sscanf(line+2, "%d %s", &index, filename); |
| 517 |
if (count==1) |
| 518 |
record(index, NULL); |
| 519 |
else if (count==2) |
| 520 |
record(index, filename); |
| 521 |
else |
| 522 |
puts("error: invalid command syntax"); |
| 523 |
} |
| 524 |
break; |
| 525 |
|
| 526 |
case 'p': |
| 527 |
|
| 528 |
{ |
| 529 |
int index; |
| 530 |
char filename[80]; |
| 531 |
int count; |
| 532 |
|
| 533 |
count = sscanf(line+2, "%d %s", &index, filename); |
| 534 |
if (count==1) |
| 535 |
play_file(index, NULL); |
| 536 |
else if (count==2) |
| 537 |
play_file(index, filename); |
| 538 |
else |
| 539 |
puts("error: invalid command syntax"); |
| 540 |
} |
| 541 |
break; |
| 542 |
|
| 543 |
case 'd': |
| 544 |
|
| 545 |
{ |
| 546 |
int rec_lat, play_lat; |
| 547 |
|
| 548 |
if (sscanf(line+2, "%d %d", &rec_lat, &play_lat) == 2) { |
| 549 |
capture_lat = (unsigned) |
| 550 |
(rec_lat>=0? rec_lat:PJMEDIA_SND_DEFAULT_REC_LATENCY); |
| 551 |
playback_lat = (unsigned) |
| 552 |
(play_lat >= 0? play_lat : PJMEDIA_SND_DEFAULT_PLAY_LATENCY); |
| 553 |
printf("Recording latency=%ums, playback latency=%ums", |
| 554 |
capture_lat, playback_lat); |
| 555 |
} else { |
| 556 |
printf("Current latencies: record=%ums, playback=%ums", |
| 557 |
capture_lat, playback_lat); |
| 558 |
} |
| 559 |
puts(""); |
| 560 |
} |
| 561 |
break; |
| 562 |
|
| 563 |
case 'v': |
| 564 |
if (pj_log_get_level() <= 3) { |
| 565 |
pj_log_set_level(5); |
| 566 |
puts("Logging set to detail"); |
| 567 |
} else { |
| 568 |
pj_log_set_level(3); |
| 569 |
puts("Logging set to quiet"); |
| 570 |
} |
| 571 |
break; |
| 572 |
|
| 573 |
case 'q': |
| 574 |
done = PJ_TRUE; |
| 575 |
break; |
| 576 |
} |
| 577 |
} |
| 578 |
|
| 579 |
pj_caching_pool_destroy(&cp); |
| 580 |
pj_shutdown(); |
| 581 |
return 0; |
| 582 |
} |
| 583 |
|
| 584 |
|