blob: 52b7756ab2a6c85e9def1c4a592cda81b193b2f4 [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>
Wind Yuan136aa4f2016-09-08 02:56:31 -040019 * Author: Yinhang Liu <yinhangx.liu@intel.com>
20 * Author: Wei Zong <wei.zong@intel.com>
Wind Yuan75564b12015-01-15 06:51:15 -050021 */
22
23#include "device_manager.h"
Sameer Kibey7b429292015-08-07 10:55:38 -070024#include "uvc_device.h"
Jia Meng0a532932015-10-15 08:44:09 -040025#include "fake_v4l2_device.h"
Wind Yuan75564b12015-01-15 06:51:15 -050026#include "x3a_analyzer_simple.h"
Yinhang Liue37a8722016-06-27 18:14:35 +080027#include "analyzer_loader.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
Yinhang Liu7110f892017-06-30 13:11:10 +080030#include "isp/atomisp_device.h"
31#include "isp/isp_controller.h"
32#include "isp/isp_image_processor.h"
33#include "isp/isp_poll_thread.h"
34#include "isp/x3a_analyzer_aiq.h"
Yinhang Liu6c367352016-03-31 20:23:22 +080035#include "x3a_analyze_tuner.h"
Yinhang Liu454a3892016-11-07 16:30:35 +080036#include "dynamic_analyzer_loader.h"
Yinhang Liu7110f892017-06-30 13:11:10 +080037#include "isp/hybrid_analyzer_loader.h"
Wind Yuan75564b12015-01-15 06:51:15 -050038#endif
Wind Yuand4427312015-02-11 16:09:00 +080039#if HAVE_LIBCL
Yinhang Liu7110f892017-06-30 13:11:10 +080040#include "ocl/cl_3a_image_processor.h"
41#include "ocl/cl_post_image_processor.h"
42#include "ocl/cl_csc_image_processor.h"
43#include "ocl/cl_tnr_handler.h"
Wind Yuane4ba0c92015-03-26 16:59:06 +080044#endif
45#if HAVE_LIBDRM
46#include "drm_display.h"
Wind Yuand4427312015-02-11 16:09:00 +080047#endif
Jia Meng0a532932015-10-15 08:44:09 -040048#include "fake_poll_thread.h"
Wind Yuan136aa4f2016-09-08 02:56:31 -040049#include "image_file_handle.h"
Jia Meng66efecf2015-06-17 11:11:10 +000050#include <base/xcam_3a_types.h>
Wind Yuan75564b12015-01-15 06:51:15 -050051#include <unistd.h>
52#include <signal.h>
53#include <stdlib.h>
ShincyTue521cf92015-03-27 15:13:51 +080054#include <string>
Yinhang Liu81c44e02015-06-03 15:47:48 +080055#include <getopt.h>
John Yeae9da732015-01-22 13:36:36 +080056#include "test_common.h"
57
Wind Yuan75564b12015-01-15 06:51:15 -050058using namespace XCam;
59
wujunkai16682950fb2015-10-19 18:09:05 +080060#define IMX185_WDR_CPF "/etc/atomisp/imx185_wdr.cpf"
61
ShincyTue521cf92015-03-27 15:13:51 +080062static Mutex g_mutex;
63static Cond g_cond;
64static bool g_stop = false;
65
Wind Yuan75564b12015-01-15 06:51:15 -050066class MainDeviceManager
67 : public DeviceManager
68{
69public:
70 MainDeviceManager ()
Wind Yuan136aa4f2016-09-08 02:56:31 -040071 : _save_file (false)
Wind Yuan75564b12015-01-15 06:51:15 -050072 , _interval (1)
Yinhang Liud9346492015-12-17 11:14:25 +080073 , _frame_width (0)
74 , _frame_height (0)
Wind Yuan75564b12015-01-15 06:51:15 -050075 , _frame_count (0)
ShincyTue521cf92015-03-27 15:13:51 +080076 , _frame_save (0)
Wind Yuan683f8662015-03-27 18:52:38 +080077 , _enable_display (false)
Wind Yuane4ba0c92015-03-26 16:59:06 +080078 {
79#if HAVE_LIBDRM
Yinhang Liu5855e6f2016-11-14 21:04:22 +080080 _display = DrmDisplay::instance ();
Wind Yuane4ba0c92015-03-26 16:59:06 +080081#endif
Wind Yuan91625802015-06-24 15:36:01 +080082 XCAM_OBJ_PROFILING_INIT;
Wind Yuane4ba0c92015-03-26 16:59:06 +080083 }
Wind Yuan75564b12015-01-15 06:51:15 -050084
85 ~MainDeviceManager () {
Wind Yuan136aa4f2016-09-08 02:56:31 -040086 _file_handle.close ();
Wind Yuan75564b12015-01-15 06:51:15 -050087 }
88
89 void enable_save_file (bool enable) {
90 _save_file = enable;
91 }
Yinhang Liud9346492015-12-17 11:14:25 +080092
Wind Yuan75564b12015-01-15 06:51:15 -050093 void set_interval (uint32_t inteval) {
94 _interval = inteval;
95 }
Yinhang Liud9346492015-12-17 11:14:25 +080096
97 void set_frame_width (uint32_t frame_width) {
98 _frame_width = frame_width;
99 }
100
101 void set_frame_height (uint32_t frame_height) {
102 _frame_height = frame_height;
103 }
104
ShincyTue521cf92015-03-27 15:13:51 +0800105 void set_frame_save (uint32_t frame_save) {
106 _frame_save = frame_save;
107 }
Wind Yuan75564b12015-01-15 06:51:15 -0500108
Wind Yuan683f8662015-03-27 18:52:38 +0800109 void enable_display(bool value) {
110 _enable_display = value;
111 }
112
wangfeicf4c4e72015-05-25 17:11:41 +0800113 void set_display_mode(DrmDisplayMode mode) {
114 _display->set_display_mode (mode);
115 }
116
Wind Yuan75564b12015-01-15 06:51:15 -0500117protected:
Wind Yuan73af3932015-07-02 17:52:43 +0800118 virtual void handle_message (const SmartPtr<XCamMessage> &msg);
119 virtual void handle_buffer (const SmartPtr<VideoBuffer> &buf);
Wind Yuan75564b12015-01-15 06:51:15 -0500120
Wind Yuan73af3932015-07-02 17:52:43 +0800121 int display_buf (const SmartPtr<VideoBuffer> &buf);
Wind Yuane4ba0c92015-03-26 16:59:06 +0800122
Wind Yuan75564b12015-01-15 06:51:15 -0500123private:
124 void open_file ();
Wind Yuan75564b12015-01-15 06:51:15 -0500125
Wind Yuan136aa4f2016-09-08 02:56:31 -0400126private:
Wind Yuan75564b12015-01-15 06:51:15 -0500127 bool _save_file;
128 uint32_t _interval;
Yinhang Liud9346492015-12-17 11:14:25 +0800129 uint32_t _frame_width;
130 uint32_t _frame_height;
Wind Yuan75564b12015-01-15 06:51:15 -0500131 uint32_t _frame_count;
ShincyTue521cf92015-03-27 15:13:51 +0800132 uint32_t _frame_save;
Yinhang Liu5855e6f2016-11-14 21:04:22 +0800133 bool _enable_display;
Wind Yuan136aa4f2016-09-08 02:56:31 -0400134 ImageFileHandle _file_handle;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800135 SmartPtr<DrmDisplay> _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 Yuan6d144ce2017-08-16 18:29:29 +0800148 if (!buf.ptr ()) {
149 XCAM_LOG_WARNING ("video buffer is null, handle buffer failed.");
150 return;
151 }
152
Wind Yuan683f8662015-03-27 18:52:38 +0800153 FPS_CALCULATION (fps_buf, 30);
Wind Yuan91625802015-06-24 15:36:01 +0800154 XCAM_OBJ_PROFILING_START;
155
Wind Yuan683f8662015-03-27 18:52:38 +0800156 if (_enable_display)
157 display_buf (buf);
Wind Yuane4ba0c92015-03-26 16:59:06 +0800158
Yinhang Liu070c7592017-04-13 19:22:17 +0800159 XCAM_OBJ_PROFILING_END("main_dev_manager_display", XCAM_OBJ_DUR_FRAME_NUM);
Wind Yuan91625802015-06-24 15:36:01 +0800160
Wind Yuan75564b12015-01-15 06:51:15 -0500161 if (!_save_file)
162 return ;
163
164 if ((_frame_count++ % _interval) != 0)
165 return;
166
ShincyTue521cf92015-03-27 15:13:51 +0800167 if ((_frame_save != 0) && (_frame_count > _frame_save)) {
168 SmartLock locker (g_mutex);
169 g_stop = true;
170 g_cond.broadcast ();
171 return;
172 }
173
Wind Yuan75564b12015-01-15 06:51:15 -0500174 open_file ();
Jia Meng6c9241d2015-06-12 11:08:45 +0000175
Wind Yuan136aa4f2016-09-08 02:56:31 -0400176 if (!_file_handle.is_valid ()) {
Jia Meng6c9241d2015-06-12 11:08:45 +0000177 XCAM_LOG_ERROR ("open file failed");
Jia Meng54a2dcb2015-08-20 15:23:47 +0800178 return;
Jia Meng6c9241d2015-06-12 11:08:45 +0000179 }
Wind Yuan6d144ce2017-08-16 18:29:29 +0800180 _file_handle.write_buf (buf);
Wind Yuan75564b12015-01-15 06:51:15 -0500181}
182
Wind Yuane4ba0c92015-03-26 16:59:06 +0800183int
Wind Yuan73af3932015-07-02 17:52:43 +0800184MainDeviceManager::display_buf (const SmartPtr<VideoBuffer> &data)
Wind Yuane4ba0c92015-03-26 16:59:06 +0800185{
186#if HAVE_LIBDRM
187 XCamReturn ret = XCAM_RETURN_NO_ERROR;
Wind Yuan73af3932015-07-02 17:52:43 +0800188 SmartPtr<VideoBuffer> buf = data;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800189 const VideoBufferInfo & frame_info = buf->get_video_info ();
Yinhang Liuaadb8ba2016-11-18 18:43:29 +0800190 struct v4l2_rect rect = { 0, 0, frame_info.width, frame_info.height};
Wind Yuane4ba0c92015-03-26 16:59:06 +0800191
192 if (!_display->is_render_inited ()) {
Yinhang Liud9346492015-12-17 11:14:25 +0800193 ret = _display->render_init (0, 0, this->_frame_width, this->_frame_height,
194 frame_info.format, &rect);
Wind Yuane4ba0c92015-03-26 16:59:06 +0800195 CHECK (ret, "display failed on render_init");
196 }
197 ret = _display->render_setup_frame_buffer (buf);
198 CHECK (ret, "display failed on framebuf set");
199 ret = _display->render_buffer (buf);
200 CHECK (ret, "display failed on rendering");
201#endif
202 return 0;
203}
204
205
Wind Yuan75564b12015-01-15 06:51:15 -0500206void
207MainDeviceManager::open_file ()
208{
Wind Yuan136aa4f2016-09-08 02:56:31 -0400209 if (_file_handle.is_valid () && (_frame_save == 0))
Wind Yuan75564b12015-01-15 06:51:15 -0500210 return;
ShincyTue521cf92015-03-27 15:13:51 +0800211
212 std::string file_name = DEFAULT_SAVE_FILE_NAME;
213
214 if (_frame_save != 0) {
215 file_name += std::to_string(_frame_count);
216 }
217 file_name += ".raw";
218
Wind Yuan136aa4f2016-09-08 02:56:31 -0400219 if (_file_handle.open (file_name.c_str (), "wb") != XCAM_RETURN_NO_ERROR) {
220 XCAM_LOG_WARNING ("create file(%s) failed", file_name.c_str ());
Wind Yuan71111322016-02-24 22:56:27 +0800221 }
Wind Yuan71111322016-02-24 22:56:27 +0800222}
223
Wind Yuan75564b12015-01-15 06:51:15 -0500224#define V4L2_CAPTURE_MODE_STILL 0x2000
225#define V4L2_CAPTURE_MODE_VIDEO 0x4000
226#define V4L2_CAPTURE_MODE_PREVIEW 0x8000
227
Wind Yuan26e9e212015-04-16 15:55:45 +0800228typedef enum {
229 AnalyzerTypeSimple = 0,
Yinhang Liu6c367352016-03-31 20:23:22 +0800230 AnalyzerTypeAiqTuner,
Wind Yuane25ce3f2015-05-04 18:07:29 +0800231 AnalyzerTypeDynamic,
Jia Meng9724cfe2015-08-12 15:04:45 +0800232 AnalyzerTypeHybrid,
Wind Yuan26e9e212015-04-16 15:55:45 +0800233} AnalyzerType;
234
Wind Yuan75564b12015-01-15 06:51:15 -0500235void dev_stop_handler(int sig)
236{
237 XCAM_UNUSED (sig);
238
239 SmartLock locker (g_mutex);
240 g_stop = true;
241 g_cond.broadcast ();
242
243 //exit(0);
244}
245
246void print_help (const char *bin_name)
247{
248 printf ("Usage: %s [-a analyzer]\n"
Yinhang Liu81c44e02015-06-03 15:47:48 +0800249 "Configurations:\n"
Yinhang Liu454a3892016-11-07 16:30:35 +0800250 "\t -a analyzer specify a analyzer\n"
251 "\t select from [simple"
252#if HAVE_IA_AIQ
zongwave213b5d62016-11-25 18:46:53 +0800253 ", aiq"
Yinhang Liuc2f19082015-08-28 12:27:48 +0800254#if HAVE_LIBCL
zongwave213b5d62016-11-25 18:46:53 +0800255 ", dynamic, hybrid"
Yinhang Liuc2f19082015-08-28 12:27:48 +0800256#endif
Yinhang Liu454a3892016-11-07 16:30:35 +0800257#endif
zongwave213b5d62016-11-25 18:46:53 +0800258 "], default is [simple]\n"
Yinhang Liu454a3892016-11-07 16:30:35 +0800259 "\t -m mem_type specify video memory type\n"
260 "\t mem_type select from [dma, mmap], default is [mmap]\n"
261 "\t -s save file to %s\n"
262 "\t -n interval save file on every [interval] frame\n"
263 "\t -f pixel_fmt specify output pixel format\n"
264 "\t pixel_fmt select from [NV12, YUYV, BA10, BA12], default is [NV12]\n"
Yinhang Liu2bdc67a2017-02-28 11:27:49 +0800265 "\t -W image_width specify image width, default is [1920]\n"
266 "\t -H image_height specify image height, default is [1080]\n"
Yinhang Liu454a3892016-11-07 16:30:35 +0800267 "\t -d cap_mode specify capture mode\n"
268 "\t cap_mode select from [video, still], default is [video]\n"
269 "\t -i frame_save specify the frame count to save, default is 0 which means endless\n"
Yinhang Liu5855e6f2016-11-14 21:04:22 +0800270 "\t -p preview on enable local display, need root privilege\n"
Yinhang Liu454a3892016-11-07 16:30:35 +0800271 "\t --usb specify node for usb camera device, enables capture path through USB camera \n"
272 "\t specify [/dev/video4, /dev/video5] depending on which node USB camera is attached\n"
Yinhang Liu454a3892016-11-07 16:30:35 +0800273 "\t -e display_mode preview mode\n"
274 "\t select from [primary, overlay], default is [primary]\n"
275 "\t --sync set analyzer in sync mode\n"
276 "\t -r raw_input specify the path of raw image as fake source instead of live camera\n"
277 "\t -h help\n"
Yinhang Liuc2f19082015-08-28 12:27:48 +0800278#if HAVE_LIBCL
Yinhang Liu81c44e02015-06-03 15:47:48 +0800279 "CL features:\n"
Yinhang Liu454a3892016-11-07 16:30:35 +0800280 "\t -c process image with cl kernel\n"
281#if HAVE_IA_AIQ
282 "\t -b brightness specify brightness level\n"
283 "\t brightness level select from [0, 256], default is [128]\n"
284#endif
285 "\t --capture specify the capture stage of image\n"
286 "\t capture_stage select from [bayer, tonemapping], default is [tonemapping]\n"
Yinhang Liu454a3892016-11-07 16:30:35 +0800287 "\t --tnr specify temporal noise reduction type, default is tnr off\n"
Wind Yuan9d5e6a32017-01-26 03:09:39 -0500288 "\t only support [yuv]\n"
Yinhang Liu454a3892016-11-07 16:30:35 +0800289 "\t --tnr-level specify tnr level\n"
290 "\t --wdr-mode specify wdr mode. select from [gaussian, haleq]\n"
Yinhang Liu454a3892016-11-07 16:30:35 +0800291 "\t --enable-bnr enable bayer noise reduction\n"
Yinhang Liu454a3892016-11-07 16:30:35 +0800292 "\t --defog-mode specify defog mode\n"
293 "\t select from [disabled, retinex, dcp], default is [disabled]\n"
294 "\t --wavelet-mode specify wavelet denoise mode, default is off\n"
295 "\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"
296 "\t --3d-denoise specify 3D Denoise mode\n"
297 "\t select from [disabled, yuv, uv], default is [disabled]\n"
Yinhang Liu4ea70612016-05-26 18:26:29 +0800298 "\t --enable-wireframe enable wire frame\n"
Yinhang Liu454a3892016-11-07 16:30:35 +0800299 "\t --pipeline specify pipe mode\n"
300 "\t select from [basic, advance, extreme], default is [basic]\n"
301 "\t --disable-post disable cl post image processor\n"
Yinhang Liue26b2622015-07-21 18:32:36 +0800302 "(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 +0800303#endif
Wind Yuan75564b12015-01-15 06:51:15 -0500304 , bin_name
305 , DEFAULT_SAVE_FILE_NAME);
306}
307
308int main (int argc, char *argv[])
309{
310 XCamReturn ret = XCAM_RETURN_NO_ERROR;
Wind Yuan75564b12015-01-15 06:51:15 -0500311 SmartPtr<V4l2Device> device;
Yinhang Liu454a3892016-11-07 16:30:35 +0800312#if HAVE_IA_AIQ
Yinhang Liu5c1381c2016-11-19 16:35:38 +0800313 SmartPtr<V4l2SubDevice> event_device;
Wind Yuan75564b12015-01-15 06:51:15 -0500314 SmartPtr<IspController> isp_controller;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800315 SmartPtr<ImageProcessor> isp_processor;
Yinhang Liu454a3892016-11-07 16:30:35 +0800316#endif
317 SmartPtr<X3aAnalyzer> analyzer;
318 SmartPtr<AnalyzerLoader> loader;
Wind Yuan26e9e212015-04-16 15:55:45 +0800319 AnalyzerType analyzer_type = AnalyzerTypeSimple;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800320
Wind Yuand4427312015-02-11 16:09:00 +0800321#if HAVE_LIBCL
Yinhang Liu454a3892016-11-07 16:30:35 +0800322 bool have_cl_processor = false;
323 SmartPtr<SmartAnalyzer> smart_analyzer;
Yinhang Liuc64ed592016-07-15 18:53:34 +0800324 bool have_cl_post_processor = true;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800325 SmartPtr<CL3aImageProcessor> cl_processor;
Yinhang Liu2ab1f992016-03-15 10:41:17 +0800326 SmartPtr<CLPostImageProcessor> cl_post_processor;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800327 uint32_t tnr_type = CL_TNR_DISABLE;
328 uint32_t denoise_type = 0;
329 uint8_t tnr_level = 0;
Wangfei1487b9b2015-08-28 15:10:39 +0800330 CL3aImageProcessor::PipelineProfile pipeline_mode = CL3aImageProcessor::BasicPipelineProfile;
wujunkai166a84ba052015-09-08 15:54:12 +0800331 CL3aImageProcessor::CaptureStage capture_stage = CL3aImageProcessor::TonemappingStage;
wujunkai16606f77622016-03-18 14:41:10 +0800332 CL3aImageProcessor::CLTonemappingMode wdr_mode = CL3aImageProcessor::WDRdisabled;
Yinhang Liuc64ed592016-07-15 18:53:34 +0800333
Yinhang Liu454a3892016-11-07 16:30:35 +0800334#if HAVE_IA_AIQ
335 int32_t brightness_level = 128;
336#endif
Wind Yuanf4e17ab2016-05-05 02:54:01 +0800337 uint32_t defog_type = 0;
zongwaveb7140442016-03-25 18:15:12 +0800338 CLWaveletBasis wavelet_mode = CL_WAVELET_DISABLED;
zongwave98d23202016-06-27 13:46:27 +0800339 uint32_t wavelet_channel = CL_IMAGE_CHANNEL_UV;
340 bool wavelet_bayes_shrink = false;
Yinhang Liud341dbe2016-07-25 12:00:17 +0800341 uint32_t denoise_3d_mode = 0;
342 uint8_t denoise_3d_ref_count = 3;
Yinhang Liu4ea70612016-05-26 18:26:29 +0800343 bool wireframe_type = false;
zongwave1b10d6f2016-10-25 17:47:51 +0800344 bool image_warp_type = false;
Yinhang Liuc64ed592016-07-15 18:53:34 +0800345#endif
zongwaveb7140442016-03-25 18:15:12 +0800346
Yinhang Liu454a3892016-11-07 16:30:35 +0800347 bool need_display = false;
Yinhang Liu5855e6f2016-11-14 21:04:22 +0800348 DrmDisplayMode display_mode = DRM_DISPLAY_MODE_PRIMARY;
Yinhang Liu454a3892016-11-07 16:30:35 +0800349 enum v4l2_memory v4l2_mem_type = V4L2_MEMORY_MMAP;
350 const char *bin_name = argv[0];
351 uint32_t capture_mode = V4L2_CAPTURE_MODE_VIDEO;
352 uint32_t pixel_format = V4L2_PIX_FMT_NV12;
353
Sameer Kibey7b429292015-08-07 10:55:38 -0700354 bool have_usbcam = 0;
Wind Yuan155c8f52016-03-18 23:16:59 +0800355 SmartPtr<char> usb_device_name;
Jia Meng8f94a102015-08-11 16:24:19 +0800356 bool sync_mode = false;
Yinhang Liu5855e6f2016-11-14 21:04:22 +0800357 bool save_file = false;
358 uint32_t interval_frames = 1;
359 uint32_t save_frames = 0;
360 uint32_t frame_rate;
361 uint32_t frame_width = 1920;
362 uint32_t frame_height = 1080;
Wind Yuan155c8f52016-03-18 23:16:59 +0800363 SmartPtr<char> path_to_fake = NULL;
Wind Yuan75564b12015-01-15 06:51:15 -0500364
Yinhang Liu454a3892016-11-07 16:30:35 +0800365 int opt;
Yinhang Liu2bdc67a2017-02-28 11:27:49 +0800366 const char *short_opts = "sca:n:m:f:W:H:d:b:pi:e:r:h";
Yinhang Liu81c44e02015-06-03 15:47:48 +0800367 const struct option long_opts[] = {
Yinhang Liu81c44e02015-06-03 15:47:48 +0800368 {"tnr", required_argument, NULL, 'T'},
369 {"tnr-level", required_argument, NULL, 'L'},
Yinhang Liu2bdc67a2017-02-28 11:27:49 +0800370 {"wdr-mode", required_argument, NULL, 'w'},
ShincyTu63e2c262015-06-26 10:52:51 +0800371 {"enable-bnr", no_argument, NULL, 'B'},
Wind Yuanf4e17ab2016-05-05 02:54:01 +0800372 {"defog-mode", required_argument, NULL, 'X'},
zongwave2ba7f642016-03-15 19:24:12 +0800373 {"wavelet-mode", required_argument, NULL, 'V'},
zongwavebec89e12016-07-23 12:34:20 +0800374 {"3d-denoise", required_argument, NULL, 'N'},
Yinhang Liu4ea70612016-05-26 18:26:29 +0800375 {"enable-wireframe", no_argument, NULL, 'F'},
zongwave1b10d6f2016-10-25 17:47:51 +0800376 {"enable-warp", no_argument, NULL, 'A'},
Sameer Kibey7b429292015-08-07 10:55:38 -0700377 {"usb", required_argument, NULL, 'U'},
Jia Meng8f94a102015-08-11 16:24:19 +0800378 {"sync", no_argument, NULL, 'Y'},
wujunkai166a84ba052015-09-08 15:54:12 +0800379 {"capture", required_argument, NULL, 'C'},
Wangfei1487b9b2015-08-28 15:10:39 +0800380 {"pipeline", required_argument, NULL, 'P'},
Yinhang Liub0ad64b2016-03-18 16:03:51 +0800381 {"disable-post", no_argument, NULL, 'O'},
Yinhang Liu81c44e02015-06-03 15:47:48 +0800382 {0, 0, 0, 0},
383 };
384
385 while ((opt = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
Wind Yuan75564b12015-01-15 06:51:15 -0500386 switch (opt) {
387 case 'a': {
Wind Yuan6b437392016-02-02 00:31:30 +0800388 XCAM_ASSERT (optarg);
Yinhang Liu454a3892016-11-07 16:30:35 +0800389 if (!strcmp (optarg, "simple"))
Wind Yuan26e9e212015-04-16 15:55:45 +0800390 analyzer_type = AnalyzerTypeSimple;
Wind Yuan75564b12015-01-15 06:51:15 -0500391#if HAVE_IA_AIQ
392 else if (!strcmp (optarg, "aiq"))
Yinhang Liu6c367352016-03-31 20:23:22 +0800393 analyzer_type = AnalyzerTypeAiqTuner;
Yinhang Liu454a3892016-11-07 16:30:35 +0800394#if HAVE_LIBCL
395 else if (!strcmp (optarg, "dynamic"))
396 analyzer_type = AnalyzerTypeDynamic;
Jia Meng9724cfe2015-08-12 15:04:45 +0800397 else if (!strcmp (optarg, "hybrid"))
398 analyzer_type = AnalyzerTypeHybrid;
Wind Yuan75564b12015-01-15 06:51:15 -0500399#endif
Yinhang Liu454a3892016-11-07 16:30:35 +0800400#endif
Wind Yuan75564b12015-01-15 06:51:15 -0500401 else {
402 print_help (bin_name);
403 return -1;
404 }
405 break;
406 }
407
Wind Yuand4427312015-02-11 16:09:00 +0800408 case 'm': {
Wind Yuan6b437392016-02-02 00:31:30 +0800409 XCAM_ASSERT (optarg);
Wind Yuand4427312015-02-11 16:09:00 +0800410 if (!strcmp (optarg, "dma"))
411 v4l2_mem_type = V4L2_MEMORY_DMABUF;
412 else if (!strcmp (optarg, "mmap"))
413 v4l2_mem_type = V4L2_MEMORY_MMAP;
414 else
415 print_help (bin_name);
416 break;
417 }
418
Wind Yuan75564b12015-01-15 06:51:15 -0500419 case 's':
Yinhang Liu5855e6f2016-11-14 21:04:22 +0800420 save_file = true;
Wind Yuan75564b12015-01-15 06:51:15 -0500421 break;
422 case 'n':
Yinhang Liu1aa97602016-05-27 14:58:21 +0800423 XCAM_ASSERT (optarg);
Yinhang Liu5855e6f2016-11-14 21:04:22 +0800424 interval_frames = atoi(optarg);
425 break;
426 case 'i':
427 XCAM_ASSERT (optarg);
428 save_frames = atoi(optarg);
Wind Yuan75564b12015-01-15 06:51:15 -0500429 break;
ShincyTu2808b592015-03-13 17:17:25 +0800430 case 'f':
Yinhang Liu1aa97602016-05-27 14:58:21 +0800431 XCAM_ASSERT (optarg);
ShincyTuc8466402015-03-31 11:03:39 +0800432 CHECK_EXP ((strlen(optarg) == 4), "invalid pixel format\n");
433 pixel_format = v4l2_fourcc ((unsigned)optarg[0],
434 (unsigned)optarg[1],
435 (unsigned)optarg[2],
436 (unsigned)optarg[3]);
ShincyTu2808b592015-03-13 17:17:25 +0800437 break;
438 case 'd':
Wind Yuan6b437392016-02-02 00:31:30 +0800439 XCAM_ASSERT (optarg);
ShincyTu2808b592015-03-13 17:17:25 +0800440 if (!strcmp (optarg, "still"))
441 capture_mode = V4L2_CAPTURE_MODE_STILL;
442 else if (!strcmp (optarg, "video"))
443 capture_mode = V4L2_CAPTURE_MODE_VIDEO;
444 else {
445 print_help (bin_name);
446 return -1;
447 }
448 break;
Sameer Kibey7b429292015-08-07 10:55:38 -0700449 case 'U':
Yinhang Liu1aa97602016-05-27 14:58:21 +0800450 XCAM_ASSERT (optarg);
Sameer Kibey7b429292015-08-07 10:55:38 -0700451 have_usbcam = true;
Wind Yuan155c8f52016-03-18 23:16:59 +0800452 usb_device_name = strndup(optarg, XCAM_MAX_STR_SIZE);
453 XCAM_LOG_DEBUG("using USB camera plugged in at node: %s", XCAM_STR(usb_device_name.ptr ()));
Sameer Kibey7b429292015-08-07 10:55:38 -0700454 break;
Yinhang Liu2bdc67a2017-02-28 11:27:49 +0800455 case 'W':
Wind Yuan6b437392016-02-02 00:31:30 +0800456 XCAM_ASSERT (optarg);
Yinhang Liu2bdc67a2017-02-28 11:27:49 +0800457 frame_width = atoi(optarg);
458 break;
459 case 'H':
460 XCAM_ASSERT (optarg);
461 frame_height = atoi(optarg);
Yinhang Liud9346492015-12-17 11:14:25 +0800462 break;
wangfeicf4c4e72015-05-25 17:11:41 +0800463 case 'e': {
Wind Yuan6b437392016-02-02 00:31:30 +0800464 XCAM_ASSERT (optarg);
wangfeicf4c4e72015-05-25 17:11:41 +0800465 if (!strcmp (optarg, "primary"))
466 display_mode = DRM_DISPLAY_MODE_PRIMARY;
467 else if (!strcmp (optarg, "overlay"))
468 display_mode = DRM_DISPLAY_MODE_OVERLAY;
469 else {
470 print_help (bin_name);
471 return -1;
472 }
473 break;
474 }
Jia Meng8f94a102015-08-11 16:24:19 +0800475 case 'Y':
476 sync_mode = true;
477 break;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800478#if HAVE_LIBCL
Yinhang Liu454a3892016-11-07 16:30:35 +0800479 case 'c':
480 have_cl_processor = true;
481 break;
482#if HAVE_IA_AIQ
483 case 'b':
484 XCAM_ASSERT (optarg);
485 brightness_level = atoi(optarg);
486 if(brightness_level < 0 || brightness_level > 256) {
487 print_help (bin_name);
488 return -1;
489 }
490 break;
491#endif
Wind Yuan9d5e6a32017-01-26 03:09:39 -0500492
ShincyTu63e2c262015-06-26 10:52:51 +0800493 case 'B': {
494 denoise_type |= XCAM_DENOISE_TYPE_BNR;
495 break;
496 }
Wangfei8e5e3e42016-02-18 19:41:54 +0800497 case 'X': {
Wind Yuanf4e17ab2016-05-05 02:54:01 +0800498 XCAM_ASSERT (optarg);
499 defog_type = true;
500 if (!strcmp (optarg, "disabled"))
501 defog_type = CLPostImageProcessor::DefogDisabled;
502 else if (!strcmp (optarg, "retinex"))
503 defog_type = CLPostImageProcessor::DefogRetinex;
504 else if (!strcmp (optarg, "dcp"))
505 defog_type = CLPostImageProcessor::DefogDarkChannelPrior;
506 else {
507 print_help (bin_name);
508 return -1;
509 }
Wangfei8e5e3e42016-02-18 19:41:54 +0800510 break;
511 }
zongwave80adcf52016-02-29 12:38:06 +0800512 case 'V': {
zongwave2ba7f642016-03-15 19:24:12 +0800513 XCAM_ASSERT (optarg);
514 if (atoi(optarg) < 0 || atoi(optarg) > 255) {
515 print_help (bin_name);
516 return -1;
517 }
zongwave28a747b2016-03-17 12:49:08 +0800518 if (atoi(optarg) == 1) {
zongwaveb7140442016-03-25 18:15:12 +0800519 wavelet_mode = CL_WAVELET_HAT;
zongwave98d23202016-06-27 13:46:27 +0800520 wavelet_channel = CL_IMAGE_CHANNEL_Y;
zongwave28a747b2016-03-17 12:49:08 +0800521 } else if (atoi(optarg) == 2) {
zongwaveb7140442016-03-25 18:15:12 +0800522 wavelet_mode = CL_WAVELET_HAT;
zongwave98d23202016-06-27 13:46:27 +0800523 wavelet_channel = CL_IMAGE_CHANNEL_UV;
zongwaveb7140442016-03-25 18:15:12 +0800524 } else if (atoi(optarg) == 3) {
525 wavelet_mode = CL_WAVELET_HAAR;
zongwave98d23202016-06-27 13:46:27 +0800526 wavelet_channel = CL_IMAGE_CHANNEL_Y;
zongwaveb7140442016-03-25 18:15:12 +0800527 } else if (atoi(optarg) == 4) {
528 wavelet_mode = CL_WAVELET_HAAR;
zongwave98d23202016-06-27 13:46:27 +0800529 wavelet_channel = CL_IMAGE_CHANNEL_UV;
zongwaveb7140442016-03-25 18:15:12 +0800530 } else if (atoi(optarg) == 5) {
531 wavelet_mode = CL_WAVELET_HAAR;
zongwave98d23202016-06-27 13:46:27 +0800532 wavelet_channel = CL_IMAGE_CHANNEL_UV | CL_IMAGE_CHANNEL_Y;
533 } else if (atoi(optarg) == 6) {
534 wavelet_mode = CL_WAVELET_HAAR;
535 wavelet_channel = CL_IMAGE_CHANNEL_UV | CL_IMAGE_CHANNEL_Y;
536 wavelet_bayes_shrink = true;
zongwave28a747b2016-03-17 12:49:08 +0800537 } else {
zongwaveb7140442016-03-25 18:15:12 +0800538 wavelet_mode = CL_WAVELET_DISABLED;
zongwave28a747b2016-03-17 12:49:08 +0800539 }
zongwave80adcf52016-02-29 12:38:06 +0800540 break;
541 }
zongwavebec89e12016-07-23 12:34:20 +0800542 case 'N': {
543 XCAM_ASSERT (optarg);
544 denoise_3d_mode = true;
545 if (!strcmp (optarg, "disabled"))
546 denoise_3d_mode = CLPostImageProcessor::Denoise3DDisabled;
547 else if (!strcmp (optarg, "yuv"))
548 denoise_3d_mode = CLPostImageProcessor::Denoise3DYuv;
549 else if (!strcmp (optarg, "uv"))
550 denoise_3d_mode = CLPostImageProcessor::Denoise3DUV;
551 else {
552 print_help (bin_name);
553 return -1;
554 }
555 break;
556 }
Yinhang Liu4ea70612016-05-26 18:26:29 +0800557 case 'F': {
558 wireframe_type = true;
559 break;
560 }
zongwave1b10d6f2016-10-25 17:47:51 +0800561 case 'A': {
562 image_warp_type = true;
563 break;
564 }
Yinhang Liu81c44e02015-06-03 15:47:48 +0800565 case 'T': {
Wind Yuan6b437392016-02-02 00:31:30 +0800566 XCAM_ASSERT (optarg);
Yinhang Liu81c44e02015-06-03 15:47:48 +0800567 if (!strcasecmp (optarg, "yuv"))
568 tnr_type = CL_TNR_TYPE_YUV;
Yinhang Liu81c44e02015-06-03 15:47:48 +0800569 else {
Wind Yuan9d5e6a32017-01-26 03:09:39 -0500570 printf ("--tnr only support <yuv>, <%s> is not supported\n", optarg);
Yinhang Liu81c44e02015-06-03 15:47:48 +0800571 print_help (bin_name);
572 return -1;
573 }
574 break;
575 }
576 case 'L': {
Wind Yuan6b437392016-02-02 00:31:30 +0800577 XCAM_ASSERT (optarg);
Yinhang Liu81c44e02015-06-03 15:47:48 +0800578 if (atoi(optarg) < 0 || atoi(optarg) > 255) {
579 print_help (bin_name);
580 return -1;
581 }
582 tnr_level = atoi(optarg);
583 break;
584 }
Yinhang Liu2bdc67a2017-02-28 11:27:49 +0800585 case 'w': {
wujunkai16606f77622016-03-18 14:41:10 +0800586 XCAM_ASSERT (optarg);
587 if (!strcasecmp (optarg, "gaussian"))
588 wdr_mode = CL3aImageProcessor::Gaussian;
589 else if (!strcasecmp (optarg, "haleq"))
590 wdr_mode = CL3aImageProcessor::Haleq;
wujunkai16682950fb2015-10-19 18:09:05 +0800591
wujunkai166b0bd5512016-02-18 18:25:42 +0800592 pixel_format = V4L2_PIX_FMT_SGRBG12;
wujunkai166b0bd5512016-02-18 18:25:42 +0800593 setenv ("AIQ_CPF_PATH", IMX185_WDR_CPF, 1);
594 break;
595 }
Wangfei1487b9b2015-08-28 15:10:39 +0800596 case 'P': {
Wind Yuan6b437392016-02-02 00:31:30 +0800597 XCAM_ASSERT (optarg);
Wangfei1487b9b2015-08-28 15:10:39 +0800598 if (!strcasecmp (optarg, "basic"))
599 pipeline_mode = CL3aImageProcessor::BasicPipelineProfile;
600 else if (!strcasecmp (optarg, "advance"))
601 pipeline_mode = CL3aImageProcessor::AdvancedPipelineProfile;
Wangfei16b65db2015-09-11 14:44:28 +0800602 else if (!strcasecmp (optarg, "extreme"))
603 pipeline_mode = CL3aImageProcessor::ExtremePipelineProfile;
Wangfei1487b9b2015-08-28 15:10:39 +0800604 else {
605 print_help (bin_name);
606 return -1;
607 }
608 break;
609 }
wujunkai166a84ba052015-09-08 15:54:12 +0800610 case 'C': {
Wind Yuan6b437392016-02-02 00:31:30 +0800611 XCAM_ASSERT (optarg);
wujunkai166a84ba052015-09-08 15:54:12 +0800612 if (!strcmp (optarg, "bayer"))
613 capture_stage = CL3aImageProcessor::BasicbayerStage;
614 break;
615 }
Yinhang Liub0ad64b2016-03-18 16:03:51 +0800616 case 'O': {
617 have_cl_post_processor = false;
618 break;
619 }
Yinhang Liuc2f19082015-08-28 12:27:48 +0800620#endif
Jia Meng0a532932015-10-15 08:44:09 -0400621 case 'r': {
Yinhang Liu1aa97602016-05-27 14:58:21 +0800622 XCAM_ASSERT (optarg);
623 XCAM_LOG_INFO ("use raw image %s as input source", optarg);
624 path_to_fake = strndup(optarg, XCAM_MAX_STR_SIZE);
Jia Meng0a532932015-10-15 08:44:09 -0400625 break;
626 }
Yinhang Liu5855e6f2016-11-14 21:04:22 +0800627 case 'p': {
Yinhang Liu454a3892016-11-07 16:30:35 +0800628 need_display = true;
629 break;
Yinhang Liu5855e6f2016-11-14 21:04:22 +0800630 }
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 Liu5855e6f2016-11-14 21:04:22 +0800641 if (need_display && !DrmDisplay::set_preview (need_display)) {
642 need_display = false;
643 XCAM_LOG_WARNING ("set preview failed, disable local preview now");
wangfeicf4c4e72015-05-25 17:11:41 +0800644 }
Yinhang Liu5855e6f2016-11-14 21:04:22 +0800645
646 SmartPtr<MainDeviceManager> device_manager = new MainDeviceManager ();
647 device_manager->enable_save_file (save_file);
648 device_manager->set_interval (interval_frames);
649 device_manager->set_frame_save (save_frames);
650 device_manager->set_frame_width (frame_width);
651 device_manager->set_frame_height (frame_height);
652 device_manager->enable_display (need_display);
653 device_manager->set_display_mode (display_mode);
654
ShincyTu2808b592015-03-13 17:17:25 +0800655 if (!device.ptr ()) {
Wind Yuan155c8f52016-03-18 23:16:59 +0800656 if (path_to_fake.ptr ()) {
Jia Meng0a532932015-10-15 08:44:09 -0400657 device = new FakeV4l2Device ();
658 } else if (have_usbcam) {
Wind Yuan155c8f52016-03-18 23:16:59 +0800659 device = new UVCDevice (usb_device_name.ptr ());
Yinhang Liu454a3892016-11-07 16:30:35 +0800660 }
661#if HAVE_IA_AIQ
662 else {
Sameer Kibey7b429292015-08-07 10:55:38 -0700663 if (capture_mode == V4L2_CAPTURE_MODE_STILL)
664 device = new AtomispDevice (CAPTURE_DEVICE_STILL);
665 else if (capture_mode == V4L2_CAPTURE_MODE_VIDEO)
666 device = new AtomispDevice (CAPTURE_DEVICE_VIDEO);
667 else
668 device = new AtomispDevice (DEFAULT_CAPTURE_DEVICE);
669 }
Yinhang Liu454a3892016-11-07 16:30:35 +0800670#endif
ShincyTu2808b592015-03-13 17:17:25 +0800671 }
Yinhang Liu5c1381c2016-11-19 16:35:38 +0800672
Yinhang Liu454a3892016-11-07 16:30:35 +0800673#if HAVE_IA_AIQ
Wind Yuan75564b12015-01-15 06:51:15 -0500674 if (!isp_controller.ptr ())
675 isp_controller = new IspController (device);
Yinhang Liu454a3892016-11-07 16:30:35 +0800676#endif
Wind Yuan26e9e212015-04-16 15:55:45 +0800677
678 switch (analyzer_type) {
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800679 case AnalyzerTypeSimple:
680 analyzer = new X3aAnalyzerSimple ();
681 break;
Wind Yuan26e9e212015-04-16 15:55:45 +0800682#if HAVE_IA_AIQ
Yinhang Liu6c367352016-03-31 20:23:22 +0800683 case AnalyzerTypeAiqTuner: {
684 SmartPtr<X3aAnalyzer> aiq_analyzer = new X3aAnalyzerAiq (isp_controller, DEFAULT_CPF_FILE);
685 SmartPtr<X3aAnalyzeTuner> tuner_analyzer = new X3aAnalyzeTuner ();
686 XCAM_ASSERT (aiq_analyzer.ptr () && tuner_analyzer.ptr ());
687 tuner_analyzer->set_analyzer (aiq_analyzer);
688 analyzer = tuner_analyzer;
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800689 break;
Yinhang Liu6c367352016-03-31 20:23:22 +0800690 }
Yinhang Liu454a3892016-11-07 16:30:35 +0800691#if HAVE_LIBCL
692 case AnalyzerTypeDynamic: {
693 const char *path_of_3a = DEFAULT_DYNAMIC_3A_LIB;
694 SmartPtr<DynamicAnalyzerLoader> dynamic_loader = new DynamicAnalyzerLoader (path_of_3a);
695 loader = dynamic_loader.dynamic_cast_ptr<AnalyzerLoader> ();
696 analyzer = dynamic_loader->load_analyzer (loader);
697 CHECK_EXP (analyzer.ptr (), "load dynamic 3a lib(%s) failed", path_of_3a);
698 break;
699 }
Jia Meng9724cfe2015-08-12 15:04:45 +0800700 case AnalyzerTypeHybrid: {
Yinhang Liu454a3892016-11-07 16:30:35 +0800701 const char *path_of_3a = DEFAULT_HYBRID_3A_LIB;
Yinhang Liue37a8722016-06-27 18:14:35 +0800702 SmartPtr<HybridAnalyzerLoader> hybrid_loader = new HybridAnalyzerLoader (path_of_3a);
703 hybrid_loader->set_cpf_path (DEFAULT_CPF_FILE);
704 hybrid_loader->set_isp_controller (isp_controller);
705 loader = hybrid_loader.dynamic_cast_ptr<AnalyzerLoader> ();
706 analyzer = hybrid_loader->load_analyzer (loader);
Jia Meng9724cfe2015-08-12 15:04:45 +0800707 CHECK_EXP (analyzer.ptr (), "load hybrid 3a lib(%s) failed", path_of_3a);
708 break;
709 }
Wind Yuan26e9e212015-04-16 15:55:45 +0800710#endif
Yinhang Liu454a3892016-11-07 16:30:35 +0800711#endif
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800712 default:
713 print_help (bin_name);
714 return -1;
Wind Yuan26e9e212015-04-16 15:55:45 +0800715 }
Jia Meng8f94a102015-08-11 16:24:19 +0800716 XCAM_ASSERT (analyzer.ptr ());
717 analyzer->set_sync_mode (sync_mode);
Wind Yuan75564b12015-01-15 06:51:15 -0500718
Yinhang Liu3fef5d72016-07-25 14:43:20 +0800719#if HAVE_LIBCL
720 SmartHandlerList smart_handlers = SmartAnalyzerLoader::load_smart_handlers (DEFAULT_SMART_ANALYSIS_LIB_DIR);
721 if (!smart_handlers.empty ()) {
722 smart_analyzer = new SmartAnalyzer ();
723 if (smart_analyzer.ptr ()) {
724 SmartHandlerList::iterator i_handler = smart_handlers.begin ();
Wind Yuan136aa4f2016-09-08 02:56:31 -0400725 for (; i_handler != smart_handlers.end (); ++i_handler)
Yinhang Liu3fef5d72016-07-25 14:43:20 +0800726 {
727 XCAM_ASSERT ((*i_handler).ptr ());
728 smart_analyzer->add_handler (*i_handler);
729 }
730 } else {
731 XCAM_LOG_WARNING ("load smart analyzer(%s) failed, please check.", DEFAULT_SMART_ANALYSIS_LIB_DIR);
732 }
733 }
Yinhang Liu454a3892016-11-07 16:30:35 +0800734
735 if (smart_analyzer.ptr ()) {
736 if (smart_analyzer->prepare_handlers () != XCAM_RETURN_NO_ERROR) {
737 XCAM_LOG_WARNING ("analyzer(%s) prepare handlers failed", smart_analyzer->get_name ());
738 }
739 device_manager->set_smart_analyzer (smart_analyzer);
740 }
Yinhang Liu3fef5d72016-07-25 14:43:20 +0800741#endif
742
Wind Yuan75564b12015-01-15 06:51:15 -0500743 signal(SIGINT, dev_stop_handler);
744
745 device->set_sensor_id (0);
ShincyTu2808b592015-03-13 17:17:25 +0800746 device->set_capture_mode (capture_mode);
Wind Yuan75564b12015-01-15 06:51:15 -0500747 //device->set_mem_type (V4L2_MEMORY_DMABUF);
Wind Yuand4427312015-02-11 16:09:00 +0800748 device->set_mem_type (v4l2_mem_type);
Wind Yuan75564b12015-01-15 06:51:15 -0500749 device->set_buffer_count (8);
Jia Meng757f3c92015-09-09 11:18:36 +0800750 if (pixel_format == V4L2_PIX_FMT_SGRBG12) {
751 frame_rate = 30;
752 device->set_framerate (frame_rate, 1);
753 }
Yinhang Liuc64ed592016-07-15 18:53:34 +0800754#if HAVE_LIBCL
Jia Meng757f3c92015-09-09 11:18:36 +0800755 else {
756 frame_rate = 25;
757 device->set_framerate (frame_rate, 1);
Yinhang Liuefe4f0f2016-12-29 13:17:22 +0800758 if(wdr_mode != CL3aImageProcessor::WDRdisabled) {
wujunkai166a9a55f22015-10-10 15:53:32 +0800759 XCAM_LOG_WARNING("Tonemapping is only applicable under BA12 format. Disable tonemapping automatically.");
Yinhang Liuefe4f0f2016-12-29 13:17:22 +0800760 wdr_mode = CL3aImageProcessor::WDRdisabled;
wujunkai166a9a55f22015-10-10 15:53:32 +0800761 }
Jia Meng757f3c92015-09-09 11:18:36 +0800762 }
Yinhang Liuc64ed592016-07-15 18:53:34 +0800763#endif
Wind Yuan75564b12015-01-15 06:51:15 -0500764 ret = device->open ();
765 CHECK (ret, "device(%s) open failed", device->get_device_name());
Yinhang Liud9346492015-12-17 11:14:25 +0800766 ret = device->set_format (frame_width, frame_height, pixel_format, V4L2_FIELD_NONE, frame_width * 2);
Wind Yuan75564b12015-01-15 06:51:15 -0500767 CHECK (ret, "device(%s) set format failed", device->get_device_name());
768
Yinhang Liu5c1381c2016-11-19 16:35:38 +0800769#if HAVE_IA_AIQ
770 if (!event_device.ptr ())
771 event_device = new V4l2SubDevice (DEFAULT_EVENT_DEVICE);
Wind Yuan75564b12015-01-15 06:51:15 -0500772 ret = event_device->open ();
Wind Yuanb67045c2015-08-27 13:50:53 +0800773 if (ret == XCAM_RETURN_NO_ERROR) {
774 CHECK (ret, "event device(%s) open failed", event_device->get_device_name());
775 int event = V4L2_EVENT_ATOMISP_3A_STATS_READY;
776 ret = event_device->subscribe_event (event);
777 CHECK_CONTINUE (
778 ret,
779 "device(%s) subscribe event(%d) failed",
780 event_device->get_device_name(), event);
781 event = V4L2_EVENT_FRAME_SYNC;
782 ret = event_device->subscribe_event (event);
783 CHECK_CONTINUE (
784 ret,
785 "device(%s) subscribe event(%d) failed",
786 event_device->get_device_name(), event);
787
788 device_manager->set_event_device (event_device);
789 }
Yinhang Liu5c1381c2016-11-19 16:35:38 +0800790#endif
Wind Yuan75564b12015-01-15 06:51:15 -0500791
792 device_manager->set_capture_device (device);
Wind Yuan75564b12015-01-15 06:51:15 -0500793 if (analyzer.ptr())
zongwave03954a32015-09-22 15:40:44 +0800794 device_manager->set_3a_analyzer (analyzer);
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800795
Yinhang Liu454a3892016-11-07 16:30:35 +0800796#if HAVE_IA_AIQ
797#if HAVE_LIBCL
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800798 if (have_cl_processor)
799 isp_processor = new IspExposureImageProcessor (isp_controller);
800 else
Yinhang Liu454a3892016-11-07 16:30:35 +0800801#endif
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800802 isp_processor = new IspImageProcessor (isp_controller);
803
804 XCAM_ASSERT (isp_processor.ptr ());
Wind Yuane4ba0c92015-03-26 16:59:06 +0800805 device_manager->add_image_processor (isp_processor);
Yinhang Liu454a3892016-11-07 16:30:35 +0800806#endif
Yinhang Liuc2f19082015-08-28 12:27:48 +0800807#if HAVE_LIBCL
Wind Yuand4427312015-02-11 16:09:00 +0800808 if (have_cl_processor) {
Wind Yuane4ba0c92015-03-26 16:59:06 +0800809 cl_processor = new CL3aImageProcessor ();
Wind Yuan7ddf2602015-04-14 18:49:45 +0800810 cl_processor->set_stats_callback(device_manager);
Jia Meng66efecf2015-06-17 11:11:10 +0000811 cl_processor->set_denoise (denoise_type);
wujunkai166a84ba052015-09-08 15:54:12 +0800812 cl_processor->set_capture_stage (capture_stage);
wujunkai166c8f3b442016-02-29 17:12:09 +0800813
Yinhang Liuefe4f0f2016-12-29 13:17:22 +0800814 cl_processor->set_tonemapping (wdr_mode);
815 if (wdr_mode != CL3aImageProcessor::WDRdisabled) {
816 cl_processor->set_gamma (false);
817 cl_processor->set_3a_stats_bits (12);
wujunkai166c8f3b442016-02-29 17:12:09 +0800818 }
Yinhang Liuefe4f0f2016-12-29 13:17:22 +0800819
Yinhang Liu81c44e02015-06-03 15:47:48 +0800820 cl_processor->set_tnr (tnr_type, tnr_level);
Wangfei1487b9b2015-08-28 15:10:39 +0800821 cl_processor->set_profile (pipeline_mode);
Yinhang Liu454a3892016-11-07 16:30:35 +0800822#if HAVE_IA_AIQ
yaowang1a5f12122015-07-27 14:53:38 +0800823 analyzer->set_parameter_brightness((brightness_level - 128) / 128.0);
Yinhang Liu454a3892016-11-07 16:30:35 +0800824#endif
Wind Yuand4427312015-02-11 16:09:00 +0800825 device_manager->add_image_processor (cl_processor);
826 }
Yinhang Liu3c17fea2016-03-15 10:47:03 +0800827
Yinhang Liub0ad64b2016-03-18 16:03:51 +0800828 if (have_cl_post_processor) {
829 cl_post_processor = new CLPostImageProcessor ();
Yinhang Liu3c721c12016-03-15 15:03:51 +0800830
Yinhang Liud341dbe2016-07-25 12:00:17 +0800831 cl_post_processor->set_stats_callback (device_manager);
Wind Yuanf4e17ab2016-05-05 02:54:01 +0800832 cl_post_processor->set_defog_mode ((CLPostImageProcessor::CLDefogMode)defog_type);
Yinhang Liud341dbe2016-07-25 12:00:17 +0800833 cl_post_processor->set_wavelet (wavelet_mode, wavelet_channel, wavelet_bayes_shrink);
834 cl_post_processor->set_3ddenoise_mode ((CLPostImageProcessor::CL3DDenoiseMode) denoise_3d_mode, denoise_3d_ref_count);
Yinhang Liu3c721c12016-03-15 15:03:51 +0800835
Yinhang Liud341dbe2016-07-25 12:00:17 +0800836 cl_post_processor->set_wireframe (wireframe_type);
zongwave1b10d6f2016-10-25 17:47:51 +0800837 cl_post_processor->set_image_warp (image_warp_type);
838 if (smart_analyzer.ptr () && (wireframe_type || image_warp_type)) {
Yinhang Liud341dbe2016-07-25 12:00:17 +0800839 cl_post_processor->set_scaler (true);
840 cl_post_processor->set_scaler_factor (640.0 / frame_width);
841 }
zongwavebec89e12016-07-23 12:34:20 +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;
Yinhang Liu454a3892016-11-07 16:30:35 +0800851 if (have_usbcam) {
852 poll_thread = new PollThread ();
853 } else if (path_to_fake.ptr ()) {
Wind Yuan155c8f52016-03-18 23:16:59 +0800854 poll_thread = new FakePollThread (path_to_fake.ptr ());
Yinhang Liu454a3892016-11-07 16:30:35 +0800855 }
856#if HAVE_IA_AIQ
Yinhang Liue37a8722016-06-27 18:14:35 +0800857 else {
858 SmartPtr<IspPollThread> isp_poll_thread = new IspPollThread ();
859 isp_poll_thread->set_isp_controller (isp_controller);
860 poll_thread = isp_poll_thread;
861 }
Yinhang Liu454a3892016-11-07 16:30:35 +0800862#endif
Jia Meng0a532932015-10-15 08:44:09 -0400863 device_manager->set_poll_thread (poll_thread);
864
Wind Yuan75564b12015-01-15 06:51:15 -0500865 ret = device_manager->start ();
866 CHECK (ret, "device manager start failed");
867
Yinhang Liuc64ed592016-07-15 18:53:34 +0800868#if HAVE_LIBCL
Jia Meng757f3c92015-09-09 11:18:36 +0800869 // hard code exposure range and max gain for imx185 WDR
Yinhang Liuefe4f0f2016-12-29 13:17:22 +0800870 if (wdr_mode != CL3aImageProcessor::WDRdisabled) {
Jia Meng757f3c92015-09-09 11:18:36 +0800871 if (frame_rate == 30)
872 analyzer->set_ae_exposure_time_range (80 * 1110 * 1000 / 37125, 1120 * 1110 * 1000 / 37125);
873 else
Jia Menga6580232015-10-08 16:51:28 +0800874 analyzer->set_ae_exposure_time_range (80 * 1320 * 1000 / 37125, 1120 * 1320 * 1000 / 37125);
Jia Meng757f3c92015-09-09 11:18:36 +0800875 analyzer->set_ae_max_analog_gain (3.98); // 12dB
876 }
Yinhang Liuc64ed592016-07-15 18:53:34 +0800877#endif
Jia Meng757f3c92015-09-09 11:18:36 +0800878
Wind Yuan75564b12015-01-15 06:51:15 -0500879 // wait for interruption
880 {
881 SmartLock locker (g_mutex);
882 while (!g_stop)
883 g_cond.wait (g_mutex);
884 }
885
886 ret = device_manager->stop();
887 CHECK_CONTINUE (ret, "device manager stop failed");
888 device->close ();
Yinhang Liu5c1381c2016-11-19 16:35:38 +0800889#if HAVE_IA_AIQ
Wind Yuan75564b12015-01-15 06:51:15 -0500890 event_device->close ();
Yinhang Liu5c1381c2016-11-19 16:35:38 +0800891#endif
Wind Yuan75564b12015-01-15 06:51:15 -0500892
893 return 0;
894}