Manual code updates for *Return types

This commit is contained in:
François Laignel 2021-04-28 14:34:56 +02:00 committed by Sebastian Dröge
parent 2364361f6b
commit 5505715cc4
35 changed files with 290 additions and 783 deletions

View file

@ -2,13 +2,8 @@
use crate::AppSink; use crate::AppSink;
use glib::ffi::gpointer; use glib::ffi::gpointer;
use glib::object::ObjectType;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*; use glib::translate::*;
use std::boxed::Box as Box_;
use std::cell::RefCell; use std::cell::RefCell;
use std::mem::transmute;
use std::panic; use std::panic;
use std::ptr; use std::ptr;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
@ -277,72 +272,12 @@ impl AppSink {
} }
} }
pub fn connect_new_sample<
F: Fn(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError> + Send + 'static,
>(
&self,
f: F,
) -> SignalHandlerId {
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"new-sample\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
new_sample_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
pub fn connect_new_preroll<
F: Fn(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError> + Send + 'static,
>(
&self,
f: F,
) -> SignalHandlerId {
unsafe {
let f: Box_<F> = Box_::new(f);
connect_raw(
self.as_ptr() as *mut _,
b"new-preroll\0".as_ptr() as *const _,
Some(transmute::<_, unsafe extern "C" fn()>(
new_preroll_trampoline::<F> as *const (),
)),
Box_::into_raw(f),
)
}
}
#[cfg(any(feature = "v1_10"))] #[cfg(any(feature = "v1_10"))]
pub fn stream(&self) -> AppSinkStream { pub fn stream(&self) -> AppSinkStream {
AppSinkStream::new(self) AppSinkStream::new(self)
} }
} }
unsafe extern "C" fn new_sample_trampoline<
F: Fn(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError> + Send + 'static,
>(
this: *mut ffi::GstAppSink,
f: glib::ffi::gpointer,
) -> gst::ffi::GstFlowReturn {
let f: &F = &*(f as *const F);
let ret: gst::FlowReturn = f(&from_glib_borrow(this)).into();
ret.into_glib()
}
unsafe extern "C" fn new_preroll_trampoline<
F: Fn(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError> + Send + 'static,
>(
this: *mut ffi::GstAppSink,
f: glib::ffi::gpointer,
) -> gst::ffi::GstFlowReturn {
let f: &F = &*(f as *const F);
let ret: gst::FlowReturn = f(&from_glib_borrow(this)).into();
ret.into_glib()
}
#[cfg(any(feature = "v1_10"))] #[cfg(any(feature = "v1_10"))]
#[derive(Debug)] #[derive(Debug)]
pub struct AppSinkStream { pub struct AppSinkStream {

View file

@ -207,20 +207,13 @@ unsafe extern "C" fn destroy_callbacks(ptr: gpointer) {
} }
impl AppSrc { impl AppSrc {
pub fn end_of_stream(&self) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn =
unsafe { from_glib(ffi::gst_app_src_end_of_stream(self.to_glib_none().0)) };
ret.into_result()
}
pub fn push_buffer(&self, buffer: gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError> { pub fn push_buffer(&self, buffer: gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe { unsafe {
from_glib(ffi::gst_app_src_push_buffer( gst::FlowSuccess::try_from_glib(ffi::gst_app_src_push_buffer(
self.to_glib_none().0, self.to_glib_none().0,
buffer.into_ptr(), buffer.into_ptr(),
)) ))
}; }
ret.into_result()
} }
#[cfg(any(feature = "v1_14", feature = "dox"))] #[cfg(any(feature = "v1_14", feature = "dox"))]
@ -229,23 +222,12 @@ impl AppSrc {
&self, &self,
list: gst::BufferList, list: gst::BufferList,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe { unsafe {
from_glib(ffi::gst_app_src_push_buffer_list( gst::FlowSuccess::try_from_glib(ffi::gst_app_src_push_buffer_list(
self.to_glib_none().0, self.to_glib_none().0,
list.into_ptr(), list.into_ptr(),
)) ))
};
ret.into_result()
} }
pub fn push_sample(&self, sample: &gst::Sample) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe {
from_glib(ffi::gst_app_src_push_sample(
self.to_glib_none().0,
sample.to_glib_none().0,
))
};
ret.into_result()
} }
pub fn set_callbacks(&self, callbacks: AppSrcCallbacks) { pub fn set_callbacks(&self, callbacks: AppSrcCallbacks) {

View file

@ -65,14 +65,13 @@ impl<O: IsA<AudioDecoder>> AudioDecoderExtManual for O {
buffer: Option<gst::Buffer>, buffer: Option<gst::Buffer>,
frames: i32, frames: i32,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe { unsafe {
from_glib(ffi::gst_audio_decoder_finish_frame( gst::FlowSuccess::try_from_glib(ffi::gst_audio_decoder_finish_frame(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
buffer.map(|b| b.into_ptr()).unwrap_or(ptr::null_mut()), buffer.map(|b| b.into_ptr()).unwrap_or(ptr::null_mut()),
frames, frames,
)) ))
}; }
ret.into_result()
} }
#[cfg(any(feature = "v1_16", feature = "dox"))] #[cfg(any(feature = "v1_16", feature = "dox"))]
@ -81,13 +80,12 @@ impl<O: IsA<AudioDecoder>> AudioDecoderExtManual for O {
&self, &self,
buffer: Option<gst::Buffer>, buffer: Option<gst::Buffer>,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe { unsafe {
from_glib(ffi::gst_audio_decoder_finish_subframe( gst::FlowSuccess::try_from_glib(ffi::gst_audio_decoder_finish_subframe(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
buffer.map(|b| b.into_ptr()).unwrap_or(ptr::null_mut()), buffer.map(|b| b.into_ptr()).unwrap_or(ptr::null_mut()),
)) ))
}; }
ret.into_result()
} }
fn negotiate(&self) -> Result<(), gst::FlowError> { fn negotiate(&self) -> Result<(), gst::FlowError> {
@ -156,8 +154,8 @@ impl<O: IsA<AudioDecoder>> AudioDecoderExtManual for O {
function: &str, function: &str,
line: u32, line: u32,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe { unsafe {
from_glib(_gst_audio_decoder_error( gst::FlowSuccess::try_from_glib(_gst_audio_decoder_error(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
weight, weight,
T::domain().into_glib(), T::domain().into_glib(),
@ -168,8 +166,7 @@ impl<O: IsA<AudioDecoder>> AudioDecoderExtManual for O {
function.to_glib_none().0, function.to_glib_none().0,
line as i32, line as i32,
)) ))
}; }
ret.into_result()
} }
} }

View file

@ -30,14 +30,13 @@ impl<O: IsA<AudioEncoder>> AudioEncoderExtManual for O {
buffer: Option<gst::Buffer>, buffer: Option<gst::Buffer>,
frames: i32, frames: i32,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe { unsafe {
from_glib(ffi::gst_audio_encoder_finish_frame( gst::FlowSuccess::try_from_glib(ffi::gst_audio_encoder_finish_frame(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
buffer.map(|b| b.into_ptr()).unwrap_or(ptr::null_mut()), buffer.map(|b| b.into_ptr()).unwrap_or(ptr::null_mut()),
frames, frames,
)) ))
}; }
ret.into_result()
} }
fn negotiate(&self) -> Result<(), gst::FlowError> { fn negotiate(&self) -> Result<(), gst::FlowError> {

View file

@ -295,23 +295,19 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
.map(|f| { .map(|f| {
let mut offset = mem::MaybeUninit::uninit(); let mut offset = mem::MaybeUninit::uninit();
let mut len = mem::MaybeUninit::uninit(); let mut len = mem::MaybeUninit::uninit();
match gst::FlowReturn::from_glib(f( gst::FlowSuccess::try_from_glib(f(
element.unsafe_cast_ref::<AudioDecoder>().to_glib_none().0, element.unsafe_cast_ref::<AudioDecoder>().to_glib_none().0,
adapter.to_glib_none().0, adapter.to_glib_none().0,
offset.as_mut_ptr(), offset.as_mut_ptr(),
len.as_mut_ptr(), len.as_mut_ptr(),
)) ))
.into_result() .map(|_| {
{
Ok(_) => {
let offset = offset.assume_init(); let offset = offset.assume_init();
let len = len.assume_init(); let len = len.assume_init();
assert!(offset >= 0); assert!(offset >= 0);
assert!(len >= 0); assert!(len >= 0);
Ok((offset as u32, len as u32)) (offset as u32, len as u32)
} })
Err(err) => Err(err),
}
}) })
.unwrap_or_else(|| Ok((0, adapter.available() as u32))) .unwrap_or_else(|| Ok((0, adapter.available() as u32)))
} }
@ -328,15 +324,14 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
(*parent_class) (*parent_class)
.handle_frame .handle_frame
.map(|f| { .map(|f| {
gst::FlowReturn::from_glib(f( gst::FlowSuccess::try_from_glib(f(
element.unsafe_cast_ref::<AudioDecoder>().to_glib_none().0, element.unsafe_cast_ref::<AudioDecoder>().to_glib_none().0,
buffer buffer
.map(|buffer| buffer.as_mut_ptr() as *mut *mut gst::ffi::GstBuffer) .map(|buffer| buffer.as_mut_ptr() as *mut *mut gst::ffi::GstBuffer)
.unwrap_or(ptr::null_mut()), .unwrap_or(ptr::null_mut()),
)) ))
}) })
.unwrap_or(gst::FlowReturn::Error) .unwrap_or(Err(gst::FlowError::Error))
.into_result()
} }
} }
@ -350,15 +345,11 @@ impl<T: AudioDecoderImpl> AudioDecoderImplExt for T {
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioDecoderClass;
if let Some(f) = (*parent_class).pre_push { if let Some(f) = (*parent_class).pre_push {
let mut buffer = buffer.into_ptr(); let mut buffer = buffer.into_ptr();
match gst::FlowReturn::from_glib(f( gst::FlowSuccess::try_from_glib(f(
element.unsafe_cast_ref::<AudioDecoder>().to_glib_none().0, element.unsafe_cast_ref::<AudioDecoder>().to_glib_none().0,
&mut buffer, &mut buffer,
)) ))
.into_result() .map(|_| from_glib_full(buffer))
{
Ok(_) => Ok(from_glib_full(buffer)),
Err(err) => Err(err),
}
} else { } else {
Ok(Some(buffer)) Ok(Some(buffer))
} }

View file

@ -279,15 +279,14 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
(*parent_class) (*parent_class)
.handle_frame .handle_frame
.map(|f| { .map(|f| {
gst::FlowReturn::from_glib(f( gst::FlowSuccess::try_from_glib(f(
element.unsafe_cast_ref::<AudioEncoder>().to_glib_none().0, element.unsafe_cast_ref::<AudioEncoder>().to_glib_none().0,
buffer buffer
.map(|buffer| buffer.as_mut_ptr() as *mut *mut gst::ffi::GstBuffer) .map(|buffer| buffer.as_mut_ptr() as *mut *mut gst::ffi::GstBuffer)
.unwrap_or(ptr::null_mut()), .unwrap_or(ptr::null_mut()),
)) ))
}) })
.unwrap_or(gst::FlowReturn::Error) .unwrap_or(Err(gst::FlowError::Error))
.into_result()
} }
} }
@ -301,15 +300,11 @@ impl<T: AudioEncoderImpl> AudioEncoderImplExt for T {
let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstAudioEncoderClass;
if let Some(f) = (*parent_class).pre_push { if let Some(f) = (*parent_class).pre_push {
let mut buffer = buffer.into_ptr(); let mut buffer = buffer.into_ptr();
match gst::FlowReturn::from_glib(f( gst::FlowSuccess::try_from_glib(f(
element.unsafe_cast_ref::<AudioEncoder>().to_glib_none().0, element.unsafe_cast_ref::<AudioEncoder>().to_glib_none().0,
&mut buffer, &mut buffer,
)) ))
.into_result() .map(|_| from_glib_full(buffer))
{
Ok(_) => Ok(from_glib_full(buffer)),
Err(err) => Err(err),
}
} else { } else {
Ok(Some(buffer)) Ok(Some(buffer))
} }

View file

@ -99,13 +99,12 @@ impl<O: IsA<Aggregator>> AggregatorExtManual for O {
} }
fn finish_buffer(&self, buffer: gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError> { fn finish_buffer(&self, buffer: gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe { unsafe {
from_glib(ffi::gst_aggregator_finish_buffer( gst::FlowSuccess::try_from_glib(ffi::gst_aggregator_finish_buffer(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
buffer.into_ptr(), buffer.into_ptr(),
)) ))
}; }
ret.into_result()
} }
#[cfg(any(feature = "v1_18", feature = "dox"))] #[cfg(any(feature = "v1_18", feature = "dox"))]
@ -114,13 +113,12 @@ impl<O: IsA<Aggregator>> AggregatorExtManual for O {
&self, &self,
bufferlist: gst::BufferList, bufferlist: gst::BufferList,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe { unsafe {
from_glib(ffi::gst_aggregator_finish_buffer_list( gst::FlowSuccess::try_from_glib(ffi::gst_aggregator_finish_buffer_list(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
bufferlist.into_ptr(), bufferlist.into_ptr(),
)) ))
}; }
ret.into_result()
} }
#[cfg(any(feature = "v1_16", feature = "dox"))] #[cfg(any(feature = "v1_16", feature = "dox"))]

