QCamera3Factory.cpp revision d5d5a90863708ac1cdbef25c41853b6f6f05d4e2
1/* Copyright (c) 2012-2013, The Linux Foundataion. All rights reserved. 2* 3* Redistribution and use in source and binary forms, with or without 4* modification, are permitted provided that the following conditions are 5* met: 6* * Redistributions of source code must retain the above copyright 7* notice, this list of conditions and the following disclaimer. 8* * Redistributions in binary form must reproduce the above 9* copyright notice, this list of conditions and the following 10* disclaimer in the documentation and/or other materials provided 11* with the distribution. 12* * Neither the name of The Linux Foundation nor the names of its 13* contributors may be used to endorse or promote products derived 14* from this software without specific prior written permission. 15* 16* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 17* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 19* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 20* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 26* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27* 28*/ 29 30#define LOG_NIDEBUG 0 31#define LOG_TAG "QCamera3Factory" 32 33#include <stdlib.h> 34#include <utils/Log.h> 35#include <utils/Errors.h> 36#include <hardware/camera3.h> 37 38#include "QCamera3Factory.h" 39 40using namespace android; 41 42namespace qcamera { 43 44QCamera3Factory gQCamera3Factory; 45 46/*=========================================================================== 47 * FUNCTION : QCamera3Factory 48 * 49 * DESCRIPTION: default constructor of QCamera3Factory 50 * 51 * PARAMETERS : none 52 * 53 * RETURN : None 54 *==========================================================================*/ 55QCamera3Factory::QCamera3Factory() 56{ 57 mNumOfCameras = get_num_of_cameras(); 58} 59 60/*=========================================================================== 61 * FUNCTION : ~QCamera3Factory 62 * 63 * DESCRIPTION: deconstructor of QCamera2Factory 64 * 65 * PARAMETERS : none 66 * 67 * RETURN : None 68 *==========================================================================*/ 69QCamera3Factory::~QCamera3Factory() 70{ 71} 72 73/*=========================================================================== 74 * FUNCTION : get_number_of_cameras 75 * 76 * DESCRIPTION: static function to query number of cameras detected 77 * 78 * PARAMETERS : none 79 * 80 * RETURN : number of cameras detected 81 *==========================================================================*/ 82int QCamera3Factory::get_number_of_cameras() 83{ 84 return gQCamera3Factory.getNumberOfCameras(); 85} 86 87/*=========================================================================== 88 * FUNCTION : get_camera_info 89 * 90 * DESCRIPTION: static function to query camera information with its ID 91 * 92 * PARAMETERS : 93 * @camera_id : camera ID 94 * @info : ptr to camera info struct 95 * 96 * RETURN : int32_t type of status 97 * NO_ERROR -- success 98 * none-zero failure code 99 *==========================================================================*/ 100int QCamera3Factory::get_camera_info(int camera_id, struct camera_info *info) 101{ 102 return gQCamera3Factory.getCameraInfo(camera_id, info); 103} 104 105/*=========================================================================== 106 * FUNCTION : getNumberOfCameras 107 * 108 * DESCRIPTION: query number of cameras detected 109 * 110 * PARAMETERS : none 111 * 112 * RETURN : number of cameras detected 113 *==========================================================================*/ 114int QCamera3Factory::getNumberOfCameras() 115{ 116 return mNumOfCameras; 117} 118 119/*=========================================================================== 120 * FUNCTION : getCameraInfo 121 * 122 * DESCRIPTION: query camera information with its ID 123 * 124 * PARAMETERS : 125 * @camera_id : camera ID 126 * @info : ptr to camera info struct 127 * 128 * RETURN : int32_t type of status 129 * NO_ERROR -- success 130 * none-zero failure code 131 *==========================================================================*/ 132int QCamera3Factory::getCameraInfo(int camera_id, struct camera_info *info) 133{ 134 int rc; 135 ALOGV("%s: E, camera_id = %d", __func__, camera_id); 136 137 if (!mNumOfCameras || camera_id >= mNumOfCameras || !info) { 138 return INVALID_OPERATION; 139 } 140 141 rc = QCamera3HardwareInterface::getCamInfo(camera_id, info); 142 ALOGV("%s: X", __func__); 143 return rc; 144} 145 146/*=========================================================================== 147 * FUNCTION : cameraDeviceOpen 148 * 149 * DESCRIPTION: open a camera device with its ID 150 * 151 * PARAMETERS : 152 * @camera_id : camera ID 153 * @hw_device : ptr to struct storing camera hardware device info 154 * 155 * RETURN : int32_t type of status 156 * NO_ERROR -- success 157 * none-zero failure code 158 *==========================================================================*/ 159int QCamera3Factory::cameraDeviceOpen(int camera_id, 160 struct hw_device_t **hw_device) 161{ 162 int rc = NO_ERROR; 163 if (camera_id < 0 || camera_id >= mNumOfCameras) 164 return BAD_VALUE; 165 166 QCamera3HardwareInterface *hw = new QCamera3HardwareInterface(camera_id); 167 if (!hw) { 168 ALOGE("Allocation of hardware interface failed"); 169 return NO_MEMORY; 170 } 171 rc = hw->openCamera(hw_device); 172 if (rc != 0) { 173 delete hw; 174 } 175 return rc; 176} 177 178/*=========================================================================== 179 * FUNCTION : camera_device_open 180 * 181 * DESCRIPTION: static function to open a camera device by its ID 182 * 183 * PARAMETERS : 184 * @camera_id : camera ID 185 * @hw_device : ptr to struct storing camera hardware device info 186 * 187 * RETURN : int32_t type of status 188 * NO_ERROR -- success 189 * none-zero failure code 190 *==========================================================================*/ 191int QCamera3Factory::camera_device_open( 192 const struct hw_module_t *module, const char *id, 193 struct hw_device_t **hw_device) 194{ 195 if (module != &HAL_MODULE_INFO_SYM.common) { 196 ALOGE("Invalid module. Trying to open %p, expect %p", 197 module, &HAL_MODULE_INFO_SYM.common); 198 return INVALID_OPERATION; 199 } 200 if (!id) { 201 ALOGE("Invalid camera id"); 202 return BAD_VALUE; 203 } 204 return gQCamera3Factory.cameraDeviceOpen(atoi(id), hw_device); 205} 206 207struct hw_module_methods_t QCamera3Factory::mModuleMethods = { 208 open: QCamera3Factory::camera_device_open, 209}; 210 211}; // namespace qcamera 212 213