Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 1 | /* |
| 2 | * main.cpp - test |
| 3 | * |
| 4 | * Copyright (c) 2014 Intel Corporation |
| 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | * |
| 18 | * Author: Wind Yuan <feng.yuan@intel.com> |
Wind Yuan | 136aa4f | 2016-09-08 02:56:31 -0400 | [diff] [blame] | 19 | * Author: Yinhang Liu <yinhangx.liu@intel.com> |
| 20 | * Author: Wei Zong <wei.zong@intel.com> |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | #include "device_manager.h" |
Sameer Kibey | 7b42929 | 2015-08-07 10:55:38 -0700 | [diff] [blame] | 24 | #include "uvc_device.h" |
Jia Meng | 0a53293 | 2015-10-15 08:44:09 -0400 | [diff] [blame] | 25 | #include "fake_v4l2_device.h" |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 26 | #include "x3a_analyzer_simple.h" |
Yinhang Liu | e37a872 | 2016-06-27 18:14:35 +0800 | [diff] [blame] | 27 | #include "analyzer_loader.h" |
Yinhang Liu | 4afa364 | 2016-05-13 19:13:07 +0800 | [diff] [blame] | 28 | #include "smart_analyzer_loader.h" |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 29 | #if HAVE_IA_AIQ |
Yinhang Liu | 7110f89 | 2017-06-30 13:11:10 +0800 | [diff] [blame] | 30 | #include "isp/atomisp_device.h" |
| 31 | #include "isp/isp_controller.h" |
| 32 | #include "isp/isp_image_processor.h" |
| 33 | #include "isp/isp_poll_thread.h" |
| 34 | #include "isp/x3a_analyzer_aiq.h" |
Yinhang Liu | 6c36735 | 2016-03-31 20:23:22 +0800 | [diff] [blame] | 35 | #include "x3a_analyze_tuner.h" |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 36 | #include "dynamic_analyzer_loader.h" |
Yinhang Liu | 7110f89 | 2017-06-30 13:11:10 +0800 | [diff] [blame] | 37 | #include "isp/hybrid_analyzer_loader.h" |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 38 | #endif |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 39 | #if HAVE_LIBCL |
Yinhang Liu | 7110f89 | 2017-06-30 13:11:10 +0800 | [diff] [blame] | 40 | #include "ocl/cl_3a_image_processor.h" |
| 41 | #include "ocl/cl_post_image_processor.h" |
| 42 | #include "ocl/cl_csc_image_processor.h" |
| 43 | #include "ocl/cl_tnr_handler.h" |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 44 | #endif |
| 45 | #if HAVE_LIBDRM |
| 46 | #include "drm_display.h" |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 47 | #endif |
Jia Meng | 0a53293 | 2015-10-15 08:44:09 -0400 | [diff] [blame] | 48 | #include "fake_poll_thread.h" |
Wind Yuan | 136aa4f | 2016-09-08 02:56:31 -0400 | [diff] [blame] | 49 | #include "image_file_handle.h" |
Jia Meng | 66efecf | 2015-06-17 11:11:10 +0000 | [diff] [blame] | 50 | #include <base/xcam_3a_types.h> |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 51 | #include <unistd.h> |
| 52 | #include <signal.h> |
| 53 | #include <stdlib.h> |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 54 | #include <string> |
Yinhang Liu | 81c44e0 | 2015-06-03 15:47:48 +0800 | [diff] [blame] | 55 | #include <getopt.h> |
John Ye | ae9da73 | 2015-01-22 13:36:36 +0800 | [diff] [blame] | 56 | #include "test_common.h" |
| 57 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 58 | using namespace XCam; |
| 59 | |
wujunkai166 | 82950fb | 2015-10-19 18:09:05 +0800 | [diff] [blame] | 60 | #define IMX185_WDR_CPF "/etc/atomisp/imx185_wdr.cpf" |
| 61 | |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 62 | static Mutex g_mutex; |
| 63 | static Cond g_cond; |
| 64 | static bool g_stop = false; |
| 65 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 66 | class MainDeviceManager |
| 67 | : public DeviceManager |
| 68 | { |
| 69 | public: |
| 70 | MainDeviceManager () |
Wind Yuan | 136aa4f | 2016-09-08 02:56:31 -0400 | [diff] [blame] | 71 | : _save_file (false) |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 72 | , _interval (1) |
Yinhang Liu | d934649 | 2015-12-17 11:14:25 +0800 | [diff] [blame] | 73 | , _frame_width (0) |
| 74 | , _frame_height (0) |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 75 | , _frame_count (0) |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 76 | , _frame_save (0) |
Wind Yuan | 683f866 | 2015-03-27 18:52:38 +0800 | [diff] [blame] | 77 | , _enable_display (false) |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 78 | { |
| 79 | #if HAVE_LIBDRM |
Yinhang Liu | 5855e6f | 2016-11-14 21:04:22 +0800 | [diff] [blame] | 80 | _display = DrmDisplay::instance (); |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 81 | #endif |
Wind Yuan | 9162580 | 2015-06-24 15:36:01 +0800 | [diff] [blame] | 82 | XCAM_OBJ_PROFILING_INIT; |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 83 | } |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 84 | |
| 85 | ~MainDeviceManager () { |
Wind Yuan | 136aa4f | 2016-09-08 02:56:31 -0400 | [diff] [blame] | 86 | _file_handle.close (); |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | void enable_save_file (bool enable) { |
| 90 | _save_file = enable; |
| 91 | } |
Yinhang Liu | d934649 | 2015-12-17 11:14:25 +0800 | [diff] [blame] | 92 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 93 | void set_interval (uint32_t inteval) { |
| 94 | _interval = inteval; |
| 95 | } |
Yinhang Liu | d934649 | 2015-12-17 11:14:25 +0800 | [diff] [blame] | 96 | |
| 97 | void set_frame_width (uint32_t frame_width) { |
| 98 | _frame_width = frame_width; |
| 99 | } |
| 100 | |
| 101 | void set_frame_height (uint32_t frame_height) { |
| 102 | _frame_height = frame_height; |
| 103 | } |
| 104 | |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 105 | void set_frame_save (uint32_t frame_save) { |
| 106 | _frame_save = frame_save; |
| 107 | } |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 108 | |
Wind Yuan | 683f866 | 2015-03-27 18:52:38 +0800 | [diff] [blame] | 109 | void enable_display(bool value) { |
| 110 | _enable_display = value; |
| 111 | } |
| 112 | |
Yinhang Liu | 6987f2b | 2017-09-30 10:39:58 +0800 | [diff] [blame] | 113 | #if HAVE_LIBDRM |
wangfei | cf4c4e7 | 2015-05-25 17:11:41 +0800 | [diff] [blame] | 114 | void set_display_mode(DrmDisplayMode mode) { |
| 115 | _display->set_display_mode (mode); |
| 116 | } |
Yinhang Liu | 6987f2b | 2017-09-30 10:39:58 +0800 | [diff] [blame] | 117 | #endif |
wangfei | cf4c4e7 | 2015-05-25 17:11:41 +0800 | [diff] [blame] | 118 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 119 | protected: |
Wind Yuan | 73af393 | 2015-07-02 17:52:43 +0800 | [diff] [blame] | 120 | virtual void handle_message (const SmartPtr<XCamMessage> &msg); |
| 121 | virtual void handle_buffer (const SmartPtr<VideoBuffer> &buf); |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 122 | |
Wind Yuan | 73af393 | 2015-07-02 17:52:43 +0800 | [diff] [blame] | 123 | int display_buf (const SmartPtr<VideoBuffer> &buf); |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 124 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 125 | private: |
| 126 | void open_file (); |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 127 | |
Wind Yuan | 136aa4f | 2016-09-08 02:56:31 -0400 | [diff] [blame] | 128 | private: |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 129 | bool _save_file; |
| 130 | uint32_t _interval; |
Yinhang Liu | d934649 | 2015-12-17 11:14:25 +0800 | [diff] [blame] | 131 | uint32_t _frame_width; |
| 132 | uint32_t _frame_height; |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 133 | uint32_t _frame_count; |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 134 | uint32_t _frame_save; |
Yinhang Liu | 5855e6f | 2016-11-14 21:04:22 +0800 | [diff] [blame] | 135 | bool _enable_display; |
Wind Yuan | 136aa4f | 2016-09-08 02:56:31 -0400 | [diff] [blame] | 136 | ImageFileHandle _file_handle; |
Yinhang Liu | 6987f2b | 2017-09-30 10:39:58 +0800 | [diff] [blame] | 137 | #if HAVE_LIBDRM |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 138 | SmartPtr<DrmDisplay> _display; |
Yinhang Liu | 6987f2b | 2017-09-30 10:39:58 +0800 | [diff] [blame] | 139 | #endif |
Wind Yuan | 9162580 | 2015-06-24 15:36:01 +0800 | [diff] [blame] | 140 | XCAM_OBJ_PROFILING_DEFINES; |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 141 | }; |
| 142 | |
| 143 | void |
Wind Yuan | 73af393 | 2015-07-02 17:52:43 +0800 | [diff] [blame] | 144 | MainDeviceManager::handle_message (const SmartPtr<XCamMessage> &msg) |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 145 | { |
| 146 | XCAM_UNUSED (msg); |
| 147 | } |
| 148 | |
| 149 | void |
Wind Yuan | 73af393 | 2015-07-02 17:52:43 +0800 | [diff] [blame] | 150 | MainDeviceManager::handle_buffer (const SmartPtr<VideoBuffer> &buf) |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 151 | { |
Wind Yuan | 6d144ce | 2017-08-16 18:29:29 +0800 | [diff] [blame] | 152 | if (!buf.ptr ()) { |
| 153 | XCAM_LOG_WARNING ("video buffer is null, handle buffer failed."); |
| 154 | return; |
| 155 | } |
| 156 | |
Wind Yuan | 683f866 | 2015-03-27 18:52:38 +0800 | [diff] [blame] | 157 | FPS_CALCULATION (fps_buf, 30); |
Wind Yuan | 9162580 | 2015-06-24 15:36:01 +0800 | [diff] [blame] | 158 | XCAM_OBJ_PROFILING_START; |
| 159 | |
Wind Yuan | 683f866 | 2015-03-27 18:52:38 +0800 | [diff] [blame] | 160 | if (_enable_display) |
| 161 | display_buf (buf); |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 162 | |
Yinhang Liu | 070c759 | 2017-04-13 19:22:17 +0800 | [diff] [blame] | 163 | XCAM_OBJ_PROFILING_END("main_dev_manager_display", XCAM_OBJ_DUR_FRAME_NUM); |
Wind Yuan | 9162580 | 2015-06-24 15:36:01 +0800 | [diff] [blame] | 164 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 165 | if (!_save_file) |
| 166 | return ; |
| 167 | |
| 168 | if ((_frame_count++ % _interval) != 0) |
| 169 | return; |
| 170 | |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 171 | if ((_frame_save != 0) && (_frame_count > _frame_save)) { |
| 172 | SmartLock locker (g_mutex); |
| 173 | g_stop = true; |
| 174 | g_cond.broadcast (); |
| 175 | return; |
| 176 | } |
| 177 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 178 | open_file (); |
Jia Meng | 6c9241d | 2015-06-12 11:08:45 +0000 | [diff] [blame] | 179 | |
Wind Yuan | 136aa4f | 2016-09-08 02:56:31 -0400 | [diff] [blame] | 180 | if (!_file_handle.is_valid ()) { |
Jia Meng | 6c9241d | 2015-06-12 11:08:45 +0000 | [diff] [blame] | 181 | XCAM_LOG_ERROR ("open file failed"); |
Jia Meng | 54a2dcb | 2015-08-20 15:23:47 +0800 | [diff] [blame] | 182 | return; |
Jia Meng | 6c9241d | 2015-06-12 11:08:45 +0000 | [diff] [blame] | 183 | } |
Wind Yuan | 6d144ce | 2017-08-16 18:29:29 +0800 | [diff] [blame] | 184 | _file_handle.write_buf (buf); |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 185 | } |
| 186 | |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 187 | int |
Wind Yuan | 73af393 | 2015-07-02 17:52:43 +0800 | [diff] [blame] | 188 | MainDeviceManager::display_buf (const SmartPtr<VideoBuffer> &data) |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 189 | { |
| 190 | #if HAVE_LIBDRM |
| 191 | XCamReturn ret = XCAM_RETURN_NO_ERROR; |
Wind Yuan | 73af393 | 2015-07-02 17:52:43 +0800 | [diff] [blame] | 192 | SmartPtr<VideoBuffer> buf = data; |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 193 | const VideoBufferInfo & frame_info = buf->get_video_info (); |
Yinhang Liu | aadb8ba | 2016-11-18 18:43:29 +0800 | [diff] [blame] | 194 | struct v4l2_rect rect = { 0, 0, frame_info.width, frame_info.height}; |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 195 | |
| 196 | if (!_display->is_render_inited ()) { |
Yinhang Liu | d934649 | 2015-12-17 11:14:25 +0800 | [diff] [blame] | 197 | ret = _display->render_init (0, 0, this->_frame_width, this->_frame_height, |
| 198 | frame_info.format, &rect); |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 199 | CHECK (ret, "display failed on render_init"); |
| 200 | } |
| 201 | ret = _display->render_setup_frame_buffer (buf); |
| 202 | CHECK (ret, "display failed on framebuf set"); |
| 203 | ret = _display->render_buffer (buf); |
| 204 | CHECK (ret, "display failed on rendering"); |
Yinhang Liu | 6987f2b | 2017-09-30 10:39:58 +0800 | [diff] [blame] | 205 | #else |
| 206 | XCAM_UNUSED (data); |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 207 | #endif |
Yinhang Liu | 6987f2b | 2017-09-30 10:39:58 +0800 | [diff] [blame] | 208 | |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 213 | void |
| 214 | MainDeviceManager::open_file () |
| 215 | { |
Wind Yuan | 136aa4f | 2016-09-08 02:56:31 -0400 | [diff] [blame] | 216 | if (_file_handle.is_valid () && (_frame_save == 0)) |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 217 | return; |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 218 | |
| 219 | std::string file_name = DEFAULT_SAVE_FILE_NAME; |
| 220 | |
| 221 | if (_frame_save != 0) { |
| 222 | file_name += std::to_string(_frame_count); |
| 223 | } |
| 224 | file_name += ".raw"; |
| 225 | |
Wind Yuan | 136aa4f | 2016-09-08 02:56:31 -0400 | [diff] [blame] | 226 | if (_file_handle.open (file_name.c_str (), "wb") != XCAM_RETURN_NO_ERROR) { |
| 227 | XCAM_LOG_WARNING ("create file(%s) failed", file_name.c_str ()); |
Wind Yuan | 7111132 | 2016-02-24 22:56:27 +0800 | [diff] [blame] | 228 | } |
Wind Yuan | 7111132 | 2016-02-24 22:56:27 +0800 | [diff] [blame] | 229 | } |
| 230 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 231 | #define V4L2_CAPTURE_MODE_STILL 0x2000 |
| 232 | #define V4L2_CAPTURE_MODE_VIDEO 0x4000 |
| 233 | #define V4L2_CAPTURE_MODE_PREVIEW 0x8000 |
| 234 | |
Wind Yuan | 26e9e21 | 2015-04-16 15:55:45 +0800 | [diff] [blame] | 235 | typedef enum { |
| 236 | AnalyzerTypeSimple = 0, |
Yinhang Liu | 6c36735 | 2016-03-31 20:23:22 +0800 | [diff] [blame] | 237 | AnalyzerTypeAiqTuner, |
Wind Yuan | e25ce3f | 2015-05-04 18:07:29 +0800 | [diff] [blame] | 238 | AnalyzerTypeDynamic, |
Jia Meng | 9724cfe | 2015-08-12 15:04:45 +0800 | [diff] [blame] | 239 | AnalyzerTypeHybrid, |
Wind Yuan | 26e9e21 | 2015-04-16 15:55:45 +0800 | [diff] [blame] | 240 | } AnalyzerType; |
| 241 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 242 | void dev_stop_handler(int sig) |
| 243 | { |
| 244 | XCAM_UNUSED (sig); |
| 245 | |
| 246 | SmartLock locker (g_mutex); |
| 247 | g_stop = true; |
| 248 | g_cond.broadcast (); |
| 249 | |
| 250 | //exit(0); |
| 251 | } |
| 252 | |
| 253 | void print_help (const char *bin_name) |
| 254 | { |
| 255 | printf ("Usage: %s [-a analyzer]\n" |
Yinhang Liu | 81c44e0 | 2015-06-03 15:47:48 +0800 | [diff] [blame] | 256 | "Configurations:\n" |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 257 | "\t -a analyzer specify a analyzer\n" |
| 258 | "\t select from [simple" |
| 259 | #if HAVE_IA_AIQ |
zongwave | 213b5d6 | 2016-11-25 18:46:53 +0800 | [diff] [blame] | 260 | ", aiq" |
Yinhang Liu | c2f1908 | 2015-08-28 12:27:48 +0800 | [diff] [blame] | 261 | #if HAVE_LIBCL |
zongwave | 213b5d6 | 2016-11-25 18:46:53 +0800 | [diff] [blame] | 262 | ", dynamic, hybrid" |
Yinhang Liu | c2f1908 | 2015-08-28 12:27:48 +0800 | [diff] [blame] | 263 | #endif |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 264 | #endif |
zongwave | 213b5d6 | 2016-11-25 18:46:53 +0800 | [diff] [blame] | 265 | "], default is [simple]\n" |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 266 | "\t -m mem_type specify video memory type\n" |
| 267 | "\t mem_type select from [dma, mmap], default is [mmap]\n" |
| 268 | "\t -s save file to %s\n" |
| 269 | "\t -n interval save file on every [interval] frame\n" |
| 270 | "\t -f pixel_fmt specify output pixel format\n" |
| 271 | "\t pixel_fmt select from [NV12, YUYV, BA10, BA12], default is [NV12]\n" |
Yinhang Liu | 2bdc67a | 2017-02-28 11:27:49 +0800 | [diff] [blame] | 272 | "\t -W image_width specify image width, default is [1920]\n" |
| 273 | "\t -H image_height specify image height, default is [1080]\n" |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 274 | "\t -d cap_mode specify capture mode\n" |
| 275 | "\t cap_mode select from [video, still], default is [video]\n" |
| 276 | "\t -i frame_save specify the frame count to save, default is 0 which means endless\n" |
Yinhang Liu | 5855e6f | 2016-11-14 21:04:22 +0800 | [diff] [blame] | 277 | "\t -p preview on enable local display, need root privilege\n" |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 278 | "\t --usb specify node for usb camera device, enables capture path through USB camera \n" |
| 279 | "\t specify [/dev/video4, /dev/video5] depending on which node USB camera is attached\n" |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 280 | "\t -e display_mode preview mode\n" |
| 281 | "\t select from [primary, overlay], default is [primary]\n" |
| 282 | "\t --sync set analyzer in sync mode\n" |
| 283 | "\t -r raw_input specify the path of raw image as fake source instead of live camera\n" |
| 284 | "\t -h help\n" |
Yinhang Liu | c2f1908 | 2015-08-28 12:27:48 +0800 | [diff] [blame] | 285 | #if HAVE_LIBCL |
Yinhang Liu | 81c44e0 | 2015-06-03 15:47:48 +0800 | [diff] [blame] | 286 | "CL features:\n" |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 287 | "\t -c process image with cl kernel\n" |
| 288 | #if HAVE_IA_AIQ |
| 289 | "\t -b brightness specify brightness level\n" |
| 290 | "\t brightness level select from [0, 256], default is [128]\n" |
| 291 | #endif |
| 292 | "\t --capture specify the capture stage of image\n" |
| 293 | "\t capture_stage select from [bayer, tonemapping], default is [tonemapping]\n" |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 294 | "\t --tnr specify temporal noise reduction type, default is tnr off\n" |
Wind Yuan | 9d5e6a3 | 2017-01-26 03:09:39 -0500 | [diff] [blame] | 295 | "\t only support [yuv]\n" |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 296 | "\t --tnr-level specify tnr level\n" |
| 297 | "\t --wdr-mode specify wdr mode. select from [gaussian, haleq]\n" |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 298 | "\t --enable-bnr enable bayer noise reduction\n" |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 299 | "\t --defog-mode specify defog mode\n" |
| 300 | "\t select from [disabled, retinex, dcp], default is [disabled]\n" |
| 301 | "\t --wavelet-mode specify wavelet denoise mode, default is off\n" |
| 302 | "\t select from [0:disable, 1:Hat Y, 2:Hat UV, 3:Haar Y, 4:Haar UV, 5:Haar YUV, 6:Haar Bayes Shrink]\n" |
| 303 | "\t --3d-denoise specify 3D Denoise mode\n" |
| 304 | "\t select from [disabled, yuv, uv], default is [disabled]\n" |
Yinhang Liu | 4ea7061 | 2016-05-26 18:26:29 +0800 | [diff] [blame] | 305 | "\t --enable-wireframe enable wire frame\n" |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 306 | "\t --pipeline specify pipe mode\n" |
| 307 | "\t select from [basic, advance, extreme], default is [basic]\n" |
| 308 | "\t --disable-post disable cl post image processor\n" |
Yinhang Liu | c2f1908 | 2015-08-28 12:27:48 +0800 | [diff] [blame] | 309 | #endif |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 310 | , bin_name |
| 311 | , DEFAULT_SAVE_FILE_NAME); |
| 312 | } |
| 313 | |
| 314 | int main (int argc, char *argv[]) |
| 315 | { |
| 316 | XCamReturn ret = XCAM_RETURN_NO_ERROR; |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 317 | SmartPtr<V4l2Device> device; |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 318 | #if HAVE_IA_AIQ |
Yinhang Liu | 5c1381c | 2016-11-19 16:35:38 +0800 | [diff] [blame] | 319 | SmartPtr<V4l2SubDevice> event_device; |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 320 | SmartPtr<IspController> isp_controller; |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 321 | SmartPtr<ImageProcessor> isp_processor; |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 322 | #endif |
| 323 | SmartPtr<X3aAnalyzer> analyzer; |
| 324 | SmartPtr<AnalyzerLoader> loader; |
Wind Yuan | 26e9e21 | 2015-04-16 15:55:45 +0800 | [diff] [blame] | 325 | AnalyzerType analyzer_type = AnalyzerTypeSimple; |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 326 | |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 327 | #if HAVE_LIBCL |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 328 | bool have_cl_processor = false; |
| 329 | SmartPtr<SmartAnalyzer> smart_analyzer; |
Yinhang Liu | c64ed59 | 2016-07-15 18:53:34 +0800 | [diff] [blame] | 330 | bool have_cl_post_processor = true; |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 331 | SmartPtr<CL3aImageProcessor> cl_processor; |
Yinhang Liu | 2ab1f99 | 2016-03-15 10:41:17 +0800 | [diff] [blame] | 332 | SmartPtr<CLPostImageProcessor> cl_post_processor; |
Yinhang Liu | c2f1908 | 2015-08-28 12:27:48 +0800 | [diff] [blame] | 333 | uint32_t tnr_type = CL_TNR_DISABLE; |
| 334 | uint32_t denoise_type = 0; |
| 335 | uint8_t tnr_level = 0; |
Wangfei | 1487b9b | 2015-08-28 15:10:39 +0800 | [diff] [blame] | 336 | CL3aImageProcessor::PipelineProfile pipeline_mode = CL3aImageProcessor::BasicPipelineProfile; |
wujunkai166 | a84ba05 | 2015-09-08 15:54:12 +0800 | [diff] [blame] | 337 | CL3aImageProcessor::CaptureStage capture_stage = CL3aImageProcessor::TonemappingStage; |
wujunkai166 | 06f7762 | 2016-03-18 14:41:10 +0800 | [diff] [blame] | 338 | CL3aImageProcessor::CLTonemappingMode wdr_mode = CL3aImageProcessor::WDRdisabled; |
Yinhang Liu | c64ed59 | 2016-07-15 18:53:34 +0800 | [diff] [blame] | 339 | |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 340 | #if HAVE_IA_AIQ |
| 341 | int32_t brightness_level = 128; |
| 342 | #endif |
Wind Yuan | f4e17ab | 2016-05-05 02:54:01 +0800 | [diff] [blame] | 343 | uint32_t defog_type = 0; |
zongwave | b714044 | 2016-03-25 18:15:12 +0800 | [diff] [blame] | 344 | CLWaveletBasis wavelet_mode = CL_WAVELET_DISABLED; |
zongwave | 98d2320 | 2016-06-27 13:46:27 +0800 | [diff] [blame] | 345 | uint32_t wavelet_channel = CL_IMAGE_CHANNEL_UV; |
| 346 | bool wavelet_bayes_shrink = false; |
Yinhang Liu | d341dbe | 2016-07-25 12:00:17 +0800 | [diff] [blame] | 347 | uint32_t denoise_3d_mode = 0; |
| 348 | uint8_t denoise_3d_ref_count = 3; |
Yinhang Liu | 4ea7061 | 2016-05-26 18:26:29 +0800 | [diff] [blame] | 349 | bool wireframe_type = false; |
zongwave | 1b10d6f | 2016-10-25 17:47:51 +0800 | [diff] [blame] | 350 | bool image_warp_type = false; |
Yinhang Liu | c64ed59 | 2016-07-15 18:53:34 +0800 | [diff] [blame] | 351 | #endif |
zongwave | b714044 | 2016-03-25 18:15:12 +0800 | [diff] [blame] | 352 | |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 353 | bool need_display = false; |
Yinhang Liu | 6987f2b | 2017-09-30 10:39:58 +0800 | [diff] [blame] | 354 | #if HAVE_LIBDRM |
Yinhang Liu | 5855e6f | 2016-11-14 21:04:22 +0800 | [diff] [blame] | 355 | DrmDisplayMode display_mode = DRM_DISPLAY_MODE_PRIMARY; |
Yinhang Liu | 6987f2b | 2017-09-30 10:39:58 +0800 | [diff] [blame] | 356 | #endif |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 357 | enum v4l2_memory v4l2_mem_type = V4L2_MEMORY_MMAP; |
| 358 | const char *bin_name = argv[0]; |
| 359 | uint32_t capture_mode = V4L2_CAPTURE_MODE_VIDEO; |
| 360 | uint32_t pixel_format = V4L2_PIX_FMT_NV12; |
| 361 | |
Sameer Kibey | 7b42929 | 2015-08-07 10:55:38 -0700 | [diff] [blame] | 362 | bool have_usbcam = 0; |
Wind Yuan | 2893591 | 2017-08-24 19:18:34 +0800 | [diff] [blame] | 363 | std::string usb_device_name; |
Jia Meng | 8f94a10 | 2015-08-11 16:24:19 +0800 | [diff] [blame] | 364 | bool sync_mode = false; |
Yinhang Liu | 5855e6f | 2016-11-14 21:04:22 +0800 | [diff] [blame] | 365 | bool save_file = false; |
| 366 | uint32_t interval_frames = 1; |
| 367 | uint32_t save_frames = 0; |
| 368 | uint32_t frame_rate; |
| 369 | uint32_t frame_width = 1920; |
| 370 | uint32_t frame_height = 1080; |
Wind Yuan | 2893591 | 2017-08-24 19:18:34 +0800 | [diff] [blame] | 371 | std::string path_to_fake; |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 372 | |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 373 | int opt; |
Yinhang Liu | 2bdc67a | 2017-02-28 11:27:49 +0800 | [diff] [blame] | 374 | const char *short_opts = "sca:n:m:f:W:H:d:b:pi:e:r:h"; |
Yinhang Liu | 81c44e0 | 2015-06-03 15:47:48 +0800 | [diff] [blame] | 375 | const struct option long_opts[] = { |
Yinhang Liu | 81c44e0 | 2015-06-03 15:47:48 +0800 | [diff] [blame] | 376 | {"tnr", required_argument, NULL, 'T'}, |
| 377 | {"tnr-level", required_argument, NULL, 'L'}, |
Yinhang Liu | 2bdc67a | 2017-02-28 11:27:49 +0800 | [diff] [blame] | 378 | {"wdr-mode", required_argument, NULL, 'w'}, |
ShincyTu | 63e2c26 | 2015-06-26 10:52:51 +0800 | [diff] [blame] | 379 | {"enable-bnr", no_argument, NULL, 'B'}, |
Wind Yuan | f4e17ab | 2016-05-05 02:54:01 +0800 | [diff] [blame] | 380 | {"defog-mode", required_argument, NULL, 'X'}, |
zongwave | 2ba7f64 | 2016-03-15 19:24:12 +0800 | [diff] [blame] | 381 | {"wavelet-mode", required_argument, NULL, 'V'}, |
zongwave | bec89e1 | 2016-07-23 12:34:20 +0800 | [diff] [blame] | 382 | {"3d-denoise", required_argument, NULL, 'N'}, |
Yinhang Liu | 4ea7061 | 2016-05-26 18:26:29 +0800 | [diff] [blame] | 383 | {"enable-wireframe", no_argument, NULL, 'F'}, |
zongwave | 1b10d6f | 2016-10-25 17:47:51 +0800 | [diff] [blame] | 384 | {"enable-warp", no_argument, NULL, 'A'}, |
Sameer Kibey | 7b42929 | 2015-08-07 10:55:38 -0700 | [diff] [blame] | 385 | {"usb", required_argument, NULL, 'U'}, |
Jia Meng | 8f94a10 | 2015-08-11 16:24:19 +0800 | [diff] [blame] | 386 | {"sync", no_argument, NULL, 'Y'}, |
wujunkai166 | a84ba05 | 2015-09-08 15:54:12 +0800 | [diff] [blame] | 387 | {"capture", required_argument, NULL, 'C'}, |
Wangfei | 1487b9b | 2015-08-28 15:10:39 +0800 | [diff] [blame] | 388 | {"pipeline", required_argument, NULL, 'P'}, |
Yinhang Liu | b0ad64b | 2016-03-18 16:03:51 +0800 | [diff] [blame] | 389 | {"disable-post", no_argument, NULL, 'O'}, |
Yinhang Liu | 81c44e0 | 2015-06-03 15:47:48 +0800 | [diff] [blame] | 390 | {0, 0, 0, 0}, |
| 391 | }; |
| 392 | |
| 393 | while ((opt = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) { |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 394 | switch (opt) { |
| 395 | case 'a': { |
Wind Yuan | 6b43739 | 2016-02-02 00:31:30 +0800 | [diff] [blame] | 396 | XCAM_ASSERT (optarg); |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 397 | if (!strcmp (optarg, "simple")) |
Wind Yuan | 26e9e21 | 2015-04-16 15:55:45 +0800 | [diff] [blame] | 398 | analyzer_type = AnalyzerTypeSimple; |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 399 | #if HAVE_IA_AIQ |
| 400 | else if (!strcmp (optarg, "aiq")) |
Yinhang Liu | 6c36735 | 2016-03-31 20:23:22 +0800 | [diff] [blame] | 401 | analyzer_type = AnalyzerTypeAiqTuner; |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 402 | #if HAVE_LIBCL |
| 403 | else if (!strcmp (optarg, "dynamic")) |
| 404 | analyzer_type = AnalyzerTypeDynamic; |
Jia Meng | 9724cfe | 2015-08-12 15:04:45 +0800 | [diff] [blame] | 405 | else if (!strcmp (optarg, "hybrid")) |
| 406 | analyzer_type = AnalyzerTypeHybrid; |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 407 | #endif |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 408 | #endif |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 409 | else { |
| 410 | print_help (bin_name); |
| 411 | return -1; |
| 412 | } |
| 413 | break; |
| 414 | } |
| 415 | |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 416 | case 'm': { |
Wind Yuan | 6b43739 | 2016-02-02 00:31:30 +0800 | [diff] [blame] | 417 | XCAM_ASSERT (optarg); |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 418 | if (!strcmp (optarg, "dma")) |
| 419 | v4l2_mem_type = V4L2_MEMORY_DMABUF; |
| 420 | else if (!strcmp (optarg, "mmap")) |
| 421 | v4l2_mem_type = V4L2_MEMORY_MMAP; |
| 422 | else |
| 423 | print_help (bin_name); |
| 424 | break; |
| 425 | } |
| 426 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 427 | case 's': |
Yinhang Liu | 5855e6f | 2016-11-14 21:04:22 +0800 | [diff] [blame] | 428 | save_file = true; |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 429 | break; |
| 430 | case 'n': |
Yinhang Liu | 1aa9760 | 2016-05-27 14:58:21 +0800 | [diff] [blame] | 431 | XCAM_ASSERT (optarg); |
Yinhang Liu | 5855e6f | 2016-11-14 21:04:22 +0800 | [diff] [blame] | 432 | interval_frames = atoi(optarg); |
| 433 | break; |
| 434 | case 'i': |
| 435 | XCAM_ASSERT (optarg); |
| 436 | save_frames = atoi(optarg); |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 437 | break; |
ShincyTu | 2808b59 | 2015-03-13 17:17:25 +0800 | [diff] [blame] | 438 | case 'f': |
Yinhang Liu | 1aa9760 | 2016-05-27 14:58:21 +0800 | [diff] [blame] | 439 | XCAM_ASSERT (optarg); |
ShincyTu | c846640 | 2015-03-31 11:03:39 +0800 | [diff] [blame] | 440 | CHECK_EXP ((strlen(optarg) == 4), "invalid pixel format\n"); |
| 441 | pixel_format = v4l2_fourcc ((unsigned)optarg[0], |
| 442 | (unsigned)optarg[1], |
| 443 | (unsigned)optarg[2], |
| 444 | (unsigned)optarg[3]); |
ShincyTu | 2808b59 | 2015-03-13 17:17:25 +0800 | [diff] [blame] | 445 | break; |
| 446 | case 'd': |
Wind Yuan | 6b43739 | 2016-02-02 00:31:30 +0800 | [diff] [blame] | 447 | XCAM_ASSERT (optarg); |
ShincyTu | 2808b59 | 2015-03-13 17:17:25 +0800 | [diff] [blame] | 448 | if (!strcmp (optarg, "still")) |
| 449 | capture_mode = V4L2_CAPTURE_MODE_STILL; |
| 450 | else if (!strcmp (optarg, "video")) |
| 451 | capture_mode = V4L2_CAPTURE_MODE_VIDEO; |
| 452 | else { |
| 453 | print_help (bin_name); |
| 454 | return -1; |
| 455 | } |
| 456 | break; |
Sameer Kibey | 7b42929 | 2015-08-07 10:55:38 -0700 | [diff] [blame] | 457 | case 'U': |
Yinhang Liu | 1aa9760 | 2016-05-27 14:58:21 +0800 | [diff] [blame] | 458 | XCAM_ASSERT (optarg); |
Sameer Kibey | 7b42929 | 2015-08-07 10:55:38 -0700 | [diff] [blame] | 459 | have_usbcam = true; |
Wind Yuan | 2893591 | 2017-08-24 19:18:34 +0800 | [diff] [blame] | 460 | usb_device_name = optarg; |
| 461 | XCAM_LOG_DEBUG("using USB camera plugged in at node: %s", XCAM_STR(usb_device_name.c_str())); |
Sameer Kibey | 7b42929 | 2015-08-07 10:55:38 -0700 | [diff] [blame] | 462 | break; |
Yinhang Liu | 2bdc67a | 2017-02-28 11:27:49 +0800 | [diff] [blame] | 463 | case 'W': |
Wind Yuan | 6b43739 | 2016-02-02 00:31:30 +0800 | [diff] [blame] | 464 | XCAM_ASSERT (optarg); |
Yinhang Liu | 2bdc67a | 2017-02-28 11:27:49 +0800 | [diff] [blame] | 465 | frame_width = atoi(optarg); |
| 466 | break; |
| 467 | case 'H': |
| 468 | XCAM_ASSERT (optarg); |
| 469 | frame_height = atoi(optarg); |
Yinhang Liu | d934649 | 2015-12-17 11:14:25 +0800 | [diff] [blame] | 470 | break; |
wangfei | cf4c4e7 | 2015-05-25 17:11:41 +0800 | [diff] [blame] | 471 | case 'e': { |
Yinhang Liu | 6987f2b | 2017-09-30 10:39:58 +0800 | [diff] [blame] | 472 | #if HAVE_LIBDRM |
Wind Yuan | 6b43739 | 2016-02-02 00:31:30 +0800 | [diff] [blame] | 473 | XCAM_ASSERT (optarg); |
wangfei | cf4c4e7 | 2015-05-25 17:11:41 +0800 | [diff] [blame] | 474 | if (!strcmp (optarg, "primary")) |
| 475 | display_mode = DRM_DISPLAY_MODE_PRIMARY; |
| 476 | else if (!strcmp (optarg, "overlay")) |
| 477 | display_mode = DRM_DISPLAY_MODE_OVERLAY; |
| 478 | else { |
| 479 | print_help (bin_name); |
| 480 | return -1; |
| 481 | } |
Yinhang Liu | 6987f2b | 2017-09-30 10:39:58 +0800 | [diff] [blame] | 482 | #else |
| 483 | XCAM_LOG_WARNING ("preview is not supported"); |
| 484 | #endif |
wangfei | cf4c4e7 | 2015-05-25 17:11:41 +0800 | [diff] [blame] | 485 | break; |
| 486 | } |
Yinhang Liu | 6987f2b | 2017-09-30 10:39:58 +0800 | [diff] [blame] | 487 | |
Jia Meng | 8f94a10 | 2015-08-11 16:24:19 +0800 | [diff] [blame] | 488 | case 'Y': |
| 489 | sync_mode = true; |
| 490 | break; |
Yinhang Liu | c2f1908 | 2015-08-28 12:27:48 +0800 | [diff] [blame] | 491 | #if HAVE_LIBCL |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 492 | case 'c': |
| 493 | have_cl_processor = true; |
| 494 | break; |
| 495 | #if HAVE_IA_AIQ |
| 496 | case 'b': |
| 497 | XCAM_ASSERT (optarg); |
| 498 | brightness_level = atoi(optarg); |
| 499 | if(brightness_level < 0 || brightness_level > 256) { |
| 500 | print_help (bin_name); |
| 501 | return -1; |
| 502 | } |
| 503 | break; |
| 504 | #endif |
Wind Yuan | 9d5e6a3 | 2017-01-26 03:09:39 -0500 | [diff] [blame] | 505 | |
ShincyTu | 63e2c26 | 2015-06-26 10:52:51 +0800 | [diff] [blame] | 506 | case 'B': { |
| 507 | denoise_type |= XCAM_DENOISE_TYPE_BNR; |
| 508 | break; |
| 509 | } |
Wangfei | 8e5e3e4 | 2016-02-18 19:41:54 +0800 | [diff] [blame] | 510 | case 'X': { |
Wind Yuan | f4e17ab | 2016-05-05 02:54:01 +0800 | [diff] [blame] | 511 | XCAM_ASSERT (optarg); |
| 512 | defog_type = true; |
| 513 | if (!strcmp (optarg, "disabled")) |
| 514 | defog_type = CLPostImageProcessor::DefogDisabled; |
| 515 | else if (!strcmp (optarg, "retinex")) |
| 516 | defog_type = CLPostImageProcessor::DefogRetinex; |
| 517 | else if (!strcmp (optarg, "dcp")) |
| 518 | defog_type = CLPostImageProcessor::DefogDarkChannelPrior; |
| 519 | else { |
| 520 | print_help (bin_name); |
| 521 | return -1; |
| 522 | } |
Wangfei | 8e5e3e4 | 2016-02-18 19:41:54 +0800 | [diff] [blame] | 523 | break; |
| 524 | } |
zongwave | 80adcf5 | 2016-02-29 12:38:06 +0800 | [diff] [blame] | 525 | case 'V': { |
zongwave | 2ba7f64 | 2016-03-15 19:24:12 +0800 | [diff] [blame] | 526 | XCAM_ASSERT (optarg); |
| 527 | if (atoi(optarg) < 0 || atoi(optarg) > 255) { |
| 528 | print_help (bin_name); |
| 529 | return -1; |
| 530 | } |
zongwave | 28a747b | 2016-03-17 12:49:08 +0800 | [diff] [blame] | 531 | if (atoi(optarg) == 1) { |
zongwave | b714044 | 2016-03-25 18:15:12 +0800 | [diff] [blame] | 532 | wavelet_mode = CL_WAVELET_HAT; |
zongwave | 98d2320 | 2016-06-27 13:46:27 +0800 | [diff] [blame] | 533 | wavelet_channel = CL_IMAGE_CHANNEL_Y; |
zongwave | 28a747b | 2016-03-17 12:49:08 +0800 | [diff] [blame] | 534 | } else if (atoi(optarg) == 2) { |
zongwave | b714044 | 2016-03-25 18:15:12 +0800 | [diff] [blame] | 535 | wavelet_mode = CL_WAVELET_HAT; |
zongwave | 98d2320 | 2016-06-27 13:46:27 +0800 | [diff] [blame] | 536 | wavelet_channel = CL_IMAGE_CHANNEL_UV; |
zongwave | b714044 | 2016-03-25 18:15:12 +0800 | [diff] [blame] | 537 | } else if (atoi(optarg) == 3) { |
| 538 | wavelet_mode = CL_WAVELET_HAAR; |
zongwave | 98d2320 | 2016-06-27 13:46:27 +0800 | [diff] [blame] | 539 | wavelet_channel = CL_IMAGE_CHANNEL_Y; |
zongwave | b714044 | 2016-03-25 18:15:12 +0800 | [diff] [blame] | 540 | } else if (atoi(optarg) == 4) { |
| 541 | wavelet_mode = CL_WAVELET_HAAR; |
zongwave | 98d2320 | 2016-06-27 13:46:27 +0800 | [diff] [blame] | 542 | wavelet_channel = CL_IMAGE_CHANNEL_UV; |
zongwave | b714044 | 2016-03-25 18:15:12 +0800 | [diff] [blame] | 543 | } else if (atoi(optarg) == 5) { |
| 544 | wavelet_mode = CL_WAVELET_HAAR; |
zongwave | 98d2320 | 2016-06-27 13:46:27 +0800 | [diff] [blame] | 545 | wavelet_channel = CL_IMAGE_CHANNEL_UV | CL_IMAGE_CHANNEL_Y; |
| 546 | } else if (atoi(optarg) == 6) { |
| 547 | wavelet_mode = CL_WAVELET_HAAR; |
| 548 | wavelet_channel = CL_IMAGE_CHANNEL_UV | CL_IMAGE_CHANNEL_Y; |
| 549 | wavelet_bayes_shrink = true; |
zongwave | 28a747b | 2016-03-17 12:49:08 +0800 | [diff] [blame] | 550 | } else { |
zongwave | b714044 | 2016-03-25 18:15:12 +0800 | [diff] [blame] | 551 | wavelet_mode = CL_WAVELET_DISABLED; |
zongwave | 28a747b | 2016-03-17 12:49:08 +0800 | [diff] [blame] | 552 | } |
zongwave | 80adcf5 | 2016-02-29 12:38:06 +0800 | [diff] [blame] | 553 | break; |
| 554 | } |
zongwave | bec89e1 | 2016-07-23 12:34:20 +0800 | [diff] [blame] | 555 | case 'N': { |
| 556 | XCAM_ASSERT (optarg); |
| 557 | denoise_3d_mode = true; |
| 558 | if (!strcmp (optarg, "disabled")) |
| 559 | denoise_3d_mode = CLPostImageProcessor::Denoise3DDisabled; |
| 560 | else if (!strcmp (optarg, "yuv")) |
| 561 | denoise_3d_mode = CLPostImageProcessor::Denoise3DYuv; |
| 562 | else if (!strcmp (optarg, "uv")) |
| 563 | denoise_3d_mode = CLPostImageProcessor::Denoise3DUV; |
| 564 | else { |
| 565 | print_help (bin_name); |
| 566 | return -1; |
| 567 | } |
| 568 | break; |
| 569 | } |
Yinhang Liu | 4ea7061 | 2016-05-26 18:26:29 +0800 | [diff] [blame] | 570 | case 'F': { |
| 571 | wireframe_type = true; |
| 572 | break; |
| 573 | } |
zongwave | 1b10d6f | 2016-10-25 17:47:51 +0800 | [diff] [blame] | 574 | case 'A': { |
| 575 | image_warp_type = true; |
| 576 | break; |
| 577 | } |
Yinhang Liu | 81c44e0 | 2015-06-03 15:47:48 +0800 | [diff] [blame] | 578 | case 'T': { |
Wind Yuan | 6b43739 | 2016-02-02 00:31:30 +0800 | [diff] [blame] | 579 | XCAM_ASSERT (optarg); |
Yinhang Liu | 81c44e0 | 2015-06-03 15:47:48 +0800 | [diff] [blame] | 580 | if (!strcasecmp (optarg, "yuv")) |
| 581 | tnr_type = CL_TNR_TYPE_YUV; |
Yinhang Liu | 81c44e0 | 2015-06-03 15:47:48 +0800 | [diff] [blame] | 582 | else { |
Wind Yuan | 9d5e6a3 | 2017-01-26 03:09:39 -0500 | [diff] [blame] | 583 | printf ("--tnr only support <yuv>, <%s> is not supported\n", optarg); |
Yinhang Liu | 81c44e0 | 2015-06-03 15:47:48 +0800 | [diff] [blame] | 584 | print_help (bin_name); |
| 585 | return -1; |
| 586 | } |
| 587 | break; |
| 588 | } |
| 589 | case 'L': { |
Wind Yuan | 6b43739 | 2016-02-02 00:31:30 +0800 | [diff] [blame] | 590 | XCAM_ASSERT (optarg); |
Yinhang Liu | 81c44e0 | 2015-06-03 15:47:48 +0800 | [diff] [blame] | 591 | if (atoi(optarg) < 0 || atoi(optarg) > 255) { |
| 592 | print_help (bin_name); |
| 593 | return -1; |
| 594 | } |
| 595 | tnr_level = atoi(optarg); |
| 596 | break; |
| 597 | } |
Yinhang Liu | 2bdc67a | 2017-02-28 11:27:49 +0800 | [diff] [blame] | 598 | case 'w': { |
wujunkai166 | 06f7762 | 2016-03-18 14:41:10 +0800 | [diff] [blame] | 599 | XCAM_ASSERT (optarg); |
| 600 | if (!strcasecmp (optarg, "gaussian")) |
| 601 | wdr_mode = CL3aImageProcessor::Gaussian; |
| 602 | else if (!strcasecmp (optarg, "haleq")) |
| 603 | wdr_mode = CL3aImageProcessor::Haleq; |
wujunkai166 | 82950fb | 2015-10-19 18:09:05 +0800 | [diff] [blame] | 604 | |
wujunkai166 | b0bd551 | 2016-02-18 18:25:42 +0800 | [diff] [blame] | 605 | pixel_format = V4L2_PIX_FMT_SGRBG12; |
wujunkai166 | b0bd551 | 2016-02-18 18:25:42 +0800 | [diff] [blame] | 606 | setenv ("AIQ_CPF_PATH", IMX185_WDR_CPF, 1); |
| 607 | break; |
| 608 | } |
Wangfei | 1487b9b | 2015-08-28 15:10:39 +0800 | [diff] [blame] | 609 | case 'P': { |
Wind Yuan | 6b43739 | 2016-02-02 00:31:30 +0800 | [diff] [blame] | 610 | XCAM_ASSERT (optarg); |
Wangfei | 1487b9b | 2015-08-28 15:10:39 +0800 | [diff] [blame] | 611 | if (!strcasecmp (optarg, "basic")) |
| 612 | pipeline_mode = CL3aImageProcessor::BasicPipelineProfile; |
| 613 | else if (!strcasecmp (optarg, "advance")) |
| 614 | pipeline_mode = CL3aImageProcessor::AdvancedPipelineProfile; |
Wangfei | 16b65db | 2015-09-11 14:44:28 +0800 | [diff] [blame] | 615 | else if (!strcasecmp (optarg, "extreme")) |
| 616 | pipeline_mode = CL3aImageProcessor::ExtremePipelineProfile; |
Wangfei | 1487b9b | 2015-08-28 15:10:39 +0800 | [diff] [blame] | 617 | else { |
| 618 | print_help (bin_name); |
| 619 | return -1; |
| 620 | } |
| 621 | break; |
| 622 | } |
wujunkai166 | a84ba05 | 2015-09-08 15:54:12 +0800 | [diff] [blame] | 623 | case 'C': { |
Wind Yuan | 6b43739 | 2016-02-02 00:31:30 +0800 | [diff] [blame] | 624 | XCAM_ASSERT (optarg); |
wujunkai166 | a84ba05 | 2015-09-08 15:54:12 +0800 | [diff] [blame] | 625 | if (!strcmp (optarg, "bayer")) |
| 626 | capture_stage = CL3aImageProcessor::BasicbayerStage; |
| 627 | break; |
| 628 | } |
Yinhang Liu | b0ad64b | 2016-03-18 16:03:51 +0800 | [diff] [blame] | 629 | case 'O': { |
| 630 | have_cl_post_processor = false; |
| 631 | break; |
| 632 | } |
Yinhang Liu | c2f1908 | 2015-08-28 12:27:48 +0800 | [diff] [blame] | 633 | #endif |
Jia Meng | 0a53293 | 2015-10-15 08:44:09 -0400 | [diff] [blame] | 634 | case 'r': { |
Yinhang Liu | 1aa9760 | 2016-05-27 14:58:21 +0800 | [diff] [blame] | 635 | XCAM_ASSERT (optarg); |
| 636 | XCAM_LOG_INFO ("use raw image %s as input source", optarg); |
Wind Yuan | 2893591 | 2017-08-24 19:18:34 +0800 | [diff] [blame] | 637 | path_to_fake = optarg; |
Jia Meng | 0a53293 | 2015-10-15 08:44:09 -0400 | [diff] [blame] | 638 | break; |
| 639 | } |
Yinhang Liu | 5855e6f | 2016-11-14 21:04:22 +0800 | [diff] [blame] | 640 | case 'p': { |
Yinhang Liu | 6987f2b | 2017-09-30 10:39:58 +0800 | [diff] [blame] | 641 | #if HAVE_LIBDRM |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 642 | need_display = true; |
Yinhang Liu | 6987f2b | 2017-09-30 10:39:58 +0800 | [diff] [blame] | 643 | #else |
| 644 | XCAM_LOG_WARNING ("preview is not supported, disable preview now"); |
| 645 | need_display = false; |
| 646 | #endif |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 647 | break; |
Yinhang Liu | 5855e6f | 2016-11-14 21:04:22 +0800 | [diff] [blame] | 648 | } |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 649 | case 'h': |
| 650 | print_help (bin_name); |
| 651 | return 0; |
| 652 | |
| 653 | default: |
| 654 | print_help (bin_name); |
| 655 | return -1; |
| 656 | } |
| 657 | } |
| 658 | |
Yinhang Liu | 5855e6f | 2016-11-14 21:04:22 +0800 | [diff] [blame] | 659 | SmartPtr<MainDeviceManager> device_manager = new MainDeviceManager (); |
| 660 | device_manager->enable_save_file (save_file); |
| 661 | device_manager->set_interval (interval_frames); |
| 662 | device_manager->set_frame_save (save_frames); |
| 663 | device_manager->set_frame_width (frame_width); |
| 664 | device_manager->set_frame_height (frame_height); |
Yinhang Liu | 5855e6f | 2016-11-14 21:04:22 +0800 | [diff] [blame] | 665 | |
ShincyTu | 2808b59 | 2015-03-13 17:17:25 +0800 | [diff] [blame] | 666 | if (!device.ptr ()) { |
Wind Yuan | 2893591 | 2017-08-24 19:18:34 +0800 | [diff] [blame] | 667 | if (path_to_fake.c_str ()) { |
Jia Meng | 0a53293 | 2015-10-15 08:44:09 -0400 | [diff] [blame] | 668 | device = new FakeV4l2Device (); |
| 669 | } else if (have_usbcam) { |
Wind Yuan | 2893591 | 2017-08-24 19:18:34 +0800 | [diff] [blame] | 670 | device = new UVCDevice (usb_device_name.c_str ()); |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 671 | } |
| 672 | #if HAVE_IA_AIQ |
| 673 | else { |
Sameer Kibey | 7b42929 | 2015-08-07 10:55:38 -0700 | [diff] [blame] | 674 | if (capture_mode == V4L2_CAPTURE_MODE_STILL) |
| 675 | device = new AtomispDevice (CAPTURE_DEVICE_STILL); |
| 676 | else if (capture_mode == V4L2_CAPTURE_MODE_VIDEO) |
| 677 | device = new AtomispDevice (CAPTURE_DEVICE_VIDEO); |
| 678 | else |
| 679 | device = new AtomispDevice (DEFAULT_CAPTURE_DEVICE); |
| 680 | } |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 681 | #endif |
ShincyTu | 2808b59 | 2015-03-13 17:17:25 +0800 | [diff] [blame] | 682 | } |
Yinhang Liu | 5c1381c | 2016-11-19 16:35:38 +0800 | [diff] [blame] | 683 | |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 684 | #if HAVE_IA_AIQ |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 685 | if (!isp_controller.ptr ()) |
| 686 | isp_controller = new IspController (device); |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 687 | #endif |
Wind Yuan | 26e9e21 | 2015-04-16 15:55:45 +0800 | [diff] [blame] | 688 | |
| 689 | switch (analyzer_type) { |
Wind Yuan | 3d1d15e | 2015-04-16 17:40:47 +0800 | [diff] [blame] | 690 | case AnalyzerTypeSimple: |
| 691 | analyzer = new X3aAnalyzerSimple (); |
| 692 | break; |
Wind Yuan | 26e9e21 | 2015-04-16 15:55:45 +0800 | [diff] [blame] | 693 | #if HAVE_IA_AIQ |
Yinhang Liu | 6c36735 | 2016-03-31 20:23:22 +0800 | [diff] [blame] | 694 | case AnalyzerTypeAiqTuner: { |
| 695 | SmartPtr<X3aAnalyzer> aiq_analyzer = new X3aAnalyzerAiq (isp_controller, DEFAULT_CPF_FILE); |
| 696 | SmartPtr<X3aAnalyzeTuner> tuner_analyzer = new X3aAnalyzeTuner (); |
| 697 | XCAM_ASSERT (aiq_analyzer.ptr () && tuner_analyzer.ptr ()); |
| 698 | tuner_analyzer->set_analyzer (aiq_analyzer); |
| 699 | analyzer = tuner_analyzer; |
Wind Yuan | 3d1d15e | 2015-04-16 17:40:47 +0800 | [diff] [blame] | 700 | break; |
Yinhang Liu | 6c36735 | 2016-03-31 20:23:22 +0800 | [diff] [blame] | 701 | } |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 702 | #if HAVE_LIBCL |
| 703 | case AnalyzerTypeDynamic: { |
| 704 | const char *path_of_3a = DEFAULT_DYNAMIC_3A_LIB; |
| 705 | SmartPtr<DynamicAnalyzerLoader> dynamic_loader = new DynamicAnalyzerLoader (path_of_3a); |
| 706 | loader = dynamic_loader.dynamic_cast_ptr<AnalyzerLoader> (); |
| 707 | analyzer = dynamic_loader->load_analyzer (loader); |
| 708 | CHECK_EXP (analyzer.ptr (), "load dynamic 3a lib(%s) failed", path_of_3a); |
| 709 | break; |
| 710 | } |
Jia Meng | 9724cfe | 2015-08-12 15:04:45 +0800 | [diff] [blame] | 711 | case AnalyzerTypeHybrid: { |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 712 | const char *path_of_3a = DEFAULT_HYBRID_3A_LIB; |
Yinhang Liu | e37a872 | 2016-06-27 18:14:35 +0800 | [diff] [blame] | 713 | SmartPtr<HybridAnalyzerLoader> hybrid_loader = new HybridAnalyzerLoader (path_of_3a); |
| 714 | hybrid_loader->set_cpf_path (DEFAULT_CPF_FILE); |
| 715 | hybrid_loader->set_isp_controller (isp_controller); |
| 716 | loader = hybrid_loader.dynamic_cast_ptr<AnalyzerLoader> (); |
| 717 | analyzer = hybrid_loader->load_analyzer (loader); |
Jia Meng | 9724cfe | 2015-08-12 15:04:45 +0800 | [diff] [blame] | 718 | CHECK_EXP (analyzer.ptr (), "load hybrid 3a lib(%s) failed", path_of_3a); |
| 719 | break; |
| 720 | } |
Wind Yuan | 26e9e21 | 2015-04-16 15:55:45 +0800 | [diff] [blame] | 721 | #endif |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 722 | #endif |
Wind Yuan | 3d1d15e | 2015-04-16 17:40:47 +0800 | [diff] [blame] | 723 | default: |
| 724 | print_help (bin_name); |
| 725 | return -1; |
Wind Yuan | 26e9e21 | 2015-04-16 15:55:45 +0800 | [diff] [blame] | 726 | } |
Jia Meng | 8f94a10 | 2015-08-11 16:24:19 +0800 | [diff] [blame] | 727 | XCAM_ASSERT (analyzer.ptr ()); |
| 728 | analyzer->set_sync_mode (sync_mode); |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 729 | |
Yinhang Liu | 3fef5d7 | 2016-07-25 14:43:20 +0800 | [diff] [blame] | 730 | #if HAVE_LIBCL |
| 731 | SmartHandlerList smart_handlers = SmartAnalyzerLoader::load_smart_handlers (DEFAULT_SMART_ANALYSIS_LIB_DIR); |
| 732 | if (!smart_handlers.empty ()) { |
| 733 | smart_analyzer = new SmartAnalyzer (); |
| 734 | if (smart_analyzer.ptr ()) { |
| 735 | SmartHandlerList::iterator i_handler = smart_handlers.begin (); |
Wind Yuan | 136aa4f | 2016-09-08 02:56:31 -0400 | [diff] [blame] | 736 | for (; i_handler != smart_handlers.end (); ++i_handler) |
Yinhang Liu | 3fef5d7 | 2016-07-25 14:43:20 +0800 | [diff] [blame] | 737 | { |
| 738 | XCAM_ASSERT ((*i_handler).ptr ()); |
| 739 | smart_analyzer->add_handler (*i_handler); |
| 740 | } |
| 741 | } else { |
| 742 | XCAM_LOG_WARNING ("load smart analyzer(%s) failed, please check.", DEFAULT_SMART_ANALYSIS_LIB_DIR); |
| 743 | } |
| 744 | } |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 745 | |
| 746 | if (smart_analyzer.ptr ()) { |
| 747 | if (smart_analyzer->prepare_handlers () != XCAM_RETURN_NO_ERROR) { |
| 748 | XCAM_LOG_WARNING ("analyzer(%s) prepare handlers failed", smart_analyzer->get_name ()); |
| 749 | } |
| 750 | device_manager->set_smart_analyzer (smart_analyzer); |
| 751 | } |
Yinhang Liu | 3fef5d7 | 2016-07-25 14:43:20 +0800 | [diff] [blame] | 752 | #endif |
| 753 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 754 | signal(SIGINT, dev_stop_handler); |
| 755 | |
| 756 | device->set_sensor_id (0); |
ShincyTu | 2808b59 | 2015-03-13 17:17:25 +0800 | [diff] [blame] | 757 | device->set_capture_mode (capture_mode); |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 758 | //device->set_mem_type (V4L2_MEMORY_DMABUF); |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 759 | device->set_mem_type (v4l2_mem_type); |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 760 | device->set_buffer_count (8); |
Jia Meng | 757f3c9 | 2015-09-09 11:18:36 +0800 | [diff] [blame] | 761 | if (pixel_format == V4L2_PIX_FMT_SGRBG12) { |
| 762 | frame_rate = 30; |
| 763 | device->set_framerate (frame_rate, 1); |
| 764 | } |
Yinhang Liu | c64ed59 | 2016-07-15 18:53:34 +0800 | [diff] [blame] | 765 | #if HAVE_LIBCL |
Jia Meng | 757f3c9 | 2015-09-09 11:18:36 +0800 | [diff] [blame] | 766 | else { |
| 767 | frame_rate = 25; |
| 768 | device->set_framerate (frame_rate, 1); |
Yinhang Liu | efe4f0f | 2016-12-29 13:17:22 +0800 | [diff] [blame] | 769 | if(wdr_mode != CL3aImageProcessor::WDRdisabled) { |
wujunkai166 | a9a55f2 | 2015-10-10 15:53:32 +0800 | [diff] [blame] | 770 | XCAM_LOG_WARNING("Tonemapping is only applicable under BA12 format. Disable tonemapping automatically."); |
Yinhang Liu | efe4f0f | 2016-12-29 13:17:22 +0800 | [diff] [blame] | 771 | wdr_mode = CL3aImageProcessor::WDRdisabled; |
wujunkai166 | a9a55f2 | 2015-10-10 15:53:32 +0800 | [diff] [blame] | 772 | } |
Jia Meng | 757f3c9 | 2015-09-09 11:18:36 +0800 | [diff] [blame] | 773 | } |
Yinhang Liu | c64ed59 | 2016-07-15 18:53:34 +0800 | [diff] [blame] | 774 | #endif |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 775 | ret = device->open (); |
| 776 | CHECK (ret, "device(%s) open failed", device->get_device_name()); |
Yinhang Liu | d934649 | 2015-12-17 11:14:25 +0800 | [diff] [blame] | 777 | ret = device->set_format (frame_width, frame_height, pixel_format, V4L2_FIELD_NONE, frame_width * 2); |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 778 | CHECK (ret, "device(%s) set format failed", device->get_device_name()); |
| 779 | |
Yinhang Liu | 5c1381c | 2016-11-19 16:35:38 +0800 | [diff] [blame] | 780 | #if HAVE_IA_AIQ |
| 781 | if (!event_device.ptr ()) |
| 782 | event_device = new V4l2SubDevice (DEFAULT_EVENT_DEVICE); |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 783 | ret = event_device->open (); |
Wind Yuan | b67045c | 2015-08-27 13:50:53 +0800 | [diff] [blame] | 784 | if (ret == XCAM_RETURN_NO_ERROR) { |
| 785 | CHECK (ret, "event device(%s) open failed", event_device->get_device_name()); |
| 786 | int event = V4L2_EVENT_ATOMISP_3A_STATS_READY; |
| 787 | ret = event_device->subscribe_event (event); |
| 788 | CHECK_CONTINUE ( |
| 789 | ret, |
| 790 | "device(%s) subscribe event(%d) failed", |
| 791 | event_device->get_device_name(), event); |
| 792 | event = V4L2_EVENT_FRAME_SYNC; |
| 793 | ret = event_device->subscribe_event (event); |
| 794 | CHECK_CONTINUE ( |
| 795 | ret, |
| 796 | "device(%s) subscribe event(%d) failed", |
| 797 | event_device->get_device_name(), event); |
| 798 | |
| 799 | device_manager->set_event_device (event_device); |
| 800 | } |
Yinhang Liu | 5c1381c | 2016-11-19 16:35:38 +0800 | [diff] [blame] | 801 | #endif |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 802 | |
| 803 | device_manager->set_capture_device (device); |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 804 | if (analyzer.ptr()) |
zongwave | 03954a3 | 2015-09-22 15:40:44 +0800 | [diff] [blame] | 805 | device_manager->set_3a_analyzer (analyzer); |
Wind Yuan | 3d1d15e | 2015-04-16 17:40:47 +0800 | [diff] [blame] | 806 | |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 807 | #if HAVE_IA_AIQ |
| 808 | #if HAVE_LIBCL |
Wind Yuan | 3d1d15e | 2015-04-16 17:40:47 +0800 | [diff] [blame] | 809 | if (have_cl_processor) |
| 810 | isp_processor = new IspExposureImageProcessor (isp_controller); |
| 811 | else |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 812 | #endif |
Wind Yuan | 3d1d15e | 2015-04-16 17:40:47 +0800 | [diff] [blame] | 813 | isp_processor = new IspImageProcessor (isp_controller); |
| 814 | |
| 815 | XCAM_ASSERT (isp_processor.ptr ()); |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 816 | device_manager->add_image_processor (isp_processor); |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 817 | #endif |
Yinhang Liu | c2f1908 | 2015-08-28 12:27:48 +0800 | [diff] [blame] | 818 | #if HAVE_LIBCL |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 819 | if (have_cl_processor) { |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 820 | cl_processor = new CL3aImageProcessor (); |
Wind Yuan | 7ddf260 | 2015-04-14 18:49:45 +0800 | [diff] [blame] | 821 | cl_processor->set_stats_callback(device_manager); |
Jia Meng | 66efecf | 2015-06-17 11:11:10 +0000 | [diff] [blame] | 822 | cl_processor->set_denoise (denoise_type); |
wujunkai166 | a84ba05 | 2015-09-08 15:54:12 +0800 | [diff] [blame] | 823 | cl_processor->set_capture_stage (capture_stage); |
wujunkai166 | c8f3b44 | 2016-02-29 17:12:09 +0800 | [diff] [blame] | 824 | |
Yinhang Liu | efe4f0f | 2016-12-29 13:17:22 +0800 | [diff] [blame] | 825 | cl_processor->set_tonemapping (wdr_mode); |
| 826 | if (wdr_mode != CL3aImageProcessor::WDRdisabled) { |
| 827 | cl_processor->set_gamma (false); |
| 828 | cl_processor->set_3a_stats_bits (12); |
wujunkai166 | c8f3b44 | 2016-02-29 17:12:09 +0800 | [diff] [blame] | 829 | } |
Yinhang Liu | efe4f0f | 2016-12-29 13:17:22 +0800 | [diff] [blame] | 830 | |
Yinhang Liu | 81c44e0 | 2015-06-03 15:47:48 +0800 | [diff] [blame] | 831 | cl_processor->set_tnr (tnr_type, tnr_level); |
Wangfei | 1487b9b | 2015-08-28 15:10:39 +0800 | [diff] [blame] | 832 | cl_processor->set_profile (pipeline_mode); |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 833 | #if HAVE_IA_AIQ |
yaowang1 | a5f1212 | 2015-07-27 14:53:38 +0800 | [diff] [blame] | 834 | analyzer->set_parameter_brightness((brightness_level - 128) / 128.0); |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 835 | #endif |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 836 | device_manager->add_image_processor (cl_processor); |
| 837 | } |
Yinhang Liu | 3c17fea | 2016-03-15 10:47:03 +0800 | [diff] [blame] | 838 | |
Yinhang Liu | b0ad64b | 2016-03-18 16:03:51 +0800 | [diff] [blame] | 839 | if (have_cl_post_processor) { |
| 840 | cl_post_processor = new CLPostImageProcessor (); |
Yinhang Liu | 3c721c1 | 2016-03-15 15:03:51 +0800 | [diff] [blame] | 841 | |
Yinhang Liu | d341dbe | 2016-07-25 12:00:17 +0800 | [diff] [blame] | 842 | cl_post_processor->set_stats_callback (device_manager); |
Wind Yuan | f4e17ab | 2016-05-05 02:54:01 +0800 | [diff] [blame] | 843 | cl_post_processor->set_defog_mode ((CLPostImageProcessor::CLDefogMode)defog_type); |
Yinhang Liu | d341dbe | 2016-07-25 12:00:17 +0800 | [diff] [blame] | 844 | cl_post_processor->set_wavelet (wavelet_mode, wavelet_channel, wavelet_bayes_shrink); |
| 845 | cl_post_processor->set_3ddenoise_mode ((CLPostImageProcessor::CL3DDenoiseMode) denoise_3d_mode, denoise_3d_ref_count); |
Yinhang Liu | 3c721c1 | 2016-03-15 15:03:51 +0800 | [diff] [blame] | 846 | |
Yinhang Liu | d341dbe | 2016-07-25 12:00:17 +0800 | [diff] [blame] | 847 | cl_post_processor->set_wireframe (wireframe_type); |
zongwave | 1b10d6f | 2016-10-25 17:47:51 +0800 | [diff] [blame] | 848 | cl_post_processor->set_image_warp (image_warp_type); |
| 849 | if (smart_analyzer.ptr () && (wireframe_type || image_warp_type)) { |
Yinhang Liu | d341dbe | 2016-07-25 12:00:17 +0800 | [diff] [blame] | 850 | cl_post_processor->set_scaler (true); |
| 851 | cl_post_processor->set_scaler_factor (640.0 / frame_width); |
| 852 | } |
zongwave | bec89e1 | 2016-07-23 12:34:20 +0800 | [diff] [blame] | 853 | |
Yinhang Liu | d6d824a | 2016-03-22 20:43:00 +0800 | [diff] [blame] | 854 | if (need_display) { |
Yinhang Liu | cff638b | 2017-09-25 21:16:28 +0800 | [diff] [blame] | 855 | need_display = false; |
| 856 | XCAM_LOG_WARNING ("CLVideoBuffer doesn't support local preview, disable local preview now"); |
Yinhang Liu | 6987f2b | 2017-09-30 10:39:58 +0800 | [diff] [blame] | 857 | } |
Yinhang Liu | cff638b | 2017-09-25 21:16:28 +0800 | [diff] [blame] | 858 | |
Yinhang Liu | 6987f2b | 2017-09-30 10:39:58 +0800 | [diff] [blame] | 859 | if (need_display) { |
| 860 | #if HAVE_LIBDRM |
| 861 | if (DrmDisplay::set_preview (need_display)) { |
| 862 | device_manager->set_display_mode (display_mode); |
| 863 | cl_post_processor->set_output_format (V4L2_PIX_FMT_XBGR32); |
| 864 | } else { |
| 865 | need_display = false; |
| 866 | XCAM_LOG_WARNING ("set preview failed, disable local preview now"); |
| 867 | } |
| 868 | #else |
| 869 | XCAM_LOG_WARNING ("preview is not supported, disable preview now"); |
| 870 | need_display = false; |
| 871 | #endif |
| 872 | } |
Yinhang Liu | cff638b | 2017-09-25 21:16:28 +0800 | [diff] [blame] | 873 | device_manager->enable_display (need_display); |
| 874 | |
Yinhang Liu | b0ad64b | 2016-03-18 16:03:51 +0800 | [diff] [blame] | 875 | device_manager->add_image_processor (cl_post_processor); |
Yinhang Liu | 3c17fea | 2016-03-15 10:47:03 +0800 | [diff] [blame] | 876 | } |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 877 | #endif |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 878 | |
Jia Meng | 0a53293 | 2015-10-15 08:44:09 -0400 | [diff] [blame] | 879 | SmartPtr<PollThread> poll_thread; |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 880 | if (have_usbcam) { |
| 881 | poll_thread = new PollThread (); |
Wind Yuan | 2893591 | 2017-08-24 19:18:34 +0800 | [diff] [blame] | 882 | } else if (path_to_fake.c_str ()) { |
| 883 | poll_thread = new FakePollThread (path_to_fake.c_str ()); |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 884 | } |
| 885 | #if HAVE_IA_AIQ |
Yinhang Liu | e37a872 | 2016-06-27 18:14:35 +0800 | [diff] [blame] | 886 | else { |
| 887 | SmartPtr<IspPollThread> isp_poll_thread = new IspPollThread (); |
| 888 | isp_poll_thread->set_isp_controller (isp_controller); |
| 889 | poll_thread = isp_poll_thread; |
| 890 | } |
Yinhang Liu | 454a389 | 2016-11-07 16:30:35 +0800 | [diff] [blame] | 891 | #endif |
Jia Meng | 0a53293 | 2015-10-15 08:44:09 -0400 | [diff] [blame] | 892 | device_manager->set_poll_thread (poll_thread); |
| 893 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 894 | ret = device_manager->start (); |
| 895 | CHECK (ret, "device manager start failed"); |
| 896 | |
Yinhang Liu | c64ed59 | 2016-07-15 18:53:34 +0800 | [diff] [blame] | 897 | #if HAVE_LIBCL |
Jia Meng | 757f3c9 | 2015-09-09 11:18:36 +0800 | [diff] [blame] | 898 | // hard code exposure range and max gain for imx185 WDR |
Yinhang Liu | efe4f0f | 2016-12-29 13:17:22 +0800 | [diff] [blame] | 899 | if (wdr_mode != CL3aImageProcessor::WDRdisabled) { |
Jia Meng | 757f3c9 | 2015-09-09 11:18:36 +0800 | [diff] [blame] | 900 | if (frame_rate == 30) |
| 901 | analyzer->set_ae_exposure_time_range (80 * 1110 * 1000 / 37125, 1120 * 1110 * 1000 / 37125); |
| 902 | else |
Jia Meng | a658023 | 2015-10-08 16:51:28 +0800 | [diff] [blame] | 903 | analyzer->set_ae_exposure_time_range (80 * 1320 * 1000 / 37125, 1120 * 1320 * 1000 / 37125); |
Jia Meng | 757f3c9 | 2015-09-09 11:18:36 +0800 | [diff] [blame] | 904 | analyzer->set_ae_max_analog_gain (3.98); // 12dB |
| 905 | } |
Yinhang Liu | c64ed59 | 2016-07-15 18:53:34 +0800 | [diff] [blame] | 906 | #endif |
Jia Meng | 757f3c9 | 2015-09-09 11:18:36 +0800 | [diff] [blame] | 907 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 908 | // wait for interruption |
| 909 | { |
| 910 | SmartLock locker (g_mutex); |
| 911 | while (!g_stop) |
| 912 | g_cond.wait (g_mutex); |
| 913 | } |
| 914 | |
| 915 | ret = device_manager->stop(); |
| 916 | CHECK_CONTINUE (ret, "device manager stop failed"); |
| 917 | device->close (); |
Yinhang Liu | 5c1381c | 2016-11-19 16:35:38 +0800 | [diff] [blame] | 918 | #if HAVE_IA_AIQ |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 919 | event_device->close (); |
Yinhang Liu | 5c1381c | 2016-11-19 16:35:38 +0800 | [diff] [blame] | 920 | #endif |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 921 | |
| 922 | return 0; |
| 923 | } |