Replace XXXReturn with Result<XXXSuccess, XXXError>

... in function signatures.

These breaking changes aim at improving usability by allowing users
to take advantage of Rust error management features sur as `ok_or`,
`map_err`, `expect` and the `?` operator. See the `examples` and
`tutorials` to get an idea of the impacts.
This commit is contained in:
François Laignel 2019-01-08 17:13:37 +01:00
parent 226070d216
commit 948fb2ae4b
64 changed files with 987 additions and 529 deletions

View file

@ -386,6 +386,26 @@ status = "generate"
[object.function.return] [object.function.return]
bool_return_is_error = "Failed to sync state with parent" bool_return_is_error = "Failed to sync state with parent"
[[object.function]]
name = "change_state"
# Use Result<StateChangeSuccess, StateChangeError>
ignore = true
[[object.function]]
name = "continue_state"
# Use Result<StateChangeSuccess, StateChangeError>
ignore = true
[[object.function]]
name = "get_state"
# Use Result<StateChangeSuccess, StateChangeError>
ignore = true
[[object.function]]
name = "set_state"
# Use Result<StateChangeSuccess, StateChangeError>
ignore = true
[[object.function]] [[object.function]]
name = "query" name = "query"
# correct mutability # correct mutability
@ -645,6 +665,11 @@ status = "generate"
# Buffer can be NULL # Buffer can be NULL
ignore = true ignore = true
[[object.function]]
name = "get_last_flow_return"
# Use Result<FlowSuccess, FlowError>
ignore = true
[[object.function]] [[object.function]]
name = "query" name = "query"
# Correct mutability # Correct mutability
@ -685,6 +710,21 @@ status = "generate"
# Pass by value # Pass by value
ignore = true ignore = true
[[object.function]]
name = "link"
# Use Result<PadLinkSuccess, PadLinkError>
ignore = true
[[object.function]]
name = "link_full"
# Use Result<PadLinkSuccess, PadLinkError>
ignore = true
[[object.function]]
name = "store_sticky_event"
# Use Result<FlowSuccess, FlowError>
ignore = true
[[object.function]] [[object.function]]
name = "new_from_static_template" name = "new_from_static_template"
# Correct mutability # Correct mutability

View file

@ -57,6 +57,16 @@ trait = false
# Action signal # Action signal
ignore = true ignore = true
[[object.signal]]
name = "new-sample"
# Use Result<FlowSuccess, FlowError>
ignore = true
[[object.signal]]
name = "new-preroll"
# Use Result<FlowSuccess, FlowError>
ignore = true
[[object.function]] [[object.function]]
name = "set_caps" name = "set_caps"
[[object.function.parameter]] [[object.function.parameter]]
@ -98,6 +108,16 @@ trait = false
# Action signal # Action signal
ignore = true ignore = true
[[object.function]]
name = "end_of_stream"
# Use Result<FlowSuccess, FlowError>
ignore = true
[[object.function]]
name = "push_sample"
# Use Result<FlowSuccess, FlowError>
ignore = true
[[object.function]] [[object.function]]
name = "set_latency" name = "set_latency"
# ClockTime # ClockTime

View file

@ -77,16 +77,41 @@ name = "GstBase.BaseSink"
subclassing = true subclassing = true
status = "generate" status = "generate"
[[object.function]]
name = "wait"
# Use Result<FlowSuccess, FlowError>
ignore = true
[[object.function]]
name = "wait_preroll"
# Use Result<FlowSuccess, FlowError>
ignore = true
[[object]] [[object]]
name = "GstBase.BaseSrc" name = "GstBase.BaseSrc"
subclassing = true subclassing = true
status = "generate" status = "generate"
[[object.function]]
name = "start_complete"
# Use Result<FlowSuccess, FlowError>
ignore = true
[[object.function]]
name = "start_wait"
# Use Result<FlowSuccess, FlowError>
ignore = true
[[object.function]] [[object.function]]
name = "submit_buffer_list" name = "submit_buffer_list"
# Pass by value, to be added manually # Pass by value, to be added manually
ignore = true ignore = true
[[object.function]]
name = "wait_playing"
# Use Result<FlowSuccess, FlowError>
ignore = true
[[object]] [[object]]
name = "GstBase.BaseTransform" name = "GstBase.BaseTransform"
subclassing = true subclassing = true

View file

@ -122,6 +122,16 @@ status = "generate"
name = "GstRtspServer.RTSPStream" name = "GstRtspServer.RTSPStream"
status = "generate" status = "generate"
[[object.function]]
name = "recv_rtcp"
# Use Result<FlowSuccess, FlowError>
ignore = true
[[object.function]]
name = "recv_rtp"
# Use Result<FlowSuccess, FlowError>
ignore = true
[[object.function]] [[object.function]]
name = "query_position" name = "query_position"
ignore = true ignore = true
@ -160,6 +170,11 @@ name = "GstRtspServer.RTSPStreamTransport"
status = "generate" status = "generate"
concurrency = "none" concurrency = "none"
[[object.function]]
name = "recv_data"
# Use Result<FlowSuccess, FlowError>
ignore = true
[[object.function]] [[object.function]]
name = "send_rtcp" name = "send_rtcp"
[object.function.return] [object.function.return]

View file

@ -87,22 +87,16 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
// Add a handler to the "new-sample" signal. // Add a handler to the "new-sample" signal.
.new_sample(|appsink| { .new_sample(|appsink| {
// Pull the sample in question out of the appsink's buffer. // Pull the sample in question out of the appsink's buffer.
let sample = match appsink.pull_sample() { let sample = appsink.pull_sample().ok_or(gst::FlowError::Eos)?;
None => return gst::FlowReturn::Eos, let buffer = sample.get_buffer().ok_or_else(|| {
Some(sample) => sample,
};
let buffer = if let Some(buffer) = sample.get_buffer() {
buffer
} else {
gst_element_error!( gst_element_error!(
appsink, appsink,
gst::ResourceError::Failed, gst::ResourceError::Failed,
("Failed to get buffer from appsink") ("Failed to get buffer from appsink")
); );
return gst::FlowReturn::Error; gst::FlowError::Error
}; })?;
// At this point, buffer is only a reference to an existing memory region somewhere. // At this point, buffer is only a reference to an existing memory region somewhere.
// When we want to access its content, we have to map it while requesting the required // When we want to access its content, we have to map it while requesting the required
@ -111,32 +105,28 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
// on the machine's main memory itself, but rather in the GPU's memory. // on the machine's main memory itself, but rather in the GPU's memory.
// So mapping the buffer makes the underlying memory region accessible to us. // So mapping the buffer makes the underlying memory region accessible to us.
// See: https://gstreamer.freedesktop.org/documentation/plugin-development/advanced/allocation.html // See: https://gstreamer.freedesktop.org/documentation/plugin-development/advanced/allocation.html
let map = if let Some(map) = buffer.map_readable() { let map = buffer.map_readable().ok_or_else(|| {
map
} else {
gst_element_error!( gst_element_error!(
appsink, appsink,
gst::ResourceError::Failed, gst::ResourceError::Failed,
("Failed to map buffer readable") ("Failed to map buffer readable")
); );
return gst::FlowReturn::Error; gst::FlowError::Error
}; })?;
// We know what format the data in the memory region has, since we requested // We know what format the data in the memory region has, since we requested
// it by setting the appsink's caps. So what we do here is interpret the // it by setting the appsink's caps. So what we do here is interpret the
// memory region we mapped as an array of signed 16 bit integers. // memory region we mapped as an array of signed 16 bit integers.
let samples = if let Ok(samples) = map.as_slice_of::<i16>() { let samples = map.as_slice_of::<i16>().map_err(|_| {
samples
} else {
gst_element_error!( gst_element_error!(
appsink, appsink,
gst::ResourceError::Failed, gst::ResourceError::Failed,
("Failed to interprete buffer as S16 PCM") ("Failed to interprete buffer as S16 PCM")
); );
return gst::FlowReturn::Error; gst::FlowError::Error
}; })?;
// For buffer (= chunk of samples), we calculate the root mean square: // For buffer (= chunk of samples), we calculate the root mean square:
// (https://en.wikipedia.org/wiki/Root_mean_square) // (https://en.wikipedia.org/wiki/Root_mean_square)
@ -150,7 +140,7 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
let rms = (sum / (samples.len() as f64)).sqrt(); let rms = (sum / (samples.len() as f64)).sqrt();
println!("rms: {}", rms); println!("rms: {}", rms);
gst::FlowReturn::Ok Ok(gst::FlowSuccess::Ok)
}) })
.build(), .build(),
); );
@ -159,7 +149,7 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
} }
fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> { fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
pipeline.set_state(gst::State::Playing).into_result()?; pipeline.set_state(gst::State::Playing)?;
let bus = pipeline let bus = pipeline
.get_bus() .get_bus()
@ -171,7 +161,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
match msg.view() { match msg.view() {
MessageView::Eos(..) => break, MessageView::Eos(..) => break,
MessageView::Error(err) => { MessageView::Error(err) => {
pipeline.set_state(gst::State::Null).into_result()?; pipeline.set_state(gst::State::Null)?;
Err(ErrorMessage { Err(ErrorMessage {
src: msg src: msg
.get_src() .get_src()
@ -186,7 +176,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
} }
} }
pipeline.set_state(gst::State::Null).into_result()?; pipeline.set_state(gst::State::Null)?;
Ok(()) Ok(())
} }

View file

@ -141,7 +141,7 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
} }
fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> { fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
pipeline.set_state(gst::State::Playing).into_result()?; pipeline.set_state(gst::State::Playing)?;
let bus = pipeline let bus = pipeline
.get_bus() .get_bus()
@ -153,7 +153,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
match msg.view() { match msg.view() {
MessageView::Eos(..) => break, MessageView::Eos(..) => break,
MessageView::Error(err) => { MessageView::Error(err) => {
pipeline.set_state(gst::State::Null).into_result()?; pipeline.set_state(gst::State::Null)?;
Err(ErrorMessage { Err(ErrorMessage {
src: msg src: msg
.get_src() .get_src()
@ -168,7 +168,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
} }
} }
pipeline.set_state(gst::State::Null).into_result()?; pipeline.set_state(gst::State::Null)?;
Ok(()) Ok(())
} }

View file

@ -181,7 +181,7 @@ fn example_main() -> Result<(), Error> {
// Get the queue element's sink pad and link the decodebin's newly created // Get the queue element's sink pad and link the decodebin's newly created
// src pad for the audio stream to it. // src pad for the audio stream to it.
let sink_pad = queue.get_static_pad("sink").expect("queue has no sinkpad"); let sink_pad = queue.get_static_pad("sink").expect("queue has no sinkpad");
src_pad.link(&sink_pad).into_result()?; src_pad.link(&sink_pad)?;
} else if is_video { } else if is_video {
// decodebin found a raw videostream, so we build the follow-up pipeline to // decodebin found a raw videostream, so we build the follow-up pipeline to
// display it using the autovideosink. // display it using the autovideosink.
@ -205,7 +205,7 @@ fn example_main() -> Result<(), Error> {
// Get the queue element's sink pad and link the decodebin's newly created // Get the queue element's sink pad and link the decodebin's newly created
// src pad for the video stream to it. // src pad for the video stream to it.
let sink_pad = queue.get_static_pad("sink").expect("queue has no sinkpad"); let sink_pad = queue.get_static_pad("sink").expect("queue has no sinkpad");
src_pad.link(&sink_pad).into_result()?; src_pad.link(&sink_pad)?;
} }
Ok(()) Ok(())
@ -243,7 +243,7 @@ fn example_main() -> Result<(), Error> {
} }
}); });
pipeline.set_state(gst::State::Playing).into_result()?; pipeline.set_state(gst::State::Playing)?;
let bus = pipeline let bus = pipeline
.get_bus() .get_bus()
@ -259,7 +259,7 @@ fn example_main() -> Result<(), Error> {
match msg.view() { match msg.view() {
MessageView::Eos(..) => break, MessageView::Eos(..) => break,
MessageView::Error(err) => { MessageView::Error(err) => {
pipeline.set_state(gst::State::Null).into_result()?; pipeline.set_state(gst::State::Null)?;
#[cfg(feature = "v1_10")] #[cfg(feature = "v1_10")]
{ {
@ -313,7 +313,7 @@ fn example_main() -> Result<(), Error> {
} }
} }
pipeline.set_state(gst::State::Null).into_result()?; pipeline.set_state(gst::State::Null)?;
Ok(()) Ok(())
} }

View file

@ -210,7 +210,7 @@ fn example_main() -> Result<(), Error> {
let src_pad = resample let src_pad = resample
.get_static_pad("src") .get_static_pad("src")
.expect("resample has no srcpad"); .expect("resample has no srcpad");
src_pad.link(&enc_sink_pad).into_result()?; src_pad.link(&enc_sink_pad)?;
for e in elements { for e in elements {
e.sync_state_with_parent()?; e.sync_state_with_parent()?;
@ -219,7 +219,7 @@ fn example_main() -> Result<(), Error> {
// Get the queue element's sink pad and link the decodebin's newly created // Get the queue element's sink pad and link the decodebin's newly created
// src pad for the audio stream to it. // src pad for the audio stream to it.
let sink_pad = queue.get_static_pad("sink").expect("queue has no sinkpad"); let sink_pad = queue.get_static_pad("sink").expect("queue has no sinkpad");
dbin_src_pad.link(&sink_pad).into_result()?; dbin_src_pad.link(&sink_pad)?;
} else if is_video { } else if is_video {
let queue = let queue =
gst::ElementFactory::make("queue", None).ok_or(MissingElement("queue"))?; gst::ElementFactory::make("queue", None).ok_or(MissingElement("queue"))?;
@ -243,7 +243,7 @@ fn example_main() -> Result<(), Error> {
let src_pad = scale let src_pad = scale
.get_static_pad("src") .get_static_pad("src")
.expect("videoscale has no srcpad"); .expect("videoscale has no srcpad");
src_pad.link(&enc_sink_pad).into_result()?; src_pad.link(&enc_sink_pad)?;
for e in elements { for e in elements {
e.sync_state_with_parent()? e.sync_state_with_parent()?
@ -252,7 +252,7 @@ fn example_main() -> Result<(), Error> {
// Get the queue element's sink pad and link the decodebin's newly created // Get the queue element's sink pad and link the decodebin's newly created
// src pad for the video stream to it. // src pad for the video stream to it.
let sink_pad = queue.get_static_pad("sink").expect("queue has no sinkpad"); let sink_pad = queue.get_static_pad("sink").expect("queue has no sinkpad");
dbin_src_pad.link(&sink_pad).into_result()?; dbin_src_pad.link(&sink_pad)?;
} }
Ok(()) Ok(())
@ -280,7 +280,7 @@ fn example_main() -> Result<(), Error> {
} }
}); });
pipeline.set_state(gst::State::Playing).into_result()?; pipeline.set_state(gst::State::Playing)?;
let bus = pipeline let bus = pipeline
.get_bus() .get_bus()
@ -292,7 +292,7 @@ fn example_main() -> Result<(), Error> {
match msg.view() { match msg.view() {
MessageView::Eos(..) => break, MessageView::Eos(..) => break,
MessageView::Error(err) => { MessageView::Error(err) => {
pipeline.set_state(gst::State::Null).into_result()?; pipeline.set_state(gst::State::Null)?;
#[cfg(feature = "v1_10")] #[cfg(feature = "v1_10")]
{ {
@ -342,7 +342,7 @@ fn example_main() -> Result<(), Error> {
} }
} }
pipeline.set_state(gst::State::Null).into_result()?; pipeline.set_state(gst::State::Null)?;
Ok(()) Ok(())
} }

View file

@ -36,8 +36,9 @@ fn example_main() {
let pipeline = gst::parse_launch("audiotestsrc ! fakesink").unwrap(); let pipeline = gst::parse_launch("audiotestsrc ! fakesink").unwrap();
let bus = pipeline.get_bus().unwrap(); let bus = pipeline.get_bus().unwrap();
let ret = pipeline.set_state(gst::State::Playing); pipeline
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Playing)
.expect("Unable to set the pipeline to the `Playing` state");
// Need to move a new reference into the closure. // Need to move a new reference into the closure.
// !!ATTENTION!!: // !!ATTENTION!!:
@ -122,8 +123,9 @@ fn example_main() {
// (see above for how to do this). // (see above for how to do this).
main_loop.run(); main_loop.run();
let ret = pipeline.set_state(gst::State::Null); pipeline
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Null)
.expect("Unable to set the pipeline to the `Null` state");
// Remove the watch function from the bus. // Remove the watch function from the bus.
// Again: There can always only be one watch function. // Again: There can always only be one watch function.

View file

@ -25,8 +25,9 @@ fn example_main() {
let pipeline = gst::parse_launch(&pipeline_str).unwrap(); let pipeline = gst::parse_launch(&pipeline_str).unwrap();
let bus = pipeline.get_bus().unwrap(); let bus = pipeline.get_bus().unwrap();
let ret = pipeline.set_state(gst::State::Playing); pipeline
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Playing)
.expect("Unable to set the pipeline to the `Playing` state");
// BusStream implements the Stream trait, but Stream::for_each is // BusStream implements the Stream trait, but Stream::for_each is
// calling a closure for each item and returns a Future that resolves // calling a closure for each item and returns a Future that resolves
@ -65,8 +66,9 @@ fn example_main() {
// Synchronously wait on the future we created above. // Synchronously wait on the future we created above.
let _ = block_on(messages); let _ = block_on(messages);
let ret = pipeline.set_state(gst::State::Null); pipeline
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Null)
.expect("Unable to set the pipeline to the `Null` state");
} }
fn main() { fn main() {

View file

@ -100,8 +100,9 @@ fn main_loop(uri: &str) -> Result<(), glib::BoolError> {
clip.set_inpoint(duration / 2); clip.set_inpoint(duration / 2);
clip.set_duration(duration / 4); clip.set_duration(duration / 4);
let ret = pipeline.set_state(gst::State::Playing); pipeline
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Playing)
.expect("Unable to set the pipeline to the `Playing` state");
let bus = pipeline.get_bus().unwrap(); let bus = pipeline.get_bus().unwrap();
for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
@ -122,8 +123,9 @@ fn main_loop(uri: &str) -> Result<(), glib::BoolError> {
} }
} }
let ret = pipeline.set_state(gst::State::Null); pipeline
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Null)
.expect("Unable to set the pipeline to the `Null` state");
Ok(()) Ok(())
} }

