2020-12-15 10:53:31 +00:00
|
|
|
// Take a look at the license at the top of the repository in the LICENSE file.
|
2017-08-08 22:29:49 +00:00
|
|
|
|
2020-06-05 09:57:29 +00:00
|
|
|
use std::cmp::Ordering;
|
2017-08-08 22:29:49 +00:00
|
|
|
use std::ffi::CStr;
|
|
|
|
use std::fmt;
|
|
|
|
use std::str;
|
|
|
|
|
2021-04-27 15:15:46 +00:00
|
|
|
use glib::translate::{from_glib, from_glib_none, FromGlib, IntoGlib, ToGlibPtr, ToGlibPtrMut};
|
2021-04-20 07:19:02 +00:00
|
|
|
use glib::StaticType;
|
2017-08-08 22:29:49 +00:00
|
|
|
|
2017-11-26 21:50:39 +00:00
|
|
|
#[derive(PartialEq, Eq, Copy, Clone, Debug, Hash)]
|
2017-08-08 22:29:49 +00:00
|
|
|
pub enum AudioEndianness {
|
|
|
|
Unknown,
|
|
|
|
LittleEndian = 1234,
|
|
|
|
BigEndian = 4321,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromGlib<i32> for AudioEndianness {
|
2020-12-08 14:07:12 +00:00
|
|
|
#[allow(unused_unsafe)]
|
|
|
|
unsafe fn from_glib(value: i32) -> Self {
|
2017-08-30 11:39:09 +00:00
|
|
|
assert_initialized_main_thread!();
|
|
|
|
|
2017-08-08 22:29:49 +00:00
|
|
|
match value {
|
2021-04-29 20:49:26 +00:00
|
|
|
1234 => Self::LittleEndian,
|
|
|
|
4321 => Self::BigEndian,
|
|
|
|
_ => Self::Unknown,
|
2017-08-08 22:29:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-27 15:15:46 +00:00
|
|
|
impl IntoGlib for AudioEndianness {
|
2017-08-08 22:29:49 +00:00
|
|
|
type GlibType = i32;
|
|
|
|
|
2021-04-27 15:15:46 +00:00
|
|
|
fn into_glib(self) -> i32 {
|
|
|
|
match self {
|
2021-04-29 20:49:26 +00:00
|
|
|
Self::LittleEndian => 1234,
|
|
|
|
Self::BigEndian => 4321,
|
2017-08-08 22:29:49 +00:00
|
|
|
_ => 0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-01 13:15:59 +00:00
|
|
|
#[doc(alias = "GstAudioFormatInfo")]
|
2020-11-21 18:17:20 +00:00
|
|
|
pub struct AudioFormatInfo(&'static ffi::GstAudioFormatInfo);
|
2017-08-08 22:29:49 +00:00
|
|
|
|
|
|
|
impl AudioFormatInfo {
|
2021-04-29 20:49:26 +00:00
|
|
|
pub fn from_format(format: crate::AudioFormat) -> Self {
|
2017-08-30 11:39:09 +00:00
|
|
|
assert_initialized_main_thread!();
|
|
|
|
|
2017-08-08 22:29:49 +00:00
|
|
|
unsafe {
|
2021-04-27 15:15:46 +00:00
|
|
|
let info = ffi::gst_audio_format_get_info(format.into_glib());
|
2017-08-08 22:29:49 +00:00
|
|
|
assert!(!info.is_null());
|
|
|
|
|
2021-04-29 20:49:26 +00:00
|
|
|
Self(&*info)
|
2017-08-08 22:29:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 18:17:20 +00:00
|
|
|
pub fn format(&self) -> crate::AudioFormat {
|
2020-12-08 14:07:12 +00:00
|
|
|
unsafe { from_glib(self.0.format) }
|
2017-08-08 22:29:49 +00:00
|
|
|
}
|
|
|
|
|
2017-09-01 08:40:32 +00:00
|
|
|
pub fn name<'a>(&self) -> &'a str {
|
2017-08-08 22:29:49 +00:00
|
|
|
unsafe { CStr::from_ptr(self.0.name).to_str().unwrap() }
|
|
|
|
}
|
|
|
|
|
2017-09-01 08:40:32 +00:00
|
|
|
pub fn description<'a>(&self) -> &'a str {
|
2017-08-08 22:29:49 +00:00
|
|
|
unsafe { CStr::from_ptr(self.0.description).to_str().unwrap() }
|
|
|
|
}
|
|
|
|
|
2020-11-21 18:17:20 +00:00
|
|
|
pub fn flags(&self) -> crate::AudioFormatFlags {
|
2020-12-08 14:07:12 +00:00
|
|
|
unsafe { from_glib(self.0.flags) }
|
2017-08-08 22:29:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn endianness(&self) -> AudioEndianness {
|
2020-12-08 14:07:12 +00:00
|
|
|
unsafe { from_glib(self.0.endianness) }
|
2017-08-08 22:29:49 +00:00
|
|
|
}
|
|
|
|
|
2017-08-10 21:41:36 +00:00
|
|
|
pub fn width(&self) -> u32 {
|
|
|
|
self.0.width as u32
|
2017-08-08 22:29:49 +00:00
|
|
|
}
|
|
|
|
|
2017-08-10 21:41:36 +00:00
|
|
|
pub fn depth(&self) -> u32 {
|
|
|
|
self.0.depth as u32
|
2017-08-08 22:29:49 +00:00
|
|
|
}
|
|
|
|
|
2020-11-21 18:17:20 +00:00
|
|
|
pub fn unpack_format(&self) -> crate::AudioFormat {
|
2020-12-08 14:07:12 +00:00
|
|
|
unsafe { from_glib(self.0.unpack_format) }
|
2017-08-08 22:29:49 +00:00
|
|
|
}
|
|
|
|
|
2017-09-01 08:40:32 +00:00
|
|
|
pub fn silence<'a>(&self) -> &'a [u8] {
|
2017-08-08 22:29:49 +00:00
|
|
|
&self.0.silence
|
|
|
|
}
|
|
|
|
|
2020-11-21 18:17:20 +00:00
|
|
|
pub fn unpack(&self, flags: crate::AudioPackFlags, dest: &mut [u8], src: &[u8]) {
|
2017-08-08 22:29:49 +00:00
|
|
|
let unpack_format = Self::from_format(self.unpack_format());
|
|
|
|
let unpack_width = unpack_format.width() as usize;
|
|
|
|
|
|
|
|
if unpack_width == 0 || self.0.unpack_func.is_none() {
|
|
|
|
panic!("No unpack format for {:?}", self);
|
|
|
|
}
|
|
|
|
|
|
|
|
let self_width = self.width() as usize;
|
|
|
|
if self_width == 0 {
|
|
|
|
panic!("No width for {:?}", self);
|
|
|
|
}
|
|
|
|
|
|
|
|
if src.len() % (self_width / 8) != 0 {
|
|
|
|
panic!("Incomplete number of samples in src");
|
|
|
|
}
|
|
|
|
|
|
|
|
let nsamples = src.len() / (self_width / 8);
|
|
|
|
|
|
|
|
if dest.len() != nsamples * (unpack_width / 8) {
|
|
|
|
panic!("Invalid dest length");
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
(self.0.unpack_func.as_ref().unwrap())(
|
|
|
|
self.0,
|
2021-04-27 15:15:46 +00:00
|
|
|
flags.into_glib(),
|
2017-08-08 22:29:49 +00:00
|
|
|
dest.as_mut_ptr() as *mut _,
|
2019-05-26 16:31:21 +00:00
|
|
|
src.as_ptr() as *const _,
|
2017-08-08 22:29:49 +00:00
|
|
|
nsamples as i32,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 18:17:20 +00:00
|
|
|
pub fn pack(&self, flags: crate::AudioPackFlags, dest: &mut [u8], src: &[u8]) {
|
2017-08-08 22:29:49 +00:00
|
|
|
let unpack_format = Self::from_format(self.unpack_format());
|
|
|
|
let unpack_width = unpack_format.width() as usize;
|
|
|
|
|
|
|
|
if unpack_width == 0 || self.0.pack_func.is_none() {
|
|
|
|
panic!("No unpack format for {:?}", self);
|
|
|
|
}
|
|
|
|
|
|
|
|
let self_width = self.width() as usize;
|
|
|
|
if self_width == 0 {
|
|
|
|
panic!("No width for {:?}", self);
|
|
|
|
}
|
|
|
|
|
|
|
|
if src.len() % (unpack_width / 8) != 0 {
|
|
|
|
panic!("Incomplete number of samples in src");
|
|
|
|
}
|
|
|
|
|
|
|
|
let nsamples = src.len() / (unpack_width / 8);
|
|
|
|
|
|
|
|
if dest.len() != nsamples * (self_width / 8) {
|
|
|
|
panic!("Invalid dest length");
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
(self.0.pack_func.as_ref().unwrap())(
|
|
|
|
self.0,
|
2021-04-27 15:15:46 +00:00
|
|
|
flags.into_glib(),
|
2019-05-26 16:31:21 +00:00
|
|
|
src.as_ptr() as *const _,
|
2017-08-08 22:29:49 +00:00
|
|
|
dest.as_mut_ptr() as *mut _,
|
|
|
|
nsamples as i32,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 20:35:47 +00:00
|
|
|
#[doc(alias = "gst_audio_format_info_fill_silence")]
|
|
|
|
#[doc(alias = "gst_audio_format_fill_silence")]
|
2017-08-08 22:29:49 +00:00
|
|
|
pub fn fill_silence(&self, dest: &mut [u8]) {
|
|
|
|
let self_width = self.width() as usize;
|
|
|
|
|
|
|
|
if self_width == 0 {
|
|
|
|
panic!("Filling with silence unsupported");
|
|
|
|
}
|
|
|
|
|
|
|
|
if dest.len() % (self_width / 8) != 0 {
|
|
|
|
panic!("Incomplete number of samples in dest");
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe {
|
2020-11-24 09:11:35 +00:00
|
|
|
cfg_if::cfg_if! {
|
2021-04-17 10:11:52 +00:00
|
|
|
if #[cfg(feature = "v1_20")] {
|
2020-11-24 09:11:35 +00:00
|
|
|
ffi::gst_audio_format_info_fill_silence(self.0, dest.as_mut_ptr() as *mut _, dest.len())
|
|
|
|
} else {
|
|
|
|
ffi::gst_audio_format_fill_silence(self.0, dest.as_mut_ptr() as *mut _, dest.len())
|
|
|
|
}
|
|
|
|
}
|
2017-08-08 22:29:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_float(&self) -> bool {
|
2020-11-21 18:17:20 +00:00
|
|
|
self.flags().contains(crate::AudioFormatFlags::FLOAT)
|
2017-08-08 22:29:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_integer(&self) -> bool {
|
2020-11-21 18:17:20 +00:00
|
|
|
self.flags().contains(crate::AudioFormatFlags::INTEGER)
|
2017-08-08 22:29:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_signed(&self) -> bool {
|
2020-11-21 18:17:20 +00:00
|
|
|
self.flags().contains(crate::AudioFormatFlags::SIGNED)
|
2017-08-08 22:29:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_little_endian(&self) -> bool {
|
|
|
|
self.endianness() == AudioEndianness::LittleEndian
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_big_endian(&self) -> bool {
|
|
|
|
self.endianness() == AudioEndianness::BigEndian
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe impl Sync for AudioFormatInfo {}
|
|
|
|
unsafe impl Send for AudioFormatInfo {}
|
|
|
|
|
|
|
|
impl PartialEq for AudioFormatInfo {
|
|
|
|
fn eq(&self, other: &Self) -> bool {
|
|
|
|
self.format() == other.format()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Eq for AudioFormatInfo {}
|
|
|
|
|
2020-06-05 09:57:29 +00:00
|
|
|
impl PartialOrd for AudioFormatInfo {
|
2021-04-29 20:49:26 +00:00
|
|
|
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
2020-06-05 09:57:29 +00:00
|
|
|
Some(self.cmp(other))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Ord for AudioFormatInfo {
|
|
|
|
// See GST_AUDIO_FORMATS_ALL for the sorting algorithm
|
2021-04-29 20:49:26 +00:00
|
|
|
fn cmp(&self, other: &Self) -> Ordering {
|
2020-06-05 09:57:29 +00:00
|
|
|
self.depth()
|
|
|
|
.cmp(&other.depth())
|
|
|
|
.then_with(|| self.width().cmp(&other.width()))
|
|
|
|
.then_with(|| {
|
|
|
|
match (
|
2020-11-21 18:17:20 +00:00
|
|
|
self.flags().contains(crate::AudioFormatFlags::FLOAT),
|
|
|
|
other.flags().contains(crate::AudioFormatFlags::FLOAT),
|
2020-06-05 09:57:29 +00:00
|
|
|
) {
|
|
|
|
(true, false) => Ordering::Greater,
|
|
|
|
(false, true) => Ordering::Less,
|
|
|
|
_ => Ordering::Equal,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then_with(|| {
|
|
|
|
match (
|
2020-11-21 18:17:20 +00:00
|
|
|
self.flags().contains(crate::AudioFormatFlags::SIGNED),
|
|
|
|
other.flags().contains(crate::AudioFormatFlags::SIGNED),
|
2020-06-05 09:57:29 +00:00
|
|
|
) {
|
|
|
|
(true, false) => Ordering::Greater,
|
|
|
|
(false, true) => Ordering::Less,
|
|
|
|
_ => Ordering::Equal,
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then_with(|| match (self.endianness(), other.endianness()) {
|
2020-11-21 18:17:20 +00:00
|
|
|
(crate::AudioEndianness::LittleEndian, crate::AudioEndianness::BigEndian) => {
|
2020-06-05 09:57:29 +00:00
|
|
|
#[cfg(target_endian = "little")]
|
|
|
|
{
|
|
|
|
Ordering::Greater
|
|
|
|
}
|
|
|
|
#[cfg(target_endian = "big")]
|
|
|
|
{
|
|
|
|
Ordering::Less
|
|
|
|
}
|
|
|
|
}
|
2020-11-21 18:17:20 +00:00
|
|
|
(crate::AudioEndianness::BigEndian, crate::AudioEndianness::LittleEndian) => {
|
2020-06-05 09:57:29 +00:00
|
|
|
#[cfg(target_endian = "little")]
|
|
|
|
{
|
|
|
|
Ordering::Less
|
|
|
|
}
|
|
|
|
#[cfg(target_endian = "big")]
|
|
|
|
{
|
|
|
|
Ordering::Greater
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => Ordering::Equal,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-08 22:29:49 +00:00
|
|
|
impl fmt::Debug for AudioFormatInfo {
|
2020-11-28 11:33:46 +00:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2019-07-03 12:23:09 +00:00
|
|
|
f.debug_struct("AudioFormatInfo")
|
|
|
|
.field("format", &self.format())
|
|
|
|
.field("name", &self.name())
|
|
|
|
.field("description", &self.description())
|
|
|
|
.field("flags", &self.flags())
|
|
|
|
.field("endianness", &self.endianness())
|
|
|
|
.field("width", &self.width())
|
|
|
|
.field("depth", &self.depth())
|
|
|
|
.field("silence", &self.silence())
|
|
|
|
.finish()
|
2017-08-08 22:29:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-10 08:14:08 +00:00
|
|
|
impl fmt::Display for AudioFormatInfo {
|
2020-11-28 11:33:46 +00:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
2017-08-10 08:14:08 +00:00
|
|
|
f.write_str(self.name())
|
2017-08-08 22:29:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 18:17:20 +00:00
|
|
|
impl str::FromStr for crate::AudioFormatInfo {
|
2019-12-17 19:00:42 +00:00
|
|
|
type Err = glib::BoolError;
|
2017-08-08 22:29:49 +00:00
|
|
|
|
2020-11-28 11:34:36 +00:00
|
|
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2017-08-10 08:14:08 +00:00
|
|
|
let format = s.parse()?;
|
2020-11-28 11:34:36 +00:00
|
|
|
Ok(Self::from_format(format))
|
2017-08-10 08:14:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-21 18:17:20 +00:00
|
|
|
impl From<crate::AudioFormat> for AudioFormatInfo {
|
|
|
|
fn from(f: crate::AudioFormat) -> Self {
|
2017-08-30 11:39:09 +00:00
|
|
|
skip_assert_initialized!();
|
2017-08-10 08:14:08 +00:00
|
|
|
Self::from_format(f)
|
2017-08-08 22:29:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-09 22:13:47 +00:00
|
|
|
impl glib::types::StaticType for AudioFormatInfo {
|
|
|
|
fn static_type() -> glib::types::Type {
|
2020-11-21 18:17:20 +00:00
|
|
|
unsafe { glib::translate::from_glib(ffi::gst_audio_format_info_get_type()) }
|
2017-08-09 22:13:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-20 07:19:02 +00:00
|
|
|
impl glib::value::ValueType for AudioFormatInfo {
|
|
|
|
type Type = Self;
|
|
|
|
}
|
|
|
|
|
2017-08-09 22:13:47 +00:00
|
|
|
#[doc(hidden)]
|
2021-04-20 07:19:02 +00:00
|
|
|
unsafe impl<'a> glib::value::FromValue<'a> for AudioFormatInfo {
|
|
|
|
type Checker = glib::value::GenericValueTypeOrNoneChecker<Self>;
|
|
|
|
|
|
|
|
unsafe fn from_value(value: &'a glib::Value) -> Self {
|
|
|
|
skip_assert_initialized!();
|
|
|
|
from_glib_none(glib::gobject_ffi::g_value_get_boxed(value.to_glib_none().0)
|
|
|
|
as *mut ffi::GstAudioFormatInfo)
|
2017-08-09 22:13:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(hidden)]
|
2021-04-20 07:19:02 +00:00
|
|
|
impl glib::value::ToValue for AudioFormatInfo {
|
|
|
|
fn to_value(&self) -> glib::Value {
|
2021-04-25 16:46:18 +00:00
|
|
|
let mut value = glib::Value::for_value_type::<Self>();
|
2021-04-20 07:19:02 +00:00
|
|
|
unsafe {
|
|
|
|
glib::gobject_ffi::g_value_set_boxed(
|
|
|
|
value.to_glib_none_mut().0,
|
|
|
|
self.to_glib_none().0 as *mut _,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
value
|
|
|
|
}
|
|
|
|
|
|
|
|
fn value_type(&self) -> glib::Type {
|
|
|
|
Self::static_type()
|
2017-08-09 22:13:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(hidden)]
|
2021-04-20 07:19:02 +00:00
|
|
|
impl glib::value::ToValueOptional for AudioFormatInfo {
|
|
|
|
fn to_value_optional(s: Option<&Self>) -> glib::Value {
|
|
|
|
skip_assert_initialized!();
|
2021-04-25 16:46:18 +00:00
|
|
|
let mut value = glib::Value::for_value_type::<Self>();
|
2021-04-20 07:19:02 +00:00
|
|
|
unsafe {
|
|
|
|
glib::gobject_ffi::g_value_set_boxed(
|
|
|
|
value.to_glib_none_mut().0,
|
|
|
|
s.to_glib_none().0 as *mut _,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
value
|
2017-08-09 22:13:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(hidden)]
|
|
|
|
impl glib::translate::GlibPtrDefault for AudioFormatInfo {
|
2020-11-21 18:17:20 +00:00
|
|
|
type GlibType = *mut ffi::GstAudioFormatInfo;
|
2017-08-09 22:13:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(hidden)]
|
2020-11-21 18:17:20 +00:00
|
|
|
impl<'a> glib::translate::ToGlibPtr<'a, *const ffi::GstAudioFormatInfo> for AudioFormatInfo {
|
2021-04-29 20:49:26 +00:00
|
|
|
type Storage = &'a Self;
|
2017-08-09 22:13:47 +00:00
|
|
|
|
2020-11-21 18:17:20 +00:00
|
|
|
fn to_glib_none(&'a self) -> glib::translate::Stash<'a, *const ffi::GstAudioFormatInfo, Self> {
|
2017-08-09 22:13:47 +00:00
|
|
|
glib::translate::Stash(self.0, self)
|
|
|
|
}
|
|
|
|
|
2020-11-21 18:17:20 +00:00
|
|
|
fn to_glib_full(&self) -> *const ffi::GstAudioFormatInfo {
|
2017-08-09 22:13:47 +00:00
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[doc(hidden)]
|
2020-11-21 18:17:20 +00:00
|
|
|
impl glib::translate::FromGlibPtrNone<*mut ffi::GstAudioFormatInfo> for AudioFormatInfo {
|
2017-08-09 22:13:47 +00:00
|
|
|
#[inline]
|
2020-11-21 18:17:20 +00:00
|
|
|
unsafe fn from_glib_none(ptr: *mut ffi::GstAudioFormatInfo) -> Self {
|
2021-04-29 20:49:26 +00:00
|
|
|
Self(&*ptr)
|
2017-08-09 22:13:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-15 15:56:20 +00:00
|
|
|
#[doc(hidden)]
|
|
|
|
impl glib::translate::FromGlibPtrNone<*const ffi::GstAudioFormatInfo> for AudioFormatInfo {
|
|
|
|
#[inline]
|
|
|
|
unsafe fn from_glib_none(ptr: *const ffi::GstAudioFormatInfo) -> Self {
|
2021-04-29 20:49:26 +00:00
|
|
|
Self(&*ptr)
|
2020-11-15 15:56:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-08 22:29:49 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_get() {
|
|
|
|
gst::init().unwrap();
|
|
|
|
|
2020-11-21 18:17:20 +00:00
|
|
|
let info = AudioFormatInfo::from_format(crate::AudioFormat::S16le);
|
2017-08-08 22:29:49 +00:00
|
|
|
assert_eq!(info.name(), "S16LE");
|
|
|
|
|
|
|
|
let other_info = "S16LE".parse().unwrap();
|
|
|
|
assert_eq!(info, other_info);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn pack_unpack() {
|
|
|
|
gst::init().unwrap();
|
|
|
|
|
2020-11-21 18:17:20 +00:00
|
|
|
let info = AudioFormatInfo::from_format(crate::AudioFormat::S16le);
|
2017-08-08 22:29:49 +00:00
|
|
|
let unpack_info = AudioFormatInfo::from_format(info.unpack_format());
|
|
|
|
|
|
|
|
assert!(unpack_info.width() > 0);
|
|
|
|
|
|
|
|
let input = [0, 0, 255, 255, 128, 128, 64, 64];
|
|
|
|
let mut unpacked = [0; 16];
|
|
|
|
let mut output = [0; 8];
|
|
|
|
|
2020-11-21 18:17:20 +00:00
|
|
|
info.unpack(crate::AudioPackFlags::empty(), &mut unpacked, &input);
|
|
|
|
info.pack(crate::AudioPackFlags::empty(), &mut output, &unpacked);
|
2017-08-08 22:29:49 +00:00
|
|
|
|
|
|
|
assert_eq!(input, output);
|
|
|
|
}
|
|
|
|
}
|