blob: d4bd72082072fca367922ecb8a23609982c97073 [file] [log] [blame]
Wind Yuan75564b12015-01-15 06:51:15 -05001/*
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 Kibey7b429292015-08-07 10:55:38 -070023#include "uvc_device.h"
Wind Yuan75564b12015-01-15 06:51:15 -050024#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 Yuand4427312015-02-11 16:09:00 +080030#if HAVE_LIBCL
Wind Yuane4ba0c92015-03-26 16:59:06 +080031#include "cl_3a_image_processor.h"
wangfeicf4c4e72015-05-25 17:11:41 +080032#include "cl_csc_image_processor.h"
Yinhang Liu81c44e02015-06-03 15:47:48 +080033#include "cl_hdr_handler.h"
34#include "cl_tnr_handler.h"
Wind Yuane4ba0c92015-03-26 16:59:06 +080035#endif
36#if HAVE_LIBDRM
37#include "drm_display.h"
Wind Yuand4427312015-02-11 16:09:00 +080038#endif
Wind Yuane25ce3f2015-05-04 18:07:29 +080039#include "analyzer_loader.h"
Jia Meng66efecf2015-06-17 11:11:10 +000040#include <base/xcam_3a_types.h>
Wind Yuan75564b12015-01-15 06:51:15 -050041#include <unistd.h>
42#include <signal.h>
43#include <stdlib.h>
ShincyTue521cf92015-03-27 15:13:51 +080044#include <string>
Yinhang Liu81c44e02015-06-03 15:47:48 +080045#include <getopt.h>
John Yeae9da732015-01-22 13:36:36 +080046#include "test_common.h"
47
Wind Yuan75564b12015-01-15 06:51:15 -050048using namespace XCam;
49
ShincyTue521cf92015-03-27 15:13:51 +080050static Mutex g_mutex;
51static Cond g_cond;
52static bool g_stop = false;
53
Wind Yuan75564b12015-01-15 06:51:15 -050054class MainDeviceManager
55 : public DeviceManager
56{
57public:
58 MainDeviceManager ()
59 : _file (NULL)
60 , _save_file (false)
61 , _interval (1)
62 , _frame_count (0)
ShincyTue521cf92015-03-27 15:13:51 +080063 , _frame_save (0)
Wind Yuan683f8662015-03-27 18:52:38 +080064 , _enable_display (false)
Wind Yuane4ba0c92015-03-26 16:59:06 +080065 {
66#if HAVE_LIBDRM
67 _display = DrmDisplay::instance();
68#endif
Wind Yuan91625802015-06-24 15:36:01 +080069 XCAM_OBJ_PROFILING_INIT;
Wind Yuane4ba0c92015-03-26 16:59:06 +080070 }
Wind Yuan75564b12015-01-15 06:51:15 -050071
72 ~MainDeviceManager () {
73 close_file ();
74 }
75
76 void enable_save_file (bool enable) {
77 _save_file = enable;
78 }
79 void set_interval (uint32_t inteval) {
80 _interval = inteval;
81 }
ShincyTue521cf92015-03-27 15:13:51 +080082 void set_frame_save (uint32_t frame_save) {
83 _frame_save = frame_save;
84 }
Wind Yuan75564b12015-01-15 06:51:15 -050085
Wind Yuan683f8662015-03-27 18:52:38 +080086 void enable_display(bool value) {
87 _enable_display = value;
88 }
89
wangfeicf4c4e72015-05-25 17:11:41 +080090 void set_display_mode(DrmDisplayMode mode) {
91 _display->set_display_mode (mode);
92 }
93
Wind Yuan75564b12015-01-15 06:51:15 -050094protected:
Wind Yuan73af3932015-07-02 17:52:43 +080095 virtual void handle_message (const SmartPtr<XCamMessage> &msg);
96 virtual void handle_buffer (const SmartPtr<VideoBuffer> &buf);
Wind Yuan75564b12015-01-15 06:51:15 -050097
Wind Yuan73af3932015-07-02 17:52:43 +080098 int display_buf (const SmartPtr<VideoBuffer> &buf);
Wind Yuane4ba0c92015-03-26 16:59:06 +080099
Wind Yuan75564b12015-01-15 06:51:15 -0500100private:
101 void open_file ();
102 void close_file ();
103
104 FILE *_file;
105 bool _save_file;
106 uint32_t _interval;
107 uint32_t _frame_count;
ShincyTue521cf92015-03-27 15:13:51 +0800108 uint32_t _frame_save;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800109 SmartPtr<DrmDisplay> _display;
Wind Yuan683f8662015-03-27 18:52:38 +0800110 bool _enable_display;
Wind Yuan91625802015-06-24 15:36:01 +0800111 XCAM_OBJ_PROFILING_DEFINES;
Wind Yuan75564b12015-01-15 06:51:15 -0500112};
113
114void
Wind Yuan73af3932015-07-02 17:52:43 +0800115MainDeviceManager::handle_message (const SmartPtr<XCamMessage> &msg)
Wind Yuan75564b12015-01-15 06:51:15 -0500116{
117 XCAM_UNUSED (msg);
118}
119
120void
Wind Yuan73af3932015-07-02 17:52:43 +0800121MainDeviceManager::handle_buffer (const SmartPtr<VideoBuffer> &buf)
Wind Yuan75564b12015-01-15 06:51:15 -0500122{
Wind Yuan683f8662015-03-27 18:52:38 +0800123 FPS_CALCULATION (fps_buf, 30);
124
Wind Yuan91625802015-06-24 15:36:01 +0800125 XCAM_OBJ_PROFILING_START;
126
Wind Yuan683f8662015-03-27 18:52:38 +0800127 if (_enable_display)
128 display_buf (buf);
Wind Yuane4ba0c92015-03-26 16:59:06 +0800129
Wind Yuan91625802015-06-24 15:36:01 +0800130 XCAM_OBJ_PROFILING_END("main_dev_manager_display", 30);
131
Wind Yuan75564b12015-01-15 06:51:15 -0500132 if (!_save_file)
133 return ;
134
135 if ((_frame_count++ % _interval) != 0)
136 return;
137
ShincyTue521cf92015-03-27 15:13:51 +0800138 if ((_frame_save != 0) && (_frame_count > _frame_save)) {
139 SmartLock locker (g_mutex);
140 g_stop = true;
141 g_cond.broadcast ();
142 return;
143 }
144
Wind Yuan75564b12015-01-15 06:51:15 -0500145 const VideoBufferInfo & frame_info = buf->get_video_info ();
146 uint8_t *frame = buf->map ();
ShincyTu2808b592015-03-13 17:17:25 +0800147
Wind Yuan75564b12015-01-15 06:51:15 -0500148 if (frame == NULL)
149 return;
ShincyTu2808b592015-03-13 17:17:25 +0800150
151 uint32_t size = 0;
152
153 switch(frame_info.format) {
154 case V4L2_PIX_FMT_NV12: // 420
155 case V4L2_PIX_FMT_NV21:
156 size = XCAM_ALIGN_UP(frame_info.width, 2) * XCAM_ALIGN_UP(frame_info.height, 2) * 3 / 2;
157 break;
158 case V4L2_PIX_FMT_YUV422P: // 422 Planar
159 case V4L2_PIX_FMT_YUYV: // 422
160 case V4L2_PIX_FMT_SBGGR10:
161 case V4L2_PIX_FMT_SGBRG10:
162 case V4L2_PIX_FMT_SGRBG10:
163 case V4L2_PIX_FMT_SRGGB10:
ShincyTu1a4de9d2015-06-01 18:04:51 +0800164 case V4L2_PIX_FMT_SBGGR12:
165 case V4L2_PIX_FMT_SGBRG12:
166 case V4L2_PIX_FMT_SGRBG12:
167 case V4L2_PIX_FMT_SRGGB12:
ShincyTu2808b592015-03-13 17:17:25 +0800168 size = XCAM_ALIGN_UP(frame_info.width, 2) * XCAM_ALIGN_UP(frame_info.height, 2) * 2;
169 break;
170 default:
171 XCAM_LOG_ERROR (
172 "unknown v4l2 format(%s) in buffer handle",
173 xcam_fourcc_to_string (frame_info.format));
174 return;
175 }
176
Wind Yuan75564b12015-01-15 06:51:15 -0500177 open_file ();
Jia Meng6c9241d2015-06-12 11:08:45 +0000178
179 if (!_file) {
180 XCAM_LOG_ERROR ("open file failed");
Jia Meng54a2dcb2015-08-20 15:23:47 +0800181 return;
Jia Meng6c9241d2015-06-12 11:08:45 +0000182 }
183
Wind Yuan75564b12015-01-15 06:51:15 -0500184 if (fwrite (frame, size, 1, _file) <= 0) {
185 XCAM_LOG_WARNING ("write frame failed.");
186 }
187}
188
Wind Yuane4ba0c92015-03-26 16:59:06 +0800189int
Wind Yuan73af3932015-07-02 17:52:43 +0800190MainDeviceManager::display_buf (const SmartPtr<VideoBuffer> &data)
Wind Yuane4ba0c92015-03-26 16:59:06 +0800191{
192#if HAVE_LIBDRM
193 XCamReturn ret = XCAM_RETURN_NO_ERROR;
Wind Yuan73af3932015-07-02 17:52:43 +0800194 SmartPtr<VideoBuffer> buf = data;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800195 const VideoBufferInfo & frame_info = buf->get_video_info ();
196 struct v4l2_rect rect = { 0, 0, (int)frame_info.width, (int)frame_info.height };
197
198 if (!_display->is_render_inited ()) {
wangfei139ea7e2015-04-27 18:13:40 +0800199 ret = _display->render_init (0, 0, 1920, 1080, frame_info.format, &rect);
Wind Yuane4ba0c92015-03-26 16:59:06 +0800200 CHECK (ret, "display failed on render_init");
201 }
202 ret = _display->render_setup_frame_buffer (buf);
203 CHECK (ret, "display failed on framebuf set");
204 ret = _display->render_buffer (buf);
205 CHECK (ret, "display failed on rendering");
206#endif
207 return 0;
208}
209
210
Wind Yuan75564b12015-01-15 06:51:15 -0500211void
212MainDeviceManager::open_file ()
213{
ShincyTue521cf92015-03-27 15:13:51 +0800214 if ((_file) && (_frame_save == 0))
Wind Yuan75564b12015-01-15 06:51:15 -0500215 return;
ShincyTue521cf92015-03-27 15:13:51 +0800216
217 std::string file_name = DEFAULT_SAVE_FILE_NAME;
218
219 if (_frame_save != 0) {
220 file_name += std::to_string(_frame_count);
221 }
222 file_name += ".raw";
223
224 _file = fopen(file_name.c_str(), "wb");
Wind Yuan75564b12015-01-15 06:51:15 -0500225}
226
227void
228MainDeviceManager::close_file ()
229{
230 if (_file)
231 fclose (_file);
232 _file = NULL;
233}
234
235#define V4L2_CAPTURE_MODE_STILL 0x2000
236#define V4L2_CAPTURE_MODE_VIDEO 0x4000
237#define V4L2_CAPTURE_MODE_PREVIEW 0x8000
238
Wind Yuan26e9e212015-04-16 15:55:45 +0800239typedef enum {
240 AnalyzerTypeSimple = 0,
241 AnalyzerTypeAiq,
Wind Yuane25ce3f2015-05-04 18:07:29 +0800242 AnalyzerTypeDynamic,
Jia Meng9724cfe2015-08-12 15:04:45 +0800243 AnalyzerTypeHybrid,
Wind Yuan26e9e212015-04-16 15:55:45 +0800244} AnalyzerType;
245
Wind Yuan75564b12015-01-15 06:51:15 -0500246void dev_stop_handler(int sig)
247{
248 XCAM_UNUSED (sig);
249
250 SmartLock locker (g_mutex);
251 g_stop = true;
252 g_cond.broadcast ();
253
254 //exit(0);
255}
256
257void print_help (const char *bin_name)
258{
259 printf ("Usage: %s [-a analyzer]\n"
Yinhang Liu81c44e02015-06-03 15:47:48 +0800260 "Configurations:\n"
ShincyTue521cf92015-03-27 15:13:51 +0800261 "\t -a analyzer specify a analyzer\n"
Wind Yuane25ce3f2015-05-04 18:07:29 +0800262 "\t select from [simple, aiq, dynamic], default is [simple]\n"
ShincyTue521cf92015-03-27 15:13:51 +0800263 "\t -m mem_type specify video memory type\n"
264 "\t mem_type select from [dma, mmap], default is [mmap]\n"
265 "\t -s save file to %s\n"
266 "\t -n interval save file on every [interval] frame\n"
267 "\t -c process image with cl kernel\n"
268 "\t -f pixel_fmt specify output pixel format\n"
ShincyTu1a4de9d2015-06-01 18:04:51 +0800269 "\t pixel_fmt select from [NV12, YUYV, BA10, RG12], default is [NV12]\n"
ShincyTue521cf92015-03-27 15:13:51 +0800270 "\t -d cap_mode specify capture mode\n"
271 "\t cap_mode select from [video, still], default is [video]\n"
yaowang1a5f12122015-07-27 14:53:38 +0800272 "\t -b brightness specify brightness level\n"
273 "\t brightness level select from [0, 256], default is [128]\n"
ShincyTue521cf92015-03-27 15:13:51 +0800274 "\t -i frame_save specify the frame count to save, default is 0 which means endless\n"
wangfeicf4c4e72015-05-25 17:11:41 +0800275 "\t -p preview on local display\n"
Sameer Kibey7b429292015-08-07 10:55:38 -0700276 "\t --usb specify node for usb camera device, enables capture path through USB camera \n"
277 "\t specify [/dev/video4, /dev/video5] depending on which node USB camera is attached\n"
wangfeicf4c4e72015-05-25 17:11:41 +0800278 "\t -e display_mode preview mode\n"
279 "\t select from [primary, overlay], default is [primary]\n"
Jia Meng8f94a102015-08-11 16:24:19 +0800280 "\t --sync set analyzer in sync mode\n"
ShincyTue521cf92015-03-27 15:13:51 +0800281 "\t -h help\n"
Yinhang Liu81c44e02015-06-03 15:47:48 +0800282 "CL features:\n"
283 "\t --hdr specify hdr type, default is hdr off\n"
284 "\t select from [rgb, lab]\n"
285 "\t --tnr specify temporal noise reduction type, default is tnr off\n"
286 "\t select from [rgb, yuv, both]\n"
287 "\t --tnr-level specify tnr level\n"
Yinhang Liub92930c2015-06-23 16:26:35 +0800288 "\t --bilateral enable bilateral noise reduction\n"
Yinhang Liu81c44e02015-06-03 15:47:48 +0800289 "\t --enable-snr enable simple noise reduction\n"
Jia Meng66efecf2015-06-17 11:11:10 +0000290 "\t --enable-ee enable YEENR\n"
ShincyTu63e2c262015-06-26 10:52:51 +0800291 "\t --enable-bnr enable bayer noise reduction\n"
Yinhang Liue26b2622015-07-21 18:32:36 +0800292 "\t --enable-dpc enable defect pixel correction\n"
yaowang16e051152015-08-14 13:49:03 +0800293 "\t --enable-tonemapping enable tonemapping\n"
Yinhang Liue26b2622015-07-21 18:32:36 +0800294 "(e.g.: xxxx --hdr=xx --tnr=xx --tnr-level=xx --bilateral --enable-snr --enable-ee --enable-bnr --enable-dpc)\n\n"
Wind Yuan75564b12015-01-15 06:51:15 -0500295 , bin_name
296 , DEFAULT_SAVE_FILE_NAME);
297}
298
299int main (int argc, char *argv[])
300{
301 XCamReturn ret = XCAM_RETURN_NO_ERROR;
302 SmartPtr<MainDeviceManager> device_manager = new MainDeviceManager;
303 SmartPtr<V4l2Device> device;
304 SmartPtr<V4l2SubDevice> event_device;
305 SmartPtr<IspController> isp_controller;
306 SmartPtr<X3aAnalyzer> analyzer;
Jia Meng9724cfe2015-08-12 15:04:45 +0800307 SmartPtr<AnalyzerLoader> loader;
308 const char *path_of_3a;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800309 SmartPtr<ImageProcessor> isp_processor;
wangfeicf4c4e72015-05-25 17:11:41 +0800310 SmartPtr<CLCscImageProcessor> cl_csc_proccessor;
Wind Yuan26e9e212015-04-16 15:55:45 +0800311 AnalyzerType analyzer_type = AnalyzerTypeSimple;
wangfeicf4c4e72015-05-25 17:11:41 +0800312 DrmDisplayMode display_mode = DRM_DISPLAY_MODE_PRIMARY;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800313#if HAVE_LIBDRM
314 SmartPtr<DrmDisplay> drm_disp = DrmDisplay::instance();
315#endif
316
Wind Yuand4427312015-02-11 16:09:00 +0800317#if HAVE_LIBCL
Wind Yuane4ba0c92015-03-26 16:59:06 +0800318 SmartPtr<CL3aImageProcessor> cl_processor;
Wind Yuand4427312015-02-11 16:09:00 +0800319#endif
320 bool have_cl_processor = false;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800321 bool need_display = false;
Wind Yuand4427312015-02-11 16:09:00 +0800322 enum v4l2_memory v4l2_mem_type = V4L2_MEMORY_MMAP;
Wind Yuan75564b12015-01-15 06:51:15 -0500323 const char *bin_name = argv[0];
324 int opt;
ShincyTu2808b592015-03-13 17:17:25 +0800325 uint32_t capture_mode = V4L2_CAPTURE_MODE_VIDEO;
326 uint32_t pixel_format = V4L2_PIX_FMT_NV12;
Yinhang Liu81c44e02015-06-03 15:47:48 +0800327 uint32_t hdr_type = CL_HDR_DISABLE;
328 uint32_t tnr_type = CL_TNR_DISABLE;
Jia Meng66efecf2015-06-17 11:11:10 +0000329 uint32_t denoise_type = 0;
Yinhang Liu81c44e02015-06-03 15:47:48 +0800330 uint8_t tnr_level = 0;
Yinhang Liue26b2622015-07-21 18:32:36 +0800331 bool dpc_type = false;
yaowang16e051152015-08-14 13:49:03 +0800332 bool tonemapping_type = false;
yaowang1a5f12122015-07-27 14:53:38 +0800333 int32_t brightness_level = 128;
Sameer Kibey7b429292015-08-07 10:55:38 -0700334 bool have_usbcam = 0;
335 char* usb_device_name = NULL;
Jia Meng8f94a102015-08-11 16:24:19 +0800336 bool sync_mode = false;
Wind Yuan75564b12015-01-15 06:51:15 -0500337
yaowang1a5f12122015-07-27 14:53:38 +0800338 const char *short_opts = "sca:n:m:f:d:b:pi:e:h";
Yinhang Liu81c44e02015-06-03 15:47:48 +0800339 const struct option long_opts[] = {
340 {"hdr", required_argument, NULL, 'H'},
341 {"tnr", required_argument, NULL, 'T'},
342 {"tnr-level", required_argument, NULL, 'L'},
Yinhang Liub92930c2015-06-23 16:26:35 +0800343 {"bilateral", no_argument, NULL, 'I'},
Yinhang Liu81c44e02015-06-03 15:47:48 +0800344 {"enable-snr", no_argument, NULL, 'S'},
Jia Meng66efecf2015-06-17 11:11:10 +0000345 {"enable-ee", no_argument, NULL, 'E'},
ShincyTu63e2c262015-06-26 10:52:51 +0800346 {"enable-bnr", no_argument, NULL, 'B'},
Yinhang Liue26b2622015-07-21 18:32:36 +0800347 {"enable-dpc", no_argument, NULL, 'D'},
yaowang16e051152015-08-14 13:49:03 +0800348 {"enable-tonemapping", no_argument, NULL, 'M'},
Sameer Kibey7b429292015-08-07 10:55:38 -0700349 {"usb", required_argument, NULL, 'U'},
Jia Meng8f94a102015-08-11 16:24:19 +0800350 {"sync", no_argument, NULL, 'Y'},
Yinhang Liu81c44e02015-06-03 15:47:48 +0800351 {0, 0, 0, 0},
352 };
353
354 while ((opt = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
Wind Yuan75564b12015-01-15 06:51:15 -0500355 switch (opt) {
356 case 'a': {
Wind Yuane25ce3f2015-05-04 18:07:29 +0800357 if (!strcmp (optarg, "dynamic"))
358 analyzer_type = AnalyzerTypeDynamic;
359 else if (!strcmp (optarg, "simple"))
Wind Yuan26e9e212015-04-16 15:55:45 +0800360 analyzer_type = AnalyzerTypeSimple;
Wind Yuan75564b12015-01-15 06:51:15 -0500361#if HAVE_IA_AIQ
362 else if (!strcmp (optarg, "aiq"))
Wind Yuan26e9e212015-04-16 15:55:45 +0800363 analyzer_type = AnalyzerTypeAiq;
Jia Meng9724cfe2015-08-12 15:04:45 +0800364 else if (!strcmp (optarg, "hybrid"))
365 analyzer_type = AnalyzerTypeHybrid;
Wind Yuan75564b12015-01-15 06:51:15 -0500366#endif
367 else {
368 print_help (bin_name);
369 return -1;
370 }
371 break;
372 }
373
Wind Yuand4427312015-02-11 16:09:00 +0800374 case 'm': {
375 if (!strcmp (optarg, "dma"))
376 v4l2_mem_type = V4L2_MEMORY_DMABUF;
377 else if (!strcmp (optarg, "mmap"))
378 v4l2_mem_type = V4L2_MEMORY_MMAP;
379 else
380 print_help (bin_name);
381 break;
382 }
383
Wind Yuan75564b12015-01-15 06:51:15 -0500384 case 's':
385 device_manager->enable_save_file (true);
386 break;
387 case 'n':
388 device_manager->set_interval (atoi(optarg));
389 break;
Wind Yuand4427312015-02-11 16:09:00 +0800390 case 'c':
391 have_cl_processor = true;
392 break;
ShincyTu2808b592015-03-13 17:17:25 +0800393 case 'f':
ShincyTuc8466402015-03-31 11:03:39 +0800394 CHECK_EXP ((strlen(optarg) == 4), "invalid pixel format\n");
395 pixel_format = v4l2_fourcc ((unsigned)optarg[0],
396 (unsigned)optarg[1],
397 (unsigned)optarg[2],
398 (unsigned)optarg[3]);
ShincyTu2808b592015-03-13 17:17:25 +0800399 break;
400 case 'd':
401 if (!strcmp (optarg, "still"))
402 capture_mode = V4L2_CAPTURE_MODE_STILL;
403 else if (!strcmp (optarg, "video"))
404 capture_mode = V4L2_CAPTURE_MODE_VIDEO;
405 else {
406 print_help (bin_name);
407 return -1;
408 }
409 break;
yaowang1a5f12122015-07-27 14:53:38 +0800410 case 'b':
411 brightness_level = atoi(optarg);
412 if(brightness_level < 0 || brightness_level > 256) {
413 print_help (bin_name);
414 return -1;
415 }
416 break;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800417 case 'p':
418 need_display = true;
419 break;
Sameer Kibey7b429292015-08-07 10:55:38 -0700420 case 'U':
421 have_usbcam = true;
422 usb_device_name = strdup(optarg);
423 XCAM_LOG_DEBUG("using USB camera plugged in at node: %s", usb_device_name);
424 break;
wangfeicf4c4e72015-05-25 17:11:41 +0800425 case 'e': {
426 if (!strcmp (optarg, "primary"))
427 display_mode = DRM_DISPLAY_MODE_PRIMARY;
428 else if (!strcmp (optarg, "overlay"))
429 display_mode = DRM_DISPLAY_MODE_OVERLAY;
430 else {
431 print_help (bin_name);
432 return -1;
433 }
434 break;
435 }
ShincyTue521cf92015-03-27 15:13:51 +0800436 case 'i':
437 device_manager->set_frame_save(atoi(optarg));
438 break;
Jia Meng8f94a102015-08-11 16:24:19 +0800439 case 'Y':
440 sync_mode = true;
441 break;
Yinhang Liu81c44e02015-06-03 15:47:48 +0800442 case 'H': {
443 if (!strcasecmp (optarg, "rgb"))
444 hdr_type = CL_HDR_TYPE_RGB;
445 else if (!strcasecmp (optarg, "lab"))
446 hdr_type = CL_HDR_TYPE_LAB;
447 else {
448 print_help (bin_name);
449 return -1;
450 }
451 break;
452 }
Yinhang Liub92930c2015-06-23 16:26:35 +0800453 case 'I': {
Jia Meng66efecf2015-06-17 11:11:10 +0000454 denoise_type |= XCAM_DENOISE_TYPE_BILATERAL;
Yinhang Liu81c44e02015-06-03 15:47:48 +0800455 break;
456 }
457 case 'S': {
Jia Meng66efecf2015-06-17 11:11:10 +0000458 denoise_type |= XCAM_DENOISE_TYPE_SIMPLE;
459 break;
460 }
461 case 'E': {
462 denoise_type |= XCAM_DENOISE_TYPE_EE;
Yinhang Liu81c44e02015-06-03 15:47:48 +0800463 break;
464 }
ShincyTu63e2c262015-06-26 10:52:51 +0800465 case 'B': {
466 denoise_type |= XCAM_DENOISE_TYPE_BNR;
467 break;
468 }
Yinhang Liue26b2622015-07-21 18:32:36 +0800469 case 'D': {
470 dpc_type = true;
471 break;
472 }
Yinhang Liu81c44e02015-06-03 15:47:48 +0800473 case 'T': {
474 if (!strcasecmp (optarg, "yuv"))
475 tnr_type = CL_TNR_TYPE_YUV;
476 else if (!strcasecmp (optarg, "rgb"))
477 tnr_type = CL_TNR_TYPE_RGB;
478 else if (!strcasecmp (optarg, "both"))
479 tnr_type = CL_TNR_TYPE_YUV | CL_TNR_TYPE_RGB;
480 else {
481 print_help (bin_name);
482 return -1;
483 }
484 break;
485 }
486 case 'L': {
487 if (atoi(optarg) < 0 || atoi(optarg) > 255) {
488 print_help (bin_name);
489 return -1;
490 }
491 tnr_level = atoi(optarg);
492 break;
493 }
yaowang16e051152015-08-14 13:49:03 +0800494 case 'M': {
495 tonemapping_type = true;
496 break;
497 }
Wind Yuan75564b12015-01-15 06:51:15 -0500498 case 'h':
499 print_help (bin_name);
500 return 0;
501
502 default:
503 print_help (bin_name);
504 return -1;
505 }
506 }
507
wangfeicf4c4e72015-05-25 17:11:41 +0800508 if (need_display) {
Wind Yuan683f8662015-03-27 18:52:38 +0800509 device_manager->enable_display (true);
wangfeicf4c4e72015-05-25 17:11:41 +0800510 device_manager->set_display_mode (display_mode);
511 }
ShincyTu2808b592015-03-13 17:17:25 +0800512 if (!device.ptr ()) {
Sameer Kibey7b429292015-08-07 10:55:38 -0700513 if (have_usbcam) {
514 device = new UVCDevice (usb_device_name);
515 } else {
516 if (capture_mode == V4L2_CAPTURE_MODE_STILL)
517 device = new AtomispDevice (CAPTURE_DEVICE_STILL);
518 else if (capture_mode == V4L2_CAPTURE_MODE_VIDEO)
519 device = new AtomispDevice (CAPTURE_DEVICE_VIDEO);
520 else
521 device = new AtomispDevice (DEFAULT_CAPTURE_DEVICE);
522 }
ShincyTu2808b592015-03-13 17:17:25 +0800523 }
Wind Yuan75564b12015-01-15 06:51:15 -0500524 if (!event_device.ptr ())
525 event_device = new V4l2SubDevice (DEFAULT_EVENT_DEVICE);
526 if (!isp_controller.ptr ())
527 isp_controller = new IspController (device);
Wind Yuan26e9e212015-04-16 15:55:45 +0800528
529 switch (analyzer_type) {
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800530 case AnalyzerTypeSimple:
531 analyzer = new X3aAnalyzerSimple ();
532 break;
Wind Yuan26e9e212015-04-16 15:55:45 +0800533#if HAVE_IA_AIQ
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800534 case AnalyzerTypeAiq:
535 analyzer = new X3aAnalyzerAiq (isp_controller, DEFAULT_CPF_FILE);
536 break;
Jia Meng9724cfe2015-08-12 15:04:45 +0800537 case AnalyzerTypeHybrid: {
Jia Mengc54c3322015-08-26 09:45:18 +0800538 path_of_3a = DEFAULT_HYBRID_3A_LIB;
Jia Meng9724cfe2015-08-12 15:04:45 +0800539 loader = new AnalyzerLoader (path_of_3a);
540 analyzer = loader->load_hybrid_analyzer (loader, isp_controller, DEFAULT_CPF_FILE);
541 CHECK_EXP (analyzer.ptr (), "load hybrid 3a lib(%s) failed", path_of_3a);
542 break;
543 }
Wind Yuan26e9e212015-04-16 15:55:45 +0800544#endif
Wind Yuane25ce3f2015-05-04 18:07:29 +0800545 case AnalyzerTypeDynamic: {
Jia Meng9724cfe2015-08-12 15:04:45 +0800546 path_of_3a = DEFAULT_DYNAMIC_3A_LIB;
547 loader = new AnalyzerLoader (path_of_3a);
548 analyzer = loader->load_dynamic_analyzer (loader);
Wind Yuane25ce3f2015-05-04 18:07:29 +0800549 CHECK_EXP (analyzer.ptr (), "load dynamic 3a lib(%s) failed", path_of_3a);
550 break;
551 }
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800552 default:
553 print_help (bin_name);
554 return -1;
Wind Yuan26e9e212015-04-16 15:55:45 +0800555 }
Jia Meng8f94a102015-08-11 16:24:19 +0800556 XCAM_ASSERT (analyzer.ptr ());
557 analyzer->set_sync_mode (sync_mode);
Wind Yuan75564b12015-01-15 06:51:15 -0500558
559 signal(SIGINT, dev_stop_handler);
560
561 device->set_sensor_id (0);
ShincyTu2808b592015-03-13 17:17:25 +0800562 device->set_capture_mode (capture_mode);
Wind Yuan75564b12015-01-15 06:51:15 -0500563 //device->set_mem_type (V4L2_MEMORY_DMABUF);
Wind Yuand4427312015-02-11 16:09:00 +0800564 device->set_mem_type (v4l2_mem_type);
Wind Yuan75564b12015-01-15 06:51:15 -0500565 device->set_buffer_count (8);
ShincyTu1a4de9d2015-06-01 18:04:51 +0800566 if (pixel_format == V4L2_PIX_FMT_SRGGB12)
567 device->set_framerate (30, 1);
568 else
569 device->set_framerate (25, 1);
Wind Yuan75564b12015-01-15 06:51:15 -0500570 ret = device->open ();
571 CHECK (ret, "device(%s) open failed", device->get_device_name());
ShincyTu2808b592015-03-13 17:17:25 +0800572 ret = device->set_format (1920, 1080, pixel_format, V4L2_FIELD_NONE, 1920 * 2);
Wind Yuan75564b12015-01-15 06:51:15 -0500573 CHECK (ret, "device(%s) set format failed", device->get_device_name());
574
575 ret = event_device->open ();
576 CHECK (ret, "event device(%s) open failed", event_device->get_device_name());
577 int event = V4L2_EVENT_ATOMISP_3A_STATS_READY;
578 ret = event_device->subscribe_event (event);
579 CHECK_CONTINUE (
580 ret,
581 "device(%s) subscribe event(%d) failed",
582 event_device->get_device_name(), event);
583 event = V4L2_EVENT_FRAME_SYNC;
584 ret = event_device->subscribe_event (event);
585 CHECK_CONTINUE (
586 ret,
587 "device(%s) subscribe event(%d) failed",
588 event_device->get_device_name(), event);
589
590 device_manager->set_capture_device (device);
591 device_manager->set_event_device (event_device);
592 device_manager->set_isp_controller (isp_controller);
593 if (analyzer.ptr())
594 device_manager->set_analyzer (analyzer);
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800595
596 if (have_cl_processor)
597 isp_processor = new IspExposureImageProcessor (isp_controller);
598 else
599 isp_processor = new IspImageProcessor (isp_controller);
600
601 XCAM_ASSERT (isp_processor.ptr ());
Wind Yuane4ba0c92015-03-26 16:59:06 +0800602 device_manager->add_image_processor (isp_processor);
wangfeicf4c4e72015-05-25 17:11:41 +0800603 if ((display_mode == DRM_DISPLAY_MODE_PRIMARY) && need_display && (!have_cl_processor)) {
604 cl_csc_proccessor = new CLCscImageProcessor();
605 XCAM_ASSERT (cl_csc_proccessor.ptr ());
606 device_manager->add_image_processor (cl_csc_proccessor);
607 }
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800608
Wind Yuand4427312015-02-11 16:09:00 +0800609#if HAVE_LIBCL
610 if (have_cl_processor) {
yaowang1a5f12122015-07-27 14:53:38 +0800611
Wind Yuane4ba0c92015-03-26 16:59:06 +0800612 cl_processor = new CL3aImageProcessor ();
Wind Yuan7ddf2602015-04-14 18:49:45 +0800613 cl_processor->set_stats_callback(device_manager);
Yinhang Liue26b2622015-07-21 18:32:36 +0800614 cl_processor->set_dpc(dpc_type);
Yinhang Liu81c44e02015-06-03 15:47:48 +0800615 cl_processor->set_hdr (hdr_type);
Jia Meng66efecf2015-06-17 11:11:10 +0000616 cl_processor->set_denoise (denoise_type);
yaowang16e051152015-08-14 13:49:03 +0800617 cl_processor->set_tonemapping(tonemapping_type);
Wind Yuane4ba0c92015-03-26 16:59:06 +0800618 if (need_display) {
619 cl_processor->set_output_format (V4L2_PIX_FMT_XBGR32);
620 }
Yinhang Liu81c44e02015-06-03 15:47:48 +0800621 cl_processor->set_tnr (tnr_type, tnr_level);
yaowang1a5f12122015-07-27 14:53:38 +0800622 analyzer->set_parameter_brightness((brightness_level - 128) / 128.0);
Wind Yuand4427312015-02-11 16:09:00 +0800623 device_manager->add_image_processor (cl_processor);
624 }
625#endif
Wind Yuane4ba0c92015-03-26 16:59:06 +0800626
Wind Yuan75564b12015-01-15 06:51:15 -0500627 ret = device_manager->start ();
628 CHECK (ret, "device manager start failed");
629
630 // wait for interruption
631 {
632 SmartLock locker (g_mutex);
633 while (!g_stop)
634 g_cond.wait (g_mutex);
635 }
636
637 ret = device_manager->stop();
638 CHECK_CONTINUE (ret, "device manager stop failed");
639 device->close ();
640 event_device->close ();
641
642 return 0;
643}