blob: e2e0da14406b2397e5a62a401d0fbb1c1cfddc75 [file] [log] [blame]
Wind Yuan75564b12015-01-15 06:51:15 -05001/*
2 * main.cpp - test
3 *
4 * Copyright (c) 2014 Intel Corporation
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *
18 * Author: Wind Yuan <feng.yuan@intel.com>
19 */
20
21#include "device_manager.h"
22#include "atomisp_device.h"
Sameer Kibey7b429292015-08-07 10:55:38 -070023#include "uvc_device.h"
Jia Meng0a532932015-10-15 08:44:09 -040024#include "fake_v4l2_device.h"
Wind Yuan75564b12015-01-15 06:51:15 -050025#include "isp_controller.h"
26#include "isp_image_processor.h"
27#include "x3a_analyzer_simple.h"
28#if HAVE_IA_AIQ
29#include "x3a_analyzer_aiq.h"
30#endif
Wind Yuand4427312015-02-11 16:09:00 +080031#if HAVE_LIBCL
Wind Yuane4ba0c92015-03-26 16:59:06 +080032#include "cl_3a_image_processor.h"
wangfeicf4c4e72015-05-25 17:11:41 +080033#include "cl_csc_image_processor.h"
Yinhang Liu81c44e02015-06-03 15:47:48 +080034#include "cl_hdr_handler.h"
35#include "cl_tnr_handler.h"
Wind Yuane4ba0c92015-03-26 16:59:06 +080036#endif
37#if HAVE_LIBDRM
38#include "drm_display.h"
Wind Yuand4427312015-02-11 16:09:00 +080039#endif
zongwave03954a32015-09-22 15:40:44 +080040#include "x3a_analyzer_loader.h"
Jia Meng0a532932015-10-15 08:44:09 -040041#include "poll_thread.h"
42#include "fake_poll_thread.h"
Jia Meng66efecf2015-06-17 11:11:10 +000043#include <base/xcam_3a_types.h>
Wind Yuan75564b12015-01-15 06:51:15 -050044#include <unistd.h>
45#include <signal.h>
46#include <stdlib.h>
ShincyTue521cf92015-03-27 15:13:51 +080047#include <string>
Yinhang Liu81c44e02015-06-03 15:47:48 +080048#include <getopt.h>
John Yeae9da732015-01-22 13:36:36 +080049#include "test_common.h"
50
Wind Yuan75564b12015-01-15 06:51:15 -050051using namespace XCam;
52
wujunkai16682950fb2015-10-19 18:09:05 +080053#define IMX185_WDR_CPF "/etc/atomisp/imx185_wdr.cpf"
54
ShincyTue521cf92015-03-27 15:13:51 +080055static Mutex g_mutex;
56static Cond g_cond;
57static bool g_stop = false;
58
Wind Yuan75564b12015-01-15 06:51:15 -050059class MainDeviceManager
60 : public DeviceManager
61{
62public:
63 MainDeviceManager ()
64 : _file (NULL)
65 , _save_file (false)
66 , _interval (1)
67 , _frame_count (0)
ShincyTue521cf92015-03-27 15:13:51 +080068 , _frame_save (0)
Wind Yuan683f8662015-03-27 18:52:38 +080069 , _enable_display (false)
Wind Yuane4ba0c92015-03-26 16:59:06 +080070 {
71#if HAVE_LIBDRM
72 _display = DrmDisplay::instance();
73#endif
Wind Yuan91625802015-06-24 15:36:01 +080074 XCAM_OBJ_PROFILING_INIT;
Wind Yuane4ba0c92015-03-26 16:59:06 +080075 }
Wind Yuan75564b12015-01-15 06:51:15 -050076
77 ~MainDeviceManager () {
78 close_file ();
79 }
80
81 void enable_save_file (bool enable) {
82 _save_file = enable;
83 }
84 void set_interval (uint32_t inteval) {
85 _interval = inteval;
86 }
ShincyTue521cf92015-03-27 15:13:51 +080087 void set_frame_save (uint32_t frame_save) {
88 _frame_save = frame_save;
89 }
Wind Yuan75564b12015-01-15 06:51:15 -050090
Wind Yuan683f8662015-03-27 18:52:38 +080091 void enable_display(bool value) {
92 _enable_display = value;
93 }
94
wangfeicf4c4e72015-05-25 17:11:41 +080095 void set_display_mode(DrmDisplayMode mode) {
96 _display->set_display_mode (mode);
97 }
98
Wind Yuan75564b12015-01-15 06:51:15 -050099protected:
Wind Yuan73af3932015-07-02 17:52:43 +0800100 virtual void handle_message (const SmartPtr<XCamMessage> &msg);
101 virtual void handle_buffer (const SmartPtr<VideoBuffer> &buf);
Wind Yuan75564b12015-01-15 06:51:15 -0500102
Wind Yuan73af3932015-07-02 17:52:43 +0800103 int display_buf (const SmartPtr<VideoBuffer> &buf);
Wind Yuane4ba0c92015-03-26 16:59:06 +0800104
Wind Yuan75564b12015-01-15 06:51:15 -0500105private:
106 void open_file ();
107 void close_file ();
108
109 FILE *_file;
110 bool _save_file;
111 uint32_t _interval;
112 uint32_t _frame_count;
ShincyTue521cf92015-03-27 15:13:51 +0800113 uint32_t _frame_save;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800114 SmartPtr<DrmDisplay> _display;
Wind Yuan683f8662015-03-27 18:52:38 +0800115 bool _enable_display;
Wind Yuan91625802015-06-24 15:36:01 +0800116 XCAM_OBJ_PROFILING_DEFINES;
Wind Yuan75564b12015-01-15 06:51:15 -0500117};
118
119void
Wind Yuan73af3932015-07-02 17:52:43 +0800120MainDeviceManager::handle_message (const SmartPtr<XCamMessage> &msg)
Wind Yuan75564b12015-01-15 06:51:15 -0500121{
122 XCAM_UNUSED (msg);
123}
124
125void
Wind Yuan73af3932015-07-02 17:52:43 +0800126MainDeviceManager::handle_buffer (const SmartPtr<VideoBuffer> &buf)
Wind Yuan75564b12015-01-15 06:51:15 -0500127{
Wind Yuan683f8662015-03-27 18:52:38 +0800128 FPS_CALCULATION (fps_buf, 30);
129
Wind Yuan91625802015-06-24 15:36:01 +0800130 XCAM_OBJ_PROFILING_START;
131
Wind Yuan683f8662015-03-27 18:52:38 +0800132 if (_enable_display)
133 display_buf (buf);
Wind Yuane4ba0c92015-03-26 16:59:06 +0800134
Wind Yuan91625802015-06-24 15:36:01 +0800135 XCAM_OBJ_PROFILING_END("main_dev_manager_display", 30);
136
Wind Yuan75564b12015-01-15 06:51:15 -0500137 if (!_save_file)
138 return ;
139
140 if ((_frame_count++ % _interval) != 0)
141 return;
142
ShincyTue521cf92015-03-27 15:13:51 +0800143 if ((_frame_save != 0) && (_frame_count > _frame_save)) {
144 SmartLock locker (g_mutex);
145 g_stop = true;
146 g_cond.broadcast ();
147 return;
148 }
149
Wind Yuan75564b12015-01-15 06:51:15 -0500150 const VideoBufferInfo & frame_info = buf->get_video_info ();
151 uint8_t *frame = buf->map ();
ShincyTu2808b592015-03-13 17:17:25 +0800152
Wind Yuan75564b12015-01-15 06:51:15 -0500153 if (frame == NULL)
154 return;
ShincyTu2808b592015-03-13 17:17:25 +0800155
156 uint32_t size = 0;
157
158 switch(frame_info.format) {
159 case V4L2_PIX_FMT_NV12: // 420
160 case V4L2_PIX_FMT_NV21:
161 size = XCAM_ALIGN_UP(frame_info.width, 2) * XCAM_ALIGN_UP(frame_info.height, 2) * 3 / 2;
162 break;
163 case V4L2_PIX_FMT_YUV422P: // 422 Planar
164 case V4L2_PIX_FMT_YUYV: // 422
165 case V4L2_PIX_FMT_SBGGR10:
166 case V4L2_PIX_FMT_SGBRG10:
167 case V4L2_PIX_FMT_SGRBG10:
168 case V4L2_PIX_FMT_SRGGB10:
ShincyTu1a4de9d2015-06-01 18:04:51 +0800169 case V4L2_PIX_FMT_SBGGR12:
170 case V4L2_PIX_FMT_SGBRG12:
171 case V4L2_PIX_FMT_SGRBG12:
172 case V4L2_PIX_FMT_SRGGB12:
ShincyTu2808b592015-03-13 17:17:25 +0800173 size = XCAM_ALIGN_UP(frame_info.width, 2) * XCAM_ALIGN_UP(frame_info.height, 2) * 2;
174 break;
wujunkai166a84ba052015-09-08 15:54:12 +0800175 case XCAM_PIX_FMT_RGBA64:
176 size = XCAM_ALIGN_UP(frame_info.width, 2) * XCAM_ALIGN_UP(frame_info.height, 2) * 2 * 4;
177 break;
ShincyTu2808b592015-03-13 17:17:25 +0800178 default:
179 XCAM_LOG_ERROR (
180 "unknown v4l2 format(%s) in buffer handle",
181 xcam_fourcc_to_string (frame_info.format));
182 return;
183 }
184
Wind Yuan75564b12015-01-15 06:51:15 -0500185 open_file ();
Jia Meng6c9241d2015-06-12 11:08:45 +0000186
187 if (!_file) {
188 XCAM_LOG_ERROR ("open file failed");
Jia Meng54a2dcb2015-08-20 15:23:47 +0800189 return;
Jia Meng6c9241d2015-06-12 11:08:45 +0000190 }
191
Wind Yuan75564b12015-01-15 06:51:15 -0500192 if (fwrite (frame, size, 1, _file) <= 0) {
193 XCAM_LOG_WARNING ("write frame failed.");
194 }
195}
196
Wind Yuane4ba0c92015-03-26 16:59:06 +0800197int
Wind Yuan73af3932015-07-02 17:52:43 +0800198MainDeviceManager::display_buf (const SmartPtr<VideoBuffer> &data)
Wind Yuane4ba0c92015-03-26 16:59:06 +0800199{
200#if HAVE_LIBDRM
201 XCamReturn ret = XCAM_RETURN_NO_ERROR;
Wind Yuan73af3932015-07-02 17:52:43 +0800202 SmartPtr<VideoBuffer> buf = data;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800203 const VideoBufferInfo & frame_info = buf->get_video_info ();
204 struct v4l2_rect rect = { 0, 0, (int)frame_info.width, (int)frame_info.height };
205
206 if (!_display->is_render_inited ()) {
wangfei139ea7e2015-04-27 18:13:40 +0800207 ret = _display->render_init (0, 0, 1920, 1080, frame_info.format, &rect);
Wind Yuane4ba0c92015-03-26 16:59:06 +0800208 CHECK (ret, "display failed on render_init");
209 }
210 ret = _display->render_setup_frame_buffer (buf);
211 CHECK (ret, "display failed on framebuf set");
212 ret = _display->render_buffer (buf);
213 CHECK (ret, "display failed on rendering");
214#endif
215 return 0;
216}
217
218
Wind Yuan75564b12015-01-15 06:51:15 -0500219void
220MainDeviceManager::open_file ()
221{
ShincyTue521cf92015-03-27 15:13:51 +0800222 if ((_file) && (_frame_save == 0))
Wind Yuan75564b12015-01-15 06:51:15 -0500223 return;
ShincyTue521cf92015-03-27 15:13:51 +0800224
225 std::string file_name = DEFAULT_SAVE_FILE_NAME;
226
227 if (_frame_save != 0) {
228 file_name += std::to_string(_frame_count);
229 }
230 file_name += ".raw";
231
232 _file = fopen(file_name.c_str(), "wb");
Wind Yuan75564b12015-01-15 06:51:15 -0500233}
234
235void
236MainDeviceManager::close_file ()
237{
238 if (_file)
239 fclose (_file);
240 _file = NULL;
241}
242
243#define V4L2_CAPTURE_MODE_STILL 0x2000
244#define V4L2_CAPTURE_MODE_VIDEO 0x4000
245#define V4L2_CAPTURE_MODE_PREVIEW 0x8000
246
Wind Yuan26e9e212015-04-16 15:55:45 +0800247typedef enum {
248 AnalyzerTypeSimple = 0,
249 AnalyzerTypeAiq,
Wind Yuane25ce3f2015-05-04 18:07:29 +0800250 AnalyzerTypeDynamic,
Jia Meng9724cfe2015-08-12 15:04:45 +0800251 AnalyzerTypeHybrid,
Wind Yuan26e9e212015-04-16 15:55:45 +0800252} AnalyzerType;
253
Wind Yuan75564b12015-01-15 06:51:15 -0500254void dev_stop_handler(int sig)
255{
256 XCAM_UNUSED (sig);
257
258 SmartLock locker (g_mutex);
259 g_stop = true;
260 g_cond.broadcast ();
261
262 //exit(0);
263}
264
265void print_help (const char *bin_name)
266{
267 printf ("Usage: %s [-a analyzer]\n"
Yinhang Liu81c44e02015-06-03 15:47:48 +0800268 "Configurations:\n"
ShincyTue521cf92015-03-27 15:13:51 +0800269 "\t -a analyzer specify a analyzer\n"
Wind Yuane25ce3f2015-05-04 18:07:29 +0800270 "\t select from [simple, aiq, dynamic], default is [simple]\n"
ShincyTue521cf92015-03-27 15:13:51 +0800271 "\t -m mem_type specify video memory type\n"
272 "\t mem_type select from [dma, mmap], default is [mmap]\n"
273 "\t -s save file to %s\n"
274 "\t -n interval save file on every [interval] frame\n"
Yinhang Liuc2f19082015-08-28 12:27:48 +0800275#if HAVE_LIBCL
ShincyTue521cf92015-03-27 15:13:51 +0800276 "\t -c process image with cl kernel\n"
Yinhang Liuc2f19082015-08-28 12:27:48 +0800277#endif
ShincyTue521cf92015-03-27 15:13:51 +0800278 "\t -f pixel_fmt specify output pixel format\n"
wujunkai1669845b022015-08-27 15:59:27 +0800279 "\t pixel_fmt select from [NV12, YUYV, BA10, BA12], default is [NV12]\n"
ShincyTue521cf92015-03-27 15:13:51 +0800280 "\t -d cap_mode specify capture mode\n"
281 "\t cap_mode select from [video, still], default is [video]\n"
yaowang1a5f12122015-07-27 14:53:38 +0800282 "\t -b brightness specify brightness level\n"
283 "\t brightness level select from [0, 256], default is [128]\n"
ShincyTue521cf92015-03-27 15:13:51 +0800284 "\t -i frame_save specify the frame count to save, default is 0 which means endless\n"
wangfeicf4c4e72015-05-25 17:11:41 +0800285 "\t -p preview on local display\n"
Sameer Kibey7b429292015-08-07 10:55:38 -0700286 "\t --usb specify node for usb camera device, enables capture path through USB camera \n"
287 "\t specify [/dev/video4, /dev/video5] depending on which node USB camera is attached\n"
wangfeicf4c4e72015-05-25 17:11:41 +0800288 "\t -e display_mode preview mode\n"
289 "\t select from [primary, overlay], default is [primary]\n"
Jia Meng8f94a102015-08-11 16:24:19 +0800290 "\t --sync set analyzer in sync mode\n"
Jia Meng0a532932015-10-15 08:44:09 -0400291 "\t -r raw_input specify the path of raw image as fake source instead of live camera\n"
ShincyTue521cf92015-03-27 15:13:51 +0800292 "\t -h help\n"
Yinhang Liuc2f19082015-08-28 12:27:48 +0800293#if HAVE_LIBCL
Yinhang Liu81c44e02015-06-03 15:47:48 +0800294 "CL features:\n"
wujunkai166a84ba052015-09-08 15:54:12 +0800295 "\t --capture capture_stage specify the capture stage of image\n"
296 "\t capture_stage select from [bayer, tonemapping], default is [tonemapping]\n"
Yinhang Liu81c44e02015-06-03 15:47:48 +0800297 "\t --hdr specify hdr type, default is hdr off\n"
298 "\t select from [rgb, lab]\n"
299 "\t --tnr specify temporal noise reduction type, default is tnr off\n"
300 "\t select from [rgb, yuv, both]\n"
301 "\t --tnr-level specify tnr level\n"
Yinhang Liub92930c2015-06-23 16:26:35 +0800302 "\t --bilateral enable bilateral noise reduction\n"
Yinhang Liu81c44e02015-06-03 15:47:48 +0800303 "\t --enable-snr enable simple noise reduction\n"
Jia Meng66efecf2015-06-17 11:11:10 +0000304 "\t --enable-ee enable YEENR\n"
ShincyTu63e2c262015-06-26 10:52:51 +0800305 "\t --enable-bnr enable bayer noise reduction\n"
Yinhang Liue26b2622015-07-21 18:32:36 +0800306 "\t --enable-dpc enable defect pixel correction\n"
Jia Menga6580232015-10-08 16:51:28 +0800307 "\t --enable-wdr enable wdr\n"
Wangfei1487b9b2015-08-28 15:10:39 +0800308 "\t --pipeline pipe mode\n"
Wangfei16b65db2015-09-11 14:44:28 +0800309 "\t select from [basic, advance, extreme], default is [basic]\n"
Yinhang Liue26b2622015-07-21 18:32:36 +0800310 "(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 +0800311#endif
Wind Yuan75564b12015-01-15 06:51:15 -0500312 , bin_name
313 , DEFAULT_SAVE_FILE_NAME);
314}
315
316int main (int argc, char *argv[])
317{
318 XCamReturn ret = XCAM_RETURN_NO_ERROR;
319 SmartPtr<MainDeviceManager> device_manager = new MainDeviceManager;
320 SmartPtr<V4l2Device> device;
321 SmartPtr<V4l2SubDevice> event_device;
322 SmartPtr<IspController> isp_controller;
323 SmartPtr<X3aAnalyzer> analyzer;
zongwave03954a32015-09-22 15:40:44 +0800324 SmartPtr<X3aAnalyzerLoader> loader;
Jia Meng9724cfe2015-08-12 15:04:45 +0800325 const char *path_of_3a;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800326 SmartPtr<ImageProcessor> isp_processor;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800327#if HAVE_LIBCL
wangfeicf4c4e72015-05-25 17:11:41 +0800328 SmartPtr<CLCscImageProcessor> cl_csc_proccessor;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800329#endif
Wind Yuan26e9e212015-04-16 15:55:45 +0800330 AnalyzerType analyzer_type = AnalyzerTypeSimple;
wangfeicf4c4e72015-05-25 17:11:41 +0800331 DrmDisplayMode display_mode = DRM_DISPLAY_MODE_PRIMARY;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800332#if HAVE_LIBDRM
333 SmartPtr<DrmDisplay> drm_disp = DrmDisplay::instance();
334#endif
335
Wind Yuand4427312015-02-11 16:09:00 +0800336#if HAVE_LIBCL
Wind Yuane4ba0c92015-03-26 16:59:06 +0800337 SmartPtr<CL3aImageProcessor> cl_processor;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800338 uint32_t hdr_type = CL_HDR_DISABLE;
339 uint32_t tnr_type = CL_TNR_DISABLE;
340 uint32_t denoise_type = 0;
341 uint8_t tnr_level = 0;
342 bool dpc_type = false;
Wangfei1487b9b2015-08-28 15:10:39 +0800343 CL3aImageProcessor::PipelineProfile pipeline_mode = CL3aImageProcessor::BasicPipelineProfile;
wujunkai166a84ba052015-09-08 15:54:12 +0800344 CL3aImageProcessor::CaptureStage capture_stage = CL3aImageProcessor::TonemappingStage;
Wind Yuand4427312015-02-11 16:09:00 +0800345#endif
346 bool have_cl_processor = false;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800347 bool need_display = false;
Wind Yuand4427312015-02-11 16:09:00 +0800348 enum v4l2_memory v4l2_mem_type = V4L2_MEMORY_MMAP;
Wind Yuan75564b12015-01-15 06:51:15 -0500349 const char *bin_name = argv[0];
350 int opt;
ShincyTu2808b592015-03-13 17:17:25 +0800351 uint32_t capture_mode = V4L2_CAPTURE_MODE_VIDEO;
352 uint32_t pixel_format = V4L2_PIX_FMT_NV12;
yaowang16e051152015-08-14 13:49:03 +0800353 bool tonemapping_type = false;
Jia Menga6580232015-10-08 16:51:28 +0800354 bool wdr_type = false;
yaowang1a5f12122015-07-27 14:53:38 +0800355 int32_t brightness_level = 128;
Sameer Kibey7b429292015-08-07 10:55:38 -0700356 bool have_usbcam = 0;
357 char* usb_device_name = NULL;
Jia Meng8f94a102015-08-11 16:24:19 +0800358 bool sync_mode = false;
Jia Meng757f3c92015-09-09 11:18:36 +0800359 int frame_rate;
Jia Meng0a532932015-10-15 08:44:09 -0400360 char *path_to_fake = NULL;
Wind Yuan75564b12015-01-15 06:51:15 -0500361
Jia Meng0a532932015-10-15 08:44:09 -0400362 const char *short_opts = "sca:n:m:f:d:b:pi:e:r:h";
Yinhang Liu81c44e02015-06-03 15:47:48 +0800363 const struct option long_opts[] = {
364 {"hdr", required_argument, NULL, 'H'},
365 {"tnr", required_argument, NULL, 'T'},
366 {"tnr-level", required_argument, NULL, 'L'},
Yinhang Liub92930c2015-06-23 16:26:35 +0800367 {"bilateral", no_argument, NULL, 'I'},
Yinhang Liu81c44e02015-06-03 15:47:48 +0800368 {"enable-snr", no_argument, NULL, 'S'},
Jia Meng66efecf2015-06-17 11:11:10 +0000369 {"enable-ee", no_argument, NULL, 'E'},
ShincyTu63e2c262015-06-26 10:52:51 +0800370 {"enable-bnr", no_argument, NULL, 'B'},
Yinhang Liue26b2622015-07-21 18:32:36 +0800371 {"enable-dpc", no_argument, NULL, 'D'},
Jia Menga6580232015-10-08 16:51:28 +0800372 {"enable-wdr", no_argument, NULL, 'W'},
Sameer Kibey7b429292015-08-07 10:55:38 -0700373 {"usb", required_argument, NULL, 'U'},
Jia Meng8f94a102015-08-11 16:24:19 +0800374 {"sync", no_argument, NULL, 'Y'},
wujunkai166a84ba052015-09-08 15:54:12 +0800375 {"capture", required_argument, NULL, 'C'},
Wangfei1487b9b2015-08-28 15:10:39 +0800376 {"pipeline", required_argument, NULL, 'P'},
Yinhang Liu81c44e02015-06-03 15:47:48 +0800377 {0, 0, 0, 0},
378 };
379
380 while ((opt = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
Wind Yuan75564b12015-01-15 06:51:15 -0500381 switch (opt) {
382 case 'a': {
Wind Yuane25ce3f2015-05-04 18:07:29 +0800383 if (!strcmp (optarg, "dynamic"))
384 analyzer_type = AnalyzerTypeDynamic;
385 else if (!strcmp (optarg, "simple"))
Wind Yuan26e9e212015-04-16 15:55:45 +0800386 analyzer_type = AnalyzerTypeSimple;
Wind Yuan75564b12015-01-15 06:51:15 -0500387#if HAVE_IA_AIQ
388 else if (!strcmp (optarg, "aiq"))
Wind Yuan26e9e212015-04-16 15:55:45 +0800389 analyzer_type = AnalyzerTypeAiq;
Jia Meng9724cfe2015-08-12 15:04:45 +0800390 else if (!strcmp (optarg, "hybrid"))
391 analyzer_type = AnalyzerTypeHybrid;
Wind Yuan75564b12015-01-15 06:51:15 -0500392#endif
393 else {
394 print_help (bin_name);
395 return -1;
396 }
397 break;
398 }
399
Wind Yuand4427312015-02-11 16:09:00 +0800400 case 'm': {
401 if (!strcmp (optarg, "dma"))
402 v4l2_mem_type = V4L2_MEMORY_DMABUF;
403 else if (!strcmp (optarg, "mmap"))
404 v4l2_mem_type = V4L2_MEMORY_MMAP;
405 else
406 print_help (bin_name);
407 break;
408 }
409
Wind Yuan75564b12015-01-15 06:51:15 -0500410 case 's':
411 device_manager->enable_save_file (true);
412 break;
413 case 'n':
414 device_manager->set_interval (atoi(optarg));
415 break;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800416#if HAVE_LIBCL
Wind Yuand4427312015-02-11 16:09:00 +0800417 case 'c':
418 have_cl_processor = true;
419 break;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800420#endif
ShincyTu2808b592015-03-13 17:17:25 +0800421 case 'f':
ShincyTuc8466402015-03-31 11:03:39 +0800422 CHECK_EXP ((strlen(optarg) == 4), "invalid pixel format\n");
423 pixel_format = v4l2_fourcc ((unsigned)optarg[0],
424 (unsigned)optarg[1],
425 (unsigned)optarg[2],
426 (unsigned)optarg[3]);
ShincyTu2808b592015-03-13 17:17:25 +0800427 break;
428 case 'd':
429 if (!strcmp (optarg, "still"))
430 capture_mode = V4L2_CAPTURE_MODE_STILL;
431 else if (!strcmp (optarg, "video"))
432 capture_mode = V4L2_CAPTURE_MODE_VIDEO;
433 else {
434 print_help (bin_name);
435 return -1;
436 }
437 break;
yaowang1a5f12122015-07-27 14:53:38 +0800438 case 'b':
439 brightness_level = atoi(optarg);
440 if(brightness_level < 0 || brightness_level > 256) {
441 print_help (bin_name);
442 return -1;
443 }
444 break;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800445 case 'p':
446 need_display = true;
447 break;
Sameer Kibey7b429292015-08-07 10:55:38 -0700448 case 'U':
449 have_usbcam = true;
450 usb_device_name = strdup(optarg);
451 XCAM_LOG_DEBUG("using USB camera plugged in at node: %s", usb_device_name);
452 break;
wangfeicf4c4e72015-05-25 17:11:41 +0800453 case 'e': {
454 if (!strcmp (optarg, "primary"))
455 display_mode = DRM_DISPLAY_MODE_PRIMARY;
456 else if (!strcmp (optarg, "overlay"))
457 display_mode = DRM_DISPLAY_MODE_OVERLAY;
458 else {
459 print_help (bin_name);
460 return -1;
461 }
462 break;
463 }
ShincyTue521cf92015-03-27 15:13:51 +0800464 case 'i':
465 device_manager->set_frame_save(atoi(optarg));
466 break;
Jia Meng8f94a102015-08-11 16:24:19 +0800467 case 'Y':
468 sync_mode = true;
469 break;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800470#if HAVE_LIBCL
Yinhang Liu81c44e02015-06-03 15:47:48 +0800471 case 'H': {
472 if (!strcasecmp (optarg, "rgb"))
473 hdr_type = CL_HDR_TYPE_RGB;
474 else if (!strcasecmp (optarg, "lab"))
475 hdr_type = CL_HDR_TYPE_LAB;
476 else {
477 print_help (bin_name);
478 return -1;
479 }
480 break;
481 }
Yinhang Liub92930c2015-06-23 16:26:35 +0800482 case 'I': {
Jia Meng66efecf2015-06-17 11:11:10 +0000483 denoise_type |= XCAM_DENOISE_TYPE_BILATERAL;
Juan Zhaod9664932015-09-08 10:22:19 +0800484 denoise_type |= XCAM_DENOISE_TYPE_BIYUV;
Yinhang Liu81c44e02015-06-03 15:47:48 +0800485 break;
486 }
487 case 'S': {
Jia Meng66efecf2015-06-17 11:11:10 +0000488 denoise_type |= XCAM_DENOISE_TYPE_SIMPLE;
489 break;
490 }
491 case 'E': {
492 denoise_type |= XCAM_DENOISE_TYPE_EE;
Yinhang Liu81c44e02015-06-03 15:47:48 +0800493 break;
494 }
ShincyTu63e2c262015-06-26 10:52:51 +0800495 case 'B': {
496 denoise_type |= XCAM_DENOISE_TYPE_BNR;
497 break;
498 }
Yinhang Liue26b2622015-07-21 18:32:36 +0800499 case 'D': {
500 dpc_type = true;
501 break;
502 }
Yinhang Liu81c44e02015-06-03 15:47:48 +0800503 case 'T': {
504 if (!strcasecmp (optarg, "yuv"))
505 tnr_type = CL_TNR_TYPE_YUV;
506 else if (!strcasecmp (optarg, "rgb"))
507 tnr_type = CL_TNR_TYPE_RGB;
508 else if (!strcasecmp (optarg, "both"))
509 tnr_type = CL_TNR_TYPE_YUV | CL_TNR_TYPE_RGB;
510 else {
511 print_help (bin_name);
512 return -1;
513 }
514 break;
515 }
516 case 'L': {
517 if (atoi(optarg) < 0 || atoi(optarg) > 255) {
518 print_help (bin_name);
519 return -1;
520 }
521 tnr_level = atoi(optarg);
522 break;
523 }
Jia Menga6580232015-10-08 16:51:28 +0800524 case 'W': {
525 wdr_type = true;
wujunkai166fd374802015-10-15 16:50:06 +0800526 tonemapping_type = true;
527 pixel_format = V4L2_PIX_FMT_SGRBG12;
wujunkai16682950fb2015-10-19 18:09:05 +0800528
529 setenv ("AIQ_CPF_PATH", IMX185_WDR_CPF, 1);
Jia Menga6580232015-10-08 16:51:28 +0800530 break;
531 }
Wangfei1487b9b2015-08-28 15:10:39 +0800532 case 'P': {
533 if (!strcasecmp (optarg, "basic"))
534 pipeline_mode = CL3aImageProcessor::BasicPipelineProfile;
535 else if (!strcasecmp (optarg, "advance"))
536 pipeline_mode = CL3aImageProcessor::AdvancedPipelineProfile;
Wangfei16b65db2015-09-11 14:44:28 +0800537 else if (!strcasecmp (optarg, "extreme"))
538 pipeline_mode = CL3aImageProcessor::ExtremePipelineProfile;
Wangfei1487b9b2015-08-28 15:10:39 +0800539 else {
540 print_help (bin_name);
541 return -1;
542 }
543 break;
544 }
wujunkai166a84ba052015-09-08 15:54:12 +0800545 case 'C': {
546 if (!strcmp (optarg, "bayer"))
547 capture_stage = CL3aImageProcessor::BasicbayerStage;
548 break;
549 }
Yinhang Liuc2f19082015-08-28 12:27:48 +0800550#endif
Jia Meng0a532932015-10-15 08:44:09 -0400551 case 'r': {
552 if (optarg) {
553 XCAM_LOG_INFO ("use raw image %s as input source", optarg);
554 path_to_fake = strdup(optarg);
555 }
556 break;
557 }
Wind Yuan75564b12015-01-15 06:51:15 -0500558 case 'h':
559 print_help (bin_name);
560 return 0;
561
562 default:
563 print_help (bin_name);
564 return -1;
565 }
566 }
567
wangfeicf4c4e72015-05-25 17:11:41 +0800568 if (need_display) {
Wind Yuan683f8662015-03-27 18:52:38 +0800569 device_manager->enable_display (true);
wangfeicf4c4e72015-05-25 17:11:41 +0800570 device_manager->set_display_mode (display_mode);
571 }
ShincyTu2808b592015-03-13 17:17:25 +0800572 if (!device.ptr ()) {
Jia Meng0a532932015-10-15 08:44:09 -0400573 if (path_to_fake) {
574 device = new FakeV4l2Device ();
575 } else if (have_usbcam) {
Sameer Kibey7b429292015-08-07 10:55:38 -0700576 device = new UVCDevice (usb_device_name);
577 } else {
578 if (capture_mode == V4L2_CAPTURE_MODE_STILL)
579 device = new AtomispDevice (CAPTURE_DEVICE_STILL);
580 else if (capture_mode == V4L2_CAPTURE_MODE_VIDEO)
581 device = new AtomispDevice (CAPTURE_DEVICE_VIDEO);
582 else
583 device = new AtomispDevice (DEFAULT_CAPTURE_DEVICE);
584 }
ShincyTu2808b592015-03-13 17:17:25 +0800585 }
Wind Yuan75564b12015-01-15 06:51:15 -0500586 if (!event_device.ptr ())
587 event_device = new V4l2SubDevice (DEFAULT_EVENT_DEVICE);
588 if (!isp_controller.ptr ())
589 isp_controller = new IspController (device);
Wind Yuan26e9e212015-04-16 15:55:45 +0800590
591 switch (analyzer_type) {
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800592 case AnalyzerTypeSimple:
593 analyzer = new X3aAnalyzerSimple ();
594 break;
Wind Yuan26e9e212015-04-16 15:55:45 +0800595#if HAVE_IA_AIQ
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800596 case AnalyzerTypeAiq:
597 analyzer = new X3aAnalyzerAiq (isp_controller, DEFAULT_CPF_FILE);
598 break;
Jia Meng9724cfe2015-08-12 15:04:45 +0800599 case AnalyzerTypeHybrid: {
Jia Mengc54c3322015-08-26 09:45:18 +0800600 path_of_3a = DEFAULT_HYBRID_3A_LIB;
zongwave03954a32015-09-22 15:40:44 +0800601 loader = new X3aAnalyzerLoader (path_of_3a);
Jia Meng9724cfe2015-08-12 15:04:45 +0800602 analyzer = loader->load_hybrid_analyzer (loader, isp_controller, DEFAULT_CPF_FILE);
603 CHECK_EXP (analyzer.ptr (), "load hybrid 3a lib(%s) failed", path_of_3a);
604 break;
605 }
Wind Yuan26e9e212015-04-16 15:55:45 +0800606#endif
Wind Yuane25ce3f2015-05-04 18:07:29 +0800607 case AnalyzerTypeDynamic: {
Jia Meng9724cfe2015-08-12 15:04:45 +0800608 path_of_3a = DEFAULT_DYNAMIC_3A_LIB;
zongwave03954a32015-09-22 15:40:44 +0800609 loader = new X3aAnalyzerLoader (path_of_3a);
Jia Meng9724cfe2015-08-12 15:04:45 +0800610 analyzer = loader->load_dynamic_analyzer (loader);
Wind Yuane25ce3f2015-05-04 18:07:29 +0800611 CHECK_EXP (analyzer.ptr (), "load dynamic 3a lib(%s) failed", path_of_3a);
612 break;
613 }
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800614 default:
615 print_help (bin_name);
616 return -1;
Wind Yuan26e9e212015-04-16 15:55:45 +0800617 }
Jia Meng8f94a102015-08-11 16:24:19 +0800618 XCAM_ASSERT (analyzer.ptr ());
619 analyzer->set_sync_mode (sync_mode);
Wind Yuan75564b12015-01-15 06:51:15 -0500620
621 signal(SIGINT, dev_stop_handler);
622
623 device->set_sensor_id (0);
ShincyTu2808b592015-03-13 17:17:25 +0800624 device->set_capture_mode (capture_mode);
Wind Yuan75564b12015-01-15 06:51:15 -0500625 //device->set_mem_type (V4L2_MEMORY_DMABUF);
Wind Yuand4427312015-02-11 16:09:00 +0800626 device->set_mem_type (v4l2_mem_type);
Wind Yuan75564b12015-01-15 06:51:15 -0500627 device->set_buffer_count (8);
Jia Meng757f3c92015-09-09 11:18:36 +0800628 if (pixel_format == V4L2_PIX_FMT_SGRBG12) {
629 frame_rate = 30;
630 device->set_framerate (frame_rate, 1);
631 }
632 else {
633 frame_rate = 25;
634 device->set_framerate (frame_rate, 1);
wujunkai166a9a55f22015-10-10 15:53:32 +0800635 if(tonemapping_type == true) {
636 XCAM_LOG_WARNING("Tonemapping is only applicable under BA12 format. Disable tonemapping automatically.");
637 tonemapping_type = false;
638 }
Jia Meng757f3c92015-09-09 11:18:36 +0800639 }
Wind Yuan75564b12015-01-15 06:51:15 -0500640 ret = device->open ();
641 CHECK (ret, "device(%s) open failed", device->get_device_name());
ShincyTu2808b592015-03-13 17:17:25 +0800642 ret = device->set_format (1920, 1080, pixel_format, V4L2_FIELD_NONE, 1920 * 2);
Wind Yuan75564b12015-01-15 06:51:15 -0500643 CHECK (ret, "device(%s) set format failed", device->get_device_name());
644
645 ret = event_device->open ();
Wind Yuanb67045c2015-08-27 13:50:53 +0800646 if (ret == XCAM_RETURN_NO_ERROR) {
647 CHECK (ret, "event device(%s) open failed", event_device->get_device_name());
648 int event = V4L2_EVENT_ATOMISP_3A_STATS_READY;
649 ret = event_device->subscribe_event (event);
650 CHECK_CONTINUE (
651 ret,
652 "device(%s) subscribe event(%d) failed",
653 event_device->get_device_name(), event);
654 event = V4L2_EVENT_FRAME_SYNC;
655 ret = event_device->subscribe_event (event);
656 CHECK_CONTINUE (
657 ret,
658 "device(%s) subscribe event(%d) failed",
659 event_device->get_device_name(), event);
660
661 device_manager->set_event_device (event_device);
662 }
Wind Yuan75564b12015-01-15 06:51:15 -0500663
664 device_manager->set_capture_device (device);
Wind Yuan75564b12015-01-15 06:51:15 -0500665 device_manager->set_isp_controller (isp_controller);
666 if (analyzer.ptr())
zongwave03954a32015-09-22 15:40:44 +0800667 device_manager->set_3a_analyzer (analyzer);
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800668
669 if (have_cl_processor)
670 isp_processor = new IspExposureImageProcessor (isp_controller);
671 else
672 isp_processor = new IspImageProcessor (isp_controller);
673
674 XCAM_ASSERT (isp_processor.ptr ());
Wind Yuane4ba0c92015-03-26 16:59:06 +0800675 device_manager->add_image_processor (isp_processor);
Yinhang Liuc2f19082015-08-28 12:27:48 +0800676#if HAVE_LIBCL
wangfeicf4c4e72015-05-25 17:11:41 +0800677 if ((display_mode == DRM_DISPLAY_MODE_PRIMARY) && need_display && (!have_cl_processor)) {
678 cl_csc_proccessor = new CLCscImageProcessor();
679 XCAM_ASSERT (cl_csc_proccessor.ptr ());
680 device_manager->add_image_processor (cl_csc_proccessor);
681 }
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800682
Wind Yuand4427312015-02-11 16:09:00 +0800683 if (have_cl_processor) {
Wind Yuane4ba0c92015-03-26 16:59:06 +0800684 cl_processor = new CL3aImageProcessor ();
Wind Yuan7ddf2602015-04-14 18:49:45 +0800685 cl_processor->set_stats_callback(device_manager);
Yinhang Liue26b2622015-07-21 18:32:36 +0800686 cl_processor->set_dpc(dpc_type);
Yinhang Liu81c44e02015-06-03 15:47:48 +0800687 cl_processor->set_hdr (hdr_type);
Jia Meng66efecf2015-06-17 11:11:10 +0000688 cl_processor->set_denoise (denoise_type);
yaowang16e051152015-08-14 13:49:03 +0800689 cl_processor->set_tonemapping(tonemapping_type);
Jia Menga6580232015-10-08 16:51:28 +0800690 cl_processor->set_gamma (!wdr_type); // disable gamma for WDR
wujunkai166a84ba052015-09-08 15:54:12 +0800691 cl_processor->set_capture_stage (capture_stage);
Wind Yuane4ba0c92015-03-26 16:59:06 +0800692 if (need_display) {
693 cl_processor->set_output_format (V4L2_PIX_FMT_XBGR32);
694 }
Yinhang Liu81c44e02015-06-03 15:47:48 +0800695 cl_processor->set_tnr (tnr_type, tnr_level);
Wangfei1487b9b2015-08-28 15:10:39 +0800696 cl_processor->set_profile (pipeline_mode);
yaowang1a5f12122015-07-27 14:53:38 +0800697 analyzer->set_parameter_brightness((brightness_level - 128) / 128.0);
Wind Yuand4427312015-02-11 16:09:00 +0800698 device_manager->add_image_processor (cl_processor);
699 }
700#endif
Wind Yuane4ba0c92015-03-26 16:59:06 +0800701
Jia Meng0a532932015-10-15 08:44:09 -0400702 SmartPtr<PollThread> poll_thread;
703 if (path_to_fake)
704 poll_thread = new FakePollThread (path_to_fake);
705 else
706 poll_thread = new PollThread ();
707 device_manager->set_poll_thread (poll_thread);
708
Wind Yuan75564b12015-01-15 06:51:15 -0500709 ret = device_manager->start ();
710 CHECK (ret, "device manager start failed");
711
Jia Meng757f3c92015-09-09 11:18:36 +0800712 // hard code exposure range and max gain for imx185 WDR
Jia Menga6580232015-10-08 16:51:28 +0800713 if (wdr_type) {
Jia Meng757f3c92015-09-09 11:18:36 +0800714 if (frame_rate == 30)
715 analyzer->set_ae_exposure_time_range (80 * 1110 * 1000 / 37125, 1120 * 1110 * 1000 / 37125);
716 else
Jia Menga6580232015-10-08 16:51:28 +0800717 analyzer->set_ae_exposure_time_range (80 * 1320 * 1000 / 37125, 1120 * 1320 * 1000 / 37125);
Jia Meng757f3c92015-09-09 11:18:36 +0800718 analyzer->set_ae_max_analog_gain (3.98); // 12dB
719 }
720
Wind Yuan75564b12015-01-15 06:51:15 -0500721 // wait for interruption
722 {
723 SmartLock locker (g_mutex);
724 while (!g_stop)
725 g_cond.wait (g_mutex);
726 }
727
728 ret = device_manager->stop();
729 CHECK_CONTINUE (ret, "device manager stop failed");
730 device->close ();
731 event_device->close ();
Jia Meng0a532932015-10-15 08:44:09 -0400732 if (usb_device_name)
733 free (usb_device_name);
734 if (path_to_fake)
735 free (path_to_fake);
Wind Yuan75564b12015-01-15 06:51:15 -0500736
737 return 0;
738}