View file

@ -128,12 +128,11 @@ impl<O: IsA<BaseParse>> BaseParseExtManual for O {
size: u32, size: u32,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe { unsafe {
gst::FlowReturn::from_glib(ffi::gst_base_parse_finish_frame( gst::FlowSuccess::try_from_glib(ffi::gst_base_parse_finish_frame(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
frame.to_glib_none().0, frame.to_glib_none().0,
i32::try_from(size).expect("size higher than i32::MAX"), i32::try_from(size).expect("size higher than i32::MAX"),
)) ))
.into_result()
} }
} }
} }

View file

@ -9,20 +9,6 @@ pub trait BaseSinkExtManual: 'static {
#[doc(alias = "get_segment")] #[doc(alias = "get_segment")]
fn segment(&self) -> gst::Segment; fn segment(&self) -> gst::Segment;
fn wait(
&self,
time: gst::ClockTime,
) -> (Result<gst::FlowSuccess, gst::FlowError>, gst::ClockTimeDiff);
fn wait_preroll(&self) -> Result<gst::FlowSuccess, gst::FlowError>;
fn wait_clock(
&self,
time: gst::ClockTime,
) -> (
Result<gst::ClockSuccess, gst::ClockError>,
gst::ClockTimeDiff,
);
fn query_latency( fn query_latency(
&self, &self,
) -> Result<(bool, bool, gst::ClockTime, gst::ClockTime), glib::BoolError>; ) -> Result<(bool, bool, gst::ClockTime, gst::ClockTime), glib::BoolError>;
@ -37,48 +23,6 @@ impl<O: IsA<BaseSink>> BaseSinkExtManual for O {
} }
} }
fn wait(
&self,
time: gst::ClockTime,
) -> (Result<gst::FlowSuccess, gst::FlowError>, gst::ClockTimeDiff) {
unsafe {
let mut jitter = 0;
let ret: gst::FlowReturn = from_glib(ffi::gst_base_sink_wait(
self.as_ref().to_glib_none().0,
time.into_glib(),
&mut jitter,
));
(ret.into_result(), jitter)
}
}
fn wait_preroll(&self) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe {
from_glib(ffi::gst_base_sink_wait_preroll(
self.as_ref().to_glib_none().0,
))
};
ret.into_result()
}
fn wait_clock(
&self,
time: gst::ClockTime,
) -> (
Result<gst::ClockSuccess, gst::ClockError>,
gst::ClockTimeDiff,
) {
unsafe {
let mut jitter = 0;
let ret: gst::ClockReturn = from_glib(ffi::gst_base_sink_wait_clock(
self.as_ref().to_glib_none().0,
time.into_glib(),
&mut jitter,
));
(ret.into_result(), jitter)
}
}
fn query_latency( fn query_latency(
&self, &self,
) -> Result<(bool, bool, gst::ClockTime, gst::ClockTime), glib::BoolError> { ) -> Result<(bool, bool, gst::ClockTime, gst::ClockTime), glib::BoolError> {

View file

@ -14,12 +14,6 @@ pub trait BaseSrcExtManual: 'static {
#[doc(alias = "get_segment")] #[doc(alias = "get_segment")]
fn segment(&self) -> gst::Segment; fn segment(&self) -> gst::Segment;
fn start_complete(&self, ret: Result<gst::FlowSuccess, gst::FlowError>);
fn start_wait(&self) -> Result<gst::FlowSuccess, gst::FlowError>;
fn wait_playing(&self) -> Result<gst::FlowSuccess, gst::FlowError>;
fn query_latency(&self) -> Result<(bool, gst::ClockTime, gst::ClockTime), glib::BoolError>; fn query_latency(&self) -> Result<(bool, gst::ClockTime, gst::ClockTime), glib::BoolError>;
#[cfg(any(feature = "v1_18", feature = "dox"))] #[cfg(any(feature = "v1_18", feature = "dox"))]
@ -49,28 +43,6 @@ impl<O: IsA<BaseSrc>> BaseSrcExtManual for O {
} }
} }
fn start_complete(&self, ret: Result<gst::FlowSuccess, gst::FlowError>) {
let ret: gst::FlowReturn = ret.into();
unsafe {
ffi::gst_base_src_start_complete(self.as_ref().to_glib_none().0, ret.into_glib());
}
}
fn start_wait(&self) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn =
unsafe { from_glib(ffi::gst_base_src_start_wait(self.as_ref().to_glib_none().0)) };
ret.into_result()
}
fn wait_playing(&self) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe {
from_glib(ffi::gst_base_src_wait_playing(
self.as_ref().to_glib_none().0,
))
};
ret.into_result()
}
fn query_latency(&self) -> Result<(bool, gst::ClockTime, gst::ClockTime), glib::BoolError> { fn query_latency(&self) -> Result<(bool, gst::ClockTime, gst::ClockTime), glib::BoolError> {
unsafe { unsafe {
let mut live = mem::MaybeUninit::uninit(); let mut live = mem::MaybeUninit::uninit();

View file

@ -65,13 +65,12 @@ impl FlowCombiner {
fret: FRet, fret: FRet,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
let fret: gst::FlowReturn = fret.into(); let fret: gst::FlowReturn = fret.into();
let ret: gst::FlowReturn = unsafe { unsafe {
from_glib(ffi::gst_flow_combiner_update_flow( gst::FlowSuccess::try_from_glib(ffi::gst_flow_combiner_update_flow(
self.to_glib_none().0, self.to_glib_none().0,
fret.into_glib(), fret.into_glib(),
)) ))
}; }
ret.into_result()
} }
pub fn update_pad_flow<P: IsA<gst::Pad>, FRet: Into<gst::FlowReturn>>( pub fn update_pad_flow<P: IsA<gst::Pad>, FRet: Into<gst::FlowReturn>>(
@ -80,14 +79,13 @@ impl FlowCombiner {
fret: FRet, fret: FRet,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
let fret: gst::FlowReturn = fret.into(); let fret: gst::FlowReturn = fret.into();
let ret: gst::FlowReturn = unsafe { unsafe {
from_glib(ffi::gst_flow_combiner_update_pad_flow( gst::FlowSuccess::try_from_glib(ffi::gst_flow_combiner_update_pad_flow(
self.to_glib_none().0, self.to_glib_none().0,
pad.as_ref().to_glib_none().0, pad.as_ref().to_glib_none().0,
fret.into_glib(), fret.into_glib(),
)) ))
}; }
ret.into_result()
} }
} }

View file

@ -288,13 +288,12 @@ impl<T: AggregatorImpl> AggregatorImplExt for T {
(*parent_class) (*parent_class)
.flush .flush
.map(|f| { .map(|f| {
from_glib(f(aggregator gst::FlowSuccess::try_from_glib(f(aggregator
.unsafe_cast_ref::<Aggregator>() .unsafe_cast_ref::<Aggregator>()
.to_glib_none() .to_glib_none()
.0)) .0))
}) })
.unwrap_or(gst::FlowReturn::Ok) .unwrap_or(Ok(gst::FlowSuccess::Ok))
.into_result()
} }
} }
@ -329,11 +328,10 @@ impl<T: AggregatorImpl> AggregatorImplExt for T {
let f = (*parent_class) let f = (*parent_class)
.finish_buffer .finish_buffer
.expect("Missing parent function `finish_buffer`"); .expect("Missing parent function `finish_buffer`");
gst::FlowReturn::from_glib(f( gst::FlowSuccess::try_from_glib(f(
aggregator.unsafe_cast_ref::<Aggregator>().to_glib_none().0, aggregator.unsafe_cast_ref::<Aggregator>().to_glib_none().0,
buffer.into_ptr(), buffer.into_ptr(),
)) ))
.into_result()
} }
} }
@ -350,11 +348,10 @@ impl<T: AggregatorImpl> AggregatorImplExt for T {
let f = (*parent_class) let f = (*parent_class)
.finish_buffer_list .finish_buffer_list
.expect("Missing parent function `finish_buffer_list`"); .expect("Missing parent function `finish_buffer_list`");
gst::FlowReturn::from_glib(f( gst::FlowSuccess::try_from_glib(f(
aggregator.unsafe_cast_ref::<Aggregator>().to_glib_none().0, aggregator.unsafe_cast_ref::<Aggregator>().to_glib_none().0,
buffer_list.into_ptr(), buffer_list.into_ptr(),
)) ))
.into_result()
} }
} }
@ -392,12 +389,11 @@ impl<T: AggregatorImpl> AggregatorImplExt for T {
let f = (*parent_class) let f = (*parent_class)
.sink_event_pre_queue .sink_event_pre_queue
.expect("Missing parent function `sink_event_pre_queue`"); .expect("Missing parent function `sink_event_pre_queue`");
gst::FlowReturn::from_glib(f( gst::FlowSuccess::try_from_glib(f(
aggregator.unsafe_cast_ref::<Aggregator>().to_glib_none().0, aggregator.unsafe_cast_ref::<Aggregator>().to_glib_none().0,
aggregator_pad.to_glib_none().0, aggregator_pad.to_glib_none().0,
event.into_ptr(), event.into_ptr(),
)) ))
.into_result()
} }
} }
@ -506,11 +502,10 @@ impl<T: AggregatorImpl> AggregatorImplExt for T {
let f = (*parent_class) let f = (*parent_class)
.aggregate .aggregate
.expect("Missing parent function `aggregate`"); .expect("Missing parent function `aggregate`");
gst::FlowReturn::from_glib(f( gst::FlowSuccess::try_from_glib(f(
aggregator.unsafe_cast_ref::<Aggregator>().to_glib_none().0, aggregator.unsafe_cast_ref::<Aggregator>().to_glib_none().0,
timeout.into_glib(), timeout.into_glib(),
)) ))
.into_result()
} }
} }
@ -613,12 +608,12 @@ impl<T: AggregatorImpl> AggregatorImplExt for T {
.expect("Missing parent function `update_src_caps`"); .expect("Missing parent function `update_src_caps`");
let mut out_caps = ptr::null_mut(); let mut out_caps = ptr::null_mut();
gst::FlowReturn::from_glib(f( gst::FlowSuccess::try_from_glib(f(
aggregator.unsafe_cast_ref::<Aggregator>().to_glib_none().0, aggregator.unsafe_cast_ref::<Aggregator>().to_glib_none().0,
caps.as_mut_ptr(), caps.as_mut_ptr(),
&mut out_caps, &mut out_caps,
)) ))
.into_result_value(|| from_glib_full(out_caps)) .map(|_| from_glib_full(out_caps))
} }
} }

