diff options
author | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-06-22 17:05:17 +0000 |
---|---|---|
committer | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-06-22 17:05:17 +0000 |
commit | 75865d5802e68f217cb6d5b27e205948a935883e (patch) | |
tree | 09e0da9c9e65e62322d7b473d2f44a59feef1bbb /channels | |
parent | f3f7a9e1aaee38f18bc703bef74d441b3069eb41 (diff) |
- dynamically allocate the ast_jb structure that is on the channel structure
so that channels not using a jitterbuffer don't waste as much memory
- ensure that the channel drivers that use jitterbuffers can handle a failure
from configuring a jitterbuffer on a new channel because of a memory
allocation error
- On passing through these channel drivers, configure the jitterbuffer before
starting the PBX thread instead of afterwards. If the pbx fails to start for
whatever reason, this would have caused a crash.
- Also on passing, move the increase of the usecount to after all of the
possible failure conditions in the function
- fix a place where ast_update_use_count() was not called
- ensure that the owner channel pointer of the channel pvt strcutures is set to
NULL in failure conditions
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@35553 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels')
-rw-r--r-- | channels/chan_alsa.c | 18 | ||||
-rw-r--r-- | channels/chan_h323.c | 21 | ||||
-rw-r--r-- | channels/chan_jingle.c | 21 | ||||
-rw-r--r-- | channels/chan_mgcp.c | 20 | ||||
-rw-r--r-- | channels/chan_oss.c | 21 | ||||
-rw-r--r-- | channels/chan_sip.c | 20 | ||||
-rw-r--r-- | channels/chan_skinny.c | 25 | ||||
-rw-r--r-- | channels/chan_zap.c | 22 |
8 files changed, 105 insertions, 63 deletions
diff --git a/channels/chan_alsa.c b/channels/chan_alsa.c index 5c921b918..d274b736b 100644 --- a/channels/chan_alsa.c +++ b/channels/chan_alsa.c @@ -812,19 +812,23 @@ 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); - ast_mutex_lock(&usecnt_lock); - usecnt++; - ast_mutex_unlock(&usecnt_lock); - ast_update_use_count(); + if (ast_jb_configure(tmp, &global_jbconf)) { + ast_hangup(tmp); + p->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); - tmp = NULL; + p->owner = NULL; + return NULL; } } - if (tmp) - ast_jb_configure(tmp, &global_jbconf); + ast_mutex_lock(&usecnt_lock); + usecnt++; + ast_mutex_unlock(&usecnt_lock); + ast_update_use_count(); } return tmp; } diff --git a/channels/chan_h323.c b/channels/chan_h323.c index 36c0582b8..42c9b6101 100644 --- a/channels/chan_h323.c +++ b/channels/chan_h323.c @@ -746,9 +746,6 @@ 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; @@ -803,17 +800,25 @@ 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); - ch = NULL; + pvt->owner = NULL; + return NULL; } } - - /* Configure the new channel jb */ - if (ch && pvt && pvt->rtp) - ast_jb_configure(ch, &global_jbconf); + /* Update usage counter */ + ast_atomic_fetchadd_int(&__mod_desc->usecnt, +1); + ast_update_use_count(); } else { ast_log(LOG_WARNING, "Unable to allocate channel structure\n"); } diff --git a/channels/chan_jingle.c b/channels/chan_jingle.c index 16bd521da..b9aae9d54 100644 --- a/channels/chan_jingle.c +++ b/channels/chan_jingle.c @@ -756,9 +756,6 @@ 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)) @@ -769,16 +766,26 @@ 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); - tmp = NULL; + i->owner = NULL; + return NULL; } - /* Configure the new channel jb */ - if (tmp && i && i->rtp) - ast_jb_configure(tmp, &global_jbconf); + ast_mutex_lock(&usecnt_lock); + usecnt++; + ast_mutex_unlock(&usecnt_lock); + ast_update_use_count(); return tmp; } diff --git a/channels/chan_mgcp.c b/channels/chan_mgcp.c index 9d9499fe6..c32de10fa 100644 --- a/channels/chan_mgcp.c +++ b/channels/chan_mgcp.c @@ -1478,8 +1478,6 @@ 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); @@ -1490,22 +1488,28 @@ 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); - tmp = NULL; + sub->owner = NULL; + return 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)); } - - /* Configure the new channel jb */ - if (tmp && sub && sub->rtp) - ast_jb_configure(tmp, &global_jbconf); + ast_atomic_fetchadd_int(&__mod_desc->usecnt, +1); + ast_update_use_count(); } else { ast_log(LOG_WARNING, "Unable to allocate channel structure\n"); } diff --git a/channels/chan_oss.c b/channels/chan_oss.c index 98ca519de..36a418bd0 100644 --- a/channels/chan_oss.c +++ b/channels/chan_oss.c @@ -1000,21 +1000,24 @@ static struct ast_channel *oss_new(struct chan_oss_pvt *o, o->owner = c; ast_setstate(c, state); - ast_mutex_lock(&usecnt_lock); - usecnt++; - ast_mutex_unlock(&usecnt_lock); - ast_update_use_count(); + if (ast_jb_configure(c, &global_jbconf)) { + ast_hangup(c); + o->owner = NULL; + return NULL; + } 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 = c = NULL; - /* XXX what about the channel itself ? */ - /* XXX what about usecnt ? */ + o->owner = NULL; + return NULL; } } - if (c) - ast_jb_configure(c, &global_jbconf); + + ast_mutex_lock(&usecnt_lock); + usecnt++; + ast_mutex_unlock(&usecnt_lock); + ast_update_use_count(); return c; } diff --git a/channels/chan_sip.c b/channels/chan_sip.c index 498087cdc..2dbf6ddd0 100644 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -3648,9 +3648,6 @@ 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)) @@ -3671,11 +3668,20 @@ 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); - tmp = NULL; + i->owner = NULL; + return NULL; } /* Set channel variables for this call from configuration */ for (v = i->chanvars ; v ; v = v->next) @@ -3684,9 +3690,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); - /* Configure the new channel jb */ - if (tmp && i && i->rtp) - ast_jb_configure(tmp, &global_jbconf); + ast_mutex_lock(&usecnt_lock); + usecnt++; + ast_mutex_unlock(&usecnt_lock); return tmp; } diff --git a/channels/chan_skinny.c b/channels/chan_skinny.c index 899bd13df..da7d118f6 100644 --- a/channels/chan_skinny.c +++ b/channels/chan_skinny.c @@ -2516,10 +2516,6 @@ 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); @@ -2530,18 +2526,29 @@ 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); - tmp = NULL; + sub->owner = NULL; + return NULL; } } - - /* Configure the new channel jb */ - if (tmp && sub->rtp) - ast_jb_configure(tmp, &global_jbconf); } + + ast_mutex_lock(&usecnt_lock); + usecnt++; + ast_mutex_unlock(&usecnt_lock); + ast_update_use_count(); + return tmp; } diff --git a/channels/chan_zap.c b/channels/chan_zap.c index 8ddb3efcc..4485d5bd4 100644 --- a/channels/chan_zap.c +++ b/channels/chan_zap.c @@ -5190,22 +5190,28 @@ static struct ast_channel *zt_new(struct zt_pvt *i, int state, int startpbx, int /* Assure there is no confmute on this channel */ zt_confmute(i, 0); ast_setstate(tmp, state); - ast_mutex_lock(&usecnt_lock); - usecnt++; - ast_mutex_unlock(&usecnt_lock); - ast_update_use_count(); + /* Configure the new channel jb */ + if (ast_jb_configure(tmp, &global_jbconf)) { + ast_hangup(tmp); + i->owner = NULL; + return NULL; + } if (startpbx) { if (ast_pbx_start(tmp)) { ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name); ast_hangup(tmp); - tmp = NULL; + i->owner = NULL; + return NULL; } } } else ast_log(LOG_WARNING, "Unable to allocate channel structure\n"); - /* Configure the new channel jb */ - if (tmp && i) - ast_jb_configure(tmp, &global_jbconf); + + ast_mutex_lock(&usecnt_lock); + usecnt++; + ast_mutex_unlock(&usecnt_lock); + ast_update_use_count(); + return tmp; } |