From: Holger Hans Peter Freyther holger@moiji-mobile.com
We will have the NOOP implementation (e.g. used by the NAT), the SW implementation (using software codecs), a HW assisted one that will use a DSP to do transcoding and in theory the RTP based one (but I will remove that code). --- openbsc/include/openbsc/mgcp.h | 14 ++++++------- openbsc/include/openbsc/mgcp_internal.h | 15 ++++++++++++-- openbsc/include/openbsc/mgcp_transcode.h | 2 ++ openbsc/src/libmgcp/mgcp_network.c | 3 ++- openbsc/src/libmgcp/mgcp_protocol.c | 33 ++++++++++++++++++------------ openbsc/src/libmgcp/mgcp_transcode.c | 12 ++++++++--- openbsc/src/osmo-bsc_mgcp/mgcp_main.c | 10 ++++----- openbsc/tests/mgcp/mgcp_transcoding_test.c | 11 ++++++---- 8 files changed, 63 insertions(+), 37 deletions(-)
diff --git a/openbsc/include/openbsc/mgcp.h b/openbsc/include/openbsc/mgcp.h index b2262bc..a216547 100644 --- a/openbsc/include/openbsc/mgcp.h +++ b/openbsc/include/openbsc/mgcp.h @@ -1,8 +1,8 @@ /* A Media Gateway Control Protocol Media Gateway: RFC 3435 */
/* - * (C) 2009-2012 by Holger Hans Peter Freyther zecke@selfish.org - * (C) 2009-2012 by On-Waves + * (C) 2009-2016 by Holger Hans Peter Freyther zecke@selfish.org + * (C) 2009-2016 by On-Waves * All Rights Reserved * * This program is free software; you can redistribute it and/or modify @@ -69,6 +69,7 @@ struct mgcp_endpoint; struct mgcp_config; struct mgcp_trunk_config; struct mgcp_rtp_end; +struct mgcp_transcoding;
#define MGCP_ENDP_CRCX 1 #define MGCP_ENDP_DLCX 2 @@ -158,6 +159,9 @@ struct mgcp_trunk_config { /* spec handling */ int force_realloc;
+ /* transcoding */ + const struct mgcp_transcoding *transcoder; + /* timer */ struct osmo_timer_list keepalive_timer;
@@ -184,12 +188,6 @@ struct mgcp_config { struct in_addr transcoder_in; int transcoder_remote_base;
- /* RTP processing */ - mgcp_processing rtp_processing_cb; - mgcp_processing_setup setup_rtp_processing_cb; - - mgcp_get_format get_net_downlink_format_cb; - struct osmo_wqueue gw_fd;
struct mgcp_port_range bts_ports; diff --git a/openbsc/include/openbsc/mgcp_internal.h b/openbsc/include/openbsc/mgcp_internal.h index 7c89d10..a62dbb2 100644 --- a/openbsc/include/openbsc/mgcp_internal.h +++ b/openbsc/include/openbsc/mgcp_internal.h @@ -1,8 +1,8 @@ /* MGCP Private Data */
/* - * (C) 2009-2012 by Holger Hans Peter Freyther zecke@selfish.org - * (C) 2009-2012 by On-Waves + * (C) 2009-2016 by Holger Hans Peter Freyther zecke@selfish.org + * (C) 2009-2016 by On-Waves * All Rights Reserved * * This program is free software; you can redistribute it and/or modify @@ -150,6 +150,17 @@ enum mgcp_type { MGCP_OSMUX_BSC_NAT, };
+/** + * Function pointers for RTP processing/transcoding + */ +struct mgcp_transcoding { + mgcp_processing processing_cb; + mgcp_processing_setup setup_processing_cb; + mgcp_get_format get_net_downlink_format_cb; +}; + +extern const struct mgcp_transcoding *mgcp_default_transcoder; + #include <openbsc/osmux.h>
struct mgcp_endpoint { diff --git a/openbsc/include/openbsc/mgcp_transcode.h b/openbsc/include/openbsc/mgcp_transcode.h index 147e48b..02b039d 100644 --- a/openbsc/include/openbsc/mgcp_transcode.h +++ b/openbsc/include/openbsc/mgcp_transcode.h @@ -37,6 +37,8 @@ enum audio_format { AF_PCMU };
+struct mgcp_transcoding; +extern const struct mgcp_transcoding mgcp_sw_transcoder;
struct mgcp_process_rtp_state { /* decoding */ diff --git a/openbsc/src/libmgcp/mgcp_network.c b/openbsc/src/libmgcp/mgcp_network.c index abce6e4..e4f5f7d 100644 --- a/openbsc/src/libmgcp/mgcp_network.c +++ b/openbsc/src/libmgcp/mgcp_network.c @@ -584,6 +584,7 @@ int mgcp_send(struct mgcp_endpoint *endp, int dest, int is_rtp, struct sockaddr_in *addr, char *buf, int rc) { struct mgcp_trunk_config *tcfg = endp->tcfg; + const struct mgcp_transcoding *trans = tcfg->transcoder; struct mgcp_rtp_end *rtp_end; struct mgcp_rtp_state *rtp_state; int tap_idx; @@ -613,7 +614,7 @@ int mgcp_send(struct mgcp_endpoint *endp, int dest, int is_rtp, int nbytes = 0; int len = rc; do { - cont = endp->cfg->rtp_processing_cb(endp, rtp_end, + cont = trans->processing_cb(endp, rtp_end, buf, &len, RTP_BUF_SIZE); if (cont < 0) break; diff --git a/openbsc/src/libmgcp/mgcp_protocol.c b/openbsc/src/libmgcp/mgcp_protocol.c index 1819cea..8017fe8 100644 --- a/openbsc/src/libmgcp/mgcp_protocol.c +++ b/openbsc/src/libmgcp/mgcp_protocol.c @@ -2,8 +2,8 @@ /* The protocol implementation */
/* - * (C) 2009-2012 by Holger Hans Peter Freyther zecke@selfish.org - * (C) 2009-2012 by On-Waves + * (C) 2009-2016 by Holger Hans Peter Freyther zecke@selfish.org + * (C) 2009-2016 by On-Waves * All Rights Reserved * * This program is free software; you can redistribute it and/or modify @@ -66,6 +66,14 @@ static int setup_rtp_processing(struct mgcp_endpoint *endp);
static int mgcp_analyze_header(struct mgcp_parse_data *parse, char *data);
+static const struct mgcp_transcoding no_transcoder = { + .processing_cb = &mgcp_rtp_processing_default, + .setup_processing_cb = &mgcp_setup_rtp_processing_default, + .get_net_downlink_format_cb = &mgcp_get_net_downlink_format_default, +}; + +const struct mgcp_transcoding *mgcp_default_transcoder = &no_transcoder; + static int mgcp_check_param(const struct mgcp_endpoint *endp, const char *line) { const size_t line_len = strlen(line); @@ -197,13 +205,15 @@ static struct msgb *create_err_response(struct mgcp_endpoint *endp, static int write_response_sdp(struct mgcp_endpoint *endp, char *sdp_record, size_t size, const char *addr) { + const struct mgcp_transcoding *trans; const char *fmtp_extra; const char *audio_name; int payload_type; int len; int nchars;
- endp->cfg->get_net_downlink_format_cb(endp, &payload_type, + trans = endp->tcfg->transcoder; + trans->get_net_downlink_format_cb(endp, &payload_type, &audio_name, &fmtp_extra);
len = snprintf(sdp_record, size, @@ -1200,12 +1210,8 @@ struct mgcp_config *mgcp_config_alloc(void) cfg->bts_ports.base_port = RTP_PORT_DEFAULT; cfg->net_ports.base_port = RTP_PORT_NET_DEFAULT;
- cfg->rtp_processing_cb = &mgcp_rtp_processing_default; - cfg->setup_rtp_processing_cb = &mgcp_setup_rtp_processing_default; - - cfg->get_net_downlink_format_cb = &mgcp_get_net_downlink_format_default; - /* default trunk handling */ + cfg->trunk.transcoder = mgcp_default_transcoder; cfg->trunk.cfg = cfg; cfg->trunk.trunk_nr = 0; cfg->trunk.trunk_type = MGCP_TRUNK_VIRTUAL; @@ -1231,6 +1237,7 @@ struct mgcp_trunk_config *mgcp_trunk_alloc(struct mgcp_config *cfg, int nr) return NULL; }
+ trunk->transcoder = mgcp_default_transcoder; trunk->cfg = cfg; trunk->trunk_type = MGCP_TRUNK_E1; trunk->trunk_nr = nr; @@ -1459,7 +1466,7 @@ int mgcp_send_reset_ep(struct mgcp_endpoint *endp, int endpoint) static int setup_rtp_processing(struct mgcp_endpoint *endp) { int rc = 0; - struct mgcp_config *cfg = endp->cfg; + const struct mgcp_transcoding *trans = endp->tcfg->transcoder;
if (endp->type != MGCP_RTP_DEFAULT) return 0; @@ -1468,14 +1475,14 @@ static int setup_rtp_processing(struct mgcp_endpoint *endp) return 0;
if (endp->conn_mode & MGCP_CONN_SEND_ONLY) - rc |= cfg->setup_rtp_processing_cb(endp, &endp->net_end, &endp->bts_end); + rc |= trans->setup_processing_cb(endp, &endp->net_end, &endp->bts_end); else - rc |= cfg->setup_rtp_processing_cb(endp, &endp->net_end, NULL); + rc |= trans->setup_processing_cb(endp, &endp->net_end, NULL);
if (endp->conn_mode & MGCP_CONN_RECV_ONLY) - rc |= cfg->setup_rtp_processing_cb(endp, &endp->bts_end, &endp->net_end); + rc |= trans->setup_processing_cb(endp, &endp->bts_end, &endp->net_end); else - rc |= cfg->setup_rtp_processing_cb(endp, &endp->bts_end, NULL); + rc |= trans->setup_processing_cb(endp, &endp->bts_end, NULL); return rc; }
diff --git a/openbsc/src/libmgcp/mgcp_transcode.c b/openbsc/src/libmgcp/mgcp_transcode.c index c994d32..aaa8863 100644 --- a/openbsc/src/libmgcp/mgcp_transcode.c +++ b/openbsc/src/libmgcp/mgcp_transcode.c @@ -32,6 +32,12 @@ #include <osmocom/core/talloc.h> #include <osmocom/netif/rtp.h>
+const struct mgcp_transcoding mgcp_sw_transcoder = { + .processing_cb = mgcp_transcoding_process_rtp, + .setup_processing_cb = mgcp_transcoding_setup, + .get_net_downlink_format_cb = mgcp_transcoding_net_downlink_format, +}; + int mgcp_transcoding_get_frame_size(void *state_, int nsamples, int dst) { struct mgcp_process_rtp_state *state = state_; @@ -470,12 +476,12 @@ struct mgcp_process_rtp_state *check_transcode_state( goto done; /* The matching alternate payload type? Then switch */ if (rtp_hdr->payload_type == src_end->alt_codec.payload_type) { - struct mgcp_config *cfg = endp->cfg; + const struct mgcp_transcoding *trans = endp->tcfg->transcoder; struct mgcp_rtp_codec tmp_codec = src_end->alt_codec; src_end->alt_codec = src_end->codec; src_end->codec = tmp_codec; - cfg->setup_rtp_processing_cb(endp, &endp->net_end, &endp->bts_end); - cfg->setup_rtp_processing_cb(endp, &endp->bts_end, &endp->net_end); + trans->setup_processing_cb(endp, &endp->net_end, &endp->bts_end); + trans->setup_processing_cb(endp, &endp->bts_end, &endp->net_end); }
done: diff --git a/openbsc/src/osmo-bsc_mgcp/mgcp_main.c b/openbsc/src/osmo-bsc_mgcp/mgcp_main.c index e226b02..3c968be 100644 --- a/openbsc/src/osmo-bsc_mgcp/mgcp_main.c +++ b/openbsc/src/osmo-bsc_mgcp/mgcp_main.c @@ -207,16 +207,14 @@ int main(int argc, char **argv) osmo_init_ignore_signals(); osmo_init_logging(&log_info);
+#ifdef BUILD_MGCP_TRANSCODING + mgcp_default_transcoder = &mgcp_sw_transcoder; +#endif + cfg = mgcp_config_alloc(); if (!cfg) return -1;
-#ifdef BUILD_MGCP_TRANSCODING - cfg->setup_rtp_processing_cb = &mgcp_transcoding_setup; - cfg->rtp_processing_cb = &mgcp_transcoding_process_rtp; - cfg->get_net_downlink_format_cb = &mgcp_transcoding_net_downlink_format; -#endif - vty_info.copyright = openbsc_copyright; vty_init(&vty_info); logging_vty_add_cmds(&log_info); diff --git a/openbsc/tests/mgcp/mgcp_transcoding_test.c b/openbsc/tests/mgcp/mgcp_transcoding_test.c index c5c0a0b..72c75eb 100644 --- a/openbsc/tests/mgcp/mgcp_transcoding_test.c +++ b/openbsc/tests/mgcp/mgcp_transcoding_test.c @@ -161,6 +161,12 @@ static int audio_name_to_type(const char *name)
int mgcp_get_trans_frame_size(void *state_, int nsamples, int dst);
+static const struct mgcp_transcoding test_transcoder = { + .setup_processing_cb = mgcp_transcoding_setup, + .processing_cb = mgcp_transcoding_process_rtp, + .get_net_downlink_format_cb = mgcp_transcoding_net_downlink_format, +}; + static int given_configured_endpoint(int in_samples, int out_samples, const char *srcfmt, const char *dstfmt, void **out_ctx, struct mgcp_endpoint **out_endp) @@ -176,10 +182,7 @@ static int given_configured_endpoint(int in_samples, int out_samples, tcfg = talloc_zero(cfg, struct mgcp_trunk_config); endp = talloc_zero(tcfg, struct mgcp_endpoint);
- cfg->setup_rtp_processing_cb = mgcp_transcoding_setup; - cfg->rtp_processing_cb = mgcp_transcoding_process_rtp; - cfg->get_net_downlink_format_cb = mgcp_transcoding_net_downlink_format; - + tcfg->transcoder = &test_transcoder; tcfg->endpoints = endp; tcfg->number_endpoints = 1; tcfg->cfg = cfg;
From: Holger Hans Peter Freyther holger@moiji-mobile.com
Now they are included in a struct we can just call them setup, process and get_net_downlink_format to manage the lifetime. --- openbsc/include/openbsc/mgcp_internal.h | 6 +++--- openbsc/src/libmgcp/mgcp_network.c | 2 +- openbsc/src/libmgcp/mgcp_protocol.c | 16 ++++++++-------- openbsc/src/libmgcp/mgcp_transcode.c | 10 +++++----- openbsc/tests/mgcp/mgcp_transcoding_test.c | 6 +++--- 5 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/openbsc/include/openbsc/mgcp_internal.h b/openbsc/include/openbsc/mgcp_internal.h index a62dbb2..8fb8a45 100644 --- a/openbsc/include/openbsc/mgcp_internal.h +++ b/openbsc/include/openbsc/mgcp_internal.h @@ -154,9 +154,9 @@ enum mgcp_type { * Function pointers for RTP processing/transcoding */ struct mgcp_transcoding { - mgcp_processing processing_cb; - mgcp_processing_setup setup_processing_cb; - mgcp_get_format get_net_downlink_format_cb; + mgcp_processing process; + mgcp_processing_setup setup; + mgcp_get_format get_net_downlink_format; };
extern const struct mgcp_transcoding *mgcp_default_transcoder; diff --git a/openbsc/src/libmgcp/mgcp_network.c b/openbsc/src/libmgcp/mgcp_network.c index e4f5f7d..ed90d34 100644 --- a/openbsc/src/libmgcp/mgcp_network.c +++ b/openbsc/src/libmgcp/mgcp_network.c @@ -614,7 +614,7 @@ int mgcp_send(struct mgcp_endpoint *endp, int dest, int is_rtp, int nbytes = 0; int len = rc; do { - cont = trans->processing_cb(endp, rtp_end, + cont = trans->process(endp, rtp_end, buf, &len, RTP_BUF_SIZE); if (cont < 0) break; diff --git a/openbsc/src/libmgcp/mgcp_protocol.c b/openbsc/src/libmgcp/mgcp_protocol.c index 8017fe8..18a25bc 100644 --- a/openbsc/src/libmgcp/mgcp_protocol.c +++ b/openbsc/src/libmgcp/mgcp_protocol.c @@ -67,9 +67,9 @@ static int setup_rtp_processing(struct mgcp_endpoint *endp); static int mgcp_analyze_header(struct mgcp_parse_data *parse, char *data);
static const struct mgcp_transcoding no_transcoder = { - .processing_cb = &mgcp_rtp_processing_default, - .setup_processing_cb = &mgcp_setup_rtp_processing_default, - .get_net_downlink_format_cb = &mgcp_get_net_downlink_format_default, + .process = &mgcp_rtp_processing_default, + .setup = &mgcp_setup_rtp_processing_default, + .get_net_downlink_format = &mgcp_get_net_downlink_format_default, };
const struct mgcp_transcoding *mgcp_default_transcoder = &no_transcoder; @@ -213,7 +213,7 @@ static int write_response_sdp(struct mgcp_endpoint *endp, int nchars;
trans = endp->tcfg->transcoder; - trans->get_net_downlink_format_cb(endp, &payload_type, + trans->get_net_downlink_format(endp, &payload_type, &audio_name, &fmtp_extra);
len = snprintf(sdp_record, size, @@ -1475,14 +1475,14 @@ static int setup_rtp_processing(struct mgcp_endpoint *endp) return 0;
if (endp->conn_mode & MGCP_CONN_SEND_ONLY) - rc |= trans->setup_processing_cb(endp, &endp->net_end, &endp->bts_end); + rc |= trans->setup(endp, &endp->net_end, &endp->bts_end); else - rc |= trans->setup_processing_cb(endp, &endp->net_end, NULL); + rc |= trans->setup(endp, &endp->net_end, NULL);
if (endp->conn_mode & MGCP_CONN_RECV_ONLY) - rc |= trans->setup_processing_cb(endp, &endp->bts_end, &endp->net_end); + rc |= trans->setup(endp, &endp->bts_end, &endp->net_end); else - rc |= trans->setup_processing_cb(endp, &endp->bts_end, NULL); + rc |= trans->setup(endp, &endp->bts_end, NULL); return rc; }
diff --git a/openbsc/src/libmgcp/mgcp_transcode.c b/openbsc/src/libmgcp/mgcp_transcode.c index aaa8863..6407cfb 100644 --- a/openbsc/src/libmgcp/mgcp_transcode.c +++ b/openbsc/src/libmgcp/mgcp_transcode.c @@ -33,9 +33,9 @@ #include <osmocom/netif/rtp.h>
const struct mgcp_transcoding mgcp_sw_transcoder = { - .processing_cb = mgcp_transcoding_process_rtp, - .setup_processing_cb = mgcp_transcoding_setup, - .get_net_downlink_format_cb = mgcp_transcoding_net_downlink_format, + .process = mgcp_transcoding_process_rtp, + .setup = mgcp_transcoding_setup, + .get_net_downlink_format = mgcp_transcoding_net_downlink_format, };
int mgcp_transcoding_get_frame_size(void *state_, int nsamples, int dst) @@ -480,8 +480,8 @@ struct mgcp_process_rtp_state *check_transcode_state( struct mgcp_rtp_codec tmp_codec = src_end->alt_codec; src_end->alt_codec = src_end->codec; src_end->codec = tmp_codec; - trans->setup_processing_cb(endp, &endp->net_end, &endp->bts_end); - trans->setup_processing_cb(endp, &endp->bts_end, &endp->net_end); + trans->setup(endp, &endp->net_end, &endp->bts_end); + trans->setup(endp, &endp->bts_end, &endp->net_end); }
done: diff --git a/openbsc/tests/mgcp/mgcp_transcoding_test.c b/openbsc/tests/mgcp/mgcp_transcoding_test.c index 72c75eb..02f2817 100644 --- a/openbsc/tests/mgcp/mgcp_transcoding_test.c +++ b/openbsc/tests/mgcp/mgcp_transcoding_test.c @@ -162,9 +162,9 @@ static int audio_name_to_type(const char *name) int mgcp_get_trans_frame_size(void *state_, int nsamples, int dst);
static const struct mgcp_transcoding test_transcoder = { - .setup_processing_cb = mgcp_transcoding_setup, - .processing_cb = mgcp_transcoding_process_rtp, - .get_net_downlink_format_cb = mgcp_transcoding_net_downlink_format, + .setup = mgcp_transcoding_setup, + .process = mgcp_transcoding_process_rtp, + .get_net_downlink_format = mgcp_transcoding_net_downlink_format, };
static int given_configured_endpoint(int in_samples, int out_samples,
From: Holger Hans Peter Freyther holger@moiji-mobile.com
Back in the day we worked around a field proven jitter buffer by transcoding AMR to AMR with the MTN4200 and by this fixing RTP timing as this device had:
a.) A working and stable time (generating RTP every N ms) b.) A working jitter buffer
The code has probably rotted, it never retried MGCP commands sent to the transcoder and it is not deployed either. Simplify the code by removing it. If we ever need it back we can use the new transcoding API to keep the state there. I think this code will not be missed but the PerformanceTechnology Hard- and Firmware was rather nice. --- openbsc/include/openbsc/mgcp.h | 7 -- openbsc/include/openbsc/mgcp_internal.h | 16 ---- openbsc/src/libmgcp/mgcp_network.c | 105 ---------------------- openbsc/src/libmgcp/mgcp_protocol.c | 141 ------------------------------ openbsc/src/libmgcp/mgcp_vty.c | 77 +++++----------- openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c | 9 -- 6 files changed, 21 insertions(+), 334 deletions(-)
diff --git a/openbsc/include/openbsc/mgcp.h b/openbsc/include/openbsc/mgcp.h index a216547..dfa41a3 100644 --- a/openbsc/include/openbsc/mgcp.h +++ b/openbsc/include/openbsc/mgcp.h @@ -183,16 +183,10 @@ struct mgcp_config {
struct in_addr bts_in;
- /* transcoder handling */ - char *transcoder_ip; - struct in_addr transcoder_in; - int transcoder_remote_base; - struct osmo_wqueue gw_fd;
struct mgcp_port_range bts_ports; struct mgcp_port_range net_ports; - struct mgcp_port_range transcoder_ports; int endp_dscp;
int bts_force_ptime; @@ -244,7 +238,6 @@ int mgcp_vty_init(void); int mgcp_endpoints_allocate(struct mgcp_trunk_config *cfg); void mgcp_release_endp(struct mgcp_endpoint *endp); void mgcp_initialize_endp(struct mgcp_endpoint *endp); -int mgcp_reset_transcoder(struct mgcp_config *cfg); void mgcp_format_stats(struct mgcp_endpoint *endp, char *stats, size_t size); int mgcp_parse_stats(struct msgb *msg, uint32_t *ps, uint32_t *os, uint32_t *pr, uint32_t *_or, int *loss, uint32_t *jitter);
diff --git a/openbsc/include/openbsc/mgcp_internal.h b/openbsc/include/openbsc/mgcp_internal.h index 8fb8a45..dd195e0 100644 --- a/openbsc/include/openbsc/mgcp_internal.h +++ b/openbsc/include/openbsc/mgcp_internal.h @@ -145,7 +145,6 @@ struct mgcp_lco {
enum mgcp_type { MGCP_RTP_DEFAULT = 0, - MGCP_RTP_TRANSCODED, MGCP_OSMUX_BSC, MGCP_OSMUX_BSC_NAT, }; @@ -179,13 +178,6 @@ struct mgcp_endpoint { struct mgcp_rtp_end bts_end; struct mgcp_rtp_end net_end;
- /* - * For transcoding we will send from the local_port - * of trans_bts and it will arrive at trans_net from - * where we will forward it to the network. - */ - struct mgcp_rtp_end trans_bts; - struct mgcp_rtp_end trans_net; enum mgcp_type type;
/* sequence bits */ @@ -268,16 +260,8 @@ struct mgcp_parse_data { int mgcp_send_dummy(struct mgcp_endpoint *endp); int mgcp_bind_bts_rtp_port(struct mgcp_endpoint *endp, int rtp_port); int mgcp_bind_net_rtp_port(struct mgcp_endpoint *endp, int rtp_port); -int mgcp_bind_trans_bts_rtp_port(struct mgcp_endpoint *enp, int rtp_port); -int mgcp_bind_trans_net_rtp_port(struct mgcp_endpoint *enp, int rtp_port); int mgcp_free_rtp_port(struct mgcp_rtp_end *end);
-/* For transcoding we need to manage an in and an output that are connected */ -static inline int endp_back_channel(int endpoint) -{ - return endpoint + 60; -} - struct mgcp_trunk_config *mgcp_trunk_alloc(struct mgcp_config *cfg, int index); struct mgcp_trunk_config *mgcp_trunk_num(struct mgcp_config *cfg, int index);
diff --git a/openbsc/src/libmgcp/mgcp_network.c b/openbsc/src/libmgcp/mgcp_network.c index ed90d34..1eb87bb 100644 --- a/openbsc/src/libmgcp/mgcp_network.c +++ b/openbsc/src/libmgcp/mgcp_network.c @@ -553,33 +553,6 @@ static int forward_data(int fd, struct mgcp_rtp_tap *tap, const char *buf, int l (struct sockaddr *)&tap->forward, sizeof(tap->forward)); }
-static int mgcp_send_transcoder(struct mgcp_rtp_end *end, - struct mgcp_config *cfg, int is_rtp, - const char *buf, int len) -{ - int rc; - int port; - struct sockaddr_in addr; - - port = is_rtp ? end->rtp_port : end->rtcp_port; - - addr.sin_family = AF_INET; - addr.sin_addr = cfg->transcoder_in; - addr.sin_port = port; - - rc = sendto(is_rtp ? - end->rtp.fd : - end->rtcp.fd, buf, len, 0, - (struct sockaddr *) &addr, sizeof(addr)); - - if (rc != len) - LOGP(DMGCP, LOGL_ERROR, - "Failed to send data to the transcoder: %s\n", - strerror(errno)); - - return rc; -} - int mgcp_send(struct mgcp_endpoint *endp, int dest, int is_rtp, struct sockaddr_in *addr, char *buf, int rc) { @@ -688,7 +661,6 @@ static int rtp_data_net(struct osmo_fd *fd, unsigned int what)
switch(endp->type) { case MGCP_RTP_DEFAULT: - case MGCP_RTP_TRANSCODED: if (endp->net_end.rtp_port != addr.sin_port && endp->net_end.rtcp_port != addr.sin_port) { LOGP(DMGCP, LOGL_ERROR, @@ -719,9 +691,6 @@ static int rtp_data_net(struct osmo_fd *fd, unsigned int what) case MGCP_RTP_DEFAULT: return mgcp_send(endp, MGCP_DEST_BTS, proto == MGCP_PROTO_RTP, &addr, buf, rc); - case MGCP_RTP_TRANSCODED: - return mgcp_send_transcoder(&endp->trans_net, endp->cfg, - proto == MGCP_PROTO_RTP, buf, rc); case MGCP_OSMUX_BSC_NAT: return osmux_xfrm_to_osmux(MGCP_DEST_BTS, buf, rc, endp); case MGCP_OSMUX_BSC: /* Should not happen */ @@ -811,9 +780,6 @@ static int rtp_data_bts(struct osmo_fd *fd, unsigned int what) case MGCP_RTP_DEFAULT: return mgcp_send(endp, MGCP_DEST_NET, proto == MGCP_PROTO_RTP, &addr, buf, rc); - case MGCP_RTP_TRANSCODED: - return mgcp_send_transcoder(&endp->trans_bts, endp->cfg, - proto == MGCP_PROTO_RTP, buf, rc); case MGCP_OSMUX_BSC: /* OSMUX translation: BTS -> BSC */ return osmux_xfrm_to_osmux(MGCP_DEST_NET, buf, rc, endp); @@ -826,63 +792,6 @@ static int rtp_data_bts(struct osmo_fd *fd, unsigned int what) return 0; }
-static int rtp_data_transcoder(struct mgcp_rtp_end *end, struct mgcp_endpoint *_endp, - int dest, struct osmo_fd *fd) -{ - char buf[RTP_BUF_SIZE]; - struct sockaddr_in addr; - struct mgcp_config *cfg; - int rc, proto; - - cfg = _endp->cfg; - rc = receive_from(_endp, fd->fd, &addr, buf, sizeof(buf)); - if (rc <= 0) - return -1; - - proto = fd == &end->rtp ? MGCP_PROTO_RTP : MGCP_PROTO_RTCP; - - if (memcmp(&addr.sin_addr, &cfg->transcoder_in, sizeof(addr.sin_addr)) != 0) { - LOGP(DMGCP, LOGL_ERROR, - "Data not coming from transcoder dest: %d %s on 0x%x\n", - dest, inet_ntoa(addr.sin_addr), ENDPOINT_NUMBER(_endp)); - return -1; - } - - if (end->rtp_port != addr.sin_port && - end->rtcp_port != addr.sin_port) { - LOGP(DMGCP, LOGL_ERROR, - "Data from wrong transcoder dest %d source port %d on 0x%x\n", - dest, ntohs(addr.sin_port), ENDPOINT_NUMBER(_endp)); - return -1; - } - - /* throw away the dummy message */ - if (rc == 1 && buf[0] == MGCP_DUMMY_LOAD) { - LOGP(DMGCP, LOGL_NOTICE, "Filtered dummy from transcoder dest %d on 0x%x\n", - dest, ENDPOINT_NUMBER(_endp)); - return 0; - } - - end->packets += 1; - return mgcp_send(_endp, dest, proto == MGCP_PROTO_RTP, &addr, buf, rc); -} - -static int rtp_data_trans_net(struct osmo_fd *fd, unsigned int what) -{ - struct mgcp_endpoint *endp; - endp = (struct mgcp_endpoint *) fd->data; - - return rtp_data_transcoder(&endp->trans_net, endp, MGCP_DEST_NET, fd); -} - -static int rtp_data_trans_bts(struct osmo_fd *fd, unsigned int what) -{ - struct mgcp_endpoint *endp; - endp = (struct mgcp_endpoint *) fd->data; - - return rtp_data_transcoder(&endp->trans_bts, endp, MGCP_DEST_BTS, fd); -} - int mgcp_create_bind(const char *source_addr, struct osmo_fd *fd, int port) { struct sockaddr_in addr; @@ -998,20 +907,6 @@ int mgcp_bind_net_rtp_port(struct mgcp_endpoint *endp, int rtp_port) mgcp_net_src_addr(endp), rtp_port); }
-int mgcp_bind_trans_net_rtp_port(struct mgcp_endpoint *endp, int rtp_port) -{ - return int_bind("trans-net", &endp->trans_net, - rtp_data_trans_net, endp, - endp->cfg->source_addr, rtp_port); -} - -int mgcp_bind_trans_bts_rtp_port(struct mgcp_endpoint *endp, int rtp_port) -{ - return int_bind("trans-bts", &endp->trans_bts, - rtp_data_trans_bts, endp, - endp->cfg->source_addr, rtp_port); -} - int mgcp_free_rtp_port(struct mgcp_rtp_end *end) { if (end->rtp.fd != -1) { diff --git a/openbsc/src/libmgcp/mgcp_protocol.c b/openbsc/src/libmgcp/mgcp_protocol.c index 18a25bc..c136e31 100644 --- a/openbsc/src/libmgcp/mgcp_protocol.c +++ b/openbsc/src/libmgcp/mgcp_protocol.c @@ -59,9 +59,6 @@ static struct msgb *handle_modify_con(struct mgcp_parse_data *data); static struct msgb *handle_rsip(struct mgcp_parse_data *data); static struct msgb *handle_noti_req(struct mgcp_parse_data *data);
-static void create_transcoder(struct mgcp_endpoint *endp); -static void delete_transcoder(struct mgcp_endpoint *endp); - static int setup_rtp_processing(struct mgcp_endpoint *endp);
static int mgcp_analyze_header(struct mgcp_parse_data *parse, char *data); @@ -604,28 +601,6 @@ static int allocate_ports(struct mgcp_endpoint *endp) return -1; }
- if (endp->cfg->transcoder_ip && endp->tcfg->trunk_type == MGCP_TRUNK_VIRTUAL) { - if (allocate_port(endp, &endp->trans_net, - &endp->cfg->transcoder_ports, - mgcp_bind_trans_net_rtp_port) != 0) { - mgcp_rtp_end_reset(&endp->net_end); - mgcp_rtp_end_reset(&endp->bts_end); - return -1; - } - - if (allocate_port(endp, &endp->trans_bts, - &endp->cfg->transcoder_ports, - mgcp_bind_trans_bts_rtp_port) != 0) { - mgcp_rtp_end_reset(&endp->net_end); - mgcp_rtp_end_reset(&endp->bts_end); - mgcp_rtp_end_reset(&endp->trans_net); - return -1; - } - - /* remember that we have set up transcoding */ - endp->type = MGCP_RTP_TRANSCODED; - } - return 0; }
@@ -868,7 +843,6 @@ mgcp_header_done: break; case MGCP_POLICY_DEFER: /* stop processing */ - create_transcoder(endp); return NULL; break; case MGCP_POLICY_CONT: @@ -887,7 +861,6 @@ mgcp_header_done: send_dummy(endp); }
- create_transcoder(endp); return create_response_with_sdp(endp, "CRCX", p->trans); error2: mgcp_release_endp(endp); @@ -1070,7 +1043,6 @@ static struct msgb *handle_delete_con(struct mgcp_parse_data *p) break; case MGCP_POLICY_DEFER: /* stop processing */ - delete_transcoder(endp); return NULL; break; case MGCP_POLICY_CONT: @@ -1086,7 +1058,6 @@ static struct msgb *handle_delete_con(struct mgcp_parse_data *p) /* save the statistics of the current call */ mgcp_format_stats(endp, stats, sizeof(stats));
- delete_transcoder(endp); mgcp_release_endp(endp); if (p->cfg->change_cb) p->cfg->change_cb(endp->tcfg, ENDPOINT_NUMBER(endp), MGCP_ENDP_DLCX); @@ -1205,8 +1176,6 @@ struct mgcp_config *mgcp_config_alloc(void) cfg->source_addr = talloc_strdup(cfg, "0.0.0.0"); cfg->osmux_addr = talloc_strdup(cfg, "0.0.0.0");
- cfg->transcoder_remote_base = 4000; - cfg->bts_ports.base_port = RTP_PORT_DEFAULT; cfg->net_ports.base_port = RTP_PORT_NET_DEFAULT;
@@ -1328,8 +1297,6 @@ int mgcp_endpoints_allocate(struct mgcp_trunk_config *tcfg) tcfg->endpoints[i].tcfg = tcfg; mgcp_rtp_end_init(&tcfg->endpoints[i].net_end); mgcp_rtp_end_init(&tcfg->endpoints[i].bts_end); - mgcp_rtp_end_init(&tcfg->endpoints[i].trans_net); - mgcp_rtp_end_init(&tcfg->endpoints[i].trans_bts); }
return 0; @@ -1351,8 +1318,6 @@ void mgcp_release_endp(struct mgcp_endpoint *endp)
mgcp_rtp_end_reset(&endp->bts_end); mgcp_rtp_end_reset(&endp->net_end); - mgcp_rtp_end_reset(&endp->trans_net); - mgcp_rtp_end_reset(&endp->trans_bts); endp->type = MGCP_RTP_DEFAULT;
memset(&endp->net_state, 0, sizeof(endp->net_state)); @@ -1374,65 +1339,6 @@ void mgcp_initialize_endp(struct mgcp_endpoint *endp) return mgcp_release_endp(endp); }
-static int send_trans(struct mgcp_config *cfg, const char *buf, int len) -{ - struct sockaddr_in addr; - - memset(&addr, 0, sizeof(addr)); - addr.sin_family = AF_INET; - addr.sin_addr = cfg->transcoder_in; - addr.sin_port = htons(2427); - return sendto(cfg->gw_fd.bfd.fd, buf, len, 0, - (struct sockaddr *) &addr, sizeof(addr)); -} - -static void send_msg(struct mgcp_endpoint *endp, int endpoint, int port, - const char *msg, const char *mode) -{ - char buf[2096]; - int len; - int nchars; - - /* hardcoded to AMR right now, we do not know the real type at this point */ - len = snprintf(buf, sizeof(buf), - "%s 42 %x@mgw MGCP 1.0\r\n" - "C: 4256\r\n" - "M: %s\r\n" - "\r\n", - msg, endpoint, mode); - - if (len < 0) - return; - - nchars = write_response_sdp(endp, buf + len, sizeof(buf) + len - 1, NULL); - if (nchars < 0) - return; - - len += nchars; - - buf[sizeof(buf) - 1] = '\0'; - - send_trans(endp->cfg, buf, len); -} - -static void send_dlcx(struct mgcp_endpoint *endp, int endpoint) -{ - char buf[2096]; - int len; - - len = snprintf(buf, sizeof(buf), - "DLCX 43 %x@mgw MGCP 1.0\r\n" - "C: 4256\r\n" - , endpoint); - - if (len < 0) - return; - - buf[sizeof(buf) - 1] = '\0'; - - send_trans(endp->cfg, buf, len); -} - static int send_agent(struct mgcp_config *cfg, const char *buf, int len) { return write(cfg->gw_fd.bfd.fd, buf, len); @@ -1486,53 +1392,6 @@ static int setup_rtp_processing(struct mgcp_endpoint *endp) return rc; }
-static void create_transcoder(struct mgcp_endpoint *endp) -{ - int port; - int in_endp = ENDPOINT_NUMBER(endp); - int out_endp = endp_back_channel(in_endp); - - if (endp->type != MGCP_RTP_TRANSCODED) - return; - - send_msg(endp, in_endp, endp->trans_bts.local_port, "CRCX", "sendrecv"); - send_msg(endp, in_endp, endp->trans_bts.local_port, "MDCX", "sendrecv"); - send_msg(endp, out_endp, endp->trans_net.local_port, "CRCX", "sendrecv"); - send_msg(endp, out_endp, endp->trans_net.local_port, "MDCX", "sendrecv"); - - port = rtp_calculate_port(in_endp, endp->cfg->transcoder_remote_base); - endp->trans_bts.rtp_port = htons(port); - endp->trans_bts.rtcp_port = htons(port + 1); - - port = rtp_calculate_port(out_endp, endp->cfg->transcoder_remote_base); - endp->trans_net.rtp_port = htons(port); - endp->trans_net.rtcp_port = htons(port + 1); -} - -static void delete_transcoder(struct mgcp_endpoint *endp) -{ - int in_endp = ENDPOINT_NUMBER(endp); - int out_endp = endp_back_channel(in_endp); - - if (endp->type != MGCP_RTP_TRANSCODED) - return; - - send_dlcx(endp, in_endp); - send_dlcx(endp, out_endp); -} - -int mgcp_reset_transcoder(struct mgcp_config *cfg) -{ - if (!cfg->transcoder_ip) - return 0; - - static const char mgcp_reset[] = { - "RSIP 1 13@mgw MGCP 1.0\r\n" - }; - - return send_trans(cfg, mgcp_reset, sizeof mgcp_reset -1); -} - void mgcp_format_stats(struct mgcp_endpoint *endp, char *msg, size_t size) { uint32_t expected, jitter; diff --git a/openbsc/src/libmgcp/mgcp_vty.c b/openbsc/src/libmgcp/mgcp_vty.c index 13f66c5..5300ffc 100644 --- a/openbsc/src/libmgcp/mgcp_vty.c +++ b/openbsc/src/libmgcp/mgcp_vty.c @@ -128,17 +128,8 @@ static int config_write_mgcp(struct vty *vty) g_cfg->trunk.no_audio_transcoding ? "no " : "", VTY_NEWLINE); if (g_cfg->call_agent_addr) vty_out(vty, " call-agent ip %s%s", g_cfg->call_agent_addr, VTY_NEWLINE); - if (g_cfg->transcoder_ip) - vty_out(vty, " transcoder-mgw %s%s", g_cfg->transcoder_ip, VTY_NEWLINE); - - if (g_cfg->transcoder_ports.mode == PORT_ALLOC_STATIC) - vty_out(vty, " rtp transcoder-base %u%s", g_cfg->transcoder_ports.base_port, VTY_NEWLINE); - else - vty_out(vty, " rtp transcoder-range %u %u%s", - g_cfg->transcoder_ports.range_start, g_cfg->transcoder_ports.range_end, VTY_NEWLINE); if (g_cfg->bts_force_ptime > 0) vty_out(vty, " rtp force-ptime %d%s", g_cfg->bts_force_ptime, VTY_NEWLINE); - vty_out(vty, " transcoder-remote-base %u%s", g_cfg->transcoder_remote_base, VTY_NEWLINE);
switch (g_cfg->osmux) { case OSMUX_USAGE_ON: @@ -209,13 +200,12 @@ static void dump_trunk(struct vty *vty, struct mgcp_trunk_config *cfg, int verbo struct mgcp_endpoint *endp = &cfg->endpoints[i]; vty_out(vty, " Endpoint 0x%.2x: CI: %d net: %u/%u bts: %u/%u on %s " - "traffic received bts: %u remote: %u transcoder: %u/%u%s", + "traffic received bts: %u remote: %u%s", i, endp->ci, ntohs(endp->net_end.rtp_port), ntohs(endp->net_end.rtcp_port), ntohs(endp->bts_end.rtp_port), ntohs(endp->bts_end.rtcp_port), inet_ntoa(endp->bts_end.addr), endp->bts_end.packets, endp->net_end.packets, - endp->trans_net.packets, endp->trans_bts.packets, VTY_NEWLINE);
if (verbose && endp->allocated) { @@ -378,24 +368,26 @@ ALIAS_DEPRECATED(cfg_mgcp_rtp_bts_base_port, cfg_mgcp_rtp_base_port_cmd, "rtp base <0-65534>", RTP_STR BTS_START_STR UDP_PORT_STR)
-DEFUN(cfg_mgcp_rtp_transcoder_range, +DEFUN_DEPRECATED(cfg_mgcp_rtp_transcoder_range, cfg_mgcp_rtp_transcoder_range_cmd, "rtp transcoder-range <0-65534> <0-65534>", RTP_STR "Range of ports to use for the Transcoder\n" RANGE_START_STR RANGE_END_STR) { - parse_range(&g_cfg->transcoder_ports, argv); - return CMD_SUCCESS; + vty_out(vty, + "%% MGCP RTP transcoding has been removed.%s", VTY_NEWLINE); + return CMD_WARNING; }
-DEFUN(cfg_mgcp_rtp_transcoder_base, +DEFUN_DEPRECATED(cfg_mgcp_rtp_transcoder_base, cfg_mgcp_rtp_transcoder_base_cmd, "rtp transcoder-base <0-65534>", RTP_STR "First UDP port allocated for the Transcoder side\n" UDP_PORT_STR) { - parse_base(&g_cfg->transcoder_ports, argv); - return CMD_SUCCESS; + vty_out(vty, + "%% MGCP RTP transcoding has been removed.%s", VTY_NEWLINE); + return CMD_WARNING; }
DEFUN(cfg_mgcp_rtp_bts_bind_ip, @@ -724,39 +716,35 @@ ALIAS_DEPRECATED(cfg_mgcp_agent_addr, cfg_mgcp_agent_addr_cmd_old, "IPv4 Address of the callagent\n")
-DEFUN(cfg_mgcp_transcoder, +DEFUN_DEPRECATED(cfg_mgcp_transcoder, cfg_mgcp_transcoder_cmd, "transcoder-mgw A.B.C.D", "Use a MGW to detranscoder RTP\n" "The IP address of the MGW") { - bsc_replace_string(g_cfg, &g_cfg->transcoder_ip, argv[0]); - inet_aton(g_cfg->transcoder_ip, &g_cfg->transcoder_in); - - return CMD_SUCCESS; + vty_out(vty, + "%% MGCP RTP transcoding has been removed.%s", VTY_NEWLINE); + return CMD_WARNING; }
-DEFUN(cfg_mgcp_no_transcoder, +DEFUN_DEPRECATED(cfg_mgcp_no_transcoder, cfg_mgcp_no_transcoder_cmd, "no transcoder-mgw", NO_STR "Disable the transcoding\n") { - if (g_cfg->transcoder_ip) { - LOGP(DMGCP, LOGL_NOTICE, "Disabling transcoding on future calls.\n"); - talloc_free(g_cfg->transcoder_ip); - g_cfg->transcoder_ip = NULL; - } - - return CMD_SUCCESS; + vty_out(vty, + "%% MGCP RTP transcoding has been removed.%s", VTY_NEWLINE); + return CMD_WARNING; }
-DEFUN(cfg_mgcp_transcoder_remote_base, +DEFUN_DEPRECATED(cfg_mgcp_transcoder_remote_base, cfg_mgcp_transcoder_remote_base_cmd, "transcoder-remote-base <0-65534>", "Set the base port for the transcoder\n" "The RTP base port on the transcoder") { - g_cfg->transcoder_remote_base = atoi(argv[0]); - return CMD_SUCCESS; + vty_out(vty, + "%% MGCP RTP transcoding has been removed.%s", VTY_NEWLINE); + return CMD_WARNING; }
DEFUN(cfg_mgcp_trunk, cfg_mgcp_trunk_cmd, @@ -1466,29 +1454,6 @@ static int allocate_trunk(struct mgcp_trunk_config *trunk) } endp->net_end.local_alloc = PORT_ALLOC_STATIC; } - - if (trunk->trunk_type == MGCP_TRUNK_VIRTUAL && - cfg->transcoder_ip && cfg->transcoder_ports.mode == PORT_ALLOC_STATIC) { - int rtp_port; - - /* network side */ - rtp_port = rtp_calculate_port(ENDPOINT_NUMBER(endp), - cfg->transcoder_ports.base_port); - if (mgcp_bind_trans_net_rtp_port(endp, rtp_port) != 0) { - LOGP(DMGCP, LOGL_FATAL, "Failed to bind: %d\n", rtp_port); - return -1; - } - endp->trans_net.local_alloc = PORT_ALLOC_STATIC; - - /* bts side */ - rtp_port = rtp_calculate_port(endp_back_channel(ENDPOINT_NUMBER(endp)), - cfg->transcoder_ports.base_port); - if (mgcp_bind_trans_bts_rtp_port(endp, rtp_port) != 0) { - LOGP(DMGCP, LOGL_FATAL, "Failed to bind: %d\n", rtp_port); - return -1; - } - endp->trans_bts.local_alloc = PORT_ALLOC_STATIC; - } }
return 0; diff --git a/openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c b/openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c index 9fd9967..67149b8 100644 --- a/openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c +++ b/openbsc/src/osmo-bsc_nat/bsc_mgcp_utils.c @@ -1116,15 +1116,6 @@ int bsc_mgcp_nat_init(struct bsc_nat *nat) return -1; }
- if (mgcp_reset_transcoder(cfg) < 0) { - LOGP(DMGCP, LOGL_ERROR, "Failed to send packet to the transcoder.\n"); - talloc_free(nat->bsc_endpoints); - nat->bsc_endpoints = NULL; - close(cfg->gw_fd.bfd.fd); - cfg->gw_fd.bfd.fd = -1; - return -1; - } - return 0; }