blob: 9c5b42443b098bb1e7614a0d95eba76fa2967cbe [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)
Yinhang Liud9346492015-12-17 11:14:25 +080067 , _frame_width (0)
68 , _frame_height (0)
Wind Yuan75564b12015-01-15 06:51:15 -050069 , _frame_count (0)
ShincyTue521cf92015-03-27 15:13:51 +080070 , _frame_save (0)
Wind Yuan683f8662015-03-27 18:52:38 +080071 , _enable_display (false)
Wind Yuane4ba0c92015-03-26 16:59:06 +080072 {
73#if HAVE_LIBDRM
74 _display = DrmDisplay::instance();
75#endif
Wind Yuan91625802015-06-24 15:36:01 +080076 XCAM_OBJ_PROFILING_INIT;
Wind Yuane4ba0c92015-03-26 16:59:06 +080077 }
Wind Yuan75564b12015-01-15 06:51:15 -050078
79 ~MainDeviceManager () {
80 close_file ();
81 }
82
83 void enable_save_file (bool enable) {
84 _save_file = enable;
85 }
Yinhang Liud9346492015-12-17 11:14:25 +080086
Wind Yuan75564b12015-01-15 06:51:15 -050087 void set_interval (uint32_t inteval) {
88 _interval = inteval;
89 }
Yinhang Liud9346492015-12-17 11:14:25 +080090
91 void set_frame_width (uint32_t frame_width) {
92 _frame_width = frame_width;
93 }
94
95 void set_frame_height (uint32_t frame_height) {
96 _frame_height = frame_height;
97 }
98
ShincyTue521cf92015-03-27 15:13:51 +080099 void set_frame_save (uint32_t frame_save) {
100 _frame_save = frame_save;
101 }
Wind Yuan75564b12015-01-15 06:51:15 -0500102
Wind Yuan683f8662015-03-27 18:52:38 +0800103 void enable_display(bool value) {
104 _enable_display = value;
105 }
106
wangfeicf4c4e72015-05-25 17:11:41 +0800107 void set_display_mode(DrmDisplayMode mode) {
108 _display->set_display_mode (mode);
109 }
110
Wind Yuan75564b12015-01-15 06:51:15 -0500111protected:
Wind Yuan73af3932015-07-02 17:52:43 +0800112 virtual void handle_message (const SmartPtr<XCamMessage> &msg);
113 virtual void handle_buffer (const SmartPtr<VideoBuffer> &buf);
Wind Yuan75564b12015-01-15 06:51:15 -0500114
Wind Yuan73af3932015-07-02 17:52:43 +0800115 int display_buf (const SmartPtr<VideoBuffer> &buf);
Wind Yuane4ba0c92015-03-26 16:59:06 +0800116
Wind Yuan75564b12015-01-15 06:51:15 -0500117private:
118 void open_file ();
119 void close_file ();
Wind Yuan71111322016-02-24 22:56:27 +0800120 XCamReturn write_buf (const SmartPtr<VideoBuffer> &buf);
Wind Yuan75564b12015-01-15 06:51:15 -0500121
122 FILE *_file;
123 bool _save_file;
124 uint32_t _interval;
Yinhang Liud9346492015-12-17 11:14:25 +0800125 uint32_t _frame_width;
126 uint32_t _frame_height;
Wind Yuan75564b12015-01-15 06:51:15 -0500127 uint32_t _frame_count;
ShincyTue521cf92015-03-27 15:13:51 +0800128 uint32_t _frame_save;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800129 SmartPtr<DrmDisplay> _display;
Wind Yuan683f8662015-03-27 18:52:38 +0800130 bool _enable_display;
Wind Yuan91625802015-06-24 15:36:01 +0800131 XCAM_OBJ_PROFILING_DEFINES;
Wind Yuan75564b12015-01-15 06:51:15 -0500132};
133
134void
Wind Yuan73af3932015-07-02 17:52:43 +0800135MainDeviceManager::handle_message (const SmartPtr<XCamMessage> &msg)
Wind Yuan75564b12015-01-15 06:51:15 -0500136{
137 XCAM_UNUSED (msg);
138}
139
140void
Wind Yuan73af3932015-07-02 17:52:43 +0800141MainDeviceManager::handle_buffer (const SmartPtr<VideoBuffer> &buf)
Wind Yuan75564b12015-01-15 06:51:15 -0500142{
Wind Yuan683f8662015-03-27 18:52:38 +0800143 FPS_CALCULATION (fps_buf, 30);
144
Wind Yuan91625802015-06-24 15:36:01 +0800145 XCAM_OBJ_PROFILING_START;
146
Wind Yuan683f8662015-03-27 18:52:38 +0800147 if (_enable_display)
148 display_buf (buf);
Wind Yuane4ba0c92015-03-26 16:59:06 +0800149
Wind Yuan91625802015-06-24 15:36:01 +0800150 XCAM_OBJ_PROFILING_END("main_dev_manager_display", 30);
151
Wind Yuan75564b12015-01-15 06:51:15 -0500152 if (!_save_file)
153 return ;
154
155 if ((_frame_count++ % _interval) != 0)
156 return;
157
ShincyTue521cf92015-03-27 15:13:51 +0800158 if ((_frame_save != 0) && (_frame_count > _frame_save)) {
159 SmartLock locker (g_mutex);
160 g_stop = true;
161 g_cond.broadcast ();
162 return;
163 }
164
Wind Yuan75564b12015-01-15 06:51:15 -0500165 open_file ();
Jia Meng6c9241d2015-06-12 11:08:45 +0000166
167 if (!_file) {
168 XCAM_LOG_ERROR ("open file failed");
Jia Meng54a2dcb2015-08-20 15:23:47 +0800169 return;
Jia Meng6c9241d2015-06-12 11:08:45 +0000170 }
Wind Yuan71111322016-02-24 22:56:27 +0800171 write_buf (buf);
Wind Yuan75564b12015-01-15 06:51:15 -0500172}
173
Wind Yuane4ba0c92015-03-26 16:59:06 +0800174int
Wind Yuan73af3932015-07-02 17:52:43 +0800175MainDeviceManager::display_buf (const SmartPtr<VideoBuffer> &data)
Wind Yuane4ba0c92015-03-26 16:59:06 +0800176{
177#if HAVE_LIBDRM
178 XCamReturn ret = XCAM_RETURN_NO_ERROR;
Wind Yuan73af3932015-07-02 17:52:43 +0800179 SmartPtr<VideoBuffer> buf = data;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800180 const VideoBufferInfo & frame_info = buf->get_video_info ();
181 struct v4l2_rect rect = { 0, 0, (int)frame_info.width, (int)frame_info.height };
182
183 if (!_display->is_render_inited ()) {
Yinhang Liud9346492015-12-17 11:14:25 +0800184 ret = _display->render_init (0, 0, this->_frame_width, this->_frame_height,
185 frame_info.format, &rect);
Wind Yuane4ba0c92015-03-26 16:59:06 +0800186 CHECK (ret, "display failed on render_init");
187 }
188 ret = _display->render_setup_frame_buffer (buf);
189 CHECK (ret, "display failed on framebuf set");
190 ret = _display->render_buffer (buf);
191 CHECK (ret, "display failed on rendering");
192#endif
193 return 0;
194}
195
196
Wind Yuan75564b12015-01-15 06:51:15 -0500197void
198MainDeviceManager::open_file ()
199{
ShincyTue521cf92015-03-27 15:13:51 +0800200 if ((_file) && (_frame_save == 0))
Wind Yuan75564b12015-01-15 06:51:15 -0500201 return;
ShincyTue521cf92015-03-27 15:13:51 +0800202
203 std::string file_name = DEFAULT_SAVE_FILE_NAME;
204
205 if (_frame_save != 0) {
206 file_name += std::to_string(_frame_count);
207 }
208 file_name += ".raw";
209
210 _file = fopen(file_name.c_str(), "wb");
Wind Yuan75564b12015-01-15 06:51:15 -0500211}
212
213void
214MainDeviceManager::close_file ()
215{
216 if (_file)
217 fclose (_file);
218 _file = NULL;
219}
220
Wind Yuan71111322016-02-24 22:56:27 +0800221XCamReturn
222MainDeviceManager::write_buf (const SmartPtr<VideoBuffer> &buf)
223{
224 const VideoBufferInfo &info = buf->get_video_info ();
225 VideoBufferPlanarInfo planar;
226 uint8_t *memory = NULL;
227 XCamReturn ret = XCAM_RETURN_NO_ERROR;
228
229 memory = buf->map ();
230 if (!memory) {
231 XCAM_LOG_ERROR ("map buffer failed in write_buf");
232 return XCAM_RETURN_ERROR_MEM;
233 }
234
235 for (uint32_t index = 0; index < info.components; index++) {
236 info.get_planar_info (planar, index);
237 uint32_t line_bytes = planar.width * planar.pixel_bytes;
238
239 for (uint32_t i = 0; i < planar.height; i++) {
240 if (fwrite (memory + info.offsets [index] + i * info.strides [index], 1, line_bytes, _file) != line_bytes) {
241 XCAM_LOG_ERROR ("write file failed, size doesn't match");
242 ret = XCAM_RETURN_ERROR_FILE;
243 }
244 }
245 }
246 buf->unmap ();
247 return ret;
248}
249
Wind Yuan75564b12015-01-15 06:51:15 -0500250#define V4L2_CAPTURE_MODE_STILL 0x2000
251#define V4L2_CAPTURE_MODE_VIDEO 0x4000
252#define V4L2_CAPTURE_MODE_PREVIEW 0x8000
253
Wind Yuan26e9e212015-04-16 15:55:45 +0800254typedef enum {
255 AnalyzerTypeSimple = 0,
256 AnalyzerTypeAiq,
Wind Yuane25ce3f2015-05-04 18:07:29 +0800257 AnalyzerTypeDynamic,
Jia Meng9724cfe2015-08-12 15:04:45 +0800258 AnalyzerTypeHybrid,
Wind Yuan26e9e212015-04-16 15:55:45 +0800259} AnalyzerType;
260
Wind Yuan75564b12015-01-15 06:51:15 -0500261void dev_stop_handler(int sig)
262{
263 XCAM_UNUSED (sig);
264
265 SmartLock locker (g_mutex);
266 g_stop = true;
267 g_cond.broadcast ();
268
269 //exit(0);
270}
271
272void print_help (const char *bin_name)
273{
274 printf ("Usage: %s [-a analyzer]\n"
Yinhang Liu81c44e02015-06-03 15:47:48 +0800275 "Configurations:\n"
ShincyTue521cf92015-03-27 15:13:51 +0800276 "\t -a analyzer specify a analyzer\n"
Wind Yuane25ce3f2015-05-04 18:07:29 +0800277 "\t select from [simple, aiq, dynamic], default is [simple]\n"
ShincyTue521cf92015-03-27 15:13:51 +0800278 "\t -m mem_type specify video memory type\n"
279 "\t mem_type select from [dma, mmap], default is [mmap]\n"
280 "\t -s save file to %s\n"
281 "\t -n interval save file on every [interval] frame\n"
Yinhang Liuc2f19082015-08-28 12:27:48 +0800282#if HAVE_LIBCL
ShincyTue521cf92015-03-27 15:13:51 +0800283 "\t -c process image with cl kernel\n"
Yinhang Liuc2f19082015-08-28 12:27:48 +0800284#endif
ShincyTue521cf92015-03-27 15:13:51 +0800285 "\t -f pixel_fmt specify output pixel format\n"
wujunkai1669845b022015-08-27 15:59:27 +0800286 "\t pixel_fmt select from [NV12, YUYV, BA10, BA12], default is [NV12]\n"
ShincyTue521cf92015-03-27 15:13:51 +0800287 "\t -d cap_mode specify capture mode\n"
288 "\t cap_mode select from [video, still], default is [video]\n"
yaowang1a5f12122015-07-27 14:53:38 +0800289 "\t -b brightness specify brightness level\n"
290 "\t brightness level select from [0, 256], default is [128]\n"
ShincyTue521cf92015-03-27 15:13:51 +0800291 "\t -i frame_save specify the frame count to save, default is 0 which means endless\n"
wangfeicf4c4e72015-05-25 17:11:41 +0800292 "\t -p preview on local display\n"
Sameer Kibey7b429292015-08-07 10:55:38 -0700293 "\t --usb specify node for usb camera device, enables capture path through USB camera \n"
294 "\t specify [/dev/video4, /dev/video5] depending on which node USB camera is attached\n"
Yinhang Liud9346492015-12-17 11:14:25 +0800295 "\t --resolution specify the resolution of usb camera\n"
296 "\t select from [1920x1080, 1280x720 ...], default is [1920x1080]\n"
wangfeicf4c4e72015-05-25 17:11:41 +0800297 "\t -e display_mode preview mode\n"
298 "\t select from [primary, overlay], default is [primary]\n"
Jia Meng8f94a102015-08-11 16:24:19 +0800299 "\t --sync set analyzer in sync mode\n"
Jia Meng0a532932015-10-15 08:44:09 -0400300 "\t -r raw_input specify the path of raw image as fake source instead of live camera\n"
ShincyTue521cf92015-03-27 15:13:51 +0800301 "\t -h help\n"
Yinhang Liuc2f19082015-08-28 12:27:48 +0800302#if HAVE_LIBCL
Yinhang Liu81c44e02015-06-03 15:47:48 +0800303 "CL features:\n"
wujunkai166a84ba052015-09-08 15:54:12 +0800304 "\t --capture capture_stage specify the capture stage of image\n"
305 "\t capture_stage select from [bayer, tonemapping], default is [tonemapping]\n"
Yinhang Liu81c44e02015-06-03 15:47:48 +0800306 "\t --hdr specify hdr type, default is hdr off\n"
307 "\t select from [rgb, lab]\n"
308 "\t --tnr specify temporal noise reduction type, default is tnr off\n"
309 "\t select from [rgb, yuv, both]\n"
310 "\t --tnr-level specify tnr level\n"
Yinhang Liub92930c2015-06-23 16:26:35 +0800311 "\t --bilateral enable bilateral noise reduction\n"
Yinhang Liu81c44e02015-06-03 15:47:48 +0800312 "\t --enable-snr enable simple noise reduction\n"
Jia Meng66efecf2015-06-17 11:11:10 +0000313 "\t --enable-ee enable YEENR\n"
ShincyTu63e2c262015-06-26 10:52:51 +0800314 "\t --enable-bnr enable bayer noise reduction\n"
Yinhang Liue26b2622015-07-21 18:32:36 +0800315 "\t --enable-dpc enable defect pixel correction\n"
Jia Menga6580232015-10-08 16:51:28 +0800316 "\t --enable-wdr enable wdr\n"
wujunkai166b0bd5512016-02-18 18:25:42 +0800317 "\t --enable-new-wdr enable new wdr algorithm\n"
Wangfei8e5e3e42016-02-18 19:41:54 +0800318 "\t --enable-retinex enable retinex\n"
Wangfei1487b9b2015-08-28 15:10:39 +0800319 "\t --pipeline pipe mode\n"
Wangfei16b65db2015-09-11 14:44:28 +0800320 "\t select from [basic, advance, extreme], default is [basic]\n"
Yinhang Liue26b2622015-07-21 18:32:36 +0800321 "(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 +0800322#endif
Wind Yuan75564b12015-01-15 06:51:15 -0500323 , bin_name
324 , DEFAULT_SAVE_FILE_NAME);
325}
326
327int main (int argc, char *argv[])
328{
329 XCamReturn ret = XCAM_RETURN_NO_ERROR;
330 SmartPtr<MainDeviceManager> device_manager = new MainDeviceManager;
331 SmartPtr<V4l2Device> device;
332 SmartPtr<V4l2SubDevice> event_device;
333 SmartPtr<IspController> isp_controller;
334 SmartPtr<X3aAnalyzer> analyzer;
zongwave03954a32015-09-22 15:40:44 +0800335 SmartPtr<X3aAnalyzerLoader> loader;
Jia Meng9724cfe2015-08-12 15:04:45 +0800336 const char *path_of_3a;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800337 SmartPtr<ImageProcessor> isp_processor;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800338#if HAVE_LIBCL
wangfeicf4c4e72015-05-25 17:11:41 +0800339 SmartPtr<CLCscImageProcessor> cl_csc_proccessor;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800340#endif
Wind Yuan26e9e212015-04-16 15:55:45 +0800341 AnalyzerType analyzer_type = AnalyzerTypeSimple;
wangfeicf4c4e72015-05-25 17:11:41 +0800342 DrmDisplayMode display_mode = DRM_DISPLAY_MODE_PRIMARY;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800343#if HAVE_LIBDRM
344 SmartPtr<DrmDisplay> drm_disp = DrmDisplay::instance();
345#endif
346
Wind Yuand4427312015-02-11 16:09:00 +0800347#if HAVE_LIBCL
Wind Yuane4ba0c92015-03-26 16:59:06 +0800348 SmartPtr<CL3aImageProcessor> cl_processor;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800349 uint32_t hdr_type = CL_HDR_DISABLE;
350 uint32_t tnr_type = CL_TNR_DISABLE;
351 uint32_t denoise_type = 0;
352 uint8_t tnr_level = 0;
353 bool dpc_type = false;
Wangfei1487b9b2015-08-28 15:10:39 +0800354 CL3aImageProcessor::PipelineProfile pipeline_mode = CL3aImageProcessor::BasicPipelineProfile;
wujunkai166a84ba052015-09-08 15:54:12 +0800355 CL3aImageProcessor::CaptureStage capture_stage = CL3aImageProcessor::TonemappingStage;
Wind Yuand4427312015-02-11 16:09:00 +0800356#endif
357 bool have_cl_processor = false;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800358 bool need_display = false;
Wind Yuand4427312015-02-11 16:09:00 +0800359 enum v4l2_memory v4l2_mem_type = V4L2_MEMORY_MMAP;
Wind Yuan75564b12015-01-15 06:51:15 -0500360 const char *bin_name = argv[0];
361 int opt;
ShincyTu2808b592015-03-13 17:17:25 +0800362 uint32_t capture_mode = V4L2_CAPTURE_MODE_VIDEO;
363 uint32_t pixel_format = V4L2_PIX_FMT_NV12;
yaowang16e051152015-08-14 13:49:03 +0800364 bool tonemapping_type = false;
wujunkai166b0bd5512016-02-18 18:25:42 +0800365 bool newtonemapping_type = false;
Jia Menga6580232015-10-08 16:51:28 +0800366 bool wdr_type = false;
Wangfei8e5e3e42016-02-18 19:41:54 +0800367 bool retinex_type = false;
yaowang1a5f12122015-07-27 14:53:38 +0800368 int32_t brightness_level = 128;
Sameer Kibey7b429292015-08-07 10:55:38 -0700369 bool have_usbcam = 0;
370 char* usb_device_name = NULL;
Jia Meng8f94a102015-08-11 16:24:19 +0800371 bool sync_mode = false;
Jia Meng757f3c92015-09-09 11:18:36 +0800372 int frame_rate;
Yinhang Liud9346492015-12-17 11:14:25 +0800373 int frame_width = 1920;
374 int frame_height = 1080;
Jia Meng0a532932015-10-15 08:44:09 -0400375 char *path_to_fake = NULL;
Wind Yuan75564b12015-01-15 06:51:15 -0500376
Jia Meng0a532932015-10-15 08:44:09 -0400377 const char *short_opts = "sca:n:m:f:d:b:pi:e:r:h";
Yinhang Liu81c44e02015-06-03 15:47:48 +0800378 const struct option long_opts[] = {
379 {"hdr", required_argument, NULL, 'H'},
380 {"tnr", required_argument, NULL, 'T'},
381 {"tnr-level", required_argument, NULL, 'L'},
Yinhang Liub92930c2015-06-23 16:26:35 +0800382 {"bilateral", no_argument, NULL, 'I'},
Yinhang Liu81c44e02015-06-03 15:47:48 +0800383 {"enable-snr", no_argument, NULL, 'S'},
Jia Meng66efecf2015-06-17 11:11:10 +0000384 {"enable-ee", no_argument, NULL, 'E'},
ShincyTu63e2c262015-06-26 10:52:51 +0800385 {"enable-bnr", no_argument, NULL, 'B'},
Yinhang Liue26b2622015-07-21 18:32:36 +0800386 {"enable-dpc", no_argument, NULL, 'D'},
Jia Menga6580232015-10-08 16:51:28 +0800387 {"enable-wdr", no_argument, NULL, 'W'},
wujunkai166b0bd5512016-02-18 18:25:42 +0800388 {"enable-new-wdr", no_argument, NULL, 'N'},
Wangfei8e5e3e42016-02-18 19:41:54 +0800389 {"enable-retinex", no_argument, NULL, 'X'},
Sameer Kibey7b429292015-08-07 10:55:38 -0700390 {"usb", required_argument, NULL, 'U'},
Yinhang Liud9346492015-12-17 11:14:25 +0800391 {"resolution", required_argument, NULL, 'R'},
Jia Meng8f94a102015-08-11 16:24:19 +0800392 {"sync", no_argument, NULL, 'Y'},
wujunkai166a84ba052015-09-08 15:54:12 +0800393 {"capture", required_argument, NULL, 'C'},
Wangfei1487b9b2015-08-28 15:10:39 +0800394 {"pipeline", required_argument, NULL, 'P'},
Yinhang Liu81c44e02015-06-03 15:47:48 +0800395 {0, 0, 0, 0},
396 };
397
398 while ((opt = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
Wind Yuan75564b12015-01-15 06:51:15 -0500399 switch (opt) {
400 case 'a': {
Wind Yuan6b437392016-02-02 00:31:30 +0800401 XCAM_ASSERT (optarg);
Wind Yuane25ce3f2015-05-04 18:07:29 +0800402 if (!strcmp (optarg, "dynamic"))
403 analyzer_type = AnalyzerTypeDynamic;
404 else if (!strcmp (optarg, "simple"))
Wind Yuan26e9e212015-04-16 15:55:45 +0800405 analyzer_type = AnalyzerTypeSimple;
Wind Yuan75564b12015-01-15 06:51:15 -0500406#if HAVE_IA_AIQ
407 else if (!strcmp (optarg, "aiq"))
Wind Yuan26e9e212015-04-16 15:55:45 +0800408 analyzer_type = AnalyzerTypeAiq;
Jia Meng9724cfe2015-08-12 15:04:45 +0800409 else if (!strcmp (optarg, "hybrid"))
410 analyzer_type = AnalyzerTypeHybrid;
Wind Yuan75564b12015-01-15 06:51:15 -0500411#endif
412 else {
413 print_help (bin_name);
414 return -1;
415 }
416 break;
417 }
418
Wind Yuand4427312015-02-11 16:09:00 +0800419 case 'm': {
Wind Yuan6b437392016-02-02 00:31:30 +0800420 XCAM_ASSERT (optarg);
Wind Yuand4427312015-02-11 16:09:00 +0800421 if (!strcmp (optarg, "dma"))
422 v4l2_mem_type = V4L2_MEMORY_DMABUF;
423 else if (!strcmp (optarg, "mmap"))
424 v4l2_mem_type = V4L2_MEMORY_MMAP;
425 else
426 print_help (bin_name);
427 break;
428 }
429
Wind Yuan75564b12015-01-15 06:51:15 -0500430 case 's':
431 device_manager->enable_save_file (true);
432 break;
433 case 'n':
434 device_manager->set_interval (atoi(optarg));
435 break;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800436#if HAVE_LIBCL
Wind Yuand4427312015-02-11 16:09:00 +0800437 case 'c':
438 have_cl_processor = true;
439 break;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800440#endif
ShincyTu2808b592015-03-13 17:17:25 +0800441 case 'f':
ShincyTuc8466402015-03-31 11:03:39 +0800442 CHECK_EXP ((strlen(optarg) == 4), "invalid pixel format\n");
443 pixel_format = v4l2_fourcc ((unsigned)optarg[0],
444 (unsigned)optarg[1],
445 (unsigned)optarg[2],
446 (unsigned)optarg[3]);
ShincyTu2808b592015-03-13 17:17:25 +0800447 break;
448 case 'd':
Wind Yuan6b437392016-02-02 00:31:30 +0800449 XCAM_ASSERT (optarg);
ShincyTu2808b592015-03-13 17:17:25 +0800450 if (!strcmp (optarg, "still"))
451 capture_mode = V4L2_CAPTURE_MODE_STILL;
452 else if (!strcmp (optarg, "video"))
453 capture_mode = V4L2_CAPTURE_MODE_VIDEO;
454 else {
455 print_help (bin_name);
456 return -1;
457 }
458 break;
yaowang1a5f12122015-07-27 14:53:38 +0800459 case 'b':
460 brightness_level = atoi(optarg);
461 if(brightness_level < 0 || brightness_level > 256) {
462 print_help (bin_name);
463 return -1;
464 }
465 break;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800466 case 'p':
467 need_display = true;
468 break;
Sameer Kibey7b429292015-08-07 10:55:38 -0700469 case 'U':
470 have_usbcam = true;
471 usb_device_name = strdup(optarg);
472 XCAM_LOG_DEBUG("using USB camera plugged in at node: %s", usb_device_name);
473 break;
Yinhang Liud9346492015-12-17 11:14:25 +0800474 case 'R':
Wind Yuan6b437392016-02-02 00:31:30 +0800475 XCAM_ASSERT (optarg);
Yinhang Liud9346492015-12-17 11:14:25 +0800476 sscanf (optarg, "%d%*c%d", &frame_width, &frame_height);
477 break;
wangfeicf4c4e72015-05-25 17:11:41 +0800478 case 'e': {
Wind Yuan6b437392016-02-02 00:31:30 +0800479 XCAM_ASSERT (optarg);
wangfeicf4c4e72015-05-25 17:11:41 +0800480 if (!strcmp (optarg, "primary"))
481 display_mode = DRM_DISPLAY_MODE_PRIMARY;
482 else if (!strcmp (optarg, "overlay"))
483 display_mode = DRM_DISPLAY_MODE_OVERLAY;
484 else {
485 print_help (bin_name);
486 return -1;
487 }
488 break;
489 }
ShincyTue521cf92015-03-27 15:13:51 +0800490 case 'i':
491 device_manager->set_frame_save(atoi(optarg));
492 break;
Jia Meng8f94a102015-08-11 16:24:19 +0800493 case 'Y':
494 sync_mode = true;
495 break;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800496#if HAVE_LIBCL
Yinhang Liu81c44e02015-06-03 15:47:48 +0800497 case 'H': {
Wind Yuan6b437392016-02-02 00:31:30 +0800498 XCAM_ASSERT (optarg);
Yinhang Liu81c44e02015-06-03 15:47:48 +0800499 if (!strcasecmp (optarg, "rgb"))
500 hdr_type = CL_HDR_TYPE_RGB;
501 else if (!strcasecmp (optarg, "lab"))
502 hdr_type = CL_HDR_TYPE_LAB;
503 else {
504 print_help (bin_name);
505 return -1;
506 }
507 break;
508 }
Yinhang Liub92930c2015-06-23 16:26:35 +0800509 case 'I': {
Jia Meng66efecf2015-06-17 11:11:10 +0000510 denoise_type |= XCAM_DENOISE_TYPE_BILATERAL;
Juan Zhaod9664932015-09-08 10:22:19 +0800511 denoise_type |= XCAM_DENOISE_TYPE_BIYUV;
Yinhang Liu81c44e02015-06-03 15:47:48 +0800512 break;
513 }
514 case 'S': {
Jia Meng66efecf2015-06-17 11:11:10 +0000515 denoise_type |= XCAM_DENOISE_TYPE_SIMPLE;
516 break;
517 }
518 case 'E': {
519 denoise_type |= XCAM_DENOISE_TYPE_EE;
Yinhang Liu81c44e02015-06-03 15:47:48 +0800520 break;
521 }
ShincyTu63e2c262015-06-26 10:52:51 +0800522 case 'B': {
523 denoise_type |= XCAM_DENOISE_TYPE_BNR;
524 break;
525 }
Wangfei8e5e3e42016-02-18 19:41:54 +0800526 case 'X': {
527 retinex_type = true;
528 break;
529 }
530
Yinhang Liue26b2622015-07-21 18:32:36 +0800531 case 'D': {
532 dpc_type = true;
533 break;
534 }
Yinhang Liu81c44e02015-06-03 15:47:48 +0800535 case 'T': {
Wind Yuan6b437392016-02-02 00:31:30 +0800536 XCAM_ASSERT (optarg);
Yinhang Liu81c44e02015-06-03 15:47:48 +0800537 if (!strcasecmp (optarg, "yuv"))
538 tnr_type = CL_TNR_TYPE_YUV;
539 else if (!strcasecmp (optarg, "rgb"))
540 tnr_type = CL_TNR_TYPE_RGB;
541 else if (!strcasecmp (optarg, "both"))
542 tnr_type = CL_TNR_TYPE_YUV | CL_TNR_TYPE_RGB;
543 else {
544 print_help (bin_name);
545 return -1;
546 }
547 break;
548 }
549 case 'L': {
Wind Yuan6b437392016-02-02 00:31:30 +0800550 XCAM_ASSERT (optarg);
Yinhang Liu81c44e02015-06-03 15:47:48 +0800551 if (atoi(optarg) < 0 || atoi(optarg) > 255) {
552 print_help (bin_name);
553 return -1;
554 }
555 tnr_level = atoi(optarg);
556 break;
557 }
Jia Menga6580232015-10-08 16:51:28 +0800558 case 'W': {
559 wdr_type = true;
wujunkai166fd374802015-10-15 16:50:06 +0800560 tonemapping_type = true;
561 pixel_format = V4L2_PIX_FMT_SGRBG12;
wujunkai16682950fb2015-10-19 18:09:05 +0800562
563 setenv ("AIQ_CPF_PATH", IMX185_WDR_CPF, 1);
Jia Menga6580232015-10-08 16:51:28 +0800564 break;
565 }
wujunkai166b0bd5512016-02-18 18:25:42 +0800566 case 'N': {
567 wdr_type = true;
568 newtonemapping_type = true;
569 pixel_format = V4L2_PIX_FMT_SGRBG12;
570
571 setenv ("AIQ_CPF_PATH", IMX185_WDR_CPF, 1);
572 break;
573 }
Wangfei1487b9b2015-08-28 15:10:39 +0800574 case 'P': {
Wind Yuan6b437392016-02-02 00:31:30 +0800575 XCAM_ASSERT (optarg);
Wangfei1487b9b2015-08-28 15:10:39 +0800576 if (!strcasecmp (optarg, "basic"))
577 pipeline_mode = CL3aImageProcessor::BasicPipelineProfile;
578 else if (!strcasecmp (optarg, "advance"))
579 pipeline_mode = CL3aImageProcessor::AdvancedPipelineProfile;
Wangfei16b65db2015-09-11 14:44:28 +0800580 else if (!strcasecmp (optarg, "extreme"))
581 pipeline_mode = CL3aImageProcessor::ExtremePipelineProfile;
Wangfei1487b9b2015-08-28 15:10:39 +0800582 else {
583 print_help (bin_name);
584 return -1;
585 }
586 break;
587 }
wujunkai166a84ba052015-09-08 15:54:12 +0800588 case 'C': {
Wind Yuan6b437392016-02-02 00:31:30 +0800589 XCAM_ASSERT (optarg);
wujunkai166a84ba052015-09-08 15:54:12 +0800590 if (!strcmp (optarg, "bayer"))
591 capture_stage = CL3aImageProcessor::BasicbayerStage;
592 break;
593 }
Yinhang Liuc2f19082015-08-28 12:27:48 +0800594#endif
Jia Meng0a532932015-10-15 08:44:09 -0400595 case 'r': {
596 if (optarg) {
597 XCAM_LOG_INFO ("use raw image %s as input source", optarg);
598 path_to_fake = strdup(optarg);
599 }
600 break;
601 }
Wind Yuan75564b12015-01-15 06:51:15 -0500602 case 'h':
603 print_help (bin_name);
604 return 0;
605
606 default:
607 print_help (bin_name);
608 return -1;
609 }
610 }
611
Yinhang Liud9346492015-12-17 11:14:25 +0800612 device_manager->set_frame_width(frame_width);
613 device_manager->set_frame_height(frame_height);
wangfeicf4c4e72015-05-25 17:11:41 +0800614 if (need_display) {
Wind Yuan683f8662015-03-27 18:52:38 +0800615 device_manager->enable_display (true);
wangfeicf4c4e72015-05-25 17:11:41 +0800616 device_manager->set_display_mode (display_mode);
617 }
ShincyTu2808b592015-03-13 17:17:25 +0800618 if (!device.ptr ()) {
Jia Meng0a532932015-10-15 08:44:09 -0400619 if (path_to_fake) {
620 device = new FakeV4l2Device ();
621 } else if (have_usbcam) {
Sameer Kibey7b429292015-08-07 10:55:38 -0700622 device = new UVCDevice (usb_device_name);
623 } else {
624 if (capture_mode == V4L2_CAPTURE_MODE_STILL)
625 device = new AtomispDevice (CAPTURE_DEVICE_STILL);
626 else if (capture_mode == V4L2_CAPTURE_MODE_VIDEO)
627 device = new AtomispDevice (CAPTURE_DEVICE_VIDEO);
628 else
629 device = new AtomispDevice (DEFAULT_CAPTURE_DEVICE);
630 }
ShincyTu2808b592015-03-13 17:17:25 +0800631 }
Wind Yuan75564b12015-01-15 06:51:15 -0500632 if (!event_device.ptr ())
633 event_device = new V4l2SubDevice (DEFAULT_EVENT_DEVICE);
634 if (!isp_controller.ptr ())
635 isp_controller = new IspController (device);
Wind Yuan26e9e212015-04-16 15:55:45 +0800636
637 switch (analyzer_type) {
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800638 case AnalyzerTypeSimple:
639 analyzer = new X3aAnalyzerSimple ();
640 break;
Wind Yuan26e9e212015-04-16 15:55:45 +0800641#if HAVE_IA_AIQ
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800642 case AnalyzerTypeAiq:
643 analyzer = new X3aAnalyzerAiq (isp_controller, DEFAULT_CPF_FILE);
644 break;
Jia Meng9724cfe2015-08-12 15:04:45 +0800645 case AnalyzerTypeHybrid: {
Jia Mengc54c3322015-08-26 09:45:18 +0800646 path_of_3a = DEFAULT_HYBRID_3A_LIB;
zongwave03954a32015-09-22 15:40:44 +0800647 loader = new X3aAnalyzerLoader (path_of_3a);
Jia Meng9724cfe2015-08-12 15:04:45 +0800648 analyzer = loader->load_hybrid_analyzer (loader, isp_controller, DEFAULT_CPF_FILE);
649 CHECK_EXP (analyzer.ptr (), "load hybrid 3a lib(%s) failed", path_of_3a);
650 break;
651 }
Wind Yuan26e9e212015-04-16 15:55:45 +0800652#endif
Wind Yuane25ce3f2015-05-04 18:07:29 +0800653 case AnalyzerTypeDynamic: {
Jia Meng9724cfe2015-08-12 15:04:45 +0800654 path_of_3a = DEFAULT_DYNAMIC_3A_LIB;
zongwave03954a32015-09-22 15:40:44 +0800655 loader = new X3aAnalyzerLoader (path_of_3a);
Jia Meng9724cfe2015-08-12 15:04:45 +0800656 analyzer = loader->load_dynamic_analyzer (loader);
Wind Yuane25ce3f2015-05-04 18:07:29 +0800657 CHECK_EXP (analyzer.ptr (), "load dynamic 3a lib(%s) failed", path_of_3a);
658 break;
659 }
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800660 default:
661 print_help (bin_name);
662 return -1;
Wind Yuan26e9e212015-04-16 15:55:45 +0800663 }
Jia Meng8f94a102015-08-11 16:24:19 +0800664 XCAM_ASSERT (analyzer.ptr ());
665 analyzer->set_sync_mode (sync_mode);
Wind Yuan75564b12015-01-15 06:51:15 -0500666
667 signal(SIGINT, dev_stop_handler);
668
669 device->set_sensor_id (0);
ShincyTu2808b592015-03-13 17:17:25 +0800670 device->set_capture_mode (capture_mode);
Wind Yuan75564b12015-01-15 06:51:15 -0500671 //device->set_mem_type (V4L2_MEMORY_DMABUF);
Wind Yuand4427312015-02-11 16:09:00 +0800672 device->set_mem_type (v4l2_mem_type);
Wind Yuan75564b12015-01-15 06:51:15 -0500673 device->set_buffer_count (8);
Jia Meng757f3c92015-09-09 11:18:36 +0800674 if (pixel_format == V4L2_PIX_FMT_SGRBG12) {
675 frame_rate = 30;
676 device->set_framerate (frame_rate, 1);
677 }
678 else {
679 frame_rate = 25;
680 device->set_framerate (frame_rate, 1);
wujunkai166a9a55f22015-10-10 15:53:32 +0800681 if(tonemapping_type == true) {
682 XCAM_LOG_WARNING("Tonemapping is only applicable under BA12 format. Disable tonemapping automatically.");
683 tonemapping_type = false;
684 }
Jia Meng757f3c92015-09-09 11:18:36 +0800685 }
Wind Yuan75564b12015-01-15 06:51:15 -0500686 ret = device->open ();
687 CHECK (ret, "device(%s) open failed", device->get_device_name());
Yinhang Liud9346492015-12-17 11:14:25 +0800688 ret = device->set_format (frame_width, frame_height, pixel_format, V4L2_FIELD_NONE, frame_width * 2);
Wind Yuan75564b12015-01-15 06:51:15 -0500689 CHECK (ret, "device(%s) set format failed", device->get_device_name());
690
691 ret = event_device->open ();
Wind Yuanb67045c2015-08-27 13:50:53 +0800692 if (ret == XCAM_RETURN_NO_ERROR) {
693 CHECK (ret, "event device(%s) open failed", event_device->get_device_name());
694 int event = V4L2_EVENT_ATOMISP_3A_STATS_READY;
695 ret = event_device->subscribe_event (event);
696 CHECK_CONTINUE (
697 ret,
698 "device(%s) subscribe event(%d) failed",
699 event_device->get_device_name(), event);
700 event = V4L2_EVENT_FRAME_SYNC;
701 ret = event_device->subscribe_event (event);
702 CHECK_CONTINUE (
703 ret,
704 "device(%s) subscribe event(%d) failed",
705 event_device->get_device_name(), event);
706
707 device_manager->set_event_device (event_device);
708 }
Wind Yuan75564b12015-01-15 06:51:15 -0500709
710 device_manager->set_capture_device (device);
Wind Yuan75564b12015-01-15 06:51:15 -0500711 device_manager->set_isp_controller (isp_controller);
712 if (analyzer.ptr())
zongwave03954a32015-09-22 15:40:44 +0800713 device_manager->set_3a_analyzer (analyzer);
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800714
715 if (have_cl_processor)
716 isp_processor = new IspExposureImageProcessor (isp_controller);
717 else
718 isp_processor = new IspImageProcessor (isp_controller);
719
720 XCAM_ASSERT (isp_processor.ptr ());
Wind Yuane4ba0c92015-03-26 16:59:06 +0800721 device_manager->add_image_processor (isp_processor);
Yinhang Liuc2f19082015-08-28 12:27:48 +0800722#if HAVE_LIBCL
wangfeicf4c4e72015-05-25 17:11:41 +0800723 if ((display_mode == DRM_DISPLAY_MODE_PRIMARY) && need_display && (!have_cl_processor)) {
724 cl_csc_proccessor = new CLCscImageProcessor();
725 XCAM_ASSERT (cl_csc_proccessor.ptr ());
726 device_manager->add_image_processor (cl_csc_proccessor);
727 }
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800728
Wind Yuand4427312015-02-11 16:09:00 +0800729 if (have_cl_processor) {
Wind Yuane4ba0c92015-03-26 16:59:06 +0800730 cl_processor = new CL3aImageProcessor ();
Wind Yuan7ddf2602015-04-14 18:49:45 +0800731 cl_processor->set_stats_callback(device_manager);
Yinhang Liue26b2622015-07-21 18:32:36 +0800732 cl_processor->set_dpc(dpc_type);
Yinhang Liu81c44e02015-06-03 15:47:48 +0800733 cl_processor->set_hdr (hdr_type);
Jia Meng66efecf2015-06-17 11:11:10 +0000734 cl_processor->set_denoise (denoise_type);
yaowang16e051152015-08-14 13:49:03 +0800735 cl_processor->set_tonemapping(tonemapping_type);
wujunkai166b0bd5512016-02-18 18:25:42 +0800736 cl_processor->set_newtonemapping(newtonemapping_type);
Jia Menga6580232015-10-08 16:51:28 +0800737 cl_processor->set_gamma (!wdr_type); // disable gamma for WDR
Wangfei8e5e3e42016-02-18 19:41:54 +0800738 cl_processor->set_retinex (retinex_type);
wujunkai166a84ba052015-09-08 15:54:12 +0800739 cl_processor->set_capture_stage (capture_stage);
Wind Yuane4ba0c92015-03-26 16:59:06 +0800740 if (need_display) {
741 cl_processor->set_output_format (V4L2_PIX_FMT_XBGR32);
742 }
Yinhang Liu81c44e02015-06-03 15:47:48 +0800743 cl_processor->set_tnr (tnr_type, tnr_level);
Wangfei1487b9b2015-08-28 15:10:39 +0800744 cl_processor->set_profile (pipeline_mode);
yaowang1a5f12122015-07-27 14:53:38 +0800745 analyzer->set_parameter_brightness((brightness_level - 128) / 128.0);
Wind Yuand4427312015-02-11 16:09:00 +0800746 device_manager->add_image_processor (cl_processor);
747 }
748#endif
Wind Yuane4ba0c92015-03-26 16:59:06 +0800749
Jia Meng0a532932015-10-15 08:44:09 -0400750 SmartPtr<PollThread> poll_thread;
751 if (path_to_fake)
752 poll_thread = new FakePollThread (path_to_fake);
753 else
754 poll_thread = new PollThread ();
755 device_manager->set_poll_thread (poll_thread);
756
Wind Yuan75564b12015-01-15 06:51:15 -0500757 ret = device_manager->start ();
758 CHECK (ret, "device manager start failed");
759
Jia Meng757f3c92015-09-09 11:18:36 +0800760 // hard code exposure range and max gain for imx185 WDR
Jia Menga6580232015-10-08 16:51:28 +0800761 if (wdr_type) {
Jia Meng757f3c92015-09-09 11:18:36 +0800762 if (frame_rate == 30)
763 analyzer->set_ae_exposure_time_range (80 * 1110 * 1000 / 37125, 1120 * 1110 * 1000 / 37125);
764 else
Jia Menga6580232015-10-08 16:51:28 +0800765 analyzer->set_ae_exposure_time_range (80 * 1320 * 1000 / 37125, 1120 * 1320 * 1000 / 37125);
Jia Meng757f3c92015-09-09 11:18:36 +0800766 analyzer->set_ae_max_analog_gain (3.98); // 12dB
767 }
768
Wind Yuan75564b12015-01-15 06:51:15 -0500769 // wait for interruption
770 {
771 SmartLock locker (g_mutex);
772 while (!g_stop)
773 g_cond.wait (g_mutex);
774 }
775
776 ret = device_manager->stop();
777 CHECK_CONTINUE (ret, "device manager stop failed");
778 device->close ();
779 event_device->close ();
Jia Meng0a532932015-10-15 08:44:09 -0400780 if (usb_device_name)
781 free (usb_device_name);
782 if (path_to_fake)
783 free (path_to_fake);
Wind Yuan75564b12015-01-15 06:51:15 -0500784
785 return 0;
786}