• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * x3a_analyze_tuner.cpp - x3a analyzer Common IQ tuning adaptor
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: Zong Wei <wei.zong@intel.com>
19  */
20 
21 #include "xcam_utils.h"
22 #include "x3a_stats_pool.h"
23 #include "x3a_analyzer.h"
24 #include "x3a_analyze_tuner.h"
25 #include "x3a_ciq_tuning_handler.h"
26 #include "x3a_ciq_tnr_tuning_handler.h"
27 #include "x3a_ciq_bnr_ee_tuning_handler.h"
28 #include "x3a_ciq_wavelet_tuning_handler.h"
29 
30 namespace XCam {
31 
X3aAnalyzeTuner()32 X3aAnalyzeTuner::X3aAnalyzeTuner ()
33     : X3aAnalyzer ("X3aAnalyzeTuner")
34 {
35 }
36 
~X3aAnalyzeTuner()37 X3aAnalyzeTuner::~X3aAnalyzeTuner ()
38 {
39 }
40 
41 void
set_analyzer(SmartPtr<X3aAnalyzer> & analyzer)42 X3aAnalyzeTuner::set_analyzer (SmartPtr<X3aAnalyzer> &analyzer)
43 {
44     XCAM_ASSERT (analyzer.ptr () && !_analyzer.ptr ());
45     _analyzer = analyzer;
46 
47     _analyzer->set_results_callback (this);
48     _analyzer->prepare_handlers ();
49     _analyzer->set_sync_mode (true);
50 }
51 
52 XCamReturn
create_tuning_handlers()53 X3aAnalyzeTuner::create_tuning_handlers ()
54 {
55     XCamReturn ret = XCAM_RETURN_NO_ERROR;
56 
57     SmartPtr<AeHandler> ae_handler = _analyzer->get_ae_handler ();
58     SmartPtr<AwbHandler> awb_handler = _analyzer->get_awb_handler();
59 
60     SmartPtr<X3aCiqTuningHandler> tnr_tuning = new X3aCiqTnrTuningHandler ();
61     SmartPtr<X3aCiqTuningHandler> bnr_ee_tuning = new X3aCiqBnrEeTuningHandler ();
62     SmartPtr<X3aCiqTuningHandler> wavelet_tuning = new X3aCiqWaveletTuningHandler ();
63 
64     if (tnr_tuning.ptr ()) {
65         tnr_tuning->set_ae_handler (ae_handler);
66         tnr_tuning->set_awb_handler (awb_handler);
67         add_handler (tnr_tuning);
68     } else {
69         ret = XCAM_RETURN_ERROR_PARAM;
70     }
71 
72     if (bnr_ee_tuning.ptr ()) {
73         bnr_ee_tuning->set_ae_handler (ae_handler);
74         bnr_ee_tuning->set_awb_handler (awb_handler);
75         add_handler (bnr_ee_tuning);
76     } else {
77         ret = XCAM_RETURN_ERROR_PARAM;
78     }
79 
80     if (wavelet_tuning.ptr ()) {
81         wavelet_tuning->set_ae_handler (ae_handler);
82         wavelet_tuning->set_awb_handler (awb_handler);
83         add_handler (wavelet_tuning);
84     } else {
85         ret = XCAM_RETURN_ERROR_PARAM;
86     }
87 
88     return ret;
89 }
90 
91 bool
add_handler(SmartPtr<X3aCiqTuningHandler> & handler)92 X3aAnalyzeTuner::add_handler (SmartPtr<X3aCiqTuningHandler> &handler)
93 {
94     XCAM_ASSERT (handler.ptr ());
95     _handlers.push_back (handler);
96     return true;
97 }
98 
99 XCamReturn
analyze_ae(XCamAeParam & param)100 X3aAnalyzeTuner::analyze_ae (XCamAeParam &param)
101 {
102     XCamReturn ret = XCAM_RETURN_NO_ERROR;
103 
104     XCAM_ASSERT (_analyzer.ptr ());
105     _analyzer->update_ae_parameters (param);
106     return ret;
107 }
108 
109 XCamReturn
analyze_awb(XCamAwbParam & param)110 X3aAnalyzeTuner::analyze_awb (XCamAwbParam &param)
111 {
112     XCamReturn ret = XCAM_RETURN_NO_ERROR;
113 
114     XCAM_ASSERT (_analyzer.ptr ());
115     _analyzer->update_awb_parameters (param);
116     return ret;
117 }
118 
119 XCamReturn
analyze_af(XCamAfParam & param)120 X3aAnalyzeTuner::analyze_af (XCamAfParam &param)
121 {
122     XCamReturn ret = XCAM_RETURN_NO_ERROR;
123 
124     XCAM_ASSERT (_analyzer.ptr ());
125     _analyzer->update_af_parameters (param);
126     return ret;
127 }
128 
129 XCamReturn
analyze_common(XCamCommonParam & param)130 X3aAnalyzeTuner::analyze_common (XCamCommonParam &param)
131 {
132     XCamReturn ret = XCAM_RETURN_NO_ERROR;
133 
134     XCAM_ASSERT (_analyzer.ptr ());
135     _analyzer->update_common_parameters (param);
136     return ret;
137 }
138 
139 SmartPtr<AeHandler>
create_ae_handler()140 X3aAnalyzeTuner::create_ae_handler ()
141 {
142     SmartPtr<AeHandler> ae_handler = new X3aCiqTuningAeHandler (this);
143     return ae_handler;
144 }
145 
146 SmartPtr<AwbHandler>
create_awb_handler()147 X3aAnalyzeTuner::create_awb_handler ()
148 {
149     SmartPtr<AwbHandler> awb_handler = new X3aCiqTuningAwbHandler (this);
150     return awb_handler;
151 }
152 
153 SmartPtr<AfHandler>
create_af_handler()154 X3aAnalyzeTuner::create_af_handler ()
155 {
156     SmartPtr<AfHandler> af_handler = new X3aCiqTuningAfHandler (this);
157     return af_handler;
158 }
159 
160 SmartPtr<CommonHandler>
create_common_handler()161 X3aAnalyzeTuner::create_common_handler ()
162 {
163     SmartPtr<CommonHandler> common_handler = new X3aCiqTuningCommonHandler (this);
164     return common_handler;
165 }
166 
167 XCamReturn
internal_init(uint32_t width,uint32_t height,double framerate)168 X3aAnalyzeTuner::internal_init (uint32_t width, uint32_t height, double framerate)
169 {
170     XCAM_ASSERT (_analyzer.ptr ());
171     XCamReturn ret = XCAM_RETURN_NO_ERROR;
172 
173     _analyzer->init (width, height, framerate);
174 
175     if (XCAM_RETURN_NO_ERROR == ret) {
176         ret = create_tuning_handlers ();
177     }
178     return ret;
179 }
180 
181 XCamReturn
internal_deinit()182 X3aAnalyzeTuner::internal_deinit ()
183 {
184     XCAM_ASSERT (_analyzer.ptr ());
185     XCamReturn ret = XCAM_RETURN_NO_ERROR;
186 
187     ret = _analyzer->deinit ();
188 
189     return ret;
190 }
191 
192 XCamReturn
configure_3a()193 X3aAnalyzeTuner::configure_3a ()
194 {
195     XCAM_ASSERT (_analyzer.ptr ());
196     XCamReturn ret = XCAM_RETURN_NO_ERROR;
197 
198     ret = _analyzer->start ();
199 
200     return ret;
201 }
202 
203 XCamReturn
pre_3a_analyze(SmartPtr<X3aStats> & stats)204 X3aAnalyzeTuner::pre_3a_analyze (SmartPtr<X3aStats> &stats)
205 {
206     // save stats for aiq analyzer
207     XCamReturn ret = XCAM_RETURN_NO_ERROR;
208     if (stats.ptr ()) {
209         _stats = stats;
210     }
211     return ret;
212 }
213 
214 XCamReturn
post_3a_analyze(X3aResultList & results)215 X3aAnalyzeTuner::post_3a_analyze (X3aResultList &results)
216 {
217     XCamReturn ret = XCAM_RETURN_NO_ERROR;
218 
219     XCAM_ASSERT (_analyzer.ptr ());
220     ret = _analyzer->push_3a_stats (_stats);
221     _stats.release ();
222 
223     results.insert (results.end (), _results.begin (), _results.end ());
224     _results.clear ();
225 
226     X3aCiqTuningHandlerList::iterator i_handler = _handlers.begin ();
227     for (; i_handler != _handlers.end ();  ++i_handler)
228     {
229         (*i_handler)->analyze (results);
230     }
231 
232     return ret;
233 }
234 
235 void
x3a_calculation_done(XAnalyzer * analyzer,X3aResultList & results)236 X3aAnalyzeTuner::x3a_calculation_done (XAnalyzer *analyzer, X3aResultList &results)
237 {
238     XCAM_UNUSED (analyzer);
239     _results.clear ();
240     _results.assign (results.begin (), results.end ());
241 }
242 
243 };
244 
245