diff --git a/include/re_rtp.h b/include/re_rtp.h index 5855e27a6..2e8bb71b7 100644 --- a/include/re_rtp.h +++ b/include/re_rtp.h @@ -23,7 +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 */ + uint64_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 194b6b692..d85404866 100644 --- a/src/rtp/rtcp.h +++ b/src/rtp/rtcp.h @@ -44,6 +44,7 @@ struct rtp_source { 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 */ }; diff --git a/src/rtp/sess.c b/src/rtp/sess.c index bba3a387a..4d6e5f565 100644 --- a/src/rtp/sess.c +++ b/src/rtp/sess.c @@ -598,12 +598,19 @@ void rtcp_sess_rx_rtp(struct rtcp_sess *sess, struct rtp_header *hdr, if (sess->srate_rx) { /* Convert from wall-clock time to timestamp units */ - hdr->ts_arrive = - (uint32_t)(tmr_jiffies() * sess->srate_rx / 1000); - - source_calc_jitter(mbr->s, hdr->ts, hdr->ts_arrive); + hdr->ts_arrive = tmr_jiffies() * sess->srate_rx / 1000; + + /* + * Calculate jitter only when the timestamp is different than + * last packet (see RTP FAQ + * https://www.cs.columbia.edu/~hgs/rtp/faq.html#jitter). + */ + if (hdr->ts != mbr->s->last_rtp_ts) + source_calc_jitter(mbr->s, hdr->ts, + (uint32_t)hdr->ts_arrive); } + mbr->s->last_rtp_ts = hdr->ts; mbr->s->rtp_rx_bytes += payload_size; }