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:
Tony Jinwoo Ahn 2019-12-16 11:29:51 +00:00 committed by Sebastian Dröge
parent eaafbd14f7
commit 62c0b689a6
3 changed files with 22 additions and 22 deletions

View file

@ -183,15 +183,15 @@ impl UniqueAdapter {
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;
unsafe {
let ptr = gst_base_sys::gst_adapter_map(self.0.to_glib_none().0, nbytes);
if ptr.is_null() {
None
Err(glib_bool_error!("size bytes are not available"))
} else {
Some(UniqueAdapterMap(
Ok(UniqueAdapterMap(
self,
slice::from_raw_parts(ptr as *const u8, nbytes),
))

View file

@ -15,7 +15,7 @@ use std::mem;
pub fn type_find_helper_for_data<P: IsA<gst::Object>, R: AsRef<[u8]>>(
obj: Option<&P>,
data: R,
) -> Option<(gst::Caps, gst::TypeFindProbability)> {
) -> Result<(gst::Caps, gst::TypeFindProbability), glib::error::BoolError> {
assert_initialized_main_thread!();
unsafe {
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(),
);
if ret.is_null() {
None
Err(glib_bool_error!("No type could be found"))
} 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>,
data: R,
extension: Option<&str>,
) -> Option<(gst::Caps, gst::TypeFindProbability)> {
) -> Result<(gst::Caps, gst::TypeFindProbability), glib::error::BoolError> {
assert_initialized_main_thread!();
unsafe {
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(),
);
if ret.is_null() {
None
Err(glib_bool_error!("No type could be found"))
} 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>>(
obj: Option<&P>,
buf: &gst::Buffer,
) -> Option<(gst::Caps, gst::TypeFindProbability)> {
) -> Result<(gst::Caps, gst::TypeFindProbability), glib::error::BoolError> {
assert_initialized_main_thread!();
unsafe {
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(),
);
if ret.is_null() {
None
Err(glib_bool_error!("No type could be found"))
} 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>,
buf: &gst::Buffer,
extension: Option<&str>,
) -> Option<(gst::Caps, gst::TypeFindProbability)> {
) -> Result<(gst::Caps, gst::TypeFindProbability), glib::error::BoolError> {
assert_initialized_main_thread!();
unsafe {
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(),
);
if ret.is_null() {
None
Err(glib_bool_error!("No type could be found"))
} else {
Some((from_glib_full(ret), from_glib(prob.assume_init())))
Ok((from_glib_full(ret), from_glib(prob.assume_init())))
}
}
}

View file

@ -147,9 +147,9 @@ impl PartialEq for VideoColorimetry {
impl Eq 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!();
unsafe {
@ -161,7 +161,7 @@ impl str::FromStr for ::VideoColorimetry {
if valid {
Ok(VideoColorimetry(colorimetry.assume_init()))
} else {
Err(())
Err(glib_bool_error!("Invalid colorimetry info"))
}
}
}
@ -834,9 +834,9 @@ impl ::VideoFieldOrder {
#[cfg(any(feature = "v1_12", feature = "dox"))]
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!();
unsafe {
@ -867,9 +867,9 @@ impl ::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!();
unsafe {