forked from mirrors/gstreamer-rs
gstreamer-base/{adapter,functions}, gstreamer-video/video_info: Change functions from returning Option to Result
Partial work for: https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/issues/216
This commit is contained in:
parent
eaafbd14f7
commit
62c0b689a6
3 changed files with 22 additions and 22 deletions
|
@ -183,15 +183,15 @@ impl UniqueAdapter {
|
||||||
self.0.push(buf);
|
self.0.push(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn map(&mut self, nbytes: usize) -> Option<UniqueAdapterMap> {
|
pub fn map(&mut self, nbytes: usize) -> Result<UniqueAdapterMap, glib::error::BoolError> {
|
||||||
use std::slice;
|
use std::slice;
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = gst_base_sys::gst_adapter_map(self.0.to_glib_none().0, nbytes);
|
let ptr = gst_base_sys::gst_adapter_map(self.0.to_glib_none().0, nbytes);
|
||||||
if ptr.is_null() {
|
if ptr.is_null() {
|
||||||
None
|
Err(glib_bool_error!("size bytes are not available"))
|
||||||
} else {
|
} else {
|
||||||
Some(UniqueAdapterMap(
|
Ok(UniqueAdapterMap(
|
||||||
self,
|
self,
|
||||||
slice::from_raw_parts(ptr as *const u8, nbytes),
|
slice::from_raw_parts(ptr as *const u8, nbytes),
|
||||||
))
|
))
|
||||||
|
|
|
@ -15,7 +15,7 @@ use std::mem;
|
||||||
pub fn type_find_helper_for_data<P: IsA<gst::Object>, R: AsRef<[u8]>>(
|
pub fn type_find_helper_for_data<P: IsA<gst::Object>, R: AsRef<[u8]>>(
|
||||||
obj: Option<&P>,
|
obj: Option<&P>,
|
||||||
data: R,
|
data: R,
|
||||||
) -> Option<(gst::Caps, gst::TypeFindProbability)> {
|
) -> Result<(gst::Caps, gst::TypeFindProbability), glib::error::BoolError> {
|
||||||
assert_initialized_main_thread!();
|
assert_initialized_main_thread!();
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut prob = mem::MaybeUninit::uninit();
|
let mut prob = mem::MaybeUninit::uninit();
|
||||||
|
@ -28,9 +28,9 @@ pub fn type_find_helper_for_data<P: IsA<gst::Object>, R: AsRef<[u8]>>(
|
||||||
prob.as_mut_ptr(),
|
prob.as_mut_ptr(),
|
||||||
);
|
);
|
||||||
if ret.is_null() {
|
if ret.is_null() {
|
||||||
None
|
Err(glib_bool_error!("No type could be found"))
|
||||||
} else {
|
} else {
|
||||||
Some((from_glib_full(ret), from_glib(prob.assume_init())))
|
Ok((from_glib_full(ret), from_glib(prob.assume_init())))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ pub fn type_find_helper_for_data_with_extension<P: IsA<gst::Object>, R: AsRef<[u
|
||||||
obj: Option<&P>,
|
obj: Option<&P>,
|
||||||
data: R,
|
data: R,
|
||||||
extension: Option<&str>,
|
extension: Option<&str>,
|
||||||
) -> Option<(gst::Caps, gst::TypeFindProbability)> {
|
) -> Result<(gst::Caps, gst::TypeFindProbability), glib::error::BoolError> {
|
||||||
assert_initialized_main_thread!();
|
assert_initialized_main_thread!();
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut prob = mem::MaybeUninit::uninit();
|
let mut prob = mem::MaybeUninit::uninit();
|
||||||
|
@ -54,9 +54,9 @@ pub fn type_find_helper_for_data_with_extension<P: IsA<gst::Object>, R: AsRef<[u
|
||||||
prob.as_mut_ptr(),
|
prob.as_mut_ptr(),
|
||||||
);
|
);
|
||||||
if ret.is_null() {
|
if ret.is_null() {
|
||||||
None
|
Err(glib_bool_error!("No type could be found"))
|
||||||
} else {
|
} else {
|
||||||
Some((from_glib_full(ret), from_glib(prob.assume_init())))
|
Ok((from_glib_full(ret), from_glib(prob.assume_init())))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ pub fn type_find_helper_for_data_with_extension<P: IsA<gst::Object>, R: AsRef<[u
|
||||||
pub fn type_find_helper_for_buffer<P: IsA<gst::Object>>(
|
pub fn type_find_helper_for_buffer<P: IsA<gst::Object>>(
|
||||||
obj: Option<&P>,
|
obj: Option<&P>,
|
||||||
buf: &gst::Buffer,
|
buf: &gst::Buffer,
|
||||||
) -> Option<(gst::Caps, gst::TypeFindProbability)> {
|
) -> Result<(gst::Caps, gst::TypeFindProbability), glib::error::BoolError> {
|
||||||
assert_initialized_main_thread!();
|
assert_initialized_main_thread!();
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut prob = mem::MaybeUninit::uninit();
|
let mut prob = mem::MaybeUninit::uninit();
|
||||||
|
@ -74,9 +74,9 @@ pub fn type_find_helper_for_buffer<P: IsA<gst::Object>>(
|
||||||
prob.as_mut_ptr(),
|
prob.as_mut_ptr(),
|
||||||
);
|
);
|
||||||
if ret.is_null() {
|
if ret.is_null() {
|
||||||
None
|
Err(glib_bool_error!("No type could be found"))
|
||||||
} else {
|
} else {
|
||||||
Some((from_glib_full(ret), from_glib(prob.assume_init())))
|
Ok((from_glib_full(ret), from_glib(prob.assume_init())))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ pub fn type_find_helper_for_buffer_with_extension<P: IsA<gst::Object>>(
|
||||||
obj: Option<&P>,
|
obj: Option<&P>,
|
||||||
buf: &gst::Buffer,
|
buf: &gst::Buffer,
|
||||||
extension: Option<&str>,
|
extension: Option<&str>,
|
||||||
) -> Option<(gst::Caps, gst::TypeFindProbability)> {
|
) -> Result<(gst::Caps, gst::TypeFindProbability), glib::error::BoolError> {
|
||||||
assert_initialized_main_thread!();
|
assert_initialized_main_thread!();
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut prob = mem::MaybeUninit::uninit();
|
let mut prob = mem::MaybeUninit::uninit();
|
||||||
|
@ -97,9 +97,9 @@ pub fn type_find_helper_for_buffer_with_extension<P: IsA<gst::Object>>(
|
||||||
prob.as_mut_ptr(),
|
prob.as_mut_ptr(),
|
||||||
);
|
);
|
||||||
if ret.is_null() {
|
if ret.is_null() {
|
||||||
None
|
Err(glib_bool_error!("No type could be found"))
|
||||||
} else {
|
} else {
|
||||||
Some((from_glib_full(ret), from_glib(prob.assume_init())))
|
Ok((from_glib_full(ret), from_glib(prob.assume_init())))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,9 +147,9 @@ impl PartialEq for VideoColorimetry {
|
||||||
impl Eq for VideoColorimetry {}
|
impl Eq for VideoColorimetry {}
|
||||||
|
|
||||||
impl str::FromStr for ::VideoColorimetry {
|
impl str::FromStr for ::VideoColorimetry {
|
||||||
type Err = ();
|
type Err = glib::error::BoolError;
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, ()> {
|
fn from_str(s: &str) -> Result<Self, glib::error::BoolError> {
|
||||||
assert_initialized_main_thread!();
|
assert_initialized_main_thread!();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -161,7 +161,7 @@ impl str::FromStr for ::VideoColorimetry {
|
||||||
if valid {
|
if valid {
|
||||||
Ok(VideoColorimetry(colorimetry.assume_init()))
|
Ok(VideoColorimetry(colorimetry.assume_init()))
|
||||||
} else {
|
} else {
|
||||||
Err(())
|
Err(glib_bool_error!("Invalid colorimetry info"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -834,9 +834,9 @@ impl ::VideoFieldOrder {
|
||||||
|
|
||||||
#[cfg(any(feature = "v1_12", feature = "dox"))]
|
#[cfg(any(feature = "v1_12", feature = "dox"))]
|
||||||
impl str::FromStr for ::VideoFieldOrder {
|
impl str::FromStr for ::VideoFieldOrder {
|
||||||
type Err = ();
|
type Err = glib::error::BoolError;
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, ()> {
|
fn from_str(s: &str) -> Result<Self, glib::error::BoolError> {
|
||||||
assert_initialized_main_thread!();
|
assert_initialized_main_thread!();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -867,9 +867,9 @@ impl ::VideoInterlaceMode {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl str::FromStr for ::VideoInterlaceMode {
|
impl str::FromStr for ::VideoInterlaceMode {
|
||||||
type Err = ();
|
type Err = glib::error::BoolError;
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, ()> {
|
fn from_str(s: &str) -> Result<Self, glib::error::BoolError> {
|
||||||
assert_initialized_main_thread!();
|
assert_initialized_main_thread!();
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
Loading…
Reference in a new issue