@@ -108,6 +108,7 @@ struct splitcomb
108
108
struct reverse_port
109
109
{
110
110
pjmedia_port base ;
111
+ pj_pool_t * pool ;
111
112
struct splitcomb * parent ;
112
113
unsigned ch_num ;
113
114
@@ -323,7 +324,7 @@ PJ_DEF(pj_status_t) pjmedia_splitcomb_set_channel( pjmedia_port *splitcomb,
323
324
/*
324
325
* Create reverse phase port for the specified channel.
325
326
*/
326
- PJ_DEF (pj_status_t ) pjmedia_splitcomb_create_rev_channel ( pj_pool_t * pool ,
327
+ PJ_DEF (pj_status_t ) pjmedia_splitcomb_create_rev_channel ( pj_pool_t * pool_ ,
327
328
pjmedia_port * splitcomb ,
328
329
unsigned ch_num ,
329
330
unsigned options ,
@@ -336,25 +337,33 @@ PJ_DEF(pj_status_t) pjmedia_splitcomb_create_rev_channel( pj_pool_t *pool,
336
337
unsigned buf_options ;
337
338
const pjmedia_audio_format_detail * sc_afd , * p_afd ;
338
339
pjmedia_port * port ;
340
+ pj_pool_t * pool ;
339
341
pj_status_t status ;
340
342
341
343
/* Sanity check */
342
344
PJ_ASSERT_RETURN (splitcomb , PJ_EINVAL );
343
- PJ_UNUSED_ARG (pool );
344
345
345
346
/* Make sure this is really a splitcomb port */
346
347
PJ_ASSERT_RETURN (sc -> base .info .signature == SIGNATURE , PJ_EINVAL );
347
348
348
349
/* Check the channel number */
349
350
PJ_ASSERT_RETURN (ch_num < PJMEDIA_PIA_CCNT (& sc -> base .info ), PJ_EINVAL );
350
351
352
+ /* Make sure that the channel has not been setup */
353
+ PJ_ASSERT_RETURN (sc -> port_desc [ch_num ].port == NULL , PJ_EINVALIDOP );
354
+
351
355
/* options is unused for now */
352
356
PJ_UNUSED_ARG (options );
353
357
354
358
sc_afd = pjmedia_format_get_audio_format_detail (& splitcomb -> info .fmt , 1 );
355
359
360
+ /* Create own pool */
361
+ pool = pj_pool_create (pool_ -> factory , "sc-revch" , 500 , 500 , NULL );
362
+ PJ_ASSERT_RETURN (pool , PJ_ENOMEM );
363
+
356
364
/* Create the port */
357
- rport = PJ_POOL_ZALLOC_T (sc -> pool , struct reverse_port );
365
+ rport = PJ_POOL_ZALLOC_T (pool , struct reverse_port );
366
+ rport -> pool = pool ;
358
367
rport -> parent = sc ;
359
368
rport -> ch_num = ch_num ;
360
369
@@ -393,6 +402,7 @@ PJ_DEF(pj_status_t) pjmedia_splitcomb_create_rev_channel( pj_pool_t *pool,
393
402
buf_options ,
394
403
& rport -> buf [DIR_DOWNSTREAM ].dbuf );
395
404
if (status != PJ_SUCCESS ) {
405
+ rport_on_destroy (port );
396
406
return status ;
397
407
}
398
408
@@ -405,7 +415,7 @@ PJ_DEF(pj_status_t) pjmedia_splitcomb_create_rev_channel( pj_pool_t *pool,
405
415
buf_options ,
406
416
& rport -> buf [DIR_UPSTREAM ].dbuf );
407
417
if (status != PJ_SUCCESS ) {
408
- pjmedia_delay_buf_destroy ( rport -> buf [ DIR_DOWNSTREAM ]. dbuf );
418
+ rport_on_destroy ( port );
409
419
return status ;
410
420
}
411
421
@@ -419,9 +429,9 @@ PJ_DEF(pj_status_t) pjmedia_splitcomb_create_rev_channel( pj_pool_t *pool,
419
429
sc -> port_desc [ch_num ].reversed = PJ_TRUE ;
420
430
421
431
/* Init group lock */
422
- status = pjmedia_port_init_grp_lock (port , sc -> pool , sc -> base .grp_lock );
432
+ status = pjmedia_port_init_grp_lock (port , pool , sc -> base .grp_lock );
423
433
if (status != PJ_SUCCESS ) {
424
- rport_on_destroy (& rport -> base );
434
+ rport_on_destroy (port );
425
435
return status ;
426
436
}
427
437
@@ -846,8 +856,13 @@ static pj_status_t rport_on_destroy(pjmedia_port *this_port)
846
856
{
847
857
struct reverse_port * rport = (struct reverse_port * ) this_port ;
848
858
849
- pjmedia_delay_buf_destroy (rport -> buf [DIR_DOWNSTREAM ].dbuf );
850
- pjmedia_delay_buf_destroy (rport -> buf [DIR_UPSTREAM ].dbuf );
859
+ if (rport -> buf [DIR_DOWNSTREAM ].dbuf )
860
+ pjmedia_delay_buf_destroy (rport -> buf [DIR_DOWNSTREAM ].dbuf );
861
+
862
+ if (rport -> buf [DIR_UPSTREAM ].dbuf )
863
+ pjmedia_delay_buf_destroy (rport -> buf [DIR_UPSTREAM ].dbuf );
864
+
865
+ pj_pool_safe_release (& rport -> pool );
851
866
852
867
return PJ_SUCCESS ;
853
868
}
0 commit comments