diff --git a/abstract_jb.c b/abstract_jb.c index e9ab1ad9ca1ab3a3f432f1812ead59f8d64bc9ac..1525d81b01a22aa66cf3891de33868530740f57f 100644 --- a/abstract_jb.c +++ b/abstract_jb.c @@ -176,7 +176,7 @@ static long get_now(struct ast_jb *jb, struct timeval *tv); static void jb_choose_impl(struct ast_channel *chan) { - struct ast_jb *jb = chan->jb; + struct ast_jb *jb = &chan->jb; struct ast_jb_conf *jbconf = &jb->conf; struct ast_jb_impl *test_impl; int i, avail_impl_count = sizeof(avail_impl) / sizeof(avail_impl[0]); @@ -197,8 +197,8 @@ static void jb_choose_impl(struct ast_channel *chan) int ast_jb_do_usecheck(struct ast_channel *c0, struct ast_channel *c1) { - struct ast_jb *jb0 = c0->jb; - struct ast_jb *jb1 = c1->jb; + struct ast_jb *jb0 = &c0->jb; + struct ast_jb *jb1 = &c1->jb; struct ast_jb_conf *conf0 = &jb0->conf; struct ast_jb_conf *conf1 = &jb1->conf; int c0_wants_jitter = c0->tech->properties & AST_CHAN_TP_WANTSJITTER; @@ -258,8 +258,8 @@ int ast_jb_do_usecheck(struct ast_channel *c0, struct ast_channel *c1) int ast_jb_get_when_to_wakeup(struct ast_channel *c0, struct ast_channel *c1, int time_left) { - struct ast_jb *jb0 = c0->jb; - struct ast_jb *jb1 = c1->jb; + struct ast_jb *jb0 = &c0->jb; + struct ast_jb *jb1 = &c1->jb; int c0_use_jb = ast_test_flag(jb0, JB_USE); int c0_jb_is_created = ast_test_flag(jb0, JB_CREATED); int c1_use_jb = ast_test_flag(jb1, JB_USE); @@ -298,7 +298,7 @@ int ast_jb_get_when_to_wakeup(struct ast_channel *c0, struct ast_channel *c1, in int ast_jb_put(struct ast_channel *chan, struct ast_frame *f) { - struct ast_jb *jb = chan->jb; + struct ast_jb *jb = &chan->jb; struct ast_jb_impl *jbimpl = jb->impl; void *jbobj = jb->jbobj; struct ast_frame *frr; @@ -366,8 +366,8 @@ int ast_jb_put(struct ast_channel *chan, struct ast_frame *f) void ast_jb_get_and_deliver(struct ast_channel *c0, struct ast_channel *c1) { - struct ast_jb *jb0 = c0->jb; - struct ast_jb *jb1 = c1->jb; + struct ast_jb *jb0 = &c0->jb; + struct ast_jb *jb1 = &c1->jb; int c0_use_jb = ast_test_flag(jb0, JB_USE); int c0_jb_is_created = ast_test_flag(jb0, JB_CREATED); int c1_use_jb = ast_test_flag(jb1, JB_USE); @@ -383,7 +383,7 @@ void ast_jb_get_and_deliver(struct ast_channel *c0, struct ast_channel *c1) static void jb_get_and_deliver(struct ast_channel *chan) { - struct ast_jb *jb = chan->jb; + struct ast_jb *jb = &chan->jb; struct ast_jb_impl *jbimpl = jb->impl; void *jbobj = jb->jbobj; struct ast_frame *f, finterp; @@ -447,7 +447,7 @@ static void jb_get_and_deliver(struct ast_channel *chan) static int create_jb(struct ast_channel *chan, struct ast_frame *frr) { - struct ast_jb *jb = chan->jb; + struct ast_jb *jb = &chan->jb; struct ast_jb_conf *jbconf = &jb->conf; struct ast_jb_impl *jbimpl = jb->impl; void *jbobj; @@ -527,7 +527,7 @@ static int create_jb(struct ast_channel *chan, struct ast_frame *frr) void ast_jb_destroy(struct ast_channel *chan) { - struct ast_jb *jb = chan->jb; + struct ast_jb *jb = &chan->jb; struct ast_jb_impl *jbimpl = jb->impl; void *jbobj = jb->jbobj; struct ast_frame *f; @@ -551,8 +551,6 @@ void ast_jb_destroy(struct ast_channel *chan) if (option_verbose > 2) ast_verbose(VERBOSE_PREFIX_3 "%s jitterbuffer destroyed on channel %s\n", jbimpl->name, chan->name); } - - free(jb); } @@ -603,25 +601,15 @@ int ast_jb_read_conf(struct ast_jb_conf *conf, char *varname, char *value) } -int ast_jb_configure(struct ast_channel *chan, const struct ast_jb_conf *conf) +void ast_jb_configure(struct ast_channel *chan, const struct ast_jb_conf *conf) { - if (!(chan->jb = ast_calloc(1, sizeof(*chan->jb)))) - return -1; - - memcpy(&chan->jb->conf, conf, sizeof(*conf)); - - return 0; + memcpy(&chan->jb.conf, conf, sizeof(*conf)); } -int ast_jb_get_config(const struct ast_channel *chan, struct ast_jb_conf *conf) +void ast_jb_get_config(const struct ast_channel *chan, struct ast_jb_conf *conf) { - if (!chan->jb) - return -1; - - memcpy(conf, &chan->jb->conf, sizeof(*conf)); - - return 0; + memcpy(conf, &chan->jb.conf, sizeof(*conf)); } diff --git a/channel.c b/channel.c index 84e2fbe79761a9f02be8f7e0a301ea8dea183829..30a1ad073a728fd1963d32514b53cfb4f894b2f1 100644 --- a/channel.c +++ b/channel.c @@ -1015,8 +1015,7 @@ void ast_channel_free(struct ast_channel *chan) ast_var_delete(vardata); /* Destroy the jitterbuffer */ - if (chan->jb) - ast_jb_destroy(chan); + ast_jb_destroy(chan); ast_string_field_free_all(chan); free(chan); diff --git a/channels/chan_alsa.c b/channels/chan_alsa.c index d274b736ba4c82c504df16b0a0b7daade6357dcf..5c921b9181027c367db4b4d5ce49d7dfc9bd1f46 100644 --- a/channels/chan_alsa.c +++ b/channels/chan_alsa.c @@ -812,23 +812,19 @@ static struct ast_channel *alsa_new(struct chan_alsa_pvt *p, int state) ast_string_field_set(tmp, language, language); p->owner = tmp; ast_setstate(tmp, state); - if (ast_jb_configure(tmp, &global_jbconf)) { - ast_hangup(tmp); - p->owner = NULL; - return NULL; - } + ast_mutex_lock(&usecnt_lock); + usecnt++; + ast_mutex_unlock(&usecnt_lock); + ast_update_use_count(); if (state != AST_STATE_DOWN) { if (ast_pbx_start(tmp)) { ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name); ast_hangup(tmp); - p->owner = NULL; - return NULL; + tmp = NULL; } } - ast_mutex_lock(&usecnt_lock); - usecnt++; - ast_mutex_unlock(&usecnt_lock); - ast_update_use_count(); + if (tmp) + ast_jb_configure(tmp, &global_jbconf); } return tmp; } diff --git a/channels/chan_h323.c b/channels/chan_h323.c index 42c9b61016c4dfa4154f7046d8eece61dff17856..36c0582b81c6190c6b73ab4f51dfc21e128dac6a 100644 --- a/channels/chan_h323.c +++ b/channels/chan_h323.c @@ -746,6 +746,9 @@ static struct ast_channel *__oh323_new(struct oh323_pvt *pvt, int state, const c /* Don't hold a oh323_pvt lock while we allocate a chanel */ ast_mutex_unlock(&pvt->lock); ch = ast_channel_alloc(1); + /* Update usage counter */ + ast_atomic_fetchadd_int(&__mod_desc->usecnt, +1); + ast_update_use_count(); ast_mutex_lock(&pvt->lock); if (ch) { ch->tech = &oh323_tech; @@ -800,25 +803,17 @@ static struct ast_channel *__oh323_new(struct oh323_pvt *pvt, int state, const c ch->cid.cid_dnid = strdup(pvt->exten); } ast_setstate(ch, state); - /* Configure the new channel jb */ - if (pvt->rtp) { - if (ast_jb_configure(ch, &global_jbconf)) { - ast_hangup(ch); - pvt->owner = NULL; - return NULL; - } - } if (state != AST_STATE_DOWN) { if (ast_pbx_start(ch)) { ast_log(LOG_WARNING, "Unable to start PBX on %s\n", ch->name); ast_hangup(ch); - pvt->owner = NULL; - return NULL; + ch = NULL; } } - /* Update usage counter */ - ast_atomic_fetchadd_int(&__mod_desc->usecnt, +1); - ast_update_use_count(); + + /* Configure the new channel jb */ + if (ch && pvt && pvt->rtp) + ast_jb_configure(ch, &global_jbconf); } else { ast_log(LOG_WARNING, "Unable to allocate channel structure\n"); } diff --git a/channels/chan_jingle.c b/channels/chan_jingle.c index b9aae9d543c3cef70c73a5f61e9d84664c6249de..16bd521da2c146892fff96e536404e5944a1c432 100644 --- a/channels/chan_jingle.c +++ b/channels/chan_jingle.c @@ -756,6 +756,9 @@ static struct ast_channel *jingle_new(struct jingle *client, struct jingle_pvt * if (!ast_strlen_zero(client->musicclass)) ast_string_field_set(tmp, musicclass, client->musicclass); i->owner = tmp; + ast_mutex_lock(&usecnt_lock); + usecnt++; + ast_mutex_unlock(&usecnt_lock); ast_copy_string(tmp->context, client->context, sizeof(tmp->context)); ast_copy_string(tmp->exten, i->exten, sizeof(tmp->exten)); if (!ast_strlen_zero(i->cid_num)) @@ -766,26 +769,16 @@ static struct ast_channel *jingle_new(struct jingle *client, struct jingle_pvt * tmp->cid.cid_dnid = ast_strdup(i->exten); tmp->priority = 1; ast_setstate(tmp, state); - /* Configure the new channel jb */ - if (i->rtp) { - if (ast_jb_configure(tmp, &global_jbconf)) { - ast_hangup(tmp); - i->owner = NULL; - return NULL; - } - } if (state != AST_STATE_DOWN && ast_pbx_start(tmp)) { ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name); tmp->hangupcause = AST_CAUSE_SWITCH_CONGESTION; ast_hangup(tmp); - i->owner = NULL; - return NULL; + tmp = NULL; } - ast_mutex_lock(&usecnt_lock); - usecnt++; - ast_mutex_unlock(&usecnt_lock); - ast_update_use_count(); + /* Configure the new channel jb */ + if (tmp && i && i->rtp) + ast_jb_configure(tmp, &global_jbconf); return tmp; } diff --git a/channels/chan_mgcp.c b/channels/chan_mgcp.c index c32de10fa3987b6e7fbd84671bd394ceba363d09..9d9499fe651f32a4f09eaa4e800985d6893b6cc7 100644 --- a/channels/chan_mgcp.c +++ b/channels/chan_mgcp.c @@ -1478,6 +1478,8 @@ static struct ast_channel *mgcp_new(struct mgcp_subchannel *sub, int state) if (i->amaflags) tmp->amaflags = i->amaflags; sub->owner = tmp; + ast_atomic_fetchadd_int(&__mod_desc->usecnt, +1); + ast_update_use_count(); tmp->callgroup = i->callgroup; tmp->pickupgroup = i->pickupgroup; ast_string_field_set(tmp, call_forward, i->call_forward); @@ -1488,28 +1490,22 @@ static struct ast_channel *mgcp_new(struct mgcp_subchannel *sub, int state) if (!i->adsi) tmp->adsicpe = AST_ADSI_UNAVAILABLE; tmp->priority = 1; - /* Configure the new channel jb */ - if (sub->rtp) { - if (ast_jb_configure(tmp, &global_jbconf)) { - ast_hangup(tmp); - sub->owner = NULL; - return NULL; - } - } if (state != AST_STATE_DOWN) { if (ast_pbx_start(tmp)) { ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name); ast_hangup(tmp); - sub->owner = NULL; - return NULL; + tmp = NULL; } } + /* SC: verbose level check */ if (option_verbose > 2) { ast_verbose(VERBOSE_PREFIX_3 "MGCP mgcp_new(%s) created in state: %s\n", tmp->name, ast_state2str(state)); } - ast_atomic_fetchadd_int(&__mod_desc->usecnt, +1); - ast_update_use_count(); + + /* Configure the new channel jb */ + if (tmp && sub && sub->rtp) + ast_jb_configure(tmp, &global_jbconf); } else { ast_log(LOG_WARNING, "Unable to allocate channel structure\n"); } diff --git a/channels/chan_oss.c b/channels/chan_oss.c index 36a418bd0ee82671fae649b70a75a5ff39dba7eb..98ca519de5c26a4c6412aca3e7ae63af49877f37 100644 --- a/channels/chan_oss.c +++ b/channels/chan_oss.c @@ -1000,24 +1000,21 @@ static struct ast_channel *oss_new(struct chan_oss_pvt *o, o->owner = c; ast_setstate(c, state); - if (ast_jb_configure(c, &global_jbconf)) { - ast_hangup(c); - o->owner = NULL; - return NULL; - } + ast_mutex_lock(&usecnt_lock); + usecnt++; + ast_mutex_unlock(&usecnt_lock); + ast_update_use_count(); if (state != AST_STATE_DOWN) { if (ast_pbx_start(c)) { ast_log(LOG_WARNING, "Unable to start PBX on %s\n", c->name); ast_hangup(c); - o->owner = NULL; - return NULL; + o->owner = c = NULL; + /* XXX what about the channel itself ? */ + /* XXX what about usecnt ? */ } } - - ast_mutex_lock(&usecnt_lock); - usecnt++; - ast_mutex_unlock(&usecnt_lock); - ast_update_use_count(); + if (c) + ast_jb_configure(c, &global_jbconf); return c; } diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 2dbf6ddd045cf4601b069532501ea59c1005ca81..498087cdc9c5503c2af53f64ab903bb96a285a81 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -3648,6 +3648,9 @@ static struct ast_channel *sip_new(struct sip_pvt *i, int state, const char *tit if (!ast_strlen_zero(i->musicclass)) ast_string_field_set(tmp, musicclass, i->musicclass); i->owner = tmp; + ast_mutex_lock(&usecnt_lock); + usecnt++; + ast_mutex_unlock(&usecnt_lock); ast_copy_string(tmp->context, i->context, sizeof(tmp->context)); ast_copy_string(tmp->exten, i->exten, sizeof(tmp->exten)); if (!ast_strlen_zero(i->cid_num)) @@ -3668,20 +3671,11 @@ static struct ast_channel *sip_new(struct sip_pvt *i, int state, const char *tit if (!ast_strlen_zero(i->callid)) pbx_builtin_setvar_helper(tmp, "SIPCALLID", i->callid); ast_setstate(tmp, state); - /* Configure the new channel jb */ - if (i->rtp) { - if (ast_jb_configure(tmp, &global_jbconf)) { - ast_hangup(tmp); - i->owner = NULL; - return NULL; - } - } if (state != AST_STATE_DOWN && ast_pbx_start(tmp)) { ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name); tmp->hangupcause = AST_CAUSE_SWITCH_CONGESTION; ast_hangup(tmp); - i->owner = NULL; - return NULL; + tmp = NULL; } /* Set channel variables for this call from configuration */ for (v = i->chanvars ; v ; v = v->next) @@ -3690,9 +3684,9 @@ static struct ast_channel *sip_new(struct sip_pvt *i, int state, const char *tit if (recordhistory) append_history(i, "NewChan", "Channel %s - from %s", tmp->name, i->callid); - ast_mutex_lock(&usecnt_lock); - usecnt++; - ast_mutex_unlock(&usecnt_lock); + /* Configure the new channel jb */ + if (tmp && i && i->rtp) + ast_jb_configure(tmp, &global_jbconf); return tmp; } diff --git a/channels/chan_skinny.c b/channels/chan_skinny.c index da7d118f6a7a9d1418ace6588e1714cec7a67f96..899bd13df6771f25527e8f3a5b73b739099ae5df 100644 --- a/channels/chan_skinny.c +++ b/channels/chan_skinny.c @@ -2516,6 +2516,10 @@ static struct ast_channel *skinny_new(struct skinny_line *l, int state) if (l->amaflags) tmp->amaflags = l->amaflags; + ast_mutex_lock(&usecnt_lock); + usecnt++; + ast_mutex_unlock(&usecnt_lock); + ast_update_use_count(); tmp->callgroup = l->callgroup; tmp->pickupgroup = l->pickupgroup; ast_string_field_set(tmp, call_forward, l->call_forward); @@ -2526,29 +2530,18 @@ static struct ast_channel *skinny_new(struct skinny_line *l, int state) tmp->priority = 1; tmp->adsicpe = AST_ADSI_UNAVAILABLE; - /* Configure the new channel jb */ - if (sub->rtp) { - if (ast_jb_configure(tmp, &global_jbconf)) { - ast_hangup(tmp); - sub->owner = NULL; - return NULL; - } - } if (state != AST_STATE_DOWN) { if (ast_pbx_start(tmp)) { ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name); ast_hangup(tmp); - sub->owner = NULL; - return NULL; + tmp = NULL; } } - } - - ast_mutex_lock(&usecnt_lock); - usecnt++; - ast_mutex_unlock(&usecnt_lock); - ast_update_use_count(); + /* Configure the new channel jb */ + if (tmp && sub->rtp) + ast_jb_configure(tmp, &global_jbconf); + } return tmp; } diff --git a/channels/chan_zap.c b/channels/chan_zap.c index 255ab663c97d906e355396ec85752aefc4936212..2f8e767f8e077d9c99a1edca150604e9a1991a53 100644 --- a/channels/chan_zap.c +++ b/channels/chan_zap.c @@ -5188,11 +5188,7 @@ static struct ast_channel *zt_new(struct zt_pvt *i, int state, int startpbx, int zt_confmute(i, 0); ast_setstate(tmp, state); /* Configure the new channel jb */ - if (ast_jb_configure(tmp, &global_jbconf)) { - ast_hangup(tmp); - i->owner = NULL; - return NULL; - } + ast_jb_configure(tmp, &global_jbconf); if (startpbx) { if (ast_pbx_start(tmp)) { ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name); diff --git a/include/asterisk/abstract_jb.h b/include/asterisk/abstract_jb.h index 8f365a86089d2453be629fd765cef2406bfb856e..014902be804808629ddbd1b6c9be983adf8df7d9 100644 --- a/include/asterisk/abstract_jb.h +++ b/include/asterisk/abstract_jb.h @@ -202,22 +202,16 @@ int ast_jb_read_conf(struct ast_jb_conf *conf, char *varname, char *value); * * Called from a channel driver when a channel is created and its jitterbuffer needs * to be configured. - * - * \retval 0 success - * \retval -1 failure */ -int ast_jb_configure(struct ast_channel *chan, const struct ast_jb_conf *conf); +void ast_jb_configure(struct ast_channel *chan, const struct ast_jb_conf *conf); /*! * \brief Copies a channel's jitterbuffer configuration. * \param chan channel. * \param conf destination. - * - * \retval 0 success - * \retval -1 failure */ -int ast_jb_get_config(const struct ast_channel *chan, struct ast_jb_conf *conf); +void ast_jb_get_config(const struct ast_channel *chan, struct ast_jb_conf *conf); #if defined(__cplusplus) || defined(c_plusplus) diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h index 0168b90fae075a42df0d2a4a24401da645d004e1..3d842bbe36a0c6d62f5081ede73bb8af15014400 100644 --- a/include/asterisk/channel.h +++ b/include/asterisk/channel.h @@ -383,7 +383,7 @@ struct ast_channel { struct ast_channel_spy_list *spies; /*!< Chan Spy stuff */ AST_LIST_ENTRY(ast_channel) chan_list; /*!< For easy linking */ - struct ast_jb *jb; /*!< The jitterbuffer state */ + struct ast_jb jb; /*!< The jitterbuffer state */ /*! \brief Data stores on the channel */ AST_LIST_HEAD_NOLOCK(datastores, ast_datastore) datastores;