1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410
|
/*
* Copyright (C) 2012 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Contains implementation of a class EmulatedCamera that encapsulates
* functionality common to all version 2.0 emulated camera devices. Instances
* of this class (for each emulated camera) are created during the construction
* of the EmulatedCameraFactory instance. This class serves as an entry point
* for all camera API calls that defined by camera2_device_ops_t API.
*/
//#define LOG_NDEBUG 0
#define LOG_TAG "EmulatedCamera2_Camera"
#include <cutils/log.h>
#include "EmulatedCamera2.h"
#include "system/camera_metadata.h"
namespace android {
/* Constructs EmulatedCamera2 instance.
* Param:
* cameraId - Zero based camera identifier, which is an index of the camera
* instance in camera factory's array.
* module - Emulated camera HAL module descriptor.
*/
EmulatedCamera2::EmulatedCamera2(int cameraId,
struct hw_module_t* module):
EmulatedBaseCamera(cameraId,
CAMERA_DEVICE_API_VERSION_2_0,
&common,
module)
{
common.close = EmulatedCamera2::close;
ops = &sDeviceOps;
priv = this;
mNotifyCb = NULL;
mRequestQueueSrc = NULL;
mFrameQueueDst = NULL;
mVendorTagOps.get_camera_vendor_section_name =
EmulatedCamera2::get_camera_vendor_section_name;
mVendorTagOps.get_camera_vendor_tag_name =
EmulatedCamera2::get_camera_vendor_tag_name;
mVendorTagOps.get_camera_vendor_tag_type =
EmulatedCamera2::get_camera_vendor_tag_type;
mVendorTagOps.parent = this;
mStatusPresent = true;
}
/* Destructs EmulatedCamera2 instance. */
EmulatedCamera2::~EmulatedCamera2() {
}
/****************************************************************************
* Abstract API
***************************************************************************/
/****************************************************************************
* Public API
***************************************************************************/
status_t EmulatedCamera2::Initialize() {
return NO_ERROR;
}
/****************************************************************************
* Camera API implementation
***************************************************************************/
status_t EmulatedCamera2::connectCamera(hw_device_t** device) {
*device = &common;
return NO_ERROR;
}
status_t EmulatedCamera2::closeCamera() {
return NO_ERROR;
}
status_t EmulatedCamera2::getCameraInfo(struct camera_info* info) {
return EmulatedBaseCamera::getCameraInfo(info);
}
/****************************************************************************
* Camera Device API implementation.
* These methods are called from the camera API callback routines.
***************************************************************************/
/** Request input queue */
int EmulatedCamera2::requestQueueNotify() {
return INVALID_OPERATION;
}
/** Count of requests in flight */
int EmulatedCamera2::getInProgressCount() {
return INVALID_OPERATION;
}
/** Cancel all captures in flight */
int EmulatedCamera2::flushCapturesInProgress() {
return INVALID_OPERATION;
}
/** Construct a default request for a given use case */
int EmulatedCamera2::constructDefaultRequest(
int request_template,
camera_metadata_t **request) {
return INVALID_OPERATION;
}
/** Output stream creation and management */
int EmulatedCamera2::allocateStream(
uint32_t width,
uint32_t height,
int format,
const camera2_stream_ops_t *stream_ops,
uint32_t *stream_id,
uint32_t *format_actual,
uint32_t *usage,
uint32_t *max_buffers) {
return INVALID_OPERATION;
}
int EmulatedCamera2::registerStreamBuffers(
uint32_t stream_id,
int num_buffers,
buffer_handle_t *buffers) {
return INVALID_OPERATION;
}
int EmulatedCamera2::releaseStream(uint32_t stream_id) {
return INVALID_OPERATION;
}
/** Reprocessing input stream management */
int EmulatedCamera2::allocateReprocessStream(
uint32_t width,
uint32_t height,
uint32_t format,
const camera2_stream_in_ops_t *reprocess_stream_ops,
uint32_t *stream_id,
uint32_t *consumer_usage,
uint32_t *max_buffers) {
return INVALID_OPERATION;
}
int EmulatedCamera2::allocateReprocessStreamFromStream(
uint32_t output_stream_id,
const camera2_stream_in_ops_t *reprocess_stream_ops,
uint32_t *stream_id) {
return INVALID_OPERATION;
}
int EmulatedCamera2::releaseReprocessStream(uint32_t stream_id) {
return INVALID_OPERATION;
}
/** 3A triggering */
int EmulatedCamera2::triggerAction(uint32_t trigger_id,
int ext1, int ext2) {
return INVALID_OPERATION;
}
/** Custom tag query methods */
const char* EmulatedCamera2::getVendorSectionName(uint32_t tag) {
return NULL;
}
const char* EmulatedCamera2::getVendorTagName(uint32_t tag) {
return NULL;
}
int EmulatedCamera2::getVendorTagType(uint32_t tag) {
return -1;
}
/** Debug methods */
int EmulatedCamera2::dump(int fd) {
return INVALID_OPERATION;
}
/****************************************************************************
* Private API.
***************************************************************************/
/****************************************************************************
* Camera API callbacks as defined by camera2_device_ops structure. See
* hardware/libhardware/include/hardware/camera2.h for information on each
* of these callbacks. Implemented in this class, these callbacks simply
* dispatch the call into an instance of EmulatedCamera2 class defined by the
* 'camera_device2' parameter, or set a member value in the same.
***************************************************************************/
EmulatedCamera2* getInstance(const camera2_device_t *d) {
const EmulatedCamera2* cec = static_cast<const EmulatedCamera2*>(d);
return const_cast<EmulatedCamera2*>(cec);
}
int EmulatedCamera2::set_request_queue_src_ops(const camera2_device_t *d,
const camera2_request_queue_src_ops *queue_src_ops) {
EmulatedCamera2* ec = getInstance(d);
ec->mRequestQueueSrc = queue_src_ops;
return NO_ERROR;
}
int EmulatedCamera2::notify_request_queue_not_empty(const camera2_device_t *d) {
EmulatedCamera2* ec = getInstance(d);
return ec->requestQueueNotify();
}
int EmulatedCamera2::set_frame_queue_dst_ops(const camera2_device_t *d,
const camera2_frame_queue_dst_ops *queue_dst_ops) {
EmulatedCamera2* ec = getInstance(d);
ec->mFrameQueueDst = queue_dst_ops;
return NO_ERROR;
}
int EmulatedCamera2::get_in_progress_count(const camera2_device_t *d) {
EmulatedCamera2* ec = getInstance(d);
return ec->getInProgressCount();
}
int EmulatedCamera2::flush_captures_in_progress(const camera2_device_t *d) {
EmulatedCamera2* ec = getInstance(d);
return ec->flushCapturesInProgress();
}
int EmulatedCamera2::construct_default_request(const camera2_device_t *d,
int request_template,
camera_metadata_t **request) {
EmulatedCamera2* ec = getInstance(d);
return ec->constructDefaultRequest(request_template, request);
}
int EmulatedCamera2::allocate_stream(const camera2_device_t *d,
uint32_t width,
uint32_t height,
int format,
const camera2_stream_ops_t *stream_ops,
uint32_t *stream_id,
uint32_t *format_actual,
uint32_t *usage,
uint32_t *max_buffers) {
EmulatedCamera2* ec = getInstance(d);
return ec->allocateStream(width, height, format, stream_ops,
stream_id, format_actual, usage, max_buffers);
}
int EmulatedCamera2::register_stream_buffers(const camera2_device_t *d,
uint32_t stream_id,
int num_buffers,
buffer_handle_t *buffers) {
EmulatedCamera2* ec = getInstance(d);
return ec->registerStreamBuffers(stream_id,
num_buffers,
buffers);
}
int EmulatedCamera2::release_stream(const camera2_device_t *d,
uint32_t stream_id) {
EmulatedCamera2* ec = getInstance(d);
return ec->releaseStream(stream_id);
}
int EmulatedCamera2::allocate_reprocess_stream(const camera2_device_t *d,
uint32_t width,
uint32_t height,
uint32_t format,
const camera2_stream_in_ops_t *reprocess_stream_ops,
uint32_t *stream_id,
uint32_t *consumer_usage,
uint32_t *max_buffers) {
EmulatedCamera2* ec = getInstance(d);
return ec->allocateReprocessStream(width, height, format,
reprocess_stream_ops, stream_id, consumer_usage, max_buffers);
}
int EmulatedCamera2::allocate_reprocess_stream_from_stream(
const camera2_device_t *d,
uint32_t output_stream_id,
const camera2_stream_in_ops_t *reprocess_stream_ops,
uint32_t *stream_id) {
EmulatedCamera2* ec = getInstance(d);
return ec->allocateReprocessStreamFromStream(output_stream_id,
reprocess_stream_ops, stream_id);
}
int EmulatedCamera2::release_reprocess_stream(const camera2_device_t *d,
uint32_t stream_id) {
EmulatedCamera2* ec = getInstance(d);
return ec->releaseReprocessStream(stream_id);
}
int EmulatedCamera2::trigger_action(const camera2_device_t *d,
uint32_t trigger_id,
int ext1,
int ext2) {
EmulatedCamera2* ec = getInstance(d);
return ec->triggerAction(trigger_id, ext1, ext2);
}
int EmulatedCamera2::set_notify_callback(const camera2_device_t *d,
camera2_notify_callback notify_cb, void* user) {
EmulatedCamera2* ec = getInstance(d);
Mutex::Autolock l(ec->mMutex);
ec->mNotifyCb = notify_cb;
ec->mNotifyUserPtr = user;
return NO_ERROR;
}
int EmulatedCamera2::get_metadata_vendor_tag_ops(const camera2_device_t *d,
vendor_tag_query_ops_t **ops) {
EmulatedCamera2* ec = getInstance(d);
*ops = static_cast<vendor_tag_query_ops_t*>(
&ec->mVendorTagOps);
return NO_ERROR;
}
const char* EmulatedCamera2::get_camera_vendor_section_name(
const vendor_tag_query_ops_t *v,
uint32_t tag) {
EmulatedCamera2* ec = static_cast<const TagOps*>(v)->parent;
return ec->getVendorSectionName(tag);
}
const char* EmulatedCamera2::get_camera_vendor_tag_name(
const vendor_tag_query_ops_t *v,
uint32_t tag) {
EmulatedCamera2* ec = static_cast<const TagOps*>(v)->parent;
return ec->getVendorTagName(tag);
}
int EmulatedCamera2::get_camera_vendor_tag_type(
const vendor_tag_query_ops_t *v,
uint32_t tag) {
EmulatedCamera2* ec = static_cast<const TagOps*>(v)->parent;
return ec->getVendorTagType(tag);
}
int EmulatedCamera2::dump(const camera2_device_t *d, int fd) {
EmulatedCamera2* ec = getInstance(d);
return ec->dump(fd);
}
int EmulatedCamera2::close(struct hw_device_t* device) {
EmulatedCamera2* ec =
static_cast<EmulatedCamera2*>(
reinterpret_cast<camera2_device_t*>(device) );
if (ec == NULL) {
ALOGE("%s: Unexpected NULL camera2 device", __FUNCTION__);
return -EINVAL;
}
return ec->closeCamera();
}
void EmulatedCamera2::sendNotification(int32_t msgType,
int32_t ext1, int32_t ext2, int32_t ext3) {
camera2_notify_callback notifyCb;
{
Mutex::Autolock l(mMutex);
notifyCb = mNotifyCb;
}
if (notifyCb != NULL) {
notifyCb(msgType, ext1, ext2, ext3, mNotifyUserPtr);
}
}
camera2_device_ops_t EmulatedCamera2::sDeviceOps = {
EmulatedCamera2::set_request_queue_src_ops,
EmulatedCamera2::notify_request_queue_not_empty,
EmulatedCamera2::set_frame_queue_dst_ops,
EmulatedCamera2::get_in_progress_count,
EmulatedCamera2::flush_captures_in_progress,
EmulatedCamera2::construct_default_request,
EmulatedCamera2::allocate_stream,
EmulatedCamera2::register_stream_buffers,
EmulatedCamera2::release_stream,
EmulatedCamera2::allocate_reprocess_stream,
EmulatedCamera2::allocate_reprocess_stream_from_stream,
EmulatedCamera2::release_reprocess_stream,
EmulatedCamera2::trigger_action,
EmulatedCamera2::set_notify_callback,
EmulatedCamera2::get_metadata_vendor_tag_ops,
EmulatedCamera2::dump
};
}; /* namespace android */
|