mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-11 09:55:36 +00:00
smhsink: Check return values of functions working on memory
https://bugzilla.gnome.org/show_bug.cgi?id=768530
This commit is contained in:
parent
f4b9d8c299
commit
9a128603c9
1 changed files with 38 additions and 17 deletions
|
@ -698,13 +698,11 @@ gst_shm_sink_render (GstBaseSink * bsink, GstBuffer * buf)
|
|||
if (need_new_memory) {
|
||||
if (gst_buffer_get_size (buf) > sp_writer_get_max_buf_size (self->pipe)) {
|
||||
gsize area_size = sp_writer_get_max_buf_size (self->pipe);
|
||||
GST_OBJECT_UNLOCK (self);
|
||||
GST_ELEMENT_ERROR (self, RESOURCE, NO_SPACE_LEFT,
|
||||
("Shared memory area is too small"),
|
||||
GST_ELEMENT_ERROR (self, RESOURCE, NO_SPACE_LEFT, (NULL),
|
||||
("Shared memory area of size %" G_GSIZE_FORMAT " is smaller than"
|
||||
"buffer of size %" G_GSIZE_FORMAT, area_size,
|
||||
gst_buffer_get_size (buf)));
|
||||
return GST_FLOW_ERROR;
|
||||
goto error;
|
||||
}
|
||||
|
||||
while ((memory =
|
||||
|
@ -724,24 +722,48 @@ gst_shm_sink_render (GstBaseSink * bsink, GstBuffer * buf)
|
|||
}
|
||||
}
|
||||
|
||||
gst_memory_map (memory, &map, GST_MAP_WRITE);
|
||||
gst_buffer_extract (buf, 0, map.data, map.size);
|
||||
if (!gst_memory_map (memory, &map, GST_MAP_WRITE)) {
|
||||
GST_ELEMENT_ERROR (self, STREAM, FAILED,
|
||||
(NULL), ("Failed to map memory"));
|
||||
goto error;
|
||||
}
|
||||
|
||||
GST_DEBUG_OBJECT (self,
|
||||
"Copying %" G_GSIZE_FORMAT " bytes into map of size %" G_GSIZE_FORMAT
|
||||
" bytes.", gst_buffer_get_size (buf), map.size);
|
||||
gsize written_bytes = gst_buffer_extract (buf, 0, map.data, map.size);
|
||||
GST_DEBUG_OBJECT (self, "Copied %" G_GSIZE_FORMAT " bytes.", written_bytes);
|
||||
gst_memory_unmap (memory, &map);
|
||||
|
||||
sendbuf = gst_buffer_new ();
|
||||
gst_buffer_copy_into (sendbuf, buf, GST_BUFFER_COPY_METADATA, 0, -1);
|
||||
if (!gst_buffer_copy_into (sendbuf, buf, GST_BUFFER_COPY_METADATA, 0, -1)) {
|
||||
GST_ELEMENT_ERROR (self, STREAM, FAILED,
|
||||
(NULL), ("Failed to copy data into send buffer"));
|
||||
gst_buffer_unref (sendbuf);
|
||||
goto error;
|
||||
}
|
||||
gst_buffer_append_memory (sendbuf, memory);
|
||||
} else {
|
||||
sendbuf = gst_buffer_ref (buf);
|
||||
}
|
||||
|
||||
gst_buffer_map (sendbuf, &map, GST_MAP_READ);
|
||||
if (!gst_buffer_map (sendbuf, &map, GST_MAP_READ)) {
|
||||
GST_ELEMENT_ERROR (self, STREAM, FAILED,
|
||||
(NULL), ("Failed to map data into send buffer"));
|
||||
goto error;
|
||||
}
|
||||
|
||||
/* Make the memory readonly as of now as we've sent it to the other side
|
||||
* We know it's not mapped for writing anywhere as we just mapped it for
|
||||
* reading
|
||||
*/
|
||||
|
||||
rv = sp_writer_send_buf (self->pipe, (char *) map.data, map.size, sendbuf);
|
||||
if (rv == -1) {
|
||||
GST_ELEMENT_ERROR (self, STREAM, FAILED,
|
||||
(NULL), ("Failed to send data over SHM"));
|
||||
gst_buffer_unmap (sendbuf, &map);
|
||||
goto error;
|
||||
}
|
||||
|
||||
gst_buffer_unmap (sendbuf, &map);
|
||||
|
||||
|
@ -750,19 +772,17 @@ gst_shm_sink_render (GstBaseSink * bsink, GstBuffer * buf)
|
|||
if (rv == 0) {
|
||||
GST_DEBUG_OBJECT (self, "No clients connected, unreffing buffer");
|
||||
gst_buffer_unref (sendbuf);
|
||||
} else if (rv == -1) {
|
||||
GST_ELEMENT_ERROR (self, STREAM, FAILED, ("Invalid allocated buffer"),
|
||||
("The shmpipe library rejects our buffer, this is a bug"));
|
||||
ret = GST_FLOW_ERROR;
|
||||
}
|
||||
|
||||
/* If we allocated our own memory, then unmap it */
|
||||
|
||||
return ret;
|
||||
|
||||
flushing:
|
||||
GST_OBJECT_UNLOCK (self);
|
||||
return GST_FLOW_FLUSHING;
|
||||
|
||||
error:
|
||||
GST_OBJECT_UNLOCK (self);
|
||||
return GST_FLOW_ERROR;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -790,7 +810,8 @@ pollthread_func (gpointer data)
|
|||
} while (rv < 0 && errno == EINTR);
|
||||
|
||||
if (rv < 0) {
|
||||
GST_ELEMENT_ERROR (self, RESOURCE, READ, ("Failed waiting on fd activity"),
|
||||
GST_ELEMENT_ERROR (self, RESOURCE, READ,
|
||||
("Failed waiting on fd activity"),
|
||||
("gst_poll_wait returned %d, errno: %d", rv, errno));
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue