bin: Drop need-context messages without source instead of crashing
[platform/upstream/gstreamer.git] / gst / gstbuffer.c
index 1e79acf..19a70b4 100644 (file)
  * Typically, #GstParentBufferMeta is used when the child buffer is directly
  * using the #GstMemory of the parent buffer, and wants to prevent the parent
  * buffer from being returned to a buffer pool until the #GstMemory is available
- * for re-use. (Since 1.6)
+ * for re-use. (Since: 1.6)
  *
  */
 #include "gst_private.h"
@@ -145,6 +145,7 @@ GType _gst_buffer_type = 0;
 #define GST_BUFFER_MEM_PTR(b,i)    (((GstBufferImpl *)(b))->mem[i])
 #define GST_BUFFER_BUFMEM(b)       (((GstBufferImpl *)(b))->bufmem)
 #define GST_BUFFER_META(b)         (((GstBufferImpl *)(b))->item)
+#define GST_BUFFER_TAIL_META(b)    (((GstBufferImpl *)(b))->tail_item)
 
 typedef struct
 {
@@ -162,6 +163,7 @@ typedef struct
   /* FIXME, make metadata allocation more efficient by using part of the
    * GstBufferImpl */
   GstMetaItem *item;
+  GstMetaItem *tail_item;
 } GstBufferImpl;
 
 static gint64 meta_seq;         /* 0 *//* ATOMIC */
@@ -178,7 +180,7 @@ gst_atomic_int64_inc (volatile gint64 * atomic)
 static inline gint64
 gst_atomic_int64_inc (volatile gint64 * atomic)
 {
-  InterlockedExchangeAdd (atomic, 1);
+  return InterlockedExchangeAdd64 (atomic, 1);
 }
 #else
 #warning No 64-bit atomic int defined for this platform/toolchain!
@@ -1832,7 +1834,7 @@ gst_buffer_map_range (GstBuffer * buffer, guint idx, gint length,
   /* ERROR */
 not_writable:
   {
-    GST_WARNING_OBJECT (buffer, "write map requested on non-writable buffer");
+    GST_WARNING ("write map requested on non-writable buffer");
     g_critical ("write map requested on non-writable buffer");
     memset (info, 0, sizeof (GstMapInfo));
     return FALSE;
@@ -1840,13 +1842,13 @@ not_writable:
 no_memory:
   {
     /* empty buffer, we need to return NULL */
-    GST_DEBUG_OBJECT (buffer, "can't get buffer memory");
+    GST_DEBUG ("can't get buffer memory");
     memset (info, 0, sizeof (GstMapInfo));
     return TRUE;
   }
 cannot_map:
   {
-    GST_DEBUG_OBJECT (buffer, "cannot map memory");
+    GST_DEBUG ("cannot map memory");
     memset (info, 0, sizeof (GstMapInfo));
     return FALSE;
   }
@@ -2284,10 +2286,15 @@ gst_buffer_add_meta (GstBuffer * buffer, const GstMetaInfo * info,
       goto init_failed;
 
   item->seq_num = gst_atomic_int64_inc (&meta_seq);
+  item->next = NULL;
 
-  /* and add to the list of metadata */
-  item->next = GST_BUFFER_META (buffer);
-  GST_BUFFER_META (buffer) = item;
+  if (!GST_BUFFER_META (buffer)) {
+    GST_BUFFER_META (buffer) = item;
+    GST_BUFFER_TAIL_META (buffer) = item;
+  } else {
+    GST_BUFFER_TAIL_META (buffer)->next = item;
+    GST_BUFFER_TAIL_META (buffer) = item;
+  }
 
   return result;
 
@@ -2327,10 +2334,18 @@ gst_buffer_remove_meta (GstBuffer * buffer, GstMeta * meta)
       const GstMetaInfo *info = meta->info;
 
       /* remove from list */
+      if (GST_BUFFER_TAIL_META (buffer) == walk) {
+        if (prev != walk)
+          GST_BUFFER_TAIL_META (buffer) = prev;
+        else
+          GST_BUFFER_TAIL_META (buffer) = NULL;
+      }
+
       if (GST_BUFFER_META (buffer) == walk)
         GST_BUFFER_META (buffer) = walk->next;
       else
         prev->next = walk->next;
+
       /* call free_func if any */
       if (info->free_func)
         info->free_func (m, buffer);
@@ -2466,6 +2481,13 @@ gst_buffer_foreach_meta (GstBuffer * buffer, GstBufferForeachMetaFunc func,
       g_return_val_if_fail (!GST_META_FLAG_IS_SET (m, GST_META_FLAG_LOCKED),
           FALSE);
 
+      if (GST_BUFFER_TAIL_META (buffer) == walk) {
+        if (prev != walk)
+          GST_BUFFER_TAIL_META (buffer) = prev;
+        else
+          GST_BUFFER_TAIL_META (buffer) = NULL;
+      }
+
       /* remove from list */
       if (GST_BUFFER_META (buffer) == walk)
         prev = GST_BUFFER_META (buffer) = next;