blob: fefdd12b3421191e513108a0d2f1fc91b2f80eb7 [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 Liu4afa3642016-05-13 19:13:07 +080028#include "smart_analyzer_loader.h"
Wind Yuan75564b12015-01-15 06:51:15 -050029#if HAVE_IA_AIQ
30#include "x3a_analyzer_aiq.h"
Yinhang Liu6c367352016-03-31 20:23:22 +080031#include "x3a_analyze_tuner.h"
Wind Yuan75564b12015-01-15 06:51:15 -050032#endif
Wind Yuand4427312015-02-11 16:09:00 +080033#if HAVE_LIBCL
Wind Yuane4ba0c92015-03-26 16:59:06 +080034#include "cl_3a_image_processor.h"
Yinhang Liu2ab1f992016-03-15 10:41:17 +080035#include "cl_post_image_processor.h"
wangfeicf4c4e72015-05-25 17:11:41 +080036#include "cl_csc_image_processor.h"
Yinhang Liu81c44e02015-06-03 15:47:48 +080037#include "cl_hdr_handler.h"
38#include "cl_tnr_handler.h"
Wind Yuane4ba0c92015-03-26 16:59:06 +080039#endif
40#if HAVE_LIBDRM
41#include "drm_display.h"
Wind Yuand4427312015-02-11 16:09:00 +080042#endif
zongwave03954a32015-09-22 15:40:44 +080043#include "x3a_analyzer_loader.h"
Jia Meng0a532932015-10-15 08:44:09 -040044#include "poll_thread.h"
45#include "fake_poll_thread.h"
Jia Meng66efecf2015-06-17 11:11:10 +000046#include <base/xcam_3a_types.h>
Wind Yuan75564b12015-01-15 06:51:15 -050047#include <unistd.h>
48#include <signal.h>
49#include <stdlib.h>
ShincyTue521cf92015-03-27 15:13:51 +080050#include <string>
Yinhang Liu81c44e02015-06-03 15:47:48 +080051#include <getopt.h>
John Yeae9da732015-01-22 13:36:36 +080052#include "test_common.h"
53
Wind Yuan75564b12015-01-15 06:51:15 -050054using namespace XCam;
55
wujunkai16682950fb2015-10-19 18:09:05 +080056#define IMX185_WDR_CPF "/etc/atomisp/imx185_wdr.cpf"
57
ShincyTue521cf92015-03-27 15:13:51 +080058static Mutex g_mutex;
59static Cond g_cond;
60static bool g_stop = false;
61
Wind Yuan75564b12015-01-15 06:51:15 -050062class MainDeviceManager
63 : public DeviceManager
64{
65public:
66 MainDeviceManager ()
67 : _file (NULL)
68 , _save_file (false)
69 , _interval (1)
Yinhang Liud9346492015-12-17 11:14:25 +080070 , _frame_width (0)
71 , _frame_height (0)
Wind Yuan75564b12015-01-15 06:51:15 -050072 , _frame_count (0)
ShincyTue521cf92015-03-27 15:13:51 +080073 , _frame_save (0)
Wind Yuan683f8662015-03-27 18:52:38 +080074 , _enable_display (false)
Wind Yuane4ba0c92015-03-26 16:59:06 +080075 {
76#if HAVE_LIBDRM
77 _display = DrmDisplay::instance();
78#endif
Wind Yuan91625802015-06-24 15:36:01 +080079 XCAM_OBJ_PROFILING_INIT;
Wind Yuane4ba0c92015-03-26 16:59:06 +080080 }
Wind Yuan75564b12015-01-15 06:51:15 -050081
82 ~MainDeviceManager () {
83 close_file ();
84 }
85
86 void enable_save_file (bool enable) {
87 _save_file = enable;
88 }
Yinhang Liud9346492015-12-17 11:14:25 +080089
Wind Yuan75564b12015-01-15 06:51:15 -050090 void set_interval (uint32_t inteval) {
91 _interval = inteval;
92 }
Yinhang Liud9346492015-12-17 11:14:25 +080093
94 void set_frame_width (uint32_t frame_width) {
95 _frame_width = frame_width;
96 }
97
98 void set_frame_height (uint32_t frame_height) {
99 _frame_height = frame_height;
100 }
101
ShincyTue521cf92015-03-27 15:13:51 +0800102 void set_frame_save (uint32_t frame_save) {
103 _frame_save = frame_save;
104 }
Wind Yuan75564b12015-01-15 06:51:15 -0500105
Wind Yuan683f8662015-03-27 18:52:38 +0800106 void enable_display(bool value) {
107 _enable_display = value;
108 }
109
wangfeicf4c4e72015-05-25 17:11:41 +0800110 void set_display_mode(DrmDisplayMode mode) {
111 _display->set_display_mode (mode);
112 }
113
Wind Yuan75564b12015-01-15 06:51:15 -0500114protected:
Wind Yuan73af3932015-07-02 17:52:43 +0800115 virtual void handle_message (const SmartPtr<XCamMessage> &msg);
116 virtual void handle_buffer (const SmartPtr<VideoBuffer> &buf);
Wind Yuan75564b12015-01-15 06:51:15 -0500117
Wind Yuan73af3932015-07-02 17:52:43 +0800118 int display_buf (const SmartPtr<VideoBuffer> &buf);
Wind Yuane4ba0c92015-03-26 16:59:06 +0800119
Wind Yuan75564b12015-01-15 06:51:15 -0500120private:
121 void open_file ();
122 void close_file ();
Wind Yuan71111322016-02-24 22:56:27 +0800123 XCamReturn write_buf (const SmartPtr<VideoBuffer> &buf);
Wind Yuan75564b12015-01-15 06:51:15 -0500124
125 FILE *_file;
126 bool _save_file;
127 uint32_t _interval;
Yinhang Liud9346492015-12-17 11:14:25 +0800128 uint32_t _frame_width;
129 uint32_t _frame_height;
Wind Yuan75564b12015-01-15 06:51:15 -0500130 uint32_t _frame_count;
ShincyTue521cf92015-03-27 15:13:51 +0800131 uint32_t _frame_save;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800132 SmartPtr<DrmDisplay> _display;
Wind Yuan683f8662015-03-27 18:52:38 +0800133 bool _enable_display;
Wind Yuan91625802015-06-24 15:36:01 +0800134 XCAM_OBJ_PROFILING_DEFINES;
Wind Yuan75564b12015-01-15 06:51:15 -0500135};
136
137void
Wind Yuan73af3932015-07-02 17:52:43 +0800138MainDeviceManager::handle_message (const SmartPtr<XCamMessage> &msg)
Wind Yuan75564b12015-01-15 06:51:15 -0500139{
140 XCAM_UNUSED (msg);
141}
142
143void
Wind Yuan73af3932015-07-02 17:52:43 +0800144MainDeviceManager::handle_buffer (const SmartPtr<VideoBuffer> &buf)
Wind Yuan75564b12015-01-15 06:51:15 -0500145{
Wind Yuan683f8662015-03-27 18:52:38 +0800146 FPS_CALCULATION (fps_buf, 30);
147
Wind Yuan91625802015-06-24 15:36:01 +0800148 XCAM_OBJ_PROFILING_START;
149
Wind Yuan683f8662015-03-27 18:52:38 +0800150 if (_enable_display)
151 display_buf (buf);
Wind Yuane4ba0c92015-03-26 16:59:06 +0800152
Wind Yuan91625802015-06-24 15:36:01 +0800153 XCAM_OBJ_PROFILING_END("main_dev_manager_display", 30);
154
Wind Yuan75564b12015-01-15 06:51:15 -0500155 if (!_save_file)
156 return ;
157
158 if ((_frame_count++ % _interval) != 0)
159 return;
160
ShincyTue521cf92015-03-27 15:13:51 +0800161 if ((_frame_save != 0) && (_frame_count > _frame_save)) {
162 SmartLock locker (g_mutex);
163 g_stop = true;
164 g_cond.broadcast ();
165 return;
166 }
167
Wind Yuan75564b12015-01-15 06:51:15 -0500168 open_file ();
Jia Meng6c9241d2015-06-12 11:08:45 +0000169
170 if (!_file) {
171 XCAM_LOG_ERROR ("open file failed");
Jia Meng54a2dcb2015-08-20 15:23:47 +0800172 return;
Jia Meng6c9241d2015-06-12 11:08:45 +0000173 }
Wind Yuan71111322016-02-24 22:56:27 +0800174 write_buf (buf);
Wind Yuan75564b12015-01-15 06:51:15 -0500175}
176
Wind Yuane4ba0c92015-03-26 16:59:06 +0800177int
Wind Yuan73af3932015-07-02 17:52:43 +0800178MainDeviceManager::display_buf (const SmartPtr<VideoBuffer> &data)
Wind Yuane4ba0c92015-03-26 16:59:06 +0800179{
180#if HAVE_LIBDRM
181 XCamReturn ret = XCAM_RETURN_NO_ERROR;
Wind Yuan73af3932015-07-02 17:52:43 +0800182 SmartPtr<VideoBuffer> buf = data;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800183 const VideoBufferInfo & frame_info = buf->get_video_info ();
184 struct v4l2_rect rect = { 0, 0, (int)frame_info.width, (int)frame_info.height };
185
186 if (!_display->is_render_inited ()) {
Yinhang Liud9346492015-12-17 11:14:25 +0800187 ret = _display->render_init (0, 0, this->_frame_width, this->_frame_height,
188 frame_info.format, &rect);
Wind Yuane4ba0c92015-03-26 16:59:06 +0800189 CHECK (ret, "display failed on render_init");
190 }
191 ret = _display->render_setup_frame_buffer (buf);
192 CHECK (ret, "display failed on framebuf set");
193 ret = _display->render_buffer (buf);
194 CHECK (ret, "display failed on rendering");
195#endif
196 return 0;
197}
198
199
Wind Yuan75564b12015-01-15 06:51:15 -0500200void
201MainDeviceManager::open_file ()
202{
ShincyTue521cf92015-03-27 15:13:51 +0800203 if ((_file) && (_frame_save == 0))
Wind Yuan75564b12015-01-15 06:51:15 -0500204 return;
ShincyTue521cf92015-03-27 15:13:51 +0800205
206 std::string file_name = DEFAULT_SAVE_FILE_NAME;
207
208 if (_frame_save != 0) {
209 file_name += std::to_string(_frame_count);
210 }
211 file_name += ".raw";
212
213 _file = fopen(file_name.c_str(), "wb");
Wind Yuan75564b12015-01-15 06:51:15 -0500214}
215
216void
217MainDeviceManager::close_file ()
218{
219 if (_file)
220 fclose (_file);
221 _file = NULL;
222}
223
Wind Yuan71111322016-02-24 22:56:27 +0800224XCamReturn
225MainDeviceManager::write_buf (const SmartPtr<VideoBuffer> &buf)
226{
227 const VideoBufferInfo &info = buf->get_video_info ();
228 VideoBufferPlanarInfo planar;
229 uint8_t *memory = NULL;
230 XCamReturn ret = XCAM_RETURN_NO_ERROR;
231
232 memory = buf->map ();
233 if (!memory) {
234 XCAM_LOG_ERROR ("map buffer failed in write_buf");
235 return XCAM_RETURN_ERROR_MEM;
236 }
237
238 for (uint32_t index = 0; index < info.components; index++) {
239 info.get_planar_info (planar, index);
240 uint32_t line_bytes = planar.width * planar.pixel_bytes;
241
242 for (uint32_t i = 0; i < planar.height; i++) {
243 if (fwrite (memory + info.offsets [index] + i * info.strides [index], 1, line_bytes, _file) != line_bytes) {
244 XCAM_LOG_ERROR ("write file failed, size doesn't match");
245 ret = XCAM_RETURN_ERROR_FILE;
246 }
247 }
248 }
249 buf->unmap ();
250 return ret;
251}
252
Wind Yuan75564b12015-01-15 06:51:15 -0500253#define V4L2_CAPTURE_MODE_STILL 0x2000
254#define V4L2_CAPTURE_MODE_VIDEO 0x4000
255#define V4L2_CAPTURE_MODE_PREVIEW 0x8000
256
Wind Yuan26e9e212015-04-16 15:55:45 +0800257typedef enum {
258 AnalyzerTypeSimple = 0,
Yinhang Liu6c367352016-03-31 20:23:22 +0800259 AnalyzerTypeAiqTuner,
Wind Yuane25ce3f2015-05-04 18:07:29 +0800260 AnalyzerTypeDynamic,
Jia Meng9724cfe2015-08-12 15:04:45 +0800261 AnalyzerTypeHybrid,
Wind Yuan26e9e212015-04-16 15:55:45 +0800262} AnalyzerType;
263
Wind Yuan75564b12015-01-15 06:51:15 -0500264void dev_stop_handler(int sig)
265{
266 XCAM_UNUSED (sig);
267
268 SmartLock locker (g_mutex);
269 g_stop = true;
270 g_cond.broadcast ();
271
272 //exit(0);
273}
274
275void print_help (const char *bin_name)
276{
277 printf ("Usage: %s [-a analyzer]\n"
Yinhang Liu81c44e02015-06-03 15:47:48 +0800278 "Configurations:\n"
ShincyTue521cf92015-03-27 15:13:51 +0800279 "\t -a analyzer specify a analyzer\n"
Wind Yuane25ce3f2015-05-04 18:07:29 +0800280 "\t select from [simple, aiq, dynamic], default is [simple]\n"
ShincyTue521cf92015-03-27 15:13:51 +0800281 "\t -m mem_type specify video memory type\n"
282 "\t mem_type select from [dma, mmap], default is [mmap]\n"
283 "\t -s save file to %s\n"
284 "\t -n interval save file on every [interval] frame\n"
Yinhang Liuc2f19082015-08-28 12:27:48 +0800285#if HAVE_LIBCL
ShincyTue521cf92015-03-27 15:13:51 +0800286 "\t -c process image with cl kernel\n"
Yinhang Liuc2f19082015-08-28 12:27:48 +0800287#endif
ShincyTue521cf92015-03-27 15:13:51 +0800288 "\t -f pixel_fmt specify output pixel format\n"
wujunkai1669845b022015-08-27 15:59:27 +0800289 "\t pixel_fmt select from [NV12, YUYV, BA10, BA12], default is [NV12]\n"
ShincyTue521cf92015-03-27 15:13:51 +0800290 "\t -d cap_mode specify capture mode\n"
291 "\t cap_mode select from [video, still], default is [video]\n"
yaowang1a5f12122015-07-27 14:53:38 +0800292 "\t -b brightness specify brightness level\n"
293 "\t brightness level select from [0, 256], default is [128]\n"
ShincyTue521cf92015-03-27 15:13:51 +0800294 "\t -i frame_save specify the frame count to save, default is 0 which means endless\n"
wangfeicf4c4e72015-05-25 17:11:41 +0800295 "\t -p preview on local display\n"
Sameer Kibey7b429292015-08-07 10:55:38 -0700296 "\t --usb specify node for usb camera device, enables capture path through USB camera \n"
297 "\t specify [/dev/video4, /dev/video5] depending on which node USB camera is attached\n"
Yinhang Liud9346492015-12-17 11:14:25 +0800298 "\t --resolution specify the resolution of usb camera\n"
299 "\t select from [1920x1080, 1280x720 ...], default is [1920x1080]\n"
wangfeicf4c4e72015-05-25 17:11:41 +0800300 "\t -e display_mode preview mode\n"
301 "\t select from [primary, overlay], default is [primary]\n"
Jia Meng8f94a102015-08-11 16:24:19 +0800302 "\t --sync set analyzer in sync mode\n"
Jia Meng0a532932015-10-15 08:44:09 -0400303 "\t -r raw_input specify the path of raw image as fake source instead of live camera\n"
ShincyTue521cf92015-03-27 15:13:51 +0800304 "\t -h help\n"
Yinhang Liuc2f19082015-08-28 12:27:48 +0800305#if HAVE_LIBCL
Yinhang Liu81c44e02015-06-03 15:47:48 +0800306 "CL features:\n"
wujunkai166a84ba052015-09-08 15:54:12 +0800307 "\t --capture capture_stage specify the capture stage of image\n"
308 "\t capture_stage select from [bayer, tonemapping], default is [tonemapping]\n"
Yinhang Liu81c44e02015-06-03 15:47:48 +0800309 "\t --hdr specify hdr type, default is hdr off\n"
310 "\t select from [rgb, lab]\n"
311 "\t --tnr specify temporal noise reduction type, default is tnr off\n"
312 "\t select from [rgb, yuv, both]\n"
313 "\t --tnr-level specify tnr level\n"
wujunkai16606f77622016-03-18 14:41:10 +0800314 "\t --wdr-mode specify wdr mode. select from [gaussian, haleq]\n"
Yinhang Liub92930c2015-06-23 16:26:35 +0800315 "\t --bilateral enable bilateral noise reduction\n"
Yinhang Liu81c44e02015-06-03 15:47:48 +0800316 "\t --enable-snr enable simple noise reduction\n"
Jia Meng66efecf2015-06-17 11:11:10 +0000317 "\t --enable-ee enable YEENR\n"
ShincyTu63e2c262015-06-26 10:52:51 +0800318 "\t --enable-bnr enable bayer noise reduction\n"
Yinhang Liue26b2622015-07-21 18:32:36 +0800319 "\t --enable-dpc enable defect pixel correction\n"
Wind Yuanf4e17ab2016-05-05 02:54:01 +0800320 "\t --defog-mode mode enable defog\n"
321 "\t select from [disabled, retinex, dcp], default is [disabled]\n"
zongwave3b419ed2016-05-10 17:21:54 +0800322 "\t --enable-retinex enable retinex\n"
323 "\t --wavelet-mode specify wavelet denoise mode, default is off\n"
zongwave98d23202016-06-27 13:46:27 +0800324 "\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 +0800325 "\t --enable-wireframe enable wire frame\n"
zongwave3b419ed2016-05-10 17:21:54 +0800326 "\t --pipeline pipe mode\n"
Wangfei16b65db2015-09-11 14:44:28 +0800327 "\t select from [basic, advance, extreme], default is [basic]\n"
Yinhang Liub0ad64b2016-03-18 16:03:51 +0800328 "\t --disable-post disable cl post image processor\n"
Yinhang Liue26b2622015-07-21 18:32:36 +0800329 "(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 +0800330#endif
Wind Yuan75564b12015-01-15 06:51:15 -0500331 , bin_name
332 , DEFAULT_SAVE_FILE_NAME);
333}
334
335int main (int argc, char *argv[])
336{
337 XCamReturn ret = XCAM_RETURN_NO_ERROR;
338 SmartPtr<MainDeviceManager> device_manager = new MainDeviceManager;
339 SmartPtr<V4l2Device> device;
340 SmartPtr<V4l2SubDevice> event_device;
341 SmartPtr<IspController> isp_controller;
342 SmartPtr<X3aAnalyzer> analyzer;
Yinhang Liu4afa3642016-05-13 19:13:07 +0800343 SmartPtr<SmartAnalyzer> smart_analyzer;
zongwave03954a32015-09-22 15:40:44 +0800344 SmartPtr<X3aAnalyzerLoader> loader;
Jia Meng9724cfe2015-08-12 15:04:45 +0800345 const char *path_of_3a;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800346 SmartPtr<ImageProcessor> isp_processor;
Wind Yuan26e9e212015-04-16 15:55:45 +0800347 AnalyzerType analyzer_type = AnalyzerTypeSimple;
wangfeicf4c4e72015-05-25 17:11:41 +0800348 DrmDisplayMode display_mode = DRM_DISPLAY_MODE_PRIMARY;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800349#if HAVE_LIBDRM
350 SmartPtr<DrmDisplay> drm_disp = DrmDisplay::instance();
351#endif
352
Wind Yuand4427312015-02-11 16:09:00 +0800353#if HAVE_LIBCL
Wind Yuane4ba0c92015-03-26 16:59:06 +0800354 SmartPtr<CL3aImageProcessor> cl_processor;
Yinhang Liu2ab1f992016-03-15 10:41:17 +0800355 SmartPtr<CLPostImageProcessor> cl_post_processor;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800356 uint32_t hdr_type = CL_HDR_DISABLE;
357 uint32_t tnr_type = CL_TNR_DISABLE;
358 uint32_t denoise_type = 0;
359 uint8_t tnr_level = 0;
360 bool dpc_type = false;
Wangfei1487b9b2015-08-28 15:10:39 +0800361 CL3aImageProcessor::PipelineProfile pipeline_mode = CL3aImageProcessor::BasicPipelineProfile;
wujunkai166a84ba052015-09-08 15:54:12 +0800362 CL3aImageProcessor::CaptureStage capture_stage = CL3aImageProcessor::TonemappingStage;
wujunkai16606f77622016-03-18 14:41:10 +0800363 CL3aImageProcessor::CLTonemappingMode wdr_mode = CL3aImageProcessor::WDRdisabled;
Wind Yuand4427312015-02-11 16:09:00 +0800364#endif
365 bool have_cl_processor = false;
Yinhang Liub0ad64b2016-03-18 16:03:51 +0800366 bool have_cl_post_processor = true;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800367 bool need_display = false;
Wind Yuand4427312015-02-11 16:09:00 +0800368 enum v4l2_memory v4l2_mem_type = V4L2_MEMORY_MMAP;
Wind Yuan75564b12015-01-15 06:51:15 -0500369 const char *bin_name = argv[0];
370 int opt;
ShincyTu2808b592015-03-13 17:17:25 +0800371 uint32_t capture_mode = V4L2_CAPTURE_MODE_VIDEO;
372 uint32_t pixel_format = V4L2_PIX_FMT_NV12;
Jia Menga6580232015-10-08 16:51:28 +0800373 bool wdr_type = false;
Wind Yuanf4e17ab2016-05-05 02:54:01 +0800374 uint32_t defog_type = 0;
zongwaveb7140442016-03-25 18:15:12 +0800375 CLWaveletBasis wavelet_mode = CL_WAVELET_DISABLED;
zongwave98d23202016-06-27 13:46:27 +0800376 uint32_t wavelet_channel = CL_IMAGE_CHANNEL_UV;
377 bool wavelet_bayes_shrink = false;
Yinhang Liu4ea70612016-05-26 18:26:29 +0800378 bool wireframe_type = false;
zongwaveb7140442016-03-25 18:15:12 +0800379
yaowang1a5f12122015-07-27 14:53:38 +0800380 int32_t brightness_level = 128;
Sameer Kibey7b429292015-08-07 10:55:38 -0700381 bool have_usbcam = 0;
Wind Yuan155c8f52016-03-18 23:16:59 +0800382 SmartPtr<char> usb_device_name;
Jia Meng8f94a102015-08-11 16:24:19 +0800383 bool sync_mode = false;
Jia Meng757f3c92015-09-09 11:18:36 +0800384 int frame_rate;
Yinhang Liud9346492015-12-17 11:14:25 +0800385 int frame_width = 1920;
386 int frame_height = 1080;
Wind Yuan155c8f52016-03-18 23:16:59 +0800387 SmartPtr<char> path_to_fake = NULL;
Wind Yuan75564b12015-01-15 06:51:15 -0500388
Jia Meng0a532932015-10-15 08:44:09 -0400389 const char *short_opts = "sca:n:m:f:d:b:pi:e:r:h";
Yinhang Liu81c44e02015-06-03 15:47:48 +0800390 const struct option long_opts[] = {
391 {"hdr", required_argument, NULL, 'H'},
392 {"tnr", required_argument, NULL, 'T'},
393 {"tnr-level", required_argument, NULL, 'L'},
wujunkai16606f77622016-03-18 14:41:10 +0800394 {"wdr-mode", required_argument, NULL, 'W'},
Yinhang Liub92930c2015-06-23 16:26:35 +0800395 {"bilateral", no_argument, NULL, 'I'},
Yinhang Liu81c44e02015-06-03 15:47:48 +0800396 {"enable-snr", no_argument, NULL, 'S'},
Jia Meng66efecf2015-06-17 11:11:10 +0000397 {"enable-ee", no_argument, NULL, 'E'},
ShincyTu63e2c262015-06-26 10:52:51 +0800398 {"enable-bnr", no_argument, NULL, 'B'},
Yinhang Liue26b2622015-07-21 18:32:36 +0800399 {"enable-dpc", no_argument, NULL, 'D'},
Wind Yuanf4e17ab2016-05-05 02:54:01 +0800400 {"defog-mode", required_argument, NULL, 'X'},
zongwave2ba7f642016-03-15 19:24:12 +0800401 {"wavelet-mode", required_argument, NULL, 'V'},
Yinhang Liu4ea70612016-05-26 18:26:29 +0800402 {"enable-wireframe", no_argument, NULL, 'F'},
Sameer Kibey7b429292015-08-07 10:55:38 -0700403 {"usb", required_argument, NULL, 'U'},
Yinhang Liud9346492015-12-17 11:14:25 +0800404 {"resolution", required_argument, NULL, 'R'},
Jia Meng8f94a102015-08-11 16:24:19 +0800405 {"sync", no_argument, NULL, 'Y'},
wujunkai166a84ba052015-09-08 15:54:12 +0800406 {"capture", required_argument, NULL, 'C'},
Wangfei1487b9b2015-08-28 15:10:39 +0800407 {"pipeline", required_argument, NULL, 'P'},
Yinhang Liub0ad64b2016-03-18 16:03:51 +0800408 {"disable-post", no_argument, NULL, 'O'},
Yinhang Liu81c44e02015-06-03 15:47:48 +0800409 {0, 0, 0, 0},
410 };
411
412 while ((opt = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
Wind Yuan75564b12015-01-15 06:51:15 -0500413 switch (opt) {
414 case 'a': {
Wind Yuan6b437392016-02-02 00:31:30 +0800415 XCAM_ASSERT (optarg);
Wind Yuane25ce3f2015-05-04 18:07:29 +0800416 if (!strcmp (optarg, "dynamic"))
417 analyzer_type = AnalyzerTypeDynamic;
418 else if (!strcmp (optarg, "simple"))
Wind Yuan26e9e212015-04-16 15:55:45 +0800419 analyzer_type = AnalyzerTypeSimple;
Wind Yuan75564b12015-01-15 06:51:15 -0500420#if HAVE_IA_AIQ
421 else if (!strcmp (optarg, "aiq"))
Yinhang Liu6c367352016-03-31 20:23:22 +0800422 analyzer_type = AnalyzerTypeAiqTuner;
Jia Meng9724cfe2015-08-12 15:04:45 +0800423 else if (!strcmp (optarg, "hybrid"))
424 analyzer_type = AnalyzerTypeHybrid;
Wind Yuan75564b12015-01-15 06:51:15 -0500425#endif
426 else {
427 print_help (bin_name);
428 return -1;
429 }
430 break;
431 }
432
Wind Yuand4427312015-02-11 16:09:00 +0800433 case 'm': {
Wind Yuan6b437392016-02-02 00:31:30 +0800434 XCAM_ASSERT (optarg);
Wind Yuand4427312015-02-11 16:09:00 +0800435 if (!strcmp (optarg, "dma"))
436 v4l2_mem_type = V4L2_MEMORY_DMABUF;
437 else if (!strcmp (optarg, "mmap"))
438 v4l2_mem_type = V4L2_MEMORY_MMAP;
439 else
440 print_help (bin_name);
441 break;
442 }
443
Wind Yuan75564b12015-01-15 06:51:15 -0500444 case 's':
445 device_manager->enable_save_file (true);
446 break;
447 case 'n':
Yinhang Liu1aa97602016-05-27 14:58:21 +0800448 XCAM_ASSERT (optarg);
Wind Yuan75564b12015-01-15 06:51:15 -0500449 device_manager->set_interval (atoi(optarg));
450 break;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800451#if HAVE_LIBCL
Wind Yuand4427312015-02-11 16:09:00 +0800452 case 'c':
453 have_cl_processor = true;
454 break;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800455#endif
ShincyTu2808b592015-03-13 17:17:25 +0800456 case 'f':
Yinhang Liu1aa97602016-05-27 14:58:21 +0800457 XCAM_ASSERT (optarg);
ShincyTuc8466402015-03-31 11:03:39 +0800458 CHECK_EXP ((strlen(optarg) == 4), "invalid pixel format\n");
459 pixel_format = v4l2_fourcc ((unsigned)optarg[0],
460 (unsigned)optarg[1],
461 (unsigned)optarg[2],
462 (unsigned)optarg[3]);
ShincyTu2808b592015-03-13 17:17:25 +0800463 break;
464 case 'd':
Wind Yuan6b437392016-02-02 00:31:30 +0800465 XCAM_ASSERT (optarg);
ShincyTu2808b592015-03-13 17:17:25 +0800466 if (!strcmp (optarg, "still"))
467 capture_mode = V4L2_CAPTURE_MODE_STILL;
468 else if (!strcmp (optarg, "video"))
469 capture_mode = V4L2_CAPTURE_MODE_VIDEO;
470 else {
471 print_help (bin_name);
472 return -1;
473 }
474 break;
yaowang1a5f12122015-07-27 14:53:38 +0800475 case 'b':
Yinhang Liu1aa97602016-05-27 14:58:21 +0800476 XCAM_ASSERT (optarg);
yaowang1a5f12122015-07-27 14:53:38 +0800477 brightness_level = atoi(optarg);
478 if(brightness_level < 0 || brightness_level > 256) {
479 print_help (bin_name);
480 return -1;
481 }
482 break;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800483 case 'p':
484 need_display = true;
485 break;
Sameer Kibey7b429292015-08-07 10:55:38 -0700486 case 'U':
Yinhang Liu1aa97602016-05-27 14:58:21 +0800487 XCAM_ASSERT (optarg);
Sameer Kibey7b429292015-08-07 10:55:38 -0700488 have_usbcam = true;
Wind Yuan155c8f52016-03-18 23:16:59 +0800489 usb_device_name = strndup(optarg, XCAM_MAX_STR_SIZE);
490 XCAM_LOG_DEBUG("using USB camera plugged in at node: %s", XCAM_STR(usb_device_name.ptr ()));
Sameer Kibey7b429292015-08-07 10:55:38 -0700491 break;
Yinhang Liud9346492015-12-17 11:14:25 +0800492 case 'R':
Wind Yuan6b437392016-02-02 00:31:30 +0800493 XCAM_ASSERT (optarg);
Yinhang Liud9346492015-12-17 11:14:25 +0800494 sscanf (optarg, "%d%*c%d", &frame_width, &frame_height);
495 break;
wangfeicf4c4e72015-05-25 17:11:41 +0800496 case 'e': {
Wind Yuan6b437392016-02-02 00:31:30 +0800497 XCAM_ASSERT (optarg);
wangfeicf4c4e72015-05-25 17:11:41 +0800498 if (!strcmp (optarg, "primary"))
499 display_mode = DRM_DISPLAY_MODE_PRIMARY;
500 else if (!strcmp (optarg, "overlay"))
501 display_mode = DRM_DISPLAY_MODE_OVERLAY;
502 else {
503 print_help (bin_name);
504 return -1;
505 }
506 break;
507 }
ShincyTue521cf92015-03-27 15:13:51 +0800508 case 'i':
Yinhang Liu1aa97602016-05-27 14:58:21 +0800509 XCAM_ASSERT (optarg);
ShincyTue521cf92015-03-27 15:13:51 +0800510 device_manager->set_frame_save(atoi(optarg));
511 break;
Jia Meng8f94a102015-08-11 16:24:19 +0800512 case 'Y':
513 sync_mode = true;
514 break;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800515#if HAVE_LIBCL
Yinhang Liu81c44e02015-06-03 15:47:48 +0800516 case 'H': {
Wind Yuan6b437392016-02-02 00:31:30 +0800517 XCAM_ASSERT (optarg);
Yinhang Liu81c44e02015-06-03 15:47:48 +0800518 if (!strcasecmp (optarg, "rgb"))
519 hdr_type = CL_HDR_TYPE_RGB;
520 else if (!strcasecmp (optarg, "lab"))
521 hdr_type = CL_HDR_TYPE_LAB;
522 else {
523 print_help (bin_name);
524 return -1;
525 }
526 break;
527 }
Yinhang Liub92930c2015-06-23 16:26:35 +0800528 case 'I': {
Jia Meng66efecf2015-06-17 11:11:10 +0000529 denoise_type |= XCAM_DENOISE_TYPE_BILATERAL;
Juan Zhaod9664932015-09-08 10:22:19 +0800530 denoise_type |= XCAM_DENOISE_TYPE_BIYUV;
Yinhang Liu81c44e02015-06-03 15:47:48 +0800531 break;
532 }
533 case 'S': {
Jia Meng66efecf2015-06-17 11:11:10 +0000534 denoise_type |= XCAM_DENOISE_TYPE_SIMPLE;
535 break;
536 }
537 case 'E': {
538 denoise_type |= XCAM_DENOISE_TYPE_EE;
Yinhang Liu81c44e02015-06-03 15:47:48 +0800539 break;
540 }
ShincyTu63e2c262015-06-26 10:52:51 +0800541 case 'B': {
542 denoise_type |= XCAM_DENOISE_TYPE_BNR;
543 break;
544 }
Wangfei8e5e3e42016-02-18 19:41:54 +0800545 case 'X': {
Wind Yuanf4e17ab2016-05-05 02:54:01 +0800546 XCAM_ASSERT (optarg);
547 defog_type = true;
548 if (!strcmp (optarg, "disabled"))
549 defog_type = CLPostImageProcessor::DefogDisabled;
550 else if (!strcmp (optarg, "retinex"))
551 defog_type = CLPostImageProcessor::DefogRetinex;
552 else if (!strcmp (optarg, "dcp"))
553 defog_type = CLPostImageProcessor::DefogDarkChannelPrior;
554 else {
555 print_help (bin_name);
556 return -1;
557 }
Wangfei8e5e3e42016-02-18 19:41:54 +0800558 break;
559 }
zongwave80adcf52016-02-29 12:38:06 +0800560 case 'V': {
zongwave2ba7f642016-03-15 19:24:12 +0800561 XCAM_ASSERT (optarg);
562 if (atoi(optarg) < 0 || atoi(optarg) > 255) {
563 print_help (bin_name);
564 return -1;
565 }
zongwave28a747b2016-03-17 12:49:08 +0800566 if (atoi(optarg) == 1) {
zongwaveb7140442016-03-25 18:15:12 +0800567 wavelet_mode = CL_WAVELET_HAT;
zongwave98d23202016-06-27 13:46:27 +0800568 wavelet_channel = CL_IMAGE_CHANNEL_Y;
zongwave28a747b2016-03-17 12:49:08 +0800569 } else if (atoi(optarg) == 2) {
zongwaveb7140442016-03-25 18:15:12 +0800570 wavelet_mode = CL_WAVELET_HAT;
zongwave98d23202016-06-27 13:46:27 +0800571 wavelet_channel = CL_IMAGE_CHANNEL_UV;
zongwaveb7140442016-03-25 18:15:12 +0800572 } else if (atoi(optarg) == 3) {
573 wavelet_mode = CL_WAVELET_HAAR;
zongwave98d23202016-06-27 13:46:27 +0800574 wavelet_channel = CL_IMAGE_CHANNEL_Y;
zongwaveb7140442016-03-25 18:15:12 +0800575 } else if (atoi(optarg) == 4) {
576 wavelet_mode = CL_WAVELET_HAAR;
zongwave98d23202016-06-27 13:46:27 +0800577 wavelet_channel = CL_IMAGE_CHANNEL_UV;
zongwaveb7140442016-03-25 18:15:12 +0800578 } else if (atoi(optarg) == 5) {
579 wavelet_mode = CL_WAVELET_HAAR;
zongwave98d23202016-06-27 13:46:27 +0800580 wavelet_channel = CL_IMAGE_CHANNEL_UV | CL_IMAGE_CHANNEL_Y;
581 } else if (atoi(optarg) == 6) {
582 wavelet_mode = CL_WAVELET_HAAR;
583 wavelet_channel = CL_IMAGE_CHANNEL_UV | CL_IMAGE_CHANNEL_Y;
584 wavelet_bayes_shrink = true;
zongwave28a747b2016-03-17 12:49:08 +0800585 } else {
zongwaveb7140442016-03-25 18:15:12 +0800586 wavelet_mode = CL_WAVELET_DISABLED;
zongwave28a747b2016-03-17 12:49:08 +0800587 }
zongwave80adcf52016-02-29 12:38:06 +0800588 break;
589 }
Yinhang Liu4ea70612016-05-26 18:26:29 +0800590 case 'F': {
591 wireframe_type = true;
592 break;
593 }
Yinhang Liue26b2622015-07-21 18:32:36 +0800594 case 'D': {
595 dpc_type = true;
596 break;
597 }
Yinhang Liu81c44e02015-06-03 15:47:48 +0800598 case 'T': {
Wind Yuan6b437392016-02-02 00:31:30 +0800599 XCAM_ASSERT (optarg);
Yinhang Liu81c44e02015-06-03 15:47:48 +0800600 if (!strcasecmp (optarg, "yuv"))
601 tnr_type = CL_TNR_TYPE_YUV;
602 else if (!strcasecmp (optarg, "rgb"))
603 tnr_type = CL_TNR_TYPE_RGB;
604 else if (!strcasecmp (optarg, "both"))
605 tnr_type = CL_TNR_TYPE_YUV | CL_TNR_TYPE_RGB;
606 else {
607 print_help (bin_name);
608 return -1;
609 }
610 break;
611 }
612 case 'L': {
Wind Yuan6b437392016-02-02 00:31:30 +0800613 XCAM_ASSERT (optarg);
Yinhang Liu81c44e02015-06-03 15:47:48 +0800614 if (atoi(optarg) < 0 || atoi(optarg) > 255) {
615 print_help (bin_name);
616 return -1;
617 }
618 tnr_level = atoi(optarg);
619 break;
620 }
Jia Menga6580232015-10-08 16:51:28 +0800621 case 'W': {
wujunkai16606f77622016-03-18 14:41:10 +0800622 XCAM_ASSERT (optarg);
623 if (!strcasecmp (optarg, "gaussian"))
624 wdr_mode = CL3aImageProcessor::Gaussian;
625 else if (!strcasecmp (optarg, "haleq"))
626 wdr_mode = CL3aImageProcessor::Haleq;
wujunkai16682950fb2015-10-19 18:09:05 +0800627
wujunkai166b0bd5512016-02-18 18:25:42 +0800628 pixel_format = V4L2_PIX_FMT_SGRBG12;
wujunkai16606f77622016-03-18 14:41:10 +0800629 wdr_type = true;
wujunkai166b0bd5512016-02-18 18:25:42 +0800630 setenv ("AIQ_CPF_PATH", IMX185_WDR_CPF, 1);
631 break;
632 }
Wangfei1487b9b2015-08-28 15:10:39 +0800633 case 'P': {
Wind Yuan6b437392016-02-02 00:31:30 +0800634 XCAM_ASSERT (optarg);
Wangfei1487b9b2015-08-28 15:10:39 +0800635 if (!strcasecmp (optarg, "basic"))
636 pipeline_mode = CL3aImageProcessor::BasicPipelineProfile;
637 else if (!strcasecmp (optarg, "advance"))
638 pipeline_mode = CL3aImageProcessor::AdvancedPipelineProfile;
Wangfei16b65db2015-09-11 14:44:28 +0800639 else if (!strcasecmp (optarg, "extreme"))
640 pipeline_mode = CL3aImageProcessor::ExtremePipelineProfile;
Wangfei1487b9b2015-08-28 15:10:39 +0800641 else {
642 print_help (bin_name);
643 return -1;
644 }
645 break;
646 }
wujunkai166a84ba052015-09-08 15:54:12 +0800647 case 'C': {
Wind Yuan6b437392016-02-02 00:31:30 +0800648 XCAM_ASSERT (optarg);
wujunkai166a84ba052015-09-08 15:54:12 +0800649 if (!strcmp (optarg, "bayer"))
650 capture_stage = CL3aImageProcessor::BasicbayerStage;
651 break;
652 }
Yinhang Liub0ad64b2016-03-18 16:03:51 +0800653 case 'O': {
654 have_cl_post_processor = false;
655 break;
656 }
Yinhang Liuc2f19082015-08-28 12:27:48 +0800657#endif
Jia Meng0a532932015-10-15 08:44:09 -0400658 case 'r': {
Yinhang Liu1aa97602016-05-27 14:58:21 +0800659 XCAM_ASSERT (optarg);
660 XCAM_LOG_INFO ("use raw image %s as input source", optarg);
661 path_to_fake = strndup(optarg, XCAM_MAX_STR_SIZE);
Jia Meng0a532932015-10-15 08:44:09 -0400662 break;
663 }
Wind Yuan75564b12015-01-15 06:51:15 -0500664 case 'h':
665 print_help (bin_name);
666 return 0;
667
668 default:
669 print_help (bin_name);
670 return -1;
671 }
672 }
673
Yinhang Liud9346492015-12-17 11:14:25 +0800674 device_manager->set_frame_width(frame_width);
675 device_manager->set_frame_height(frame_height);
wangfeicf4c4e72015-05-25 17:11:41 +0800676 if (need_display) {
Wind Yuan683f8662015-03-27 18:52:38 +0800677 device_manager->enable_display (true);
wangfeicf4c4e72015-05-25 17:11:41 +0800678 device_manager->set_display_mode (display_mode);
679 }
ShincyTu2808b592015-03-13 17:17:25 +0800680 if (!device.ptr ()) {
Wind Yuan155c8f52016-03-18 23:16:59 +0800681 if (path_to_fake.ptr ()) {
Jia Meng0a532932015-10-15 08:44:09 -0400682 device = new FakeV4l2Device ();
683 } else if (have_usbcam) {
Wind Yuan155c8f52016-03-18 23:16:59 +0800684 device = new UVCDevice (usb_device_name.ptr ());
Sameer Kibey7b429292015-08-07 10:55:38 -0700685 } else {
686 if (capture_mode == V4L2_CAPTURE_MODE_STILL)
687 device = new AtomispDevice (CAPTURE_DEVICE_STILL);
688 else if (capture_mode == V4L2_CAPTURE_MODE_VIDEO)
689 device = new AtomispDevice (CAPTURE_DEVICE_VIDEO);
690 else
691 device = new AtomispDevice (DEFAULT_CAPTURE_DEVICE);
692 }
ShincyTu2808b592015-03-13 17:17:25 +0800693 }
Wind Yuan75564b12015-01-15 06:51:15 -0500694 if (!event_device.ptr ())
695 event_device = new V4l2SubDevice (DEFAULT_EVENT_DEVICE);
696 if (!isp_controller.ptr ())
697 isp_controller = new IspController (device);
Wind Yuan26e9e212015-04-16 15:55:45 +0800698
699 switch (analyzer_type) {
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800700 case AnalyzerTypeSimple:
701 analyzer = new X3aAnalyzerSimple ();
702 break;
Wind Yuan26e9e212015-04-16 15:55:45 +0800703#if HAVE_IA_AIQ
Yinhang Liu6c367352016-03-31 20:23:22 +0800704 case AnalyzerTypeAiqTuner: {
705 SmartPtr<X3aAnalyzer> aiq_analyzer = new X3aAnalyzerAiq (isp_controller, DEFAULT_CPF_FILE);
706 SmartPtr<X3aAnalyzeTuner> tuner_analyzer = new X3aAnalyzeTuner ();
707 XCAM_ASSERT (aiq_analyzer.ptr () && tuner_analyzer.ptr ());
708 tuner_analyzer->set_analyzer (aiq_analyzer);
709 analyzer = tuner_analyzer;
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800710 break;
Yinhang Liu6c367352016-03-31 20:23:22 +0800711 }
Jia Meng9724cfe2015-08-12 15:04:45 +0800712 case AnalyzerTypeHybrid: {
Jia Mengc54c3322015-08-26 09:45:18 +0800713 path_of_3a = DEFAULT_HYBRID_3A_LIB;
zongwave03954a32015-09-22 15:40:44 +0800714 loader = new X3aAnalyzerLoader (path_of_3a);
Jia Meng9724cfe2015-08-12 15:04:45 +0800715 analyzer = loader->load_hybrid_analyzer (loader, isp_controller, DEFAULT_CPF_FILE);
716 CHECK_EXP (analyzer.ptr (), "load hybrid 3a lib(%s) failed", path_of_3a);
717 break;
718 }
Wind Yuan26e9e212015-04-16 15:55:45 +0800719#endif
Wind Yuane25ce3f2015-05-04 18:07:29 +0800720 case AnalyzerTypeDynamic: {
Jia Meng9724cfe2015-08-12 15:04:45 +0800721 path_of_3a = DEFAULT_DYNAMIC_3A_LIB;
zongwave03954a32015-09-22 15:40:44 +0800722 loader = new X3aAnalyzerLoader (path_of_3a);
Jia Meng9724cfe2015-08-12 15:04:45 +0800723 analyzer = loader->load_dynamic_analyzer (loader);
Wind Yuane25ce3f2015-05-04 18:07:29 +0800724 CHECK_EXP (analyzer.ptr (), "load dynamic 3a lib(%s) failed", path_of_3a);
Yinhang Liu4afa3642016-05-13 19:13:07 +0800725
726 // Create smart analyzer from dynamic libraries
727 SmartHandlerList smart_handlers = SmartAnalyzerLoader::load_smart_handlers (DEFAULT_SMART_ANALYSIS_LIB_DIR);
728 if (!smart_handlers.empty () ) {
729 smart_analyzer = new SmartAnalyzer ();
730 if (!smart_analyzer.ptr ()) {
731 XCAM_LOG_INFO ("load smart analyzer(%s) failed", DEFAULT_SMART_ANALYSIS_LIB_DIR);
732 break;
733 }
734 SmartHandlerList::iterator i_handler = smart_handlers.begin ();
735 for (; i_handler != smart_handlers.end (); ++i_handler) {
736 XCAM_ASSERT ((*i_handler).ptr ());
737 smart_analyzer->add_handler (*i_handler);
738 }
739 }
Wind Yuane25ce3f2015-05-04 18:07:29 +0800740 break;
741 }
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800742 default:
743 print_help (bin_name);
744 return -1;
Wind Yuan26e9e212015-04-16 15:55:45 +0800745 }
Jia Meng8f94a102015-08-11 16:24:19 +0800746 XCAM_ASSERT (analyzer.ptr ());
747 analyzer->set_sync_mode (sync_mode);
Wind Yuan75564b12015-01-15 06:51:15 -0500748
749 signal(SIGINT, dev_stop_handler);
750
751 device->set_sensor_id (0);
ShincyTu2808b592015-03-13 17:17:25 +0800752 device->set_capture_mode (capture_mode);
Wind Yuan75564b12015-01-15 06:51:15 -0500753 //device->set_mem_type (V4L2_MEMORY_DMABUF);
Wind Yuand4427312015-02-11 16:09:00 +0800754 device->set_mem_type (v4l2_mem_type);
Wind Yuan75564b12015-01-15 06:51:15 -0500755 device->set_buffer_count (8);
Jia Meng757f3c92015-09-09 11:18:36 +0800756 if (pixel_format == V4L2_PIX_FMT_SGRBG12) {
757 frame_rate = 30;
758 device->set_framerate (frame_rate, 1);
759 }
760 else {
761 frame_rate = 25;
762 device->set_framerate (frame_rate, 1);
wujunkai16606f77622016-03-18 14:41:10 +0800763 if(wdr_type == true) {
wujunkai166a9a55f22015-10-10 15:53:32 +0800764 XCAM_LOG_WARNING("Tonemapping is only applicable under BA12 format. Disable tonemapping automatically.");
wujunkai16606f77622016-03-18 14:41:10 +0800765 wdr_type = false;
wujunkai166a9a55f22015-10-10 15:53:32 +0800766 }
Jia Meng757f3c92015-09-09 11:18:36 +0800767 }
Wind Yuan75564b12015-01-15 06:51:15 -0500768 ret = device->open ();
769 CHECK (ret, "device(%s) open failed", device->get_device_name());
Yinhang Liud9346492015-12-17 11:14:25 +0800770 ret = device->set_format (frame_width, frame_height, pixel_format, V4L2_FIELD_NONE, frame_width * 2);
Wind Yuan75564b12015-01-15 06:51:15 -0500771 CHECK (ret, "device(%s) set format failed", device->get_device_name());
772
773 ret = event_device->open ();
Wind Yuanb67045c2015-08-27 13:50:53 +0800774 if (ret == XCAM_RETURN_NO_ERROR) {
775 CHECK (ret, "event device(%s) open failed", event_device->get_device_name());
776 int event = V4L2_EVENT_ATOMISP_3A_STATS_READY;
777 ret = event_device->subscribe_event (event);
778 CHECK_CONTINUE (
779 ret,
780 "device(%s) subscribe event(%d) failed",
781 event_device->get_device_name(), event);
782 event = V4L2_EVENT_FRAME_SYNC;
783 ret = event_device->subscribe_event (event);
784 CHECK_CONTINUE (
785 ret,
786 "device(%s) subscribe event(%d) failed",
787 event_device->get_device_name(), event);
788
789 device_manager->set_event_device (event_device);
790 }
Wind Yuan75564b12015-01-15 06:51:15 -0500791
792 device_manager->set_capture_device (device);
Wind Yuan75564b12015-01-15 06:51:15 -0500793 device_manager->set_isp_controller (isp_controller);
794 if (analyzer.ptr())
zongwave03954a32015-09-22 15:40:44 +0800795 device_manager->set_3a_analyzer (analyzer);
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800796
Yinhang Liu4afa3642016-05-13 19:13:07 +0800797 if (smart_analyzer.ptr ()) {
798 if (smart_analyzer->prepare_handlers () != XCAM_RETURN_NO_ERROR) {
799 XCAM_LOG_WARNING ("analyzer(%s) prepare handlers failed", smart_analyzer->get_name ());
800 }
801 device_manager->set_smart_analyzer (smart_analyzer);
802 }
803
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800804 if (have_cl_processor)
805 isp_processor = new IspExposureImageProcessor (isp_controller);
806 else
807 isp_processor = new IspImageProcessor (isp_controller);
808
809 XCAM_ASSERT (isp_processor.ptr ());
Wind Yuane4ba0c92015-03-26 16:59:06 +0800810 device_manager->add_image_processor (isp_processor);
Yinhang Liuc2f19082015-08-28 12:27:48 +0800811#if HAVE_LIBCL
Wind Yuand4427312015-02-11 16:09:00 +0800812 if (have_cl_processor) {
Wind Yuane4ba0c92015-03-26 16:59:06 +0800813 cl_processor = new CL3aImageProcessor ();
Wind Yuan7ddf2602015-04-14 18:49:45 +0800814 cl_processor->set_stats_callback(device_manager);
Yinhang Liue26b2622015-07-21 18:32:36 +0800815 cl_processor->set_dpc(dpc_type);
Yinhang Liu81c44e02015-06-03 15:47:48 +0800816 cl_processor->set_hdr (hdr_type);
Jia Meng66efecf2015-06-17 11:11:10 +0000817 cl_processor->set_denoise (denoise_type);
wujunkai16606f77622016-03-18 14:41:10 +0800818 cl_processor->set_tonemapping(wdr_mode);
Jia Menga6580232015-10-08 16:51:28 +0800819 cl_processor->set_gamma (!wdr_type); // disable gamma for WDR
zongwave98d23202016-06-27 13:46:27 +0800820 cl_processor->set_wavelet (wavelet_mode, wavelet_channel, wavelet_bayes_shrink);
Yinhang Liu4ea70612016-05-26 18:26:29 +0800821 cl_processor->set_wireframe (wireframe_type);
wujunkai166a84ba052015-09-08 15:54:12 +0800822 cl_processor->set_capture_stage (capture_stage);
wujunkai166c8f3b442016-02-29 17:12:09 +0800823
824 if (wdr_type) {
825 cl_processor->set_3a_stats_bits(12);
826 }
Yinhang Liu81c44e02015-06-03 15:47:48 +0800827 cl_processor->set_tnr (tnr_type, tnr_level);
Wangfei1487b9b2015-08-28 15:10:39 +0800828 cl_processor->set_profile (pipeline_mode);
yaowang1a5f12122015-07-27 14:53:38 +0800829 analyzer->set_parameter_brightness((brightness_level - 128) / 128.0);
Wind Yuand4427312015-02-11 16:09:00 +0800830 device_manager->add_image_processor (cl_processor);
Yinhang Liu4afa3642016-05-13 19:13:07 +0800831
832 if (smart_analyzer.ptr ()) {
833 cl_processor->set_scaler (true);
834 cl_processor->set_scaler_factor (640.0 / frame_width);
835 }
Wind Yuand4427312015-02-11 16:09:00 +0800836 }
Yinhang Liu3c17fea2016-03-15 10:47:03 +0800837
Yinhang Liub0ad64b2016-03-18 16:03:51 +0800838 if (have_cl_post_processor) {
839 cl_post_processor = new CLPostImageProcessor ();
Yinhang Liu3c721c12016-03-15 15:03:51 +0800840
Wind Yuanf4e17ab2016-05-05 02:54:01 +0800841 cl_post_processor->set_defog_mode ((CLPostImageProcessor::CLDefogMode)defog_type);
Yinhang Liu3c721c12016-03-15 15:03:51 +0800842
Yinhang Liud6d824a2016-03-22 20:43:00 +0800843 if (need_display) {
Yinhang Liub0ad64b2016-03-18 16:03:51 +0800844 cl_post_processor->set_output_format (V4L2_PIX_FMT_XBGR32);
845 }
846 device_manager->add_image_processor (cl_post_processor);
Yinhang Liu3c17fea2016-03-15 10:47:03 +0800847 }
Wind Yuand4427312015-02-11 16:09:00 +0800848#endif
Wind Yuane4ba0c92015-03-26 16:59:06 +0800849
Jia Meng0a532932015-10-15 08:44:09 -0400850 SmartPtr<PollThread> poll_thread;
Wind Yuan155c8f52016-03-18 23:16:59 +0800851 if (path_to_fake.ptr ())
852 poll_thread = new FakePollThread (path_to_fake.ptr ());
Jia Meng0a532932015-10-15 08:44:09 -0400853 else
854 poll_thread = new PollThread ();
855 device_manager->set_poll_thread (poll_thread);
856
Wind Yuan75564b12015-01-15 06:51:15 -0500857 ret = device_manager->start ();
858 CHECK (ret, "device manager start failed");
859
Jia Meng757f3c92015-09-09 11:18:36 +0800860 // hard code exposure range and max gain for imx185 WDR
Jia Menga6580232015-10-08 16:51:28 +0800861 if (wdr_type) {
Jia Meng757f3c92015-09-09 11:18:36 +0800862 if (frame_rate == 30)
863 analyzer->set_ae_exposure_time_range (80 * 1110 * 1000 / 37125, 1120 * 1110 * 1000 / 37125);
864 else
Jia Menga6580232015-10-08 16:51:28 +0800865 analyzer->set_ae_exposure_time_range (80 * 1320 * 1000 / 37125, 1120 * 1320 * 1000 / 37125);
Jia Meng757f3c92015-09-09 11:18:36 +0800866 analyzer->set_ae_max_analog_gain (3.98); // 12dB
867 }
868
Wind Yuan75564b12015-01-15 06:51:15 -0500869 // wait for interruption
870 {
871 SmartLock locker (g_mutex);
872 while (!g_stop)
873 g_cond.wait (g_mutex);
874 }
875
876 ret = device_manager->stop();
877 CHECK_CONTINUE (ret, "device manager stop failed");
878 device->close ();
879 event_device->close ();
Wind Yuan75564b12015-01-15 06:51:15 -0500880
881 return 0;
882}