View file

@ -54,7 +54,7 @@ impl<T: AggregatorPadImpl> AggregatorPadImplExt for T {
(*parent_class) (*parent_class)
.flush .flush
.map(|f| { .map(|f| {
from_glib(f( gst::FlowSuccess::try_from_glib(f(
aggregator_pad aggregator_pad
.unsafe_cast_ref::<AggregatorPad>() .unsafe_cast_ref::<AggregatorPad>()
.to_glib_none() .to_glib_none()
@ -62,8 +62,7 @@ impl<T: AggregatorPadImpl> AggregatorPadImplExt for T {
aggregator.to_glib_none().0, aggregator.to_glib_none().0,
)) ))
}) })
.unwrap_or(gst::FlowReturn::Ok) .unwrap_or(Ok(gst::FlowSuccess::Ok))
.into_result()
} }
} }

View file

@ -149,22 +149,17 @@ impl<T: BaseParseImpl> BaseParseImplExt for T {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseParseClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstBaseParseClass;
let mut skipsize = 0; let mut skipsize = 0;
let res = (*parent_class).handle_frame.map(|f| { (*parent_class)
let res = gst::FlowReturn::from_glib(f( .handle_frame
.map(|f| {
let res = gst::FlowSuccess::try_from_glib(f(
element.unsafe_cast_ref::<BaseParse>().to_glib_none().0, element.unsafe_cast_ref::<BaseParse>().to_glib_none().0,
frame.to_glib_none().0, frame.to_glib_none().0,
&mut skipsize, &mut skipsize,
)); ));
(res, skipsize as u32) (res.unwrap(), skipsize as u32)
}); })
.ok_or(gst::FlowError::Error)
match res {
Some((res, skipsize)) => {
let res = res.into_result();
Ok((res.unwrap(), skipsize))
}
None => Err(gst::FlowError::Error),
}
} }
} }

View file

