Skip to content

Commit

Permalink
Revert "Fix AVChannelLayout::describe"
Browse files Browse the repository at this point in the history
This reverts commit 75f7a29.
  • Loading branch information
ldm0 committed Jan 1, 2024
1 parent 75f7a29 commit df4f261
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/avutil/channel_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,22 @@ impl AVChannelLayout {
/// channel layout, except for opaque pointers.
pub fn describe(&self) -> Result<CString> {
const BUF_SIZE: usize = 32;
let mut buf = vec![0u8; BUF_SIZE + 1];

// Note: len doesn't include the trailing zero
//
let mut buf = vec![0u8; BUF_SIZE];
// # Safety: after upgrading len is assumed to be positive.
let len = unsafe {
ffi::av_channel_layout_describe(self.as_ptr(), buf.as_mut_ptr() as *mut i8, BUF_SIZE)
}
.upgrade()? as usize;

let len = if len > BUF_SIZE {
buf.resize(len + 1, 0);
buf.resize(len, 0);
unsafe {
ffi::av_channel_layout_describe(self.as_ptr(), buf.as_mut_ptr() as *mut i8, len)
}
.upgrade()? as usize
} else {
len
};
Ok(CString::new(&buf[..len + 1]).unwrap())
Ok(CString::new(&buf[..len]).unwrap())
}

/// Get the channel with the given index in a channel layout.
Expand Down

0 comments on commit df4f261

Please sign in to comment.