audio/video: Update to v1.20 functions

This commit is contained in:
Marijn Suijten 2020-11-24 10:11:35 +01:00
parent 132477f51f
commit a215610167
3 changed files with 23 additions and 12 deletions

View file

@ -15,6 +15,7 @@ edition = "2018"
[dependencies] [dependencies]
libc = "0.2" libc = "0.2"
cfg-if = "1.0"
bitflags = "1.0" bitflags = "1.0"
ffi = { package = "gstreamer-audio-sys", path = "sys", features = ["v1_8"] } ffi = { package = "gstreamer-audio-sys", path = "sys", features = ["v1_8"] }
glib = { git = "https://github.com/gtk-rs/gtk-rs" } glib = { git = "https://github.com/gtk-rs/gtk-rs" }

View file

@ -175,9 +175,15 @@ impl AudioFormatInfo {
} }
unsafe { unsafe {
cfg_if::cfg_if! {
if #[cfg(any(feature = "v1_20", all(not(doctest), doc)))] {
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()) ffi::gst_audio_format_fill_silence(self.0, dest.as_mut_ptr() as *mut _, dest.len())
} }
} }
}
}
pub fn is_float(&self) -> bool { pub fn is_float(&self) -> bool {
self.flags().contains(crate::AudioFormatFlags::FLOAT) self.flags().contains(crate::AudioFormatFlags::FLOAT)

View file

@ -12,10 +12,6 @@ use glib::translate::{
}; };
use gst::prelude::*; use gst::prelude::*;
#[cfg(any(feature = "v1_12", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_12")))]
use std::ffi::CStr;
use std::fmt; use std::fmt;
use std::mem; use std::mem;
use std::ptr; use std::ptr;
@ -183,11 +179,18 @@ impl str::FromStr for crate::VideoChromaSite {
type Err = glib::error::BoolError; type Err = glib::error::BoolError;
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
assert_initialized_main_thread!(); skip_assert_initialized!();
unsafe { cfg_if::cfg_if! {
if #[cfg(any(feature = "v1_20", all(not(doctest), doc)))] {
let chroma_site = Self::from_string(s);
} else {
assert_initialized_main_thread!();
let chroma_site: Self = let chroma_site: Self =
from_glib(ffi::gst_video_chroma_from_string(s.to_glib_none().0)); unsafe { from_glib(ffi::gst_video_chroma_from_string(s.to_glib_none().0)) };
}
};
if chroma_site.is_empty() { if chroma_site.is_empty() {
Err(glib::glib_bool_error!("Invalid chroma site")) Err(glib::glib_bool_error!("Invalid chroma site"))
} else { } else {
@ -195,7 +198,6 @@ impl str::FromStr for crate::VideoChromaSite {
} }
} }
} }
}
impl fmt::Display for crate::VideoChromaSite { impl fmt::Display for crate::VideoChromaSite {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@ -935,6 +937,8 @@ impl glib::translate::FromGlibPtrFull<*mut ffi::GstVideoInfo> for VideoInfo {
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_12")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_12")))]
impl crate::VideoFieldOrder { impl crate::VideoFieldOrder {
pub fn to_str<'a>(self) -> &'a str { pub fn to_str<'a>(self) -> &'a str {
use std::ffi::CStr;
if self == Self::Unknown { if self == Self::Unknown {
return "UNKNOWN"; return "UNKNOWN";
} }