[cheese/three-point-oh] Added functions to show video with arbritary effect in arbritary structure



commit 92a4cbc048ce5912892d8581cbab38d37dea59dd
Author: Yuvaraj Pandian T <yuvipanda gmail com>
Date:   Sun Jun 27 04:07:47 2010 +0530

    Added functions to show video with arbritary effect in arbritary structure

 data/cheese-viewport.json       |    8 +++++
 libcheese/cheese-camera.c       |   63 +++++++++++++++++++++++++++++++--------
 libcheese/cheese-camera.h       |    1 +
 valasrc/cheese-window.vala      |    6 ++-
 valasrc/vapi/cheese-common.vapi |    1 +
 5 files changed, 64 insertions(+), 15 deletions(-)
---
diff --git a/data/cheese-viewport.json b/data/cheese-viewport.json
index 0d5cb3e..48b3a6d 100644
--- a/data/cheese-viewport.json
+++ b/data/cheese-viewport.json
@@ -6,6 +6,13 @@
     "child::y-align": "CLUTTER_BIN_ALIGNMENT_FILL"
 },
 {
+    "id": "testy",
+    "type": "ClutterTexture",
+    "child::x-align": "CLUTTER_BIN_ALIGNMENT_FILL",
+    "child::y-align": "CLUTTER_BIN_ALIGNMENT_FILL",
+    "opacity": 128
+},
+{
     "id": "countdown_layer",
     "type": "ClutterText",
     "child::x-align": "CLUTTER_BIN_ALIGNMENT_CENTER",
@@ -20,6 +27,7 @@
     "children":
     [
 	'video_preview',
+	"testy",
 	'countdown_layer'
     ] 
 },
diff --git a/libcheese/cheese-camera.c b/libcheese/cheese-camera.c
index 476bb3c..7e22db1 100644
--- a/libcheese/cheese-camera.c
+++ b/libcheese/cheese-camera.c
@@ -69,6 +69,7 @@ typedef struct
   
   GstElement *effect_filter, *csp_post_effect;
   GstElement *video_balance, *csp_post_balance;
+  GstElement *camera_tee;
 
   gulong photo_handler_signal_id;
 
