From 551899fa4e93e25c2ff3b80ad8ced8029eefe572 Mon Sep 17 00:00:00 2001 From: Niko Date: Mon, 7 Oct 2024 22:33:38 -0600 Subject: [PATCH] Move debug logging into RtpPacket event --- scripty_audio_handler/src/audio_handler.rs | 5 +++ scripty_audio_handler/src/events/mod.rs | 2 ++ .../src/events/rtp_packet.rs | 17 ++++++++++ .../src/events/voice_tick.rs | 34 ------------------- 4 files changed, 24 insertions(+), 34 deletions(-) create mode 100644 scripty_audio_handler/src/events/rtp_packet.rs diff --git a/scripty_audio_handler/src/audio_handler.rs b/scripty_audio_handler/src/audio_handler.rs index a687c23..642ba9d 100644 --- a/scripty_audio_handler/src/audio_handler.rs +++ b/scripty_audio_handler/src/audio_handler.rs @@ -276,6 +276,11 @@ impl EventHandler for AudioHandler { self.seen_users.clone(), self.ephemeral, )), + EventContext::RtpPacket(rtp_data) => { + rtp_packet(rtp_data, self.guild_id); + return None; + } + _ => return None, }; None diff --git a/scripty_audio_handler/src/events/mod.rs b/scripty_audio_handler/src/events/mod.rs index 29465e6..c25d040 100644 --- a/scripty_audio_handler/src/events/mod.rs +++ b/scripty_audio_handler/src/events/mod.rs @@ -1,11 +1,13 @@ mod client_disconnect; mod driver_connect; mod driver_disconnect; +mod rtp_packet; mod speaking_state_update; mod voice_tick; pub use client_disconnect::client_disconnect; pub use driver_connect::driver_connect; pub use driver_disconnect::driver_disconnect; +pub use rtp_packet::rtp_packet; pub use speaking_state_update::speaking_state_update; pub use voice_tick::{voice_tick, VoiceTickContext}; diff --git a/scripty_audio_handler/src/events/rtp_packet.rs b/scripty_audio_handler/src/events/rtp_packet.rs new file mode 100644 index 0000000..f73214b --- /dev/null +++ b/scripty_audio_handler/src/events/rtp_packet.rs @@ -0,0 +1,17 @@ +use serenity::model::id::GuildId; +use songbird::events::context_data::RtpData; + +pub fn rtp_packet(rtp_packet: &RtpData, guild_id: GuildId) { + let rtp_packet = rtp_packet.rtp(); + let ssrc = rtp_packet.get_ssrc(); + let timestamp = rtp_packet.get_timestamp().0; + let sequence = rtp_packet.get_sequence().0; + + trace!( + %guild_id, + %ssrc, + "debug_log_audio_data: RTP packet data: sequence {}, timestamp {}", + sequence, + timestamp, + ); +} diff --git a/scripty_audio_handler/src/events/voice_tick.rs b/scripty_audio_handler/src/events/voice_tick.rs index cdfec62..67a3ae5 100644 --- a/scripty_audio_handler/src/events/voice_tick.rs +++ b/scripty_audio_handler/src/events/voice_tick.rs @@ -66,8 +66,6 @@ pub async fn voice_tick( kiai_client, }: VoiceTickContext, ) { - debug_log_audio_data(&voice_data, guild_id); - let metrics = scripty_metrics::get_metrics(); let tick_start_time = Instant::now(); @@ -117,38 +115,6 @@ pub async fn voice_tick( metrics.audio_tick_time.observe(total_tick_time); } -fn debug_log_audio_data(VoiceTick { speaking, .. }: &VoiceTick, guild_id: GuildId) { - for ( - ssrc, - VoiceData { - packet, - decoded_voice, - .. - }, - ) in speaking.iter() - { - let voice_is_empty = if let Some(decoded_voice) = decoded_voice { - decoded_voice.iter().all(|x| *x == 0) - } else { - warn!(%guild_id, %ssrc, "debug_log_audio_data: packet for this voice tick lost"); - true - }; - if let Some(packet) = packet { - let rtp = packet.rtp(); - trace!( - %guild_id, - %ssrc, - "debug_log_audio_data: RTP packet data: sequence {}, timestamp {}, voice_is_empty {}", - rtp.get_sequence().0, - rtp.get_timestamp().0, - voice_is_empty - ); - } else { - trace!(%guild_id, %ssrc, "debug_log_audio_data: no RTP packet for this tick: voice_is_empty {}", voice_is_empty); - } - } -} - struct SilentSpeakersContext { ssrc_state: Arc, last_tick_speakers: DashSet,