[fix](trx-server): enable audio by default and fix playback thread panic
Enable audio streaming by default in AudioConfig. Fix panic in audio playback thread caused by calling tokio::runtime::Handle::current() from a plain std::thread. Use rx.blocking_recv() instead, which is the correct API for consuming a tokio mpsc receiver from a synchronous context. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Stanislaw Grams <stanislawgrams@gmail.com>
This commit is contained in:
@@ -206,22 +206,19 @@ fn run_playback(
|
|||||||
stream.play()?;
|
stream.play()?;
|
||||||
info!("Audio playback: started");
|
info!("Audio playback: started");
|
||||||
|
|
||||||
let rt = tokio::runtime::Handle::current();
|
|
||||||
let mut pcm_buf = vec![0f32; frame_samples];
|
let mut pcm_buf = vec![0f32; frame_samples];
|
||||||
|
|
||||||
rt.block_on(async {
|
while let Some(packet) = rx.blocking_recv() {
|
||||||
while let Some(packet) = rx.recv().await {
|
match decoder.decode_float(&packet, &mut pcm_buf, false) {
|
||||||
match decoder.decode_float(&packet, &mut pcm_buf, false) {
|
Ok(decoded) => {
|
||||||
Ok(decoded) => {
|
let mut ring = ring_writer.lock().unwrap();
|
||||||
let mut ring = ring_writer.lock().unwrap();
|
ring.extend(&pcm_buf[..decoded * channels as usize]);
|
||||||
ring.extend(&pcm_buf[..decoded * channels as usize]);
|
}
|
||||||
}
|
Err(e) => {
|
||||||
Err(e) => {
|
warn!("Opus decode error: {}", e);
|
||||||
warn!("Opus decode error: {}", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ pub struct AudioConfig {
|
|||||||
impl Default for AudioConfig {
|
impl Default for AudioConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
enabled: false,
|
enabled: true,
|
||||||
listen: IpAddr::V4(std::net::Ipv4Addr::LOCALHOST),
|
listen: IpAddr::V4(std::net::Ipv4Addr::LOCALHOST),
|
||||||
port: 4533,
|
port: 4533,
|
||||||
rx_enabled: true,
|
rx_enabled: true,
|
||||||
@@ -305,7 +305,7 @@ mod tests {
|
|||||||
assert!(config.listen.enabled);
|
assert!(config.listen.enabled);
|
||||||
assert_eq!(config.listen.port, 4532);
|
assert_eq!(config.listen.port, 4532);
|
||||||
assert!(config.listen.auth.tokens.is_empty());
|
assert!(config.listen.auth.tokens.is_empty());
|
||||||
assert!(!config.audio.enabled);
|
assert!(config.audio.enabled);
|
||||||
assert_eq!(config.audio.port, 4533);
|
assert_eq!(config.audio.port, 4533);
|
||||||
assert_eq!(config.audio.sample_rate, 48000);
|
assert_eq!(config.audio.sample_rate, 48000);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user