mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-12 15:45:18 +00:00
channels: Return allocated channels locked.
This change makes ast_channel_alloc return allocated channels locked. By doing so no other thread can acquire, lock, and manipulate the channel before it is completely set up. (closes issue AST-1256) Review: https://reviewboard.asterisk.org/r/3067/ ........ Merged revisions 404204 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@404210 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -359,24 +359,14 @@ static struct ast_channel *chan_pjsip_new(struct ast_sip_session *session, int s
|
||||
ast_channel_tech_set(chan, &chan_pjsip_tech);
|
||||
|
||||
if (!(channel = ast_sip_channel_pvt_alloc(pvt, session))) {
|
||||
ast_channel_unlock(chan);
|
||||
ast_hangup(chan);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ast_channel_stage_snapshot(chan);
|
||||
|
||||
/* If res_pjsip_session is ever updated to create/destroy ast_sip_session_media
|
||||
* during a call such as if multiple same-type stream support is introduced,
|
||||
* these will need to be recaptured as well */
|
||||
pvt->media[SIP_MEDIA_AUDIO] = ao2_find(session->media, "audio", OBJ_KEY);
|
||||
pvt->media[SIP_MEDIA_VIDEO] = ao2_find(session->media, "video", OBJ_KEY);
|
||||
ast_channel_tech_pvt_set(chan, channel);
|
||||
if (pvt->media[SIP_MEDIA_AUDIO] && pvt->media[SIP_MEDIA_AUDIO]->rtp) {
|
||||
ast_rtp_instance_set_channel_id(pvt->media[SIP_MEDIA_AUDIO]->rtp, ast_channel_uniqueid(chan));
|
||||
}
|
||||
if (pvt->media[SIP_MEDIA_VIDEO] && pvt->media[SIP_MEDIA_VIDEO]->rtp) {
|
||||
ast_rtp_instance_set_channel_id(pvt->media[SIP_MEDIA_VIDEO]->rtp, ast_channel_uniqueid(chan));
|
||||
}
|
||||
|
||||
if (ast_format_cap_is_empty(session->req_caps) || !ast_format_cap_has_joint(session->req_caps, session->endpoint->media.codecs)) {
|
||||
ast_format_cap_copy(ast_channel_nativeformats(chan), session->endpoint->media.codecs);
|
||||
@@ -418,9 +408,22 @@ static struct ast_channel *chan_pjsip_new(struct ast_sip_session *session, int s
|
||||
ast_channel_zone_set(chan, zone);
|
||||
}
|
||||
|
||||
ast_endpoint_add_channel(session->endpoint->persistent, chan);
|
||||
|
||||
ast_channel_stage_snapshot_done(chan);
|
||||
ast_channel_unlock(chan);
|
||||
|
||||
/* If res_pjsip_session is ever updated to create/destroy ast_sip_session_media
|
||||
* during a call such as if multiple same-type stream support is introduced,
|
||||
* these will need to be recaptured as well */
|
||||
pvt->media[SIP_MEDIA_AUDIO] = ao2_find(session->media, "audio", OBJ_KEY);
|
||||
pvt->media[SIP_MEDIA_VIDEO] = ao2_find(session->media, "video", OBJ_KEY);
|
||||
if (pvt->media[SIP_MEDIA_AUDIO] && pvt->media[SIP_MEDIA_AUDIO]->rtp) {
|
||||
ast_rtp_instance_set_channel_id(pvt->media[SIP_MEDIA_AUDIO]->rtp, ast_channel_uniqueid(chan));
|
||||
}
|
||||
if (pvt->media[SIP_MEDIA_VIDEO] && pvt->media[SIP_MEDIA_VIDEO]->rtp) {
|
||||
ast_rtp_instance_set_channel_id(pvt->media[SIP_MEDIA_VIDEO]->rtp, ast_channel_uniqueid(chan));
|
||||
}
|
||||
|
||||
ast_endpoint_add_channel(session->endpoint->persistent, chan);
|
||||
|
||||
return chan;
|
||||
}
|
||||
|
Reference in New Issue
Block a user