[cheese/three-point-oh] Basic video preview works



commit 9787de161afa872485d5db5a7f3bbc17799f62e3
Author: Yuvaraj Pandian T <yuvipanda gmail com>
Date:   Sun Jun 6 21:10:12 2010 +0530

    Basic video preview works

 configure.ac                                       |    2 +
 libcheese/cheese-camera.c                          |   34 +++--
 libcheese/cheese-camera.h                          |    3 +-
 valasrc/Makefile.am                                |    9 +-
 valasrc/cheese-main.vala                           |    2 +
 valasrc/cheese-window.vala                         |   23 ++-
 valasrc/vapi/cheese-common.deps                    |    2 +
 valasrc/vapi/cheese-common.vapi                    |  169 ++++++++++++++++++++
 ...{cheesethumbview.vapi => cheese-thumbview.vapi} |    0
 9 files changed, 218 insertions(+), 26 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 1161741..c1ef434 100644
--- a/configure.ac
+++ b/configure.ac
@@ -90,6 +90,7 @@ PANGOCAIRO_REQUIRED=1.18.0
 LIBRSVG_REQUIRED=2.18.0
 CLUTTER_REQUIRED=1.0
 CLUTTERGTK_REQUIRED=0.10
+CLUTTERGST_REQUIRED=0.10
 
 #*******************************************************************************
 # Check for udev
@@ -147,6 +148,7 @@ PKG_CHECK_MODULES(CHEESE, \
   librsvg-2.0 >= $LIBRSVG_REQUIRED \
   clutter-1.0 >= $CLUTTER_REQUIRED \
   clutter-gtk-0.10 >= $CLUTTERGTK_REQUIRED \
+  clutter-gst-0.10 >= $CLUTTERGST_REQUIRED \
   libcanberra-gtk $UDEV_PKG)
 AC_SUBST(CHEESE_CFLAGS)
 
diff --git a/libcheese/cheese-camera.c b/libcheese/cheese-camera.c
index 453fcde..cb37d70 100644
--- a/libcheese/cheese-camera.c
+++ b/libcheese/cheese-camera.c
@@ -27,6 +27,8 @@
 #include <glib.h>
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
+#include <clutter/clutter.h>
+#include <clutter-gst/clutter-gst.h>
 #include <gdk/gdkx.h>
 #include <gst/gst.h>
 #include <gdk-pixbuf/gdk-pixbuf.h>
@@ -63,6 +65,8 @@ typedef struct
   GstElement *audio_enc;
   GstElement *video_enc;
 
+  ClutterTexture *video_texture;
+  
   GstElement *effect_filter, *csp_post_effect;
   GstElement *video_balance, *csp_post_balance;
 
@@ -88,7 +92,7 @@ typedef struct
 enum
 {
   PROP_0,
-  PROP_VIDEO_WINDOW,
+  PROP_VIDEO_TEXTURE,
   PROP_DEVICE_NAME,
   PROP_FORMAT,
 };
@@ -155,7 +159,7 @@ cheese_camera_bus_sync_handler (GstBus *bus, GstMessage *message, CheeseCamera *
   if (!gst_structure_has_name (message->structure, "prepare-xwindow-id"))
     return GST_BUS_PASS;
 
-  overlay = GST_X_OVERLAY (GST_MESSAGE_SRC (message));
+  /*  overlay = GST_X_OVERLAY (GST_MESSAGE_SRC (message));
 
   if (g_object_class_find_property (G_OBJECT_GET_CLASS (overlay),
                                     "force-aspect-ratio"))
@@ -164,7 +168,7 @@ cheese_camera_bus_sync_handler (GstBus *bus, GstMessage *message, CheeseCamera *
   gst_x_overlay_set_xwindow_id (overlay,
                                 GDK_WINDOW_XWINDOW (gtk_widget_get_window (priv->video_window)));
 
-  gst_message_unref (message);
+  gst_message_unref (message);   */
 
   return GST_BUS_DROP;
 }
@@ -477,7 +481,7 @@ cheese_camera_create_video_display_bin (CheeseCamera *camera, GError **error)
     g_object_set (video_scale, "method", 1, NULL);
   }
 
