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" |
| 23 | #include "isp_controller.h" |
| 24 | #include "isp_image_processor.h" |
| 25 | #include "x3a_analyzer_simple.h" |
| 26 | #if HAVE_IA_AIQ |
| 27 | #include "x3a_analyzer_aiq.h" |
| 28 | #endif |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 29 | #if HAVE_LIBCL |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 30 | #include "cl_3a_image_processor.h" |
wangfei | cf4c4e7 | 2015-05-25 17:11:41 +0800 | [diff] [blame] | 31 | #include "cl_csc_image_processor.h" |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 32 | #endif |
| 33 | #if HAVE_LIBDRM |
| 34 | #include "drm_display.h" |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 35 | #endif |
Wind Yuan | e25ce3f | 2015-05-04 18:07:29 +0800 | [diff] [blame] | 36 | #include "analyzer_loader.h" |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 37 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 38 | #include <unistd.h> |
| 39 | #include <signal.h> |
| 40 | #include <stdlib.h> |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 41 | #include <string> |
John Ye | ae9da73 | 2015-01-22 13:36:36 +0800 | [diff] [blame] | 42 | #include "test_common.h" |
| 43 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 44 | using namespace XCam; |
| 45 | |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 46 | static Mutex g_mutex; |
| 47 | static Cond g_cond; |
| 48 | static bool g_stop = false; |
| 49 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 50 | class MainDeviceManager |
| 51 | : public DeviceManager |
| 52 | { |
| 53 | public: |
| 54 | MainDeviceManager () |
| 55 | : _file (NULL) |
| 56 | , _save_file (false) |
| 57 | , _interval (1) |
| 58 | , _frame_count (0) |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 59 | , _frame_save (0) |
Wind Yuan | 683f866 | 2015-03-27 18:52:38 +0800 | [diff] [blame] | 60 | , _enable_display (false) |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 61 | { |
| 62 | #if HAVE_LIBDRM |
| 63 | _display = DrmDisplay::instance(); |
| 64 | #endif |
| 65 | } |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 66 | |
| 67 | ~MainDeviceManager () { |
| 68 | close_file (); |
| 69 | } |
| 70 | |
| 71 | void enable_save_file (bool enable) { |
| 72 | _save_file = enable; |
| 73 | } |
| 74 | void set_interval (uint32_t inteval) { |
| 75 | _interval = inteval; |
| 76 | } |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 77 | void set_frame_save (uint32_t frame_save) { |
| 78 | _frame_save = frame_save; |
| 79 | } |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 80 | |
Wind Yuan | 683f866 | 2015-03-27 18:52:38 +0800 | [diff] [blame] | 81 | void enable_display(bool value) { |
| 82 | _enable_display = value; |
| 83 | } |
| 84 | |
wangfei | cf4c4e7 | 2015-05-25 17:11:41 +0800 | [diff] [blame] | 85 | void set_display_mode(DrmDisplayMode mode) { |
| 86 | _display->set_display_mode (mode); |
| 87 | } |
| 88 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 89 | protected: |
| 90 | virtual void handle_message (SmartPtr<XCamMessage> &msg); |
| 91 | virtual void handle_buffer (SmartPtr<VideoBuffer> &buf); |
| 92 | |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 93 | int display_buf (SmartPtr<VideoBuffer> &buf); |
| 94 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 95 | private: |
| 96 | void open_file (); |
| 97 | void close_file (); |
| 98 | |
| 99 | FILE *_file; |
| 100 | bool _save_file; |
| 101 | uint32_t _interval; |
| 102 | uint32_t _frame_count; |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 103 | uint32_t _frame_save; |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 104 | SmartPtr<DrmDisplay> _display; |
Wind Yuan | 683f866 | 2015-03-27 18:52:38 +0800 | [diff] [blame] | 105 | bool _enable_display; |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | void |
| 109 | MainDeviceManager::handle_message (SmartPtr<XCamMessage> &msg) |
| 110 | { |
| 111 | XCAM_UNUSED (msg); |
| 112 | } |
| 113 | |
| 114 | void |
| 115 | MainDeviceManager::handle_buffer (SmartPtr<VideoBuffer> &buf) |
| 116 | { |
Wind Yuan | 683f866 | 2015-03-27 18:52:38 +0800 | [diff] [blame] | 117 | FPS_CALCULATION (fps_buf, 30); |
| 118 | |
| 119 | if (_enable_display) |
| 120 | display_buf (buf); |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 121 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 122 | if (!_save_file) |
| 123 | return ; |
| 124 | |
| 125 | if ((_frame_count++ % _interval) != 0) |
| 126 | return; |
| 127 | |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 128 | if ((_frame_save != 0) && (_frame_count > _frame_save)) { |
| 129 | SmartLock locker (g_mutex); |
| 130 | g_stop = true; |
| 131 | g_cond.broadcast (); |
| 132 | return; |
| 133 | } |
| 134 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 135 | const VideoBufferInfo & frame_info = buf->get_video_info (); |
| 136 | uint8_t *frame = buf->map (); |
ShincyTu | 2808b59 | 2015-03-13 17:17:25 +0800 | [diff] [blame] | 137 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 138 | if (frame == NULL) |
| 139 | return; |
ShincyTu | 2808b59 | 2015-03-13 17:17:25 +0800 | [diff] [blame] | 140 | |
| 141 | uint32_t size = 0; |
| 142 | |
| 143 | switch(frame_info.format) { |
| 144 | case V4L2_PIX_FMT_NV12: // 420 |
| 145 | case V4L2_PIX_FMT_NV21: |
| 146 | size = XCAM_ALIGN_UP(frame_info.width, 2) * XCAM_ALIGN_UP(frame_info.height, 2) * 3 / 2; |
| 147 | break; |
| 148 | case V4L2_PIX_FMT_YUV422P: // 422 Planar |
| 149 | case V4L2_PIX_FMT_YUYV: // 422 |
| 150 | case V4L2_PIX_FMT_SBGGR10: |
| 151 | case V4L2_PIX_FMT_SGBRG10: |
| 152 | case V4L2_PIX_FMT_SGRBG10: |
| 153 | case V4L2_PIX_FMT_SRGGB10: |
ShincyTu | 1a4de9d | 2015-06-01 18:04:51 +0800 | [diff] [blame^] | 154 | case V4L2_PIX_FMT_SBGGR12: |
| 155 | case V4L2_PIX_FMT_SGBRG12: |
| 156 | case V4L2_PIX_FMT_SGRBG12: |
| 157 | case V4L2_PIX_FMT_SRGGB12: |
ShincyTu | 2808b59 | 2015-03-13 17:17:25 +0800 | [diff] [blame] | 158 | size = XCAM_ALIGN_UP(frame_info.width, 2) * XCAM_ALIGN_UP(frame_info.height, 2) * 2; |
| 159 | break; |
| 160 | default: |
| 161 | XCAM_LOG_ERROR ( |
| 162 | "unknown v4l2 format(%s) in buffer handle", |
| 163 | xcam_fourcc_to_string (frame_info.format)); |
| 164 | return; |
| 165 | } |
| 166 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 167 | open_file (); |
| 168 | if (fwrite (frame, size, 1, _file) <= 0) { |
| 169 | XCAM_LOG_WARNING ("write frame failed."); |
| 170 | } |
| 171 | } |
| 172 | |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 173 | int |
| 174 | MainDeviceManager::display_buf (SmartPtr<VideoBuffer> &buf) |
| 175 | { |
| 176 | #if HAVE_LIBDRM |
| 177 | XCamReturn ret = XCAM_RETURN_NO_ERROR; |
| 178 | const VideoBufferInfo & frame_info = buf->get_video_info (); |
| 179 | struct v4l2_rect rect = { 0, 0, (int)frame_info.width, (int)frame_info.height }; |
| 180 | |
| 181 | if (!_display->is_render_inited ()) { |
wangfei | 139ea7e | 2015-04-27 18:13:40 +0800 | [diff] [blame] | 182 | ret = _display->render_init (0, 0, 1920, 1080, frame_info.format, &rect); |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 183 | CHECK (ret, "display failed on render_init"); |
| 184 | } |
| 185 | ret = _display->render_setup_frame_buffer (buf); |
| 186 | CHECK (ret, "display failed on framebuf set"); |
| 187 | ret = _display->render_buffer (buf); |
| 188 | CHECK (ret, "display failed on rendering"); |
| 189 | #endif |
| 190 | return 0; |
| 191 | } |
| 192 | |
| 193 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 194 | void |
| 195 | MainDeviceManager::open_file () |
| 196 | { |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 197 | if ((_file) && (_frame_save == 0)) |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 198 | return; |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 199 | |
| 200 | std::string file_name = DEFAULT_SAVE_FILE_NAME; |
| 201 | |
| 202 | if (_frame_save != 0) { |
| 203 | file_name += std::to_string(_frame_count); |
| 204 | } |
| 205 | file_name += ".raw"; |
| 206 | |
| 207 | _file = fopen(file_name.c_str(), "wb"); |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | void |
| 211 | MainDeviceManager::close_file () |
| 212 | { |
| 213 | if (_file) |
| 214 | fclose (_file); |
| 215 | _file = NULL; |
| 216 | } |
| 217 | |
| 218 | #define V4L2_CAPTURE_MODE_STILL 0x2000 |
| 219 | #define V4L2_CAPTURE_MODE_VIDEO 0x4000 |
| 220 | #define V4L2_CAPTURE_MODE_PREVIEW 0x8000 |
| 221 | |
Wind Yuan | 26e9e21 | 2015-04-16 15:55:45 +0800 | [diff] [blame] | 222 | typedef enum { |
| 223 | AnalyzerTypeSimple = 0, |
| 224 | AnalyzerTypeAiq, |
Wind Yuan | e25ce3f | 2015-05-04 18:07:29 +0800 | [diff] [blame] | 225 | AnalyzerTypeDynamic, |
Wind Yuan | 26e9e21 | 2015-04-16 15:55:45 +0800 | [diff] [blame] | 226 | } AnalyzerType; |
| 227 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 228 | void dev_stop_handler(int sig) |
| 229 | { |
| 230 | XCAM_UNUSED (sig); |
| 231 | |
| 232 | SmartLock locker (g_mutex); |
| 233 | g_stop = true; |
| 234 | g_cond.broadcast (); |
| 235 | |
| 236 | //exit(0); |
| 237 | } |
| 238 | |
| 239 | void print_help (const char *bin_name) |
| 240 | { |
| 241 | printf ("Usage: %s [-a analyzer]\n" |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 242 | "\t -a analyzer specify a analyzer\n" |
Wind Yuan | e25ce3f | 2015-05-04 18:07:29 +0800 | [diff] [blame] | 243 | "\t select from [simple, aiq, dynamic], default is [simple]\n" |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 244 | "\t -m mem_type specify video memory type\n" |
| 245 | "\t mem_type select from [dma, mmap], default is [mmap]\n" |
| 246 | "\t -s save file to %s\n" |
| 247 | "\t -n interval save file on every [interval] frame\n" |
| 248 | "\t -c process image with cl kernel\n" |
| 249 | "\t -f pixel_fmt specify output pixel format\n" |
ShincyTu | 1a4de9d | 2015-06-01 18:04:51 +0800 | [diff] [blame^] | 250 | "\t pixel_fmt select from [NV12, YUYV, BA10, RG12], default is [NV12]\n" |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 251 | "\t -d cap_mode specify capture mode\n" |
| 252 | "\t cap_mode select from [video, still], default is [video]\n" |
| 253 | "\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] | 254 | "\t -p preview on local display\n" |
| 255 | "\t -e display_mode preview mode\n" |
| 256 | "\t select from [primary, overlay], default is [primary]\n" |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 257 | "\t -h help\n" |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 258 | , bin_name |
| 259 | , DEFAULT_SAVE_FILE_NAME); |
| 260 | } |
| 261 | |
| 262 | int main (int argc, char *argv[]) |
| 263 | { |
| 264 | XCamReturn ret = XCAM_RETURN_NO_ERROR; |
| 265 | SmartPtr<MainDeviceManager> device_manager = new MainDeviceManager; |
| 266 | SmartPtr<V4l2Device> device; |
| 267 | SmartPtr<V4l2SubDevice> event_device; |
| 268 | SmartPtr<IspController> isp_controller; |
| 269 | SmartPtr<X3aAnalyzer> analyzer; |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 270 | SmartPtr<ImageProcessor> isp_processor; |
wangfei | cf4c4e7 | 2015-05-25 17:11:41 +0800 | [diff] [blame] | 271 | SmartPtr<CLCscImageProcessor> cl_csc_proccessor; |
Wind Yuan | 26e9e21 | 2015-04-16 15:55:45 +0800 | [diff] [blame] | 272 | AnalyzerType analyzer_type = AnalyzerTypeSimple; |
wangfei | cf4c4e7 | 2015-05-25 17:11:41 +0800 | [diff] [blame] | 273 | DrmDisplayMode display_mode = DRM_DISPLAY_MODE_PRIMARY; |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 274 | #if HAVE_LIBDRM |
| 275 | SmartPtr<DrmDisplay> drm_disp = DrmDisplay::instance(); |
| 276 | #endif |
| 277 | |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 278 | #if HAVE_LIBCL |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 279 | SmartPtr<CL3aImageProcessor> cl_processor; |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 280 | #endif |
| 281 | bool have_cl_processor = false; |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 282 | bool need_display = false; |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 283 | enum v4l2_memory v4l2_mem_type = V4L2_MEMORY_MMAP; |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 284 | const char *bin_name = argv[0]; |
| 285 | int opt; |
ShincyTu | 2808b59 | 2015-03-13 17:17:25 +0800 | [diff] [blame] | 286 | uint32_t capture_mode = V4L2_CAPTURE_MODE_VIDEO; |
| 287 | uint32_t pixel_format = V4L2_PIX_FMT_NV12; |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 288 | |
wangfei | cf4c4e7 | 2015-05-25 17:11:41 +0800 | [diff] [blame] | 289 | while ((opt = getopt(argc, argv, "sca:n:m:f:d:pi:e:h")) != -1) { |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 290 | switch (opt) { |
| 291 | case 'a': { |
Wind Yuan | e25ce3f | 2015-05-04 18:07:29 +0800 | [diff] [blame] | 292 | if (!strcmp (optarg, "dynamic")) |
| 293 | analyzer_type = AnalyzerTypeDynamic; |
| 294 | else if (!strcmp (optarg, "simple")) |
Wind Yuan | 26e9e21 | 2015-04-16 15:55:45 +0800 | [diff] [blame] | 295 | analyzer_type = AnalyzerTypeSimple; |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 296 | #if HAVE_IA_AIQ |
| 297 | else if (!strcmp (optarg, "aiq")) |
Wind Yuan | 26e9e21 | 2015-04-16 15:55:45 +0800 | [diff] [blame] | 298 | analyzer_type = AnalyzerTypeAiq; |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 299 | #endif |
| 300 | else { |
| 301 | print_help (bin_name); |
| 302 | return -1; |
| 303 | } |
| 304 | break; |
| 305 | } |
| 306 | |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 307 | case 'm': { |
| 308 | if (!strcmp (optarg, "dma")) |
| 309 | v4l2_mem_type = V4L2_MEMORY_DMABUF; |
| 310 | else if (!strcmp (optarg, "mmap")) |
| 311 | v4l2_mem_type = V4L2_MEMORY_MMAP; |
| 312 | else |
| 313 | print_help (bin_name); |
| 314 | break; |
| 315 | } |
| 316 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 317 | case 's': |
| 318 | device_manager->enable_save_file (true); |
| 319 | break; |
| 320 | case 'n': |
| 321 | device_manager->set_interval (atoi(optarg)); |
| 322 | break; |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 323 | case 'c': |
| 324 | have_cl_processor = true; |
| 325 | break; |
ShincyTu | 2808b59 | 2015-03-13 17:17:25 +0800 | [diff] [blame] | 326 | case 'f': |
ShincyTu | c846640 | 2015-03-31 11:03:39 +0800 | [diff] [blame] | 327 | CHECK_EXP ((strlen(optarg) == 4), "invalid pixel format\n"); |
| 328 | pixel_format = v4l2_fourcc ((unsigned)optarg[0], |
| 329 | (unsigned)optarg[1], |
| 330 | (unsigned)optarg[2], |
| 331 | (unsigned)optarg[3]); |
ShincyTu | 2808b59 | 2015-03-13 17:17:25 +0800 | [diff] [blame] | 332 | break; |
| 333 | case 'd': |
| 334 | if (!strcmp (optarg, "still")) |
| 335 | capture_mode = V4L2_CAPTURE_MODE_STILL; |
| 336 | else if (!strcmp (optarg, "video")) |
| 337 | capture_mode = V4L2_CAPTURE_MODE_VIDEO; |
| 338 | else { |
| 339 | print_help (bin_name); |
| 340 | return -1; |
| 341 | } |
| 342 | break; |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 343 | case 'p': |
| 344 | need_display = true; |
| 345 | break; |
wangfei | cf4c4e7 | 2015-05-25 17:11:41 +0800 | [diff] [blame] | 346 | case 'e': { |
| 347 | if (!strcmp (optarg, "primary")) |
| 348 | display_mode = DRM_DISPLAY_MODE_PRIMARY; |
| 349 | else if (!strcmp (optarg, "overlay")) |
| 350 | display_mode = DRM_DISPLAY_MODE_OVERLAY; |
| 351 | else { |
| 352 | print_help (bin_name); |
| 353 | return -1; |
| 354 | } |
| 355 | break; |
| 356 | } |
ShincyTu | e521cf9 | 2015-03-27 15:13:51 +0800 | [diff] [blame] | 357 | case 'i': |
| 358 | device_manager->set_frame_save(atoi(optarg)); |
| 359 | break; |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 360 | case 'h': |
| 361 | print_help (bin_name); |
| 362 | return 0; |
| 363 | |
| 364 | default: |
| 365 | print_help (bin_name); |
| 366 | return -1; |
| 367 | } |
| 368 | } |
| 369 | |
wangfei | cf4c4e7 | 2015-05-25 17:11:41 +0800 | [diff] [blame] | 370 | if (need_display) { |
Wind Yuan | 683f866 | 2015-03-27 18:52:38 +0800 | [diff] [blame] | 371 | device_manager->enable_display (true); |
wangfei | cf4c4e7 | 2015-05-25 17:11:41 +0800 | [diff] [blame] | 372 | device_manager->set_display_mode (display_mode); |
| 373 | } |
ShincyTu | 2808b59 | 2015-03-13 17:17:25 +0800 | [diff] [blame] | 374 | if (!device.ptr ()) { |
| 375 | if (capture_mode == V4L2_CAPTURE_MODE_STILL) |
| 376 | device = new AtomispDevice (CAPTURE_DEVICE_STILL); |
| 377 | else if (capture_mode == V4L2_CAPTURE_MODE_VIDEO) |
| 378 | device = new AtomispDevice (CAPTURE_DEVICE_VIDEO); |
| 379 | else |
| 380 | device = new AtomispDevice (DEFAULT_CAPTURE_DEVICE); |
| 381 | } |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 382 | if (!event_device.ptr ()) |
| 383 | event_device = new V4l2SubDevice (DEFAULT_EVENT_DEVICE); |
| 384 | if (!isp_controller.ptr ()) |
| 385 | isp_controller = new IspController (device); |
Wind Yuan | 26e9e21 | 2015-04-16 15:55:45 +0800 | [diff] [blame] | 386 | |
| 387 | switch (analyzer_type) { |
Wind Yuan | 3d1d15e | 2015-04-16 17:40:47 +0800 | [diff] [blame] | 388 | case AnalyzerTypeSimple: |
| 389 | analyzer = new X3aAnalyzerSimple (); |
| 390 | break; |
Wind Yuan | 26e9e21 | 2015-04-16 15:55:45 +0800 | [diff] [blame] | 391 | #if HAVE_IA_AIQ |
Wind Yuan | 3d1d15e | 2015-04-16 17:40:47 +0800 | [diff] [blame] | 392 | case AnalyzerTypeAiq: |
| 393 | analyzer = new X3aAnalyzerAiq (isp_controller, DEFAULT_CPF_FILE); |
| 394 | break; |
Wind Yuan | 26e9e21 | 2015-04-16 15:55:45 +0800 | [diff] [blame] | 395 | #endif |
Wind Yuan | e25ce3f | 2015-05-04 18:07:29 +0800 | [diff] [blame] | 396 | case AnalyzerTypeDynamic: { |
| 397 | const char *path_of_3a = DEFAULT_DYNAMIC_3A_LIB; |
| 398 | SmartPtr<AnalyzerLoader> loader = new AnalyzerLoader (path_of_3a); |
| 399 | analyzer = loader->load_analyzer (loader); |
| 400 | CHECK_EXP (analyzer.ptr (), "load dynamic 3a lib(%s) failed", path_of_3a); |
| 401 | break; |
| 402 | } |
Wind Yuan | 3d1d15e | 2015-04-16 17:40:47 +0800 | [diff] [blame] | 403 | default: |
| 404 | print_help (bin_name); |
| 405 | return -1; |
Wind Yuan | 26e9e21 | 2015-04-16 15:55:45 +0800 | [diff] [blame] | 406 | } |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 407 | |
| 408 | signal(SIGINT, dev_stop_handler); |
| 409 | |
| 410 | device->set_sensor_id (0); |
ShincyTu | 2808b59 | 2015-03-13 17:17:25 +0800 | [diff] [blame] | 411 | device->set_capture_mode (capture_mode); |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 412 | //device->set_mem_type (V4L2_MEMORY_DMABUF); |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 413 | device->set_mem_type (v4l2_mem_type); |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 414 | device->set_buffer_count (8); |
ShincyTu | 1a4de9d | 2015-06-01 18:04:51 +0800 | [diff] [blame^] | 415 | if (pixel_format == V4L2_PIX_FMT_SRGGB12) |
| 416 | device->set_framerate (30, 1); |
| 417 | else |
| 418 | device->set_framerate (25, 1); |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 419 | ret = device->open (); |
| 420 | CHECK (ret, "device(%s) open failed", device->get_device_name()); |
ShincyTu | 2808b59 | 2015-03-13 17:17:25 +0800 | [diff] [blame] | 421 | 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] | 422 | CHECK (ret, "device(%s) set format failed", device->get_device_name()); |
| 423 | |
| 424 | ret = event_device->open (); |
| 425 | CHECK (ret, "event device(%s) open failed", event_device->get_device_name()); |
| 426 | int event = V4L2_EVENT_ATOMISP_3A_STATS_READY; |
| 427 | ret = event_device->subscribe_event (event); |
| 428 | CHECK_CONTINUE ( |
| 429 | ret, |
| 430 | "device(%s) subscribe event(%d) failed", |
| 431 | event_device->get_device_name(), event); |
| 432 | event = V4L2_EVENT_FRAME_SYNC; |
| 433 | ret = event_device->subscribe_event (event); |
| 434 | CHECK_CONTINUE ( |
| 435 | ret, |
| 436 | "device(%s) subscribe event(%d) failed", |
| 437 | event_device->get_device_name(), event); |
| 438 | |
| 439 | device_manager->set_capture_device (device); |
| 440 | device_manager->set_event_device (event_device); |
| 441 | device_manager->set_isp_controller (isp_controller); |
| 442 | if (analyzer.ptr()) |
| 443 | device_manager->set_analyzer (analyzer); |
Wind Yuan | 3d1d15e | 2015-04-16 17:40:47 +0800 | [diff] [blame] | 444 | |
| 445 | if (have_cl_processor) |
| 446 | isp_processor = new IspExposureImageProcessor (isp_controller); |
| 447 | else |
| 448 | isp_processor = new IspImageProcessor (isp_controller); |
| 449 | |
| 450 | XCAM_ASSERT (isp_processor.ptr ()); |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 451 | device_manager->add_image_processor (isp_processor); |
wangfei | cf4c4e7 | 2015-05-25 17:11:41 +0800 | [diff] [blame] | 452 | if ((display_mode == DRM_DISPLAY_MODE_PRIMARY) && need_display && (!have_cl_processor)) { |
| 453 | cl_csc_proccessor = new CLCscImageProcessor(); |
| 454 | XCAM_ASSERT (cl_csc_proccessor.ptr ()); |
| 455 | device_manager->add_image_processor (cl_csc_proccessor); |
| 456 | } |
Wind Yuan | 3d1d15e | 2015-04-16 17:40:47 +0800 | [diff] [blame] | 457 | |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 458 | #if HAVE_LIBCL |
| 459 | if (have_cl_processor) { |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 460 | cl_processor = new CL3aImageProcessor (); |
Wind Yuan | 7ddf260 | 2015-04-14 18:49:45 +0800 | [diff] [blame] | 461 | cl_processor->set_stats_callback(device_manager); |
Wind Yuan | 3d1d15e | 2015-04-16 17:40:47 +0800 | [diff] [blame] | 462 | //cl_processor->set_hdr (true); |
Juan Zhao | ab5e6fe | 2015-04-08 14:12:46 +0800 | [diff] [blame] | 463 | cl_processor->set_denoise (false); |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 464 | if (need_display) { |
| 465 | cl_processor->set_output_format (V4L2_PIX_FMT_XBGR32); |
| 466 | } |
ShincyTu | eace4f2 | 2015-04-29 17:40:36 +0800 | [diff] [blame] | 467 | cl_processor->set_snr (false); |
Wind Yuan | d442731 | 2015-02-11 16:09:00 +0800 | [diff] [blame] | 468 | device_manager->add_image_processor (cl_processor); |
| 469 | } |
| 470 | #endif |
Wind Yuan | e4ba0c9 | 2015-03-26 16:59:06 +0800 | [diff] [blame] | 471 | |
Wind Yuan | 75564b1 | 2015-01-15 06:51:15 -0500 | [diff] [blame] | 472 | ret = device_manager->start (); |
| 473 | CHECK (ret, "device manager start failed"); |
| 474 | |
| 475 | // wait for interruption |
| 476 | { |
| 477 | SmartLock locker (g_mutex); |
| 478 | while (!g_stop) |
| 479 | g_cond.wait (g_mutex); |
| 480 | } |
| 481 | |
| 482 | ret = device_manager->stop(); |
| 483 | CHECK_CONTINUE (ret, "device manager stop failed"); |
| 484 | device->close (); |
| 485 | event_device->close (); |
| 486 | |
| 487 | return 0; |
| 488 | } |