• Home
  • 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 
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:
getCameraId()60     int getCameraId() const { return mCameraID; }
61 
62     /* Creates connection to the emulated camera device.
63      * This method is called in response to hw_module_methods_t::open callback.
64      * NOTE: When this method is called the object is locked.
65      * Note that failures in this method are reported as negative EXXX statuses.
66      */
67     virtual status_t connectCamera(hw_device_t** device) = 0;
68 
69 
70     /* Plug the connection for the emulated camera. Until it's plugged in
71      * calls to connectCamera should fail with -ENODEV.
72      */
73     virtual status_t plugCamera();
74 
75     /* Unplug the connection from underneath the emulated camera.
76      * This is similar to closing the camera, except that
77      * all function calls into the camera device will return
78      * -EPIPE errors until the camera is reopened.
79      */
80     virtual status_t unplugCamera();
81 
82     virtual camera_device_status_t getHotplugStatus();
83 
84     /* Closes connection to the emulated camera.
85      * This method is called in response to camera_device::close callback.
86      * NOTE: When this method is called the object is locked.
87      * Note that failures in this method are reported as negative EXXX statuses.
88      */
89     virtual status_t closeCamera() = 0;
90 
91     /* Gets camera information.
92      * This method is called in response to camera_module_t::get_camera_info
93      * callback.
94      * NOTE: When this method is called the object is locked.
95      * Note that failures in this method are reported as negative EXXX statuses.
96      */
97     virtual status_t getCameraInfo(struct camera_info* info) = 0;
98 
99     /****************************************************************************
100      * Data members
101      ***************************************************************************/
102 
103   protected:
104     /* Fixed camera information for camera2 devices. Must be valid to access if
105      * mCameraDeviceVersion is >= HARDWARE_DEVICE_API_VERSION(2,0)  */
106     camera_metadata_t *mCameraInfo;
107 
108     /* Zero-based ID assigned to this camera. */
109     int mCameraID;
110 
111   private:
112 
113     /* Version of the camera device HAL implemented by this camera */
114     int mCameraDeviceVersion;
115 };
116 
117 } /* namespace android */
118 
119 #endif /* HW_EMULATOR_CAMERA_EMULATED_BASE_CAMERA_H */
120