base:tizenmemory: Export gst_tizen_video_meta_map/unmap API and fix memory leak 69/302469/1 accepted/tizen/unified/20231211.095342 accepted/tizen/unified/riscv/20231226.211303
authorJeongmo Yang <jm80.yang@samsung.com>
Tue, 5 Dec 2023 06:15:43 +0000 (15:15 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Thu, 7 Dec 2023 09:03:17 +0000 (18:03 +0900)
- Fixed memory leak
 : The return value of "gst_buffer_get_memory()" should be released after use, but it was not.
   This patch replaces it by "gst_buffer_peek_memory()" and we don't need to release it.

[Version] 1.22.0-38
[Issue Type] API export

Change-Id: I09e00e2282706e8d4e7a5ddf7cf87313b86277b0
Signed-off-by: Jeongmo Yang <jm80.yang@samsung.com>
packaging/gstreamer.spec
subprojects/gst-plugins-base/gst-libs/gst/allocators/gsttizenmemory.c
subprojects/gst-plugins-base/gst-libs/gst/allocators/gsttizenmemory.h

index 1da1610..a1180e9 100644 (file)
@@ -62,7 +62,7 @@
 
 Name:           %{_name}
 Version:        1.22.0
-Release:        37
+Release:        38
 Summary:        Streaming-Media Framework Runtime
 License:        LGPL-2.0+
 Group:          Multimedia/Framework
index cb28501..87f4c11 100644 (file)
@@ -115,8 +115,14 @@ _tizen_video_mem_new (GstAllocator * allocator, GstMemory * parent, GstVideoInfo
 
   for (i = 0; i < sinfo.num_planes; i++) {
     GST_VIDEO_INFO_PLANE_STRIDE (vinfo, i) = sinfo.planes[i].stride;
+#if 0
+    /* The offset from TBM surface is not matched to GST_VIDEO_INFO.
+       They are initialized as 0 when created and it's not needed to updated now,
+       and can be updated if needed in the future. */
     GST_VIDEO_INFO_PLANE_OFFSET (vinfo, i) = sinfo.planes[i].offset;
-    GST_DEBUG ("tbm surface plane[%d][%p]", i, sinfo.planes[i].ptr);
+#endif
+    GST_DEBUG ("tbm surface plane[%d][%p][stride:%u]",
+      i, sinfo.planes[i].ptr, sinfo.planes[i].stride);
   }
 
   GST_VIDEO_INFO_SIZE (vinfo) = sinfo.size;
@@ -813,7 +819,7 @@ gst_tizen_video_meta_map (GstVideoMeta * meta, guint plane, GstMapInfo * info,
   int tbm_opt = 0;
   gboolean mapped = FALSE;
   GstBuffer *buffer = meta->buffer;
-  GstTizenMemory *tmem = (GstTizenMemory *) gst_buffer_get_memory (buffer, 0);
+  GstTizenMemory *tmem = (GstTizenMemory *) gst_buffer_peek_memory (buffer, 0);
 
   g_return_val_if_fail (GST_IS_TIZEN_ALLOCATOR (((GstMemory *) tmem)->allocator), FALSE);
 
@@ -825,7 +831,7 @@ gst_tizen_video_meta_map (GstVideoMeta * meta, guint plane, GstMapInfo * info,
   g_mutex_lock (&tmem->lock);
 
   if (tmem->video_memory_map[plane]) {
-    GST_ERROR ("buf[%p] plane[%d] is already mapped", buffer, plane);
+    GST_ERROR ("buf[%p] plane[%u] is already mapped", buffer, plane);
     goto _VIDEO_MEMORY_MAP_DONE;
   }
 
@@ -844,13 +850,11 @@ gst_tizen_video_meta_map (GstVideoMeta * meta, guint plane, GstMapInfo * info,
   }
 
   if (plane >= tmem->surface_info.num_planes) {
-    GST_ERROR ("buf[%p] invalid plane index[%d] (num plane[%d])",
+    GST_ERROR ("buf[%p] invalid plane[%u] (num_plane[%d])",
       buffer, plane, tmem->surface_info.num_planes);
 
-    if (tmem->video_memory_map_count == 0) {
-      GST_ERROR ("buf[%p] unmap surface[%p]", buffer, tmem->surface);
+    if (tmem->video_memory_map_count == 0)
       tbm_surface_unmap (tmem->surface);
-    }
 
     goto _VIDEO_MEMORY_MAP_DONE;
   }
@@ -864,8 +868,8 @@ gst_tizen_video_meta_map (GstVideoMeta * meta, guint plane, GstMapInfo * info,
   /* set map flags */
   info->flags = flags;
 
-  GST_DEBUG ("buf[%p] plane[%d], data[%p], stride[%d], flags[0x%x]",
-    buffer, plane, *data, *stride, info->flags);
+  GST_DEBUG ("mapped: b[%p] p[%d], d[%p], s[%d], f[0x%x], map_count[%d]",
+    buffer, plane, *data, *stride, info->flags, tmem->video_memory_map_count);
 
   mapped = TRUE;
 
@@ -889,7 +893,7 @@ gst_tizen_video_meta_unmap (GstVideoMeta * meta, guint plane, GstMapInfo * info)
   int tbm_ret = TBM_SURFACE_ERROR_NONE;
   gboolean unmapped = FALSE;
   GstBuffer *buffer = meta->buffer;
-  GstTizenMemory *tmem = (GstTizenMemory *) gst_buffer_get_memory (buffer, 0);
+  GstTizenMemory *tmem = (GstTizenMemory *) gst_buffer_peek_memory (buffer, 0);
 
   g_return_val_if_fail (GST_IS_TIZEN_ALLOCATOR (((GstMemory *) tmem)->allocator), FALSE);
 
@@ -901,13 +905,13 @@ gst_tizen_video_meta_unmap (GstVideoMeta * meta, guint plane, GstMapInfo * info)
   g_mutex_lock (&tmem->lock);
 
   if (tmem->video_memory_map[plane] == FALSE) {
-    GST_ERROR ("buf[%p] plane[%d] is already unmapped",
+    GST_ERROR ("buf[%p] plane[%u] is already unmapped",
       buffer, plane);
     goto _VIDEO_MEMORY_UNMAP_DONE;
   }
 
   if (tmem->video_memory_map_count > 1) {
-    GST_DEBUG ("buf[%p] plane[%d] skip unmap surface[%p]",
+    GST_DEBUG ("buf[%p] plane[%u] skip unmap surface[%p]",
       buffer, plane, tmem->surface);
     unmapped = TRUE;
     goto _VIDEO_MEMORY_UNMAP_DONE;
@@ -922,13 +926,13 @@ gst_tizen_video_meta_unmap (GstVideoMeta * meta, guint plane, GstMapInfo * info)
 
   unmapped = TRUE;
 
-  GST_DEBUG ("buf[%p] plane[%d] unmap surface[%p] done",
-    buffer, plane, tmem->surface);
-
 _VIDEO_MEMORY_UNMAP_DONE:
   if (unmapped == TRUE) {
     tmem->video_memory_map[plane] = FALSE;
     tmem->video_memory_map_count--;
+
+    GST_DEBUG ("unmapped: b[%p] p[%d], map_count[%d]",
+      buffer, plane, tmem->video_memory_map_count);
   }
 
   g_mutex_unlock (&tmem->lock);
index 88bd093..48cbed1 100644 (file)
@@ -146,11 +146,11 @@ GstMemory *     gst_tizen_allocator_dmabuf_export (GstAllocator * allocator, Gst
 GST_ALLOCATORS_API
 GstTizenMemory *gst_tizen_allocator_dmabuf_import (GstAllocator * allocator, gint * fds, gint planes, gsize offsets[4], GstVideoInfo * vinfo);
 
-GST_VIDEO_API
+GST_ALLOCATORS_API
 gboolean        gst_tizen_video_meta_map (GstVideoMeta * meta, guint plane, GstMapInfo * info,
                     gpointer * data, gint * stride, GstMapFlags flags);
 
-GST_VIDEO_API
+GST_ALLOCATORS_API
 gboolean        gst_tizen_video_meta_unmap (GstVideoMeta * meta, guint plane, GstMapInfo * info);
 
 GST_ALLOCATORS_API