tizenmemory: Support gst_tizen_memory_get_fd() in all kinds of tizen memories 67/297167/3 accepted/tizen/7.0/unified/20230816.171631
authorJeongmo Yang <jm80.yang@samsung.com>
Fri, 11 Aug 2023 06:00:44 +0000 (15:00 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Fri, 11 Aug 2023 08:55:27 +0000 (17:55 +0900)
- Previously, gst_tizen_memory_get_fd() is only available with the tizen memory
  which is created by gst_tizen_allocator_alloc_fd().
- The tizen memory which is created by other alloc functions
  (gst_tizen_allocator_alloc(), gst_tizen_allocator_alloc_bo(), gst_tizen_allocator_alloc_surface())
  also supports gst_tizen_memory_get_fd() now.

[Version] 1.20.0-50
[Issue Type] Improvement

Change-Id: I317a77381c84992e861cee32c4278b00a530f48b
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 ed66d090035381c5fcb30ae2980895542cd71694..01edb379fc056111d22a60070e93f6da8256f8d3 100644 (file)
@@ -62,7 +62,7 @@
 
 Name:           %{_name}
 Version:        1.20.0
-Release:        49
+Release:        50
 Summary:        Streaming-Media Framework Runtime
 License:        LGPL-2.0+
 Group:          Multimedia/Framework
index f1082928af0301baf1f079c2a95a9f484fd24626..ee822ed33fce10a218cdcaec813b59bbd2ce9351 100644 (file)
@@ -22,6 +22,7 @@
 #include "config.h"
 #endif
 
+#include <unistd.h>
 #include "string.h"
 #include "gstdmabuf.h"
 #include "gsttizenmemory.h"
@@ -82,7 +83,9 @@ _tizen_video_mem_new (GstAllocator * allocator, GstMemory * parent, GstVideoInfo
   GstTizenMemory *tmem;
   tbm_surface_info_s sinfo;
   tbm_format format;
-  gint i;
+  int i = 0;
+  int j = 0;
+  int bo_num = 0;
 
   if (!vinfo) {
     GST_ERROR ("invalid vinfo");
@@ -118,6 +121,26 @@ _tizen_video_mem_new (GstAllocator * allocator, GstMemory * parent, GstVideoInfo
 
   GST_VIDEO_INFO_SIZE (vinfo) = sinfo.size;
 
+  bo_num = tbm_surface_internal_get_num_bos (tmem->surface);
+
+  for (i = 0 ; i < bo_num ; i++) {
+    tmem->fd[i] = tbm_bo_export_fd (tbm_surface_internal_get_bo (tmem->surface, i));
+    if (tmem->fd[i] < 0) {
+      GST_ERROR ("fd export failed for bo[%d] %p",
+        i, tbm_surface_internal_get_bo (tmem->surface, i));
+
+      for (j = i - 1 ; j >= 0 ; j--) {
+        GST_WARNING ("close exported fd[%d] %d", j, tmem->fd[j]);
+        close (tmem->fd[j]);
+      }
+
+      g_slice_free (GstTizenMemory, tmem);
+      return NULL;
+    }
+
+    GST_DEBUG ("exported fd[%d] %d", i, tmem->fd[i]);
+  }
+
   gst_memory_init (GST_MEMORY_CAST (tmem), 0,
     allocator, parent, GST_VIDEO_INFO_SIZE (vinfo), 0, 0,
     GST_VIDEO_INFO_SIZE (vinfo));
@@ -125,6 +148,9 @@ _tizen_video_mem_new (GstAllocator * allocator, GstMemory * parent, GstVideoInfo
   tmem->info = gst_video_info_copy (vinfo);
   tmem->notify = notify;
   tmem->user_data = user_data;
+  tmem->fd_count = bo_num;
+  tmem->is_fd_exported = TRUE;
+
   g_mutex_init (&tmem->lock);
 
   GST_DEBUG ("mem[%p], surface[%p], size[%" G_GSIZE_FORMAT"]",
@@ -137,6 +163,7 @@ static GstTizenMemory *
 _tizen_video_mem_new2 (GstAllocator * allocator, GstMemory * parent, GstVideoInfo * vinfo,
     tbm_bo bo, gsize size, gpointer user_data, GDestroyNotify notify)
 {
+  int fd = -1;
   int bo_size = tbm_bo_size (bo);
   GstTizenMemory *tmem;
 
@@ -157,6 +184,13 @@ _tizen_video_mem_new2 (GstAllocator * allocator, GstMemory * parent, GstVideoInf
     return NULL;
   }
 
+  fd = tbm_bo_export_fd (bo);
+  if (fd < 0) {
+    GST_ERROR ("bo[%p] export failed", bo);
+    tbm_bo_unref (bo);
+    return NULL;
+  }
+
   tmem = g_slice_new0 (GstTizenMemory);
 
   gst_memory_init (GST_MEMORY_CAST (tmem), 0,
@@ -166,6 +200,10 @@ _tizen_video_mem_new2 (GstAllocator * allocator, GstMemory * parent, GstVideoInf
   tmem->info = gst_video_info_copy (vinfo);
   tmem->notify = notify;
   tmem->user_data = user_data;
+  tmem->fd[0] = fd;
+  tmem->fd_count = 1;
+  tmem->is_fd_exported = TRUE;
+
   GST_VIDEO_INFO_SIZE (tmem->info) = size;
 
   g_mutex_init (&tmem->lock);
@@ -228,6 +266,7 @@ _tizen_video_mem_new3 (GstAllocator * allocator, GstMemory * parent, GstVideoInf
   tmem->info = gst_video_info_copy (vinfo);
   tmem->notify = notify;
   tmem->user_data = user_data;
+  tmem->is_fd_exported = FALSE;
 
   GST_VIDEO_INFO_SIZE (tmem->info) = tsinfo->size;
 
@@ -248,8 +287,17 @@ _TIZEN_VIDEO_MEM_NEW3_FAILED:
 static void
 gst_tizen_mem_free (GstAllocator * allocator, GstMemory * mem)
 {
+  int i = 0;
   GstTizenMemory *tmem = (GstTizenMemory *) mem;
 
+  if (tmem->is_fd_exported) {
+    for (i = 0 ; i < tmem->fd_count && tmem->fd[i] >= 0 ; i++) {
+      GST_DEBUG ("close exported fd[%d] %d", i, tmem->fd[i]);
+      close (tmem->fd[i]);
+      tmem->fd[i] = -1;
+    }
+  }
+
   if (tmem->bo) {
     GST_DEBUG ("unref bo[%p] from mem[%p]", tmem->bo, tmem);
     tbm_bo_unref (tmem->bo);
@@ -385,7 +433,7 @@ gst_tizen_mem_copy (GstMemory * gmem, gssize offset, gsize size)
   GstMemory *copy = NULL;
   GstTizenMemory *tmem = (GstTizenMemory *) gmem;
 
-  GST_DEBUG ("copy mem[%p], offset[%d], size[%"G_GSIZE_FORMAT"]",
+  GST_DEBUG ("copy mem[%p], offset[%"G_GSSIZE_FORMAT"], size[%"G_GSIZE_FORMAT"]",
     tmem, offset, size);
 
   if (tmem->surface) {
index 8cadb6aa5a1ebd8479059a5fc97d241a8b8e6c05..88bd093d586d0a079a32960e8b1c2a96b546cf43 100644 (file)
@@ -76,6 +76,7 @@ struct _GstTizenMemory
   /* for fd */
   int fd[GST_TIZEN_MEMORY_MAX_FD];
   int fd_count;
+  gboolean is_fd_exported;
 };
 
 struct _GstTizenAllocatorPrivate