v4l2videodec: Add ref/unref code to avoid crash
[platform/upstream/gst-plugins-good.git] / sys / v4l2 / gstv4l2bufferpool.c
index dce6daa..494b5b8 100644 (file)
@@ -45,9 +45,9 @@
 #include "gstv4l2object.h"
 #include "gst/gst-i18n-plugin.h"
 #include <gst/glib-compat-private.h>
-#ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER
+#ifdef TIZEN_FEATURE_V4L2_TBM_SUPPORT
 #include <gst/allocators/gsttizenmemory.h>
-#endif /* TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER */
+#endif /* TIZEN_FEATURE_V4L2_TBM_SUPPORT */
 
 GST_DEBUG_CATEGORY_STATIC (v4l2bufferpool_debug);
 GST_DEBUG_CATEGORY_STATIC (CAT_PERFORMANCE);
@@ -70,7 +70,7 @@ enum _GstV4l2BufferPoolAcquireFlags
 
 static void gst_v4l2_buffer_pool_release_buffer (GstBufferPool * bpool,
     GstBuffer * buffer);
-#ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER
+#ifdef TIZEN_FEATURE_V4L2_TBM_SUPPORT
 typedef struct _GstV4l2TizenBuffer GstV4l2TizenBuffer;
 struct _GstV4l2TizenBuffer {
   int index;
@@ -104,6 +104,8 @@ static void gst_v4l2_tizen_buffer_finalize (GstV4l2TizenBuffer *tizen_buffer)
 
   g_mutex_unlock (&pool->buffer_lock);
 
+  gst_object_unref (pool);
+
   g_free(tizen_buffer);
 }
 
