mirror of
https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs.git
synced 2025-04-28 07:55:22 +00:00
fallbacksrc: Use new proxy_pad_chain_function() support when building pads
Less unsafe code.
This commit is contained in:
parent
fc20df294e
commit
fe274ac6e7
1 changed files with 12 additions and 16 deletions
|
@ -781,25 +781,21 @@ impl FallbackSrc {
|
||||||
.get_pad_template(if is_audio { "audio" } else { "video" })
|
.get_pad_template(if is_audio { "audio" } else { "video" })
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let ghostpad = gst::GhostPad::builder_with_template(&templ, Some(&templ.get_name()))
|
let ghostpad = gst::GhostPad::builder_with_template(&templ, Some(&templ.get_name()))
|
||||||
|
.proxy_pad_chain_function({
|
||||||
|
let element_weak = element.downgrade();
|
||||||
|
move |pad, _parent, buffer| {
|
||||||
|
let element = match element_weak.upgrade() {
|
||||||
|
None => return Err(gst::FlowError::Flushing),
|
||||||
|
Some(element) => element,
|
||||||
|
};
|
||||||
|
|
||||||
|
let src = FallbackSrc::from_instance(&element);
|
||||||
|
src.proxy_pad_chain(&element, pad, buffer)
|
||||||
|
}
|
||||||
|
})
|
||||||
.build_with_target(&srcpad)
|
.build_with_target(&srcpad)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let proxypad = ghostpad.get_internal().expect("no internal pad");
|
|
||||||
let element_weak = element.downgrade();
|
|
||||||
// Safety: Nothing else can have a reference to the proxy pad yet apart from the ghost pad
|
|
||||||
// itself, so changing the chain function is still safe.
|
|
||||||
unsafe {
|
|
||||||
proxypad.set_chain_function(move |pad, _parent, buffer| {
|
|
||||||
let element = match element_weak.upgrade() {
|
|
||||||
None => return Err(gst::FlowError::Flushing),
|
|
||||||
Some(element) => element,
|
|
||||||
};
|
|
||||||
|
|
||||||
let src = FallbackSrc::from_instance(&element);
|
|
||||||
src.proxy_pad_chain(&element, pad, buffer)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
element.add_pad(&ghostpad).unwrap();
|
element.add_pad(&ghostpad).unwrap();
|
||||||
|
|
||||||
Ok(Stream {
|
Ok(Stream {
|
||||||
|
|
Loading…
Reference in a new issue