blob: 9e59bba3e8c9fad7a2d8e4f0da1f92615848b0f1 [file] [log] [blame]
Thierry Strudel3d639192016-09-09 11:52:26 -07001/* 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 Parkd4caeb72017-06-12 17:16:36 +090034#include <CameraMetadata.h>
Chien-Yu Chend77a5462017-06-02 18:00:38 -070035#include <map>
36#include <mutex>
Thierry Strudel3d639192016-09-09 11:52:26 -070037#include <pthread.h>
38#include <utils/KeyedVector.h>
39#include <utils/List.h>
Thierry Strudel3d639192016-09-09 11:52:26 -070040// 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 Strudel04e026f2016-10-10 11:27:36 -070048#include "QCamera3VendorTags.h"
Thierry Strudel2896d122017-02-23 19:18:03 -080049#include "QCameraDualCamSettings.h"
Thierry Strudel3d639192016-09-09 11:52:26 -070050
Chien-Yu Chen90f1fc12017-07-14 14:31:53 -070051#include "EaselManagerClient.h"
Chien-Yu Chen8e599492016-11-01 13:37:46 -070052#include "HdrPlusClient.h"
53
Thierry Strudel3d639192016-09-09 11:52:26 -070054extern "C" {
55#include "mm_camera_interface.h"
56#include "mm_jpeg_interface.h"
57}
58
Jiyong Parkd4caeb72017-06-12 17:16:36 +090059using ::android::hardware::camera::common::V1_0::helper::CameraMetadata;
Thierry Strudel3d639192016-09-09 11:52:26 -070060using namespace android;
61
62namespace 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 */
73typedef int64_t nsecs_t;
74#define NSEC_PER_SEC 1000000000LLU
75#define NSEC_PER_USEC 1000LLU
76#define NSEC_PER_33MSEC 33000000LLU
77
Thierry Strudele80ad7c2016-12-06 10:16:27 -080078/*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 Strudel3d639192016-09-09 11:52:26 -070087typedef enum {
88 SET_ENABLE,
89 SET_CONTROLENABLE,
90 SET_RELOAD_CHROMATIX,
91 SET_STATUS,
92} optype_t;
93
94#define MODULE_ALL 0
95
96extern volatile uint32_t gCamHal3LogLevel;
97
98class QCamera3MetadataChannel;
99class QCamera3PicChannel;
100class QCamera3HeapMemory;
101class QCamera3Exif;
Chien-Yu Chen3f303522017-05-19 15:21:45 -0700102class ShutterDispatcher;
103class BufferDispatcher;
Thierry Strudel3d639192016-09-09 11:52:26 -0700104
105typedef 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
113typedef struct {
114 // Stream handle
115 camera3_stream_t *stream;
116 // Buffer handle
117 buffer_handle_t *buffer;
Thierry Strudelc2ee3302016-11-17 12:33:12 -0800118 // Buffer status
119 camera3_buffer_status_t bufStatus = CAMERA3_BUFFER_STATUS_OK;
Thierry Strudel3d639192016-09-09 11:52:26 -0700120} PendingBufferInfo;
121
122typedef 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 Chene687bd02016-12-07 18:30:26 -0800128 bool hdrplus;
Thierry Strudel3d639192016-09-09 11:52:26 -0700129} PendingBuffersInRequest;
130
131class PendingBuffersMap {
132public:
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 Strudelc2ee3302016-11-17 12:33:12 -0800139 int32_t getBufErrStatus(buffer_handle_t *buffer);
Thierry Strudel3d639192016-09-09 11:52:26 -0700140};
141
Thierry Strudele80ad7c2016-12-06 10:16:27 -0800142class FrameNumberRegistry {
143public:
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
154private:
155 std::map<uint32_t, uint32_t> _register;
156 uint32_t _nextFreeInternalNumber;
157 Mutex mRegistryLock;
158};
Thierry Strudel3d639192016-09-09 11:52:26 -0700159
Chien-Yu Chen3f303522017-05-19 15:21:45 -0700160class 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 */
167class ShutterDispatcher {
168public:
169 ShutterDispatcher(QCamera3HardwareInterface *parent);
170 virtual ~ShutterDispatcher() = default;
171
172 // Tell dispatch to expect a shutter for a frame number.
Chien-Yu Chena7f98612017-06-20 16:54:10 -0700173 void expectShutter(uint32_t frameNumber, bool isReprocess);
Chien-Yu Chen3f303522017-05-19 15:21:45 -0700174 // 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
181private:
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 Chena7f98612017-06-20 16:54:10 -0700192 std::map<uint32_t, Shutter> mReprocessShutters;
Chien-Yu Chen3f303522017-05-19 15:21:45 -0700193
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 */
202class OutputBufferDispatcher {
203public:
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
217private:
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 Chen90f1fc12017-07-14 14:31:53 -0700232class QCamera3HardwareInterface : public HdrPlusClientListener,
233 public EaselManagerClientListener {
Thierry Strudel3d639192016-09-09 11:52:26 -0700234public:
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
252public:
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 Strudele80ad7c2016-12-06 10:16:27 -0800261 typedef struct {
262 camera3_stream_t *stream;
263 bool need_metadata;
264 bool meteringOnly;
265 } InternalRequest;
266
Thierry Strudel3d639192016-09-09 11:52:26 -0700267 static int getCamInfo(uint32_t cameraId, struct camera_info *info);
Thierry Strudelcca4d9c2016-10-20 08:25:53 -0700268 static cam_capability_t *getCapabilities(mm_camera_ops_t *ops,
269 uint32_t cam_handle);
Thierry Strudel3d639192016-09-09 11:52:26 -0700270 static int initCapabilities(uint32_t cameraId);
271 static int initStaticMetadata(uint32_t cameraId);
Chien-Yu Chen27ec9622017-02-23 13:39:41 -0800272 static int initHdrPlusClientLocked();
Thierry Strudel3d639192016-09-09 11:52:26 -0700273 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 Chen92724a82017-01-06 11:50:30 -0800284 static void convertFromRegions(cam_area_t &roi, const CameraMetadata &frame_settings,
Thierry Strudel3d639192016-09-09 11:52:26 -0700285 uint32_t tag);
286 static bool resetIfNeededROI(cam_area_t* roi, const cam_crop_region_t* scalerCropRegion);
Thierry Strudel3d639192016-09-09 11:52:26 -0700287 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 Strudele80ad7c2016-12-06 10:16:27 -0800299 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 Strudel3d639192016-09-09 11:52:26 -0700305 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 Chen92724a82017-01-06 11:50:30 -0800314 int translateFwkMetadataToHalMetadata(const camera_metadata_t *frameworkMetadata,
315 metadata_buffer_t *hal_metadata, uint32_t snapshotStreamId, int64_t minFrameDuration);
Thierry Strudel3d639192016-09-09 11:52:26 -0700316 camera_metadata_t* translateCbUrgentMetadataToResultMetadata (
Shuzhen Wang181c57b2017-07-21 11:39:44 -0700317 metadata_buffer_t *metadata, bool lastUrgentMetadataInBatch,
Shuzhen Wang485e2442017-08-02 12:21:08 -0700318 uint32_t frame_number, bool isJumpstartMetadata);
Thierry Strudel3d639192016-09-09 11:52:26 -0700319 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 Strudelc2ee3302016-11-17 12:33:12 -0800347 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 Wangf6890e02016-08-12 14:28:54 -0700351 bool is60HzZone();
Thierry Strudel3d639192016-09-09 11:52:26 -0700352
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 Strudel3d639192016-09-09 11:52:26 -0700369private:
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 Chen09cb28e2017-07-21 13:15:52 -0700404 int flush(bool restartChannels, bool stopChannelImmediately = false);
Thierry Strudel3d639192016-09-09 11:52:26 -0700405 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 Strudele80ad7c2016-12-06 10:16:27 -0800411 int validateCaptureRequest(camera3_capture_request_t *request,
412 List<InternalRequest> &internallyRequestedStreams);
Thierry Strudel3d639192016-09-09 11:52:26 -0700413 int validateStreamDimensions(camera3_stream_configuration_t *streamList);
414 int validateStreamRotations(camera3_stream_configuration_t *streamList);
Shuzhen Wangbb03f5c2017-02-17 15:38:24 -0800415 int validateUsageFlags(const camera3_stream_configuration_t *streamList);
416 int validateUsageFlagsForEis(const camera3_stream_configuration_t *streamList);
Thierry Strudel3d639192016-09-09 11:52:26 -0700417 void deriveMinFrameDuration();
418 void handleBuffersDuringFlushLock(camera3_stream_buffer_t *buffer);
Thierry Strudel3d639192016-09-09 11:52:26 -0700419 int64_t getMinFrameDuration(const camera3_capture_request_t *request);
420 void handleMetadataWithLock(mm_camera_super_buf_t *metadata_buf,
Thierry Strudel9e74aae2016-09-22 17:10:18 -0700421 bool free_and_bufdone_meta_buf,
Shuzhen Wang94ddf072017-03-12 19:47:23 -0700422 bool lastUrgentMetadataInBatch,
423 bool lastMetadataInBatch,
Thierry Strudel54dc9782017-02-15 12:12:10 -0800424 bool *p_is_metabuf_queued);
Thierry Strudel3d639192016-09-09 11:52:26 -0700425 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 Chene687bd02016-12-07 18:30:26 -0800430 // Handle pending results when a new result metadata of a frame is received.
Chien-Yu Chen3f303522017-05-19 15:21:45 -0700431 // metadata callbacks are invoked in the order of frame number.
432 void handlePendingResultMetadataWithLock(uint32_t frameNumber,
Chien-Yu Chenbc730232017-07-12 14:49:55 -0700433 camera_metadata_t *resultMetadata);
Chien-Yu Chen588cc852017-06-23 18:39:51 -0700434 // 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 Peev7650c122017-01-19 08:24:33 -0800439 void handleDepthDataLocked(const cam_depth_data_t &depthData,
Emilian Peev4e0fe952017-06-30 12:40:09 -0700440 uint32_t frameNumber, uint8_t valid);
Emilian Peev7650c122017-01-19 08:24:33 -0800441 void notifyErrorFoPendingDepthData(QCamera3DepthChannel *depthCh);
Thierry Strudel3d639192016-09-09 11:52:26 -0700442 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 Peev0f3c3162017-03-15 12:57:46 +0000446 static int32_t getPDStatIndex(cam_capability_t *caps);
Thierry Strudel3d639192016-09-09 11:52:26 -0700447
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 Strudele80ad7c2016-12-06 10:16:27 -0800454 bool isHdrSnapshotRequest(camera3_capture_request *request);
Thierry Strudel3d639192016-09-09 11:52:26 -0700455 int32_t setMobicat();
456
Chien-Yu Chen8e599492016-11-01 13:37:46 -0700457 int32_t getSensorModeInfo(cam_sensor_mode_info_t &sensorModeInfo);
Chien-Yu Chen605c3872017-06-14 11:09:23 -0700458 // Get information of the sensor mode that is currently selected.
459 int32_t getCurrentSensorModeInfo(cam_sensor_mode_info_t &sensorModeInfo);
Thierry Strudel3d639192016-09-09 11:52:26 -0700460 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 Strudel04e026f2016-10-10 11:27:36 -0700464 int32_t setVideoHdrMode(metadata_buffer_t *hal_metadata,
465 cam_video_hdr_mode_t vhdr);
Thierry Strudel3d639192016-09-09 11:52:26 -0700466 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 Strudelcca4d9c2016-10-20 08:25:53 -0700471 void updateTimeStampInPendingBuffers(uint32_t frameNumber, nsecs_t timestamp);
Thierry Strudel3d639192016-09-09 11:52:26 -0700472
473 void enablePowerHint();
474 void disablePowerHint();
475 int32_t dynamicUpdateMetaStreamInfo();
476 int32_t startAllChannels();
477 int32_t stopAllChannels();
478 int32_t notifyErrorForPendingRequests();
Thierry Strudel9e74aae2016-09-22 17:10:18 -0700479 void notifyError(uint32_t frameNumber,
480 camera3_error_msg_code_t errorCode);
Thierry Strudel3d639192016-09-09 11:52:26 -0700481 int32_t getReprocessibleOutputStreamId(uint32_t &id);
Chien-Yu Chen09cb28e2017-07-21 13:15:52 -0700482 int32_t handleCameraDeviceError(bool stopChannelImmediately = false);
Thierry Strudel3d639192016-09-09 11:52:26 -0700483
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 Strudel295a0ca2016-11-03 18:38:47 -0700490 int32_t setInstantAEC(const CameraMetadata &meta);
Thierry Strudel3d639192016-09-09 11:52:26 -0700491
Thierry Strudel04e026f2016-10-10 11:27:36 -0700492 static void convertLandmarks(cam_face_landmarks_info_t face, int32_t* landmarks);
493 static void setInvalidLandmarks(int32_t* landmarks);
494
Thierry Strudel3d639192016-09-09 11:52:26 -0700495 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 Aftab58465fa2017-01-26 15:02:44 -0800498 int32_t setSensorHDR(metadata_buffer_t *hal_metadata, bool enable,
499 bool isVideoHdrEnable = false);
Thierry Strudel3d639192016-09-09 11:52:26 -0700500
Shuzhen Wanga5da1022016-07-13 20:18:42 -0700501 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 Strudel3d639192016-09-09 11:52:26 -0700506 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 Chen8e599492016-11-01 13:37:46 -0700519 QCamera3HdrPlusRawSrcChannel *mHdrPlusRawSrcChannel;
Thierry Strudel3d639192016-09-09 11:52:26 -0700520 QCamera3RegularChannel *mDummyBatchChannel;
Emilian Peev7650c122017-01-19 08:24:33 -0800521 QCamera3DepthChannel *mDepthChannel;
Emilian Peev656e4fa2017-06-02 16:47:04 +0100522 cam_sensor_pd_data_t mDepthCloudMode; //Cache last configured mode
Thierry Strudelc2ee3302016-11-17 12:33:12 -0800523 QCameraPerfLockMgr mPerfLockMgr;
Thierry Strudel3d639192016-09-09 11:52:26 -0700524
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 Strudele80ad7c2016-12-06 10:16:27 -0800535 bool mForceHdrSnapshot;
Thierry Strudel3d639192016-09-09 11:52:26 -0700536 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 Strudel2896d122017-02-23 19:18:03 -0800544 bool m_bEis3PropertyEnabled;
Thierry Strudel9e74aae2016-09-22 17:10:18 -0700545 bool m_bEisSupported;
Thierry Strudel3d639192016-09-09 11:52:26 -0700546 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 Strudele80ad7c2016-12-06 10:16:27 -0800557 uint8_t m_bSwTnrPreview;
Thierry Strudel3d639192016-09-09 11:52:26 -0700558 uint8_t m_bTnrVideo;
559 uint8_t m_debug_avtimer;
Mansoor Aftab93a66e52017-01-26 14:58:25 -0800560 uint8_t m_bVideoHdrEnabled;
Thierry Strudel54dc9782017-02-15 12:12:10 -0800561 uint8_t m_cacModeDisabled;
Shuzhen Wangb57ec912017-07-31 13:24:27 -0700562 uint8_t m_bForceInfinityAf;
Thierry Strudel3d639192016-09-09 11:52:26 -0700563
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 Strudele80ad7c2016-12-06 10:16:27 -0800572
Thierry Strudel3d639192016-09-09 11:52:26 -0700573 typedef struct {
574 uint32_t frame_number;
575 uint32_t num_buffers;
576 int32_t request_id;
577 List<RequestedBufferInfo> buffers;
Thierry Strudele80ad7c2016-12-06 10:16:27 -0800578 List<InternalRequest> internalRequestList;
Thierry Strudel3d639192016-09-09 11:52:26 -0700579 int blob_request;
Shuzhen Wang3c077d72017-04-20 22:48:59 -0700580 uint8_t bUseFirstPartial; // Use first available partial result in case of jumpstart.
Thierry Strudel3d639192016-09-09 11:52:26 -0700581 nsecs_t timestamp;
Emilian Peev30522a12017-08-03 14:36:33 +0100582 nsecs_t expectedFrameDuration;
Thierry Strudel3d639192016-09-09 11:52:26 -0700583 camera3_stream_buffer_t *input_buffer;
584 const camera_metadata_t *settings;
Chien-Yu Chene687bd02016-12-07 18:30:26 -0800585 const camera_metadata_t *resultMetadata; // Result metadata for this request.
Thierry Strudel3d639192016-09-09 11:52:26 -0700586 CameraMetadata jpegMetadata;
587 uint8_t pipeline_depth;
588 uint32_t partial_result_cnt;
589 uint8_t capture_intent;
590 uint8_t fwkCacMode;
Shuzhen Wang2abea3d2016-03-31 11:09:27 -0700591 uint8_t hybrid_ae_enable;
Samuel Ha68ba5172016-12-15 18:41:12 -0800592 /* DevCamDebug metadata PendingRequestInfo */
593 uint8_t DevCamDebug_meta_enable;
594 /* DevCamDebug metadata end */
Chien-Yu Chene687bd02016-12-07 18:30:26 -0800595
Shuzhen Wang3733cc92017-07-27 18:15:05 -0700596 bool focusStateSent = false;
597 bool focusStateValid = false;
598 uint8_t focusState = ANDROID_CONTROL_AF_STATE_INACTIVE;
Shuzhen Wang181c57b2017-07-21 11:39:44 -0700599
Chien-Yu Chen66ec22a2017-04-13 18:00:36 -0700600 bool enableZsl; // If ZSL is enabled.
Chien-Yu Chene687bd02016-12-07 18:30:26 -0800601 bool hdrplus; // If this is an HDR+ request.
Chien-Yu Chenbc730232017-07-12 14:49:55 -0700602 uint8_t requestedLensShadingMapMode; // Lens shading map mode for this request.
Thierry Strudel3d639192016-09-09 11:52:26 -0700603 } PendingRequestInfo;
604 typedef struct {
605 uint32_t frame_number;
606 uint32_t stream_ID;
607 } PendingFrameDropInfo;
608
Thierry Strudele80ad7c2016-12-06 10:16:27 -0800609 class FrameNumberRegistry _orchestrationDb;
Thierry Strudel3d639192016-09-09 11:52:26 -0700610 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 Strudel3d639192016-09-09 11:52:26 -0700616 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 Strudelc2ee3302016-11-17 12:33:12 -0800621 cam_stream_ID_t mBatchedStreamsArray;
Thierry Strudel3d639192016-09-09 11:52:26 -0700622
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 Chen3f303522017-05-19 15:21:45 -0700630 ShutterDispatcher mShutterDispatcher;
631 OutputBufferDispatcher mOutputBufferDispatcher;
632
Thierry Strudel3d639192016-09-09 11:52:26 -0700633 //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 Peev30522a12017-08-03 14:36:33 +0100644 nsecs_t mExpectedFrameDuration;
645 nsecs_t mExpectedInflightDuration;
646 static const nsecs_t kDefaultExpectedDuration = 100000000; // 100 ms
Thierry Strudel3d639192016-09-09 11:52:26 -0700647
648 uint32_t mMetaFrameCount;
649 bool mUpdateDebugLevel;
650 const camera_module_callbacks_t *mCallbacks;
651
652 uint8_t mCaptureIntent;
653 uint8_t mCacMode;
Shuzhen Wang2abea3d2016-03-31 11:09:27 -0700654 uint8_t mHybridAeEnable;
Samuel Ha68ba5172016-12-15 18:41:12 -0800655 // DevCamDebug metadata internal variable
656 uint8_t mDevCamDebugMetaEnable;
657 /* DevCamDebug metadata end */
658
Thierry Strudel3d639192016-09-09 11:52:26 -0700659 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 Strudelc2ee3302016-11-17 12:33:12 -0800666public:
Thierry Strudel2896d122017-02-23 19:18:03 -0800667 uint32_t mOpMode;
Thierry Strudel54dc9782017-02-15 12:12:10 -0800668 bool mStreamConfig;
Thierry Strudel2896d122017-02-23 19:18:03 -0800669 QCameraCommon mCommon;
Thierry Strudelc2ee3302016-11-17 12:33:12 -0800670private:
Thierry Strudel3d639192016-09-09 11:52:26 -0700671 uint32_t mFirstFrameNumberInBatch;
672 camera3_stream_t mDummyBatchStream;
673 bool mNeedSensorRestart;
Thierry Strudelc2ee3302016-11-17 12:33:12 -0800674 bool mPreviewStarted;
Thierry Strudel9e74aae2016-09-22 17:10:18 -0700675 uint32_t mMinInFlightRequests;
676 uint32_t mMaxInFlightRequests;
Emilian Peev0f3c3162017-03-15 12:57:46 +0000677 bool mPDSupported;
678 int32_t mPDIndex;
Thierry Strudel295a0ca2016-11-03 18:38:47 -0700679 // 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 Strudel3d639192016-09-09 11:52:26 -0700689 /* sensor output size with current stream configuration */
690 QCamera3CropRegionMapper mCropRegionMapper;
Chien-Yu Chenbc730232017-07-12 14:49:55 -0700691 // Last lens shading map mode framework requsted.
692 uint8_t mLastRequestedLensShadingMapMode;
Thierry Strudel3d639192016-09-09 11:52:26 -0700693
Thierry Strudel54dc9782017-02-15 12:12:10 -0800694 cam_feature_mask_t mCurrFeatureState;
Thierry Strudel3d639192016-09-09 11:52:26 -0700695 /* Ldaf calibration data */
696 bool mLdafCalibExist;
697 uint32_t mLdafCalib[2];
Thierry Strudel3d639192016-09-09 11:52:26 -0700698 int32_t mLastCustIntentFrmNum;
Thierry Strudel3d639192016-09-09 11:52:26 -0700699
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 Strudel04e026f2016-10-10 11:27:36 -0700724 static const QCameraMap<camera_metadata_enum_android_video_hdr_mode_t,
725 cam_video_hdr_mode_t> VIDEO_HDR_MODES_MAP[];
Thierry Strudel3d639192016-09-09 11:52:26 -0700726 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 Strudel04e026f2016-10-10 11:27:36 -0700730 static const QCameraMap<camera_metadata_enum_android_ir_mode_t,
731 cam_ir_mode_type_t> IR_MODES_MAP[];
Thierry Strudel295a0ca2016-11-03 18:38:47 -0700732 static const QCameraMap<qcamera3_ext_instant_aec_mode_t,
733 cam_aec_convergence_type> INSTANT_AEC_MODES_MAP[];
Thierry Strudel54dc9782017-02-15 12:12:10 -0800734 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 Strudel3d639192016-09-09 11:52:26 -0700740 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 Wang3c077d72017-04-20 22:48:59 -0700748 bool mFirstMetadataCallback;
749 void sendPartialMetadataWithLock(metadata_buffer_t *metadata,
750 const pendingRequestIterator requestIter,
Shuzhen Wang485e2442017-08-02 12:21:08 -0700751 bool lastUrgentMetadataInBatch, bool isJumpstartMetadata);
Shuzhen Wang3c077d72017-04-20 22:48:59 -0700752
Shuzhen Wang181c57b2017-07-21 11:39:44 -0700753 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 Strudel3d639192016-09-09 11:52:26 -0700760 State mState;
761 //Dual camera related params
762 bool mIsDeviceLinked;
763 bool mIsMainCamera;
764 uint8_t mLinkedCameraId;
Thierry Strudel295a0ca2016-11-03 18:38:47 -0700765 QCamera3HeapMemory *m_pDualCamCmdHeap;
766 cam_dual_camera_cmd_info_t *m_pDualCamCmdPtr;
Thierry Strudel3d639192016-09-09 11:52:26 -0700767 cam_sync_related_sensors_event_info_t m_relCamSyncInfo;
Thierry Strudele80ad7c2016-12-06 10:16:27 -0800768 Mutex mFlushLock;
Shuzhen Wangf6890e02016-08-12 14:28:54 -0700769 bool m60HzZone;
770
Chien-Yu Chen8e599492016-11-01 13:37:46 -0700771 // 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 Chene687bd02016-12-07 18:30:26 -0800776 // 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 Chen8e599492016-11-01 13:37:46 -0700793 // 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 Chen54c19cb2017-03-31 17:53:18 -0700797 // Open HDR+ client asynchronously.
798 status_t openHdrPlusClientAsyncLocked();
799
Chien-Yu Chenee335912017-02-09 17:53:20 -0800800 // 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 Chendeaebad2017-06-30 11:46:34 -0700806 // Return if current session with configured streams is compatible with HDR+ mode.
807 bool isSessionHdrPlusModeCompatible();
808
Chien-Yu Chen200b2ce2017-02-01 15:03:02 -0800809 // Configure streams for HDR+.
Chien-Yu Chenee335912017-02-09 17:53:20 -0800810 status_t configureHdrPlusStreamsLocked();
Chien-Yu Chen200b2ce2017-02-01 15:03:02 -0800811
812 // Try to submit an HDR+ request. Returning true if an HDR+ request was submitted. Returning
Chien-Yu Chen54c19cb2017-03-31 17:53:18 -0700813 // 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 Chen200b2ce2017-02-01 15:03:02 -0800816 const camera3_capture_request_t &request, const CameraMetadata &metadata);
817
Chien-Yu Chen92724a82017-01-06 11:50:30 -0800818 // 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 Chen77ccd022017-06-23 12:00:36 -0700822 // Wait until opening HDR+ client completes if it's being opened.
823 void finishHdrPlusClientOpeningLocked(std::unique_lock<std::mutex> &lock);
Chien-Yu Chen90f1fc12017-07-14 14:31:53 -0700824 // Easel manager client callbacks.
825 void onEaselFatalError(std::string errMsg);
Chien-Yu Chen77ccd022017-06-23 12:00:36 -0700826
Chien-Yu Chen8e599492016-11-01 13:37:46 -0700827 // HDR+ client callbacks.
Chien-Yu Chen54c19cb2017-03-31 17:53:18 -0700828 void onOpened(std::unique_ptr<HdrPlusClient> client) override;
829 void onOpenFailed(status_t err) override;
Chien-Yu Chen411e9c52017-05-08 11:58:50 -0700830 void onFatalError() override;
Chien-Yu Chen8e599492016-11-01 13:37:46 -0700831 void onCaptureResult(pbcamera::CaptureResult *result,
832 const camera_metadata_t &resultMetadata) override;
833 void onFailedCaptureResult(pbcamera::CaptureResult *failedResult) override;
Chien-Yu Chen29fd1d72017-04-27 18:42:09 -0700834 void onShutter(uint32_t requestId, int64_t apSensorTimestampNs) override;
Chien-Yu Chen8e599492016-11-01 13:37:46 -0700835
Emilian Peev30522a12017-08-03 14:36:33 +0100836 nsecs_t calculateMaxExpectedDuration(const camera_metadata_t *request);
837 void getExpectedFrameDuration(const camera_metadata_t *request, nsecs_t *frameDuration);
838
Chien-Yu Chene687bd02016-12-07 18:30:26 -0800839 // Map from frame number to frame. Must be protected by mHdrPlusPendingRequestsLock.
840 std::map<uint32_t, HdrPlusPendingRequest> mHdrPlusPendingRequests;
841 Mutex mHdrPlusPendingRequestsLock;
Chien-Yu Chenee335912017-02-09 17:53:20 -0800842
843 // If HDR+ mode is enabled i.e. if Easel is capturing ZSL buffers.
844 bool mHdrPlusModeEnabled;
845
Chien-Yu Chen66ec22a2017-04-13 18:00:36 -0700846 // If ZSL is enabled (android.control.enableZsl).
847 bool mZslEnabled;
848
Chien-Yu Chenee335912017-02-09 17:53:20 -0800849 // 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 Aftab58465fa2017-01-26 15:02:44 -0800858 bool m_bSensorHDREnabled;
Shuzhen Wang181c57b2017-07-21 11:39:44 -0700859
860 cam_trigger_t mAfTrigger;
Thierry Strudel3d639192016-09-09 11:52:26 -0700861};
862
863}; // namespace qcamera
864
865#endif /* __QCAMERA2HARDWAREINTERFACE_H__ */