diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2020-10-14 19:42:28 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2020-10-14 19:42:28 +0200 |
| commit | afd537e085ddf2c92fb1f1879a72d290010fa570 (patch) | |
| tree | d789c98a4748cc391e91794737399056977223fc /mumd | |
| parent | 8f32d34f1cf31cfd10d07e623842dd3f7fc86e8e (diff) | |
| download | mum-afd537e085ddf2c92fb1f1879a72d290010fa570.tar.gz | |
cargo clippy
Diffstat (limited to 'mumd')
| -rw-r--r-- | mumd/src/audio.rs | 20 | ||||
| -rw-r--r-- | mumd/src/main.rs | 8 | ||||
| -rw-r--r-- | mumd/src/network/tcp.rs | 14 | ||||
| -rw-r--r-- | mumd/src/state.rs | 50 |
4 files changed, 45 insertions, 47 deletions
diff --git a/mumd/src/audio.rs b/mumd/src/audio.rs index 58424b6..d8a37a8 100644 --- a/mumd/src/audio.rs +++ b/mumd/src/audio.rs @@ -107,7 +107,7 @@ impl Audio { input_encoder, input_sender, input_config.sample_rate.0, - 10.0, + 4, // 10 ms ), err_fn, ), @@ -117,7 +117,7 @@ impl Audio { input_encoder, input_sender, input_config.sample_rate.0, - 10.0, + 4, // 10 ms ), err_fn, ), @@ -127,7 +127,7 @@ impl Audio { input_encoder, input_sender, input_config.sample_rate.0, - 10.0, + 4, // 10 ms ), err_fn, ), @@ -276,16 +276,16 @@ fn input_callback<T: Sample>( mut opus_encoder: opus::Encoder, mut input_sender: Sender<VoicePacketPayload>, sample_rate: u32, - opus_frame_size_ms: f32, + opus_frame_size_blocks: u32, // blocks of 2.5ms ) -> impl FnMut(&[T], &InputCallbackInfo) + Send + 'static { - if !(opus_frame_size_ms == 2.5 - || opus_frame_size_ms == 5.0 - || opus_frame_size_ms == 10.0 - || opus_frame_size_ms == 20.0) + if !(opus_frame_size_blocks == 1 + || opus_frame_size_blocks == 2 + || opus_frame_size_blocks == 4 + || opus_frame_size_blocks == 8) { - panic!("Unsupported opus frame size {}", opus_frame_size_ms); + panic!("Unsupported amount of opus frame blocks {}", opus_frame_size_blocks); } - let opus_frame_size = (opus_frame_size_ms * sample_rate as f32) as u32 / 1000; + let opus_frame_size = opus_frame_size_blocks * sample_rate / 400; let buf = Arc::new(Mutex::new(VecDeque::new())); move |data: &[T], _info: &InputCallbackInfo| { diff --git a/mumd/src/main.rs b/mumd/src/main.rs index 797b71f..f837a52 100644 --- a/mumd/src/main.rs +++ b/mumd/src/main.rs @@ -119,13 +119,13 @@ async fn main() { } async fn send_commands(command_sender: mpsc::UnboundedSender<Command>, connect_command: Command) { - command_sender.send(connect_command.clone()); + command_sender.send(connect_command.clone()).unwrap(); tokio::time::delay_for(Duration::from_secs(2)).await; - command_sender.send(Command::ServerDisconnect); + command_sender.send(Command::ServerDisconnect).unwrap(); tokio::time::delay_for(Duration::from_secs(2)).await; - command_sender.send(connect_command.clone()); + command_sender.send(connect_command.clone()).unwrap(); tokio::time::delay_for(Duration::from_secs(2)).await; - command_sender.send(Command::ServerDisconnect); + command_sender.send(Command::ServerDisconnect).unwrap(); debug!("Finished sending commands"); } diff --git a/mumd/src/network/tcp.rs b/mumd/src/network/tcp.rs index e096843..6a369e5 100644 --- a/mumd/src/network/tcp.rs +++ b/mumd/src/network/tcp.rs @@ -186,7 +186,7 @@ async fn send_packets( } //clears queue of remaining packets - while let Ok(_) = packet_receiver.try_recv() {} + while packet_receiver.try_recv().is_ok() {} sink.close().await.unwrap(); }; @@ -270,12 +270,12 @@ async fn listen( } let mut state = state.lock().unwrap(); let server = state.server_mut().unwrap(); - server.parse_server_sync(msg); + server.parse_server_sync(*msg); match &server.welcome_text { Some(s) => info!("Welcome: {}", s), None => info!("No welcome received"), } - for (_, channel) in server.channels() { + for channel in server.channels().values() { info!("Found channel {}", channel.name()); } state.initialized(); @@ -288,9 +288,9 @@ async fn listen( let session = msg.get_session(); state.audio_mut().add_client(msg.get_session()); //TODO if *state.phase_receiver().borrow() == StatePhase::Connecting { - state.parse_initial_user_state(msg); + state.parse_initial_user_state(*msg); } else { - state.server_mut().unwrap().parse_user_state(msg); + state.server_mut().unwrap().parse_user_state(*msg); } let server = state.server_mut().unwrap(); let user = server.users().get(&session).unwrap(); @@ -311,7 +311,7 @@ async fn listen( .unwrap() .server_mut() .unwrap() - .parse_channel_state(msg); //TODO parse initial if initial + .parse_channel_state(*msg); //TODO parse initial if initial } ControlPacket::ChannelRemove(msg) => { state @@ -319,7 +319,7 @@ async fn listen( .unwrap() .server_mut() .unwrap() - .parse_channel_remove(msg); + .parse_channel_remove(*msg); } _ => {} } diff --git a/mumd/src/state.rs b/mumd/src/state.rs index 69a462d..b6fe780 100644 --- a/mumd/src/state.rs +++ b/mumd/src/state.rs @@ -135,30 +135,28 @@ impl State { } } - pub fn parse_initial_user_state(&mut self, msg: Box<msgs::UserState>) { + pub fn parse_initial_user_state(&mut self, msg: msgs::UserState) { if !msg.has_session() { warn!("Can't parse user state without session"); return; } if !msg.has_name() { warn!("Missing name in initial user state"); - } else { - if msg.get_name() == self.username.as_ref().unwrap() { - match self.session_id { - None => { - debug!("Found our session id: {}", msg.get_session()); - self.session_id = Some(msg.get_session()); - } - Some(session) => { - if session != msg.get_session() { - error!( - "Got two different session IDs ({} and {}) for ourselves", - session, - msg.get_session() - ); - } else { - debug!("Got our session ID twice"); - } + } else if msg.get_name() == self.username.as_ref().unwrap() { + match self.session_id { + None => { + debug!("Found our session id: {}", msg.get_session()); + self.session_id = Some(msg.get_session()); + } + Some(session) => { + if session != msg.get_session() { + error!( + "Got two different session IDs ({} and {}) for ourselves", + session, + msg.get_session() + ); + } else { + debug!("Got our session ID twice"); } } } @@ -209,13 +207,13 @@ impl Server { } } - pub fn parse_server_sync(&mut self, mut msg: Box<msgs::ServerSync>) { + pub fn parse_server_sync(&mut self, mut msg: msgs::ServerSync) { if msg.has_welcome_text() { self.welcome_text = Some(msg.take_welcome_text()); } } - pub fn parse_channel_state(&mut self, msg: Box<msgs::ChannelState>) { + pub fn parse_channel_state(&mut self, msg: msgs::ChannelState) { if !msg.has_channel_id() { warn!("Can't parse channel state without channel id"); return; @@ -228,7 +226,7 @@ impl Server { } } - pub fn parse_channel_remove(&mut self, msg: Box<msgs::ChannelRemove>) { + pub fn parse_channel_remove(&mut self, msg: msgs::ChannelRemove) { if !msg.has_channel_id() { warn!("Can't parse channel remove without channel id"); return; @@ -243,7 +241,7 @@ impl Server { } } - pub fn parse_user_state(&mut self, msg: Box<msgs::UserState>) { + pub fn parse_user_state(&mut self, msg: msgs::UserState) { if !msg.has_session() { warn!("Can't parse user state without session"); return; @@ -276,7 +274,7 @@ pub struct Channel { } impl Channel { - pub fn new(mut msg: Box<msgs::ChannelState>) -> Self { + pub fn new(mut msg: msgs::ChannelState) -> Self { Self { description: if msg.has_description() { Some(msg.take_description()) @@ -295,7 +293,7 @@ impl Channel { } } - pub fn parse_channel_state(&mut self, mut msg: Box<msgs::ChannelState>) { + pub fn parse_channel_state(&mut self, mut msg: msgs::ChannelState) { if msg.has_description() { self.description = Some(msg.take_description()); } @@ -336,7 +334,7 @@ pub struct User { } impl User { - pub fn new(mut msg: Box<msgs::UserState>) -> Self { + pub fn new(mut msg: msgs::UserState) -> Self { Self { channel: msg.get_channel_id(), comment: if msg.has_comment() { @@ -360,7 +358,7 @@ impl User { } } - pub fn parse_user_state(&mut self, mut msg: Box<msgs::UserState>) { + pub fn parse_user_state(&mut self, mut msg: msgs::UserState) { if msg.has_channel_id() { self.channel = msg.get_channel_id(); } |
