From facaae6be9fec12894741a94987c8d806efdbe0c Mon Sep 17 00:00:00 2001 From: Philippe Normand Date: Wed, 30 Aug 2017 15:00:28 +0100 Subject: [PATCH] examples: Quartz support for the gtkvideooverlay example Fixes https://github.com/sdroege/gstreamer-rs/pull/31 --- examples/Cargo.toml | 2 ++ examples/src/bin/gtkvideooverlay.rs | 26 ++++++++++++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 48e951f88..fbb7bc55a 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -22,6 +22,8 @@ byte-slice-cast = "0.1" gst-player = ["gstreamer-player"] gtksink = ["gtk", "gio"] gtkvideooverlay = ["gtk", "gdk", "gio"] +gtkvideooverlay-x11 = ["gtkvideooverlay"] +gtkvideooverlay-quartz = ["gtkvideooverlay"] tokio = ["gstreamer/futures", "futures", "tokio-core"] default-features = [] diff --git a/examples/src/bin/gtkvideooverlay.rs b/examples/src/bin/gtkvideooverlay.rs index a8a87e8e9..bef8a1754 100644 --- a/examples/src/bin/gtkvideooverlay.rs +++ b/examples/src/bin/gtkvideooverlay.rs @@ -47,8 +47,10 @@ fn create_ui(app: >k::Application) { let pipeline = gst::Pipeline::new(None); let src = gst::ElementFactory::make("videotestsrc", None).unwrap(); - let sink = if cfg!(unix) { + let sink = if cfg!(feature = "gtkvideooverlay-x11") { gst::ElementFactory::make("xvimagesink", None).unwrap() + } else if cfg!(feature = "gtkvideooverlay-quartz") { + gst::ElementFactory::make("glimagesink", None).unwrap() } else { unreachable!() }; @@ -76,10 +78,9 @@ fn create_ui(app: >k::Application) { process::exit(-1); } - #[cfg(unix)] - { - let display_type_name = gdk_window.get_display().get_type().name(); + let display_type_name = gdk_window.get_display().get_type().name(); + if cfg!(feature = "gtkvideooverlay-x11") { // Check if we're using X11 or ... if display_type_name == "GdkX11Display" { extern "C" { @@ -96,7 +97,24 @@ fn create_ui(app: >k::Application) { println!("Add support for display type '{}'", display_type_name); process::exit(-1); } + } else if cfg!(feature = "gtkvideooverlay-quartz") { + if display_type_name == "GdkQuartzDisplay" { + extern "C" { + pub fn gdk_quartz_window_get_nsview( + window: *mut glib::object::GObject, + ) -> *mut c_void; + } + + unsafe { + let window = gdk_quartz_window_get_nsview(gdk_window.to_glib_none().0); + video_overlay.set_window_handle(window as usize); + } + } else { + println!("Unsupported display type '{}", display_type_name); + process::exit(-1); + } } + }); vbox.pack_start(&video_window, true, true, 0);