← Back to team overview

rohc team mailing list archive

Re: RTP compare port python binding

 

Hi,

> Yes I follow it but when I try to include/modify the code in function
> "rohc_comp_rtp_cb" at file rohc_helpers.h to include additional ports
> it seems it doesn't works since rohc give me a bad profile error at
> run time. My setup works for the list of 6 ports you have there, that
> is,
> 
> default_rtp_ports[] = { 1234, 36780, 33238, 5020, 5002, 5006 }
> 
> but if I tried add or even try to modify the array and it doesn't
> work afetr build/install of python binding. (I already modify the
> index value). I also try to recompile rohc before the python binding.
> 
> The modification I did for this is 
> 
> default_rtp_ports[] = { 10050, 36780, 33238, 5020, 5002, 5006 } with
> same index
> 
> or 
> 
> default_rtp_ports[] = { 1234, 36780, 33238, 5020, 5002, 5006, 10050}
> with index=7

Looks ok. Did you re-build the Python module? To be sure that
everything is re-built, you may remove entirely the build subdir.

$ cd contrib/python/
$ rm -rf build
$ python setup.py build

Then run your test.


> I endup trying this because what I try initially didn't work, I
> actually wanted to add a function that modify the array of udp ports,
> a function that I could call from python, I saw a similar function in
> older version of rohc but it's now deprecated and actually it was a c
> function.  If my function prototype is 
> 
> bool rohc_comp_add_rtp_port(const unsigned int port);
> 
> I understand I need to add a line like the following to rohc.i file 
> 
> %constant bool rohc_comp_add_rtp_port(const unsigned int);
> 
> but again basic stuff haven't work for me. Perhaps I am missing
> something else when trying to modify the udp port?
> 
> I am using rohc 2, not sure which version but I am working with git
> sources.

Ok, I see. Please try the attached patch. Let me know if it solves your
problem.

Regards,
Didier
diff --git a/contrib/python/example.py b/contrib/python/example.py
index 9b9e9bf..55e19d5 100755
--- a/contrib/python/example.py
+++ b/contrib/python/example.py
@@ -109,6 +109,13 @@ for i in range(0, packets_nr):
 print("%i %i-byte RTP packets created with %i-byte payload" \
       % (len(uncomp_pkts), len(uncomp_pkts[0]), len(RTP_PAYLOAD)))
 
+# setup the list of UDP ports for RTP streams
+for udp_port in [1234, 36780, 33238, 5020, 5002, 5006]:
+    ret = rohc_comp_add_rtp_port(udp_port)
+    if ret is not True:
+        print("failed to add the UDP port %i for RTP streams" % udp_port)
+        sys.exit(1)
+
 # create one ROHC compressor
 print("create ROHC compressor")
 comp = RohcCompressor(cid_type=ROHC_LARGE_CID, profiles=[ROHC_PROFILE_RTP], \
diff --git a/contrib/python/rohc.i b/contrib/python/rohc.i
index b56c322..074b3f2 100644
--- a/contrib/python/rohc.i
+++ b/contrib/python/rohc.i
@@ -32,6 +32,7 @@
 #include "rohc/rohc_comp.h"
 #include "rohc/rohc_decomp.h"
 
+#include "rohc_helpers2.h"
 #include "rohc_helpers.h"
 %}
 
@@ -99,6 +100,8 @@
 %include "rohc/rohc_comp.h"
 %include "rohc/rohc_decomp.h"
 
+%include "rohc_helpers2.h"
+
 %constant void print_rohc_traces(void *const, const rohc_trace_level_t, const rohc_trace_entity_t, const int, const char *const, ...);
 %constant int gen_false_random_num(const struct rohc_comp *const, void *const);
 %constant bool rohc_comp_rtp_cb(const unsigned char *const, const unsigned char *const, const unsigned char *const, const unsigned int, void *const rtp_private);
diff --git a/contrib/python/rohc_helpers.h b/contrib/python/rohc_helpers.h
index 746d188..508c149 100644
--- a/contrib/python/rohc_helpers.h
+++ b/contrib/python/rohc_helpers.h
@@ -95,8 +95,6 @@ static bool rohc_comp_rtp_cb(const unsigned char *const ip __attribute__((unused
                              const unsigned int payload_size __attribute__((unused)),
                              void *const rtp_private __attribute__((unused)))
 {
-	const size_t default_rtp_ports_nr = 6;
-	unsigned int default_rtp_ports[] = { 1234, 36780, 33238, 5020, 5002, 5006 };
 	uint16_t udp_dport;
 	bool is_rtp = false;
 	size_t i;
@@ -111,9 +109,9 @@ static bool rohc_comp_rtp_cb(const unsigned char *const ip __attribute__((unused
 
 	/* is the UDP destination port in the list of ports reserved for RTP
 	 * traffic by default (for compatibility reasons) */
-	for(i = 0; i < default_rtp_ports_nr; i++)
+	for(i = 0; i < RTP_PORTS_MAX_NR; i++)
 	{
-		if(ntohs(udp_dport) == default_rtp_ports[i])
+		if(rtp_ports[i] != 0 && ntohs(udp_dport) == rtp_ports[i])
 		{
 			is_rtp = true;
 			break;
diff --git a/contrib/python/rohc_helpers2.h b/contrib/python/rohc_helpers2.h
new file mode 100644
index 0000000..3270a8f
--- /dev/null
+++ b/contrib/python/rohc_helpers2.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2016 Didier Barvaux
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+/**
+ * @file    rohc_helpers2.h
+ * @brief   Helpers for the python binding of the ROHC library
+ * @author  Didier Barvaux <didier@xxxxxxxxxxx>
+ */
+
+#ifndef ROHC_HELPERS2_H
+#define ROHC_HELPERS2_H
+
+
+#define RTP_PORTS_MAX_NR 10U
+static unsigned int rtp_ports[RTP_PORTS_MAX_NR] = { 0 };
+
+
+/**
+ * @brief Add new UDP port for RTP streams
+ *
+ * @param new_port  The UDP port to add
+ * @return          true if port was successfully added,
+ *                  false if the list of ports is full
+ */
+bool rohc_comp_add_rtp_port(const unsigned int new_port)
+{
+	size_t i;
+
+	/* find the first free slot in the list and record the new port there */
+	for(i = 0; i < RTP_PORTS_MAX_NR; i++)
+	{
+		if(rtp_ports[i] == 0)
+		{
+			rtp_ports[i] = new_port;
+			return true;
+		}
+	}
+
+	/* list is full */
+	return false;
+}
+
+
+#endif /* ROHC_HELPERS2_H */
+
diff --git a/contrib/python/test_non_regression.py b/contrib/python/test_non_regression.py
index 2655022..9f041fc 100755
--- a/contrib/python/test_non_regression.py
+++ b/contrib/python/test_non_regression.py
@@ -321,6 +321,13 @@ def remove_padding__str(pkt):
 
 def create_comp_decomp(cid_type, cid_max, wlsb_width, profiles, verbose):
 
+    # setup the list of UDP ports for RTP streams
+    for udp_port in [1234, 36780, 33238, 5020, 5002, 5006]:
+        ret = rohc_comp_add_rtp_port(udp_port)
+        if ret is not True:
+            print("failed to add the UDP port %i for RTP streams" % udp_port)
+            return (False, None, None, None, None)
+
     print("\ncreate ROHC compressor 1")
     comp1 = RohcCompressor(cid_type, cid_max, wlsb_width, profiles, verbose)
     if comp1 is None:

Attachment: pgpmkux75KVw_.pgp
Description: Signature digitale OpenPGP


Follow ups

References