@ -179,13 +179,12 @@ impl<T: BaseSinkImpl> BaseSinkImplExt for T {
(*parent_class) (*parent_class)
.render .render
.map(|f| { .map(|f| {
gst::FlowReturn::from_glib(f( gst::FlowSuccess::try_from_glib(f(
element.unsafe_cast_ref::<BaseSink>().to_glib_none().0, element.unsafe_cast_ref::<BaseSink>().to_glib_none().0,
buffer.to_glib_none().0, buffer.to_glib_none().0,
)) ))
}) })
.unwrap_or(gst::FlowReturn::Ok) .unwrap_or(Ok(gst::FlowSuccess::Ok))
.into_result()
} }
} }
@ -200,13 +199,12 @@ impl<T: BaseSinkImpl> BaseSinkImplExt for T {
(*parent_class) (*parent_class)
.prepare .prepare
.map(|f| { .map(|f| {
from_glib(f( gst::FlowSuccess::try_from_glib(f(
element.unsafe_cast_ref::<BaseSink>().to_glib_none().0, element.unsafe_cast_ref::<BaseSink>().to_glib_none().0,
buffer.to_glib_none().0, buffer.to_glib_none().0,
)) ))
}) })
.unwrap_or(gst::FlowReturn::Ok) .unwrap_or(Ok(gst::FlowSuccess::Ok))
.into_result()
} }
} }
@ -221,11 +219,10 @@ impl<T: BaseSinkImpl> BaseSinkImplExt for T {
(*parent_class) (*parent_class)
.render_list .render_list
.map(|f| { .map(|f| {
gst::FlowReturn::from_glib(f( gst::FlowSuccess::try_from_glib(f(
element.unsafe_cast_ref::<BaseSink>().to_glib_none().0, element.unsafe_cast_ref::<BaseSink>().to_glib_none().0,
list.to_glib_none().0, list.to_glib_none().0,
)) ))
.into_result()
}) })
.unwrap_or_else(|| { .unwrap_or_else(|| {
for buffer in list.iter() { for buffer in list.iter() {
@ -247,11 +244,10 @@ impl<T: BaseSinkImpl> BaseSinkImplExt for T {
(*parent_class) (*parent_class)
.prepare_list .prepare_list
.map(|f| { .map(|f| {
gst::FlowReturn::from_glib(f( gst::FlowSuccess::try_from_glib(f(
element.unsafe_cast_ref::<BaseSink>().to_glib_none().0, element.unsafe_cast_ref::<BaseSink>().to_glib_none().0,
list.to_glib_none().0, list.to_glib_none().0,
)) ))
.into_result()
}) })
.unwrap_or_else(|| { .unwrap_or_else(|| {
for buffer in list.iter() { for buffer in list.iter() {

View file

@ -284,15 +284,14 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
(*parent_class) (*parent_class)
.fill .fill
.map(|f| { .map(|f| {
gst::FlowReturn::from_glib(f( gst::FlowSuccess::try_from_glib(f(
element.unsafe_cast_ref::<BaseSrc>().to_glib_none().0, element.unsafe_cast_ref::<BaseSrc>().to_glib_none().0,
offset, offset,
length, length,
buffer.as_mut_ptr(), buffer.as_mut_ptr(),
)) ))
}) })
.unwrap_or(gst::FlowReturn::NotSupported) .unwrap_or(Err(gst::FlowError::NotSupported))
.into_result()
} }
} }
@ -314,13 +313,13 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
// https://gitlab.freedesktop.org/gstreamer/gstreamer-rs-sys/issues/3 // https://gitlab.freedesktop.org/gstreamer/gstreamer-rs-sys/issues/3
let buffer_ref = &mut buffer_ptr as *mut _ as *mut gst::ffi::GstBuffer; let buffer_ref = &mut buffer_ptr as *mut _ as *mut gst::ffi::GstBuffer;
let res = gst::FlowReturn::from_glib(f( gst::FlowSuccess::try_from_glib(f(
element.unsafe_cast_ref::<BaseSrc>().to_glib_none().0, element.unsafe_cast_ref::<BaseSrc>().to_glib_none().0,
offset, offset,
length, length,
buffer_ref, buffer_ref,
)); ))
res.into_result_value(|| from_glib_full(buffer_ptr)) .map(|_| from_glib_full(buffer_ptr))
}) })
.unwrap_or(Err(gst::FlowError::NotSupported)) .unwrap_or(Err(gst::FlowError::NotSupported))
} }
@ -349,14 +348,14 @@ impl<T: BaseSrcImpl> BaseSrcImplExt for T {
// https://gitlab.freedesktop.org/gstreamer/gstreamer-rs-sys/issues/3 // https://gitlab.freedesktop.org/gstreamer/gstreamer-rs-sys/issues/3
let buffer_ref = &mut buffer_ptr as *mut _ as *mut gst::ffi::GstBuffer; let buffer_ref = &mut buffer_ptr as *mut _ as *mut gst::ffi::GstBuffer;
gst::FlowReturn::from_glib( gst::FlowSuccess::try_from_glib(
f( f(
element.unsafe_cast_ref::<BaseSrc>().to_glib_none().0, element.unsafe_cast_ref::<BaseSrc>().to_glib_none().0,
offset, offset,
length, length,
buffer_ref, buffer_ref,
) )
).into_result()?; )?;
if let Some(passed_buffer) = buffer { if let Some(passed_buffer) = buffer {
if buffer_ptr != orig_buffer_ptr { if buffer_ptr != orig_buffer_ptr {

View file

@ -572,23 +572,19 @@ impl<T: BaseTransformImpl> BaseTransformImplExt for T {
.map(|f| { .map(|f| {
let mut outbuf: *mut gst::ffi::GstBuffer = ptr::null_mut(); let mut outbuf: *mut gst::ffi::GstBuffer = ptr::null_mut();
// FIXME: Wrong signature in FFI // FIXME: Wrong signature in FFI
let res = from_glib(f( gst::FlowSuccess::try_from_glib(f(
element.unsafe_cast_ref::<BaseTransform>().to_glib_none().0, element.unsafe_cast_ref::<BaseTransform>().to_glib_none().0,
inbuf.as_ptr() as *mut gst::ffi::GstBuffer, inbuf.as_ptr() as *mut gst::ffi::GstBuffer,
(&mut outbuf) as *mut *mut gst::ffi::GstBuffer as *mut gst::ffi::GstBuffer, (&mut outbuf) as *mut *mut gst::ffi::GstBuffer as *mut gst::ffi::GstBuffer,
)); ))
.map(|_| {
match gst::FlowReturn::into_result(res) {
Err(err) => Err(err),
Ok(_) => {
if outbuf == inbuf.as_ptr() as *mut _ { if outbuf == inbuf.as_ptr() as *mut _ {
Ok(PrepareOutputBufferSuccess::InputBuffer) PrepareOutputBufferSuccess::InputBuffer
} else { } else {
Ok(PrepareOutputBufferSuccess::Buffer(from_glib_full(outbuf))) PrepareOutputBufferSuccess::Buffer(from_glib_full(outbuf))
}
}
} }
}) })
})
.unwrap_or(Err(gst::FlowError::NotSupported)) .unwrap_or(Err(gst::FlowError::NotSupported))
} }
} }
@ -605,7 +601,7 @@ impl<T: BaseTransformImpl> BaseTransformImplExt for T {
(*parent_class) (*parent_class)
.transform .transform
.map(|f| { .map(|f| {
from_glib(f( gst::FlowSuccess::try_from_glib(f(
element.unsafe_cast_ref::<BaseTransform>().to_glib_none().0, element.unsafe_cast_ref::<BaseTransform>().to_glib_none().0,
inbuf.to_glib_none().0, inbuf.to_glib_none().0,
outbuf.as_mut_ptr(), outbuf.as_mut_ptr(),
@ -613,7 +609,7 @@ impl<T: BaseTransformImpl> BaseTransformImplExt for T {
}) })
.unwrap_or_else(|| { .unwrap_or_else(|| {
if !element.unsafe_cast_ref::<BaseTransform>().is_in_place() { if !element.unsafe_cast_ref::<BaseTransform>().is_in_place() {
gst::FlowReturn::NotSupported Err(gst::FlowError::NotSupported)
} else { } else {
unreachable!(concat!( unreachable!(concat!(
"parent `transform` called ", "parent `transform` called ",
@ -621,7 +617,6 @@ impl<T: BaseTransformImpl> BaseTransformImplExt for T {
)); ));
} }
}) })
.into_result()
} }
} }
@ -647,11 +642,10 @@ impl<T: BaseTransformImpl> BaseTransformImplExt for T {
} }
}); });
gst::FlowReturn::from_glib(f( gst::FlowSuccess::try_from_glib(f(
element.unsafe_cast_ref::<BaseTransform>().to_glib_none().0, element.unsafe_cast_ref::<BaseTransform>().to_glib_none().0,
buf.as_mut_ptr() as *mut _, buf.as_mut_ptr() as *mut _,
)) ))
.into_result()
} }
} }
@ -679,11 +673,10 @@ impl<T: BaseTransformImpl> BaseTransformImplExt for T {
// FIXME: Wrong signature in FFI // FIXME: Wrong signature in FFI
let buf: *mut gst::ffi::GstBuffer = buf.to_glib_none().0; let buf: *mut gst::ffi::GstBuffer = buf.to_glib_none().0;
gst::FlowReturn::from_glib(f( gst::FlowSuccess::try_from_glib(f(
element.unsafe_cast_ref::<BaseTransform>().to_glib_none().0, element.unsafe_cast_ref::<BaseTransform>().to_glib_none().0,
buf as *mut _, buf as *mut _,
)) ))
.into_result()
} }
} }
@ -762,12 +755,11 @@ impl<T: BaseTransformImpl> BaseTransformImplExt for T {
.submit_input_buffer .submit_input_buffer
.expect("Missing parent function `submit_input_buffer`"); .expect("Missing parent function `submit_input_buffer`");
gst::FlowReturn::from_glib(f( gst::FlowSuccess::try_from_glib(f(
element.unsafe_cast_ref::<BaseTransform>().to_glib_none().0, element.unsafe_cast_ref::<BaseTransform>().to_glib_none().0,
is_discont.into_glib(), is_discont.into_glib(),
inbuf.into_ptr(), inbuf.into_ptr(),
)) ))
.into_result()
} }
} }
@ -783,11 +775,10 @@ impl<T: BaseTransformImpl> BaseTransformImplExt for T {
.expect("Missing parent function `generate_output`"); .expect("Missing parent function `generate_output`");
let mut outbuf = ptr::null_mut(); let mut outbuf = ptr::null_mut();
gst::FlowReturn::from_glib(f( gst::FlowSuccess::try_from_glib(f(
element.unsafe_cast_ref::<BaseTransform>().to_glib_none().0, element.unsafe_cast_ref::<BaseTransform>().to_glib_none().0,
&mut outbuf, &mut outbuf,
)) ))
.into_result()
.map(|res| { .map(|res| {
if res == crate::BASE_TRANSFORM_FLOW_DROPPED { if res == crate::BASE_TRANSFORM_FLOW_DROPPED {
GenerateOutputSuccess::Dropped GenerateOutputSuccess::Dropped

View file

@ -51,13 +51,12 @@ impl<T: PushSrcImpl> PushSrcImplExt for T {
(*parent_class) (*parent_class)
.fill .fill
.map(|f| { .map(|f| {
gst::FlowReturn::from_glib(f( gst::FlowSuccess::try_from_glib(f(
element.unsafe_cast_ref::<PushSrc>().to_glib_none().0, element.unsafe_cast_ref::<PushSrc>().to_glib_none().0,
buffer.as_mut_ptr(), buffer.as_mut_ptr(),
)) ))
}) })
.unwrap_or(gst::FlowReturn::NotSupported) .unwrap_or(Err(gst::FlowError::NotSupported))
.into_result()
} }
} }
@ -74,11 +73,11 @@ impl<T: PushSrcImpl> PushSrcImplExt for T {
// https://gitlab.freedesktop.org/gstreamer/gstreamer-rs-sys/issues/3 // https://gitlab.freedesktop.org/gstreamer/gstreamer-rs-sys/issues/3
let buffer_ref = &mut buffer_ptr as *mut _ as *mut gst::ffi::GstBuffer; let buffer_ref = &mut buffer_ptr as *mut _ as *mut gst::ffi::GstBuffer;
let res = gst::FlowReturn::from_glib(f( gst::FlowSuccess::try_from_glib(f(
element.unsafe_cast_ref::<PushSrc>().to_glib_none().0, element.unsafe_cast_ref::<PushSrc>().to_glib_none().0,
buffer_ref, buffer_ref,
)); ))
res.into_result_value(|| from_glib_full(buffer_ref)) .map(|_| from_glib_full(buffer_ref))
}) })
.unwrap_or(Err(gst::FlowError::NotSupported)) .unwrap_or(Err(gst::FlowError::NotSupported))
} }
@ -97,11 +96,11 @@ impl<T: PushSrcImpl> PushSrcImplExt for T {
// https://gitlab.freedesktop.org/gstreamer/gstreamer-rs-sys/issues/3 // https://gitlab.freedesktop.org/gstreamer/gstreamer-rs-sys/issues/3
let buffer_ref = &mut buffer_ptr as *mut _ as *mut gst::ffi::GstBuffer; let buffer_ref = &mut buffer_ptr as *mut _ as *mut gst::ffi::GstBuffer;
let res = gst::FlowReturn::from_glib(f( gst::FlowSuccess::try_from_glib(f(
element.unsafe_cast_ref::<PushSrc>().to_glib_none().0, element.unsafe_cast_ref::<PushSrc>().to_glib_none().0,
buffer_ref, buffer_ref,
)); ))
res.into_result_value(|| from_glib_full(buffer_ref)) .map(|_| from_glib_full(buffer_ref))
}) })
.unwrap_or(Err(gst::FlowError::NotSupported)) .unwrap_or(Err(gst::FlowError::NotSupported))
} }

View file

