From 92bcedc08ae9bc692bf4bc29467f12b3502617b8 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 2 Apr 2020 13:03:21 -0400 Subject: [PATCH] TT#78307 keep track of RTP stats also when forwarding Change-Id: Iea6214104b7032687608af71f6270a375fed2702 --- daemon/call.c | 14 +++++++++----- daemon/media_socket.c | 15 ++++++++++++++- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/daemon/call.c b/daemon/call.c index b0e7fdcb5..72582ae50 100644 --- a/daemon/call.c +++ b/daemon/call.c @@ -638,12 +638,16 @@ static void call_timer(void *ptr) { } mutex_lock(&ps->in_lock); - if (sfd->crypto.params.crypto_suite && ps->ssrc_in - && ntohl(ke->target.ssrc) == ps->ssrc_in->parent->h.ssrc - && ke->target.decrypt.last_index - ps->ssrc_in->srtp_index > 0x4000) - { + + if (ps->ssrc_in && ntohl(ke->target.ssrc) == ps->ssrc_in->parent->h.ssrc) { + atomic64_add(&ps->ssrc_in->octets, diff_bytes); + atomic64_add(&ps->ssrc_in->packets, diff_packets); ps->ssrc_in->srtp_index = ke->target.decrypt.last_index; - update = 1; + + if (sfd->crypto.params.crypto_suite + && ke->target.decrypt.last_index + - ps->ssrc_in->srtp_index > 0x4000) + update = 1; } mutex_unlock(&ps->in_lock); } diff --git a/daemon/media_socket.c b/daemon/media_socket.c index 471888878..1cea7406c 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -1848,9 +1848,22 @@ static int stream_packet(struct packet_handler_ctx *phc) { media_packet_rtp(phc); // SSRC receive stats - if (phc->mp.ssrc_in) { + if (phc->mp.ssrc_in && phc->mp.rtp) { atomic64_inc(&phc->mp.ssrc_in->packets); atomic64_add(&phc->mp.ssrc_in->packets, phc->mp.raw.len); + // no real sequencing, so this is rudimentary + uint64_t old_seq = atomic64_get(&phc->mp.ssrc_in->last_seq); + uint64_t new_seq = ntohs(phc->mp.rtp->seq_num) | (old_seq & 0xffff0000UL); + // XXX combine this with similar code elsewhere + long seq_diff = new_seq - old_seq; + while (seq_diff < -60000) { + new_seq += 0x10000; + seq_diff += 0x10000; + } + if (seq_diff > 0 || seq_diff < -10) { + atomic64_set(&phc->mp.ssrc_in->last_seq, new_seq); + atomic64_set(&phc->mp.ssrc_in->last_ts, ntohl(phc->mp.rtp->timestamp)); + } }