[0.11] gstreamer: memory: take offset into account

Wim Taymans wtay at kemper.freedesktop.org
Thu Jan 5 08:29:00 PST 2012


Module: gstreamer
Branch: 0.11
Commit: 6e0024e76ea88c1220eb69da8baabb7f3ca35193
URL:    http://cgit.freedesktop.org/gstreamer/gstreamer/commit/?id=6e0024e76ea88c1220eb69da8baabb7f3ca35193

Author: Wim Taymans <wim.taymans at collabora.co.uk>
Date:   Thu Jan  5 17:28:28 2012 +0100

memory: take offset into account

Take the offset into account whem mapping and unmapping the buffer.

---

 docs/design/part-memory.txt |    2 +-
 gst/gstmemory.c             |    4 ++--
 tests/check/gst/gstmemory.c |   10 ++++++++++
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/docs/design/part-memory.txt b/docs/design/part-memory.txt
index c8b69eb..af12090 100644
--- a/docs/design/part-memory.txt
+++ b/docs/design/part-memory.txt
@@ -127,7 +127,7 @@ Data Access
  When the final reference on a memory object is dropped, all outstanding
  mappings are automatically unmapped.
 
- Resizing a GstMemory does not influence any current mappings.
+ Resizing a GstMemory does not influence any current mappings an any way.
 
 
 Copy
diff --git a/gst/gstmemory.c b/gst/gstmemory.c
index e2f5e48..0791fb8 100644
--- a/gst/gstmemory.c
+++ b/gst/gstmemory.c
@@ -206,7 +206,7 @@ _default_mem_map (GstMemoryDefault * mem, gsize * size, gsize * maxsize,
   if (size)
     *size = mem->size;
   if (maxsize)
-    *maxsize = mem->maxsize;
+    *maxsize = mem->maxsize - mem->offset;
 
   return mem->data + mem->offset;
 }
@@ -215,7 +215,7 @@ static gboolean
 _default_mem_unmap (GstMemoryDefault * mem, gpointer data, gsize size)
 {
   if (size != -1) {
-    g_return_val_if_fail (size <= mem->maxsize, FALSE);
+    g_return_val_if_fail (mem->offset + size <= mem->maxsize, FALSE);
     mem->size = size;
   }
   return TRUE;
diff --git a/tests/check/gst/gstmemory.c b/tests/check/gst/gstmemory.c
index 0191006..b903a51 100644
--- a/tests/check/gst/gstmemory.c
+++ b/tests/check/gst/gstmemory.c
@@ -421,6 +421,16 @@ GST_START_TEST (test_map)
   ASSERT_CRITICAL (gst_memory_unmap (mem, data, maxsize + 1));
   gst_memory_unmap (mem, data, maxsize);
 
+  /* add offset, maxsize should be smaller now */
+  gst_memory_resize (mem, 1, 99);
+
+  data = gst_memory_map (mem, &size, &maxsize, GST_MAP_READ);
+  fail_unless (data != NULL);
+  fail_unless (size == 99);
+  fail_unless (maxsize == maxalloc - 1);
+  ASSERT_CRITICAL (gst_memory_unmap (mem, data, maxsize + 1));
+  gst_memory_unmap (mem, data, maxsize);
+
   gst_memory_unref (mem);
 }
 



More information about the gstreamer-commits mailing list