blob: 0d6c68122e33873544be422f1e593a24fac6a663 [file] [log] [blame]
Wind Yuan75564b12015-01-15 06:51:15 -05001/*
2 * x3a_image_process_center.cpp - 3a process center
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#include "x3a_image_process_center.h"
21
22namespace XCam {
23
24X3aImageProcessCenter::X3aImageProcessCenter()
25 : _callback (NULL)
26{
27 XCAM_LOG_DEBUG ("X3aImageProcessCenter construction");
28}
29
30X3aImageProcessCenter::~X3aImageProcessCenter()
31{
32 stop ();
33 XCAM_LOG_DEBUG ("~X3aImageProcessCenter destruction");
34}
35
36bool
37X3aImageProcessCenter::set_image_callback (ImageProcessCallback *callback)
38{
39 XCAM_ASSERT (!_callback);
40 _callback = callback;
41 return true;
42}
43
44bool
45X3aImageProcessCenter::insert_processor (SmartPtr<ImageProcessor> &processor)
46{
47 _image_processors.push_back (processor);
48 XCAM_LOG_INFO ("Add processor(%s) into image processor center", XCAM_STR (processor->get_name()));
49 return true;
50}
51
52bool
53X3aImageProcessCenter::has_processors ()
54{
55 return !_image_processors.empty();
56}
57
58XCamReturn
59X3aImageProcessCenter::start ()
60{
61 XCamReturn ret = XCAM_RETURN_NO_ERROR;
62
63 if (_image_processors.empty()) {
64 XCAM_LOG_ERROR ("process center start failed, no processor found");
65 return XCAM_RETURN_ERROR_PARAM;
66 }
67
68 for (ImageProcessorList::iterator i_pro = _image_processors.begin ();
69 i_pro != _image_processors.end(); ++i_pro)
70 {
71 SmartPtr<ImageProcessor> &processor = *i_pro;
72 XCAM_ASSERT (processor.ptr());
73 processor->set_callback (this);
74 ret = processor->start ();
75 if (ret != XCAM_RETURN_NO_ERROR) {
76 XCAM_LOG_ERROR ("processor(%s) start failed", XCAM_STR(processor->get_name()));
77 break;
78 }
79 }
80
81 if (ret != XCAM_RETURN_NO_ERROR)
82 stop();
83 else {
84 XCAM_LOG_INFO ("3a process center started");
85 }
86
87 return ret;
88}
89
90XCamReturn
91X3aImageProcessCenter::stop ()
92{
93 for (ImageProcessorList::iterator i_pro = _image_processors.begin ();
94 i_pro != _image_processors.end(); ++i_pro)
95 {
96 SmartPtr<ImageProcessor> &processor = *i_pro;
97 XCAM_ASSERT (processor.ptr());
98 processor->stop ();
99 }
100
101 XCAM_LOG_INFO ("3a process center stopped");
102
103 _image_processors.clear();
104 return XCAM_RETURN_NO_ERROR;
105}
106
107bool
108X3aImageProcessCenter::put_buffer (SmartPtr<VideoBuffer> &buf)
109{
110 XCAM_ASSERT (!_image_processors.empty());
111 if (_image_processors.empty())
112 return false;
113
114 ImageProcessorList::iterator i_pro = _image_processors.begin ();
115 SmartPtr<ImageProcessor> &processor = *i_pro;
116 if (processor->push_buffer (buf) != XCAM_RETURN_NO_ERROR)
117 return false;
118 return true;
119}
120
121
122XCamReturn
123X3aImageProcessCenter::put_3a_results (X3aResultList &results)
124{
125 XCamReturn ret = XCAM_RETURN_NO_ERROR;
126
127 XCAM_FAIL_RETURN (ERROR, !results.empty(), XCAM_RETURN_ERROR_PARAM, "results empty");
128
129 for (ImageProcessorIter i_pro = _image_processors.begin();
130 i_pro != _image_processors.end(); i_pro++) {
131 SmartPtr<ImageProcessor> &processor = *i_pro;
132 XCAM_ASSERT (processor.ptr());
133 ret = processor->push_3a_results (results);
134 if (ret != XCAM_RETURN_NO_ERROR && ret != XCAM_RETURN_BYPASS) {
135 XCAM_LOG_WARNING ("processor(%s) gailed on results", XCAM_STR(processor->get_name()));
136 break;
137 }
138 if (results.empty ()) {
139 XCAM_LOG_DEBUG ("results done");
140 return XCAM_RETURN_NO_ERROR;
141 }
142 }
143
144 if (!results.empty()) {
145 XCAM_LOG_DEBUG ("process center: results left without being processed");
146 return XCAM_RETURN_BYPASS;
147 }
148
149 return XCAM_RETURN_NO_ERROR;
150}
151
152XCamReturn
153X3aImageProcessCenter::put_3a_result (SmartPtr<X3aResult> &result)
154{
155 XCamReturn ret = XCAM_RETURN_NO_ERROR;
156
157 XCAM_FAIL_RETURN (ERROR, !result.ptr(), XCAM_RETURN_ERROR_PARAM, "result empty");
158
159 for (ImageProcessorIter i_pro = _image_processors.begin();
160 i_pro != _image_processors.end(); i_pro++)
161 {
162 SmartPtr<ImageProcessor> &processor = *i_pro;
163 XCAM_ASSERT (processor.ptr());
164 ret = processor->push_3a_result (result);
165
166 if (ret == XCAM_RETURN_BYPASS)
167 continue;
168
169 if (ret == XCAM_RETURN_NO_ERROR)
170 return XCAM_RETURN_NO_ERROR;
171
172 XCAM_LOG_WARNING ("processor(%s) failed on result", XCAM_STR(processor->get_name()));
173 return ret;
174 }
175
176 if (ret == XCAM_RETURN_BYPASS) {
177 XCAM_LOG_WARNING ("processor center: no processor can handle result()");
178 }
179
180 return ret;
181}
182
183void
184X3aImageProcessCenter::process_buffer_done (ImageProcessor *processor, SmartPtr<VideoBuffer> &buf)
185{
186 ImageProcessorIter i_pro = _image_processors.begin();
187 for (; i_pro != _image_processors.end(); ++i_pro)
188 {
189 SmartPtr<ImageProcessor> &cur_pro = *i_pro;
190 XCAM_ASSERT (cur_pro.ptr());
191 if (cur_pro.ptr() == processor)
192 break;
193 }
194
195 XCAM_ASSERT (i_pro != _image_processors.end());
196 if (i_pro == _image_processors.end()) {
197 XCAM_LOG_ERROR ("processor doesn't found from list of image center");
198 return;
199 }
200
201 if (++i_pro != _image_processors.end()) {
202 SmartPtr<ImageProcessor> &next_processor = *i_pro;
203 XCAM_ASSERT (next_processor.ptr());
204 XCamReturn ret = next_processor->push_buffer (buf);
205 if (ret != XCAM_RETURN_NO_ERROR) {
206 XCAM_LOG_ERROR ("processor(%s) failed in push_buffer", next_processor->get_name());
207 }
208 return;
209 }
210
211 //all processor done
212 if (_callback)
213 _callback->process_buffer_done (processor, buf);
214 else
215 ImageProcessCallback::process_buffer_done (processor, buf);
216}
217
218void
219X3aImageProcessCenter::process_buffer_failed (ImageProcessor *processor, SmartPtr<VideoBuffer> &buf)
220{
221 if (_callback)
222 _callback->process_buffer_failed(processor, buf);
223 else
224 ImageProcessCallback::process_buffer_failed (processor, buf);
225}
226
227void
228X3aImageProcessCenter::process_image_result_done (ImageProcessor *processor, SmartPtr<X3aResult> &result)
229{
230 if (_callback)
231 _callback->process_image_result_done(processor, result);
232 else
233 ImageProcessCallback::process_image_result_done (processor, result);
234}
235
236};