- Timestamp:
- Feb 21, 2009 2:21:59 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/aps-direct/pjsip/src/pjsua-lib/pjsua_media.c
r2462 r2468 1515 1515 * Open sound device with extended setting. 1516 1516 */ 1517 static pj_status_t open_snd_dev_ext( int capture_dev, 1518 int playback_dev, 1519 unsigned clock_rate, 1520 unsigned channel_count, 1521 unsigned samples_per_frame, 1522 const pjmedia_snd_setting *setting) 1517 static pj_status_t open_snd_dev_ext(pjmedia_aud_param *param) 1523 1518 { 1524 1519 pjmedia_port *conf_port; 1525 1520 pj_status_t status; 1526 1521 1527 PJ_ASSERT_RETURN( setting, PJ_EINVAL);1522 PJ_ASSERT_RETURN(param, PJ_EINVAL); 1528 1523 1529 1524 /* Check if NULL sound device is used */ 1530 if (NULL_SND_DEV_ID == capture_dev || NULL_SND_DEV_ID == playback_dev) {1525 if (NULL_SND_DEV_ID==param->rec_id || NULL_SND_DEV_ID==param->play_id) { 1531 1526 return pjsua_set_null_snd_dev(); 1532 1527 } … … 1545 1540 1546 1541 PJ_LOG(4,(THIS_FILE, "Opening sound device @%d/%d/%s", 1547 clock_rate,channel_count,1548 ( setting->format.id==PJMEDIA_FORMAT_L16?"raw":"encoded")));1542 param->clock_rate, param->channel_count, 1543 (param->ext_fmt.id==PJMEDIA_FORMAT_L16?"pcm":"encoded"))); 1549 1544 1550 1545 status = pjmedia_snd_port_create2( pjsua_var.snd_pool, 1551 PJMEDIA_DIR_CAPTURE_PLAYBACK, 1552 capture_dev, 1553 playback_dev, 1554 clock_rate, 1555 channel_count, 1556 samples_per_frame, 1557 16, 1558 setting, 1559 &pjsua_var.snd_port); 1546 param, &pjsua_var.snd_port); 1560 1547 1561 1548 /* Update port 0 info when sound dev opened successfully. */ 1562 1549 if (status == PJ_SUCCESS) { 1563 conf_port->info.format = setting->format; 1564 conf_port->info.clock_rate = clock_rate; 1565 conf_port->info.samples_per_frame = samples_per_frame; 1566 conf_port->info.channel_count = channel_count; 1550 pj_memcpy(&conf_port->info.format, ¶m->ext_fmt, 1551 sizeof(conf_port->info.format)); 1552 conf_port->info.clock_rate = param->clock_rate; 1553 conf_port->info.samples_per_frame = param->samples_per_frame; 1554 conf_port->info.channel_count = param->channel_count; 1567 1555 conf_port->info.bits_per_sample = 16; 1568 1556 } else { … … 1583 1571 1584 1572 /* Save the device IDs */ 1585 pjsua_var.cap_dev = capture_dev;1586 pjsua_var.play_dev = p layback_dev;1573 pjsua_var.cap_dev = param->rec_id; 1574 pjsua_var.play_dev = param->play_id; 1587 1575 1588 1576 /* Update sound device name. */ 1589 do{1590 const pjmedia_snd_dev_info *play_info;1591 pjmedia_ snd_stream *strm;1592 pjmedia_ snd_stream_infosi;1577 { 1578 pjmedia_aud_dev_info play_info; 1579 pjmedia_aud_stream *strm; 1580 pjmedia_aud_param si; 1593 1581 pj_str_t tmp; 1594 1582 1595 1583 strm = pjmedia_snd_port_get_snd_stream(pjsua_var.snd_port); 1596 pjmedia_ snd_stream_get_info(strm, &si);1597 play_info = pjmedia_snd_get_dev_info(si.rec_id);1598 1599 pjmedia_conf_set_port0_name(pjsua_var.mconf,1600 pj_cstr(&tmp, play_info->name));1601 } while(0);1584 pjmedia_aud_stream_get_param(strm, &si); 1585 if (pjmedia_aud_dev_get_info(si.play_id, &play_info)==PJ_SUCCESS) { 1586 pjmedia_conf_set_port0_name(pjsua_var.mconf, 1587 pj_cstr(&tmp, play_info.name)); 1588 } 1589 }; 1602 1590 1603 1591 return PJ_SUCCESS; … … 1612 1600 /* Close sound device */ 1613 1601 if (pjsua_var.snd_port) { 1614 pjmedia_ snd_dev_info cap_info, play_info;1615 pjmedia_ snd_stream *strm;1616 pjmedia_ snd_stream_info si;1602 pjmedia_aud_dev_info cap_info, play_info; 1603 pjmedia_aud_stream *strm; 1604 pjmedia_aud_param param; 1617 1605 1618 1606 strm = pjmedia_snd_port_get_snd_stream(pjsua_var.snd_port); 1619 pjmedia_snd_stream_get_info(strm, &si); 1620 cap_info = *(pjmedia_snd_get_dev_info(si.rec_id)); 1621 play_info = *(pjmedia_snd_get_dev_info(si.play_id)); 1607 pjmedia_aud_stream_get_param(strm, ¶m); 1608 1609 if (pjmedia_aud_dev_get_info(param.rec_id, &cap_info) != PJ_SUCCESS) 1610 cap_info.name[0] = '\0'; 1611 if (pjmedia_aud_dev_get_info(param.play_id, &play_info) != PJ_SUCCESS) 1612 play_info.name[0] = '\0'; 1622 1613 1623 1614 PJ_LOG(4,(THIS_FILE, "Closing %s sound playback device and " … … 1797 1788 1798 1789 if (need_reopen) { 1799 pjmedia_snd_setting setting; 1800 1801 pj_bzero(&setting, sizeof(setting)); 1802 setting.format = peer_info.format; 1803 setting.plc = PJ_FALSE; 1804 setting.route = PJMEDIA_SND_ROUTE_DEFAULT; 1790 pjmedia_aud_param param; 1791 1792 status = pjmedia_aud_dev_default_param(pjsua_var.cap_dev, ¶m); 1793 if (status != PJ_SUCCESS) { 1794 pjsua_perror(THIS_FILE, "Error retrieving default audio " 1795 "device parameters", status); 1796 return status; 1797 } 1798 1799 param.dir = PJMEDIA_DIR_CAPTURE_PLAYBACK; 1800 param.rec_id = pjsua_var.cap_dev; 1801 param.play_id = pjsua_var.play_dev; 1802 param.clock_rate = peer_info.clock_rate; 1803 param.samples_per_frame = peer_info.samples_per_frame; 1804 param.channel_count = peer_info.channel_count; 1805 param.bits_per_sample = peer_info.bits_per_sample; 1806 /* Latency setting */ 1807 param.flags |= (PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY | 1808 PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY); 1809 param.input_latency_ms = pjsua_var.media_cfg.snd_rec_latency; 1810 param.output_latency_ms = pjsua_var.media_cfg.snd_play_latency; 1811 /* EC settings */ 1812 if (pjsua_var.media_cfg.ec_tail_len) { 1813 param.flags |= (PJMEDIA_AUD_DEV_CAP_EC | PJMEDIA_AUD_DEV_CAP_EC_TAIL); 1814 param.ec_enabled = PJ_TRUE; 1815 param.ec_tail_ms = pjsua_var.media_cfg.ec_tail_len; 1816 } else { 1817 param.flags &= ~(PJMEDIA_AUD_DEV_CAP_EC | PJMEDIA_AUD_DEV_CAP_EC_TAIL); 1818 } 1819 /* Format */ 1820 param.flags |= (PJMEDIA_AUD_DEV_CAP_EXT_FORMAT | 1821 PJMEDIA_AUD_DEV_CAP_OUTPUT_ROUTE); 1822 param.ext_fmt = peer_info.format; 1823 //param.plc = PJ_FALSE; 1824 param.out_route = PJMEDIA_AUD_DEV_ROUTE_DEFAULT; 1805 1825 1806 status = open_snd_dev_ext(pjsua_var.cap_dev, pjsua_var.play_dev, 1807 peer_info.clock_rate, 1808 peer_info.channel_count, 1809 peer_info.samples_per_frame, 1810 &setting); 1826 status = open_snd_dev_ext(¶m); 1811 1827 if (status != PJ_SUCCESS) { 1812 1828 pjsua_perror(THIS_FILE, "Error opening sound device", status); … … 2307 2323 * Enum sound devices. 2308 2324 */ 2325 #if PJMEDIA_AUDIO_API==PJMEDIA_AUDIO_API_NEW_ONLY 2326 PJ_DEF(pj_status_t) pjsua_enum_snd_devs( pjmedia_aud_dev_info info[], 2327 unsigned *count) 2328 { 2329 unsigned i, dev_count; 2330 2331 dev_count = pjmedia_aud_dev_count(); 2332 2333 if (dev_count > *count) dev_count = *count; 2334 2335 for (i=0; i<dev_count; ++i) { 2336 pj_status_t status; 2337 2338 status = pjmedia_aud_dev_get_info(i, &info[i]); 2339 if (status != PJ_SUCCESS) 2340 return status; 2341 } 2342 2343 *count = dev_count; 2344 2345 return PJ_SUCCESS; 2346 } 2347 #else /* PJMEDIA_AUDIO_API */ 2309 2348 PJ_DEF(pj_status_t) pjsua_enum_snd_devs( pjmedia_snd_dev_info info[], 2310 2349 unsigned *count) … … 2312 2351 unsigned i, dev_count; 2313 2352 2314 dev_count = pjmedia_ snd_get_dev_count();2353 dev_count = pjmedia_aud_dev_count(); 2315 2354 2316 2355 if (dev_count > *count) dev_count = *count; 2356 pj_bzero(info, dev_count * sizeof(pjmedia_snd_dev_info)); 2317 2357 2318 2358 for (i=0; i<dev_count; ++i) { 2319 const pjmedia_snd_dev_info *ci; 2320 2321 ci = pjmedia_snd_get_dev_info(i); 2322 pj_memcpy(&info[i], ci, sizeof(*ci)); 2359 pjmedia_aud_dev_info ai; 2360 pj_status_t status; 2361 2362 status = pjmedia_aud_dev_get_info(i, &ai); 2363 if (status != PJ_SUCCESS) 2364 return status; 2365 2366 strncpy(info[i].name, ai.name, sizeof(info[i].name)); 2367 info[i].name[sizeof(info[i].name)-1] = '\0'; 2368 info[i].input_count = ai.input_count; 2369 info[i].output_count = ai.output_count; 2370 info[i].default_samples_per_sec = ai.default_samples_per_sec; 2323 2371 } 2324 2372 … … 2327 2375 return PJ_SUCCESS; 2328 2376 } 2377 #endif 2378 2379 2329 2380 /* 2330 2381 * Select or change sound device. Application may call this function at … … 2335 2386 { 2336 2387 pjmedia_port *conf_port; 2337 const pjmedia_snd_dev_info *play_info; 2388 pjmedia_aud_dev_info play_info; 2389 pjmedia_aud_param param; 2338 2390 unsigned clock_rates[] = {0, 44100, 48000, 32000, 16000, 8000}; 2339 2391 unsigned selected_clock_rate = 0; 2340 2392 unsigned i; 2341 pjmedia_snd_stream *strm; 2342 pjmedia_snd_stream_info si; 2393 pjmedia_aud_stream *strm; 2343 2394 pj_str_t tmp; 2344 2395 pj_status_t status = -1; … … 2353 2404 2354 2405 /* Create memory pool for sound device. */ 2355 pjsua_var.snd_pool = pjsua_pool_create("pjsua_snd", 4000, 4000);2406 pjsua_var.snd_pool = pjsua_pool_create("pjsua_snd", 1000, 1000); 2356 2407 PJ_ASSERT_RETURN(pjsua_var.snd_pool, PJ_ENOMEM); 2357 2408 … … 2365 2416 pj_assert(conf_port != NULL); 2366 2417 2418 /* Create default parameters for the device */ 2419 status = pjmedia_aud_dev_default_param(capture_dev, ¶m); 2420 if (status != PJ_SUCCESS) { 2421 return status; 2422 } 2423 param.dir = PJMEDIA_DIR_CAPTURE_PLAYBACK; 2424 param.rec_id = capture_dev; 2425 param.play_id = playback_dev; 2426 param.channel_count = pjsua_var.media_cfg.channel_count; 2427 /* Latency settings */ 2428 param.flags |= (PJMEDIA_AUD_DEV_CAP_INPUT_LATENCY | 2429 PJMEDIA_AUD_DEV_CAP_OUTPUT_LATENCY); 2430 param.input_latency_ms = pjsua_var.media_cfg.snd_rec_latency; 2431 param.output_latency_ms = pjsua_var.media_cfg.snd_play_latency; 2432 /* EC settings */ 2433 if (pjsua_var.media_cfg.ec_tail_len) { 2434 param.flags |= (PJMEDIA_AUD_DEV_CAP_EC | PJMEDIA_AUD_DEV_CAP_EC_TAIL); 2435 param.ec_enabled = PJ_TRUE; 2436 param.ec_tail_ms = pjsua_var.media_cfg.ec_tail_len; 2437 } else { 2438 param.flags &= ~(PJMEDIA_AUD_DEV_CAP_EC | PJMEDIA_AUD_DEV_CAP_EC_TAIL); 2439 } 2440 2367 2441 /* Attempts to open the sound device with different clock rates */ 2368 2442 for (i=0; i<PJ_ARRAY_SIZE(clock_rates); ++i) { 2369 2443 char errmsg[PJ_ERR_MSG_SIZE]; 2370 unsigned samples_per_frame;2371 2444 2372 2445 PJ_LOG(4,(THIS_FILE, … … 2374 2447 "@%d Hz", clock_rates[i])); 2375 2448 2376 samples_per_frame = clock_rates[i] * 2377 pjsua_var.media_cfg.audio_frame_ptime * 2378 pjsua_var.media_cfg.channel_count / 1000; 2449 param.clock_rate = clock_rates[i]; 2450 param.samples_per_frame = clock_rates[i] * 2451 pjsua_var.media_cfg.audio_frame_ptime * 2452 pjsua_var.media_cfg.channel_count / 1000; 2379 2453 2380 2454 /* Create the sound device. Sound port will start immediately. */ 2381 status = pjmedia_snd_port_create(pjsua_var.snd_pool, capture_dev, 2382 playback_dev, 2383 clock_rates[i], 2384 pjsua_var.media_cfg.channel_count, 2385 samples_per_frame, 2386 16, 0, &pjsua_var.snd_port); 2455 status = pjmedia_snd_port_create2(pjsua_var.snd_pool, ¶m, 2456 &pjsua_var.snd_port); 2387 2457 2388 2458 if (status == PJ_SUCCESS) { … … 2438 2508 } 2439 2509 2440 /* Set AEC */2441 pjmedia_snd_port_set_ec( pjsua_var.snd_port, pjsua_var.snd_pool,2442 pjsua_var.media_cfg.ec_tail_len,2443 pjsua_var.media_cfg.ec_options);2444 2445 2510 /* Connect sound port to the bridge */ 2446 2511 status = pjmedia_snd_port_connect(pjsua_var.snd_port, … … 2460 2525 /* Update sound device name. */ 2461 2526 strm = pjmedia_snd_port_get_snd_stream(pjsua_var.snd_port); 2462 pjmedia_ snd_stream_get_info(strm, &si);2463 p lay_info = pjmedia_snd_get_dev_info(si.rec_id);2464 2465 if ( si.clock_rate != pjsua_var.media_cfg.clock_rate) {2527 pjmedia_aud_stream_get_param(strm, ¶m); 2528 pjmedia_aud_dev_get_info(param.play_id, &play_info); 2529 2530 if (param.clock_rate != pjsua_var.media_cfg.clock_rate) { 2466 2531 char tmp_buf[128]; 2467 2532 int tmp_buf_len = sizeof(tmp_buf); 2468 2533 2469 2534 tmp_buf_len = pj_ansi_snprintf(tmp_buf, sizeof(tmp_buf)-1, "%s (%dKHz)", 2470 play_info ->name, si.clock_rate/1000);2535 play_info.name, param.clock_rate/1000); 2471 2536 pj_strset(&tmp, tmp_buf, tmp_buf_len); 2472 2537 pjmedia_conf_set_port0_name(pjsua_var.mconf, &tmp); 2473 2538 } else { 2474 2539 pjmedia_conf_set_port0_name(pjsua_var.mconf, 2475 pj_cstr(&tmp, play_info ->name));2540 pj_cstr(&tmp, play_info.name)); 2476 2541 } 2477 2542 … … 2580 2645 } 2581 2646 2582 /*2583 * Header for specific Symbian APS audio routing.2584 */2585 #include <pjmedia/symbian_sound_aps.h>2586 2587 /*2588 * Set sound device route.2589 */2590 PJ_DEF(pj_status_t) pjsua_set_snd_route(pjmedia_snd_route route)2591 {2592 #if PJMEDIA_SOUND_IMPLEMENTATION == PJMEDIA_SOUND_SYMB_APS_SOUND2593 pjmedia_snd_stream *strm;2594 2595 if (!pjsua_var.snd_port)2596 return PJ_ENOTFOUND;2597 2598 strm = pjmedia_snd_port_get_snd_stream(pjsua_var.snd_port);2599 return pjmedia_snd_aps_set_route(strm, route);2600 #else2601 PJ_UNUSED_ARG(route);2602 return PJ_ENOTSUP;2603 #endif2604 }2605 2647 2606 2648 /*****************************************************************************
Note: See TracChangeset
for help on using the changeset viewer.