feat(util): replace old bitmask ChannelLayout with more flexible struct wrapper

This commit is contained in:
tilpner
2023-05-24 17:22:59 +02:00
committed by Till Höppner
parent 0049b3d075
commit bdb9f7684b
9 changed files with 666 additions and 86 deletions
+1
View File
@@ -132,3 +132,4 @@ optional = true
[dev-dependencies]
env_logger = "0.8"
serde_json = "1"
+2 -8
View File
@@ -46,18 +46,12 @@ impl Audio {
}
pub fn channel_layout(&self) -> ChannelLayout {
unsafe { ChannelLayout::from_bits_truncate((*self.as_ptr()).channel_layout) }
unsafe { (*self.as_ptr()).ch_layout.into() }
}
pub fn set_channel_layout(&mut self, value: ChannelLayout) {
unsafe {
(*self.as_mut_ptr()).channel_layout = value.bits();
}
}
pub fn request_channel_layout(&mut self, value: ChannelLayout) {
unsafe {
(*self.as_mut_ptr()).request_channel_layout = value.bits();
(*self.as_mut_ptr()).ch_layout = value.into();
}
}
+2 -2
View File
@@ -95,12 +95,12 @@ impl Audio {
pub fn set_channel_layout(&mut self, value: ChannelLayout) {
unsafe {
(*self.as_mut_ptr()).channel_layout = value.bits();
(*self.as_mut_ptr()).ch_layout = value.into();
}
}
pub fn channel_layout(&self) -> ChannelLayout {
unsafe { ChannelLayout::from_bits_truncate((*self.as_ptr()).channel_layout) }
unsafe { (*self.as_ptr()).ch_layout.into() }
}
pub fn set_channels(&mut self, value: i32) {
+1 -1
View File
@@ -50,7 +50,7 @@ impl<'a> Context<'a> {
}
pub fn set_channel_layout(&mut self, value: ChannelLayout) {
let _ = option::Settable::set(self, "channel_layouts", &value.bits());
let _ = option::Settable::set(self, "ch_layouts", &value);
}
}
+1 -1
View File
@@ -13,7 +13,7 @@ pub use crate::sys as ffi;
#[macro_use]
pub mod util;
pub use crate::util::{
channel_layout::{self, ChannelLayout},
channel_layout::{self, Channel, ChannelLayout},
chroma, color, dictionary,
dictionary::{Mut as DictionaryMut, Owned as Dictionary, Ref as DictionaryRef},
error::Error,
+1 -1
View File
@@ -5,7 +5,7 @@ use libc::c_int;
use super::Delay;
use crate::{ffi::*, frame, util::format, ChannelLayout, Error};
#[derive(Eq, PartialEq, Copy, Clone)]
#[derive(Copy, Clone)]
pub struct Definition {
pub format: format::Sample,
pub channel_layout: ChannelLayout,
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -49,6 +49,7 @@ impl From<AVOptionType> for Type {
AV_OPT_TYPE_DURATION => Type::Duration,
AV_OPT_TYPE_COLOR => Type::Color,
AV_OPT_TYPE_CHANNEL_LAYOUT => Type::ChannelLayout,
AV_OPT_TYPE_CHLAYOUT => Type::ChannelLayout,
}
}
}
@@ -75,7 +76,7 @@ impl Into<AVOptionType> for Type {
Type::VideoRate => AV_OPT_TYPE_VIDEO_RATE,
Type::Duration => AV_OPT_TYPE_DURATION,
Type::Color => AV_OPT_TYPE_COLOR,
Type::ChannelLayout => AV_OPT_TYPE_CHANNEL_LAYOUT,
Type::ChannelLayout => AV_OPT_TYPE_CHLAYOUT,
}
}
}
+2 -2
View File
@@ -132,10 +132,10 @@ pub trait Settable: Target {
unsafe {
let name = CString::new(name).unwrap();
check!(av_opt_set_channel_layout(
check!(av_opt_set_chlayout(
self.as_mut_ptr(),
name.as_ptr(),
layout.bits() as i64,
layout.as_ptr(),
AV_OPT_SEARCH_CHILDREN
))
}