From fab9d12a44985021a769f39fbdf11a5138785a99 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 27 Jan 2023 11:49:20 +0100 Subject: [PATCH] module-rtp-source: use simple boolean to check activity Avoid doing clock_gettime for each RTP packet and use a simple boolean to check if packets arrived since the last SAP timeout check. --- src/modules/module-rtp-source.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/modules/module-rtp-source.c b/src/modules/module-rtp-source.c index 847b0e319..21400256d 100644 --- a/src/modules/module-rtp-source.c +++ b/src/modules/module-rtp-source.c @@ -247,6 +247,7 @@ struct session { float max_error; unsigned buffering:1; unsigned first:1; + unsigned receiving:1; }; static void stream_destroy(void *d) @@ -443,8 +444,8 @@ on_rtp_io(void *data, int fd, uint32_t mask) filled, target_buffer); } } + sess->receiving = true; } - session_touch(sess); return; receive_error: @@ -1100,10 +1101,16 @@ static void on_timer_event(void *data, uint64_t expirations) spa_list_for_each_safe(sess, tmp, &impl->sessions, link) { if (sess->timestamp + interval < timestamp) { - pw_log_debug("More than %lu elapsed from last advertisement at %lu", interval, sess->timestamp); - pw_log_info("No advertisement packets found for timeout, closing RTP source"); - session_free(sess); + pw_log_debug("More than %lu elapsed from last advertisement at %lu", + interval, sess->timestamp); + if (!sess->receiving) { + pw_log_info("SAP timeout, closing inactive RTP source"); + session_free(sess); + } else { + pw_log_info("SAP timeout, keeping active RTP source"); + } } + sess->receiving = false; } }