[cheese] Fix possible crasher in CheeseCamera when capturing pixbufs
- From: Bastien Nocera <hadess src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [cheese] Fix possible crasher in CheeseCamera when capturing pixbufs
- Date: Thu, 14 Jan 2010 17:05:13 +0000 (UTC)
commit 735ac61f8a67f92479cf49f8b5286353ee62f602
Author: Bastien Nocera <hadess hadess net>
Date: Thu Jan 14 16:48:20 2010 +0000
Fix possible crasher in CheeseCamera when capturing pixbufs
Craziness. We were creating a pixbuf from a GstBuffer, but the
data in the GstBuffer is from GStreamer, and might change at the
end of the function.
We need to duplicate the buffer if we want the pixbuf to stay
static, otherwise funny effects like a cropped copy of the
pixbuf reflecting the live video.
libcheese/cheese-camera.c | 13 +++++++++++--
1 files changed, 11 insertions(+), 2 deletions(-)
---
diff --git a/libcheese/cheese-camera.c b/libcheese/cheese-camera.c
index d6d7794..63e4139 100644
--- a/libcheese/cheese-camera.c
+++ b/libcheese/cheese-camera.c
@@ -223,6 +223,7 @@ cheese_camera_photo_data_cb (GstElement *element, GstBuffer *buffer,
int width, height, stride;
GdkPixbuf *pixbuf;
const int bits_per_pixel = 8;
+ guchar *data;
caps = gst_buffer_get_caps (buffer);
structure = gst_caps_get_structure (caps, 0);
@@ -230,9 +231,17 @@ cheese_camera_photo_data_cb (GstElement *element, GstBuffer *buffer,
gst_structure_get_int (structure, "height", &height);
stride = buffer->size / height;
- pixbuf = gdk_pixbuf_new_from_data (GST_BUFFER_DATA (buffer), GDK_COLORSPACE_RGB,
+
+ /* Only copy the data if we're giving away a pixbuf,
+ * not if we're throwing everything away straight away */
+ if (priv->photo_filename != NULL)
+ data = NULL;
+ else
+ data = g_memdup (GST_BUFFER_DATA (buffer), buffer->size);
+ pixbuf = gdk_pixbuf_new_from_data (data ? data : GST_BUFFER_DATA (buffer),
+ GDK_COLORSPACE_RGB,
FALSE, bits_per_pixel, width, height, stride,
- NULL, NULL);
+ data ? (GdkPixbufDestroyNotify) g_free : NULL, NULL);
g_signal_handler_disconnect (G_OBJECT (priv->photo_sink),
priv->photo_handler_signal_id);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]