• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * x3a_analyzer.cpp - 3a analyzer
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 "xcam_analyzer.h"
22 #include "x3a_analyzer.h"
23 #include "x3a_stats_pool.h"
24 
25 namespace XCam {
26 
X3aAnalyzer(const char * name)27 X3aAnalyzer::X3aAnalyzer (const char *name)
28     : XAnalyzer (name)
29     , _brightness_level_param (0.0)
30     , _ae_handler (NULL)
31     , _awb_handler (NULL)
32     , _af_handler (NULL)
33     , _common_handler (NULL)
34 {
35 }
36 
~X3aAnalyzer()37 X3aAnalyzer::~X3aAnalyzer()
38 {
39 }
40 
41 XCamReturn
create_handlers()42 X3aAnalyzer::create_handlers ()
43 {
44     SmartPtr<AeHandler> ae_handler;
45     SmartPtr<AwbHandler> awb_handler;
46     SmartPtr<AfHandler> af_handler;
47     SmartPtr<CommonHandler> common_handler;
48 
49     if (_ae_handler.ptr() && _awb_handler.ptr() &&
50             _af_handler.ptr() && _common_handler.ptr())
51         return XCAM_RETURN_NO_ERROR;
52 
53     ae_handler = create_ae_handler ();
54     awb_handler = create_awb_handler ();
55     af_handler = create_af_handler ();
56     common_handler = create_common_handler ();
57 
58     if (!ae_handler.ptr() || !awb_handler.ptr() || !af_handler.ptr() || !common_handler.ptr()) {
59         XCAM_LOG_WARNING ("create handlers failed");
60         return XCAM_RETURN_ERROR_MEM;
61     }
62 
63     _ae_handler = ae_handler;
64     _awb_handler = awb_handler;
65     _af_handler = af_handler;
66     _common_handler = common_handler;
67 
68     return XCAM_RETURN_NO_ERROR;
69 }
70 
71 XCamReturn
release_handlers()72 X3aAnalyzer::release_handlers ()
73 {
74     _ae_handler.release ();
75     _awb_handler.release ();
76     _af_handler.release ();
77     _common_handler.release ();
78 
79     return XCAM_RETURN_NO_ERROR;
80 }
81 
82 XCamReturn
configure()83 X3aAnalyzer::configure ()
84 {
85     return configure_3a ();
86 }
87 
88 XCamReturn
analyze(const SmartPtr<VideoBuffer> & buffer)89 X3aAnalyzer::analyze (const SmartPtr<VideoBuffer> &buffer)
90 {
91     SmartPtr<X3aStats> stats = buffer.dynamic_cast_ptr<X3aStats> ();
92 
93     return analyze_3a_statistics (stats);
94 }
95 
96 XCamReturn
push_3a_stats(const SmartPtr<X3aStats> & stats)97 X3aAnalyzer::push_3a_stats (const SmartPtr<X3aStats> &stats)
98 {
99     return XAnalyzer::push_buffer (stats);
100 }
101 
102 
103 XCamReturn
analyze_3a_statistics(SmartPtr<X3aStats> & stats)104 X3aAnalyzer::analyze_3a_statistics (SmartPtr<X3aStats> &stats)
105 {
106     XCamReturn ret = XCAM_RETURN_NO_ERROR;
107     X3aResultList results;
108 
109     ret = pre_3a_analyze (stats);
110     if (ret != XCAM_RETURN_NO_ERROR) {
111         notify_calculation_failed(
112             NULL, stats->get_timestamp (), "pre 3a analyze failed");
113         return ret;
114     }
115 
116     ret = _ae_handler->analyze (results);
117     if (ret != XCAM_RETURN_NO_ERROR) {
118         notify_calculation_failed(
119             _ae_handler.ptr(), stats->get_timestamp (), "ae calculation failed");
120         return ret;
121     }
122 
123     ret = _awb_handler->analyze (results);
124     if (ret != XCAM_RETURN_NO_ERROR) {
125         notify_calculation_failed(
126             _awb_handler.ptr(), stats->get_timestamp (), "awb calculation failed");
127         return ret;
128     }
129 
130     ret = _af_handler->analyze (results);
131     if (ret != XCAM_RETURN_NO_ERROR) {
132         notify_calculation_failed(
133             _af_handler.ptr(), stats->get_timestamp (), "af calculation failed");
134         return ret;
135     }
136 
137     ret = _common_handler->analyze (results);
138     if (ret != XCAM_RETURN_NO_ERROR) {
139         notify_calculation_failed(
140             _common_handler.ptr(), stats->get_timestamp (), "3a other calculation failed");
141         return ret;
142     }
143 
144     ret = post_3a_analyze (results);
145     if (ret != XCAM_RETURN_NO_ERROR) {
146         notify_calculation_failed(
147             NULL, stats->get_timestamp (), "3a collect results failed");
148         return ret;
149     }
150 
151     if (!results.empty ()) {
152         set_results_timestamp(results, stats->get_timestamp ());
153         notify_calculation_done (results);
154     }
155 
156     return ret;
157 }
158 
159 /* AWB */
160 bool
set_awb_mode(XCamAwbMode mode)161 X3aAnalyzer::set_awb_mode (XCamAwbMode mode)
162 {
163     XCAM_ASSERT (_awb_handler.ptr());
164     return _awb_handler->set_mode (mode);
165 }
166 
167 bool
set_awb_speed(double speed)168 X3aAnalyzer::set_awb_speed (double speed)
169 {
170     XCAM_ASSERT (_awb_handler.ptr());
171     return _awb_handler->set_speed (speed);
172 }
173 
174 bool
set_awb_color_temperature_range(uint32_t cct_min,uint32_t cct_max)175 X3aAnalyzer::set_awb_color_temperature_range (uint32_t cct_min, uint32_t cct_max)
176 {
177     XCAM_ASSERT (_awb_handler.ptr());
178     return _awb_handler->set_color_temperature_range (cct_min, cct_max);
179 }
180 
181 bool
set_awb_manual_gain(double gr,double r,double b,double gb)182 X3aAnalyzer::set_awb_manual_gain (double gr, double r, double b, double gb)
183 {
184     XCAM_ASSERT (_awb_handler.ptr());
185     return _awb_handler->set_manual_gain (gr, r, b, gb);
186 }
187 
188 /* AE */
189 bool
set_ae_mode(XCamAeMode mode)190 X3aAnalyzer::set_ae_mode (XCamAeMode mode)
191 {
192     XCAM_ASSERT (_ae_handler.ptr());
193     return _ae_handler->set_mode (mode);
194 }
195 
196 bool
set_ae_metering_mode(XCamAeMeteringMode mode)197 X3aAnalyzer::set_ae_metering_mode (XCamAeMeteringMode mode)
198 {
199     XCAM_ASSERT (_ae_handler.ptr());
200     return _ae_handler->set_metering_mode (mode);
201 }
202 
203 bool
set_ae_window(XCam3AWindow * window,uint8_t count)204 X3aAnalyzer::set_ae_window (XCam3AWindow *window, uint8_t count)
205 {
206     XCAM_ASSERT (_ae_handler.ptr());
207     return _ae_handler->set_window (window, count);
208 }
209 
210 bool
set_ae_ev_shift(double ev_shift)211 X3aAnalyzer::set_ae_ev_shift (double ev_shift)
212 {
213     XCAM_ASSERT (_ae_handler.ptr());
214     return _ae_handler->set_ev_shift (ev_shift);
215 }
216 
217 bool
set_ae_speed(double speed)218 X3aAnalyzer::set_ae_speed (double speed)
219 {
220     XCAM_ASSERT (_ae_handler.ptr());
221     return _ae_handler->set_speed (speed);
222 }
223 
224 bool
set_ae_flicker_mode(XCamFlickerMode flicker)225 X3aAnalyzer::set_ae_flicker_mode (XCamFlickerMode flicker)
226 {
227     XCAM_ASSERT (_ae_handler.ptr());
228     return _ae_handler->set_flicker_mode (flicker);
229 }
230 
231 XCamFlickerMode
get_ae_flicker_mode()232 X3aAnalyzer::get_ae_flicker_mode ()
233 {
234     XCAM_ASSERT (_ae_handler.ptr());
235     return _ae_handler->get_flicker_mode ();
236 }
237 
238 uint64_t
get_ae_current_exposure_time()239 X3aAnalyzer::get_ae_current_exposure_time ()
240 {
241     XCAM_ASSERT (_ae_handler.ptr());
242     return _ae_handler->get_current_exposure_time();
243 }
244 
245 double
get_ae_current_analog_gain()246 X3aAnalyzer::get_ae_current_analog_gain ()
247 {
248     XCAM_ASSERT (_ae_handler.ptr());
249     return _ae_handler->get_current_analog_gain ();
250 }
251 
252 bool
set_ae_manual_exposure_time(int64_t time_in_us)253 X3aAnalyzer::set_ae_manual_exposure_time (int64_t time_in_us)
254 {
255     XCAM_ASSERT (_ae_handler.ptr());
256     return _ae_handler->set_manual_exposure_time (time_in_us);
257 }
258 
259 bool
set_ae_manual_analog_gain(double gain)260 X3aAnalyzer::set_ae_manual_analog_gain (double gain)
261 {
262     XCAM_ASSERT (_ae_handler.ptr());
263     return _ae_handler->set_manual_analog_gain (gain);
264 }
265 
266 bool
set_ae_aperture(double fn)267 X3aAnalyzer::set_ae_aperture (double fn)
268 {
269     XCAM_ASSERT (_ae_handler.ptr());
270     return _ae_handler->set_aperture (fn);
271 }
272 
273 bool
set_ae_max_analog_gain(double max_gain)274 X3aAnalyzer::set_ae_max_analog_gain (double max_gain)
275 {
276     XCAM_ASSERT (_ae_handler.ptr());
277     return _ae_handler->set_max_analog_gain (max_gain);
278 }
279 
280 double
get_ae_max_analog_gain()281 X3aAnalyzer::get_ae_max_analog_gain ()
282 {
283     XCAM_ASSERT (_ae_handler.ptr());
284     return _ae_handler->get_max_analog_gain();
285 }
286 
287 bool
set_ae_exposure_time_range(int64_t min_time_in_us,int64_t max_time_in_us)288 X3aAnalyzer::set_ae_exposure_time_range (int64_t min_time_in_us, int64_t max_time_in_us)
289 {
290     XCAM_ASSERT (_ae_handler.ptr());
291     return _ae_handler->set_exposure_time_range (min_time_in_us, max_time_in_us);
292 }
293 
294 bool
get_ae_exposure_time_range(int64_t * min_time_in_us,int64_t * max_time_in_us)295 X3aAnalyzer::get_ae_exposure_time_range (int64_t *min_time_in_us, int64_t *max_time_in_us)
296 {
297     XCAM_ASSERT (_ae_handler.ptr());
298     return _ae_handler->get_exposure_time_range (min_time_in_us, max_time_in_us);
299 }
300 
301 /* DVS */
302 bool
set_dvs(bool enable)303 X3aAnalyzer::set_dvs (bool enable)
304 {
305     XCAM_ASSERT (_common_handler.ptr());
306     return _common_handler->set_dvs (enable);
307 }
308 
309 bool
set_gbce(bool enable)310 X3aAnalyzer::set_gbce (bool enable)
311 {
312     XCAM_ASSERT (_common_handler.ptr());
313     return _common_handler->set_gbce (enable);
314 }
315 
316 bool
set_night_mode(bool enable)317 X3aAnalyzer::set_night_mode (bool enable)
318 {
319     XCAM_ASSERT (_common_handler.ptr());
320     return _common_handler->set_night_mode (enable);
321 }
322 
323 bool
set_color_effect(XCamColorEffect type)324 X3aAnalyzer::set_color_effect (XCamColorEffect type)
325 {
326 
327     XCAM_ASSERT (_common_handler.ptr());
328     return _common_handler->set_color_effect (type);
329 }
330 
331 /* Picture quality */
332 bool
set_noise_reduction_level(double level)333 X3aAnalyzer::set_noise_reduction_level (double level)
334 {
335     XCAM_ASSERT (_common_handler.ptr());
336     return _common_handler->set_noise_reduction_level (level);
337 }
338 
339 bool
set_temporal_noise_reduction_level(double level)340 X3aAnalyzer::set_temporal_noise_reduction_level (double level)
341 {
342     XCAM_ASSERT (_common_handler.ptr());
343     return _common_handler->set_temporal_noise_reduction_level (level);
344 }
345 
346 bool
set_manual_brightness(double level)347 X3aAnalyzer::set_manual_brightness (double level)
348 {
349     XCAM_ASSERT (_common_handler.ptr());
350     return _common_handler->set_manual_brightness (level);
351 }
352 
353 bool
set_manual_contrast(double level)354 X3aAnalyzer::set_manual_contrast (double level)
355 {
356     XCAM_ASSERT (_common_handler.ptr());
357     return _common_handler->set_manual_contrast (level);
358 }
359 
360 bool
set_manual_hue(double level)361 X3aAnalyzer::set_manual_hue (double level)
362 {
363     XCAM_ASSERT (_common_handler.ptr());
364     return _common_handler->set_manual_hue (level);
365 }
366 
367 bool
set_manual_saturation(double level)368 X3aAnalyzer::set_manual_saturation (double level)
369 {
370     XCAM_ASSERT (_common_handler.ptr());
371     return _common_handler->set_manual_saturation (level);
372 }
373 
374 bool
set_manual_sharpness(double level)375 X3aAnalyzer::set_manual_sharpness (double level)
376 {
377     XCAM_ASSERT (_common_handler.ptr());
378     return _common_handler->set_manual_sharpness (level);
379 }
380 
381 bool
set_gamma_table(double * r_table,double * g_table,double * b_table)382 X3aAnalyzer::set_gamma_table (double *r_table, double *g_table, double *b_table)
383 {
384     XCAM_ASSERT (_common_handler.ptr());
385     return _common_handler->set_gamma_table (r_table, g_table, b_table);
386 }
387 
388 bool
set_parameter_brightness(double level)389 X3aAnalyzer::set_parameter_brightness(double level)
390 {
391     _brightness_level_param = level;
392     return true;
393 }
394 
395 bool
update_awb_parameters(const XCamAwbParam & params)396 X3aAnalyzer::update_awb_parameters (const XCamAwbParam &params)
397 {
398     XCAM_ASSERT (_awb_handler.ptr());
399     return _awb_handler->update_parameters (params);
400 }
401 
402 bool
update_common_parameters(const XCamCommonParam & params)403 X3aAnalyzer::update_common_parameters (const XCamCommonParam &params)
404 {
405     XCAM_ASSERT (_common_handler.ptr());
406     return _common_handler->update_parameters (params);
407 }
408 
409 bool
update_ae_parameters(const XCamAeParam & params)410 X3aAnalyzer::update_ae_parameters (const XCamAeParam &params)
411 {
412     XCAM_ASSERT (_ae_handler.ptr());
413     return _ae_handler->update_parameters (params);
414 }
415 
416 bool
update_af_parameters(const XCamAfParam & params)417 X3aAnalyzer::update_af_parameters (const XCamAfParam &params)
418 {
419     XCAM_ASSERT (_af_handler.ptr());
420     return _af_handler->update_parameters (params);
421 }
422 
423 };
424