2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef HW_EMULATOR_CAMERA_EMULATED_CAMERA_FACTORY_H
18 #define HW_EMULATOR_CAMERA_EMULATED_CAMERA_FACTORY_H
20 #include <utils/RefBase.h>
21 #include "EmulatedBaseCamera.h"
22 #include "QemuClient.h"
26 struct EmulatedCameraHotplugThread;
29 * Contains declaration of a class EmulatedCameraFactory that manages cameras
30 * available for the emulation. A global instance of this class is statically
31 * instantiated and initialized when camera emulation HAL is loaded.
34 /* Class EmulatedCameraFactoryManages cameras available for the emulation.
36 * When the global static instance of this class is created on the module load,
37 * it enumerates cameras available for the emulation by connecting to the
38 * emulator's 'camera' service. For every camera found out there it creates an
39 * instance of an appropriate class, and stores it an in array of emulated
40 * cameras. In addition to the cameras reported by the emulator, a fake camera
41 * emulator is always created, so there is always at least one camera that is
44 * Instance of this class is also used as the entry point for the camera HAL API,
46 * - hw_module_methods_t::open entry point
47 * - camera_module_t::get_number_of_cameras entry point
48 * - camera_module_t::get_camera_info entry point
51 class EmulatedCameraFactory {
53 /* Constructs EmulatedCameraFactory instance.
54 * In this constructor the factory will create and initialize a list of
55 * emulated cameras. All errors that occur on this constructor are reported
56 * via mConstructedOK data member of this class.
58 EmulatedCameraFactory();
60 /* Destructs EmulatedCameraFactory instance. */
61 ~EmulatedCameraFactory();
63 /****************************************************************************
64 * Camera HAL API handlers.
65 ***************************************************************************/
68 /* Opens (connects to) a camera device.
69 * This method is called in response to hw_module_methods_t::open callback.
71 int cameraDeviceOpen(int camera_id, hw_device_t** device);
73 /* Gets emulated camera information.
74 * This method is called in response to camera_module_t::get_camera_info callback.
76 int getCameraInfo(int camera_id, struct camera_info *info);
78 /* Sets emulated camera callbacks.
79 * This method is called in response to camera_module_t::set_callbacks callback.
81 int setCallbacks(const camera_module_callbacks_t *callbacks);
83 /* Fill in vendor tags for the module
84 * This method is called in response to camera_module_t::get_vendor_tag_ops callback.
86 void getVendorTagOps(vendor_tag_ops_t* ops);
88 /****************************************************************************
89 * Camera HAL API callbacks.
90 ***************************************************************************/
93 /* camera_module_t::get_number_of_cameras callback entry point. */
94 static int get_number_of_cameras(void);
96 /* camera_module_t::get_camera_info callback entry point. */
97 static int get_camera_info(int camera_id, struct camera_info *info);
99 /* camera_module_t::set_callbacks callback entry point. */
100 static int set_callbacks(const camera_module_callbacks_t *callbacks);
102 /* camera_module_t::get_vendor_tag_ops callback entry point */
103 static void get_vendor_tag_ops(vendor_tag_ops_t* ops);
105 /* camera_module_t::open_legacy callback entry point */
106 static int open_legacy(const struct hw_module_t* module, const char* id,
107 uint32_t halVersion, struct hw_device_t** device);
110 /* hw_module_methods_t::open callback entry point. */
111 static int device_open(const hw_module_t* module,
113 hw_device_t** device);
115 /****************************************************************************
117 ***************************************************************************/
121 /* Gets fake camera orientation. */
122 int getFakeCameraOrientation() {
123 /* TODO: Have a boot property that controls that. */
127 /* Gets qemu camera orientation. */
128 int getQemuCameraOrientation() {
129 /* TODO: Have a boot property that controls that. */
133 /* Gets number of emulated cameras.
135 int getEmulatedCameraNum() const {
136 return mEmulatedCameraNum;
139 /* Checks whether or not the constructor has succeeded.
141 bool isConstructedOK() const {
142 return mConstructedOK;
145 void onStatusChanged(int cameraId, int newStatus);
147 /****************************************************************************
149 ***************************************************************************/
152 /* Populates emulated cameras array with cameras that are available via
153 * 'camera' service in the emulator. For each such camera and instance of
154 * the EmulatedCameraQemud will be created and added to the mEmulatedCameras
157 void createQemuCameras();
159 /* Checks if fake camera emulation is on for the camera facing back. */
160 bool isBackFakeCameraEmulationOn();
162 /* Gets camera device version number to use for back camera emulation */
163 int getBackCameraHalVersion();
165 /* Checks if fake camera emulation is on for the camera facing front. */
166 bool isFrontFakeCameraEmulationOn();
168 /* Gets camera device version number to use for front camera emulation */
169 int getFrontCameraHalVersion();
171 /****************************************************************************
173 ***************************************************************************/
176 /* Connection to the camera service in the emulator. */
177 FactoryQemuClient mQemuClient;
179 /* Array of cameras available for the emulation. */
180 EmulatedBaseCamera** mEmulatedCameras;
182 /* Number of emulated cameras (including the fake ones). */
183 int mEmulatedCameraNum;
185 /* Number of emulated fake cameras. */
188 /* Flags whether or not constructor has succeeded. */
191 /* Camera callbacks (for status changing) */
192 const camera_module_callbacks_t* mCallbacks;
194 /* Hotplug thread (to call onStatusChanged) */
195 sp<EmulatedCameraHotplugThread> mHotplugThread;
198 /* Contains device open entry point, as required by HAL API. */
199 static struct hw_module_methods_t mCameraModuleMethods;
202 }; /* namespace android */
204 /* References the global EmulatedCameraFactory instance. */
205 extern android::EmulatedCameraFactory gEmulatedCameraFactory;
207 #endif /* HW_EMULATOR_CAMERA_EMULATED_CAMERA_FACTORY_H */