Blame SOURCES/0020-cheese-camera-Downscale-image-for-effects-preview-pi.patch

ecdf9b
From 5cb470a89ed733ef7b0db3c534d1ce6e76648fae Mon Sep 17 00:00:00 2001
ecdf9b
From: Hans de Goede <hdegoede@redhat.com>
ecdf9b
Date: Tue, 11 Jun 2013 16:16:23 +0200
ecdf9b
Subject: [PATCH 20/35] cheese-camera: Downscale image for effects-preview
ecdf9b
 pipeline
ecdf9b
ecdf9b
Having the whole effects-preview bin deal with ie 1280x800 images is not very
ecdf9b
useful, esp since even when fullscreen on a full-hd monitor, the preview images
ecdf9b
are smaller then 640xXXX. This useless high-res processing for 9 preview images
ecdf9b
in paralellel brings my 2nd gen core i5 @ 3.1 GHz to its knees, resulting in a
ecdf9b
non fluid preview panel.
ecdf9b
ecdf9b
Also after clicking through all effect preview pages, so that all effect
ecdf9b
preview textures are connected, cheese will use 1GB of *resident* ram with
ecdf9b
the example 1280x800 capture resolution.
ecdf9b
ecdf9b
This patch fixes this by downscaling the images from the video-source to
ecdf9b
640xXXX where XXX is determined by the original resolution aspect-ratio.
ecdf9b
ecdf9b
After this patch the effects preview framerate is much smoother, and the
ecdf9b
latency is noticably less. And as a bonus the maximal resident size of cheese
ecdf9b
in this example is reduced to 350 MB.
ecdf9b
ecdf9b
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
ecdf9b
---
ecdf9b
 libcheese/cheese-camera.c | 42 ++++++++++++++++++++++++++++++++++--------
ecdf9b
 1 file changed, 34 insertions(+), 8 deletions(-)
ecdf9b
ecdf9b
diff --git a/libcheese/cheese-camera.c b/libcheese/cheese-camera.c
ecdf9b
index 2dc5655..31348d2 100644
ecdf9b
--- a/libcheese/cheese-camera.c
ecdf9b
+++ b/libcheese/cheese-camera.c
ecdf9b
@@ -76,7 +76,7 @@ struct _CheeseCameraPrivate
ecdf9b
 
ecdf9b
   ClutterTexture *video_texture;
ecdf9b
 
ecdf9b
-  GstElement *effect_filter;
ecdf9b
+  GstElement *effect_filter, *effects_capsfilter;
ecdf9b
   GstElement *video_balance;
ecdf9b
   GstElement *camera_tee, *effects_tee;
ecdf9b
   GstElement *main_valve, *effects_valve;
ecdf9b
@@ -517,27 +517,39 @@ cheese_camera_create_effects_preview_bin (CheeseCamera *camera, GError **error)
ecdf9b
   CheeseCameraPrivate *priv = camera->priv;
ecdf9b
 
ecdf9b
   gboolean ok = TRUE;
ecdf9b
+  GstElement *scale;
ecdf9b
   GstPad  *pad;
ecdf9b
 
ecdf9b
   g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
ecdf9b
 
ecdf9b
   priv->effects_preview_bin = gst_bin_new ("effects_preview_bin");
ecdf9b
 
ecdf9b
-  if ((priv->effects_tee = gst_element_factory_make ("tee", "effects_tee")) == NULL)
ecdf9b
+  if ((priv->effects_valve = gst_element_factory_make ("valve", "effects_valve")) == NULL)
ecdf9b
   {
ecdf9b
-    cheese_camera_set_error_element_not_found (error, "tee");
ecdf9b
+    cheese_camera_set_error_element_not_found (error, "effects_valve");
ecdf9b
     return FALSE;
ecdf9b
   }
ecdf9b
-  if ((priv->effects_valve = gst_element_factory_make ("valve", "effects_valve")) == NULL)
ecdf9b
+  if ((scale = gst_element_factory_make ("videoscale", "effects_scale")) == NULL)
ecdf9b
   {
ecdf9b
-    cheese_camera_set_error_element_not_found (error, "effects_valve");
ecdf9b
+    cheese_camera_set_error_element_not_found (error, "videoscale");
ecdf9b
+    return FALSE;
ecdf9b
+  }
ecdf9b
+  if ((priv->effects_capsfilter = gst_element_factory_make ("capsfilter", "effects_capsfilter")) == NULL)
ecdf9b
+  {
ecdf9b
+    cheese_camera_set_error_element_not_found (error, "capsfilter");
ecdf9b
+    return FALSE;
ecdf9b
+  }
ecdf9b
+  if ((priv->effects_tee = gst_element_factory_make ("tee", "effects_tee")) == NULL)
ecdf9b
+  {
ecdf9b
+    cheese_camera_set_error_element_not_found (error, "tee");
ecdf9b
     return FALSE;
ecdf9b
   }
ecdf9b
 
ecdf9b
-  gst_bin_add_many (GST_BIN (priv->effects_preview_bin),
ecdf9b
-		    priv->effects_valve, priv->effects_tee, NULL);
ecdf9b
+  gst_bin_add_many (GST_BIN (priv->effects_preview_bin), priv->effects_valve,
ecdf9b
+                    scale, priv->effects_capsfilter, priv->effects_tee, NULL);
ecdf9b
 
ecdf9b
-  ok &= gst_element_link_many (priv->effects_valve, priv->effects_tee, NULL);
ecdf9b
+  ok &= gst_element_link_many (priv->effects_valve, scale,
ecdf9b
+                           priv->effects_capsfilter, priv->effects_tee, NULL);
ecdf9b
 
ecdf9b
   /* add ghostpads */
ecdf9b
 
ecdf9b
@@ -723,6 +735,8 @@ cheese_camera_set_new_caps (CheeseCamera *camera)
ecdf9b
   CheeseCameraPrivate *priv;
ecdf9b
   CheeseCameraDevice *device;
ecdf9b
   GstCaps *caps;
ecdf9b
+  gchar *caps_desc;
ecdf9b
+  int width, height;
ecdf9b
 
ecdf9b
   g_return_if_fail (CHEESE_IS_CAMERA (camera));
ecdf9b
 
ecdf9b
@@ -746,6 +760,18 @@ cheese_camera_set_new_caps (CheeseCamera *camera)
ecdf9b
     g_object_set (priv->camerabin, "viewfinder-caps", caps, NULL);
ecdf9b
     g_object_set (priv->camerabin, "image-capture-caps", caps, NULL);
ecdf9b
     g_object_set (priv->camerabin, "video-capture-caps", caps, NULL);
ecdf9b
+    gst_caps_unref (caps);
ecdf9b
+
ecdf9b
+    width = priv->current_format->width;
ecdf9b
+    width = width > 640 ? 640 : width;
ecdf9b
+    height = width * priv->current_format->height / priv->current_format->width;
ecdf9b
+    /* !! Gstreamer will crash if this is not a multiple of 2 !! */
ecdf9b
+    height = (height + 1) & ~1;
ecdf9b
+    caps_desc = g_strdup_printf ("video/x-raw, width=%d, height=%d",
ecdf9b
+                                 width, height);
ecdf9b
+    caps = gst_caps_from_string (caps_desc);
ecdf9b
+    g_free (caps_desc);
ecdf9b
+    g_object_set (priv->effects_capsfilter, "caps", caps, NULL);
ecdf9b
   }
ecdf9b
   gst_caps_unref (caps);
ecdf9b
 }
ecdf9b
-- 
ecdf9b
1.8.2.1
ecdf9b