Make appsink/appsrc callbacks builder more consistent with other code

Move the constructor of the builder to the main type
This commit is contained in:
Sebastian Dröge 2017-12-16 11:37:00 +02:00
parent 7dc2e43db3
commit 396dae666f
3 changed files with 23 additions and 9 deletions

View file

@ -61,7 +61,7 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
));
appsink.set_callbacks(
gst_app::AppSinkCallbacksBuilder::new()
gst_app::AppSinkCallbacks::new()
.new_sample(|appsink| {
let sample = match appsink.pull_sample() {
None => return gst::FlowReturn::Eos,

View file

@ -22,14 +22,8 @@ pub struct AppSinkCallbacks {
callbacks: ffi::GstAppSinkCallbacks,
}
pub struct AppSinkCallbacksBuilder {
eos: Option<Box<Fn(&AppSink) + Send + Sync + 'static>>,
new_preroll: Option<Box<Fn(&AppSink) -> gst::FlowReturn + Send + Sync + 'static>>,
new_sample: Option<Box<Fn(&AppSink) -> gst::FlowReturn + Send + Sync + 'static>>,
}
impl AppSinkCallbacksBuilder {
pub fn new() -> Self {
impl AppSinkCallbacks {
pub fn new() -> AppSinkCallbacksBuilder {
skip_assert_initialized!();
AppSinkCallbacksBuilder {
eos: None,
@ -37,7 +31,15 @@ impl AppSinkCallbacksBuilder {
new_sample: None,
}
}
}
pub struct AppSinkCallbacksBuilder {
eos: Option<Box<Fn(&AppSink) + Send + Sync + 'static>>,
new_preroll: Option<Box<Fn(&AppSink) -> gst::FlowReturn + Send + Sync + 'static>>,
new_sample: Option<Box<Fn(&AppSink) -> gst::FlowReturn + Send + Sync + 'static>>,
}
impl AppSinkCallbacksBuilder {
pub fn eos<F: Fn(&AppSink) + Send + Sync + 'static>(self, eos: F) -> Self {
Self {
eos: Some(Box::new(eos)),

View file

@ -21,6 +21,18 @@ pub struct AppSrcCallbacks {
callbacks: ffi::GstAppSrcCallbacks,
}
impl AppSrcCallbacks {
pub fn new() -> AppSrcCallbacksBuilder {
skip_assert_initialized!();
AppSrcCallbacksBuilder {
need_data: None,
enough_data: None,
seek_data: None,
}
}
}
pub struct AppSrcCallbacksBuilder {
need_data: Option<Box<Fn(&AppSrc, u32) + Send + Sync + 'static>>,
enough_data: Option<Box<Fn(&AppSrc) + Send + Sync + 'static>>,