From 368312a4f523eecb43fdb1e629c968508f702a78 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Tue, 6 Feb 2018 13:40:03 -0500 Subject: [PATCH] TT#31403 keep local packet stats for RTCP output/rewriting Change-Id: Ib086bbacf5613e1480bfb9050612163152e24b28 --- daemon/codec.c | 11 ++++++++++- daemon/ssrc.h | 6 ++++++ lib/codeclib.c | 6 +++++- lib/codeclib.h | 2 +- recording-daemon/packet.c | 2 +- 5 files changed, 23 insertions(+), 4 deletions(-) diff --git a/daemon/codec.c b/daemon/codec.c index 7fed58813..e1cc659ea 100644 --- a/daemon/codec.c +++ b/daemon/codec.c @@ -504,6 +504,9 @@ static int __packet_encoded(encoder_t *enc, void *u1, void *u2) { p->free_func = free; g_queue_push_tail(&mp->packets_out, p); + atomic64_inc(&mp->ssrc_out->packets); + atomic64_add(&mp->ssrc_out->octets, inout.len); + if (ret == 0) { // no more to go break; @@ -546,6 +549,9 @@ static int handler_func_transcode(struct codec_handler *h, struct call_media *me if (G_UNLIKELY(!ch)) return 0; + atomic64_inc(&mp->ssrc_in->packets); + atomic64_add(&mp->ssrc_in->octets, mp->payload.len); + struct transcode_packet *packet = g_slice_alloc0(sizeof(*packet)); packet->p.seq = ntohs(mp->rtp->seq_num); packet->payload = str_dup(&mp->payload); @@ -564,10 +570,13 @@ static int handler_func_transcode(struct codec_handler *h, struct call_media *me // got a new packet, run decoder while (1) { - packet = packet_sequencer_next_packet(&ch->sequencer); + unsigned int lost; + packet = packet_sequencer_next_packet(&ch->sequencer, &lost); if (G_UNLIKELY(!packet)) break; + atomic64_add(&mp->ssrc_in->packets_lost, lost); + ilog(LOG_DEBUG, "Decoding RTP packet: seq %u, TS %lu", packet->p.seq, packet->ts); diff --git a/daemon/ssrc.h b/daemon/ssrc.h index 249220913..2cd040e14 100644 --- a/daemon/ssrc.h +++ b/daemon/ssrc.h @@ -40,7 +40,13 @@ struct ssrc_ctx { u_int64_t srtp_index, srtcp_index; // XXX move entire crypto context in here? + + // for transcoding u_int32_t ssrc_map_out; + + atomic64 packets, + octets, + packets_lost; }; struct ssrc_stats_block { diff --git a/lib/codeclib.c b/lib/codeclib.c index 15cfd348f..5eeedd42c 100644 --- a/lib/codeclib.c +++ b/lib/codeclib.c @@ -631,7 +631,7 @@ static int packet_tree_search(const void *testseq_p, const void *ts_p) { return -1; } // caller must take care of locking -void *packet_sequencer_next_packet(packet_sequencer_t *ps) { +void *packet_sequencer_next_packet(packet_sequencer_t *ps, unsigned int *lost) { // see if we have a packet with the correct seq nr in the queue seq_packet_t *packet = g_tree_lookup(ps->packets, GINT_TO_POINTER(ps->seq)); if (G_LIKELY(packet != NULL)) { @@ -679,6 +679,10 @@ void *packet_sequencer_next_packet(packet_sequencer_t *ps) { dbg("lost multiple packets - returning packet with next highest seq %i", packet->seq); out: + if (lost) { + u_int16_t l = packet->seq - ps->seq; + *lost = l; + } g_tree_steal(ps->packets, GINT_TO_POINTER(packet->seq)); ps->seq = (packet->seq + 1) & 0xffff; return packet; diff --git a/lib/codeclib.h b/lib/codeclib.h index 372940575..5ffdada7f 100644 --- a/lib/codeclib.h +++ b/lib/codeclib.h @@ -142,7 +142,7 @@ int encoder_input_fifo(encoder_t *enc, AVFrame *frame, void packet_sequencer_init(packet_sequencer_t *ps, GDestroyNotify); void packet_sequencer_destroy(packet_sequencer_t *ps); -void *packet_sequencer_next_packet(packet_sequencer_t *ps); +void *packet_sequencer_next_packet(packet_sequencer_t *ps, unsigned int *); int packet_sequencer_insert(packet_sequencer_t *ps, seq_packet_t *); diff --git a/recording-daemon/packet.c b/recording-daemon/packet.c index 91b1e0d12..28a727d0e 100644 --- a/recording-daemon/packet.c +++ b/recording-daemon/packet.c @@ -105,7 +105,7 @@ static void packet_decode(ssrc_t *ssrc, packet_t *packet) { static void ssrc_run(ssrc_t *ssrc) { while (1) { // see if we have a packet with the correct seq nr in the queue - packet_t *packet = packet_sequencer_next_packet(&ssrc->sequencer); + packet_t *packet = packet_sequencer_next_packet(&ssrc->sequencer, NULL); if (G_UNLIKELY(packet == NULL)) break;