Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // -*- Mode: vala; indent-tabs-mode: nil; tab-width: 4 -*-
- /***
- BEGIN LICENSE
- Copyright (C) 2011-2013 Mario Guerriero <mario@elementaryos.org>
- This program is free software: you can redistribute it and/or modify it
- under the terms of the GNU Lesser General Public License version 3, as
- published by the Free Software Foundation.
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranties of
- MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
- PURPOSE. See the GNU General Public License for more details.
- You should have received a copy of the GNU General Public License along
- with this program. If not, see <http://www.gnu.org/licenses>
- END LICENSE
- ***/
- namespace Snap.Widgets {
- public class Camera : Gtk.DrawingArea {
- private uint* xid;
- private Gst.Element? camerabin = null;
- public class Camera () {
- this.realize.connect (() => {
- this.get_window ().ensure_native ();
- xid = (uint*)Gdk.X11Window.get_xid (this.get_window ());
- });
- this.camerabin = Gst.ElementFactory.make ("camerabin", "camera");
- var bus = this.camerabin.get_bus ();
- bus.add_watch (Priority.DEFAULT, on_bus_watch);
- bus.set_sync_handler (on_bus_callback);
- var wrapper_src = Gst.ElementFactory.make ("wrappercamerabinsrc", null);
- camerabin.set ("camera-source", wrapper_src);
- var v4l2_src = Gst.ElementFactory.make ("v4l2src", null);
- wrapper_src.set ("video-source", v4l2_src);
- var gudev = new GUdev.Client ({ "video4linux", null });
- var devices = gudev.query_by_subsystem ("video4linux");
- var device_file = devices.data.get_device_file ();
- v4l2_src.set ("device", device_file);
- this.play ();
- this.show_all ();
- }
- private bool on_bus_watch (Gst.Bus bus, Gst.Message message) {
- if(Gst.Video.is_video_overlay_prepare_window_handle_message(message))
- (message.src as Gst.Video.Overlay).set_window_handle(xid);
- return true;
- }
- private Gst.BusSyncReply on_bus_callback (Gst.Bus bus, Gst.Message message) {
- if (message.type != Gst.MessageType.ELEMENT)
- return Gst.BusSyncReply.PASS;
- if (!message.has_name ("prepare-window-handle"))
- return Gst.BusSyncReply.PASS;
- var overlay = message.src as Gst.Video.Overlay;
- overlay.set_window_handle (Camera.xid);
- return Gst.BusSyncReply.DROP;
- }
- public void play () {
- this.camerabin.set_state (Gst.State.PLAYING);
- }
- public void stop () {
- this.camerabin.set_state (Gst.State.NULL);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement