mirror of
https://github.com/rustdesk/magnum-opus.git
synced 2025-07-01 15:25:27 +00:00
Pass null pointer on empty decode input, for packet loss
Although this does not change behavior in the current implementation, which also accepts a length of zero to mean packet loss, the documentation only indicates that a null pointer means packet loss. For future safety, pass a null pointer when the packet is empty.
This commit is contained in:
parent
7def3a668c
commit
06643a441c
12
src/lib.rs
12
src/lib.rs
@ -384,8 +384,12 @@ impl Decoder {
|
||||
|
||||
/// Decode an Opus packet.
|
||||
pub fn decode(&mut self, input: &[u8], output: &mut [i16], fec: bool) -> Result<usize> {
|
||||
let ptr = match input.len() {
|
||||
0 => std::ptr::null(),
|
||||
_ => input.as_ptr(),
|
||||
};
|
||||
let len = ffi!(opus_decode, self.ptr,
|
||||
input.as_ptr(), len(input),
|
||||
ptr, len(input),
|
||||
output.as_mut_ptr(), len(output) / self.channels as c_int,
|
||||
fec as c_int);
|
||||
Ok(len as usize)
|
||||
@ -393,8 +397,12 @@ impl Decoder {
|
||||
|
||||
/// Decode an Opus packet with floating point output.
|
||||
pub fn decode_float(&mut self, input: &[u8], output: &mut [f32], fec: bool) -> Result<usize> {
|
||||
let ptr = match input.len() {
|
||||
0 => std::ptr::null(),
|
||||
_ => input.as_ptr(),
|
||||
};
|
||||
let len = ffi!(opus_decode_float, self.ptr,
|
||||
input.as_ptr(), len(input),
|
||||
ptr, len(input),
|
||||
output.as_mut_ptr(), len(output) / self.channels as c_int,
|
||||
fec as c_int);
|
||||
Ok(len as usize)
|
||||
|
Loading…
x
Reference in New Issue
Block a user