From eadb3c6db265df0342e76856ceb7fc8caf82eaee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 23 Jan 2023 12:40:47 +0200 Subject: [PATCH] audio: Reduce size of `AudioInfo` from 832 to 320 bytes and make audio channel position handling more efficient Assume that there are never more than 64 named channel positions and by that provide an 1:1 mapping between the C and Rust types. Part-of: --- gstreamer-audio/Gir.toml | 2 +- gstreamer-audio/src/audio_channel_position.rs | 333 ++++++++++++------ gstreamer-audio/src/audio_info.rs | 57 +-- gstreamer-audio/src/auto/enums.rs | 198 ----------- gstreamer-audio/src/auto/mod.rs | 1 - 5 files changed, 247 insertions(+), 344 deletions(-) diff --git a/gstreamer-audio/Gir.toml b/gstreamer-audio/Gir.toml index 2c88bcd38..ac185997d 100644 --- a/gstreamer-audio/Gir.toml +++ b/gstreamer-audio/Gir.toml @@ -21,7 +21,6 @@ generate = [ "GstAudio.AudioAggregatorConvertPad", "GstAudio.AudioAggregatorPad", "GstAudio.AudioBaseSrc", - "GstAudio.AudioChannelPosition", "GstAudio.AudioDitherMethod", "GstAudio.AudioFilter", "GstAudio.AudioFormatFlags", @@ -44,6 +43,7 @@ manual = [ "Gst.Format", "Gst.TagList", "Gst.TagMergeMode", + "GstAudio.AudioChannelPosition", "GstAudio.AudioClippingMeta", "GstAudio.AudioFormatInfo", "GstAudio.AudioInfo", diff --git a/gstreamer-audio/src/audio_channel_position.rs b/gstreamer-audio/src/audio_channel_position.rs index 8bac50dc0..8932ab41b 100644 --- a/gstreamer-audio/src/audio_channel_position.rs +++ b/gstreamer-audio/src/audio_channel_position.rs @@ -1,10 +1,220 @@ // Take a look at the license at the top of the repository in the LICENSE file. -use std::mem; +use std::{mem, slice}; -use glib::translate::{from_glib, IntoGlib}; +use glib::{translate::*, value::FromValue, StaticType, ToValue, Type}; -use crate::AudioChannelPosition; +#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)] +#[non_exhaustive] +#[doc(alias = "GstAudioChannelPosition")] +#[repr(i32)] +pub enum AudioChannelPosition { + #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_NONE")] + None = ffi::GST_AUDIO_CHANNEL_POSITION_NONE, + #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_MONO")] + Mono, + #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_INVALID")] + Invalid, + #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT")] + FrontLeft, + #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT")] + FrontRight, + #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER")] + FrontCenter, + #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_LFE1")] + Lfe1, + #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_REAR_LEFT")] + RearLeft, + #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT")] + RearRight, + #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER")] + FrontLeftOfCenter, + #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER")] + FrontRightOfCenter, + #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_REAR_CENTER")] + RearCenter, + #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_LFE2")] + Lfe2, + #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT")] + SideLeft, + #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT")] + SideRight, + #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_LEFT")] + TopFrontLeft, + #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_RIGHT")] + TopFrontRight, + #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_CENTER")] + TopFrontCenter, + #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_TOP_CENTER")] + TopCenter, + #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_TOP_REAR_LEFT")] + TopRearLeft, + #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_TOP_REAR_RIGHT")] + TopRearRight, + #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_TOP_SIDE_LEFT")] + TopSideLeft, + #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_TOP_SIDE_RIGHT")] + TopSideRight, + #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_TOP_REAR_CENTER")] + TopRearCenter, + #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_BOTTOM_FRONT_CENTER")] + BottomFrontCenter, + #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_BOTTOM_FRONT_LEFT")] + BottomFrontLeft, + #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_BOTTOM_FRONT_RIGHT")] + BottomFrontRight, + #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_WIDE_LEFT")] + WideLeft, + #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_WIDE_RIGHT")] + WideRight, + #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_SURROUND_LEFT")] + SurroundLeft, + #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_SURROUND_RIGHT")] + SurroundRight = ffi::GST_AUDIO_CHANNEL_POSITION_SURROUND_RIGHT, + #[doc(hidden)] + UnknownChannel28 = 28, + #[doc(hidden)] + UnknownChannel29 = 29, + #[doc(hidden)] + UnknownChannel30 = 30, + #[doc(hidden)] + UnknownChannel31 = 31, + #[doc(hidden)] + UnknownChannel32 = 32, + #[doc(hidden)] + UnknownChannel33 = 33, + #[doc(hidden)] + UnknownChannel34 = 34, + #[doc(hidden)] + UnknownChannel35 = 35, + #[doc(hidden)] + UnknownChannel36 = 36, + #[doc(hidden)] + UnknownChannel37 = 37, + #[doc(hidden)] + UnknownChannel38 = 38, + #[doc(hidden)] + UnknownChannel39 = 39, + #[doc(hidden)] + UnknownChannel40 = 40, + #[doc(hidden)] + UnknownChannel41 = 41, + #[doc(hidden)] + UnknownChannel42 = 42, + #[doc(hidden)] + UnknownChannel43 = 43, + #[doc(hidden)] + UnknownChannel44 = 44, + #[doc(hidden)] + UnknownChannel45 = 45, + #[doc(hidden)] + UnknownChannel46 = 46, + #[doc(hidden)] + UnknownChannel47 = 47, + #[doc(hidden)] + UnknownChannel48 = 48, + #[doc(hidden)] + UnknownChannel49 = 49, + #[doc(hidden)] + UnknownChannel50 = 50, + #[doc(hidden)] + UnknownChannel51 = 51, + #[doc(hidden)] + UnknownChannel52 = 52, + #[doc(hidden)] + UnknownChannel53 = 53, + #[doc(hidden)] + UnknownChannel54 = 54, + #[doc(hidden)] + UnknownChannel55 = 55, + #[doc(hidden)] + UnknownChannel56 = 56, + #[doc(hidden)] + UnknownChannel57 = 57, + #[doc(hidden)] + UnknownChannel58 = 58, + #[doc(hidden)] + UnknownChannel59 = 59, + #[doc(hidden)] + UnknownChannel60 = 60, + #[doc(hidden)] + UnknownChannel61 = 61, + #[doc(hidden)] + UnknownChannel62 = 62, + #[doc(hidden)] + UnknownChannel63 = 63, + #[doc(hidden)] + UnknownChannel64 = 64, +} + +unsafe impl TransparentType for AudioChannelPosition { + type GlibType = ffi::GstAudioChannelPosition; +} + +#[doc(hidden)] +impl IntoGlib for AudioChannelPosition { + type GlibType = ffi::GstAudioChannelPosition; + + #[inline] + fn into_glib(self) -> ffi::GstAudioChannelPosition { + self as ffi::GstAudioChannelPosition + } +} + +#[doc(hidden)] +impl FromGlib for AudioChannelPosition { + #[inline] + unsafe fn from_glib(value: ffi::GstAudioChannelPosition) -> Self { + skip_assert_initialized!(); + debug_assert!((ffi::GST_AUDIO_CHANNEL_POSITION_NONE..=64).contains(&value)); + mem::transmute::(value) + } +} + +impl StaticType for AudioChannelPosition { + #[inline] + fn static_type() -> Type { + unsafe { from_glib(ffi::gst_audio_channel_position_get_type()) } + } +} + +impl glib::value::ValueType for AudioChannelPosition { + type Type = Self; +} + +unsafe impl<'a> FromValue<'a> for AudioChannelPosition { + type Checker = glib::value::GenericValueTypeChecker; + + #[inline] + unsafe fn from_value(value: &'a glib::Value) -> Self { + skip_assert_initialized!(); + from_glib(glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0)) + } +} + +impl ToValue for AudioChannelPosition { + #[inline] + fn to_value(&self) -> glib::Value { + let mut value = glib::Value::for_value_type::(); + unsafe { + glib::gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, self.into_glib()); + } + value + } + + #[inline] + fn value_type(&self) -> glib::Type { + Self::static_type() + } +} + +impl From for glib::Value { + #[inline] + fn from(v: AudioChannelPosition) -> Self { + skip_assert_initialized!(); + ToValue::to_value(&v) + } +} impl AudioChannelPosition { pub fn to_mask(self) -> u64 { @@ -28,18 +238,10 @@ impl AudioChannelPosition { return Err(glib::bool_error!("Invalid number of channels")); } - let positions_raw: [ffi::GstAudioChannelPosition; 64] = std::array::from_fn(|i| { - if i >= len { - ffi::GST_AUDIO_CHANNEL_POSITION_INVALID - } else { - positions[i].into_glib() - } - }); - unsafe { let mut mask = mem::MaybeUninit::uninit(); let valid: bool = from_glib(ffi::gst_audio_channel_positions_to_mask( - positions_raw.as_ptr() as *mut _, + positions.as_ptr() as *mut _, len as i32, force_order.into_glib(), mask.as_mut_ptr(), @@ -63,20 +265,15 @@ impl AudioChannelPosition { } let len = positions.len(); - let mut positions_raw: [ffi::GstAudioChannelPosition; 64] = - [ffi::GST_AUDIO_CHANNEL_POSITION_INVALID; 64]; let valid: bool = unsafe { from_glib(ffi::gst_audio_channel_positions_from_mask( len as i32, mask, - positions_raw.as_mut_ptr(), + positions.as_mut_ptr() as *mut _, )) }; if valid { - for (d, s) in positions.iter_mut().zip(positions_raw.iter()) { - *d = unsafe { from_glib(*s) }; - } Ok(()) } else { Err(glib::bool_error!( @@ -94,25 +291,14 @@ impl AudioChannelPosition { } let len = positions.len(); - let mut positions_raw: [ffi::GstAudioChannelPosition; 64] = std::array::from_fn(|i| { - if i >= len { - ffi::GST_AUDIO_CHANNEL_POSITION_INVALID - } else { - positions[i].into_glib() - } - }); - let valid: bool = unsafe { from_glib(ffi::gst_audio_channel_positions_to_valid_order( - positions_raw.as_mut_ptr(), + positions.as_mut_ptr() as *mut _, len as i32, )) }; if valid { - for (d, s) in positions.iter_mut().zip(positions_raw.iter()) { - *d = unsafe { from_glib(*s) }; - } Ok(()) } else { Err(glib::bool_error!( @@ -138,17 +324,9 @@ impl AudioChannelPosition { } let len = positions.len(); - let positions_raw: [ffi::GstAudioChannelPosition; 64] = std::array::from_fn(|i| { - if i >= len { - ffi::GST_AUDIO_CHANNEL_POSITION_INVALID - } else { - positions[i].into_glib() - } - }); - unsafe { from_glib(ffi::gst_audio_check_valid_channel_positions( - positions_raw.as_ptr() as *mut _, + positions.as_ptr() as *mut _, len as i32, force_order.into_glib(), )) @@ -170,32 +348,13 @@ pub fn buffer_reorder_channels( return Err(glib::bool_error!("Invalid number of channels")); } - let from_len = from.len(); - let to_len = to.len(); - - let from_raw: [ffi::GstAudioChannelPosition; 64] = std::array::from_fn(|i| { - if i >= from_len { - ffi::GST_AUDIO_CHANNEL_POSITION_INVALID - } else { - from[i].into_glib() - } - }); - - let to_raw: [ffi::GstAudioChannelPosition; 64] = std::array::from_fn(|i| { - if i >= to_len { - ffi::GST_AUDIO_CHANNEL_POSITION_INVALID - } else { - to[i].into_glib() - } - }); - let valid: bool = unsafe { from_glib(ffi::gst_audio_buffer_reorder_channels( buffer.as_mut_ptr(), format.into_glib(), channels as i32, - from_raw.as_ptr() as *mut _, - to_raw.as_ptr() as *mut _, + from.as_ptr() as *mut _, + to.as_ptr() as *mut _, )) }; @@ -220,33 +379,14 @@ pub fn reorder_channels( return Err(glib::bool_error!("Invalid number of channels")); } - let from_len = from.len(); - let to_len = to.len(); - - let from_raw: [ffi::GstAudioChannelPosition; 64] = std::array::from_fn(|i| { - if i >= from_len { - ffi::GST_AUDIO_CHANNEL_POSITION_INVALID - } else { - from[i].into_glib() - } - }); - - let to_raw: [ffi::GstAudioChannelPosition; 64] = std::array::from_fn(|i| { - if i >= to_len { - ffi::GST_AUDIO_CHANNEL_POSITION_INVALID - } else { - to[i].into_glib() - } - }); - let valid: bool = unsafe { from_glib(ffi::gst_audio_reorder_channels( data.as_mut_ptr() as *mut _, data.len(), format.into_glib(), channels as i32, - from_raw.as_ptr() as *mut _, - to_raw.as_ptr() as *mut _, + from.as_ptr() as *mut _, + to.as_ptr() as *mut _, )) }; @@ -270,36 +410,19 @@ pub fn channel_reorder_map( return Err(glib::bool_error!("Invalid number of channels")); } - let from_len = from.len(); - let to_len = to.len(); - - let from_raw: [ffi::GstAudioChannelPosition; 64] = std::array::from_fn(|i| { - if i >= from_len { - ffi::GST_AUDIO_CHANNEL_POSITION_INVALID - } else { - from[i].into_glib() - } - }); - - let to_raw: [ffi::GstAudioChannelPosition; 64] = std::array::from_fn(|i| { - if i >= to_len { - ffi::GST_AUDIO_CHANNEL_POSITION_INVALID - } else { - to[i].into_glib() - } - }); - - let mut reorder_map_raw = [0i32, 64]; + let mut reorder_map_raw = mem::MaybeUninit::<[i32; 64]>::uninit(); let valid: bool = unsafe { from_glib(ffi::gst_audio_get_channel_reorder_map( - from_len as i32, - from_raw.as_ptr() as *mut _, - to_raw.as_ptr() as *mut _, - reorder_map_raw.as_mut_ptr(), + from.len() as i32, + from.as_ptr() as *mut _, + to.as_ptr() as *mut _, + reorder_map_raw.as_mut_ptr() as *mut i32, )) }; if valid { + let reorder_map_raw = + unsafe { slice::from_raw_parts(reorder_map_raw.as_ptr() as *const i32, from.len()) }; for (d, s) in reorder_map.iter_mut().zip(reorder_map_raw.iter()) { *d = *s as usize; } diff --git a/gstreamer-audio/src/audio_info.rs b/gstreamer-audio/src/audio_info.rs index 666719012..a96872888 100644 --- a/gstreamer-audio/src/audio_info.rs +++ b/gstreamer-audio/src/audio_info.rs @@ -1,6 +1,6 @@ // Take a look at the license at the top of the repository in the LICENSE file. -use std::{fmt, marker::PhantomData, mem, ptr}; +use std::{fmt, marker::PhantomData, mem, ptr, slice}; use glib::translate::{ from_glib, from_glib_full, from_glib_none, IntoGlib, ToGlibPtr, ToGlibPtrMut, @@ -8,7 +8,8 @@ use glib::translate::{ use gst::prelude::*; #[doc(alias = "GstAudioInfo")] -pub struct AudioInfo(ffi::GstAudioInfo, [crate::AudioChannelPosition; 64]); +#[derive(Clone)] +pub struct AudioInfo(ffi::GstAudioInfo); impl fmt::Debug for AudioInfo { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -40,34 +41,23 @@ impl<'a> AudioInfoBuilder<'a> { unsafe { let mut info = mem::MaybeUninit::uninit(); - let positions = if let Some(p) = self.positions { + if let Some(p) = self.positions { if p.len() != self.channels as usize || p.len() > 64 { return Err(glib::bool_error!("Invalid positions length")); } - let positions: [ffi::GstAudioChannelPosition; 64] = std::array::from_fn(|i| { - if i >= self.channels as usize { - ffi::GST_AUDIO_CHANNEL_POSITION_INVALID - } else { - p[i].into_glib() - } - }); - let valid: bool = from_glib(ffi::gst_audio_check_valid_channel_positions( - positions.as_ptr() as *mut _, + p.as_ptr() as *mut _, self.channels as i32, true.into_glib(), )); if !valid { return Err(glib::bool_error!("channel positions are invalid")); } + } - Some(positions) - } else { - None - }; - - let positions_ptr = positions + let positions_ptr = self + .positions .as_ref() .map(|p| p.as_ptr()) .unwrap_or(ptr::null()); @@ -94,8 +84,7 @@ impl<'a> AudioInfoBuilder<'a> { info.layout = layout.into_glib(); } - let positions = std::array::from_fn(|i| from_glib(info.position[i])); - Ok(AudioInfo(info, positions)) + Ok(AudioInfo(info)) } } @@ -154,9 +143,7 @@ impl AudioInfo { info.as_mut_ptr(), caps.as_ptr(), )) { - let info = info.assume_init(); - let positions = std::array::from_fn(|i| from_glib(info.position[i])); - Ok(Self(info, positions)) + Ok(Self(info.assume_init())) } else { Err(glib::bool_error!("Failed to create AudioInfo from caps")) } @@ -311,7 +298,12 @@ impl AudioInfo { return None; } - Some(&self.1[0..(self.0.channels as usize)]) + Some(unsafe { + slice::from_raw_parts( + &self.0.position as *const i32 as *const crate::AudioChannelPosition, + self.0.channels as usize, + ) + }) } #[inline] @@ -320,13 +312,6 @@ impl AudioInfo { } } -impl Clone for AudioInfo { - #[inline] - fn clone(&self) -> Self { - unsafe { Self(ptr::read(&self.0), self.1) } - } -} - impl PartialEq for AudioInfo { #[doc(alias = "gst_audio_info_is_equal")] #[inline] @@ -435,10 +420,7 @@ impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstAudioInfo> for AudioInfo impl glib::translate::FromGlibPtrNone<*const ffi::GstAudioInfo> for AudioInfo { #[inline] unsafe fn from_glib_none(ptr: *const ffi::GstAudioInfo) -> Self { - Self( - ptr::read(ptr), - std::array::from_fn(|i| from_glib((*ptr).position[i])), - ) + Self(ptr::read(ptr)) } } @@ -446,10 +428,7 @@ impl glib::translate::FromGlibPtrNone<*const ffi::GstAudioInfo> for AudioInfo { impl glib::translate::FromGlibPtrNone<*mut ffi::GstAudioInfo> for AudioInfo { #[inline] unsafe fn from_glib_none(ptr: *mut ffi::GstAudioInfo) -> Self { - Self( - ptr::read(ptr), - std::array::from_fn(|i| from_glib((*ptr).position[i])), - ) + Self(ptr::read(ptr)) } } diff --git a/gstreamer-audio/src/auto/enums.rs b/gstreamer-audio/src/auto/enums.rs index b5dc4f0ca..cfa443825 100644 --- a/gstreamer-audio/src/auto/enums.rs +++ b/gstreamer-audio/src/auto/enums.rs @@ -6,204 +6,6 @@ use glib::{translate::*, value::FromValue, value::ToValue, StaticType, Type}; use std::fmt; -#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)] -#[non_exhaustive] -#[doc(alias = "GstAudioChannelPosition")] -pub enum AudioChannelPosition { - #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_NONE")] - None, - #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_MONO")] - Mono, - #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_INVALID")] - Invalid, - #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT")] - FrontLeft, - #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT")] - FrontRight, - #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER")] - FrontCenter, - #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_LFE1")] - Lfe1, - #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_REAR_LEFT")] - RearLeft, - #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT")] - RearRight, - #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER")] - FrontLeftOfCenter, - #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER")] - FrontRightOfCenter, - #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_REAR_CENTER")] - RearCenter, - #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_LFE2")] - Lfe2, - #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT")] - SideLeft, - #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT")] - SideRight, - #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_LEFT")] - TopFrontLeft, - #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_RIGHT")] - TopFrontRight, - #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_CENTER")] - TopFrontCenter, - #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_TOP_CENTER")] - TopCenter, - #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_TOP_REAR_LEFT")] - TopRearLeft, - #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_TOP_REAR_RIGHT")] - TopRearRight, - #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_TOP_SIDE_LEFT")] - TopSideLeft, - #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_TOP_SIDE_RIGHT")] - TopSideRight, - #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_TOP_REAR_CENTER")] - TopRearCenter, - #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_BOTTOM_FRONT_CENTER")] - BottomFrontCenter, - #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_BOTTOM_FRONT_LEFT")] - BottomFrontLeft, - #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_BOTTOM_FRONT_RIGHT")] - BottomFrontRight, - #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_WIDE_LEFT")] - WideLeft, - #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_WIDE_RIGHT")] - WideRight, - #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_SURROUND_LEFT")] - SurroundLeft, - #[doc(alias = "GST_AUDIO_CHANNEL_POSITION_SURROUND_RIGHT")] - SurroundRight, - #[doc(hidden)] - __Unknown(i32), -} - -#[doc(hidden)] -impl IntoGlib for AudioChannelPosition { - type GlibType = ffi::GstAudioChannelPosition; - - fn into_glib(self) -> ffi::GstAudioChannelPosition { - match self { - Self::None => ffi::GST_AUDIO_CHANNEL_POSITION_NONE, - Self::Mono => ffi::GST_AUDIO_CHANNEL_POSITION_MONO, - Self::Invalid => ffi::GST_AUDIO_CHANNEL_POSITION_INVALID, - Self::FrontLeft => ffi::GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT, - Self::FrontRight => ffi::GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT, - Self::FrontCenter => ffi::GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER, - Self::Lfe1 => ffi::GST_AUDIO_CHANNEL_POSITION_LFE1, - Self::RearLeft => ffi::GST_AUDIO_CHANNEL_POSITION_REAR_LEFT, - Self::RearRight => ffi::GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT, - Self::FrontLeftOfCenter => ffi::GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER, - Self::FrontRightOfCenter => ffi::GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER, - Self::RearCenter => ffi::GST_AUDIO_CHANNEL_POSITION_REAR_CENTER, - Self::Lfe2 => ffi::GST_AUDIO_CHANNEL_POSITION_LFE2, - Self::SideLeft => ffi::GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT, - Self::SideRight => ffi::GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT, - Self::TopFrontLeft => ffi::GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_LEFT, - Self::TopFrontRight => ffi::GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_RIGHT, - Self::TopFrontCenter => ffi::GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_CENTER, - Self::TopCenter => ffi::GST_AUDIO_CHANNEL_POSITION_TOP_CENTER, - Self::TopRearLeft => ffi::GST_AUDIO_CHANNEL_POSITION_TOP_REAR_LEFT, - Self::TopRearRight => ffi::GST_AUDIO_CHANNEL_POSITION_TOP_REAR_RIGHT, - Self::TopSideLeft => ffi::GST_AUDIO_CHANNEL_POSITION_TOP_SIDE_LEFT, - Self::TopSideRight => ffi::GST_AUDIO_CHANNEL_POSITION_TOP_SIDE_RIGHT, - Self::TopRearCenter => ffi::GST_AUDIO_CHANNEL_POSITION_TOP_REAR_CENTER, - Self::BottomFrontCenter => ffi::GST_AUDIO_CHANNEL_POSITION_BOTTOM_FRONT_CENTER, - Self::BottomFrontLeft => ffi::GST_AUDIO_CHANNEL_POSITION_BOTTOM_FRONT_LEFT, - Self::BottomFrontRight => ffi::GST_AUDIO_CHANNEL_POSITION_BOTTOM_FRONT_RIGHT, - Self::WideLeft => ffi::GST_AUDIO_CHANNEL_POSITION_WIDE_LEFT, - Self::WideRight => ffi::GST_AUDIO_CHANNEL_POSITION_WIDE_RIGHT, - Self::SurroundLeft => ffi::GST_AUDIO_CHANNEL_POSITION_SURROUND_LEFT, - Self::SurroundRight => ffi::GST_AUDIO_CHANNEL_POSITION_SURROUND_RIGHT, - Self::__Unknown(value) => value, - } - } -} - -#[doc(hidden)] -impl FromGlib for AudioChannelPosition { - unsafe fn from_glib(value: ffi::GstAudioChannelPosition) -> Self { - skip_assert_initialized!(); - match value { - ffi::GST_AUDIO_CHANNEL_POSITION_NONE => Self::None, - ffi::GST_AUDIO_CHANNEL_POSITION_MONO => Self::Mono, - ffi::GST_AUDIO_CHANNEL_POSITION_INVALID => Self::Invalid, - ffi::GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT => Self::FrontLeft, - ffi::GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT => Self::FrontRight, - ffi::GST_AUDIO_CHANNEL_POSITION_FRONT_CENTER => Self::FrontCenter, - ffi::GST_AUDIO_CHANNEL_POSITION_LFE1 => Self::Lfe1, - ffi::GST_AUDIO_CHANNEL_POSITION_REAR_LEFT => Self::RearLeft, - ffi::GST_AUDIO_CHANNEL_POSITION_REAR_RIGHT => Self::RearRight, - ffi::GST_AUDIO_CHANNEL_POSITION_FRONT_LEFT_OF_CENTER => Self::FrontLeftOfCenter, - ffi::GST_AUDIO_CHANNEL_POSITION_FRONT_RIGHT_OF_CENTER => Self::FrontRightOfCenter, - ffi::GST_AUDIO_CHANNEL_POSITION_REAR_CENTER => Self::RearCenter, - ffi::GST_AUDIO_CHANNEL_POSITION_LFE2 => Self::Lfe2, - ffi::GST_AUDIO_CHANNEL_POSITION_SIDE_LEFT => Self::SideLeft, - ffi::GST_AUDIO_CHANNEL_POSITION_SIDE_RIGHT => Self::SideRight, - ffi::GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_LEFT => Self::TopFrontLeft, - ffi::GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_RIGHT => Self::TopFrontRight, - ffi::GST_AUDIO_CHANNEL_POSITION_TOP_FRONT_CENTER => Self::TopFrontCenter, - ffi::GST_AUDIO_CHANNEL_POSITION_TOP_CENTER => Self::TopCenter, - ffi::GST_AUDIO_CHANNEL_POSITION_TOP_REAR_LEFT => Self::TopRearLeft, - ffi::GST_AUDIO_CHANNEL_POSITION_TOP_REAR_RIGHT => Self::TopRearRight, - ffi::GST_AUDIO_CHANNEL_POSITION_TOP_SIDE_LEFT => Self::TopSideLeft, - ffi::GST_AUDIO_CHANNEL_POSITION_TOP_SIDE_RIGHT => Self::TopSideRight, - ffi::GST_AUDIO_CHANNEL_POSITION_TOP_REAR_CENTER => Self::TopRearCenter, - ffi::GST_AUDIO_CHANNEL_POSITION_BOTTOM_FRONT_CENTER => Self::BottomFrontCenter, - ffi::GST_AUDIO_CHANNEL_POSITION_BOTTOM_FRONT_LEFT => Self::BottomFrontLeft, - ffi::GST_AUDIO_CHANNEL_POSITION_BOTTOM_FRONT_RIGHT => Self::BottomFrontRight, - ffi::GST_AUDIO_CHANNEL_POSITION_WIDE_LEFT => Self::WideLeft, - ffi::GST_AUDIO_CHANNEL_POSITION_WIDE_RIGHT => Self::WideRight, - ffi::GST_AUDIO_CHANNEL_POSITION_SURROUND_LEFT => Self::SurroundLeft, - ffi::GST_AUDIO_CHANNEL_POSITION_SURROUND_RIGHT => Self::SurroundRight, - value => Self::__Unknown(value), - } - } -} - -impl StaticType for AudioChannelPosition { - #[inline] - fn static_type() -> Type { - unsafe { from_glib(ffi::gst_audio_channel_position_get_type()) } - } -} - -impl glib::value::ValueType for AudioChannelPosition { - type Type = Self; -} - -unsafe impl<'a> FromValue<'a> for AudioChannelPosition { - type Checker = glib::value::GenericValueTypeChecker; - - #[inline] - unsafe fn from_value(value: &'a glib::Value) -> Self { - skip_assert_initialized!(); - from_glib(glib::gobject_ffi::g_value_get_enum(value.to_glib_none().0)) - } -} - -impl ToValue for AudioChannelPosition { - #[inline] - fn to_value(&self) -> glib::Value { - let mut value = glib::Value::for_value_type::(); - unsafe { - glib::gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, self.into_glib()); - } - value - } - - #[inline] - fn value_type(&self) -> glib::Type { - Self::static_type() - } -} - -impl From for glib::Value { - #[inline] - fn from(v: AudioChannelPosition) -> Self { - skip_assert_initialized!(); - ToValue::to_value(&v) - } -} - #[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)] #[non_exhaustive] #[doc(alias = "GstAudioDitherMethod")] diff --git a/gstreamer-audio/src/auto/mod.rs b/gstreamer-audio/src/auto/mod.rs index c5fafdaee..3bc064267 100644 --- a/gstreamer-audio/src/auto/mod.rs +++ b/gstreamer-audio/src/auto/mod.rs @@ -40,7 +40,6 @@ mod audio_stream_align; pub use self::audio_stream_align::AudioStreamAlign; mod enums; -pub use self::enums::AudioChannelPosition; pub use self::enums::AudioDitherMethod; pub use self::enums::AudioFormat; pub use self::enums::AudioLayout;