#include "config.h"
#endif
+#include <unistd.h>
#include "string.h"
#include "gstdmabuf.h"
#include "gsttizenmemory.h"
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");
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));
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"]",
_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;
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,
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);
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;
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);
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) {