blob: 16f1369b865c0a48167758014655ee597fd7965c [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"
Yinhang Liue37a8722016-06-27 18:14:35 +080028#include "analyzer_loader.h"
Yinhang Liu4afa3642016-05-13 19:13:07 +080029#include "smart_analyzer_loader.h"
Wind Yuan75564b12015-01-15 06:51:15 -050030#if HAVE_IA_AIQ
31#include "x3a_analyzer_aiq.h"
Yinhang Liu6c367352016-03-31 20:23:22 +080032#include "x3a_analyze_tuner.h"
Wind Yuan75564b12015-01-15 06:51:15 -050033#endif
Wind Yuand4427312015-02-11 16:09:00 +080034#if HAVE_LIBCL
Wind Yuane4ba0c92015-03-26 16:59:06 +080035#include "cl_3a_image_processor.h"
Yinhang Liu2ab1f992016-03-15 10:41:17 +080036#include "cl_post_image_processor.h"
wangfeicf4c4e72015-05-25 17:11:41 +080037#include "cl_csc_image_processor.h"
Yinhang Liu81c44e02015-06-03 15:47:48 +080038#include "cl_hdr_handler.h"
39#include "cl_tnr_handler.h"
Wind Yuane4ba0c92015-03-26 16:59:06 +080040#endif
41#if HAVE_LIBDRM
42#include "drm_display.h"
Wind Yuand4427312015-02-11 16:09:00 +080043#endif
Yinhang Liue37a8722016-06-27 18:14:35 +080044#include "dynamic_analyzer_loader.h"
45#include "hybrid_analyzer_loader.h"
46#include "isp_poll_thread.h"
Jia Meng0a532932015-10-15 08:44:09 -040047#include "fake_poll_thread.h"
Jia Meng66efecf2015-06-17 11:11:10 +000048#include <base/xcam_3a_types.h>
Wind Yuan75564b12015-01-15 06:51:15 -050049#include <unistd.h>
50#include <signal.h>
51#include <stdlib.h>
ShincyTue521cf92015-03-27 15:13:51 +080052#include <string>
Yinhang Liu81c44e02015-06-03 15:47:48 +080053#include <getopt.h>
John Yeae9da732015-01-22 13:36:36 +080054#include "test_common.h"
55
Wind Yuan75564b12015-01-15 06:51:15 -050056using namespace XCam;
57
wujunkai16682950fb2015-10-19 18:09:05 +080058#define IMX185_WDR_CPF "/etc/atomisp/imx185_wdr.cpf"
59
ShincyTue521cf92015-03-27 15:13:51 +080060static Mutex g_mutex;
61static Cond g_cond;
62static bool g_stop = false;
63
Wind Yuan75564b12015-01-15 06:51:15 -050064class MainDeviceManager
65 : public DeviceManager
66{
67public:
68 MainDeviceManager ()
69 : _file (NULL)
70 , _save_file (false)
71 , _interval (1)
Yinhang Liud9346492015-12-17 11:14:25 +080072 , _frame_width (0)
73 , _frame_height (0)
Wind Yuan75564b12015-01-15 06:51:15 -050074 , _frame_count (0)
ShincyTue521cf92015-03-27 15:13:51 +080075 , _frame_save (0)
Wind Yuan683f8662015-03-27 18:52:38 +080076 , _enable_display (false)
Wind Yuane4ba0c92015-03-26 16:59:06 +080077 {
78#if HAVE_LIBDRM
79 _display = DrmDisplay::instance();
80#endif
Wind Yuan91625802015-06-24 15:36:01 +080081 XCAM_OBJ_PROFILING_INIT;
Wind Yuane4ba0c92015-03-26 16:59:06 +080082 }
Wind Yuan75564b12015-01-15 06:51:15 -050083
84 ~MainDeviceManager () {
85 close_file ();
86 }
87
88 void enable_save_file (bool enable) {
89 _save_file = enable;
90 }
Yinhang Liud9346492015-12-17 11:14:25 +080091
Wind Yuan75564b12015-01-15 06:51:15 -050092 void set_interval (uint32_t inteval) {
93 _interval = inteval;
94 }
Yinhang Liud9346492015-12-17 11:14:25 +080095
96 void set_frame_width (uint32_t frame_width) {
97 _frame_width = frame_width;
98 }
99
100 void set_frame_height (uint32_t frame_height) {
101 _frame_height = frame_height;
102 }
103
ShincyTue521cf92015-03-27 15:13:51 +0800104 void set_frame_save (uint32_t frame_save) {
105 _frame_save = frame_save;
106 }
Wind Yuan75564b12015-01-15 06:51:15 -0500107
Wind Yuan683f8662015-03-27 18:52:38 +0800108 void enable_display(bool value) {
109 _enable_display = value;
110 }
111
wangfeicf4c4e72015-05-25 17:11:41 +0800112 void set_display_mode(DrmDisplayMode mode) {
113 _display->set_display_mode (mode);
114 }
115
Wind Yuan75564b12015-01-15 06:51:15 -0500116protected:
Wind Yuan73af3932015-07-02 17:52:43 +0800117 virtual void handle_message (const SmartPtr<XCamMessage> &msg);
118 virtual void handle_buffer (const SmartPtr<VideoBuffer> &buf);
Wind Yuan75564b12015-01-15 06:51:15 -0500119
Wind Yuan73af3932015-07-02 17:52:43 +0800120 int display_buf (const SmartPtr<VideoBuffer> &buf);
Wind Yuane4ba0c92015-03-26 16:59:06 +0800121
Wind Yuan75564b12015-01-15 06:51:15 -0500122private:
123 void open_file ();
124 void close_file ();
Wind Yuan71111322016-02-24 22:56:27 +0800125 XCamReturn write_buf (const SmartPtr<VideoBuffer> &buf);
Wind Yuan75564b12015-01-15 06:51:15 -0500126
127 FILE *_file;
128 bool _save_file;
129 uint32_t _interval;
Yinhang Liud9346492015-12-17 11:14:25 +0800130 uint32_t _frame_width;
131 uint32_t _frame_height;
Wind Yuan75564b12015-01-15 06:51:15 -0500132 uint32_t _frame_count;
ShincyTue521cf92015-03-27 15:13:51 +0800133 uint32_t _frame_save;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800134 SmartPtr<DrmDisplay> _display;
Wind Yuan683f8662015-03-27 18:52:38 +0800135 bool _enable_display;
Wind Yuan91625802015-06-24 15:36:01 +0800136 XCAM_OBJ_PROFILING_DEFINES;
Wind Yuan75564b12015-01-15 06:51:15 -0500137};
138
139void
Wind Yuan73af3932015-07-02 17:52:43 +0800140MainDeviceManager::handle_message (const SmartPtr<XCamMessage> &msg)
Wind Yuan75564b12015-01-15 06:51:15 -0500141{
142 XCAM_UNUSED (msg);
143}
144
145void
Wind Yuan73af3932015-07-02 17:52:43 +0800146MainDeviceManager::handle_buffer (const SmartPtr<VideoBuffer> &buf)
Wind Yuan75564b12015-01-15 06:51:15 -0500147{
Wind Yuan683f8662015-03-27 18:52:38 +0800148 FPS_CALCULATION (fps_buf, 30);
149
Wind Yuan91625802015-06-24 15:36:01 +0800150 XCAM_OBJ_PROFILING_START;
151
Wind Yuan683f8662015-03-27 18:52:38 +0800152 if (_enable_display)
153 display_buf (buf);
Wind Yuane4ba0c92015-03-26 16:59:06 +0800154
Wind Yuan91625802015-06-24 15:36:01 +0800155 XCAM_OBJ_PROFILING_END("main_dev_manager_display", 30);
156
Wind Yuan75564b12015-01-15 06:51:15 -0500157 if (!_save_file)
158 return ;
159
160 if ((_frame_count++ % _interval) != 0)
161 return;
162
ShincyTue521cf92015-03-27 15:13:51 +0800163 if ((_frame_save != 0) && (_frame_count > _frame_save)) {
164 SmartLock locker (g_mutex);
165 g_stop = true;
166 g_cond.broadcast ();
167 return;
168 }
169
Wind Yuan75564b12015-01-15 06:51:15 -0500170 open_file ();
Jia Meng6c9241d2015-06-12 11:08:45 +0000171
172 if (!_file) {
173 XCAM_LOG_ERROR ("open file failed");
Jia Meng54a2dcb2015-08-20 15:23:47 +0800174 return;
Jia Meng6c9241d2015-06-12 11:08:45 +0000175 }
Wind Yuan71111322016-02-24 22:56:27 +0800176 write_buf (buf);
Wind Yuan75564b12015-01-15 06:51:15 -0500177}
178
Wind Yuane4ba0c92015-03-26 16:59:06 +0800179int
Wind Yuan73af3932015-07-02 17:52:43 +0800180MainDeviceManager::display_buf (const SmartPtr<VideoBuffer> &data)
Wind Yuane4ba0c92015-03-26 16:59:06 +0800181{
182#if HAVE_LIBDRM
183 XCamReturn ret = XCAM_RETURN_NO_ERROR;
Wind Yuan73af3932015-07-02 17:52:43 +0800184 SmartPtr<VideoBuffer> buf = data;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800185 const VideoBufferInfo & frame_info = buf->get_video_info ();
186 struct v4l2_rect rect = { 0, 0, (int)frame_info.width, (int)frame_info.height };
187
188 if (!_display->is_render_inited ()) {
Yinhang Liud9346492015-12-17 11:14:25 +0800189 ret = _display->render_init (0, 0, this->_frame_width, this->_frame_height,
190 frame_info.format, &rect);
Wind Yuane4ba0c92015-03-26 16:59:06 +0800191 CHECK (ret, "display failed on render_init");
192 }
193 ret = _display->render_setup_frame_buffer (buf);
194 CHECK (ret, "display failed on framebuf set");
195 ret = _display->render_buffer (buf);
196 CHECK (ret, "display failed on rendering");
197#endif
198 return 0;
199}
200
201
Wind Yuan75564b12015-01-15 06:51:15 -0500202void
203MainDeviceManager::open_file ()
204{
ShincyTue521cf92015-03-27 15:13:51 +0800205 if ((_file) && (_frame_save == 0))
Wind Yuan75564b12015-01-15 06:51:15 -0500206 return;
ShincyTue521cf92015-03-27 15:13:51 +0800207
208 std::string file_name = DEFAULT_SAVE_FILE_NAME;
209
210 if (_frame_save != 0) {
211 file_name += std::to_string(_frame_count);
212 }
213 file_name += ".raw";
214
215 _file = fopen(file_name.c_str(), "wb");
Wind Yuan75564b12015-01-15 06:51:15 -0500216}
217
218void
219MainDeviceManager::close_file ()
220{
221 if (_file)
222 fclose (_file);
223 _file = NULL;
224}
225
Wind Yuan71111322016-02-24 22:56:27 +0800226XCamReturn
227MainDeviceManager::write_buf (const SmartPtr<VideoBuffer> &buf)
228{
229 const VideoBufferInfo &info = buf->get_video_info ();
230 VideoBufferPlanarInfo planar;
231 uint8_t *memory = NULL;
232 XCamReturn ret = XCAM_RETURN_NO_ERROR;
233
234 memory = buf->map ();
235 if (!memory) {
236 XCAM_LOG_ERROR ("map buffer failed in write_buf");
237 return XCAM_RETURN_ERROR_MEM;
238 }
239
240 for (uint32_t index = 0; index < info.components; index++) {
241 info.get_planar_info (planar, index);
242 uint32_t line_bytes = planar.width * planar.pixel_bytes;
243
244 for (uint32_t i = 0; i < planar.height; i++) {
245 if (fwrite (memory + info.offsets [index] + i * info.strides [index], 1, line_bytes, _file) != line_bytes) {
246 XCAM_LOG_ERROR ("write file failed, size doesn't match");
247 ret = XCAM_RETURN_ERROR_FILE;
248 }
249 }
250 }
251 buf->unmap ();
252 return ret;
253}
254
Wind Yuan75564b12015-01-15 06:51:15 -0500255#define V4L2_CAPTURE_MODE_STILL 0x2000
256#define V4L2_CAPTURE_MODE_VIDEO 0x4000
257#define V4L2_CAPTURE_MODE_PREVIEW 0x8000
258
Wind Yuan26e9e212015-04-16 15:55:45 +0800259typedef enum {
260 AnalyzerTypeSimple = 0,
Yinhang Liu6c367352016-03-31 20:23:22 +0800261 AnalyzerTypeAiqTuner,
Wind Yuane25ce3f2015-05-04 18:07:29 +0800262 AnalyzerTypeDynamic,
Jia Meng9724cfe2015-08-12 15:04:45 +0800263 AnalyzerTypeHybrid,
Wind Yuan26e9e212015-04-16 15:55:45 +0800264} AnalyzerType;
265
Wind Yuan75564b12015-01-15 06:51:15 -0500266void dev_stop_handler(int sig)
267{
268 XCAM_UNUSED (sig);
269
270 SmartLock locker (g_mutex);
271 g_stop = true;
272 g_cond.broadcast ();
273
274 //exit(0);
275}
276
277void print_help (const char *bin_name)
278{
279 printf ("Usage: %s [-a analyzer]\n"
Yinhang Liu81c44e02015-06-03 15:47:48 +0800280 "Configurations:\n"
ShincyTue521cf92015-03-27 15:13:51 +0800281 "\t -a analyzer specify a analyzer\n"
Wind Yuane25ce3f2015-05-04 18:07:29 +0800282 "\t select from [simple, aiq, dynamic], default is [simple]\n"
ShincyTue521cf92015-03-27 15:13:51 +0800283 "\t -m mem_type specify video memory type\n"
284 "\t mem_type select from [dma, mmap], default is [mmap]\n"
285 "\t -s save file to %s\n"
286 "\t -n interval save file on every [interval] frame\n"
Yinhang Liuc2f19082015-08-28 12:27:48 +0800287#if HAVE_LIBCL
ShincyTue521cf92015-03-27 15:13:51 +0800288 "\t -c process image with cl kernel\n"
Yinhang Liuc2f19082015-08-28 12:27:48 +0800289#endif
ShincyTue521cf92015-03-27 15:13:51 +0800290 "\t -f pixel_fmt specify output pixel format\n"
wujunkai1669845b022015-08-27 15:59:27 +0800291 "\t pixel_fmt select from [NV12, YUYV, BA10, BA12], default is [NV12]\n"
ShincyTue521cf92015-03-27 15:13:51 +0800292 "\t -d cap_mode specify capture mode\n"
293 "\t cap_mode select from [video, still], default is [video]\n"
yaowang1a5f12122015-07-27 14:53:38 +0800294 "\t -b brightness specify brightness level\n"
295 "\t brightness level select from [0, 256], default is [128]\n"
ShincyTue521cf92015-03-27 15:13:51 +0800296 "\t -i frame_save specify the frame count to save, default is 0 which means endless\n"
wangfeicf4c4e72015-05-25 17:11:41 +0800297 "\t -p preview on local display\n"
Sameer Kibey7b429292015-08-07 10:55:38 -0700298 "\t --usb specify node for usb camera device, enables capture path through USB camera \n"
299 "\t specify [/dev/video4, /dev/video5] depending on which node USB camera is attached\n"
Yinhang Liud9346492015-12-17 11:14:25 +0800300 "\t --resolution specify the resolution of usb camera\n"
301 "\t select from [1920x1080, 1280x720 ...], default is [1920x1080]\n"
wangfeicf4c4e72015-05-25 17:11:41 +0800302 "\t -e display_mode preview mode\n"
303 "\t select from [primary, overlay], default is [primary]\n"
Jia Meng8f94a102015-08-11 16:24:19 +0800304 "\t --sync set analyzer in sync mode\n"
Jia Meng0a532932015-10-15 08:44:09 -0400305 "\t -r raw_input specify the path of raw image as fake source instead of live camera\n"
ShincyTue521cf92015-03-27 15:13:51 +0800306 "\t -h help\n"
Yinhang Liuc2f19082015-08-28 12:27:48 +0800307#if HAVE_LIBCL
Yinhang Liu81c44e02015-06-03 15:47:48 +0800308 "CL features:\n"
wujunkai166a84ba052015-09-08 15:54:12 +0800309 "\t --capture capture_stage specify the capture stage of image\n"
310 "\t capture_stage select from [bayer, tonemapping], default is [tonemapping]\n"
Yinhang Liu81c44e02015-06-03 15:47:48 +0800311 "\t --hdr specify hdr type, default is hdr off\n"
312 "\t select from [rgb, lab]\n"
313 "\t --tnr specify temporal noise reduction type, default is tnr off\n"
314 "\t select from [rgb, yuv, both]\n"
315 "\t --tnr-level specify tnr level\n"
wujunkai16606f77622016-03-18 14:41:10 +0800316 "\t --wdr-mode specify wdr mode. select from [gaussian, haleq]\n"
Yinhang Liub92930c2015-06-23 16:26:35 +0800317 "\t --bilateral enable bilateral noise reduction\n"
Yinhang Liu81c44e02015-06-03 15:47:48 +0800318 "\t --enable-snr enable simple noise reduction\n"
Jia Meng66efecf2015-06-17 11:11:10 +0000319 "\t --enable-ee enable YEENR\n"
ShincyTu63e2c262015-06-26 10:52:51 +0800320 "\t --enable-bnr enable bayer noise reduction\n"
Yinhang Liue26b2622015-07-21 18:32:36 +0800321 "\t --enable-dpc enable defect pixel correction\n"
Wind Yuanf4e17ab2016-05-05 02:54:01 +0800322 "\t --defog-mode mode enable defog\n"
323 "\t select from [disabled, retinex, dcp], default is [disabled]\n"
zongwave3b419ed2016-05-10 17:21:54 +0800324 "\t --enable-retinex enable retinex\n"
325 "\t --wavelet-mode specify wavelet denoise mode, default is off\n"
zongwave98d23202016-06-27 13:46:27 +0800326 "\t select from [0:disable, 1:Hat Y, 2:Hat UV, 3:Haar Y, 4:Haar UV, 5:Haar YUV, 6:Haar Bayes Shrink]\n"
Yinhang Liu4ea70612016-05-26 18:26:29 +0800327 "\t --enable-wireframe enable wire frame\n"
zongwave3b419ed2016-05-10 17:21:54 +0800328 "\t --pipeline pipe mode\n"
Wangfei16b65db2015-09-11 14:44:28 +0800329 "\t select from [basic, advance, extreme], default is [basic]\n"
Yinhang Liub0ad64b2016-03-18 16:03:51 +0800330 "\t --disable-post disable cl post image processor\n"
Yinhang Liue26b2622015-07-21 18:32:36 +0800331 "(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 +0800332#endif
Wind Yuan75564b12015-01-15 06:51:15 -0500333 , bin_name
334 , DEFAULT_SAVE_FILE_NAME);
335}
336
337int main (int argc, char *argv[])
338{
339 XCamReturn ret = XCAM_RETURN_NO_ERROR;
340 SmartPtr<MainDeviceManager> device_manager = new MainDeviceManager;
341 SmartPtr<V4l2Device> device;
342 SmartPtr<V4l2SubDevice> event_device;
343 SmartPtr<IspController> isp_controller;
344 SmartPtr<X3aAnalyzer> analyzer;
Yinhang Liu4afa3642016-05-13 19:13:07 +0800345 SmartPtr<SmartAnalyzer> smart_analyzer;
Yinhang Liue37a8722016-06-27 18:14:35 +0800346 SmartPtr<AnalyzerLoader> loader;
Jia Meng9724cfe2015-08-12 15:04:45 +0800347 const char *path_of_3a;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800348 SmartPtr<ImageProcessor> isp_processor;
Wind Yuan26e9e212015-04-16 15:55:45 +0800349 AnalyzerType analyzer_type = AnalyzerTypeSimple;
wangfeicf4c4e72015-05-25 17:11:41 +0800350 DrmDisplayMode display_mode = DRM_DISPLAY_MODE_PRIMARY;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800351#if HAVE_LIBDRM
352 SmartPtr<DrmDisplay> drm_disp = DrmDisplay::instance();
353#endif
354
Yinhang Liuc64ed592016-07-15 18:53:34 +0800355 bool have_cl_processor = false;
Wind Yuand4427312015-02-11 16:09:00 +0800356#if HAVE_LIBCL
Yinhang Liuc64ed592016-07-15 18:53:34 +0800357 bool have_cl_post_processor = true;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800358 SmartPtr<CL3aImageProcessor> cl_processor;
Yinhang Liu2ab1f992016-03-15 10:41:17 +0800359 SmartPtr<CLPostImageProcessor> cl_post_processor;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800360 uint32_t hdr_type = CL_HDR_DISABLE;
361 uint32_t tnr_type = CL_TNR_DISABLE;
362 uint32_t denoise_type = 0;
363 uint8_t tnr_level = 0;
364 bool dpc_type = false;
Wangfei1487b9b2015-08-28 15:10:39 +0800365 CL3aImageProcessor::PipelineProfile pipeline_mode = CL3aImageProcessor::BasicPipelineProfile;
wujunkai166a84ba052015-09-08 15:54:12 +0800366 CL3aImageProcessor::CaptureStage capture_stage = CL3aImageProcessor::TonemappingStage;
wujunkai16606f77622016-03-18 14:41:10 +0800367 CL3aImageProcessor::CLTonemappingMode wdr_mode = CL3aImageProcessor::WDRdisabled;
Wind Yuand4427312015-02-11 16:09:00 +0800368#endif
Wind Yuane4ba0c92015-03-26 16:59:06 +0800369 bool need_display = false;
Wind Yuand4427312015-02-11 16:09:00 +0800370 enum v4l2_memory v4l2_mem_type = V4L2_MEMORY_MMAP;
Wind Yuan75564b12015-01-15 06:51:15 -0500371 const char *bin_name = argv[0];
372 int opt;
ShincyTu2808b592015-03-13 17:17:25 +0800373 uint32_t capture_mode = V4L2_CAPTURE_MODE_VIDEO;
374 uint32_t pixel_format = V4L2_PIX_FMT_NV12;
Yinhang Liuc64ed592016-07-15 18:53:34 +0800375
376#if HAVE_LIBCL
Jia Menga6580232015-10-08 16:51:28 +0800377 bool wdr_type = false;
Wind Yuanf4e17ab2016-05-05 02:54:01 +0800378 uint32_t defog_type = 0;
zongwavebec89e12016-07-23 12:34:20 +0800379 uint32_t denoise_3d_mode = 0;
380 uint8_t denoise_3d_ref_count = 3;
zongwaveb7140442016-03-25 18:15:12 +0800381 CLWaveletBasis wavelet_mode = CL_WAVELET_DISABLED;
zongwave98d23202016-06-27 13:46:27 +0800382 uint32_t wavelet_channel = CL_IMAGE_CHANNEL_UV;
383 bool wavelet_bayes_shrink = false;
Yinhang Liu4ea70612016-05-26 18:26:29 +0800384 bool wireframe_type = false;
Yinhang Liuc64ed592016-07-15 18:53:34 +0800385#endif
zongwaveb7140442016-03-25 18:15:12 +0800386
yaowang1a5f12122015-07-27 14:53:38 +0800387 int32_t brightness_level = 128;
Sameer Kibey7b429292015-08-07 10:55:38 -0700388 bool have_usbcam = 0;
Wind Yuan155c8f52016-03-18 23:16:59 +0800389 SmartPtr<char> usb_device_name;
Jia Meng8f94a102015-08-11 16:24:19 +0800390 bool sync_mode = false;
Jia Meng757f3c92015-09-09 11:18:36 +0800391 int frame_rate;
Yinhang Liud9346492015-12-17 11:14:25 +0800392 int frame_width = 1920;
393 int frame_height = 1080;
Wind Yuan155c8f52016-03-18 23:16:59 +0800394 SmartPtr<char> path_to_fake = NULL;
Wind Yuan75564b12015-01-15 06:51:15 -0500395
Jia Meng0a532932015-10-15 08:44:09 -0400396 const char *short_opts = "sca:n:m:f:d:b:pi:e:r:h";
Yinhang Liu81c44e02015-06-03 15:47:48 +0800397 const struct option long_opts[] = {
398 {"hdr", required_argument, NULL, 'H'},
399 {"tnr", required_argument, NULL, 'T'},
400 {"tnr-level", required_argument, NULL, 'L'},
wujunkai16606f77622016-03-18 14:41:10 +0800401 {"wdr-mode", required_argument, NULL, 'W'},
Yinhang Liub92930c2015-06-23 16:26:35 +0800402 {"bilateral", no_argument, NULL, 'I'},
Yinhang Liu81c44e02015-06-03 15:47:48 +0800403 {"enable-snr", no_argument, NULL, 'S'},
Jia Meng66efecf2015-06-17 11:11:10 +0000404 {"enable-ee", no_argument, NULL, 'E'},
ShincyTu63e2c262015-06-26 10:52:51 +0800405 {"enable-bnr", no_argument, NULL, 'B'},
Yinhang Liue26b2622015-07-21 18:32:36 +0800406 {"enable-dpc", no_argument, NULL, 'D'},
Wind Yuanf4e17ab2016-05-05 02:54:01 +0800407 {"defog-mode", required_argument, NULL, 'X'},
zongwave2ba7f642016-03-15 19:24:12 +0800408 {"wavelet-mode", required_argument, NULL, 'V'},
zongwavebec89e12016-07-23 12:34:20 +0800409 {"3d-denoise", required_argument, NULL, 'N'},
Yinhang Liu4ea70612016-05-26 18:26:29 +0800410 {"enable-wireframe", no_argument, NULL, 'F'},
Sameer Kibey7b429292015-08-07 10:55:38 -0700411 {"usb", required_argument, NULL, 'U'},
Yinhang Liud9346492015-12-17 11:14:25 +0800412 {"resolution", required_argument, NULL, 'R'},
Jia Meng8f94a102015-08-11 16:24:19 +0800413 {"sync", no_argument, NULL, 'Y'},
wujunkai166a84ba052015-09-08 15:54:12 +0800414 {"capture", required_argument, NULL, 'C'},
Wangfei1487b9b2015-08-28 15:10:39 +0800415 {"pipeline", required_argument, NULL, 'P'},
Yinhang Liub0ad64b2016-03-18 16:03:51 +0800416 {"disable-post", no_argument, NULL, 'O'},
Yinhang Liu81c44e02015-06-03 15:47:48 +0800417 {0, 0, 0, 0},
418 };
419
420 while ((opt = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
Wind Yuan75564b12015-01-15 06:51:15 -0500421 switch (opt) {
422 case 'a': {
Wind Yuan6b437392016-02-02 00:31:30 +0800423 XCAM_ASSERT (optarg);
Wind Yuane25ce3f2015-05-04 18:07:29 +0800424 if (!strcmp (optarg, "dynamic"))
425 analyzer_type = AnalyzerTypeDynamic;
426 else if (!strcmp (optarg, "simple"))
Wind Yuan26e9e212015-04-16 15:55:45 +0800427 analyzer_type = AnalyzerTypeSimple;
Wind Yuan75564b12015-01-15 06:51:15 -0500428#if HAVE_IA_AIQ
429 else if (!strcmp (optarg, "aiq"))
Yinhang Liu6c367352016-03-31 20:23:22 +0800430 analyzer_type = AnalyzerTypeAiqTuner;
Jia Meng9724cfe2015-08-12 15:04:45 +0800431 else if (!strcmp (optarg, "hybrid"))
432 analyzer_type = AnalyzerTypeHybrid;
Wind Yuan75564b12015-01-15 06:51:15 -0500433#endif
434 else {
435 print_help (bin_name);
436 return -1;
437 }
438 break;
439 }
440
Wind Yuand4427312015-02-11 16:09:00 +0800441 case 'm': {
Wind Yuan6b437392016-02-02 00:31:30 +0800442 XCAM_ASSERT (optarg);
Wind Yuand4427312015-02-11 16:09:00 +0800443 if (!strcmp (optarg, "dma"))
444 v4l2_mem_type = V4L2_MEMORY_DMABUF;
445 else if (!strcmp (optarg, "mmap"))
446 v4l2_mem_type = V4L2_MEMORY_MMAP;
447 else
448 print_help (bin_name);
449 break;
450 }
451
Wind Yuan75564b12015-01-15 06:51:15 -0500452 case 's':
453 device_manager->enable_save_file (true);
454 break;
455 case 'n':
Yinhang Liu1aa97602016-05-27 14:58:21 +0800456 XCAM_ASSERT (optarg);
Wind Yuan75564b12015-01-15 06:51:15 -0500457 device_manager->set_interval (atoi(optarg));
458 break;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800459#if HAVE_LIBCL
Wind Yuand4427312015-02-11 16:09:00 +0800460 case 'c':
461 have_cl_processor = true;
462 break;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800463#endif
ShincyTu2808b592015-03-13 17:17:25 +0800464 case 'f':
Yinhang Liu1aa97602016-05-27 14:58:21 +0800465 XCAM_ASSERT (optarg);
ShincyTuc8466402015-03-31 11:03:39 +0800466 CHECK_EXP ((strlen(optarg) == 4), "invalid pixel format\n");
467 pixel_format = v4l2_fourcc ((unsigned)optarg[0],
468 (unsigned)optarg[1],
469 (unsigned)optarg[2],
470 (unsigned)optarg[3]);
ShincyTu2808b592015-03-13 17:17:25 +0800471 break;
472 case 'd':
Wind Yuan6b437392016-02-02 00:31:30 +0800473 XCAM_ASSERT (optarg);
ShincyTu2808b592015-03-13 17:17:25 +0800474 if (!strcmp (optarg, "still"))
475 capture_mode = V4L2_CAPTURE_MODE_STILL;
476 else if (!strcmp (optarg, "video"))
477 capture_mode = V4L2_CAPTURE_MODE_VIDEO;
478 else {
479 print_help (bin_name);
480 return -1;
481 }
482 break;
yaowang1a5f12122015-07-27 14:53:38 +0800483 case 'b':
Yinhang Liu1aa97602016-05-27 14:58:21 +0800484 XCAM_ASSERT (optarg);
yaowang1a5f12122015-07-27 14:53:38 +0800485 brightness_level = atoi(optarg);
486 if(brightness_level < 0 || brightness_level > 256) {
487 print_help (bin_name);
488 return -1;
489 }
490 break;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800491 case 'p':
492 need_display = true;
493 break;
Sameer Kibey7b429292015-08-07 10:55:38 -0700494 case 'U':
Yinhang Liu1aa97602016-05-27 14:58:21 +0800495 XCAM_ASSERT (optarg);
Sameer Kibey7b429292015-08-07 10:55:38 -0700496 have_usbcam = true;
Wind Yuan155c8f52016-03-18 23:16:59 +0800497 usb_device_name = strndup(optarg, XCAM_MAX_STR_SIZE);
498 XCAM_LOG_DEBUG("using USB camera plugged in at node: %s", XCAM_STR(usb_device_name.ptr ()));
Sameer Kibey7b429292015-08-07 10:55:38 -0700499 break;
Yinhang Liud9346492015-12-17 11:14:25 +0800500 case 'R':
Wind Yuan6b437392016-02-02 00:31:30 +0800501 XCAM_ASSERT (optarg);
Yinhang Liud9346492015-12-17 11:14:25 +0800502 sscanf (optarg, "%d%*c%d", &frame_width, &frame_height);
503 break;
wangfeicf4c4e72015-05-25 17:11:41 +0800504 case 'e': {
Wind Yuan6b437392016-02-02 00:31:30 +0800505 XCAM_ASSERT (optarg);
wangfeicf4c4e72015-05-25 17:11:41 +0800506 if (!strcmp (optarg, "primary"))
507 display_mode = DRM_DISPLAY_MODE_PRIMARY;
508 else if (!strcmp (optarg, "overlay"))
509 display_mode = DRM_DISPLAY_MODE_OVERLAY;
510 else {
511 print_help (bin_name);
512 return -1;
513 }
514 break;
515 }
ShincyTue521cf92015-03-27 15:13:51 +0800516 case 'i':
Yinhang Liu1aa97602016-05-27 14:58:21 +0800517 XCAM_ASSERT (optarg);
ShincyTue521cf92015-03-27 15:13:51 +0800518 device_manager->set_frame_save(atoi(optarg));
519 break;
Jia Meng8f94a102015-08-11 16:24:19 +0800520 case 'Y':
521 sync_mode = true;
522 break;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800523#if HAVE_LIBCL
Yinhang Liu81c44e02015-06-03 15:47:48 +0800524 case 'H': {
Wind Yuan6b437392016-02-02 00:31:30 +0800525 XCAM_ASSERT (optarg);
Yinhang Liu81c44e02015-06-03 15:47:48 +0800526 if (!strcasecmp (optarg, "rgb"))
527 hdr_type = CL_HDR_TYPE_RGB;
528 else if (!strcasecmp (optarg, "lab"))
529 hdr_type = CL_HDR_TYPE_LAB;
530 else {
531 print_help (bin_name);
532 return -1;
533 }
534 break;
535 }
Yinhang Liub92930c2015-06-23 16:26:35 +0800536 case 'I': {
Jia Meng66efecf2015-06-17 11:11:10 +0000537 denoise_type |= XCAM_DENOISE_TYPE_BILATERAL;
Juan Zhaod9664932015-09-08 10:22:19 +0800538 denoise_type |= XCAM_DENOISE_TYPE_BIYUV;
Yinhang Liu81c44e02015-06-03 15:47:48 +0800539 break;
540 }
541 case 'S': {
Jia Meng66efecf2015-06-17 11:11:10 +0000542 denoise_type |= XCAM_DENOISE_TYPE_SIMPLE;
543 break;
544 }
545 case 'E': {
546 denoise_type |= XCAM_DENOISE_TYPE_EE;
Yinhang Liu81c44e02015-06-03 15:47:48 +0800547 break;
548 }
ShincyTu63e2c262015-06-26 10:52:51 +0800549 case 'B': {
550 denoise_type |= XCAM_DENOISE_TYPE_BNR;
551 break;
552 }
Wangfei8e5e3e42016-02-18 19:41:54 +0800553 case 'X': {
Wind Yuanf4e17ab2016-05-05 02:54:01 +0800554 XCAM_ASSERT (optarg);
555 defog_type = true;
556 if (!strcmp (optarg, "disabled"))
557 defog_type = CLPostImageProcessor::DefogDisabled;
558 else if (!strcmp (optarg, "retinex"))
559 defog_type = CLPostImageProcessor::DefogRetinex;
560 else if (!strcmp (optarg, "dcp"))
561 defog_type = CLPostImageProcessor::DefogDarkChannelPrior;
562 else {
563 print_help (bin_name);
564 return -1;
565 }
Wangfei8e5e3e42016-02-18 19:41:54 +0800566 break;
567 }
zongwave80adcf52016-02-29 12:38:06 +0800568 case 'V': {
zongwave2ba7f642016-03-15 19:24:12 +0800569 XCAM_ASSERT (optarg);
570 if (atoi(optarg) < 0 || atoi(optarg) > 255) {
571 print_help (bin_name);
572 return -1;
573 }
zongwave28a747b2016-03-17 12:49:08 +0800574 if (atoi(optarg) == 1) {
zongwaveb7140442016-03-25 18:15:12 +0800575 wavelet_mode = CL_WAVELET_HAT;
zongwave98d23202016-06-27 13:46:27 +0800576 wavelet_channel = CL_IMAGE_CHANNEL_Y;
zongwave28a747b2016-03-17 12:49:08 +0800577 } else if (atoi(optarg) == 2) {
zongwaveb7140442016-03-25 18:15:12 +0800578 wavelet_mode = CL_WAVELET_HAT;
zongwave98d23202016-06-27 13:46:27 +0800579 wavelet_channel = CL_IMAGE_CHANNEL_UV;
zongwaveb7140442016-03-25 18:15:12 +0800580 } else if (atoi(optarg) == 3) {
581 wavelet_mode = CL_WAVELET_HAAR;
zongwave98d23202016-06-27 13:46:27 +0800582 wavelet_channel = CL_IMAGE_CHANNEL_Y;
zongwaveb7140442016-03-25 18:15:12 +0800583 } else if (atoi(optarg) == 4) {
584 wavelet_mode = CL_WAVELET_HAAR;
zongwave98d23202016-06-27 13:46:27 +0800585 wavelet_channel = CL_IMAGE_CHANNEL_UV;
zongwaveb7140442016-03-25 18:15:12 +0800586 } else if (atoi(optarg) == 5) {
587 wavelet_mode = CL_WAVELET_HAAR;
zongwave98d23202016-06-27 13:46:27 +0800588 wavelet_channel = CL_IMAGE_CHANNEL_UV | CL_IMAGE_CHANNEL_Y;
589 } else if (atoi(optarg) == 6) {
590 wavelet_mode = CL_WAVELET_HAAR;
591 wavelet_channel = CL_IMAGE_CHANNEL_UV | CL_IMAGE_CHANNEL_Y;
592 wavelet_bayes_shrink = true;
zongwave28a747b2016-03-17 12:49:08 +0800593 } else {
zongwaveb7140442016-03-25 18:15:12 +0800594 wavelet_mode = CL_WAVELET_DISABLED;
zongwave28a747b2016-03-17 12:49:08 +0800595 }
zongwave80adcf52016-02-29 12:38:06 +0800596 break;
597 }
zongwavebec89e12016-07-23 12:34:20 +0800598 case 'N': {
599 XCAM_ASSERT (optarg);
600 denoise_3d_mode = true;
601 if (!strcmp (optarg, "disabled"))
602 denoise_3d_mode = CLPostImageProcessor::Denoise3DDisabled;
603 else if (!strcmp (optarg, "yuv"))
604 denoise_3d_mode = CLPostImageProcessor::Denoise3DYuv;
605 else if (!strcmp (optarg, "uv"))
606 denoise_3d_mode = CLPostImageProcessor::Denoise3DUV;
607 else {
608 print_help (bin_name);
609 return -1;
610 }
611 break;
612 }
Yinhang Liu4ea70612016-05-26 18:26:29 +0800613 case 'F': {
614 wireframe_type = true;
615 break;
616 }
Yinhang Liue26b2622015-07-21 18:32:36 +0800617 case 'D': {
618 dpc_type = true;
619 break;
620 }
Yinhang Liu81c44e02015-06-03 15:47:48 +0800621 case 'T': {
Wind Yuan6b437392016-02-02 00:31:30 +0800622 XCAM_ASSERT (optarg);
Yinhang Liu81c44e02015-06-03 15:47:48 +0800623 if (!strcasecmp (optarg, "yuv"))
624 tnr_type = CL_TNR_TYPE_YUV;
625 else if (!strcasecmp (optarg, "rgb"))
626 tnr_type = CL_TNR_TYPE_RGB;
627 else if (!strcasecmp (optarg, "both"))
628 tnr_type = CL_TNR_TYPE_YUV | CL_TNR_TYPE_RGB;
629 else {
630 print_help (bin_name);
631 return -1;
632 }
633 break;
634 }
635 case 'L': {
Wind Yuan6b437392016-02-02 00:31:30 +0800636 XCAM_ASSERT (optarg);
Yinhang Liu81c44e02015-06-03 15:47:48 +0800637 if (atoi(optarg) < 0 || atoi(optarg) > 255) {
638 print_help (bin_name);
639 return -1;
640 }
641 tnr_level = atoi(optarg);
642 break;
643 }
Jia Menga6580232015-10-08 16:51:28 +0800644 case 'W': {
wujunkai16606f77622016-03-18 14:41:10 +0800645 XCAM_ASSERT (optarg);
646 if (!strcasecmp (optarg, "gaussian"))
647 wdr_mode = CL3aImageProcessor::Gaussian;
648 else if (!strcasecmp (optarg, "haleq"))
649 wdr_mode = CL3aImageProcessor::Haleq;
wujunkai16682950fb2015-10-19 18:09:05 +0800650
wujunkai166b0bd5512016-02-18 18:25:42 +0800651 pixel_format = V4L2_PIX_FMT_SGRBG12;
wujunkai16606f77622016-03-18 14:41:10 +0800652 wdr_type = true;
wujunkai166b0bd5512016-02-18 18:25:42 +0800653 setenv ("AIQ_CPF_PATH", IMX185_WDR_CPF, 1);
654 break;
655 }
Wangfei1487b9b2015-08-28 15:10:39 +0800656 case 'P': {
Wind Yuan6b437392016-02-02 00:31:30 +0800657 XCAM_ASSERT (optarg);
Wangfei1487b9b2015-08-28 15:10:39 +0800658 if (!strcasecmp (optarg, "basic"))
659 pipeline_mode = CL3aImageProcessor::BasicPipelineProfile;
660 else if (!strcasecmp (optarg, "advance"))
661 pipeline_mode = CL3aImageProcessor::AdvancedPipelineProfile;
Wangfei16b65db2015-09-11 14:44:28 +0800662 else if (!strcasecmp (optarg, "extreme"))
663 pipeline_mode = CL3aImageProcessor::ExtremePipelineProfile;
Wangfei1487b9b2015-08-28 15:10:39 +0800664 else {
665 print_help (bin_name);
666 return -1;
667 }
668 break;
669 }
wujunkai166a84ba052015-09-08 15:54:12 +0800670 case 'C': {
Wind Yuan6b437392016-02-02 00:31:30 +0800671 XCAM_ASSERT (optarg);
wujunkai166a84ba052015-09-08 15:54:12 +0800672 if (!strcmp (optarg, "bayer"))
673 capture_stage = CL3aImageProcessor::BasicbayerStage;
674 break;
675 }
Yinhang Liub0ad64b2016-03-18 16:03:51 +0800676 case 'O': {
677 have_cl_post_processor = false;
678 break;
679 }
Yinhang Liuc2f19082015-08-28 12:27:48 +0800680#endif
Jia Meng0a532932015-10-15 08:44:09 -0400681 case 'r': {
Yinhang Liu1aa97602016-05-27 14:58:21 +0800682 XCAM_ASSERT (optarg);
683 XCAM_LOG_INFO ("use raw image %s as input source", optarg);
684 path_to_fake = strndup(optarg, XCAM_MAX_STR_SIZE);
Jia Meng0a532932015-10-15 08:44:09 -0400685 break;
686 }
Wind Yuan75564b12015-01-15 06:51:15 -0500687 case 'h':
688 print_help (bin_name);
689 return 0;
690
691 default:
692 print_help (bin_name);
693 return -1;
694 }
695 }
696
Yinhang Liud9346492015-12-17 11:14:25 +0800697 device_manager->set_frame_width(frame_width);
698 device_manager->set_frame_height(frame_height);
wangfeicf4c4e72015-05-25 17:11:41 +0800699 if (need_display) {
Wind Yuan683f8662015-03-27 18:52:38 +0800700 device_manager->enable_display (true);
wangfeicf4c4e72015-05-25 17:11:41 +0800701 device_manager->set_display_mode (display_mode);
702 }
ShincyTu2808b592015-03-13 17:17:25 +0800703 if (!device.ptr ()) {
Wind Yuan155c8f52016-03-18 23:16:59 +0800704 if (path_to_fake.ptr ()) {
Jia Meng0a532932015-10-15 08:44:09 -0400705 device = new FakeV4l2Device ();
706 } else if (have_usbcam) {
Wind Yuan155c8f52016-03-18 23:16:59 +0800707 device = new UVCDevice (usb_device_name.ptr ());
Sameer Kibey7b429292015-08-07 10:55:38 -0700708 } else {
709 if (capture_mode == V4L2_CAPTURE_MODE_STILL)
710 device = new AtomispDevice (CAPTURE_DEVICE_STILL);
711 else if (capture_mode == V4L2_CAPTURE_MODE_VIDEO)
712 device = new AtomispDevice (CAPTURE_DEVICE_VIDEO);
713 else
714 device = new AtomispDevice (DEFAULT_CAPTURE_DEVICE);
715 }
ShincyTu2808b592015-03-13 17:17:25 +0800716 }
Wind Yuan75564b12015-01-15 06:51:15 -0500717 if (!event_device.ptr ())
718 event_device = new V4l2SubDevice (DEFAULT_EVENT_DEVICE);
719 if (!isp_controller.ptr ())
720 isp_controller = new IspController (device);
Wind Yuan26e9e212015-04-16 15:55:45 +0800721
722 switch (analyzer_type) {
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800723 case AnalyzerTypeSimple:
724 analyzer = new X3aAnalyzerSimple ();
725 break;
Wind Yuan26e9e212015-04-16 15:55:45 +0800726#if HAVE_IA_AIQ
Yinhang Liu6c367352016-03-31 20:23:22 +0800727 case AnalyzerTypeAiqTuner: {
728 SmartPtr<X3aAnalyzer> aiq_analyzer = new X3aAnalyzerAiq (isp_controller, DEFAULT_CPF_FILE);
729 SmartPtr<X3aAnalyzeTuner> tuner_analyzer = new X3aAnalyzeTuner ();
730 XCAM_ASSERT (aiq_analyzer.ptr () && tuner_analyzer.ptr ());
731 tuner_analyzer->set_analyzer (aiq_analyzer);
732 analyzer = tuner_analyzer;
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800733 break;
Yinhang Liu6c367352016-03-31 20:23:22 +0800734 }
Jia Meng9724cfe2015-08-12 15:04:45 +0800735 case AnalyzerTypeHybrid: {
Jia Mengc54c3322015-08-26 09:45:18 +0800736 path_of_3a = DEFAULT_HYBRID_3A_LIB;
Yinhang Liue37a8722016-06-27 18:14:35 +0800737 SmartPtr<HybridAnalyzerLoader> hybrid_loader = new HybridAnalyzerLoader (path_of_3a);
738 hybrid_loader->set_cpf_path (DEFAULT_CPF_FILE);
739 hybrid_loader->set_isp_controller (isp_controller);
740 loader = hybrid_loader.dynamic_cast_ptr<AnalyzerLoader> ();
741 analyzer = hybrid_loader->load_analyzer (loader);
Jia Meng9724cfe2015-08-12 15:04:45 +0800742 CHECK_EXP (analyzer.ptr (), "load hybrid 3a lib(%s) failed", path_of_3a);
743 break;
744 }
Wind Yuan26e9e212015-04-16 15:55:45 +0800745#endif
Wind Yuane25ce3f2015-05-04 18:07:29 +0800746 case AnalyzerTypeDynamic: {
Jia Meng9724cfe2015-08-12 15:04:45 +0800747 path_of_3a = DEFAULT_DYNAMIC_3A_LIB;
Yinhang Liue37a8722016-06-27 18:14:35 +0800748 SmartPtr<DynamicAnalyzerLoader> dynamic_loader = new DynamicAnalyzerLoader (path_of_3a);
749 loader = dynamic_loader.dynamic_cast_ptr<AnalyzerLoader> ();
750 analyzer = dynamic_loader->load_analyzer (loader);
Wind Yuane25ce3f2015-05-04 18:07:29 +0800751 CHECK_EXP (analyzer.ptr (), "load dynamic 3a lib(%s) failed", path_of_3a);
Yinhang Liu4afa3642016-05-13 19:13:07 +0800752
753 // Create smart analyzer from dynamic libraries
754 SmartHandlerList smart_handlers = SmartAnalyzerLoader::load_smart_handlers (DEFAULT_SMART_ANALYSIS_LIB_DIR);
755 if (!smart_handlers.empty () ) {
756 smart_analyzer = new SmartAnalyzer ();
757 if (!smart_analyzer.ptr ()) {
758 XCAM_LOG_INFO ("load smart analyzer(%s) failed", DEFAULT_SMART_ANALYSIS_LIB_DIR);
759 break;
760 }
761 SmartHandlerList::iterator i_handler = smart_handlers.begin ();
762 for (; i_handler != smart_handlers.end (); ++i_handler) {
763 XCAM_ASSERT ((*i_handler).ptr ());
764 smart_analyzer->add_handler (*i_handler);
765 }
766 }
Wind Yuane25ce3f2015-05-04 18:07:29 +0800767 break;
768 }
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800769 default:
770 print_help (bin_name);
771 return -1;
Wind Yuan26e9e212015-04-16 15:55:45 +0800772 }
Jia Meng8f94a102015-08-11 16:24:19 +0800773 XCAM_ASSERT (analyzer.ptr ());
774 analyzer->set_sync_mode (sync_mode);
Wind Yuan75564b12015-01-15 06:51:15 -0500775
776 signal(SIGINT, dev_stop_handler);
777
778 device->set_sensor_id (0);
ShincyTu2808b592015-03-13 17:17:25 +0800779 device->set_capture_mode (capture_mode);
Wind Yuan75564b12015-01-15 06:51:15 -0500780 //device->set_mem_type (V4L2_MEMORY_DMABUF);
Wind Yuand4427312015-02-11 16:09:00 +0800781 device->set_mem_type (v4l2_mem_type);
Wind Yuan75564b12015-01-15 06:51:15 -0500782 device->set_buffer_count (8);
Jia Meng757f3c92015-09-09 11:18:36 +0800783 if (pixel_format == V4L2_PIX_FMT_SGRBG12) {
784 frame_rate = 30;
785 device->set_framerate (frame_rate, 1);
786 }
Yinhang Liuc64ed592016-07-15 18:53:34 +0800787#if HAVE_LIBCL
Jia Meng757f3c92015-09-09 11:18:36 +0800788 else {
789 frame_rate = 25;
790 device->set_framerate (frame_rate, 1);
wujunkai16606f77622016-03-18 14:41:10 +0800791 if(wdr_type == true) {
wujunkai166a9a55f22015-10-10 15:53:32 +0800792 XCAM_LOG_WARNING("Tonemapping is only applicable under BA12 format. Disable tonemapping automatically.");
wujunkai16606f77622016-03-18 14:41:10 +0800793 wdr_type = false;
wujunkai166a9a55f22015-10-10 15:53:32 +0800794 }
Jia Meng757f3c92015-09-09 11:18:36 +0800795 }
Yinhang Liuc64ed592016-07-15 18:53:34 +0800796#endif
Wind Yuan75564b12015-01-15 06:51:15 -0500797 ret = device->open ();
798 CHECK (ret, "device(%s) open failed", device->get_device_name());
Yinhang Liud9346492015-12-17 11:14:25 +0800799 ret = device->set_format (frame_width, frame_height, pixel_format, V4L2_FIELD_NONE, frame_width * 2);
Wind Yuan75564b12015-01-15 06:51:15 -0500800 CHECK (ret, "device(%s) set format failed", device->get_device_name());
801
802 ret = event_device->open ();
Wind Yuanb67045c2015-08-27 13:50:53 +0800803 if (ret == XCAM_RETURN_NO_ERROR) {
804 CHECK (ret, "event device(%s) open failed", event_device->get_device_name());
805 int event = V4L2_EVENT_ATOMISP_3A_STATS_READY;
806 ret = event_device->subscribe_event (event);
807 CHECK_CONTINUE (
808 ret,
809 "device(%s) subscribe event(%d) failed",
810 event_device->get_device_name(), event);
811 event = V4L2_EVENT_FRAME_SYNC;
812 ret = event_device->subscribe_event (event);
813 CHECK_CONTINUE (
814 ret,
815 "device(%s) subscribe event(%d) failed",
816 event_device->get_device_name(), event);
817
818 device_manager->set_event_device (event_device);
819 }
Wind Yuan75564b12015-01-15 06:51:15 -0500820
821 device_manager->set_capture_device (device);
Wind Yuan75564b12015-01-15 06:51:15 -0500822 if (analyzer.ptr())
zongwave03954a32015-09-22 15:40:44 +0800823 device_manager->set_3a_analyzer (analyzer);
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800824
Yinhang Liu4afa3642016-05-13 19:13:07 +0800825 if (smart_analyzer.ptr ()) {
826 if (smart_analyzer->prepare_handlers () != XCAM_RETURN_NO_ERROR) {
827 XCAM_LOG_WARNING ("analyzer(%s) prepare handlers failed", smart_analyzer->get_name ());
828 }
829 device_manager->set_smart_analyzer (smart_analyzer);
830 }
831
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800832 if (have_cl_processor)
833 isp_processor = new IspExposureImageProcessor (isp_controller);
834 else
835 isp_processor = new IspImageProcessor (isp_controller);
836
837 XCAM_ASSERT (isp_processor.ptr ());
Wind Yuane4ba0c92015-03-26 16:59:06 +0800838 device_manager->add_image_processor (isp_processor);
Yinhang Liuc2f19082015-08-28 12:27:48 +0800839#if HAVE_LIBCL
Wind Yuand4427312015-02-11 16:09:00 +0800840 if (have_cl_processor) {
Wind Yuane4ba0c92015-03-26 16:59:06 +0800841 cl_processor = new CL3aImageProcessor ();
Wind Yuan7ddf2602015-04-14 18:49:45 +0800842 cl_processor->set_stats_callback(device_manager);
Yinhang Liue26b2622015-07-21 18:32:36 +0800843 cl_processor->set_dpc(dpc_type);
Yinhang Liu81c44e02015-06-03 15:47:48 +0800844 cl_processor->set_hdr (hdr_type);
Jia Meng66efecf2015-06-17 11:11:10 +0000845 cl_processor->set_denoise (denoise_type);
wujunkai16606f77622016-03-18 14:41:10 +0800846 cl_processor->set_tonemapping(wdr_mode);
Jia Menga6580232015-10-08 16:51:28 +0800847 cl_processor->set_gamma (!wdr_type); // disable gamma for WDR
zongwave98d23202016-06-27 13:46:27 +0800848 cl_processor->set_wavelet (wavelet_mode, wavelet_channel, wavelet_bayes_shrink);
Yinhang Liu4ea70612016-05-26 18:26:29 +0800849 cl_processor->set_wireframe (wireframe_type);
wujunkai166a84ba052015-09-08 15:54:12 +0800850 cl_processor->set_capture_stage (capture_stage);
wujunkai166c8f3b442016-02-29 17:12:09 +0800851
852 if (wdr_type) {
853 cl_processor->set_3a_stats_bits(12);
854 }
Yinhang Liu81c44e02015-06-03 15:47:48 +0800855 cl_processor->set_tnr (tnr_type, tnr_level);
Wangfei1487b9b2015-08-28 15:10:39 +0800856 cl_processor->set_profile (pipeline_mode);
yaowang1a5f12122015-07-27 14:53:38 +0800857 analyzer->set_parameter_brightness((brightness_level - 128) / 128.0);
Wind Yuand4427312015-02-11 16:09:00 +0800858 device_manager->add_image_processor (cl_processor);
Yinhang Liu4afa3642016-05-13 19:13:07 +0800859
860 if (smart_analyzer.ptr ()) {
861 cl_processor->set_scaler (true);
862 cl_processor->set_scaler_factor (640.0 / frame_width);
863 }
Wind Yuand4427312015-02-11 16:09:00 +0800864 }
Yinhang Liu3c17fea2016-03-15 10:47:03 +0800865
Yinhang Liub0ad64b2016-03-18 16:03:51 +0800866 if (have_cl_post_processor) {
867 cl_post_processor = new CLPostImageProcessor ();
Yinhang Liu3c721c12016-03-15 15:03:51 +0800868
Wind Yuanf4e17ab2016-05-05 02:54:01 +0800869 cl_post_processor->set_defog_mode ((CLPostImageProcessor::CLDefogMode)defog_type);
Yinhang Liu3c721c12016-03-15 15:03:51 +0800870
zongwavebec89e12016-07-23 12:34:20 +0800871 cl_post_processor->set_3ddenoise_mode ((CLPostImageProcessor::CL3DDenoiseMode)denoise_3d_mode, denoise_3d_ref_count);
872
Yinhang Liud6d824a2016-03-22 20:43:00 +0800873 if (need_display) {
Yinhang Liub0ad64b2016-03-18 16:03:51 +0800874 cl_post_processor->set_output_format (V4L2_PIX_FMT_XBGR32);
875 }
876 device_manager->add_image_processor (cl_post_processor);
Yinhang Liu3c17fea2016-03-15 10:47:03 +0800877 }
Wind Yuand4427312015-02-11 16:09:00 +0800878#endif
Wind Yuane4ba0c92015-03-26 16:59:06 +0800879
Jia Meng0a532932015-10-15 08:44:09 -0400880 SmartPtr<PollThread> poll_thread;
Wind Yuan155c8f52016-03-18 23:16:59 +0800881 if (path_to_fake.ptr ())
882 poll_thread = new FakePollThread (path_to_fake.ptr ());
Yinhang Liue37a8722016-06-27 18:14:35 +0800883 else {
884 SmartPtr<IspPollThread> isp_poll_thread = new IspPollThread ();
885 isp_poll_thread->set_isp_controller (isp_controller);
886 poll_thread = isp_poll_thread;
887 }
Jia Meng0a532932015-10-15 08:44:09 -0400888 device_manager->set_poll_thread (poll_thread);
889
Wind Yuan75564b12015-01-15 06:51:15 -0500890 ret = device_manager->start ();
891 CHECK (ret, "device manager start failed");
892
Yinhang Liuc64ed592016-07-15 18:53:34 +0800893#if HAVE_LIBCL
Jia Meng757f3c92015-09-09 11:18:36 +0800894 // hard code exposure range and max gain for imx185 WDR
Jia Menga6580232015-10-08 16:51:28 +0800895 if (wdr_type) {
Jia Meng757f3c92015-09-09 11:18:36 +0800896 if (frame_rate == 30)
897 analyzer->set_ae_exposure_time_range (80 * 1110 * 1000 / 37125, 1120 * 1110 * 1000 / 37125);
898 else
Jia Menga6580232015-10-08 16:51:28 +0800899 analyzer->set_ae_exposure_time_range (80 * 1320 * 1000 / 37125, 1120 * 1320 * 1000 / 37125);
Jia Meng757f3c92015-09-09 11:18:36 +0800900 analyzer->set_ae_max_analog_gain (3.98); // 12dB
901 }
Yinhang Liuc64ed592016-07-15 18:53:34 +0800902#endif
Jia Meng757f3c92015-09-09 11:18:36 +0800903
Wind Yuan75564b12015-01-15 06:51:15 -0500904 // wait for interruption
905 {
906 SmartLock locker (g_mutex);
907 while (!g_stop)
908 g_cond.wait (g_mutex);
909 }
910
911 ret = device_manager->stop();
912 CHECK_CONTINUE (ret, "device manager stop failed");
913 device->close ();
914 event_device->close ();
Wind Yuan75564b12015-01-15 06:51:15 -0500915
916 return 0;
917}