missing crtp init in mod_freetdm.c -- start implementing media modify

This commit is contained in:
Mathieu Rene 2012-07-25 18:57:32 -04:00
parent f223b9a0bb
commit 898a183a0e
3 changed files with 69 additions and 19 deletions

View File

@ -178,6 +178,7 @@ static const char* channel_get_variable(switch_core_session_t *session, switch_e
ftdm_status_t ftdm_channel_from_event(ftdm_sigmsg_t *sigmsg, switch_core_session_t **sp);
void dump_chan(ftdm_span_t *span, uint32_t chan_id, switch_stream_handle_t *stream);
void dump_chan_xml(ftdm_span_t *span, uint32_t chan_id, switch_stream_handle_t *stream);
void ctdm_init(switch_loadable_module_interface_t *module_interface);
static switch_core_session_t *ftdm_channel_get_session(ftdm_channel_t *channel, int32_t id)
{
@ -5359,6 +5360,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_freetdm_load)
SWITCH_ADD_APP(app_interface, "disable_dtmf", "Disable DTMF Detection", "Disable DTMF Detection", disable_dtmf_function, "", SAF_NONE);
SWITCH_ADD_APP(app_interface, "enable_dtmf", "Enable DTMF Detection", "Enable DTMF Detection", enable_dtmf_function, "", SAF_NONE);
ctdm_init(*module_interface);
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}

View File

@ -88,19 +88,6 @@ switch_status_t megaco_activate_termination(mg_termination_t *term)
switch_status_t status = SWITCH_STATUS_SUCCESS;
char dialstring[100];
switch_call_cause_t cause;
if (!zstr(term->uuid)) {
/* A UUID is present, check if the channel still exists */
switch_core_session_t *session;
if ((session = switch_core_session_locate(term->uuid))) {
switch_core_session_rwunlock(session);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Channel [%s] already exists for termination [%s]\n", term->uuid, term->name);
return SWITCH_STATUS_SUCCESS;
}
/* The referenced channel doesn't exist anymore, clear it */
term->uuid = NULL;
}
switch_event_create(&var_event, SWITCH_EVENT_CLONE);
@ -126,14 +113,35 @@ switch_status_t megaco_activate_termination(mg_termination_t *term)
/* Set common variables on the channel */
switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, SWITCH_PARK_AFTER_BRIDGE_VARIABLE, "true");
if (!zstr(term->uuid)) {
/* A UUID is present, check if the channel still exists */
switch_core_session_t *session;
if ((session = switch_core_session_locate(term->uuid))) {
switch_event_add_header_string(var_event, SWITCH_STACK_BOTTOM, "command", "media_modify");
switch_core_session_receive_event(session, &var_event);
if (switch_ivr_originate(NULL, &session, &cause, dialstring, 0, NULL, NULL, NULL, NULL, var_event, 0, NULL) != SWITCH_CAUSE_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to instanciate termination [%s]: %s\n", term->name, switch_channel_cause2str(cause));
status = SWITCH_STATUS_FALSE;
goto done;
switch_core_session_rwunlock(session);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sent refresh to channel [%s], for termination [%s]\n", term->uuid, term->name);
return SWITCH_STATUS_SUCCESS;
}
/* The referenced channel doesn't exist anymore, clear it */
term->uuid = NULL;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Termination [%s] successfully instanciated as [%s] [%s]\n", term->name, dialstring, switch_core_session_get_uuid(session));
if (!zstr(term->uuid)) {
if (switch_ivr_originate(NULL, &session, &cause, dialstring, 0, NULL, NULL, NULL, NULL, var_event, 0, NULL) != SWITCH_CAUSE_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to instanciate termination [%s]: %s\n", term->name, switch_channel_cause2str(cause));
status = SWITCH_STATUS_FALSE;
goto done;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Termination [%s] successfully instanciated as [%s] [%s]\n", term->name, dialstring, switch_core_session_get_uuid(session));
}
switch_set_flag(term, MGT_ACTIVE);
@ -162,7 +170,7 @@ mg_termination_t *megaco_choose_termination(megaco_profile_t *profile, const cha
switch_snprintf(name, sizeof name, "%s/%d", profile->rtp_termination_id_prefix, term_id);
} else {
for (term = profile->physical_terminations; term; term = term->next) {
if (!strncasecmp(prefix, term->name, prefixlen) && !switch_test_flag(term, MGT_ALLOCATED)) {
if (!switch_test_flag(term, MGT_ALLOCATED) && !strncasecmp(prefix, term->name, prefixlen)) {
switch_set_flag(term, MGT_ALLOCATED);
return term;
}
@ -185,6 +193,7 @@ mg_termination_t *megaco_choose_termination(megaco_profile_t *profile, const cha
term->u.rtp.local_port = switch_rtp_request_port(term->u.rtp.local_addr);
term->u.rtp.codec = megaco_codec_str(profile->default_codec);
term->u.rtp.term_id = term_id;
term->u.rtp.ptime = 20;
term->name = switch_core_strdup(term->pool, name);
}

View File

@ -93,6 +93,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, switch_io_flag_t flags, int stream_id);
static switch_status_t channel_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg);
static switch_status_t channel_send_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf);
static switch_status_t channel_receive_event(switch_core_session_t *session, switch_event_t *event);
switch_state_handler_table_t crtp_state_handlers = {
.on_init = channel_on_init,
@ -104,6 +105,7 @@ switch_io_routines_t crtp_io_routines = {
.read_frame = channel_read_frame,
.write_frame = channel_write_frame,
.receive_message = channel_receive_message,
.receive_event = channel_receive_event,
.send_dtmf = channel_send_dtmf
};
@ -395,6 +397,42 @@ static switch_status_t channel_send_dtmf(switch_core_session_t *session, const s
return SWITCH_STATUS_SUCCESS;
}
static switch_bool_t compare_var(switch_event_t *event, switch_channel_t *channel, const char *varname)
{
const char *chan_val = switch_channel_get_variable_dup(channel, varname, SWITCH_FALSE, -1);
const char *event_val = switch_event_get_header(event, varname);
return strcasecmp(chan_val, event_val);
}
static switch_status_t channel_receive_event(switch_core_session_t *session, switch_event_t *event)
{
const char *command = switch_event_get_header(event, "command");
switch_channel_t *channel = switch_core_session_get_channel(session);
if (!zstr(command) && !strcasecmp(command, "media_modify")) {
/* Compare parameters */
if (compare_var(event, channel, kREMOTEADDR) ||
compare_var(event, channel, kREMOTEPORT) ||
compare_var(event, channel, kLOCALADDR) ||
compare_var(event, channel, kLOCALPORT)) {
/* We need to reset the rtp session */
}
if (compare_var(event, channel, kCODEC) ||
compare_var(event, channel, kPTIME) ||
compare_var(event, channel, kPT) ||
compare_var(event, channel, kRATE)) {
/* Reset codec */
}
} else {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Received unknown command [%s] in event.\n", !command ? "null" : command);
}
}
static switch_status_t channel_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg)
{
crtp_private_t *tech_pvt = NULL;