Skip to content

Commit 3ed968a

Browse files
committed
Add own pool to splitcomb's reverse channel. (#4208)
1 parent 9835a9a commit 3ed968a

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

pjmedia/src/pjmedia/splitcomb.c

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ struct splitcomb
108108
struct reverse_port
109109
{
110110
pjmedia_port base;
111+
pj_pool_t *pool;
111112
struct splitcomb*parent;
112113
unsigned ch_num;
113114

@@ -323,7 +324,7 @@ PJ_DEF(pj_status_t) pjmedia_splitcomb_set_channel( pjmedia_port *splitcomb,
323324
/*
324325
* Create reverse phase port for the specified channel.
325326
*/
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_,
327328
pjmedia_port *splitcomb,
328329
unsigned ch_num,
329330
unsigned options,
@@ -336,25 +337,33 @@ PJ_DEF(pj_status_t) pjmedia_splitcomb_create_rev_channel( pj_pool_t *pool,
336337
unsigned buf_options;
337338
const pjmedia_audio_format_detail *sc_afd, *p_afd;
338339
pjmedia_port *port;
340+
pj_pool_t* pool;
339341
pj_status_t status;
340342

341343
/* Sanity check */
342344
PJ_ASSERT_RETURN(splitcomb, PJ_EINVAL);
343-
PJ_UNUSED_ARG(pool);
344345

345346
/* Make sure this is really a splitcomb port */
346347
PJ_ASSERT_RETURN(sc->base.info.signature == SIGNATURE, PJ_EINVAL);
347348

348349
/* Check the channel number */
349350
PJ_ASSERT_RETURN(ch_num < PJMEDIA_PIA_CCNT(&sc->base.info), PJ_EINVAL);
350351

352+
/* Make sure that the channel has not been setup */
353+
PJ_ASSERT_RETURN(sc->port_desc[ch_num].port==NULL, PJ_EINVALIDOP);
354+
351355
/* options is unused for now */
352356
PJ_UNUSED_ARG(options);
353357

354358
sc_afd = pjmedia_format_get_audio_format_detail(&splitcomb->info.fmt, 1);
355359

360+
/* Create own pool */
361+
pool = pj_pool_create(pool_->factory, "sc-revch", 500, 500, NULL);
362+
PJ_ASSERT_RETURN(pool, PJ_ENOMEM);
363+
356364
/* 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;
358367
rport->parent = sc;
359368
rport->ch_num = ch_num;
360369

@@ -393,6 +402,7 @@ PJ_DEF(pj_status_t) pjmedia_splitcomb_create_rev_channel( pj_pool_t *pool,
393402
buf_options,
394403
&rport->buf[DIR_DOWNSTREAM].dbuf);
395404
if (status != PJ_SUCCESS) {
405+
rport_on_destroy(port);
396406
return status;
397407
}
398408

@@ -405,7 +415,7 @@ PJ_DEF(pj_status_t) pjmedia_splitcomb_create_rev_channel( pj_pool_t *pool,
405415
buf_options,
406416
&rport->buf[DIR_UPSTREAM].dbuf);
407417
if (status != PJ_SUCCESS) {
408-
pjmedia_delay_buf_destroy(rport->buf[DIR_DOWNSTREAM].dbuf);
418+
rport_on_destroy(port);
409419
return status;
410420
}
411421

@@ -419,9 +429,9 @@ PJ_DEF(pj_status_t) pjmedia_splitcomb_create_rev_channel( pj_pool_t *pool,
419429
sc->port_desc[ch_num].reversed = PJ_TRUE;
420430

421431
/* 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);
423433
if (status != PJ_SUCCESS) {
424-
rport_on_destroy(&rport->base);
434+
rport_on_destroy(port);
425435
return status;
426436
}
427437

@@ -846,8 +856,13 @@ static pj_status_t rport_on_destroy(pjmedia_port *this_port)
846856
{
847857
struct reverse_port *rport = (struct reverse_port*) this_port;
848858

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);
851866

852867
return PJ_SUCCESS;
853868
}

0 commit comments

Comments
 (0)