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