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