Module: sip-router
Branch: carstenbock/rtpproxy
Commit: ac84acd54496dec044b2c27ddf80139432f9ae28
URL:
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=ac84acd…
Author: Carsten Bock <lists(a)bock.info>
Committer: Carsten Bock <lists(a)bock.info>
Date: Wed Aug 18 21:27:30 2010 +0200
- added support for the retrieval of RTP-Statistics through $rtpstat
- added support for sending a timeout socket towards the RTP-Proxy (for timeout
notifications)
---
modules_k/rtpproxy/doc/rtpproxy_admin.xml | 42 +++++++++++++-
modules_k/rtpproxy/rtpproxy.c | 88 ++++++++++++++++++++++++++++-
2 files changed, 128 insertions(+), 2 deletions(-)
diff --git a/modules_k/rtpproxy/doc/rtpproxy_admin.xml
b/modules_k/rtpproxy/doc/rtpproxy_admin.xml
index 671dff1..f23bc58 100644
--- a/modules_k/rtpproxy/doc/rtpproxy_admin.xml
+++ b/modules_k/rtpproxy/doc/rtpproxy_admin.xml
@@ -232,7 +232,29 @@ modparam("rtpproxy", "nortpproxy_str",
"a=sdpmangled:yes\r\n")
</example>
</section>
</section>
-
+ <section>
+ <title><varname>timeout_socket</varname> (string)</title>
+ <para>
+ The parameter sets timeout socket, which is transmitted to the RTP-Proxy.
+ </para>
+ <para>
+ If it is an empty string, no timeout socket will be transmitted to the RTP-Proxy.
+ </para>
+ <para>
+ <emphasis>
+ Default value is <quote></quote>.
+ </emphasis>
+ </para>
+ <example>
+ <title>Set <varname>timeout_socket</varname> parameter</title>
+ <programlisting format="linespecific">
+...
+modparam("nathelper", "timeout_socket",
"http://127.0.0.1:8000/RPC2")
+...
+</programlisting>
+ </example>
+ </section>
+ </section>
<section>
<title>Exported Functions</title>
@@ -589,6 +611,24 @@ start_recording();
<section>
<title>Exported Pseudo Variables</title>
+ <section>
+ <title><function
moreinfo="none">$rtpstart</function></title>
+ <para>
+ Returns the RTP-Statistics from the RTP-Proxy. The RTP-Statistics from the RTP-Proxy
+ are provided as a string and it does contain several packet-counters. The statistics
+ must be retrieved before the session is deleted (before unforce_rtpproxy).
+ </para>
+
+ <example>
+ <title>$rtpstat-Usage</title>
+ <programlisting format="linespecific">
+...
+ append_hf("X-RTP-Statistics: $rtpstat\r\n");
+...
+ </programlisting>
+ </example>
+ </section>
+
</section>
<section>
diff --git a/modules_k/rtpproxy/rtpproxy.c b/modules_k/rtpproxy/rtpproxy.c
index 4303844..8f68a0f 100644
--- a/modules_k/rtpproxy/rtpproxy.c
+++ b/modules_k/rtpproxy/rtpproxy.c
@@ -306,6 +306,9 @@ static int mod_init(void);
static int child_init(int);
static void mod_destroy(void);
+/* Pseudo-Variables */
+static int pv_get_rtpstat_f(struct sip_msg *, pv_param_t *, pv_value_t *);
+
/*mi commands*/
static struct mi_root* mi_enable_rtp_proxy(struct mi_root* cmd_tree,
void* param );
@@ -337,6 +340,8 @@ static int *rtpp_socks = 0;
/*0-> disabled, 1 ->enabled*/
unsigned int *natping_state=0;
+static str timeout_socket_str = {0, 0};
+
static cmd_export_t cmds[] = {
{"set_rtp_proxy_set", (cmd_function)set_rtp_proxy_set_f, 1,
fixup_set_id, 0,
@@ -390,6 +395,8 @@ static cmd_export_t cmds[] = {
};
static pv_export_t mod_pvs[] = {
+ {{"rtpstat", (sizeof("rtpstat")-1)}, /* RTP-Statistics */
+ PVT_OTHER, pv_get_rtpstat_f, 0, 0, 0, 0, 0},
{{0, 0}, 0, 0, 0, 0, 0, 0, 0}
};
@@ -400,6 +407,7 @@ static param_export_t params[] = {
{"rtpproxy_disable_tout", INT_PARAM, &rtpproxy_disable_tout },
{"rtpproxy_retr", INT_PARAM, &rtpproxy_retr },
{"rtpproxy_tout", INT_PARAM, &rtpproxy_tout },
+ {"timeout_socket_str", STR_PARAM, &timeout_socket_str.s },
{0, 0, 0}
};
@@ -854,9 +862,17 @@ mod_init(void)
if(rtpp_strings[i])
pkg_free(rtpp_strings[i]);
}
+ if (timeout_socket_str.s==NULL || timeout_socket_str.s[0]==0) {
+ timeout_socket_str.len = 0;
+ timeout_socket_str.s = NULL;
+ } else {
+ timeout_socket_str.len = strlen(timeout_socket_str.s);
+ }
+
if (rtpp_strings)
pkg_free(rtpp_strings);
+
return 0;
}
@@ -1799,7 +1815,11 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, int
offer)
{NULL, 0}, /* to_tag */
{";", 1}, /* separator */
{NULL, 0} /* medianum */
+ {" ", 1}, /* separator */
+ {NULL, 0}, /* Timeout-Socket */
};
+ int iovec_param_count;
+
char *c1p, *c2p, *bodylimit, *o1p;
char medianum_buf[20];
int medianum, media_multi;
@@ -2151,7 +2171,17 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* str2, int
offer)
} else {
v[3].iov_len = 0;
}
- cp = send_rtpp_command(node, v, (to_tag.len > 0) ? 18 : 14);
+ if (to_tag.len > 0) {
+ iovec_param_count = 18;
+ } else {
+ iovec_param_count = 14;
+ if (timeout_socket_str.len > 0) {
+ iovec_param_count = 16;
+ STR2IOVEC(timeout_socket_str, v[15]);
+ }
+ }
+
+ cp = send_rtpp_command(node, v, iovec_param_count);
} while (cp == NULL);
LM_DBG("proxy reply: %s\n", cp);
/* Parse proxy reply to <argc,argv> */
@@ -2389,3 +2419,59 @@ static int start_recording_f(struct sip_msg* msg, char *foo, char
*bar)
return 1;
}
+/*
+ * Returns the current RTP-Statistics from the RTP-Proxy
+ */
+static int
+pv_get_rtpstat_f(struct sip_msg *msg, pv_param_t *param,
+ pv_value_t *res)
+{
+ str ret_val = {0, 0};
+ int nitems;
+ str callid = {0, 0};
+ str from_tag = {0, 0};
+ str to_tag = {0, 0};
+ struct rtpp_node *node;
+ struct iovec v[1 + 4 + 3 + 1] = {{NULL, 0}, {"Q", 1}, {" ", 1},
{NULL, 0}, {" ", 1}, {NULL, 0}, {";1 ", 3}, {";1", }, {NULL,
0}};
+
+ if (get_callid(msg, &callid) == -1 || callid.len == 0) {
+ LM_ERR("can't get Call-Id field\n");
+ return -1;
+ }
+ if (get_to_tag(msg, &to_tag) == -1) {
+ LM_ERR("can't get To tag\n");
+ return -1;
+ }
+ if (get_from_tag(msg, &from_tag) == -1 || from_tag.len == 0) {
+ LM_ERR("can't get From tag\n");
+ return -1;
+ }
+ if(msg->id != current_msg_id){
+ selected_rtpp_set = default_rtpp_set;
+ }
+
+ STR2IOVEC(callid, v[3]);
+ STR2IOVEC(from_tag, v[5]);
+ STR2IOVEC(to_tag, v[7]);
+ node = select_rtpp_node(callid, 1);
+ if (!node) {
+ LM_ERR("no available proxies\n");
+ return -1;
+ }
+ nitems = 8;
+ if (msg->first_line.type == SIP_REPLY) {
+ if (to_tag.len == 0)
+ return -1;
+ STR2IOVEC(to_tag, v[5]);
+ STR2IOVEC(from_tag, v[7]);
+ } else {
+ STR2IOVEC(from_tag, v[5]);
+ STR2IOVEC(to_tag, v[7]);
+ if (to_tag.len <= 0)
+ nitems = 6;
+ }
+ ret_val.s = send_rtpp_command(node, v, nitems);
+ ret_val.len = strlen(ret_val.s);
+ return pv_get_strval(msg, param, res, &ret_val);
+}
+