@ -272,9 +272,12 @@ impl Harness {
} }
pub fn push(&mut self, buffer: gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError> { pub fn push(&mut self, buffer: gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe {
unsafe { from_glib(ffi::gst_harness_push(self.0.as_ptr(), buffer.into_ptr())) }; gst::FlowSuccess::try_from_glib(ffi::gst_harness_push(
ret.into_result() self.0.as_ptr(),
buffer.into_ptr(),
))
}
} }
pub fn push_and_pull(&mut self, buffer: gst::Buffer) -> Result<gst::Buffer, glib::BoolError> { pub fn push_and_pull(&mut self, buffer: gst::Buffer) -> Result<gst::Buffer, glib::BoolError> {
@ -297,15 +300,11 @@ impl Harness {
} }
pub fn push_from_src(&mut self) -> Result<gst::FlowSuccess, gst::FlowError> { pub fn push_from_src(&mut self) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe { gst::FlowSuccess::try_from_glib(ffi::gst_harness_push_from_src(self.0.as_ptr())) }
unsafe { from_glib(ffi::gst_harness_push_from_src(self.0.as_ptr())) };
ret.into_result()
} }
pub fn push_to_sink(&mut self) -> Result<gst::FlowSuccess, gst::FlowError> { pub fn push_to_sink(&mut self) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe { gst::FlowSuccess::try_from_glib(ffi::gst_harness_push_to_sink(self.0.as_ptr())) }
unsafe { from_glib(ffi::gst_harness_push_to_sink(self.0.as_ptr())) };
ret.into_result()
} }
pub fn push_upstream_event(&mut self, event: gst::Event) -> bool { pub fn push_upstream_event(&mut self, event: gst::Event) -> bool {
@ -403,13 +402,12 @@ impl Harness {
} }
pub fn sink_push_many(&mut self, pushes: u32) -> Result<gst::FlowSuccess, gst::FlowError> { pub fn sink_push_many(&mut self, pushes: u32) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe { unsafe {
from_glib(ffi::gst_harness_sink_push_many( gst::FlowSuccess::try_from_glib(ffi::gst_harness_sink_push_many(
self.0.as_ptr(), self.0.as_ptr(),
pushes as i32, pushes as i32,
)) ))
}; }
ret.into_result()
} }
pub fn src_crank_and_push_many( pub fn src_crank_and_push_many(
@ -417,14 +415,13 @@ impl Harness {
cranks: u32, cranks: u32,
pushes: u32, pushes: u32,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe { unsafe {
from_glib(ffi::gst_harness_src_crank_and_push_many( gst::FlowSuccess::try_from_glib(ffi::gst_harness_src_crank_and_push_many(
self.0.as_ptr(), self.0.as_ptr(),
cranks as i32, cranks as i32,
pushes as i32, pushes as i32,
)) ))
}; }
ret.into_result()
} }
pub fn src_push_event(&mut self) -> bool { pub fn src_push_event(&mut self) -> bool {

View file

@ -39,8 +39,6 @@ mod rtsp_media;
mod rtsp_media_factory; mod rtsp_media_factory;
mod rtsp_server; mod rtsp_server;
mod rtsp_session_pool; mod rtsp_session_pool;
mod rtsp_stream;
mod rtsp_stream_transport;
mod rtsp_thread; mod rtsp_thread;
mod rtsp_token; mod rtsp_token;
@ -129,6 +127,4 @@ pub mod prelude {
pub use crate::rtsp_media_factory::RTSPMediaFactoryExtManual; pub use crate::rtsp_media_factory::RTSPMediaFactoryExtManual;
pub use crate::rtsp_server::RTSPServerExtManual; pub use crate::rtsp_server::RTSPServerExtManual;
pub use crate::rtsp_session_pool::RTSPSessionPoolExtManual; pub use crate::rtsp_session_pool::RTSPSessionPoolExtManual;
pub use crate::rtsp_stream::RTSPStreamExtManual;
pub use crate::rtsp_stream_transport::RTSPStreamTransportExtManual;
} }

View file

@ -1,33 +0,0 @@
// Take a look at the license at the top of the repository in the LICENSE file.
use crate::RTSPStream;
use glib::prelude::*;
use glib::translate::*;
pub trait RTSPStreamExtManual: 'static {
fn recv_rtcp(&self, buffer: &gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError>;
fn recv_rtp(&self, buffer: &gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError>;
}
impl<O: IsA<RTSPStream>> RTSPStreamExtManual for O {
fn recv_rtcp(&self, buffer: &gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe {
from_glib(ffi::gst_rtsp_stream_recv_rtcp(
self.as_ref().to_glib_none().0,
buffer.to_glib_full(),
))
};
ret.into_result()
}
fn recv_rtp(&self, buffer: &gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe {
from_glib(ffi::gst_rtsp_stream_recv_rtp(
self.as_ref().to_glib_none().0,
buffer.to_glib_full(),
))
};
ret.into_result()
}
}

View file

@ -1,30 +0,0 @@
// Take a look at the license at the top of the repository in the LICENSE file.
use crate::RTSPStreamTransport;
use glib::prelude::*;
use glib::translate::*;
pub trait RTSPStreamTransportExtManual: 'static {
fn recv_data(
&self,
channel: u32,
buffer: &gst::Buffer,
) -> Result<gst::FlowSuccess, gst::FlowError>;
}
impl<O: IsA<RTSPStreamTransport>> RTSPStreamTransportExtManual for O {
fn recv_data(
&self,
channel: u32,
buffer: &gst::Buffer,
) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe {
from_glib(ffi::gst_rtsp_stream_transport_recv_data(
self.as_ref().to_glib_none().0,
channel,
buffer.to_glib_full(),
))
};
ret.into_result()
}
}

View file

@ -269,13 +269,12 @@ impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
(*parent_class) (*parent_class)
.finish .finish
.map(|f| { .map(|f| {
gst::FlowReturn::from_glib(f(element gst::FlowSuccess::try_from_glib(f(element
.unsafe_cast_ref::<VideoDecoder>() .unsafe_cast_ref::<VideoDecoder>()
.to_glib_none() .to_glib_none()
.0)) .0))
}) })
.unwrap_or(gst::FlowReturn::Ok) .unwrap_or(Ok(gst::FlowSuccess::Ok))
.into_result()
} }
} }
@ -286,13 +285,12 @@ impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
(*parent_class) (*parent_class)
.drain .drain
.map(|f| { .map(|f| {
gst::FlowReturn::from_glib(f(element gst::FlowSuccess::try_from_glib(f(element
.unsafe_cast_ref::<VideoDecoder>() .unsafe_cast_ref::<VideoDecoder>()
.to_glib_none() .to_glib_none()
.0)) .0))
}) })
.unwrap_or(gst::FlowReturn::Ok) .unwrap_or(Ok(gst::FlowSuccess::Ok))
.into_result()
} }
} }
@ -333,15 +331,14 @@ impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
(*parent_class) (*parent_class)
.parse .parse
.map(|f| { .map(|f| {
gst::FlowReturn::from_glib(f( gst::FlowSuccess::try_from_glib(f(
element.unsafe_cast_ref::<VideoDecoder>().to_glib_none().0, element.unsafe_cast_ref::<VideoDecoder>().to_glib_none().0,
frame.to_glib_none().0, frame.to_glib_none().0,
adapter.to_glib_none().0, adapter.to_glib_none().0,
at_eos.into_glib(), at_eos.into_glib(),
)) ))
}) })
.unwrap_or(gst::FlowReturn::Ok) .unwrap_or(Ok(gst::FlowSuccess::Ok))
.into_result()
} }
} }
@ -356,13 +353,12 @@ impl<T: VideoDecoderImpl> VideoDecoderImplExt for T {
(*parent_class) (*parent_class)
.handle_frame .handle_frame
.map(|f| { .map(|f| {
gst::FlowReturn::from_glib(f( gst::FlowSuccess::try_from_glib(f(
element.unsafe_cast_ref::<VideoDecoder>().to_glib_none().0, element.unsafe_cast_ref::<VideoDecoder>().to_glib_none().0,
frame.to_glib_none().0, frame.to_glib_none().0,
)) ))
}) })
.unwrap_or(gst::FlowReturn::Error) .unwrap_or(Err(gst::FlowError::Error))
.into_result()
} }
} }

View file

@ -245,13 +245,12 @@ impl<T: VideoEncoderImpl> VideoEncoderImplExt for T {
(*parent_class) (*parent_class)
.finish .finish
.map(|f| { .map(|f| {
gst::FlowReturn::from_glib(f(element gst::FlowSuccess::try_from_glib(f(element
.unsafe_cast_ref::<VideoEncoder>() .unsafe_cast_ref::<VideoEncoder>()
.to_glib_none() .to_glib_none()
.0)) .0))
}) })
.unwrap_or(gst::FlowReturn::Ok) .unwrap_or(Ok(gst::FlowSuccess::Ok))
.into_result()
} }
} }
@ -290,13 +289,12 @@ impl<T: VideoEncoderImpl> VideoEncoderImplExt for T {
(*parent_class) (*parent_class)
.handle_frame .handle_frame
.map(|f| { .map(|f| {
gst::FlowReturn::from_glib(f( gst::FlowSuccess::try_from_glib(f(
element.unsafe_cast_ref::<VideoEncoder>().to_glib_none().0, element.unsafe_cast_ref::<VideoEncoder>().to_glib_none().0,
frame.to_glib_none().0, frame.to_glib_none().0,
)) ))
}) })
.unwrap_or(gst::FlowReturn::Error) .unwrap_or(Err(gst::FlowError::Error))
.into_result()
} }
} }

View file

@ -37,13 +37,12 @@ impl<T: VideoSinkImpl> VideoSinkImplExt for T {
(*parent_class) (*parent_class)
.show_frame .show_frame
.map(|f| { .map(|f| {
gst::FlowReturn::from_glib(f( gst::FlowSuccess::try_from_glib(f(
element.unsafe_cast_ref::<VideoSink>().to_glib_none().0, element.unsafe_cast_ref::<VideoSink>().to_glib_none().0,
buffer.to_glib_none().0, buffer.to_glib_none().0,
)) ))
}) })
.unwrap_or(gst::FlowReturn::Error) .unwrap_or(Err(gst::FlowError::Error))
.into_result()
} }
} }
} }

View file

@ -46,7 +46,6 @@ pub trait VideoDecoderExtManual: 'static {
#[doc(alias = "get_allocator")] #[doc(alias = "get_allocator")]
fn allocator(&self) -> (Option<gst::Allocator>, gst::AllocationParams); fn allocator(&self) -> (Option<gst::Allocator>, gst::AllocationParams);
fn have_frame(&self) -> Result<gst::FlowSuccess, gst::FlowError>;
fn finish_frame(&self, frame: VideoCodecFrame) -> Result<gst::FlowSuccess, gst::FlowError>; fn finish_frame(&self, frame: VideoCodecFrame) -> Result<gst::FlowSuccess, gst::FlowError>;
fn release_frame(&self, frame: VideoCodecFrame); fn release_frame(&self, frame: VideoCodecFrame);
fn drop_frame(&self, frame: VideoCodecFrame) -> Result<gst::FlowSuccess, gst::FlowError>; fn drop_frame(&self, frame: VideoCodecFrame) -> Result<gst::FlowSuccess, gst::FlowError>;
@ -101,15 +100,16 @@ impl<O: IsA<VideoDecoder>> VideoDecoderExtManual for O {
frame: &mut VideoCodecFrame, frame: &mut VideoCodecFrame,
params: Option<&gst::BufferPoolAcquireParams>, params: Option<&gst::BufferPoolAcquireParams>,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe { unsafe {
let params_ptr = params.to_glib_none().0 as *mut _; let params_ptr = params.to_glib_none().0 as *mut _;
from_glib(ffi::gst_video_decoder_allocate_output_frame_with_params( gst::FlowSuccess::try_from_glib(
ffi::gst_video_decoder_allocate_output_frame_with_params(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
frame.to_glib_none().0, frame.to_glib_none().0,
params_ptr, params_ptr,
)) ),
}; )
ret.into_result() }
} }
fn allocator(&self) -> (Option<gst::Allocator>, gst::AllocationParams) { fn allocator(&self) -> (Option<gst::Allocator>, gst::AllocationParams) {
@ -125,23 +125,13 @@ impl<O: IsA<VideoDecoder>> VideoDecoderExtManual for O {
} }
} }
fn have_frame(&self) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe {
from_glib(ffi::gst_video_decoder_have_frame(
self.as_ref().to_glib_none().0,
))
};
ret.into_result()
}
fn finish_frame(&self, frame: VideoCodecFrame) -> Result<gst::FlowSuccess, gst::FlowError> { fn finish_frame(&self, frame: VideoCodecFrame) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe { unsafe {
from_glib(ffi::gst_video_decoder_finish_frame( gst::FlowSuccess::try_from_glib(ffi::gst_video_decoder_finish_frame(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
frame.into_ptr(), frame.into_ptr(),
)) ))
}; }
ret.into_result()
} }
fn release_frame(&self, frame: VideoCodecFrame) { fn release_frame(&self, frame: VideoCodecFrame) {
@ -151,13 +141,12 @@ impl<O: IsA<VideoDecoder>> VideoDecoderExtManual for O {
} }
fn drop_frame(&self, frame: VideoCodecFrame) -> Result<gst::FlowSuccess, gst::FlowError> { fn drop_frame(&self, frame: VideoCodecFrame) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe { unsafe {
from_glib(ffi::gst_video_decoder_drop_frame( gst::FlowSuccess::try_from_glib(ffi::gst_video_decoder_drop_frame(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
frame.into_ptr(), frame.into_ptr(),
)) ))
}; }
ret.into_result()
} }
fn latency(&self) -> (gst::ClockTime, gst::ClockTime) { fn latency(&self) -> (gst::ClockTime, gst::ClockTime) {
@ -327,8 +316,8 @@ impl<O: IsA<VideoDecoder>> VideoDecoderExtManual for O {
function: &str, function: &str,
line: u32, line: u32,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe { unsafe {
from_glib(_gst_video_decoder_error( gst::FlowSuccess::try_from_glib(_gst_video_decoder_error(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
weight, weight,
T::domain().into_glib(), T::domain().into_glib(),
@ -339,8 +328,7 @@ impl<O: IsA<VideoDecoder>> VideoDecoderExtManual for O {
function.to_glib_none().0, function.to_glib_none().0,
line as i32, line as i32,
)) ))
}; }
ret.into_result()
} }
} }

View file

