Changeset 5717 for pjproject/trunk/pjsip/src/pjsua-lib/pjsua_aud.c
- Timestamp:
- Dec 19, 2017 1:45:37 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_aud.c
r5713 r5717 2310 2310 } 2311 2311 2312 2313 /* 2314 * Extra sound device 2315 */ 2316 struct pjsua_ext_snd_dev 2317 { 2318 pj_pool_t *pool; 2319 pjmedia_port *splitcomb; 2320 pjmedia_port *rev_port; 2321 pjmedia_snd_port *snd_port; 2322 pjsua_conf_port_id port_id; 2323 }; 2324 2325 2326 /* 2327 * Create an extra sound device and register it to conference bridge. 2328 */ 2329 PJ_DEF(pj_status_t) pjsua_ext_snd_dev_create( pjmedia_snd_port_param *param, 2330 pjsua_ext_snd_dev **p_snd) 2331 { 2332 pjsua_ext_snd_dev *snd = NULL; 2333 pj_pool_t *pool; 2334 pj_status_t status; 2335 2336 PJ_ASSERT_RETURN(param && p_snd, PJ_EINVAL); 2337 2338 pool = pjsua_pool_create("extsnd%p", 512, 512); 2339 if (!pool) 2340 return PJ_ENOMEM; 2341 2342 snd = PJ_POOL_ZALLOC_T(pool, pjsua_ext_snd_dev); 2343 if (!snd) { 2344 pj_pool_release(pool); 2345 return PJ_ENOMEM; 2346 } 2347 2348 snd->pool = pool; 2349 snd->port_id = PJSUA_INVALID_ID; 2350 2351 /* Create mono splitter/combiner */ 2352 status = pjmedia_splitcomb_create( 2353 pool, 2354 param->base.clock_rate, 2355 param->base.channel_count, 2356 param->base.samples_per_frame, 2357 param->base.bits_per_sample, 2358 0, /* options */ 2359 &snd->splitcomb); 2360 if (status != PJ_SUCCESS) 2361 goto on_return; 2362 2363 /* Create reverse channel */ 2364 status = pjmedia_splitcomb_create_rev_channel( 2365 pool, 2366 snd->splitcomb, 2367 0 /* channel #1 */, 2368 0 /* options */, 2369 &snd->rev_port); 2370 if (status != PJ_SUCCESS) 2371 goto on_return; 2372 2373 /* And register it to conference bridge */ 2374 status = pjsua_conf_add_port(pool, snd->rev_port, &snd->port_id); 2375 if (status != PJ_SUCCESS) 2376 goto on_return; 2377 2378 /* Create sound device */ 2379 status = pjmedia_snd_port_create2(pool, param, &snd->snd_port); 2380 if (status != PJ_SUCCESS) 2381 goto on_return; 2382 2383 /* Connect the splitter to the sound device */ 2384 status = pjmedia_snd_port_connect(snd->snd_port, snd->splitcomb); 2385 if (status != PJ_SUCCESS) 2386 goto on_return; 2387 2388 /* Finally */ 2389 *p_snd = snd; 2390 PJ_LOG(4,(THIS_FILE, "Extra sound device created")); 2391 2392 on_return: 2393 if (status != PJ_SUCCESS) { 2394 PJ_LOG(3,(THIS_FILE, "Failed creating extra sound device")); 2395 pjsua_ext_snd_dev_destroy(snd); 2396 } 2397 2398 return status; 2399 } 2400 2401 2402 /* 2403 * Destroy an extra sound device and unregister it from conference bridge. 2404 */ 2405 PJ_DEF(pj_status_t) pjsua_ext_snd_dev_destroy(pjsua_ext_snd_dev *snd) 2406 { 2407 PJ_ASSERT_RETURN(snd, PJ_EINVAL); 2408 2409 /* Unregister from the conference bridge */ 2410 if (snd->port_id != PJSUA_INVALID_ID) { 2411 pjsua_conf_remove_port(snd->port_id); 2412 snd->port_id = PJSUA_INVALID_ID; 2413 } 2414 2415 /* Destroy all components */ 2416 if (snd->snd_port) { 2417 pjmedia_snd_port_disconnect(snd->snd_port); 2418 pjmedia_snd_port_destroy(snd->snd_port); 2419 snd->snd_port = NULL; 2420 } 2421 if (snd->rev_port) { 2422 pjmedia_port_destroy(snd->rev_port); 2423 snd->rev_port = NULL; 2424 } 2425 if (snd->splitcomb) { 2426 pjmedia_port_destroy(snd->splitcomb); 2427 snd->splitcomb = NULL; 2428 } 2429 2430 /* Finally */ 2431 pj_pool_safe_release(&snd->pool); 2432 2433 PJ_LOG(4,(THIS_FILE, "Extra sound device destroyed")); 2434 2435 return PJ_SUCCESS; 2436 } 2437 2438 2439 /* 2440 * Get sound port instance of an extra sound device. 2441 */ 2442 PJ_DEF(pjmedia_snd_port*) pjsua_ext_snd_dev_get_snd_port( 2443 pjsua_ext_snd_dev *snd) 2444 { 2445 PJ_ASSERT_RETURN(snd, NULL); 2446 return snd->snd_port; 2447 } 2448 2449 /* 2450 * Get conference port ID of an extra sound device. 2451 */ 2452 PJ_DEF(pjsua_conf_port_id) pjsua_ext_snd_dev_get_conf_port( 2453 pjsua_ext_snd_dev *snd) 2454 { 2455 PJ_ASSERT_RETURN(snd, PJSUA_INVALID_ID); 2456 return snd->port_id; 2457 } 2458 2459 2312 2460 #endif /* PJSUA_MEDIA_HAS_PJMEDIA */
Note: See TracChangeset
for help on using the changeset viewer.