switch_thread_rwlock_wrlock(verto_globals.tech_rwlock);
tech_pvt->next = verto_globals.tech_head;
verto_globals.tech_head = tech_pvt;
+ switch_set_flag(tech_pvt, TFLAG_TRACKED);
switch_thread_rwlock_unlock(verto_globals.tech_rwlock);
}
{
verto_pvt_t *p, *last = NULL;
int wake = 0;
-
+
switch_thread_rwlock_wrlock(verto_globals.tech_rwlock);
+
if (tech_pvt->detach_time) {
verto_globals.detached--;
tech_pvt->detach_time = 0;
wake = 1;
}
- for(p = verto_globals.tech_head; p; p = p->next) {
- if (p == tech_pvt) {
- if (last) {
- last->next = p->next;
- } else {
- verto_globals.tech_head = p->next;
+ if (switch_test_flag(tech_pvt, TFLAG_TRACKED)) {
+ switch_clear_flag(tech_pvt, TFLAG_TRACKED);
+ for(p = verto_globals.tech_head; p; p = p->next) {
+ if (p == tech_pvt) {
+ if (last) {
+ last->next = p->next;
+ } else {
+ verto_globals.tech_head = p->next;
+ }
+ break;
}
- break;
- }
- last = p;
+ last = p;
+ }
}
+
switch_thread_rwlock_unlock(verto_globals.tech_rwlock);
if (wake) attach_wake();
return SWITCH_STATUS_SUCCESS;
}
-static void verto_set_media_options(verto_pvt_t *tech_pvt, verto_profile_t *profile);
+static switch_status_t verto_set_media_options(verto_pvt_t *tech_pvt, verto_profile_t *profile);
static switch_status_t verto_connect(switch_core_session_t *session, const char *method)
{
switch_channel_set_variable(tech_pvt->channel, "media_webrtc", "true");
switch_core_session_set_ice(tech_pvt->session);
- verto_set_media_options(tech_pvt, jsock->profile);
+ if (verto_set_media_options(tech_pvt, jsock->profile) != SWITCH_STATUS_SUCCESS) {
+ status = SWITCH_STATUS_FALSE;
+ switch_thread_rwlock_unlock(jsock->rwlock);
+ return status;
+ }
switch_channel_set_variable(tech_pvt->channel, "verto_profile_name", jsock->profile->name);
if ((status = switch_core_media_choose_ports(tech_pvt->session, SWITCH_TRUE, SWITCH_TRUE)) != SWITCH_STATUS_SUCCESS) {
//if ((status = switch_core_media_choose_port(tech_pvt->session, SWITCH_MEDIA_TYPE_AUDIO, 0)) != SWITCH_STATUS_SUCCESS) {
- switch_channel_hangup(tech_pvt->channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
switch_thread_rwlock_unlock(jsock->rwlock);
return status;
}
switch_channel_set_flag(tech_pvt->channel, CF_VIDEO_BREAK);
switch_core_session_kill_channel(tech_pvt->session, SWITCH_SIG_BREAK);
- return status;
+ goto end;
}
if (switch_channel_direction(tech_pvt->channel) == SWITCH_CALL_DIRECTION_OUTBOUND) {
}
}
+ end:
+
+ if (status == SWITCH_STATUS_SUCCESS) {
+ track_pvt(tech_pvt);
+ }
+
return status;
}
-static void verto_set_media_options(verto_pvt_t *tech_pvt, verto_profile_t *profile)
+static switch_status_t verto_set_media_options(verto_pvt_t *tech_pvt, verto_profile_t *profile)
{
uint32_t i;
+
+ switch_mutex_lock(profile->mutex);
if (!zstr(profile->rtpip[profile->rtpip_cur])) {
tech_pvt->mparams->rtpip4 = switch_core_session_strdup(tech_pvt->session, profile->rtpip[profile->rtpip_cur++]);
tech_pvt->mparams->rtpip = tech_pvt->mparams->rtpip4;
profile->rtpip_cur6 = 0;
}
}
+ switch_mutex_unlock(profile->mutex);
if (zstr(tech_pvt->mparams->rtpip)) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(tech_pvt->session), SWITCH_LOG_ERROR, "%s has no media ip, check your configuration\n",
switch_channel_get_name(tech_pvt->channel));
- switch_channel_hangup(tech_pvt->channel, SWITCH_CAUSE_BEARERCAPABILITY_NOTAVAIL);
+ //switch_channel_hangup(tech_pvt->channel, SWITCH_CAUSE_BEARERCAPABILITY_NOTAVAIL);
+ return SWITCH_STATUS_FALSE;
}
tech_pvt->mparams->extrtpip = tech_pvt->mparams->extsipip = profile->extrtpip;
if (profile->enable_text && !tech_pvt->text_read_buffer) {
set_text_funcs(tech_pvt->session);
}
+
+ return SWITCH_STATUS_SUCCESS;
}
static switch_status_t verto_media(switch_core_session_t *session)
if ((tech_pvt->smh = switch_core_session_get_media_handle(session))) {
tech_pvt->mparams = switch_core_media_get_mparams(tech_pvt->smh);
- verto_set_media_options(tech_pvt, profile);
+ if (verto_set_media_options(tech_pvt, profile) != SWITCH_STATUS_SUCCESS) {
+ UNPROTECT_INTERFACE(verto_endpoint_interface);
+ return 0;
+ }
}
switch_channel_add_state_handler(channel, &verto_state_handlers);
switch_core_event_hook_add_receive_message(session, messagehook);
- track_pvt(tech_pvt);
+ //track_pvt(tech_pvt);
//switch_channel_clear_flag(tech_pvt->channel, CF_ANSWERED);
//switch_channel_clear_flag(tech_pvt->channel, CF_EARLY_MEDIA);
if ((tech_pvt->smh = switch_core_session_get_media_handle(session))) {
tech_pvt->mparams = switch_core_media_get_mparams(tech_pvt->smh);
- verto_set_media_options(tech_pvt, jsock->profile);
+ if (verto_set_media_options(tech_pvt, jsock->profile) != SWITCH_STATUS_SUCCESS) {
+ cJSON_AddItemToObject(obj, "message", cJSON_CreateString("Cannot set media options"));
+ err = 1; goto cleanup;
+ }
} else {
cJSON_AddItemToObject(obj, "message", cJSON_CreateString("Cannot create media handle"));
err = 1; goto cleanup;
switch_channel_add_state_handler(channel, &verto_state_handlers);
switch_core_event_hook_add_receive_message(session, messagehook);
switch_channel_set_state(channel, CS_INIT);
- track_pvt(tech_pvt);
+ //track_pvt(tech_pvt);
switch_core_session_thread_launch(session);
cleanup:
switch_channel_add_state_handler(channel, &verto_state_handlers);
switch_core_event_hook_add_receive_message(*new_session, messagehook);
switch_channel_set_state(channel, CS_INIT);
- track_pvt(tech_pvt);
+ //track_pvt(tech_pvt);
}
end: