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:
Tad Hardesty 2017-05-20 20:38:59 -07:00
parent 7def3a668c
commit 06643a441c
No known key found for this signature in database
GPG Key ID: AEFCC915C75ACC47

View File

@ -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)