Skip to content

Commit 31d6397

Browse files
committed
refactor: everything (again)
1 parent e7d7953 commit 31d6397

9 files changed

Lines changed: 1177 additions & 865 deletions

File tree

‎player/src/audio.rs‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use opus::Decoder;
77
use ringbuf::{LocalRb, Rb};
88

99
use protocol::AudioData;
10+
use tokio::sync::mpsc;
1011

1112
use crate::gui::visualizer::calculate_visualizer;
1213
use crate::AudioStatus;
@@ -208,20 +209,18 @@ pub enum AudioCommand {
208209
Shutdown,
209210
}
210211

211-
pub type AudioTx = std::sync::mpsc::Sender<AudioCommand>;
212-
pub type AudioRx = std::sync::mpsc::Receiver<AudioCommand>;
213-
pub type AudioStatusTx = tokio::sync::mpsc::UnboundedSender<AudioStatus>;
214-
pub type AudioStatusRx = tokio::sync::mpsc::UnboundedReceiver<AudioStatus>;
212+
pub type AudioTx = mpsc::UnboundedSender<AudioCommand>;
213+
pub type AudioRx = mpsc::UnboundedReceiver<AudioCommand>;
214+
pub type AudioStatusTx = mpsc::UnboundedSender<AudioStatus>;
215+
pub type AudioStatusRx = mpsc::UnboundedReceiver<AudioStatus>;
215216

217+
#[derive(Clone)]
216218
pub struct AudioThreadHandle {
217219
tx: AudioTx,
218220
}
219221

220222
impl AudioThreadHandle {
221-
pub fn send(
222-
&mut self,
223-
cmd: AudioCommand,
224-
) -> Result<(), std::sync::mpsc::SendError<AudioCommand>> {
223+
pub fn send(&mut self, cmd: AudioCommand) -> Result<(), mpsc::error::SendError<AudioCommand>> {
225224
self.tx.send(cmd)
226225
}
227226
}
@@ -262,7 +261,7 @@ impl AudioThread {
262261
}
263262

264263
fn run(&mut self) {
265-
while let Ok(data) = self.rx.recv() {
264+
while let Some(data) = self.rx.blocking_recv() {
266265
match data {
267266
AudioCommand::AudioData(d) => match d {
268267
AudioData::Frame(frame) => {

0 commit comments

Comments
 (0)