76 lines
2.2 KiB
Rust
76 lines
2.2 KiB
Rust
#![cfg_attr(
|
|
debug_assertions,
|
|
allow(dead_code, unused_imports, unused_variables)
|
|
)]
|
|
|
|
|
|
use anyhow::{Context, Result};
|
|
|
|
use cpal::traits::HostTrait;
|
|
|
|
use log::{trace};
|
|
|
|
use tokio::sync::mpsc::{channel, unbounded_channel};
|
|
|
|
//use ringbuf::
|
|
|
|
mod task_msg;
|
|
use crate::task_msg::{PcmFrameMessage, RawIpDataMessage};
|
|
|
|
mod audio_receiver;
|
|
use crate::audio_receiver::audio_receiver_main;
|
|
|
|
mod dsp_inb;
|
|
use crate::dsp_inb::dsp_inb_main;
|
|
|
|
//#[derive(argh::FromArgs)]
|
|
//struct Cli {}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<()> {
|
|
simple_logger::init_with_level(log::Level::Trace)
|
|
.expect("logger init failure???");
|
|
|
|
let cpal_host = cpal::default_host();
|
|
let cpal_input = cpal_host.default_input_device().context(
|
|
"no audio input could be found; is a microphone installed?"
|
|
)?;
|
|
let cpal_output = cpal_host.default_output_device().context(
|
|
"no audio output could be found; is a sound card installed?",
|
|
)?;
|
|
|
|
let (tx_for_demod, rx_for_demod) = channel::<PcmFrameMessage>(1024);
|
|
let (tx_for_ip_inb, rx_for_ip_inb) =
|
|
unbounded_channel::<RawIpDataMessage>();
|
|
let (tx_for_mod, rx_for_mod) = unbounded_channel::<RawIpDataMessage>();
|
|
let (tx_for_wire, rx_for_wire) = unbounded_channel::<PcmFrameMessage>();
|
|
|
|
trace!("starting listener for audio on wire");
|
|
audio_receiver_main(tx_for_demod, cpal_input)
|
|
.context("listener for audio on wire has failed to start");
|
|
|
|
let mut tasks = tokio::task::JoinSet::new();
|
|
|
|
let task_dsp_inb = tasks.spawn(async move {
|
|
trace!("starting inbound audio demodulator");
|
|
dsp_inb_main(tx_for_ip_inb, rx_for_demod).await
|
|
});
|
|
//let task_tun_junction = tasks.spawn(async move {
|
|
// trace!("Starting tun manager");
|
|
// tun_junction_main(tx_for_mod, rx_for_ip_inb).await
|
|
//});
|
|
//let task_dsp_outb = tasks.spawn(async move {
|
|
// trace!("Starting outbound audio modulator");
|
|
// dsp_outb_main(tx_for_wire, rx_for_mod).await
|
|
//});
|
|
//let task_audio_sender = tasks.spawn(async move {
|
|
// trace!("Starting audio transmitter");
|
|
// audio_sender_main(rx_for_mod, cpal_output).await
|
|
//});
|
|
|
|
while let Some(task_result) = tasks.join_next().await {
|
|
task_result??
|
|
}
|
|
|
|
Ok(())
|
|
}
|