2 * Copyright (C) 2013 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
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.
25 //#define LOG_NDEBUG 0
26 #define LOG_TAG "EmulatedCamera3_Camera"
27 #include <cutils/log.h>
29 #include "EmulatedCamera3.h"
30 #include "system/camera_metadata.h"
35 * Constructs EmulatedCamera3 instance.
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.
41 EmulatedCamera3::EmulatedCamera3(int cameraId,
42 struct hw_module_t* module):
43 EmulatedBaseCamera(cameraId,
44 CAMERA_DEVICE_API_VERSION_3_3,
49 common.close = EmulatedCamera3::close;
56 /* Destructs EmulatedCamera3 instance. */
57 EmulatedCamera3::~EmulatedCamera3() {
60 /****************************************************************************
62 ***************************************************************************/
64 /****************************************************************************
66 ***************************************************************************/
68 status_t EmulatedCamera3::Initialize() {
69 ALOGV("%s", __FUNCTION__);
71 mStatus = STATUS_CLOSED;
75 /****************************************************************************
76 * Camera API implementation
77 ***************************************************************************/
79 status_t EmulatedCamera3::connectCamera(hw_device_t** device) {
80 ALOGV("%s", __FUNCTION__);
81 if (device == NULL) return BAD_VALUE;
83 if (mStatus != STATUS_CLOSED) {
84 ALOGE("%s: Trying to open a camera in state %d!",
85 __FUNCTION__, mStatus);
86 return INVALID_OPERATION;
90 mStatus = STATUS_OPEN;
94 status_t EmulatedCamera3::closeCamera() {
95 mStatus = STATUS_CLOSED;
99 status_t EmulatedCamera3::getCameraInfo(struct camera_info* info) {
100 return EmulatedBaseCamera::getCameraInfo(info);
103 /****************************************************************************
104 * Camera Device API implementation.
105 * These methods are called from the camera API callback routines.
106 ***************************************************************************/
108 status_t EmulatedCamera3::initializeDevice(
109 const camera3_callback_ops *callbackOps) {
110 if (callbackOps == NULL) {
111 ALOGE("%s: NULL callback ops provided to HAL!",
116 if (mStatus != STATUS_OPEN) {
117 ALOGE("%s: Trying to initialize a camera in state %d!",
118 __FUNCTION__, mStatus);
119 return INVALID_OPERATION;
122 mCallbackOps = callbackOps;
123 mStatus = STATUS_READY;
128 status_t EmulatedCamera3::configureStreams(
129 camera3_stream_configuration *streamList) {
130 ALOGE("%s: Not implemented", __FUNCTION__);
131 return INVALID_OPERATION;
134 status_t EmulatedCamera3::registerStreamBuffers(
135 const camera3_stream_buffer_set *bufferSet) {
136 ALOGE("%s: Not implemented", __FUNCTION__);
137 return INVALID_OPERATION;
140 const camera_metadata_t* EmulatedCamera3::constructDefaultRequestSettings(
142 ALOGE("%s: Not implemented", __FUNCTION__);
146 status_t EmulatedCamera3::processCaptureRequest(
147 camera3_capture_request *request) {
148 ALOGE("%s: Not implemented", __FUNCTION__);
149 return INVALID_OPERATION;
152 status_t EmulatedCamera3::flush() {
153 ALOGE("%s: Not implemented", __FUNCTION__);
154 return INVALID_OPERATION;
159 void EmulatedCamera3::dump(int fd) {
160 ALOGE("%s: Not implemented", __FUNCTION__);
164 /****************************************************************************
165 * Protected API. Callbacks to the framework.
166 ***************************************************************************/
168 void EmulatedCamera3::sendCaptureResult(camera3_capture_result_t *result) {
169 mCallbackOps->process_capture_result(mCallbackOps, result);
172 void EmulatedCamera3::sendNotify(camera3_notify_msg_t *msg) {
173 mCallbackOps->notify(mCallbackOps, msg);
176 /****************************************************************************
178 ***************************************************************************/
180 /****************************************************************************
181 * Camera API callbacks as defined by camera3_device_ops structure. See
182 * hardware/libhardware/include/hardware/camera3.h for information on each
183 * of these callbacks. Implemented in this class, these callbacks simply
184 * dispatch the call into an instance of EmulatedCamera3 class defined by the
185 * 'camera_device3' parameter, or set a member value in the same.
186 ***************************************************************************/
188 EmulatedCamera3* getInstance(const camera3_device_t *d) {
189 const EmulatedCamera3* cec = static_cast<const EmulatedCamera3*>(d);
190 return const_cast<EmulatedCamera3*>(cec);
193 int EmulatedCamera3::initialize(const struct camera3_device *d,
194 const camera3_callback_ops_t *callback_ops) {
195 EmulatedCamera3* ec = getInstance(d);
196 return ec->initializeDevice(callback_ops);
199 int EmulatedCamera3::configure_streams(const struct camera3_device *d,
200 camera3_stream_configuration_t *stream_list) {
201 EmulatedCamera3* ec = getInstance(d);
202 return ec->configureStreams(stream_list);
205 int EmulatedCamera3::register_stream_buffers(
206 const struct camera3_device *d,
207 const camera3_stream_buffer_set_t *buffer_set) {
208 EmulatedCamera3* ec = getInstance(d);
209 return ec->registerStreamBuffers(buffer_set);
212 int EmulatedCamera3::process_capture_request(
213 const struct camera3_device *d,
214 camera3_capture_request_t *request) {
215 EmulatedCamera3* ec = getInstance(d);
216 return ec->processCaptureRequest(request);
219 const camera_metadata_t* EmulatedCamera3::construct_default_request_settings(
220 const camera3_device_t *d, int type) {
221 EmulatedCamera3* ec = getInstance(d);
222 return ec->constructDefaultRequestSettings(type);
225 void EmulatedCamera3::dump(const camera3_device_t *d, int fd) {
226 EmulatedCamera3* ec = getInstance(d);
230 int EmulatedCamera3::flush(const camera3_device_t *d) {
231 EmulatedCamera3* ec = getInstance(d);
235 int EmulatedCamera3::close(struct hw_device_t* device) {
236 EmulatedCamera3* ec =
237 static_cast<EmulatedCamera3*>(
238 reinterpret_cast<camera3_device_t*>(device) );
240 ALOGE("%s: Unexpected NULL camera3 device", __FUNCTION__);
243 return ec->closeCamera();
246 camera3_device_ops_t EmulatedCamera3::sDeviceOps = {
247 EmulatedCamera3::initialize,
248 EmulatedCamera3::configure_streams,
249 /* DEPRECATED: register_stream_buffers */ nullptr,
250 EmulatedCamera3::construct_default_request_settings,
251 EmulatedCamera3::process_capture_request,
252 /* DEPRECATED: get_metadata_vendor_tag_ops */ nullptr,
253 EmulatedCamera3::dump,
254 EmulatedCamera3::flush
257 const char* EmulatedCamera3::sAvailableCapabilitiesStrings[NUM_CAPABILITIES] = {
258 "BACKWARD_COMPATIBLE",
260 "MANUAL_POST_PROCESSING",
262 "PRIVATE_REPROCESSING",
263 "READ_SENSOR_SETTINGS",
267 "CONSTRAINED_HIGH_SPEED_VIDEO",
271 }; /* namespace android */