• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <cutils/log.h>
30 
31 #include "EmulatedBaseCamera.h"
32 
33 namespace android {
34 
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 
52 EmulatedBaseCamera::~EmulatedBaseCamera() {}
53 
54 status_t EmulatedBaseCamera::getCameraInfo(struct camera_info* info) {
55   ALOGV("%s", __FUNCTION__);
56 
57   info->device_version = mCameraDeviceVersion;
58 #if VSOC_PLATFORM_SDK_BEFORE(O)
59   // static_camera_characteristics should be initialized if and only if two
60   // conditions hold:
61   //    CAMERA_MODULE_API_VERSION_2_0 or higher
62   //    CAMERA_DEVICE_API_VERSION_2_0 or higher
63   // See android/hardware/libhardware/include/hardware/camera_common.h
64   //
65   // The CAMERA_MODULE_API_VERSION is above 2 on all of the supported
66   // branches.
67   //
68   // The CVD supports both CAMERA_DEVICE_API_VERSION_1_0 and
69   // CAMERA_DEVICE_API_VERSION_3_0.
70   //
71   // By the spec, the framework should not look at this field on
72   // CAMERA_DEVICE_API_VERSION_1_0. However, the framework
73   // referenced them unconditionally in the M, N, and N-MR1 branches.
74   // See b/67841929 for evidence.
75   //
76   // We have to support those branches, so make initialization uconditional.
77   // However, keep the 0xcafef00d fake initiziation on O and later to ensure
78   // that we'll catch future framework changes that violate the spec.
79   info->static_camera_characteristics = mCameraInfo;
80 #else
81   if (mCameraDeviceVersion >= HARDWARE_DEVICE_API_VERSION(2, 0)) {
82     info->static_camera_characteristics = mCameraInfo;
83   } else {
84     info->static_camera_characteristics = (camera_metadata_t*)0xcafef00d;
85   }
86 #endif
87 
88   return NO_ERROR;
89 }
90 
91 status_t EmulatedBaseCamera::plugCamera() {
92   ALOGE("%s: not supported", __FUNCTION__);
93   return INVALID_OPERATION;
94 }
95 
96 status_t EmulatedBaseCamera::unplugCamera() {
97   ALOGE("%s: not supported", __FUNCTION__);
98   return INVALID_OPERATION;
99 }
100 
101 #if VSOC_PLATFORM_SDK_AFTER(J_MR2)
102 camera_device_status_t EmulatedBaseCamera::getHotplugStatus() {
103   return CAMERA_DEVICE_STATUS_PRESENT;
104 }
105 #endif
106 
107 status_t EmulatedBaseCamera::setTorchMode(bool /* enabled */) {
108   ALOGE("%s: not supported", __FUNCTION__);
109   return INVALID_OPERATION;
110 }
111 
112 } /* namespace android */
113