return tmem;
}
+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,
+ gpointer user_data, GDestroyNotify notify)
+{
+ int i = 0;
+ tbm_bo bos[GST_TIZEN_MEMORY_MAX_FD] = {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);
+ return NULL;
+ }
+
+ if (!tallocator->bufmgr) {
+ GST_ERROR ("No TBM bufmgr");
+ 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;
+ }
+ }
+
+ 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;
+ }
+
+ 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];
+ }
+
+ tmem->surface = surface;
+ tmem->fd_count = fd_count;
+ tmem->info = gst_video_info_copy (vinfo);
+ tmem->notify = notify;
+ tmem->user_data = user_data;
+
+ GST_VIDEO_INFO_SIZE (tmem->info) = tsinfo->size;
+
+ g_mutex_init (&tmem->lock);
+
+ GST_DEBUG ("mem[%p], fd[0][%d], fd_count[%d], size[%" G_GSIZE_FORMAT"], max[%" G_GSIZE_FORMAT"]",
+ tmem, tmem->fd[0], tmem->fd_count, tmem->mem.size, tmem->mem.maxsize);
+
+ return tmem;
+
+_TIZEN_VIDEO_MEM_NEW3_FAILED:
+ for (i = 0 ; i < fd_count && bos[i] ; i++)
+ tbm_bo_unref (bos[i]);
+
+ return NULL;
+}
+
static void
gst_tizen_mem_free (GstAllocator * allocator, GstMemory * mem)
{
g_list_free (allocator->priv->mem_cache);
allocator->priv->mem_cache = NULL;
+ tbm_bufmgr_deinit (allocator->bufmgr);
+ allocator->bufmgr = NULL;
+
G_OBJECT_CLASS (parent_class)->finalize (obj);
}
alloc->mem_copy = (GstMemoryCopyFunction) gst_tizen_mem_copy;
GST_OBJECT_FLAG_SET (allocator, GST_ALLOCATOR_FLAG_CUSTOM_ALLOC);
+
+ allocator->bufmgr = tbm_bufmgr_init (-1);
+ if (!allocator->bufmgr)
+ GST_ERROR ("TBM bufmgr failed");
}
/**
return (GstMemory *)_tizen_video_mem_new2 (allocator, NULL, vinfo, bo, size, user_data, notify);
}
+/**
+ * gst_tizen_allocator_alloc_fd: (skip)
+ * @allocator: a #GstAllocator to use
+ * @vinfo: a #GstVideoInfo to be referred for memory size and type
+ * @tsinfo: a #tbm_surface_info_s to be referred for information of TBM surface
+ * @fd: fd list to be used for allocated memory
+ * @fd_count: a count of fd in list
+ * @user_data: (allow-none): user data pointer
+ * @notify: (allow-none) (closure user_data): called with @user_data when the memory is freed
+ *
+ * Returns: (transfer full) (nullable): a new #GstMemory.
+ */
+GstMemory *
+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)
+{
+ 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);
+}
+
gboolean
gst_is_tizen_memory (GstMemory * mem)
{
return tmem->surface;
}
+gint
+gst_tizen_memory_get_num_fd (GstMemory * mem)
+{
+ GstTizenMemory *tmem;
+
+ g_return_val_if_fail (mem != NULL, -1);
+ g_return_val_if_fail (GST_IS_TIZEN_ALLOCATOR (mem->allocator), -1);
+
+ tmem = (GstTizenMemory *)mem;
+
+ GST_DEBUG ("fd count[%d] in mem[%p]", tmem->fd_count, tmem);
+
+ return tmem->fd_count;
+}
+
+gint
+gst_tizen_memory_get_fd (GstMemory * mem, gint index)
+{
+ GstTizenMemory *tmem = (GstTizenMemory *)mem;
+
+ g_return_val_if_fail (mem != NULL, -1);
+ g_return_val_if_fail (GST_IS_TIZEN_ALLOCATOR (mem->allocator), -1);
+ g_return_val_if_fail (index >= 0 && index < tmem->fd_count, -1);
+
+ GST_DEBUG ("fd[%d] %d in mem[%p]", index, tmem->fd[index], tmem);
+
+ return tmem->fd[index];
+}
+
static void
cached_tizen_disposed_cb (GstTizenAllocator * allocator, GstMiniObject *obj)
{
#define GST_TIZEN_ALLOCATOR_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_TIZEN_ALLOCATOR, GstTizenAllocatorClass))
#define GST_TIZEN_ALLOCATOR_CAST(obj) ((GstTizenAllocator *)(obj))
-#define GST_TIZEN_MEMORY_TYPE "TizenVideoMemory"
+#define GST_TIZEN_MEMORY_TYPE "TizenVideoMemory"
+#define GST_TIZEN_MEMORY_MAX_FD 4
struct _GstTizenMemory
{
/* for encoded format */
tbm_bo bo;
tbm_bo_handle bo_handle;
+
+ /* for fd */
+ int fd[GST_TIZEN_MEMORY_MAX_FD];
+ int fd_count;
};
struct _GstTizenAllocatorPrivate
{
GstAllocator parent;
GstTizenAllocatorPrivate *priv;
+ tbm_bufmgr bufmgr;
};
};
GST_ALLOCATORS_API
-GstAllocator * gst_tizen_allocator_new (void);
+GstAllocator * gst_tizen_allocator_new (void);
GST_ALLOCATORS_API
-GstMemory * gst_tizen_allocator_alloc (GstAllocator * allocator, GstVideoInfo * vinfo);
+GstMemory * gst_tizen_allocator_alloc (GstAllocator * allocator, GstVideoInfo * vinfo);
GST_ALLOCATORS_API
GstMemory * gst_tizen_allocator_alloc_surface (GstAllocator * allocator, GstVideoInfo * vinfo,
tbm_bo bo, gsize size, gpointer user_data, GDestroyNotify notify);
GST_ALLOCATORS_API
-gboolean gst_is_tizen_memory (GstMemory *mem);
+GstMemory * 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);
+
+GST_ALLOCATORS_API
+gboolean gst_is_tizen_memory (GstMemory * mem);
+
+GST_ALLOCATORS_API
+gint gst_tizen_memory_get_num_bos (GstMemory * mem);
+
+GST_ALLOCATORS_API
+void * gst_tizen_memory_get_bos (GstMemory * mem, gint index);
GST_ALLOCATORS_API
-gint gst_tizen_memory_get_num_bos (GstMemory *mem);
+void * gst_tizen_memory_get_surface (GstMemory * mem);
GST_ALLOCATORS_API
-void * gst_tizen_memory_get_bos (GstMemory *mem, gint index);
+gint gst_tizen_memory_get_num_fd (GstMemory * mem);
GST_ALLOCATORS_API
-void * gst_tizen_memory_get_surface (GstMemory *mem);
+gint gst_tizen_memory_get_fd (GstMemory * mem, gint index);
GST_ALLOCATORS_API
-GstMemory * gst_tizen_allocator_dmabuf_export (GstAllocator * allocator, GstMemory *tmem, int bo_idx);
+GstMemory * gst_tizen_allocator_dmabuf_export (GstAllocator * allocator, GstMemory * tmem, int bo_idx);
GST_ALLOCATORS_API
GstTizenMemory *gst_tizen_allocator_dmabuf_import (GstAllocator * allocator, gint * fds, gint planes, gsize offsets[4], GstVideoInfo * vinfo);