diff options
-rw-r--r-- | modules/ocl/Makefile.am | 2 | ||||
-rw-r--r-- | modules/ocl/cl_defog_dcp_handler.cpp | 16 | ||||
-rw-r--r-- | modules/ocl/cl_image_handler.cpp | 12 | ||||
-rw-r--r-- | modules/ocl/cl_image_handler.h | 6 | ||||
-rw-r--r-- | modules/ocl/cl_memory.h | 4 | ||||
-rw-r--r-- | modules/ocl/cl_newtonemapping_handler.cpp | 16 | ||||
-rw-r--r-- | modules/ocl/cl_tonemapping_handler.cpp | 16 | ||||
-rw-r--r-- | modules/ocl/cl_utils.cpp | 19 | ||||
-rw-r--r-- | modules/ocl/cl_utils.h | 1 | ||||
-rw-r--r-- | modules/ocl/cl_video_buffer.cpp | 153 | ||||
-rw-r--r-- | modules/ocl/cl_video_buffer.h | 106 |
11 files changed, 315 insertions, 36 deletions
diff --git a/modules/ocl/Makefile.am b/modules/ocl/Makefile.am index 49a2bdf..e7dba8e 100644 --- a/modules/ocl/Makefile.am +++ b/modules/ocl/Makefile.am @@ -68,6 +68,7 @@ xcam_ocl_sources = \ cl_3d_denoise_handler.cpp \ cl_image_warp_handler.cpp \ cl_video_stabilizer.cpp \ + cl_video_buffer.cpp \ priority_buffer_queue.cpp \ $(NULL) @@ -144,6 +145,7 @@ nobase_libxcam_oclinclude_HEADERS = \ cl_newwavelet_denoise_handler.h \ cl_wire_frame_handler.h \ cl_video_stabilizer.h \ + cl_video_buffer.h \ $(NULL) if HAVE_OPENCV diff --git a/modules/ocl/cl_defog_dcp_handler.cpp b/modules/ocl/cl_defog_dcp_handler.cpp index 529bd39..e6bd579 100644 --- a/modules/ocl/cl_defog_dcp_handler.cpp +++ b/modules/ocl/cl_defog_dcp_handler.cpp @@ -200,14 +200,14 @@ CLDefogRecoverKernel::get_max_value (SmartPtr<VideoBuffer> &buf) float ret = 255.0f; const float max_percent = 1.0f; - SmartPtr<DrmBoBuffer> bo_buf = buf.dynamic_cast_ptr<DrmBoBuffer> (); - XCAM_FAIL_RETURN ( - ERROR, - bo_buf.ptr (), - XCAM_RETURN_ERROR_MEM, - "get DrmBoBuffer failed"); - - SmartPtr<X3aStats> stats = bo_buf->find_3a_stats (); + SmartPtr<X3aStats> stats; + SmartPtr<CLVideoBuffer> cl_buf = buf.dynamic_cast_ptr<CLVideoBuffer> (); + if (cl_buf.ptr ()) { + stats = cl_buf->find_3a_stats (); + } else { + SmartPtr<DrmBoBuffer> bo_buf = buf.dynamic_cast_ptr<DrmBoBuffer> (); + stats = bo_buf->find_3a_stats (); + } _max_r = 230.0f; _max_g = 230.0f; diff --git a/modules/ocl/cl_image_handler.cpp b/modules/ocl/cl_image_handler.cpp index 0e04b8b..573a202 100644 --- a/modules/ocl/cl_image_handler.cpp +++ b/modules/ocl/cl_image_handler.cpp @@ -153,20 +153,20 @@ CLImageHandler::is_handler_enabled () const XCamReturn CLImageHandler::create_buffer_pool (const VideoBufferInfo &video_info) { - SmartPtr<DrmBoBufferPool> buffer_pool; - SmartPtr<DrmDisplay> display; - if (_buf_pool.ptr ()) return XCAM_RETURN_ERROR_PARAM; - display = DrmDisplay::instance (); + SmartPtr<DrmDisplay> display = DrmDisplay::instance (); XCAM_FAIL_RETURN( WARNING, display.ptr (), XCAM_RETURN_ERROR_CL, "CLImageHandler(%s) failed to get drm dispay", XCAM_STR (_name)); - if (_buf_pool_type == CLImageHandler::DrmBoPoolType) + SmartPtr<BufferPool> buffer_pool; + if (_buf_pool_type == CLImageHandler::CLVideoPoolType) + buffer_pool = new CLVideoBufferPool (); + else if (_buf_pool_type == CLImageHandler::DrmBoPoolType) buffer_pool = new DrmBoBufferPool (display); else if (_buf_pool_type == CLImageHandler::CLBoPoolType) { buffer_pool = new CLBoBufferPool (display, get_context ()); @@ -180,7 +180,7 @@ CLImageHandler::create_buffer_pool (const VideoBufferInfo &video_info) XCAM_STR (_name), (int32_t)_buf_pool_type); XCAM_ASSERT (buffer_pool.ptr ()); - buffer_pool->set_swap_flags (_buf_swap_flags, _buf_swap_init_order); + // buffer_pool->set_swap_flags (_buf_swap_flags, _buf_swap_init_order); buffer_pool->set_video_info (video_info); XCAM_FAIL_RETURN( diff --git a/modules/ocl/cl_image_handler.h b/modules/ocl/cl_image_handler.h index 434ded0..6432a8c 100644 --- a/modules/ocl/cl_image_handler.h +++ b/modules/ocl/cl_image_handler.h @@ -26,6 +26,7 @@ #include "ocl/cl_kernel.h" #include "ocl/cl_argument.h" #include "ocl/cl_memory.h" +#include "ocl/cl_video_buffer.h" #include "x3a_result.h" namespace XCam { @@ -70,8 +71,9 @@ class CLImageHandler public: typedef std::list<SmartPtr<CLImageKernel>> KernelList; enum BufferPoolType { - CLBoPoolType = 0x0001, - DrmBoPoolType = 0x0002, + CLVideoPoolType = 0x0000, + CLBoPoolType = 0x0001, + DrmBoPoolType = 0x0002 }; public: diff --git a/modules/ocl/cl_memory.h b/modules/ocl/cl_memory.h index 8e670cb..9c6c96d 100644 --- a/modules/ocl/cl_memory.h +++ b/modules/ocl/cl_memory.h @@ -116,6 +116,10 @@ public: CLEventList &event_waits = CLEvent::EmptyList, SmartPtr<CLEvent> &event_out = CLEvent::NullEvent); + uint32_t get_buf_size () { + return _size; + } + private: bool init_buffer ( const SmartPtr<CLContext> &context, uint32_t size, diff --git a/modules/ocl/cl_newtonemapping_handler.cpp b/modules/ocl/cl_newtonemapping_handler.cpp index ea87094..378a1ce 100644 --- a/modules/ocl/cl_newtonemapping_handler.cpp +++ b/modules/ocl/cl_newtonemapping_handler.cpp @@ -278,14 +278,14 @@ CLNewTonemappingImageHandler::prepare_parameters ( XCAM_RETURN_ERROR_MEM, "cl image handler(%s) in/out memory not available", XCAM_STR (get_name ())); - SmartPtr<DrmBoBuffer> bo_buf = input.dynamic_cast_ptr<DrmBoBuffer> (); - XCAM_FAIL_RETURN ( - ERROR, - bo_buf.ptr (), - XCAM_RETURN_ERROR_MEM, - "get DrmBoBuffer failed"); - - SmartPtr<X3aStats> stats = bo_buf->find_3a_stats (); + SmartPtr<X3aStats> stats; + SmartPtr<CLVideoBuffer> cl_buf = input.dynamic_cast_ptr<CLVideoBuffer> (); + if (cl_buf.ptr ()) { + stats = cl_buf->find_3a_stats (); + } else { + SmartPtr<DrmBoBuffer> bo_buf = input.dynamic_cast_ptr<DrmBoBuffer> (); + stats = bo_buf->find_3a_stats (); + } XCAM_FAIL_RETURN ( ERROR, stats.ptr (), XCAM_RETURN_ERROR_MEM, "new tonemapping handler prepare_arguments find_3a_stats failed"); diff --git a/modules/ocl/cl_tonemapping_handler.cpp b/modules/ocl/cl_tonemapping_handler.cpp index 8fff7e7..2835854 100644 --- a/modules/ocl/cl_tonemapping_handler.cpp +++ b/modules/ocl/cl_tonemapping_handler.cpp @@ -114,14 +114,14 @@ CLTonemappingImageHandler::prepare_parameters ( XCAM_RETURN_ERROR_MEM, "cl image handler(%s) in/out memory not available", XCAM_STR(get_name ())); - SmartPtr<DrmBoBuffer> bo_buf = input.dynamic_cast_ptr<DrmBoBuffer> (); - XCAM_FAIL_RETURN ( - ERROR, - bo_buf.ptr (), - XCAM_RETURN_ERROR_MEM, - "get DrmBoBuffer failed"); - - SmartPtr<X3aStats> stats = bo_buf->find_3a_stats (); + SmartPtr<X3aStats> stats; + SmartPtr<CLVideoBuffer> cl_buf = input.dynamic_cast_ptr<CLVideoBuffer> (); + if (cl_buf.ptr ()) { + stats = cl_buf->find_3a_stats (); + } else { + SmartPtr<DrmBoBuffer> bo_buf = input.dynamic_cast_ptr<DrmBoBuffer> (); + stats = bo_buf->find_3a_stats (); + } XCAM_FAIL_RETURN ( ERROR, stats.ptr (), diff --git a/modules/ocl/cl_utils.cpp b/modules/ocl/cl_utils.cpp index 9583989..e2a927b 100644 --- a/modules/ocl/cl_utils.cpp +++ b/modules/ocl/cl_utils.cpp @@ -61,8 +61,13 @@ convert_to_clbuffer ( { SmartPtr<CLBuffer> cl_buf; - SmartPtr<DrmBoBuffer> bo_buf = buf.dynamic_cast_ptr<DrmBoBuffer> (); - cl_buf = new CLVaBuffer (context, bo_buf); + SmartPtr<CLVideoBuffer> cl_video_buf = buf.dynamic_cast_ptr<CLVideoBuffer> (); + if (cl_video_buf.ptr ()) { + cl_buf = cl_video_buf->get_cl_buffer (); + } else { + SmartPtr<DrmBoBuffer> bo_buf = buf.dynamic_cast_ptr<DrmBoBuffer> (); + cl_buf = new CLVaBuffer (context, bo_buf); + } XCAM_FAIL_RETURN (WARNING, cl_buf.ptr (), NULL, "convert to clbuffer failed"); return cl_buf; @@ -78,8 +83,14 @@ convert_to_climage ( { SmartPtr<CLImage> cl_image; - SmartPtr<DrmBoBuffer> bo_buf = buf.dynamic_cast_ptr<DrmBoBuffer> (); - cl_image = new CLVaImage (context, bo_buf, desc, offset); + SmartPtr<CLVideoBuffer> cl_video_buf = buf.dynamic_cast_ptr<CLVideoBuffer> (); + if (cl_video_buf.ptr ()) { + SmartPtr<CLBuffer> cl_buf = cl_video_buf->get_cl_buffer (); + cl_image = new CLImage2D (context, desc, flags, cl_buf); + } else { + SmartPtr<DrmBoBuffer> bo_buf = buf.dynamic_cast_ptr<DrmBoBuffer> (); + cl_image = new CLVaImage (context, bo_buf, desc, offset); + } XCAM_FAIL_RETURN (WARNING, cl_image.ptr (), NULL, "convert to climage failed"); return cl_image; diff --git a/modules/ocl/cl_utils.h b/modules/ocl/cl_utils.h index af5d8b4..d4f9f0d 100644 --- a/modules/ocl/cl_utils.h +++ b/modules/ocl/cl_utils.h @@ -24,6 +24,7 @@ #include "xcam_utils.h" #include "ocl/cl_context.h" #include "ocl/cl_memory.h" +#include "ocl/cl_video_buffer.h" namespace XCam { diff --git a/modules/ocl/cl_video_buffer.cpp b/modules/ocl/cl_video_buffer.cpp new file mode 100644 index 0000000..5dc55a6 --- /dev/null +++ b/modules/ocl/cl_video_buffer.cpp @@ -0,0 +1,153 @@ +/* + * cl_video_buffer.cpp - cl video buffer + * + * Copyright (c) 2017 Intel Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Author: Yinhang Liu <yinhangx.liu@intel.com> + * Author: Wind Yuan <feng.yuan@intel.com> + */ + +#include "ocl/cl_memory.h" +#include "ocl/cl_device.h" +#include "ocl/cl_video_buffer.h" + +namespace XCam { + +CLVideoBufferData::CLVideoBufferData (SmartPtr<CLBuffer> &body) + : _buf_ptr (NULL) + , _buf (body) +{ + XCAM_ASSERT (body.ptr ()); +} + +CLVideoBufferData::~CLVideoBufferData () +{ + unmap (); + _buf.release (); +} + +cl_mem & +CLVideoBufferData::get_mem_id () { + return _buf->get_mem_id (); +} + +uint8_t * +CLVideoBufferData::map () +{ + if (_buf_ptr) + return _buf_ptr; + + uint32_t size = _buf->get_buf_size (); + XCamReturn ret = _buf->enqueue_map ((void*&) _buf_ptr, 0, size); + XCAM_FAIL_RETURN ( + ERROR, + ret == XCAM_RETURN_NO_ERROR, + NULL, + "CLVideoBufferData map data failed"); + + return _buf_ptr; +} + +bool +CLVideoBufferData::unmap () +{ + if (!_buf_ptr) + return true; + + XCamReturn ret = _buf->enqueue_unmap ((void*&) _buf_ptr); + XCAM_FAIL_RETURN ( + ERROR, + ret == XCAM_RETURN_NO_ERROR, + NULL, + "CLVideoBufferData unmap data failed"); + + _buf_ptr = NULL; + return true; +} + +CLVideoBuffer::CLVideoBuffer ( + const VideoBufferInfo &info, const SmartPtr<CLVideoBufferData> &data) + : BufferProxy (info, data) +{ + XCAM_ASSERT (data.ptr ()); +} + +cl_mem & +CLVideoBuffer::get_mem_id () +{ + SmartPtr<BufferData> data = get_buffer_data (); + SmartPtr<CLVideoBufferData> cl_data = data.dynamic_cast_ptr<CLVideoBufferData> (); + XCAM_ASSERT (cl_data.ptr ()); + + return cl_data->get_mem_id (); +} + +SmartPtr<CLBuffer> +CLVideoBuffer::get_cl_buffer () +{ + SmartPtr<BufferData> data = get_buffer_data (); + SmartPtr<CLVideoBufferData> cl_data = data.dynamic_cast_ptr<CLVideoBufferData> (); + XCAM_FAIL_RETURN( + WARNING, + cl_data.ptr(), + NULL, + "CLVideoBuffer get buffer data failed with NULL"); + + return cl_data->get_cl_buffer (); +} + +SmartPtr<X3aStats> +CLVideoBuffer::find_3a_stats () +{ + return find_typed_attach<X3aStats> (); +} + +bool +CLVideoBufferPool::fixate_video_info (VideoBufferInfo &info) +{ + if (info.format != V4L2_PIX_FMT_NV12) + return true; + + VideoBufferInfo out_info; + out_info.init (info.format, info.width, info.height, info.aligned_width, info.aligned_height); + + return true; +} + +SmartPtr<BufferData> +CLVideoBufferPool::allocate_data (const VideoBufferInfo &buffer_info) +{ + SmartPtr<CLContext> context = CLDevice::instance ()->get_context (); + + SmartPtr<CLBuffer> buf = new CLBuffer (context, buffer_info.size); + XCAM_ASSERT (buf.ptr ()); + + return new CLVideoBufferData (buf); +} + +SmartPtr<BufferProxy> +CLVideoBufferPool::create_buffer_from_data (SmartPtr<BufferData> &data) +{ + const VideoBufferInfo & info = get_video_info (); + SmartPtr<CLVideoBufferData> cl_data = data.dynamic_cast_ptr<CLVideoBufferData> (); + XCAM_ASSERT (cl_data.ptr ()); + + SmartPtr<CLVideoBuffer> buf = new CLVideoBuffer (info, cl_data); + XCAM_ASSERT (buf.ptr ()); + + return buf; +} + +}; diff --git a/modules/ocl/cl_video_buffer.h b/modules/ocl/cl_video_buffer.h new file mode 100644 index 0000000..4d8c927 --- /dev/null +++ b/modules/ocl/cl_video_buffer.h @@ -0,0 +1,106 @@ +/* + * cl_video_buffer.h - cl video buffer + * + * Copyright (c) 2017 Intel Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Author: Yinhang Liu <yinhangx.liu@intel.com> + * Author: Wind Yuan <feng.yuan@intel.com> + */ +#ifndef XCAM_CL_VIDEO_BUFFER_H +#define XCAM_CL_VIDEO_BUFFER_H + +#include "xcam_utils.h" +#include "smartptr.h" +#include "safe_list.h" +#include "xcam_mutex.h" +#include "buffer_pool.h" +#include "x3a_stats_pool.h" +#include "ocl/cl_context.h" + +namespace XCam { + +class CLBuffer; +class CLVideoBufferPool; + +class CLVideoBufferData + : public BufferData +{ + friend class CLVideoBufferPool; + +public: + ~CLVideoBufferData (); + + cl_mem &get_mem_id (); + SmartPtr<CLBuffer> get_cl_buffer () { + return _buf; + } + + //derived from BufferData + virtual uint8_t *map (); + virtual bool unmap (); + +protected: + explicit CLVideoBufferData (SmartPtr<CLBuffer> &body); + +private: + XCAM_DEAD_COPY (CLVideoBufferData); + +private: + uint8_t *_buf_ptr; + SmartPtr<CLBuffer> _buf; +}; + +class CLVideoBuffer + : public BufferProxy +{ + friend class CLVideoBufferPool; + +public: + virtual ~CLVideoBuffer () {} + + cl_mem &get_mem_id (); + SmartPtr<CLBuffer> get_cl_buffer (); + + SmartPtr<X3aStats> find_3a_stats (); + +protected: + CLVideoBuffer (const VideoBufferInfo &info, const SmartPtr<CLVideoBufferData> &data); + +private: + XCAM_DEAD_COPY (CLVideoBuffer); +}; + +class CLVideoBufferPool + : public BufferPool +{ + friend class CLVideoBuffer; + +public: + explicit CLVideoBufferPool () {} + ~CLVideoBufferPool () {} + +protected: + // derived from BufferPool + virtual bool fixate_video_info (VideoBufferInfo &info); + virtual SmartPtr<BufferData> allocate_data (const VideoBufferInfo &buffer_info); + virtual SmartPtr<BufferProxy> create_buffer_from_data (SmartPtr<BufferData> &data); + +private: + XCAM_DEAD_COPY (CLVideoBufferPool); +}; + +}; + +#endif // XCAM_CL_VIDEO_BUFFER_H |