base:tizenmemory: Fix build warning and add exception handling code 27/297727/1 accepted/tizen/8.0/unified/20231005.094934 accepted/tizen/unified/20230825.044244 tizen_8.0_m2_release
authorJeongmo Yang <jm80.yang@samsung.com>
Wed, 23 Aug 2023 08:50:46 +0000 (17:50 +0900)
committerJeongmo Yang <jm80.yang@samsung.com>
Wed, 23 Aug 2023 08:51:36 +0000 (17:51 +0900)
[Version] 1.22.0-34
[Issue Type] Improvement

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

index d4c258f..c6b4e10 100644 (file)
@@ -62,7 +62,7 @@
 
 Name:           %{_name}
 Version:        1.22.0
-Release:        33
+Release:        34
 Summary:        Streaming-Media Framework Runtime
 License:        LGPL-2.0+
 Group:          Multimedia/Framework
index ce944f3..cb28501 100644 (file)
@@ -22,6 +22,7 @@
 #include "config.h"
 #endif
 
+#include <unistd.h>
 #include "string.h"
 #include "gstdmabuf.h"
 #include "gsttizenmemory.h"
@@ -79,12 +80,12 @@ _tizen_video_mem_new (GstAllocator * allocator, GstMemory * parent, GstVideoInfo
     tbm_surface_h surface, gpointer user_data, GDestroyNotify notify)
 {
   int i = 0;
+  int j = 0;
   int num_bos = 0;
   gint width, height;
   GstTizenMemory *tmem;
   tbm_surface_info_s sinfo;
   tbm_format format;
-  tbm_bo bo = NULL;
 
   if (!vinfo) {
     GST_ERROR ("invalid vinfo");
@@ -121,9 +122,24 @@ _tizen_video_mem_new (GstAllocator * allocator, GstMemory * parent, GstVideoInfo
   GST_VIDEO_INFO_SIZE (vinfo) = sinfo.size;
 
   num_bos = tbm_surface_internal_get_num_bos (tmem->surface);
+
   for (i = 0 ; i < num_bos ; i++) {
-    bo = tbm_surface_internal_get_bo (tmem->surface, i);
-    tmem->fd[i] = tbm_bo_export_fd (bo);
+    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]);
+      }
+
+      tbm_surface_internal_unref (tmem->surface);
+      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,
@@ -135,6 +151,7 @@ _tizen_video_mem_new (GstAllocator * allocator, GstMemory * parent, GstVideoInfo
   tmem->user_data = user_data;
   tmem->fd_count = num_bos;
   tmem->is_fd_exported = TRUE;
+
   g_mutex_init (&tmem->lock);
 
   GST_DEBUG ("mem[%p], surface[%p], size[%" G_GSIZE_FORMAT"]",
@@ -273,6 +290,14 @@ 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);
@@ -288,11 +313,6 @@ gst_tizen_mem_free (GstAllocator * allocator, GstMemory * mem)
   if (tmem->notify)
     tmem->notify (tmem->user_data);
 
-  if (tmem->is_fd_exported) {
-    for (i = 0 ; i < tmem->fd_count ; i++)
-      close (tmem->fd[i]);
-  }
-
   gst_video_info_free (tmem->info);
   g_mutex_clear (&tmem->lock);
   g_slice_free (GstTizenMemory, tmem);
@@ -413,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) {