Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2012-2016, The Linux Foundation. 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 | // System dependencies |
Jiyong Park | d4caeb7 | 2017-06-12 17:16:36 +0900 | [diff] [blame] | 34 | #include <CameraMetadata.h> |
Chien-Yu Chen | d77a546 | 2017-06-02 18:00:38 -0700 | [diff] [blame] | 35 | #include <map> |
| 36 | #include <mutex> |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 37 | #include <pthread.h> |
| 38 | #include <utils/KeyedVector.h> |
| 39 | #include <utils/List.h> |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 40 | // Camera dependencies |
| 41 | #include "hardware/camera3.h" |
| 42 | #include "QCamera3Channel.h" |
| 43 | #include "QCamera3CropRegionMapper.h" |
| 44 | #include "QCamera3HALHeader.h" |
| 45 | #include "QCamera3Mem.h" |
| 46 | #include "QCameraPerf.h" |
| 47 | #include "QCameraCommon.h" |
Thierry Strudel | 04e026f | 2016-10-10 11:27:36 -0700 | [diff] [blame] | 48 | #include "QCamera3VendorTags.h" |
Thierry Strudel | 2896d12 | 2017-02-23 19:18:03 -0800 | [diff] [blame] | 49 | #include "QCameraDualCamSettings.h" |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 50 | |
Chien-Yu Chen | 90f1fc1 | 2017-07-14 14:31:53 -0700 | [diff] [blame] | 51 | #include "EaselManagerClient.h" |
Chien-Yu Chen | 8e59949 | 2016-11-01 13:37:46 -0700 | [diff] [blame] | 52 | #include "HdrPlusClient.h" |
| 53 | |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 54 | extern "C" { |
| 55 | #include "mm_camera_interface.h" |
| 56 | #include "mm_jpeg_interface.h" |
| 57 | } |
| 58 | |
Jiyong Park | d4caeb7 | 2017-06-12 17:16:36 +0900 | [diff] [blame] | 59 | using ::android::hardware::camera::common::V1_0::helper::CameraMetadata; |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 60 | using namespace android; |
| 61 | |
| 62 | namespace qcamera { |
| 63 | |
| 64 | #ifndef TRUE |
| 65 | #define TRUE 1 |
| 66 | #endif |
| 67 | |
| 68 | #ifndef FALSE |
| 69 | #define FALSE 0 |
| 70 | #endif |
| 71 | |
| 72 | /* Time related macros */ |
| 73 | typedef int64_t nsecs_t; |
| 74 | #define NSEC_PER_SEC 1000000000LLU |
| 75 | #define NSEC_PER_USEC 1000LLU |
| 76 | #define NSEC_PER_33MSEC 33000000LLU |
| 77 | |
Thierry Strudel | e80ad7c | 2016-12-06 10:16:27 -0800 | [diff] [blame] | 78 | /*Orchestrate Macros */ |
| 79 | #define EV_COMP_SETTLE_DELAY 2 |
| 80 | #define GB_HDR_HALF_STEP_EV -6 |
| 81 | #define GB_HDR_2X_STEP_EV 6 |
| 82 | |
| 83 | #define FRAME_REGISTER_LRU_SIZE 256 |
| 84 | #define INTERNAL_FRAME_STARTING_NUMBER 800 |
| 85 | #define EMPTY_FRAMEWORK_FRAME_NUMBER 0xFFFFFFFF |
| 86 | |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 87 | typedef enum { |
| 88 | SET_ENABLE, |
| 89 | SET_CONTROLENABLE, |
| 90 | SET_RELOAD_CHROMATIX, |
| 91 | SET_STATUS, |
| 92 | } optype_t; |
| 93 | |
| 94 | #define MODULE_ALL 0 |
| 95 | |
| 96 | extern volatile uint32_t gCamHal3LogLevel; |
| 97 | |
| 98 | class QCamera3MetadataChannel; |
| 99 | class QCamera3PicChannel; |
| 100 | class QCamera3HeapMemory; |
| 101 | class QCamera3Exif; |
Chien-Yu Chen | 3f30352 | 2017-05-19 15:21:45 -0700 | [diff] [blame] | 102 | class ShutterDispatcher; |
| 103 | class BufferDispatcher; |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 104 | |
| 105 | typedef struct { |
| 106 | camera3_stream_t *stream; |
| 107 | camera3_stream_buffer_set_t buffer_set; |
| 108 | stream_status_t status; |
| 109 | int registered; |
| 110 | QCamera3ProcessingChannel *channel; |
| 111 | } stream_info_t; |
| 112 | |
| 113 | typedef struct { |
| 114 | // Stream handle |
| 115 | camera3_stream_t *stream; |
| 116 | // Buffer handle |
| 117 | buffer_handle_t *buffer; |
Thierry Strudel | c2ee330 | 2016-11-17 12:33:12 -0800 | [diff] [blame] | 118 | // Buffer status |
| 119 | camera3_buffer_status_t bufStatus = CAMERA3_BUFFER_STATUS_OK; |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 120 | } PendingBufferInfo; |
| 121 | |
| 122 | typedef struct { |
| 123 | // Frame number corresponding to request |
| 124 | uint32_t frame_number; |
| 125 | // Time when request queued into system |
| 126 | nsecs_t timestamp; |
| 127 | List<PendingBufferInfo> mPendingBufferList; |
Chien-Yu Chen | e687bd0 | 2016-12-07 18:30:26 -0800 | [diff] [blame] | 128 | bool hdrplus; |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 129 | } PendingBuffersInRequest; |
| 130 | |
| 131 | class PendingBuffersMap { |
| 132 | public: |
| 133 | // Number of outstanding buffers at flush |
| 134 | uint32_t numPendingBufsAtFlush; |
| 135 | // List of pending buffers per request |
| 136 | List<PendingBuffersInRequest> mPendingBuffersInRequest; |
| 137 | uint32_t get_num_overall_buffers(); |
| 138 | void removeBuf(buffer_handle_t *buffer); |
Thierry Strudel | c2ee330 | 2016-11-17 12:33:12 -0800 | [diff] [blame] | 139 | int32_t getBufErrStatus(buffer_handle_t *buffer); |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 140 | }; |
| 141 | |
Thierry Strudel | e80ad7c | 2016-12-06 10:16:27 -0800 | [diff] [blame] | 142 | class FrameNumberRegistry { |
| 143 | public: |
| 144 | |
| 145 | FrameNumberRegistry(); |
| 146 | ~FrameNumberRegistry(); |
| 147 | int32_t allocStoreInternalFrameNumber(uint32_t frameworkFrameNumber, |
| 148 | uint32_t &internalFrameNumber); |
| 149 | int32_t generateStoreInternalFrameNumber(uint32_t &internalFrameNumber); |
| 150 | int32_t freeInternalFrameNumber(uint32_t internalFrameNumber); |
| 151 | int32_t getFrameworkFrameNumber(uint32_t internalFrameNumber, uint32_t &frameworkFrameNumber); |
| 152 | void purgeOldEntriesLocked(); |
| 153 | |
| 154 | private: |
| 155 | std::map<uint32_t, uint32_t> _register; |
| 156 | uint32_t _nextFreeInternalNumber; |
| 157 | Mutex mRegistryLock; |
| 158 | }; |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 159 | |
Chien-Yu Chen | 3f30352 | 2017-05-19 15:21:45 -0700 | [diff] [blame] | 160 | class QCamera3HardwareInterface; |
| 161 | |
| 162 | /* |
| 163 | * ShutterDispatcher class dispatches shutter callbacks in order of the frame |
| 164 | * number. It will dispatch a shutter callback only after all shutter callbacks |
| 165 | * of previous frames were dispatched. |
| 166 | */ |
| 167 | class ShutterDispatcher { |
| 168 | public: |
| 169 | ShutterDispatcher(QCamera3HardwareInterface *parent); |
| 170 | virtual ~ShutterDispatcher() = default; |
| 171 | |
| 172 | // Tell dispatch to expect a shutter for a frame number. |
Chien-Yu Chen | a7f9861 | 2017-06-20 16:54:10 -0700 | [diff] [blame] | 173 | void expectShutter(uint32_t frameNumber, bool isReprocess); |
Chien-Yu Chen | 3f30352 | 2017-05-19 15:21:45 -0700 | [diff] [blame] | 174 | // Mark a shutter callback for a frame ready. |
| 175 | void markShutterReady(uint32_t frameNumber, uint64_t timestamp); |
| 176 | // Discard a pending shutter for frame number. |
| 177 | void clear(uint32_t frameNumber); |
| 178 | // Discard all pending shutters. |
| 179 | void clear(); |
| 180 | |
| 181 | private: |
| 182 | struct Shutter { |
| 183 | bool ready; // If the shutter is ready. |
| 184 | uint64_t timestamp; // Timestamp of the shutter. |
| 185 | Shutter() : ready(false), timestamp(0) {}; |
| 186 | }; |
| 187 | |
| 188 | std::mutex mLock; |
| 189 | |
| 190 | // frame number -> shutter map. Protected by mLock. |
| 191 | std::map<uint32_t, Shutter> mShutters; |
Chien-Yu Chen | a7f9861 | 2017-06-20 16:54:10 -0700 | [diff] [blame] | 192 | std::map<uint32_t, Shutter> mReprocessShutters; |
Chien-Yu Chen | 3f30352 | 2017-05-19 15:21:45 -0700 | [diff] [blame] | 193 | |
| 194 | QCamera3HardwareInterface *mParent; |
| 195 | }; |
| 196 | |
| 197 | /* |
| 198 | * BufferDispatcher class dispatches output buffers in a stream in order of the |
| 199 | * frame number. It will dispatch an output buffer in a stream only after all |
| 200 | * previous output buffers in the same stream were dispatched. |
| 201 | */ |
| 202 | class OutputBufferDispatcher { |
| 203 | public: |
| 204 | OutputBufferDispatcher(QCamera3HardwareInterface *parent); |
| 205 | virtual ~OutputBufferDispatcher() = default; |
| 206 | |
| 207 | // Configure streams. |
| 208 | status_t configureStreams(camera3_stream_configuration_t *streamList); |
| 209 | // Tell dispatcher to expect a buffer for a stream for a frame number. |
| 210 | status_t expectBuffer(uint32_t frameNumber, camera3_stream_t *stream); |
| 211 | // Mark a buffer ready for a stream for a frame number. |
| 212 | void markBufferReady(uint32_t frameNumber, const camera3_stream_buffer_t &buffer); |
| 213 | // Discard all pending buffers. If clearConfiguredStreams is true, discard configured streams |
| 214 | // as well. |
| 215 | void clear(bool clearConfiguredStreams = true); |
| 216 | |
| 217 | private: |
| 218 | struct Buffer { |
| 219 | bool ready; // If the buffer is ready. |
| 220 | camera3_stream_buffer_t buffer; |
| 221 | Buffer() : ready(false), buffer({}) {}; |
| 222 | }; |
| 223 | |
| 224 | std::mutex mLock; |
| 225 | |
| 226 | // A two-level map: stream -> (frame number -> buffer). Protected by mLock. |
| 227 | std::map<camera3_stream_t*, std::map<uint32_t, Buffer>> mStreamBuffers; |
| 228 | |
| 229 | QCamera3HardwareInterface *mParent; |
| 230 | }; |
| 231 | |
Chien-Yu Chen | 90f1fc1 | 2017-07-14 14:31:53 -0700 | [diff] [blame] | 232 | class QCamera3HardwareInterface : public HdrPlusClientListener, |
| 233 | public EaselManagerClientListener { |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 234 | public: |
| 235 | /* static variable and functions accessed by camera service */ |
| 236 | static camera3_device_ops_t mCameraOps; |
| 237 | //Id of each session in bundle/link |
| 238 | static uint32_t sessionId[MM_CAMERA_MAX_NUM_SENSORS]; |
| 239 | static int initialize(const struct camera3_device *, |
| 240 | const camera3_callback_ops_t *callback_ops); |
| 241 | static int configure_streams(const struct camera3_device *, |
| 242 | camera3_stream_configuration_t *stream_list); |
| 243 | static const camera_metadata_t* construct_default_request_settings( |
| 244 | const struct camera3_device *, int type); |
| 245 | static int process_capture_request(const struct camera3_device *, |
| 246 | camera3_capture_request_t *request); |
| 247 | |
| 248 | static void dump(const struct camera3_device *, int fd); |
| 249 | static int flush(const struct camera3_device *); |
| 250 | static int close_camera_device(struct hw_device_t* device); |
| 251 | |
| 252 | public: |
| 253 | QCamera3HardwareInterface(uint32_t cameraId, |
| 254 | const camera_module_callbacks_t *callbacks); |
| 255 | virtual ~QCamera3HardwareInterface(); |
| 256 | static void camEvtHandle(uint32_t camera_handle, mm_camera_event_t *evt, |
| 257 | void *user_data); |
| 258 | int openCamera(struct hw_device_t **hw_device); |
| 259 | camera_metadata_t* translateCapabilityToMetadata(int type); |
| 260 | |
Thierry Strudel | e80ad7c | 2016-12-06 10:16:27 -0800 | [diff] [blame] | 261 | typedef struct { |
| 262 | camera3_stream_t *stream; |
| 263 | bool need_metadata; |
| 264 | bool meteringOnly; |
| 265 | } InternalRequest; |
| 266 | |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 267 | static int getCamInfo(uint32_t cameraId, struct camera_info *info); |
Thierry Strudel | cca4d9c | 2016-10-20 08:25:53 -0700 | [diff] [blame] | 268 | static cam_capability_t *getCapabilities(mm_camera_ops_t *ops, |
| 269 | uint32_t cam_handle); |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 270 | static int initCapabilities(uint32_t cameraId); |
| 271 | static int initStaticMetadata(uint32_t cameraId); |
Chien-Yu Chen | 27ec962 | 2017-02-23 13:39:41 -0800 | [diff] [blame] | 272 | static int initHdrPlusClientLocked(); |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 273 | static void makeTable(cam_dimension_t *dimTable, size_t size, |
| 274 | size_t max_size, int32_t *sizeTable); |
| 275 | static void makeFPSTable(cam_fps_range_t *fpsTable, size_t size, |
| 276 | size_t max_size, int32_t *fpsRangesTable); |
| 277 | static void makeOverridesList(cam_scene_mode_overrides_t *overridesTable, |
| 278 | size_t size, size_t max_size, uint8_t *overridesList, |
| 279 | uint8_t *supported_indexes, uint32_t camera_id); |
| 280 | static size_t filterJpegSizes(int32_t *jpegSizes, int32_t *processedSizes, |
| 281 | size_t processedSizesCnt, size_t maxCount, cam_rect_t active_array_size, |
| 282 | uint8_t downscale_factor); |
| 283 | static void convertToRegions(cam_rect_t rect, int32_t* region, int weight); |
Chien-Yu Chen | 92724a8 | 2017-01-06 11:50:30 -0800 | [diff] [blame] | 284 | static void convertFromRegions(cam_area_t &roi, const CameraMetadata &frame_settings, |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 285 | uint32_t tag); |
| 286 | static bool resetIfNeededROI(cam_area_t* roi, const cam_crop_region_t* scalerCropRegion); |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 287 | static int32_t getSensorSensitivity(int32_t iso_mode); |
| 288 | |
| 289 | double computeNoiseModelEntryS(int32_t sensitivity); |
| 290 | double computeNoiseModelEntryO(int32_t sensitivity); |
| 291 | |
| 292 | static void captureResultCb(mm_camera_super_buf_t *metadata, |
| 293 | camera3_stream_buffer_t *buffer, uint32_t frame_number, |
| 294 | bool isInputBuffer, void *userdata); |
| 295 | |
| 296 | int initialize(const camera3_callback_ops_t *callback_ops); |
| 297 | int configureStreams(camera3_stream_configuration_t *stream_list); |
| 298 | int configureStreamsPerfLocked(camera3_stream_configuration_t *stream_list); |
Thierry Strudel | e80ad7c | 2016-12-06 10:16:27 -0800 | [diff] [blame] | 299 | int processCaptureRequest(camera3_capture_request_t *request, |
| 300 | List<InternalRequest> &internalReqs); |
| 301 | int orchestrateRequest(camera3_capture_request_t *request); |
| 302 | void orchestrateResult(camera3_capture_result_t *result); |
| 303 | void orchestrateNotify(camera3_notify_msg_t *notify_msg); |
| 304 | |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 305 | void dump(int fd); |
| 306 | int flushPerf(); |
| 307 | |
| 308 | int setFrameParameters(camera3_capture_request_t *request, |
| 309 | cam_stream_ID_t streamID, int blob_request, uint32_t snapshotStreamId); |
| 310 | int32_t setReprocParameters(camera3_capture_request_t *request, |
| 311 | metadata_buffer_t *reprocParam, uint32_t snapshotStreamId); |
| 312 | int translateToHalMetadata(const camera3_capture_request_t *request, |
| 313 | metadata_buffer_t *parm, uint32_t snapshotStreamId); |
Chien-Yu Chen | 92724a8 | 2017-01-06 11:50:30 -0800 | [diff] [blame] | 314 | int translateFwkMetadataToHalMetadata(const camera_metadata_t *frameworkMetadata, |
| 315 | metadata_buffer_t *hal_metadata, uint32_t snapshotStreamId, int64_t minFrameDuration); |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 316 | camera_metadata_t* translateCbUrgentMetadataToResultMetadata ( |
Shuzhen Wang | 181c57b | 2017-07-21 11:39:44 -0700 | [diff] [blame] | 317 | metadata_buffer_t *metadata, bool lastUrgentMetadataInBatch, |
Shuzhen Wang | 485e244 | 2017-08-02 12:21:08 -0700 | [diff] [blame] | 318 | uint32_t frame_number, bool isJumpstartMetadata); |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 319 | camera_metadata_t* saveRequestSettings(const CameraMetadata& jpegMetadata, |
| 320 | camera3_capture_request_t *request); |
| 321 | int initParameters(); |
| 322 | void deinitParameters(); |
| 323 | QCamera3ReprocessChannel *addOfflineReprocChannel(const reprocess_config_t &config, |
| 324 | QCamera3ProcessingChannel *inputChHandle); |
| 325 | bool needRotationReprocess(); |
| 326 | bool needJpegExifRotation(); |
| 327 | bool needReprocess(cam_feature_mask_t postprocess_mask); |
| 328 | bool needJpegRotation(); |
| 329 | cam_denoise_process_type_t getWaveletDenoiseProcessPlate(); |
| 330 | cam_denoise_process_type_t getTemporalDenoiseProcessPlate(); |
| 331 | |
| 332 | void captureResultCb(mm_camera_super_buf_t *metadata, |
| 333 | camera3_stream_buffer_t *buffer, uint32_t frame_number, |
| 334 | bool isInputBuffer); |
| 335 | cam_dimension_t calcMaxJpegDim(); |
| 336 | bool needOnlineRotation(); |
| 337 | uint32_t getJpegQuality(); |
| 338 | QCamera3Exif *getExifData(); |
| 339 | mm_jpeg_exif_params_t get3AExifParams(); |
| 340 | uint8_t getMobicatMask(); |
| 341 | static void getFlashInfo(const int cameraId, |
| 342 | bool& hasFlash, |
| 343 | char (&flashNode)[QCAMERA_MAX_FILEPATH_LENGTH]); |
| 344 | const char *getEepromVersionInfo(); |
| 345 | const uint32_t *getLdafCalib(); |
| 346 | void get3AVersion(cam_q3a_version_t &swVersion); |
Thierry Strudel | c2ee330 | 2016-11-17 12:33:12 -0800 | [diff] [blame] | 347 | static void setBufferErrorStatus(QCamera3Channel*, uint32_t frameNumber, |
| 348 | camera3_buffer_status_t err, void *userdata); |
| 349 | void setBufferErrorStatus(QCamera3Channel*, uint32_t frameNumber, |
| 350 | camera3_buffer_status_t err); |
Shuzhen Wang | f6890e0 | 2016-08-12 14:28:54 -0700 | [diff] [blame] | 351 | bool is60HzZone(); |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 352 | |
| 353 | // Get dual camera related info |
| 354 | bool isDeviceLinked() {return mIsDeviceLinked;} |
| 355 | bool isMainCamera() {return mIsMainCamera;} |
| 356 | uint32_t getSensorMountAngle(); |
| 357 | const cam_related_system_calibration_data_t *getRelatedCalibrationData(); |
| 358 | |
| 359 | template <typename fwkType, typename halType> struct QCameraMap { |
| 360 | fwkType fwk_name; |
| 361 | halType hal_name; |
| 362 | }; |
| 363 | |
| 364 | typedef struct { |
| 365 | const char *const desc; |
| 366 | cam_cds_mode_type_t val; |
| 367 | } QCameraPropMap; |
| 368 | |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 369 | private: |
| 370 | |
| 371 | // State transition conditions: |
| 372 | // "\" means not applicable |
| 373 | // "x" means not valid |
| 374 | // +------------+----------+----------+-------------+------------+---------+-------+--------+ |
| 375 | // | | CLOSED | OPENED | INITIALIZED | CONFIGURED | STARTED | ERROR | DEINIT | |
| 376 | // +------------+----------+----------+-------------+------------+---------+-------+--------+ |
| 377 | // | CLOSED | \ | open | x | x | x | x | x | |
| 378 | // +------------+----------+----------+-------------+------------+---------+-------+--------+ |
| 379 | // | OPENED | close | \ | initialize | x | x | error | x | |
| 380 | // +------------+----------+----------+-------------+------------+---------+-------+--------+ |
| 381 | // |INITIALIZED | close | x | \ | configure | x | error | x | |
| 382 | // +------------+----------+----------+-------------+------------+---------+-------+--------+ |
| 383 | // | CONFIGURED | close | x | x | configure | request | error | x | |
| 384 | // +------------+----------+----------+-------------+------------+---------+-------+--------+ |
| 385 | // | STARTED | close | x | x | configure | \ | error | x | |
| 386 | // +------------+----------+----------+-------------+------------+---------+-------+--------+ |
| 387 | // | ERROR | close | x | x | x | x | \ | any | |
| 388 | // +------------+----------+----------+-------------+------------+---------+-------+--------+ |
| 389 | // | DEINIT | close | x | x | x | x | x | \ | |
| 390 | // +------------+----------+----------+-------------+------------+---------+-------+--------+ |
| 391 | |
| 392 | typedef enum { |
| 393 | CLOSED, |
| 394 | OPENED, |
| 395 | INITIALIZED, |
| 396 | CONFIGURED, |
| 397 | STARTED, |
| 398 | ERROR, |
| 399 | DEINIT |
| 400 | } State; |
| 401 | |
| 402 | int openCamera(); |
| 403 | int closeCamera(); |
Chien-Yu Chen | 09cb28e | 2017-07-21 13:15:52 -0700 | [diff] [blame] | 404 | int flush(bool restartChannels, bool stopChannelImmediately = false); |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 405 | static size_t calcMaxJpegSize(uint32_t camera_id); |
| 406 | cam_dimension_t getMaxRawSize(uint32_t camera_id); |
| 407 | static void addStreamConfig(Vector<int32_t> &available_stream_configs, |
| 408 | int32_t scalar_format, const cam_dimension_t &dim, |
| 409 | int32_t config_type); |
| 410 | |
Thierry Strudel | e80ad7c | 2016-12-06 10:16:27 -0800 | [diff] [blame] | 411 | int validateCaptureRequest(camera3_capture_request_t *request, |
| 412 | List<InternalRequest> &internallyRequestedStreams); |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 413 | int validateStreamDimensions(camera3_stream_configuration_t *streamList); |
| 414 | int validateStreamRotations(camera3_stream_configuration_t *streamList); |
Shuzhen Wang | bb03f5c | 2017-02-17 15:38:24 -0800 | [diff] [blame] | 415 | int validateUsageFlags(const camera3_stream_configuration_t *streamList); |
| 416 | int validateUsageFlagsForEis(const camera3_stream_configuration_t *streamList); |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 417 | void deriveMinFrameDuration(); |
| 418 | void handleBuffersDuringFlushLock(camera3_stream_buffer_t *buffer); |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 419 | int64_t getMinFrameDuration(const camera3_capture_request_t *request); |
| 420 | void handleMetadataWithLock(mm_camera_super_buf_t *metadata_buf, |
Thierry Strudel | 9e74aae | 2016-09-22 17:10:18 -0700 | [diff] [blame] | 421 | bool free_and_bufdone_meta_buf, |
Shuzhen Wang | 94ddf07 | 2017-03-12 19:47:23 -0700 | [diff] [blame] | 422 | bool lastUrgentMetadataInBatch, |
| 423 | bool lastMetadataInBatch, |
Thierry Strudel | 54dc978 | 2017-02-15 12:12:10 -0800 | [diff] [blame] | 424 | bool *p_is_metabuf_queued); |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 425 | void handleBatchMetadata(mm_camera_super_buf_t *metadata_buf, |
| 426 | bool free_and_bufdone_meta_buf); |
| 427 | void handleBufferWithLock(camera3_stream_buffer_t *buffer, |
| 428 | uint32_t frame_number); |
| 429 | void handleInputBufferWithLock(uint32_t frame_number); |
Chien-Yu Chen | e687bd0 | 2016-12-07 18:30:26 -0800 | [diff] [blame] | 430 | // Handle pending results when a new result metadata of a frame is received. |
Chien-Yu Chen | 3f30352 | 2017-05-19 15:21:45 -0700 | [diff] [blame] | 431 | // metadata callbacks are invoked in the order of frame number. |
| 432 | void handlePendingResultMetadataWithLock(uint32_t frameNumber, |
Chien-Yu Chen | bc73023 | 2017-07-12 14:49:55 -0700 | [diff] [blame] | 433 | camera_metadata_t *resultMetadata); |
Chien-Yu Chen | 588cc85 | 2017-06-23 18:39:51 -0700 | [diff] [blame] | 434 | // Going through pending request list and send out result metadata for requests |
| 435 | // that are ready. |
| 436 | // frameNumber is the lastest frame whose result metadata is ready. |
| 437 | // isLiveRequest is whether the frame belongs to a live request. |
| 438 | void dispatchResultMetadataWithLock(uint32_t frameNumber, bool isLiveRequest); |
Emilian Peev | 7650c12 | 2017-01-19 08:24:33 -0800 | [diff] [blame] | 439 | void handleDepthDataLocked(const cam_depth_data_t &depthData, |
Emilian Peev | 4e0fe95 | 2017-06-30 12:40:09 -0700 | [diff] [blame] | 440 | uint32_t frameNumber, uint8_t valid); |
Emilian Peev | 7650c12 | 2017-01-19 08:24:33 -0800 | [diff] [blame] | 441 | void notifyErrorFoPendingDepthData(QCamera3DepthChannel *depthCh); |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 442 | void unblockRequestIfNecessary(); |
| 443 | void dumpMetadataToFile(tuning_params_t &meta, uint32_t &dumpFrameCount, |
| 444 | bool enabled, const char *type, uint32_t frameNumber); |
| 445 | static void getLogLevel(); |
Emilian Peev | 0f3c316 | 2017-03-15 12:57:46 +0000 | [diff] [blame] | 446 | static int32_t getPDStatIndex(cam_capability_t *caps); |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 447 | |
| 448 | void cleanAndSortStreamInfo(); |
| 449 | void extractJpegMetadata(CameraMetadata& jpegMetadata, |
| 450 | const camera3_capture_request_t *request); |
| 451 | |
| 452 | bool isSupportChannelNeeded(camera3_stream_configuration_t *streamList, |
| 453 | cam_stream_size_info_t stream_config_info); |
Thierry Strudel | e80ad7c | 2016-12-06 10:16:27 -0800 | [diff] [blame] | 454 | bool isHdrSnapshotRequest(camera3_capture_request *request); |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 455 | int32_t setMobicat(); |
| 456 | |
Chien-Yu Chen | 8e59949 | 2016-11-01 13:37:46 -0700 | [diff] [blame] | 457 | int32_t getSensorModeInfo(cam_sensor_mode_info_t &sensorModeInfo); |
Chien-Yu Chen | 605c387 | 2017-06-14 11:09:23 -0700 | [diff] [blame] | 458 | // Get information of the sensor mode that is currently selected. |
| 459 | int32_t getCurrentSensorModeInfo(cam_sensor_mode_info_t &sensorModeInfo); |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 460 | int32_t setHalFpsRange(const CameraMetadata &settings, |
| 461 | metadata_buffer_t *hal_metadata); |
| 462 | int32_t extractSceneMode(const CameraMetadata &frame_settings, uint8_t metaMode, |
| 463 | metadata_buffer_t *hal_metadata); |
Thierry Strudel | 04e026f | 2016-10-10 11:27:36 -0700 | [diff] [blame] | 464 | int32_t setVideoHdrMode(metadata_buffer_t *hal_metadata, |
| 465 | cam_video_hdr_mode_t vhdr); |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 466 | int32_t numOfSizesOnEncoder(const camera3_stream_configuration_t *streamList, |
| 467 | const cam_dimension_t &maxViewfinderSize); |
| 468 | |
| 469 | void addToPPFeatureMask(int stream_format, uint32_t stream_idx); |
| 470 | void updateFpsInPreviewBuffer(metadata_buffer_t *metadata, uint32_t frame_number); |
Thierry Strudel | cca4d9c | 2016-10-20 08:25:53 -0700 | [diff] [blame] | 471 | void updateTimeStampInPendingBuffers(uint32_t frameNumber, nsecs_t timestamp); |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 472 | |
| 473 | void enablePowerHint(); |
| 474 | void disablePowerHint(); |
| 475 | int32_t dynamicUpdateMetaStreamInfo(); |
| 476 | int32_t startAllChannels(); |
| 477 | int32_t stopAllChannels(); |
| 478 | int32_t notifyErrorForPendingRequests(); |
Thierry Strudel | 9e74aae | 2016-09-22 17:10:18 -0700 | [diff] [blame] | 479 | void notifyError(uint32_t frameNumber, |
| 480 | camera3_error_msg_code_t errorCode); |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 481 | int32_t getReprocessibleOutputStreamId(uint32_t &id); |
Chien-Yu Chen | 09cb28e | 2017-07-21 13:15:52 -0700 | [diff] [blame] | 482 | int32_t handleCameraDeviceError(bool stopChannelImmediately = false); |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 483 | |
| 484 | bool isOnEncoder(const cam_dimension_t max_viewfinder_size, |
| 485 | uint32_t width, uint32_t height); |
| 486 | void hdrPlusPerfLock(mm_camera_super_buf_t *metadata_buf); |
| 487 | |
| 488 | static bool supportBurstCapture(uint32_t cameraId); |
| 489 | int32_t setBundleInfo(); |
Thierry Strudel | 295a0ca | 2016-11-03 18:38:47 -0700 | [diff] [blame] | 490 | int32_t setInstantAEC(const CameraMetadata &meta); |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 491 | |
Thierry Strudel | 04e026f | 2016-10-10 11:27:36 -0700 | [diff] [blame] | 492 | static void convertLandmarks(cam_face_landmarks_info_t face, int32_t* landmarks); |
| 493 | static void setInvalidLandmarks(int32_t* landmarks); |
| 494 | |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 495 | static void setPAAFSupport(cam_feature_mask_t& feature_mask, |
| 496 | cam_stream_type_t stream_type, |
| 497 | cam_color_filter_arrangement_t filter_arrangement); |
Mansoor Aftab | 58465fa | 2017-01-26 15:02:44 -0800 | [diff] [blame] | 498 | int32_t setSensorHDR(metadata_buffer_t *hal_metadata, bool enable, |
| 499 | bool isVideoHdrEnable = false); |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 500 | |
Shuzhen Wang | a5da102 | 2016-07-13 20:18:42 -0700 | [diff] [blame] | 501 | template <typename T> |
| 502 | static void adjustBlackLevelForCFA(T input[BLACK_LEVEL_PATTERN_CNT], |
| 503 | T output[BLACK_LEVEL_PATTERN_CNT], |
| 504 | cam_color_filter_arrangement_t color_arrangement); |
| 505 | |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 506 | camera3_device_t mCameraDevice; |
| 507 | uint32_t mCameraId; |
| 508 | mm_camera_vtbl_t *mCameraHandle; |
| 509 | bool mCameraInitialized; |
| 510 | camera_metadata_t *mDefaultMetadata[CAMERA3_TEMPLATE_COUNT]; |
| 511 | const camera3_callback_ops_t *mCallbackOps; |
| 512 | |
| 513 | QCamera3MetadataChannel *mMetadataChannel; |
| 514 | QCamera3PicChannel *mPictureChannel; |
| 515 | QCamera3RawChannel *mRawChannel; |
| 516 | QCamera3SupportChannel *mSupportChannel; |
| 517 | QCamera3SupportChannel *mAnalysisChannel; |
| 518 | QCamera3RawDumpChannel *mRawDumpChannel; |
Chien-Yu Chen | 8e59949 | 2016-11-01 13:37:46 -0700 | [diff] [blame] | 519 | QCamera3HdrPlusRawSrcChannel *mHdrPlusRawSrcChannel; |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 520 | QCamera3RegularChannel *mDummyBatchChannel; |
Emilian Peev | 7650c12 | 2017-01-19 08:24:33 -0800 | [diff] [blame] | 521 | QCamera3DepthChannel *mDepthChannel; |
Emilian Peev | 656e4fa | 2017-06-02 16:47:04 +0100 | [diff] [blame] | 522 | cam_sensor_pd_data_t mDepthCloudMode; //Cache last configured mode |
Thierry Strudel | c2ee330 | 2016-11-17 12:33:12 -0800 | [diff] [blame] | 523 | QCameraPerfLockMgr mPerfLockMgr; |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 524 | |
| 525 | uint32_t mChannelHandle; |
| 526 | |
| 527 | void saveExifParams(metadata_buffer_t *metadata); |
| 528 | mm_jpeg_exif_params_t mExifParams; |
| 529 | |
| 530 | //First request yet to be processed after configureStreams |
| 531 | bool mFirstConfiguration; |
| 532 | bool mFlush; |
| 533 | bool mFlushPerf; |
| 534 | bool mEnableRawDump; |
Thierry Strudel | e80ad7c | 2016-12-06 10:16:27 -0800 | [diff] [blame] | 535 | bool mForceHdrSnapshot; |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 536 | QCamera3HeapMemory *mParamHeap; |
| 537 | metadata_buffer_t* mParameters; |
| 538 | metadata_buffer_t* mPrevParameters; |
| 539 | CameraMetadata mCurJpegMeta; |
| 540 | bool m_bIsVideo; |
| 541 | bool m_bIs4KVideo; |
| 542 | bool m_bEisSupportedSize; |
| 543 | bool m_bEisEnable; |
Thierry Strudel | 2896d12 | 2017-02-23 19:18:03 -0800 | [diff] [blame] | 544 | bool m_bEis3PropertyEnabled; |
Thierry Strudel | 9e74aae | 2016-09-22 17:10:18 -0700 | [diff] [blame] | 545 | bool m_bEisSupported; |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 546 | typedef struct { |
| 547 | cam_dimension_t dim; |
| 548 | int format; |
| 549 | uint32_t usage; |
| 550 | } InputStreamInfo; |
| 551 | |
| 552 | InputStreamInfo mInputStreamInfo; |
| 553 | uint8_t m_MobicatMask; |
| 554 | uint8_t m_bTnrEnabled; |
| 555 | int8_t mSupportedFaceDetectMode; |
| 556 | uint8_t m_bTnrPreview; |
Thierry Strudel | e80ad7c | 2016-12-06 10:16:27 -0800 | [diff] [blame] | 557 | uint8_t m_bSwTnrPreview; |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 558 | uint8_t m_bTnrVideo; |
| 559 | uint8_t m_debug_avtimer; |
Mansoor Aftab | 93a66e5 | 2017-01-26 14:58:25 -0800 | [diff] [blame] | 560 | uint8_t m_bVideoHdrEnabled; |
Thierry Strudel | 54dc978 | 2017-02-15 12:12:10 -0800 | [diff] [blame] | 561 | uint8_t m_cacModeDisabled; |
Shuzhen Wang | b57ec91 | 2017-07-31 13:24:27 -0700 | [diff] [blame] | 562 | uint8_t m_bForceInfinityAf; |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 563 | |
| 564 | /* Data structure to store pending request */ |
| 565 | typedef struct { |
| 566 | camera3_stream_t *stream; |
| 567 | camera3_stream_buffer_t *buffer; |
| 568 | // metadata needs to be consumed by the corresponding stream |
| 569 | // in order to generate the buffer. |
| 570 | bool need_metadata; |
| 571 | } RequestedBufferInfo; |
Thierry Strudel | e80ad7c | 2016-12-06 10:16:27 -0800 | [diff] [blame] | 572 | |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 573 | typedef struct { |
| 574 | uint32_t frame_number; |
| 575 | uint32_t num_buffers; |
| 576 | int32_t request_id; |
| 577 | List<RequestedBufferInfo> buffers; |
Thierry Strudel | e80ad7c | 2016-12-06 10:16:27 -0800 | [diff] [blame] | 578 | List<InternalRequest> internalRequestList; |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 579 | int blob_request; |
Shuzhen Wang | 3c077d7 | 2017-04-20 22:48:59 -0700 | [diff] [blame] | 580 | uint8_t bUseFirstPartial; // Use first available partial result in case of jumpstart. |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 581 | nsecs_t timestamp; |
Emilian Peev | 30522a1 | 2017-08-03 14:36:33 +0100 | [diff] [blame] | 582 | nsecs_t expectedFrameDuration; |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 583 | camera3_stream_buffer_t *input_buffer; |
| 584 | const camera_metadata_t *settings; |
Chien-Yu Chen | e687bd0 | 2016-12-07 18:30:26 -0800 | [diff] [blame] | 585 | const camera_metadata_t *resultMetadata; // Result metadata for this request. |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 586 | CameraMetadata jpegMetadata; |
| 587 | uint8_t pipeline_depth; |
| 588 | uint32_t partial_result_cnt; |
| 589 | uint8_t capture_intent; |
| 590 | uint8_t fwkCacMode; |
Shuzhen Wang | 2abea3d | 2016-03-31 11:09:27 -0700 | [diff] [blame] | 591 | uint8_t hybrid_ae_enable; |
Samuel Ha | 68ba517 | 2016-12-15 18:41:12 -0800 | [diff] [blame] | 592 | /* DevCamDebug metadata PendingRequestInfo */ |
| 593 | uint8_t DevCamDebug_meta_enable; |
| 594 | /* DevCamDebug metadata end */ |
Chien-Yu Chen | e687bd0 | 2016-12-07 18:30:26 -0800 | [diff] [blame] | 595 | |
Shuzhen Wang | 3733cc9 | 2017-07-27 18:15:05 -0700 | [diff] [blame] | 596 | bool focusStateSent = false; |
| 597 | bool focusStateValid = false; |
| 598 | uint8_t focusState = ANDROID_CONTROL_AF_STATE_INACTIVE; |
Shuzhen Wang | 181c57b | 2017-07-21 11:39:44 -0700 | [diff] [blame] | 599 | |
Chien-Yu Chen | 66ec22a | 2017-04-13 18:00:36 -0700 | [diff] [blame] | 600 | bool enableZsl; // If ZSL is enabled. |
Chien-Yu Chen | e687bd0 | 2016-12-07 18:30:26 -0800 | [diff] [blame] | 601 | bool hdrplus; // If this is an HDR+ request. |
Chien-Yu Chen | bc73023 | 2017-07-12 14:49:55 -0700 | [diff] [blame] | 602 | uint8_t requestedLensShadingMapMode; // Lens shading map mode for this request. |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 603 | } PendingRequestInfo; |
| 604 | typedef struct { |
| 605 | uint32_t frame_number; |
| 606 | uint32_t stream_ID; |
| 607 | } PendingFrameDropInfo; |
| 608 | |
Thierry Strudel | e80ad7c | 2016-12-06 10:16:27 -0800 | [diff] [blame] | 609 | class FrameNumberRegistry _orchestrationDb; |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 610 | typedef KeyedVector<uint32_t, Vector<PendingBufferInfo> > FlushMap; |
| 611 | typedef List<QCamera3HardwareInterface::PendingRequestInfo>::iterator |
| 612 | pendingRequestIterator; |
| 613 | typedef List<QCamera3HardwareInterface::RequestedBufferInfo>::iterator |
| 614 | pendingBufferIterator; |
| 615 | |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 616 | List<PendingRequestInfo> mPendingRequestsList; |
| 617 | List<PendingFrameDropInfo> mPendingFrameDropList; |
| 618 | /* Use last frame number of the batch as key and first frame number of the |
| 619 | * batch as value for that key */ |
| 620 | KeyedVector<uint32_t, uint32_t> mPendingBatchMap; |
Thierry Strudel | c2ee330 | 2016-11-17 12:33:12 -0800 | [diff] [blame] | 621 | cam_stream_ID_t mBatchedStreamsArray; |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 622 | |
| 623 | PendingBuffersMap mPendingBuffersMap; |
| 624 | pthread_cond_t mRequestCond; |
| 625 | uint32_t mPendingLiveRequest; |
| 626 | bool mWokenUpByDaemon; |
| 627 | int32_t mCurrentRequestId; |
| 628 | cam_stream_size_info_t mStreamConfigInfo; |
| 629 | |
Chien-Yu Chen | 3f30352 | 2017-05-19 15:21:45 -0700 | [diff] [blame] | 630 | ShutterDispatcher mShutterDispatcher; |
| 631 | OutputBufferDispatcher mOutputBufferDispatcher; |
| 632 | |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 633 | //mutex for serialized access to camera3_device_ops_t functions |
| 634 | pthread_mutex_t mMutex; |
| 635 | |
| 636 | //condition used to signal flush after buffers have returned |
| 637 | pthread_cond_t mBuffersCond; |
| 638 | |
| 639 | List<stream_info_t*> mStreamInfo; |
| 640 | |
| 641 | int64_t mMinProcessedFrameDuration; |
| 642 | int64_t mMinJpegFrameDuration; |
| 643 | int64_t mMinRawFrameDuration; |
Emilian Peev | 30522a1 | 2017-08-03 14:36:33 +0100 | [diff] [blame] | 644 | nsecs_t mExpectedFrameDuration; |
| 645 | nsecs_t mExpectedInflightDuration; |
| 646 | static const nsecs_t kDefaultExpectedDuration = 100000000; // 100 ms |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 647 | |
| 648 | uint32_t mMetaFrameCount; |
| 649 | bool mUpdateDebugLevel; |
| 650 | const camera_module_callbacks_t *mCallbacks; |
| 651 | |
| 652 | uint8_t mCaptureIntent; |
| 653 | uint8_t mCacMode; |
Shuzhen Wang | 2abea3d | 2016-03-31 11:09:27 -0700 | [diff] [blame] | 654 | uint8_t mHybridAeEnable; |
Samuel Ha | 68ba517 | 2016-12-15 18:41:12 -0800 | [diff] [blame] | 655 | // DevCamDebug metadata internal variable |
| 656 | uint8_t mDevCamDebugMetaEnable; |
| 657 | /* DevCamDebug metadata end */ |
| 658 | |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 659 | metadata_buffer_t mReprocMeta; //scratch meta buffer |
| 660 | /* 0: Not batch, non-zero: Number of image buffers in a batch */ |
| 661 | uint8_t mBatchSize; |
| 662 | // Used only in batch mode |
| 663 | uint8_t mToBeQueuedVidBufs; |
| 664 | // Fixed video fps |
| 665 | float mHFRVideoFps; |
Thierry Strudel | c2ee330 | 2016-11-17 12:33:12 -0800 | [diff] [blame] | 666 | public: |
Thierry Strudel | 2896d12 | 2017-02-23 19:18:03 -0800 | [diff] [blame] | 667 | uint32_t mOpMode; |
Thierry Strudel | 54dc978 | 2017-02-15 12:12:10 -0800 | [diff] [blame] | 668 | bool mStreamConfig; |
Thierry Strudel | 2896d12 | 2017-02-23 19:18:03 -0800 | [diff] [blame] | 669 | QCameraCommon mCommon; |
Thierry Strudel | c2ee330 | 2016-11-17 12:33:12 -0800 | [diff] [blame] | 670 | private: |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 671 | uint32_t mFirstFrameNumberInBatch; |
| 672 | camera3_stream_t mDummyBatchStream; |
| 673 | bool mNeedSensorRestart; |
Thierry Strudel | c2ee330 | 2016-11-17 12:33:12 -0800 | [diff] [blame] | 674 | bool mPreviewStarted; |
Thierry Strudel | 9e74aae | 2016-09-22 17:10:18 -0700 | [diff] [blame] | 675 | uint32_t mMinInFlightRequests; |
| 676 | uint32_t mMaxInFlightRequests; |
Emilian Peev | 0f3c316 | 2017-03-15 12:57:46 +0000 | [diff] [blame] | 677 | bool mPDSupported; |
| 678 | int32_t mPDIndex; |
Thierry Strudel | 295a0ca | 2016-11-03 18:38:47 -0700 | [diff] [blame] | 679 | // Param to trigger instant AEC. |
| 680 | bool mInstantAEC; |
| 681 | // Param to know when to reset AEC |
| 682 | bool mResetInstantAEC; |
| 683 | // Frame number, untill which we need to drop the frames. |
| 684 | uint32_t mInstantAECSettledFrameNumber; |
| 685 | // Max number of frames, that HAL will hold without displaying, for instant AEC mode. |
| 686 | uint8_t mAecSkipDisplayFrameBound; |
| 687 | // Counter to keep track of number of frames that took for AEC convergence. |
| 688 | uint8_t mInstantAecFrameIdxCount; |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 689 | /* sensor output size with current stream configuration */ |
| 690 | QCamera3CropRegionMapper mCropRegionMapper; |
Chien-Yu Chen | bc73023 | 2017-07-12 14:49:55 -0700 | [diff] [blame] | 691 | // Last lens shading map mode framework requsted. |
| 692 | uint8_t mLastRequestedLensShadingMapMode; |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 693 | |
Thierry Strudel | 54dc978 | 2017-02-15 12:12:10 -0800 | [diff] [blame] | 694 | cam_feature_mask_t mCurrFeatureState; |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 695 | /* Ldaf calibration data */ |
| 696 | bool mLdafCalibExist; |
| 697 | uint32_t mLdafCalib[2]; |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 698 | int32_t mLastCustIntentFrmNum; |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 699 | |
| 700 | static const QCameraMap<camera_metadata_enum_android_control_effect_mode_t, |
| 701 | cam_effect_mode_type> EFFECT_MODES_MAP[]; |
| 702 | static const QCameraMap<camera_metadata_enum_android_control_awb_mode_t, |
| 703 | cam_wb_mode_type> WHITE_BALANCE_MODES_MAP[]; |
| 704 | static const QCameraMap<camera_metadata_enum_android_control_scene_mode_t, |
| 705 | cam_scene_mode_type> SCENE_MODES_MAP[]; |
| 706 | static const QCameraMap<camera_metadata_enum_android_control_af_mode_t, |
| 707 | cam_focus_mode_type> FOCUS_MODES_MAP[]; |
| 708 | static const QCameraMap<camera_metadata_enum_android_color_correction_aberration_mode_t, |
| 709 | cam_aberration_mode_t> COLOR_ABERRATION_MAP[]; |
| 710 | static const QCameraMap<camera_metadata_enum_android_control_ae_antibanding_mode_t, |
| 711 | cam_antibanding_mode_type> ANTIBANDING_MODES_MAP[]; |
| 712 | static const QCameraMap<camera_metadata_enum_android_lens_state_t, |
| 713 | cam_af_lens_state_t> LENS_STATE_MAP[]; |
| 714 | static const QCameraMap<camera_metadata_enum_android_control_ae_mode_t, |
| 715 | cam_flash_mode_t> AE_FLASH_MODE_MAP[]; |
| 716 | static const QCameraMap<camera_metadata_enum_android_flash_mode_t, |
| 717 | cam_flash_mode_t> FLASH_MODES_MAP[]; |
| 718 | static const QCameraMap<camera_metadata_enum_android_statistics_face_detect_mode_t, |
| 719 | cam_face_detect_mode_t> FACEDETECT_MODES_MAP[]; |
| 720 | static const QCameraMap<camera_metadata_enum_android_lens_info_focus_distance_calibration_t, |
| 721 | cam_focus_calibration_t> FOCUS_CALIBRATION_MAP[]; |
| 722 | static const QCameraMap<camera_metadata_enum_android_sensor_test_pattern_mode_t, |
| 723 | cam_test_pattern_mode_t> TEST_PATTERN_MAP[]; |
Thierry Strudel | 04e026f | 2016-10-10 11:27:36 -0700 | [diff] [blame] | 724 | static const QCameraMap<camera_metadata_enum_android_video_hdr_mode_t, |
| 725 | cam_video_hdr_mode_t> VIDEO_HDR_MODES_MAP[]; |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 726 | static const QCameraMap<camera_metadata_enum_android_sensor_reference_illuminant1_t, |
| 727 | cam_illuminat_t> REFERENCE_ILLUMINANT_MAP[]; |
| 728 | static const QCameraMap<int32_t, |
| 729 | cam_hfr_mode_t> HFR_MODE_MAP[]; |
Thierry Strudel | 04e026f | 2016-10-10 11:27:36 -0700 | [diff] [blame] | 730 | static const QCameraMap<camera_metadata_enum_android_ir_mode_t, |
| 731 | cam_ir_mode_type_t> IR_MODES_MAP[]; |
Thierry Strudel | 295a0ca | 2016-11-03 18:38:47 -0700 | [diff] [blame] | 732 | static const QCameraMap<qcamera3_ext_instant_aec_mode_t, |
| 733 | cam_aec_convergence_type> INSTANT_AEC_MODES_MAP[]; |
Thierry Strudel | 54dc978 | 2017-02-15 12:12:10 -0800 | [diff] [blame] | 734 | static const QCameraMap<camera_metadata_enum_android_binning_correction_mode_t, |
| 735 | cam_binning_correction_mode_t> BINNING_CORRECTION_MODES_MAP[]; |
| 736 | static const QCameraMap<qcamera3_ext_exposure_meter_mode_t, |
| 737 | cam_auto_exposure_mode_type> AEC_MODES_MAP[]; |
| 738 | static const QCameraMap<qcamera3_ext_iso_mode_t, |
| 739 | cam_iso_mode_type> ISO_MODES_MAP[]; |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 740 | static const QCameraPropMap CDS_MAP[]; |
| 741 | |
| 742 | pendingRequestIterator erasePendingRequest(pendingRequestIterator i); |
| 743 | //GPU library to read buffer padding details. |
| 744 | void *lib_surface_utils; |
| 745 | int (*LINK_get_surface_pixel_alignment)(); |
| 746 | uint32_t mSurfaceStridePadding; |
| 747 | |
Shuzhen Wang | 3c077d7 | 2017-04-20 22:48:59 -0700 | [diff] [blame] | 748 | bool mFirstMetadataCallback; |
| 749 | void sendPartialMetadataWithLock(metadata_buffer_t *metadata, |
| 750 | const pendingRequestIterator requestIter, |
Shuzhen Wang | 485e244 | 2017-08-02 12:21:08 -0700 | [diff] [blame] | 751 | bool lastUrgentMetadataInBatch, bool isJumpstartMetadata); |
Shuzhen Wang | 3c077d7 | 2017-04-20 22:48:59 -0700 | [diff] [blame] | 752 | |
Shuzhen Wang | 181c57b | 2017-07-21 11:39:44 -0700 | [diff] [blame] | 753 | camera_metadata_t* translateFromHalMetadata(metadata_buffer_t *metadata, |
| 754 | const PendingRequestInfo& pendingRequest, |
| 755 | /* DevCamDebug metadata end */ |
| 756 | bool pprocDone, |
| 757 | bool lastMetadataInBatch, |
| 758 | const bool *enableZsl); |
| 759 | |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 760 | State mState; |
| 761 | //Dual camera related params |
| 762 | bool mIsDeviceLinked; |
| 763 | bool mIsMainCamera; |
| 764 | uint8_t mLinkedCameraId; |
Thierry Strudel | 295a0ca | 2016-11-03 18:38:47 -0700 | [diff] [blame] | 765 | QCamera3HeapMemory *m_pDualCamCmdHeap; |
| 766 | cam_dual_camera_cmd_info_t *m_pDualCamCmdPtr; |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 767 | cam_sync_related_sensors_event_info_t m_relCamSyncInfo; |
Thierry Strudel | e80ad7c | 2016-12-06 10:16:27 -0800 | [diff] [blame] | 768 | Mutex mFlushLock; |
Shuzhen Wang | f6890e0 | 2016-08-12 14:28:54 -0700 | [diff] [blame] | 769 | bool m60HzZone; |
| 770 | |
Chien-Yu Chen | 8e59949 | 2016-11-01 13:37:46 -0700 | [diff] [blame] | 771 | // Stream IDs used in stream configuration with HDR+ client. |
| 772 | const static uint32_t kPbRaw10InputStreamId = 0; |
| 773 | const static uint32_t kPbYuvOutputStreamId = 1; |
| 774 | const static uint32_t kPbRaw16OutputStreamId = 2; |
| 775 | |
Chien-Yu Chen | e687bd0 | 2016-12-07 18:30:26 -0800 | [diff] [blame] | 776 | // Issue an additional RAW for every 10 requests to control RAW capture rate. Requesting RAW |
| 777 | // too often will cause frame drops due to latency of sending RAW to HDR+ service. |
| 778 | const static uint32_t kHdrPlusRawPeriod = 10; |
| 779 | |
| 780 | // Define a pending HDR+ request submitted to HDR+ service and not yet received by HAL. |
| 781 | struct HdrPlusPendingRequest { |
| 782 | // YUV buffer from QCamera3PicChannel to be filled by HDR+ client with an HDR+ processed |
| 783 | // frame. |
| 784 | std::shared_ptr<mm_camera_buf_def_t> yuvBuffer; |
| 785 | |
| 786 | // Output buffers in camera framework's request. |
| 787 | std::vector<camera3_stream_buffer_t> frameworkOutputBuffers; |
| 788 | |
| 789 | // Settings in camera framework's request. |
| 790 | std::shared_ptr<metadata_buffer_t> settings; |
| 791 | }; |
| 792 | |
Chien-Yu Chen | 8e59949 | 2016-11-01 13:37:46 -0700 | [diff] [blame] | 793 | // Fill pbcamera::StreamConfiguration based on the channel stream. |
| 794 | status_t fillPbStreamConfig(pbcamera::StreamConfiguration *config, uint32_t pbStreamId, |
| 795 | int pbStreamFormat, QCamera3Channel *channel, uint32_t streamIndex); |
| 796 | |
Chien-Yu Chen | 54c19cb | 2017-03-31 17:53:18 -0700 | [diff] [blame] | 797 | // Open HDR+ client asynchronously. |
| 798 | status_t openHdrPlusClientAsyncLocked(); |
| 799 | |
Chien-Yu Chen | ee33591 | 2017-02-09 17:53:20 -0800 | [diff] [blame] | 800 | // Enable HDR+ mode. Easel will start capturing ZSL buffers. |
| 801 | status_t enableHdrPlusModeLocked(); |
| 802 | |
| 803 | // Disable HDR+ mode. Easel will stop capturing ZSL buffers. |
| 804 | void disableHdrPlusModeLocked(); |
| 805 | |
Chien-Yu Chen | deaebad | 2017-06-30 11:46:34 -0700 | [diff] [blame] | 806 | // Return if current session with configured streams is compatible with HDR+ mode. |
| 807 | bool isSessionHdrPlusModeCompatible(); |
| 808 | |
Chien-Yu Chen | 200b2ce | 2017-02-01 15:03:02 -0800 | [diff] [blame] | 809 | // Configure streams for HDR+. |
Chien-Yu Chen | ee33591 | 2017-02-09 17:53:20 -0800 | [diff] [blame] | 810 | status_t configureHdrPlusStreamsLocked(); |
Chien-Yu Chen | 200b2ce | 2017-02-01 15:03:02 -0800 | [diff] [blame] | 811 | |
| 812 | // Try to submit an HDR+ request. Returning true if an HDR+ request was submitted. Returning |
Chien-Yu Chen | 54c19cb | 2017-03-31 17:53:18 -0700 | [diff] [blame] | 813 | // false if it is not an HDR+ request or submitting an HDR+ request failed. Must be called with |
| 814 | // gHdrPlusClientLock held. |
| 815 | bool trySubmittingHdrPlusRequestLocked(HdrPlusPendingRequest *hdrPlusRequest, |
Chien-Yu Chen | 200b2ce | 2017-02-01 15:03:02 -0800 | [diff] [blame] | 816 | const camera3_capture_request_t &request, const CameraMetadata &metadata); |
| 817 | |
Chien-Yu Chen | 92724a8 | 2017-01-06 11:50:30 -0800 | [diff] [blame] | 818 | // Update HDR+ result metadata with the still capture's request settings. |
| 819 | void updateHdrPlusResultMetadata(CameraMetadata &resultMetadata, |
| 820 | std::shared_ptr<metadata_buffer_t> settings); |
| 821 | |
Chien-Yu Chen | 77ccd02 | 2017-06-23 12:00:36 -0700 | [diff] [blame] | 822 | // Wait until opening HDR+ client completes if it's being opened. |
| 823 | void finishHdrPlusClientOpeningLocked(std::unique_lock<std::mutex> &lock); |
Chien-Yu Chen | 90f1fc1 | 2017-07-14 14:31:53 -0700 | [diff] [blame] | 824 | // Easel manager client callbacks. |
| 825 | void onEaselFatalError(std::string errMsg); |
Chien-Yu Chen | 77ccd02 | 2017-06-23 12:00:36 -0700 | [diff] [blame] | 826 | |
Chien-Yu Chen | 8e59949 | 2016-11-01 13:37:46 -0700 | [diff] [blame] | 827 | // HDR+ client callbacks. |
Chien-Yu Chen | 54c19cb | 2017-03-31 17:53:18 -0700 | [diff] [blame] | 828 | void onOpened(std::unique_ptr<HdrPlusClient> client) override; |
| 829 | void onOpenFailed(status_t err) override; |
Chien-Yu Chen | 411e9c5 | 2017-05-08 11:58:50 -0700 | [diff] [blame] | 830 | void onFatalError() override; |
Chien-Yu Chen | 8e59949 | 2016-11-01 13:37:46 -0700 | [diff] [blame] | 831 | void onCaptureResult(pbcamera::CaptureResult *result, |
| 832 | const camera_metadata_t &resultMetadata) override; |
| 833 | void onFailedCaptureResult(pbcamera::CaptureResult *failedResult) override; |
Chien-Yu Chen | 29fd1d7 | 2017-04-27 18:42:09 -0700 | [diff] [blame] | 834 | void onShutter(uint32_t requestId, int64_t apSensorTimestampNs) override; |
Chien-Yu Chen | 8e59949 | 2016-11-01 13:37:46 -0700 | [diff] [blame] | 835 | |
Emilian Peev | 30522a1 | 2017-08-03 14:36:33 +0100 | [diff] [blame] | 836 | nsecs_t calculateMaxExpectedDuration(const camera_metadata_t *request); |
| 837 | void getExpectedFrameDuration(const camera_metadata_t *request, nsecs_t *frameDuration); |
| 838 | |
Chien-Yu Chen | e687bd0 | 2016-12-07 18:30:26 -0800 | [diff] [blame] | 839 | // Map from frame number to frame. Must be protected by mHdrPlusPendingRequestsLock. |
| 840 | std::map<uint32_t, HdrPlusPendingRequest> mHdrPlusPendingRequests; |
| 841 | Mutex mHdrPlusPendingRequestsLock; |
Chien-Yu Chen | ee33591 | 2017-02-09 17:53:20 -0800 | [diff] [blame] | 842 | |
| 843 | // If HDR+ mode is enabled i.e. if Easel is capturing ZSL buffers. |
| 844 | bool mHdrPlusModeEnabled; |
| 845 | |
Chien-Yu Chen | 66ec22a | 2017-04-13 18:00:36 -0700 | [diff] [blame] | 846 | // If ZSL is enabled (android.control.enableZsl). |
| 847 | bool mZslEnabled; |
| 848 | |
Chien-Yu Chen | ee33591 | 2017-02-09 17:53:20 -0800 | [diff] [blame] | 849 | // If HAL provides RAW input buffers to Easel. This is just for prototyping. |
| 850 | bool mIsApInputUsedForHdrPlus; |
| 851 | |
| 852 | // Current sensor mode information. |
| 853 | cam_sensor_mode_info_t mSensorModeInfo; |
| 854 | |
| 855 | // If there is a capture request with preview intent since stream configuration. |
| 856 | bool mFirstPreviewIntentSeen; |
| 857 | |
Mansoor Aftab | 58465fa | 2017-01-26 15:02:44 -0800 | [diff] [blame] | 858 | bool m_bSensorHDREnabled; |
Shuzhen Wang | 181c57b | 2017-07-21 11:39:44 -0700 | [diff] [blame] | 859 | |
| 860 | cam_trigger_t mAfTrigger; |
Thierry Strudel | 3d63919 | 2016-09-09 11:52:26 -0700 | [diff] [blame] | 861 | }; |
| 862 | |
| 863 | }; // namespace qcamera |
| 864 | |
| 865 | #endif /* __QCAMERA2HARDWAREINTERFACE_H__ */ |