summaryrefslogtreecommitdiff
path: root/v3/EmulatedCameraFactory.h (plain)
blob: c844c564c8a2e694bf8c4fe376e8c1f57497db20
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"
28namespace android {
29
30#ifndef ARRAY_SIZE
31#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
32#endif
33
34struct 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
64class EmulatedCameraFactory {
65public:
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
80public:
81 EmulatedBaseCamera* getValidCameraOject(void);
82
83 int getValidCameraOjectId(void);
84 /* Opens (connects to) a camera device.
85 * This method is called in response to hw_module_methods_t::open callback.
86 */
87 int cameraDeviceOpen(int camera_id, hw_device_t** device);
88
89 /* Gets emulated camera information.
90 * This method is called in response to camera_module_t::get_camera_info callback.
91 */
92 int getCameraInfo(int camera_id, struct camera_info *info);
93
94 /* Sets emulated camera callbacks.
95 * This method is called in response to camera_module_t::set_callbacks callback.
96 */
97 int setCallbacks(const camera_module_callbacks_t *callbacks);
98
99 /* Sets emulated camera vendor tag.
100 * This method is called in response to camera_module_t::get_vendor_tag_ops callback.
101 */
102 void getvendortagops(vendor_tag_ops_t* ops);
103 /****************************************************************************
104 * Camera HAL API callbacks.
105 ***************************************************************************/
106
107public:
108 /* camera_module_t::get_number_of_cameras callback entry point. */
109 static int get_number_of_cameras(void);
110
111 /* camera_module_t::get_camera_info callback entry point. */
112 static int get_camera_info(int camera_id, struct camera_info *info);
113
114 /* camera_module_t::set_callbacks callback entry point. */
115 static int set_callbacks(const camera_module_callbacks_t *callbacks);
116 /* camera_module_t::get_vendor_tag_ops callback entry point. */
117 static void get_vendor_tag_ops(vendor_tag_ops_t* ops);
118
119private:
120 /* hw_module_methods_t::open callback entry point. */
121 static int device_open(const hw_module_t* module,
122 const char* name,
123 hw_device_t** device);
124
125 /****************************************************************************
126 * Public API.
127 ***************************************************************************/
128
129public:
130
131 /* Gets fake camera orientation. */
132 int getFakeCameraOrientation() {
133 /* TODO: Have a boot property that controls that. */
134 return 90;
135 }
136
137 /* Gets qemu camera orientation. */
138 int getQemuCameraOrientation() {
139 /* TODO: Have a boot property that controls that. */
140 return 270;
141 }
142
143 /* Gets number of emulated cameras.
144 */
145 int getEmulatedCameraNum() const {
146 return mEmulatedCameraNum;
147 }
148
149 /* Checks whether or not the constructor has succeeded.
150 */
151 bool isConstructedOK() const {
152 return mConstructedOK;
153 }
154
155 void onStatusChanged(int cameraId, int newStatus);
156
157 int getValidCameraId(void);
158
159 /****************************************************************************
160 * Private API
161 ***************************************************************************/
162
163private:
164 /* Populates emulated cameras array with cameras that are available via
165 * 'camera' service in the emulator. For each such camera and instance of
166 * the EmulatedCameraQemud will be created and added to the mEmulatedCameras
167 * array.
168 */
169 void createQemuCameras();
170
171 /* Checks if fake camera emulation is on for the camera facing front. */
172 bool isFakeCameraFacingBack(int cameraId);
173
174 /* Gets camera device version number to use for front camera emulation */
175 int getFakeCameraHalVersion(int cameraId);
176
177 /****************************************************************************
178 * Data members.
179 ***************************************************************************/
180
181private:
182 /* Connection to the camera service in the emulator. */
183 FactoryQemuClient mQemuClient;
184
185 /* Array of cameras available for the emulation. */
186 EmulatedBaseCamera* mEmulatedCameras[MAX_CAMERA_NUM];
187
188 /* Number of emulated cameras (including the fake ones). */
189 int mEmulatedCameraNum;
190
191 /* Number of emulated fake cameras. */
192 int mFakeCameraNum;
193
194 /* Flags whether or not constructor has succeeded. */
195 bool mConstructedOK;
196
197 /* Camera callbacks (for status changing) */
198 const camera_module_callbacks_t* mCallbacks;
199
200 /* Hotplug thread (to call onStatusChanged) */
201 sp<EmulatedCameraHotplugThread> mHotplugThread;
202
203public:
204 /* Contains device open entry point, as required by HAL API. */
205 static struct hw_module_methods_t mCameraModuleMethods;
206};
207
208}; /* namespace android */
209
210/* References the global EmulatedCameraFactory instance. */
211extern android::EmulatedCameraFactory gEmulatedCameraFactory;
212
213#endif /* HW_EMULATOR_CAMERA_EMULATED_CAMERA_FACTORY_H */
214