Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions crates/ironrdp-rdpsnd-native/src/cpal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,19 @@ impl DecodeStream {
clippy::as_conversions,
reason = "opus::Channels has no conversions to usize implemented"
)]
let mut pcm = vec![0u8; nb_samples * chan as usize * size_of::<i16>()];
if let Err(error) = dec.decode(&pkt, bytemuck::cast_slice_mut(pcm.as_mut_slice()), false) {
let mut pcm_i16 = vec![0i16; nb_samples * chan as usize];
if let Err(error) = dec.decode(&pkt, &mut pcm_i16, false) {
error!(?error, "Failed to decode an Opus packet");
continue;
}
// Vec<u8> is what the channel carries downstream. Reinterpreting
// Vec<i16> -> Vec<u8> via cast_slice is safe (smaller alignment).
// Allocating as Vec<i16> in the first place avoids the alignment
// hazard of `bytemuck::cast_slice_mut::<u8, i16>` panicking when
// the allocator hands back a u8 buffer that is not 2-byte aligned
// (which manifested as a hard crash in #1202 under the burst of
// malformed Opus packets generated by a server reboot).
let pcm = bytemuck::cast_slice(&pcm_i16).to_vec();

if dec_tx.send(pcm).is_err() {
error!("Failed to send the decoded Opus packet over the channel");
Expand Down
Loading