• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * handler_interface.cpp - handler interface
3  *
4  *  Copyright (c) 2014-2015 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 "handler_interface.h"
22 
23 namespace XCam {
24 
AeHandler()25 AeHandler::AeHandler()
26 {
27     reset_parameters ();
28 }
29 
30 void
reset_parameters()31 AeHandler::reset_parameters ()
32 {
33     // in case missing any parameters
34     xcam_mem_clear (_params);
35 
36     _params.mode = XCAM_AE_MODE_AUTO;
37     _params.metering_mode = XCAM_AE_METERING_MODE_AUTO;
38     _params.flicker_mode = XCAM_AE_FLICKER_MODE_AUTO;
39     _params.speed = 1.0;
40     _params.exposure_time_min = UINT64_C(0);
41     _params.exposure_time_max = UINT64_C(0);
42     _params.max_analog_gain = 0.0;
43     _params.manual_exposure_time = UINT64_C (0);
44     _params.manual_analog_gain = 0.0;
45     _params.aperture_fn = 0.0;
46     _params.ev_shift = 0.0;
47 
48     _params.window.x_start = 0;
49     _params.window.y_start = 0;
50     _params.window.x_end = 0;
51     _params.window.y_end = 0;
52     _params.window.weight = 0;
53 
54     xcam_mem_clear (_params.window_list);
55 }
56 
57 bool
set_mode(XCamAeMode mode)58 AeHandler::set_mode (XCamAeMode mode)
59 {
60     AnalyzerHandler::HandlerLock lock(this);
61     _params.mode = mode;
62 
63     XCAM_LOG_DEBUG ("ae set mode [%d]", mode);
64     return true;
65 }
66 
67 bool
set_metering_mode(XCamAeMeteringMode mode)68 AeHandler::set_metering_mode (XCamAeMeteringMode mode)
69 {
70     AnalyzerHandler::HandlerLock lock(this);
71     _params.metering_mode = mode;
72 
73     XCAM_LOG_DEBUG ("ae set metering mode [%d]", mode);
74     return true;
75 }
76 
77 bool
set_window(XCam3AWindow * window)78 AeHandler::set_window (XCam3AWindow *window)
79 {
80     AnalyzerHandler::HandlerLock lock(this);
81     _params.window = *window;
82 
83     XCAM_LOG_DEBUG ("ae set metering mode window [x:%d, y:%d, x_end:%d, y_end:%d, weight:%d]",
84                     window->x_start,
85                     window->y_start,
86                     window->x_end,
87                     window->y_end,
88                     window->weight);
89     return true;
90 }
91 
92 bool
set_window(XCam3AWindow * window,uint8_t count)93 AeHandler::set_window (XCam3AWindow *window, uint8_t count)
94 {
95     if (0 == count) {
96         XCAM_LOG_WARNING ("invalid input parameter, window count = %d, reset to default value", count);
97         XCam3AWindow defaultWindow = {0, 0, 1000, 1000, 15};
98         set_window(&defaultWindow);
99         _params.window_list[0] = defaultWindow;
100         return true;
101     }
102 
103     if (XCAM_AE_MAX_METERING_WINDOW_COUNT < count) {
104         XCAM_LOG_WARNING ("invalid input parameter, window count = %d, reset count to maximum", count);
105         count = XCAM_AE_MAX_METERING_WINDOW_COUNT;
106     }
107 
108     AnalyzerHandler::HandlerLock lock(this);
109 
110     _params.window = *window;
111 
112     for (int i = 0; i < count; i++) {
113         XCAM_LOG_DEBUG ("window start point(%d, %d), end point(%d, %d), weight = %d",
114                         window[i].x_start, window[i].y_start, window[i].x_end, window[i].y_end, window[i].weight);
115 
116         _params.window_list[i] = window[i];
117         if (_params.window.weight < window[i].weight) {
118             _params.window.weight = window[i].weight;
119             _params.window.x_start = window[i].x_start;
120             _params.window.y_start = window[i].y_start;
121             _params.window.x_end = window[i].x_end;
122             _params.window.y_end = window[i].y_end;
123         }
124     }
125 
126     XCAM_LOG_DEBUG ("ae set metering mode window [x:%d, y:%d, x_end:%d, y_end:%d, weight:%d]",
127                     _params.window.x_start,
128                     _params.window.y_start,
129                     _params.window.x_end,
130                     _params.window.y_end,
131                     _params.window.weight);
132 
133     return true;
134 }
135 
136 bool
set_ev_shift(double ev_shift)137 AeHandler::set_ev_shift (double ev_shift)
138 {
139     AnalyzerHandler::HandlerLock lock(this);
140     _params.ev_shift = ev_shift;
141 
142     XCAM_LOG_DEBUG ("ae set ev shift:%.03f", ev_shift);
143     return true;
144 }
145 
146 bool
set_speed(double speed)147 AeHandler::set_speed (double speed)
148 {
149     AnalyzerHandler::HandlerLock lock(this);
150     _params.speed = speed;
151 
152     XCAM_LOG_DEBUG ("ae set speed:%.03f", speed);
153     return true;
154 }
155 
156 bool
set_flicker_mode(XCamFlickerMode flicker)157 AeHandler::set_flicker_mode (XCamFlickerMode flicker)
158 {
159     AnalyzerHandler::HandlerLock lock(this);
160     _params.flicker_mode = flicker;
161 
162     XCAM_LOG_DEBUG ("ae set flicker:%d", flicker);
163     return true;
164 }
165 
166 XCamFlickerMode
get_flicker_mode()167 AeHandler::get_flicker_mode ()
168 {
169     AnalyzerHandler::HandlerLock lock(this);
170     return _params.flicker_mode;
171 }
172 
173 int64_t
get_current_exposure_time()174 AeHandler::get_current_exposure_time ()
175 {
176     AnalyzerHandler::HandlerLock lock(this);
177     if (_params.mode == XCAM_AE_MODE_MANUAL)
178         return _params.manual_exposure_time;
179     return INT64_C(-1);
180 }
181 
182 double
get_current_analog_gain()183 AeHandler::get_current_analog_gain ()
184 {
185     AnalyzerHandler::HandlerLock lock(this);
186     if (_params.mode == XCAM_AE_MODE_MANUAL)
187         return _params.manual_analog_gain;
188     return 0.0;
189 }
190 
191 bool
set_manual_exposure_time(int64_t time_in_us)192 AeHandler::set_manual_exposure_time (int64_t time_in_us)
193 {
194     AnalyzerHandler::HandlerLock lock(this);
195     _params.manual_exposure_time = time_in_us;
196 
197     XCAM_LOG_DEBUG ("ae set manual exposure time: %" PRId64 "us", time_in_us);
198     return true;
199 }
200 
201 bool
set_manual_analog_gain(double gain)202 AeHandler::set_manual_analog_gain (double gain)
203 {
204     AnalyzerHandler::HandlerLock lock(this);
205     _params.manual_analog_gain = gain;
206 
207     XCAM_LOG_DEBUG ("ae set manual analog gain: %.03f", gain);
208     return true;
209 }
210 
211 bool
set_aperture(double fn)212 AeHandler::set_aperture (double fn)
213 {
214     AnalyzerHandler::HandlerLock lock(this);
215     _params.aperture_fn = fn;
216 
217     XCAM_LOG_DEBUG ("ae set aperture fn: %.03f", fn);
218     return true;
219 }
220 
221 bool
set_max_analog_gain(double max_gain)222 AeHandler::set_max_analog_gain (double max_gain)
223 {
224     AnalyzerHandler::HandlerLock lock(this);
225     _params.max_analog_gain = max_gain;
226 
227     XCAM_LOG_DEBUG ("ae set max analog_gain: %.03f", max_gain);
228     return true;
229 }
230 
get_max_analog_gain()231 double AeHandler::get_max_analog_gain ()
232 {
233     AnalyzerHandler::HandlerLock lock(this);
234     return _params.max_analog_gain;
235 }
236 
set_exposure_time_range(int64_t min_time_in_us,int64_t max_time_in_us)237 bool AeHandler::set_exposure_time_range (int64_t min_time_in_us, int64_t max_time_in_us)
238 {
239     AnalyzerHandler::HandlerLock lock(this);
240     _params.exposure_time_min = min_time_in_us;
241     _params.exposure_time_max = max_time_in_us;
242 
243     XCAM_LOG_DEBUG ("ae set exposrue range[%" PRId64 "us, %" PRId64 "us]", min_time_in_us, max_time_in_us);
244     return true;
245 }
246 
247 bool
update_parameters(const XCamAeParam & params)248 AeHandler::update_parameters (const XCamAeParam &params)
249 {
250     {
251         AnalyzerHandler::HandlerLock lock (this);
252         _params = params;
253     }
254     XCAM_LOG_DEBUG ("ae parameters updated");
255     return true;
256 }
257 
258 bool
get_exposure_time_range(int64_t * min_time_in_us,int64_t * max_time_in_us)259 AeHandler::get_exposure_time_range (int64_t *min_time_in_us, int64_t *max_time_in_us)
260 {
261     XCAM_ASSERT (min_time_in_us && max_time_in_us);
262 
263     AnalyzerHandler::HandlerLock lock(this);
264     *min_time_in_us = _params.exposure_time_min;
265     *max_time_in_us = _params.exposure_time_max;
266 
267     return true;
268 }
269 
AwbHandler()270 AwbHandler::AwbHandler()
271 {
272     reset_parameters ();
273 }
274 
275 void
reset_parameters()276 AwbHandler::reset_parameters ()
277 {
278     xcam_mem_clear (_params);
279     _params.mode = XCAM_AWB_MODE_AUTO;
280     _params.speed = 1.0;
281     _params.cct_min = 0;
282     _params.cct_max = 0;
283     _params.gr_gain = 0.0;
284     _params.r_gain = 0.0;
285     _params.b_gain = 0.0;
286     _params.gb_gain = 0.0;
287 
288     _params.window.x_start = 0;
289     _params.window.y_start = 0;
290     _params.window.x_end = 0;
291     _params.window.y_end = 0;
292     _params.window.weight = 0;
293 }
294 
295 bool
set_mode(XCamAwbMode mode)296 AwbHandler::set_mode (XCamAwbMode mode)
297 {
298     AnalyzerHandler::HandlerLock lock(this);
299     _params.mode = mode;
300 
301     XCAM_LOG_DEBUG ("awb set mode [%d]", mode);
302     return true;
303 }
304 
305 bool
set_speed(double speed)306 AwbHandler::set_speed (double speed)
307 {
308     XCAM_FAIL_RETURN (
309         ERROR,
310         (0.0 < speed) && (speed <= 1.0),
311         false,
312         "awb speed(%f) is out of range, suggest (0.0, 1.0]", speed);
313 
314     AnalyzerHandler::HandlerLock lock(this);
315     _params.speed = speed;
316 
317     XCAM_LOG_DEBUG ("awb set speed [%f]", speed);
318     return true;
319 }
320 
321 bool
set_color_temperature_range(uint32_t cct_min,uint32_t cct_max)322 AwbHandler::set_color_temperature_range (uint32_t cct_min, uint32_t cct_max)
323 {
324     XCAM_FAIL_RETURN (
325         ERROR,
326         (cct_min <= cct_max),
327         false,
328         "awb set wrong cct(%u, %u) parameters", cct_min, cct_max);
329 
330     AnalyzerHandler::HandlerLock lock(this);
331     _params.cct_min = cct_min;
332     _params.cct_max = cct_max;
333 
334     XCAM_LOG_DEBUG ("awb set cct range [%u, %u]", cct_min, cct_max);
335     return true;
336 }
337 
338 bool
set_manual_gain(double gr,double r,double b,double gb)339 AwbHandler::set_manual_gain (double gr, double r, double b, double gb)
340 {
341     XCAM_FAIL_RETURN (
342         ERROR,
343         gr >= 0.0 && r >= 0.0 && b >= 0.0 && gb >= 0.0,
344         false,
345         "awb manual gain value must >= 0.0");
346 
347     AnalyzerHandler::HandlerLock lock(this);
348     _params.gr_gain = gr;
349     _params.r_gain = r;
350     _params.b_gain = b;
351     _params.gb_gain = gb;
352     XCAM_LOG_DEBUG ("awb set manual gain value(gr:%.03f, r:%.03f, b:%.03f, gb:%.03f)", gr, r, b, gb);
353     return true;
354 }
355 
356 bool
update_parameters(const XCamAwbParam & params)357 AwbHandler::update_parameters (const XCamAwbParam &params)
358 {
359     {
360         AnalyzerHandler::HandlerLock lock (this);
361         _params = params;
362     }
363     XCAM_LOG_DEBUG ("awb parameters updated");
364     return true;
365 }
366 
367 uint32_t
get_current_estimate_cct()368 AwbHandler::get_current_estimate_cct ()
369 {
370     AnalyzerHandler::HandlerLock lock(this);
371     if (_params.mode == XCAM_AWB_MODE_MANUAL)
372         return (_params.cct_max + _params.cct_min) / 2;
373     return 0.0;
374 }
375 
376 bool
update_parameters(const XCamAfParam & params)377 AfHandler::update_parameters (const XCamAfParam &params)
378 {
379     {
380         AnalyzerHandler::HandlerLock lock (this);
381         _params = params;
382     }
383     XCAM_LOG_DEBUG ("af parameters updated");
384     return true;
385 }
386 
CommonHandler()387 CommonHandler::CommonHandler()
388 {
389     reset_parameters ();
390 }
391 
392 void
reset_parameters()393 CommonHandler::reset_parameters ()
394 {
395     xcam_mem_clear (_params);
396 
397     _params.is_manual_gamma = false;
398     _params.nr_level = 0.0;
399     _params.tnr_level = 0.0;
400     _params.brightness = 0.0;
401     _params.contrast = 0.0;
402     _params.hue = 0.0;
403     _params.saturation = 0.0;
404     _params.sharpness = 0.0;
405     _params.enable_dvs = false;
406     _params.enable_gbce = false;
407     _params.enable_night_mode = false;
408 }
409 
set_dvs(bool enable)410 bool CommonHandler::set_dvs (bool enable)
411 {
412     AnalyzerHandler::HandlerLock lock(this);
413     _params.enable_dvs = enable;
414 
415     XCAM_LOG_DEBUG ("common 3A enable dvs:%s", XCAM_BOOL2STR(enable));
416     return true;
417 }
418 
419 bool
set_gbce(bool enable)420 CommonHandler::set_gbce (bool enable)
421 {
422     AnalyzerHandler::HandlerLock lock(this);
423     _params.enable_gbce = enable;
424 
425     XCAM_LOG_DEBUG ("common 3A enable gbce:%s", XCAM_BOOL2STR(enable));
426     return true;
427 }
428 
429 bool
set_night_mode(bool enable)430 CommonHandler::set_night_mode (bool enable)
431 {
432     AnalyzerHandler::HandlerLock lock(this);
433     _params.enable_night_mode = enable;
434 
435     XCAM_LOG_DEBUG ("common 3A enable night mode:%s", XCAM_BOOL2STR(enable));
436     return true;
437 }
438 
439 /* Picture quality */
440 bool
set_noise_reduction_level(double level)441 CommonHandler::set_noise_reduction_level (double level)
442 {
443     XCAM_FAIL_RETURN (
444         ERROR,
445         level >= -1.0 && level < 1.0,
446         false,
447         "set NR levlel(%.03f) out of range[-1.0, 1.0]", level);
448 
449     AnalyzerHandler::HandlerLock lock(this);
450     _params.nr_level = level;
451 
452     XCAM_LOG_DEBUG ("common 3A set NR level:%.03f", level);
453     return true;
454 }
455 
456 bool
set_temporal_noise_reduction_level(double level)457 CommonHandler::set_temporal_noise_reduction_level (double level)
458 {
459     XCAM_FAIL_RETURN (
460         ERROR,
461         level >= -1.0 && level < 1.0,
462         false,
463         "set TNR levlel(%.03f) out of range[-1.0, 1.0]", level);
464 
465     AnalyzerHandler::HandlerLock lock(this);
466     _params.tnr_level = level;
467 
468     XCAM_LOG_DEBUG ("common 3A set TNR level:%.03f", level);
469     return true;
470 }
471 
472 bool
set_manual_brightness(double level)473 CommonHandler::set_manual_brightness (double level)
474 {
475     XCAM_FAIL_RETURN (
476         ERROR,
477         level >= -1.0 && level < 1.0,
478         false,
479         "set brightness levlel(%.03f) out of range[-1.0, 1.0]", level);
480 
481     AnalyzerHandler::HandlerLock lock(this);
482     _params.brightness = level;
483 
484     XCAM_LOG_DEBUG ("common 3A set brightness level:%.03f", level);
485     return true;
486 }
487 
set_manual_contrast(double level)488 bool CommonHandler::set_manual_contrast (double level)
489 {
490     XCAM_FAIL_RETURN (
491         ERROR,
492         level >= -1.0 && level < 1.0,
493         false,
494         "set contrast levlel(%.03f) out of range[-1.0, 1.0]", level);
495 
496     AnalyzerHandler::HandlerLock lock(this);
497     _params.contrast = level;
498 
499     XCAM_LOG_DEBUG ("common 3A set contrast level:%.03f", level);
500     return true;
501 }
502 
set_manual_hue(double level)503 bool CommonHandler::set_manual_hue (double level)
504 {
505     XCAM_FAIL_RETURN (
506         ERROR,
507         level >= -1.0 && level < 1.0,
508         false,
509         "set hue levlel(%.03f) out of range[-1.0, 1.0]", level);
510 
511     AnalyzerHandler::HandlerLock lock(this);
512     _params.hue = level;
513 
514     XCAM_LOG_DEBUG ("common 3A set hue level:%.03f", level);
515     return true;
516 }
517 
518 bool
set_manual_saturation(double level)519 CommonHandler::set_manual_saturation (double level)
520 {
521     XCAM_FAIL_RETURN (
522         ERROR,
523         level >= -1.0 && level < 1.0,
524         false,
525         "set saturation levlel(%.03f) out of range[-1.0, 1.0]", level);
526 
527     AnalyzerHandler::HandlerLock lock(this);
528     _params.saturation = level;
529 
530     XCAM_LOG_DEBUG ("common 3A set saturation level:%.03f", level);
531     return true;
532 }
533 
set_manual_sharpness(double level)534 bool CommonHandler::set_manual_sharpness (double level)
535 {
536     XCAM_FAIL_RETURN (
537         ERROR,
538         level >= -1.0 && level < 1.0,
539         false,
540         "set sharpness levlel(%.03f) out of range[-1.0, 1.0]", level);
541 
542     AnalyzerHandler::HandlerLock lock(this);
543     _params.sharpness = level;
544 
545     XCAM_LOG_DEBUG ("common 3A set sharpness level:%.03f", level);
546     return true;
547 }
548 
549 bool
set_gamma_table(double * r_table,double * g_table,double * b_table)550 CommonHandler::set_gamma_table (double *r_table, double *g_table, double *b_table)
551 {
552     AnalyzerHandler::HandlerLock lock(this);
553     if (!r_table && ! g_table && !b_table) {
554         _params.is_manual_gamma = false;
555         XCAM_LOG_DEBUG ("common 3A disabled gamma");
556         return true;
557     }
558 
559     if (!r_table || !g_table || !b_table) {
560         XCAM_LOG_ERROR ("common 3A gamma table parameters wrong");
561         return false;
562     }
563 
564     for (uint32_t i = 0; i < XCAM_GAMMA_TABLE_SIZE; ++i) {
565         _params.r_gamma [i] = r_table [i];
566         _params.g_gamma [i] = g_table [i];
567         _params.b_gamma [i] = b_table [i];
568     }
569     _params.is_manual_gamma = true;
570 
571     XCAM_LOG_DEBUG ("common 3A enabled RGB gamma");
572     return true;
573 }
574 
575 bool
set_color_effect(XCamColorEffect effect)576 CommonHandler::set_color_effect (XCamColorEffect effect)
577 {
578     // TODO validate the input
579 
580     AnalyzerHandler::HandlerLock lock(this);
581 
582     _params.color_effect = effect;
583 
584     XCAM_LOG_DEBUG ("common 3A set color effect");
585     return true;
586 }
587 
588 bool
update_parameters(const XCamCommonParam & params)589 CommonHandler::update_parameters (const XCamCommonParam &params)
590 {
591     {
592         AnalyzerHandler::HandlerLock lock (this);
593         _params = params;
594     }
595     XCAM_LOG_DEBUG ("common parameters updated");
596     return true;
597 }
598 
599 };
600