mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-26 19:41:09 +00:00
Use FlowError instead of FlowReturn as error part of Result
This prevents the possibility of a Result that is an Err(Ok), which would not be meaningful.
This commit is contained in:
parent
a4f25df045
commit
f4685c4629
4 changed files with 29 additions and 36 deletions
|
@ -234,7 +234,7 @@ pub trait BufferPoolExtManual {
|
||||||
fn acquire_buffer<'a, P: Into<Option<&'a BufferPoolAcquireParams>>>(
|
fn acquire_buffer<'a, P: Into<Option<&'a BufferPoolAcquireParams>>>(
|
||||||
&self,
|
&self,
|
||||||
params: P,
|
params: P,
|
||||||
) -> Result<::Buffer, ::FlowReturn>;
|
) -> Result<::Buffer, ::FlowError>;
|
||||||
fn release_buffer(&self, buffer: ::Buffer);
|
fn release_buffer(&self, buffer: ::Buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,7 +267,7 @@ impl<O: IsA<BufferPool>> BufferPoolExtManual for O {
|
||||||
fn acquire_buffer<'a, P: Into<Option<&'a BufferPoolAcquireParams>>>(
|
fn acquire_buffer<'a, P: Into<Option<&'a BufferPoolAcquireParams>>>(
|
||||||
&self,
|
&self,
|
||||||
params: P,
|
params: P,
|
||||||
) -> Result<::Buffer, ::FlowReturn> {
|
) -> Result<::Buffer, ::FlowError> {
|
||||||
let params = params.into();
|
let params = params.into();
|
||||||
let params_ptr = match params {
|
let params_ptr = match params {
|
||||||
Some(params) => ¶ms.0 as *const _ as *mut _,
|
Some(params) => ¶ms.0 as *const _ as *mut _,
|
||||||
|
@ -276,17 +276,13 @@ impl<O: IsA<BufferPool>> BufferPoolExtManual for O {
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut buffer = ptr::null_mut();
|
let mut buffer = ptr::null_mut();
|
||||||
let ret = from_glib(ffi::gst_buffer_pool_acquire_buffer(
|
let ret: ::FlowReturn = from_glib(ffi::gst_buffer_pool_acquire_buffer(
|
||||||
self.to_glib_none().0,
|
self.to_glib_none().0,
|
||||||
&mut buffer,
|
&mut buffer,
|
||||||
params_ptr,
|
params_ptr,
|
||||||
));
|
));
|
||||||
|
|
||||||
if ret == ::FlowReturn::Ok {
|
ret.into_result_value(|| from_glib_full(buffer))
|
||||||
Ok(from_glib_full(buffer))
|
|
||||||
} else {
|
|
||||||
Err(ret)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,13 @@ impl FlowReturn {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn into_result_value<T, F: FnOnce() -> T>(self, func: F) -> Result<T, FlowError> {
|
||||||
|
match self.into_result() {
|
||||||
|
Ok(_) => Ok(func()),
|
||||||
|
Err(err) => Err(err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn from_error(v: FlowError) -> Self {
|
pub fn from_error(v: FlowError) -> Self {
|
||||||
match v {
|
match v {
|
||||||
FlowError::NotLinked => FlowReturn::NotLinked,
|
FlowError::NotLinked => FlowReturn::NotLinked,
|
||||||
|
|
|
@ -10,6 +10,7 @@ use miniobject::MiniObject;
|
||||||
use Buffer;
|
use Buffer;
|
||||||
use BufferList;
|
use BufferList;
|
||||||
use Event;
|
use Event;
|
||||||
|
use FlowError;
|
||||||
use FlowReturn;
|
use FlowReturn;
|
||||||
use Format;
|
use Format;
|
||||||
use FormattedValue;
|
use FormattedValue;
|
||||||
|
@ -115,8 +116,8 @@ pub trait PadExtManual {
|
||||||
fn chain_list(&self, list: BufferList) -> FlowReturn;
|
fn chain_list(&self, list: BufferList) -> FlowReturn;
|
||||||
fn push_list(&self, list: BufferList) -> FlowReturn;
|
fn push_list(&self, list: BufferList) -> FlowReturn;
|
||||||
|
|
||||||
fn pull_range(&self, offset: u64, size: u32) -> Result<Buffer, FlowReturn>;
|
fn pull_range(&self, offset: u64, size: u32) -> Result<Buffer, FlowError>;
|
||||||
fn get_range(&self, offset: u64, size: u32) -> Result<Buffer, FlowReturn>;
|
fn get_range(&self, offset: u64, size: u32) -> Result<Buffer, FlowError>;
|
||||||
|
|
||||||
fn peer_query(&self, query: &mut QueryRef) -> bool;
|
fn peer_query(&self, query: &mut QueryRef) -> bool;
|
||||||
fn query(&self, query: &mut QueryRef) -> bool;
|
fn query(&self, query: &mut QueryRef) -> bool;
|
||||||
|
@ -170,7 +171,7 @@ pub trait PadExtManual {
|
||||||
|
|
||||||
fn set_getrange_function<F>(&self, func: F)
|
fn set_getrange_function<F>(&self, func: F)
|
||||||
where
|
where
|
||||||
F: Fn(&Pad, &Option<::Object>, u64, u32) -> Result<::Buffer, ::FlowReturn>
|
F: Fn(&Pad, &Option<::Object>, u64, u32) -> Result<::Buffer, ::FlowError>
|
||||||
+ Send
|
+ Send
|
||||||
+ Sync
|
+ Sync
|
||||||
+ 'static;
|
+ 'static;
|
||||||
|
@ -290,37 +291,29 @@ impl<O: IsA<Pad>> PadExtManual for O {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_range(&self, offset: u64, size: u32) -> Result<Buffer, FlowReturn> {
|
fn get_range(&self, offset: u64, size: u32) -> Result<Buffer, FlowError> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut buffer = ptr::null_mut();
|
let mut buffer = ptr::null_mut();
|
||||||
let ret = from_glib(ffi::gst_pad_get_range(
|
let ret: FlowReturn = from_glib(ffi::gst_pad_get_range(
|
||||||
self.to_glib_none().0,
|
self.to_glib_none().0,
|
||||||
offset,
|
offset,
|
||||||
size,
|
size,
|
||||||
&mut buffer,
|
&mut buffer,
|
||||||
));
|
));
|
||||||
if ret == FlowReturn::Ok {
|
ret.into_result_value(|| from_glib_full(buffer))
|
||||||
Ok(from_glib_full(buffer))
|
|
||||||
} else {
|
|
||||||
Err(ret)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pull_range(&self, offset: u64, size: u32) -> Result<Buffer, FlowReturn> {
|
fn pull_range(&self, offset: u64, size: u32) -> Result<Buffer, FlowError> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut buffer = ptr::null_mut();
|
let mut buffer = ptr::null_mut();
|
||||||
let ret = from_glib(ffi::gst_pad_pull_range(
|
let ret: FlowReturn = from_glib(ffi::gst_pad_pull_range(
|
||||||
self.to_glib_none().0,
|
self.to_glib_none().0,
|
||||||
offset,
|
offset,
|
||||||
size,
|
size,
|
||||||
&mut buffer,
|
&mut buffer,
|
||||||
));
|
));
|
||||||
if ret == FlowReturn::Ok {
|
ret.into_result_value(|| from_glib_full(buffer))
|
||||||
Ok(from_glib_full(buffer))
|
|
||||||
} else {
|
|
||||||
Err(ret)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -544,7 +537,7 @@ impl<O: IsA<Pad>> PadExtManual for O {
|
||||||
|
|
||||||
fn set_getrange_function<F>(&self, func: F)
|
fn set_getrange_function<F>(&self, func: F)
|
||||||
where
|
where
|
||||||
F: Fn(&Pad, &Option<::Object>, u64, u32) -> Result<::Buffer, ::FlowReturn>
|
F: Fn(&Pad, &Option<::Object>, u64, u32) -> Result<::Buffer, ::FlowError>
|
||||||
+ Send
|
+ Send
|
||||||
+ Sync
|
+ Sync
|
||||||
+ 'static,
|
+ 'static,
|
||||||
|
@ -552,7 +545,7 @@ impl<O: IsA<Pad>> PadExtManual for O {
|
||||||
unsafe {
|
unsafe {
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
|
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
|
||||||
let func_box: Box<
|
let func_box: Box<
|
||||||
Fn(&Pad, &Option<::Object>, u64, u32) -> Result<::Buffer, ::FlowReturn>
|
Fn(&Pad, &Option<::Object>, u64, u32) -> Result<::Buffer, ::FlowError>
|
||||||
+ Send
|
+ Send
|
||||||
+ Sync
|
+ Sync
|
||||||
+ 'static,
|
+ 'static,
|
||||||
|
@ -1109,7 +1102,7 @@ unsafe extern "C" fn trampoline_getrange_function(
|
||||||
buffer: *mut *mut ffi::GstBuffer,
|
buffer: *mut *mut ffi::GstBuffer,
|
||||||
) -> ffi::GstFlowReturn {
|
) -> ffi::GstFlowReturn {
|
||||||
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
#[cfg_attr(feature = "cargo-clippy", allow(transmute_ptr_to_ref))]
|
||||||
let func: &&(Fn(&Pad, &Option<::Object>, u64, u32) -> Result<::Buffer, ::FlowReturn>
|
let func: &&(Fn(&Pad, &Option<::Object>, u64, u32) -> Result<::Buffer, ::FlowError>
|
||||||
+ Send
|
+ Send
|
||||||
+ Sync
|
+ Sync
|
||||||
+ 'static) = transmute((*pad).getrangedata);
|
+ 'static) = transmute((*pad).getrangedata);
|
||||||
|
@ -1124,7 +1117,7 @@ unsafe extern "C" fn trampoline_getrange_function(
|
||||||
*buffer = new_buffer.into_ptr();
|
*buffer = new_buffer.into_ptr();
|
||||||
::FlowReturn::Ok.to_glib()
|
::FlowReturn::Ok.to_glib()
|
||||||
}
|
}
|
||||||
Err(ret) => ret.to_glib(),
|
Err(ret) => ::FlowReturn::from_error(ret).to_glib(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use Buffer;
|
use Buffer;
|
||||||
use BufferList;
|
use BufferList;
|
||||||
|
use FlowError;
|
||||||
use FlowReturn;
|
use FlowReturn;
|
||||||
use Object;
|
use Object;
|
||||||
use Pad;
|
use Pad;
|
||||||
|
@ -59,22 +60,18 @@ impl ProxyPad {
|
||||||
parent: &Q,
|
parent: &Q,
|
||||||
offset: u64,
|
offset: u64,
|
||||||
size: u32,
|
size: u32,
|
||||||
) -> Result<Buffer, FlowReturn> {
|
) -> Result<Buffer, FlowError> {
|
||||||
skip_assert_initialized!();
|
skip_assert_initialized!();
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut buffer = ptr::null_mut();
|
let mut buffer = ptr::null_mut();
|
||||||
let ret = from_glib(ffi::gst_proxy_pad_getrange_default(
|
let ret: FlowReturn = from_glib(ffi::gst_proxy_pad_getrange_default(
|
||||||
pad.to_glib_none().0 as *mut ffi::GstPad,
|
pad.to_glib_none().0 as *mut ffi::GstPad,
|
||||||
parent.to_glib_none().0,
|
parent.to_glib_none().0,
|
||||||
offset,
|
offset,
|
||||||
size,
|
size,
|
||||||
&mut buffer,
|
&mut buffer,
|
||||||
));
|
));
|
||||||
if ret == FlowReturn::Ok {
|
ret.into_result_value(|| from_glib_full(buffer))
|
||||||
Ok(from_glib_full(buffer))
|
|
||||||
} else {
|
|
||||||
Err(ret)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue