From 151dfdbabcc5e611e07a0d55676369df5c65bcb1 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Mon, 14 Nov 2022 09:43:31 -0500 Subject: [PATCH] MT#55283 allow for delay in kernel mode In some cases it's possible that some packets still arrive in userspace immediately after a stream has been pushed to the kernel, for example if some packets are already in the queue or if there is some processing delay (e.g. writing to Redis). Allow for a short delay before counting a stream as userspace if it has been pushed to the kernel. Change-Id: I55a6e255868c8c2a9e93355a4aa2287f07b3748d (cherry picked from commit 8a99171200ac341dc1b8436b587790d0ec35a9cd) (cherry picked from commit 0cbf96b18753506d1247e54870538312aad81857) --- daemon/media_socket.c | 5 ++++- include/call.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/daemon/media_socket.c b/daemon/media_socket.c index 7ba7918db..50a9db4af 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -1419,6 +1419,7 @@ void kernelize(struct packet_stream *stream) { g_slice_free1(sizeof(*redi), redi); } + stream->kernel_time = rtpe_now.tv_sec; PS_SET(stream, KERNELIZED); return; @@ -1426,6 +1427,7 @@ no_kernel_warn: ilog(LOG_WARNING, "No support for kernel packet forwarding available (%s)", nk_warn_msg); no_kernel: PS_SET(stream, KERNELIZED); + stream->kernel_time = rtpe_now.tv_sec; PS_SET(stream, NO_KERNEL_SUPPORT); } @@ -2433,7 +2435,8 @@ static int stream_packet(struct packet_handler_ctx *phc) { RTPE_STATS_INC(packets_user); RTPE_STATS_ADD(bytes_user, phc->s.len); - count_stream_stats_userspace(phc->mp.stream); + if (!PS_ISSET(phc->mp.stream, KERNELIZED) || rtpe_now.tv_sec > phc->mp.stream->kernel_time + 1) + count_stream_stats_userspace(phc->mp.stream); int address_check = media_packet_address_check(phc); if (address_check) diff --git a/include/call.h b/include/call.h index 687da9f3a..52f50ce48 100644 --- a/include/call.h +++ b/include/call.h @@ -341,6 +341,7 @@ struct packet_stream { ssrc_out_idx; // LOCK: out_lock struct send_timer *send_timer; /* RO */ struct jitter_buffer *jb; /* RO */ + time_t kernel_time; struct stream_stats stats; struct stream_stats kernel_stats;