fixed buffer overflow issues, bumped deps

This commit is contained in:
2026-09-11 19:28:22 -06:00
parent 3e6552d012
commit 63477d22a6
4 changed files with 385 additions and 154 deletions
+20 -12
View File
@@ -1,3 +1,4 @@
use std::io::{stdin, Read};
use crate::tx_thread::TxThread;
use crate::udp_connection::OpusUdpConnection;
use crate::util::{SAMPLE_RATE, SAMPLE_RATE_RAW, STEREO_FRAME_SIZE, ThreadMessage};
@@ -5,7 +6,7 @@ use anyhow::Error;
use audiopus::coder::Encoder;
use audiopus::{Application, Bitrate, Channels, Signal};
use cpal::traits::{DeviceTrait, HostTrait, StreamTrait};
use cpal::{BufferSize, FromSample, Host, Sample, StreamConfig};
use cpal::{BufferSize, FromSample, Host, Sample, SampleRate, StreamConfig};
use log::{error, info};
use std::net::SocketAddr;
use std::sync::mpsc::{Sender, channel};
@@ -21,20 +22,24 @@ pub fn tap(
let device = if device == "default" {
host.default_input_device()
} else {
host.input_devices()?
.find(|x| x.name().map(|y| y == device).unwrap_or(false))
let id = &device.parse().expect("failed to parse input device id");
host.device_by_id(id)
}
.expect("failed to find input device");
info!("Input device: {}", device.name()?);
for dev in host.input_devices()? {
info!("ID: {}", dev.id()?);
}
info!("Input device: {}", device.id()?);
let config = device
.default_input_config()
.expect("Failed to get default input config");
let mut stream_config = StreamConfig::from(config.clone());
stream_config.sample_rate = cpal::SampleRate(SAMPLE_RATE_RAW as u32);
stream_config.buffer_size = BufferSize::Fixed(STEREO_FRAME_SIZE as u32 * 2);
let mut stream_config = StreamConfig::from(config);
let count = stream_config.channels;
stream_config.sample_rate = SAMPLE_RATE_RAW as SampleRate;
stream_config.buffer_size = BufferSize::Fixed(STEREO_FRAME_SIZE as u32 / count as u32);
for cfg in device.supported_input_configs()? {
info!("{:?}", cfg)
@@ -60,25 +65,25 @@ pub fn tap(
let stream = match config.sample_format() {
cpal::SampleFormat::I8 => device.build_input_stream(
&stream_config,
stream_config,
move |data, _: &_| write_input_data::<i8>(data, &sender),
err_fn,
None,
)?,
cpal::SampleFormat::I16 => device.build_input_stream(
&stream_config,
stream_config,
move |data, _: &_| write_input_data::<i16>(data, &sender),
err_fn,
None,
)?,
cpal::SampleFormat::I32 => device.build_input_stream(
&stream_config,
stream_config,
move |data, _: &_| write_input_data::<i32>(data, &sender),
err_fn,
None,
)?,
cpal::SampleFormat::F32 => device.build_input_stream(
&stream_config,
stream_config,
move |data, _: &_| write_input_data::<f32>(data, &sender),
err_fn,
None,
@@ -93,7 +98,10 @@ pub fn tap(
info!("Running tap...");
stream.play()?;
thread::park();
let mut stdin = stdin().lock();
let mut exit = [0u8; 1];
stdin.read_exact(&mut exit)?;
info!("Exiting...");
Ok(())