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 
23 namespace android {
24 
25 /*
26  * Contains declaration of a class EmulatedBaseCamera that encapsulates
27  * functionality common to all emulated camera device versions ("fake",
28  * "webcam", "video file", etc.).  Instances of this class (for each emulated
29  * camera) are created during the construction of the EmulatedCameraFactory
30  * instance.  This class serves as an entry point for all camera API calls that
31  * are common across all versions of the camera_device_t/camera_module_t
32  * structures.
33  */
34 
35 class EmulatedBaseCamera {
36   public:
37     EmulatedBaseCamera(int cameraId,
38             uint32_t cameraVersion,
39             struct hw_device_t* device,
40             struct hw_module_t* module);
41 
42     virtual ~EmulatedBaseCamera();
43 
44     /****************************************************************************
45      * Public API
46      ***************************************************************************/
47 
48   public:
49     /* Initializes EmulatedCamera instance.
50      * Return:
51      *  NO_ERROR on success, or an appropriate error status on failure.
52      */
53     virtual status_t Initialize() = 0;
54 
55     /****************************************************************************
56      * Camera API implementation
57      ***************************************************************************/
58 
59   public:
60     /* Creates connection to the emulated camera device.
61      * This method is called in response to hw_module_methods_t::open callback.
62      * NOTE: When this method is called the object is locked.
63      * Note that failures in this method are reported as negative EXXX statuses.
64      */
65     virtual status_t connectCamera(hw_device_t** device) = 0;
66 
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     /****************************************************************************
98      * Data members
99      ***************************************************************************/
100 
101   protected:
102     /* Fixed camera information for camera2 devices. Must be valid to access if
103      * mCameraDeviceVersion is >= HARDWARE_DEVICE_API_VERSION(2,0)  */
104     camera_metadata_t *mCameraInfo;
105 
106     /* Zero-based ID assigned to this camera. */
107     int mCameraID;
108 
109   private:
110 
111     /* Version of the camera device HAL implemented by this camera */
112     int mCameraDeviceVersion;
113 };
114 
115 } /* namespace android */
116 
117 #endif /* HW_EMULATOR_CAMERA_EMULATED_BASE_CAMERA_H */
118