summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWim Taymans <wtaymans@redhat.com>2020-07-13 21:10:17 +0200
committerWim Taymans <wtaymans@redhat.com>2020-07-13 21:13:28 +0200
commit52c9e9997bba0259481b38bcd39ed1fb1e67182d (patch)
tree15fc91f1444a111420149f11fbe66c22f13748fb
parent0a31bae60daab9f7c78f0a95b263c2310934906a (diff)
downloadcheese-52c9e9997bba0259481b38bcd39ed1fb1e67182d.tar.gz
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.
-rw-r--r--libcheese/cheese-camera-device.c25
1 files 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));
}
}
}