blob: bbd75598e1331a89433c8e8bf1baadce34e8d03c [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"
Wind Yuan75564b12015-01-15 06:51:15 -050024#include "isp_controller.h"
25#include "isp_image_processor.h"
26#include "x3a_analyzer_simple.h"
27#if HAVE_IA_AIQ
28#include "x3a_analyzer_aiq.h"
29#endif
Wind Yuand4427312015-02-11 16:09:00 +080030#if HAVE_LIBCL
Wind Yuane4ba0c92015-03-26 16:59:06 +080031#include "cl_3a_image_processor.h"
wangfeicf4c4e72015-05-25 17:11:41 +080032#include "cl_csc_image_processor.h"
Yinhang Liu81c44e02015-06-03 15:47:48 +080033#include "cl_hdr_handler.h"
34#include "cl_tnr_handler.h"
Wind Yuane4ba0c92015-03-26 16:59:06 +080035#endif
36#if HAVE_LIBDRM
37#include "drm_display.h"
Wind Yuand4427312015-02-11 16:09:00 +080038#endif
zongwave03954a32015-09-22 15:40:44 +080039#include "x3a_analyzer_loader.h"
Jia Meng66efecf2015-06-17 11:11:10 +000040#include <base/xcam_3a_types.h>
Wind Yuan75564b12015-01-15 06:51:15 -050041#include <unistd.h>
42#include <signal.h>
43#include <stdlib.h>
ShincyTue521cf92015-03-27 15:13:51 +080044#include <string>
Yinhang Liu81c44e02015-06-03 15:47:48 +080045#include <getopt.h>
John Yeae9da732015-01-22 13:36:36 +080046#include "test_common.h"
47
Wind Yuan75564b12015-01-15 06:51:15 -050048using namespace XCam;
49
ShincyTue521cf92015-03-27 15:13:51 +080050static Mutex g_mutex;
51static Cond g_cond;
52static bool g_stop = false;
53
Wind Yuan75564b12015-01-15 06:51:15 -050054class MainDeviceManager
55 : public DeviceManager
56{
57public:
58 MainDeviceManager ()
59 : _file (NULL)
60 , _save_file (false)
61 , _interval (1)
62 , _frame_count (0)
ShincyTue521cf92015-03-27 15:13:51 +080063 , _frame_save (0)
Wind Yuan683f8662015-03-27 18:52:38 +080064 , _enable_display (false)
Wind Yuane4ba0c92015-03-26 16:59:06 +080065 {
66#if HAVE_LIBDRM
67 _display = DrmDisplay::instance();
68#endif
Wind Yuan91625802015-06-24 15:36:01 +080069 XCAM_OBJ_PROFILING_INIT;
Wind Yuane4ba0c92015-03-26 16:59:06 +080070 }
Wind Yuan75564b12015-01-15 06:51:15 -050071
72 ~MainDeviceManager () {
73 close_file ();
74 }
75
76 void enable_save_file (bool enable) {
77 _save_file = enable;
78 }
79 void set_interval (uint32_t inteval) {
80 _interval = inteval;
81 }
ShincyTue521cf92015-03-27 15:13:51 +080082 void set_frame_save (uint32_t frame_save) {
83 _frame_save = frame_save;
84 }
Wind Yuan75564b12015-01-15 06:51:15 -050085
Wind Yuan683f8662015-03-27 18:52:38 +080086 void enable_display(bool value) {
87 _enable_display = value;
88 }
89
wangfeicf4c4e72015-05-25 17:11:41 +080090 void set_display_mode(DrmDisplayMode mode) {
91 _display->set_display_mode (mode);
92 }
93
Wind Yuan75564b12015-01-15 06:51:15 -050094protected:
Wind Yuan73af3932015-07-02 17:52:43 +080095 virtual void handle_message (const SmartPtr<XCamMessage> &msg);
96 virtual void handle_buffer (const SmartPtr<VideoBuffer> &buf);
Wind Yuan75564b12015-01-15 06:51:15 -050097
Wind Yuan73af3932015-07-02 17:52:43 +080098 int display_buf (const SmartPtr<VideoBuffer> &buf);
Wind Yuane4ba0c92015-03-26 16:59:06 +080099
Wind Yuan75564b12015-01-15 06:51:15 -0500100private:
101 void open_file ();
102 void close_file ();
103
104 FILE *_file;
105 bool _save_file;
106 uint32_t _interval;
107 uint32_t _frame_count;
ShincyTue521cf92015-03-27 15:13:51 +0800108 uint32_t _frame_save;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800109 SmartPtr<DrmDisplay> _display;
Wind Yuan683f8662015-03-27 18:52:38 +0800110 bool _enable_display;
Wind Yuan91625802015-06-24 15:36:01 +0800111 XCAM_OBJ_PROFILING_DEFINES;
Wind Yuan75564b12015-01-15 06:51:15 -0500112};
113
114void
Wind Yuan73af3932015-07-02 17:52:43 +0800115MainDeviceManager::handle_message (const SmartPtr<XCamMessage> &msg)
Wind Yuan75564b12015-01-15 06:51:15 -0500116{
117 XCAM_UNUSED (msg);
118}
119
120void
Wind Yuan73af3932015-07-02 17:52:43 +0800121MainDeviceManager::handle_buffer (const SmartPtr<VideoBuffer> &buf)
Wind Yuan75564b12015-01-15 06:51:15 -0500122{
Wind Yuan683f8662015-03-27 18:52:38 +0800123 FPS_CALCULATION (fps_buf, 30);
124
Wind Yuan91625802015-06-24 15:36:01 +0800125 XCAM_OBJ_PROFILING_START;
126
Wind Yuan683f8662015-03-27 18:52:38 +0800127 if (_enable_display)
128 display_buf (buf);
Wind Yuane4ba0c92015-03-26 16:59:06 +0800129
Wind Yuan91625802015-06-24 15:36:01 +0800130 XCAM_OBJ_PROFILING_END("main_dev_manager_display", 30);
131
Wind Yuan75564b12015-01-15 06:51:15 -0500132 if (!_save_file)
133 return ;
134
135 if ((_frame_count++ % _interval) != 0)
136 return;
137
ShincyTue521cf92015-03-27 15:13:51 +0800138 if ((_frame_save != 0) && (_frame_count > _frame_save)) {
139 SmartLock locker (g_mutex);
140 g_stop = true;
141 g_cond.broadcast ();
142 return;
143 }
144
Wind Yuan75564b12015-01-15 06:51:15 -0500145 const VideoBufferInfo & frame_info = buf->get_video_info ();
146 uint8_t *frame = buf->map ();
ShincyTu2808b592015-03-13 17:17:25 +0800147
Wind Yuan75564b12015-01-15 06:51:15 -0500148 if (frame == NULL)
149 return;
ShincyTu2808b592015-03-13 17:17:25 +0800150
151 uint32_t size = 0;
152
153 switch(frame_info.format) {
154 case V4L2_PIX_FMT_NV12: // 420
155 case V4L2_PIX_FMT_NV21:
156 size = XCAM_ALIGN_UP(frame_info.width, 2) * XCAM_ALIGN_UP(frame_info.height, 2) * 3 / 2;
157 break;
158 case V4L2_PIX_FMT_YUV422P: // 422 Planar
159 case V4L2_PIX_FMT_YUYV: // 422
160 case V4L2_PIX_FMT_SBGGR10:
161 case V4L2_PIX_FMT_SGBRG10:
162 case V4L2_PIX_FMT_SGRBG10:
163 case V4L2_PIX_FMT_SRGGB10:
ShincyTu1a4de9d2015-06-01 18:04:51 +0800164 case V4L2_PIX_FMT_SBGGR12:
165 case V4L2_PIX_FMT_SGBRG12:
166 case V4L2_PIX_FMT_SGRBG12:
167 case V4L2_PIX_FMT_SRGGB12:
ShincyTu2808b592015-03-13 17:17:25 +0800168 size = XCAM_ALIGN_UP(frame_info.width, 2) * XCAM_ALIGN_UP(frame_info.height, 2) * 2;
169 break;
wujunkai166a84ba052015-09-08 15:54:12 +0800170 case XCAM_PIX_FMT_RGBA64:
171 size = XCAM_ALIGN_UP(frame_info.width, 2) * XCAM_ALIGN_UP(frame_info.height, 2) * 2 * 4;
172 break;
ShincyTu2808b592015-03-13 17:17:25 +0800173 default:
174 XCAM_LOG_ERROR (
175 "unknown v4l2 format(%s) in buffer handle",
176 xcam_fourcc_to_string (frame_info.format));
177 return;
178 }
179
Wind Yuan75564b12015-01-15 06:51:15 -0500180 open_file ();
Jia Meng6c9241d2015-06-12 11:08:45 +0000181
182 if (!_file) {
183 XCAM_LOG_ERROR ("open file failed");
Jia Meng54a2dcb2015-08-20 15:23:47 +0800184 return;
Jia Meng6c9241d2015-06-12 11:08:45 +0000185 }
186
Wind Yuan75564b12015-01-15 06:51:15 -0500187 if (fwrite (frame, size, 1, _file) <= 0) {
188 XCAM_LOG_WARNING ("write frame failed.");
189 }
190}
191
Wind Yuane4ba0c92015-03-26 16:59:06 +0800192int
Wind Yuan73af3932015-07-02 17:52:43 +0800193MainDeviceManager::display_buf (const SmartPtr<VideoBuffer> &data)
Wind Yuane4ba0c92015-03-26 16:59:06 +0800194{
195#if HAVE_LIBDRM
196 XCamReturn ret = XCAM_RETURN_NO_ERROR;
Wind Yuan73af3932015-07-02 17:52:43 +0800197 SmartPtr<VideoBuffer> buf = data;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800198 const VideoBufferInfo & frame_info = buf->get_video_info ();
199 struct v4l2_rect rect = { 0, 0, (int)frame_info.width, (int)frame_info.height };
200
201 if (!_display->is_render_inited ()) {
wangfei139ea7e2015-04-27 18:13:40 +0800202 ret = _display->render_init (0, 0, 1920, 1080, frame_info.format, &rect);
Wind Yuane4ba0c92015-03-26 16:59:06 +0800203 CHECK (ret, "display failed on render_init");
204 }
205 ret = _display->render_setup_frame_buffer (buf);
206 CHECK (ret, "display failed on framebuf set");
207 ret = _display->render_buffer (buf);
208 CHECK (ret, "display failed on rendering");
209#endif
210 return 0;
211}
212
213
Wind Yuan75564b12015-01-15 06:51:15 -0500214void
215MainDeviceManager::open_file ()
216{
ShincyTue521cf92015-03-27 15:13:51 +0800217 if ((_file) && (_frame_save == 0))
Wind Yuan75564b12015-01-15 06:51:15 -0500218 return;
ShincyTue521cf92015-03-27 15:13:51 +0800219
220 std::string file_name = DEFAULT_SAVE_FILE_NAME;
221
222 if (_frame_save != 0) {
223 file_name += std::to_string(_frame_count);
224 }
225 file_name += ".raw";
226
227 _file = fopen(file_name.c_str(), "wb");
Wind Yuan75564b12015-01-15 06:51:15 -0500228}
229
230void
231MainDeviceManager::close_file ()
232{
233 if (_file)
234 fclose (_file);
235 _file = NULL;
236}
237
238#define V4L2_CAPTURE_MODE_STILL 0x2000
239#define V4L2_CAPTURE_MODE_VIDEO 0x4000
240#define V4L2_CAPTURE_MODE_PREVIEW 0x8000
241
Wind Yuan26e9e212015-04-16 15:55:45 +0800242typedef enum {
243 AnalyzerTypeSimple = 0,
244 AnalyzerTypeAiq,
Wind Yuane25ce3f2015-05-04 18:07:29 +0800245 AnalyzerTypeDynamic,
Jia Meng9724cfe2015-08-12 15:04:45 +0800246 AnalyzerTypeHybrid,
Wind Yuan26e9e212015-04-16 15:55:45 +0800247} AnalyzerType;
248
Wind Yuan75564b12015-01-15 06:51:15 -0500249void dev_stop_handler(int sig)
250{
251 XCAM_UNUSED (sig);
252
253 SmartLock locker (g_mutex);
254 g_stop = true;
255 g_cond.broadcast ();
256
257 //exit(0);
258}
259
260void print_help (const char *bin_name)
261{
262 printf ("Usage: %s [-a analyzer]\n"
Yinhang Liu81c44e02015-06-03 15:47:48 +0800263 "Configurations:\n"
ShincyTue521cf92015-03-27 15:13:51 +0800264 "\t -a analyzer specify a analyzer\n"
Wind Yuane25ce3f2015-05-04 18:07:29 +0800265 "\t select from [simple, aiq, dynamic], default is [simple]\n"
ShincyTue521cf92015-03-27 15:13:51 +0800266 "\t -m mem_type specify video memory type\n"
267 "\t mem_type select from [dma, mmap], default is [mmap]\n"
268 "\t -s save file to %s\n"
269 "\t -n interval save file on every [interval] frame\n"
Yinhang Liuc2f19082015-08-28 12:27:48 +0800270#if HAVE_LIBCL
ShincyTue521cf92015-03-27 15:13:51 +0800271 "\t -c process image with cl kernel\n"
Yinhang Liuc2f19082015-08-28 12:27:48 +0800272#endif
ShincyTue521cf92015-03-27 15:13:51 +0800273 "\t -f pixel_fmt specify output pixel format\n"
wujunkai1669845b022015-08-27 15:59:27 +0800274 "\t pixel_fmt select from [NV12, YUYV, BA10, BA12], default is [NV12]\n"
ShincyTue521cf92015-03-27 15:13:51 +0800275 "\t -d cap_mode specify capture mode\n"
276 "\t cap_mode select from [video, still], default is [video]\n"
yaowang1a5f12122015-07-27 14:53:38 +0800277 "\t -b brightness specify brightness level\n"
278 "\t brightness level select from [0, 256], default is [128]\n"
ShincyTue521cf92015-03-27 15:13:51 +0800279 "\t -i frame_save specify the frame count to save, default is 0 which means endless\n"
wangfeicf4c4e72015-05-25 17:11:41 +0800280 "\t -p preview on local display\n"
Sameer Kibey7b429292015-08-07 10:55:38 -0700281 "\t --usb specify node for usb camera device, enables capture path through USB camera \n"
282 "\t specify [/dev/video4, /dev/video5] depending on which node USB camera is attached\n"
wangfeicf4c4e72015-05-25 17:11:41 +0800283 "\t -e display_mode preview mode\n"
284 "\t select from [primary, overlay], default is [primary]\n"
Jia Meng8f94a102015-08-11 16:24:19 +0800285 "\t --sync set analyzer in sync mode\n"
ShincyTue521cf92015-03-27 15:13:51 +0800286 "\t -h help\n"
Yinhang Liuc2f19082015-08-28 12:27:48 +0800287#if HAVE_LIBCL
Yinhang Liu81c44e02015-06-03 15:47:48 +0800288 "CL features:\n"
wujunkai166a84ba052015-09-08 15:54:12 +0800289 "\t --capture capture_stage specify the capture stage of image\n"
290 "\t capture_stage select from [bayer, tonemapping], default is [tonemapping]\n"
Yinhang Liu81c44e02015-06-03 15:47:48 +0800291 "\t --hdr specify hdr type, default is hdr off\n"
292 "\t select from [rgb, lab]\n"
293 "\t --tnr specify temporal noise reduction type, default is tnr off\n"
294 "\t select from [rgb, yuv, both]\n"
295 "\t --tnr-level specify tnr level\n"
Yinhang Liub92930c2015-06-23 16:26:35 +0800296 "\t --bilateral enable bilateral noise reduction\n"
Yinhang Liu81c44e02015-06-03 15:47:48 +0800297 "\t --enable-snr enable simple noise reduction\n"
Jia Meng66efecf2015-06-17 11:11:10 +0000298 "\t --enable-ee enable YEENR\n"
ShincyTu63e2c262015-06-26 10:52:51 +0800299 "\t --enable-bnr enable bayer noise reduction\n"
Yinhang Liue26b2622015-07-21 18:32:36 +0800300 "\t --enable-dpc enable defect pixel correction\n"
yaowang16e051152015-08-14 13:49:03 +0800301 "\t --enable-tonemapping enable tonemapping\n"
Jia Menga6580232015-10-08 16:51:28 +0800302 "\t --enable-wdr enable wdr\n"
Wangfei1487b9b2015-08-28 15:10:39 +0800303 "\t --pipeline pipe mode\n"
Wangfei16b65db2015-09-11 14:44:28 +0800304 "\t select from [basic, advance, extreme], default is [basic]\n"
Yinhang Liue26b2622015-07-21 18:32:36 +0800305 "(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 +0800306#endif
Wind Yuan75564b12015-01-15 06:51:15 -0500307 , bin_name
308 , DEFAULT_SAVE_FILE_NAME);
309}
310
311int main (int argc, char *argv[])
312{
313 XCamReturn ret = XCAM_RETURN_NO_ERROR;
314 SmartPtr<MainDeviceManager> device_manager = new MainDeviceManager;
315 SmartPtr<V4l2Device> device;
316 SmartPtr<V4l2SubDevice> event_device;
317 SmartPtr<IspController> isp_controller;
318 SmartPtr<X3aAnalyzer> analyzer;
zongwave03954a32015-09-22 15:40:44 +0800319 SmartPtr<X3aAnalyzerLoader> loader;
Jia Meng9724cfe2015-08-12 15:04:45 +0800320 const char *path_of_3a;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800321 SmartPtr<ImageProcessor> isp_processor;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800322#if HAVE_LIBCL
wangfeicf4c4e72015-05-25 17:11:41 +0800323 SmartPtr<CLCscImageProcessor> cl_csc_proccessor;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800324#endif
Wind Yuan26e9e212015-04-16 15:55:45 +0800325 AnalyzerType analyzer_type = AnalyzerTypeSimple;
wangfeicf4c4e72015-05-25 17:11:41 +0800326 DrmDisplayMode display_mode = DRM_DISPLAY_MODE_PRIMARY;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800327#if HAVE_LIBDRM
328 SmartPtr<DrmDisplay> drm_disp = DrmDisplay::instance();
329#endif
330
Wind Yuand4427312015-02-11 16:09:00 +0800331#if HAVE_LIBCL
Wind Yuane4ba0c92015-03-26 16:59:06 +0800332 SmartPtr<CL3aImageProcessor> cl_processor;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800333 uint32_t hdr_type = CL_HDR_DISABLE;
334 uint32_t tnr_type = CL_TNR_DISABLE;
335 uint32_t denoise_type = 0;
336 uint8_t tnr_level = 0;
337 bool dpc_type = false;
Wangfei1487b9b2015-08-28 15:10:39 +0800338 CL3aImageProcessor::PipelineProfile pipeline_mode = CL3aImageProcessor::BasicPipelineProfile;
wujunkai166a84ba052015-09-08 15:54:12 +0800339 CL3aImageProcessor::CaptureStage capture_stage = CL3aImageProcessor::TonemappingStage;
Wind Yuand4427312015-02-11 16:09:00 +0800340#endif
341 bool have_cl_processor = false;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800342 bool need_display = false;
Wind Yuand4427312015-02-11 16:09:00 +0800343 enum v4l2_memory v4l2_mem_type = V4L2_MEMORY_MMAP;
Wind Yuan75564b12015-01-15 06:51:15 -0500344 const char *bin_name = argv[0];
345 int opt;
ShincyTu2808b592015-03-13 17:17:25 +0800346 uint32_t capture_mode = V4L2_CAPTURE_MODE_VIDEO;
347 uint32_t pixel_format = V4L2_PIX_FMT_NV12;
yaowang16e051152015-08-14 13:49:03 +0800348 bool tonemapping_type = false;
Jia Menga6580232015-10-08 16:51:28 +0800349 bool wdr_type = false;
yaowang1a5f12122015-07-27 14:53:38 +0800350 int32_t brightness_level = 128;
Sameer Kibey7b429292015-08-07 10:55:38 -0700351 bool have_usbcam = 0;
352 char* usb_device_name = NULL;
Jia Meng8f94a102015-08-11 16:24:19 +0800353 bool sync_mode = false;
Jia Meng757f3c92015-09-09 11:18:36 +0800354 int frame_rate;
Wind Yuan75564b12015-01-15 06:51:15 -0500355
yaowang1a5f12122015-07-27 14:53:38 +0800356 const char *short_opts = "sca:n:m:f:d:b:pi:e:h";
Yinhang Liu81c44e02015-06-03 15:47:48 +0800357 const struct option long_opts[] = {
358 {"hdr", required_argument, NULL, 'H'},
359 {"tnr", required_argument, NULL, 'T'},
360 {"tnr-level", required_argument, NULL, 'L'},
Yinhang Liub92930c2015-06-23 16:26:35 +0800361 {"bilateral", no_argument, NULL, 'I'},
Yinhang Liu81c44e02015-06-03 15:47:48 +0800362 {"enable-snr", no_argument, NULL, 'S'},
Jia Meng66efecf2015-06-17 11:11:10 +0000363 {"enable-ee", no_argument, NULL, 'E'},
ShincyTu63e2c262015-06-26 10:52:51 +0800364 {"enable-bnr", no_argument, NULL, 'B'},
Yinhang Liue26b2622015-07-21 18:32:36 +0800365 {"enable-dpc", no_argument, NULL, 'D'},
yaowang16e051152015-08-14 13:49:03 +0800366 {"enable-tonemapping", no_argument, NULL, 'M'},
Jia Menga6580232015-10-08 16:51:28 +0800367 {"enable-wdr", no_argument, NULL, 'W'},
Sameer Kibey7b429292015-08-07 10:55:38 -0700368 {"usb", required_argument, NULL, 'U'},
Jia Meng8f94a102015-08-11 16:24:19 +0800369 {"sync", no_argument, NULL, 'Y'},
wujunkai166a84ba052015-09-08 15:54:12 +0800370 {"capture", required_argument, NULL, 'C'},
Wangfei1487b9b2015-08-28 15:10:39 +0800371 {"pipeline", required_argument, NULL, 'P'},
Yinhang Liu81c44e02015-06-03 15:47:48 +0800372 {0, 0, 0, 0},
373 };
374
375 while ((opt = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) {
Wind Yuan75564b12015-01-15 06:51:15 -0500376 switch (opt) {
377 case 'a': {
Wind Yuane25ce3f2015-05-04 18:07:29 +0800378 if (!strcmp (optarg, "dynamic"))
379 analyzer_type = AnalyzerTypeDynamic;
380 else if (!strcmp (optarg, "simple"))
Wind Yuan26e9e212015-04-16 15:55:45 +0800381 analyzer_type = AnalyzerTypeSimple;
Wind Yuan75564b12015-01-15 06:51:15 -0500382#if HAVE_IA_AIQ
383 else if (!strcmp (optarg, "aiq"))
Wind Yuan26e9e212015-04-16 15:55:45 +0800384 analyzer_type = AnalyzerTypeAiq;
Jia Meng9724cfe2015-08-12 15:04:45 +0800385 else if (!strcmp (optarg, "hybrid"))
386 analyzer_type = AnalyzerTypeHybrid;
Wind Yuan75564b12015-01-15 06:51:15 -0500387#endif
388 else {
389 print_help (bin_name);
390 return -1;
391 }
392 break;
393 }
394
Wind Yuand4427312015-02-11 16:09:00 +0800395 case 'm': {
396 if (!strcmp (optarg, "dma"))
397 v4l2_mem_type = V4L2_MEMORY_DMABUF;
398 else if (!strcmp (optarg, "mmap"))
399 v4l2_mem_type = V4L2_MEMORY_MMAP;
400 else
401 print_help (bin_name);
402 break;
403 }
404
Wind Yuan75564b12015-01-15 06:51:15 -0500405 case 's':
406 device_manager->enable_save_file (true);
407 break;
408 case 'n':
409 device_manager->set_interval (atoi(optarg));
410 break;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800411#if HAVE_LIBCL
Wind Yuand4427312015-02-11 16:09:00 +0800412 case 'c':
413 have_cl_processor = true;
414 break;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800415#endif
ShincyTu2808b592015-03-13 17:17:25 +0800416 case 'f':
ShincyTuc8466402015-03-31 11:03:39 +0800417 CHECK_EXP ((strlen(optarg) == 4), "invalid pixel format\n");
418 pixel_format = v4l2_fourcc ((unsigned)optarg[0],
419 (unsigned)optarg[1],
420 (unsigned)optarg[2],
421 (unsigned)optarg[3]);
ShincyTu2808b592015-03-13 17:17:25 +0800422 break;
423 case 'd':
424 if (!strcmp (optarg, "still"))
425 capture_mode = V4L2_CAPTURE_MODE_STILL;
426 else if (!strcmp (optarg, "video"))
427 capture_mode = V4L2_CAPTURE_MODE_VIDEO;
428 else {
429 print_help (bin_name);
430 return -1;
431 }
432 break;
yaowang1a5f12122015-07-27 14:53:38 +0800433 case 'b':
434 brightness_level = atoi(optarg);
435 if(brightness_level < 0 || brightness_level > 256) {
436 print_help (bin_name);
437 return -1;
438 }
439 break;
Wind Yuane4ba0c92015-03-26 16:59:06 +0800440 case 'p':
441 need_display = true;
442 break;
Sameer Kibey7b429292015-08-07 10:55:38 -0700443 case 'U':
444 have_usbcam = true;
445 usb_device_name = strdup(optarg);
446 XCAM_LOG_DEBUG("using USB camera plugged in at node: %s", usb_device_name);
447 break;
wangfeicf4c4e72015-05-25 17:11:41 +0800448 case 'e': {
449 if (!strcmp (optarg, "primary"))
450 display_mode = DRM_DISPLAY_MODE_PRIMARY;
451 else if (!strcmp (optarg, "overlay"))
452 display_mode = DRM_DISPLAY_MODE_OVERLAY;
453 else {
454 print_help (bin_name);
455 return -1;
456 }
457 break;
458 }
ShincyTue521cf92015-03-27 15:13:51 +0800459 case 'i':
460 device_manager->set_frame_save(atoi(optarg));
461 break;
Jia Meng8f94a102015-08-11 16:24:19 +0800462 case 'Y':
463 sync_mode = true;
464 break;
Yinhang Liuc2f19082015-08-28 12:27:48 +0800465#if HAVE_LIBCL
Yinhang Liu81c44e02015-06-03 15:47:48 +0800466 case 'H': {
467 if (!strcasecmp (optarg, "rgb"))
468 hdr_type = CL_HDR_TYPE_RGB;
469 else if (!strcasecmp (optarg, "lab"))
470 hdr_type = CL_HDR_TYPE_LAB;
471 else {
472 print_help (bin_name);
473 return -1;
474 }
475 break;
476 }
Yinhang Liub92930c2015-06-23 16:26:35 +0800477 case 'I': {
Jia Meng66efecf2015-06-17 11:11:10 +0000478 denoise_type |= XCAM_DENOISE_TYPE_BILATERAL;
Juan Zhaod9664932015-09-08 10:22:19 +0800479 denoise_type |= XCAM_DENOISE_TYPE_BIYUV;
Yinhang Liu81c44e02015-06-03 15:47:48 +0800480 break;
481 }
482 case 'S': {
Jia Meng66efecf2015-06-17 11:11:10 +0000483 denoise_type |= XCAM_DENOISE_TYPE_SIMPLE;
484 break;
485 }
486 case 'E': {
487 denoise_type |= XCAM_DENOISE_TYPE_EE;
Yinhang Liu81c44e02015-06-03 15:47:48 +0800488 break;
489 }
ShincyTu63e2c262015-06-26 10:52:51 +0800490 case 'B': {
491 denoise_type |= XCAM_DENOISE_TYPE_BNR;
492 break;
493 }
Yinhang Liue26b2622015-07-21 18:32:36 +0800494 case 'D': {
495 dpc_type = true;
496 break;
497 }
Yinhang Liu81c44e02015-06-03 15:47:48 +0800498 case 'T': {
499 if (!strcasecmp (optarg, "yuv"))
500 tnr_type = CL_TNR_TYPE_YUV;
501 else if (!strcasecmp (optarg, "rgb"))
502 tnr_type = CL_TNR_TYPE_RGB;
503 else if (!strcasecmp (optarg, "both"))
504 tnr_type = CL_TNR_TYPE_YUV | CL_TNR_TYPE_RGB;
505 else {
506 print_help (bin_name);
507 return -1;
508 }
509 break;
510 }
511 case 'L': {
512 if (atoi(optarg) < 0 || atoi(optarg) > 255) {
513 print_help (bin_name);
514 return -1;
515 }
516 tnr_level = atoi(optarg);
517 break;
518 }
yaowang16e051152015-08-14 13:49:03 +0800519 case 'M': {
520 tonemapping_type = true;
521 break;
522 }
Jia Menga6580232015-10-08 16:51:28 +0800523 case 'W': {
524 wdr_type = true;
525 break;
526 }
Wangfei1487b9b2015-08-28 15:10:39 +0800527 case 'P': {
528 if (!strcasecmp (optarg, "basic"))
529 pipeline_mode = CL3aImageProcessor::BasicPipelineProfile;
530 else if (!strcasecmp (optarg, "advance"))
531 pipeline_mode = CL3aImageProcessor::AdvancedPipelineProfile;
Wangfei16b65db2015-09-11 14:44:28 +0800532 else if (!strcasecmp (optarg, "extreme"))
533 pipeline_mode = CL3aImageProcessor::ExtremePipelineProfile;
Wangfei1487b9b2015-08-28 15:10:39 +0800534 else {
535 print_help (bin_name);
536 return -1;
537 }
538 break;
539 }
wujunkai166a84ba052015-09-08 15:54:12 +0800540 case 'C': {
541 if (!strcmp (optarg, "bayer"))
542 capture_stage = CL3aImageProcessor::BasicbayerStage;
543 break;
544 }
Yinhang Liuc2f19082015-08-28 12:27:48 +0800545#endif
Wind Yuan75564b12015-01-15 06:51:15 -0500546 case 'h':
547 print_help (bin_name);
548 return 0;
549
550 default:
551 print_help (bin_name);
552 return -1;
553 }
554 }
555
wangfeicf4c4e72015-05-25 17:11:41 +0800556 if (need_display) {
Wind Yuan683f8662015-03-27 18:52:38 +0800557 device_manager->enable_display (true);
wangfeicf4c4e72015-05-25 17:11:41 +0800558 device_manager->set_display_mode (display_mode);
559 }
ShincyTu2808b592015-03-13 17:17:25 +0800560 if (!device.ptr ()) {
Sameer Kibey7b429292015-08-07 10:55:38 -0700561 if (have_usbcam) {
562 device = new UVCDevice (usb_device_name);
563 } else {
564 if (capture_mode == V4L2_CAPTURE_MODE_STILL)
565 device = new AtomispDevice (CAPTURE_DEVICE_STILL);
566 else if (capture_mode == V4L2_CAPTURE_MODE_VIDEO)
567 device = new AtomispDevice (CAPTURE_DEVICE_VIDEO);
568 else
569 device = new AtomispDevice (DEFAULT_CAPTURE_DEVICE);
570 }
ShincyTu2808b592015-03-13 17:17:25 +0800571 }
Wind Yuan75564b12015-01-15 06:51:15 -0500572 if (!event_device.ptr ())
573 event_device = new V4l2SubDevice (DEFAULT_EVENT_DEVICE);
574 if (!isp_controller.ptr ())
575 isp_controller = new IspController (device);
Wind Yuan26e9e212015-04-16 15:55:45 +0800576
577 switch (analyzer_type) {
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800578 case AnalyzerTypeSimple:
579 analyzer = new X3aAnalyzerSimple ();
580 break;
Wind Yuan26e9e212015-04-16 15:55:45 +0800581#if HAVE_IA_AIQ
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800582 case AnalyzerTypeAiq:
583 analyzer = new X3aAnalyzerAiq (isp_controller, DEFAULT_CPF_FILE);
584 break;
Jia Meng9724cfe2015-08-12 15:04:45 +0800585 case AnalyzerTypeHybrid: {
Jia Mengc54c3322015-08-26 09:45:18 +0800586 path_of_3a = DEFAULT_HYBRID_3A_LIB;
zongwave03954a32015-09-22 15:40:44 +0800587 loader = new X3aAnalyzerLoader (path_of_3a);
Jia Meng9724cfe2015-08-12 15:04:45 +0800588 analyzer = loader->load_hybrid_analyzer (loader, isp_controller, DEFAULT_CPF_FILE);
589 CHECK_EXP (analyzer.ptr (), "load hybrid 3a lib(%s) failed", path_of_3a);
590 break;
591 }
Wind Yuan26e9e212015-04-16 15:55:45 +0800592#endif
Wind Yuane25ce3f2015-05-04 18:07:29 +0800593 case AnalyzerTypeDynamic: {
Jia Meng9724cfe2015-08-12 15:04:45 +0800594 path_of_3a = DEFAULT_DYNAMIC_3A_LIB;
zongwave03954a32015-09-22 15:40:44 +0800595 loader = new X3aAnalyzerLoader (path_of_3a);
Jia Meng9724cfe2015-08-12 15:04:45 +0800596 analyzer = loader->load_dynamic_analyzer (loader);
Wind Yuane25ce3f2015-05-04 18:07:29 +0800597 CHECK_EXP (analyzer.ptr (), "load dynamic 3a lib(%s) failed", path_of_3a);
598 break;
599 }
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800600 default:
601 print_help (bin_name);
602 return -1;
Wind Yuan26e9e212015-04-16 15:55:45 +0800603 }
Jia Meng8f94a102015-08-11 16:24:19 +0800604 XCAM_ASSERT (analyzer.ptr ());
605 analyzer->set_sync_mode (sync_mode);
Wind Yuan75564b12015-01-15 06:51:15 -0500606
607 signal(SIGINT, dev_stop_handler);
608
609 device->set_sensor_id (0);
ShincyTu2808b592015-03-13 17:17:25 +0800610 device->set_capture_mode (capture_mode);
Wind Yuan75564b12015-01-15 06:51:15 -0500611 //device->set_mem_type (V4L2_MEMORY_DMABUF);
Wind Yuand4427312015-02-11 16:09:00 +0800612 device->set_mem_type (v4l2_mem_type);
Wind Yuan75564b12015-01-15 06:51:15 -0500613 device->set_buffer_count (8);
Jia Meng757f3c92015-09-09 11:18:36 +0800614 if (pixel_format == V4L2_PIX_FMT_SGRBG12) {
615 frame_rate = 30;
616 device->set_framerate (frame_rate, 1);
617 }
618 else {
619 frame_rate = 25;
620 device->set_framerate (frame_rate, 1);
621 }
Wind Yuan75564b12015-01-15 06:51:15 -0500622 ret = device->open ();
623 CHECK (ret, "device(%s) open failed", device->get_device_name());
ShincyTu2808b592015-03-13 17:17:25 +0800624 ret = device->set_format (1920, 1080, pixel_format, V4L2_FIELD_NONE, 1920 * 2);
Wind Yuan75564b12015-01-15 06:51:15 -0500625 CHECK (ret, "device(%s) set format failed", device->get_device_name());
626
627 ret = event_device->open ();
Wind Yuanb67045c2015-08-27 13:50:53 +0800628 if (ret == XCAM_RETURN_NO_ERROR) {
629 CHECK (ret, "event device(%s) open failed", event_device->get_device_name());
630 int event = V4L2_EVENT_ATOMISP_3A_STATS_READY;
631 ret = event_device->subscribe_event (event);
632 CHECK_CONTINUE (
633 ret,
634 "device(%s) subscribe event(%d) failed",
635 event_device->get_device_name(), event);
636 event = V4L2_EVENT_FRAME_SYNC;
637 ret = event_device->subscribe_event (event);
638 CHECK_CONTINUE (
639 ret,
640 "device(%s) subscribe event(%d) failed",
641 event_device->get_device_name(), event);
642
643 device_manager->set_event_device (event_device);
644 }
Wind Yuan75564b12015-01-15 06:51:15 -0500645
646 device_manager->set_capture_device (device);
Wind Yuan75564b12015-01-15 06:51:15 -0500647 device_manager->set_isp_controller (isp_controller);
648 if (analyzer.ptr())
zongwave03954a32015-09-22 15:40:44 +0800649 device_manager->set_3a_analyzer (analyzer);
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800650
651 if (have_cl_processor)
652 isp_processor = new IspExposureImageProcessor (isp_controller);
653 else
654 isp_processor = new IspImageProcessor (isp_controller);
655
656 XCAM_ASSERT (isp_processor.ptr ());
Wind Yuane4ba0c92015-03-26 16:59:06 +0800657 device_manager->add_image_processor (isp_processor);
Yinhang Liuc2f19082015-08-28 12:27:48 +0800658#if HAVE_LIBCL
wangfeicf4c4e72015-05-25 17:11:41 +0800659 if ((display_mode == DRM_DISPLAY_MODE_PRIMARY) && need_display && (!have_cl_processor)) {
660 cl_csc_proccessor = new CLCscImageProcessor();
661 XCAM_ASSERT (cl_csc_proccessor.ptr ());
662 device_manager->add_image_processor (cl_csc_proccessor);
663 }
Wind Yuan3d1d15e2015-04-16 17:40:47 +0800664
Wind Yuand4427312015-02-11 16:09:00 +0800665 if (have_cl_processor) {
Wind Yuane4ba0c92015-03-26 16:59:06 +0800666 cl_processor = new CL3aImageProcessor ();
Wind Yuan7ddf2602015-04-14 18:49:45 +0800667 cl_processor->set_stats_callback(device_manager);
Yinhang Liue26b2622015-07-21 18:32:36 +0800668 cl_processor->set_dpc(dpc_type);
Yinhang Liu81c44e02015-06-03 15:47:48 +0800669 cl_processor->set_hdr (hdr_type);
Jia Meng66efecf2015-06-17 11:11:10 +0000670 cl_processor->set_denoise (denoise_type);
yaowang16e051152015-08-14 13:49:03 +0800671 cl_processor->set_tonemapping(tonemapping_type);
Jia Menga6580232015-10-08 16:51:28 +0800672 cl_processor->set_gamma (!wdr_type); // disable gamma for WDR
wujunkai166a84ba052015-09-08 15:54:12 +0800673 cl_processor->set_capture_stage (capture_stage);
Wind Yuane4ba0c92015-03-26 16:59:06 +0800674 if (need_display) {
675 cl_processor->set_output_format (V4L2_PIX_FMT_XBGR32);
676 }
Yinhang Liu81c44e02015-06-03 15:47:48 +0800677 cl_processor->set_tnr (tnr_type, tnr_level);
Wangfei1487b9b2015-08-28 15:10:39 +0800678 cl_processor->set_profile (pipeline_mode);
yaowang1a5f12122015-07-27 14:53:38 +0800679 analyzer->set_parameter_brightness((brightness_level - 128) / 128.0);
Wind Yuand4427312015-02-11 16:09:00 +0800680 device_manager->add_image_processor (cl_processor);
681 }
682#endif
Wind Yuane4ba0c92015-03-26 16:59:06 +0800683
Wind Yuan75564b12015-01-15 06:51:15 -0500684 ret = device_manager->start ();
685 CHECK (ret, "device manager start failed");
686
Jia Meng757f3c92015-09-09 11:18:36 +0800687 // hard code exposure range and max gain for imx185 WDR
Jia Menga6580232015-10-08 16:51:28 +0800688 if (wdr_type) {
Jia Meng757f3c92015-09-09 11:18:36 +0800689 if (frame_rate == 30)
690 analyzer->set_ae_exposure_time_range (80 * 1110 * 1000 / 37125, 1120 * 1110 * 1000 / 37125);
691 else
Jia Menga6580232015-10-08 16:51:28 +0800692 analyzer->set_ae_exposure_time_range (80 * 1320 * 1000 / 37125, 1120 * 1320 * 1000 / 37125);
Jia Meng757f3c92015-09-09 11:18:36 +0800693 analyzer->set_ae_max_analog_gain (3.98); // 12dB
694 }
695
Wind Yuan75564b12015-01-15 06:51:15 -0500696 // wait for interruption
697 {
698 SmartLock locker (g_mutex);
699 while (!g_stop)
700 g_cond.wait (g_mutex);
701 }
702
703 ret = device_manager->stop();
704 CHECK_CONTINUE (ret, "device manager stop failed");
705 device->close ();
706 event_device->close ();
707
708 return 0;
709}