blob: 53db0263ff86e12b130b0d8eb5234b610b427db4 [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"
Jia Meng0a532932015-10-15 08:44:09 -040024#include "fake_v4l2_device.h"
Wind Yuan75564b12015-01-15 06:51:15 -050025#include "isp_controller.h"
26#include "isp_image_processor.h"
27#include "x3a_analyzer_simple.h"
28#if HAVE_IA_AIQ
29#include "x3a_analyzer_aiq.h"
Yinhang Liu6c367352016-03-31 20:23:22 +080030#include "x3a_analyze_tuner.h"
Wind Yuan75564b12015-01-15 06:51:15 -050031#endif
Wind Yuand4427312015-02-11 16:09:00 +080032#if HAVE_LIBCL
Wind Yuane4ba0c92015-03-26 16:59:06 +080033#include "cl_3a_image_processor.h"
Yinhang Liu2ab1f992016-03-15 10:41:17 +080034#include "cl_post_image_processor.h"
wangfeicf4c4e72015-05-25 17:11:41 +080035#include "cl_csc_image_processor.h"
Yinhang Liu81c44e02015-06-03 15:47:48 +080036#include "cl_hdr_handler.h"
37#include "cl_tnr_handler.h"
Wind Yuane4ba0c92015-03-26 16:59:06 +080038#endif
39#if HAVE_LIBDRM
40#include "drm_display.h"
Wind Yuand4427312015-02-11 16:09:00 +080041#endif
zongwave03954a32015-09-22 15:40:44 +080042#include "x3a_analyzer_loader.h"
Jia Meng0a532932015-10-15 08:44:09 -040043#include "poll_thread.h"
44#include "fake_poll_thread.h"
Jia Meng66efecf2015-06-17 11:11:10 +000045#include <base/xcam_3a_types.h>
Wind Yuan75564b12015-01-15 06:51:15 -050046#include <unistd.h>
47#include <signal.h>
48#include <stdlib.h>
ShincyTue521cf92015-03-27 15:13:51 +080049#include <string>
Yinhang Liu81c44e02015-06-03 15:47:48 +080050#include <getopt.h>
John Yeae9da732015-01-22 13:36:36 +080051#include "test_common.h"
52
Wind Yuan75564b12015-01-15 06:51:15 -050053using namespace XCam;
54
wujunkai16682950fb2015-10-19 18:09:05 +080055#define IMX185_WDR_CPF "/etc/atomisp/imx185_wdr.cpf"
56
ShincyTue521cf92015-03-27 15:13:51 +080057static Mutex g_mutex;
58static Cond g_cond;
59static bool g_stop = false;
60
Wind Yuan75564b12015-01-15 06:51:15 -050061class MainDeviceManager
62 : public DeviceManager
63{
64public:
65 MainDeviceManager ()
66 : _file (NULL)
67 , _save_file (false)
68 , _interval (1)
Yinhang Liud9346492015-12-17 11:14:25 +080069 , _frame_width (0)
70 , _frame_height (0)
Wind Yuan75564b12015-01-15 06:51:15 -050071 , _frame_count (0)
ShincyTue521cf92015-03-27 15:13:51 +080072 , _frame_save (0)
Wind Yuan683f8662015-03-27 18:52:38 +080073 , _enable_display (false)
Wind Yuane4ba0c92015-03-26 16:59:06 +080074 {
75#if HAVE_LIBDRM
76 _display = DrmDisplay::instance();
77#endif
Wind Yuan91625802015-06-24 15:36:01 +080078 XCAM_OBJ_PROFILING_INIT;
Wind Yuane4ba0c92015-03-26 16:59:06 +080079 }
Wind Yuan75564b12015-01-15 06:51:15 -050080
81 ~MainDeviceManager () {
82 close_file ();
83 }
84
85 void enable_save_file (bool enable) {
86 _save_file = enable;
87 }
Yinhang Liud9346492015-12-17 11:14:25 +080088
Wind Yuan75564b12015-01-15 06:51:15 -050089 void set_interval (uint32_t inteval) {
90 _interval = inteval;
91 }
Yinhang Liud9346492015-12-17 11:14:25 +080092
93 void set_frame_width (uint32_t frame_width) {
94 _frame_width = frame_width;
95 }
96
97 void set_frame_height (uint32_t frame_height) {
98 _frame_height = frame_height;
99 }
100
ShincyTue521cf92015-03-27 15:13:51 +0800101 void set_frame_save (uint32_t frame_save) {
102 _frame_save = frame_save;
103 }
Wind Yuan75564b12015-01-15 06:51:15 -0500104
Wind Yuan683f8662015-03-27 18:52:38 +0800105 void enable_display(bool value) {
106 _enable_display = value;
107 }
108
wangfeicf4c4e72015-05-25 17:11:41 +0800109 void set_display_mode(DrmDisplayMode mode) {
110 _display->set_display_mode (mode);
111 }
112
Wind Yuan75564b12015-01-15 06:51:15 -0500113protected:
Wind Yuan73af3932015-07-02 17:52:43 +0800114 virtual void handle_message (const SmartPtr<XCamMessage> &msg);
115 virtual void handle_buffer (const SmartPtr<VideoBuffer> &buf);
Wind Yuan75564b12015-01-15 06:51:15 -0500116
Wind Yuan73af3932015-07-02 17:52:43 +0800117 int display_buf (const SmartPtr<VideoBuffer> &buf);
Wind Yuane4ba0c92015-03-26 16:59:06 +0800118
Wind Yuan75564b12015-01-15 06:51:15 -0500119private:
120 void open_file ();
121 void close_file ();
Wind Yuan71111322016-02-24 22:56:27 +0800122 XCamReturn write_buf (const SmartPtr<VideoBuffer> &buf);
Wind Yuan75564b12015-01-15 06:51:15 -0500123
124 FILE *_file;
125 bool _save_file;
126 uint32_t _interval;
Yinhang Liud9346492015-12-17 11:14:25 +0800127 uint32_t _frame_width;
128 uint32_t _frame_height;
Wind Yuan75564b12015-01-15 06:51:15 -0500129 uint32_t _frame_count;
ShincyTue521cf92015-03-27 15:13:51 +0800130 uint32_t _frame_save;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800131 SmartPtr<DrmDisplay> _display;
Wind Yuan683f8662015-03-27 18:52:38 +0800132 bool _enable_display;
Wind Yuan91625802015-06-24 15:36:01 +0800133 XCAM_OBJ_PROFILING_DEFINES;
Wind Yuan75564b12015-01-15 06:51:15 -0500134};
135
136void
Wind Yuan73af3932015-07-02 17:52:43 +0800137MainDeviceManager::handle_message (const SmartPtr<XCamMessage> &msg)
Wind Yuan75564b12015-01-15 06:51:15 -0500138{
139 XCAM_UNUSED (msg);
140}
141
142void
Wind Yuan73af3932015-07-02 17:52:43 +0800143MainDeviceManager::handle_buffer (const SmartPtr<VideoBuffer> &buf)
Wind Yuan75564b12015-01-15 06:51:15 -0500144{
Wind Yuan683f8662015-03-27 18:52:38 +0800145 FPS_CALCULATION (fps_buf, 30);
146
Wind Yuan91625802015-06-24 15:36:01 +0800147 XCAM_OBJ_PROFILING_START;
148
Wind Yuan683f8662015-03-27 18:52:38 +0800149 if (_enable_display)
150 display_buf (buf);
Wind Yuane4ba0c92015-03-26 16:59:06 +0800151
Wind Yuan91625802015-06-24 15:36:01 +0800152 XCAM_OBJ_PROFILING_END("main_dev_manager_display", 30);
153
Wind Yuan75564b12015-01-15 06:51:15 -0500154 if (!_save_file)
155 return ;
156
157 if ((_frame_count++ % _interval) != 0)
158 return;
159
ShincyTue521cf92015-03-27 15:13:51 +0800160 if ((_frame_save != 0) && (_frame_count > _frame_save)) {
161 SmartLock locker (g_mutex);
162 g_stop = true;
163 g_cond.broadcast ();
164 return;
165 }
166
Wind Yuan75564b12015-01-15 06:51:15 -0500167 open_file ();
Jia Meng6c9241d2015-06-12 11:08:45 +0000168
169 if (!_file) {
170 XCAM_LOG_ERROR ("open file failed");
Jia Meng54a2dcb2015-08-20 15:23:47 +0800171 return;
Jia Meng6c9241d2015-06-12 11:08:45 +0000172 }
Wind Yuan71111322016-02-24 22:56:27 +0800173 write_buf (buf);
Wind Yuan75564b12015-01-15 06:51:15 -0500174}
175
Wind Yuane4ba0c92015-03-26 16:59:06 +0800176int
Wind Yuan73af3932015-07-02 17:52:43 +0800177MainDeviceManager::display_buf (const SmartPtr<VideoBuffer> &data)
Wind Yuane4ba0c92015-03-26 16:59:06 +0800178{
179#if HAVE_LIBDRM
180 XCamReturn ret = XCAM_RETURN_NO_ERROR;
Wind Yuan73af3932015-07-02 17:52:43 +0800181 SmartPtr<VideoBuffer> buf = data;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800182 const VideoBufferInfo & frame_info = buf->get_video_info ();
183 struct v4l2_rect rect = { 0, 0, (int)frame_info.width, (int)frame_info.height };
184
185 if (!_display->is_render_inited ()) {
Yinhang Liud9346492015-12-17 11:14:25 +0800186 ret = _display->render_init (0, 0, this->_frame_width, this->_frame_height,
187 frame_info.format, &rect);
Wind Yuane4ba0c92015-03-26 16:59:06 +0800188 CHECK (ret, "display failed on render_init");
189 }
190 ret = _display->render_setup_frame_buffer (buf);
191 CHECK (ret, "display failed on framebuf set");
192 ret = _display->render_buffer (buf);
193 CHECK (ret, "display failed on rendering");
194#endif
195 return 0;
196}
197
198
Wind Yuan75564b12015-01-15 06:51:15 -0500199void
200MainDeviceManager::open_file ()
201{
ShincyTue521cf92015-03-27 15:13:51 +0800202 if ((_file) && (_frame_save == 0))
Wind Yuan75564b12015-01-15 06:51:15 -0500203 return;
ShincyTue521cf92015-03-27 15:13:51 +0800204
205 std::string file_name = DEFAULT_SAVE_FILE_NAME;
206
207 if (_frame_save != 0) {
208 file_name += std::to_string(_frame_count);
209 }
210 file_name += ".raw";
211
212 _file = fopen(file_name.c_str(), "wb");
Wind Yuan75564b12015-01-15 06:51:15 -0500213}
214
215void
216MainDeviceManager::close_file ()
217{
218 if (_file)
219 fclose (_file);
220 _file = NULL;
221}
222
Wind Yuan71111322016-02-24 22:56:27 +0800223XCamReturn
224MainDeviceManager::write_buf (const SmartPtr<VideoBuffer> &buf)
225{
226 const VideoBufferInfo &info = buf->get_video_info ();
227 VideoBufferPlanarInfo planar;
228 uint8_t *memory = NULL;
229 XCamReturn ret = XCAM_RETURN_NO_ERROR;
230
231 memory = buf->map ();
232 if (!memory) {
233 XCAM_LOG_ERROR ("map buffer failed in write_buf");
234 return XCAM_RETURN_ERROR_MEM;
235 }
236
237 for (uint32_t index = 0; index < info.components; index++) {
238 info.get_planar_info (planar, index);
239 uint32_t line_bytes = planar.width * planar.pixel_bytes;
240
241 for (uint32_t i = 0; i < planar.height; i++) {
242 if (fwrite (memory + info.offsets [index] + i * info.strides [index], 1, line_bytes, _file) != line_bytes) {
243 XCAM_LOG_ERROR ("write file failed, size doesn't match");
244 ret = XCAM_RETURN_ERROR_FILE;
245 }
246 }
247 }
248 buf->unmap ();
249 return ret;
250}
251
Wind Yuan75564b12015-01-15 06:51:15 -0500252#define V4L2_CAPTURE_MODE_STILL 0x2000
253#define V4L2_CAPTURE_MODE_VIDEO 0x4000
254#define V4L2_CAPTURE_MODE_PREVIEW 0x8000
255
Wind Yuan26e9e212015-04-16 15:55:45 +0800256typedef enum {
257 AnalyzerTypeSimple = 0,
Yinhang Liu6c367352016-03-31 20:23:22 +0800258 AnalyzerTypeAiqTuner,
Wind Yuane25ce3f2015-05-04 18:07:29 +0800259 AnalyzerTypeDynamic,
Jia Meng9724cfe2015-08-12 15:04:45 +0800260 AnalyzerTypeHybrid,
Wind Yuan26e9e212015-04-16 15:55:45 +0800261} AnalyzerType;
262
Wind Yuan75564b12015-01-15 06:51:15 -0500263void dev_stop_handler(int sig)
264{
265 XCAM_UNUSED (sig);
266
267 SmartLock locker (g_mutex);
268 g_stop = true;
269 g_cond.broadcast ();
270
271 //exit(0);
272}
273
274void print_help (const char *bin_name)
275{
276 printf ("Usage: %s [-a analyzer]\n"
Yinhang Liu81c44e02015-06-03 15:47:48 +0800277 "Configurations:\n"
ShincyTue521cf92015-03-27 15:13:51 +0800278 "\t -a analyzer specify a analyzer\n"
Wind Yuane25ce3f2015-05-04 18:07:29 +0800279 "\t select from [simple, aiq, dynamic], default is [simple]\n"
ShincyTue521cf92015-03-27 15:13:51 +0800280 "\t -m mem_type specify video memory type\n"
281 "\t mem_type select from [dma, mmap], default is [mmap]\n"
282 "\t -s save file to %s\n"
283 "\t -n interval save file on every [interval] frame\n"
Yinhang Liuc2f19082015-08-28 12:27:48 +0800284#if HAVE_LIBCL
ShincyTue521cf92015-03-27 15:13:51 +0800285 "\t -c process image with cl kernel\n"
Yinhang Liuc2f19082015-08-28 12:27:48 +0800286#endif
ShincyTue521cf92015-03-27 15:13:51 +0800287 "\t -f pixel_fmt specify output pixel format\n"
wujunkai1669845b022015-08-27 15:59:27 +0800288 "\t pixel_fmt select from [NV12, YUYV, BA10, BA12], default is [NV12]\n"
ShincyTue521cf92015-03-27 15:13:51 +0800289 "\t -d cap_mode specify capture mode\n"
290 "\t cap_mode select from [video, still], default is [video]\n"
yaowang1a5f12122015-07-27 14:53:38 +0800291 "\t -b brightness specify brightness level\n"
292 "\t brightness level select from [0, 256], default is [128]\n"
ShincyTue521cf92015-03-27 15:13:51 +0800293 "\t -i frame_save specify the frame count to save, default is 0 which means endless\n"
wangfeicf4c4e72015-05-25 17:11:41 +0800294 "\t -p preview on local display\n"
Sameer Kibey7b429292015-08-07 10:55:38 -0700295 "\t --usb specify node for usb camera device, enables capture path through USB camera \n"
296 "\t specify [/dev/video4, /dev/video5] depending on which node USB camera is attached\n"
Yinhang Liud9346492015-12-17 11:14:25 +0800297 "\t --resolution specify the resolution of usb camera\n"
298 "\t select from [1920x1080, 1280x720 ...], default is [1920x1080]\n"
wangfeicf4c4e72015-05-25 17:11:41 +0800299 "\t -e display_mode preview mode\n"
300 "\t select from [primary, overlay], default is [primary]\n"
Jia Meng8f94a102015-08-11 16:24:19 +0800301 "\t --sync set analyzer in sync mode\n"
Jia Meng0a532932015-10-15 08:44:09 -0400302 "\t -r raw_input specify the path of raw image as fake source instead of live camera\n"
ShincyTue521cf92015-03-27 15:13:51 +0800303 "\t -h help\n"
Yinhang Liuc2f19082015-08-28 12:27:48 +0800304#if HAVE_LIBCL
Yinhang Liu81c44e02015-06-03 15:47:48 +0800305 "CL features:\n"
wujunkai166a84ba052015-09-08 15:54:12 +0800306 "\t --capture capture_stage specify the capture stage of image\n"
307 "\t capture_stage select from [bayer, tonemapping], default is [tonemapping]\n"
Yinhang Liu81c44e02015-06-03 15:47:48 +0800308 "\t --hdr specify hdr type, default is hdr off\n"
309 "\t select from [rgb, lab]\n"
310 "\t --tnr specify temporal noise reduction type, default is tnr off\n"
311 "\t select from [rgb, yuv, both]\n"
312 "\t --tnr-level specify tnr level\n"
wujunkai16606f77622016-03-18 14:41:10 +0800313 "\t --wdr-mode specify wdr mode. select from [gaussian, haleq]\n"
Yinhang Liub92930c2015-06-23 16:26:35 +0800314 "\t --bilateral enable bilateral noise reduction\n"
Yinhang Liu81c44e02015-06-03 15:47:48 +0800315 "\t --enable-snr enable simple noise reduction\n"
Jia Meng66efecf2015-06-17 11:11:10 +0000316 "\t --enable-ee enable YEENR\n"
ShincyTu63e2c262015-06-26 10:52:51 +0800317 "\t --enable-bnr enable bayer noise reduction\n"
Yinhang Liue26b2622015-07-21 18:32:36 +0800318 "\t --enable-dpc enable defect pixel correction\n"
Wangfei8e5e3e42016-02-18 19:41:54 +0800319 "\t --enable-retinex enable retinex\n"
zongwave2ba7f642016-03-15 19:24:12 +0800320 "\t --wavelet-mode specify wavelet mode\n"
Wangfei1487b9b2015-08-28 15:10:39 +0800321 "\t --pipeline pipe mode\n"
Wangfei16b65db2015-09-11 14:44:28 +0800322 "\t select from [basic, advance, extreme], default is [basic]\n"
Yinhang Liub0ad64b2016-03-18 16:03:51 +0800323 "\t --disable-post disable cl post image processor\n"
Yinhang Liue26b2622015-07-21 18:32:36 +0800324 "(e.g.: xxxx --hdr=xx --tnr=xx --tnr-level=xx --bilateral --enable-snr --enable-ee --enable-bnr --enable-dpc)\n\n"
Yinhang Liuc2f19082015-08-28 12:27:48 +0800325#endif
Wind Yuan75564b12015-01-15 06:51:15 -0500326 , bin_name
327 , DEFAULT_SAVE_FILE_NAME);
328}
329
330int main (int argc, char *argv[])
331{
332 XCamReturn ret = XCAM_RETURN_NO_ERROR;
333 SmartPtr<MainDeviceManager> device_manager = new MainDeviceManager;
334 SmartPtr<V4l2Device> device;
335 SmartPtr<V4l2SubDevice> event_device;
336 SmartPtr<IspController> isp_controller;
337 SmartPtr<X3aAnalyzer> analyzer;
zongwave03954a32015-09-22 15:40:44 +0800338 SmartPtr<X3aAnalyzerLoader> loader;
Jia Meng9724cfe2015-08-12 15:04:45 +0800339 const char *path_of_3a;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800340 SmartPtr<ImageProcessor> isp_processor;
Wind Yuan26e9e212015-04-16 15:55:45 +0800341 AnalyzerType analyzer_type = AnalyzerTypeSimple;
wangfeicf4c4e72015-05-25 17:11:41 +0800342 DrmDisplayMode display_mode = DRM_DISPLAY_MODE_PRIMARY;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800343#if HAVE_LIBDRM
344 SmartPtr<DrmDisplay> drm_disp = DrmDisplay::instance();
345#endif
346
Wind Yuand4427312015-02-11 16:09:00 +0800347#if HAVE_LIBCL
Wind Yuane4ba0c92015-03-26 16:59:06 +0800348 SmartPtr<CL3aImageProcessor> cl_processor;
Yinhang Liu2ab1f992016-03-15 10:41:17 +0800349 SmartPtr<CLPostImageProcessor> cl_post_processor;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800350 uint32_t hdr_type = CL_HDR_DISABLE;
351 uint32_t tnr_type = CL_TNR_DISABLE;
352 uint32_t denoise_type = 0;
353 uint8_t tnr_level = 0;
354 bool dpc_type = false;
Wangfei1487b9b2015-08-28 15:10:39 +0800355 CL3aImageProcessor::PipelineProfile pipeline_mode = CL3aImageProcessor::BasicPipelineProfile;
wujunkai166a84ba052015-09-08 15:54:12 +0800356 CL3aImageProcessor::CaptureStage capture_stage = CL3aImageProcessor::TonemappingStage;
wujunkai16606f77622016-03-18 14:41:10 +0800357 CL3aImageProcessor::CLTonemappingMode wdr_mode = CL3aImageProcessor::WDRdisabled;
Wind Yuand4427312015-02-11 16:09:00 +0800358#endif
359 bool have_cl_processor = false;
Yinhang Liub0ad64b2016-03-18 16:03:51 +0800360 bool have_cl_post_processor = true;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800361 bool need_display = false;
Wind Yuand4427312015-02-11 16:09:00 +0800362 enum v4l2_memory v4l2_mem_type = V4L2_MEMORY_MMAP;
Wind Yuan75564b12015-01-15 06:51:15 -0500363 const char *bin_name = argv[0];
364 int opt;
ShincyTu2808b592015-03-13 17:17:25 +0800365 uint32_t capture_mode = V4L2_CAPTURE_MODE_VIDEO;
366 uint32_t pixel_format = V4L2_PIX_FMT_NV12;
Jia Menga6580232015-10-08 16:51:28 +0800367 bool wdr_type = false;
Wangfei8e5e3e42016-02-18 19:41:54 +0800368 bool retinex_type = false;
zongwaveb7140442016-03-25 18:15:12 +0800369 CLWaveletBasis wavelet_mode = CL_WAVELET_DISABLED;
370 uint32_t wavelet_channel = CL_WAVELET_CHANNEL_UV;
371
yaowang1a5f12122015-07-27 14:53:38 +0800372 int32_t brightness_level = 128;
Sameer Kibey7b429292015-08-07 10:55:38 -0700373 bool have_usbcam = 0;
Wind Yuan155c8f52016-03-18 23:16:59 +0800374 SmartPtr<char> usb_device_name;
Jia Meng8f94a102015-08-11 16:24:19 +0800375 bool sync_mode = false;
Jia Meng757f3c92015-09-09 11:18:36 +0800376 int frame_rate;
Yinhang Liud9346492015-12-17 11:14:25 +0800377 int frame_width = 1920;
378 int frame_height = 1080;
Wind Yuan155c8f52016-03-18 23:16:59 +0800379 SmartPtr<char> path_to_fake = NULL;
Wind Yuan75564b12015-01-15 06:51:15 -0500380
Jia Meng0a532932015-10-15 08:44:09 -0400381 const char *short_opts = "sca:n:m:f:d:b:pi:e:r:h";
Yinhang Liu81c44e02015-06-03 15:47:48 +0800382 const struct option long_opts[] = {
383 {"hdr", required_argument, NULL, 'H'},
384 {"tnr", required_argument, NULL, 'T'},
385 {"tnr-level", required_argument, NULL, 'L'},
wujunkai16606f77622016-03-18 14:41:10 +0800386 {"wdr-mode", required_argument, NULL, 'W'},
Yinhang Liub92930c2015-06-23 16:26:35 +0800387 {"bilateral", no_argument, NULL, 'I'},
Yinhang Liu81c44e02015-06-03 15:47:48 +0800388 {"enable-snr", no_argument, NULL, 'S'},
Jia Meng66efecf2015-06-17 11:11:10 +0000389 {"enable-ee", no_argument, NULL, 'E'},
ShincyTu63e2c262015-06-26 10:52:51 +0800390 {"enable-bnr", no_argument, NULL, 'B'},
Yinhang Liue26b2622015-07-21 18:32:36 +0800391 {"enable-dpc", no_argument, NULL, 'D'},
Wangfei8e5e3e42016-02-18 19:41:54 +0800392 {"enable-retinex", no_argument, NULL, 'X'},
zongwave2ba7f642016-03-15 19:24:12 +0800393 {"wavelet-mode", required_argument, NULL, 'V'},
Sameer Kibey7b429292015-08-07 10:55:38 -0700394 {"usb", required_argument, NULL, 'U'},
Yinhang Liud9346492015-12-17 11:14:25 +0800395 {"resolution", required_argument, NULL, 'R'},
Jia Meng8f94a102015-08-11 16:24:19 +0800396 {"sync", no_argument, NULL, 'Y'},
wujunkai166a84ba052015-09-08 15:54:12 +0800397 {"capture", required_argument, NULL, 'C'},
Wangfei1487b9b2015-08-28 15:10:39 +0800398 {"pipeline", required_argument, NULL, 'P'},
Yinhang Liub0ad64b2016-03-18 16:03:51 +0800399 {"disable-post", no_argument, NULL, 'O'},
Yinhang Liu81c44e02015-06-03 15:47:48 +0800400 {0, 0, 0, 0},
401 };
402
403 while ((opt = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
Wind Yuan75564b12015-01-15 06:51:15 -0500404 switch (opt) {
405 case 'a': {
Wind Yuan6b437392016-02-02 00:31:30 +0800406 XCAM_ASSERT (optarg);
Wind Yuane25ce3f2015-05-04 18:07:29 +0800407 if (!strcmp (optarg, "dynamic"))
408 analyzer_type = AnalyzerTypeDynamic;
409 else if (!strcmp (optarg, "simple"))
Wind Yuan26e9e212015-04-16 15:55:45 +0800410 analyzer_type = AnalyzerTypeSimple;
Wind Yuan75564b12015-01-15 06:51:15 -0500411#if HAVE_IA_AIQ
412 else if (!strcmp (optarg, "aiq"))
Yinhang Liu6c367352016-03-31 20:23:22 +0800413 analyzer_type = AnalyzerTypeAiqTuner;
Jia Meng9724cfe2015-08-12 15:04:45 +0800414 else if (!strcmp (optarg, "hybrid"))
415 analyzer_type = AnalyzerTypeHybrid;
Wind Yuan75564b12015-01-15 06:51:15 -0500416#endif
417 else {
418 print_help (bin_name);
419 return -1;
420 }
421 break;
422 }
423
Wind Yuand4427312015-02-11 16:09:00 +0800424 case 'm': {
Wind Yuan6b437392016-02-02 00:31:30 +0800425 XCAM_ASSERT (optarg);
Wind Yuand4427312015-02-11 16:09:00 +0800426 if (!strcmp (optarg, "dma"))
427 v4l2_mem_type = V4L2_MEMORY_DMABUF;
428 else if (!strcmp (optarg, "mmap"))
429 v4l2_mem_type = V4L2_MEMORY_MMAP;
430 else
431 print_help (bin_name);
432 break;
433 }
434
Wind Yuan75564b12015-01-15 06:51:15 -0500435 case 's':
436 device_manager->enable_save_file (true);
437 break;
438 case 'n':
439 device_manager->set_interval (atoi(optarg));
440 break;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800441#if HAVE_LIBCL
Wind Yuand4427312015-02-11 16:09:00 +0800442 case 'c':
443 have_cl_processor = true;
444 break;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800445#endif
ShincyTu2808b592015-03-13 17:17:25 +0800446 case 'f':
ShincyTuc8466402015-03-31 11:03:39 +0800447 CHECK_EXP ((strlen(optarg) == 4), "invalid pixel format\n");
448 pixel_format = v4l2_fourcc ((unsigned)optarg[0],
449 (unsigned)optarg[1],
450 (unsigned)optarg[2],
451 (unsigned)optarg[3]);
ShincyTu2808b592015-03-13 17:17:25 +0800452 break;
453 case 'd':
Wind Yuan6b437392016-02-02 00:31:30 +0800454 XCAM_ASSERT (optarg);
ShincyTu2808b592015-03-13 17:17:25 +0800455 if (!strcmp (optarg, "still"))
456 capture_mode = V4L2_CAPTURE_MODE_STILL;
457 else if (!strcmp (optarg, "video"))
458 capture_mode = V4L2_CAPTURE_MODE_VIDEO;
459 else {
460 print_help (bin_name);
461 return -1;
462 }
463 break;
yaowang1a5f12122015-07-27 14:53:38 +0800464 case 'b':
465 brightness_level = atoi(optarg);
466 if(brightness_level < 0 || brightness_level > 256) {
467 print_help (bin_name);
468 return -1;
469 }
470 break;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800471 case 'p':
472 need_display = true;
473 break;
Sameer Kibey7b429292015-08-07 10:55:38 -0700474 case 'U':
475 have_usbcam = true;
Wind Yuan155c8f52016-03-18 23:16:59 +0800476 usb_device_name = strndup(optarg, XCAM_MAX_STR_SIZE);
477 XCAM_LOG_DEBUG("using USB camera plugged in at node: %s", XCAM_STR(usb_device_name.ptr ()));
Sameer Kibey7b429292015-08-07 10:55:38 -0700478 break;
Yinhang Liud9346492015-12-17 11:14:25 +0800479 case 'R':
Wind Yuan6b437392016-02-02 00:31:30 +0800480 XCAM_ASSERT (optarg);
Yinhang Liud9346492015-12-17 11:14:25 +0800481 sscanf (optarg, "%d%*c%d", &frame_width, &frame_height);
482 break;
wangfeicf4c4e72015-05-25 17:11:41 +0800483 case 'e': {
Wind Yuan6b437392016-02-02 00:31:30 +0800484 XCAM_ASSERT (optarg);
wangfeicf4c4e72015-05-25 17:11:41 +0800485 if (!strcmp (optarg, "primary"))
486 display_mode = DRM_DISPLAY_MODE_PRIMARY;
487 else if (!strcmp (optarg, "overlay"))
488 display_mode = DRM_DISPLAY_MODE_OVERLAY;
489 else {
490 print_help (bin_name);
491 return -1;
492 }
493 break;
494 }
ShincyTue521cf92015-03-27 15:13:51 +0800495 case 'i':
496 device_manager->set_frame_save(atoi(optarg));
497 break;
Jia Meng8f94a102015-08-11 16:24:19 +0800498 case 'Y':
499 sync_mode = true;
500 break;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800501#if HAVE_LIBCL
Yinhang Liu81c44e02015-06-03 15:47:48 +0800502 case 'H': {
Wind Yuan6b437392016-02-02 00:31:30 +0800503 XCAM_ASSERT (optarg);
Yinhang Liu81c44e02015-06-03 15:47:48 +0800504 if (!strcasecmp (optarg, "rgb"))
505 hdr_type = CL_HDR_TYPE_RGB;
506 else if (!strcasecmp (optarg, "lab"))
507 hdr_type = CL_HDR_TYPE_LAB;
508 else {
509 print_help (bin_name);
510 return -1;
511 }
512 break;
513 }
Yinhang Liub92930c2015-06-23 16:26:35 +0800514 case 'I': {
Jia Meng66efecf2015-06-17 11:11:10 +0000515 denoise_type |= XCAM_DENOISE_TYPE_BILATERAL;
Juan Zhaod9664932015-09-08 10:22:19 +0800516 denoise_type |= XCAM_DENOISE_TYPE_BIYUV;
Yinhang Liu81c44e02015-06-03 15:47:48 +0800517 break;
518 }
519 case 'S': {
Jia Meng66efecf2015-06-17 11:11:10 +0000520 denoise_type |= XCAM_DENOISE_TYPE_SIMPLE;
521 break;
522 }
523 case 'E': {
524 denoise_type |= XCAM_DENOISE_TYPE_EE;
Yinhang Liu81c44e02015-06-03 15:47:48 +0800525 break;
526 }
ShincyTu63e2c262015-06-26 10:52:51 +0800527 case 'B': {
528 denoise_type |= XCAM_DENOISE_TYPE_BNR;
529 break;
530 }
Wangfei8e5e3e42016-02-18 19:41:54 +0800531 case 'X': {
532 retinex_type = true;
533 break;
534 }
zongwave80adcf52016-02-29 12:38:06 +0800535 case 'V': {
zongwave2ba7f642016-03-15 19:24:12 +0800536 XCAM_ASSERT (optarg);
537 if (atoi(optarg) < 0 || atoi(optarg) > 255) {
538 print_help (bin_name);
539 return -1;
540 }
zongwave28a747b2016-03-17 12:49:08 +0800541 if (atoi(optarg) == 1) {
zongwaveb7140442016-03-25 18:15:12 +0800542 wavelet_mode = CL_WAVELET_HAT;
543 wavelet_channel = CL_WAVELET_CHANNEL_Y;
zongwave28a747b2016-03-17 12:49:08 +0800544 } else if (atoi(optarg) == 2) {
zongwaveb7140442016-03-25 18:15:12 +0800545 wavelet_mode = CL_WAVELET_HAT;
546 wavelet_channel = CL_WAVELET_CHANNEL_UV;
547 } else if (atoi(optarg) == 3) {
548 wavelet_mode = CL_WAVELET_HAAR;
549 wavelet_channel = CL_WAVELET_CHANNEL_Y;
550 } else if (atoi(optarg) == 4) {
551 wavelet_mode = CL_WAVELET_HAAR;
552 wavelet_channel = CL_WAVELET_CHANNEL_UV;
553 } else if (atoi(optarg) == 5) {
554 wavelet_mode = CL_WAVELET_HAAR;
555 wavelet_channel = CL_WAVELET_CHANNEL_UV | CL_WAVELET_CHANNEL_Y;
zongwave28a747b2016-03-17 12:49:08 +0800556 } else {
zongwaveb7140442016-03-25 18:15:12 +0800557 wavelet_mode = CL_WAVELET_DISABLED;
zongwave28a747b2016-03-17 12:49:08 +0800558 }
zongwave80adcf52016-02-29 12:38:06 +0800559 break;
560 }
Yinhang Liue26b2622015-07-21 18:32:36 +0800561 case 'D': {
562 dpc_type = true;
563 break;
564 }
Yinhang Liu81c44e02015-06-03 15:47:48 +0800565 case 'T': {
Wind Yuan6b437392016-02-02 00:31:30 +0800566 XCAM_ASSERT (optarg);
Yinhang Liu81c44e02015-06-03 15:47:48 +0800567 if (!strcasecmp (optarg, "yuv"))
568 tnr_type = CL_TNR_TYPE_YUV;
569 else if (!strcasecmp (optarg, "rgb"))
570 tnr_type = CL_TNR_TYPE_RGB;
571 else if (!strcasecmp (optarg, "both"))
572 tnr_type = CL_TNR_TYPE_YUV | CL_TNR_TYPE_RGB;
573 else {
574 print_help (bin_name);
575 return -1;
576 }
577 break;
578 }
579 case 'L': {
Wind Yuan6b437392016-02-02 00:31:30 +0800580 XCAM_ASSERT (optarg);
Yinhang Liu81c44e02015-06-03 15:47:48 +0800581 if (atoi(optarg) < 0 || atoi(optarg) > 255) {
582 print_help (bin_name);
583 return -1;
584 }
585 tnr_level = atoi(optarg);
586 break;
587 }
Jia Menga6580232015-10-08 16:51:28 +0800588 case 'W': {
wujunkai16606f77622016-03-18 14:41:10 +0800589 XCAM_ASSERT (optarg);
590 if (!strcasecmp (optarg, "gaussian"))
591 wdr_mode = CL3aImageProcessor::Gaussian;
592 else if (!strcasecmp (optarg, "haleq"))
593 wdr_mode = CL3aImageProcessor::Haleq;
wujunkai16682950fb2015-10-19 18:09:05 +0800594
wujunkai166b0bd5512016-02-18 18:25:42 +0800595 pixel_format = V4L2_PIX_FMT_SGRBG12;
wujunkai16606f77622016-03-18 14:41:10 +0800596 wdr_type = true;
wujunkai166b0bd5512016-02-18 18:25:42 +0800597 setenv ("AIQ_CPF_PATH", IMX185_WDR_CPF, 1);
598 break;
599 }
Wangfei1487b9b2015-08-28 15:10:39 +0800600 case 'P': {
Wind Yuan6b437392016-02-02 00:31:30 +0800601 XCAM_ASSERT (optarg);
Wangfei1487b9b2015-08-28 15:10:39 +0800602 if (!strcasecmp (optarg, "basic"))
603 pipeline_mode = CL3aImageProcessor::BasicPipelineProfile;
604 else if (!strcasecmp (optarg, "advance"))
605 pipeline_mode = CL3aImageProcessor::AdvancedPipelineProfile;
Wangfei16b65db2015-09-11 14:44:28 +0800606 else if (!strcasecmp (optarg, "extreme"))
607 pipeline_mode = CL3aImageProcessor::ExtremePipelineProfile;
Wangfei1487b9b2015-08-28 15:10:39 +0800608 else {
609 print_help (bin_name);
610 return -1;
611 }
612 break;
613 }
wujunkai166a84ba052015-09-08 15:54:12 +0800614 case 'C': {
Wind Yuan6b437392016-02-02 00:31:30 +0800615 XCAM_ASSERT (optarg);
wujunkai166a84ba052015-09-08 15:54:12 +0800616 if (!strcmp (optarg, "bayer"))
617 capture_stage = CL3aImageProcessor::BasicbayerStage;
618 break;
619 }
Yinhang Liub0ad64b2016-03-18 16:03:51 +0800620 case 'O': {
621 have_cl_post_processor = false;
622 break;
623 }
Yinhang Liuc2f19082015-08-28 12:27:48 +0800624#endif
Jia Meng0a532932015-10-15 08:44:09 -0400625 case 'r': {
626 if (optarg) {
627 XCAM_LOG_INFO ("use raw image %s as input source", optarg);
Wind Yuan155c8f52016-03-18 23:16:59 +0800628 path_to_fake = strndup(optarg, XCAM_MAX_STR_SIZE);
Jia Meng0a532932015-10-15 08:44:09 -0400629 }
630 break;
631 }
Wind Yuan75564b12015-01-15 06:51:15 -0500632 case 'h':
633 print_help (bin_name);
634 return 0;
635
636 default:
637 print_help (bin_name);
638 return -1;
639 }
640 }
641
Yinhang Liud9346492015-12-17 11:14:25 +0800642 device_manager->set_frame_width(frame_width);
643 device_manager->set_frame_height(frame_height);
wangfeicf4c4e72015-05-25 17:11:41 +0800644 if (need_display) {
Wind Yuan683f8662015-03-27 18:52:38 +0800645 device_manager->enable_display (true);
wangfeicf4c4e72015-05-25 17:11:41 +0800646 device_manager->set_display_mode (display_mode);
647 }
ShincyTu2808b592015-03-13 17:17:25 +0800648 if (!device.ptr ()) {
Wind Yuan155c8f52016-03-18 23:16:59 +0800649 if (path_to_fake.ptr ()) {
Jia Meng0a532932015-10-15 08:44:09 -0400650 device = new FakeV4l2Device ();
651 } else if (have_usbcam) {
Wind Yuan155c8f52016-03-18 23:16:59 +0800652 device = new UVCDevice (usb_device_name.ptr ());
Sameer Kibey7b429292015-08-07 10:55:38 -0700653 } else {
654 if (capture_mode == V4L2_CAPTURE_MODE_STILL)
655 device = new AtomispDevice (CAPTURE_DEVICE_STILL);
656 else if (capture_mode == V4L2_CAPTURE_MODE_VIDEO)
657 device = new AtomispDevice (CAPTURE_DEVICE_VIDEO);
658 else
659 device = new AtomispDevice (DEFAULT_CAPTURE_DEVICE);
660 }
ShincyTu2808b592015-03-13 17:17:25 +0800661 }
Wind Yuan75564b12015-01-15 06:51:15 -0500662 if (!event_device.ptr ())
663 event_device = new V4l2SubDevice (DEFAULT_EVENT_DEVICE);
664 if (!isp_controller.ptr ())
665 isp_controller = new IspController (device);
Wind Yuan26e9e212015-04-16 15:55:45 +0800666
667 switch (analyzer_type) {
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800668 case AnalyzerTypeSimple:
669 analyzer = new X3aAnalyzerSimple ();
670 break;
Wind Yuan26e9e212015-04-16 15:55:45 +0800671#if HAVE_IA_AIQ
Yinhang Liu6c367352016-03-31 20:23:22 +0800672 case AnalyzerTypeAiqTuner: {
673 SmartPtr<X3aAnalyzer> aiq_analyzer = new X3aAnalyzerAiq (isp_controller, DEFAULT_CPF_FILE);
674 SmartPtr<X3aAnalyzeTuner> tuner_analyzer = new X3aAnalyzeTuner ();
675 XCAM_ASSERT (aiq_analyzer.ptr () && tuner_analyzer.ptr ());
676 tuner_analyzer->set_analyzer (aiq_analyzer);
677 analyzer = tuner_analyzer;
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800678 break;
Yinhang Liu6c367352016-03-31 20:23:22 +0800679 }
Jia Meng9724cfe2015-08-12 15:04:45 +0800680 case AnalyzerTypeHybrid: {
Jia Mengc54c3322015-08-26 09:45:18 +0800681 path_of_3a = DEFAULT_HYBRID_3A_LIB;
zongwave03954a32015-09-22 15:40:44 +0800682 loader = new X3aAnalyzerLoader (path_of_3a);
Jia Meng9724cfe2015-08-12 15:04:45 +0800683 analyzer = loader->load_hybrid_analyzer (loader, isp_controller, DEFAULT_CPF_FILE);
684 CHECK_EXP (analyzer.ptr (), "load hybrid 3a lib(%s) failed", path_of_3a);
685 break;
686 }
Wind Yuan26e9e212015-04-16 15:55:45 +0800687#endif
Wind Yuane25ce3f2015-05-04 18:07:29 +0800688 case AnalyzerTypeDynamic: {
Jia Meng9724cfe2015-08-12 15:04:45 +0800689 path_of_3a = DEFAULT_DYNAMIC_3A_LIB;
zongwave03954a32015-09-22 15:40:44 +0800690 loader = new X3aAnalyzerLoader (path_of_3a);
Jia Meng9724cfe2015-08-12 15:04:45 +0800691 analyzer = loader->load_dynamic_analyzer (loader);
Wind Yuane25ce3f2015-05-04 18:07:29 +0800692 CHECK_EXP (analyzer.ptr (), "load dynamic 3a lib(%s) failed", path_of_3a);
693 break;
694 }
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800695 default:
696 print_help (bin_name);
697 return -1;
Wind Yuan26e9e212015-04-16 15:55:45 +0800698 }
Jia Meng8f94a102015-08-11 16:24:19 +0800699 XCAM_ASSERT (analyzer.ptr ());
700 analyzer->set_sync_mode (sync_mode);
Wind Yuan75564b12015-01-15 06:51:15 -0500701
702 signal(SIGINT, dev_stop_handler);
703
704 device->set_sensor_id (0);
ShincyTu2808b592015-03-13 17:17:25 +0800705 device->set_capture_mode (capture_mode);
Wind Yuan75564b12015-01-15 06:51:15 -0500706 //device->set_mem_type (V4L2_MEMORY_DMABUF);
Wind Yuand4427312015-02-11 16:09:00 +0800707 device->set_mem_type (v4l2_mem_type);
Wind Yuan75564b12015-01-15 06:51:15 -0500708 device->set_buffer_count (8);
Jia Meng757f3c92015-09-09 11:18:36 +0800709 if (pixel_format == V4L2_PIX_FMT_SGRBG12) {
710 frame_rate = 30;
711 device->set_framerate (frame_rate, 1);
712 }
713 else {
714 frame_rate = 25;
715 device->set_framerate (frame_rate, 1);
wujunkai16606f77622016-03-18 14:41:10 +0800716 if(wdr_type == true) {
wujunkai166a9a55f22015-10-10 15:53:32 +0800717 XCAM_LOG_WARNING("Tonemapping is only applicable under BA12 format. Disable tonemapping automatically.");
wujunkai16606f77622016-03-18 14:41:10 +0800718 wdr_type = false;
wujunkai166a9a55f22015-10-10 15:53:32 +0800719 }
Jia Meng757f3c92015-09-09 11:18:36 +0800720 }
Wind Yuan75564b12015-01-15 06:51:15 -0500721 ret = device->open ();
722 CHECK (ret, "device(%s) open failed", device->get_device_name());
Yinhang Liud9346492015-12-17 11:14:25 +0800723 ret = device->set_format (frame_width, frame_height, pixel_format, V4L2_FIELD_NONE, frame_width * 2);
Wind Yuan75564b12015-01-15 06:51:15 -0500724 CHECK (ret, "device(%s) set format failed", device->get_device_name());
725
726 ret = event_device->open ();
Wind Yuanb67045c2015-08-27 13:50:53 +0800727 if (ret == XCAM_RETURN_NO_ERROR) {
728 CHECK (ret, "event device(%s) open failed", event_device->get_device_name());
729 int event = V4L2_EVENT_ATOMISP_3A_STATS_READY;
730 ret = event_device->subscribe_event (event);
731 CHECK_CONTINUE (
732 ret,
733 "device(%s) subscribe event(%d) failed",
734 event_device->get_device_name(), event);
735 event = V4L2_EVENT_FRAME_SYNC;
736 ret = event_device->subscribe_event (event);
737 CHECK_CONTINUE (
738 ret,
739 "device(%s) subscribe event(%d) failed",
740 event_device->get_device_name(), event);
741
742 device_manager->set_event_device (event_device);
743 }
Wind Yuan75564b12015-01-15 06:51:15 -0500744
745 device_manager->set_capture_device (device);
Wind Yuan75564b12015-01-15 06:51:15 -0500746 device_manager->set_isp_controller (isp_controller);
747 if (analyzer.ptr())
zongwave03954a32015-09-22 15:40:44 +0800748 device_manager->set_3a_analyzer (analyzer);
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800749
750 if (have_cl_processor)
751 isp_processor = new IspExposureImageProcessor (isp_controller);
752 else
753 isp_processor = new IspImageProcessor (isp_controller);
754
755 XCAM_ASSERT (isp_processor.ptr ());
Wind Yuane4ba0c92015-03-26 16:59:06 +0800756 device_manager->add_image_processor (isp_processor);
Yinhang Liuc2f19082015-08-28 12:27:48 +0800757#if HAVE_LIBCL
Wind Yuand4427312015-02-11 16:09:00 +0800758 if (have_cl_processor) {
Wind Yuane4ba0c92015-03-26 16:59:06 +0800759 cl_processor = new CL3aImageProcessor ();
Wind Yuan7ddf2602015-04-14 18:49:45 +0800760 cl_processor->set_stats_callback(device_manager);
Yinhang Liue26b2622015-07-21 18:32:36 +0800761 cl_processor->set_dpc(dpc_type);
Yinhang Liu81c44e02015-06-03 15:47:48 +0800762 cl_processor->set_hdr (hdr_type);
Jia Meng66efecf2015-06-17 11:11:10 +0000763 cl_processor->set_denoise (denoise_type);
wujunkai16606f77622016-03-18 14:41:10 +0800764 cl_processor->set_tonemapping(wdr_mode);
Jia Menga6580232015-10-08 16:51:28 +0800765 cl_processor->set_gamma (!wdr_type); // disable gamma for WDR
zongwaveb7140442016-03-25 18:15:12 +0800766 cl_processor->set_wavelet (wavelet_mode, wavelet_channel);
wujunkai166a84ba052015-09-08 15:54:12 +0800767 cl_processor->set_capture_stage (capture_stage);
wujunkai166c8f3b442016-02-29 17:12:09 +0800768
769 if (wdr_type) {
770 cl_processor->set_3a_stats_bits(12);
771 }
Yinhang Liu81c44e02015-06-03 15:47:48 +0800772 cl_processor->set_tnr (tnr_type, tnr_level);
Wangfei1487b9b2015-08-28 15:10:39 +0800773 cl_processor->set_profile (pipeline_mode);
yaowang1a5f12122015-07-27 14:53:38 +0800774 analyzer->set_parameter_brightness((brightness_level - 128) / 128.0);
Wind Yuand4427312015-02-11 16:09:00 +0800775 device_manager->add_image_processor (cl_processor);
776 }
Yinhang Liu3c17fea2016-03-15 10:47:03 +0800777
Yinhang Liub0ad64b2016-03-18 16:03:51 +0800778 if (have_cl_post_processor) {
779 cl_post_processor = new CLPostImageProcessor ();
Yinhang Liu3c721c12016-03-15 15:03:51 +0800780
Yinhang Liub0ad64b2016-03-18 16:03:51 +0800781 cl_post_processor->set_retinex (retinex_type);
Yinhang Liu3c721c12016-03-15 15:03:51 +0800782
Yinhang Liud6d824a2016-03-22 20:43:00 +0800783 if (need_display) {
Yinhang Liub0ad64b2016-03-18 16:03:51 +0800784 cl_post_processor->set_output_format (V4L2_PIX_FMT_XBGR32);
785 }
786 device_manager->add_image_processor (cl_post_processor);
Yinhang Liu3c17fea2016-03-15 10:47:03 +0800787 }
Wind Yuand4427312015-02-11 16:09:00 +0800788#endif
Wind Yuane4ba0c92015-03-26 16:59:06 +0800789
Jia Meng0a532932015-10-15 08:44:09 -0400790 SmartPtr<PollThread> poll_thread;
Wind Yuan155c8f52016-03-18 23:16:59 +0800791 if (path_to_fake.ptr ())
792 poll_thread = new FakePollThread (path_to_fake.ptr ());
Jia Meng0a532932015-10-15 08:44:09 -0400793 else
794 poll_thread = new PollThread ();
795 device_manager->set_poll_thread (poll_thread);
796
Wind Yuan75564b12015-01-15 06:51:15 -0500797 ret = device_manager->start ();
798 CHECK (ret, "device manager start failed");
799
Jia Meng757f3c92015-09-09 11:18:36 +0800800 // hard code exposure range and max gain for imx185 WDR
Jia Menga6580232015-10-08 16:51:28 +0800801 if (wdr_type) {
Jia Meng757f3c92015-09-09 11:18:36 +0800802 if (frame_rate == 30)
803 analyzer->set_ae_exposure_time_range (80 * 1110 * 1000 / 37125, 1120 * 1110 * 1000 / 37125);
804 else
Jia Menga6580232015-10-08 16:51:28 +0800805 analyzer->set_ae_exposure_time_range (80 * 1320 * 1000 / 37125, 1120 * 1320 * 1000 / 37125);
Jia Meng757f3c92015-09-09 11:18:36 +0800806 analyzer->set_ae_max_analog_gain (3.98); // 12dB
807 }
808
Wind Yuan75564b12015-01-15 06:51:15 -0500809 // wait for interruption
810 {
811 SmartLock locker (g_mutex);
812 while (!g_stop)
813 g_cond.wait (g_mutex);
814 }
815
816 ret = device_manager->stop();
817 CHECK_CONTINUE (ret, "device manager stop failed");
818 device->close ();
819 event_device->close ();
Wind Yuan75564b12015-01-15 06:51:15 -0500820
821 return 0;
822}