View file

@ -21,8 +21,9 @@ fn example_main() {
let pipeline = gst::parse_launch(&pipeline_str).unwrap(); let pipeline = gst::parse_launch(&pipeline_str).unwrap();
let bus = pipeline.get_bus().unwrap(); let bus = pipeline.get_bus().unwrap();
let ret = pipeline.set_state(gst::State::Playing); pipeline
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Playing)
.expect("Unable to set the pipeline to the `Playing` state");
let messages = gst::BusStream::new(&bus) let messages = gst::BusStream::new(&bus)
.for_each(|msg| { .for_each(|msg| {
@ -52,8 +53,9 @@ fn example_main() {
let _ = ctx.block_on(messages); let _ = ctx.block_on(messages);
let ret = pipeline.set_state(gst::State::Null); pipeline
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Null)
.expect("Unable to set the pipeline to the `Null` state");
} }
fn main() { fn main() {

View file

@ -428,34 +428,42 @@ impl App {
self.appsink.set_callbacks( self.appsink.set_callbacks(
gst_app::AppSinkCallbacks::new() gst_app::AppSinkCallbacks::new()
.new_sample(move |appsink| { .new_sample(move |appsink| {
let sample = match appsink.pull_sample() { let sample = appsink.pull_sample().ok_or(gst::FlowError::Eos)?;
None => return gst::FlowReturn::Eos,
Some(sample) => sample,
};
let buffer = sample.get_buffer(); let _buffer = sample.get_buffer().ok_or_else(|| {
let info = sample
.get_caps()
.and_then(|caps| gst_video::VideoInfo::from_caps(caps.as_ref()));
if buffer.is_none() || info.is_none() {
gst_element_error!( gst_element_error!(
appsink, appsink,
gst::ResourceError::Failed, gst::ResourceError::Failed,
("Failed to get buffer from appsink") ("Failed to get buffer from appsink")
); );
return gst::FlowReturn::Error; gst::FlowError::Error
}; })?;
match sender_clone.lock().unwrap().send(sample) { let _info = sample
Ok(_) => return gst::FlowReturn::Ok, .get_caps()
Err(_) => return gst::FlowReturn::Error, .and_then(|caps| gst_video::VideoInfo::from_caps(caps.as_ref()))
} .ok_or_else(|| {
gst_element_error!(
appsink,
gst::ResourceError::Failed,
("Failed to get video info from sample")
);
gst::FlowError::Error
})?;
sender_clone
.lock()
.unwrap()
.send(sample)
.map(|_| gst::FlowSuccess::Ok)
.map_err(|_| gst::FlowError::Error)
}) })
.build(), .build(),
); );
self.pipeline.set_state(gst::State::Playing).into_result()?; self.pipeline.set_state(gst::State::Playing)?;
Ok((bus_handler, receiver)) Ok((bus_handler, receiver))
} }
@ -576,7 +584,7 @@ fn main_loop(mut app: App) -> Result<(), Error> {
app.pipeline.send_event(gst::Event::new_eos().build()); app.pipeline.send_event(gst::Event::new_eos().build());
bus_handler.join().expect("Could join bus handler thread"); bus_handler.join().expect("Could join bus handler thread");
app.pipeline.set_state(gst::State::Null).into_result()?; app.pipeline.set_state(gst::State::Null)?;
Ok(()) Ok(())
} }

View file

@ -108,8 +108,9 @@ fn create_ui(app: &gtk::Application) {
let bus = pipeline.get_bus().unwrap(); let bus = pipeline.get_bus().unwrap();
let ret = pipeline.set_state(gst::State::Playing); pipeline
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Playing)
.expect("Unable to set the pipeline to the `Playing` state");
let app_weak = glib::SendWeakRef::from(app.downgrade()); let app_weak = glib::SendWeakRef::from(app.downgrade());
bus.add_watch(move |_, msg| { bus.add_watch(move |_, msg| {
@ -141,8 +142,9 @@ fn create_ui(app: &gtk::Application) {
// destroyed once the app is destroyed // destroyed once the app is destroyed
let timeout_id = RefCell::new(Some(timeout_id)); let timeout_id = RefCell::new(Some(timeout_id));
app.connect_shutdown(move |_| { app.connect_shutdown(move |_| {
let ret = pipeline.set_state(gst::State::Null); pipeline
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Null)
.expect("Unable to set the pipeline to the `Null` state");
bus.remove_watch(); bus.remove_watch();
if let Some(timeout_id) = timeout_id.borrow_mut().take() { if let Some(timeout_id) = timeout_id.borrow_mut().take() {

View file

@ -211,8 +211,9 @@ fn create_ui(app: &gtk::Application) {
let bus = pipeline.get_bus().unwrap(); let bus = pipeline.get_bus().unwrap();
let ret = pipeline.set_state(gst::State::Playing); pipeline
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Playing)
.expect("Unable to set the pipeline to the `Playing` state");
let app_weak = glib::SendWeakRef::from(app.downgrade()); let app_weak = glib::SendWeakRef::from(app.downgrade());
bus.add_watch(move |_, msg| { bus.add_watch(move |_, msg| {
@ -244,8 +245,9 @@ fn create_ui(app: &gtk::Application) {
// destroyed once the app is destroyed // destroyed once the app is destroyed
let timeout_id = RefCell::new(Some(timeout_id)); let timeout_id = RefCell::new(Some(timeout_id));
app.connect_shutdown(move |_| { app.connect_shutdown(move |_| {
let ret = pipeline.set_state(gst::State::Null); pipeline
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Null)
.expect("Unable to set the pipeline to the `Null` state");
bus.remove_watch(); bus.remove_watch();
if let Some(timeout_id) = timeout_id.borrow_mut().take() { if let Some(timeout_id) = timeout_id.borrow_mut().take() {

View file

@ -43,8 +43,9 @@ fn example_main() {
}; };
let bus = pipeline.get_bus().unwrap(); let bus = pipeline.get_bus().unwrap();
let ret = pipeline.set_state(gst::State::Playing); pipeline
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Playing)
.expect("Unable to set the pipeline to the `Playing` state");
for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
use gst::MessageView; use gst::MessageView;
@ -64,8 +65,9 @@ fn example_main() {
} }
} }
let ret = pipeline.set_state(gst::State::Null); pipeline
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Null)
.expect("Unable to set the pipeline to the `Null` state");
} }
fn main() { fn main() {

View file

@ -30,8 +30,9 @@ fn example_main() {
let pipeline = gst::parse_launch(&pipeline_str).unwrap(); let pipeline = gst::parse_launch(&pipeline_str).unwrap();
let bus = pipeline.get_bus().unwrap(); let bus = pipeline.get_bus().unwrap();
let ret = pipeline.set_state(gst::State::Playing); pipeline
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Playing)
.expect("Unable to set the pipeline to the `Playing` state");
let main_loop_clone = main_loop.clone(); let main_loop_clone = main_loop.clone();
@ -60,8 +61,9 @@ fn example_main() {
main_loop.run(); main_loop.run();
let ret = pipeline.set_state(gst::State::Null); pipeline
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Null)
.expect("Unable to set the pipeline to the `Null` state");
// Here we remove the bus watch we added above. This avoids a memory leak, that might // Here we remove the bus watch we added above. This avoids a memory leak, that might
// otherwise happen because we moved a strong reference (clone of main_loop) into the // otherwise happen because we moved a strong reference (clone of main_loop) into the

View file

@ -75,8 +75,9 @@ fn example_main() {
gst::PadProbeReturn::Ok gst::PadProbeReturn::Ok
}); });
let ret = pipeline.set_state(gst::State::Playing); pipeline
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Playing)
.expect("Unable to set the pipeline to the `Playing` state");
let bus = pipeline.get_bus().unwrap(); let bus = pipeline.get_bus().unwrap();
for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
@ -97,8 +98,9 @@ fn example_main() {
} }
} }
let ret = pipeline.set_state(gst::State::Null); pipeline
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Null)
.expect("Unable to set the pipeline to the `Null` state");
} }
fn main() { fn main() {

View file

@ -237,7 +237,7 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
} }
fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> { fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
pipeline.set_state(gst::State::Playing).into_result()?; pipeline.set_state(gst::State::Playing)?;
let bus = pipeline let bus = pipeline
.get_bus() .get_bus()
@ -249,7 +249,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
match msg.view() { match msg.view() {
MessageView::Eos(..) => break, MessageView::Eos(..) => break,
MessageView::Error(err) => { MessageView::Error(err) => {
pipeline.set_state(gst::State::Null).into_result()?; pipeline.set_state(gst::State::Null)?;
Err(ErrorMessage { Err(ErrorMessage {
src: msg src: msg
.get_src() .get_src()
@ -264,7 +264,7 @@ fn main_loop(pipeline: gst::Pipeline) -> Result<(), Error> {
} }
} }
pipeline.set_state(gst::State::Null).into_result()?; pipeline.set_state(gst::State::Null)?;
Ok(()) Ok(())
} }

View file

@ -103,8 +103,9 @@ fn example_main() {
// created from an element factory. // created from an element factory.
let bus = playbin.get_bus().unwrap(); let bus = playbin.get_bus().unwrap();
let ret = playbin.set_state(gst::State::Playing); playbin
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Playing)
.expect("Unable to set the pipeline to the `Playing` state");
for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
use gst::MessageView; use gst::MessageView;
@ -124,8 +125,9 @@ fn example_main() {
} }
} }
let ret = playbin.set_state(gst::State::Null); playbin
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Null)
.expect("Unable to set the pipeline to the `Null` state");
} }
fn main() { fn main() {

View file

@ -34,8 +34,9 @@ fn example_main() {
let pipeline = gst::parse_launch(&pipeline_str).unwrap(); let pipeline = gst::parse_launch(&pipeline_str).unwrap();
let bus = pipeline.get_bus().unwrap(); let bus = pipeline.get_bus().unwrap();
let ret = pipeline.set_state(gst::State::Playing); pipeline
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Playing)
.expect("Unable to set the pipeline to the `Playing` state");
// Need to move a new reference into the closure. // Need to move a new reference into the closure.
// !!ATTENTION!!: // !!ATTENTION!!:
@ -119,8 +120,9 @@ fn example_main() {
main_loop.run(); main_loop.run();
let ret = pipeline.set_state(gst::State::Null); pipeline
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Null)
.expect("Unable to set the pipeline to the `Null` state");
bus.remove_watch(); bus.remove_watch();
glib::source_remove(timeout_id); glib::source_remove(timeout_id);

View file

@ -84,7 +84,7 @@ fn connect_rtpbin_srcpad(src_pad: &gst::Pad, sink: &gst::Element) -> Result<(),
match pt { match pt {
96 => { 96 => {
let sinkpad = get_static_pad(sink, "sink")?; let sinkpad = get_static_pad(sink, "sink")?;
src_pad.link(&sinkpad).into_result()?; src_pad.link(&sinkpad)?;
Ok(()) Ok(())
} }
_ => Err(Error::from(UnknownPT(pt))), _ => Err(Error::from(UnknownPT(pt))),
@ -208,7 +208,7 @@ fn example_main() -> Result<(), Error> {
let srcpad = get_static_pad(&netsim, "src")?; let srcpad = get_static_pad(&netsim, "src")?;
let sinkpad = get_request_pad(&rtpbin, "recv_rtp_sink_0")?; let sinkpad = get_request_pad(&rtpbin, "recv_rtp_sink_0")?;
srcpad.link(&sinkpad).into_result()?; srcpad.link(&sinkpad)?;
let depay_weak = depay.downgrade(); let depay_weak = depay.downgrade();
rtpbin.connect_pad_added(move |rtpbin, src_pad| { rtpbin.connect_pad_added(move |rtpbin, src_pad| {
@ -246,8 +246,9 @@ fn example_main() -> Result<(), Error> {
.get_bus() .get_bus()
.expect("Pipeline without bus. Shouldn't happen!"); .expect("Pipeline without bus. Shouldn't happen!");
let ret = pipeline.set_state(gst::State::Playing); pipeline
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Playing)
.expect("Unable to set the pipeline to the `Playing` state");
for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
use gst::MessageView; use gst::MessageView;
@ -255,8 +256,9 @@ fn example_main() -> Result<(), Error> {
match msg.view() { match msg.view() {
MessageView::Eos(..) => break, MessageView::Eos(..) => break,
MessageView::Error(err) => { MessageView::Error(err) => {
let ret = pipeline.set_state(gst::State::Null); pipeline
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Null)
.expect("Unable to set the pipeline to the `Null` state");
return Err(ErrorMessage { return Err(ErrorMessage {
src: msg src: msg
@ -286,8 +288,9 @@ fn example_main() -> Result<(), Error> {
} }
} }
let ret = pipeline.set_state(gst::State::Null); pipeline
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Null)
.expect("Unable to set the pipeline to the `Null` state");
Ok(()) Ok(())
} }

View file

@ -74,7 +74,7 @@ fn get_request_pad(element: &gst::Element, pad_name: &'static str) -> Result<gst
fn connect_decodebin_pad(src_pad: &gst::Pad, sink: &gst::Element) -> Result<(), Error> { fn connect_decodebin_pad(src_pad: &gst::Pad, sink: &gst::Element) -> Result<(), Error> {
let sinkpad = get_static_pad(&sink, "sink")?; let sinkpad = get_static_pad(&sink, "sink")?;
src_pad.link(&sinkpad).into_result()?; src_pad.link(&sinkpad)?;
Ok(()) Ok(())
} }
@ -137,11 +137,11 @@ fn example_main() -> Result<(), Error> {
let srcpad = get_static_pad(&q2, "src")?; let srcpad = get_static_pad(&q2, "src")?;
let sinkpad = get_request_pad(&rtpbin, "send_rtp_sink_0")?; let sinkpad = get_request_pad(&rtpbin, "send_rtp_sink_0")?;
srcpad.link(&sinkpad).into_result()?; srcpad.link(&sinkpad)?;
let srcpad = get_static_pad(&rtpbin, "send_rtp_src_0")?; let srcpad = get_static_pad(&rtpbin, "send_rtp_src_0")?;
let sinkpad = get_static_pad(&sink, "sink")?; let sinkpad = get_static_pad(&sink, "sink")?;
srcpad.link(&sinkpad).into_result()?; srcpad.link(&sinkpad)?;
let convclone = conv.clone(); let convclone = conv.clone();
src.connect_pad_added(move |decodebin, src_pad| { src.connect_pad_added(move |decodebin, src_pad| {
@ -177,8 +177,9 @@ fn example_main() -> Result<(), Error> {
.get_bus() .get_bus()
.expect("Pipeline without bus. Shouldn't happen!"); .expect("Pipeline without bus. Shouldn't happen!");
let ret = pipeline.set_state(gst::State::Playing); pipeline
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Playing)
.expect("Unable to set the pipeline to the `Playing` state");
for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
use gst::MessageView; use gst::MessageView;
@ -186,8 +187,9 @@ fn example_main() -> Result<(), Error> {
match msg.view() { match msg.view() {
MessageView::Eos(..) => break, MessageView::Eos(..) => break,
MessageView::Error(err) => { MessageView::Error(err) => {
let ret = pipeline.set_state(gst::State::Null); pipeline
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Null)
.expect("Unable to set the pipeline to the `Null` state");
return Err(ErrorMessage { return Err(ErrorMessage {
src: msg src: msg
@ -217,8 +219,9 @@ fn example_main() -> Result<(), Error> {
} }
} }
let ret = pipeline.set_state(gst::State::Null); pipeline
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Null)
.expect("Unable to set the pipeline to the `Null` state");
Ok(()) Ok(())
} }

View file

@ -94,7 +94,7 @@ fn example_main() -> Result<(), Error> {
let bus = pipeline.get_bus().unwrap(); let bus = pipeline.get_bus().unwrap();
pipeline.set_state(gst::State::Playing).into_result()?; pipeline.set_state(gst::State::Playing)?;
for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
use gst::MessageView; use gst::MessageView;
@ -118,7 +118,7 @@ fn example_main() -> Result<(), Error> {
} }
} }
pipeline.set_state(gst::State::Null).into_result()?; pipeline.set_state(gst::State::Null)?;
Ok(()) Ok(())
} }

View file

@ -75,13 +75,14 @@ fn example_main() {
} }
let sink_pad = queue.get_static_pad("sink").unwrap(); let sink_pad = queue.get_static_pad("sink").unwrap();
assert_eq!(src_pad.link(&sink_pad), gst::PadLinkReturn::Ok); src_pad
.link(&sink_pad)
.expect("Unable to link src pad to sink pad");
}); });
assert_ne!( pipeline
pipeline.set_state(gst::State::Paused), .set_state(gst::State::Paused)
gst::StateChangeReturn::Failure .expect("Unable to set the pipeline to the `Paused` state");
);
let bus = pipeline.get_bus().unwrap(); let bus = pipeline.get_bus().unwrap();
@ -161,10 +162,9 @@ fn example_main() {
} }
} }
assert_ne!( pipeline
pipeline.set_state(gst::State::Null), .set_state(gst::State::Null)
gst::StateChangeReturn::Failure .expect("Unable to set the pipeline to the `Null` state");
);
} }
fn main() { fn main() {

View file

@ -153,7 +153,7 @@ fn example_main() -> Result<(), Error> {
}) })
.expect("Failed to register have-type signal of typefind"); .expect("Failed to register have-type signal of typefind");
pipeline.set_state(gst::State::Playing).into_result()?; pipeline.set_state(gst::State::Playing)?;
let bus = pipeline let bus = pipeline
.get_bus() .get_bus()
@ -165,7 +165,7 @@ fn example_main() -> Result<(), Error> {
match msg.view() { match msg.view() {
MessageView::Eos(..) => break, MessageView::Eos(..) => break,
MessageView::Error(err) => { MessageView::Error(err) => {
pipeline.set_state(gst::State::Null).into_result()?; pipeline.set_state(gst::State::Null)?;
Err(ErrorMessage { Err(ErrorMessage {
src: msg src: msg
@ -191,7 +191,7 @@ fn example_main() -> Result<(), Error> {
} }
} }
pipeline.set_state(gst::State::Null).into_result()?; pipeline.set_state(gst::State::Null)?;
Ok(()) Ok(())
} }
@ -209,7 +209,7 @@ fn handle_demux_pad_added(
let queue_sink_pad = queue let queue_sink_pad = queue
.get_request_pad("sink_%u") .get_request_pad("sink_%u")
.expect("If this happened, something is terribly wrong"); .expect("If this happened, something is terribly wrong");
demux_src_pad.link(&queue_sink_pad).into_result()?; demux_src_pad.link(&queue_sink_pad)?;
// Now that we requested a sink pad fitting our needs from the multiqueue, // Now that we requested a sink pad fitting our needs from the multiqueue,
// the multiqueue automatically created a fitting src pad on the other side. // the multiqueue automatically created a fitting src pad on the other side.
// sink and src pad are linked internally, so we can iterate this internal link chain // sink and src pad are linked internally, so we can iterate this internal link chain
@ -224,7 +224,7 @@ fn handle_demux_pad_added(
let muxer_sink_pad = muxer let muxer_sink_pad = muxer
.get_compatible_pad(&queue_src_pad, None) .get_compatible_pad(&queue_src_pad, None)
.expect("Aww, you found a format that matroska doesn't support!"); .expect("Aww, you found a format that matroska doesn't support!");
queue_src_pad.link(&muxer_sink_pad).into_result()?; queue_src_pad.link(&muxer_sink_pad)?;
Ok(()) Ok(())
}; };

View file

@ -7,19 +7,27 @@
// except according to those terms. // except according to those terms.
use ffi; use ffi;
use glib::signal::connect_raw;
use glib::signal::SignalHandlerId;
use glib::translate::*; use glib::translate::*;
use glib_ffi::gpointer; use glib_ffi::gpointer;
use gst; use gst;
use gst_ffi; use gst_ffi;
use std::boxed::Box as Box_;
use std::cell::RefCell; use std::cell::RefCell;
use std::mem::transmute;
use std::ptr; use std::ptr;
use AppSink; use AppSink;
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))] #[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
pub struct AppSinkCallbacks { pub struct AppSinkCallbacks {
eos: Option<RefCell<Box<FnMut(&AppSink) + Send + 'static>>>, eos: Option<RefCell<Box<FnMut(&AppSink) + Send + 'static>>>,
new_preroll: Option<RefCell<Box<FnMut(&AppSink) -> gst::FlowReturn + Send + 'static>>>, new_preroll: Option<
new_sample: Option<RefCell<Box<FnMut(&AppSink) -> gst::FlowReturn + Send + 'static>>>, RefCell<Box<FnMut(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError> + Send + 'static>>,
>,
new_sample: Option<
RefCell<Box<FnMut(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError> + Send + 'static>>,
>,
callbacks: ffi::GstAppSinkCallbacks, callbacks: ffi::GstAppSinkCallbacks,
} }
@ -40,8 +48,12 @@ impl AppSinkCallbacks {
#[cfg_attr(feature = "cargo-clippy", allow(type_complexity))] #[cfg_attr(feature = "cargo-clippy", allow(type_complexity))]
pub struct AppSinkCallbacksBuilder { pub struct AppSinkCallbacksBuilder {
eos: Option<RefCell<Box<FnMut(&AppSink) + Send + 'static>>>, eos: Option<RefCell<Box<FnMut(&AppSink) + Send + 'static>>>,
new_preroll: Option<RefCell<Box<FnMut(&AppSink) -> gst::FlowReturn + Send + 'static>>>, new_preroll: Option<
new_sample: Option<RefCell<Box<FnMut(&AppSink) -> gst::FlowReturn + Send + 'static>>>, RefCell<Box<FnMut(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError> + Send + 'static>>,
>,
new_sample: Option<
RefCell<Box<FnMut(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError> + Send + 'static>>,
>,
} }
impl AppSinkCallbacksBuilder { impl AppSinkCallbacksBuilder {
@ -52,7 +64,9 @@ impl AppSinkCallbacksBuilder {
} }
} }
pub fn new_preroll<F: Fn(&AppSink) -> gst::FlowReturn + Send + Sync + 'static>( pub fn new_preroll<
F: Fn(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError> + Send + Sync + 'static,
>(
self, self,
new_preroll: F, new_preroll: F,
) -> Self { ) -> Self {
@ -62,7 +76,9 @@ impl AppSinkCallbacksBuilder {
} }
} }
pub fn new_sample<F: Fn(&AppSink) -> gst::FlowReturn + Send + Sync + 'static>( pub fn new_sample<
F: Fn(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError> + Send + Sync + 'static,
>(
self, self,
new_sample: F, new_sample: F,
) -> Self { ) -> Self {
@ -119,7 +135,7 @@ unsafe extern "C" fn trampoline_new_preroll(
let callbacks = &*(callbacks as *const AppSinkCallbacks); let callbacks = &*(callbacks as *const AppSinkCallbacks);
let ret = if let Some(ref new_preroll) = callbacks.new_preroll { let ret = if let Some(ref new_preroll) = callbacks.new_preroll {
(&mut *new_preroll.borrow_mut())(&from_glib_borrow(appsink)) (&mut *new_preroll.borrow_mut())(&from_glib_borrow(appsink)).into()
} else { } else {
gst::FlowReturn::Error gst::FlowReturn::Error
}; };
@ -134,7 +150,7 @@ unsafe extern "C" fn trampoline_new_sample(
let callbacks = &*(callbacks as *const AppSinkCallbacks); let callbacks = &*(callbacks as *const AppSinkCallbacks);
let ret = if let Some(ref new_sample) = callbacks.new_sample { let ret = if let Some(ref new_sample) = callbacks.new_sample {
(&mut *new_sample.borrow_mut())(&from_glib_borrow(appsink)) (&mut *new_sample.borrow_mut())(&from_glib_borrow(appsink)).into()
} else { } else {
gst::FlowReturn::Error gst::FlowReturn::Error
}; };
@ -157,4 +173,72 @@ impl AppSink {
); );
} }
} }
pub fn connect_new_sample<
F: Fn(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError> + Send + Sync + 'static,
>(
&self,
f: F,
) -> SignalHandlerId {
unsafe {
let f: Box_<
Box_<
Fn(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError>
+ Send
+ Sync
+ 'static,
>,
> = Box_::new(Box_::new(f));
connect_raw(
self.to_glib_none().0,
b"new-sample\0".as_ptr() as *const _,
transmute(new_sample_trampoline as usize),
Box_::into_raw(f) as *mut _,
)
}
}
pub fn connect_new_preroll<
F: Fn(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError> + Send + Sync + 'static,
>(
&self,
f: F,
) -> SignalHandlerId {
unsafe {
let f: Box_<
Box_<
Fn(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError>
+ Send
+ Sync
+ 'static,
>,
> = Box_::new(Box_::new(f));
connect_raw(
self.to_glib_none().0,
b"new-preroll\0".as_ptr() as *const _,
transmute(new_preroll_trampoline as usize),
Box_::into_raw(f) as *mut _,
)
}
}
}
unsafe extern "C" fn new_sample_trampoline(
this: *mut ffi::GstAppSink,
f: glib_ffi::gpointer,
) -> gst_ffi::GstFlowReturn {
let f: &&(Fn(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError> + Send + Sync + 'static) =
transmute(f);
let ret: gst::FlowReturn = f(&from_glib_borrow(this)).into();
ret.to_glib()
}
unsafe extern "C" fn new_preroll_trampoline(
this: *mut ffi::GstAppSink,
f: glib_ffi::gpointer,
) -> gst_ffi::GstFlowReturn {
let f: &&(Fn(&AppSink) -> Result<gst::FlowSuccess, gst::FlowError> + Send + Sync + 'static) =
transmute(f);
let ret: gst::FlowReturn = f(&from_glib_borrow(this)).into();
ret.to_glib()
} }

View file

@ -147,23 +147,44 @@ unsafe extern "C" fn destroy_callbacks(ptr: gpointer) {
} }
impl AppSrc { impl AppSrc {
pub fn push_buffer(&self, buffer: gst::Buffer) -> gst::FlowReturn { pub fn end_of_stream(&self) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe { 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> {
let ret: gst::FlowReturn = unsafe {
from_glib(ffi::gst_app_src_push_buffer( 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"))]
pub fn push_buffer_list(&self, list: gst::BufferList) -> gst::FlowReturn { pub fn push_buffer_list(
unsafe { &self,
list: gst::BufferList,
) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe {
from_glib(ffi::gst_app_src_push_buffer_list( 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

@ -173,22 +173,6 @@ impl AppSink {
} }
} }
pub fn connect_new_preroll<F: Fn(&AppSink) -> gst::FlowReturn + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<Box_<Fn(&AppSink) -> gst::FlowReturn + Send + Sync + 'static>> = Box_::new(Box_::new(f));
connect_raw(self.to_glib_none().0, b"new-preroll\0".as_ptr() as *const _,
transmute(new_preroll_trampoline as usize), Box_::into_raw(f) as *mut _)
}
}
pub fn connect_new_sample<F: Fn(&AppSink) -> gst::FlowReturn + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
unsafe {
let f: Box_<Box_<Fn(&AppSink) -> gst::FlowReturn + Send + Sync + 'static>> = Box_::new(Box_::new(f));
connect_raw(self.to_glib_none().0, b"new-sample\0".as_ptr() as *const _,
transmute(new_sample_trampoline as usize), Box_::into_raw(f) as *mut _)
}
}
pub fn connect_property_buffer_list_notify<F: Fn(&AppSink) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId { pub fn connect_property_buffer_list_notify<F: Fn(&AppSink) + Send + Sync + 'static>(&self, f: F) -> SignalHandlerId {
unsafe { unsafe {
let f: Box_<Box_<Fn(&AppSink) + Send + Sync + 'static>> = Box_::new(Box_::new(f)); let f: Box_<Box_<Fn(&AppSink) + Send + Sync + 'static>> = Box_::new(Box_::new(f));
@ -254,16 +238,6 @@ unsafe extern "C" fn eos_trampoline(this: *mut ffi::GstAppSink, f: glib_ffi::gpo
f(&from_glib_borrow(this)) f(&from_glib_borrow(this))
} }
unsafe extern "C" fn new_preroll_trampoline(this: *mut ffi::GstAppSink, f: glib_ffi::gpointer) -> gst_ffi::GstFlowReturn {
let f: &&(Fn(&AppSink) -> gst::FlowReturn + Send + Sync + 'static) = transmute(f);
f(&from_glib_borrow(this)).to_glib()
}
unsafe extern "C" fn new_sample_trampoline(this: *mut ffi::GstAppSink, f: glib_ffi::gpointer) -> gst_ffi::GstFlowReturn {
let f: &&(Fn(&AppSink) -> gst::FlowReturn + Send + Sync + 'static) = transmute(f);
f(&from_glib_borrow(this)).to_glib()
}
unsafe extern "C" fn notify_buffer_list_trampoline(this: *mut ffi::GstAppSink, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer) { unsafe extern "C" fn notify_buffer_list_trampoline(this: *mut ffi::GstAppSink, _param_spec: glib_ffi::gpointer, f: glib_ffi::gpointer) {
let f: &&(Fn(&AppSink) + Send + Sync + 'static) = transmute(f); let f: &&(Fn(&AppSink) + Send + Sync + 'static) = transmute(f);
f(&from_glib_borrow(this)) f(&from_glib_borrow(this))

View file

@ -33,12 +33,6 @@ glib_wrapper! {
} }
impl AppSrc { impl AppSrc {
pub fn end_of_stream(&self) -> gst::FlowReturn {
unsafe {
from_glib(ffi::gst_app_src_end_of_stream(self.to_glib_none().0))
}
}
pub fn get_caps(&self) -> Option<gst::Caps> { pub fn get_caps(&self) -> Option<gst::Caps> {
unsafe { unsafe {
from_glib_full(ffi::gst_app_src_get_caps(self.to_glib_none().0)) from_glib_full(ffi::gst_app_src_get_caps(self.to_glib_none().0))
@ -82,12 +76,6 @@ impl AppSrc {
} }
} }
pub fn push_sample(&self, sample: &gst::Sample) -> gst::FlowReturn {
unsafe {
from_glib(ffi::gst_app_src_push_sample(self.to_glib_none().0, sample.to_glib_none().0))
}
}
//pub fn set_callbacks(&self, callbacks: /*Ignored*/&mut AppSrcCallbacks, notify: /*Unknown conversion*//*Unimplemented*/DestroyNotify) { //pub fn set_callbacks(&self, callbacks: /*Ignored*/&mut AppSrcCallbacks, notify: /*Unknown conversion*//*Unimplemented*/DestroyNotify) {
// unsafe { TODO: call ffi::gst_app_src_set_callbacks() } // unsafe { TODO: call ffi::gst_app_src_set_callbacks() }
//} //}

View file

@ -15,17 +15,18 @@ use Aggregator;
use std::ops; use std::ops;
pub trait AggregatorExtManual: 'static { pub trait AggregatorExtManual: 'static {
fn finish_buffer(&self, buffer: gst::Buffer) -> gst::FlowReturn; fn finish_buffer(&self, buffer: gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError>;
} }
impl<O: IsA<Aggregator>> AggregatorExtManual for O { impl<O: IsA<Aggregator>> AggregatorExtManual for O {
fn finish_buffer(&self, buffer: gst::Buffer) -> gst::FlowReturn { fn finish_buffer(&self, buffer: gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe { let ret: gst::FlowReturn = unsafe {
from_glib(ffi::gst_aggregator_finish_buffer( from_glib(ffi::gst_aggregator_finish_buffer(
self.to_glib_none().0, self.to_glib_none().0,
buffer.into_ptr(), buffer.into_ptr(),
)) ))
} };
ret.into_result()
} }
} }

View file

@ -88,12 +88,8 @@ pub trait BaseSinkExt: 'static {
fn set_ts_offset(&self, offset: gst::ClockTimeDiff); fn set_ts_offset(&self, offset: gst::ClockTimeDiff);
fn wait(&self, time: gst::ClockTime) -> (gst::FlowReturn, gst::ClockTimeDiff);
fn wait_clock(&self, time: gst::ClockTime) -> (gst::ClockReturn, gst::ClockTimeDiff); fn wait_clock(&self, time: gst::ClockTime) -> (gst::ClockReturn, gst::ClockTimeDiff);
fn wait_preroll(&self) -> gst::FlowReturn;
fn get_property_async(&self) -> bool; fn get_property_async(&self) -> bool;
fn set_property_async(&self, async: bool); fn set_property_async(&self, async: bool);
@ -291,14 +287,6 @@ impl<O: IsA<BaseSink>> BaseSinkExt for O {
} }
} }
fn wait(&self, time: gst::ClockTime) -> (gst::FlowReturn, gst::ClockTimeDiff) {
unsafe {
let mut jitter = mem::uninitialized();
let ret = from_glib(ffi::gst_base_sink_wait(self.to_glib_none().0, time.to_glib(), &mut jitter));
(ret, jitter)
}
}
fn wait_clock(&self, time: gst::ClockTime) -> (gst::ClockReturn, gst::ClockTimeDiff) { fn wait_clock(&self, time: gst::ClockTime) -> (gst::ClockReturn, gst::ClockTimeDiff) {
unsafe { unsafe {
let mut jitter = mem::uninitialized(); let mut jitter = mem::uninitialized();
@ -307,12 +295,6 @@ impl<O: IsA<BaseSink>> BaseSinkExt for O {
} }
} }
fn wait_preroll(&self) -> gst::FlowReturn {
unsafe {
from_glib(ffi::gst_base_sink_wait_preroll(self.to_glib_none().0))
}
}
fn get_property_async(&self) -> bool { fn get_property_async(&self) -> bool {
unsafe { unsafe {
let mut value = Value::from_type(<bool as StaticType>::static_type()); let mut value = Value::from_type(<bool as StaticType>::static_type());

View file

@ -66,12 +66,6 @@ pub trait BaseSrcExt: 'static {
fn set_live(&self, live: bool); fn set_live(&self, live: bool);
fn start_complete(&self, ret: gst::FlowReturn);
fn start_wait(&self) -> gst::FlowReturn;
fn wait_playing(&self) -> gst::FlowReturn;
fn get_property_num_buffers(&self) -> i32; fn get_property_num_buffers(&self) -> i32;
fn set_property_num_buffers(&self, num_buffers: i32); fn set_property_num_buffers(&self, num_buffers: i32);
@ -188,24 +182,6 @@ impl<O: IsA<BaseSrc>> BaseSrcExt for O {
} }
} }
fn start_complete(&self, ret: gst::FlowReturn) {
unsafe {
ffi::gst_base_src_start_complete(self.to_glib_none().0, ret.to_glib());
}
}
fn start_wait(&self) -> gst::FlowReturn {
unsafe {
from_glib(ffi::gst_base_src_start_wait(self.to_glib_none().0))
}
}
fn wait_playing(&self) -> gst::FlowReturn {
unsafe {
from_glib(ffi::gst_base_src_wait_playing(self.to_glib_none().0))
}
}
fn get_property_num_buffers(&self) -> i32 { fn get_property_num_buffers(&self) -> i32 {
unsafe { unsafe {
let mut value = Value::from_type(<i32 as StaticType>::static_type()); let mut value = Value::from_type(<i32 as StaticType>::static_type());

View file

@ -10,11 +10,19 @@ use ffi;
use glib::translate::*; use glib::translate::*;
use glib::{IsA, IsClassFor}; use glib::{IsA, IsClassFor};
use gst; use gst;
use std::mem;
use std::ops; use std::ops;
use BaseSink; use BaseSink;
pub trait BaseSinkExtManual: 'static { pub trait BaseSinkExtManual: 'static {
fn get_segment(&self) -> gst::Segment; fn get_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>;
} }
impl<O: IsA<BaseSink>> BaseSinkExtManual for O { impl<O: IsA<BaseSink>> BaseSinkExtManual for O {
@ -26,6 +34,27 @@ impl<O: IsA<BaseSink>> BaseSinkExtManual for O {
from_glib_none(&sink.segment as *const _) from_glib_none(&sink.segment as *const _)
} }
} }
fn wait(
&self,
time: gst::ClockTime,
) -> (Result<gst::FlowSuccess, gst::FlowError>, gst::ClockTimeDiff) {
unsafe {
let mut jitter = mem::uninitialized();
let ret: gst::FlowReturn = from_glib(ffi::gst_base_sink_wait(
self.to_glib_none().0,
time.to_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.to_glib_none().0)) };
ret.into_result()
}
} }
#[repr(C)] #[repr(C)]

View file

@ -15,6 +15,12 @@ use BaseSrc;
pub trait BaseSrcExtManual: 'static { pub trait BaseSrcExtManual: 'static {
fn get_segment(&self) -> gst::Segment; fn get_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>;
} }
impl<O: IsA<BaseSrc>> BaseSrcExtManual for O { impl<O: IsA<BaseSrc>> BaseSrcExtManual for O {
@ -26,6 +32,25 @@ impl<O: IsA<BaseSrc>> BaseSrcExtManual for O {
from_glib_none(&src.segment as *const _) from_glib_none(&src.segment as *const _)
} }
} }
fn start_complete(&self, ret: Result<gst::FlowSuccess, gst::FlowError>) {
let ret: gst::FlowReturn = ret.into();
unsafe {
ffi::gst_base_src_start_complete(self.to_glib_none().0, ret.to_glib());
}
}
fn start_wait(&self) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn =
unsafe { from_glib(ffi::gst_base_src_start_wait(self.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.to_glib_none().0)) };
ret.into_result()
}
} }
#[repr(C)] #[repr(C)]

View file

@ -57,27 +57,34 @@ impl FlowCombiner {
} }
} }
pub fn update_flow(&self, fret: gst::FlowReturn) -> gst::FlowReturn { pub fn update_flow<FRet: Into<gst::FlowReturn>>(
unsafe { &self,
fret: FRet,
) -> Result<gst::FlowSuccess, gst::FlowError> {
let fret: gst::FlowReturn = fret.into();
let ret: gst::FlowReturn = unsafe {
from_glib(ffi::gst_flow_combiner_update_flow( from_glib(ffi::gst_flow_combiner_update_flow(
self.to_glib_none().0, self.to_glib_none().0,
fret.to_glib(), fret.to_glib(),
)) ))
} };
ret.into_result()
} }
pub fn update_pad_flow<P: IsA<gst::Pad>>( pub fn update_pad_flow<P: IsA<gst::Pad>, FRet: Into<gst::FlowReturn>>(
&self, &self,
pad: &P, pad: &P,
fret: gst::FlowReturn, fret: FRet,
) -> gst::FlowReturn { ) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe { let fret: gst::FlowReturn = fret.into();
let ret: gst::FlowReturn = unsafe {
from_glib(ffi::gst_flow_combiner_update_pad_flow( from_glib(ffi::gst_flow_combiner_update_pad_flow(
self.to_glib_none().0, self.to_glib_none().0,
pad.to_glib_none().0, pad.to_glib_none().0,
fret.to_glib(), fret.to_glib(),
)) ))
} };
ret.into_result()
} }
} }
@ -114,15 +121,18 @@ impl UniqueFlowCombiner {
self.0.reset(); self.0.reset();
} }
pub fn update_flow(&mut self, fret: gst::FlowReturn) -> gst::FlowReturn { pub fn update_flow(
&mut self,
fret: Result<gst::FlowSuccess, gst::FlowError>,
) -> Result<gst::FlowSuccess, gst::FlowError> {
self.0.update_flow(fret) self.0.update_flow(fret)
} }
pub fn update_pad_flow<P: IsA<gst::Pad>>( pub fn update_pad_flow<P: IsA<gst::Pad>>(
&mut self, &mut self,
pad: &P, pad: &P,
fret: gst::FlowReturn, fret: Result<gst::FlowSuccess, gst::FlowError>,
) -> gst::FlowReturn { ) -> Result<gst::FlowSuccess, gst::FlowError> {
self.0.update_pad_flow(pad, fret) self.0.update_pad_flow(pad, fret)
} }
} }

View file

@ -26,7 +26,7 @@ use AggregatorClass;
use AggregatorPad; use AggregatorPad;
pub trait AggregatorImpl: ElementImpl + Send + Sync + 'static { pub trait AggregatorImpl: ElementImpl + Send + Sync + 'static {
fn flush(&self, aggregator: &Aggregator) -> gst::FlowReturn { fn flush(&self, aggregator: &Aggregator) -> Result<gst::FlowSuccess, gst::FlowError> {
self.parent_flush(aggregator) self.parent_flush(aggregator)
} }
@ -39,7 +39,11 @@ pub trait AggregatorImpl: ElementImpl + Send + Sync + 'static {
self.parent_clip(aggregator, aggregator_pad, buffer) self.parent_clip(aggregator, aggregator_pad, buffer)
} }
fn finish_buffer(&self, aggregator: &Aggregator, buffer: gst::Buffer) -> gst::FlowReturn { fn finish_buffer(
&self,
aggregator: &Aggregator,
buffer: gst::Buffer,
) -> Result<gst::FlowSuccess, gst::FlowError> {
self.parent_finish_buffer(aggregator, buffer) self.parent_finish_buffer(aggregator, buffer)
} }
@ -73,7 +77,11 @@ pub trait AggregatorImpl: ElementImpl + Send + Sync + 'static {
self.parent_src_activate(aggregator, mode, active) self.parent_src_activate(aggregator, mode, active)
} }
fn aggregate(&self, aggregator: &Aggregator, timeout: bool) -> gst::FlowReturn; fn aggregate(
&self,
aggregator: &Aggregator,
timeout: bool,
) -> Result<gst::FlowSuccess, gst::FlowError>;
fn start(&self, aggregator: &Aggregator) -> bool { fn start(&self, aggregator: &Aggregator) -> bool {
self.parent_start(aggregator) self.parent_start(aggregator)
@ -113,7 +121,7 @@ pub trait AggregatorImpl: ElementImpl + Send + Sync + 'static {
self.parent_negotiated_src_caps(aggregator, caps) self.parent_negotiated_src_caps(aggregator, caps)
} }
fn parent_flush(&self, aggregator: &Aggregator) -> gst::FlowReturn { fn parent_flush(&self, aggregator: &Aggregator) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe { unsafe {
let data = self.get_type_data(); let data = self.get_type_data();
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAggregatorClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAggregatorClass;
@ -121,6 +129,7 @@ pub trait AggregatorImpl: ElementImpl + Send + Sync + 'static {
.flush .flush
.map(|f| from_glib(f(aggregator.to_glib_none().0))) .map(|f| from_glib(f(aggregator.to_glib_none().0)))
.unwrap_or(gst::FlowReturn::Ok) .unwrap_or(gst::FlowReturn::Ok)
.into_result()
} }
} }
@ -148,7 +157,7 @@ pub trait AggregatorImpl: ElementImpl + Send + Sync + 'static {
&self, &self,
aggregator: &Aggregator, aggregator: &Aggregator,
buffer: gst::Buffer, buffer: gst::Buffer,
) -> gst::FlowReturn { ) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe { unsafe {
let data = self.get_type_data(); let data = self.get_type_data();
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAggregatorClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAggregatorClass;
@ -156,6 +165,7 @@ pub trait AggregatorImpl: ElementImpl + Send + Sync + 'static {
.finish_buffer .finish_buffer
.map(|f| from_glib(f(aggregator.to_glib_none().0, buffer.into_ptr()))) .map(|f| from_glib(f(aggregator.to_glib_none().0, buffer.into_ptr())))
.unwrap_or(gst::FlowReturn::Ok) .unwrap_or(gst::FlowReturn::Ok)
.into_result()
} }
} }
@ -247,7 +257,11 @@ pub trait AggregatorImpl: ElementImpl + Send + Sync + 'static {
} }
} }
fn parent_aggregate(&self, aggregator: &Aggregator, timeout: bool) -> gst::FlowReturn { fn parent_aggregate(
&self,
aggregator: &Aggregator,
timeout: bool,
) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe { unsafe {
let data = self.get_type_data(); let data = self.get_type_data();
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAggregatorClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAggregatorClass;
@ -255,6 +269,7 @@ pub trait AggregatorImpl: ElementImpl + Send + Sync + 'static {
.aggregate .aggregate
.map(|f| from_glib(f(aggregator.to_glib_none().0, timeout.to_glib()))) .map(|f| from_glib(f(aggregator.to_glib_none().0, timeout.to_glib())))
.unwrap_or(gst::FlowReturn::Error) .unwrap_or(gst::FlowReturn::Error)
.into_result()
} }
} }
@ -403,7 +418,7 @@ where
let wrap: Aggregator = from_glib_borrow(ptr); let wrap: Aggregator = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, { gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, {
imp.flush(&wrap) imp.flush(&wrap).into()
}) })
.to_glib() .to_glib()
} }
@ -447,7 +462,7 @@ where
let wrap: Aggregator = from_glib_borrow(ptr); let wrap: Aggregator = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, { gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, {
imp.finish_buffer(&wrap, from_glib_full(buffer)) imp.finish_buffer(&wrap, from_glib_full(buffer)).into()
}) })
.to_glib() .to_glib()
} }
@ -572,7 +587,7 @@ where
let wrap: Aggregator = from_glib_borrow(ptr); let wrap: Aggregator = from_glib_borrow(ptr);
gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, { gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, {
imp.aggregate(&wrap, from_glib(timeout)) imp.aggregate(&wrap, from_glib(timeout)).into()
}) })
.to_glib() .to_glib()
} }