@ -63,14 +63,13 @@ impl<O: IsA<VideoEncoder>> VideoEncoderExtManual for O {
frame: &mut VideoCodecFrame, frame: &mut VideoCodecFrame,
size: usize, size: usize,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe { unsafe {
from_glib(ffi::gst_video_encoder_allocate_output_frame( gst::FlowSuccess::try_from_glib(ffi::gst_video_encoder_allocate_output_frame(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
frame.to_glib_none().0, frame.to_glib_none().0,
size, size,
)) ))
}; }
ret.into_result()
} }
fn allocator(&self) -> (Option<gst::Allocator>, gst::AllocationParams) { fn allocator(&self) -> (Option<gst::Allocator>, gst::AllocationParams) {
@ -90,25 +89,23 @@ impl<O: IsA<VideoEncoder>> VideoEncoderExtManual for O {
&self, &self,
frame: Option<VideoCodecFrame>, frame: Option<VideoCodecFrame>,
) -> Result<gst::FlowSuccess, gst::FlowError> { ) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe { unsafe {
from_glib(ffi::gst_video_encoder_finish_frame( gst::FlowSuccess::try_from_glib(ffi::gst_video_encoder_finish_frame(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
frame.map(|f| f.into_ptr()).unwrap_or(ptr::null_mut()), frame.map(|f| f.into_ptr()).unwrap_or(ptr::null_mut()),
)) ))
}; }
ret.into_result()
} }
#[cfg(any(feature = "v1_18", feature = "dox"))] #[cfg(any(feature = "v1_18", feature = "dox"))]
#[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))] #[cfg_attr(feature = "dox", doc(cfg(feature = "v1_18")))]
fn finish_subframe(&self, frame: &VideoCodecFrame) -> Result<gst::FlowSuccess, gst::FlowError> { fn finish_subframe(&self, frame: &VideoCodecFrame) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe { unsafe {
from_glib(ffi::gst_video_encoder_finish_subframe( gst::FlowSuccess::try_from_glib(ffi::gst_video_encoder_finish_subframe(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
frame.to_glib_none().0, frame.to_glib_none().0,
)) ))
}; }
ret.into_result()
} }
fn latency(&self) -> (gst::ClockTime, gst::ClockTime) { fn latency(&self) -> (gst::ClockTime, gst::ClockTime) {

View file

@ -6,9 +6,7 @@ use crate::BufferPool;
use crate::Structure; use crate::Structure;
use glib::prelude::*; use glib::prelude::*;
use glib::translate::{ use glib::translate::*;
from_glib, from_glib_full, from_glib_none, IntoGlib, ToGlibPtr, ToGlibPtrMut,
};
use std::mem; use std::mem;
use std::ops; use std::ops;
@ -334,13 +332,12 @@ impl<O: IsA<BufferPool>> BufferPoolExtManual for O {
unsafe { unsafe {
let mut buffer = ptr::null_mut(); let mut buffer = ptr::null_mut();
let ret: crate::FlowReturn = from_glib(ffi::gst_buffer_pool_acquire_buffer( crate::FlowSuccess::try_from_glib(ffi::gst_buffer_pool_acquire_buffer(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
&mut buffer, &mut buffer,
params_ptr, params_ptr,
)); ))
.map(|_| from_glib_full(buffer))
ret.into_result_value(|| from_glib_full(buffer))
} }
} }

View file

@ -45,9 +45,11 @@ impl ClockId {
pub fn wait(&self) -> (Result<ClockSuccess, ClockError>, ClockTimeDiff) { pub fn wait(&self) -> (Result<ClockSuccess, ClockError>, ClockTimeDiff) {
unsafe { unsafe {
let mut jitter = 0; let mut jitter = 0;
let res: ClockReturn = let res = ClockSuccess::try_from_glib(ffi::gst_clock_id_wait(
from_glib(ffi::gst_clock_id_wait(self.to_glib_none().0, &mut jitter)); self.to_glib_none().0,
(res.into_result(), jitter) &mut jitter,
));
(res, jitter)
} }
} }
@ -160,15 +162,14 @@ impl SingleShotClockId {
let func: Box<Option<F>> = Box::new(Some(func)); let func: Box<Option<F>> = Box::new(Some(func));
let ret: ClockReturn = unsafe { unsafe {
from_glib(ffi::gst_clock_id_wait_async( ClockSuccess::try_from_glib(ffi::gst_clock_id_wait_async(
self.to_glib_none().0, self.to_glib_none().0,
Some(trampoline::<F>), Some(trampoline::<F>),
Box::into_raw(func) as gpointer, Box::into_raw(func) as gpointer,
Some(destroy_notify::<F>), Some(destroy_notify::<F>),
)) ))
}; }
ret.into_result()
} }
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
@ -264,15 +265,14 @@ impl PeriodicClockId {
} }
let func: Box<F> = Box::new(func); let func: Box<F> = Box::new(func);
let ret: ClockReturn = unsafe { unsafe {
from_glib(ffi::gst_clock_id_wait_async( ClockSuccess::try_from_glib(ffi::gst_clock_id_wait_async(
self.to_glib_none().0, self.to_glib_none().0,
Some(trampoline::<F>), Some(trampoline::<F>),
Box::into_raw(func) as gpointer, Box::into_raw(func) as gpointer,
Some(destroy_notify::<F>), Some(destroy_notify::<F>),
)) ))
}; }
ret.into_result()
} }
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]

View file

