blob: 504f84273edb33cc4cc50cca48b02b39e1d9a2e2
1 | /* |
2 | * Copyright (C) 2011 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_CAMERA_FACTORY_H |
18 | #define HW_EMULATOR_CAMERA_EMULATED_CAMERA_FACTORY_H |
19 | |
20 | #include <utils/RefBase.h> |
21 | #include "EmulatedBaseCamera.h" |
22 | #include "QemuClient.h" |
23 | |
24 | #include <hardware/hardware.h> |
25 | #include <hardware/camera_common.h> |
26 | #include <system/camera_vendor_tags.h> |
27 | #include "VendorTags.h" |
28 | namespace android { |
29 | |
30 | #ifndef ARRAY_SIZE |
31 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) |
32 | #endif |
33 | |
34 | struct EmulatedCameraHotplugThread; |
35 | |
36 | |
37 | /* |
38 | * Contains declaration of a class EmulatedCameraFactory that manages cameras |
39 | * available for the emulation. A global instance of this class is statically |
40 | * instantiated and initialized when camera emulation HAL is loaded. |
41 | */ |
42 | |
43 | /* Class EmulatedCameraFactoryManages cameras available for the emulation. |
44 | * |
45 | * When the global static instance of this class is created on the module load, |
46 | * it enumerates cameras available for the emulation by connecting to the |
47 | * emulator's 'camera' service. For every camera found out there it creates an |
48 | * instance of an appropriate class, and stores it an in array of emulated |
49 | * cameras. In addition to the cameras reported by the emulator, a fake camera |
50 | * emulator is always created, so there is always at least one camera that is |
51 | * available. |
52 | * |
53 | * Instance of this class is also used as the entry point for the camera HAL API, |
54 | * including: |
55 | * - hw_module_methods_t::open entry point |
56 | * - camera_module_t::get_number_of_cameras entry point |
57 | * - camera_module_t::get_camera_info entry point |
58 | * |
59 | */ |
60 | |
61 | #ifndef MAX_CAMERA_NUM |
62 | #define MAX_CAMERA_NUM 6 |
63 | #endif |
64 | class EmulatedCameraFactory { |
65 | public: |
66 | /* Constructs EmulatedCameraFactory instance. |
67 | * In this constructor the factory will create and initialize a list of |
68 | * emulated cameras. All errors that occur on this constructor are reported |
69 | * via mConstructedOK data member of this class. |
70 | */ |
71 | EmulatedCameraFactory(); |
72 | |
73 | /* Destructs EmulatedCameraFactory instance. */ |
74 | ~EmulatedCameraFactory(); |
75 | |
76 | /**************************************************************************** |
77 | * Camera HAL API handlers. |
78 | ***************************************************************************/ |
79 | |
80 | public: |
81 | /* Opens (connects to) a camera device. |
82 | * This method is called in response to hw_module_methods_t::open callback. |
83 | */ |
84 | int cameraDeviceOpen(int camera_id, hw_device_t** device); |
85 | |
86 | /* Gets emulated camera information. |
87 | * This method is called in response to camera_module_t::get_camera_info callback. |
88 | */ |
89 | int getCameraInfo(int camera_id, struct camera_info *info); |
90 | |
91 | /* Sets emulated camera callbacks. |
92 | * This method is called in response to camera_module_t::set_callbacks callback. |
93 | */ |
94 | int setCallbacks(const camera_module_callbacks_t *callbacks); |
95 | |
96 | /* Sets emulated camera vendor tag. |
97 | * This method is called in response to camera_module_t::get_vendor_tag_ops callback. |
98 | */ |
99 | void getvendortagops(vendor_tag_ops_t* ops); |
100 | /**************************************************************************** |
101 | * Camera HAL API callbacks. |
102 | ***************************************************************************/ |
103 | |
104 | public: |
105 | /* camera_module_t::get_number_of_cameras callback entry point. */ |
106 | static int get_number_of_cameras(void); |
107 | |
108 | /* camera_module_t::get_camera_info callback entry point. */ |
109 | static int get_camera_info(int camera_id, struct camera_info *info); |
110 | |
111 | /* camera_module_t::set_callbacks callback entry point. */ |
112 | static int set_callbacks(const camera_module_callbacks_t *callbacks); |
113 | /* camera_module_t::get_vendor_tag_ops callback entry point. */ |
114 | static void get_vendor_tag_ops(vendor_tag_ops_t* ops); |
115 | |
116 | private: |
117 | /* hw_module_methods_t::open callback entry point. */ |
118 | static int device_open(const hw_module_t* module, |
119 | const char* name, |
120 | hw_device_t** device); |
121 | |
122 | /**************************************************************************** |
123 | * Public API. |
124 | ***************************************************************************/ |
125 | |
126 | public: |
127 | |
128 | /* Gets fake camera orientation. */ |
129 | int getFakeCameraOrientation() { |
130 | /* TODO: Have a boot property that controls that. */ |
131 | return 90; |
132 | } |
133 | |
134 | /* Gets qemu camera orientation. */ |
135 | int getQemuCameraOrientation() { |
136 | /* TODO: Have a boot property that controls that. */ |
137 | return 270; |
138 | } |
139 | |
140 | /* Gets number of emulated cameras. |
141 | */ |
142 | int getEmulatedCameraNum() const { |
143 | return mEmulatedCameraNum; |
144 | } |
145 | |
146 | /* Checks whether or not the constructor has succeeded. |
147 | */ |
148 | bool isConstructedOK() const { |
149 | return mConstructedOK; |
150 | } |
151 | |
152 | void onStatusChanged(int cameraId, int newStatus); |
153 | |
154 | /**************************************************************************** |
155 | * Private API |
156 | ***************************************************************************/ |
157 | |
158 | private: |
159 | /* Populates emulated cameras array with cameras that are available via |
160 | * 'camera' service in the emulator. For each such camera and instance of |
161 | * the EmulatedCameraQemud will be created and added to the mEmulatedCameras |
162 | * array. |
163 | */ |
164 | void createQemuCameras(); |
165 | |
166 | /* Checks if fake camera emulation is on for the camera facing front. */ |
167 | bool isFakeCameraFacingBack(int cameraId); |
168 | |
169 | /* Gets camera device version number to use for front camera emulation */ |
170 | int getFakeCameraHalVersion(int cameraId); |
171 | |
172 | /**************************************************************************** |
173 | * Data members. |
174 | ***************************************************************************/ |
175 | |
176 | private: |
177 | /* Connection to the camera service in the emulator. */ |
178 | FactoryQemuClient mQemuClient; |
179 | |
180 | /* Array of cameras available for the emulation. */ |
181 | EmulatedBaseCamera* mEmulatedCameras[MAX_CAMERA_NUM]; |
182 | |
183 | /* Number of emulated cameras (including the fake ones). */ |
184 | int mEmulatedCameraNum; |
185 | |
186 | /* Number of emulated fake cameras. */ |
187 | int mFakeCameraNum; |
188 | |
189 | /* Flags whether or not constructor has succeeded. */ |
190 | bool mConstructedOK; |
191 | |
192 | /* Camera callbacks (for status changing) */ |
193 | const camera_module_callbacks_t* mCallbacks; |
194 | |
195 | /* Hotplug thread (to call onStatusChanged) */ |
196 | sp<EmulatedCameraHotplugThread> mHotplugThread; |
197 | |
198 | public: |
199 | /* Contains device open entry point, as required by HAL API. */ |
200 | static struct hw_module_methods_t mCameraModuleMethods; |
201 | }; |
202 | |
203 | }; /* namespace android */ |
204 | |
205 | /* References the global EmulatedCameraFactory instance. */ |
206 | extern android::EmulatedCameraFactory gEmulatedCameraFactory; |
207 | |
208 | #endif /* HW_EMULATOR_CAMERA_EMULATED_CAMERA_FACTORY_H */ |
209 |