View file

@ -22,7 +22,11 @@ use AggregatorPad;
use AggregatorPadClass; use AggregatorPadClass;
pub trait AggregatorPadImpl: PadImpl + Send + Sync + 'static { pub trait AggregatorPadImpl: PadImpl + Send + Sync + 'static {
fn flush(&self, aggregator_pad: &AggregatorPad, aggregator: &Aggregator) -> gst::FlowReturn { fn flush(
&self,
aggregator_pad: &AggregatorPad,
aggregator: &Aggregator,
) -> Result<gst::FlowSuccess, gst::FlowError> {
self.parent_flush(aggregator_pad, aggregator) self.parent_flush(aggregator_pad, aggregator)
} }
@ -39,7 +43,7 @@ pub trait AggregatorPadImpl: PadImpl + Send + Sync + 'static {
&self, &self,
aggregator_pad: &AggregatorPad, aggregator_pad: &AggregatorPad,
aggregator: &Aggregator, aggregator: &Aggregator,
) -> gst::FlowReturn { ) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe { unsafe {
let data = self.get_type_data(); let data = self.get_type_data();
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAggregatorPadClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstAggregatorPadClass;
@ -52,6 +56,7 @@ pub trait AggregatorPadImpl: PadImpl + Send + Sync + 'static {
)) ))
}) })
.unwrap_or(gst::FlowReturn::Ok) .unwrap_or(gst::FlowReturn::Ok)
.into_result()
} }
} }
@ -101,7 +106,8 @@ where
let imp = instance.get_impl(); let imp = instance.get_impl();
let wrap: AggregatorPad = from_glib_borrow(ptr); let wrap: AggregatorPad = from_glib_borrow(ptr);
imp.flush(&wrap, &from_glib_borrow(aggregator)).to_glib() let res: gst::FlowReturn = imp.flush(&wrap, &from_glib_borrow(aggregator)).into();
res.to_glib()
} }
unsafe extern "C" fn aggregator_pad_skip_buffer<T: ObjectSubclass>( unsafe extern "C" fn aggregator_pad_skip_buffer<T: ObjectSubclass>(

View file

@ -31,32 +31,40 @@ pub trait BaseSinkImpl: ElementImpl + Send + Sync + 'static {
true true
} }
fn render(&self, element: &BaseSink, buffer: &gst::BufferRef) -> gst::FlowReturn; fn render(
&self,
element: &BaseSink,
buffer: &gst::BufferRef,
) -> Result<gst::FlowSuccess, gst::FlowError>;
fn prepare(&self, _element: &BaseSink, _buffer: &gst::BufferRef) -> gst::FlowReturn { fn prepare(
gst::FlowReturn::Ok &self,
_element: &BaseSink,
_buffer: &gst::BufferRef,
) -> Result<gst::FlowSuccess, gst::FlowError> {
Ok(gst::FlowSuccess::Ok)
} }
fn render_list(&self, element: &BaseSink, list: &gst::BufferListRef) -> gst::FlowReturn { fn render_list(
&self,
element: &BaseSink,
list: &gst::BufferListRef,
) -> Result<gst::FlowSuccess, gst::FlowError> {
for buffer in list.iter() { for buffer in list.iter() {
let ret = self.render(element, buffer); self.render(element, buffer)?;
if ret != gst::FlowReturn::Ok {
return ret;
} }
Ok(gst::FlowSuccess::Ok)
} }
gst::FlowReturn::Ok fn prepare_list(
} &self,
element: &BaseSink,
fn prepare_list(&self, element: &BaseSink, list: &gst::BufferListRef) -> gst::FlowReturn { list: &gst::BufferListRef,
) -> Result<gst::FlowSuccess, gst::FlowError> {
for buffer in list.iter() { for buffer in list.iter() {
let ret = self.prepare(element, buffer); self.prepare(element, buffer)?;
if ret != gst::FlowReturn::Ok {
return ret;
} }
} Ok(gst::FlowSuccess::Ok)
gst::FlowReturn::Ok
} }
fn query(&self, element: &BaseSink, query: &mut gst::QueryRef) -> bool { fn query(&self, element: &BaseSink, query: &mut gst::QueryRef) -> bool {
@ -224,7 +232,7 @@ where
let buffer = gst::BufferRef::from_ptr(buffer); let buffer = gst::BufferRef::from_ptr(buffer);
gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, { gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, {
imp.render(&wrap, buffer) imp.render(&wrap, buffer).into()
}) })
.to_glib() .to_glib()
} }
@ -244,7 +252,7 @@ where
let buffer = gst::BufferRef::from_ptr(buffer); let buffer = gst::BufferRef::from_ptr(buffer);
gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, { gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, {
imp.prepare(&wrap, buffer) imp.prepare(&wrap, buffer).into()
}) })
.to_glib() .to_glib()
} }
@ -264,7 +272,7 @@ where
let list = gst::BufferListRef::from_ptr(list); let list = gst::BufferListRef::from_ptr(list);
gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, { gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, {
imp.render_list(&wrap, list) imp.render_list(&wrap, list).into()
}) })
.to_glib() .to_glib()
} }
@ -284,7 +292,7 @@ where
let list = gst::BufferListRef::from_ptr(list); let list = gst::BufferListRef::from_ptr(list);
gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, { gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, {
imp.prepare_list(&wrap, list) imp.prepare_list(&wrap, list).into()
}) })
.to_glib() .to_glib()
} }

