[cheese] cheese: improve format parsing



commit 52c9e9997bba0259481b38bcd39ed1fb1e67182d
Author: Wim Taymans <wtaymans redhat com>
Date:   Mon Jul 13 21:10:17 2020 +0200

    cheese: improve format parsing
    
    Check if both width and height are of the expected value type.
    
    Check if width and height are > 0 before adding the format as a
    valid format. Adding 0x0 resolutions causes a divide by 0 later
    when we calculate aspect ratios.

 libcheese/cheese-camera-device.c | 25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)
---
diff --git a/libcheese/cheese-camera-device.c b/libcheese/cheese-camera-device.c
index be85b2c5..08a0a26a 100644
--- a/libcheese/cheese-camera-device.c
+++ b/libcheese/cheese-camera-device.c
@@ -446,15 +446,25 @@ cheese_camera_device_update_format_table (CheeseCameraDevice *device)
     height = gst_structure_get_value (structure, "height");
     framerate = gst_structure_get_value (structure, "framerate");
 
-    if (G_VALUE_HOLDS_INT (width))
+    if (G_VALUE_HOLDS_INT (width) && G_VALUE_HOLDS_INT (height))
     {
-      CheeseVideoFormatFull *format = g_slice_new0 (CheeseVideoFormatFull);
+      CheeseVideoFormatFull *format;
+      gint width = 0, height = 0;
 
-      gst_structure_get_int (structure, "width", &(format->width));
-      gst_structure_get_int (structure, "height", &(format->height));
-      cheese_camera_device_add_format (device, format, framerate);
+      gst_structure_get_int (structure, "width", &width);
+      gst_structure_get_int (structure, "height", &height);
+
+      if (width > 0 && height > 0) {
+        format = g_slice_new0 (CheeseVideoFormatFull);
+
+       format->width = width;
+       format->height = height;
+
+        cheese_camera_device_add_format (device, format, framerate);
+      }
     }
-    else if (GST_VALUE_HOLDS_INT_RANGE (width))
+    else if (GST_VALUE_HOLDS_INT_RANGE (width) &&
+             GST_VALUE_HOLDS_INT_RANGE (height))
     {
       gint min_width, max_width, min_height, max_height;
       gint cur_width, cur_height;
@@ -516,7 +526,8 @@ cheese_camera_device_update_format_table (CheeseCameraDevice *device)
     }
     else
     {
-      g_critical ("GValue type %s, cannot be handled for resolution width", G_VALUE_TYPE_NAME (width));
+      g_critical ("GValue type %s x %s, cannot be handled for resolution",
+                     G_VALUE_TYPE_NAME (width), G_VALUE_TYPE_NAME (height));
     }
   }
 }


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