Skip to content

Commit f354cc6

Browse files
committed
feat(avutil): add unsafe constructors for AVChannelLayout and AVChannelLayoutRef
1 parent 90eb0e9 commit f354cc6

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/avutil/channel_layout.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ impl Clone for AVChannelLayout {
4747
}
4848

4949
impl AVChannelLayout {
50+
/// Create a new channel layout from raw, user need to be sure that channel
51+
/// layout is correctly constructed.
52+
pub unsafe fn new(ch_layout: ffi::AVChannelLayout) -> Self {
53+
unsafe { Self::from_raw(NonNull::new(Box::into_raw(Box::new(ch_layout))).unwrap()) }
54+
}
55+
5056
/// Convert self into [`ffi::AVChannelLayout`]`.
5157
///
5258
/// Be careful when using it. Since this fucntion leaks the raw type,
@@ -203,6 +209,14 @@ impl AVChannelLayout {
203209
}
204210
}
205211

212+
impl AVChannelLayoutRef<'_> {
213+
/// Create a new channel layout reference from raw, user need to be sure
214+
/// that channel layout is correctly constructed.
215+
pub unsafe fn new(ch_layout: &ffi::AVChannelLayout) -> Self {
216+
unsafe { Self::from_raw(NonNull::new(ch_layout as *const _ as *mut _).unwrap()) }
217+
}
218+
}
219+
206220
/// Iterate over all standard channel layouts.
207221
pub struct AVChannelLayoutIter {
208222
opaque: *mut c_void,

0 commit comments

Comments
 (0)