Skip to content

Commit

Permalink
rtp: add ts_arrive header
Browse files Browse the repository at this point in the history
The arrival time is useful for jitter handling and local playout time
calculation.
  • Loading branch information
sreimers committed Oct 6, 2023
1 parent 33599fa commit 7289573
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
1 change: 1 addition & 0 deletions include/re_rtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; /**< Local Timestamp */
uint32_t ssrc; /**< Synchronization source */
uint32_t csrc[16]; /**< Contributing sources */
struct {
Expand Down
5 changes: 2 additions & 3 deletions src/rtp/rtcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
6 changes: 2 additions & 4 deletions src/rtp/rtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 11 additions & 13 deletions src/rtp/sess.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 7289573

Please sign in to comment.