Skip to content

Commit 4172571

Browse files
elmarcoCBenoit
authored andcommitted
refactor(rdpsnd)!: pass format_no instead of AudioFormat
This can help avoid extra lookups and cloning. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
1 parent 3d7bc28 commit 4172571

2 files changed

Lines changed: 15 additions & 16 deletions

File tree

crates/ironrdp-rdpsnd-native/src/cpal.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct RdpsndBackend {
1818
stream_handle: Option<JoinHandle<()>>,
1919
stream_ended: Arc<AtomicBool>,
2020
tx: Option<Sender<Vec<u8>>>,
21-
format: Option<AudioFormat>,
21+
format_no: Option<usize>,
2222
}
2323

2424
impl Default for RdpsndBackend {
@@ -31,7 +31,7 @@ impl RdpsndBackend {
3131
pub fn new() -> Self {
3232
Self {
3333
tx: None,
34-
format: None,
34+
format_no: None,
3535
stream_handle: None,
3636
stream_ended: Arc::new(AtomicBool::new(false)),
3737
}
@@ -69,16 +69,21 @@ impl RdpsndClientHandler for RdpsndBackend {
6969
]
7070
}
7171

72-
fn wave(&mut self, format: &AudioFormat, _ts: u32, data: Cow<'_, [u8]>) {
73-
if Some(format) != self.format.as_ref() {
74-
debug!(?format, "New audio format");
72+
fn wave(&mut self, format_no: usize, _ts: u32, data: Cow<'_, [u8]>) {
73+
if Some(format_no) != self.format_no {
74+
debug!("New audio format");
7575
self.close();
7676
}
7777

7878
if self.stream_handle.is_none() {
7979
let (tx, rx) = mpsc::channel();
8080
self.tx = Some(tx);
81-
self.format = Some(format.clone());
81+
82+
self.format_no = Some(format_no);
83+
let Some(format) = self.get_formats().get(format_no) else {
84+
warn!(?format_no, "Invalid format_no");
85+
return;
86+
};
8287
let format = format.clone();
8388
self.stream_ended.store(false, Ordering::Relaxed);
8489
let stream_ended = Arc::clone(&self.stream_ended);

crates/ironrdp-rdpsnd/src/client.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub trait RdpsndClientHandler: Send + core::fmt::Debug {
1616

1717
fn get_formats(&self) -> &[AudioFormat];
1818

19-
fn wave(&mut self, format: &AudioFormat, ts: u32, data: Cow<'_, [u8]>);
19+
fn wave(&mut self, format_no: usize, ts: u32, data: Cow<'_, [u8]>);
2020

2121
fn set_volume(&mut self, volume: VolumePdu);
2222

@@ -33,7 +33,7 @@ impl RdpsndClientHandler for NoopRdpsndBackend {
3333
&[]
3434
}
3535

36-
fn wave(&mut self, _format: &AudioFormat, _ts: u32, _data: Cow<'_, [u8]>) {}
36+
fn wave(&mut self, _format_no: usize, _ts: u32, _data: Cow<'_, [u8]>) {}
3737

3838
fn set_volume(&mut self, _volume: VolumePdu) {}
3939

@@ -183,15 +183,9 @@ impl SvcProcessor for Rdpsnd {
183183
match pdu {
184184
// TODO: handle WaveInfo for < v8
185185
pdu::ServerAudioOutputPdu::Wave2(pdu) => {
186-
// TODO: maybe change wave(fmt_no,..) API to avoid the need for clone()
187-
let fmt = self
188-
.handler
189-
.get_formats()
190-
.get(pdu.format_no as usize)
191-
.ok_or_else(|| pdu_other_err!("invalid format no"))?
192-
.clone();
186+
let format_no = pdu.format_no as usize;
193187
let ts = pdu.audio_timestamp;
194-
self.handler.wave(&fmt, ts, pdu.data);
188+
self.handler.wave(format_no, ts, pdu.data);
195189
return Ok(self.wave_confirm(pdu.timestamp, pdu.block_no)?.into());
196190
}
197191
pdu::ServerAudioOutputPdu::Volume(pdu) => {

0 commit comments

Comments
 (0)