diff options
author | Sebastian Dröge <sebastian@centricular.com> | 2020-06-22 11:03:52 +0300 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2020-06-22 11:28:19 +0300 |
commit | 9bb3e75fb9f64b531fa5ac60776c4c934b635e47 (patch) | |
tree | 7bd5447060340b6b0e12975734f1f9a94c610caa /net | |
parent | c917e77687f6d7b4de22c5a27bcf48a27982b2cc (diff) |
Update to use the new pad builders for safely setting pad functions
Only two uses of unsafely setting the pad functions is left:
- fallbacksrc for overriding the chain function of the proxy pad of a
ghost pad
- threadshare for overriding the pad functions after creationg, which
probably needs some fixing at some point
Diffstat (limited to 'net')
-rw-r--r-- | net/reqwest/tests/reqwesthttpsrc.rs | 29 | ||||
-rw-r--r-- | net/rusoto/src/aws_transcribe_parse.rs | 81 |
2 files changed, 56 insertions, 54 deletions
diff --git a/net/reqwest/tests/reqwesthttpsrc.rs b/net/reqwest/tests/reqwesthttpsrc.rs index 4daa14215..661a3c321 100644 --- a/net/reqwest/tests/reqwesthttpsrc.rs +++ b/net/reqwest/tests/reqwesthttpsrc.rs @@ -65,21 +65,26 @@ impl Harness { let (sender, receiver) = mpsc::sync_channel(0); // Sink pad that receives everything the source is generating - let pad = gst::Pad::new(Some("sink"), gst::PadDirection::Sink); + let pad = gst::Pad::builder(Some("sink"), gst::PadDirection::Sink) + .chain_function({ + let sender_clone = sender.clone(); + move |_pad, _parent, buffer| { + let _ = sender_clone.send(Message::Buffer(buffer)); + Ok(gst::FlowSuccess::Ok) + } + }) + .event_function({ + let sender_clone = sender.clone(); + move |_pad, _parent, event| { + let _ = sender_clone.send(Message::Event(event)); + true + } + }) + .build(); + let srcpad = src.get_static_pad("src").unwrap(); srcpad.link(&pad).unwrap(); - // Collect all buffers, events and messages sent from the source - let sender_clone = sender.clone(); - pad.set_chain_function(move |_pad, _parent, buffer| { - let _ = sender_clone.send(Message::Buffer(buffer)); - Ok(gst::FlowSuccess::Ok) - }); - let sender_clone = sender.clone(); - pad.set_event_function(move |_pad, _parent, event| { - let _ = sender_clone.send(Message::Event(event)); - true - }); let bus = gst::Bus::new(); bus.set_flushing(false); src.set_bus(Some(&bus)); diff --git a/net/rusoto/src/aws_transcribe_parse.rs b/net/rusoto/src/aws_transcribe_parse.rs index 259d8de94..49523814a 100644 --- a/net/rusoto/src/aws_transcribe_parse.rs +++ b/net/rusoto/src/aws_transcribe_parse.rs @@ -230,43 +230,6 @@ fn build_packet(payload: &[u8]) -> Vec<u8> { } impl Transcriber { - fn set_pad_functions(sinkpad: &gst::Pad, srcpad: &gst::Pad) { - sinkpad.set_chain_function(|pad, parent, buffer| { - Transcriber::catch_panic_pad_function( - parent, - || Err(gst::FlowError::Error), - |transcriber, element| transcriber.sink_chain(pad, element, buffer), - ) - }); - sinkpad.set_event_function(|pad, parent, event| { - Transcriber::catch_panic_pad_function( - parent, - || false, - |transcriber, element| transcriber.sink_event(pad, element, event), - ) - }); - - srcpad.set_activatemode_function(|pad, parent, mode, active| { - Transcriber::catch_panic_pad_function( - parent, - || { - Err(gst_loggable_error!( - CAT, - "Panic activating src pad with mode" - )) - }, - |transcriber, element| transcriber.src_activatemode(pad, element, mode, active), - ) - }); - srcpad.set_query_function(|pad, parent, query| { - Transcriber::catch_panic_pad_function( - parent, - || false, - |transcriber, element| transcriber.src_query(pad, element, query), - ) - }); - } - fn dequeue(&self, element: &gst::Element) -> bool { /* First, check our pending buffers */ let mut items = vec![]; @@ -1031,13 +994,47 @@ impl ObjectSubclass for Transcriber { fn with_class(klass: &subclass::simple::ClassStruct<Self>) -> Self { let templ = klass.get_pad_template("sink").unwrap(); - let sinkpad = gst::Pad::from_template(&templ, Some("sink")); - let templ = klass.get_pad_template("src").unwrap(); - let srcpad = gst::Pad::from_template(&templ, Some("src")); + let sinkpad = gst::Pad::builder_with_template(&templ, Some("sink")) + .chain_function(|pad, parent, buffer| { + Transcriber::catch_panic_pad_function( + parent, + || Err(gst::FlowError::Error), + |transcriber, element| transcriber.sink_chain(pad, element, buffer), + ) + }) + .event_function(|pad, parent, event| { + Transcriber::catch_panic_pad_function( + parent, + || false, + |transcriber, element| transcriber.sink_event(pad, element, event), + ) + }) + .build(); - srcpad.use_fixed_caps(); + let templ = klass.get_pad_template("src").unwrap(); + let srcpad = gst::Pad::builder_with_template(&templ, Some("src")) + .activatemode_function(|pad, parent, mode, active| { + Transcriber::catch_panic_pad_function( + parent, + || { + Err(gst_loggable_error!( + CAT, + "Panic activating src pad with mode" + )) + }, + |transcriber, element| transcriber.src_activatemode(pad, element, mode, active), + ) + }) + .query_function(|pad, parent, query| { + Transcriber::catch_panic_pad_function( + parent, + || false, + |transcriber, element| transcriber.src_query(pad, element, query), + ) + }) + .flags(gst::PadFlags::FIXED_CAPS) + .build(); - Transcriber::set_pad_functions(&sinkpad, &srcpad); let settings = Mutex::new(Settings::default()); Self { |