Module: sip-router
Branch: rfuchs/rtpproxy-ng
Commit: eba7dcbe6b3ba7b88c0fa0b231cb265a68995e47
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=eba7dcbe6b3ba7b88c0fa0b231cb265a68995e47

Author: Richard Fuchs <[email protected]>
Committer: Richard Fuchs <[email protected]>
Date:   Thu Jul 11 15:36:54 2013 -0400

rtpproxy-ng: implement $rtpstat and document start_recording()

---

 modules/rtpproxy-ng/README                 |   43 +++++++---
 modules/rtpproxy-ng/doc/rtpproxy_admin.xml |   16 ++--
 modules/rtpproxy-ng/rtpproxy.c             |  123 +++++++++++++--------------
 3 files changed, 98 insertions(+), 84 deletions(-)

diff --git a/modules/rtpproxy-ng/README b/modules/rtpproxy-ng/README
index 6c33f36..3155db6 100644
--- a/modules/rtpproxy-ng/README
+++ b/modules/rtpproxy-ng/README
@@ -74,10 +74,11 @@ Richard Fuchs
               5.4. rtpproxy_destroy([flags])
               5.5. unforce_rtp_proxy()
               5.6. rtpproxy_manage([flags [, ip_address]])
+              5.7. start_recording()
 
         6. Exported Pseudo Variables
 
-              6.1. $rtpstart
+              6.1. $rtpstat
 
         7. MI Commands
 
@@ -98,9 +99,10 @@ Richard Fuchs
    1.8. rtpproxy_answer usage
    1.9. rtpproxy_destroy usage
    1.10. rtpproxy_manage usage
-   1.11. $rtpstat-Usage
-   1.12. nh_enable_rtpp usage
-   1.13. nh_show_rtpp usage
+   1.11. start_recording usage
+   1.12. $rtpstat Usage
+   1.13. nh_enable_rtpp usage
+   1.14. nh_show_rtpp usage
 
 Chapter 1. Admin Guide
 
@@ -129,10 +131,11 @@ Chapter 1. Admin Guide
         5.4. rtpproxy_destroy([flags])
         5.5. unforce_rtp_proxy()
         5.6. rtpproxy_manage([flags [, ip_address]])
+        5.7. start_recording()
 
    6. Exported Pseudo Variables
 
-        6.1. $rtpstart
+        6.1. $rtpstat
 
    7. MI Commands
 
@@ -278,6 +281,7 @@ modparam("rtpproxy-ng", "extra_id_pv", "$avp(extra_id)")
    5.4. rtpproxy_destroy([flags])
    5.5. unforce_rtp_proxy()
    5.6. rtpproxy_manage([flags [, ip_address]])
+   5.7. start_recording()
 
 5.1.  set_rtp_proxy_set(setid)
 
@@ -538,18 +542,31 @@ rtpproxy_destroy();
 rtpproxy_manage();
 ...
 
+5.7.  start_recording()
+
+   This function will send a signal to the RTP Proxy to record the RTP
+   stream on the RTP Proxy. This function is not supported by
+   ngcp-mediaproxy-ng at the moment!
+
+   This function can be used from REQUEST_ROUTE and ONREPLY_ROUTE.
+
+   Example 1.11. start_recording usage
+...
+start_recording();
+...
+
 6. Exported Pseudo Variables
 
-   6.1. $rtpstart
+   6.1. $rtpstat
 
-6.1. $rtpstart
+6.1. $rtpstat
 
-   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
+   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()).
 
-   Example 1.11. $rtpstat-Usage
+   Example 1.12. $rtpstat Usage
 ...
     append_hf("X-RTP-Statistics: $rtpstat\r\n");
 ...
@@ -572,7 +589,7 @@ rtpproxy_manage();
    NOTE: if a rtpproxy is defined multiple times (in the same or diferente
    sete), all of its instances will be enables/disabled.
 
