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