plugins: Check return values of gst_buffer_map()

They can fail for various reasons.

For non-fatal cases (such as the dump feature of identiy and fakesink),
we just silently skip it.

For other cases post an error message.

https://bugzilla.gnome.org/show_bug.cgi?id=728326
This commit is contained in:
Edward Hervey 2014-04-16 11:39:15 +02:00 committed by Edward Hervey
parent f7cba27157
commit 555df9d614
6 changed files with 64 additions and 14 deletions

View file

@ -479,9 +479,10 @@ gst_fake_sink_render (GstBaseSink * bsink, GstBuffer * buf)
if (sink->dump) {
GstMapInfo info;
gst_buffer_map (buf, &info, GST_MAP_READ);
gst_util_dump_mem (info.data, info.size);
gst_buffer_unmap (buf, &info);
if (gst_buffer_map (buf, &info, GST_MAP_READ)) {
gst_util_dump_mem (info.data, info.size);
gst_buffer_unmap (buf, &info);
}
}
if (sink->num_buffers_left == 0)
goto eos;

View file

@ -716,7 +716,10 @@ gst_fake_src_create_buffer (GstFakeSrc * src, gsize * bufsize)
/* try again (this will allocate a new parent) */
return gst_fake_src_create_buffer (src, bufsize);
}
gst_buffer_map (buf, &info, GST_MAP_WRITE);
if (buf == NULL)
goto buffer_create_fail;
if (!gst_buffer_map (buf, &info, GST_MAP_WRITE))
goto buffer_write_fail;
gst_fake_src_prepare_buffer (src, info.data, info.size);
gst_buffer_unmap (buf, &info);
break;
@ -726,12 +729,28 @@ gst_fake_src_create_buffer (GstFakeSrc * src, gsize * bufsize)
break;
}
if (dump) {
gst_buffer_map (buf, &info, GST_MAP_READ);
gst_util_dump_mem (info.data, info.size);
gst_buffer_unmap (buf, &info);
if (gst_buffer_map (buf, &info, GST_MAP_READ)) {
gst_util_dump_mem (info.data, info.size);
gst_buffer_unmap (buf, &info);
}
}
return buf;
buffer_create_fail:
{
GST_ELEMENT_ERROR (src, RESOURCE, BUSY, (NULL),
("Failed to create a buffer"));
return NULL;
}
buffer_write_fail:
{
GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL),
("Failed to write to buffer"));
gst_buffer_unref (buf);
return NULL;
}
}
static void

View file

@ -446,7 +446,8 @@ gst_fd_src_create (GstPushSrc * psrc, GstBuffer ** outbuf)
if (G_UNLIKELY (buf == NULL))
goto alloc_failed;
gst_buffer_map (buf, &info, GST_MAP_WRITE);
if (!gst_buffer_map (buf, &info, GST_MAP_WRITE))
goto buffer_read_error;
do {
readbytes = read (src->fd, info.data, blocksize);
@ -508,6 +509,12 @@ read_error:
gst_buffer_unref (buf);
return GST_FLOW_ERROR;
}
buffer_read_error:
{
GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL), ("Can't write to buffer"));
gst_buffer_unref (buf);
return GST_FLOW_ERROR;
}
}
static gboolean

View file

@ -350,7 +350,8 @@ gst_file_src_fill (GstBaseSrc * basesrc, guint64 offset, guint length,
src->read_position = offset;
}
gst_buffer_map (buf, &info, GST_MAP_WRITE);
if (!gst_buffer_map (buf, &info, GST_MAP_WRITE))
goto buffer_write_fail;
data = info.data;
bytes_read = 0;
@ -409,6 +410,11 @@ eos:
gst_buffer_resize (buf, 0, 0);
return GST_FLOW_EOS;
}
buffer_write_fail:
{
GST_ELEMENT_ERROR (src, RESOURCE, WRITE, (NULL), ("Can't write to buffer"));
return GST_FLOW_ERROR;
}
}
static gboolean

View file

@ -603,9 +603,10 @@ gst_identity_transform_ip (GstBaseTransform * trans, GstBuffer * buf)
if (identity->dump) {
GstMapInfo info;
gst_buffer_map (buf, &info, GST_MAP_READ);
gst_util_dump_mem (info.data, info.size);
gst_buffer_unmap (buf, &info);
if (gst_buffer_map (buf, &info, GST_MAP_READ)) {
gst_util_dump_mem (info.data, info.size);
gst_buffer_unmap (buf, &info);
}
}
if (!identity->silent) {

View file

@ -1382,7 +1382,8 @@ gst_queue2_create_read (GstQueue2 * queue, guint64 offset, guint length,
else
buf = *buffer;
gst_buffer_map (buf, &info, GST_MAP_WRITE);
if (!gst_buffer_map (buf, &info, GST_MAP_WRITE))
goto buffer_write_fail;
data = info.data;
GST_DEBUG_OBJECT (queue, "Reading %u bytes from %" G_GUINT64_FORMAT, length,
@ -1533,6 +1534,14 @@ read_error:
gst_buffer_unref (buf);
return ret;
}
buffer_write_fail:
{
GST_ELEMENT_ERROR (queue, RESOURCE, WRITE, (NULL),
("Can't write to buffer"));
if (*buffer == NULL)
gst_buffer_unref (buf);
return GST_FLOW_ERROR;
}
}
/* should be called with QUEUE_LOCK */
@ -1784,7 +1793,8 @@ gst_queue2_create_write (GstQueue2 * queue, GstBuffer * buffer)
ring_buffer = queue->ring_buffer;
rb_size = queue->ring_buffer_max_size;
gst_buffer_map (buffer, &info, GST_MAP_READ);
if (!gst_buffer_map (buffer, &info, GST_MAP_READ))
goto buffer_read_error;
size = info.size;
data = info.data;
@ -2060,6 +2070,12 @@ handle_error:
gst_buffer_unmap (buffer, &info);
return FALSE;
}
buffer_read_error:
{
GST_ELEMENT_ERROR (queue, RESOURCE, READ, (NULL),
("Can't read from buffer"));
return FALSE;
}
}
static gboolean