From fb2ef56bb55c9406763f6c57590793dbe046ad10 Mon Sep 17 00:00:00 2001
From: "Alfred E. Heggestad" <alfred.heggestad@gmail.com>
Date: Thu, 18 Jan 2024 20:23:49 +0100
Subject: [PATCH] rtp: make struct rtp_source public (#1057)

* rtp: make struct rtp_source public

* add rtp_ prefix
---
 include/re_rtp.h | 37 +++++++++++++++++++++++++++++++++++++
 src/rtp/ntp.c    |  8 ++++----
 src/rtp/rtcp.h   | 41 ++++-------------------------------------
 src/rtp/sess.c   |  6 +++---
 4 files changed, 48 insertions(+), 44 deletions(-)

diff --git a/include/re_rtp.h b/include/re_rtp.h
index 2e8bb71b7..05ae35a0a 100644
--- a/include/re_rtp.h
+++ b/include/re_rtp.h
@@ -311,3 +311,40 @@ static inline int16_t rtp_seq_diff(uint16_t x, uint16_t y)
 {
 	return (int16_t)(y - x);
 }
+
+
+/** NTP Time */
+struct rtp_ntp_time {
+	uint32_t hi;  /**< Seconds since 0h UTC on 1 January 1900 */
+	uint32_t lo;  /**< Fraction of seconds                    */
+};
+
+/** Per-source state information */
+struct rtp_source {
+	struct sa rtp_peer;       /**< IP-address of the RTP source        */
+	uint16_t max_seq;         /**< Highest seq. number seen            */
+	uint32_t cycles;          /**< Shifted count of seq. number cycles */
+	uint32_t base_seq;        /**< Base seq number                     */
+	uint32_t bad_seq;         /**< Last 'bad' seq number + 1           */
+	uint32_t probation;       /**< Sequ. packets till source is valid  */
+	uint32_t received;        /**< Packets received                    */
+	uint32_t expected_prior;  /**< Packet expected at last interval    */
+	uint32_t received_prior;  /**< Packet received at last interval    */
+	int transit;              /**< Relative trans time for prev pkt    */
+	uint32_t jitter;          /**< Estimated jitter                    */
+	size_t rtp_rx_bytes;      /**< Number of RTP bytes received        */
+	uint64_t sr_recv;         /**< When the last SR was received       */
+	struct rtp_ntp_time last_sr;/**< NTP Timestamp from last SR recvd  */
+	uint32_t rtp_ts;          /**< RTP timestamp                       */
+	uint32_t last_rtp_ts;     /**< Last RTP timestamp                  */
+	uint32_t psent;           /**< RTP packets sent                    */
+	uint32_t osent;           /**< RTP octets sent                     */
+};
+
+/* Source */
+void rtp_source_init_seq(struct rtp_source *s, uint16_t seq);
+int  rtp_source_update_seq(struct rtp_source *s, uint16_t seq);
+void rtp_source_calc_jitter(struct rtp_source *s, uint32_t rtp_ts,
+			uint32_t arrival);
+int  rtp_source_calc_lost(const struct rtp_source *s);
+uint8_t rtp_source_calc_fraction_lost(struct rtp_source *s);
diff --git a/src/rtp/ntp.c b/src/rtp/ntp.c
index a12135fd2..41869eea1 100644
--- a/src/rtp/ntp.c
+++ b/src/rtp/ntp.c
@@ -32,7 +32,7 @@
  * @param ntp NTP time to convert to (output)
  * @param tv  Unix time to convert from (input)
  */
-void unix2ntp(struct ntp_time *ntp, const struct timeval *tv)
+void unix2ntp(struct rtp_ntp_time *ntp, const struct timeval *tv)
 {
 	ntp->hi = (uint32_t)(tv->tv_sec + UNIX_NTP_OFFSET);
 	ntp->lo = (uint32_t)((double)tv->tv_usec*(double)(1LL<<32)*1.0e-6);
@@ -45,7 +45,7 @@ void unix2ntp(struct ntp_time *ntp, const struct timeval *tv)
  * @param tv  Unix time to convert to (output)
  * @param ntp NTP time to convert from (input)
  */
-void ntp2unix(struct timeval *tv, const struct ntp_time *ntp)
+void ntp2unix(struct timeval *tv, const struct rtp_ntp_time *ntp)
 {
 	tv->tv_sec  = ntp->hi - UNIX_NTP_OFFSET;
 	tv->tv_usec = (uint32_t)(1.0e6 * (double) ntp->lo / (1LL<<32));
@@ -58,7 +58,7 @@ void ntp2unix(struct timeval *tv, const struct ntp_time *ntp)
  * @param ntp NTP time
  * @param jfs_rt Microseconds since UNIX epoch. Optional, may be NULL.
  */
-void ntp_time_get(struct ntp_time *ntp, uint64_t *jfs_rt)
+void ntp_time_get(struct rtp_ntp_time *ntp, uint64_t *jfs_rt)
 {
 #if defined(WIN32)
 	/* timeval::tv_sec on Windows is 32-bit, and it doesn't
@@ -88,7 +88,7 @@ void ntp_time_get(struct ntp_time *ntp, uint64_t *jfs_rt)
  *
  * @return NTP time in compact representation
  */
-uint32_t ntp_compact(const struct ntp_time *ntp)
+uint32_t ntp_compact(const struct rtp_ntp_time *ntp)
 {
 	return ntp ? ((ntp->hi & 0xffff) << 16 | (ntp->lo >> 16)) : 0;
 }
diff --git a/src/rtp/rtcp.h b/src/rtp/rtcp.h
index a935c659a..980daf523 100644
--- a/src/rtp/rtcp.h
+++ b/src/rtp/rtcp.h
@@ -19,35 +19,9 @@ enum {
 	RTCP_HEADROOM  =   4,  /**< Headroom in RTCP packets     */
 };
 
-/** NTP Time */
-struct ntp_time {
-	uint32_t hi;  /**< Seconds since 0h UTC on 1 January 1900 */
-	uint32_t lo;  /**< Fraction of seconds                    */
-};
 
 struct hash;
 
-/** Per-source state information */
-struct rtp_source {
-	struct sa rtp_peer;       /**< IP-address of the RTP source        */
-	uint16_t max_seq;         /**< Highest seq. number seen            */
-	uint32_t cycles;          /**< Shifted count of seq. number cycles */
-	uint32_t base_seq;        /**< Base seq number                     */
-	uint32_t bad_seq;         /**< Last 'bad' seq number + 1           */
-	uint32_t probation;       /**< Sequ. packets till source is valid  */
-	uint32_t received;        /**< Packets received                    */
-	uint32_t expected_prior;  /**< Packet expected at last interval    */
-	uint32_t received_prior;  /**< Packet received at last interval    */
-	int transit;              /**< Relative trans time for prev pkt    */
-	uint32_t jitter;          /**< Estimated jitter                    */
-	size_t rtp_rx_bytes;      /**< Number of RTP bytes received        */
-	uint64_t sr_recv;         /**< When the last SR was received       */
-	struct ntp_time last_sr;  /**< NTP Timestamp from last SR received */
-	uint32_t rtp_ts;          /**< RTP timestamp                       */
-	uint32_t last_rtp_ts;     /**< Last RTP timestamp                  */
-	uint32_t psent;           /**< RTP packets sent                    */
-	uint32_t osent;           /**< RTP octets sent                     */
-};
 
 /** RTP Member */
 struct rtp_member {
@@ -64,13 +38,6 @@ struct rtp_member {
 struct rtp_member *member_add(struct hash *ht, uint32_t src);
 struct rtp_member *member_find(struct hash *ht, uint32_t src);
 
-/* Source */
-void rtp_source_init_seq(struct rtp_source *s, uint16_t seq);
-int  rtp_source_update_seq(struct rtp_source *s, uint16_t seq);
-void rtp_source_calc_jitter(struct rtp_source *s, uint32_t rtp_ts,
-			uint32_t arrival);
-int  rtp_source_calc_lost(const struct rtp_source *s);
-uint8_t rtp_source_calc_fraction_lost(struct rtp_source *s);
 
 /* RR (Reception report) */
 int rtcp_rr_alloc(struct rtcp_rr **rrp, size_t count);
@@ -90,10 +57,10 @@ int rtcp_psfb_decode(struct mbuf *mb, struct rtcp_msg *msg);
 
 /** NTP Time */
 struct timeval;
-void unix2ntp(struct ntp_time *ntp, const struct timeval *tv);
-void ntp2unix(struct timeval *tv, const struct ntp_time *ntp);
-void ntp_time_get(struct ntp_time *ntp, uint64_t* jfs_rt);
-uint32_t ntp_compact(const struct ntp_time *ntp);
+void unix2ntp(struct rtp_ntp_time *ntp, const struct timeval *tv);
+void ntp2unix(struct timeval *tv, const struct rtp_ntp_time *ntp);
+void ntp_time_get(struct rtp_ntp_time *ntp, uint64_t* jfs_rt);
+uint32_t ntp_compact(const struct rtp_ntp_time *ntp);
 uint64_t ntp_compact2us(uint32_t ntpc);
 
 /* RTP Socket */
diff --git a/src/rtp/sess.c b/src/rtp/sess.c
index d634da08f..c53873122 100644
--- a/src/rtp/sess.c
+++ b/src/rtp/sess.c
@@ -114,7 +114,7 @@ static struct rtp_member *get_member(struct rtcp_sess *sess, uint32_t src)
  */
 void rtcp_calc_rtt(uint32_t *rtt, uint32_t lsr, uint32_t dlsr)
 {
-	struct ntp_time ntp_time;
+	struct rtp_ntp_time ntp_time;
 	uint64_t a_us, lsr_us, dlsr_us;
 
 	ntp_time_get(&ntp_time, NULL);
@@ -371,7 +371,7 @@ int rtcp_enable(struct rtcp_sess *sess, bool enabled, const char *cname)
 
 
 /** Calculate LSR (middle 32 bits out of 64 in the NTP timestamp) */
-static uint32_t calc_lsr(const struct ntp_time *last_sr)
+static uint32_t calc_lsr(const struct rtp_ntp_time *last_sr)
 {
 	return last_sr->hi ? ntp_compact(last_sr) : 0;
 }
@@ -436,7 +436,7 @@ static int mk_sr(struct rtcp_sess *sess, struct mbuf *mb)
 	mtx_unlock(sess->lock);
 
 	if (txstat.jfs_rt_ref) {
-		struct ntp_time ntp;
+		struct rtp_ntp_time ntp;
 		uint64_t jfs_rt, dur;
 		uint32_t rtp_ts;