add management interface and some rtp goodies

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4464 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale committed 2007-03-07 18:34:22 +00:00
1 parent 30a9513b5a
commit 5131ee1cae
12 files changed
+242 -24

No files matched your search

@@ -753,6 +753,8 @@ static int activate_rtp(struct private_object *tech_pvt)
flags |= SWITCH_RTP_FLAG_USE_TIMER;
}
flags |= SWITCH_RTP_FLAG_AUTO_CNG;
if (!(tech_pvt->rtp_session = switch_rtp_new(tech_pvt->profile->ip,
tech_pvt->local_port,
tech_pvt->remote_ip,
@@ -1357,7 +1359,7 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc
samples = frames * tech_pvt->read_codec.implementation->samples_per_frame;
tech_pvt->timestamp_send += samples;
if (switch_rtp_write_frame(tech_pvt->rtp_session, frame, tech_pvt->timestamp_send) < 0) {
if (switch_rtp_write_frame(tech_pvt->rtp_session, frame, 0) < 0) {
terminate_session(&session, __LINE__, SWITCH_CAUSE_NORMAL_CLEARING);
return SWITCH_STATUS_FALSE;
}
+40 -2
View File
@@ -252,6 +252,7 @@ struct sofia_profile {
su_root_t *s_root;
sip_alias_node_t *aliases;
switch_payload_t te;
switch_payload_t cng_pt;
uint32_t codec_flags;
switch_mutex_t *ireg_mutex;
switch_mutex_t *oreg_mutex;
@@ -319,6 +320,8 @@ struct private_object {
switch_mutex_t *flag_mutex;
switch_payload_t te;
switch_payload_t bte;
switch_payload_t cng_pt;
switch_payload_t bcng_pt;
nua_handle_t *nh;
nua_handle_t *nh2;
su_home_t *home;
@@ -747,6 +750,14 @@ static void set_local_sdp(private_object_t *tech_pvt, char *ip, uint32_t port, c
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %d", tech_pvt->te);
}
if (tech_pvt->read_codec.implementation->samples_per_second == 8000) {
tech_pvt->cng_pt = SWITCH_RTP_CNG_PAYLOAD;
}
if (tech_pvt->cng_pt) {
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %d", tech_pvt->cng_pt);
}
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "\n");
if (tech_pvt->rm_encoding) {
@@ -776,6 +787,8 @@ static void set_local_sdp(private_object_t *tech_pvt, char *ip, uint32_t port, c
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=rtpmap:%d telephone-event/8000\na=fmtp:%d 0-16\n", tech_pvt->te, tech_pvt->te);
}
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=rtpmap:%d CN/%d\n", tech_pvt->cng_pt, tech_pvt->read_codec.implementation->samples_per_second);
if (ptime) {
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "a=ptime:%d\n", ptime);
}
@@ -870,9 +883,16 @@ static void attach_private(switch_core_session_t *session,
} else {
tech_pvt->te = profile->te;
}
if (tech_pvt->bcng_pt) {
tech_pvt->cng_pt = tech_pvt->bcng_pt;
} else {
tech_pvt->cng_pt = profile->cng_pt;
}
tech_pvt->session = session;
tech_pvt->home = su_home_new(sizeof(*tech_pvt->home));
switch_core_session_set_private(session, tech_pvt);
@@ -1543,6 +1563,10 @@ static switch_status_t activate_rtp(private_object_t *tech_pvt)
flags |= SWITCH_RTP_FLAG_PASS_RFC2833;
}
if (tech_pvt->cng_pt) {
flags |= SWITCH_RTP_FLAG_AUTO_CNG;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "RTP [%s] %s:%d->%s:%d codec: %u ms: %d\n",
switch_channel_get_name(channel),
tech_pvt->local_sdp_audio_ip,
@@ -1602,6 +1626,12 @@ static switch_status_t activate_rtp(private_object_t *tech_pvt)
switch_channel_get_name(switch_core_session_get_channel(tech_pvt->session)),
vad_in ? "in" : "", vad_out ? "out" : "");
}
switch_rtp_set_telephony_event(tech_pvt->rtp_session, tech_pvt->te);
if (tech_pvt->cng_pt) {
switch_rtp_set_cng_pt(tech_pvt->rtp_session, tech_pvt->cng_pt);
}
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "RTP REPORTS ERROR: [%s]\n", err);
terminate_session(&tech_pvt->session, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER, __LINE__);
@@ -1881,7 +1911,8 @@ static switch_status_t sofia_write_frame(switch_core_session_t *session, switch_
#endif
tech_pvt->timestamp_send += samples;
switch_rtp_write_frame(tech_pvt->rtp_session, frame, tech_pvt->timestamp_send);
//switch_rtp_write_frame(tech_pvt->rtp_session, frame, tech_pvt->timestamp_send);
switch_rtp_write_frame(tech_pvt->rtp_session, frame, 0);
switch_clear_flag_locked(tech_pvt, TFLAG_WRITING);
return status;
@@ -2347,6 +2378,7 @@ static switch_call_cause_t sofia_outgoing_channel(switch_core_session_t *session
ctech_pvt = switch_core_session_get_private(session);
assert(ctech_pvt != NULL);
tech_pvt->bte = ctech_pvt->te;
tech_pvt->bcng_pt = ctech_pvt->cng_pt;
}
}
@@ -5181,6 +5213,8 @@ static switch_status_t config_sofia(int reload)
switch_set_flag(profile, TFLAG_LATE_NEGOTIATION);
} else if (!strcasecmp(var, "rfc2833-pt")) {
profile->te = (switch_payload_t) atoi(val);
} else if (!strcasecmp(var, "cng-pt")) {
profile->cng_pt = (switch_payload_t) atoi(val);
} else if (!strcasecmp(var, "sip-port")) {
profile->sip_port = atoi(val);
} else if (!strcasecmp(var, "vad")) {
@@ -5270,6 +5304,10 @@ static switch_status_t config_sofia(int reload)
}
}
if (!profile->cng_pt) {
profile->cng_pt = 127;
}
if (!profile->sipip) {
profile->sipip = switch_core_strdup(profile->pool, globals.guess_ip);
}
+64 -11
View File
@@ -197,13 +197,13 @@ abyss_bool HandleHook(TSession *r)
return TRUE;
}
#define CMDLEN 1024 * 256
static xmlrpc_value *freeswitch_api(xmlrpc_env *const envP, xmlrpc_value *const paramArrayP, void *const userData)
{
char *command, *arg;
char *retbuf = malloc(CMDLEN);
switch_stream_handle_t stream = {0};
xmlrpc_value *val;
xmlrpc_value *val = NULL;
/* Parse our argument array. */
xmlrpc_decompose_value(envP, paramArrayP, "(ss)", &command, &arg);
@@ -211,16 +211,67 @@ static xmlrpc_value *freeswitch_api(xmlrpc_env *const envP, xmlrpc_value *const
return NULL;
}
memset(retbuf, 0, CMDLEN);
stream.data = retbuf;
stream.end = stream.data;
stream.data_size = CMDLEN;
stream.write_function = switch_console_stream_write;
switch_api_execute(command, arg, NULL, &stream);
SWITCH_STANDARD_STREAM(stream);
if (switch_api_execute(command, arg, NULL, &stream) == SWITCH_STATUS_SUCCESS) {
/* Return our result. */
val = xmlrpc_build_value(envP, "s", stream.data);
free(stream.data);
} else {
val = xmlrpc_build_value(envP, "s", "ERROR!");
}
return val;
}
static xmlrpc_value *freeswitch_man(xmlrpc_env *const envP, xmlrpc_value *const paramArrayP, void *const userData)
{
char *oid, *relative_oid, *s_action, *data;
char buf[SWITCH_MAX_MANAGEMENT_BUFFER_LEN] = "";
switch_management_action_t action = SMA_NONE;
switch_stream_handle_t stream = {0};
xmlrpc_value *val;
/* Parse our argument array. */
xmlrpc_decompose_value(envP, paramArrayP, "(sss)", &oid, &s_action, &data);
if (envP->fault_occurred) {
return NULL;
}
if (!strncasecmp(oid, FREESWITCH_MIB, strlen(FREESWITCH_MIB))) {
relative_oid = oid + strlen(FREESWITCH_MIB);
} else {
relative_oid = oid;
}
if (!switch_strlen_zero(data)) {
switch_copy_string(buf, data, sizeof(buf));
}
if (!strcasecmp(s_action, "get")) {
action = SMA_GET;
} else if (!strcasecmp(s_action, "set")) {
action = SMA_SET;
}
if (action) {
if (switch_core_management_exec(relative_oid, action, buf, sizeof(buf)) == SWITCH_STATUS_SUCCESS) {
if (action == SMA_SET) {
if (switch_strlen_zero(buf)) {
snprintf(buf, sizeof(buf), "OK\n");
}
}
} else {
if (switch_strlen_zero(buf)) {
snprintf(buf, sizeof(buf), "ERROR\n");
}
}
} else {
snprintf(buf, sizeof(buf), "Invalid Action %s\n", s_action);
}
/* Return our result. */
val = xmlrpc_build_value(envP, "s", retbuf);
free(retbuf);
val = xmlrpc_build_value(envP, "s", buf);
return val;
}
@@ -240,6 +291,8 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
xmlrpc_registry_add_method(&env, registryP, NULL, "freeswitch.api", &freeswitch_api, NULL);
xmlrpc_registry_add_method(&env, registryP, NULL,"freeswitch_api", &freeswitch_api, NULL);
xmlrpc_registry_add_method(&env, registryP, NULL, "freeswitch.management", &freeswitch_man, NULL);
xmlrpc_registry_add_method(&env, registryP, NULL,"freeswitch_management", &freeswitch_man, NULL);
MIMETypeInit();
MIMETypeAdd("text/html", "html");