QCamera3HWI.h revision 97e8019457b448a6e2141a49a0f471a467b70dc0
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#ifndef __QCAMERA3HARDWAREINTERFACE_H__ 31#define __QCAMERA3HARDWAREINTERFACE_H__ 32 33#include <pthread.h> 34#include <utils/List.h> 35#include <hardware/camera3.h> 36#include <camera/CameraMetadata.h> 37#include "QCamera3HALHeader.h" 38 39extern "C" { 40#include <mm_camera_interface.h> 41#include <mm_jpeg_interface.h> 42} 43 44using namespace android; 45 46namespace qcamera { 47 48#ifndef TRUE 49#define TRUE 1 50#endif 51 52#ifndef FALSE 53#define FALSE 0 54#endif 55 56class QCamera3MetadataChannel; 57class QCamera3HeapMemory; 58 59class QCamera3HardwareInterface { 60public: 61 /* static variable and functions accessed by camera service */ 62 static camera3_device_ops_t mCameraOps; 63 static int initialize(const struct camera3_device *, 64 const camera3_callback_ops_t *callback_ops); 65 static int configure_streams(const struct camera3_device *, 66 camera3_stream_configuration_t *stream_list); 67 static int register_stream_buffers(const struct camera3_device *, 68 const camera3_stream_buffer_set_t *buffer_set); 69 static const camera_metadata_t* construct_default_request_settings( 70 const struct camera3_device *, int type); 71 static int process_capture_request(const struct camera3_device *, 72 camera3_capture_request_t *request); 73 static void get_metadata_vendor_tag_ops(const struct camera3_device *, 74 vendor_tag_query_ops_t* ops); 75 static void dump(const struct camera3_device *, int fd); 76 static int close_camera_device(struct hw_device_t* device); 77public: 78 QCamera3HardwareInterface(int cameraId); 79 virtual ~QCamera3HardwareInterface(); 80 int openCamera(struct hw_device_t **hw_device); 81 int getMetadata(int type); 82 camera_metadata_t* translateCapabilityToMetadata(int type); 83 84 static int getCamInfo(int cameraId, struct camera_info *info); 85 static int initCapabilities(int cameraId); 86 static int initStaticMetadata(int cameraId); 87 static void makeTable(cam_dimension_t* dimTable, uint8_t size, int32_t* sizeTable); 88 static void convertRegions(cam_rect_t rect, int32_t* region, int weight); 89 static void convertLandmarks(cam_face_detection_info_t face, int32_t* landmarks); 90 static int32_t getScalarFormat(int32_t format); 91 92 static void captureResultCb(metadata_buffer_t *metadata, 93 camera3_stream_buffer_t *buffer, uint32_t frame_number, 94 void *userdata); 95 96 void sendCaptureResult(const struct camera3_callback_ops *, 97 const camera3_capture_result_t *result); 98 void notify(const struct camera3_callback_ops *, 99 const camera3_notify_msg_t *msg); 100 101 int initialize(const camera3_callback_ops_t *callback_ops); 102 int configureStreams(camera3_stream_configuration_t *stream_list); 103 int registerStreamBuffers(const camera3_stream_buffer_set_t *buffer_set); 104 int processCaptureRequest(camera3_capture_request_t *request); 105 void getMetadataVendorTagOps(vendor_tag_query_ops_t* ops); 106 void dump(int fd); 107 108 int setFrameParameters(int frame_id, const camera_metadata_t *settings); 109 int translateMetadataToParameters(const camera_metadata_t *settings); 110 camera_metadata_t* translateCbMetadataToResultMetadata(metadata_buffer_t *metadata); 111 int getJpegSettings(const camera_metadata_t *settings); 112 int initParameters(); 113 114 void captureResultCb(metadata_buffer_t *metadata, 115 camera3_stream_buffer_t *buffer, uint32_t frame_number); 116 117 typedef struct { 118 int fwk_name; 119 int hal_name; 120 } QCameraMap; 121 122private: 123 124 int openCamera(); 125 int closeCamera(); 126 int AddSetParmEntryToBatch(parm_buffer_t *p_table, 127 cam_intf_parm_type_t paramType, 128 uint32_t paramLength, 129 void *paramValue); 130 static int lookupHalName(const QCameraMap arr[], 131 int len, int fwk_name); 132 static int lookupFwkName(const QCameraMap arr[], 133 int len, int hal_name); 134 135 int validateCaptureRequest(camera3_capture_request_t *request); 136 137public: 138 139private: 140 camera3_device_t mCameraDevice; 141 uint8_t mCameraId; 142 mm_camera_vtbl_t *mCameraHandle; 143 bool mCameraOpened; 144 camera_metadata_t *mDefaultMetadata[CAMERA3_TEMPLATE_COUNT]; 145 146 const camera3_callback_ops_t *mCallbackOps; 147 148 camera3_stream_t *mInputStream; 149 QCamera3MetadataChannel *mMetadataChannel; 150 151 QCamera3HeapMemory *mParamHeap; 152 parm_buffer_t* mParameters; 153 154 //mutex and conditional variable for request 155 pthread_mutex_t mRequestLock; 156 pthread_cond_t mRequestCond; 157 int mPendingRequest; 158 159 //mutex for serialized access to camera3_device_ops_t functions 160 pthread_mutex_t mMutex; 161 162 //mutex to protect the critial section for processCaptureResult 163 pthread_mutex_t mCaptureResultLock; 164 jpeg_settings_t* mJpegSettings; 165 static const QCameraMap EFFECT_MODES_MAP[]; 166 static const QCameraMap WHITE_BALANCE_MODES_MAP[]; 167 static const QCameraMap SCENE_MODES_MAP[]; 168 static const QCameraMap FOCUS_MODES_MAP[]; 169 static const QCameraMap ANTIBANDING_MODES_MAP[]; 170 static const QCameraMap AUTO_EXPOSURE_MAP[]; 171 static const QCameraMap FLASH_MODES_MAP[]; 172}; 173 174}; // namespace qcamera 175 176#endif /* __QCAMERA2HARDWAREINTERFACE_H__ */ 177