-   Example 1.12.  nh_enable_rtpp usage
+   Example 1.13.  nh_enable_rtpp usage
 ...
 $ kamctl fifo nh_enable_rtpp udp:192.168.2.133:8081 0
 ...
@@ -584,7 +601,7 @@ $ kamctl fifo nh_enable_rtpp udp:192.168.2.133:8081 0
 
    No parameter.
 
-   Example 1.13.  nh_show_rtpp usage
+   Example 1.14.  nh_show_rtpp usage
 ...
 $ kamctl fifo nh_show_rtpp
 ...
diff --git a/modules/rtpproxy-ng/doc/rtpproxy_admin.xml 
b/modules/rtpproxy-ng/doc/rtpproxy_admin.xml
index 074beeb..9ad60c3 100644
--- a/modules/rtpproxy-ng/doc/rtpproxy_admin.xml
+++ b/modules/rtpproxy-ng/doc/rtpproxy_admin.xml
@@ -710,14 +710,15 @@ rtpproxy_manage();
            These functions can be used from REQUEST_ROUTE, ONREPLY_ROUTE.
        </para>
        </section>
+-->
        <section>
                <title>
                <function moreinfo="none">start_recording()</function>
                </title>
                <para>
-               This function will send a signal to the RTP-Proxy to record
-               the RTP stream on the RTP-Proxy.
-               <emphasis>This function is only supported by Sippy RTPproxy at 
the moment!</emphasis>
+               This function will send a signal to the RTP Proxy to record
+               the RTP stream on the RTP Proxy.
+               <emphasis>This function is not supported by ngcp-mediaproxy-ng 
at the moment!</emphasis>
                </para>
                <para>
                This function can be used from REQUEST_ROUTE and ONREPLY_ROUTE.
@@ -731,6 +732,7 @@ start_recording();
                </programlisting>
                </example>
        </section>
+<!--
        <section id="rtpproxy_stop_stream2uas">
        <title>
            <function>rtpproxy_stop_stream2uas(prompt_name, count)</function>
@@ -747,15 +749,15 @@ start_recording();
        <section>
                <title>Exported Pseudo Variables</title>
                <section>
-                       <title><function 
moreinfo="none">$rtpstart</function></title>
+                       <title><function 
moreinfo="none">$rtpstat</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
+                       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 
<function>unforce_rtpproxy()</function>).
                        </para>
 
                <example>
-               <title>$rtpstat-Usage</title>
+               <title>$rtpstat Usage</title>
                <programlisting format="linespecific">
 ...
     append_hf("X-RTP-Statistics: $rtpstat\r\n");
diff --git a/modules/rtpproxy-ng/rtpproxy.c b/modules/rtpproxy-ng/rtpproxy.c
index fe49329..7675cc8 100644
--- a/modules/rtpproxy-ng/rtpproxy.c
+++ b/modules/rtpproxy-ng/rtpproxy.c
@@ -283,13 +283,15 @@ enum rtpp_operation {
        OP_ANSWER,
        OP_DELETE,
        OP_START_RECORDING,
+       OP_QUERY,
 };
 
 static const char *command_strings[] = {
-       [1] = "offer",
-       [2] = "answer",
-       [3] = "delete",
-       [4] = "start recording",
+       [OP_OFFER]              = "offer",
+       [OP_ANSWER]             = "answer",
+       [OP_DELETE]             = "delete",
+       [OP_START_RECORDING]    = "start recording",
+       [OP_QUERY]              = "query",
 };
 
 static char *gencookie();
@@ -1364,6 +1366,23 @@ static int rtpp_function_call_simple(struct sip_msg 
*msg, enum rtpp_operation op
        return 1;
 }
 
+static bencode_item_t *rtpp_function_call_ok(bencode_buffer_t *bencbuf, struct 
sip_msg *msg,
+               enum rtpp_operation op, const char *flags_str, str *body) {
+       bencode_item_t *ret;
+
+       ret = rtpp_function_call(bencbuf, msg, op, flags_str, body);
+       if (!ret)
+               return NULL;
+
+       if (bencode_dictionary_get_strcmp(ret, "result", "ok")) {
+               LM_ERR("proxy didn't return \"ok\" result\n");
+               bencode_buffer_free(bencbuf);
+               return NULL;
+       }
+
+       return ret;
+}
+
 
 
 static int
