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