mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-29 04:51:09 +00:00
examples: Make use of glib::closure!
for the overlay-composition example
This commit is contained in:
parent
eecce101da
commit
1ebfaee644
1 changed files with 114 additions and 115 deletions
|
@ -116,7 +116,6 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
|
|||
info: None,
|
||||
}));
|
||||
|
||||
let drawer_clone = drawer.clone();
|
||||
// Connect to the overlaycomposition element's "draw" signal, which is emitted for
|
||||
// each videoframe piped through the element. The signal handler needs to
|
||||
// return a gst_video::VideoOverlayComposition to be drawn on the frame
|
||||
|
@ -128,15 +127,15 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
|
|||
//
|
||||
// In this case, the signal passes the gst::Element and a gst::Sample with
|
||||
// the current buffer
|
||||
overlay.connect("draw", false, move |args| {
|
||||
overlay.connect_closure(
|
||||
"draw",
|
||||
false,
|
||||
glib::closure!(@strong drawer => move |_overlay: &gst::Element,
|
||||
sample: &gst::Sample| {
|
||||
use std::f64::consts::PI;
|
||||
|
||||
let drawer = &drawer_clone;
|
||||
let drawer = drawer.lock().unwrap();
|
||||
|
||||
// Get the signal's arguments
|
||||
let _overlay = args[0].get::<gst::Element>().unwrap();
|
||||
let sample = args[1].get::<gst::Sample>().unwrap();
|
||||
let buffer = sample.buffer().unwrap();
|
||||
let timestamp = buffer.pts().unwrap();
|
||||
|
||||
|
@ -242,12 +241,10 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
|
|||
gst_video::VideoOverlayFormatFlags::PREMULTIPLIED_ALPHA,
|
||||
);
|
||||
|
||||
Some(
|
||||
gst_video::VideoOverlayComposition::new(Some(&rect))
|
||||
.unwrap()
|
||||
.to_value(),
|
||||
)
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
// Add a signal handler to the overlay's "caps-changed" signal. This could e.g.
|
||||
// be called when the sink that we render to does not support resizing the image
|
||||
|
@ -256,15 +253,17 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
|
|||
// resize our canvas's size.
|
||||
// Another possibility for when this might happen is, when our video is a network
|
||||
// stream that dynamically changes resolution when enough bandwith is available.
|
||||
overlay.connect("caps-changed", false, move |args| {
|
||||
let _overlay = args[0].get::<gst::Element>().unwrap();
|
||||
let caps = args[1].get::<gst::Caps>().unwrap();
|
||||
|
||||
overlay.connect_closure(
|
||||
"caps-changed",
|
||||
false,
|
||||
glib::closure!(move |_overlay: &gst::Element,
|
||||
caps: &gst::Caps,
|
||||
_width: u32,
|
||||
_height: u32| {
|
||||
let mut drawer = drawer.lock().unwrap();
|
||||
drawer.info = Some(gst_video::VideoInfo::from_caps(&caps).unwrap());
|
||||
|
||||
None
|
||||
});
|
||||
drawer.info = Some(gst_video::VideoInfo::from_caps(caps).unwrap());
|
||||
}),
|
||||
);
|
||||
|
||||
Ok(pipeline)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue