mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-07 07:58:51 +00:00
manual: Fix examples to check for gst_buffer_map return values
Otherwise people reading the manual will expect it to always succeed :) https://bugzilla.gnome.org/show_bug.cgi?id=728326
This commit is contained in:
parent
1f7fba19f7
commit
01ad1fb343
1 changed files with 27 additions and 18 deletions
|
@ -164,20 +164,27 @@ cb_have_data (GstPad *pad,
|
||||||
buffer = GST_PAD_PROBE_INFO_BUFFER (info);
|
buffer = GST_PAD_PROBE_INFO_BUFFER (info);
|
||||||
|
|
||||||
buffer = gst_buffer_make_writable (buffer);
|
buffer = gst_buffer_make_writable (buffer);
|
||||||
|
|
||||||
gst_buffer_map (buffer, &map, GST_MAP_WRITE);
|
|
||||||
|
|
||||||
ptr = (guint16 *) map.data;
|
/* Making a buffer writable can fail (for example if it
|
||||||
/* invert data */
|
* cannot be copied and is used more than once)
|
||||||
for (y = 0; y < 288; y++) {
|
*/
|
||||||
for (x = 0; x < 384 / 2; x++) {
|
if (buffer == NULL)
|
||||||
t = ptr[384 - 1 - x];
|
return GST_PAD_PROBE_OK;
|
||||||
ptr[384 - 1 - x] = ptr[x];
|
|
||||||
ptr[x] = t;
|
/* 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;
|
GST_PAD_PROBE_INFO_DATA (info) = buffer;
|
||||||
|
|
||||||
|
@ -995,16 +1002,18 @@ main (int argc, char *argv[])
|
||||||
/* create pixmap from buffer and save, gstreamer video buffers have a stride
|
/* create pixmap from buffer and save, gstreamer video buffers have a stride
|
||||||
* that is rounded up to the nearest multiple of 4 */
|
* that is rounded up to the nearest multiple of 4 */
|
||||||
buffer = gst_sample_get_buffer (sample);
|
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
|
#ifdef HAVE_GTK
|
||||||
pixbuf = gdk_pixbuf_new_from_data (map.data,
|
pixbuf = gdk_pixbuf_new_from_data (map.data,
|
||||||
GDK_COLORSPACE_RGB, FALSE, 8, width, height,
|
GDK_COLORSPACE_RGB, FALSE, 8, width, height,
|
||||||
GST_ROUND_UP_4 (width * 3), NULL, NULL);
|
GST_ROUND_UP_4 (width * 3), NULL, NULL);
|
||||||
|
|
||||||
/* save the pixbuf */
|
/* save the pixbuf */
|
||||||
gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL);
|
gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL);
|
||||||
#endif
|
#endif
|
||||||
gst_buffer_unmap (buffer, &map);
|
gst_buffer_unmap (buffer, &map);
|
||||||
|
}
|
||||||
gst_sample_unref (sample);
|
gst_sample_unref (sample);
|
||||||
} else {
|
} else {
|
||||||
g_print ("could not make snapshot\n");
|
g_print ("could not make snapshot\n");
|
||||||
|
|
Loading…
Reference in a new issue