From 717228a635e850f9a159f5773dcb9a5d80773bba Mon Sep 17 00:00:00 2001 From: Stan Grams Date: Wed, 11 Mar 2026 21:41:26 +0100 Subject: [PATCH] [feat](trx-server): handle virtual channel bandwidth updates Handle AUDIO_MSG_VCHAN_BW in the audio server path and apply per-channel filter bandwidth through the SoapySDR virtual channel manager. Co-authored-by: OpenAI Codex Signed-off-by: Stan Grams --- src/trx-server/src/audio.rs | 17 ++++++++++++++++- .../trx-backend-soapysdr/src/vchan_impl.rs | 14 ++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/trx-server/src/audio.rs b/src/trx-server/src/audio.rs index ab56bff..293dff9 100644 --- a/src/trx-server/src/audio.rs +++ b/src/trx-server/src/audio.rs @@ -27,7 +27,8 @@ use trx_core::audio::{ AUDIO_MSG_AIS_DECODE, AUDIO_MSG_APRS_DECODE, AUDIO_MSG_CW_DECODE, AUDIO_MSG_FT8_DECODE, AUDIO_MSG_HF_APRS_DECODE, AUDIO_MSG_HISTORY_COMPRESSED, AUDIO_MSG_RX_FRAME, AUDIO_MSG_STREAM_INFO, AUDIO_MSG_TX_FRAME, AUDIO_MSG_VCHAN_ALLOCATED, - AUDIO_MSG_VCHAN_DESTROYED, AUDIO_MSG_VCHAN_FREQ, AUDIO_MSG_VCHAN_MODE, AUDIO_MSG_VCHAN_REMOVE, + AUDIO_MSG_VCHAN_BW, AUDIO_MSG_VCHAN_DESTROYED, AUDIO_MSG_VCHAN_FREQ, AUDIO_MSG_VCHAN_MODE, + AUDIO_MSG_VCHAN_REMOVE, AUDIO_MSG_VCHAN_SUB, AUDIO_MSG_VCHAN_UNSUB, AUDIO_MSG_VDES_DECODE, AUDIO_MSG_WSPR_DECODE, }; use trx_core::vchan::SharedVChanManager; @@ -2183,6 +2184,20 @@ async fn handle_audio_client( } } } + Ok((AUDIO_MSG_VCHAN_BW, payload)) => { + if let Some(ref mgr) = vchan_manager { + if let Ok(v) = serde_json::from_slice::(&payload) { + if let (Some(uuid), Some(bandwidth_hz)) = ( + v["uuid"].as_str().and_then(|s| s.parse::().ok()), + v["bandwidth_hz"].as_u64().map(|b| b as u32), + ) { + if let Err(e) = mgr.set_channel_bandwidth(uuid, bandwidth_hz) { + warn!("Audio vchan BW: {}", e); + } + } + } + } + } Ok((AUDIO_MSG_VCHAN_REMOVE, payload)) => { match parse_vchan_uuid_msg(&payload) { Ok(uuid) => { diff --git a/src/trx-server/trx-backend/trx-backend-soapysdr/src/vchan_impl.rs b/src/trx-server/trx-backend/trx-backend-soapysdr/src/vchan_impl.rs index 2a790e3..8f483af 100644 --- a/src/trx-server/trx-backend/trx-backend-soapysdr/src/vchan_impl.rs +++ b/src/trx-server/trx-backend/trx-backend-soapysdr/src/vchan_impl.rs @@ -295,6 +295,20 @@ impl VirtualChannelManager for SdrVirtualChannelManager { Ok(()) } + fn set_channel_bandwidth(&self, id: Uuid, bandwidth_hz: u32) -> Result<(), VChanError> { + let channels = self.channels.read().unwrap(); + let ch = channels + .iter() + .find(|c| c.id == id) + .ok_or(VChanError::NotFound)?; + + let dsps = self.pipeline.channel_dsps.read().unwrap(); + if let Some(dsp_arc) = dsps.get(ch.pipeline_slot) { + dsp_arc.lock().unwrap().set_filter(bandwidth_hz, DEFAULT_FIR_TAPS); + } + Ok(()) + } + fn subscribe_pcm(&self, id: Uuid) -> Option>> { let channels = self.channels.read().unwrap(); channels