meta: add LOCKED flag
authorWim Taymans <wim.taymans@collabora.co.uk>
Tue, 17 Apr 2012 13:37:27 +0000 (15:37 +0200)
committerWim Taymans <wim.taymans@collabora.co.uk>
Tue, 17 Apr 2012 13:55:10 +0000 (15:55 +0200)
Add a new LOCKED flag to the metadata. Refuse removing LOCKED metadata from
a buffer.
Mark the metadata from the bufferpool LOCKED.
Add unit test for LOCKED flag

gst/gstbuffer.c
gst/gstbufferpool.c
gst/gstbufferpool.h
gst/gstmeta.h
tests/check/gst/gstmeta.c

index 019810f..b9783c5 100644 (file)
@@ -1625,6 +1625,8 @@ gst_buffer_remove_meta (GstBuffer * buffer, GstMeta * meta)
   g_return_val_if_fail (buffer != NULL, FALSE);
   g_return_val_if_fail (meta != NULL, FALSE);
   g_return_val_if_fail (gst_buffer_is_writable (buffer), FALSE);
+  g_return_val_if_fail (!GST_META_FLAG_IS_SET (meta, GST_META_FLAG_LOCKED),
+      FALSE);
 
   /* find the metadata and delete */
   prev = GST_BUFFER_META (buffer);
@@ -1724,6 +1726,7 @@ gst_buffer_foreach_meta (GstBuffer * buffer, GstBufferForeachMetaFunc func,
           g_type_name (info->type));
 
       g_return_if_fail (gst_buffer_is_writable (buffer));
+      g_return_if_fail (!GST_META_FLAG_IS_SET (m, GST_META_FLAG_LOCKED));
 
       /* remove from list */
       if (GST_BUFFER_META (buffer) == walk)
index 7020345..f32aa89 100644 (file)
@@ -243,6 +243,7 @@ mark_meta_pooled (GstBuffer * buffer, GstMeta ** meta, gpointer user_data)
   GST_DEBUG_OBJECT (pool, "marking meta %p as POOLED in buffer %p", *meta,
       buffer);
   GST_META_FLAG_SET (*meta, GST_META_FLAG_POOLED);
+  GST_META_FLAG_SET (*meta, GST_META_FLAG_LOCKED);
 
   return TRUE;
 }
@@ -988,8 +989,10 @@ dec_outstanding (GstBufferPool * pool)
 static gboolean
 remove_meta_unpooled (GstBuffer * buffer, GstMeta ** meta, gpointer user_data)
 {
-  if (!GST_META_FLAG_IS_SET (*meta, GST_META_FLAG_POOLED))
+  if (!GST_META_FLAG_IS_SET (*meta, GST_META_FLAG_POOLED)) {
+    GST_META_FLAG_UNSET (*meta, GST_META_FLAG_LOCKED);
     *meta = NULL;
+  }
   return TRUE;
 }
 
index aad3b22..c798223 100644 (file)
@@ -129,11 +129,12 @@ struct _GstBufferPool {
  * @alloc_buffer: allocate a buffer. the default implementation allocates
  *        buffers from the configured memory allocator and with the configured
  *        parameters. All metadata that is present on the allocated buffer will
- *        be marked as #GST_META_FLAG_POOLED and will not be removed from the
- *        buffer in @reset_buffer.
+ *        be marked as #GST_META_FLAG_POOLED and #GST_META_FLAG_LOCKED and will
+ *        not be removed from the buffer in @reset_buffer.
  * @reset_buffer: reset the buffer to its state when it was freshly allocated.
  *        The default implementation will clear the flags, timestamps and
- *        will remove the metadata without the #GST_META_FLAG_POOLED flag.
+ *        will remove the metadata without the #GST_META_FLAG_POOLED flag (even
+ *        the metadata with #GST_META_FLAG_LOCKED).
  * @release_buffer: release a buffer back in the pool. The default
  *        implementation will put the buffer back in the queue and notify any
  *        blocking acquire_buffer calls.
index bd7b2e2..e6d4f00 100644 (file)
@@ -34,8 +34,8 @@ typedef struct _GstMetaInfo GstMetaInfo;
  * GstMetaFlags:
  * @GST_META_FLAG_NONE: no flags
  * @GST_META_FLAG_READONLY: metadata should not be modified
- * @GST_META_FLAG_POOLED: metadata is managed by a bufferpool and should not
- *    be removed
+ * @GST_META_FLAG_POOLED: metadata is managed by a bufferpool
+ * @GST_META_FLAG_LOCKED: metadata should not be removed
  * @GST_META_FLAG_LAST: additional flags can be added starting from this flag.
  *
  * Extra metadata flags.
@@ -44,6 +44,7 @@ typedef enum {
   GST_META_FLAG_NONE        = 0,
   GST_META_FLAG_READONLY    = (1 << 0),
   GST_META_FLAG_POOLED      = (1 << 1),
+  GST_META_FLAG_LOCKED      = (1 << 2),
 
   GST_META_FLAG_LAST        = (1 << 16)
 } GstMetaFlags;
index 2840196..73b5d56 100644 (file)
@@ -210,6 +210,40 @@ GST_START_TEST (test_meta_test)
 
 GST_END_TEST;
 
+static gboolean
+foreach_meta (GstBuffer * buffer, GstMeta ** meta, gpointer user_data)
+{
+  /* try to remove */
+  *meta = NULL;
+  return TRUE;
+}
+
+GST_START_TEST (test_meta_locked)
+{
+  GstBuffer *buffer;
+  GstMetaTest *meta;
+
+  buffer = gst_buffer_new_and_alloc (4);
+  fail_if (buffer == NULL);
+
+  /* add some metadata */
+  meta = GST_META_TEST_ADD (buffer);
+  fail_if (meta == NULL);
+  GST_META_FLAG_SET (meta, GST_META_FLAG_LOCKED);
+
+  ASSERT_CRITICAL (gst_buffer_remove_meta (buffer, (GstMeta *) meta));
+  ASSERT_CRITICAL (gst_buffer_foreach_meta (buffer, foreach_meta, NULL));
+
+  GST_META_FLAG_UNSET (meta, GST_META_FLAG_LOCKED);
+
+  gst_buffer_remove_meta (buffer, (GstMeta *) meta);
+
+  /* clean up */
+  gst_buffer_unref (buffer);
+}
+
+GST_END_TEST;
+
 static Suite *
 gst_buffermeta_suite (void)
 {
@@ -218,6 +252,7 @@ gst_buffermeta_suite (void)
 
   suite_add_tcase (s, tc_chain);
   tcase_add_test (tc_chain, test_meta_test);
+  tcase_add_test (tc_chain, test_meta_locked);
 
   return s;
 }