Added callback to notify buffer release
authorSejun Park <sejun79.park@samsung.com>
Wed, 4 Jul 2018 07:43:21 +0000 (16:43 +0900)
committerSejun Park <sejun79.park@samsung.com>
Mon, 9 Jul 2018 05:03:58 +0000 (14:03 +0900)
Change-Id: I76295df7c8ab42d3a81f20e1ecd7f2b2621dc924

gst-libs/gst/allocators/gsttizenmemory.c
gst-libs/gst/allocators/gsttizenmemory.h

index b3f5442..c025f4e 100644 (file)
@@ -68,7 +68,8 @@ gst_video_format_to_tbm_format (GstVideoFormat format)
 }
 
 static GstTizenMemory *
-_tizen_video_mem_new (GstAllocator * allocator, GstMemory * parent, GstVideoInfo * vinfo, tbm_surface_h surface)
+_tizen_video_mem_new (GstAllocator * allocator, GstMemory * parent, GstVideoInfo * vinfo,
+    tbm_surface_h surface, gpointer user_data, GDestroyNotify notify)
 {
   gint width, height;
   GstTizenMemory *tmem;
@@ -80,6 +81,7 @@ _tizen_video_mem_new (GstAllocator * allocator, GstMemory * parent, GstVideoInfo
 
   /* Creates the tbm_surface with buffer objects. */
   if (surface) {
+    tbm_surface_internal_ref (surface);
     tmem->surface = surface;
   } else {
     width = GST_VIDEO_INFO_WIDTH (vinfo);
@@ -105,6 +107,8 @@ _tizen_video_mem_new (GstAllocator * allocator, GstMemory * parent, GstVideoInfo
     allocator, parent, GST_VIDEO_INFO_SIZE (vinfo), 0, 0,
     GST_VIDEO_INFO_SIZE (vinfo));
 
+  tmem->notify = notify;
+  tmem->user_data = user_data;
   g_mutex_init (&tmem->lock);
 
   GST_DEBUG ("%p: surface: %p size %" G_GSIZE_FORMAT, tmem, tmem->surface,
@@ -126,8 +130,11 @@ gst_tizen_mem_free (GstAllocator * allocator, GstMemory * mem)
 {
   GstTizenMemory *tmem = (GstTizenMemory *) mem;
 
+  tbm_surface_internal_unref (tmem->surface);
   GST_DEBUG ("free surface from mem : %p", tmem->surface);
-  tbm_surface_internal_destroy (tmem->surface);
+
+  if (tmem->notify)
+    tmem->notify (tmem->user_data);
 
   g_mutex_clear (&tmem->lock);
   g_slice_free (GstTizenMemory, tmem);
@@ -261,13 +268,14 @@ gst_tizen_allocator_new (void)
 GstMemory *
 gst_tizen_allocator_alloc (GstAllocator * allocator, GstVideoInfo * vinfo)
 {
-  return (GstMemory *)_tizen_video_mem_new (_tizen_allocator, NULL, vinfo, NULL);
+  return (GstMemory *)_tizen_video_mem_new (_tizen_allocator, NULL, vinfo, NULL, NULL, NULL);
 }
 
 GstMemory *
-gst_tizen_allocator_alloc_surface (GstAllocator * allocator, GstVideoInfo * vinfo, tbm_surface_h surface)
+gst_tizen_allocator_alloc_surface (GstAllocator * allocator, GstVideoInfo * vinfo,
+    tbm_surface_h surface, gpointer user_data, GDestroyNotify notify)
 {
-  return (GstMemory *)_tizen_video_mem_new (_tizen_allocator, NULL, vinfo, surface);
+  return (GstMemory *)_tizen_video_mem_new (_tizen_allocator, NULL, vinfo, surface, user_data, notify);
 }
 
 gboolean
index c15b326..c844fad 100644 (file)
@@ -91,7 +91,8 @@ GstAllocator *  gst_tizen_allocator_new    (void);
 
 GstMemory *     gst_tizen_allocator_alloc  (GstAllocator * allocator, GstVideoInfo * vinfo);
 
-GstMemory *     gst_tizen_allocator_alloc_surface (GstAllocator * allocator, GstVideoInfo * vinfo, tbm_surface_h surface);
+GstMemory *     gst_tizen_allocator_alloc_surface (GstAllocator * allocator, GstVideoInfo * vinfo,
+                                                   tbm_surface_h surface, gpointer user_data, GDestroyNotify notify);
 
 gboolean        gst_is_tizen_memory        (GstMemory *mem);