Change in mncc-python[master]: rtpsource: CTRL call rtp_create: add codec arg

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

laforge gerrit-no-reply at lists.osmocom.org
Fri May 1 14:28:35 UTC 2020


laforge has submitted this change. ( https://gerrit.osmocom.org/c/mncc-python/+/17979 )

Change subject: rtpsource: CTRL call rtp_create: add codec arg
......................................................................

rtpsource: CTRL call rtp_create: add codec arg

Instead of hardcoding FR in rtpsource, add an argument to set the codec
from mncc_mt_loadgen.py via CTRL call rtp_create. Hardcode FR in
mncc_mt_loadgen.py for now, a follow up patch will make it configurable
there, too.

Related: SYS#4924
Change-Id: If75e902b451d7e202a03e93afcd55bd24f517813
---
M mncc_mt_loadgen.py
M rtpsource/ctrl_if.c
M rtpsource/internal.h
M rtpsource/rtp_provider.c
M rtpsource/rtp_provider.h
M rtpsource/rtpsource.c
6 files changed, 60 insertions(+), 11 deletions(-)

Approvals:
  osmith: Verified
  laforge: Looks good to me, approved



diff --git a/mncc_mt_loadgen.py b/mncc_mt_loadgen.py
index 021d619..5f15e3b 100755
--- a/mncc_mt_loadgen.py
+++ b/mncc_mt_loadgen.py
@@ -80,7 +80,8 @@
 
     def on_receive(self, message):
         if message['type'] == 'rtp_create':
-            (res, var, val) = self._set_var('rtp_create', message['cname'])
+            val = '%s,%s' % (message['cname'], message['codec'])
+            (res, var, val) = self._set_var('rtp_create', val)
             v = val.split(',') # input looks like '1,127.23.23.23,37723'
             return {'cname': v[0], 'remote_host': v[1], 'remote_port': int(v[2])}
         elif message['type'] == 'rtp_connect':
@@ -113,7 +114,8 @@
         self.msisdn_called = msisdn_called
         self.msisdn_calling = msisdn_calling
         # allocate a RTP connection @ rtpsource
-        r = self.ctrl_act.ask({'type':'rtp_create', 'cname':self.callref})
+        codec = "GSM_FR"  # FIXME: make configurable
+        r = self.ctrl_act.ask({'type':'rtp_create', 'cname':self.callref, 'codec':codec})
         self.ext_rtp_host = r['remote_host']
         self.ext_rtp_port = r['remote_port']
         # start the MNCC call FSM
diff --git a/rtpsource/ctrl_if.c b/rtpsource/ctrl_if.c
index 708fb02..b021e26 100644
--- a/rtpsource/ctrl_if.c
+++ b/rtpsource/ctrl_if.c
@@ -21,27 +21,52 @@
 #include <osmocom/ctrl/control_cmd.h>
 
 #include "internal.h"
+#include "rtp_provider.h"
 
 CTRL_CMD_DEFINE_WO_NOVRF(rtp_create, "rtp_create");
 static int set_rtp_create(struct ctrl_cmd *cmd, void *data)
 {
 	struct rtp_connection *conn;
-	const char *cname = cmd->value;
+	const char *cname, *codec_str;
+	char *tmp, *saveptr;
+	enum codec_type codec;
+
+	tmp = talloc_strdup(cmd, cmd->value);
+	OSMO_ASSERT(tmp);
+
+	cname = strtok_r(tmp, ",", &saveptr);
+	codec_str = strtok_r(NULL, ",", &saveptr);
+
+	if (!cname || !codec_str) {
+		cmd->reply = "Format is cname,codec";
+		goto error;
+	}
 
 	if (find_connection_by_cname(g_rss, cname)) {
 		cmd->reply = "Connection already exists for cname";
-		return CTRL_CMD_ERROR;
+		goto error;
 	}
 
-	conn = create_connection(g_rss, cname);
+	codec = get_string_value(codec_type_names, codec_str);
+	if (codec < 0) {
+		cmd->reply = "Invalid codec name (try GSM_FR, GSM_EFR etc.)";
+		goto error;
+	}
+
+	conn = create_connection(g_rss, cname, codec);
 	if (!conn) {
 		cmd->reply = "Error creating RTP connection";
-		return CTRL_CMD_ERROR;
+		goto error;
 	}
 
 	/* Respond */
 	cmd->reply = talloc_asprintf(cmd, "%s,%s,%d", conn->cname, conn->local_host, conn->local_port);
+	talloc_free(tmp);
 	return CTRL_CMD_REPLY;
+
+error:
+	talloc_free(tmp);
+	return CTRL_CMD_ERROR;
 }
 
 CTRL_CMD_DEFINE_WO_NOVRF(rtp_connect, "rtp_connect");
diff --git a/rtpsource/internal.h b/rtpsource/internal.h
index a4501a2..35f12d0 100644
--- a/rtpsource/internal.h
+++ b/rtpsource/internal.h
@@ -4,6 +4,8 @@
 #include <osmocom/trau/osmo_ortp.h>
 #include <osmocom/ctrl/control_if.h>
 
+enum codec_type;
+
 enum {
 	DMAIN,
 };
@@ -36,7 +38,7 @@
 
 struct rtp_connection *find_connection_by_cname(struct rtpsource_state *rss, const char *cname);
 
-struct rtp_connection *create_connection(struct rtpsource_state *rss, const char *cname);
+struct rtp_connection *create_connection(struct rtpsource_state *rss, const char *cname, enum codec_type codec);
 
 int connect_connection(struct rtp_connection *conn, const char *remote_host,
 			uint16_t remote_port, uint8_t pt);
diff --git a/rtpsource/rtp_provider.c b/rtpsource/rtp_provider.c
index 0d2b9c6..7e12db3 100644
--- a/rtpsource/rtp_provider.c
+++ b/rtpsource/rtp_provider.c
@@ -9,6 +9,24 @@
 static LLIST_HEAD(g_providers);
 static LLIST_HEAD(g_prov_instances);
 
+const struct value_string codec_type_names[] = {
+	{ CODEC_ULAW,		"ULAW" },
+	{ CODEC_ALAW,		"ALAW" },
+	{ CODEC_GSM_FR,		"GSM_FR" },
+	{ CODEC_GSM_EFR,	"GSM_EFR" },
+	{ CODEC_GSM_HR,		"GSM_HR" },
+	{ CODEC_AMR_4_75,	"AMR_4_75" },
+	{ CODEC_AMR_5_15,	"AMR_5_15" },
+	{ CODEC_AMR_5_90,	"AMR_5_90" },
+	{ CODEC_AMR_6_70,	"AMR_6_70" },
+	{ CODEC_AMR_7_40,	"AMR_7_40" },
+	{ CODEC_AMR_7_95,	"AMR_7_95" },
+	{ CODEC_AMR_10_2,	"AMR_10_2" },
+	{ CODEC_AMR_12_2,	"AMR_12_2" },
+	{ CODEC_AMR_SID,	"AMR_SID" },
+	{ 0, NULL }
+};
+
 void rtp_provider_register(struct rtp_provider *prov)
 {
 	llist_add_tail(&prov->list, &g_providers);
diff --git a/rtpsource/rtp_provider.h b/rtpsource/rtp_provider.h
index 7048a3e..22ed858 100644
--- a/rtpsource/rtp_provider.h
+++ b/rtpsource/rtp_provider.h
@@ -1,6 +1,7 @@
 #pragma once
 #include <stdint.h>
 #include <osmocom/core/linuxlist.h>
+#include <osmocom/core/utils.h>
 
 enum codec_type {
 	CODEC_ULAW,
@@ -20,6 +21,8 @@
 	_NUM_CODECS
 };
 
+extern const struct value_string codec_type_names[];
+
 struct rtp_provider_instance;
 
 struct rtp_provider {
diff --git a/rtpsource/rtpsource.c b/rtpsource/rtpsource.c
index 3087262..d5ffce5 100644
--- a/rtpsource/rtpsource.c
+++ b/rtpsource/rtpsource.c
@@ -63,11 +63,10 @@
 }
 
 /* create a new RTP connection for given CNAME; includes binding of local RTP port */
-struct rtp_connection *create_connection(struct rtpsource_state *rss, const char *cname)
+struct rtp_connection *create_connection(struct rtpsource_state *rss, const char *cname, enum codec_type codec)
 {
 	const struct rtp_provider *rtp_prov;
 	struct rtp_connection *conn;
-	enum codec_type codec = CODEC_GSM_FR; // TODO: configurable
 	const char *host;
 	int port;
 	int rc;
@@ -101,8 +100,8 @@
 
 	llist_add_tail(&conn->list, &rss->connections);
 
-	CLOGP(conn, DMAIN, LOGL_INFO, "Created RTP connection; local=%s:%u\n",
-		conn->local_host, conn->local_port);
+	CLOGP(conn, DMAIN, LOGL_INFO, "Created RTP connection; local=%s:%u; codec=%s\n",
+		conn->local_host, conn->local_port, get_value_string(codec_type_names, codec));
 
 
 	return conn;

-- 
To view, visit https://gerrit.osmocom.org/c/mncc-python/+/17979
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: mncc-python
Gerrit-Branch: master
Gerrit-Change-Id: If75e902b451d7e202a03e93afcd55bd24f517813
Gerrit-Change-Number: 17979
Gerrit-PatchSet: 3
Gerrit-Owner: osmith <osmith at sysmocom.de>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: osmith <osmith at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200501/afa476ed/attachment.htm>


More information about the gerrit-log mailing list