forked from mirrors/gstreamer-rs
Implement some more traits for AudioFormat and AudioFormatInfo
This commit is contained in:
parent
6b11b8b751
commit
cff116c3aa
1 changed files with 34 additions and 18 deletions
|
@ -62,23 +62,39 @@ impl ::AudioFormat {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn from_string(s: &str) -> ::AudioFormat {
|
||||||
|
unsafe { from_glib(ffi::gst_audio_format_from_string(s.to_glib_none().0)) }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn to_string(&self) -> &'static str {
|
||||||
|
unsafe {
|
||||||
|
CStr::from_ptr(ffi::gst_audio_format_to_string(self.to_glib()))
|
||||||
|
.to_str()
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl str::FromStr for ::AudioFormat {
|
impl str::FromStr for ::AudioFormat {
|
||||||
type Err = ();
|
type Err = ();
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, ()> {
|
fn from_str(s: &str) -> Result<Self, ()> {
|
||||||
unsafe {
|
let format = Self::from_string(s);
|
||||||
let format = ffi::gst_audio_format_from_string(s.to_glib_none().0);
|
if format == ::AudioFormat::Unknown {
|
||||||
if format == ffi::GST_AUDIO_FORMAT_UNKNOWN {
|
Err(())
|
||||||
Err(())
|
} else {
|
||||||
} else {
|
Ok(format)
|
||||||
Ok(from_glib(format))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for ::AudioFormat {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||||
|
f.write_str(self.to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(target_endian = "big")]
|
#[cfg(target_endian = "big")]
|
||||||
pub const AUDIO_FORMAT_S16: ::AudioFormat = ::AudioFormat::S16be;
|
pub const AUDIO_FORMAT_S16: ::AudioFormat = ::AudioFormat::S16be;
|
||||||
#[cfg(target_endian = "big")]
|
#[cfg(target_endian = "big")]
|
||||||
|
@ -308,9 +324,9 @@ impl fmt::Debug for AudioFormatInfo {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<::AudioFormat> for AudioFormatInfo {
|
impl fmt::Display for AudioFormatInfo {
|
||||||
fn from(f: ::AudioFormat) -> Self {
|
fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
|
||||||
Self::from_format(f)
|
f.write_str(self.name())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,14 +334,14 @@ impl str::FromStr for ::AudioFormatInfo {
|
||||||
type Err = ();
|
type Err = ();
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, ()> {
|
fn from_str(s: &str) -> Result<Self, ()> {
|
||||||
unsafe {
|
let format = s.parse()?;
|
||||||
let format = ffi::gst_audio_format_from_string(s.to_glib_none().0);
|
Ok(AudioFormatInfo::from_format(format))
|
||||||
if format == ffi::GST_AUDIO_FORMAT_UNKNOWN {
|
}
|
||||||
Err(())
|
}
|
||||||
} else {
|
|
||||||
Ok(AudioFormatInfo::from_format(from_glib(format)))
|
impl From<::AudioFormat> for AudioFormatInfo {
|
||||||
}
|
fn from(f: ::AudioFormat) -> Self {
|
||||||
}
|
Self::from_format(f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue