mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-25 11:01:10 +00:00
Update to new clone macro syntax
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1463>
This commit is contained in:
parent
0be8b364f8
commit
5ea912d702
5 changed files with 172 additions and 149 deletions
26
Cargo.lock
generated
26
Cargo.lock
generated
|
@ -169,7 +169,7 @@ checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9"
|
|||
[[package]]
|
||||
name = "cairo-rs"
|
||||
version = "0.20.0"
|
||||
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#d88a7c473e2af36a4718a648406b7894d288ec1b"
|
||||
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#dc97710becdf432e5a97e0b7c22d4d1daa8cfec6"
|
||||
dependencies = [
|
||||
"bitflags 2.5.0",
|
||||
"cairo-sys-rs",
|
||||
|
@ -181,7 +181,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "cairo-sys-rs"
|
||||
version = "0.20.0"
|
||||
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#d88a7c473e2af36a4718a648406b7894d288ec1b"
|
||||
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#dc97710becdf432e5a97e0b7c22d4d1daa8cfec6"
|
||||
dependencies = [
|
||||
"glib-sys",
|
||||
"libc",
|
||||
|
@ -678,7 +678,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "gio"
|
||||
version = "0.20.0"
|
||||
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#d88a7c473e2af36a4718a648406b7894d288ec1b"
|
||||
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#dc97710becdf432e5a97e0b7c22d4d1daa8cfec6"
|
||||
dependencies = [
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
|
@ -695,7 +695,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "gio-sys"
|
||||
version = "0.20.0"
|
||||
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#d88a7c473e2af36a4718a648406b7894d288ec1b"
|
||||
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#dc97710becdf432e5a97e0b7c22d4d1daa8cfec6"
|
||||
dependencies = [
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
|
@ -724,7 +724,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "glib"
|
||||
version = "0.20.0"
|
||||
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#d88a7c473e2af36a4718a648406b7894d288ec1b"
|
||||
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#dc97710becdf432e5a97e0b7c22d4d1daa8cfec6"
|
||||
dependencies = [
|
||||
"bitflags 2.5.0",
|
||||
"futures-channel",
|
||||
|
@ -745,7 +745,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "glib-macros"
|
||||
version = "0.20.0"
|
||||
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#d88a7c473e2af36a4718a648406b7894d288ec1b"
|
||||
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#dc97710becdf432e5a97e0b7c22d4d1daa8cfec6"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro-crate",
|
||||
|
@ -757,7 +757,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "glib-sys"
|
||||
version = "0.20.0"
|
||||
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#d88a7c473e2af36a4718a648406b7894d288ec1b"
|
||||
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#dc97710becdf432e5a97e0b7c22d4d1daa8cfec6"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"system-deps",
|
||||
|
@ -820,7 +820,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "gobject-sys"
|
||||
version = "0.20.0"
|
||||
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#d88a7c473e2af36a4718a648406b7894d288ec1b"
|
||||
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#dc97710becdf432e5a97e0b7c22d4d1daa8cfec6"
|
||||
dependencies = [
|
||||
"glib-sys",
|
||||
"libc",
|
||||
|
@ -1679,7 +1679,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"windows-targets 0.52.5",
|
||||
"windows-targets 0.48.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1898,7 +1898,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "pango"
|
||||
version = "0.20.0"
|
||||
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#d88a7c473e2af36a4718a648406b7894d288ec1b"
|
||||
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#dc97710becdf432e5a97e0b7c22d4d1daa8cfec6"
|
||||
dependencies = [
|
||||
"gio",
|
||||
"glib",
|
||||
|
@ -1909,7 +1909,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "pango-sys"
|
||||
version = "0.20.0"
|
||||
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#d88a7c473e2af36a4718a648406b7894d288ec1b"
|
||||
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#dc97710becdf432e5a97e0b7c22d4d1daa8cfec6"
|
||||
dependencies = [
|
||||
"glib-sys",
|
||||
"gobject-sys",
|
||||
|
@ -1920,7 +1920,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "pangocairo"
|
||||
version = "0.20.0"
|
||||
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#d88a7c473e2af36a4718a648406b7894d288ec1b"
|
||||
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#dc97710becdf432e5a97e0b7c22d4d1daa8cfec6"
|
||||
dependencies = [
|
||||
"cairo-rs",
|
||||
"glib",
|
||||
|
@ -1932,7 +1932,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "pangocairo-sys"
|
||||
version = "0.20.0"
|
||||
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#d88a7c473e2af36a4718a648406b7894d288ec1b"
|
||||
source = "git+https://github.com/gtk-rs/gtk-rs-core?branch=master#dc97710becdf432e5a97e0b7c22d4d1daa8cfec6"
|
||||
dependencies = [
|
||||
"cairo-sys-rs",
|
||||
"glib-sys",
|
||||
|
|
|
@ -132,116 +132,125 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
|
|||
overlay.connect_closure(
|
||||
"draw",
|
||||
false,
|
||||
glib::closure!(@strong drawer => move |_overlay: &gst::Element,
|
||||
sample: &gst::Sample| {
|
||||
use std::f64::consts::PI;
|
||||
glib::closure!(
|
||||
#[strong]
|
||||
drawer,
|
||||
move |_overlay: &gst::Element, sample: &gst::Sample| {
|
||||
use std::f64::consts::PI;
|
||||
|
||||
let drawer = drawer.lock().unwrap();
|
||||
let drawer = drawer.lock().unwrap();
|
||||
|
||||
let buffer = sample.buffer().unwrap();
|
||||
let timestamp = buffer.pts().unwrap();
|
||||
let buffer = sample.buffer().unwrap();
|
||||
let timestamp = buffer.pts().unwrap();
|
||||
|
||||
let info = drawer.info.as_ref().unwrap();
|
||||
let text_layout = &drawer.text_layout;
|
||||
let bitmap = drawer.bitmap.as_ref().unwrap();
|
||||
let render_target = drawer.render_target.as_ref().unwrap();
|
||||
let info = drawer.info.as_ref().unwrap();
|
||||
let text_layout = &drawer.text_layout;
|
||||
let bitmap = drawer.bitmap.as_ref().unwrap();
|
||||
let render_target = drawer.render_target.as_ref().unwrap();
|
||||
|
||||
let global_angle = 360. * (timestamp % (10 * gst::ClockTime::SECOND)).nseconds() as f64
|
||||
/ (10.0 * gst::ClockTime::SECOND.nseconds() as f64);
|
||||
let center_x = (info.width() / 2) as f32;
|
||||
let center_y = (info.height() / 2) as f32;
|
||||
let top_margin = (info.height() / 20) as f32;
|
||||
|
||||
unsafe {
|
||||
// Begin drawing
|
||||
render_target.BeginDraw();
|
||||
|
||||
// Clear background
|
||||
render_target.Clear(Some(&D2D1_COLOR_F {
|
||||
r: 0f32,
|
||||
g: 0f32,
|
||||
b: 0f32,
|
||||
a: 0f32,
|
||||
}));
|
||||
|
||||
// This loop will render 10 times the string "GStreamer" in a circle
|
||||
for i in 0..10 {
|
||||
let angle = (360. * f64::from(i)) / 10.0;
|
||||
let red = ((1.0 + f64::cos((angle - 60.0) * PI / 180.0)) / 2.0) as f32;
|
||||
let text_brush = render_target
|
||||
.CreateSolidColorBrush(
|
||||
&D2D1_COLOR_F {
|
||||
r: red,
|
||||
g: 0f32,
|
||||
b: 1f32 - red,
|
||||
a: 1f32,
|
||||
},
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let angle = (angle + global_angle) as f32;
|
||||
let matrix = Matrix3x2::rotation(angle, center_x, center_y);
|
||||
render_target.SetTransform(&matrix);
|
||||
render_target.DrawTextLayout(
|
||||
D2D_POINT_2F { x: 0f32, y: top_margin },
|
||||
text_layout,
|
||||
&text_brush,
|
||||
D2D1_DRAW_TEXT_OPTIONS_NONE,
|
||||
);
|
||||
}
|
||||
|
||||
// EndDraw may not be successful for some reasons.
|
||||
// Ignores any error in this example
|
||||
let _ = render_target.EndDraw(None, None);
|
||||
|
||||
// Make sure all operations is completed before copying
|
||||
// bitmap to buffer
|
||||
let _ = render_target.Flush(None::<*mut u64>, None::<*mut u64>);
|
||||
}
|
||||
|
||||
let mut buffer = gst::Buffer::with_size((info.width() * info.height() * 4) as usize).unwrap();
|
||||
{
|
||||
let buffer_mut = buffer.get_mut().unwrap();
|
||||
let mut map = buffer_mut.map_writable().unwrap();
|
||||
let dst = map.as_mut_slice_of::<u8>().unwrap();
|
||||
let global_angle = 360.
|
||||
* (timestamp % (10 * gst::ClockTime::SECOND)).nseconds() as f64
|
||||
/ (10.0 * gst::ClockTime::SECOND.nseconds() as f64);
|
||||
let center_x = (info.width() / 2) as f32;
|
||||
let center_y = (info.height() / 2) as f32;
|
||||
let top_margin = (info.height() / 20) as f32;
|
||||
|
||||
unsafe {
|
||||
// Bitmap size is equal to the background image size.
|
||||
// Copy entire memory
|
||||
bitmap.CopyPixels(std::ptr::null(), info.width() * 4, dst).unwrap();
|
||||
// Begin drawing
|
||||
render_target.BeginDraw();
|
||||
|
||||
// Clear background
|
||||
render_target.Clear(Some(&D2D1_COLOR_F {
|
||||
r: 0f32,
|
||||
g: 0f32,
|
||||
b: 0f32,
|
||||
a: 0f32,
|
||||
}));
|
||||
|
||||
// This loop will render 10 times the string "GStreamer" in a circle
|
||||
for i in 0..10 {
|
||||
let angle = (360. * f64::from(i)) / 10.0;
|
||||
let red = ((1.0 + f64::cos((angle - 60.0) * PI / 180.0)) / 2.0) as f32;
|
||||
let text_brush = render_target
|
||||
.CreateSolidColorBrush(
|
||||
&D2D1_COLOR_F {
|
||||
r: red,
|
||||
g: 0f32,
|
||||
b: 1f32 - red,
|
||||
a: 1f32,
|
||||
},
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let angle = (angle + global_angle) as f32;
|
||||
let matrix = Matrix3x2::rotation(angle, center_x, center_y);
|
||||
render_target.SetTransform(&matrix);
|
||||
render_target.DrawTextLayout(
|
||||
D2D_POINT_2F {
|
||||
x: 0f32,
|
||||
y: top_margin,
|
||||
},
|
||||
text_layout,
|
||||
&text_brush,
|
||||
D2D1_DRAW_TEXT_OPTIONS_NONE,
|
||||
);
|
||||
}
|
||||
|
||||
// EndDraw may not be successful for some reasons.
|
||||
// Ignores any error in this example
|
||||
let _ = render_target.EndDraw(None, None);
|
||||
|
||||
// Make sure all operations is completed before copying
|
||||
// bitmap to buffer
|
||||
let _ = render_target.Flush(None::<*mut u64>, None::<*mut u64>);
|
||||
}
|
||||
|
||||
let mut buffer =
|
||||
gst::Buffer::with_size((info.width() * info.height() * 4) as usize).unwrap();
|
||||
{
|
||||
let buffer_mut = buffer.get_mut().unwrap();
|
||||
let mut map = buffer_mut.map_writable().unwrap();
|
||||
let dst = map.as_mut_slice_of::<u8>().unwrap();
|
||||
|
||||
unsafe {
|
||||
// Bitmap size is equal to the background image size.
|
||||
// Copy entire memory
|
||||
bitmap
|
||||
.CopyPixels(std::ptr::null(), info.width() * 4, dst)
|
||||
.unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
gst_video::VideoMeta::add_full(
|
||||
buffer.get_mut().unwrap(),
|
||||
gst_video::VideoFrameFlags::empty(),
|
||||
gst_video::VideoFormat::Bgra,
|
||||
info.width(),
|
||||
info.height(),
|
||||
&[0],
|
||||
&[(info.width() * 4) as i32],
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// Turn the buffer into a VideoOverlayRectangle, then place
|
||||
// that into a VideoOverlayComposition and return it.
|
||||
//
|
||||
// A VideoOverlayComposition can take a Vec of such rectangles
|
||||
// spaced around the video frame, but we're just outputting 1
|
||||
// here
|
||||
let rect = gst_video::VideoOverlayRectangle::new_raw(
|
||||
&buffer,
|
||||
0,
|
||||
0,
|
||||
info.width(),
|
||||
info.height(),
|
||||
gst_video::VideoOverlayFormatFlags::PREMULTIPLIED_ALPHA,
|
||||
);
|
||||
|
||||
gst_video::VideoOverlayComposition::new(Some(&rect)).unwrap()
|
||||
}
|
||||
|
||||
gst_video::VideoMeta::add_full(
|
||||
buffer.get_mut().unwrap(),
|
||||
gst_video::VideoFrameFlags::empty(),
|
||||
gst_video::VideoFormat::Bgra,
|
||||
info.width(),
|
||||
info.height(),
|
||||
&[0],
|
||||
&[(info.width() * 4) as i32],
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
// Turn the buffer into a VideoOverlayRectangle, then place
|
||||
// that into a VideoOverlayComposition and return it.
|
||||
//
|
||||
// A VideoOverlayComposition can take a Vec of such rectangles
|
||||
// spaced around the video frame, but we're just outputting 1
|
||||
// here
|
||||
let rect = gst_video::VideoOverlayRectangle::new_raw(
|
||||
&buffer,
|
||||
0,
|
||||
0,
|
||||
info.width(),
|
||||
info.height(),
|
||||
gst_video::VideoOverlayFormatFlags::PREMULTIPLIED_ALPHA,
|
||||
);
|
||||
|
||||
gst_video::VideoOverlayComposition::new(Some(&rect))
|
||||
.unwrap()
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
// Add a signal handler to the overlay's "caps-changed" signal. This could e.g.
|
||||
|
|
|
@ -119,8 +119,9 @@ fn create_pipeline() -> Result<gst::Pipeline, Error> {
|
|||
overlay.connect_closure(
|
||||
"draw",
|
||||
false,
|
||||
glib::closure!(@strong drawer => move |_overlay: &gst::Element,
|
||||
sample: &gst::Sample| {
|
||||
glib::closure!(
|
||||
#[strong] drawer,
|
||||
move |_overlay: &gst::Element, sample: &gst::Sample| {
|
||||
use std::f64::consts::PI;
|
||||
|
||||
let drawer = drawer.lock().unwrap();
|
||||
|
|
|
@ -195,20 +195,25 @@ impl StreamProducer {
|
|||
let fku_probe_id = srcpad
|
||||
.add_probe(
|
||||
gst::PadProbeType::EVENT_UPSTREAM,
|
||||
glib::clone!(@weak appsink, @weak consumer => @default-panic, move |_pad, info| {
|
||||
let Some(event) = info.event() else {
|
||||
return gst::PadProbeReturn::Ok;
|
||||
};
|
||||
glib::clone!(
|
||||
#[weak]
|
||||
appsink,
|
||||
#[upgrade_or_panic]
|
||||
move |_pad, info| {
|
||||
let Some(event) = info.event() else {
|
||||
return gst::PadProbeReturn::Ok;
|
||||
};
|
||||
|
||||
if gst_video::UpstreamForceKeyUnitEvent::parse(event).is_ok() {
|
||||
gst::debug!(CAT, obj: &appsink, "Requesting keyframe");
|
||||
// Do not use `gst_element_send_event()` as it takes the state lock which may lead to dead locks.
|
||||
let pad = appsink.static_pad("sink").unwrap();
|
||||
let _ = pad.push_event(event.clone());
|
||||
if gst_video::UpstreamForceKeyUnitEvent::parse(event).is_ok() {
|
||||
gst::debug!(CAT, obj: &appsink, "Requesting keyframe");
|
||||
// Do not use `gst_element_send_event()` as it takes the state lock which may lead to dead locks.
|
||||
let pad = appsink.static_pad("sink").unwrap();
|
||||
let _ = pad.push_event(event.clone());
|
||||
}
|
||||
|
||||
gst::PadProbeReturn::Ok
|
||||
}
|
||||
|
||||
gst::PadProbeReturn::Ok
|
||||
}),
|
||||
),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
|
@ -410,7 +415,7 @@ impl<'a> From<&'a gst_app::AppSink> for StreamProducer {
|
|||
|
||||
appsink.set_callbacks(
|
||||
gst_app::AppSinkCallbacks::builder()
|
||||
.new_sample(glib::clone!(@strong consumers => move |appsink| {
|
||||
.new_sample(glib::clone!(#[strong] consumers, move |appsink| {
|
||||
let mut consumers = consumers.lock().unwrap();
|
||||
|
||||
let sample = match appsink.pull_sample() {
|
||||
|
@ -429,7 +434,7 @@ impl<'a> From<&'a gst_app::AppSink> for StreamProducer {
|
|||
|
||||
StreamProducer::process_sample(sample, appsink, consumers)
|
||||
}))
|
||||
.new_preroll(glib::clone!(@strong consumers => move |appsink| {
|
||||
.new_preroll(glib::clone!(#[strong] consumers, move |appsink| {
|
||||
let mut consumers = consumers.lock().unwrap();
|
||||
|
||||
let sample = match appsink.pull_preroll() {
|
||||
|
@ -448,7 +453,7 @@ impl<'a> From<&'a gst_app::AppSink> for StreamProducer {
|
|||
Ok(gst::FlowSuccess::Ok)
|
||||
}
|
||||
}))
|
||||
.new_event(glib::clone!(@strong consumers => move |appsink| {
|
||||
.new_event(glib::clone!(#[strong] consumers, move |appsink| {
|
||||
match appsink.pull_object().map(|obj| obj.downcast::<gst::Event>()) {
|
||||
Ok(Ok(event)) => {
|
||||
let (events_to_forward, appsrcs) = {
|
||||
|
@ -472,7 +477,7 @@ impl<'a> From<&'a gst_app::AppSink> for StreamProducer {
|
|||
|
||||
false
|
||||
}))
|
||||
.eos(glib::clone!(@strong consumers => move |appsink| {
|
||||
.eos(glib::clone!(#[strong] consumers, move |appsink| {
|
||||
let stream_consumers = consumers
|
||||
.lock()
|
||||
.unwrap();
|
||||
|
@ -499,21 +504,25 @@ impl<'a> From<&'a gst_app::AppSink> for StreamProducer {
|
|||
let sinkpad = appsink.static_pad("sink").unwrap();
|
||||
sinkpad.add_probe(
|
||||
gst::PadProbeType::EVENT_UPSTREAM,
|
||||
glib::clone!(@strong consumers => move |_pad, info| {
|
||||
let Some(event) = info.event() else {
|
||||
return gst::PadProbeReturn::Ok;
|
||||
};
|
||||
glib::clone!(
|
||||
#[strong]
|
||||
consumers,
|
||||
move |_pad, info| {
|
||||
let Some(event) = info.event() else {
|
||||
return gst::PadProbeReturn::Ok;
|
||||
};
|
||||
|
||||
let gst::EventView::Latency(event) = event.view() else {
|
||||
return gst::PadProbeReturn::Ok;
|
||||
};
|
||||
let gst::EventView::Latency(event) = event.view() else {
|
||||
return gst::PadProbeReturn::Ok;
|
||||
};
|
||||
|
||||
let latency = event.latency();
|
||||
let mut consumers = consumers.lock().unwrap();
|
||||
consumers.current_latency = Some(latency);
|
||||
let latency = event.latency();
|
||||
let mut consumers = consumers.lock().unwrap();
|
||||
consumers.current_latency = Some(latency);
|
||||
|
||||
gst::PadProbeReturn::Ok
|
||||
}),
|
||||
gst::PadProbeReturn::Ok
|
||||
}
|
||||
),
|
||||
);
|
||||
|
||||
StreamProducer {
|
||||
|
|
|
@ -387,11 +387,15 @@ mod tests {
|
|||
let called = Arc::new(Mutex::new(false));
|
||||
let succeeding_action_type = crate::ActionTypeBuilder::new(
|
||||
"succeeds",
|
||||
glib::clone!(@strong called => move |_, _action| {
|
||||
*called.lock().unwrap() = true;
|
||||
glib::clone!(
|
||||
#[strong]
|
||||
called,
|
||||
move |_, _action| {
|
||||
*called.lock().unwrap() = true;
|
||||
|
||||
Ok(crate::ActionSuccess::Ok)
|
||||
}),
|
||||
Ok(crate::ActionSuccess::Ok)
|
||||
}
|
||||
),
|
||||
)
|
||||
.parameter(
|
||||
crate::ActionParameterBuilder::new("always", "Does the action always succeeds")
|
||||
|
|
Loading…
Reference in a new issue