Blob Blame History Raw
From 7f7e1b27e05ce3ba29e409fcf5cb58241ef99067 Mon Sep 17 00:00:00 2001
From: Hans de Goede <hdegoede@redhat.com>
Date: Tue, 11 Jun 2013 09:35:14 +0200
Subject: [PATCH 18/35] cheese-camera: Check for the current effect being the
 same as the one set

And if so, turn the cheese_camera_set_effect call into a nop.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 libcheese/cheese-camera.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/libcheese/cheese-camera.c b/libcheese/cheese-camera.c
index 7b7fac5..9cfaf7e 100644
--- a/libcheese/cheese-camera.c
+++ b/libcheese/cheese-camera.c
@@ -80,6 +80,7 @@ struct _CheeseCameraPrivate
   GstElement *video_balance;
   GstElement *camera_tee, *effects_tee;
   GstElement *main_valve, *effects_valve;
+  gchar *current_effect_desc;
 
   gboolean is_recording;
   gboolean pipeline_is_playing;
@@ -587,6 +588,7 @@ cheese_camera_create_video_filter_bin (CheeseCamera *camera, GError **error)
     cheese_camera_set_error_element_not_found (error, "identity");
     return FALSE;
   }
+  priv->current_effect_desc = g_strdup("identity");
   if ((priv->video_balance = gst_element_factory_make ("videobalance", "video_balance")) == NULL)
   {
     cheese_camera_set_error_element_not_found (error, "videobalance");
@@ -887,19 +889,36 @@ cheese_camera_element_from_effect (CheeseCamera *camera, CheeseEffect *effect)
 void
 cheese_camera_set_effect (CheeseCamera *camera, CheeseEffect *effect)
 {
+  CheeseCameraPrivate *priv;
   GstElement *effect_filter;
   gchar      *effect_desc;
 
   g_return_if_fail (CHEESE_IS_CAMERA (camera));
 
+  priv = camera->priv;
+
   g_object_get (G_OBJECT (effect), "pipeline-desc", &effect_desc, NULL);
 
+  if (strcmp(priv->current_effect_desc, effect_desc) == 0)
+  {
+    GST_INFO_OBJECT (camera, "Effect is: \"%s\", not updating", effect_desc);
+    g_free (effect_desc);
+    return;
+  }
+
+  GST_INFO_OBJECT (camera, "Changing effect to: \"%s\"", effect_desc);
+
   if (strcmp(effect_desc, "identity") == 0)
     effect_filter = gst_element_factory_make ("identity", "effect");
   else
     effect_filter = cheese_camera_element_from_effect (camera, effect);
   if (effect_filter != NULL)
+  {
     cheese_camera_change_effect_filter (camera, effect_filter);
+    g_free (priv->current_effect_desc);
+    priv->current_effect_desc = effect_desc;
+    return;
+  }
 
   g_free (effect_desc);
 }
@@ -1202,6 +1221,7 @@ cheese_camera_finalize (GObject *object)
 
   if (priv->photo_filename)
     g_free (priv->photo_filename);
+  g_free (priv->current_effect_desc);
   g_free (priv->device_node);
   g_boxed_free (CHEESE_TYPE_VIDEO_FORMAT, priv->current_format);
 
-- 
1.8.2.1