aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSylvain Munaut <tnt@246tNt.com>2019-03-11 15:36:13 +0100
committerHarald Welte <laforge@gnumonks.org>2019-03-19 13:57:06 +0000
commitbab7ae7e884cd460f64d18ca703ae1ea238fa054 (patch)
tree8c9469aae6acd453d6f52d369d0142d6c0d0c53d
parentc674e9fcdfbf415625b1a5e4a7331416735232be (diff)
rtp: Add 'autoconnect' feature to the osmo_rtp_socket
The bound RTP socket will wait for incoming RTP packets and as soon as it sees one, will 'connect' to it, so all replies will go to that sources and incoming messages from other sources will be discarded. This obviously only works once. Change-Id: I5b54ca4296901fcf37794faf29e0b2acca27bd1b Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
-rw-r--r--include/osmocom/trau/osmo_ortp.h1
-rw-r--r--src/trau/osmo_ortp.c22
2 files changed, 23 insertions, 0 deletions
diff --git a/include/osmocom/trau/osmo_ortp.h b/include/osmocom/trau/osmo_ortp.h
index 5fb2960..54afcf0 100644
--- a/include/osmocom/trau/osmo_ortp.h
+++ b/include/osmocom/trau/osmo_ortp.h
@@ -74,6 +74,7 @@ void osmo_rtp_init(void *ctx);
struct osmo_rtp_socket *osmo_rtp_socket_create(void *talloc_ctx, unsigned int flags);
int osmo_rtp_socket_bind(struct osmo_rtp_socket *rs, const char *ip, int port);
int osmo_rtp_socket_connect(struct osmo_rtp_socket *rs, const char *ip, uint16_t port);
+int osmo_rtp_socket_autoconnect(struct osmo_rtp_socket *rs);
int osmo_rtp_socket_set_pt(struct osmo_rtp_socket *rs, int payload_type);
int osmo_rtp_socket_free(struct osmo_rtp_socket *rs);
int osmo_rtp_skipped_frame(struct osmo_rtp_socket *rs, unsigned int duration);
diff --git a/src/trau/osmo_ortp.c b/src/trau/osmo_ortp.c
index 0eb1661..1d652cb 100644
--- a/src/trau/osmo_ortp.c
+++ b/src/trau/osmo_ortp.c
@@ -468,6 +468,28 @@ int osmo_rtp_socket_connect(struct osmo_rtp_socket *rs, const char *ip, uint16_t
return osmo_rtp_socket_fdreg(rs);
}
+/*! \brief Automatically associates a RTP socket with the first incoming UDP packet
+ * \param[in] rs OsmoRTP socket
+ *
+ * The bound RTP socket will wait for incoming RTP packets and as soon as it
+ * sees one, will 'connect' to it, so all replies will go to that sources and
+ * incoming messages from other sources will be discarded. This obviously only
+ * works once.
+ *
+ * \returns 0 on success, <0 in case of error.
+ */
+int osmo_rtp_socket_autoconnect(struct osmo_rtp_socket *rs)
+{
+ rtp_session_set_symmetric_rtp(rs->sess, 1);
+ rtp_session_set_connected_mode(rs->sess, 1);
+ rs->flags &= ~OSMO_RTP_F_DISABLED;
+
+ if (rs->flags & OSMO_RTP_F_POLL)
+ return 0;
+ else
+ return osmo_rtp_socket_fdreg(rs);
+}
+
/*! \brief Increment timestamp on a RTP socket without sending any packet
* \param[in] rs OsmoRTP socket
* \param[in] duration duration in number of RTP clock ticks