From 0323a2af1bdff36e7851fec14e79fee5f39fb91b Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Thu, 13 Feb 2025 20:32:05 +0900 Subject: [PATCH] base:tizenmemory: Add new APIs for secured buffer - New APIs : GstMemory *gst_tizen_allocator_alloc_secure_fd (GstAllocator * allocator, GstVideoInfo * vinfo, int fd[GST_TIZEN_MEMORY_MAX_FD], int fd_count, gsize maxsize, gsize size, gpointer user_data, GDestroyNotify notify); : gboolean gst_tizen_memory_is_secured (GstMemory * mem); [Version] 1.24.11-6 [Issue Type] New feature Change-Id: I5c97a96794f1df5839d430c2441b0fa7ce0ad857 Signed-off-by: Jeongmo Yang --- packaging/gstreamer.spec | 2 +- .../gst-libs/gst/allocators/gsttizenmemory.c | 103 +++++++++++++----- .../gst-libs/gst/allocators/gsttizenmemory.h | 9 ++ 3 files changed, 87 insertions(+), 27 deletions(-) diff --git a/packaging/gstreamer.spec b/packaging/gstreamer.spec index cd7c2750cb..718a92a700 100644 --- a/packaging/gstreamer.spec +++ b/packaging/gstreamer.spec @@ -60,7 +60,7 @@ Name: %{_name} Version: 1.24.11 -Release: 5 +Release: 6 Summary: Streaming-Media Framework Runtime License: LGPL-2.0+ Group: Multimedia/Framework diff --git a/subprojects/gst-plugins-base/gst-libs/gst/allocators/gsttizenmemory.c b/subprojects/gst-plugins-base/gst-libs/gst/allocators/gsttizenmemory.c index 87f4c11d8e..ad87f414f9 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/allocators/gsttizenmemory.c +++ b/subprojects/gst-plugins-base/gst-libs/gst/allocators/gsttizenmemory.c @@ -223,16 +223,17 @@ _tizen_video_mem_new2 (GstAllocator * allocator, GstMemory * parent, GstVideoInf static GstTizenMemory * _tizen_video_mem_new3 (GstAllocator * allocator, GstMemory * parent, GstVideoInfo * vinfo, tbm_surface_info_s * tsinfo, int fd[GST_TIZEN_MEMORY_MAX_FD], int fd_count, + gboolean is_secured, gsize maxsize, gsize size, gpointer user_data, GDestroyNotify notify) { int i = 0; - tbm_bo bos[GST_TIZEN_MEMORY_MAX_FD] = {NULL, }; + tbm_bo bos[GST_TIZEN_MEMORY_MAX_FD] = {NULL, NULL, NULL, NULL}; tbm_surface_h surface = NULL; GstTizenMemory *tmem; GstTizenAllocator *tallocator = GST_TIZEN_ALLOCATOR (allocator); - if (!vinfo || !tsinfo || fd_count < 1 || fd_count > GST_TIZEN_MEMORY_MAX_FD) { - GST_ERROR ("invalid param[vinfo:%p,tsinfo:%p, fd_count:%d]", vinfo, tsinfo, fd_count); + if (!vinfo || fd_count < 1 || fd_count > GST_TIZEN_MEMORY_MAX_FD) { + GST_ERROR ("invalid param[vinfo:%p,fd_count:%d]", vinfo, fd_count); return NULL; } @@ -241,30 +242,40 @@ _tizen_video_mem_new3 (GstAllocator * allocator, GstMemory * parent, GstVideoInf return NULL; } - for (i = 0 ; i < fd_count ; i++) { - bos[i] = tbm_bo_import_fd (tallocator->bufmgr, fd[i]); - if (!bos[i]) { - GST_ERROR ("failed to import fd[%d]", fd[i]); - goto _TIZEN_VIDEO_MEM_NEW3_FAILED; + tmem = g_slice_new0 (GstTizenMemory); + + if (is_secured) { + gst_memory_init (GST_MEMORY_CAST (tmem), 0, + allocator, parent, maxsize, 0, 0, size); + } else if (tsinfo) { + gst_memory_init (GST_MEMORY_CAST (tmem), 0, + allocator, parent, tsinfo->size, 0, 0, tsinfo->size); + + for (i = 0 ; i < fd_count ; i++) { + bos[i] = tbm_bo_import_fd (tallocator->bufmgr, fd[i]); + if (!bos[i]) { + GST_ERROR ("failed to import fd[%d]", fd[i]); + goto _TIZEN_VIDEO_MEM_NEW3_FAILED; + } } - } - surface = tbm_surface_internal_create_with_bos (tsinfo, bos, fd_count); - if (!surface) { - GST_ERROR ("failed to create surface"); + surface = tbm_surface_internal_create_with_bos (tsinfo, bos, fd_count); + if (!surface) { + GST_ERROR ("failed to create surface"); + goto _TIZEN_VIDEO_MEM_NEW3_FAILED; + } + } else { + GST_ERROR ("not secured, but NULL tsinfo"); goto _TIZEN_VIDEO_MEM_NEW3_FAILED; } - tmem = g_slice_new0 (GstTizenMemory); - - gst_memory_init (GST_MEMORY_CAST (tmem), 0, - allocator, parent, tsinfo->size, 0, 0, tsinfo->size); - - /* bos[] will be kept in tbm surface and released when surface is released finally. */ for (i = 0 ; i < fd_count ; i++) { - tbm_bo_unref (bos[i]); - bos[i] = NULL; tmem->fd[i] = fd[i]; + + if (bos[i]) { + /* bos[] will be kept in tbm surface and released when surface is released finally. */ + tbm_bo_unref (bos[i]); + } } tmem->surface = surface; @@ -273,6 +284,7 @@ _tizen_video_mem_new3 (GstAllocator * allocator, GstMemory * parent, GstVideoInf tmem->notify = notify; tmem->user_data = user_data; tmem->is_fd_exported = FALSE; + tmem->is_secured = is_secured; GST_VIDEO_INFO_SIZE (tmem->info) = tsinfo->size; @@ -287,6 +299,8 @@ _TIZEN_VIDEO_MEM_NEW3_FAILED: for (i = 0 ; i < fd_count && bos[i] ; i++) tbm_bo_unref (bos[i]); + gst_memory_unref (GST_MEMORY_CAST (tmem)); + return NULL; } @@ -579,7 +593,7 @@ gst_tizen_allocator_alloc (GstAllocator * allocator, GstVideoInfo * vinfo) { g_return_val_if_fail (GST_IS_TIZEN_ALLOCATOR (allocator), NULL); - return (GstMemory *)_tizen_video_mem_new (allocator, NULL, vinfo, NULL, NULL, NULL); + return GST_MEMORY_CAST (_tizen_video_mem_new (allocator, NULL, vinfo, NULL, NULL, NULL)); } /** @@ -598,7 +612,7 @@ gst_tizen_allocator_alloc_surface (GstAllocator * allocator, GstVideoInfo * vinf { g_return_val_if_fail (GST_IS_TIZEN_ALLOCATOR (allocator), NULL); - return (GstMemory *)_tizen_video_mem_new (allocator, NULL, vinfo, surface, user_data, notify); + return GST_MEMORY_CAST (_tizen_video_mem_new (allocator, NULL, vinfo, surface, user_data, notify)); } /** @@ -618,7 +632,7 @@ gst_tizen_allocator_alloc_bo (GstAllocator * allocator, GstVideoInfo * vinfo, { g_return_val_if_fail (GST_IS_TIZEN_ALLOCATOR (allocator), NULL); - return (GstMemory *)_tizen_video_mem_new2 (allocator, NULL, vinfo, bo, size, user_data, notify); + return GST_MEMORY_CAST (_tizen_video_mem_new2 (allocator, NULL, vinfo, bo, size, user_data, notify)); } /** @@ -638,9 +652,33 @@ gst_tizen_allocator_alloc_fd (GstAllocator * allocator, GstVideoInfo * vinfo, tbm_surface_info_s * tsinfo, int fd[GST_TIZEN_MEMORY_MAX_FD], int fd_count, gpointer user_data, GDestroyNotify notify) { + GstTizenMemory *tmem = NULL; + g_return_val_if_fail (GST_IS_TIZEN_ALLOCATOR (allocator), NULL); - return (GstMemory *)_tizen_video_mem_new3 (allocator, NULL, vinfo, tsinfo, fd, fd_count, user_data, notify); + tmem = _tizen_video_mem_new3 (allocator, NULL, vinfo, + tsinfo, fd, fd_count, + FALSE, 0, 0, + user_data, notify); + + return GST_MEMORY_CAST (tmem); +} + +GstMemory * +gst_tizen_allocator_alloc_secure_fd (GstAllocator * allocator, GstVideoInfo * vinfo, + int fd[GST_TIZEN_MEMORY_MAX_FD], int fd_count, gsize maxsize, gsize size, + gpointer user_data, GDestroyNotify notify) +{ + GstTizenMemory *tmem = NULL; + + g_return_val_if_fail (GST_IS_TIZEN_ALLOCATOR (allocator), NULL); + + tmem = _tizen_video_mem_new3 (allocator, NULL, vinfo, + NULL, fd, fd_count, + TRUE, maxsize, size, + user_data, notify); + + return GST_MEMORY_CAST (tmem); } gboolean @@ -737,6 +775,19 @@ gst_tizen_memory_get_fd (GstMemory * mem, gint index) return tmem->fd[index]; } +gboolean +gst_tizen_memory_is_secured (GstMemory * mem) +{ + GstTizenMemory *tmem = (GstTizenMemory *)mem; + + g_return_val_if_fail (mem != NULL, FALSE); + g_return_val_if_fail (GST_IS_TIZEN_ALLOCATOR (mem->allocator), FALSE); + + GST_DEBUG ("mem[%p]: is_secured[%d]", tmem, tmem->is_secured); + + return tmem->is_secured; +} + static void cached_tizen_disposed_cb (GstTizenAllocator * allocator, GstMiniObject *obj) { @@ -821,7 +872,7 @@ gst_tizen_video_meta_map (GstVideoMeta * meta, guint plane, GstMapInfo * info, GstBuffer *buffer = meta->buffer; GstTizenMemory *tmem = (GstTizenMemory *) gst_buffer_peek_memory (buffer, 0); - g_return_val_if_fail (GST_IS_TIZEN_ALLOCATOR (((GstMemory *) tmem)->allocator), FALSE); + g_return_val_if_fail (GST_IS_TIZEN_ALLOCATOR (GST_MEMORY_CAST (tmem)->allocator), FALSE); if (!tmem->surface || plane >= GST_VIDEO_MAX_PLANES) { GST_ERROR ("invalid param[surface:%p,plane:%u]", tmem->surface, plane); @@ -895,7 +946,7 @@ gst_tizen_video_meta_unmap (GstVideoMeta * meta, guint plane, GstMapInfo * info) GstBuffer *buffer = meta->buffer; GstTizenMemory *tmem = (GstTizenMemory *) gst_buffer_peek_memory (buffer, 0); - g_return_val_if_fail (GST_IS_TIZEN_ALLOCATOR (((GstMemory *) tmem)->allocator), FALSE); + g_return_val_if_fail (GST_IS_TIZEN_ALLOCATOR (GST_MEMORY_CAST (tmem)->allocator), FALSE); if (!tmem->surface) { GST_ERROR ("no surface"); diff --git a/subprojects/gst-plugins-base/gst-libs/gst/allocators/gsttizenmemory.h b/subprojects/gst-plugins-base/gst-libs/gst/allocators/gsttizenmemory.h index 48cbed13dc..a7fc02e5c0 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/allocators/gsttizenmemory.h +++ b/subprojects/gst-plugins-base/gst-libs/gst/allocators/gsttizenmemory.h @@ -77,6 +77,7 @@ struct _GstTizenMemory int fd[GST_TIZEN_MEMORY_MAX_FD]; int fd_count; gboolean is_fd_exported; + gboolean is_secured; }; struct _GstTizenAllocatorPrivate @@ -122,6 +123,11 @@ GstMemory * gst_tizen_allocator_alloc_fd (GstAllocator * allocator, GstVideo tbm_surface_info_s * tsinfo, int fd[GST_TIZEN_MEMORY_MAX_FD], int fd_count, gpointer user_data, GDestroyNotify notify); +GST_ALLOCATORS_API +GstMemory * gst_tizen_allocator_alloc_secure_fd (GstAllocator * allocator, GstVideoInfo * vinfo, + int fd[GST_TIZEN_MEMORY_MAX_FD], int fd_count, gsize maxsize, gsize size, + gpointer user_data, GDestroyNotify notify); + GST_ALLOCATORS_API gboolean gst_is_tizen_memory (GstMemory * mem); @@ -140,6 +146,9 @@ gint gst_tizen_memory_get_num_fd (GstMemory * mem); GST_ALLOCATORS_API gint gst_tizen_memory_get_fd (GstMemory * mem, gint index); +GST_ALLOCATORS_API +gboolean gst_tizen_memory_is_secured (GstMemory * mem); + GST_ALLOCATORS_API GstMemory * gst_tizen_allocator_dmabuf_export (GstAllocator * allocator, GstMemory * tmem, int bo_idx); -- 2.34.1