@@ -397,7 +398,7 @@ cheese_camera_create_video_display_bin (CheeseCamera *camera, GError **error)
 {
   CheeseCameraPrivate *priv = CHEESE_CAMERA_GET_PRIVATE (camera);
 
-  GstElement *tee, *video_display_queue, *video_scale, *video_sink, *save_queue;
+  GstElement *save_tee, *video_display_queue, *video_scale, *video_sink, *save_queue;
 
   gboolean ok;
   GstPad  *pad;
@@ -406,6 +407,10 @@ cheese_camera_create_video_display_bin (CheeseCamera *camera, GError **error)
 
   cheese_camera_create_camera_source_bin (camera);
 
+  if ((priv->camera_tee = gst_element_factory_make ("tee", "camera_tee")) == NULL)
+  {
+      cheese_camera_set_error_element_not_found (error, "tee");
+  }      
   if ((priv->effect_filter = gst_element_factory_make ("identity", "effect")) == NULL)
   {
     cheese_camera_set_error_element_not_found (error, "identity");
@@ -425,7 +430,7 @@ cheese_camera_create_video_display_bin (CheeseCamera *camera, GError **error)
     return FALSE;
   }
 
-  if ((tee = gst_element_factory_make ("tee", "tee")) == NULL)
+  if ((save_tee = gst_element_factory_make ("tee", "save_tee")) == NULL)
   {
     cheese_camera_set_error_element_not_found (error, "tee");
   }
@@ -459,25 +464,30 @@ cheese_camera_create_video_display_bin (CheeseCamera *camera, GError **error)
     return FALSE;
 
   gst_bin_add_many (GST_BIN (priv->video_display_bin), priv->camera_source_bin,
+		    priv->camera_tee,
                     priv->effect_filter, priv->csp_post_effect,
                     priv->video_balance, priv->csp_post_balance,
-                    tee, save_queue,
+                    save_tee, save_queue,
                     video_display_queue, video_scale, video_sink, NULL);
 
-  ok = gst_element_link_many (priv->camera_source_bin, priv->effect_filter,
+  ok = gst_element_link_many (priv->camera_source_bin, priv->camera_tee, NULL);
+  ok &= gst_element_link_many (priv->camera_tee, priv->effect_filter,
                               priv->csp_post_effect,
                               priv->video_balance, priv->csp_post_balance,
-                              tee, NULL);
+                              save_tee, NULL);
 
-  ok &= gst_element_link_many (tee, save_queue, NULL);
-  ok &= gst_element_link_many (tee, video_display_queue, video_scale, video_sink, NULL);
+  ok &= gst_element_link_many (save_tee, save_queue, NULL);
+  ok &= gst_element_link_many (save_tee, video_display_queue, video_scale, video_sink, NULL);
 
   /* add ghostpad */
   pad = gst_element_get_pad (save_queue, "src");
   gst_element_add_pad (priv->video_display_bin, gst_ghost_pad_new ("src", pad));
   gst_object_unref (GST_OBJECT (pad));
 
-
+  //  gint b;
+  //  g_object_get(G_OBJECT (priv->camera_tee), "num-src-pads", &b, NULL);
+  ///g_critical("Blaaaaaaaaaaaaaaaaaaaaaah %d", b);
+  
   if (!ok)
     g_error ("Unable to create display pipeline");
 
@@ -759,13 +769,13 @@ cheese_camera_change_effect_filter (CheeseCamera *camera, GstElement *new_filter
 
   cheese_camera_stop (camera);
 
-  gst_element_unlink_many (priv->camera_source_bin, priv->effect_filter,
+  gst_element_unlink_many (priv->camera_tee, priv->effect_filter,
                            priv->csp_post_effect, NULL);
 
   gst_bin_remove (GST_BIN (priv->video_display_bin), priv->effect_filter);
 
   gst_bin_add (GST_BIN (priv->video_display_bin), new_filter);
-  ok = gst_element_link_many (priv->camera_source_bin, new_filter,
+  ok = gst_element_link_many (priv->camera_tee, new_filter,
                               priv->csp_post_effect, NULL);
   g_return_if_fail (ok);
 
@@ -775,8 +785,8 @@ cheese_camera_change_effect_filter (CheeseCamera *camera, GstElement *new_filter
   priv->effect_filter = new_filter;
 }
 
-void
-cheese_camera_set_effect (CheeseCamera *camera, CheeseEffect *effect)
+GstElement*
+cheese_camera_element_from_effect (CheeseCamera *camera, CheeseEffect *effect)
 {
   char       *effects_pipeline_desc;
   GstElement *effect_filter;
@@ -795,11 +805,38 @@ cheese_camera_set_effect (CheeseCamera *camera, CheeseEffect *effect)
     g_error_free (err);
     g_error ("ERROR effect_filter\n");
   }
+  g_free (effects_pipeline_desc);
+
+  return effect_filter;
+}
+
+void
+cheese_camera_set_effect (CheeseCamera *camera, CheeseEffect *effect)
+{
+  GstElement *effect_filter;
+  effect_filter = cheese_camera_element_from_effect (camera, effect);
   cheese_camera_change_effect_filter (camera, effect_filter);
+}
 
-  g_free (effects_pipeline_desc);
+void
+cheese_camera_connect_effect_texture (CheeseCamera *camera, CheeseEffect *effect, ClutterTexture *texture)
+{
+  CheeseCameraPrivate *priv = CHEESE_CAMERA_GET_PRIVATE (camera);
+    
+  GstElement *effect_filter;
+  GstElement *display_element;
+  GstElement *display_queue;
+  gboolean ok;
+
+  display_queue = gst_element_factory_make ("queue", "queue");
+  effect_filter = cheese_camera_element_from_effect (camera, effect);
+  display_element = clutter_gst_video_sink_new (texture);
+  
+  gst_bin_add_many (GST_BIN (priv->pipeline), effect_filter, display_queue, display_element, NULL);
+  ok = gst_element_link_many (priv->camera_tee, effect_filter, display_queue, display_element, NULL);  
 }
 
+
 void
 cheese_camera_start_video_recording (CheeseCamera *camera, char *filename)
 {
diff --git a/libcheese/cheese-camera.h b/libcheese/cheese-camera.h
index 815ef3b..c0783b1 100644
--- a/libcheese/cheese-camera.h
+++ b/libcheese/cheese-camera.h
@@ -70,6 +70,7 @@ void                     cheese_camera_setup (CheeseCamera *camera, char *udi, G
 void                     cheese_camera_play (CheeseCamera *camera);
 void                     cheese_camera_stop (CheeseCamera *camera);
 void                     cheese_camera_set_effect (CheeseCamera *camera, CheeseEffect *effect);
+void                     cheese_camera_connect_effect_texture (CheeseCamera *camera, CheeseEffect *effect, ClutterTexture *texture);
 void                     cheese_camera_start_video_recording (CheeseCamera *camera, char *filename);
 void                     cheese_camera_stop_video_recording (CheeseCamera *camera);
 gboolean                 cheese_camera_take_photo (CheeseCamera *camera, char *filename);
diff --git a/valasrc/cheese-window.vala b/valasrc/cheese-window.vala
index 8d63621..6582a23 100644
--- a/valasrc/cheese-window.vala
+++ b/valasrc/cheese-window.vala
@@ -469,11 +469,13 @@ public class Cheese.MainWindow : Gtk.Window
     viewport.show_all ();
 
     camera.setup (conf.gconf_prop_camera);
-    camera.play ();
 
 	effects_manager = new EffectsManager();
 	effects_manager.load_effects();
-	camera.set_effect(effects_manager.get_effect(conf.gconf_prop_selected_effects));
+	var effect = effects_manager.get_effect(conf.gconf_prop_selected_effects);
+	Clutter.Texture testy = (Clutter.Texture) clutter_builder.get_object("testy");
+	camera.connect_effect_texture (effect, testy);
+	camera.play();
 
     set_wide_mode (conf.gconf_prop_wide_mode, true);
     set_mode (MediaMode.PHOTO);
diff --git a/valasrc/vapi/cheese-common.vapi b/valasrc/vapi/cheese-common.vapi
index 37c0420..e81d603 100644
--- a/valasrc/vapi/cheese-common.vapi
+++ b/valasrc/vapi/cheese-common.vapi
@@ -31,6 +31,7 @@ namespace Cheese
     public void                        set_device_by_dev_file (string file);
     public void                        set_device_by_dev_udi (string udi);
     public void                        set_effect (Cheese.Effect effect);
+	public void                        connect_effect_texture (Cheese.Effect effect, Clutter.Texture texture);
     public void                        set_video_format (Cheese.VideoFormat format);
     public void                        setup (string udi) throws GLib.Error;
     public void                        start_video_recording (string filename);



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