blob: d636ae28e37878c770596cdae02e41990b44db16 [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"
30#endif
Wind Yuand4427312015-02-11 16:09:00 +080031#if HAVE_LIBCL
Wind Yuane4ba0c92015-03-26 16:59:06 +080032#include "cl_3a_image_processor.h"
Yinhang Liu2ab1f992016-03-15 10:41:17 +080033#include "cl_post_image_processor.h"
wangfeicf4c4e72015-05-25 17:11:41 +080034#include "cl_csc_image_processor.h"
Yinhang Liu81c44e02015-06-03 15:47:48 +080035#include "cl_hdr_handler.h"
36#include "cl_tnr_handler.h"
Wind Yuane4ba0c92015-03-26 16:59:06 +080037#endif
38#if HAVE_LIBDRM
39#include "drm_display.h"
Wind Yuand4427312015-02-11 16:09:00 +080040#endif
zongwave03954a32015-09-22 15:40:44 +080041#include "x3a_analyzer_loader.h"
Jia Meng0a532932015-10-15 08:44:09 -040042#include "poll_thread.h"
43#include "fake_poll_thread.h"
Jia Meng66efecf2015-06-17 11:11:10 +000044#include <base/xcam_3a_types.h>
Wind Yuan75564b12015-01-15 06:51:15 -050045#include <unistd.h>
46#include <signal.h>
47#include <stdlib.h>
ShincyTue521cf92015-03-27 15:13:51 +080048#include <string>
Yinhang Liu81c44e02015-06-03 15:47:48 +080049#include <getopt.h>
John Yeae9da732015-01-22 13:36:36 +080050#include "test_common.h"
51
Wind Yuan75564b12015-01-15 06:51:15 -050052using namespace XCam;
53
wujunkai16682950fb2015-10-19 18:09:05 +080054#define IMX185_WDR_CPF "/etc/atomisp/imx185_wdr.cpf"
55
ShincyTue521cf92015-03-27 15:13:51 +080056static Mutex g_mutex;
57static Cond g_cond;
58static bool g_stop = false;
59
Wind Yuan75564b12015-01-15 06:51:15 -050060class MainDeviceManager
61 : public DeviceManager
62{
63public:
64 MainDeviceManager ()
65 : _file (NULL)
66 , _save_file (false)
67 , _interval (1)
Yinhang Liud9346492015-12-17 11:14:25 +080068 , _frame_width (0)
69 , _frame_height (0)
Wind Yuan75564b12015-01-15 06:51:15 -050070 , _frame_count (0)
ShincyTue521cf92015-03-27 15:13:51 +080071 , _frame_save (0)
Wind Yuan683f8662015-03-27 18:52:38 +080072 , _enable_display (false)
Wind Yuane4ba0c92015-03-26 16:59:06 +080073 {
74#if HAVE_LIBDRM
75 _display = DrmDisplay::instance();
76#endif
Wind Yuan91625802015-06-24 15:36:01 +080077 XCAM_OBJ_PROFILING_INIT;
Wind Yuane4ba0c92015-03-26 16:59:06 +080078 }
Wind Yuan75564b12015-01-15 06:51:15 -050079
80 ~MainDeviceManager () {
81 close_file ();
82 }
83
84 void enable_save_file (bool enable) {
85 _save_file = enable;
86 }
Yinhang Liud9346492015-12-17 11:14:25 +080087
Wind Yuan75564b12015-01-15 06:51:15 -050088 void set_interval (uint32_t inteval) {
89 _interval = inteval;
90 }
Yinhang Liud9346492015-12-17 11:14:25 +080091
92 void set_frame_width (uint32_t frame_width) {
93 _frame_width = frame_width;
94 }
95
96 void set_frame_height (uint32_t frame_height) {
97 _frame_height = frame_height;
98 }
99
ShincyTue521cf92015-03-27 15:13:51 +0800100 void set_frame_save (uint32_t frame_save) {
101 _frame_save = frame_save;
102 }
Wind Yuan75564b12015-01-15 06:51:15 -0500103
Wind Yuan683f8662015-03-27 18:52:38 +0800104 void enable_display(bool value) {
105 _enable_display = value;
106 }
107
wangfeicf4c4e72015-05-25 17:11:41 +0800108 void set_display_mode(DrmDisplayMode mode) {
109 _display->set_display_mode (mode);
110 }
111
Wind Yuan75564b12015-01-15 06:51:15 -0500112protected:
Wind Yuan73af3932015-07-02 17:52:43 +0800113 virtual void handle_message (const SmartPtr<XCamMessage> &msg);
114 virtual void handle_buffer (const SmartPtr<VideoBuffer> &buf);
Wind Yuan75564b12015-01-15 06:51:15 -0500115
Wind Yuan73af3932015-07-02 17:52:43 +0800116 int display_buf (const SmartPtr<VideoBuffer> &buf);
Wind Yuane4ba0c92015-03-26 16:59:06 +0800117
Wind Yuan75564b12015-01-15 06:51:15 -0500118private:
119 void open_file ();
120 void close_file ();
Wind Yuan71111322016-02-24 22:56:27 +0800121 XCamReturn write_buf (const SmartPtr<VideoBuffer> &buf);
Wind Yuan75564b12015-01-15 06:51:15 -0500122
123 FILE *_file;
124 bool _save_file;
125 uint32_t _interval;
Yinhang Liud9346492015-12-17 11:14:25 +0800126 uint32_t _frame_width;
127 uint32_t _frame_height;
Wind Yuan75564b12015-01-15 06:51:15 -0500128 uint32_t _frame_count;
ShincyTue521cf92015-03-27 15:13:51 +0800129 uint32_t _frame_save;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800130 SmartPtr<DrmDisplay> _display;
Wind Yuan683f8662015-03-27 18:52:38 +0800131 bool _enable_display;
Wind Yuan91625802015-06-24 15:36:01 +0800132 XCAM_OBJ_PROFILING_DEFINES;
Wind Yuan75564b12015-01-15 06:51:15 -0500133};
134
135void
Wind Yuan73af3932015-07-02 17:52:43 +0800136MainDeviceManager::handle_message (const SmartPtr<XCamMessage> &msg)
Wind Yuan75564b12015-01-15 06:51:15 -0500137{
138 XCAM_UNUSED (msg);
139}
140
141void
Wind Yuan73af3932015-07-02 17:52:43 +0800142MainDeviceManager::handle_buffer (const SmartPtr<VideoBuffer> &buf)
Wind Yuan75564b12015-01-15 06:51:15 -0500143{
Wind Yuan683f8662015-03-27 18:52:38 +0800144 FPS_CALCULATION (fps_buf, 30);
145
Wind Yuan91625802015-06-24 15:36:01 +0800146 XCAM_OBJ_PROFILING_START;
147
Wind Yuan683f8662015-03-27 18:52:38 +0800148 if (_enable_display)
149 display_buf (buf);
Wind Yuane4ba0c92015-03-26 16:59:06 +0800150
Wind Yuan91625802015-06-24 15:36:01 +0800151 XCAM_OBJ_PROFILING_END("main_dev_manager_display", 30);
152
Wind Yuan75564b12015-01-15 06:51:15 -0500153 if (!_save_file)
154 return ;
155
156 if ((_frame_count++ % _interval) != 0)
157 return;
158
ShincyTue521cf92015-03-27 15:13:51 +0800159 if ((_frame_save != 0) && (_frame_count > _frame_save)) {
160 SmartLock locker (g_mutex);
161 g_stop = true;
162 g_cond.broadcast ();
163 return;
164 }
165
Wind Yuan75564b12015-01-15 06:51:15 -0500166 open_file ();
Jia Meng6c9241d2015-06-12 11:08:45 +0000167
168 if (!_file) {
169 XCAM_LOG_ERROR ("open file failed");
Jia Meng54a2dcb2015-08-20 15:23:47 +0800170 return;
Jia Meng6c9241d2015-06-12 11:08:45 +0000171 }
Wind Yuan71111322016-02-24 22:56:27 +0800172 write_buf (buf);
Wind Yuan75564b12015-01-15 06:51:15 -0500173}
174
Wind Yuane4ba0c92015-03-26 16:59:06 +0800175int
Wind Yuan73af3932015-07-02 17:52:43 +0800176MainDeviceManager::display_buf (const SmartPtr<VideoBuffer> &data)
Wind Yuane4ba0c92015-03-26 16:59:06 +0800177{
178#if HAVE_LIBDRM
179 XCamReturn ret = XCAM_RETURN_NO_ERROR;
Wind Yuan73af3932015-07-02 17:52:43 +0800180 SmartPtr<VideoBuffer> buf = data;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800181 const VideoBufferInfo & frame_info = buf->get_video_info ();
182 struct v4l2_rect rect = { 0, 0, (int)frame_info.width, (int)frame_info.height };
183
184 if (!_display->is_render_inited ()) {
Yinhang Liud9346492015-12-17 11:14:25 +0800185 ret = _display->render_init (0, 0, this->_frame_width, this->_frame_height,
186 frame_info.format, &rect);
Wind Yuane4ba0c92015-03-26 16:59:06 +0800187 CHECK (ret, "display failed on render_init");
188 }
189 ret = _display->render_setup_frame_buffer (buf);
190 CHECK (ret, "display failed on framebuf set");
191 ret = _display->render_buffer (buf);
192 CHECK (ret, "display failed on rendering");
193#endif
194 return 0;
195}
196
197
Wind Yuan75564b12015-01-15 06:51:15 -0500198void
199MainDeviceManager::open_file ()
200{
ShincyTue521cf92015-03-27 15:13:51 +0800201 if ((_file) && (_frame_save == 0))
Wind Yuan75564b12015-01-15 06:51:15 -0500202 return;
ShincyTue521cf92015-03-27 15:13:51 +0800203
204 std::string file_name = DEFAULT_SAVE_FILE_NAME;
205
206 if (_frame_save != 0) {
207 file_name += std::to_string(_frame_count);
208 }
209 file_name += ".raw";
210
211 _file = fopen(file_name.c_str(), "wb");
Wind Yuan75564b12015-01-15 06:51:15 -0500212}
213
214void
215MainDeviceManager::close_file ()
216{
217 if (_file)
218 fclose (_file);
219 _file = NULL;
220}
221
Wind Yuan71111322016-02-24 22:56:27 +0800222XCamReturn
223MainDeviceManager::write_buf (const SmartPtr<VideoBuffer> &buf)
224{
225 const VideoBufferInfo &info = buf->get_video_info ();
226 VideoBufferPlanarInfo planar;
227 uint8_t *memory = NULL;
228 XCamReturn ret = XCAM_RETURN_NO_ERROR;
229
230 memory = buf->map ();
231 if (!memory) {
232 XCAM_LOG_ERROR ("map buffer failed in write_buf");
233 return XCAM_RETURN_ERROR_MEM;
234 }
235
236 for (uint32_t index = 0; index < info.components; index++) {
237 info.get_planar_info (planar, index);
238 uint32_t line_bytes = planar.width * planar.pixel_bytes;
239
240 for (uint32_t i = 0; i < planar.height; i++) {
241 if (fwrite (memory + info.offsets [index] + i * info.strides [index], 1, line_bytes, _file) != line_bytes) {
242 XCAM_LOG_ERROR ("write file failed, size doesn't match");
243 ret = XCAM_RETURN_ERROR_FILE;
244 }
245 }
246 }
247 buf->unmap ();
248 return ret;
249}
250
Wind Yuan75564b12015-01-15 06:51:15 -0500251#define V4L2_CAPTURE_MODE_STILL 0x2000
252#define V4L2_CAPTURE_MODE_VIDEO 0x4000
253#define V4L2_CAPTURE_MODE_PREVIEW 0x8000
254
Wind Yuan26e9e212015-04-16 15:55:45 +0800255typedef enum {
256 AnalyzerTypeSimple = 0,
257 AnalyzerTypeAiq,
Wind Yuane25ce3f2015-05-04 18:07:29 +0800258 AnalyzerTypeDynamic,
Jia Meng9724cfe2015-08-12 15:04:45 +0800259 AnalyzerTypeHybrid,
Wind Yuan26e9e212015-04-16 15:55:45 +0800260} AnalyzerType;
261
Wind Yuan75564b12015-01-15 06:51:15 -0500262void dev_stop_handler(int sig)
263{
264 XCAM_UNUSED (sig);
265
266 SmartLock locker (g_mutex);
267 g_stop = true;
268 g_cond.broadcast ();
269
270 //exit(0);
271}
272
273void print_help (const char *bin_name)
274{
275 printf ("Usage: %s [-a analyzer]\n"
Yinhang Liu81c44e02015-06-03 15:47:48 +0800276 "Configurations:\n"
ShincyTue521cf92015-03-27 15:13:51 +0800277 "\t -a analyzer specify a analyzer\n"
Wind Yuane25ce3f2015-05-04 18:07:29 +0800278 "\t select from [simple, aiq, dynamic], default is [simple]\n"
ShincyTue521cf92015-03-27 15:13:51 +0800279 "\t -m mem_type specify video memory type\n"
280 "\t mem_type select from [dma, mmap], default is [mmap]\n"
281 "\t -s save file to %s\n"
282 "\t -n interval save file on every [interval] frame\n"
Yinhang Liuc2f19082015-08-28 12:27:48 +0800283#if HAVE_LIBCL
ShincyTue521cf92015-03-27 15:13:51 +0800284 "\t -c process image with cl kernel\n"
Yinhang Liuc2f19082015-08-28 12:27:48 +0800285#endif
ShincyTue521cf92015-03-27 15:13:51 +0800286 "\t -f pixel_fmt specify output pixel format\n"
wujunkai1669845b022015-08-27 15:59:27 +0800287 "\t pixel_fmt select from [NV12, YUYV, BA10, BA12], default is [NV12]\n"
ShincyTue521cf92015-03-27 15:13:51 +0800288 "\t -d cap_mode specify capture mode\n"
289 "\t cap_mode select from [video, still], default is [video]\n"
yaowang1a5f12122015-07-27 14:53:38 +0800290 "\t -b brightness specify brightness level\n"
291 "\t brightness level select from [0, 256], default is [128]\n"
ShincyTue521cf92015-03-27 15:13:51 +0800292 "\t -i frame_save specify the frame count to save, default is 0 which means endless\n"
wangfeicf4c4e72015-05-25 17:11:41 +0800293 "\t -p preview on local display\n"
Sameer Kibey7b429292015-08-07 10:55:38 -0700294 "\t --usb specify node for usb camera device, enables capture path through USB camera \n"
295 "\t specify [/dev/video4, /dev/video5] depending on which node USB camera is attached\n"
Yinhang Liud9346492015-12-17 11:14:25 +0800296 "\t --resolution specify the resolution of usb camera\n"
297 "\t select from [1920x1080, 1280x720 ...], default is [1920x1080]\n"
wangfeicf4c4e72015-05-25 17:11:41 +0800298 "\t -e display_mode preview mode\n"
299 "\t select from [primary, overlay], default is [primary]\n"
Jia Meng8f94a102015-08-11 16:24:19 +0800300 "\t --sync set analyzer in sync mode\n"
Jia Meng0a532932015-10-15 08:44:09 -0400301 "\t -r raw_input specify the path of raw image as fake source instead of live camera\n"
ShincyTue521cf92015-03-27 15:13:51 +0800302 "\t -h help\n"
Yinhang Liuc2f19082015-08-28 12:27:48 +0800303#if HAVE_LIBCL
Yinhang Liu81c44e02015-06-03 15:47:48 +0800304 "CL features:\n"
wujunkai166a84ba052015-09-08 15:54:12 +0800305 "\t --capture capture_stage specify the capture stage of image\n"
306 "\t capture_stage select from [bayer, tonemapping], default is [tonemapping]\n"
Yinhang Liu81c44e02015-06-03 15:47:48 +0800307 "\t --hdr specify hdr type, default is hdr off\n"
308 "\t select from [rgb, lab]\n"
309 "\t --tnr specify temporal noise reduction type, default is tnr off\n"
310 "\t select from [rgb, yuv, both]\n"
311 "\t --tnr-level specify tnr level\n"
wujunkai16606f77622016-03-18 14:41:10 +0800312 "\t --wdr-mode specify wdr mode. select from [gaussian, haleq]\n"
Yinhang Liub92930c2015-06-23 16:26:35 +0800313 "\t --bilateral enable bilateral noise reduction\n"
Yinhang Liu81c44e02015-06-03 15:47:48 +0800314 "\t --enable-snr enable simple noise reduction\n"
Jia Meng66efecf2015-06-17 11:11:10 +0000315 "\t --enable-ee enable YEENR\n"
ShincyTu63e2c262015-06-26 10:52:51 +0800316 "\t --enable-bnr enable bayer noise reduction\n"
Yinhang Liue26b2622015-07-21 18:32:36 +0800317 "\t --enable-dpc enable defect pixel correction\n"
Wangfei8e5e3e42016-02-18 19:41:54 +0800318 "\t --enable-retinex enable retinex\n"
zongwave2ba7f642016-03-15 19:24:12 +0800319 "\t --wavelet-mode specify wavelet mode\n"
Wangfei1487b9b2015-08-28 15:10:39 +0800320 "\t --pipeline pipe mode\n"
Wangfei16b65db2015-09-11 14:44:28 +0800321 "\t select from [basic, advance, extreme], default is [basic]\n"
Yinhang Liub0ad64b2016-03-18 16:03:51 +0800322 "\t --disable-post disable cl post image processor\n"
Yinhang Liue26b2622015-07-21 18:32:36 +0800323 "(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 +0800324#endif
Wind Yuan75564b12015-01-15 06:51:15 -0500325 , bin_name
326 , DEFAULT_SAVE_FILE_NAME);
327}
328
329int main (int argc, char *argv[])
330{
331 XCamReturn ret = XCAM_RETURN_NO_ERROR;
332 SmartPtr<MainDeviceManager> device_manager = new MainDeviceManager;
333 SmartPtr<V4l2Device> device;
334 SmartPtr<V4l2SubDevice> event_device;
335 SmartPtr<IspController> isp_controller;
336 SmartPtr<X3aAnalyzer> analyzer;
zongwave03954a32015-09-22 15:40:44 +0800337 SmartPtr<X3aAnalyzerLoader> loader;
Jia Meng9724cfe2015-08-12 15:04:45 +0800338 const char *path_of_3a;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800339 SmartPtr<ImageProcessor> isp_processor;
Wind Yuan26e9e212015-04-16 15:55:45 +0800340 AnalyzerType analyzer_type = AnalyzerTypeSimple;
wangfeicf4c4e72015-05-25 17:11:41 +0800341 DrmDisplayMode display_mode = DRM_DISPLAY_MODE_PRIMARY;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800342#if HAVE_LIBDRM
343 SmartPtr<DrmDisplay> drm_disp = DrmDisplay::instance();
344#endif
345
Wind Yuand4427312015-02-11 16:09:00 +0800346#if HAVE_LIBCL
Wind Yuane4ba0c92015-03-26 16:59:06 +0800347 SmartPtr<CL3aImageProcessor> cl_processor;
Yinhang Liu2ab1f992016-03-15 10:41:17 +0800348 SmartPtr<CLPostImageProcessor> cl_post_processor;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800349 uint32_t hdr_type = CL_HDR_DISABLE;
350 uint32_t tnr_type = CL_TNR_DISABLE;
351 uint32_t denoise_type = 0;
352 uint8_t tnr_level = 0;
353 bool dpc_type = false;
Wangfei1487b9b2015-08-28 15:10:39 +0800354 CL3aImageProcessor::PipelineProfile pipeline_mode = CL3aImageProcessor::BasicPipelineProfile;
wujunkai166a84ba052015-09-08 15:54:12 +0800355 CL3aImageProcessor::CaptureStage capture_stage = CL3aImageProcessor::TonemappingStage;
wujunkai16606f77622016-03-18 14:41:10 +0800356 CL3aImageProcessor::CLTonemappingMode wdr_mode = CL3aImageProcessor::WDRdisabled;
Wind Yuand4427312015-02-11 16:09:00 +0800357#endif
358 bool have_cl_processor = false;
Yinhang Liub0ad64b2016-03-18 16:03:51 +0800359 bool have_cl_post_processor = true;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800360 bool need_display = false;
Wind Yuand4427312015-02-11 16:09:00 +0800361 enum v4l2_memory v4l2_mem_type = V4L2_MEMORY_MMAP;
Wind Yuan75564b12015-01-15 06:51:15 -0500362 const char *bin_name = argv[0];
363 int opt;
ShincyTu2808b592015-03-13 17:17:25 +0800364 uint32_t capture_mode = V4L2_CAPTURE_MODE_VIDEO;
365 uint32_t pixel_format = V4L2_PIX_FMT_NV12;
Jia Menga6580232015-10-08 16:51:28 +0800366 bool wdr_type = false;
Wangfei8e5e3e42016-02-18 19:41:54 +0800367 bool retinex_type = false;
zongwaveb7140442016-03-25 18:15:12 +0800368 CLWaveletBasis wavelet_mode = CL_WAVELET_DISABLED;
369 uint32_t wavelet_channel = CL_WAVELET_CHANNEL_UV;
370
yaowang1a5f12122015-07-27 14:53:38 +0800371 int32_t brightness_level = 128;
Sameer Kibey7b429292015-08-07 10:55:38 -0700372 bool have_usbcam = 0;
Wind Yuan155c8f52016-03-18 23:16:59 +0800373 SmartPtr<char> usb_device_name;
Jia Meng8f94a102015-08-11 16:24:19 +0800374 bool sync_mode = false;
Jia Meng757f3c92015-09-09 11:18:36 +0800375 int frame_rate;
Yinhang Liud9346492015-12-17 11:14:25 +0800376 int frame_width = 1920;
377 int frame_height = 1080;
Wind Yuan155c8f52016-03-18 23:16:59 +0800378 SmartPtr<char> path_to_fake = NULL;
Wind Yuan75564b12015-01-15 06:51:15 -0500379
Jia Meng0a532932015-10-15 08:44:09 -0400380 const char *short_opts = "sca:n:m:f:d:b:pi:e:r:h";
Yinhang Liu81c44e02015-06-03 15:47:48 +0800381 const struct option long_opts[] = {
382 {"hdr", required_argument, NULL, 'H'},
383 {"tnr", required_argument, NULL, 'T'},
384 {"tnr-level", required_argument, NULL, 'L'},
wujunkai16606f77622016-03-18 14:41:10 +0800385 {"wdr-mode", required_argument, NULL, 'W'},
Yinhang Liub92930c2015-06-23 16:26:35 +0800386 {"bilateral", no_argument, NULL, 'I'},
Yinhang Liu81c44e02015-06-03 15:47:48 +0800387 {"enable-snr", no_argument, NULL, 'S'},
Jia Meng66efecf2015-06-17 11:11:10 +0000388 {"enable-ee", no_argument, NULL, 'E'},
ShincyTu63e2c262015-06-26 10:52:51 +0800389 {"enable-bnr", no_argument, NULL, 'B'},
Yinhang Liue26b2622015-07-21 18:32:36 +0800390 {"enable-dpc", no_argument, NULL, 'D'},
Wangfei8e5e3e42016-02-18 19:41:54 +0800391 {"enable-retinex", no_argument, NULL, 'X'},
zongwave2ba7f642016-03-15 19:24:12 +0800392 {"wavelet-mode", required_argument, NULL, 'V'},
Sameer Kibey7b429292015-08-07 10:55:38 -0700393 {"usb", required_argument, NULL, 'U'},
Yinhang Liud9346492015-12-17 11:14:25 +0800394 {"resolution", required_argument, NULL, 'R'},
Jia Meng8f94a102015-08-11 16:24:19 +0800395 {"sync", no_argument, NULL, 'Y'},
wujunkai166a84ba052015-09-08 15:54:12 +0800396 {"capture", required_argument, NULL, 'C'},
Wangfei1487b9b2015-08-28 15:10:39 +0800397 {"pipeline", required_argument, NULL, 'P'},
Yinhang Liub0ad64b2016-03-18 16:03:51 +0800398 {"disable-post", no_argument, NULL, 'O'},
Yinhang Liu81c44e02015-06-03 15:47:48 +0800399 {0, 0, 0, 0},
400 };
401
402 while ((opt = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
Wind Yuan75564b12015-01-15 06:51:15 -0500403 switch (opt) {
404 case 'a': {
Wind Yuan6b437392016-02-02 00:31:30 +0800405 XCAM_ASSERT (optarg);
Wind Yuane25ce3f2015-05-04 18:07:29 +0800406 if (!strcmp (optarg, "dynamic"))
407 analyzer_type = AnalyzerTypeDynamic;
408 else if (!strcmp (optarg, "simple"))
Wind Yuan26e9e212015-04-16 15:55:45 +0800409 analyzer_type = AnalyzerTypeSimple;
Wind Yuan75564b12015-01-15 06:51:15 -0500410#if HAVE_IA_AIQ
411 else if (!strcmp (optarg, "aiq"))
Wind Yuan26e9e212015-04-16 15:55:45 +0800412 analyzer_type = AnalyzerTypeAiq;
Jia Meng9724cfe2015-08-12 15:04:45 +0800413 else if (!strcmp (optarg, "hybrid"))
414 analyzer_type = AnalyzerTypeHybrid;
Wind Yuan75564b12015-01-15 06:51:15 -0500415#endif
416 else {
417 print_help (bin_name);
418 return -1;
419 }
420 break;
421 }
422
Wind Yuand4427312015-02-11 16:09:00 +0800423 case 'm': {
Wind Yuan6b437392016-02-02 00:31:30 +0800424 XCAM_ASSERT (optarg);
Wind Yuand4427312015-02-11 16:09:00 +0800425 if (!strcmp (optarg, "dma"))
426 v4l2_mem_type = V4L2_MEMORY_DMABUF;
427 else if (!strcmp (optarg, "mmap"))
428 v4l2_mem_type = V4L2_MEMORY_MMAP;
429 else
430 print_help (bin_name);
431 break;
432 }
433
Wind Yuan75564b12015-01-15 06:51:15 -0500434 case 's':
435 device_manager->enable_save_file (true);
436 break;
437 case 'n':
438 device_manager->set_interval (atoi(optarg));
439 break;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800440#if HAVE_LIBCL
Wind Yuand4427312015-02-11 16:09:00 +0800441 case 'c':
442 have_cl_processor = true;
443 break;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800444#endif
ShincyTu2808b592015-03-13 17:17:25 +0800445 case 'f':
ShincyTuc8466402015-03-31 11:03:39 +0800446 CHECK_EXP ((strlen(optarg) == 4), "invalid pixel format\n");
447 pixel_format = v4l2_fourcc ((unsigned)optarg[0],
448 (unsigned)optarg[1],
449 (unsigned)optarg[2],
450 (unsigned)optarg[3]);
ShincyTu2808b592015-03-13 17:17:25 +0800451 break;
452 case 'd':
Wind Yuan6b437392016-02-02 00:31:30 +0800453 XCAM_ASSERT (optarg);
ShincyTu2808b592015-03-13 17:17:25 +0800454 if (!strcmp (optarg, "still"))
455 capture_mode = V4L2_CAPTURE_MODE_STILL;
456 else if (!strcmp (optarg, "video"))
457 capture_mode = V4L2_CAPTURE_MODE_VIDEO;
458 else {
459 print_help (bin_name);
460 return -1;
461 }
462 break;
yaowang1a5f12122015-07-27 14:53:38 +0800463 case 'b':
464 brightness_level = atoi(optarg);
465 if(brightness_level < 0 || brightness_level > 256) {
466 print_help (bin_name);
467 return -1;
468 }
469 break;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800470 case 'p':
471 need_display = true;
472 break;
Sameer Kibey7b429292015-08-07 10:55:38 -0700473 case 'U':
474 have_usbcam = true;
Wind Yuan155c8f52016-03-18 23:16:59 +0800475 usb_device_name = strndup(optarg, XCAM_MAX_STR_SIZE);
476 XCAM_LOG_DEBUG("using USB camera plugged in at node: %s", XCAM_STR(usb_device_name.ptr ()));
Sameer Kibey7b429292015-08-07 10:55:38 -0700477 break;
Yinhang Liud9346492015-12-17 11:14:25 +0800478 case 'R':
Wind Yuan6b437392016-02-02 00:31:30 +0800479 XCAM_ASSERT (optarg);
Yinhang Liud9346492015-12-17 11:14:25 +0800480 sscanf (optarg, "%d%*c%d", &frame_width, &frame_height);
481 break;
wangfeicf4c4e72015-05-25 17:11:41 +0800482 case 'e': {
Wind Yuan6b437392016-02-02 00:31:30 +0800483 XCAM_ASSERT (optarg);
wangfeicf4c4e72015-05-25 17:11:41 +0800484 if (!strcmp (optarg, "primary"))
485 display_mode = DRM_DISPLAY_MODE_PRIMARY;
486 else if (!strcmp (optarg, "overlay"))
487 display_mode = DRM_DISPLAY_MODE_OVERLAY;
488 else {
489 print_help (bin_name);
490 return -1;
491 }
492 break;
493 }
ShincyTue521cf92015-03-27 15:13:51 +0800494 case 'i':
495 device_manager->set_frame_save(atoi(optarg));
496 break;
Jia Meng8f94a102015-08-11 16:24:19 +0800497 case 'Y':
498 sync_mode = true;
499 break;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800500#if HAVE_LIBCL
Yinhang Liu81c44e02015-06-03 15:47:48 +0800501 case 'H': {
Wind Yuan6b437392016-02-02 00:31:30 +0800502 XCAM_ASSERT (optarg);
Yinhang Liu81c44e02015-06-03 15:47:48 +0800503 if (!strcasecmp (optarg, "rgb"))
504 hdr_type = CL_HDR_TYPE_RGB;
505 else if (!strcasecmp (optarg, "lab"))
506 hdr_type = CL_HDR_TYPE_LAB;
507 else {
508 print_help (bin_name);
509 return -1;
510 }
511 break;
512 }
Yinhang Liub92930c2015-06-23 16:26:35 +0800513 case 'I': {
Jia Meng66efecf2015-06-17 11:11:10 +0000514 denoise_type |= XCAM_DENOISE_TYPE_BILATERAL;
Juan Zhaod9664932015-09-08 10:22:19 +0800515 denoise_type |= XCAM_DENOISE_TYPE_BIYUV;
Yinhang Liu81c44e02015-06-03 15:47:48 +0800516 break;
517 }
518 case 'S': {
Jia Meng66efecf2015-06-17 11:11:10 +0000519 denoise_type |= XCAM_DENOISE_TYPE_SIMPLE;
520 break;
521 }
522 case 'E': {
523 denoise_type |= XCAM_DENOISE_TYPE_EE;
Yinhang Liu81c44e02015-06-03 15:47:48 +0800524 break;
525 }
ShincyTu63e2c262015-06-26 10:52:51 +0800526 case 'B': {
527 denoise_type |= XCAM_DENOISE_TYPE_BNR;
528 break;
529 }
Wangfei8e5e3e42016-02-18 19:41:54 +0800530 case 'X': {
531 retinex_type = true;
532 break;
533 }
zongwave80adcf52016-02-29 12:38:06 +0800534 case 'V': {
zongwave2ba7f642016-03-15 19:24:12 +0800535 XCAM_ASSERT (optarg);
536 if (atoi(optarg) < 0 || atoi(optarg) > 255) {
537 print_help (bin_name);
538 return -1;
539 }
zongwave28a747b2016-03-17 12:49:08 +0800540 if (atoi(optarg) == 1) {
zongwaveb7140442016-03-25 18:15:12 +0800541 wavelet_mode = CL_WAVELET_HAT;
542 wavelet_channel = CL_WAVELET_CHANNEL_Y;
zongwave28a747b2016-03-17 12:49:08 +0800543 } else if (atoi(optarg) == 2) {
zongwaveb7140442016-03-25 18:15:12 +0800544 wavelet_mode = CL_WAVELET_HAT;
545 wavelet_channel = CL_WAVELET_CHANNEL_UV;
546 } else if (atoi(optarg) == 3) {
547 wavelet_mode = CL_WAVELET_HAAR;
548 wavelet_channel = CL_WAVELET_CHANNEL_Y;
549 } else if (atoi(optarg) == 4) {
550 wavelet_mode = CL_WAVELET_HAAR;
551 wavelet_channel = CL_WAVELET_CHANNEL_UV;
552 } else if (atoi(optarg) == 5) {
553 wavelet_mode = CL_WAVELET_HAAR;
554 wavelet_channel = CL_WAVELET_CHANNEL_UV | CL_WAVELET_CHANNEL_Y;
zongwave28a747b2016-03-17 12:49:08 +0800555 } else {
zongwaveb7140442016-03-25 18:15:12 +0800556 wavelet_mode = CL_WAVELET_DISABLED;
zongwave28a747b2016-03-17 12:49:08 +0800557 }
zongwave80adcf52016-02-29 12:38:06 +0800558 break;
559 }
Yinhang Liue26b2622015-07-21 18:32:36 +0800560 case 'D': {
561 dpc_type = true;
562 break;
563 }
Yinhang Liu81c44e02015-06-03 15:47:48 +0800564 case 'T': {
Wind Yuan6b437392016-02-02 00:31:30 +0800565 XCAM_ASSERT (optarg);
Yinhang Liu81c44e02015-06-03 15:47:48 +0800566 if (!strcasecmp (optarg, "yuv"))
567 tnr_type = CL_TNR_TYPE_YUV;
568 else if (!strcasecmp (optarg, "rgb"))
569 tnr_type = CL_TNR_TYPE_RGB;
570 else if (!strcasecmp (optarg, "both"))
571 tnr_type = CL_TNR_TYPE_YUV | CL_TNR_TYPE_RGB;
572 else {
573 print_help (bin_name);
574 return -1;
575 }
576 break;
577 }
578 case 'L': {
Wind Yuan6b437392016-02-02 00:31:30 +0800579 XCAM_ASSERT (optarg);
Yinhang Liu81c44e02015-06-03 15:47:48 +0800580 if (atoi(optarg) < 0 || atoi(optarg) > 255) {
581 print_help (bin_name);
582 return -1;
583 }
584 tnr_level = atoi(optarg);
585 break;
586 }
Jia Menga6580232015-10-08 16:51:28 +0800587 case 'W': {
wujunkai16606f77622016-03-18 14:41:10 +0800588 XCAM_ASSERT (optarg);
589 if (!strcasecmp (optarg, "gaussian"))
590 wdr_mode = CL3aImageProcessor::Gaussian;
591 else if (!strcasecmp (optarg, "haleq"))
592 wdr_mode = CL3aImageProcessor::Haleq;
wujunkai16682950fb2015-10-19 18:09:05 +0800593
wujunkai166b0bd5512016-02-18 18:25:42 +0800594 pixel_format = V4L2_PIX_FMT_SGRBG12;
wujunkai16606f77622016-03-18 14:41:10 +0800595 wdr_type = true;
wujunkai166b0bd5512016-02-18 18:25:42 +0800596 setenv ("AIQ_CPF_PATH", IMX185_WDR_CPF, 1);
597 break;
598 }
Wangfei1487b9b2015-08-28 15:10:39 +0800599 case 'P': {
Wind Yuan6b437392016-02-02 00:31:30 +0800600 XCAM_ASSERT (optarg);
Wangfei1487b9b2015-08-28 15:10:39 +0800601 if (!strcasecmp (optarg, "basic"))
602 pipeline_mode = CL3aImageProcessor::BasicPipelineProfile;
603 else if (!strcasecmp (optarg, "advance"))
604 pipeline_mode = CL3aImageProcessor::AdvancedPipelineProfile;
Wangfei16b65db2015-09-11 14:44:28 +0800605 else if (!strcasecmp (optarg, "extreme"))
606 pipeline_mode = CL3aImageProcessor::ExtremePipelineProfile;
Wangfei1487b9b2015-08-28 15:10:39 +0800607 else {
608 print_help (bin_name);
609 return -1;
610 }
611 break;
612 }
wujunkai166a84ba052015-09-08 15:54:12 +0800613 case 'C': {
Wind Yuan6b437392016-02-02 00:31:30 +0800614 XCAM_ASSERT (optarg);
wujunkai166a84ba052015-09-08 15:54:12 +0800615 if (!strcmp (optarg, "bayer"))
616 capture_stage = CL3aImageProcessor::BasicbayerStage;
617 break;
618 }
Yinhang Liub0ad64b2016-03-18 16:03:51 +0800619 case 'O': {
620 have_cl_post_processor = false;
621 break;
622 }
Yinhang Liuc2f19082015-08-28 12:27:48 +0800623#endif
Jia Meng0a532932015-10-15 08:44:09 -0400624 case 'r': {
625 if (optarg) {
626 XCAM_LOG_INFO ("use raw image %s as input source", optarg);
Wind Yuan155c8f52016-03-18 23:16:59 +0800627 path_to_fake = strndup(optarg, XCAM_MAX_STR_SIZE);
Jia Meng0a532932015-10-15 08:44:09 -0400628 }
629 break;
630 }
Wind Yuan75564b12015-01-15 06:51:15 -0500631 case 'h':
632 print_help (bin_name);
633 return 0;
634
635 default:
636 print_help (bin_name);
637 return -1;
638 }
639 }
640
Yinhang Liud9346492015-12-17 11:14:25 +0800641 device_manager->set_frame_width(frame_width);
642 device_manager->set_frame_height(frame_height);
wangfeicf4c4e72015-05-25 17:11:41 +0800643 if (need_display) {
Wind Yuan683f8662015-03-27 18:52:38 +0800644 device_manager->enable_display (true);
wangfeicf4c4e72015-05-25 17:11:41 +0800645 device_manager->set_display_mode (display_mode);
646 }
ShincyTu2808b592015-03-13 17:17:25 +0800647 if (!device.ptr ()) {
Wind Yuan155c8f52016-03-18 23:16:59 +0800648 if (path_to_fake.ptr ()) {
Jia Meng0a532932015-10-15 08:44:09 -0400649 device = new FakeV4l2Device ();
650 } else if (have_usbcam) {
Wind Yuan155c8f52016-03-18 23:16:59 +0800651 device = new UVCDevice (usb_device_name.ptr ());
Sameer Kibey7b429292015-08-07 10:55:38 -0700652 } else {
653 if (capture_mode == V4L2_CAPTURE_MODE_STILL)
654 device = new AtomispDevice (CAPTURE_DEVICE_STILL);
655 else if (capture_mode == V4L2_CAPTURE_MODE_VIDEO)
656 device = new AtomispDevice (CAPTURE_DEVICE_VIDEO);
657 else
658 device = new AtomispDevice (DEFAULT_CAPTURE_DEVICE);
659 }
ShincyTu2808b592015-03-13 17:17:25 +0800660 }
Wind Yuan75564b12015-01-15 06:51:15 -0500661 if (!event_device.ptr ())
662 event_device = new V4l2SubDevice (DEFAULT_EVENT_DEVICE);
663 if (!isp_controller.ptr ())
664 isp_controller = new IspController (device);
Wind Yuan26e9e212015-04-16 15:55:45 +0800665
666 switch (analyzer_type) {
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800667 case AnalyzerTypeSimple:
668 analyzer = new X3aAnalyzerSimple ();
669 break;
Wind Yuan26e9e212015-04-16 15:55:45 +0800670#if HAVE_IA_AIQ
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800671 case AnalyzerTypeAiq:
672 analyzer = new X3aAnalyzerAiq (isp_controller, DEFAULT_CPF_FILE);
673 break;
Jia Meng9724cfe2015-08-12 15:04:45 +0800674 case AnalyzerTypeHybrid: {
Jia Mengc54c3322015-08-26 09:45:18 +0800675 path_of_3a = DEFAULT_HYBRID_3A_LIB;
zongwave03954a32015-09-22 15:40:44 +0800676 loader = new X3aAnalyzerLoader (path_of_3a);
Jia Meng9724cfe2015-08-12 15:04:45 +0800677 analyzer = loader->load_hybrid_analyzer (loader, isp_controller, DEFAULT_CPF_FILE);
678 CHECK_EXP (analyzer.ptr (), "load hybrid 3a lib(%s) failed", path_of_3a);
679 break;
680 }
Wind Yuan26e9e212015-04-16 15:55:45 +0800681#endif
Wind Yuane25ce3f2015-05-04 18:07:29 +0800682 case AnalyzerTypeDynamic: {
Jia Meng9724cfe2015-08-12 15:04:45 +0800683 path_of_3a = DEFAULT_DYNAMIC_3A_LIB;
zongwave03954a32015-09-22 15:40:44 +0800684 loader = new X3aAnalyzerLoader (path_of_3a);
Jia Meng9724cfe2015-08-12 15:04:45 +0800685 analyzer = loader->load_dynamic_analyzer (loader);
Wind Yuane25ce3f2015-05-04 18:07:29 +0800686 CHECK_EXP (analyzer.ptr (), "load dynamic 3a lib(%s) failed", path_of_3a);
687 break;
688 }
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800689 default:
690 print_help (bin_name);
691 return -1;
Wind Yuan26e9e212015-04-16 15:55:45 +0800692 }
Jia Meng8f94a102015-08-11 16:24:19 +0800693 XCAM_ASSERT (analyzer.ptr ());
694 analyzer->set_sync_mode (sync_mode);
Wind Yuan75564b12015-01-15 06:51:15 -0500695
696 signal(SIGINT, dev_stop_handler);
697
698 device->set_sensor_id (0);
ShincyTu2808b592015-03-13 17:17:25 +0800699 device->set_capture_mode (capture_mode);
Wind Yuan75564b12015-01-15 06:51:15 -0500700 //device->set_mem_type (V4L2_MEMORY_DMABUF);
Wind Yuand4427312015-02-11 16:09:00 +0800701 device->set_mem_type (v4l2_mem_type);
Wind Yuan75564b12015-01-15 06:51:15 -0500702 device->set_buffer_count (8);
Jia Meng757f3c92015-09-09 11:18:36 +0800703 if (pixel_format == V4L2_PIX_FMT_SGRBG12) {
704 frame_rate = 30;
705 device->set_framerate (frame_rate, 1);
706 }
707 else {
708 frame_rate = 25;
709 device->set_framerate (frame_rate, 1);
wujunkai16606f77622016-03-18 14:41:10 +0800710 if(wdr_type == true) {
wujunkai166a9a55f22015-10-10 15:53:32 +0800711 XCAM_LOG_WARNING("Tonemapping is only applicable under BA12 format. Disable tonemapping automatically.");
wujunkai16606f77622016-03-18 14:41:10 +0800712 wdr_type = false;
wujunkai166a9a55f22015-10-10 15:53:32 +0800713 }
Jia Meng757f3c92015-09-09 11:18:36 +0800714 }
Wind Yuan75564b12015-01-15 06:51:15 -0500715 ret = device->open ();
716 CHECK (ret, "device(%s) open failed", device->get_device_name());
Yinhang Liud9346492015-12-17 11:14:25 +0800717 ret = device->set_format (frame_width, frame_height, pixel_format, V4L2_FIELD_NONE, frame_width * 2);
Wind Yuan75564b12015-01-15 06:51:15 -0500718 CHECK (ret, "device(%s) set format failed", device->get_device_name());
719
720 ret = event_device->open ();
Wind Yuanb67045c2015-08-27 13:50:53 +0800721 if (ret == XCAM_RETURN_NO_ERROR) {
722 CHECK (ret, "event device(%s) open failed", event_device->get_device_name());
723 int event = V4L2_EVENT_ATOMISP_3A_STATS_READY;
724 ret = event_device->subscribe_event (event);
725 CHECK_CONTINUE (
726 ret,
727 "device(%s) subscribe event(%d) failed",
728 event_device->get_device_name(), event);
729 event = V4L2_EVENT_FRAME_SYNC;
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
736 device_manager->set_event_device (event_device);
737 }
Wind Yuan75564b12015-01-15 06:51:15 -0500738
739 device_manager->set_capture_device (device);
Wind Yuan75564b12015-01-15 06:51:15 -0500740 device_manager->set_isp_controller (isp_controller);
741 if (analyzer.ptr())
zongwave03954a32015-09-22 15:40:44 +0800742 device_manager->set_3a_analyzer (analyzer);
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800743
744 if (have_cl_processor)
745 isp_processor = new IspExposureImageProcessor (isp_controller);
746 else
747 isp_processor = new IspImageProcessor (isp_controller);
748
749 XCAM_ASSERT (isp_processor.ptr ());
Wind Yuane4ba0c92015-03-26 16:59:06 +0800750 device_manager->add_image_processor (isp_processor);
Yinhang Liuc2f19082015-08-28 12:27:48 +0800751#if HAVE_LIBCL
Wind Yuand4427312015-02-11 16:09:00 +0800752 if (have_cl_processor) {
Wind Yuane4ba0c92015-03-26 16:59:06 +0800753 cl_processor = new CL3aImageProcessor ();
Wind Yuan7ddf2602015-04-14 18:49:45 +0800754 cl_processor->set_stats_callback(device_manager);
Yinhang Liue26b2622015-07-21 18:32:36 +0800755 cl_processor->set_dpc(dpc_type);
Yinhang Liu81c44e02015-06-03 15:47:48 +0800756 cl_processor->set_hdr (hdr_type);
Jia Meng66efecf2015-06-17 11:11:10 +0000757 cl_processor->set_denoise (denoise_type);
wujunkai16606f77622016-03-18 14:41:10 +0800758 cl_processor->set_tonemapping(wdr_mode);
Jia Menga6580232015-10-08 16:51:28 +0800759 cl_processor->set_gamma (!wdr_type); // disable gamma for WDR
zongwaveb7140442016-03-25 18:15:12 +0800760 cl_processor->set_wavelet (wavelet_mode, wavelet_channel);
wujunkai166a84ba052015-09-08 15:54:12 +0800761 cl_processor->set_capture_stage (capture_stage);
wujunkai166c8f3b442016-02-29 17:12:09 +0800762
763 if (wdr_type) {
764 cl_processor->set_3a_stats_bits(12);
765 }
Yinhang Liu81c44e02015-06-03 15:47:48 +0800766 cl_processor->set_tnr (tnr_type, tnr_level);
Wangfei1487b9b2015-08-28 15:10:39 +0800767 cl_processor->set_profile (pipeline_mode);
yaowang1a5f12122015-07-27 14:53:38 +0800768 analyzer->set_parameter_brightness((brightness_level - 128) / 128.0);
Wind Yuand4427312015-02-11 16:09:00 +0800769 device_manager->add_image_processor (cl_processor);
770 }
Yinhang Liu3c17fea2016-03-15 10:47:03 +0800771
Yinhang Liub0ad64b2016-03-18 16:03:51 +0800772 if (have_cl_post_processor) {
773 cl_post_processor = new CLPostImageProcessor ();
Yinhang Liu3c721c12016-03-15 15:03:51 +0800774
Yinhang Liub0ad64b2016-03-18 16:03:51 +0800775 cl_post_processor->set_retinex (retinex_type);
Yinhang Liu3c721c12016-03-15 15:03:51 +0800776
Yinhang Liud6d824a2016-03-22 20:43:00 +0800777 if (need_display) {
Yinhang Liub0ad64b2016-03-18 16:03:51 +0800778 cl_post_processor->set_output_format (V4L2_PIX_FMT_XBGR32);
779 }
780 device_manager->add_image_processor (cl_post_processor);
Yinhang Liu3c17fea2016-03-15 10:47:03 +0800781 }
Wind Yuand4427312015-02-11 16:09:00 +0800782#endif
Wind Yuane4ba0c92015-03-26 16:59:06 +0800783
Jia Meng0a532932015-10-15 08:44:09 -0400784 SmartPtr<PollThread> poll_thread;
Wind Yuan155c8f52016-03-18 23:16:59 +0800785 if (path_to_fake.ptr ())
786 poll_thread = new FakePollThread (path_to_fake.ptr ());
Jia Meng0a532932015-10-15 08:44:09 -0400787 else
788 poll_thread = new PollThread ();
789 device_manager->set_poll_thread (poll_thread);
790
Wind Yuan75564b12015-01-15 06:51:15 -0500791 ret = device_manager->start ();
792 CHECK (ret, "device manager start failed");
793
Jia Meng757f3c92015-09-09 11:18:36 +0800794 // hard code exposure range and max gain for imx185 WDR
Jia Menga6580232015-10-08 16:51:28 +0800795 if (wdr_type) {
Jia Meng757f3c92015-09-09 11:18:36 +0800796 if (frame_rate == 30)
797 analyzer->set_ae_exposure_time_range (80 * 1110 * 1000 / 37125, 1120 * 1110 * 1000 / 37125);
798 else
Jia Menga6580232015-10-08 16:51:28 +0800799 analyzer->set_ae_exposure_time_range (80 * 1320 * 1000 / 37125, 1120 * 1320 * 1000 / 37125);
Jia Meng757f3c92015-09-09 11:18:36 +0800800 analyzer->set_ae_max_analog_gain (3.98); // 12dB
801 }
802
Wind Yuan75564b12015-01-15 06:51:15 -0500803 // wait for interruption
804 {
805 SmartLock locker (g_mutex);
806 while (!g_stop)
807 g_cond.wait (g_mutex);
808 }
809
810 ret = device_manager->stop();
811 CHECK_CONTINUE (ret, "device manager stop failed");
812 device->close ();
813 event_device->close ();
Wind Yuan75564b12015-01-15 06:51:15 -0500814
815 return 0;
816}