Changeset 2018 for pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c
- Timestamp:
- Jun 13, 2008 5:01:46 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_media.c
r2004 r2018 23 23 #define THIS_FILE "pjsua_media.c" 24 24 25 #define DEFAULT_RTP_PORT 4000 25 #define DEFAULT_RTP_PORT 4000 26 27 #define NULL_SND_DEV_ID -99 26 28 27 29 #ifndef PJSUA_REQUIRE_CONSECUTIVE_RTCP_PORT … … 424 426 } 425 427 428 /* Timer callback to close sound device */ 429 static void close_snd_timer_cb( pj_timer_heap_t *th, 430 pj_timer_entry *entry) 431 { 432 PJ_UNUSED_ARG(th); 433 434 PJ_LOG(4,(THIS_FILE,"Closing sound device after idle for %d seconds", 435 pjsua_var.media_cfg.snd_auto_close_time)); 436 437 entry->id = PJ_FALSE; 438 439 close_snd_dev(); 440 } 441 426 442 427 443 /* … … 445 461 } 446 462 447 /* Create sound port if none is created yet */ 448 if (pjsua_var.snd_port==NULL && pjsua_var.null_snd==NULL && 449 !pjsua_var.no_snd) 450 { 451 status = pjsua_set_snd_dev(pjsua_var.cap_dev, pjsua_var.play_dev); 452 if (status != PJ_SUCCESS) { 453 pjsua_perror(THIS_FILE, "Error opening sound device", status); 454 return status; 455 } 456 } 463 pj_timer_entry_init(&pjsua_var.snd_idle_timer, PJ_FALSE, NULL, 464 &close_snd_timer_cb); 457 465 458 466 return PJ_SUCCESS; … … 1328 1336 pjsua_conf_port_id sink) 1329 1337 { 1338 /* If sound device idle timer is active, cancel it first. */ 1339 if (pjsua_var.snd_idle_timer.id) { 1340 pjsip_endpt_cancel_timer(pjsua_var.endpt, &pjsua_var.snd_idle_timer); 1341 pjsua_var.snd_idle_timer.id = PJ_FALSE; 1342 } 1343 1344 /* Create sound port if none is instantiated */ 1345 if (pjsua_var.snd_port==NULL && pjsua_var.null_snd==NULL && 1346 !pjsua_var.no_snd) 1347 { 1348 pj_status_t status; 1349 1350 status = pjsua_set_snd_dev(pjsua_var.cap_dev, pjsua_var.play_dev); 1351 if (status != PJ_SUCCESS) { 1352 pjsua_perror(THIS_FILE, "Error opening sound device", status); 1353 return status; 1354 } 1355 } 1356 1330 1357 return pjmedia_conf_connect_port(pjsua_var.mconf, source, sink, 0); 1331 1358 } … … 1338 1365 pjsua_conf_port_id sink) 1339 1366 { 1340 return pjmedia_conf_disconnect_port(pjsua_var.mconf, source, sink); 1367 pj_status_t status; 1368 1369 status = pjmedia_conf_disconnect_port(pjsua_var.mconf, source, sink); 1370 if (status != PJ_SUCCESS) 1371 return status; 1372 1373 /* If no port is connected, sound device must be idle. Activate sound 1374 * device auto-close timer. 1375 */ 1376 if ((pjsua_var.snd_port!=NULL || pjsua_var.null_snd!=NULL) && 1377 pjsua_var.snd_idle_timer.id==PJ_FALSE && 1378 pjmedia_conf_get_connect_count(pjsua_var.mconf) == 0 && 1379 pjsua_var.media_cfg.snd_auto_close_time >= 0) 1380 { 1381 pj_time_val delay; 1382 1383 delay.msec = 0; 1384 delay.sec = pjsua_var.media_cfg.snd_auto_close_time; 1385 1386 pjsua_var.snd_idle_timer.id = PJ_TRUE; 1387 pjsip_endpt_schedule_timer(pjsua_var.endpt, &pjsua_var.snd_idle_timer, 1388 &delay); 1389 } 1390 1391 return status; 1341 1392 } 1342 1393 … … 1844 1895 pjsua_var.null_snd = NULL; 1845 1896 } 1897 1898 if (pjsua_var.snd_pool) 1899 pj_pool_release(pjsua_var.snd_pool); 1900 pjsua_var.snd_pool = NULL; 1846 1901 } 1847 1902 … … 1864 1919 pj_status_t status = -1; 1865 1920 1921 /* Check if NULL sound device is used */ 1922 if (NULL_SND_DEV_ID == capture_dev || NULL_SND_DEV_ID == playback_dev) { 1923 return pjsua_set_null_snd_dev(); 1924 } 1925 1866 1926 /* Close existing sound port */ 1867 1927 close_snd_dev(); 1868 1928 1929 /* Create memory pool for sound device. */ 1930 pjsua_var.snd_pool = pjsua_pool_create("pjsua_snd", 4000, 4000); 1931 PJ_ASSERT_RETURN(pjsua_var.snd_pool, PJ_ENOMEM); 1869 1932 1870 1933 /* Set default clock rate */ … … 1888 1951 /* Create the sound device. Sound port will start immediately. */ 1889 1952 fps = 1000 / pjsua_var.media_cfg.audio_frame_ptime; 1890 status = pjmedia_snd_port_create(pjsua_var. pool, capture_dev,1953 status = pjmedia_snd_port_create(pjsua_var.snd_pool, capture_dev, 1891 1954 playback_dev, 1892 1955 clock_rates[i], … … 1915 1978 } 1916 1979 1917 status = pjmedia_resample_port_create(pjsua_var. pool,1980 status = pjmedia_resample_port_create(pjsua_var.snd_pool, 1918 1981 conf_port, 1919 1982 selected_clock_rate, … … 1949 2012 1950 2013 /* Set AEC */ 1951 pjmedia_snd_port_set_ec( pjsua_var.snd_port, pjsua_var. pool,2014 pjmedia_snd_port_set_ec( pjsua_var.snd_port, pjsua_var.snd_pool, 1952 2015 pjsua_var.media_cfg.ec_tail_len, 1953 2016 pjsua_var.media_cfg.ec_options); … … 2020 2083 close_snd_dev(); 2021 2084 2085 /* Create memory pool for sound device. */ 2086 pjsua_var.snd_pool = pjsua_pool_create("pjsua_snd", 4000, 4000); 2087 PJ_ASSERT_RETURN(pjsua_var.snd_pool, PJ_ENOMEM); 2088 2022 2089 PJ_LOG(4,(THIS_FILE, "Opening null sound device..")); 2023 2090 … … 2029 2096 * a null port. 2030 2097 */ 2031 status = pjmedia_master_port_create(pjsua_var. pool, pjsua_var.null_port,2098 status = pjmedia_master_port_create(pjsua_var.snd_pool, pjsua_var.null_port, 2032 2099 conf_port, 0, &pjsua_var.null_snd); 2033 2100 if (status != PJ_SUCCESS) { … … 2040 2107 status = pjmedia_master_port_start(pjsua_var.null_snd); 2041 2108 PJ_ASSERT_RETURN(status == PJ_SUCCESS, status); 2109 2110 pjsua_var.cap_dev = NULL_SND_DEV_ID; 2111 pjsua_var.play_dev = NULL_SND_DEV_ID; 2042 2112 2043 2113 return PJ_SUCCESS;
Note: See TracChangeset
for help on using the changeset viewer.