View file

@ -45,7 +45,7 @@ pub trait BaseSrcImpl: ElementImpl + Send + Sync + 'static {
_offset: u64, _offset: u64,
_length: u32, _length: u32,
_buffer: &mut gst::BufferRef, _buffer: &mut gst::BufferRef,
) -> gst::FlowReturn { ) -> Result<gst::FlowSuccess, gst::FlowError> {
unimplemented!() unimplemented!()
} }
@ -325,7 +325,7 @@ where
let buffer = gst::BufferRef::from_mut_ptr(buffer); let buffer = gst::BufferRef::from_mut_ptr(buffer);
gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, { gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, {
imp.fill(&wrap, offset, length, buffer) imp.fill(&wrap, offset, length, buffer).into()
}) })
.to_glib() .to_glib()
} }

View file

@ -104,11 +104,15 @@ pub trait BaseTransformImpl: ElementImpl + Send + Sync + 'static {
_element: &BaseTransform, _element: &BaseTransform,
_inbuf: &gst::Buffer, _inbuf: &gst::Buffer,
_outbuf: &mut gst::BufferRef, _outbuf: &mut gst::BufferRef,
) -> gst::FlowReturn { ) -> Result<gst::FlowSuccess, gst::FlowError> {
unimplemented!(); unimplemented!();
} }
fn transform_ip(&self, _element: &BaseTransform, _buf: &mut gst::BufferRef) -> gst::FlowReturn { fn transform_ip(
&self,
_element: &BaseTransform,
_buf: &mut gst::BufferRef,
) -> Result<gst::FlowSuccess, gst::FlowError> {
unimplemented!(); unimplemented!();
} }
@ -116,7 +120,7 @@ pub trait BaseTransformImpl: ElementImpl + Send + Sync + 'static {
&self, &self,
_element: &BaseTransform, _element: &BaseTransform,
_buf: &gst::BufferRef, _buf: &gst::BufferRef,
) -> gst::FlowReturn { ) -> Result<gst::FlowSuccess, gst::FlowError> {
unimplemented!(); unimplemented!();
} }
@ -605,6 +609,7 @@ where
&from_glib_borrow(inbuf), &from_glib_borrow(inbuf),
gst::BufferRef::from_mut_ptr(outbuf), gst::BufferRef::from_mut_ptr(outbuf),
) )
.into()
}) })
.to_glib() .to_glib()
} }
@ -628,8 +633,10 @@ where
gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, { gst_panic_to_error!(&wrap, &instance.panicked(), gst::FlowReturn::Error, {
if from_glib(ffi::gst_base_transform_is_passthrough(ptr)) { if from_glib(ffi::gst_base_transform_is_passthrough(ptr)) {
imp.transform_ip_passthrough(&wrap, gst::BufferRef::from_ptr(buf)) imp.transform_ip_passthrough(&wrap, gst::BufferRef::from_ptr(buf))
.into()
} else { } else {
imp.transform_ip(&wrap, gst::BufferRef::from_mut_ptr(buf)) imp.transform_ip(&wrap, gst::BufferRef::from_mut_ptr(buf))
.into()
} }
}) })
.to_glib() .to_glib()

