buffer = GST_PAD_PROBE_INFO_BUFFER (info);
buffer = gst_buffer_make_writable (buffer);
-
- gst_buffer_map (buffer, &map, GST_MAP_WRITE);
-
- ptr = (guint16 *) map.data;
- /* invert data */
- for (y = 0; y < 288; y++) {
- for (x = 0; x < 384 / 2; x++) {
- t = ptr[384 - 1 - x];
- ptr[384 - 1 - x] = ptr[x];
- ptr[x] = t;
+
+ /* Making a buffer writable can fail (for example if it
+ * cannot be copied and is used more than once)
+ */
+ if (buffer == NULL)
+ return GST_PAD_PROBE_OK;
+
+ /* Mapping a buffer can fail (non-writable) */
+ if (gst_buffer_map (buffer, &map, GST_MAP_WRITE)) {
+ ptr = (guint16 *) map.data;
+ /* invert data */
+ for (y = 0; y < 288; y++) {
+ for (x = 0; x < 384 / 2; x++) {
+ t = ptr[384 - 1 - x];
+ ptr[384 - 1 - x] = ptr[x];
+ ptr[x] = t;
+ }
+ ptr += 384;
}
- ptr += 384;
+ gst_buffer_unmap (buffer, &map);
}
- gst_buffer_unmap (buffer, &map);
GST_PAD_PROBE_INFO_DATA (info) = buffer;
/* create pixmap from buffer and save, gstreamer video buffers have a stride
* that is rounded up to the nearest multiple of 4 */
buffer = gst_sample_get_buffer (sample);
- gst_buffer_map (buffer, &map, GST_MAP_READ);
+ /* Mapping a buffer can fail (non-readable) */
+ if (gst_buffer_map (buffer, &map, GST_MAP_READ)) {
#ifdef HAVE_GTK
- pixbuf = gdk_pixbuf_new_from_data (map.data,
- GDK_COLORSPACE_RGB, FALSE, 8, width, height,
- GST_ROUND_UP_4 (width * 3), NULL, NULL);
+ pixbuf = gdk_pixbuf_new_from_data (map.data,
+ GDK_COLORSPACE_RGB, FALSE, 8, width, height,
+ GST_ROUND_UP_4 (width * 3), NULL, NULL);
- /* save the pixbuf */
- gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL);
+ /* save the pixbuf */
+ gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL);
#endif
- gst_buffer_unmap (buffer, &map);
+ gst_buffer_unmap (buffer, &map);
+ }
gst_sample_unref (sample);
} else {
g_print ("could not make snapshot\n");