@@ -116,7 +118,7 @@ static GstV4l2TizenBuffer *gst_v4l2_tizen_buffer_new (GstBuffer *v4l2_buffer, in
   tizen_buffer->index = index;
   tizen_buffer->v4l2_buffer = v4l2_buffer;
   tizen_buffer->gst_buffer = gst_buffer_new ();
-  tizen_buffer->v4l2_pool = v4l2_pool;
+  tizen_buffer->v4l2_pool = gst_object_ref (v4l2_pool);
 
   memory = gst_tizen_allocator_alloc_surface (v4l2_pool->tallocator,
       &v4l2_pool->obj->info, v4l2_pool->vallocator->groups[index]->surface, (gpointer)tizen_buffer,
@@ -137,7 +139,7 @@ static GstV4l2TizenBuffer *gst_v4l2_tizen_buffer_new (GstBuffer *v4l2_buffer, in
 
   return tizen_buffer;
 }
-#endif /* TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER */
+#endif /* TIZEN_FEATURE_V4L2_TBM_SUPPORT */
 
 static gboolean
 gst_v4l2_is_buffer_valid (GstBuffer * buffer, GstV4l2MemoryGroup ** out_group)
@@ -763,14 +765,14 @@ gst_v4l2_buffer_pool_streamoff (GstV4l2BufferPool * pool)
   GstBufferPoolClass *pclass = GST_BUFFER_POOL_CLASS (parent_class);
   GstV4l2Object *obj = pool->obj;
   gint i;
-#ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER
+#ifdef TIZEN_FEATURE_V4L2_TBM_SUPPORT
   gint64 end_time = 0;
-#endif /* TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER */
+#endif /* TIZEN_FEATURE_V4L2_TBM_SUPPORT */
 
   if (!pool->streaming)
     return;
 
-#ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER
+#ifdef TIZEN_FEATURE_V4L2_TBM_SUPPORT
   if (obj->tbm_output && !V4L2_TYPE_IS_OUTPUT(pool->obj->type)) {
     g_mutex_lock (&pool->buffer_lock);
 
@@ -794,7 +796,7 @@ gst_v4l2_buffer_pool_streamoff (GstV4l2BufferPool * pool)
 
     g_mutex_unlock (&pool->buffer_lock);
   }
-#endif /* TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER */
+#endif /* TIZEN_FEATURE_V4L2_TBM_SUPPORT */
   switch (obj->mode) {
     case GST_V4L2_IO_MMAP:
     case GST_V4L2_IO_USERPTR:
@@ -1318,9 +1320,9 @@ gst_v4l2_buffer_pool_dqbuf (GstV4l2BufferPool * pool, GstBuffer ** buffer,
   GstVideoMeta *vmeta;
   gsize size;
   gint i;
-#ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER
+#ifdef TIZEN_FEATURE_V4L2_TBM_SUPPORT
   GstV4l2TizenBuffer *tizen_buffer = NULL;
-#endif /* TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER */
+#endif /* TIZEN_FEATURE_V4L2_TBM_SUPPORT */
 
   if ((res = gst_v4l2_buffer_pool_poll (pool, wait)) < GST_FLOW_OK)
     goto poll_failed;
@@ -1453,7 +1455,7 @@ gst_v4l2_buffer_pool_dqbuf (GstV4l2BufferPool * pool, GstBuffer ** buffer,
   GST_BUFFER_OFFSET (outbuf) = group->buffer.sequence;
   GST_BUFFER_OFFSET_END (outbuf) = group->buffer.sequence + 1;
 
-#ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER
+#ifdef TIZEN_FEATURE_V4L2_TBM_SUPPORT
   if (group->surface) {
     tizen_buffer = gst_v4l2_tizen_buffer_new (outbuf, group->buffer.index, pool);
     if (!tizen_buffer) {
@@ -1462,7 +1464,7 @@ gst_v4l2_buffer_pool_dqbuf (GstV4l2BufferPool * pool, GstBuffer ** buffer,
     }
     outbuf = tizen_buffer->gst_buffer;
   }
-#endif /* TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER */
+#endif /* TIZEN_FEATURE_V4L2_TBM_SUPPORT */
 done:
   *buffer = outbuf;
 
@@ -1701,14 +1703,14 @@ gst_v4l2_buffer_pool_dispose (GObject * object)
     gst_object_unref (pool->allocator);
   pool->allocator = NULL;
 
-#ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER
+#ifdef TIZEN_FEATURE_V4L2_TBM_SUPPORT
   g_cond_clear (&pool->buffer_cond);
   g_mutex_clear (&pool->buffer_lock);
 
   if (pool->tallocator)
     gst_object_unref (pool->tallocator);
   pool->tallocator = NULL;
-#endif /* TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER */
+#endif /* TIZEN_FEATURE_V4L2_TBM_SUPPORT */
   if (pool->other_pool)
     gst_object_unref (pool->other_pool);
   pool->other_pool = NULL;
@@ -1814,14 +1816,14 @@ gst_v4l2_buffer_pool_new (GstV4l2Object * obj, GstCaps * caps)
   pool->obj = obj;
   pool->can_poll_device = TRUE;
 
-#ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER
+#ifdef TIZEN_FEATURE_V4L2_TBM_SUPPORT
   pool->tallocator = gst_tizen_allocator_new ();
   if (pool->tallocator == NULL)
     goto allocator_failed;
 
   g_mutex_init (&pool->buffer_lock);
   g_cond_init (&pool->buffer_cond);
-#endif /* TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER */
+#endif /* TIZEN_FEATURE_V4L2_TBM_SUPPORT */
   pool->vallocator = gst_v4l2_allocator_new (GST_OBJECT (pool), obj);
   if (pool->vallocator == NULL)
     goto allocator_failed;
@@ -1844,12 +1846,12 @@ dup_failed:
   }
 allocator_failed:
   {
-#ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER
+#ifdef TIZEN_FEATURE_V4L2_TBM_SUPPORT
     if (pool->tallocator) {
       gst_object_unref (pool->tallocator);
       pool->tallocator = NULL;
     }
-#endif /* TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER */
+#endif /* TIZEN_FEATURE_V4L2_TBM_SUPPORT */
     GST_ERROR_OBJECT (pool, "Failed to create V4L2 allocator");
     gst_object_unref (pool);
     return NULL;
@@ -2019,19 +2021,19 @@ gst_v4l2_buffer_pool_process (GstV4l2BufferPool * pool, GstBuffer ** buf)
             if (GST_V4L2_IS_M2M (obj->device_caps))
               goto eos;
           }
-#ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER
+#ifdef TIZEN_FEATURE_V4L2_TBM_SUPPORT
           if (pool->obj->tbm_output && pool->obj->mode == GST_V4L2_IO_DMABUF) {
             gst_buffer_unref (*buf);
             *buf = tmp;
           } else {
-#endif /* TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER */
+#endif /* TIZEN_FEATURE_V4L2_TBM_SUPPORT */
           ret = gst_v4l2_buffer_pool_copy_buffer (pool, *buf, tmp);
 
           /* an queue the buffer again after the copy */
           gst_v4l2_buffer_pool_release_buffer (bpool, tmp);
-#ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER
+#ifdef TIZEN_FEATURE_V4L2_TBM_SUPPORT
           }
-#endif /* TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER */
+#endif /* TIZEN_FEATURE_V4L2_TBM_SUPPORT */
 
           if (ret != GST_FLOW_OK)
             goto copy_failed;