View file

@ -267,8 +267,10 @@ impl Harness {
unsafe { from_glib_full(ffi::gst_harness_pull_upstream_event(self.0.as_ptr())) } unsafe { from_glib_full(ffi::gst_harness_pull_upstream_event(self.0.as_ptr())) }
} }
pub fn push(&mut self, buffer: gst::Buffer) -> gst::FlowReturn { pub fn push(&mut self, buffer: gst::Buffer) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe { from_glib(ffi::gst_harness_push(self.0.as_ptr(), buffer.into_ptr())) } let ret: gst::FlowReturn =
unsafe { from_glib(ffi::gst_harness_push(self.0.as_ptr(), buffer.into_ptr())) };
ret.into_result()
} }
pub fn push_and_pull(&mut self, buffer: gst::Buffer) -> Option<gst::Buffer> { pub fn push_and_pull(&mut self, buffer: gst::Buffer) -> Option<gst::Buffer> {
@ -289,12 +291,16 @@ impl Harness {
} }
} }
pub fn push_from_src(&mut self) -> gst::FlowReturn { pub fn push_from_src(&mut self) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe { from_glib(ffi::gst_harness_push_from_src(self.0.as_ptr())) } let ret: gst::FlowReturn =
unsafe { from_glib(ffi::gst_harness_push_from_src(self.0.as_ptr())) };
ret.into_result()
} }
pub fn push_to_sink(&mut self) -> gst::FlowReturn { pub fn push_to_sink(&mut self) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe { from_glib(ffi::gst_harness_push_to_sink(self.0.as_ptr())) } let ret: gst::FlowReturn =
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 {
@ -391,23 +397,29 @@ impl Harness {
} }
} }
pub fn sink_push_many(&mut self, pushes: u32) -> gst::FlowReturn { pub fn sink_push_many(&mut self, pushes: u32) -> Result<gst::FlowSuccess, gst::FlowError> {
unsafe { let ret: gst::FlowReturn = unsafe {
from_glib(ffi::gst_harness_sink_push_many( 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(&mut self, cranks: u32, pushes: u32) -> gst::FlowReturn { pub fn src_crank_and_push_many(
unsafe { &mut self,
cranks: u32,
pushes: u32,
) -> Result<gst::FlowSuccess, gst::FlowError> {
let ret: gst::FlowReturn = unsafe {
from_glib(ffi::gst_harness_src_crank_and_push_many( 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

@ -124,10 +124,6 @@ pub trait RTSPStreamExt: 'static {
fn leave_bin<P: IsA<gst::Bin>, Q: IsA<gst::Element>>(&self, bin: &P, rtpbin: &Q) -> Result<(), glib::error::BoolError>; fn leave_bin<P: IsA<gst::Bin>, Q: IsA<gst::Element>>(&self, bin: &P, rtpbin: &Q) -> Result<(), glib::error::BoolError>;
fn recv_rtcp(&self, buffer: &gst::Buffer) -> gst::FlowReturn;
fn recv_rtp(&self, buffer: &gst::Buffer) -> gst::FlowReturn;
fn remove_transport(&self, trans: &RTSPStreamTransport) -> Result<(), glib::error::BoolError>; fn remove_transport(&self, trans: &RTSPStreamTransport) -> Result<(), glib::error::BoolError>;
fn request_aux_sender(&self, sessid: u32) -> Option<gst::Element>; fn request_aux_sender(&self, sessid: u32) -> Option<gst::Element>;
@ -425,18 +421,6 @@ impl<O: IsA<RTSPStream>> RTSPStreamExt for O {
} }
} }
fn recv_rtcp(&self, buffer: &gst::Buffer) -> gst::FlowReturn {
unsafe {
from_glib(ffi::gst_rtsp_stream_recv_rtcp(self.to_glib_none().0, buffer.to_glib_full()))
}
}
fn recv_rtp(&self, buffer: &gst::Buffer) -> gst::FlowReturn {
unsafe {
from_glib(ffi::gst_rtsp_stream_recv_rtp(self.to_glib_none().0, buffer.to_glib_full()))
}
}
fn remove_transport(&self, trans: &RTSPStreamTransport) -> Result<(), glib::error::BoolError> { fn remove_transport(&self, trans: &RTSPStreamTransport) -> Result<(), glib::error::BoolError> {
unsafe { unsafe {
glib_result_from_gboolean!(ffi::gst_rtsp_stream_remove_transport(self.to_glib_none().0, trans.to_glib_none().0), "Failed to remove transport") glib_result_from_gboolean!(ffi::gst_rtsp_stream_remove_transport(self.to_glib_none().0, trans.to_glib_none().0), "Failed to remove transport")

View file

@ -38,8 +38,6 @@ pub trait RTSPStreamTransportExt: 'static {
fn keep_alive(&self); fn keep_alive(&self);
fn recv_data(&self, channel: u32, buffer: &gst::Buffer) -> gst::FlowReturn;
fn send_rtcp(&self, buffer: &gst::Buffer) -> Result<(), glib::error::BoolError>; fn send_rtcp(&self, buffer: &gst::Buffer) -> Result<(), glib::error::BoolError>;
fn send_rtp(&self, buffer: &gst::Buffer) -> Result<(), glib::error::BoolError>; fn send_rtp(&self, buffer: &gst::Buffer) -> Result<(), glib::error::BoolError>;
@ -92,12 +90,6 @@ impl<O: IsA<RTSPStreamTransport>> RTSPStreamTransportExt for O {
} }
} }
fn recv_data(&self, channel: u32, buffer: &gst::Buffer) -> gst::FlowReturn {
unsafe {
from_glib(ffi::gst_rtsp_stream_transport_recv_data(self.to_glib_none().0, channel, buffer.to_glib_full()))
}
}
fn send_rtcp(&self, buffer: &gst::Buffer) -> Result<(), glib::error::BoolError> { fn send_rtcp(&self, buffer: &gst::Buffer) -> Result<(), glib::error::BoolError> {
unsafe { unsafe {
glib_result_from_gboolean!(ffi::gst_rtsp_stream_transport_send_rtcp(self.to_glib_none().0, buffer.to_glib_none().0), "Failed to send rtcp") glib_result_from_gboolean!(ffi::gst_rtsp_stream_transport_send_rtcp(self.to_glib_none().0, buffer.to_glib_none().0), "Failed to send rtcp")

View file

@ -57,6 +57,8 @@ mod rtsp_context;
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_token; mod rtsp_token;
pub use rtsp_address_pool::RTSPAddressPoolExtManual; pub use rtsp_address_pool::RTSPAddressPoolExtManual;
@ -141,4 +143,6 @@ pub mod prelude {
pub use rtsp_media_factory::RTSPMediaFactoryExtManual; pub use rtsp_media_factory::RTSPMediaFactoryExtManual;
pub use rtsp_server::RTSPServerExtManual; pub use rtsp_server::RTSPServerExtManual;
pub use rtsp_session_pool::RTSPSessionPoolExtManual; pub use rtsp_session_pool::RTSPSessionPoolExtManual;
pub use rtsp_stream::RTSPStreamExtManual;
pub use rtsp_stream_transport::RTSPStreamTransportExtManual;
} }

View file

@ -0,0 +1,33 @@
use ffi;
use glib::object::IsA;
use glib::translate::*;
use gst;
use RTSPStream;
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.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.to_glib_none().0,
buffer.to_glib_full(),
))
};
ret.into_result()
}
}

View file

@ -0,0 +1,30 @@
use ffi;
use glib::object::IsA;
use glib::translate::*;
use gst;
use RTSPStreamTransport;
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.to_glib_none().0,
channel,
buffer.to_glib_full(),
))
};
ret.into_result()
}
}

View file

@ -16,9 +16,6 @@ use Pad;
use PadLinkCheck; use PadLinkCheck;
use PadTemplate; use PadTemplate;
use Plugin; use Plugin;
use State;
use StateChange;
use StateChangeReturn;
use URIType; use URIType;
use ffi; use ffi;
use glib; use glib;
@ -29,7 +26,6 @@ use glib::signal::connect_raw;
use glib::translate::*; use glib::translate::*;
use glib_ffi; use glib_ffi;
use std::boxed::Box as Box_; use std::boxed::Box as Box_;
use std::mem;
use std::mem::transmute; use std::mem::transmute;
use std::ptr; use std::ptr;
@ -74,10 +70,6 @@ pub trait ElementExt: 'static {
//#[cfg(any(feature = "v1_10", feature = "dox"))] //#[cfg(any(feature = "v1_10", feature = "dox"))]
//fn call_async(&self, func: /*Unknown conversion*//*Unimplemented*/ElementCallAsyncFunc, destroy_notify: /*Unknown conversion*//*Unimplemented*/DestroyNotify); //fn call_async(&self, func: /*Unknown conversion*//*Unimplemented*/ElementCallAsyncFunc, destroy_notify: /*Unknown conversion*//*Unimplemented*/DestroyNotify);
fn change_state(&self, transition: StateChange) -> StateChangeReturn;
fn continue_state(&self, ret: StateChangeReturn) -> StateChangeReturn;
fn create_all_pads(&self); fn create_all_pads(&self);
//#[cfg(any(feature = "v1_14", feature = "dox"))] //#[cfg(any(feature = "v1_14", feature = "dox"))]
@ -109,8 +101,6 @@ pub trait ElementExt: 'static {
fn get_start_time(&self) -> ClockTime; fn get_start_time(&self) -> ClockTime;
fn get_state(&self, timeout: ClockTime) -> (StateChangeReturn, State, State);
fn get_static_pad(&self, name: &str) -> Option<Pad>; fn get_static_pad(&self, name: &str) -> Option<Pad>;
fn is_locked_state(&self) -> bool; fn is_locked_state(&self) -> bool;
@ -164,8 +154,6 @@ pub trait ElementExt: 'static {
fn set_start_time(&self, time: ClockTime); fn set_start_time(&self, time: ClockTime);
fn set_state(&self, state: State) -> StateChangeReturn;
fn sync_state_with_parent(&self) -> Result<(), glib::error::BoolError>; fn sync_state_with_parent(&self) -> Result<(), glib::error::BoolError>;
fn unlink<P: IsA<Element>>(&self, dest: &P); fn unlink<P: IsA<Element>>(&self, dest: &P);
@ -199,18 +187,6 @@ impl<O: IsA<Element>> ElementExt for O {
// unsafe { TODO: call ffi::gst_element_call_async() } // unsafe { TODO: call ffi::gst_element_call_async() }
//} //}
fn change_state(&self, transition: StateChange) -> StateChangeReturn {
unsafe {
from_glib(ffi::gst_element_change_state(self.to_glib_none().0, transition.to_glib()))
}
}
fn continue_state(&self, ret: StateChangeReturn) -> StateChangeReturn {
unsafe {
from_glib(ffi::gst_element_continue_state(self.to_glib_none().0, ret.to_glib()))
}
}
fn create_all_pads(&self) { fn create_all_pads(&self) {
unsafe { unsafe {
ffi::gst_element_create_all_pads(self.to_glib_none().0); ffi::gst_element_create_all_pads(self.to_glib_none().0);
@ -294,15 +270,6 @@ impl<O: IsA<Element>> ElementExt for O {
} }
} }
fn get_state(&self, timeout: ClockTime) -> (StateChangeReturn, State, State) {
unsafe {
let mut state = mem::uninitialized();
let mut pending = mem::uninitialized();
let ret = from_glib(ffi::gst_element_get_state(self.to_glib_none().0, &mut state, &mut pending, timeout.to_glib()));
(ret, from_glib(state), from_glib(pending))
}
}
fn get_static_pad(&self, name: &str) -> Option<Pad> { fn get_static_pad(&self, name: &str) -> Option<Pad> {
unsafe { unsafe {
from_glib_full(ffi::gst_element_get_static_pad(self.to_glib_none().0, name.to_glib_none().0)) from_glib_full(ffi::gst_element_get_static_pad(self.to_glib_none().0, name.to_glib_none().0))
@ -472,12 +439,6 @@ impl<O: IsA<Element>> ElementExt for O {
} }
} }
fn set_state(&self, state: State) -> StateChangeReturn {
unsafe {
from_glib(ffi::gst_element_set_state(self.to_glib_none().0, state.to_glib()))
}
}
fn sync_state_with_parent(&self) -> Result<(), glib::error::BoolError> { fn sync_state_with_parent(&self) -> Result<(), glib::error::BoolError> {
unsafe { unsafe {
glib_result_from_gboolean!(ffi::gst_element_sync_state_with_parent(self.to_glib_none().0), "Failed to sync state with parent") glib_result_from_gboolean!(ffi::gst_element_sync_state_with_parent(self.to_glib_none().0), "Failed to sync state with parent")

View file

@ -6,12 +6,11 @@ use Caps;
use Element; use Element;
use Event; use Event;
use EventType; use EventType;
use FlowReturn;
use Object; use Object;
use PadClass; use PadClass;
use PadDirection; use PadDirection;
#[cfg(any(feature = "v1_10", feature = "dox"))]
use PadLinkCheck; use PadLinkCheck;
use PadLinkReturn;
use PadMode; use PadMode;
use PadTemplate; use PadTemplate;
#[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg(any(feature = "v1_10", feature = "dox"))]
@ -89,8 +88,6 @@ pub trait PadExt: 'static {
//fn get_element_private(&self) -> /*Unimplemented*/Option<Fundamental: Pointer>; //fn get_element_private(&self) -> /*Unimplemented*/Option<Fundamental: Pointer>;
fn get_last_flow_return(&self) -> FlowReturn;
fn get_offset(&self) -> i64; fn get_offset(&self) -> i64;
fn get_pad_template(&self) -> Option<PadTemplate>; fn get_pad_template(&self) -> Option<PadTemplate>;
@ -125,10 +122,6 @@ pub trait PadExt: 'static {
//fn iterate_internal_links_default<'a, P: IsA<Object> + 'a, Q: Into<Option<&'a P>>>(&self, parent: Q) -> /*Ignored*/Option<Iterator>; //fn iterate_internal_links_default<'a, P: IsA<Object> + 'a, Q: Into<Option<&'a P>>>(&self, parent: Q) -> /*Ignored*/Option<Iterator>;
fn link<P: IsA<Pad>>(&self, sinkpad: &P) -> PadLinkReturn;
fn link_full<P: IsA<Pad>>(&self, sinkpad: &P, flags: PadLinkCheck) -> PadLinkReturn;
#[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg(any(feature = "v1_10", feature = "dox"))]
fn link_maybe_ghosting<P: IsA<Pad>>(&self, sink: &P) -> Result<(), glib::error::BoolError>; fn link_maybe_ghosting<P: IsA<Pad>>(&self, sink: &P) -> Result<(), glib::error::BoolError>;
@ -183,8 +176,6 @@ pub trait PadExt: 'static {
fn stop_task(&self) -> Result<(), glib::error::BoolError>; fn stop_task(&self) -> Result<(), glib::error::BoolError>;
fn store_sticky_event(&self, event: &Event) -> FlowReturn;
fn unlink<P: IsA<Pad>>(&self, sinkpad: &P) -> Result<(), glib::error::BoolError>; fn unlink<P: IsA<Pad>>(&self, sinkpad: &P) -> Result<(), glib::error::BoolError>;
fn use_fixed_caps(&self); fn use_fixed_caps(&self);
@ -271,12 +262,6 @@ impl<O: IsA<Pad>> PadExt for O {
// unsafe { TODO: call ffi::gst_pad_get_element_private() } // unsafe { TODO: call ffi::gst_pad_get_element_private() }
//} //}
fn get_last_flow_return(&self) -> FlowReturn {
unsafe {
from_glib(ffi::gst_pad_get_last_flow_return(self.to_glib_none().0))
}
}
fn get_offset(&self) -> i64 { fn get_offset(&self) -> i64 {
unsafe { unsafe {
ffi::gst_pad_get_offset(self.to_glib_none().0) ffi::gst_pad_get_offset(self.to_glib_none().0)
@ -371,18 +356,6 @@ impl<O: IsA<Pad>> PadExt for O {
// unsafe { TODO: call ffi::gst_pad_iterate_internal_links_default() } // unsafe { TODO: call ffi::gst_pad_iterate_internal_links_default() }
//} //}
fn link<P: IsA<Pad>>(&self, sinkpad: &P) -> PadLinkReturn {
unsafe {
from_glib(ffi::gst_pad_link(self.to_glib_none().0, sinkpad.to_glib_none().0))
}
}
fn link_full<P: IsA<Pad>>(&self, sinkpad: &P, flags: PadLinkCheck) -> PadLinkReturn {
unsafe {
from_glib(ffi::gst_pad_link_full(self.to_glib_none().0, sinkpad.to_glib_none().0, flags.to_glib()))
}
}
#[cfg(any(feature = "v1_10", feature = "dox"))] #[cfg(any(feature = "v1_10", feature = "dox"))]
fn link_maybe_ghosting<P: IsA<Pad>>(&self, sink: &P) -> Result<(), glib::error::BoolError> { fn link_maybe_ghosting<P: IsA<Pad>>(&self, sink: &P) -> Result<(), glib::error::BoolError> {
unsafe { unsafe {
@ -517,12 +490,6 @@ impl<O: IsA<Pad>> PadExt for O {
} }
} }
fn store_sticky_event(&self, event: &Event) -> FlowReturn {
unsafe {
from_glib(ffi::gst_pad_store_sticky_event(self.to_glib_none().0, event.to_glib_none().0))
}
}
fn unlink<P: IsA<Pad>>(&self, sinkpad: &P) -> Result<(), glib::error::BoolError> { fn unlink<P: IsA<Pad>>(&self, sinkpad: &P) -> Result<(), glib::error::BoolError> {
unsafe { unsafe {
glib_result_from_gboolean!(ffi::gst_pad_unlink(self.to_glib_none().0, sinkpad.to_glib_none().0), "Failed to unlink pad") glib_result_from_gboolean!(ffi::gst_pad_unlink(self.to_glib_none().0, sinkpad.to_glib_none().0), "Failed to unlink pad")

View file

@ -17,7 +17,9 @@ use std::mem;
use std::mem::transmute; use std::mem::transmute;
use std::ptr; use std::ptr;
use Clock; use Clock;
use ClockError;
use ClockReturn; use ClockReturn;
use ClockSuccess;
use ClockTime; use ClockTime;
use ClockTimeDiff; use ClockTimeDiff;
@ -68,26 +70,28 @@ impl ClockId {
unsafe { ffi::gst_clock_id_unschedule(self.to_glib_none().0) } unsafe { ffi::gst_clock_id_unschedule(self.to_glib_none().0) }
} }
pub fn wait(&self) -> (ClockReturn, ClockTimeDiff) { pub fn wait(&self) -> (Result<ClockSuccess, ClockError>, ClockTimeDiff) {
unsafe { unsafe {
let mut jitter = mem::uninitialized(); let mut jitter = mem::uninitialized();
let res = ffi::gst_clock_id_wait(self.to_glib_none().0, &mut jitter); let res: ClockReturn =
(from_glib(res), jitter) from_glib(ffi::gst_clock_id_wait(self.to_glib_none().0, &mut jitter));
(res.into_result(), jitter)
} }
} }
pub fn wait_async<F>(&self, func: F) -> ClockReturn pub fn wait_async<F>(&self, func: F) -> Result<ClockSuccess, ClockError>
where where
F: Fn(&Clock, ClockTime, &ClockId) -> bool + Send + 'static, F: Fn(&Clock, ClockTime, &ClockId) -> bool + Send + 'static,
{ {
unsafe { let ret: ClockReturn = unsafe {
from_glib(ffi::gst_clock_id_wait_async( from_glib(ffi::gst_clock_id_wait_async(
self.to_glib_none().0, self.to_glib_none().0,
Some(trampoline_wait_async), Some(trampoline_wait_async),
into_raw_wait_async(func), into_raw_wait_async(func),
Some(destroy_closure_wait_async), Some(destroy_closure_wait_async),
)) ))
} };
ret.into_result()
} }
} }
@ -251,7 +255,7 @@ mod tests {
let id = clock.new_single_shot_id(now + 20 * ::MSECOND).unwrap(); let id = clock.new_single_shot_id(now + 20 * ::MSECOND).unwrap();
let (res, _) = id.wait(); let (res, _) = id.wait();
assert!(res == ClockReturn::Ok || res == ClockReturn::Early); assert!(res == Ok(ClockSuccess::Ok) || res == Err(ClockError::Early));
} }
#[test] #[test]
@ -269,7 +273,7 @@ mod tests {
true true
}); });
assert!(res == ClockReturn::Ok); assert!(res == Ok(ClockSuccess::Ok));
assert_eq!(receiver.recv(), Ok(())); assert_eq!(receiver.recv(), Ok(()));
} }

View file

@ -18,6 +18,7 @@ use glib::translate::{
}; };
use glib::{IsA, IsClassFor}; use glib::{IsA, IsClassFor};
use miniobject::MiniObject; use miniobject::MiniObject;
use ClockTime;
use Event; use Event;
use Format; use Format;
use FormattedValue; use FormattedValue;
@ -26,6 +27,11 @@ use Pad;
use PadTemplate; use PadTemplate;
use QueryRef; use QueryRef;
use SpecificFormattedValue; use SpecificFormattedValue;
use State;
use StateChange;
use StateChangeError;
use StateChangeReturn;
use StateChangeSuccess;
use std::ffi::CStr; use std::ffi::CStr;
use std::mem; use std::mem;
@ -95,6 +101,19 @@ impl FromGlib<libc::c_ulong> for NotifyWatchId {
pub trait ElementExtManual: 'static { pub trait ElementExtManual: 'static {
fn get_element_class(&self) -> &ElementClass; fn get_element_class(&self) -> &ElementClass;
fn change_state(&self, transition: StateChange)
-> Result<StateChangeSuccess, StateChangeError>;
fn continue_state(
&self,
ret: StateChangeReturn,
) -> Result<StateChangeSuccess, StateChangeError>;
fn get_state(
&self,
timeout: ClockTime,
) -> (Result<StateChangeSuccess, StateChangeError>, State, State);
fn set_state(&self, state: State) -> Result<StateChangeSuccess, StateChangeError>;
fn query(&self, query: &mut QueryRef) -> bool; fn query(&self, query: &mut QueryRef) -> bool;
fn send_event(&self, event: Event) -> bool; fn send_event(&self, event: Event) -> bool;
@ -203,6 +222,59 @@ impl<O: IsA<Element>> ElementExtManual for O {
} }
} }
fn change_state(
&self,
transition: StateChange,
) -> Result<StateChangeSuccess, StateChangeError> {
let ret: StateChangeReturn = unsafe {
from_glib(ffi::gst_element_change_state(
self.to_glib_none().0,
transition.to_glib(),
))
};
ret.into_result()
}
fn continue_state(
&self,
ret: StateChangeReturn,
) -> Result<StateChangeSuccess, StateChangeError> {
let ret: StateChangeReturn = unsafe {
from_glib(ffi::gst_element_continue_state(
self.to_glib_none().0,
ret.to_glib(),
))
};
ret.into_result()
}
fn get_state(
&self,
timeout: ClockTime,
) -> (Result<StateChangeSuccess, StateChangeError>, State, State) {
unsafe {
let mut state = mem::uninitialized();
let mut pending = mem::uninitialized();
let ret: StateChangeReturn = from_glib(ffi::gst_element_get_state(
self.to_glib_none().0,
&mut state,
&mut pending,
timeout.to_glib(),
));
(ret.into_result(), from_glib(state), from_glib(pending))
}
}
fn set_state(&self, state: State) -> Result<StateChangeSuccess, StateChangeError> {
let ret: StateChangeReturn = unsafe {
from_glib(ffi::gst_element_set_state(
self.to_glib_none().0,
state.to_glib(),
))
};
ret.into_result()
}
fn query(&self, query: &mut QueryRef) -> bool { fn query(&self, query: &mut QueryRef) -> bool {
unsafe { unsafe {
from_glib(ffi::gst_element_query( from_glib(ffi::gst_element_query(

View file

@ -75,6 +75,15 @@ impl Error for StateChangeError {
} }
} }
impl From<Result<StateChangeSuccess, StateChangeError>> for StateChangeReturn {
fn from(res: Result<StateChangeSuccess, StateChangeError>) -> Self {
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> {
match self { match self {
@ -186,6 +195,15 @@ impl Error for FlowError {
} }
} }
impl From<Result<FlowSuccess, FlowError>> for FlowReturn {
fn from(res: Result<FlowSuccess, FlowError>) -> Self {
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> {
match self { match self {
@ -261,6 +279,15 @@ impl Error for PadLinkError {
} }
} }
impl From<Result<PadLinkSuccess, PadLinkError>> for PadLinkReturn {
fn from(res: Result<PadLinkSuccess, PadLinkError>) -> Self {
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> {
match self { match self {
@ -343,6 +370,15 @@ impl Error for ClockError {
} }
} }
impl From<Result<ClockSuccess, ClockError>> for ClockReturn {
fn from(res: Result<ClockSuccess, ClockError>) -> Self {
match res {
Ok(success) => ClockReturn::from_ok(success),
Err(error) => ClockReturn::from_error(error),
}
}
}
impl PartialOrd for ::TypeFindProbability { impl PartialOrd for ::TypeFindProbability {
fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> { fn partial_cmp(&self, other: &Self) -> Option<cmp::Ordering> {
self.to_glib().partial_cmp(&other.to_glib()) self.to_glib().partial_cmp(&other.to_glib())

View file

@ -12,10 +12,15 @@ use BufferList;
use Event; use Event;
use FlowError; use FlowError;
use FlowReturn; use FlowReturn;
use FlowSuccess;
use Format; use Format;
use FormattedValue; use FormattedValue;
use GenericFormattedValue; use GenericFormattedValue;
use Pad; use Pad;
use PadLinkCheck;
use PadLinkError;
use PadLinkReturn;
use PadLinkSuccess;
use PadProbeReturn; use PadProbeReturn;
use PadProbeType; use PadProbeType;
use Query; use Query;
@ -111,11 +116,11 @@ pub trait PadExtManual: 'static {
F: Fn(&Pad, &mut PadProbeInfo) -> PadProbeReturn + Send + Sync + 'static; F: Fn(&Pad, &mut PadProbeInfo) -> PadProbeReturn + Send + Sync + 'static;
fn remove_probe(&self, id: PadProbeId); fn remove_probe(&self, id: PadProbeId);
fn chain(&self, buffer: Buffer) -> FlowReturn; fn chain(&self, buffer: Buffer) -> Result<FlowSuccess, FlowError>;
fn push(&self, buffer: Buffer) -> FlowReturn; fn push(&self, buffer: Buffer) -> Result<FlowSuccess, FlowError>;
fn chain_list(&self, list: BufferList) -> FlowReturn; fn chain_list(&self, list: BufferList) -> Result<FlowSuccess, FlowError>;
fn push_list(&self, list: BufferList) -> FlowReturn; fn push_list(&self, list: BufferList) -> Result<FlowSuccess, FlowError>;
fn pull_range(&self, offset: u64, size: u32) -> Result<Buffer, FlowError>; fn pull_range(&self, offset: u64, size: u32) -> Result<Buffer, FlowError>;
fn get_range(&self, offset: u64, size: u32) -> Result<Buffer, FlowError>; fn get_range(&self, offset: u64, size: u32) -> Result<Buffer, FlowError>;
@ -138,12 +143,21 @@ 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;
fn get_last_flow_return(&self) -> Result<FlowSuccess, FlowError>;
fn iterate_internal_links(&self) -> ::Iterator<Pad>; fn iterate_internal_links(&self) -> ::Iterator<Pad>;
fn iterate_internal_links_default<'a, P: IsA<::Object> + 'a, Q: Into<Option<&'a P>>>( fn iterate_internal_links_default<'a, P: IsA<::Object> + 'a, Q: Into<Option<&'a P>>>(
&self, &self,
parent: Q, parent: Q,
) -> ::Iterator<Pad>; ) -> ::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;
fn set_activate_function<F>(&self, func: F) fn set_activate_function<F>(&self, func: F)
@ -156,11 +170,17 @@ pub trait PadExtManual: 'static {
fn set_chain_function<F>(&self, func: F) fn set_chain_function<F>(&self, func: F)
where where
F: Fn(&Pad, &Option<::Object>, ::Buffer) -> ::FlowReturn + Send + Sync + 'static; F: Fn(&Pad, &Option<::Object>, ::Buffer) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static;
fn set_chain_list_function<F>(&self, func: F) fn set_chain_list_function<F>(&self, func: F)
where where
F: Fn(&Pad, &Option<::Object>, ::BufferList) -> ::FlowReturn + Send + Sync + 'static; F: Fn(&Pad, &Option<::Object>, ::BufferList) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static;
fn set_event_function<F>(&self, func: F) fn set_event_function<F>(&self, func: F)
where where
@ -168,7 +188,10 @@ pub trait PadExtManual: 'static {
fn set_event_full_function<F>(&self, func: F) fn set_event_full_function<F>(&self, func: F)
where where
F: Fn(&Pad, &Option<::Object>, ::Event) -> ::FlowReturn + Send + Sync + 'static; F: Fn(&Pad, &Option<::Object>, ::Event) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static;
fn set_getrange_function<F>(&self, func: F) fn set_getrange_function<F>(&self, func: F)
where where
@ -183,7 +206,10 @@ pub trait PadExtManual: 'static {
fn set_link_function<F>(&self, func: F) fn set_link_function<F>(&self, func: F)
where where
F: Fn(&Pad, &Option<::Object>, &Pad) -> ::PadLinkReturn + Send + Sync + 'static; F: Fn(&Pad, &Option<::Object>, &Pad) -> Result<::PadLinkSuccess, ::PadLinkError>
+ Send
+ Sync
+ 'static;
fn set_query_function<F>(&self, func: F) fn set_query_function<F>(&self, func: F)
where where
@ -233,6 +259,8 @@ pub trait PadExtManual: 'static {
&self, &self,
func: F, func: F,
); );
fn store_sticky_event(&self, event: &Event) -> Result<FlowSuccess, FlowError>;
} }
impl<O: IsA<Pad>> PadExtManual for O { impl<O: IsA<Pad>> PadExtManual for O {
@ -266,29 +294,37 @@ impl<O: IsA<Pad>> PadExtManual for O {
} }
} }
fn chain(&self, buffer: Buffer) -> FlowReturn { fn chain(&self, buffer: Buffer) -> Result<FlowSuccess, FlowError> {
unsafe { from_glib(ffi::gst_pad_chain(self.to_glib_none().0, buffer.into_ptr())) }
}
fn push(&self, buffer: Buffer) -> FlowReturn {
unsafe { from_glib(ffi::gst_pad_push(self.to_glib_none().0, buffer.into_ptr())) }
}
fn chain_list(&self, list: BufferList) -> FlowReturn {
unsafe { unsafe {
from_glib(ffi::gst_pad_chain_list( FlowReturn::from_glib(ffi::gst_pad_chain(self.to_glib_none().0, buffer.into_ptr()))
.into_result()
}
}
fn push(&self, buffer: Buffer) -> Result<FlowSuccess, FlowError> {
unsafe {
FlowReturn::from_glib(ffi::gst_pad_push(self.to_glib_none().0, buffer.into_ptr()))
.into_result()
}
}
fn chain_list(&self, list: BufferList) -> Result<FlowSuccess, FlowError> {
unsafe {
FlowReturn::from_glib(ffi::gst_pad_chain_list(
self.to_glib_none().0, self.to_glib_none().0,
list.into_ptr(), list.into_ptr(),
)) ))
.into_result()
} }
} }
fn push_list(&self, list: BufferList) -> FlowReturn { fn push_list(&self, list: BufferList) -> Result<FlowSuccess, FlowError> {
unsafe { unsafe {
from_glib(ffi::gst_pad_push_list( FlowReturn::from_glib(ffi::gst_pad_push_list(
self.to_glib_none().0, self.to_glib_none().0,
list.into_ptr(), list.into_ptr(),
)) ))
.into_result()
} }
} }
@ -406,6 +442,12 @@ impl<O: IsA<Pad>> PadExtManual for O {
} }
} }
fn get_last_flow_return(&self) -> Result<FlowSuccess, FlowError> {
let ret: FlowReturn =
unsafe { from_glib(ffi::gst_pad_get_last_flow_return(self.to_glib_none().0)) };
ret.into_result()
}
fn iterate_internal_links(&self) -> ::Iterator<Pad> { fn iterate_internal_links(&self) -> ::Iterator<Pad> {
unsafe { from_glib_full(ffi::gst_pad_iterate_internal_links(self.to_glib_none().0)) } unsafe { from_glib_full(ffi::gst_pad_iterate_internal_links(self.to_glib_none().0)) }
} }
@ -424,6 +466,31 @@ 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.to_glib_none().0,
sinkpad.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.to_glib_none().0,
sinkpad.to_glib_none().0,
flags.to_glib(),
))
};
ret.into_result()
}
fn stream_lock(&self) -> StreamLock { fn stream_lock(&self) -> StreamLock {
unsafe { unsafe {
let pad = self.to_glib_none().0; let pad = self.to_glib_none().0;
@ -469,11 +536,17 @@ impl<O: IsA<Pad>> PadExtManual for O {
fn set_chain_function<F>(&self, func: F) fn set_chain_function<F>(&self, func: F)
where where
F: Fn(&Pad, &Option<::Object>, ::Buffer) -> ::FlowReturn + Send + Sync + 'static, F: Fn(&Pad, &Option<::Object>, ::Buffer) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static,
{ {
unsafe { unsafe {
let func_box: Box< let func_box: Box<
Fn(&Pad, &Option<::Object>, ::Buffer) -> ::FlowReturn + Send + Sync + 'static, Fn(&Pad, &Option<::Object>, ::Buffer) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static,
> = Box::new(func); > = Box::new(func);
ffi::gst_pad_set_chain_function_full( ffi::gst_pad_set_chain_function_full(
self.to_glib_none().0, self.to_glib_none().0,
@ -486,11 +559,17 @@ impl<O: IsA<Pad>> PadExtManual for O {
fn set_chain_list_function<F>(&self, func: F) fn set_chain_list_function<F>(&self, func: F)
where where
F: Fn(&Pad, &Option<::Object>, ::BufferList) -> ::FlowReturn + Send + Sync + 'static, F: Fn(&Pad, &Option<::Object>, ::BufferList) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static,
{ {
unsafe { unsafe {
let func_box: Box< let func_box: Box<
Fn(&Pad, &Option<::Object>, ::BufferList) -> ::FlowReturn + Send + Sync + 'static, Fn(&Pad, &Option<::Object>, ::BufferList) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static,
> = Box::new(func); > = Box::new(func);
ffi::gst_pad_set_chain_list_function_full( ffi::gst_pad_set_chain_list_function_full(
self.to_glib_none().0, self.to_glib_none().0,
@ -520,11 +599,17 @@ impl<O: IsA<Pad>> PadExtManual for O {
fn set_event_full_function<F>(&self, func: F) fn set_event_full_function<F>(&self, func: F)
where where
F: Fn(&Pad, &Option<::Object>, ::Event) -> ::FlowReturn + Send + Sync + 'static, F: Fn(&Pad, &Option<::Object>, ::Event) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static,
{ {
unsafe { unsafe {
let func_box: Box< let func_box: Box<
Fn(&Pad, &Option<::Object>, ::Event) -> ::FlowReturn + Send + Sync + 'static, Fn(&Pad, &Option<::Object>, ::Event) -> Result<FlowSuccess, FlowError>
+ Send
+ Sync
+ 'static,
> = Box::new(func); > = Box::new(func);
ffi::gst_pad_set_event_full_function_full( ffi::gst_pad_set_event_full_function_full(
self.to_glib_none().0, self.to_glib_none().0,
@ -537,7 +622,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, ::FlowError> F: Fn(&Pad, &Option<::Object>, u64, u32) -> Result<::Buffer, FlowError>
+ Send + Send
+ Sync + Sync
+ 'static, + 'static,
@ -545,7 +630,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, ::FlowError> Fn(&Pad, &Option<::Object>, u64, u32) -> Result<::Buffer, FlowError>
+ Send + Send
+ Sync + Sync
+ 'static, + 'static,
@ -578,11 +663,17 @@ impl<O: IsA<Pad>> PadExtManual for O {
fn set_link_function<F>(&self, func: F) fn set_link_function<F>(&self, func: F)
where where
F: Fn(&Pad, &Option<::Object>, &Pad) -> ::PadLinkReturn + Send + Sync + 'static, F: Fn(&Pad, &Option<::Object>, &Pad) -> Result<::PadLinkSuccess, ::PadLinkError>
+ Send
+ Sync
+ 'static,
{ {
unsafe { unsafe {
let func_box: Box< let func_box: Box<
Fn(&Pad, &Option<::Object>, &Pad) -> ::PadLinkReturn + Send + Sync + 'static, Fn(&Pad, &Option<::Object>, &Pad) -> Result<::PadLinkSuccess, ::PadLinkError>
+ Send
+ Sync
+ 'static,
> = Box::new(func); > = Box::new(func);
ffi::gst_pad_set_link_function_full( ffi::gst_pad_set_link_function_full(
self.to_glib_none().0, self.to_glib_none().0,
@ -910,6 +1001,16 @@ impl<O: IsA<Pad>> PadExtManual for O {
ffi::gst_pad_sticky_events_foreach(self.to_glib_none().0, Some(trampoline), func_ptr); ffi::gst_pad_sticky_events_foreach(self.to_glib_none().0, Some(trampoline), func_ptr);
} }
} }
fn store_sticky_event(&self, event: &Event) -> Result<FlowSuccess, FlowError> {
let ret: FlowReturn = unsafe {
from_glib(ffi::gst_pad_store_sticky_event(
self.to_glib_none().0,
event.to_glib_none().0,
))
};
ret.into_result()
}
} }
#[repr(C)] #[repr(C)]
@ -1048,17 +1149,18 @@ unsafe extern "C" fn trampoline_chain_function(
buffer: *mut ffi::GstBuffer, buffer: *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>, ::Buffer) -> ::FlowReturn let func: &&(Fn(&Pad, &Option<::Object>, ::Buffer) -> Result<FlowSuccess, FlowError>
+ Send + Send
+ Sync + Sync
+ 'static) = transmute((*pad).chaindata); + 'static) = transmute((*pad).chaindata);
func( let res: FlowReturn = func(
&from_glib_borrow(pad), &from_glib_borrow(pad),
&from_glib_borrow(parent), &from_glib_borrow(parent),
from_glib_full(buffer), from_glib_full(buffer),
) )
.to_glib() .into();
res.to_glib()
} }
unsafe extern "C" fn trampoline_chain_list_function( unsafe extern "C" fn trampoline_chain_list_function(
@ -1067,17 +1169,18 @@ unsafe extern "C" fn trampoline_chain_list_function(
list: *mut ffi::GstBufferList, list: *mut ffi::GstBufferList,
) -> 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>, ::BufferList) -> ::FlowReturn let func: &&(Fn(&Pad, &Option<::Object>, ::BufferList) -> Result<FlowSuccess, FlowError>
+ Send + Send
+ Sync + Sync
+ 'static) = transmute((*pad).chainlistdata); + 'static) = transmute((*pad).chainlistdata);
func( let res: FlowReturn = func(
&from_glib_borrow(pad), &from_glib_borrow(pad),
&from_glib_borrow(parent), &from_glib_borrow(parent),
from_glib_full(list), from_glib_full(list),
) )
.to_glib() .into();
res.to_glib()
} }
unsafe extern "C" fn trampoline_event_function( unsafe extern "C" fn trampoline_event_function(
@ -1103,15 +1206,18 @@ unsafe extern "C" fn trampoline_event_full_function(
event: *mut ffi::GstEvent, event: *mut ffi::GstEvent,
) -> 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>, ::Event) -> ::FlowReturn + Send + Sync + 'static) = let func: &&(Fn(&Pad, &Option<::Object>, ::Event) -> Result<FlowSuccess, FlowError>
transmute((*pad).eventdata); + Send
+ Sync
+ 'static) = transmute((*pad).eventdata);
func( let res: FlowReturn = func(
&from_glib_borrow(pad), &from_glib_borrow(pad),
&from_glib_borrow(parent), &from_glib_borrow(parent),
from_glib_full(event), from_glib_full(event),
) )
.to_glib() .into();
res.to_glib()
} }
unsafe extern "C" fn trampoline_getrange_function( unsafe extern "C" fn trampoline_getrange_function(
@ -1122,7 +1228,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, ::FlowError> let func: &&(Fn(&Pad, &Option<::Object>, u64, u32) -> Result<::Buffer, FlowError>
+ Send + Send
+ Sync + Sync
+ 'static) = transmute((*pad).getrangedata); + 'static) = transmute((*pad).getrangedata);
@ -1135,9 +1241,9 @@ unsafe extern "C" fn trampoline_getrange_function(
) { ) {
Ok(new_buffer) => { Ok(new_buffer) => {
*buffer = new_buffer.into_ptr(); *buffer = new_buffer.into_ptr();
::FlowReturn::Ok.to_glib() FlowReturn::Ok.to_glib()
} }
Err(ret) => ::FlowReturn::from_error(ret).to_glib(), Err(ret) => FlowReturn::from_error(ret).to_glib(),
} }
} }
@ -1163,17 +1269,22 @@ unsafe extern "C" fn trampoline_link_function(
peer: *mut ffi::GstPad, peer: *mut ffi::GstPad,
) -> ffi::GstPadLinkReturn { ) -> ffi::GstPadLinkReturn {
#[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>, &::Pad) -> ::PadLinkReturn let func: &&(Fn(
&Pad,
&Option<::Object>,
&::Pad,
) -> Result<::PadLinkSuccess, ::PadLinkError>
+ Send + Send
+ Sync + Sync
+ 'static) = transmute((*pad).linkdata); + 'static) = transmute((*pad).linkdata);
func( let res: ::PadLinkReturn = func(
&from_glib_borrow(pad), &from_glib_borrow(pad),
&from_glib_borrow(parent), &from_glib_borrow(parent),
&from_glib_borrow(peer), &from_glib_borrow(peer),
) )
.to_glib() .into();
res.to_glib()
} }
unsafe extern "C" fn trampoline_query_function( unsafe extern "C" fn trampoline_query_function(
@ -1252,7 +1363,7 @@ mod tests {
let mut buffers = buffers_clone.lock().unwrap(); let mut buffers = buffers_clone.lock().unwrap();
buffers.push(buffer); buffers.push(buffer);
::FlowReturn::Ok Ok(FlowSuccess::Ok)
}); });
pad.set_active(true).unwrap(); pad.set_active(true).unwrap();
@ -1261,7 +1372,7 @@ mod tests {
let segment = ::FormattedSegment::<::ClockTime>::new(); let segment = ::FormattedSegment::<::ClockTime>::new();
assert!(pad.send_event(::Event::new_segment(segment.as_ref()).build())); assert!(pad.send_event(::Event::new_segment(segment.as_ref()).build()));
assert_eq!(pad.chain(::Buffer::new()), ::FlowReturn::Ok); assert_eq!(pad.chain(::Buffer::new()), Ok(FlowSuccess::Ok));
let events = events.lock().unwrap(); let events = events.lock().unwrap();
let buffers = buffers.lock().unwrap(); let buffers = buffers.lock().unwrap();

View file

@ -11,6 +11,7 @@ use Buffer;
use BufferList; use BufferList;
use FlowError; use FlowError;
use FlowReturn; use FlowReturn;
use FlowSuccess;
use Object; use Object;
use Pad; use Pad;
use ProxyPad; use ProxyPad;
@ -25,34 +26,36 @@ impl ProxyPad {
pad: &P, pad: &P,
parent: R, parent: R,
buffer: Buffer, buffer: Buffer,
) -> FlowReturn { ) -> Result<FlowSuccess, FlowError> {
skip_assert_initialized!(); skip_assert_initialized!();
let parent = parent.into(); let parent = parent.into();
let parent = parent.to_glib_none(); let parent = parent.to_glib_none();
unsafe { let ret: FlowReturn = unsafe {
from_glib(ffi::gst_proxy_pad_chain_default( from_glib(ffi::gst_proxy_pad_chain_default(
pad.to_glib_none().0 as *mut ffi::GstPad, pad.to_glib_none().0 as *mut ffi::GstPad,
parent.0, parent.0,
buffer.into_ptr(), buffer.into_ptr(),
)) ))
} };
ret.into_result()
} }
pub fn chain_list_default<'a, P: IsA<ProxyPad>, Q: IsA<Object> + 'a, R: Into<Option<&'a Q>>>( pub fn chain_list_default<'a, P: IsA<ProxyPad>, Q: IsA<Object> + 'a, R: Into<Option<&'a Q>>>(
pad: &P, pad: &P,
parent: R, parent: R,
list: BufferList, list: BufferList,
) -> FlowReturn { ) -> Result<FlowSuccess, FlowError> {
skip_assert_initialized!(); skip_assert_initialized!();
let parent = parent.into(); let parent = parent.into();
let parent = parent.to_glib_none(); let parent = parent.to_glib_none();
unsafe { let ret: FlowReturn = unsafe {
from_glib(ffi::gst_proxy_pad_chain_list_default( from_glib(ffi::gst_proxy_pad_chain_list_default(
pad.to_glib_none().0 as *mut ffi::GstPad, pad.to_glib_none().0 as *mut ffi::GstPad,
parent.0, parent.0,
list.into_ptr(), list.into_ptr(),
)) ))
} };
ret.into_result()
} }
pub fn getrange_default<P: IsA<ProxyPad>, Q: IsA<Object>>( pub fn getrange_default<P: IsA<ProxyPad>, Q: IsA<Object>>(

View file

@ -24,10 +24,16 @@ use Event;
use PadTemplate; use PadTemplate;
use QueryRef; use QueryRef;
use StateChange; use StateChange;
use StateChangeError;
use StateChangeReturn; use StateChangeReturn;
use StateChangeSuccess;
pub trait ElementImpl: ObjectImpl + Send + Sync + 'static { pub trait ElementImpl: ObjectImpl + Send + Sync + 'static {
fn change_state(&self, element: &::Element, transition: StateChange) -> StateChangeReturn { fn change_state(
&self,
element: &::Element,
transition: StateChange,
) -> Result<StateChangeSuccess, StateChangeError> {
self.parent_change_state(element, transition) self.parent_change_state(element, transition)
} }
@ -59,7 +65,7 @@ pub trait ElementImpl: ObjectImpl + Send + Sync + 'static {
&self, &self,
element: &::Element, element: &::Element,
transition: StateChange, transition: StateChange,
) -> StateChangeReturn { ) -> Result<StateChangeSuccess, StateChangeError> {
unsafe { unsafe {
let data = self.get_type_data(); let data = self.get_type_data();
let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstElementClass; let parent_class = data.as_ref().get_parent_class() as *mut ffi::GstElementClass;
@ -68,6 +74,7 @@ pub trait ElementImpl: ObjectImpl + Send + Sync + 'static {
.change_state .change_state
.map(|f| from_glib(f(element.to_glib_none().0, transition.to_glib()))) .map(|f| from_glib(f(element.to_glib_none().0, transition.to_glib())))
.unwrap_or(::StateChangeReturn::Success) .unwrap_or(::StateChangeReturn::Success)
.into_result()
} }
} }
@ -248,7 +255,7 @@ where
}; };
gst_panic_to_error!(&wrap, &instance.panicked(), fallback, { gst_panic_to_error!(&wrap, &instance.panicked(), fallback, {
imp.change_state(&wrap, transition) imp.change_state(&wrap, transition).into()
}) })
.to_glib() .to_glib()
} }

View file

@ -14,8 +14,9 @@ fn tutorial_main() {
let pipeline = gst::parse_launch(&format!("playbin uri={}", uri)).unwrap(); let pipeline = gst::parse_launch(&format!("playbin uri={}", uri)).unwrap();
// Start playing // Start playing
let ret = pipeline.set_state(gst::State::Playing); pipeline
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Playing)
.expect("Unable to set the pipeline to the `Playing` state");
// Wait until error or EOS // Wait until error or EOS
let bus = pipeline.get_bus().unwrap(); let bus = pipeline.get_bus().unwrap();
@ -38,8 +39,9 @@ fn tutorial_main() {
} }
// Shutdown pipeline // Shutdown pipeline
let ret = pipeline.set_state(gst::State::Null); pipeline
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Null)
.expect("Unable to set the pipeline to the `Null` state");
} }
fn main() { fn main() {

View file

@ -19,8 +19,8 @@ fn tutorial_main() -> Result<(), Error> {
let pipeline = gst::parse_launch(&format!("playbin uri={}", uri))?; let pipeline = gst::parse_launch(&format!("playbin uri={}", uri))?;
// Start playing // Start playing
let ret = pipeline.set_state(gst::State::Playing).into_result()?; let res = pipeline.set_state(gst::State::Playing)?;
let is_live = ret == gst::StateChangeSuccess::NoPreroll; let is_live = res == gst::StateChangeSuccess::NoPreroll;
let main_loop = glib::MainLoop::new(None, false); let main_loop = glib::MainLoop::new(None, false);
let main_loop_clone = main_loop.clone(); let main_loop_clone = main_loop.clone();

View file

@ -25,12 +25,9 @@ fn tutorial_main() {
source.set_property_from_str("pattern", "smpte"); source.set_property_from_str("pattern", "smpte");
// Start playing // Start playing
let ret = pipeline.set_state(gst::State::Playing); pipeline
assert_ne!( .set_state(gst::State::Playing)
ret, .expect("Unable to set the pipeline to the `Playing` state");
gst::StateChangeReturn::Failure,
"Unable to set the pipeline to the Playing state."
);
// Wait until error or EOS // Wait until error or EOS
let bus = pipeline.get_bus().unwrap(); let bus = pipeline.get_bus().unwrap();
@ -51,12 +48,9 @@ fn tutorial_main() {
} }
} }
let ret = pipeline.set_state(gst::State::Null); pipeline
assert_ne!( .set_state(gst::State::Null)
ret, .expect("Unable to set the pipeline to the `Null` state");
gst::StateChangeReturn::Failure,
"Unable to set the pipeline to the Null state."
);
} }
fn main() { fn main() {

View file

@ -76,8 +76,8 @@ fn tutorial_main() {
return; return;
} }
let ret = src_pad.link(&sink_pad); let res = src_pad.link(&sink_pad);
if ret != gst::PadLinkReturn::Ok { if !res.is_ok() {
println!("Type is {} but link failed.", new_pad_type); println!("Type is {} but link failed.", new_pad_type);
} else { } else {
println!("Link succeeded (type {}).", new_pad_type); println!("Link succeeded (type {}).", new_pad_type);
@ -85,12 +85,9 @@ fn tutorial_main() {
}); });
// Start playing // Start playing
let ret = pipeline.set_state(gst::State::Playing); pipeline
assert_ne!( .set_state(gst::State::Playing)
ret, .expect("Unable to set the pipeline to the `Playing` state");
gst::StateChangeReturn::Failure,
"Unable to set the pipeline to the Playing state."
);
// Wait until error or EOS // Wait until error or EOS
let bus = pipeline.get_bus().unwrap(); let bus = pipeline.get_bus().unwrap();
@ -124,12 +121,9 @@ fn tutorial_main() {
} }
} }
let ret = pipeline.set_state(gst::State::Null); pipeline
assert_ne!( .set_state(gst::State::Null)
ret, .expect("Unable to set the pipeline to the `Null` state");
gst::StateChangeReturn::Failure,
"Unable to set the pipeline to the Null state."
);
} }
fn main() { fn main() {

View file

@ -32,8 +32,9 @@ fn tutorial_main() {
.expect("Can't set uri property on playbin"); .expect("Can't set uri property on playbin");
// Start playing // Start playing
let ret = playbin.set_state(gst::State::Playing); playbin
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Playing)
.expect("Unable to set the playbin to the `Playing` state");
// Listen to the bus // Listen to the bus
let bus = playbin.get_bus().unwrap(); let bus = playbin.get_bus().unwrap();
@ -92,8 +93,10 @@ fn tutorial_main() {
} }
// Shutdown pipeline // Shutdown pipeline
let ret = custom_data.playbin.set_state(gst::State::Null); custom_data
assert_ne!(ret, gst::StateChangeReturn::Failure); .playbin
.set_state(gst::State::Null)
.expect("Unable to set the playbin to the `Null` state");
} }
fn handle_message(custom_data: &mut CustomData, msg: &gst::GstRc<gst::MessageRef>) { fn handle_message(custom_data: &mut CustomData, msg: &gst::GstRc<gst::MessageRef>) {

View file

@ -121,8 +121,7 @@ mod tutorial5 {
let pipeline = &pipeline; let pipeline = &pipeline;
pipeline pipeline
.set_state(gst::State::Playing) .set_state(gst::State::Playing)
.into_result() .expect("Unable to set the pipeline to the `Playing` state");
.unwrap();
}); });
let pause_button = gtk::Button::new_from_icon_name( let pause_button = gtk::Button::new_from_icon_name(
@ -134,8 +133,7 @@ mod tutorial5 {
let pipeline = &pipeline; let pipeline = &pipeline;
pipeline pipeline
.set_state(gst::State::Paused) .set_state(gst::State::Paused)
.into_result() .expect("Unable to set the pipeline to the `Paused` state");
.unwrap();
}); });
let stop_button = gtk::Button::new_from_icon_name( let stop_button = gtk::Button::new_from_icon_name(
@ -145,7 +143,9 @@ mod tutorial5 {
let pipeline = playbin.clone(); let pipeline = playbin.clone();
stop_button.connect_clicked(move |_| { stop_button.connect_clicked(move |_| {
let pipeline = &pipeline; let pipeline = &pipeline;
pipeline.set_state(gst::State::Ready).into_result().unwrap(); pipeline
.set_state(gst::State::Ready)
.expect("Unable to set the pipeline to the `Ready` state");
}); });
let slider = gtk::Scale::new_with_range( let slider = gtk::Scale::new_with_range(
@ -372,7 +372,9 @@ mod tutorial5 {
// We just set the pipeline to READY (which stops playback). // We just set the pipeline to READY (which stops playback).
gst::MessageView::Eos(..) => { gst::MessageView::Eos(..) => {
println!("End-Of-Stream reached."); println!("End-Of-Stream reached.");
pipeline.set_state(gst::State::Ready).into_result().unwrap(); pipeline
.set_state(gst::State::Ready)
.expect("Unable to set the pipeline to the `Ready` state");
} }
// This is called when an error message is posted on the bus // This is called when an error message is posted on the bus
@ -401,12 +403,13 @@ mod tutorial5 {
playbin playbin
.set_state(gst::State::Playing) .set_state(gst::State::Playing)
.into_result() .expect("Unable to set the playbin to the `Playing` state");
.unwrap();
gtk::main(); gtk::main();
window.hide(); window.hide();
playbin.set_state(gst::State::Null).into_result().unwrap(); playbin
.set_state(gst::State::Null)
.expect("Unable to set the playbin to the `Null` state");
bus.remove_signal_watch(); bus.remove_signal_watch();
} }

View file

@ -111,10 +111,10 @@ fn tutorial_main() {
print_pad_capabilities(&sink, "sink"); print_pad_capabilities(&sink, "sink");
// Start playing // Start playing
let ret = pipeline.set_state(gst::State::Playing); let res = pipeline.set_state(gst::State::Playing);
if ret == gst::StateChangeReturn::Failure { if res.is_err() {
eprintln!( eprintln!(
"Unable to set the pipeline to the playing state (check the bus for error messages)." "Unable to set the pipeline to the `Playing` state (check the bus for error messages)."
) )
} }
@ -159,8 +159,9 @@ fn tutorial_main() {
} }
// Shutdown pipeline // Shutdown pipeline
let ret = pipeline.set_state(gst::State::Null); pipeline
assert_ne!(ret, gst::StateChangeReturn::Failure); .set_state(gst::State::Null)
.expect("Unable to set the pipeline to the `Null` state");
} }
fn main() { fn main() {

View file

@ -53,7 +53,7 @@ fn tutorial_main() {
tee_audio_pad.get_name() tee_audio_pad.get_name()
); );
let queue_audio_pad = audio_queue.get_static_pad("sink").unwrap(); let queue_audio_pad = audio_queue.get_static_pad("sink").unwrap();
tee_audio_pad.link(&queue_audio_pad).into_result().unwrap(); tee_audio_pad.link(&queue_audio_pad).unwrap();
let tee_video_pad = tee.get_request_pad("src_%u").unwrap(); let tee_video_pad = tee.get_request_pad("src_%u").unwrap();
println!( println!(
@ -61,12 +61,11 @@ fn tutorial_main() {
tee_video_pad.get_name() tee_video_pad.get_name()
); );
let queue_video_pad = video_queue.get_static_pad("sink").unwrap(); let queue_video_pad = video_queue.get_static_pad("sink").unwrap();
tee_video_pad.link(&queue_video_pad).into_result().unwrap(); tee_video_pad.link(&queue_video_pad).unwrap();
pipeline pipeline
.set_state(gst::State::Playing) .set_state(gst::State::Playing)
.into_result() .expect("Unable to set the pipeline to the `Playing` state");
.expect("Unable to set the pipeline to the Playing state.");
let bus = pipeline.get_bus().unwrap(); let bus = pipeline.get_bus().unwrap();
for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) { for msg in bus.iter_timed(gst::CLOCK_TIME_NONE) {
use gst::MessageView; use gst::MessageView;
@ -87,8 +86,7 @@ fn tutorial_main() {
pipeline pipeline
.set_state(gst::State::Null) .set_state(gst::State::Null)
.into_result() .expect("Unable to set the pipeline to the `Null` state");
.expect("Unable to set the pipeline to the Null state.");
} }
fn main() { fn main() {

View file

@ -108,7 +108,7 @@ fn main() {
tee_audio_pad.get_name() tee_audio_pad.get_name()
); );
let queue_audio_pad = audio_queue.get_static_pad("sink").unwrap(); let queue_audio_pad = audio_queue.get_static_pad("sink").unwrap();
tee_audio_pad.link(&queue_audio_pad).into_result().unwrap(); tee_audio_pad.link(&queue_audio_pad).unwrap();
let tee_video_pad = tee.get_request_pad("src_%u").unwrap(); let tee_video_pad = tee.get_request_pad("src_%u").unwrap();
println!( println!(
@ -116,10 +116,10 @@ fn main() {
tee_video_pad.get_name() tee_video_pad.get_name()
); );
let queue_video_pad = video_queue.get_static_pad("sink").unwrap(); let queue_video_pad = video_queue.get_static_pad("sink").unwrap();
tee_video_pad.link(&queue_video_pad).into_result().unwrap(); tee_video_pad.link(&queue_video_pad).unwrap();
let tee_app_pad = tee.get_request_pad("src_%u").unwrap(); let tee_app_pad = tee.get_request_pad("src_%u").unwrap();
let queue_app_pad = app_queue.get_static_pad("sink").unwrap(); let queue_app_pad = app_queue.get_static_pad("sink").unwrap();
tee_app_pad.link(&queue_app_pad).into_result().unwrap(); tee_app_pad.link(&queue_app_pad).unwrap();
// configure appsrc // configure appsrc
let info = AudioInfo::new(gst_audio::AudioFormat::S16le, SAMPLE_RATE, 1) let info = AudioInfo::new(gst_audio::AudioFormat::S16le, SAMPLE_RATE, 1)
@ -195,10 +195,7 @@ fn main() {
(data.appsrc.clone(), buffer) (data.appsrc.clone(), buffer)
}; };
match appsrc.push_buffer(buffer) { glib::Continue(appsrc.push_buffer(buffer).is_ok())
gst::FlowReturn::Ok => glib::Continue(true),
_ => glib::Continue(false),
}
})); }));
} }
}); });
@ -225,7 +222,7 @@ fn main() {
appsink.connect_new_sample(move |_| { appsink.connect_new_sample(move |_| {
let data = match data_weak.upgrade() { let data = match data_weak.upgrade() {
Some(data) => data, Some(data) => data,
None => return gst::FlowReturn::Ok, None => return Ok(gst::FlowSuccess::Ok),
}; };
let appsink = { let appsink = {
@ -240,7 +237,7 @@ fn main() {
let _ = io::stdout().flush(); let _ = io::stdout().flush();
} }
gst::FlowReturn::Ok Ok(gst::FlowSuccess::Ok)
}); });
let main_loop = glib::MainLoop::new(None, false); let main_loop = glib::MainLoop::new(None, false);
@ -263,15 +260,13 @@ fn main() {
pipeline pipeline
.set_state(gst::State::Playing) .set_state(gst::State::Playing)
.into_result() .expect("Unable to set the pipeline to the `Playing` state.");
.expect("Unable to set the pipeline to the Playing state.");
main_loop.run(); main_loop.run();
pipeline pipeline
.set_state(gst::State::Null) .set_state(gst::State::Null)
.into_result() .expect("Unable to set the pipeline to the `Null` state.");
.expect("Unable to set the pipeline to the Null state.");
bus.remove_signal_watch(); bus.remove_signal_watch();
} }