@@ -1865,15 +1884,10 @@ force_rtp_proxy(struct sip_msg* msg, char* str1, char* 
str2, int offer, int forc
        str body, newbody;
        struct lump *anchor;
 
-       dict = rtpp_function_call(&bencbuf, msg, offer ? OP_OFFER : OP_ANSWER, 
str1, &body);
+       dict = rtpp_function_call_ok(&bencbuf, msg, offer ? OP_OFFER : 
OP_ANSWER, str1, &body);
        if (!dict)
                return -1;
 
-       if (bencode_dictionary_get_strcmp(dict, "result", "ok")) {
-               LM_ERR("proxy didn't return \"ok\" result\n");
-               goto error;
-       }
-
        if (!bencode_dictionary_get_str_dup(dict, "sdp", &newbody)) {
                LM_ERR("failed to extract sdp body from proxy reply\n");
                goto error;
@@ -1913,59 +1927,40 @@ static int
 pv_get_rtpstat_f(struct sip_msg *msg, pv_param_t *param,
                  pv_value_t *res)
 {
-#if 0
-    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 pv_get_null(msg, param, res);
-    }
-    if (get_to_tag(msg, &to_tag) == -1) {
-        LM_ERR("can't get To tag\n");
-               return pv_get_null(msg, param, res);
-    }
-    if (get_from_tag(msg, &from_tag) == -1 || from_tag.len == 0) {
-        LM_ERR("can't get From tag\n");
-               return pv_get_null(msg, param, res);
-    }
-    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);
-       if(ret_val.s==NULL)
-               return pv_get_null(msg, param, res);
-    ret_val.len = strlen(ret_val.s);
-    return pv_get_strval(msg, param, res, &ret_val);
-#else
-       return 1;
-#endif
+       bencode_buffer_t bencbuf;
+       bencode_item_t *dict, *tot, *in, *out;
+       static char buf[256];
+       str ret;
+
+       dict = rtpp_function_call_ok(&bencbuf, msg, OP_QUERY, NULL, NULL);
+       if (!dict)
+               return -1;
+
+       tot = bencode_dictionary_get_expect(dict, "totals", BENCODE_DICTIONARY);
+       in = bencode_dictionary_get_expect(tot, "input", BENCODE_DICTIONARY);
+       in = bencode_dictionary_get_expect(in, "rtp", BENCODE_DICTIONARY);
+       out = bencode_dictionary_get_expect(tot, "output", BENCODE_DICTIONARY);
+       out = bencode_dictionary_get_expect(out, "rtp", BENCODE_DICTIONARY);
+
+       if (!in || !out)
+               goto error;
+
+       ret.s = buf;
+       ret.len = snprintf(buf, sizeof(buf),
+                       "Input: %lli bytes, %lli packets, %lli errors; "
+                       "Output: %lli bytes, %lli packets, %lli errors",
+                       bencode_dictionary_get_integer(in, "bytes", -1),
+                       bencode_dictionary_get_integer(in, "packets", -1),
+                       bencode_dictionary_get_integer(in, "errors", -1),
+                       bencode_dictionary_get_integer(out, "bytes", -1),
+                       bencode_dictionary_get_integer(out, "packets", -1),
+                       bencode_dictionary_get_integer(out, "errors", -1));
+
+       bencode_buffer_free(&bencbuf);
+       return pv_get_strval(msg, param, res, &ret);
+
+error:
+       bencode_buffer_free(&bencbuf);
+       return -1;
 }
 


_______________________________________________
sr-dev mailing list
[email protected]
http://lists.sip-router.org/cgi-bin/mailman/listinfo/sr-dev

Reply via email to