mirror of
https://github.com/encounter/rust-ffmpeg-zmwangx.git
synced 2026-07-10 21:18:40 -07:00
feat(util): replace old bitmask ChannelLayout with more flexible struct wrapper
This commit is contained in:
@@ -132,3 +132,4 @@ optional = true
|
||||
|
||||
[dev-dependencies]
|
||||
env_logger = "0.8"
|
||||
serde_json = "1"
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
+654
-70
File diff suppressed because it is too large
Load Diff
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user