]> code.octet-stream.net Git - m17rt/blobdiff - m17app/src/soundcard.rs
Add error handling
[m17rt] / m17app / src / soundcard.rs
index b12ef8839a3d64f9be476e91ebae4ca63a941d39..f89d9f4e43a9ee6a1d34ee667a90b98a7c440b8e 100644 (file)
@@ -12,7 +12,7 @@ use cpal::{
 };
 
 use crate::{
-    error::M17Error,
+    error::{M17Error, SoundmodemError},
     soundmodem::{InputSource, OutputBuffer, OutputSink, SoundmodemEvent},
 };
 
@@ -63,10 +63,7 @@ impl Soundcard {
                 continue;
             };
             if configs
-                .find(|config| {
-                    config.channels() == 1 && config.sample_format() == SampleFormat::I16
-                })
-                .is_some()
+                .any(|config| config.channels() == 1 && config.sample_format() == SampleFormat::I16)
             {
                 let Ok(name) = d.name() else {
                     continue;
@@ -89,10 +86,7 @@ impl Soundcard {
                 continue;
             };
             if configs
-                .find(|config| {
-                    config.channels() == 1 && config.sample_format() == SampleFormat::I16
-                })
-                .is_some()
+                .any(|config| config.channels() == 1 && config.sample_format() == SampleFormat::I16)
             {
                 let Ok(name) = d.name() else {
                     continue;
@@ -124,12 +118,12 @@ pub struct SoundcardInputSource {
 }
 
 impl InputSource for SoundcardInputSource {
-    fn start(&self, samples: SyncSender<SoundmodemEvent>) {
-        let _ = self.event_tx.send(SoundcardEvent::StartInput { samples });
+    fn start(&self, samples: SyncSender<SoundmodemEvent>) -> Result<(), SoundmodemError> {
+        Ok(self.event_tx.send(SoundcardEvent::StartInput { samples })?)
     }
 
-    fn close(&self) {
-        let _ = self.event_tx.send(SoundcardEvent::CloseInput);
+    fn close(&self) -> Result<(), SoundmodemError> {
+        Ok(self.event_tx.send(SoundcardEvent::CloseInput)?)
     }
 }
 
@@ -138,14 +132,18 @@ pub struct SoundcardOutputSink {
 }
 
 impl OutputSink for SoundcardOutputSink {
-    fn start(&self, event_tx: SyncSender<SoundmodemEvent>, buffer: Arc<RwLock<OutputBuffer>>) {
-        let _ = self
+    fn start(
+        &self,
+        event_tx: SyncSender<SoundmodemEvent>,
+        buffer: Arc<RwLock<OutputBuffer>>,
+    ) -> Result<(), SoundmodemError> {
+        Ok(self
             .event_tx
-            .send(SoundcardEvent::StartOutput { event_tx, buffer });
+            .send(SoundcardEvent::StartOutput { event_tx, buffer })?)
     }
 
-    fn close(&self) {
-        let _ = self.event_tx.send(SoundcardEvent::CloseOutput);
+    fn close(&self) -> Result<(), SoundmodemError> {
+        Ok(self.event_tx.send(SoundcardEvent::CloseOutput)?)
     }
 }