• 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 #ifndef HW_EMULATOR_CAMERA_EMULATED_BASE_CAMERA_H
18 #define HW_EMULATOR_CAMERA_EMULATED_BASE_CAMERA_H
19 
20 #include <hardware/camera_common.h>
21 #include <utils/Errors.h>
22 #include "CameraConfiguration.h"
23 #include "guest/libs/platform_support/api_level_fixes.h"
24 #if VSOC_PLATFORM_SDK_BEFORE(O_MR1)
25 #include <camera/CameraParameters.h>
26 #else
27 #include <CameraParameters.h>
28 using ::android::hardware::camera::common::V1_0::helper::CameraParameters;
29 #endif
30 
31 namespace android {
32 
33 /*
34  * Contains declaration of a class EmulatedBaseCamera that encapsulates
35  * functionality common to all emulated camera device versions ("fake",
36  * "webcam", "video file", etc.).  Instances of this class (for each emulated
37  * camera) are created during the construction of the EmulatedCameraFactory
38  * instance.  This class serves as an entry point for all camera API calls that
39  * are common across all versions of the camera_device_t/camera_module_t
40  * structures.
41  */
42 
43 class EmulatedBaseCamera {
44  public:
45   EmulatedBaseCamera(int cameraId, uint32_t cameraVersion,
46                      struct hw_device_t* device, struct hw_module_t* module);
47 
48   virtual ~EmulatedBaseCamera();
49 
50   /****************************************************************************
51    * Public API
52    ***************************************************************************/
53 
54  public:
55   /* Initializes EmulatedCamera instance.
56    * Return:
57    *  NO_ERROR on success, or an appropriate error status on failure.
58    */
59   virtual status_t Initialize(const cvd::CameraDefinition& params) = 0;
60 
61   /****************************************************************************
62    * Camera API implementation
63    ***************************************************************************/
64 
65  public:
66   /* Creates connection to the emulated camera device.
67    * This method is called in response to hw_module_methods_t::open callback.
68    * NOTE: When this method is called the object is locked.
69    * Note that failures in this method are reported as negative EXXX statuses.
70    */
71   virtual status_t connectCamera(hw_device_t** device) = 0;
72 
73   /* Plug the connection for the emulated camera. Until it's plugged in
74    * calls to connectCamera should fail with -ENODEV.
75    */
76   virtual status_t plugCamera();
77 
78   /* Unplug the connection from underneath the emulated camera.
79    * This is similar to closing the camera, except that
80    * all function calls into the camera device will return
81    * -EPIPE errors until the camera is reopened.
82    */
83   virtual status_t unplugCamera();
84 
85 #if VSOC_PLATFORM_SDK_AFTER(J_MR2)
86   virtual camera_device_status_t getHotplugStatus();
87 #endif
88 
89   /* Closes connection to the emulated camera.
90    * This method is called in response to camera_device::close callback.
91    * NOTE: When this method is called the object is locked.
92    * Note that failures in this method are reported as negative EXXX statuses.
93    */
94   virtual status_t closeCamera() = 0;
95 
96   /* Gets camera information.
97    * This method is called in response to camera_module_t::get_camera_info
98    * callback.
99    * NOTE: When this method is called the object is locked.
100    * Note that failures in this method are reported as negative EXXX statuses.
101    */
102   virtual status_t getCameraInfo(struct camera_info* info) = 0;
103 
104   /* Gets camera parameters.
105    * This method is called to collect metadata for (currently) taken picture.
106    */
107   virtual const CameraParameters* getCameraParameters() {
108       return NULL;
109   }
110 
111   /* Set torch mode.
112    * This method is called in response to camera_module_t::set_torch_mode
113    * callback.
114    */
115   virtual status_t setTorchMode(bool enabled);
116 
117   /****************************************************************************
118    * Data members
119    ***************************************************************************/
120 
121  protected:
122   /* Fixed camera information for camera2 devices. Must be valid to access if
123    * mCameraDeviceVersion is >= HARDWARE_DEVICE_API_VERSION(2,0)  */
124   camera_metadata_t* mCameraInfo;
125 
126   /* Zero-based ID assigned to this camera. */
127   int mCameraID;
128 
129  private:
130   /* Version of the camera device HAL implemented by this camera */
131   int mCameraDeviceVersion;
132 };
133 
134 } /* namespace android */
135 
136 #endif /* HW_EMULATOR_CAMERA_EMULATED_BASE_CAMERA_H */
137