-  if ((video_sink = gst_element_factory_make ("gconfvideosink", "video_sink")) == NULL)
+  if ((video_sink = clutter_gst_video_sink_new(priv->video_texture)) == NULL)
   {
     cheese_camera_set_error_element_not_found (error, "gconfvideosink");
   }
@@ -978,8 +982,8 @@ cheese_camera_get_property (GObject *object, guint prop_id, GValue *value,
 
   switch (prop_id)
   {
-    case PROP_VIDEO_WINDOW:
-      g_value_set_pointer (value, priv->video_window);
+    case PROP_VIDEO_TEXTURE:
+      g_value_set_pointer (value, priv->video_texture);
       break;
     case PROP_DEVICE_NAME:
       g_value_set_string (value, priv->device_name);
@@ -1004,10 +1008,10 @@ cheese_camera_set_property (GObject *object, guint prop_id, const GValue *value,
 
   switch (prop_id)
   {
-    case PROP_VIDEO_WINDOW:
-      priv->video_window = g_value_get_pointer (value);
-      g_signal_connect (priv->video_window, "expose-event",
-                        G_CALLBACK (cheese_camera_expose_cb), self);
+    case PROP_VIDEO_TEXTURE:
+      priv->video_texture = g_value_get_pointer (value);
+      //      g_signal_connect (priv->video_window, "expose-event",
+      //                G_CALLBACK (cheese_camera_expose_cb), self);
       break;
     case PROP_DEVICE_NAME:
       g_free (priv->device_name);
@@ -1060,8 +1064,8 @@ cheese_camera_class_init (CheeseCameraClass *klass)
                                               G_TYPE_NONE, 0);
 
 
-  g_object_class_install_property (object_class, PROP_VIDEO_WINDOW,
-                                   g_param_spec_pointer ("video-window",
+  g_object_class_install_property (object_class, PROP_VIDEO_TEXTURE,
+                                   g_param_spec_pointer ("video-texture",
                                                          NULL,
                                                          NULL,
                                                          G_PARAM_READWRITE));
@@ -1098,7 +1102,7 @@ cheese_camera_init (CheeseCamera *camera)
 }
 
 CheeseCamera *
-cheese_camera_new (GtkWidget *video_window, char *camera_device_name,
+cheese_camera_new (ClutterTexture *video_texture, char *camera_device_name,
                    int x_resolution, int y_resolution)
 {
   CheeseCamera      *camera;
@@ -1109,13 +1113,13 @@ cheese_camera_new (GtkWidget *video_window, char *camera_device_name,
 
   if (camera_device_name)
   {
-    camera = g_object_new (CHEESE_TYPE_CAMERA, "video-window", video_window,
+    camera = g_object_new (CHEESE_TYPE_CAMERA, "video-texture", video_texture,
                            "device_name", camera_device_name,
                            "format", format, NULL);
   }
   else
   {
-    camera = g_object_new (CHEESE_TYPE_CAMERA, "video-window", video_window,
+    camera = g_object_new (CHEESE_TYPE_CAMERA, "video-texture", video_texture,
                            "format", format, NULL);
   }
 
diff --git a/libcheese/cheese-camera.h b/libcheese/cheese-camera.h
index 14c13b9..9348086 100644
--- a/libcheese/cheese-camera.h
+++ b/libcheese/cheese-camera.h
@@ -26,6 +26,7 @@
 #include <glib-object.h>
 #include <gtk/gtk.h>
 #include <gst/interfaces/xoverlay.h>
+#include <clutter/clutter.h>
 #include <cheese-camera-device.h>
 
 G_BEGIN_DECLS
@@ -75,7 +76,7 @@ enum CheeseCameraError
 };
 
 GType         cheese_camera_get_type (void);
-CheeseCamera *cheese_camera_new (GtkWidget *video_window,
+CheeseCamera *cheese_camera_new (ClutterTexture *video_texture,
                                  char      *camera_device_name,
                                  int        x_resolution,
                                  int        y_resolution);
diff --git a/valasrc/Makefile.am b/valasrc/Makefile.am
index 0bff714..2691aad 100644
--- a/valasrc/Makefile.am
+++ b/valasrc/Makefile.am
@@ -7,8 +7,10 @@ VALAFLAGS = \
 	--pkg clutter-1.0 \
 	--pkg clutter-gtk-0.10 \
 	--pkg gconf-2.0 \
+	--pkg gstreamer-0.10 \
 	--pkg eogthumbnav \
-	--pkg cheesethumbview
+	--pkg cheese-thumbview \
+	--pkg cheese-common
 
 
 AM_CPPFLAGS = \
@@ -21,7 +23,8 @@ AM_CPPFLAGS = \
 	-DPACKAGE_LOCALEDIR=\""$(datadir)/locale"\"	\
 	-DGNOME_DESKTOP_USE_UNSTABLE_API=1 \
 	$(CHEESE_CFLAGS) \
-	-include $(CONFIG_HEADER) 
+	-include $(CONFIG_HEADER) \
+	-I top_srcdir@/libcheese 
 
 AM_CFLAGS = \
 	-export-dynamic
@@ -37,6 +40,6 @@ cheese_SOURCES = \
 	thumbview/eog-thumb-nav.c \
 	thumbview/eog-thumbnail.c
 
-
 cheese_LDADD = \
+	$(top_builddir)/libcheese/libcheesecommon.la \
 	$(CHEESE_LIBS)
diff --git a/valasrc/cheese-main.vala b/valasrc/cheese-main.vala
index 85748ae..6685f72 100644
--- a/valasrc/cheese-main.vala
+++ b/valasrc/cheese-main.vala
@@ -1,6 +1,7 @@
 using GLib;
 using Gtk;
 using Clutter;
+using Gst;
 
 public class Cheese.Main {
 	static bool verbose;
@@ -37,6 +38,7 @@ public class Cheese.Main {
 			context.add_main_entries (options, null);
 			context.add_group (Gtk.get_option_group (true));
 			context.add_group (Clutter.get_option_group ());
+			context.add_group (Gst.init_get_option_group ());
 			context.parse (ref args);
 		} catch (OptionError e) {
 			stdout.printf ("%s\n", e.message);
diff --git a/valasrc/cheese-window.vala b/valasrc/cheese-window.vala
index f3f3279..08826eb 100644
--- a/valasrc/cheese-window.vala
+++ b/valasrc/cheese-window.vala
@@ -4,7 +4,7 @@ using GtkClutter;
 using Clutter;
 using Config;
 using Eog;
-
+using Gst;
 const int FULLSCREEN_TIMEOUT_INTERVAL = 5 * 1000;
 
 enum MODE {
@@ -45,6 +45,8 @@ public class Cheese.MainWindow : Gtk.Window {
 	private bool is_wide_mode;
 
 	private Gtk.Button[] buttons;
+
+	private Cheese.Camera camera;
 	
 	[CCode (instance_pos = -1)]
 	internal void on_quit (Action action ) {
@@ -224,7 +226,12 @@ public class Cheese.MainWindow : Gtk.Window {
 			this.size_request(out req);
 			this.resize(req.width, req.height);
 		}
-	}				
+	}
+
+	[CCode (instance_pos = -1)]
+	internal void on_take_action (Action action ) {
+		camera.take_photo("/home/yuvipanda/image.jpg");
+	}
 	
 	public	void setup_ui () {
 		builder = new Builder();
@@ -265,19 +272,21 @@ public class Cheese.MainWindow : Gtk.Window {
 				   effects_toggle_button,
 				   leave_fullscreen_button};
 		
-		Clutter.Rectangle r = new Clutter.Rectangle();
-		r.width = 200;
+		Clutter.Texture r = new Clutter.Texture();
+		r.width = 600;
 		r.height = 600;
 		r.x = 0;
 		r.y = 0;
-		r.color = Clutter.Color.from_string("Red");
+//		r.color = Clutter.Color.from_string("Red");
 		viewport.add_actor(r);
-
+		camera = new Camera(r, "/dev/video0", 1024, 768);
 		thumb_view = new Cheese.ThumbView();
 		thumb_nav = new Eog.ThumbNav(thumb_view, false);
 		
 		viewport.show_all();
-		
+
+		camera.setup("/dev/video0");
+		camera.play();
 		set_wide_mode(false, true);
 		set_mode(MODE.PHOTO);
 		
diff --git a/valasrc/vapi/cheese-common.deps b/valasrc/vapi/cheese-common.deps
new file mode 100644
index 0000000..e1da2ea
--- /dev/null
+++ b/valasrc/vapi/cheese-common.deps
@@ -0,0 +1,2 @@
+gstreamer-0.10
+clutter-1.0
diff --git a/valasrc/vapi/cheese-common.vapi b/valasrc/vapi/cheese-common.vapi
new file mode 100644
index 0000000..8d0b757
--- /dev/null
+++ b/valasrc/vapi/cheese-common.vapi
@@ -0,0 +1,169 @@
+/* cheese-common.vapi generated by vapigen, do not modify. */
+
+[CCode (cprefix = "Cheese", lower_case_cprefix = "cheese_")]
+namespace Cheese {
+	[CCode (cheader_filename = "cheese-camera.h")]
+	public class Camera : GLib.Object {
+		[CCode (has_construct_function = false)]
+		public Camera (Clutter.Texture video_texture, string camera_device_name, int x_resolution, int y_resolution);
+		public bool get_balance_property_range (string property, double min, double max, double def);
+		public unowned GLib.PtrArray get_camera_devices ();
+		public unowned Cheese.VideoFormat get_current_video_format ();
+		public int get_num_camera_devices ();
+		public unowned Cheese.CameraDevice get_selected_device ();
+		public unowned GLib.List get_video_formats ();
+		public bool has_camera ();
+		public void play ();
+		public void set_balance_property (string property, double value);
+		public void set_device_by_dev_file (string file);
+		public void set_device_by_dev_udi (string udi);
+		public void set_effect (Cheese.CameraEffect effect);
+		public void set_video_format (Cheese.VideoFormat format);
+		public void setup (string udi) throws GLib.Error;
+		public void start_video_recording (string filename);
+		public void stop ();
+		public void stop_video_recording ();
+		public bool switch_camera_device ();
+		public bool take_photo (string filename);
+		public bool take_photo_pixbuf ();
+		[NoAccessorMethod]
+		public string device_name { owned get; set; }
+		[NoAccessorMethod]
+		public Cheese.VideoFormat format { owned get; set; }
+		[NoAccessorMethod]
+		public void* video_texture { get; set; }
+		public virtual signal void photo_saved ();
+		public virtual signal void photo_taken (Gdk.Pixbuf pixbuf);
+		public virtual signal void video_saved ();
+	}
+	[CCode (cheader_filename = "cheese-camera-device.h")]
+	public class CameraDevice : GLib.Object, GLib.Initable {
+		[CCode (has_construct_function = false)]
+		public CameraDevice (string device_id, string device_file, string product_name, int api_version) throws GLib.Error;
+		public unowned Cheese.VideoFormat get_best_format ();
+		public unowned Gst.Caps get_caps_for_format (Cheese.VideoFormat format);
+		public unowned string get_device_file ();
+		public unowned GLib.List get_format_list ();
+		public unowned string get_id ();
+		public unowned string get_name ();
+		public unowned string get_src ();
+		[NoAccessorMethod]
+		public int api { get; construct; }
+		public string device_file { get; construct; }
+		[NoAccessorMethod]
+		public string device_id { owned get; construct; }
+		public string name { get; construct; }
+	}
+
+	[CCode (cheader_filename = "cheese-camera-device-monitor.h")]
+	public class CameraDeviceMonitor : GLib.Object {
+		[CCode (has_construct_function = false)]
+		public CameraDeviceMonitor ();
+		public void coldplug ();
+		public virtual signal void added (string id, string device_file, string product_name, int api_version);
+		public virtual signal void removed (string id);
+	}
+
+	
+	[Compact]
+	[CCode (cheader_filename = "cheese-fileutil.h")]
+	public class FileUtil {
+		public weak GLib.Object parent;
+		[CCode (cname = "cheese_fileutil_new", has_construct_function = false)]
+		public FileUtil ();
+		[CCode (cname = "cheese_fileutil_get_log_path")]
+		public unowned string get_log_path ();
+		[CCode (cname = "cheese_fileutil_get_new_media_filename")]
+		public unowned string get_new_media_filename (Cheese.MediaMode mode);
+		[CCode (cname = "cheese_fileutil_get_path_before_224")]
+		public unowned string get_path_before_224 ();
+		[CCode (cname = "cheese_fileutil_get_photo_path")]
+		public unowned string get_photo_path ();
+		[CCode (cname = "cheese_fileutil_get_video_path")]
+		public unowned string get_video_path ();
+		[CCode (cname = "cheese_fileutil_reset_burst")]
+		public void reset_burst ();
+	}
+	[Compact]
+	[CCode (cheader_filename = "cheese-flash.h")]
+	public class Flash {
+		public weak GLib.Object parent_instance;
+		[CCode (has_construct_function = false)]
+		public Flash (Gtk.Widget parent);
+		public void fire ();
+	}
+	[CCode (cheader_filename = "cheese-gconf.h")]
+	public class GConf : GLib.Object {
+		[CCode (has_construct_function = false)]
+		public GConf ();
+		[NoAccessorMethod]
+		public double gconf_prop_brightness { get; set; }
+		[NoAccessorMethod]
+		public int gconf_prop_burst_delay { get; set; }
+		[NoAccessorMethod]
+		public int gconf_prop_burst_repeat { get; set; }
+		[NoAccessorMethod]
+		public string gconf_prop_camera { owned get; set; }
+		[NoAccessorMethod]
+		public double gconf_prop_contrast { get; set; }
+		[NoAccessorMethod]
+		public bool gconf_prop_countdown { get; set; }
+		[NoAccessorMethod]
+		public bool gconf_prop_enable_delete { get; set; }
+		[NoAccessorMethod]
+		public double gconf_prop_hue { get; set; }
+		[NoAccessorMethod]
+		public string gconf_prop_photo_path { owned get; set; }
+		[NoAccessorMethod]
+		public double gconf_prop_saturation { get; set; }
+		[NoAccessorMethod]
+		public string gconf_prop_selected_effects { owned get; set; }
+		[NoAccessorMethod]
+		public string gconf_prop_video_path { owned get; set; }
+		[NoAccessorMethod]
+		public bool gconf_prop_wide_mode { get; set; }
+		[NoAccessorMethod]
+		public int gconf_prop_x_resolution { get; set; }
+		[NoAccessorMethod]
+		public int gconf_prop_y_resolution { get; set; }
+	}
+	[Compact]
+	[CCode (type_id = "CHEESE_TYPE_VIDEO_FORMAT", cheader_filename = "cheese-camera-device.h")]
+	public class VideoFormat {
+		public int height;
+		public int width;
+	}
+	[CCode (cprefix = "CHEESE_CAMERA_EFFECT_", has_type_id = false, cheader_filename = "cheese-camera.h")]
+	public enum CameraEffect {
+		NO_EFFECT,
+		MAUVE,
+		NOIR_BLANC,
+		SATURATION,
+		HULK,
+		VERTICAL_FLIP,
+		HORIZONTAL_FLIP,
+		SHAGADELIC,
+		VERTIGO,
+		EDGE,
+		DICE,
+		WARP
+	}
+	[CCode (cprefix = "CHEESE_MEDIA_MODE_", has_type_id = false, cheader_filename = "cheese-gtk.h")]
+	public enum MediaMode {
+		PHOTO,
+		VIDEO,
+		BURST
+	}
+	[CCode (cprefix = "CHEESE_WIDGET_STATE_", cheader_filename = "cheese-fileutil.h")]
+	public enum WidgetState {
+		NONE,
+		READY,
+		ERROR
+	}
+	[CCode (cheader_filename = "cheese-countdown.h")]
+	public delegate void cheese_countdown_cb_t ();
+	[CCode (cheader_filename = "cheese-fileutil.h")]
+	public const string PHOTO_NAME_SUFFIX;
+	[CCode (cheader_filename = "cheese-fileutil.h")]
+	public const string VIDEO_NAME_SUFFIX;
+}
diff --git a/valasrc/vapi/cheesethumbview.vapi b/valasrc/vapi/cheese-thumbview.vapi
similarity index 100%
rename from valasrc/vapi/cheesethumbview.vapi
rename to valasrc/vapi/cheese-thumbview.vapi



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