]> code.octet-stream.net Git - m17rt/blobdiff - m17codec2/src/rx.rs
Make netclient work against mrefd
[m17rt] / m17codec2 / src / rx.rs
index 7c456109fc85ce703ecd9a9e30c867f184d30246..455ce42966071e489d53d37abe81cc2c25faddbc 100644 (file)
@@ -17,8 +17,8 @@ use std::fs::File;
 use std::io::Write;
 use std::path::Path;
 use std::sync::{
 use std::io::Write;
 use std::path::Path;
 use std::sync::{
-    mpsc::{channel, Receiver, Sender},
     Arc, Mutex,
     Arc, Mutex,
+    mpsc::{Receiver, Sender, channel},
 };
 
 /// Write one or more 8-byte chunks of 3200-bit Codec2 to a raw S16LE file
 };
 
 /// Write one or more 8-byte chunks of 3200-bit Codec2 to a raw S16LE file
@@ -62,6 +62,33 @@ impl Codec2RxAdapter {
     pub fn set_output_card<S: Into<String>>(&mut self, card_name: S) {
         self.output_card = Some(card_name.into());
     }
     pub fn set_output_card<S: Into<String>>(&mut self, card_name: S) {
         self.output_card = Some(card_name.into());
     }
+
+    /// List sound cards supported for audio output.
+    ///
+    /// M17RT will handle any card with 1 or 2 channels and 16-bit output.
+    pub fn supported_output_cards() -> Vec<String> {
+        let mut out = vec![];
+        let host = cpal::default_host();
+        let Ok(output_devices) = host.output_devices() else {
+            return out;
+        };
+        for d in output_devices {
+            let Ok(mut configs) = d.supported_output_configs() else {
+                continue;
+            };
+            if configs.any(|config| {
+                (config.channels() == 1 || config.channels() == 2)
+                    && config.sample_format() == SampleFormat::I16
+            }) {
+                let Ok(name) = d.name() else {
+                    continue;
+                };
+                out.push(name);
+            }
+        }
+        out.sort();
+        out
+    }
 }
 
 impl Default for Codec2RxAdapter {
 }
 
 impl Default for Codec2RxAdapter {