blob: 0cd6a3ee461848e3b0eff44eecff17bf464a3c12
1 | /* |
2 | * Copyright (C) 2013 The Android Open Source Project |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | */ |
16 | |
17 | /** |
18 | * Contains implementation of a class EmulatedCamera that encapsulates |
19 | * functionality common to all version 3.0 emulated camera devices. Instances |
20 | * of this class (for each emulated camera) are created during the construction |
21 | * of the EmulatedCameraFactory instance. This class serves as an entry point |
22 | * for all camera API calls that defined by camera3_device_ops_t API. |
23 | */ |
24 | |
25 | //#define LOG_NDEBUG 0 |
26 | #define LOG_TAG "EmulatedCamera3_Camera" |
27 | #include <cutils/log.h> |
28 | |
29 | #include "EmulatedCamera3.h" |
30 | #include "system/camera_metadata.h" |
31 | |
32 | namespace android { |
33 | |
34 | /** |
35 | * Constructs EmulatedCamera3 instance. |
36 | * Param: |
37 | * cameraId - Zero based camera identifier, which is an index of the camera |
38 | * instance in camera factory's array. |
39 | * module - Emulated camera HAL module descriptor. |
40 | */ |
41 | EmulatedCamera3::EmulatedCamera3(int cameraId, |
42 | struct hw_module_t* module): |
43 | EmulatedBaseCamera(cameraId, |
44 | CAMERA_DEVICE_API_VERSION_3_2, |
45 | &common, |
46 | module), |
47 | mStatus(STATUS_ERROR), |
48 | mPlugged(false) |
49 | { |
50 | common.close = EmulatedCamera3::close; |
51 | ops = &sDeviceOps; |
52 | |
53 | mCallbackOps = NULL; |
54 | |
55 | mVendorTagOps.get_camera_vendor_section_name = |
56 | EmulatedCamera3::get_camera_vendor_section_name; |
57 | mVendorTagOps.get_camera_vendor_tag_name = |
58 | EmulatedCamera3::get_camera_vendor_tag_name; |
59 | mVendorTagOps.get_camera_vendor_tag_type = |
60 | EmulatedCamera3::get_camera_vendor_tag_type; |
61 | mVendorTagOps.parent = this; |
62 | } |
63 | |
64 | /* Destructs EmulatedCamera3 instance. */ |
65 | EmulatedCamera3::~EmulatedCamera3() { |
66 | } |
67 | |
68 | /**************************************************************************** |
69 | * Abstract API |
70 | ***************************************************************************/ |
71 | |
72 | /**************************************************************************** |
73 | * Public API |
74 | ***************************************************************************/ |
75 | |
76 | status_t EmulatedCamera3::Initialize() { |
77 | ALOGV("%s", __FUNCTION__); |
78 | |
79 | mStatus = STATUS_CLOSED; |
80 | return NO_ERROR; |
81 | } |
82 | |
83 | bool EmulatedCamera3::getCameraStatus() |
84 | { |
85 | DBG_LOGB("%s : do nothing", __FUNCTION__); |
86 | return false; |
87 | } |
88 | |
89 | /**************************************************************************** |
90 | * Camera API implementation |
91 | ***************************************************************************/ |
92 | |
93 | status_t EmulatedCamera3::connectCamera(hw_device_t** device) { |
94 | ALOGV("%s", __FUNCTION__); |
95 | if (device == NULL) return BAD_VALUE; |
96 | |
97 | if (mStatus != STATUS_CLOSED) { |
98 | ALOGE("%s: Trying to open a camera in state %d!", |
99 | __FUNCTION__, mStatus); |
100 | return INVALID_OPERATION; |
101 | } |
102 | |
103 | *device = &common; |
104 | mStatus = STATUS_OPEN; |
105 | return NO_ERROR; |
106 | } |
107 | |
108 | status_t EmulatedCamera3::closeCamera() { |
109 | mStatus = STATUS_CLOSED; |
110 | return NO_ERROR; |
111 | } |
112 | |
113 | status_t EmulatedCamera3::getCameraInfo(struct camera_info* info) { |
114 | return EmulatedBaseCamera::getCameraInfo(info); |
115 | } |
116 | |
117 | /**************************************************************************** |
118 | * Camera Device API implementation. |
119 | * These methods are called from the camera API callback routines. |
120 | ***************************************************************************/ |
121 | |
122 | status_t EmulatedCamera3::initializeDevice( |
123 | const camera3_callback_ops *callbackOps) { |
124 | if (callbackOps == NULL) { |
125 | ALOGE("%s: NULL callback ops provided to HAL!", |
126 | __FUNCTION__); |
127 | return BAD_VALUE; |
128 | } |
129 | |
130 | if (mStatus != STATUS_OPEN) { |
131 | ALOGE("%s: Trying to initialize a camera in state %d!", |
132 | __FUNCTION__, mStatus); |
133 | return INVALID_OPERATION; |
134 | } |
135 | |
136 | mCallbackOps = callbackOps; |
137 | mStatus = STATUS_READY; |
138 | |
139 | return NO_ERROR; |
140 | } |
141 | |
142 | status_t EmulatedCamera3::configureStreams( |
143 | camera3_stream_configuration *streamList) { |
144 | ALOGE("%s: Not implemented", __FUNCTION__); |
145 | return INVALID_OPERATION; |
146 | } |
147 | |
148 | status_t EmulatedCamera3::registerStreamBuffers( |
149 | const camera3_stream_buffer_set *bufferSet) { |
150 | ALOGE("%s: Not implemented", __FUNCTION__); |
151 | return INVALID_OPERATION; |
152 | } |
153 | |
154 | const camera_metadata_t* EmulatedCamera3::constructDefaultRequestSettings( |
155 | int type) { |
156 | ALOGE("%s: Not implemented", __FUNCTION__); |
157 | return NULL; |
158 | } |
159 | |
160 | status_t EmulatedCamera3::processCaptureRequest( |
161 | camera3_capture_request *request) { |
162 | ALOGE("%s: Not implemented", __FUNCTION__); |
163 | return INVALID_OPERATION; |
164 | } |
165 | |
166 | /** Custom tag query methods */ |
167 | |
168 | const char* EmulatedCamera3::getVendorSectionName(uint32_t tag) { |
169 | ALOGE("%s: Not implemented", __FUNCTION__); |
170 | return NULL; |
171 | } |
172 | |
173 | const char* EmulatedCamera3::getVendorTagName(uint32_t tag) { |
174 | ALOGE("%s: Not implemented", __FUNCTION__); |
175 | return NULL; |
176 | } |
177 | |
178 | int EmulatedCamera3::getVendorTagType(uint32_t tag) { |
179 | ALOGE("%s: Not implemented", __FUNCTION__); |
180 | return -1; |
181 | } |
182 | |
183 | /** Debug methods */ |
184 | |
185 | void EmulatedCamera3::dump(int fd) { |
186 | ALOGE("%s: Not implemented", __FUNCTION__); |
187 | return; |
188 | } |
189 | |
190 | int EmulatedCamera3::flush_all_requests() { |
191 | ALOGE("%s: Not implemented", __FUNCTION__); |
192 | return -1; |
193 | } |
194 | |
195 | /**************************************************************************** |
196 | * Protected API. Callbacks to the framework. |
197 | ***************************************************************************/ |
198 | |
199 | void EmulatedCamera3::sendCaptureResult(camera3_capture_result_t *result) { |
200 | mCallbackOps->process_capture_result(mCallbackOps, result); |
201 | } |
202 | |
203 | void EmulatedCamera3::sendNotify(camera3_notify_msg_t *msg) { |
204 | mCallbackOps->notify(mCallbackOps, msg); |
205 | } |
206 | |
207 | /**************************************************************************** |
208 | * Private API. |
209 | ***************************************************************************/ |
210 | |
211 | /**************************************************************************** |
212 | * Camera API callbacks as defined by camera3_device_ops structure. See |
213 | * hardware/libhardware/include/hardware/camera3.h for information on each |
214 | * of these callbacks. Implemented in this class, these callbacks simply |
215 | * dispatch the call into an instance of EmulatedCamera3 class defined by the |
216 | * 'camera_device3' parameter, or set a member value in the same. |
217 | ***************************************************************************/ |
218 | |
219 | EmulatedCamera3* getInstance(const camera3_device_t *d) { |
220 | const EmulatedCamera3* cec = static_cast<const EmulatedCamera3*>(d); |
221 | return const_cast<EmulatedCamera3*>(cec); |
222 | } |
223 | |
224 | int EmulatedCamera3::initialize(const struct camera3_device *d, |
225 | const camera3_callback_ops_t *callback_ops) { |
226 | EmulatedCamera3* ec = getInstance(d); |
227 | return ec->initializeDevice(callback_ops); |
228 | } |
229 | |
230 | int EmulatedCamera3::configure_streams(const struct camera3_device *d, |
231 | camera3_stream_configuration_t *stream_list) { |
232 | EmulatedCamera3* ec = getInstance(d); |
233 | return ec->configureStreams(stream_list); |
234 | } |
235 | |
236 | int EmulatedCamera3::register_stream_buffers( |
237 | const struct camera3_device *d, |
238 | const camera3_stream_buffer_set_t *buffer_set) { |
239 | EmulatedCamera3* ec = getInstance(d); |
240 | return ec->registerStreamBuffers(buffer_set); |
241 | } |
242 | |
243 | int EmulatedCamera3::process_capture_request( |
244 | const struct camera3_device *d, |
245 | camera3_capture_request_t *request) { |
246 | EmulatedCamera3* ec = getInstance(d); |
247 | return ec->processCaptureRequest(request); |
248 | } |
249 | |
250 | const camera_metadata_t* EmulatedCamera3::construct_default_request_settings( |
251 | const camera3_device_t *d, int type) { |
252 | EmulatedCamera3* ec = getInstance(d); |
253 | return ec->constructDefaultRequestSettings(type); |
254 | } |
255 | |
256 | void EmulatedCamera3::get_metadata_vendor_tag_ops(const camera3_device_t *d, |
257 | vendor_tag_query_ops_t *ops) { |
258 | ops->get_camera_vendor_section_name = get_camera_vendor_section_name; |
259 | ops->get_camera_vendor_tag_name = get_camera_vendor_tag_name; |
260 | ops->get_camera_vendor_tag_type = get_camera_vendor_tag_type; |
261 | } |
262 | |
263 | const char* EmulatedCamera3::get_camera_vendor_section_name( |
264 | const vendor_tag_query_ops_t *v, |
265 | uint32_t tag) { |
266 | EmulatedCamera3* ec = static_cast<const TagOps*>(v)->parent; |
267 | return ec->getVendorSectionName(tag); |
268 | } |
269 | |
270 | const char* EmulatedCamera3::get_camera_vendor_tag_name( |
271 | const vendor_tag_query_ops_t *v, |
272 | uint32_t tag) { |
273 | EmulatedCamera3* ec = static_cast<const TagOps*>(v)->parent; |
274 | return ec->getVendorTagName(tag); |
275 | } |
276 | |
277 | int EmulatedCamera3::get_camera_vendor_tag_type( |
278 | const vendor_tag_query_ops_t *v, |
279 | uint32_t tag) { |
280 | EmulatedCamera3* ec = static_cast<const TagOps*>(v)->parent; |
281 | return ec->getVendorTagType(tag); |
282 | } |
283 | |
284 | void EmulatedCamera3::dump(const camera3_device_t *d, int fd) { |
285 | EmulatedCamera3* ec = getInstance(d); |
286 | ec->dump(fd); |
287 | } |
288 | |
289 | int EmulatedCamera3::flush(const struct camera3_device *d) { |
290 | EmulatedCamera3* ec = getInstance(d); |
291 | return ec->flush_all_requests(); |
292 | } |
293 | |
294 | int EmulatedCamera3::close(struct hw_device_t* device) { |
295 | EmulatedCamera3* ec = |
296 | static_cast<EmulatedCamera3*>( |
297 | reinterpret_cast<camera3_device_t*>(device) ); |
298 | if (ec == NULL) { |
299 | ALOGE("%s: Unexpected NULL camera3 device", __FUNCTION__); |
300 | return BAD_VALUE; |
301 | } |
302 | return ec->closeCamera(); |
303 | } |
304 | |
305 | camera3_device_ops_t EmulatedCamera3::sDeviceOps = { |
306 | EmulatedCamera3::initialize, |
307 | EmulatedCamera3::configure_streams, |
308 | NULL,//EmulatedCamera3::register_stream_buffers, |
309 | EmulatedCamera3::construct_default_request_settings, |
310 | EmulatedCamera3::process_capture_request, |
311 | EmulatedCamera3::get_metadata_vendor_tag_ops, |
312 | EmulatedCamera3::dump, |
313 | EmulatedCamera3::flush, |
314 | }; |
315 | |
316 | }; /* namespace android */ |
317 |