From 90b403ee009deb43f26c642ffcc3044ba33b49ac Mon Sep 17 00:00:00 2001 From: Jeongmo Yang Date: Thu, 4 Feb 2021 20:28:42 +0900 Subject: [PATCH] [v4l2videodecoder] Add new property to enable TBM output buffer - In previous code, TBM output buffer was enabled for v4l2src plugin, and it caused unexpected error when it's used for camera. [Version] 1.16.2-18 [Issue Type] Bug fix Change-Id: Ia84f6f9bdb03567b380f263074af44dcc56810ab Signed-off-by: Jeongmo Yang --- packaging/gst-plugins-good.spec | 2 +- sys/v4l2/gstv4l2allocator.c | 13 ++++++++----- sys/v4l2/gstv4l2bufferpool.c | 4 ++-- sys/v4l2/gstv4l2object.c | 5 ++++- sys/v4l2/gstv4l2object.h | 3 +++ sys/v4l2/gstv4l2videodec.c | 25 +++++++++++++++++++++++++ 6 files changed, 43 insertions(+), 9 deletions(-) diff --git a/packaging/gst-plugins-good.spec b/packaging/gst-plugins-good.spec index 628393d..3ecb1b6 100644 --- a/packaging/gst-plugins-good.spec +++ b/packaging/gst-plugins-good.spec @@ -3,7 +3,7 @@ Name: gst-plugins-good Version: 1.16.2 -Release: 17 +Release: 18 License: LGPL-2.1+ Summary: GStreamer Streaming-Media Framework Plug-Ins Url: http://gstreamer.freedesktop.org/ diff --git a/sys/v4l2/gstv4l2allocator.c b/sys/v4l2/gstv4l2allocator.c index 5f6f554..a06c822 100644 --- a/sys/v4l2/gstv4l2allocator.c +++ b/sys/v4l2/gstv4l2allocator.c @@ -692,7 +692,8 @@ gst_v4l2_allocator_new (GstObject * parent, GstV4l2Object * v4l2object) GST_OBJECT_FLAG_SET (allocator, flags); #ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER - if (!V4L2_TYPE_IS_OUTPUT (v4l2object->type) && + if (v4l2object->tbm_output && + !V4L2_TYPE_IS_OUTPUT (v4l2object->type) && v4l2object->mode == GST_V4L2_IO_DMABUF) { tbm_surface_h tmp_surface = NULL; int width = GST_VIDEO_INFO_WIDTH (&v4l2object->info); @@ -974,9 +975,11 @@ gst_v4l2_allocator_alloc_dmabuf (GstV4l2Allocator * allocator, group->planes[i].length - group->planes[i].data_offset, i, NULL, expbuf.fd, group); #ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER - bos[i] = tbm_bo_import_fd (allocator->bufmgr, expbuf.fd); - GST_INFO_OBJECT (allocator, "obj[%p,i:%d]: fd[%d] -> bo[%p]", - obj, expbuf.index, expbuf.fd, bos[i]); + if (obj->tbm_output) { + bos[i] = tbm_bo_import_fd (allocator->bufmgr, expbuf.fd); + GST_INFO_OBJECT (allocator, "obj[%p,i:%d]: fd[%d] -> bo[%p]", + obj, expbuf.index, expbuf.fd, bos[i]); + } #endif /* TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER */ } else { /* Take back the allocator reference */ @@ -1000,7 +1003,7 @@ gst_v4l2_allocator_alloc_dmabuf (GstV4l2Allocator * allocator, } #ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER - if (!group->surface) { + if (obj->tbm_output && !group->surface) { group->surface = tbm_surface_internal_create_with_bos (&allocator->s_info, bos, group->n_mem); GST_INFO_OBJECT (allocator, "new surface[%p] in memory group[%p]", group->surface, group); } diff --git a/sys/v4l2/gstv4l2bufferpool.c b/sys/v4l2/gstv4l2bufferpool.c index a2ad8f9..dce6daa 100644 --- a/sys/v4l2/gstv4l2bufferpool.c +++ b/sys/v4l2/gstv4l2bufferpool.c @@ -771,7 +771,7 @@ gst_v4l2_buffer_pool_streamoff (GstV4l2BufferPool * pool) return; #ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER - if (!V4L2_TYPE_IS_OUTPUT(pool->obj->type)) { + if (obj->tbm_output && !V4L2_TYPE_IS_OUTPUT(pool->obj->type)) { g_mutex_lock (&pool->buffer_lock); GST_INFO_OBJECT (pool, "live buffer[%d]", pool->live_buffer_count); @@ -2020,7 +2020,7 @@ gst_v4l2_buffer_pool_process (GstV4l2BufferPool * pool, GstBuffer ** buf) goto eos; } #ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER - if (pool->obj->mode == GST_V4L2_IO_DMABUF) { + if (pool->obj->tbm_output && pool->obj->mode == GST_V4L2_IO_DMABUF) { gst_buffer_unref (*buf); *buf = tmp; } else { diff --git a/sys/v4l2/gstv4l2object.c b/sys/v4l2/gstv4l2object.c index 9db4ae6..8cc1b93 100644 --- a/sys/v4l2/gstv4l2object.c +++ b/sys/v4l2/gstv4l2object.c @@ -831,10 +831,13 @@ gst_v4l2_get_driver_min_buffers (GstV4l2Object * v4l2object) "driver requires a minimum of %d buffers", control.value); #ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER #define DEFAULT_DECODER_OUTPUT_BUFFER_COUNT 5 - if (!V4L2_TYPE_IS_OUTPUT (v4l2object->type) && control.value == 1) { + if (v4l2object->tbm_output && + !V4L2_TYPE_IS_OUTPUT (v4l2object->type) && control.value == 1) { v4l2object->min_buffers = DEFAULT_DECODER_OUTPUT_BUFFER_COUNT; GST_WARNING_OBJECT (v4l2object->dbg_obj, "but SET MIN BUFFER COUNT[%d] and it will be [%d] later", v4l2object->min_buffers, v4l2object->min_buffers + 1); + } else { + v4l2object->min_buffers = control.value; } #else /* TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER */ v4l2object->min_buffers = control.value; diff --git a/sys/v4l2/gstv4l2object.h b/sys/v4l2/gstv4l2object.h index c12ff09..6393349 100644 --- a/sys/v4l2/gstv4l2object.h +++ b/sys/v4l2/gstv4l2object.h @@ -131,6 +131,9 @@ struct _GstV4l2Object { /* auto scan device */ gboolean auto_scan_device; #endif /* TIZEN_FEATURE_V4L2SRC_AUTO_SCAN_DEVICE_NODE */ +#ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER + gboolean tbm_output; +#endif /* TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER */ /* the video-device's file descriptor */ gint video_fd; diff --git a/sys/v4l2/gstv4l2videodec.c b/sys/v4l2/gstv4l2videodec.c index 1086958..b43a6c9 100644 --- a/sys/v4l2/gstv4l2videodec.c +++ b/sys/v4l2/gstv4l2videodec.c @@ -51,6 +51,9 @@ enum { PROP_0, V4L2_STD_OBJECT_PROPS +#ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER + , PROP_TBM_OUTPUT +#endif /* TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER */ }; #define gst_v4l2_video_dec_parent_class parent_class @@ -89,6 +92,13 @@ gst_v4l2_video_dec_set_property (GObject * object, G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } break; +#ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER + case PROP_TBM_OUTPUT: + self->v4l2capture->tbm_output = g_value_get_boolean (value); + GST_INFO_OBJECT (self, "tbm output [%d]", self->v4l2capture->tbm_output); + break; +#endif /* TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER */ + /* By default, only set on output */ default: @@ -113,6 +123,12 @@ gst_v4l2_video_dec_get_property (GObject * object, G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } break; +#ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER + case PROP_TBM_OUTPUT: + GST_INFO_OBJECT (self, "tbm output [%d]", self->v4l2capture->tbm_output); + g_value_set_boolean (value, self->v4l2capture->tbm_output); + break; +#endif /* TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER */ /* By default read from output */ default: @@ -1005,6 +1021,9 @@ gst_v4l2_video_dec_subinstance_init (GTypeInstance * instance, gpointer g_class) GST_OBJECT (GST_VIDEO_DECODER_SRC_PAD (self)), V4L2_BUF_TYPE_VIDEO_CAPTURE, klass->default_device, gst_v4l2_get_input, gst_v4l2_set_input, NULL); +#ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER + self->v4l2capture->tbm_output = TRUE; +#endif /* TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER */ } static void @@ -1057,6 +1076,12 @@ gst_v4l2_video_dec_class_init (GstV4l2VideoDecClass * klass) GST_DEBUG_FUNCPTR (gst_v4l2_video_dec_change_state); gst_v4l2_object_install_m2m_properties_helper (gobject_class); +#ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER + g_object_class_install_property (gobject_class, PROP_TBM_OUTPUT, + g_param_spec_boolean ("tbm-output", "Enable TBM for output buffer", + "It works for only DMABUF mode.", + TRUE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); +#endif /* TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER */ } static void -- 2.7.4