cheese r703 - in branches/cheese-vala: . src



Author: jhaitsma
Date: Wed Apr 30 22:14:10 2008
New Revision: 703
URL: http://svn.gnome.org/viewvc/cheese?rev=703&view=rev

Log:
More stuff on cheese-webcam.vala


Modified:
   branches/cheese-vala/   (props changed)
   branches/cheese-vala/src/Makefile.am
   branches/cheese-vala/src/cheese-webcam.vala
   branches/cheese-vala/src/cheese-window.vala

Modified: branches/cheese-vala/src/Makefile.am
==============================================================================
--- branches/cheese-vala/src/Makefile.am	(original)
+++ branches/cheese-vala/src/Makefile.am	Wed Apr 30 22:14:10 2008
@@ -13,7 +13,8 @@
 	--pkg gdk-pixbuf-2.0 \
 	--pkg gdk-x11-2.0 \
 	--pkg gnome-vfs-2.0 \
-	--pkg hal
+	--pkg hal \
+	--pkg dbus-glib-1 
 	
 AM_CPPFLAGS = \
 	-DBINDIR=\"$(bindir)\"			 	\

Modified: branches/cheese-vala/src/cheese-webcam.vala
==============================================================================
--- branches/cheese-vala/src/cheese-webcam.vala	(original)
+++ branches/cheese-vala/src/cheese-webcam.vala	Wed Apr 30 22:14:10 2008
@@ -19,7 +19,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-using GLib, Gst, Gtk, Gdk, Gee, Hal;
+using GLib, Gst, Gtk, Gdk, Gee, Hal, DBus;
 
 public class Cheese.Webcam : GLib.Object {
 
@@ -41,6 +41,27 @@
 		WARP            = (1 << 10)
 	}
 	
+	
+	public struct FrameRate {
+		public int numerator;
+		public int denominator;
+	}
+
+	public struct VideoFormat {
+		public string mimetype;
+		public int width;
+		public int height;
+		public FrameRate[] framerates; 
+	}
+	
+	public struct Device {
+		public string udi;
+		public string device;
+		public string gstreamer_element_name;
+		public string product_name;
+		public VideoFormat[] video_format;
+	}
+	
 	enum ColorSpace {
 		YUV,
 		RGB
@@ -78,8 +99,9 @@
 		}
 	}
 
+	Device[] devices;
 	Pipeline pipeline; 
-  	Bus      bus;
+  	Gst.Bus  bus;
 	/* We build the active pipeline by linking the appropriate pipelines 
 	   listed below */
 	Gst.Bin webcam_source_bin;
@@ -122,9 +144,12 @@
   GHashTable *supported_resolutions;
 
 */
