Merge branch 'master' into FS-4558

This commit is contained in:
Raymond Chandler
2012-09-08 02:29:59 -04:00
20 changed files with 283 additions and 69 deletions
@@ -2739,6 +2739,49 @@ SWITCH_STANDARD_API(uuid_media_function)
return SWITCH_STATUS_SUCCESS;
}
#define MEDIA_RENEG_SYNTAX "<uuid>[ <codec_string>]"
SWITCH_STANDARD_API(uuid_media_neg_function)
{
char *mycmd = NULL, *argv[2] = { 0 };
int argc = 0;
switch_status_t status = SWITCH_STATUS_FALSE;
if (!zstr(cmd) && (mycmd = strdup(cmd))) {
argc = switch_separate_string(mycmd, ' ', argv, (sizeof(argv) / sizeof(argv[0])));
}
if (zstr(cmd) || argc < 1 || zstr(argv[0])) {
stream->write_function(stream, "-USAGE: %s\n", MEDIA_RENEG_SYNTAX);
} else {
switch_core_session_message_t msg = { 0 };
switch_core_session_t *lsession = NULL;
char *uuid = argv[0];
msg.message_id = SWITCH_MESSAGE_INDICATE_MEDIA_RENEG;
msg.string_arg = argv[1];
msg.from = __FILE__;
if (*uuid == '+') {
msg.numeric_arg++;
uuid++;
}
if ((lsession = switch_core_session_locate(uuid))) {
status = switch_core_session_receive_message(lsession, &msg);
switch_core_session_rwunlock(lsession);
}
}
if (status == SWITCH_STATUS_SUCCESS) {
stream->write_function(stream, "+OK Success\n");
} else {
stream->write_function(stream, "-ERR Operation Failed\n");
}
switch_safe_free(mycmd);
return SWITCH_STATUS_SUCCESS;
}
SWITCH_STANDARD_API(uuid_early_ok_function)
{
char *uuid = (char *) cmd;
@@ -5690,6 +5733,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
SWITCH_ADD_API(commands_api_interface, "uuid_limit_release", "Release limit resource", uuid_limit_release_function, LIMIT_RELEASE_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "uuid_loglevel", "set loglevel on session", uuid_loglevel, UUID_LOGLEVEL_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "uuid_media", "media", uuid_media_function, MEDIA_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "uuid_media_reneg", "media negotiation", uuid_media_neg_function, MEDIA_RENEG_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "uuid_park", "Park Channel", park_function, PARK_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "uuid_phone_event", "Send and event to the phone", uuid_phone_event_function, PHONE_EVENT_SYNTAX);
SWITCH_ADD_API(commands_api_interface, "uuid_pre_answer", "pre_answer", uuid_pre_answer_function, "<uuid>");
@@ -5841,6 +5885,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_commands_load)
switch_console_set_complete("add uuid_media ::console::list_uuid");
switch_console_set_complete("add uuid_media off ::console::list_uuid");
switch_console_set_complete("add uuid_park ::console::list_uuid");
switch_console_set_complete("add uuid_media_reneg ::console::list_uuid");
switch_console_set_complete("add uuid_phone_event ::console::list_uuid talk");
switch_console_set_complete("add uuid_phone_event ::console::list_uuid hold");
switch_console_set_complete("add uuid_preprocess ::console::list_uuid");
+38
View File
@@ -1547,6 +1547,7 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
case SWITCH_MESSAGE_INDICATE_RECOVERY_REFRESH:
case SWITCH_MESSAGE_INDICATE_APPLICATION_EXEC:
break;
case SWITCH_MESSAGE_INDICATE_PROXY_MEDIA:
{
if (switch_rtp_ready(tech_pvt->rtp_session)) {
@@ -1849,6 +1850,43 @@ static switch_status_t sofia_receive_message(switch_core_session_t *session, swi
}
switch (msg->message_id) {
case SWITCH_MESSAGE_INDICATE_MEDIA_RENEG:
{
switch_core_session_t *nsession;
if (msg->string_arg) {
switch_channel_set_variable(channel, "absolute_codec_string", NULL);
if (*msg->string_arg == '=') {
switch_channel_set_variable(channel, "codec_string", msg->string_arg);
} else {
switch_channel_set_variable_printf(channel, "codec_string", "=%s%s%s,%s",
tech_pvt->video_rm_encoding ? tech_pvt->video_rm_encoding : "",
tech_pvt->video_rm_encoding ? "," : "",
tech_pvt->rm_encoding, msg->string_arg);
}
tech_pvt->num_codecs = 0;
tech_pvt->rm_encoding = NULL;
tech_pvt->video_rm_encoding = NULL;
sofia_clear_flag_locked(tech_pvt, TFLAG_VIDEO);
sofia_glue_tech_prepare_codecs(tech_pvt);
sofia_glue_check_video_codecs(tech_pvt);
sofia_glue_set_local_sdp(tech_pvt, NULL, 0, NULL, 1);
sofia_set_pflag(tech_pvt->profile, PFLAG_RENEG_ON_REINVITE);
}
sofia_glue_do_invite(session);
if (msg->numeric_arg && switch_core_session_get_partner(session, &nsession) == SWITCH_STATUS_SUCCESS) {
msg->numeric_arg = 0;
switch_core_session_receive_message(nsession, msg);
switch_core_session_rwunlock(nsession);
}
}
break;
case SWITCH_MESSAGE_INDICATE_VIDEO_REFRESH_REQ:
{
const char *pl = "<media_control><vc_primitive><to_encoder><picture_fast_update/></to_encoder></vc_primitive></media_control>";
+46 -19
View File
@@ -1209,11 +1209,13 @@ static void our_sofia_event_callback(nua_event_t event,
sofia_handle_sip_i_options(status, phrase, nua, profile, nh, sofia_private, sip, de, tags);
break;
case nua_i_invite:
if (session && sofia_private->is_call > 1) {
sofia_handle_sip_i_reinvite(session, nua, profile, nh, sofia_private, sip, de, tags);
} else {
sofia_private->is_call++;
sofia_handle_sip_i_invite(session, nua, profile, nh, sofia_private, sip, de, tags);
if (session && sofia_private) {
if (sofia_private->is_call > 1) {
sofia_handle_sip_i_reinvite(session, nua, profile, nh, sofia_private, sip, de, tags);
} else {
sofia_private->is_call++;
sofia_handle_sip_i_invite(session, nua, profile, nh, sofia_private, sip, de, tags);
}
}
break;
case nua_i_publish:
@@ -1688,6 +1690,14 @@ static void sofia_queue_message(sofia_dispatch_event_t *de)
switch_queue_push(mod_sofia_globals.msg_queue, de);
}
static void set_call_id(private_object_t *tech_pvt, sip_t const *sip)
{
if (!tech_pvt->call_id && tech_pvt->session && tech_pvt->channel && sip && sip->sip_call_id && sip->sip_call_id->i_id) {
tech_pvt->call_id = switch_core_session_strdup(tech_pvt->session, sip->sip_call_id->i_id);
switch_channel_set_variable(tech_pvt->channel, "sip_call_id", tech_pvt->call_id);
}
}
void sofia_event_callback(nua_event_t event,
int status,
@@ -1707,16 +1717,22 @@ void sofia_event_callback(nua_event_t event,
if ((session = switch_core_session_locate(sofia_private->uuid))) {
private_object_t *tech_pvt = switch_core_session_get_private(session);
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "detaching session %s\n", sofia_private->uuid);
tech_pvt->sofia_private = NULL;
tech_pvt->nh = NULL;
sofia_set_flag(tech_pvt, TFLAG_BYE);
switch_mutex_lock(profile->flag_mutex);
switch_core_hash_insert(profile->chat_hash, tech_pvt->call_id, strdup(switch_core_session_get_uuid(session)));
switch_mutex_unlock(profile->flag_mutex);
switch_core_session_rwunlock(session);
set_call_id(tech_pvt, sip);
if (!zstr(tech_pvt->call_id)) {
tech_pvt->sofia_private = NULL;
tech_pvt->nh = NULL;
sofia_set_flag(tech_pvt, TFLAG_BYE);
switch_mutex_lock(profile->flag_mutex);
switch_core_hash_insert(profile->chat_hash, tech_pvt->call_id, strdup(switch_core_session_get_uuid(session)));
switch_mutex_unlock(profile->flag_mutex);
switch_core_session_rwunlock(session);
} else {
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
}
}
}
goto end;
@@ -1802,9 +1818,25 @@ void sofia_event_callback(nua_event_t event,
} else {
free(uuid);
uuid = NULL;
sip = NULL;
}
}
}
if (!sip || !sip->sip_call_id || zstr(sip->sip_call_id->i_id)) {
nua_respond(nh, 503, "INVALID INVITE", TAG_END());
nua_destroy_event(de->event);
su_free(nh->nh_home, de);
switch_mutex_lock(profile->flag_mutex);
profile->queued_events--;
switch_mutex_unlock(profile->flag_mutex);
nua_handle_unref(nh);
nua_stack_unref(nua);
goto end;
}
if (sofia_test_pflag(profile, PFLAG_CALLID_AS_UUID)) {
session = switch_core_session_request_uuid(sofia_endpoint_interface, SWITCH_CALL_DIRECTION_INBOUND, SOF_NONE, NULL, sip->sip_call_id->i_id);
@@ -1827,13 +1859,8 @@ void sofia_event_callback(nua_event_t event,
}
sofia_glue_attach_private(session, profile, tech_pvt, channel_name);
if (!tech_pvt->call_id && sip->sip_call_id && sip->sip_call_id->i_id) {
switch_channel_t *channel = switch_core_session_get_channel(session);
tech_pvt->call_id = switch_core_session_strdup(session, sip->sip_call_id->i_id);
switch_channel_set_variable(channel, "sip_call_id", tech_pvt->call_id);
}
set_call_id(tech_pvt, sip);
} else {
nua_respond(nh, 503, "Maximum Calls In Progress", SIPTAG_RETRY_AFTER_STR("300"), TAG_END());
nua_destroy_event(de->event);
+15 -6
View File
@@ -833,12 +833,14 @@ void sofia_glue_tech_prepare_codecs(private_object_t *tech_pvt)
if (!(codec_string = switch_channel_get_variable(tech_pvt->channel, "codec_string"))) {
codec_string = sofia_glue_get_codec_string(tech_pvt);
if (codec_string && *codec_string == '=') {
codec_string++;
goto ready;
}
}
if (codec_string && *codec_string == '=') {
codec_string++;
goto ready;
}
if ((ocodec = switch_channel_get_variable(tech_pvt->channel, SWITCH_ORIGINATOR_CODEC_VARIABLE))) {
if (!codec_string || sofia_test_pflag(tech_pvt->profile, PFLAG_DISABLE_TRANSCODING)) {
codec_string = ocodec;
@@ -871,6 +873,7 @@ void sofia_glue_check_video_codecs(private_object_t *tech_pvt)
int i;
tech_pvt->video_count = 0;
for (i = 0; i < tech_pvt->num_codecs; i++) {
if (tech_pvt->codecs[i]->codec_type == SWITCH_CODEC_TYPE_VIDEO) {
tech_pvt->video_count++;
}
@@ -5135,6 +5138,8 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, const char *r_s
if (mimp) {
char tmp[50];
const char *mirror = switch_channel_get_variable(tech_pvt->channel, "sip_mirror_remote_audio_codec_payload");
tech_pvt->rm_encoding = switch_core_session_strdup(session, (char *) map->rm_encoding);
tech_pvt->iananame = switch_core_session_strdup(session, (char *) mimp->iananame);
tech_pvt->pt = (switch_payload_t) map->rm_pt;
@@ -5152,7 +5157,9 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, const char *r_s
switch_channel_set_variable(tech_pvt->channel, SWITCH_REMOTE_MEDIA_PORT_VARIABLE, tmp);
tech_pvt->audio_recv_pt = (switch_payload_t)map->rm_pt;
if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND && !sofia_test_flag(tech_pvt, TFLAG_REINVITE)) {
if (!switch_true(mirror) &&
switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND &&
(!sofia_test_flag(tech_pvt, TFLAG_REINVITE) || sofia_test_pflag(tech_pvt->profile, PFLAG_RENEG_ON_REINVITE))) {
sofia_glue_get_offered_pt(tech_pvt, mimp, &tech_pvt->audio_recv_pt);
}
@@ -5275,6 +5282,8 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, const char *r_s
if (mimp) {
if ((tech_pvt->video_rm_encoding = switch_core_session_strdup(session, (char *) rm_encoding))) {
char tmp[50];
const char *mirror = switch_channel_get_variable(tech_pvt->channel, "sip_mirror_remote_video_codec_payload");
tech_pvt->video_pt = (switch_payload_t) map->rm_pt;
tech_pvt->video_rm_rate = map->rm_rate;
tech_pvt->video_codec_ms = mimp->microseconds_per_packet / 1000;
@@ -5292,7 +5301,7 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, const char *r_s
tech_pvt->video_recv_pt = (switch_payload_t)map->rm_pt;
if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) {
if (!switch_true(mirror) && switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) {
sofia_glue_get_offered_pt(tech_pvt, mimp, &tech_pvt->video_recv_pt);
}
@@ -139,16 +139,13 @@ namespace FreeSWITCH.Native
// The delegate needs to be stored so it doesn't get GC'd, so we can't just return GetFunctionPointerForDelegate right away.
/// <summary>Wraps a nice handler into a delegate suitable for reverse P/Invoke. This only currently works well for hangup/reporting handlers.</summary>
public static switch_state_handler_t_delegate CreateStateHandlerDelegate(Action<ManagedSession> handler) {
public static switch_state_handler_t_delegate CreateStateHandlerDelegate(ManagedSession sess, Action<ManagedSession> handler)
{
// We create a ManagedSession on top of the session so callbacks can use it "nicely"
// Then we sort of dispose it.
switch_state_handler_t_delegate del = ptr => {
using (var sess = new ManagedSession(new SWIGTYPE_p_switch_core_session(ptr, false))) {
handler(sess);
sess.SetAutoHangup(false);
sess.destroy();
return switch_status_t.SWITCH_STATUS_SUCCESS;
}
};
return del;
}
@@ -187,7 +184,7 @@ namespace FreeSWITCH.Native
var bleg = new ManagedSession();
bleg.originate_ondestroy_delegate = bleg.originate_ondestroy_method;
bleg.originate_onhangup_delegate = CreateStateHandlerDelegate(sess_b => {
bleg.originate_onhangup_delegate = CreateStateHandlerDelegate(bleg, sess_b => {
if (onHangup != null) {
onHangup(sess_b);
}