diff options
author | Jordan Petridis <jordan@centricular.com> | 2022-08-26 20:31:19 +0300 |
---|---|---|
committer | Sebastian Dröge <sebastian@centricular.com> | 2022-09-05 11:47:37 +0300 |
commit | d8e38942097557009269f2e74c75f633e19c8b48 (patch) | |
tree | dfc52d2acf41354990b111e8196ee12f6d7d5941 /utils/togglerecord | |
parent | a60f4e9ae8c406eff615d66a2cab5eb9457bb95a (diff) |
togglerecord: Port example to GTK 4
Diffstat (limited to 'utils/togglerecord')
-rw-r--r-- | utils/togglerecord/Cargo.toml | 5 | ||||
-rw-r--r-- | utils/togglerecord/examples/gtk_recording.rs | 56 |
2 files changed, 29 insertions, 32 deletions
diff --git a/utils/togglerecord/Cargo.toml b/utils/togglerecord/Cargo.toml index a1f288b9..f7582408 100644 --- a/utils/togglerecord/Cargo.toml +++ b/utils/togglerecord/Cargo.toml @@ -12,7 +12,8 @@ rust-version = "1.63" gst = { package = "gstreamer", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } gst-audio = { package = "gstreamer-audio", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } gst-video = { package = "gstreamer-video", git = "https://gitlab.freedesktop.org/gstreamer/gstreamer-rs" } -gtk = { git = "https://github.com/gtk-rs/gtk3-rs", optional = true } +gst-plugin-gtk4 = { path = "../../video/gtk4", optional = true } +gtk = { package = "gtk4", git = "https://github.com/gtk-rs/gtk4-rs", optional = true } gio = { git = "https://github.com/gtk-rs/gtk-rs-core", optional = true } parking_lot = "0.12" once_cell = "1.0" @@ -28,7 +29,7 @@ path = "src/lib.rs" [[example]] name = "gtk-recording" path = "examples/gtk_recording.rs" -required-features = ["gtk", "gio"] +required-features = ["gtk", "gio", "gst-plugin-gtk4"] [build-dependencies] gst-plugin-version-helper = { path="../../version-helper" } diff --git a/utils/togglerecord/examples/gtk_recording.rs b/utils/togglerecord/examples/gtk_recording.rs index 748e3530..a5ce8d1d 100644 --- a/utils/togglerecord/examples/gtk_recording.rs +++ b/utils/togglerecord/examples/gtk_recording.rs @@ -11,6 +11,7 @@ use gst::prelude::*; use gio::prelude::*; use gtk::prelude::*; +use gtk::Inhibit; use std::cell::RefCell; fn create_pipeline() -> ( @@ -19,7 +20,6 @@ fn create_pipeline() -> ( gst::Pad, gst::Element, gst::Element, - gtk::Widget, ) { let pipeline = gst::Pipeline::new(None); @@ -37,18 +37,7 @@ fn create_pipeline() -> ( let video_convert1 = gst::ElementFactory::make("videoconvert", None).unwrap(); let video_convert2 = gst::ElementFactory::make("videoconvert", None).unwrap(); - let (video_sink, video_widget) = - if let Ok(gtkglsink) = gst::ElementFactory::make("gtkglsink", None) { - let glsinkbin = gst::ElementFactory::make("glsinkbin", None).unwrap(); - glsinkbin.set_property("sink", >kglsink); - - let widget = gtkglsink.property::<gtk::Widget>("widget"); - (glsinkbin, widget) - } else { - let sink = gst::ElementFactory::make("gtksink", None).unwrap(); - let widget = sink.property::<gtk::Widget>("widget"); - (sink, widget) - }; + let video_sink = gst::ElementFactory::make("gtk4paintablesink", None).unwrap(); let video_enc = gst::ElementFactory::make("x264enc", None).unwrap(); video_enc.set_property("rc-lookahead", 10i32); @@ -177,35 +166,41 @@ fn create_pipeline() -> ( audio_queue2.static_pad("sink").unwrap(), togglerecord, video_sink, - video_widget, ) } fn create_ui(app: >k::Application) { - let (pipeline, video_pad, audio_pad, togglerecord, video_sink, video_widget) = - create_pipeline(); + let (pipeline, video_pad, audio_pad, togglerecord, video_sink) = create_pipeline(); - let window = gtk::Window::new(gtk::WindowType::Toplevel); + let window = gtk::ApplicationWindow::new(app); window.set_default_size(320, 240); - let vbox = gtk::Box::new(gtk::Orientation::Vertical, 0); - vbox.pack_start(&video_widget, true, true, 0); - let hbox = gtk::Box::new(gtk::Orientation::Horizontal, 0); + let vbox = gtk::Box::new(gtk::Orientation::Vertical, 6); + let picture = gtk::Picture::new(); + let paintable = video_sink.property::<gtk::gdk::Paintable>("paintable"); + picture.set_paintable(Some(&paintable)); + vbox.append(&picture); + + let hbox = gtk::Box::new(gtk::Orientation::Horizontal, 6); + hbox.set_hexpand(true); + hbox.set_homogeneous(true); let position_label = gtk::Label::new(Some("Position: 00:00:00")); - hbox.pack_start(&position_label, true, true, 5); + hbox.append(&position_label); let recorded_duration_label = gtk::Label::new(Some("Recorded: 00:00:00")); - hbox.pack_start(&recorded_duration_label, true, true, 5); - vbox.pack_start(&hbox, false, false, 5); + hbox.append(&recorded_duration_label); + vbox.append(&hbox); - let hbox = gtk::Box::new(gtk::Orientation::Horizontal, 0); + let hbox = gtk::Box::new(gtk::Orientation::Horizontal, 6); + hbox.set_hexpand(true); + hbox.set_homogeneous(true); let record_button = gtk::Button::with_label("Record"); - hbox.pack_start(&record_button, true, true, 5); + hbox.append(&record_button); let finish_button = gtk::Button::with_label("Finish"); - hbox.pack_start(&finish_button, true, true, 5); - vbox.pack_start(&hbox, false, false, 5); + hbox.append(&finish_button); + vbox.append(&hbox); - window.add(&vbox); - window.show_all(); + window.set_child(Some(&vbox)); + window.show(); app.add_window(&window); @@ -265,7 +260,7 @@ fn create_ui(app: >k::Application) { }); let app_weak = app.downgrade(); - window.connect_delete_event(move |_, _| { + window.connect_close_request(move |_| { let app = match app_weak.upgrade() { Some(app) => app, None => return Inhibit(false), @@ -324,6 +319,7 @@ fn main() { gtk::init().unwrap(); gsttogglerecord::plugin_register_static().expect("Failed to register togglerecord plugin"); + gstgtk4::plugin_register_static().expect("Failed to register gtk4paintablesink plugin"); let app = gtk::Application::new(None, gio::ApplicationFlags::FLAGS_NONE); |