[cheese] Improve cheese_camera_device_get_best_format()



commit 228eea8a6bbaac21f04579b93510356c85782e49
Author: Hans de Goede <hdegoede redhat com>
Date:   Thu Jun 13 11:07:37 2013 +0200

    Improve cheese_camera_device_get_best_format()
    
    If a camera device which can do 1600x900 at 10 FPS and 1280x800 @ 25
    FPS, then 1600x900 is not really the best format, as 10 FPS leads to a
    bad user experience.
    
    Improve the situation by constraining
    cheese_camera_device_get_best_format() to return the format with the
    highest resolution with a width greater than 640 pixels and a framerate
    of greater the 15 FPS.
    
    If no mode matching the widh >= 640 && frame_rate >= 15 criteria is found,
    get_best_format will behave as before as simply return the highest resolution
    mode.
    
    Signed-off-by: Hans de Goede <hdegoede redhat com>

 libcheese/cheese-camera-device.c |   34 +++++++++++++++++++++++++++-------
 1 files changed, 27 insertions(+), 7 deletions(-)
---
diff --git a/libcheese/cheese-camera-device.c b/libcheese/cheese-camera-device.c
index c6faebd..0ac5b59 100644
--- a/libcheese/cheese-camera-device.c
+++ b/libcheese/cheese-camera-device.c
@@ -935,24 +935,44 @@ cheese_camera_device_get_device_node (CheeseCameraDevice *device)
  * cheese_camera_device_get_best_format:
  * @device: a #CheeseCameraDevice
  *
- * Get the #CheeseVideoFormat with the highest rsolution for this @device.
+ * Get the #CheeseVideoFormat with the highest resolution with a width greater
+ * than 640 pixels and a framerate of greater than 15 FPS for this @device. If
+ * no such format is found, get the highest available resolution instead.
  *
  * Returns: (transfer full): the highest-resolution supported
  * #CheeseVideoFormat
  */
-
 CheeseVideoFormat *
 cheese_camera_device_get_best_format (CheeseCameraDevice *device)
 {
-  CheeseVideoFormat *format;
+  CheeseVideoFormatFull *format = NULL;
+  GList *l;
 
   g_return_val_if_fail (CHEESE_IS_CAMERA_DEVICE (device), NULL);
 
-  format = g_boxed_copy (CHEESE_TYPE_VIDEO_FORMAT,
-                         device->priv->formats->data);
+  /* Check for the highest resolution with width >= 640 and FPS >= 15. */
+  for (l = device->priv->formats; l != NULL; l = g_list_next (l))
+  {
+    CheeseVideoFormatFull *item = l->data;
+    float frame_rate = (float)item->fr_numerator / (float)item->fr_denominator;
+
+    if (item->width >= 640 && frame_rate >= 15)
+    {
+      format = item;
+      break;
+    }
+  }
+
+  /* Else simply return the highest resolution. */
+  if (!format)
+  {
+    format = device->priv->formats->data;
+  }
+
+  GST_INFO ("%dx%d %d/%d", format->width, format->height,
+            format->fr_numerator, format->fr_denominator);
 
-  GST_INFO ("%dx%d", format->width, format->height);
-  return format;
+  return g_boxed_copy (CHEESE_TYPE_VIDEO_FORMAT, format);
 }
 
 static GstCaps *


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