@ -18,10 +18,6 @@ use crate::QueryRef;
use crate::Rank; use crate::Rank;
use crate::SpecificFormattedValue; use crate::SpecificFormattedValue;
use crate::State; use crate::State;
use crate::StateChange;
use crate::StateChangeError;
use crate::StateChangeReturn;
use crate::StateChangeSuccess;
use glib::translate::*; use glib::translate::*;
@ -116,29 +112,11 @@ pub trait ElementExtManual: 'static {
#[doc(alias = "get_element_class")] #[doc(alias = "get_element_class")]
fn element_class(&self) -> &glib::Class<Element>; fn element_class(&self) -> &glib::Class<Element>;
fn change_state(&self, transition: StateChange)
-> Result<StateChangeSuccess, StateChangeError>;
fn continue_state(
&self,
ret: StateChangeReturn,
) -> Result<StateChangeSuccess, StateChangeError>;
#[doc(alias = "get_state")]
fn state(
&self,
timeout: ClockTime,
) -> (Result<StateChangeSuccess, StateChangeError>, State, State);
fn set_state(&self, state: State) -> Result<StateChangeSuccess, StateChangeError>;
#[doc(alias = "get_current_state")] #[doc(alias = "get_current_state")]
fn current_state(&self) -> State { fn current_state(&self) -> State;
self.state(ClockTime::from(0)).1
}
#[doc(alias = "get_pending_state")] #[doc(alias = "get_pending_state")]
fn pending_state(&self) -> State { fn pending_state(&self) -> State;
self.state(ClockTime::from(0)).2
}
fn query(&self, query: &mut QueryRef) -> bool; fn query(&self, query: &mut QueryRef) -> bool;
@ -283,61 +261,12 @@ impl<O: IsA<Element>> ElementExtManual for O {
} }
} }
fn change_state( fn current_state(&self) -> State {
&self, self.state(ClockTime::zero()).1
transition: StateChange,
) -> Result<StateChangeSuccess, StateChangeError> {
let ret: StateChangeReturn = unsafe {
from_glib(ffi::gst_element_change_state(
self.as_ref().to_glib_none().0,
transition.into_glib(),
))
};
ret.into_result()
} }
fn continue_state( fn pending_state(&self) -> State {
&self, self.state(ClockTime::zero()).2
ret: StateChangeReturn,
) -> Result<StateChangeSuccess, StateChangeError> {
let ret: StateChangeReturn = unsafe {
from_glib(ffi::gst_element_continue_state(
self.as_ref().to_glib_none().0,
ret.into_glib(),
))
};
ret.into_result()
}
fn state(
&self,
timeout: ClockTime,
) -> (Result<StateChangeSuccess, StateChangeError>, State, State) {
unsafe {
let mut state = mem::MaybeUninit::uninit();
let mut pending = mem::MaybeUninit::uninit();
let ret: StateChangeReturn = from_glib(ffi::gst_element_get_state(
self.as_ref().to_glib_none().0,
state.as_mut_ptr(),
pending.as_mut_ptr(),
timeout.into_glib(),
));
(
ret.into_result(),
from_glib(state.assume_init()),
from_glib(pending.assume_init()),
)
}
}
fn set_state(&self, state: State) -> Result<StateChangeSuccess, StateChangeError> {
let ret: StateChangeReturn = unsafe {
from_glib(ffi::gst_element_set_state(
self.as_ref().to_glib_none().0,
state.into_glib(),
))
};
ret.into_result()
} }
fn query(&self, query: &mut QueryRef) -> bool { fn query(&self, query: &mut QueryRef) -> bool {

View file

@ -16,6 +16,58 @@ use glib::value::Value;
use glib::StaticType; use glib::StaticType;
use glib::Type; use glib::Type;
macro_rules! impl_return_result_traits {
($ffi_type:ident, $ret_type:ident, $ok_type:ident, $err_type:ident) => {
impl From<$ok_type> for $ret_type {
fn from(value: $ok_type) -> Self {
skip_assert_initialized!();
$ret_type::from_ok(value)
}
}
impl IntoGlib for $ok_type {
type GlibType = <$ret_type as IntoGlib>::GlibType;
fn into_glib(self) -> Self::GlibType {
$ret_type::from_ok(self).into_glib()
}
}
impl From<$err_type> for $ret_type {
fn from(value: $err_type) -> Self {
skip_assert_initialized!();
$ret_type::from_error(value)
}
}
impl IntoGlib for $err_type {
type GlibType = <$ret_type as IntoGlib>::GlibType;
fn into_glib(self) -> Self::GlibType {
$ret_type::from_error(self).into_glib()
}
}
impl From<Result<$ok_type, $err_type>> for $ret_type {
fn from(res: Result<$ok_type, $err_type>) -> Self {
skip_assert_initialized!();
match res {
Ok(success) => $ret_type::from_ok(success),
Err(error) => $ret_type::from_error(error),
}
}
}
impl TryFromGlib<ffi::$ffi_type> for $ok_type {
type Error = $err_type;
fn try_from_glib(val: ffi::$ffi_type) -> Result<$ok_type, $err_type> {
skip_assert_initialized!();
unsafe { $ret_type::from_glib(val) }.into_result()
}
}
};
}
impl StateChangeReturn { impl StateChangeReturn {
pub fn into_result(self) -> Result<StateChangeSuccess, StateChangeError> { pub fn into_result(self) -> Result<StateChangeSuccess, StateChangeError> {
match self { match self {
@ -49,34 +101,17 @@ pub enum StateChangeSuccess {
NoPreroll, NoPreroll,
} }
impl From<StateChangeSuccess> for StateChangeReturn {
fn from(value: StateChangeSuccess) -> Self {
skip_assert_initialized!();
StateChangeReturn::from_ok(value)
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Error)] #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Error)]
#[must_use] #[must_use]
#[error("Element failed to change its state")] #[error("Element failed to change its state")]
pub struct StateChangeError; pub struct StateChangeError;
impl From<StateChangeError> for StateChangeReturn { impl_return_result_traits!(
fn from(value: StateChangeError) -> Self { GstStateChangeReturn,
skip_assert_initialized!(); StateChangeReturn,
StateChangeReturn::from_error(value) StateChangeSuccess,
} StateChangeError
} );
impl From<Result<StateChangeSuccess, StateChangeError>> for StateChangeReturn {
fn from(res: Result<StateChangeSuccess, StateChangeError>) -> Self {
skip_assert_initialized!();
match res {
Ok(success) => StateChangeReturn::from_ok(success),
Err(error) => StateChangeReturn::from_error(error),
}
}
}
impl FlowReturn { impl FlowReturn {
pub fn into_result(self) -> Result<FlowSuccess, FlowError> { pub fn into_result(self) -> Result<FlowSuccess, FlowError> {
@ -98,13 +133,6 @@ 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 {
skip_assert_initialized!(); skip_assert_initialized!();
match v { match v {
@ -139,13 +167,6 @@ pub enum FlowSuccess {
Ok, Ok,
} }
impl From<FlowSuccess> for FlowReturn {
fn from(value: FlowSuccess) -> Self {
skip_assert_initialized!();
FlowReturn::from_ok(value)
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Error)] #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Error)]
#[must_use] #[must_use]
pub enum FlowError { pub enum FlowError {
@ -169,22 +190,7 @@ pub enum FlowError {
CustomError2, CustomError2,
} }
impl From<FlowError> for FlowReturn { impl_return_result_traits!(GstFlowReturn, FlowReturn, FlowSuccess, FlowError);
fn from(value: FlowError) -> Self {
skip_assert_initialized!();
FlowReturn::from_error(value)
}
}
impl From<Result<FlowSuccess, FlowError>> for FlowReturn {
fn from(res: Result<FlowSuccess, FlowError>) -> Self {
skip_assert_initialized!();
match res {
Ok(success) => FlowReturn::from_ok(success),
Err(error) => FlowReturn::from_error(error),
}
}
}
impl PadLinkReturn { impl PadLinkReturn {
pub fn into_result(self) -> Result<PadLinkSuccess, PadLinkError> { pub fn into_result(self) -> Result<PadLinkSuccess, PadLinkError> {
@ -221,13 +227,6 @@ impl PadLinkReturn {
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub struct PadLinkSuccess; pub struct PadLinkSuccess;
impl From<PadLinkSuccess> for PadLinkReturn {
fn from(value: PadLinkSuccess) -> Self {
skip_assert_initialized!();
PadLinkReturn::from_ok(value)
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Error)] #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Error)]
#[must_use] #[must_use]
pub enum PadLinkError { pub enum PadLinkError {
@ -245,22 +244,12 @@ pub enum PadLinkError {
Refused, Refused,
} }
impl From<PadLinkError> for PadLinkReturn { impl_return_result_traits!(
fn from(value: PadLinkError) -> Self { GstPadLinkReturn,
skip_assert_initialized!(); PadLinkReturn,
PadLinkReturn::from_error(value) PadLinkSuccess,
} PadLinkError
} );
impl From<Result<PadLinkSuccess, PadLinkError>> for PadLinkReturn {
fn from(res: Result<PadLinkSuccess, PadLinkError>) -> Self {
skip_assert_initialized!();
match res {
Ok(success) => PadLinkReturn::from_ok(success),
Err(error) => PadLinkReturn::from_error(error),
}
}
}
impl ClockReturn { impl ClockReturn {
pub fn into_result(self) -> Result<ClockSuccess, ClockError> { pub fn into_result(self) -> Result<ClockSuccess, ClockError> {
@ -304,13 +293,6 @@ pub enum ClockSuccess {
Done, Done,
} }
impl From<ClockSuccess> for ClockReturn {
fn from(value: ClockSuccess) -> Self {
skip_assert_initialized!();
ClockReturn::from_ok(value)
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Error)] #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Error)]
#[must_use] #[must_use]
pub enum ClockError { pub enum ClockError {
@ -328,22 +310,7 @@ pub enum ClockError {
Unsupported, Unsupported,
} }
impl From<ClockError> for ClockReturn { impl_return_result_traits!(GstClockReturn, ClockReturn, ClockSuccess, ClockError);
fn from(value: ClockError) -> Self {
skip_assert_initialized!();
ClockReturn::from_error(value)
}
}
impl From<Result<ClockSuccess, ClockError>> for ClockReturn {
fn from(res: Result<ClockSuccess, ClockError>) -> Self {
skip_assert_initialized!();
match res {
Ok(success) => ClockReturn::from_ok(success),
Err(error) => ClockReturn::from_error(error),
}
}
}
impl PartialEq for crate::TypeFindProbability { impl PartialEq for crate::TypeFindProbability {
fn eq(&self, other: &crate::TypeFindProbability) -> bool { fn eq(&self, other: &crate::TypeFindProbability) -> bool {

View file

@ -12,10 +12,6 @@ use crate::GenericFormattedValue;
use crate::LoggableError; use crate::LoggableError;
use crate::Pad; use crate::Pad;
use crate::PadFlags; use crate::PadFlags;
use crate::PadLinkCheck;
use crate::PadLinkError;
use crate::PadLinkReturn;
use crate::PadLinkSuccess;
use crate::PadProbeReturn; use crate::PadProbeReturn;
use crate::PadProbeType; use crate::PadProbeType;
use crate::Query; use crate::Query;
@ -30,9 +26,7 @@ use std::ptr;
use glib::ffi::gpointer; use glib::ffi::gpointer;
use glib::prelude::*; use glib::prelude::*;
use glib::translate::{ use glib::translate::*;
from_glib, from_glib_borrow, from_glib_full, FromGlib, FromGlibPtrBorrow, IntoGlib, ToGlibPtr,
};
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
pub struct PadProbeId(NonZeroU64); pub struct PadProbeId(NonZeroU64);
@ -137,22 +131,12 @@ pub trait PadExtManual: 'static {
fn push_event(&self, event: Event) -> bool; fn push_event(&self, event: Event) -> bool;
fn send_event(&self, event: Event) -> bool; fn send_event(&self, event: Event) -> bool;
#[doc(alias = "get_last_flow_result")]
fn last_flow_result(&self) -> Result<FlowSuccess, FlowError>;
fn iterate_internal_links(&self) -> crate::Iterator<Pad>; fn iterate_internal_links(&self) -> crate::Iterator<Pad>;
fn iterate_internal_links_default<P: IsA<crate::Object>>( fn iterate_internal_links_default<P: IsA<crate::Object>>(
&self, &self,
parent: Option<&P>, parent: Option<&P>,
) -> crate::Iterator<Pad>; ) -> crate::Iterator<Pad>;
fn link<P: IsA<Pad>>(&self, sinkpad: &P) -> Result<PadLinkSuccess, PadLinkError>;
fn link_full<P: IsA<Pad>>(
&self,
sinkpad: &P,
flags: PadLinkCheck,
) -> Result<PadLinkSuccess, PadLinkError>;
fn stream_lock(&self) -> StreamLock; fn stream_lock(&self) -> StreamLock;
unsafe fn set_activate_function<F>(&self, func: F) unsafe fn set_activate_function<F>(&self, func: F)
@ -269,8 +253,6 @@ pub trait PadExtManual: 'static {
func: F, func: F,
); );
fn store_sticky_event(&self, event: &Event) -> Result<FlowSuccess, FlowError>;
fn set_pad_flags(&self, flags: PadFlags); fn set_pad_flags(&self, flags: PadFlags);
fn unset_pad_flags(&self, flags: PadFlags); fn unset_pad_flags(&self, flags: PadFlags);
@ -310,54 +292,50 @@ impl<O: IsA<Pad>> PadExtManual for O {
fn chain(&self, buffer: Buffer) -> Result<FlowSuccess, FlowError> { fn chain(&self, buffer: Buffer) -> Result<FlowSuccess, FlowError> {
unsafe { unsafe {
FlowReturn::from_glib(ffi::gst_pad_chain( FlowSuccess::try_from_glib(ffi::gst_pad_chain(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
buffer.into_ptr(), buffer.into_ptr(),
)) ))
.into_result()
} }
} }
fn push(&self, buffer: Buffer) -> Result<FlowSuccess, FlowError> { fn push(&self, buffer: Buffer) -> Result<FlowSuccess, FlowError> {
unsafe { unsafe {
FlowReturn::from_glib(ffi::gst_pad_push( FlowSuccess::try_from_glib(ffi::gst_pad_push(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
buffer.into_ptr(), buffer.into_ptr(),
)) ))
.into_result()
} }
} }
fn chain_list(&self, list: BufferList) -> Result<FlowSuccess, FlowError> { fn chain_list(&self, list: BufferList) -> Result<FlowSuccess, FlowError> {
unsafe { unsafe {
FlowReturn::from_glib(ffi::gst_pad_chain_list( FlowSuccess::try_from_glib(ffi::gst_pad_chain_list(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
list.into_ptr(), list.into_ptr(),
)) ))
.into_result()
} }
} }
fn push_list(&self, list: BufferList) -> Result<FlowSuccess, FlowError> { fn push_list(&self, list: BufferList) -> Result<FlowSuccess, FlowError> {
unsafe { unsafe {
FlowReturn::from_glib(ffi::gst_pad_push_list( FlowSuccess::try_from_glib(ffi::gst_pad_push_list(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
list.into_ptr(), list.into_ptr(),
)) ))
.into_result()
} }
} }
fn range(&self, offset: u64, size: u32) -> Result<Buffer, FlowError> { fn 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: FlowReturn = from_glib(ffi::gst_pad_get_range( FlowSuccess::try_from_glib(ffi::gst_pad_get_range(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
offset, offset,
size, size,
&mut buffer, &mut buffer,
)); ))
ret.into_result_value(|| from_glib_full(buffer)) .map(|_| from_glib_full(buffer))
} }
} }
@ -371,36 +349,33 @@ impl<O: IsA<Pad>> PadExtManual for O {
unsafe { unsafe {
let mut buffer_ref = buffer.as_mut_ptr(); let mut buffer_ref = buffer.as_mut_ptr();
let ret: FlowReturn = from_glib(ffi::gst_pad_get_range( FlowSuccess::try_from_glib(ffi::gst_pad_get_range(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
offset, offset,
size, size,
&mut buffer_ref, &mut buffer_ref,
)); ))
match ret.into_result_value(|| ()) { .and_then(|_| {
Ok(_) => {
if buffer.as_mut_ptr() != buffer_ref { if buffer.as_mut_ptr() != buffer_ref {
ffi::gst_mini_object_unref(buffer_ref as *mut _); ffi::gst_mini_object_unref(buffer_ref as *mut _);
Err(crate::FlowError::Error) Err(crate::FlowError::Error)
} else { } else {
Ok(()) Ok(())
} }
} })
Err(err) => Err(err),
}
} }
} }
fn pull_range(&self, offset: u64, size: u32) -> Result<Buffer, FlowError> { 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: FlowReturn = from_glib(ffi::gst_pad_pull_range( FlowSuccess::try_from_glib(ffi::gst_pad_pull_range(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
offset, offset,
size, size,
&mut buffer, &mut buffer,
)); ))
ret.into_result_value(|| from_glib_full(buffer)) .map(|_| from_glib_full(buffer))
} }
} }
@ -414,23 +389,20 @@ impl<O: IsA<Pad>> PadExtManual for O {
unsafe { unsafe {
let mut buffer_ref = buffer.as_mut_ptr(); let mut buffer_ref = buffer.as_mut_ptr();
let ret: FlowReturn = from_glib(ffi::gst_pad_pull_range( FlowSuccess::try_from_glib(ffi::gst_pad_pull_range(
self.as_ref().to_glib_none().0, self.as_ref().to_glib_none().0,
offset, offset,
size, size,
&mut buffer_ref, &mut buffer_ref,
)); ))
match ret.into_result_value(|| ()) { .and_then(|_| {
Ok(_) => {
if buffer.as_mut_ptr() != buffer_ref { if buffer.as_mut_ptr() != buffer_ref {
ffi::gst_mini_object_unref(buffer_ref as *mut _); ffi::gst_mini_object_unref(buffer_ref as *mut _);
Err(crate::FlowError::Error) Err(crate::FlowError::Error)
} else { } else {
Ok(()) Ok(())
} }
} })
Err(err) => Err(err),
}
} }
} }
@ -514,15 +486,6 @@ impl<O: IsA<Pad>> PadExtManual for O {
} }
} }
fn last_flow_result(&self) -> Result<FlowSuccess, FlowError> {
let ret: FlowReturn = unsafe {
from_glib(ffi::gst_pad_get_last_flow_return(
self.as_ref().to_glib_none().0,
))
};
ret.into_result()
}
fn iterate_internal_links(&self) -> crate::Iterator<Pad> { fn iterate_internal_links(&self) -> crate::Iterator<Pad> {
unsafe { unsafe {
from_glib_full(ffi::gst_pad_iterate_internal_links( from_glib_full(ffi::gst_pad_iterate_internal_links(
@ -543,31 +506,6 @@ impl<O: IsA<Pad>> PadExtManual for O {
} }
} }
fn link<P: IsA<Pad>>(&self, sinkpad: &P) -> Result<PadLinkSuccess, PadLinkError> {
let ret: PadLinkReturn = unsafe {
from_glib(ffi::gst_pad_link(
self.as_ref().to_glib_none().0,
sinkpad.as_ref().to_glib_none().0,
))
};
ret.into_result()
}
fn link_full<P: IsA<Pad>>(
&self,
sinkpad: &P,
flags: PadLinkCheck,
) -> Result<PadLinkSuccess, PadLinkError> {
let ret: PadLinkReturn = unsafe {
from_glib(ffi::gst_pad_link_full(
self.as_ref().to_glib_none().0,
sinkpad.as_ref().to_glib_none().0,
flags.into_glib(),
))
};
ret.into_result()
}
fn stream_lock(&self) -> StreamLock { fn stream_lock(&self) -> StreamLock {
unsafe { unsafe {
let ptr: &mut ffi::GstPad = &mut *(self.as_ptr() as *mut _); let ptr: &mut ffi::GstPad = &mut *(self.as_ptr() as *mut _);
@ -1043,16 +981,6 @@ impl<O: IsA<Pad>> PadExtManual for O {
} }
} }
fn store_sticky_event(&self, event: &Event) -> Result<FlowSuccess, FlowError> {
let ret: FlowReturn = unsafe {
from_glib(ffi::gst_pad_store_sticky_event(
self.as_ref().to_glib_none().0,
event.to_glib_none().0,
))
};
ret.into_result()
}
fn set_pad_flags(&self, flags: PadFlags) { fn set_pad_flags(&self, flags: PadFlags) {
unsafe { unsafe {
let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _; let ptr: *mut ffi::GstObject = self.as_ptr() as *mut _;
@ -1082,7 +1010,7 @@ unsafe fn create_probe_info<'a>(
info: *mut ffi::GstPadProbeInfo, info: *mut ffi::GstPadProbeInfo,
) -> (PadProbeInfo<'a>, Option<glib::Type>) { ) -> (PadProbeInfo<'a>, Option<glib::Type>) {
let mut data_type = None; let mut data_type = None;
let flow_ret: FlowReturn = from_glib((*info).ABI.abi.flow_ret); let flow_res = FlowSuccess::try_from_glib((*info).ABI.abi.flow_ret);
let info = PadProbeInfo { let info = PadProbeInfo {
mask: from_glib((*info).type_), mask: from_glib((*info).type_),
id: Some(PadProbeId(NonZeroU64::new_unchecked((*info).id as u64))), id: Some(PadProbeId(NonZeroU64::new_unchecked((*info).id as u64))),
@ -1117,7 +1045,7 @@ unsafe fn create_probe_info<'a>(
Some(PadProbeData::__Unknown(data)) Some(PadProbeData::__Unknown(data))
} }
}, },
flow_res: flow_ret.into_result(), flow_res,
}; };
(info, data_type) (info, data_type)
} }

View file

@ -3,7 +3,6 @@
use crate::Buffer; use crate::Buffer;
use crate::BufferList; use crate::BufferList;
use crate::FlowError; use crate::FlowError;
use crate::FlowReturn;
use crate::FlowSuccess; use crate::FlowSuccess;
use crate::Object; use crate::Object;
use crate::Pad; use crate::Pad;
@ -11,7 +10,7 @@ use crate::ProxyPad;
use std::ptr; use std::ptr;
use glib::prelude::*; use glib::prelude::*;
use glib::translate::{from_glib, from_glib_full, ToGlibPtr}; use glib::translate::*;
pub trait ProxyPadExtManual: 'static { pub trait ProxyPadExtManual: 'static {
fn chain_default<P: IsA<Object>>( fn chain_default<P: IsA<Object>>(
@ -46,14 +45,13 @@ impl<O: IsA<ProxyPad>> ProxyPadExtManual for O {
buffer: Buffer, buffer: Buffer,
) -> Result<FlowSuccess, FlowError> { ) -> Result<FlowSuccess, FlowError> {
skip_assert_initialized!(); skip_assert_initialized!();
let ret: FlowReturn = unsafe { unsafe {
from_glib(ffi::gst_proxy_pad_chain_default( FlowSuccess::try_from_glib(ffi::gst_proxy_pad_chain_default(
self.as_ptr() as *mut ffi::GstPad, self.as_ptr() as *mut ffi::GstPad,
parent.map(|p| p.as_ref()).to_glib_none().0, parent.map(|p| p.as_ref()).to_glib_none().0,
buffer.into_ptr(), buffer.into_ptr(),
)) ))
}; }
ret.into_result()
} }
fn chain_list_default<P: IsA<Object>>( fn chain_list_default<P: IsA<Object>>(
@ -62,14 +60,13 @@ impl<O: IsA<ProxyPad>> ProxyPadExtManual for O {
list: BufferList, list: BufferList,
) -> Result<FlowSuccess, FlowError> { ) -> Result<FlowSuccess, FlowError> {
skip_assert_initialized!(); skip_assert_initialized!();
let ret: FlowReturn = unsafe { unsafe {
from_glib(ffi::gst_proxy_pad_chain_list_default( FlowSuccess::try_from_glib(ffi::gst_proxy_pad_chain_list_default(
self.as_ptr() as *mut ffi::GstPad, self.as_ptr() as *mut ffi::GstPad,
parent.map(|p| p.as_ref()).to_glib_none().0, parent.map(|p| p.as_ref()).to_glib_none().0,
list.into_ptr(), list.into_ptr(),
)) ))
}; }
ret.into_result()
} }
fn getrange_default<P: IsA<Object>>( fn getrange_default<P: IsA<Object>>(
@ -81,14 +78,14 @@ impl<O: IsA<ProxyPad>> ProxyPadExtManual for O {
skip_assert_initialized!(); skip_assert_initialized!();
unsafe { unsafe {
let mut buffer = ptr::null_mut(); let mut buffer = ptr::null_mut();
let ret: FlowReturn = from_glib(ffi::gst_proxy_pad_getrange_default( FlowSuccess::try_from_glib(ffi::gst_proxy_pad_getrange_default(
self.as_ptr() as *mut ffi::GstPad, self.as_ptr() as *mut ffi::GstPad,
parent.map(|p| p.as_ref()).to_glib_none().0, parent.map(|p| p.as_ref()).to_glib_none().0,
offset, offset,
size, size,
&mut buffer, &mut buffer,
)); ))
ret.into_result_value(|| from_glib_full(buffer)) .map(|_| from_glib_full(buffer))
} }
} }

View file

@ -141,7 +141,7 @@ impl<T: ClockImpl> ClockImplExt for T {
let mut jitter = 0; let mut jitter = 0;
( (
ClockReturn::from_glib( ClockSuccess::try_from_glib(
(*parent_class) (*parent_class)
.wait .wait
.map(|f| { .map(|f| {
@ -152,8 +152,7 @@ impl<T: ClockImpl> ClockImplExt for T {
) )
}) })
.unwrap_or(ffi::GST_CLOCK_UNSUPPORTED), .unwrap_or(ffi::GST_CLOCK_UNSUPPORTED),
) ),
.into_result(),
jitter, jitter,
) )
} }
@ -167,7 +166,7 @@ impl<T: ClockImpl> ClockImplExt for T {
unsafe { unsafe {
let data = Self::type_data(); let data = Self::type_data();
let parent_class = data.as_ref().parent_class() as *mut ffi::GstClockClass; let parent_class = data.as_ref().parent_class() as *mut ffi::GstClockClass;
ClockReturn::from_glib( ClockSuccess::try_from_glib(
(*parent_class) (*parent_class)
.wait_async .wait_async
.map(|f| { .map(|f| {
@ -178,7 +177,6 @@ impl<T: ClockImpl> ClockImplExt for T {
}) })
.unwrap_or(ffi::GST_CLOCK_UNSUPPORTED), .unwrap_or(ffi::GST_CLOCK_UNSUPPORTED),
) )
.into_result()
} }
} }

View file

@ -170,11 +170,10 @@ impl<T: ElementImpl> ElementImplExt for T {
let f = (*parent_class) let f = (*parent_class)
.change_state .change_state
.expect("Missing parent function `change_state`"); .expect("Missing parent function `change_state`");
StateChangeReturn::from_glib(f( StateChangeSuccess::try_from_glib(f(
element.unsafe_cast_ref::<Element>().to_glib_none().0, element.unsafe_cast_ref::<Element>().to_glib_none().0,
transition.into_glib(), transition.into_glib(),
)) ))
.into_result()
} }
} }