1 /*
2  * Copyright (C) 2012 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 EmulatedBaseCamera that encapsulates
19  * functionality common to all emulated camera device versions ("fake",
20  * "webcam", "video file", "cam2.0" etc.).  Instances of this class (for each
21  * emulated camera) are created during the construction of the
22  * EmulatedCameraFactory instance.  This class serves as an entry point for all
23  * camera API calls that are common across all versions of the
24  * camera_device_t/camera_module_t structures.
25  */
26 
27 #define LOG_NDEBUG 0
28 #define LOG_TAG "EmulatedCamera_BaseCamera"
29 #include <log/log.h>
30 
31 #include "EmulatedBaseCamera.h"
32 
33 namespace android {
34 
EmulatedBaseCamera(int cameraId,uint32_t cameraVersion,struct hw_device_t * device,struct hw_module_t * module)35 EmulatedBaseCamera::EmulatedBaseCamera(int cameraId, uint32_t cameraVersion,
36                                        struct hw_device_t* device,
37                                        struct hw_module_t* module)
38     : mCameraInfo(NULL),
39       mCameraID(cameraId),
40       mCameraDeviceVersion(cameraVersion) {
41   /*
42    * Initialize camera_device descriptor for this object.
43    */
44 
45   /* Common header */
46   device->tag = HARDWARE_DEVICE_TAG;
47   device->version = cameraVersion;
48   device->module = module;
49   device->close = NULL;  // Must be filled in by child implementation
50 }
51 
~EmulatedBaseCamera()52 EmulatedBaseCamera::~EmulatedBaseCamera() {}
53 
getCameraInfo(struct camera_info * info)54 status_t EmulatedBaseCamera::getCameraInfo(struct camera_info* info) {
55   ALOGV("%s", __FUNCTION__);
56 
57   info->device_version = mCameraDeviceVersion;
58   if (mCameraDeviceVersion >= HARDWARE_DEVICE_API_VERSION(2, 0)) {
59     info->static_camera_characteristics = mCameraInfo;
60   } else {
61     info->static_camera_characteristics = (camera_metadata_t*)0xcafef00d;
62   }
63 
64   return NO_ERROR;
65 }
66 
plugCamera()67 status_t EmulatedBaseCamera::plugCamera() {
68   ALOGE("%s: not supported", __FUNCTION__);
69   return INVALID_OPERATION;
70 }
71 
unplugCamera()72 status_t EmulatedBaseCamera::unplugCamera() {
73   ALOGE("%s: not supported", __FUNCTION__);
74   return INVALID_OPERATION;
75 }
76 
getHotplugStatus()77 camera_device_status_t EmulatedBaseCamera::getHotplugStatus() {
78   return CAMERA_DEVICE_STATUS_PRESENT;
79 }
80 
setTorchMode(bool)81 status_t EmulatedBaseCamera::setTorchMode(bool /* enabled */) {
82   ALOGE("%s: not supported", __FUNCTION__);
83   return INVALID_OPERATION;
84 }
85 
86 } /* namespace android */
87