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