-
+	public Webcam (Widget window) {
+		this.video_window = window;
+	}
 
 	public void setup () {
+		detect_webcam_devices ();
 	}
 
 	public void play () {
@@ -142,9 +167,10 @@
 	public void take_photo (string filename) {
 	}
 
-	public int get_num_devices () {
-		return 0;
+	public Device[] get_devices () {
+		return null;
 	}
+	
 	public void set_effect (Effect effect) {
 		
 	}
@@ -163,28 +189,111 @@
 		
 	}
 	
-	void on_bus_message (Bus bus, Message message) {
+	void on_bus_message (Gst.Bus bus, Message message) {
 		
 	}
 
-	void get_video_devices_from_hal () {
+	void get_video_devices_from_hal () throws WebcamError {
 		
+		RawError dbus_error;
+		
+		dbus_error.init ();
+		var hal = new Hal.Context ();
+
+		if (hal == null)
+			throw new WebcamError.FAILED ("Error getting HAL context");
+
+		if (!hal.set_dbus_connection (RawBus.get (BusType.SYSTEM, ref dbus_error))) 
+			throw new WebcamError.FAILED ("Error setting dbus connection: %s".printf (dbus_error.message));
+		
+		
+		if (!hal.init (ref dbus_error))
+			throw new WebcamError.FAILED ("Cannot initialize connection to the hald\nNormally this means that the HAL deamon (hald) is not running or not ready");
+
+		string[] udis;
+	
+		udis = hal.find_device_by_capability ("video4linux", ref dbus_error);
+		if (dbus_error.is_set ()) 
+			throw new WebcamError.FAILED ("Error finding video4linux devices: %s: %s".printf (dbus_error.name, dbus_error.message));
+
+		devices = new Device [udis.length];
+
+		for (int i = 0; i < udis.length; i++) {
+			devices[i].udi=udis[i];
+			devices[i].device = hal.device_get_property_string (udis[i], "video4linux.device", ref dbus_error);
+			if (dbus_error.is_set ()) 
+				throw new WebcamError.FAILED ("Error getting property string: %s: %s".printf (dbus_error.name, dbus_error.message));				
+		}
+	
 	}
 	
+	
 	void get_supported_framerates () {
 		
 	}
 	
-	void get_supported_video_formats () {
+	void get_supported_video_formats (Device device, Caps caps) {
 		
 	}
-	
-	void get_webcam_device_data () {
+
+	const string[] GSTREAMER_VIDEO_SOURCES = {
+		"v4l2src",
+		"v4lsrc"
+	};
+
+	void get_webcam_device_data (Device device) {
+		
+		
+		bool pipeline_works = false;
+		int i = 0;	
+		while (!pipeline_works && (i < GSTREAMER_VIDEO_SOURCES.length)) {
+			var pipeline_desc = "%s name=source device=%s ! fakesink".printf (GSTREAMER_VIDEO_SOURCES[i],
+											  device.device);
+			try {
+				var pipeline = parse_launch (pipeline_desc);
+				if (pipeline != null) {
+					pipeline.set_state (State.PLAYING);
+					
+					var ret = pipeline.get_state (null, null, 10*SECOND);
+					/* Check if any error messages were posted on the bus */
+					var bus = pipeline.get_bus ();
+					weak Gst.Message msg;
+					msg = bus.poll (Gst.MessageType.ERROR, 0);
+
+					if ((msg == null) && (ret == StateChangeReturn.SUCCESS)) {
+						pipeline_works = true;
+						pipeline.set_state (State.PAUSED);
+						device.gstreamer_element_name = GSTREAMER_VIDEO_SOURCES[i];
+						var src = ((Gst.Bin)pipeline).get_by_name ("source");
+						string name;
+						src.get ("device-name", ref name);
+						if (name == null)
+							name = "Unknown";
+						
+						print ("Detected webcam: %s\n", name);
+						device.product_name = name;
+						
+						var pad = src.get_pad ("src");
+						var caps = pad.get_caps ();
+						get_supported_video_formats (device, caps);
+					}
+					pipeline.set_state (State.NULL);
+				}
+				
+			} catch (GLib.Error e) {
+				warning ("parse_launch error: " + e.message);
+			}
+			i++;
+		}
 		
 	}
-	
+
 	void detect_webcam_devices () {
 		
+		get_video_devices_from_hal ();
+		foreach (Device d in devices) {
+			get_webcam_device_data (d);
+		}
 	}
 	
 	bool create_webcam_source_bin () {
@@ -235,3 +344,7 @@
 		}
 	}	
 }
+
+public errordomain WebcamError {
+	FAILED
+}

Modified: branches/cheese-vala/src/cheese-window.vala
==============================================================================
--- branches/cheese-vala/src/cheese-window.vala	(original)
+++ branches/cheese-vala/src/cheese-window.vala	Wed Apr 30 22:14:10 2008
@@ -46,7 +46,7 @@
 
 	int counter = 0;
 
-	//CheeseWebcam webcam;
+	Webcam webcam;
 	//WebcamMode webcam_mode;
 
 	const string GCONF_COUNTDOWN_KEY = "/apps/cheese/countdown";
@@ -291,6 +291,8 @@
 		media_path = Path.build_filename (Environment.get_home_dir(), ".local", "share", "cheese", "media");
 		DirUtils.create_with_parents (media_path, 0775);
 		setup_ui ();
+		webcam = new Webcam (screen);
+		webcam.setup ();
 	}
 
 	void setup_ui () {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]