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> |
| 19 | */ |
| 20 | |
| 21 | #include "device_manager.h" |
| 22 | #include "atomisp_device.h" |
Sameer Kibey | 7b42929 | 2015-08-07 10:55:38 -0700 | [diff] [blame] | 23 | #include "uvc_device.h" |
Jia Meng | 0a53293 | 2015-10-15 08:44:09 -0400 | [diff] [blame] | 24 | #include "fake_v4l2_device.h" |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 25 | #include "isp_controller.h" |
| 26 | #include "isp_image_processor.h" |
| 27 | #include "x3a_analyzer_simple.h" |
| 28 | #if HAVE_IA_AIQ |
| 29 | #include "x3a_analyzer_aiq.h" |
| 30 | #endif |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 31 | #if HAVE_LIBCL |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 32 | #include "cl_3a_image_processor.h" |
Yinhang Liu | 2ab1f99 | 2016-03-15 10:41:17 +0800 | [diff] [blame] | 33 | #include "cl_post_image_processor.h" |
wangfei | cf4c4e7 | 2015-05-25 17:11:41 +0800 | [diff] [blame] | 34 | #include "cl_csc_image_processor.h" |
Yinhang Liu | 81c44e0 | 2015-06-03 15:47:48 +0800 | [diff] [blame] | 35 | #include "cl_hdr_handler.h" |
| 36 | #include "cl_tnr_handler.h" |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 37 | #endif |
| 38 | #if HAVE_LIBDRM |
| 39 | #include "drm_display.h" |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 40 | #endif |
zongwave | 03954a3 | 2015-09-22 15:40:44 +0800 | [diff] [blame] | 41 | #include "x3a_analyzer_loader.h" |
Jia Meng | 0a53293 | 2015-10-15 08:44:09 -0400 | [diff] [blame] | 42 | #include "poll_thread.h" |
| 43 | #include "fake_poll_thread.h" |
Jia Meng | 66efecf | 2015-06-17 11:11:10 +0000 | [diff] [blame] | 44 | #include <base/xcam_3a_types.h> |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 45 | #include <unistd.h> |
| 46 | #include <signal.h> |
| 47 | #include <stdlib.h> |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 48 | #include <string> |
Yinhang Liu | 81c44e0 | 2015-06-03 15:47:48 +0800 | [diff] [blame] | 49 | #include <getopt.h> |
John Ye | ae9da73 | 2015-01-22 13:36:36 +0800 | [diff] [blame] | 50 | #include "test_common.h" |
| 51 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 52 | using namespace XCam; |
| 53 | |
wujunkai166 | 82950fb | 2015-10-19 18:09:05 +0800 | [diff] [blame] | 54 | #define IMX185_WDR_CPF "/etc/atomisp/imx185_wdr.cpf" |
| 55 | |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 56 | static Mutex g_mutex; |
| 57 | static Cond g_cond; |
| 58 | static bool g_stop = false; |
| 59 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 60 | class MainDeviceManager |
| 61 | : public DeviceManager |
| 62 | { |
| 63 | public: |
| 64 | MainDeviceManager () |
| 65 | : _file (NULL) |
| 66 | , _save_file (false) |
| 67 | , _interval (1) |
Yinhang Liu | d934649 | 2015-12-17 11:14:25 +0800 | [diff] [blame] | 68 | , _frame_width (0) |
| 69 | , _frame_height (0) |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 70 | , _frame_count (0) |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 71 | , _frame_save (0) |
Wind Yuan | 683f866 | 2015-03-27 18:52:38 +0800 | [diff] [blame] | 72 | , _enable_display (false) |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 73 | { |
| 74 | #if HAVE_LIBDRM |
| 75 | _display = DrmDisplay::instance(); |
| 76 | #endif |
Wind Yuan | 9162580 | 2015-06-24 15:36:01 +0800 | [diff] [blame] | 77 | XCAM_OBJ_PROFILING_INIT; |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 78 | } |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 79 | |
| 80 | ~MainDeviceManager () { |
| 81 | close_file (); |
| 82 | } |
| 83 | |
| 84 | void enable_save_file (bool enable) { |
| 85 | _save_file = enable; |
| 86 | } |
Yinhang Liu | d934649 | 2015-12-17 11:14:25 +0800 | [diff] [blame] | 87 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 88 | void set_interval (uint32_t inteval) { |
| 89 | _interval = inteval; |
| 90 | } |
Yinhang Liu | d934649 | 2015-12-17 11:14:25 +0800 | [diff] [blame] | 91 | |
| 92 | void set_frame_width (uint32_t frame_width) { |
| 93 | _frame_width = frame_width; |
| 94 | } |
| 95 | |
| 96 | void set_frame_height (uint32_t frame_height) { |
| 97 | _frame_height = frame_height; |
| 98 | } |
| 99 | |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 100 | void set_frame_save (uint32_t frame_save) { |
| 101 | _frame_save = frame_save; |
| 102 | } |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 103 | |
Wind Yuan | 683f866 | 2015-03-27 18:52:38 +0800 | [diff] [blame] | 104 | void enable_display(bool value) { |
| 105 | _enable_display = value; |
| 106 | } |
| 107 | |
wangfei | cf4c4e7 | 2015-05-25 17:11:41 +0800 | [diff] [blame] | 108 | void set_display_mode(DrmDisplayMode mode) { |
| 109 | _display->set_display_mode (mode); |
| 110 | } |
| 111 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 112 | protected: |
Wind Yuan | 73af393 | 2015-07-02 17:52:43 +0800 | [diff] [blame] | 113 | virtual void handle_message (const SmartPtr<XCamMessage> &msg); |
| 114 | virtual void handle_buffer (const SmartPtr<VideoBuffer> &buf); |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 115 | |
Wind Yuan | 73af393 | 2015-07-02 17:52:43 +0800 | [diff] [blame] | 116 | int display_buf (const SmartPtr<VideoBuffer> &buf); |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 117 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 118 | private: |
| 119 | void open_file (); |
| 120 | void close_file (); |
Wind Yuan | 7111132 | 2016-02-24 22:56:27 +0800 | [diff] [blame] | 121 | XCamReturn write_buf (const SmartPtr<VideoBuffer> &buf); |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 122 | |
| 123 | FILE *_file; |
| 124 | bool _save_file; |
| 125 | uint32_t _interval; |
Yinhang Liu | d934649 | 2015-12-17 11:14:25 +0800 | [diff] [blame] | 126 | uint32_t _frame_width; |
| 127 | uint32_t _frame_height; |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 128 | uint32_t _frame_count; |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 129 | uint32_t _frame_save; |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 130 | SmartPtr<DrmDisplay> _display; |
Wind Yuan | 683f866 | 2015-03-27 18:52:38 +0800 | [diff] [blame] | 131 | bool _enable_display; |
Wind Yuan | 9162580 | 2015-06-24 15:36:01 +0800 | [diff] [blame] | 132 | XCAM_OBJ_PROFILING_DEFINES; |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | void |
Wind Yuan | 73af393 | 2015-07-02 17:52:43 +0800 | [diff] [blame] | 136 | MainDeviceManager::handle_message (const SmartPtr<XCamMessage> &msg) |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 137 | { |
| 138 | XCAM_UNUSED (msg); |
| 139 | } |
| 140 | |
| 141 | void |
Wind Yuan | 73af393 | 2015-07-02 17:52:43 +0800 | [diff] [blame] | 142 | MainDeviceManager::handle_buffer (const SmartPtr<VideoBuffer> &buf) |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 143 | { |
Wind Yuan | 683f866 | 2015-03-27 18:52:38 +0800 | [diff] [blame] | 144 | FPS_CALCULATION (fps_buf, 30); |
| 145 | |
Wind Yuan | 9162580 | 2015-06-24 15:36:01 +0800 | [diff] [blame] | 146 | XCAM_OBJ_PROFILING_START; |
| 147 | |
Wind Yuan | 683f866 | 2015-03-27 18:52:38 +0800 | [diff] [blame] | 148 | if (_enable_display) |
| 149 | display_buf (buf); |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 150 | |
Wind Yuan | 9162580 | 2015-06-24 15:36:01 +0800 | [diff] [blame] | 151 | XCAM_OBJ_PROFILING_END("main_dev_manager_display", 30); |
| 152 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 153 | if (!_save_file) |
| 154 | return ; |
| 155 | |
| 156 | if ((_frame_count++ % _interval) != 0) |
| 157 | return; |
| 158 | |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 159 | if ((_frame_save != 0) && (_frame_count > _frame_save)) { |
| 160 | SmartLock locker (g_mutex); |
| 161 | g_stop = true; |
| 162 | g_cond.broadcast (); |
| 163 | return; |
| 164 | } |
| 165 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 166 | open_file (); |
Jia Meng | 6c9241d | 2015-06-12 11:08:45 +0000 | [diff] [blame] | 167 | |
| 168 | if (!_file) { |
| 169 | XCAM_LOG_ERROR ("open file failed"); |
Jia Meng | 54a2dcb | 2015-08-20 15:23:47 +0800 | [diff] [blame] | 170 | return; |
Jia Meng | 6c9241d | 2015-06-12 11:08:45 +0000 | [diff] [blame] | 171 | } |
Wind Yuan | 7111132 | 2016-02-24 22:56:27 +0800 | [diff] [blame] | 172 | write_buf (buf); |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 173 | } |
| 174 | |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 175 | int |
Wind Yuan | 73af393 | 2015-07-02 17:52:43 +0800 | [diff] [blame] | 176 | MainDeviceManager::display_buf (const SmartPtr<VideoBuffer> &data) |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 177 | { |
| 178 | #if HAVE_LIBDRM |
| 179 | XCamReturn ret = XCAM_RETURN_NO_ERROR; |
Wind Yuan | 73af393 | 2015-07-02 17:52:43 +0800 | [diff] [blame] | 180 | SmartPtr<VideoBuffer> buf = data; |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 181 | const VideoBufferInfo & frame_info = buf->get_video_info (); |
| 182 | struct v4l2_rect rect = { 0, 0, (int)frame_info.width, (int)frame_info.height }; |
| 183 | |
| 184 | if (!_display->is_render_inited ()) { |
Yinhang Liu | d934649 | 2015-12-17 11:14:25 +0800 | [diff] [blame] | 185 | ret = _display->render_init (0, 0, this->_frame_width, this->_frame_height, |
| 186 | frame_info.format, &rect); |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 187 | CHECK (ret, "display failed on render_init"); |
| 188 | } |
| 189 | ret = _display->render_setup_frame_buffer (buf); |
| 190 | CHECK (ret, "display failed on framebuf set"); |
| 191 | ret = _display->render_buffer (buf); |
| 192 | CHECK (ret, "display failed on rendering"); |
| 193 | #endif |
| 194 | return 0; |
| 195 | } |
| 196 | |
| 197 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 198 | void |
| 199 | MainDeviceManager::open_file () |
| 200 | { |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 201 | if ((_file) && (_frame_save == 0)) |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 202 | return; |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 203 | |
| 204 | std::string file_name = DEFAULT_SAVE_FILE_NAME; |
| 205 | |
| 206 | if (_frame_save != 0) { |
| 207 | file_name += std::to_string(_frame_count); |
| 208 | } |
| 209 | file_name += ".raw"; |
| 210 | |
| 211 | _file = fopen(file_name.c_str(), "wb"); |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | void |
| 215 | MainDeviceManager::close_file () |
| 216 | { |
| 217 | if (_file) |
| 218 | fclose (_file); |
| 219 | _file = NULL; |
| 220 | } |
| 221 | |
Wind Yuan | 7111132 | 2016-02-24 22:56:27 +0800 | [diff] [blame] | 222 | XCamReturn |
| 223 | MainDeviceManager::write_buf (const SmartPtr<VideoBuffer> &buf) |
| 224 | { |
| 225 | const VideoBufferInfo &info = buf->get_video_info (); |
| 226 | VideoBufferPlanarInfo planar; |
| 227 | uint8_t *memory = NULL; |
| 228 | XCamReturn ret = XCAM_RETURN_NO_ERROR; |
| 229 | |
| 230 | memory = buf->map (); |
| 231 | if (!memory) { |
| 232 | XCAM_LOG_ERROR ("map buffer failed in write_buf"); |
| 233 | return XCAM_RETURN_ERROR_MEM; |
| 234 | } |
| 235 | |
| 236 | for (uint32_t index = 0; index < info.components; index++) { |
| 237 | info.get_planar_info (planar, index); |
| 238 | uint32_t line_bytes = planar.width * planar.pixel_bytes; |
| 239 | |
| 240 | for (uint32_t i = 0; i < planar.height; i++) { |
| 241 | if (fwrite (memory + info.offsets [index] + i * info.strides [index], 1, line_bytes, _file) != line_bytes) { |
| 242 | XCAM_LOG_ERROR ("write file failed, size doesn't match"); |
| 243 | ret = XCAM_RETURN_ERROR_FILE; |
| 244 | } |
| 245 | } |
| 246 | } |
| 247 | buf->unmap (); |
| 248 | return ret; |
| 249 | } |
| 250 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 251 | #define V4L2_CAPTURE_MODE_STILL 0x2000 |
| 252 | #define V4L2_CAPTURE_MODE_VIDEO 0x4000 |
| 253 | #define V4L2_CAPTURE_MODE_PREVIEW 0x8000 |
| 254 | |
Wind Yuan | 26e9e21 | 2015-04-16 15:55:45 +0800 | [diff] [blame] | 255 | typedef enum { |
| 256 | AnalyzerTypeSimple = 0, |
| 257 | AnalyzerTypeAiq, |
Wind Yuan | e25ce3f | 2015-05-04 18:07:29 +0800 | [diff] [blame] | 258 | AnalyzerTypeDynamic, |
Jia Meng | 9724cfe | 2015-08-12 15:04:45 +0800 | [diff] [blame] | 259 | AnalyzerTypeHybrid, |
Wind Yuan | 26e9e21 | 2015-04-16 15:55:45 +0800 | [diff] [blame] | 260 | } AnalyzerType; |
| 261 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 262 | void dev_stop_handler(int sig) |
| 263 | { |
| 264 | XCAM_UNUSED (sig); |
| 265 | |
| 266 | SmartLock locker (g_mutex); |
| 267 | g_stop = true; |
| 268 | g_cond.broadcast (); |
| 269 | |
| 270 | //exit(0); |
| 271 | } |
| 272 | |
| 273 | void print_help (const char *bin_name) |
| 274 | { |
| 275 | printf ("Usage: %s [-a analyzer]\n" |
Yinhang Liu | 81c44e0 | 2015-06-03 15:47:48 +0800 | [diff] [blame] | 276 | "Configurations:\n" |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 277 | "\t -a analyzer specify a analyzer\n" |
Wind Yuan | e25ce3f | 2015-05-04 18:07:29 +0800 | [diff] [blame] | 278 | "\t select from [simple, aiq, dynamic], default is [simple]\n" |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 279 | "\t -m mem_type specify video memory type\n" |
| 280 | "\t mem_type select from [dma, mmap], default is [mmap]\n" |
| 281 | "\t -s save file to %s\n" |
| 282 | "\t -n interval save file on every [interval] frame\n" |
Yinhang Liu | c2f1908 | 2015-08-28 12:27:48 +0800 | [diff] [blame] | 283 | #if HAVE_LIBCL |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 284 | "\t -c process image with cl kernel\n" |
Yinhang Liu | c2f1908 | 2015-08-28 12:27:48 +0800 | [diff] [blame] | 285 | #endif |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 286 | "\t -f pixel_fmt specify output pixel format\n" |
wujunkai166 | 9845b02 | 2015-08-27 15:59:27 +0800 | [diff] [blame] | 287 | "\t pixel_fmt select from [NV12, YUYV, BA10, BA12], default is [NV12]\n" |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 288 | "\t -d cap_mode specify capture mode\n" |
| 289 | "\t cap_mode select from [video, still], default is [video]\n" |
yaowang1 | a5f1212 | 2015-07-27 14:53:38 +0800 | [diff] [blame] | 290 | "\t -b brightness specify brightness level\n" |
| 291 | "\t brightness level select from [0, 256], default is [128]\n" |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 292 | "\t -i frame_save specify the frame count to save, default is 0 which means endless\n" |
wangfei | cf4c4e7 | 2015-05-25 17:11:41 +0800 | [diff] [blame] | 293 | "\t -p preview on local display\n" |
Sameer Kibey | 7b42929 | 2015-08-07 10:55:38 -0700 | [diff] [blame] | 294 | "\t --usb specify node for usb camera device, enables capture path through USB camera \n" |
| 295 | "\t specify [/dev/video4, /dev/video5] depending on which node USB camera is attached\n" |
Yinhang Liu | d934649 | 2015-12-17 11:14:25 +0800 | [diff] [blame] | 296 | "\t --resolution specify the resolution of usb camera\n" |
| 297 | "\t select from [1920x1080, 1280x720 ...], default is [1920x1080]\n" |
wangfei | cf4c4e7 | 2015-05-25 17:11:41 +0800 | [diff] [blame] | 298 | "\t -e display_mode preview mode\n" |
| 299 | "\t select from [primary, overlay], default is [primary]\n" |
Jia Meng | 8f94a10 | 2015-08-11 16:24:19 +0800 | [diff] [blame] | 300 | "\t --sync set analyzer in sync mode\n" |
Jia Meng | 0a53293 | 2015-10-15 08:44:09 -0400 | [diff] [blame] | 301 | "\t -r raw_input specify the path of raw image as fake source instead of live camera\n" |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 302 | "\t -h help\n" |
Yinhang Liu | c2f1908 | 2015-08-28 12:27:48 +0800 | [diff] [blame] | 303 | #if HAVE_LIBCL |
Yinhang Liu | 81c44e0 | 2015-06-03 15:47:48 +0800 | [diff] [blame] | 304 | "CL features:\n" |
wujunkai166 | a84ba05 | 2015-09-08 15:54:12 +0800 | [diff] [blame] | 305 | "\t --capture capture_stage specify the capture stage of image\n" |
| 306 | "\t capture_stage select from [bayer, tonemapping], default is [tonemapping]\n" |
Yinhang Liu | 81c44e0 | 2015-06-03 15:47:48 +0800 | [diff] [blame] | 307 | "\t --hdr specify hdr type, default is hdr off\n" |
| 308 | "\t select from [rgb, lab]\n" |
| 309 | "\t --tnr specify temporal noise reduction type, default is tnr off\n" |
| 310 | "\t select from [rgb, yuv, both]\n" |
| 311 | "\t --tnr-level specify tnr level\n" |
wujunkai166 | 06f7762 | 2016-03-18 14:41:10 +0800 | [diff] [blame^] | 312 | "\t --wdr-mode specify wdr mode. select from [gaussian, haleq]\n" |
Yinhang Liu | b92930c | 2015-06-23 16:26:35 +0800 | [diff] [blame] | 313 | "\t --bilateral enable bilateral noise reduction\n" |
Yinhang Liu | 81c44e0 | 2015-06-03 15:47:48 +0800 | [diff] [blame] | 314 | "\t --enable-snr enable simple noise reduction\n" |
Jia Meng | 66efecf | 2015-06-17 11:11:10 +0000 | [diff] [blame] | 315 | "\t --enable-ee enable YEENR\n" |
ShincyTu | 63e2c26 | 2015-06-26 10:52:51 +0800 | [diff] [blame] | 316 | "\t --enable-bnr enable bayer noise reduction\n" |
Yinhang Liu | e26b262 | 2015-07-21 18:32:36 +0800 | [diff] [blame] | 317 | "\t --enable-dpc enable defect pixel correction\n" |
Wangfei | 8e5e3e4 | 2016-02-18 19:41:54 +0800 | [diff] [blame] | 318 | "\t --enable-retinex enable retinex\n" |
zongwave | 2ba7f64 | 2016-03-15 19:24:12 +0800 | [diff] [blame] | 319 | "\t --wavelet-mode specify wavelet mode\n" |
Wangfei | 1487b9b | 2015-08-28 15:10:39 +0800 | [diff] [blame] | 320 | "\t --pipeline pipe mode\n" |
Wangfei | 16b65db | 2015-09-11 14:44:28 +0800 | [diff] [blame] | 321 | "\t select from [basic, advance, extreme], default is [basic]\n" |
Yinhang Liu | e26b262 | 2015-07-21 18:32:36 +0800 | [diff] [blame] | 322 | "(e.g.: xxxx --hdr=xx --tnr=xx --tnr-level=xx --bilateral --enable-snr --enable-ee --enable-bnr --enable-dpc)\n\n" |
Yinhang Liu | c2f1908 | 2015-08-28 12:27:48 +0800 | [diff] [blame] | 323 | #endif |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 324 | , bin_name |
| 325 | , DEFAULT_SAVE_FILE_NAME); |
| 326 | } |
| 327 | |
| 328 | int main (int argc, char *argv[]) |
| 329 | { |
| 330 | XCamReturn ret = XCAM_RETURN_NO_ERROR; |
| 331 | SmartPtr<MainDeviceManager> device_manager = new MainDeviceManager; |
| 332 | SmartPtr<V4l2Device> device; |
| 333 | SmartPtr<V4l2SubDevice> event_device; |
| 334 | SmartPtr<IspController> isp_controller; |
| 335 | SmartPtr<X3aAnalyzer> analyzer; |
zongwave | 03954a3 | 2015-09-22 15:40:44 +0800 | [diff] [blame] | 336 | SmartPtr<X3aAnalyzerLoader> loader; |
Jia Meng | 9724cfe | 2015-08-12 15:04:45 +0800 | [diff] [blame] | 337 | const char *path_of_3a; |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 338 | SmartPtr<ImageProcessor> isp_processor; |
Wind Yuan | 26e9e21 | 2015-04-16 15:55:45 +0800 | [diff] [blame] | 339 | AnalyzerType analyzer_type = AnalyzerTypeSimple; |
wangfei | cf4c4e7 | 2015-05-25 17:11:41 +0800 | [diff] [blame] | 340 | DrmDisplayMode display_mode = DRM_DISPLAY_MODE_PRIMARY; |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 341 | #if HAVE_LIBDRM |
| 342 | SmartPtr<DrmDisplay> drm_disp = DrmDisplay::instance(); |
| 343 | #endif |
| 344 | |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 345 | #if HAVE_LIBCL |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 346 | SmartPtr<CL3aImageProcessor> cl_processor; |
Yinhang Liu | 2ab1f99 | 2016-03-15 10:41:17 +0800 | [diff] [blame] | 347 | SmartPtr<CLPostImageProcessor> cl_post_processor; |
Yinhang Liu | c2f1908 | 2015-08-28 12:27:48 +0800 | [diff] [blame] | 348 | uint32_t hdr_type = CL_HDR_DISABLE; |
| 349 | uint32_t tnr_type = CL_TNR_DISABLE; |
| 350 | uint32_t denoise_type = 0; |
| 351 | uint8_t tnr_level = 0; |
| 352 | bool dpc_type = false; |
Wangfei | 1487b9b | 2015-08-28 15:10:39 +0800 | [diff] [blame] | 353 | CL3aImageProcessor::PipelineProfile pipeline_mode = CL3aImageProcessor::BasicPipelineProfile; |
wujunkai166 | a84ba05 | 2015-09-08 15:54:12 +0800 | [diff] [blame] | 354 | CL3aImageProcessor::CaptureStage capture_stage = CL3aImageProcessor::TonemappingStage; |
wujunkai166 | 06f7762 | 2016-03-18 14:41:10 +0800 | [diff] [blame^] | 355 | CL3aImageProcessor::CLTonemappingMode wdr_mode = CL3aImageProcessor::WDRdisabled; |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 356 | #endif |
| 357 | bool have_cl_processor = false; |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 358 | bool need_display = false; |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 359 | enum v4l2_memory v4l2_mem_type = V4L2_MEMORY_MMAP; |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 360 | const char *bin_name = argv[0]; |
| 361 | int opt; |
ShincyTu | 2808b59 | 2015-03-13 17:17:25 +0800 | [diff] [blame] | 362 | uint32_t capture_mode = V4L2_CAPTURE_MODE_VIDEO; |
| 363 | uint32_t pixel_format = V4L2_PIX_FMT_NV12; |
Jia Meng | a658023 | 2015-10-08 16:51:28 +0800 | [diff] [blame] | 364 | bool wdr_type = false; |
Wangfei | 8e5e3e4 | 2016-02-18 19:41:54 +0800 | [diff] [blame] | 365 | bool retinex_type = false; |
zongwave | 28a747b | 2016-03-17 12:49:08 +0800 | [diff] [blame] | 366 | CL3aImageProcessor::WaveletBasis wavelet_mode = CL3aImageProcessor::WaveletDisable; |
yaowang1 | a5f1212 | 2015-07-27 14:53:38 +0800 | [diff] [blame] | 367 | int32_t brightness_level = 128; |
Sameer Kibey | 7b42929 | 2015-08-07 10:55:38 -0700 | [diff] [blame] | 368 | bool have_usbcam = 0; |
Wind Yuan | 155c8f5 | 2016-03-18 23:16:59 +0800 | [diff] [blame] | 369 | SmartPtr<char> usb_device_name; |
Jia Meng | 8f94a10 | 2015-08-11 16:24:19 +0800 | [diff] [blame] | 370 | bool sync_mode = false; |
Jia Meng | 757f3c9 | 2015-09-09 11:18:36 +0800 | [diff] [blame] | 371 | int frame_rate; |
Yinhang Liu | d934649 | 2015-12-17 11:14:25 +0800 | [diff] [blame] | 372 | int frame_width = 1920; |
| 373 | int frame_height = 1080; |
Wind Yuan | 155c8f5 | 2016-03-18 23:16:59 +0800 | [diff] [blame] | 374 | SmartPtr<char> path_to_fake = NULL; |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 375 | |
Jia Meng | 0a53293 | 2015-10-15 08:44:09 -0400 | [diff] [blame] | 376 | const char *short_opts = "sca:n:m:f:d:b:pi:e:r:h"; |
Yinhang Liu | 81c44e0 | 2015-06-03 15:47:48 +0800 | [diff] [blame] | 377 | const struct option long_opts[] = { |
| 378 | {"hdr", required_argument, NULL, 'H'}, |
| 379 | {"tnr", required_argument, NULL, 'T'}, |
| 380 | {"tnr-level", required_argument, NULL, 'L'}, |
wujunkai166 | 06f7762 | 2016-03-18 14:41:10 +0800 | [diff] [blame^] | 381 | {"wdr-mode", required_argument, NULL, 'W'}, |
Yinhang Liu | b92930c | 2015-06-23 16:26:35 +0800 | [diff] [blame] | 382 | {"bilateral", no_argument, NULL, 'I'}, |
Yinhang Liu | 81c44e0 | 2015-06-03 15:47:48 +0800 | [diff] [blame] | 383 | {"enable-snr", no_argument, NULL, 'S'}, |
Jia Meng | 66efecf | 2015-06-17 11:11:10 +0000 | [diff] [blame] | 384 | {"enable-ee", no_argument, NULL, 'E'}, |
ShincyTu | 63e2c26 | 2015-06-26 10:52:51 +0800 | [diff] [blame] | 385 | {"enable-bnr", no_argument, NULL, 'B'}, |
Yinhang Liu | e26b262 | 2015-07-21 18:32:36 +0800 | [diff] [blame] | 386 | {"enable-dpc", no_argument, NULL, 'D'}, |
Wangfei | 8e5e3e4 | 2016-02-18 19:41:54 +0800 | [diff] [blame] | 387 | {"enable-retinex", no_argument, NULL, 'X'}, |
zongwave | 2ba7f64 | 2016-03-15 19:24:12 +0800 | [diff] [blame] | 388 | {"wavelet-mode", required_argument, NULL, 'V'}, |
Sameer Kibey | 7b42929 | 2015-08-07 10:55:38 -0700 | [diff] [blame] | 389 | {"usb", required_argument, NULL, 'U'}, |
Yinhang Liu | d934649 | 2015-12-17 11:14:25 +0800 | [diff] [blame] | 390 | {"resolution", required_argument, NULL, 'R'}, |
Jia Meng | 8f94a10 | 2015-08-11 16:24:19 +0800 | [diff] [blame] | 391 | {"sync", no_argument, NULL, 'Y'}, |
wujunkai166 | a84ba05 | 2015-09-08 15:54:12 +0800 | [diff] [blame] | 392 | {"capture", required_argument, NULL, 'C'}, |
Wangfei | 1487b9b | 2015-08-28 15:10:39 +0800 | [diff] [blame] | 393 | {"pipeline", required_argument, NULL, 'P'}, |
Yinhang Liu | 81c44e0 | 2015-06-03 15:47:48 +0800 | [diff] [blame] | 394 | {0, 0, 0, 0}, |
| 395 | }; |
| 396 | |
| 397 | while ((opt = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) { |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 398 | switch (opt) { |
| 399 | case 'a': { |
Wind Yuan | 6b43739 | 2016-02-02 00:31:30 +0800 | [diff] [blame] | 400 | XCAM_ASSERT (optarg); |
Wind Yuan | e25ce3f | 2015-05-04 18:07:29 +0800 | [diff] [blame] | 401 | if (!strcmp (optarg, "dynamic")) |
| 402 | analyzer_type = AnalyzerTypeDynamic; |
| 403 | else if (!strcmp (optarg, "simple")) |
Wind Yuan | 26e9e21 | 2015-04-16 15:55:45 +0800 | [diff] [blame] | 404 | analyzer_type = AnalyzerTypeSimple; |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 405 | #if HAVE_IA_AIQ |
| 406 | else if (!strcmp (optarg, "aiq")) |
Wind Yuan | 26e9e21 | 2015-04-16 15:55:45 +0800 | [diff] [blame] | 407 | analyzer_type = AnalyzerTypeAiq; |
Jia Meng | 9724cfe | 2015-08-12 15:04:45 +0800 | [diff] [blame] | 408 | else if (!strcmp (optarg, "hybrid")) |
| 409 | analyzer_type = AnalyzerTypeHybrid; |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 410 | #endif |
| 411 | else { |
| 412 | print_help (bin_name); |
| 413 | return -1; |
| 414 | } |
| 415 | break; |
| 416 | } |
| 417 | |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 418 | case 'm': { |
Wind Yuan | 6b43739 | 2016-02-02 00:31:30 +0800 | [diff] [blame] | 419 | XCAM_ASSERT (optarg); |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 420 | if (!strcmp (optarg, "dma")) |
| 421 | v4l2_mem_type = V4L2_MEMORY_DMABUF; |
| 422 | else if (!strcmp (optarg, "mmap")) |
| 423 | v4l2_mem_type = V4L2_MEMORY_MMAP; |
| 424 | else |
| 425 | print_help (bin_name); |
| 426 | break; |
| 427 | } |
| 428 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 429 | case 's': |
| 430 | device_manager->enable_save_file (true); |
| 431 | break; |
| 432 | case 'n': |
| 433 | device_manager->set_interval (atoi(optarg)); |
| 434 | break; |
Yinhang Liu | c2f1908 | 2015-08-28 12:27:48 +0800 | [diff] [blame] | 435 | #if HAVE_LIBCL |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 436 | case 'c': |
| 437 | have_cl_processor = true; |
| 438 | break; |
Yinhang Liu | c2f1908 | 2015-08-28 12:27:48 +0800 | [diff] [blame] | 439 | #endif |
ShincyTu | 2808b59 | 2015-03-13 17:17:25 +0800 | [diff] [blame] | 440 | case 'f': |
ShincyTu | c846640 | 2015-03-31 11:03:39 +0800 | [diff] [blame] | 441 | CHECK_EXP ((strlen(optarg) == 4), "invalid pixel format\n"); |
| 442 | pixel_format = v4l2_fourcc ((unsigned)optarg[0], |
| 443 | (unsigned)optarg[1], |
| 444 | (unsigned)optarg[2], |
| 445 | (unsigned)optarg[3]); |
ShincyTu | 2808b59 | 2015-03-13 17:17:25 +0800 | [diff] [blame] | 446 | break; |
| 447 | case 'd': |
Wind Yuan | 6b43739 | 2016-02-02 00:31:30 +0800 | [diff] [blame] | 448 | XCAM_ASSERT (optarg); |
ShincyTu | 2808b59 | 2015-03-13 17:17:25 +0800 | [diff] [blame] | 449 | if (!strcmp (optarg, "still")) |
| 450 | capture_mode = V4L2_CAPTURE_MODE_STILL; |
| 451 | else if (!strcmp (optarg, "video")) |
| 452 | capture_mode = V4L2_CAPTURE_MODE_VIDEO; |
| 453 | else { |
| 454 | print_help (bin_name); |
| 455 | return -1; |
| 456 | } |
| 457 | break; |
yaowang1 | a5f1212 | 2015-07-27 14:53:38 +0800 | [diff] [blame] | 458 | case 'b': |
| 459 | brightness_level = atoi(optarg); |
| 460 | if(brightness_level < 0 || brightness_level > 256) { |
| 461 | print_help (bin_name); |
| 462 | return -1; |
| 463 | } |
| 464 | break; |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 465 | case 'p': |
| 466 | need_display = true; |
| 467 | break; |
Sameer Kibey | 7b42929 | 2015-08-07 10:55:38 -0700 | [diff] [blame] | 468 | case 'U': |
| 469 | have_usbcam = true; |
Wind Yuan | 155c8f5 | 2016-03-18 23:16:59 +0800 | [diff] [blame] | 470 | usb_device_name = strndup(optarg, XCAM_MAX_STR_SIZE); |
| 471 | XCAM_LOG_DEBUG("using USB camera plugged in at node: %s", XCAM_STR(usb_device_name.ptr ())); |
Sameer Kibey | 7b42929 | 2015-08-07 10:55:38 -0700 | [diff] [blame] | 472 | break; |
Yinhang Liu | d934649 | 2015-12-17 11:14:25 +0800 | [diff] [blame] | 473 | case 'R': |
Wind Yuan | 6b43739 | 2016-02-02 00:31:30 +0800 | [diff] [blame] | 474 | XCAM_ASSERT (optarg); |
Yinhang Liu | d934649 | 2015-12-17 11:14:25 +0800 | [diff] [blame] | 475 | sscanf (optarg, "%d%*c%d", &frame_width, &frame_height); |
| 476 | break; |
wangfei | cf4c4e7 | 2015-05-25 17:11:41 +0800 | [diff] [blame] | 477 | case 'e': { |
Wind Yuan | 6b43739 | 2016-02-02 00:31:30 +0800 | [diff] [blame] | 478 | XCAM_ASSERT (optarg); |
wangfei | cf4c4e7 | 2015-05-25 17:11:41 +0800 | [diff] [blame] | 479 | if (!strcmp (optarg, "primary")) |
| 480 | display_mode = DRM_DISPLAY_MODE_PRIMARY; |
| 481 | else if (!strcmp (optarg, "overlay")) |
| 482 | display_mode = DRM_DISPLAY_MODE_OVERLAY; |
| 483 | else { |
| 484 | print_help (bin_name); |
| 485 | return -1; |
| 486 | } |
| 487 | break; |
| 488 | } |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 489 | case 'i': |
| 490 | device_manager->set_frame_save(atoi(optarg)); |
| 491 | break; |
Jia Meng | 8f94a10 | 2015-08-11 16:24:19 +0800 | [diff] [blame] | 492 | case 'Y': |
| 493 | sync_mode = true; |
| 494 | break; |
Yinhang Liu | c2f1908 | 2015-08-28 12:27:48 +0800 | [diff] [blame] | 495 | #if HAVE_LIBCL |
Yinhang Liu | 81c44e0 | 2015-06-03 15:47:48 +0800 | [diff] [blame] | 496 | case 'H': { |
Wind Yuan | 6b43739 | 2016-02-02 00:31:30 +0800 | [diff] [blame] | 497 | XCAM_ASSERT (optarg); |
Yinhang Liu | 81c44e0 | 2015-06-03 15:47:48 +0800 | [diff] [blame] | 498 | if (!strcasecmp (optarg, "rgb")) |
| 499 | hdr_type = CL_HDR_TYPE_RGB; |
| 500 | else if (!strcasecmp (optarg, "lab")) |
| 501 | hdr_type = CL_HDR_TYPE_LAB; |
| 502 | else { |
| 503 | print_help (bin_name); |
| 504 | return -1; |
| 505 | } |
| 506 | break; |
| 507 | } |
Yinhang Liu | b92930c | 2015-06-23 16:26:35 +0800 | [diff] [blame] | 508 | case 'I': { |
Jia Meng | 66efecf | 2015-06-17 11:11:10 +0000 | [diff] [blame] | 509 | denoise_type |= XCAM_DENOISE_TYPE_BILATERAL; |
Juan Zhao | d966493 | 2015-09-08 10:22:19 +0800 | [diff] [blame] | 510 | denoise_type |= XCAM_DENOISE_TYPE_BIYUV; |
Yinhang Liu | 81c44e0 | 2015-06-03 15:47:48 +0800 | [diff] [blame] | 511 | break; |
| 512 | } |
| 513 | case 'S': { |
Jia Meng | 66efecf | 2015-06-17 11:11:10 +0000 | [diff] [blame] | 514 | denoise_type |= XCAM_DENOISE_TYPE_SIMPLE; |
| 515 | break; |
| 516 | } |
| 517 | case 'E': { |
| 518 | denoise_type |= XCAM_DENOISE_TYPE_EE; |
Yinhang Liu | 81c44e0 | 2015-06-03 15:47:48 +0800 | [diff] [blame] | 519 | break; |
| 520 | } |
ShincyTu | 63e2c26 | 2015-06-26 10:52:51 +0800 | [diff] [blame] | 521 | case 'B': { |
| 522 | denoise_type |= XCAM_DENOISE_TYPE_BNR; |
| 523 | break; |
| 524 | } |
Wangfei | 8e5e3e4 | 2016-02-18 19:41:54 +0800 | [diff] [blame] | 525 | case 'X': { |
| 526 | retinex_type = true; |
| 527 | break; |
| 528 | } |
zongwave | 80adcf5 | 2016-02-29 12:38:06 +0800 | [diff] [blame] | 529 | case 'V': { |
zongwave | 2ba7f64 | 2016-03-15 19:24:12 +0800 | [diff] [blame] | 530 | XCAM_ASSERT (optarg); |
| 531 | if (atoi(optarg) < 0 || atoi(optarg) > 255) { |
| 532 | print_help (bin_name); |
| 533 | return -1; |
| 534 | } |
zongwave | 28a747b | 2016-03-17 12:49:08 +0800 | [diff] [blame] | 535 | if (atoi(optarg) == 1) { |
| 536 | wavelet_mode = CL3aImageProcessor::HatWavelet; |
| 537 | } else if (atoi(optarg) == 2) { |
| 538 | wavelet_mode = CL3aImageProcessor::HaarWavelet; |
| 539 | } else { |
| 540 | wavelet_mode = CL3aImageProcessor::WaveletDisable; |
| 541 | } |
zongwave | 80adcf5 | 2016-02-29 12:38:06 +0800 | [diff] [blame] | 542 | break; |
| 543 | } |
Yinhang Liu | e26b262 | 2015-07-21 18:32:36 +0800 | [diff] [blame] | 544 | case 'D': { |
| 545 | dpc_type = true; |
| 546 | break; |
| 547 | } |
Yinhang Liu | 81c44e0 | 2015-06-03 15:47:48 +0800 | [diff] [blame] | 548 | case 'T': { |
Wind Yuan | 6b43739 | 2016-02-02 00:31:30 +0800 | [diff] [blame] | 549 | XCAM_ASSERT (optarg); |
Yinhang Liu | 81c44e0 | 2015-06-03 15:47:48 +0800 | [diff] [blame] | 550 | if (!strcasecmp (optarg, "yuv")) |
| 551 | tnr_type = CL_TNR_TYPE_YUV; |
| 552 | else if (!strcasecmp (optarg, "rgb")) |
| 553 | tnr_type = CL_TNR_TYPE_RGB; |
| 554 | else if (!strcasecmp (optarg, "both")) |
| 555 | tnr_type = CL_TNR_TYPE_YUV | CL_TNR_TYPE_RGB; |
| 556 | else { |
| 557 | print_help (bin_name); |
| 558 | return -1; |
| 559 | } |
| 560 | break; |
| 561 | } |
| 562 | case 'L': { |
Wind Yuan | 6b43739 | 2016-02-02 00:31:30 +0800 | [diff] [blame] | 563 | XCAM_ASSERT (optarg); |
Yinhang Liu | 81c44e0 | 2015-06-03 15:47:48 +0800 | [diff] [blame] | 564 | if (atoi(optarg) < 0 || atoi(optarg) > 255) { |
| 565 | print_help (bin_name); |
| 566 | return -1; |
| 567 | } |
| 568 | tnr_level = atoi(optarg); |
| 569 | break; |
| 570 | } |
Jia Meng | a658023 | 2015-10-08 16:51:28 +0800 | [diff] [blame] | 571 | case 'W': { |
wujunkai166 | 06f7762 | 2016-03-18 14:41:10 +0800 | [diff] [blame^] | 572 | XCAM_ASSERT (optarg); |
| 573 | if (!strcasecmp (optarg, "gaussian")) |
| 574 | wdr_mode = CL3aImageProcessor::Gaussian; |
| 575 | else if (!strcasecmp (optarg, "haleq")) |
| 576 | wdr_mode = CL3aImageProcessor::Haleq; |
wujunkai166 | 82950fb | 2015-10-19 18:09:05 +0800 | [diff] [blame] | 577 | |
wujunkai166 | b0bd551 | 2016-02-18 18:25:42 +0800 | [diff] [blame] | 578 | pixel_format = V4L2_PIX_FMT_SGRBG12; |
wujunkai166 | 06f7762 | 2016-03-18 14:41:10 +0800 | [diff] [blame^] | 579 | wdr_type = true; |
wujunkai166 | b0bd551 | 2016-02-18 18:25:42 +0800 | [diff] [blame] | 580 | setenv ("AIQ_CPF_PATH", IMX185_WDR_CPF, 1); |
| 581 | break; |
| 582 | } |
Wangfei | 1487b9b | 2015-08-28 15:10:39 +0800 | [diff] [blame] | 583 | case 'P': { |
Wind Yuan | 6b43739 | 2016-02-02 00:31:30 +0800 | [diff] [blame] | 584 | XCAM_ASSERT (optarg); |
Wangfei | 1487b9b | 2015-08-28 15:10:39 +0800 | [diff] [blame] | 585 | if (!strcasecmp (optarg, "basic")) |
| 586 | pipeline_mode = CL3aImageProcessor::BasicPipelineProfile; |
| 587 | else if (!strcasecmp (optarg, "advance")) |
| 588 | pipeline_mode = CL3aImageProcessor::AdvancedPipelineProfile; |
Wangfei | 16b65db | 2015-09-11 14:44:28 +0800 | [diff] [blame] | 589 | else if (!strcasecmp (optarg, "extreme")) |
| 590 | pipeline_mode = CL3aImageProcessor::ExtremePipelineProfile; |
Wangfei | 1487b9b | 2015-08-28 15:10:39 +0800 | [diff] [blame] | 591 | else { |
| 592 | print_help (bin_name); |
| 593 | return -1; |
| 594 | } |
| 595 | break; |
| 596 | } |
wujunkai166 | a84ba05 | 2015-09-08 15:54:12 +0800 | [diff] [blame] | 597 | case 'C': { |
Wind Yuan | 6b43739 | 2016-02-02 00:31:30 +0800 | [diff] [blame] | 598 | XCAM_ASSERT (optarg); |
wujunkai166 | a84ba05 | 2015-09-08 15:54:12 +0800 | [diff] [blame] | 599 | if (!strcmp (optarg, "bayer")) |
| 600 | capture_stage = CL3aImageProcessor::BasicbayerStage; |
| 601 | break; |
| 602 | } |
Yinhang Liu | c2f1908 | 2015-08-28 12:27:48 +0800 | [diff] [blame] | 603 | #endif |
Jia Meng | 0a53293 | 2015-10-15 08:44:09 -0400 | [diff] [blame] | 604 | case 'r': { |
| 605 | if (optarg) { |
| 606 | XCAM_LOG_INFO ("use raw image %s as input source", optarg); |
Wind Yuan | 155c8f5 | 2016-03-18 23:16:59 +0800 | [diff] [blame] | 607 | path_to_fake = strndup(optarg, XCAM_MAX_STR_SIZE); |
Jia Meng | 0a53293 | 2015-10-15 08:44:09 -0400 | [diff] [blame] | 608 | } |
| 609 | break; |
| 610 | } |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 611 | case 'h': |
| 612 | print_help (bin_name); |
| 613 | return 0; |
| 614 | |
| 615 | default: |
| 616 | print_help (bin_name); |
| 617 | return -1; |
| 618 | } |
| 619 | } |
| 620 | |
Yinhang Liu | d934649 | 2015-12-17 11:14:25 +0800 | [diff] [blame] | 621 | device_manager->set_frame_width(frame_width); |
| 622 | device_manager->set_frame_height(frame_height); |
wangfei | cf4c4e7 | 2015-05-25 17:11:41 +0800 | [diff] [blame] | 623 | if (need_display) { |
Wind Yuan | 683f866 | 2015-03-27 18:52:38 +0800 | [diff] [blame] | 624 | device_manager->enable_display (true); |
wangfei | cf4c4e7 | 2015-05-25 17:11:41 +0800 | [diff] [blame] | 625 | device_manager->set_display_mode (display_mode); |
| 626 | } |
ShincyTu | 2808b59 | 2015-03-13 17:17:25 +0800 | [diff] [blame] | 627 | if (!device.ptr ()) { |
Wind Yuan | 155c8f5 | 2016-03-18 23:16:59 +0800 | [diff] [blame] | 628 | if (path_to_fake.ptr ()) { |
Jia Meng | 0a53293 | 2015-10-15 08:44:09 -0400 | [diff] [blame] | 629 | device = new FakeV4l2Device (); |
| 630 | } else if (have_usbcam) { |
Wind Yuan | 155c8f5 | 2016-03-18 23:16:59 +0800 | [diff] [blame] | 631 | device = new UVCDevice (usb_device_name.ptr ()); |
Sameer Kibey | 7b42929 | 2015-08-07 10:55:38 -0700 | [diff] [blame] | 632 | } else { |
| 633 | if (capture_mode == V4L2_CAPTURE_MODE_STILL) |
| 634 | device = new AtomispDevice (CAPTURE_DEVICE_STILL); |
| 635 | else if (capture_mode == V4L2_CAPTURE_MODE_VIDEO) |
| 636 | device = new AtomispDevice (CAPTURE_DEVICE_VIDEO); |
| 637 | else |
| 638 | device = new AtomispDevice (DEFAULT_CAPTURE_DEVICE); |
| 639 | } |
ShincyTu | 2808b59 | 2015-03-13 17:17:25 +0800 | [diff] [blame] | 640 | } |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 641 | if (!event_device.ptr ()) |
| 642 | event_device = new V4l2SubDevice (DEFAULT_EVENT_DEVICE); |
| 643 | if (!isp_controller.ptr ()) |
| 644 | isp_controller = new IspController (device); |
Wind Yuan | 26e9e21 | 2015-04-16 15:55:45 +0800 | [diff] [blame] | 645 | |
| 646 | switch (analyzer_type) { |
Wind Yuan | 3d1d15e | 2015-04-16 17:40:47 +0800 | [diff] [blame] | 647 | case AnalyzerTypeSimple: |
| 648 | analyzer = new X3aAnalyzerSimple (); |
| 649 | break; |
Wind Yuan | 26e9e21 | 2015-04-16 15:55:45 +0800 | [diff] [blame] | 650 | #if HAVE_IA_AIQ |
Wind Yuan | 3d1d15e | 2015-04-16 17:40:47 +0800 | [diff] [blame] | 651 | case AnalyzerTypeAiq: |
| 652 | analyzer = new X3aAnalyzerAiq (isp_controller, DEFAULT_CPF_FILE); |
| 653 | break; |
Jia Meng | 9724cfe | 2015-08-12 15:04:45 +0800 | [diff] [blame] | 654 | case AnalyzerTypeHybrid: { |
Jia Meng | c54c332 | 2015-08-26 09:45:18 +0800 | [diff] [blame] | 655 | path_of_3a = DEFAULT_HYBRID_3A_LIB; |
zongwave | 03954a3 | 2015-09-22 15:40:44 +0800 | [diff] [blame] | 656 | loader = new X3aAnalyzerLoader (path_of_3a); |
Jia Meng | 9724cfe | 2015-08-12 15:04:45 +0800 | [diff] [blame] | 657 | analyzer = loader->load_hybrid_analyzer (loader, isp_controller, DEFAULT_CPF_FILE); |
| 658 | CHECK_EXP (analyzer.ptr (), "load hybrid 3a lib(%s) failed", path_of_3a); |
| 659 | break; |
| 660 | } |
Wind Yuan | 26e9e21 | 2015-04-16 15:55:45 +0800 | [diff] [blame] | 661 | #endif |
Wind Yuan | e25ce3f | 2015-05-04 18:07:29 +0800 | [diff] [blame] | 662 | case AnalyzerTypeDynamic: { |
Jia Meng | 9724cfe | 2015-08-12 15:04:45 +0800 | [diff] [blame] | 663 | path_of_3a = DEFAULT_DYNAMIC_3A_LIB; |
zongwave | 03954a3 | 2015-09-22 15:40:44 +0800 | [diff] [blame] | 664 | loader = new X3aAnalyzerLoader (path_of_3a); |
Jia Meng | 9724cfe | 2015-08-12 15:04:45 +0800 | [diff] [blame] | 665 | analyzer = loader->load_dynamic_analyzer (loader); |
Wind Yuan | e25ce3f | 2015-05-04 18:07:29 +0800 | [diff] [blame] | 666 | CHECK_EXP (analyzer.ptr (), "load dynamic 3a lib(%s) failed", path_of_3a); |
| 667 | break; |
| 668 | } |
Wind Yuan | 3d1d15e | 2015-04-16 17:40:47 +0800 | [diff] [blame] | 669 | default: |
| 670 | print_help (bin_name); |
| 671 | return -1; |
Wind Yuan | 26e9e21 | 2015-04-16 15:55:45 +0800 | [diff] [blame] | 672 | } |
Jia Meng | 8f94a10 | 2015-08-11 16:24:19 +0800 | [diff] [blame] | 673 | XCAM_ASSERT (analyzer.ptr ()); |
| 674 | analyzer->set_sync_mode (sync_mode); |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 675 | |
| 676 | signal(SIGINT, dev_stop_handler); |
| 677 | |
| 678 | device->set_sensor_id (0); |
ShincyTu | 2808b59 | 2015-03-13 17:17:25 +0800 | [diff] [blame] | 679 | device->set_capture_mode (capture_mode); |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 680 | //device->set_mem_type (V4L2_MEMORY_DMABUF); |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 681 | device->set_mem_type (v4l2_mem_type); |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 682 | device->set_buffer_count (8); |
Jia Meng | 757f3c9 | 2015-09-09 11:18:36 +0800 | [diff] [blame] | 683 | if (pixel_format == V4L2_PIX_FMT_SGRBG12) { |
| 684 | frame_rate = 30; |
| 685 | device->set_framerate (frame_rate, 1); |
| 686 | } |
| 687 | else { |
| 688 | frame_rate = 25; |
| 689 | device->set_framerate (frame_rate, 1); |
wujunkai166 | 06f7762 | 2016-03-18 14:41:10 +0800 | [diff] [blame^] | 690 | if(wdr_type == true) { |
wujunkai166 | a9a55f2 | 2015-10-10 15:53:32 +0800 | [diff] [blame] | 691 | XCAM_LOG_WARNING("Tonemapping is only applicable under BA12 format. Disable tonemapping automatically."); |
wujunkai166 | 06f7762 | 2016-03-18 14:41:10 +0800 | [diff] [blame^] | 692 | wdr_type = false; |
wujunkai166 | a9a55f2 | 2015-10-10 15:53:32 +0800 | [diff] [blame] | 693 | } |
Jia Meng | 757f3c9 | 2015-09-09 11:18:36 +0800 | [diff] [blame] | 694 | } |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 695 | ret = device->open (); |
| 696 | CHECK (ret, "device(%s) open failed", device->get_device_name()); |
Yinhang Liu | d934649 | 2015-12-17 11:14:25 +0800 | [diff] [blame] | 697 | 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] | 698 | CHECK (ret, "device(%s) set format failed", device->get_device_name()); |
| 699 | |
| 700 | ret = event_device->open (); |
Wind Yuan | b67045c | 2015-08-27 13:50:53 +0800 | [diff] [blame] | 701 | if (ret == XCAM_RETURN_NO_ERROR) { |
| 702 | CHECK (ret, "event device(%s) open failed", event_device->get_device_name()); |
| 703 | int event = V4L2_EVENT_ATOMISP_3A_STATS_READY; |
| 704 | ret = event_device->subscribe_event (event); |
| 705 | CHECK_CONTINUE ( |
| 706 | ret, |
| 707 | "device(%s) subscribe event(%d) failed", |
| 708 | event_device->get_device_name(), event); |
| 709 | event = V4L2_EVENT_FRAME_SYNC; |
| 710 | ret = event_device->subscribe_event (event); |
| 711 | CHECK_CONTINUE ( |
| 712 | ret, |
| 713 | "device(%s) subscribe event(%d) failed", |
| 714 | event_device->get_device_name(), event); |
| 715 | |
| 716 | device_manager->set_event_device (event_device); |
| 717 | } |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 718 | |
| 719 | device_manager->set_capture_device (device); |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 720 | device_manager->set_isp_controller (isp_controller); |
| 721 | if (analyzer.ptr()) |
zongwave | 03954a3 | 2015-09-22 15:40:44 +0800 | [diff] [blame] | 722 | device_manager->set_3a_analyzer (analyzer); |
Wind Yuan | 3d1d15e | 2015-04-16 17:40:47 +0800 | [diff] [blame] | 723 | |
| 724 | if (have_cl_processor) |
| 725 | isp_processor = new IspExposureImageProcessor (isp_controller); |
| 726 | else |
| 727 | isp_processor = new IspImageProcessor (isp_controller); |
| 728 | |
| 729 | XCAM_ASSERT (isp_processor.ptr ()); |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 730 | device_manager->add_image_processor (isp_processor); |
Yinhang Liu | c2f1908 | 2015-08-28 12:27:48 +0800 | [diff] [blame] | 731 | #if HAVE_LIBCL |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 732 | if (have_cl_processor) { |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 733 | cl_processor = new CL3aImageProcessor (); |
Wind Yuan | 7ddf260 | 2015-04-14 18:49:45 +0800 | [diff] [blame] | 734 | cl_processor->set_stats_callback(device_manager); |
Yinhang Liu | e26b262 | 2015-07-21 18:32:36 +0800 | [diff] [blame] | 735 | cl_processor->set_dpc(dpc_type); |
Yinhang Liu | 81c44e0 | 2015-06-03 15:47:48 +0800 | [diff] [blame] | 736 | cl_processor->set_hdr (hdr_type); |
Jia Meng | 66efecf | 2015-06-17 11:11:10 +0000 | [diff] [blame] | 737 | cl_processor->set_denoise (denoise_type); |
wujunkai166 | 06f7762 | 2016-03-18 14:41:10 +0800 | [diff] [blame^] | 738 | cl_processor->set_tonemapping(wdr_mode); |
Jia Meng | a658023 | 2015-10-08 16:51:28 +0800 | [diff] [blame] | 739 | cl_processor->set_gamma (!wdr_type); // disable gamma for WDR |
zongwave | 28a747b | 2016-03-17 12:49:08 +0800 | [diff] [blame] | 740 | cl_processor->set_wavelet (wavelet_mode); |
wujunkai166 | a84ba05 | 2015-09-08 15:54:12 +0800 | [diff] [blame] | 741 | cl_processor->set_capture_stage (capture_stage); |
wujunkai166 | c8f3b44 | 2016-02-29 17:12:09 +0800 | [diff] [blame] | 742 | |
| 743 | if (wdr_type) { |
| 744 | cl_processor->set_3a_stats_bits(12); |
| 745 | } |
Yinhang Liu | 81c44e0 | 2015-06-03 15:47:48 +0800 | [diff] [blame] | 746 | cl_processor->set_tnr (tnr_type, tnr_level); |
Wangfei | 1487b9b | 2015-08-28 15:10:39 +0800 | [diff] [blame] | 747 | cl_processor->set_profile (pipeline_mode); |
yaowang1 | a5f1212 | 2015-07-27 14:53:38 +0800 | [diff] [blame] | 748 | analyzer->set_parameter_brightness((brightness_level - 128) / 128.0); |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 749 | device_manager->add_image_processor (cl_processor); |
| 750 | } |
Yinhang Liu | 3c17fea | 2016-03-15 10:47:03 +0800 | [diff] [blame] | 751 | |
| 752 | cl_post_processor = new CLPostImageProcessor (); |
Yinhang Liu | 3c721c1 | 2016-03-15 15:03:51 +0800 | [diff] [blame] | 753 | |
| 754 | cl_post_processor->set_retinex (retinex_type); |
| 755 | |
Yinhang Liu | 3c17fea | 2016-03-15 10:47:03 +0800 | [diff] [blame] | 756 | if ((display_mode == DRM_DISPLAY_MODE_PRIMARY) && need_display) { |
| 757 | cl_post_processor->set_output_format (V4L2_PIX_FMT_XBGR32); |
| 758 | } |
| 759 | device_manager->add_image_processor (cl_post_processor); |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 760 | #endif |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 761 | |
Jia Meng | 0a53293 | 2015-10-15 08:44:09 -0400 | [diff] [blame] | 762 | SmartPtr<PollThread> poll_thread; |
Wind Yuan | 155c8f5 | 2016-03-18 23:16:59 +0800 | [diff] [blame] | 763 | if (path_to_fake.ptr ()) |
| 764 | poll_thread = new FakePollThread (path_to_fake.ptr ()); |
Jia Meng | 0a53293 | 2015-10-15 08:44:09 -0400 | [diff] [blame] | 765 | else |
| 766 | poll_thread = new PollThread (); |
| 767 | device_manager->set_poll_thread (poll_thread); |
| 768 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 769 | ret = device_manager->start (); |
| 770 | CHECK (ret, "device manager start failed"); |
| 771 | |
Jia Meng | 757f3c9 | 2015-09-09 11:18:36 +0800 | [diff] [blame] | 772 | // hard code exposure range and max gain for imx185 WDR |
Jia Meng | a658023 | 2015-10-08 16:51:28 +0800 | [diff] [blame] | 773 | if (wdr_type) { |
Jia Meng | 757f3c9 | 2015-09-09 11:18:36 +0800 | [diff] [blame] | 774 | if (frame_rate == 30) |
| 775 | analyzer->set_ae_exposure_time_range (80 * 1110 * 1000 / 37125, 1120 * 1110 * 1000 / 37125); |
| 776 | else |
Jia Meng | a658023 | 2015-10-08 16:51:28 +0800 | [diff] [blame] | 777 | 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] | 778 | analyzer->set_ae_max_analog_gain (3.98); // 12dB |
| 779 | } |
| 780 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 781 | // wait for interruption |
| 782 | { |
| 783 | SmartLock locker (g_mutex); |
| 784 | while (!g_stop) |
| 785 | g_cond.wait (g_mutex); |
| 786 | } |
| 787 | |
| 788 | ret = device_manager->stop(); |
| 789 | CHECK_CONTINUE (ret, "device manager stop failed"); |
| 790 | device->close (); |
| 791 | event_device->close (); |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 792 | |
| 793 | return 0; |
| 794 | } |