Skip to content

Commit

Permalink
rtp: use uint64_t for ts_arrive and fix video jitter calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
sreimers committed Oct 7, 2023
1 parent f58c9f6 commit 8549260
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion include/re_rtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/rtp/rtcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
};
Expand Down
15 changes: 11 additions & 4 deletions src/rtp/sess.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 8549260

Please sign in to comment.