From 684811cddf60f43df14b2fd7a64207f5566b9a32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= Date: Wed, 27 Feb 2013 21:05:38 -0500 Subject: [PATCH] shmsink: Error out if memory area is smaller than buffer --- sys/shm/gstshmsink.c | 13 +++++++++++++ sys/shm/shmpipe.c | 9 +++++++++ sys/shm/shmpipe.h | 1 + 3 files changed, 23 insertions(+) diff --git a/sys/shm/gstshmsink.c b/sys/shm/gstshmsink.c index 6228a55acd..e48785d817 100644 --- a/sys/shm/gstshmsink.c +++ b/sys/shm/gstshmsink.c @@ -424,6 +424,19 @@ gst_shm_sink_render (GstBaseSink * bsink, GstBuffer * buf) if (rv == -1) { ShmBlock *block = NULL; gchar *shmbuf = NULL; + + 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"), + ("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; + } + while ((block = sp_writer_alloc_block (self->pipe, gst_buffer_get_size (buf))) == NULL) { g_cond_wait (&self->cond, GST_OBJECT_GET_LOCK (self)); diff --git a/sys/shm/shmpipe.c b/sys/shm/shmpipe.c index 348dc4012d..676453b372 100644 --- a/sys/shm/shmpipe.c +++ b/sys/shm/shmpipe.c @@ -946,3 +946,12 @@ sp_writer_buf_get_tag (ShmBuffer * buffer) { return buffer->tag; } + +size_t +sp_writer_get_max_buf_size (ShmPipe * self) +{ + if (self->shm_area == NULL) + return 0; + + return self->shm_area->shm_area_len; +} diff --git a/sys/shm/shmpipe.h b/sys/shm/shmpipe.h index eef8877d14..ecac432a65 100644 --- a/sys/shm/shmpipe.h +++ b/sys/shm/shmpipe.h @@ -95,6 +95,7 @@ void sp_writer_free_block (ShmBlock *block); int sp_writer_send_buf (ShmPipe * self, char *buf, size_t size, uint64_t tag); char *sp_writer_block_get_buf (ShmBlock *block); ShmPipe *sp_writer_block_get_pipe (ShmBlock *block); +size_t sp_writer_get_max_buf_size (ShmPipe * self); ShmClient * sp_writer_accept_client (ShmPipe * self); void sp_writer_close_client (ShmPipe *self, ShmClient * client);