[cheese/wip/hans-fixes: 11/35] cheese-camera-device: Add cheese_camera_device_find_full_format() helper



commit d7afd9785633dd6e4f03417385a49989b34d72d1
Author: Hans de Goede <hdegoede redhat com>
Date:   Mon Jun 10 14:27:04 2013 +0200

    cheese-camera-device: Add cheese_camera_device_find_full_format() helper
    
    Signed-off-by: Hans de Goede <hdegoede redhat com>

 libcheese/cheese-camera-device.c |   40 ++++++++++++++++++++++++++++---------
 1 files changed, 30 insertions(+), 10 deletions(-)
---
diff --git a/libcheese/cheese-camera-device.c b/libcheese/cheese-camera-device.c
index c684367..25d4a51 100644
--- a/libcheese/cheese-camera-device.c
+++ b/libcheese/cheese-camera-device.c
@@ -319,6 +319,30 @@ cheese_camera_device_format_update_framerate(CheeseVideoFormatFull *format,
 }
 
 /*
+ * cheese_camera_device_find_full_format
+ * @device: a #CheeseCameraDevice
+ * @format: #CheeseVideoFormat to find the matching #CheeseVideoFormatFull for
+ *
+ * Find a #CheeseVideoFormatFull matching the passed in #CheeseVideoFormat
+ */
+static CheeseVideoFormatFull *
+cheese_camera_device_find_full_format(CheeseCameraDevice *device,
+  CheeseVideoFormat* format)
+{
+  GList *l;
+
+  for (l = device->priv->formats; l != NULL; l = l->next)
+  {
+    CheeseVideoFormatFull *item = l->data;
+    if ((item != NULL) &&
+        (item->width == format->width) &&
+        (item->height == format->height))
+      return item;
+  }
+  return NULL;
+}
+
+/*
  * cheese_camera_device_add_format:
  * @device: a #CheeseCameraDevice
  * @format: the #CheeseVideoFormatFull to add
@@ -330,18 +354,14 @@ cheese_camera_device_add_format (CheeseCameraDevice *device,
   CheeseVideoFormatFull *format, const GValue *framerate)
 {
   CheeseCameraDevicePrivate *priv =  device->priv;
-  GList *l;
+  CheeseVideoFormatFull *existing;
 
-  for (l = priv->formats; l != NULL; l = l->next)
+  existing = cheese_camera_device_find_full_format(device,
+                                                 (CheeseVideoFormat *)format);
+  if (existing)
   {
-    CheeseVideoFormatFull *item = l->data;
-    if ((item != NULL) &&
-        (item->width == format->width) &&
-        (item->height == format->height))
-    {
-      cheese_camera_device_format_update_framerate (item, framerate);
-      return;
-    }
+    cheese_camera_device_format_update_framerate (existing, framerate);
+    return;
   }
 
   cheese_camera_device_get_highest_framerate (framerate,


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