From c9c9438e225c37ac1b7c47880406c9c743c1d345 Mon Sep 17 00:00:00 2001 From: Sebastian Reimers Date: Sat, 7 Oct 2023 00:01:17 +0200 Subject: [PATCH] rtp: add ts_arrive header The arrival time is useful for jitter handling and local playout time calculation. --- include/re_rtp.h | 1 + src/rtp/rtcp.h | 5 ++--- src/rtp/rtp.c | 6 ++---- src/rtp/sess.c | 24 +++++++++++------------- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/include/re_rtp.h b/include/re_rtp.h index 4a654afbf..5855e27a6 100644 --- a/include/re_rtp.h +++ b/include/re_rtp.h @@ -23,6 +23,7 @@ struct rtp_header { uint8_t pt; /**< Payload type */ uint16_t seq; /**< Sequence number */ uint32_t ts; /**< Timestamp */ + uint32_t ts_arrive; /**< Arrival Timestamp */ uint32_t ssrc; /**< Synchronization source */ uint32_t csrc[16]; /**< Contributing sources */ struct { diff --git a/src/rtp/rtcp.h b/src/rtp/rtcp.h index f2635954d..194b6b692 100644 --- a/src/rtp/rtcp.h +++ b/src/rtp/rtcp.h @@ -116,6 +116,5 @@ int rtcp_send(struct rtp_sock *rs, struct mbuf *mb); void rtcp_handler(struct rtcp_sess *sess, struct rtcp_msg *msg); void rtcp_sess_tx_rtp(struct rtcp_sess *sess, uint32_t ts, uint64_t jfs_rt, size_t payload_size); -void rtcp_sess_rx_rtp(struct rtcp_sess *sess, uint16_t seq, uint32_t ts, - uint32_t src, size_t payload_size, - const struct sa *peer); +void rtcp_sess_rx_rtp(struct rtcp_sess *sess, struct rtp_header *hdr, + size_t payload_size, const struct sa *peer); diff --git a/src/rtp/rtp.c b/src/rtp/rtp.c index 3082c7d40..9f5205d46 100644 --- a/src/rtp/rtp.c +++ b/src/rtp/rtp.c @@ -205,10 +205,8 @@ static void udp_recv_handler(const struct sa *src, struct mbuf *mb, void *arg) if (err) return; - if (rs->rtcp) { - rtcp_sess_rx_rtp(rs->rtcp, hdr.seq, hdr.ts, - hdr.ssrc, mbuf_get_left(mb), src); - } + if (rs->rtcp) + rtcp_sess_rx_rtp(rs->rtcp, &hdr, mbuf_get_left(mb), src); if (rs->recvh) rs->recvh(src, &hdr, mb, rs->arg); diff --git a/src/rtp/sess.c b/src/rtp/sess.c index d4d970cbc..bba3a387a 100644 --- a/src/rtp/sess.c +++ b/src/rtp/sess.c @@ -563,47 +563,45 @@ void rtcp_sess_tx_rtp(struct rtcp_sess *sess, uint32_t ts, uint64_t jfs_rt, } -void rtcp_sess_rx_rtp(struct rtcp_sess *sess, uint16_t seq, uint32_t ts, - uint32_t ssrc, size_t payload_size, - const struct sa *peer) +void rtcp_sess_rx_rtp(struct rtcp_sess *sess, struct rtp_header *hdr, + size_t payload_size, const struct sa *peer) { struct rtp_member *mbr; if (!sess) return; - mbr = get_member(sess, ssrc); + mbr = get_member(sess, hdr->ssrc); if (!mbr) { - DEBUG_NOTICE("could not add member: 0x%08x\n", ssrc); + DEBUG_NOTICE("could not add member: 0x%08x\n", hdr->ssrc); return; } if (!mbr->s) { mbr->s = mem_zalloc(sizeof(*mbr->s), NULL); if (!mbr->s) { - DEBUG_NOTICE("could not add sender: 0x%08x\n", ssrc); + DEBUG_NOTICE("could not add sender: 0x%08x\n", + hdr->ssrc); return; } /* first packet - init sequence number */ - source_init_seq(mbr->s, seq); + source_init_seq(mbr->s, hdr->seq); /* probation not used */ sa_cpy(&mbr->s->rtp_peer, peer); ++sess->senderc; } - if (!source_update_seq(mbr->s, seq)) { + if (!source_update_seq(mbr->s, hdr->seq)) { DEBUG_WARNING("rtp_update_seq() returned 0\n"); } if (sess->srate_rx) { - - uint64_t ts_arrive; - /* Convert from wall-clock time to timestamp units */ - ts_arrive = tmr_jiffies() * sess->srate_rx / 1000; + hdr->ts_arrive = + (uint32_t)(tmr_jiffies() * sess->srate_rx / 1000); - source_calc_jitter(mbr->s, ts, (uint32_t)ts_arrive); + source_calc_jitter(mbr->s, hdr->ts, hdr->ts_arrive); } mbr->s->rtp_rx_bytes += payload_size;