summaryrefslogtreecommitdiff
path: root/v3/EmulatedCamera3.cpp (plain)
blob: 30d63648cfe89324f47340c5ac9fe5531fe6dbfc
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
32namespace 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 */
41EmulatedCamera3::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. */
65EmulatedCamera3::~EmulatedCamera3() {
66}
67
68/****************************************************************************
69 * Abstract API
70 ***************************************************************************/
71
72/****************************************************************************
73 * Public API
74 ***************************************************************************/
75
76status_t EmulatedCamera3::Initialize() {
77 ALOGV("%s", __FUNCTION__);
78
79 mStatus = STATUS_CLOSED;
80 return NO_ERROR;
81}
82
83void EmulatedCamera3::setCameraStatus(camera_status_t status)
84{
85 DBG_LOGB("%s : do nothing", __FUNCTION__);
86}
87
88camera_status_t EmulatedCamera3::getCameraStatus()
89{
90 DBG_LOGB("%s : do nothing", __FUNCTION__);
91 return CAMERA_READY_REMOVE;
92}
93
94/****************************************************************************
95 * Camera API implementation
96 ***************************************************************************/
97
98status_t EmulatedCamera3::connectCamera(hw_device_t** device) {
99 ALOGV("%s", __FUNCTION__);
100 if (device == NULL) return BAD_VALUE;
101
102 if (mStatus != STATUS_CLOSED) {
103 ALOGE("%s: Trying to open a camera in state %d!",
104 __FUNCTION__, mStatus);
105 return INVALID_OPERATION;
106 }
107
108 *device = &common;
109 mStatus = STATUS_OPEN;
110 return NO_ERROR;
111}
112
113status_t EmulatedCamera3::closeCamera() {
114 mStatus = STATUS_CLOSED;
115 return NO_ERROR;
116}
117
118status_t EmulatedCamera3::getCameraInfo(struct camera_info* info) {
119 return EmulatedBaseCamera::getCameraInfo(info);
120}
121
122/****************************************************************************
123 * Camera Device API implementation.
124 * These methods are called from the camera API callback routines.
125 ***************************************************************************/
126
127status_t EmulatedCamera3::initializeDevice(
128 const camera3_callback_ops *callbackOps) {
129 if (callbackOps == NULL) {
130 ALOGE("%s: NULL callback ops provided to HAL!",
131 __FUNCTION__);
132 return BAD_VALUE;
133 }
134
135 if (mStatus != STATUS_OPEN) {
136 ALOGE("%s: Trying to initialize a camera in state %d!",
137 __FUNCTION__, mStatus);
138 return INVALID_OPERATION;
139 }
140
141 mCallbackOps = callbackOps;
142 mStatus = STATUS_READY;
143
144 return NO_ERROR;
145}
146
147status_t EmulatedCamera3::configureStreams(
148 camera3_stream_configuration *streamList) {
149 ALOGE("%s: Not implemented", __FUNCTION__);
150 return INVALID_OPERATION;
151}
152
153status_t EmulatedCamera3::registerStreamBuffers(
154 const camera3_stream_buffer_set *bufferSet) {
155 ALOGE("%s: Not implemented", __FUNCTION__);
156 return INVALID_OPERATION;
157}
158
159const camera_metadata_t* EmulatedCamera3::constructDefaultRequestSettings(
160 int type) {
161 ALOGE("%s: Not implemented", __FUNCTION__);
162 return NULL;
163}
164
165status_t EmulatedCamera3::processCaptureRequest(
166 camera3_capture_request *request) {
167 ALOGE("%s: Not implemented", __FUNCTION__);
168 return INVALID_OPERATION;
169}
170
171/** Custom tag query methods */
172
173const char* EmulatedCamera3::getVendorSectionName(uint32_t tag) {
174 ALOGE("%s: Not implemented", __FUNCTION__);
175 return NULL;
176}
177
178const char* EmulatedCamera3::getVendorTagName(uint32_t tag) {
179 ALOGE("%s: Not implemented", __FUNCTION__);
180 return NULL;
181}
182
183int EmulatedCamera3::getVendorTagType(uint32_t tag) {
184 ALOGE("%s: Not implemented", __FUNCTION__);
185 return -1;
186}
187
188/** Debug methods */
189
190void EmulatedCamera3::dump(int fd) {
191 ALOGE("%s: Not implemented", __FUNCTION__);
192 return;
193}
194
195int EmulatedCamera3::flush_all_requests() {
196 ALOGE("%s: Not implemented", __FUNCTION__);
197 return -1;
198}
199
200/****************************************************************************
201 * Protected API. Callbacks to the framework.
202 ***************************************************************************/
203
204void EmulatedCamera3::sendCaptureResult(camera3_capture_result_t *result) {
205 mCallbackOps->process_capture_result(mCallbackOps, result);
206}
207
208void EmulatedCamera3::sendNotify(camera3_notify_msg_t *msg) {
209 mCallbackOps->notify(mCallbackOps, msg);
210}
211
212/****************************************************************************
213 * Private API.
214 ***************************************************************************/
215
216/****************************************************************************
217 * Camera API callbacks as defined by camera3_device_ops structure. See
218 * hardware/libhardware/include/hardware/camera3.h for information on each
219 * of these callbacks. Implemented in this class, these callbacks simply
220 * dispatch the call into an instance of EmulatedCamera3 class defined by the
221 * 'camera_device3' parameter, or set a member value in the same.
222 ***************************************************************************/
223
224EmulatedCamera3* getInstance(const camera3_device_t *d) {
225 const EmulatedCamera3* cec = static_cast<const EmulatedCamera3*>(d);
226 return const_cast<EmulatedCamera3*>(cec);
227}
228
229int EmulatedCamera3::initialize(const struct camera3_device *d,
230 const camera3_callback_ops_t *callback_ops) {
231 EmulatedCamera3* ec = getInstance(d);
232 return ec->initializeDevice(callback_ops);
233}
234
235int EmulatedCamera3::configure_streams(const struct camera3_device *d,
236 camera3_stream_configuration_t *stream_list) {
237 EmulatedCamera3* ec = getInstance(d);
238 return ec->configureStreams(stream_list);
239}
240
241int EmulatedCamera3::register_stream_buffers(
242 const struct camera3_device *d,
243 const camera3_stream_buffer_set_t *buffer_set) {
244 EmulatedCamera3* ec = getInstance(d);
245 return ec->registerStreamBuffers(buffer_set);
246}
247
248int EmulatedCamera3::process_capture_request(
249 const struct camera3_device *d,
250 camera3_capture_request_t *request) {
251 EmulatedCamera3* ec = getInstance(d);
252 return ec->processCaptureRequest(request);
253}
254
255const camera_metadata_t* EmulatedCamera3::construct_default_request_settings(
256 const camera3_device_t *d, int type) {
257 EmulatedCamera3* ec = getInstance(d);
258 return ec->constructDefaultRequestSettings(type);
259}
260
261void EmulatedCamera3::get_metadata_vendor_tag_ops(const camera3_device_t *d,
262 vendor_tag_query_ops_t *ops) {
263 ops->get_camera_vendor_section_name = get_camera_vendor_section_name;
264 ops->get_camera_vendor_tag_name = get_camera_vendor_tag_name;
265 ops->get_camera_vendor_tag_type = get_camera_vendor_tag_type;
266}
267
268const char* EmulatedCamera3::get_camera_vendor_section_name(
269 const vendor_tag_query_ops_t *v,
270 uint32_t tag) {
271 EmulatedCamera3* ec = static_cast<const TagOps*>(v)->parent;
272 return ec->getVendorSectionName(tag);
273}
274
275const char* EmulatedCamera3::get_camera_vendor_tag_name(
276 const vendor_tag_query_ops_t *v,
277 uint32_t tag) {
278 EmulatedCamera3* ec = static_cast<const TagOps*>(v)->parent;
279 return ec->getVendorTagName(tag);
280}
281
282int EmulatedCamera3::get_camera_vendor_tag_type(
283 const vendor_tag_query_ops_t *v,
284 uint32_t tag) {
285 EmulatedCamera3* ec = static_cast<const TagOps*>(v)->parent;
286 return ec->getVendorTagType(tag);
287}
288
289void EmulatedCamera3::dump(const camera3_device_t *d, int fd) {
290 EmulatedCamera3* ec = getInstance(d);
291 ec->dump(fd);
292}
293
294int EmulatedCamera3::flush(const struct camera3_device *d) {
295 EmulatedCamera3* ec = getInstance(d);
296 return ec->flush_all_requests();
297}
298
299int EmulatedCamera3::close(struct hw_device_t* device) {
300 EmulatedCamera3* ec =
301 static_cast<EmulatedCamera3*>(
302 reinterpret_cast<camera3_device_t*>(device) );
303 if (ec == NULL) {
304 ALOGE("%s: Unexpected NULL camera3 device", __FUNCTION__);
305 return BAD_VALUE;
306 }
307 return ec->closeCamera();
308}
309
310camera3_device_ops_t EmulatedCamera3::sDeviceOps = {
311 EmulatedCamera3::initialize,
312 EmulatedCamera3::configure_streams,
313 NULL,//EmulatedCamera3::register_stream_buffers,
314 EmulatedCamera3::construct_default_request_settings,
315 EmulatedCamera3::process_capture_request,
316 EmulatedCamera3::get_metadata_vendor_tag_ops,
317 EmulatedCamera3::dump,
318 EmulatedCamera3::flush,
319};
320
321}; /* namespace android */
322