1 /* 2 ** Copyright (c) 2012 The Linux Foundation. All rights reserved. 3 ** 4 ** Not a Contribution, Apache license notifications and license are retained 5 ** for attribution purposes only. 6 ** 7 ** Licensed under the Apache License, Version 2.0 (the "License"); 8 ** you may not use this file except in compliance with the License. 9 ** You may obtain a copy of the License at 10 ** 11 ** http://www.apache.org/licenses/LICENSE-2.0 12 ** 13 ** Unless required by applicable law or agreed to in writing, software 14 ** distributed under the License is distributed on an "AS IS" BASIS, 15 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 ** See the License for the specific language governing permissions and 17 ** limitations under the License. 18 */ 19 20 #ifndef ANDROID_HARDWARE_QCAMERA_HARDWARE_INTERFACE_H 21 #define ANDROID_HARDWARE_QCAMERA_HARDWARE_INTERFACE_H 22 23 24 #include <utils/threads.h> 25 #include <hardware/camera.h> 26 #include <binder/MemoryBase.h> 27 #include <binder/MemoryHeapBase.h> 28 #include <utils/threads.h> 29 #include <cutils/properties.h> 30 #include <camera/Camera.h> 31 #include <camera/QCameraParameters.h> 32 #include <system/window.h> 33 #include <system/camera.h> 34 #include <hardware/camera.h> 35 #include <gralloc_priv.h> 36 #include <QComOMXMetadata.h> 37 #include <hardware/power.h> 38 39 extern "C" { 40 #include <linux/android_pmem.h> 41 #include <linux/msm_ion.h> 42 #include <camera.h> 43 #include <camera_defs_i.h> 44 #include <mm_camera_interface.h> 45 #include "mm_jpeg_interface.h" 46 } //extern C 47 48 #include "QCameraHWI_Mem.h" 49 #include "QCameraStream.h" 50 51 //Error codes 52 #define NOT_FOUND -1 53 #define MAX_ZOOM_RATIOS 62 54 55 #ifdef Q12 56 #undef Q12 57 #endif 58 59 #define Q12 4096 60 #define QCAMERA_PARM_ENABLE 1 61 #define QCAMERA_PARM_DISABLE 0 62 #define PREVIEW_TBL_MAX_SIZE 14 63 #define VIDEO_TBL_MAX_SIZE 14 64 #define THUMB_TBL_MAX_SIZE 16 65 #define HFR_TBL_MAX_SIZE 2 66 67 #define DEFAULT_STREAM_WIDTH 320 68 #define DEFAULT_STREAM_HEIGHT 240 69 #define DEFAULT_LIVESHOT_WIDTH 2592 70 #define DEFAULT_LIVESHOT_HEIGHT 1944 71 72 //for histogram stats 73 #define HISTOGRAM_STATS_SIZE 257 74 #define NUM_HISTOGRAM_BUFFERS 3 75 76 struct str_map { 77 const char *const desc; 78 int val; 79 }; 80 81 struct preview_format_info_t { 82 int Hal_format; 83 cam_format_t mm_cam_format; 84 cam_pad_format_t padding; 85 int num_planar; 86 }; 87 88 89 typedef enum { 90 CAMERA_STATE_UNINITED, 91 CAMERA_STATE_READY, 92 CAMERA_STATE_MAX 93 } HAL_camera_state_type_t; 94 95 enum { 96 BUFFER_NOT_OWNED, 97 BUFFER_UNLOCKED, 98 BUFFER_LOCKED, 99 }; 100 101 typedef enum { 102 HAL_DUMP_FRM_PREVIEW = 1, 103 HAL_DUMP_FRM_VIDEO = 1<<1, 104 HAL_DUMP_FRM_MAIN = 1<<2, 105 HAL_DUMP_FRM_THUMBNAIL = 1<<3, 106 HAL_DUMP_FRM_RDI = 1<<4, 107 108 /*8 bits mask*/ 109 HAL_DUMP_FRM_MAX = 1 << 8 110 } HAL_cam_dump_frm_type_t; 111 112 113 typedef enum { 114 HAL_CAM_MODE_ZSL = 1, 115 116 /*add new entry before and update the max entry*/ 117 HAL_CAM_MODE_MAX = HAL_CAM_MODE_ZSL << 1, 118 } qQamera_mode_t; 119 120 121 typedef enum { 122 MM_CAMERA_OK, 123 MM_CAMERA_E_GENERAL, 124 MM_CAMERA_E_NO_MEMORY, 125 MM_CAMERA_E_NOT_SUPPORTED, 126 MM_CAMERA_E_INVALID_INPUT, 127 MM_CAMERA_E_INVALID_OPERATION, /* 5 */ 128 MM_CAMERA_E_ENCODE, 129 MM_CAMERA_E_BUFFER_REG, 130 MM_CAMERA_E_PMEM_ALLOC, 131 MM_CAMERA_E_CAPTURE_FAILED, 132 MM_CAMERA_E_CAPTURE_TIMEOUT, /* 10 */ 133 }mm_camera_status_type_t; 134 135 136 137 #define HAL_DUMP_FRM_MASK_ALL ( HAL_DUMP_FRM_PREVIEW + HAL_DUMP_FRM_VIDEO + \ 138 HAL_DUMP_FRM_MAIN + HAL_DUMP_FRM_THUMBNAIL) 139 #define QCAMERA_HAL_PREVIEW_STOPPED 0 140 #define QCAMERA_HAL_PREVIEW_START 1 141 #define QCAMERA_HAL_PREVIEW_STARTED 2 142 #define QCAMERA_HAL_RECORDING_STARTED 3 143 #define QCAMERA_HAL_TAKE_PICTURE 4 144 145 typedef struct { 146 int fd; 147 int main_ion_fd; 148 ion_user_handle_t handle; 149 uint32_t size; 150 } QCameraHalMemInfo_t; 151 152 typedef struct { 153 int buffer_count; 154 buffer_handle_t *buffer_handle[MM_CAMERA_MAX_NUM_FRAMES]; 155 struct private_handle_t *private_buffer_handle[MM_CAMERA_MAX_NUM_FRAMES]; 156 int stride[MM_CAMERA_MAX_NUM_FRAMES]; 157 uint32_t addr_offset[MM_CAMERA_MAX_NUM_FRAMES]; 158 uint8_t local_flag[MM_CAMERA_MAX_NUM_FRAMES]; 159 camera_memory_t *camera_memory[MM_CAMERA_MAX_NUM_FRAMES]; 160 QCameraHalMemInfo_t mem_info[MM_CAMERA_MAX_NUM_FRAMES]; 161 } QCameraHalMemory_t; 162 163 164 typedef struct { 165 int buffer_count; 166 int local_flag[MM_CAMERA_MAX_NUM_FRAMES]; 167 camera_memory_t * camera_memory[MM_CAMERA_MAX_NUM_FRAMES]; 168 camera_memory_t * metadata_memory[MM_CAMERA_MAX_NUM_FRAMES]; 169 QCameraHalMemInfo_t mem_info[MM_CAMERA_MAX_NUM_FRAMES]; 170 } QCameraHalHeap_t; 171 172 typedef struct { 173 camera_memory_t * camera_memory[NUM_HISTOGRAM_BUFFERS]; 174 QCameraHalMemInfo_t mem_info[NUM_HISTOGRAM_BUFFERS]; 175 int active; 176 } QCameraStatHeap_t; 177 178 typedef struct { 179 int32_t msg_type; 180 int32_t ext1; 181 int32_t ext2; 182 void *cookie; 183 } argm_notify_t; 184 185 typedef struct { 186 int32_t msg_type; 187 camera_memory_t *data; 188 unsigned int index; 189 camera_frame_metadata_t *metadata; 190 void *cookie; 191 void *user_data; 192 } argm_data_cb_t; 193 194 typedef struct { 195 camera_notify_callback notifyCb; 196 camera_data_callback dataCb; 197 argm_notify_t argm_notify; 198 argm_data_cb_t argm_data_cb; 199 } app_notify_cb_t; 200 201 /* camera_area_t 202 * rectangle with weight to store the focus and metering areas. 203 * x1, y1, x2, y2: from -1000 to 1000 204 * weight: 0 to 1000 205 */ 206 typedef struct { 207 int x1, y1, x2, y2; 208 int weight; 209 } camera_area_t; 210 211 //EXIF globals 212 static const char ExifAsciiPrefix[] = { 0x41, 0x53, 0x43, 0x49, 0x49, 0x0, 0x0, 0x0 }; // "ASCII\0\0\0" 213 static const char ExifUndefinedPrefix[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; // "\0\0\0\0\0\0\0\0" 214 215 //EXIF detfines 216 #define MAX_EXIF_TABLE_ENTRIES 14 217 #define GPS_PROCESSING_METHOD_SIZE 101 218 #define FOCAL_LENGTH_DECIMAL_PRECISION 100 219 #define EXIF_ASCII_PREFIX_SIZE 8 //(sizeof(ExifAsciiPrefix)) 220 221 typedef struct{ 222 //GPS tags 223 rat_t latitude[3]; 224 rat_t longitude[3]; 225 char lonRef[2]; 226 char latRef[2]; 227 rat_t altitude; 228 rat_t gpsTimeStamp[3]; 229 char gpsDateStamp[20]; 230 char gpsProcessingMethod[EXIF_ASCII_PREFIX_SIZE+GPS_PROCESSING_METHOD_SIZE]; 231 //Other tags 232 char dateTime[20]; 233 rat_t focalLength; 234 uint16_t flashMode; 235 uint16_t isoSpeed; 236 237 bool mAltitude; 238 bool mLongitude; 239 bool mLatitude; 240 bool mTimeStamp; 241 bool mGpsProcess; 242 243 int mAltitude_ref; 244 long mGPSTimestamp; 245 246 } exif_values_t; 247 248 typedef struct { 249 jpeg_job_status_t status; 250 uint8_t thumbnailDroppedFlag; 251 uint32_t client_hdl; 252 uint32_t jobId; 253 uint8_t* out_data; 254 uint32_t data_size; 255 mm_camera_super_buf_t* src_frame; 256 } camera_jpeg_data_t; 257 258 typedef struct { 259 mm_camera_super_buf_t* src_frame; 260 void* userdata; 261 } camera_jpeg_encode_cookie_t; 262 263 namespace android { 264 265 class QCameraStream; 266 267 typedef void (*release_data_fn)(void* data, void *user_data); 268 269 class QCameraQueue { 270 public: 271 QCameraQueue(); 272 QCameraQueue(release_data_fn data_rel_fn, void *user_data); 273 virtual ~QCameraQueue(); 274 bool enqueue(void *data); 275 bool pri_enqueue(void *data); 276 void flush(); 277 void* dequeue(); 278 bool is_empty(); 279 private: 280 typedef struct { 281 struct cam_list list; 282 void* data; 283 } camera_q_node; 284 285 camera_q_node mhead; /* dummy head */ 286 uint32_t msize; 287 pthread_mutex_t mlock; 288 release_data_fn mdata_rel_fn; 289 void * muser_data; 290 }; 291 292 typedef enum 293 { 294 CAMERA_CMD_TYPE_NONE, 295 CAMERA_CMD_TYPE_START_DATA_PROC, 296 CAMERA_CMD_TYPE_STOP_DATA_PROC, 297 CAMERA_CMD_TYPE_DO_NEXT_JOB, 298 CAMERA_CMD_TYPE_EXIT, 299 CAMERA_CMD_TYPE_MAX 300 } camera_cmd_type_t; 301 302 typedef struct snap_hdr_record_t_ { 303 bool hdr_on; 304 int num_frame; 305 int num_raw_received; 306 /*in terms of 2^*(n/6), e.g 6 means (1/2)x, whole 12 means 4x*/ 307 int exp[MAX_HDR_EXP_FRAME_NUM]; 308 mm_camera_super_buf_t *recvd_frame[MAX_HDR_EXP_FRAME_NUM]; 309 } snap_hdr_record_t; 310 311 typedef struct { 312 camera_cmd_type_t cmd; 313 } camera_cmd_t; 314 315 class QCameraCmdThread { 316 public: 317 QCameraCmdThread(); 318 ~QCameraCmdThread(); 319 320 int32_t launch(void *(*start_routine)(void *), void* user_data); 321 int32_t exit(); 322 int32_t sendCmd(camera_cmd_type_t cmd, uint8_t sync_cmd, uint8_t priority); 323 camera_cmd_type_t getCmd(); 324 325 QCameraQueue cmd_queue; /* cmd queue */ 326 pthread_t cmd_pid; /* cmd thread ID */ 327 sem_t cmd_sem; /* semaphore for cmd thread */ 328 sem_t sync_sem; /* semaphore for synchronized call signal */ 329 }; 330 331 class QCameraHardwareInterface : public virtual RefBase { 332 public: 333 334 QCameraHardwareInterface(int cameraId, int mode); 335 336 /** Set the ANativeWindow to which preview frames are sent */ 337 int setPreviewWindow(preview_stream_ops_t* window); 338 339 /** Set the notification and data callbacks */ 340 void setCallbacks(camera_notify_callback notify_cb, 341 camera_data_callback data_cb, 342 camera_data_timestamp_callback data_cb_timestamp, 343 camera_request_memory get_memory, 344 void *user); 345 346 /** 347 * The following three functions all take a msg_type, which is a bitmask of 348 * the messages defined in include/ui/Camera.h 349 */ 350 351 /** 352 * Enable a message, or set of messages. 353 */ 354 void enableMsgType(int32_t msg_type); 355 356 /** 357 * Disable a message, or a set of messages. 358 * 359 * Once received a call to disableMsgType(CAMERA_MSG_VIDEO_FRAME), camera 360 * HAL should not rely on its client to call releaseRecordingFrame() to 361 * release video recording frames sent out by the cameral HAL before and 362 * after the disableMsgType(CAMERA_MSG_VIDEO_FRAME) call. Camera HAL 363 * clients must not modify/access any video recording frame after calling 364 * disableMsgType(CAMERA_MSG_VIDEO_FRAME). 365 */ 366 void disableMsgType(int32_t msg_type); 367 368 /** 369 * Query whether a message, or a set of messages, is enabled. Note that 370 * this is operates as an AND, if any of the messages queried are off, this 371 * will return false. 372 */ 373 int msgTypeEnabled(int32_t msg_type); 374 375 /** 376 * Start preview mode. 377 */ 378 int startPreview(); 379 int startPreview2(); 380 381 /** 382 * Stop a previously started preview. 383 */ 384 void stopPreview(); 385 386 /** 387 * Returns true if preview is enabled. 388 */ 389 int previewEnabled(); 390 391 392 /** 393 * Request the camera HAL to store meta data or real YUV data in the video 394 * buffers sent out via CAMERA_MSG_VIDEO_FRAME for a recording session. If 395 * it is not called, the default camera HAL behavior is to store real YUV 396 * data in the video buffers. 397 * 398 * This method should be called before startRecording() in order to be 399 * effective. 400 * 401 * If meta data is stored in the video buffers, it is up to the receiver of 402 * the video buffers to interpret the contents and to find the actual frame 403 * data with the help of the meta data in the buffer. How this is done is 404 * outside of the scope of this method. 405 * 406 * Some camera HALs may not support storing meta data in the video buffers, 407 * but all camera HALs should support storing real YUV data in the video 408 * buffers. If the camera HAL does not support storing the meta data in the 409 * video buffers when it is requested to do do, INVALID_OPERATION must be 410 * returned. It is very useful for the camera HAL to pass meta data rather 411 * than the actual frame data directly to the video encoder, since the 412 * amount of the uncompressed frame data can be very large if video size is 413 * large. 414 * 415 * @param enable if true to instruct the camera HAL to store 416 * meta data in the video buffers; false to instruct 417 * the camera HAL to store real YUV data in the video 418 * buffers. 419 * 420 * @return OK on success. 421 */ 422 int storeMetaDataInBuffers(int enable); 423 424 /** 425 * Start record mode. When a record image is available, a 426 * CAMERA_MSG_VIDEO_FRAME message is sent with the corresponding 427 * frame. Every record frame must be released by a camera HAL client via 428 * releaseRecordingFrame() before the client calls 429 * disableMsgType(CAMERA_MSG_VIDEO_FRAME). After the client calls 430 * disableMsgType(CAMERA_MSG_VIDEO_FRAME), it is the camera HAL's 431 * responsibility to manage the life-cycle of the video recording frames, 432 * and the client must not modify/access any video recording frames. 433 */ 434 int startRecording(); 435 436 /** 437 * Stop a previously started recording. 438 */ 439 void stopRecording(); 440 441 /** 442 * Returns true if recording is enabled. 443 */ 444 int recordingEnabled(); 445 446 /** 447 * Release a record frame previously returned by CAMERA_MSG_VIDEO_FRAME. 448 * 449 * It is camera HAL client's responsibility to release video recording 450 * frames sent out by the camera HAL before the camera HAL receives a call 451 * to disableMsgType(CAMERA_MSG_VIDEO_FRAME). After it receives the call to 452 * disableMsgType(CAMERA_MSG_VIDEO_FRAME), it is the camera HAL's 453 * responsibility to manage the life-cycle of the video recording frames. 454 */ 455 void releaseRecordingFrame(const void *opaque); 456 457 /** 458 * Start auto focus, the notification callback routine is called with 459 * CAMERA_MSG_FOCUS once when focusing is complete. autoFocus() will be 460 * called again if another auto focus is needed. 461 */ 462 int autoFocus(); 463 464 /** 465 * Cancels auto-focus function. If the auto-focus is still in progress, 466 * this function will cancel it. Whether the auto-focus is in progress or 467 * not, this function will return the focus position to the default. If 468 * the camera does not support auto-focus, this is a no-op. 469 */ 470 int cancelAutoFocus(); 471 472 /** 473 * Take a picture. 474 */ 475 int takePicture(); 476 477 /** 478 * Cancel a picture that was started with takePicture. Calling this method 479 * when no picture is being taken is a no-op. 480 */ 481 int cancelPicture(); 482 483 /** 484 * Set the camera parameters. This returns BAD_VALUE if any parameter is 485 * invalid or not supported. 486 */ 487 int setParameters(const char *parms); 488 489 //status_t setParameters(const QCameraParameters& params); 490 /** Retrieve the camera parameters. The buffer returned by the camera HAL 491 must be returned back to it with put_parameters, if put_parameters 492 is not NULL. 493 */ 494 int getParameters(char **parms); 495 496 /** The camera HAL uses its own memory to pass us the parameters when we 497 call get_parameters. Use this function to return the memory back to 498 the camera HAL, if put_parameters is not NULL. If put_parameters 499 is NULL, then you have to use free() to release the memory. 500 */ 501 void putParameters(char *); 502 503 /** 504 * Send command to camera driver. 505 */ 506 int sendCommand(int32_t cmd, int32_t arg1, int32_t arg2); 507 508 /** 509 * Release the hardware resources owned by this object. Note that this is 510 * *not* done in the destructor. 511 */ 512 void release(); 513 514 /** 515 * Dump state of the camera hardware 516 */ 517 int dump(int fd); 518 void getPictureSize(int *picture_width, int *picture_height) const; 519 void getPreviewSize(int *preview_width, int *preview_height) const; 520 void getVideoSize(int *video_width,int *video_height) const; 521 void getThumbnailSize(int *thumb_width, int *thumb_height) const; 522 cam_format_t getPreviewFormat() const; 523 cam_pad_format_t getPreviewPadding() const; 524 void processEvent(mm_camera_event_t *); 525 int getJpegQuality() const; 526 int getNumOfSnapshots(void) const; 527 int getNumOfSnapshots(const QCameraParameters& params); 528 int getThumbSizesFromAspectRatio(uint32_t aspect_ratio, 529 int *picture_width, 530 int *picture_height); 531 bool isRawSnapshot(); 532 bool mShutterSoundPlayed; 533 void dumpFrameToFile(mm_camera_buf_def_t*, HAL_cam_dump_frm_type_t); 534 535 static QCameraHardwareInterface *createInstance(int, int); 536 status_t setZSLBurstLookBack(const QCameraParameters& params); 537 status_t setZSLBurstInterval(const QCameraParameters& params); 538 int getZSLBurstInterval(void); 539 int getZSLQueueDepth(void) const; 540 int getZSLBackLookCount(void) const; 541 542 ~QCameraHardwareInterface(); 543 int initHeapMem(QCameraHalHeap_t *heap, 544 int num_of_buf, 545 uint32_t buf_len, 546 int pmem_type, 547 mm_camera_frame_len_offset* offset, 548 mm_camera_buf_def_t *buf_def); 549 int releaseHeapMem( QCameraHalHeap_t *heap); 550 int allocate_ion_memory(QCameraHalMemInfo_t * mem_info, int ion_type); 551 int deallocate_ion_memory(QCameraHalMemInfo_t *mem_info); 552 553 int cache_ops(QCameraHalMemInfo_t *mem_info, 554 void *buf_ptr, 555 unsigned int cmd); 556 557 void dumpFrameToFile(const void * data, uint32_t size, char* name, 558 char* ext, int index); 559 preview_format_info_t getPreviewFormatInfo( ); 560 bool isCameraReady(); 561 bool isNoDisplayMode(); 562 563 int getBuf(uint32_t camera_handle, 564 uint32_t ch_id, uint32_t stream_id, 565 void *user_data, 566 mm_camera_frame_len_offset *frame_offset_info, 567 uint8_t num_bufs, 568 uint8_t *initial_reg_flag, 569 mm_camera_buf_def_t *bufs); 570 int putBuf(uint32_t camera_handle, 571 uint32_t ch_id, uint32_t stream_id, 572 void *user_data, uint8_t num_bufs, 573 mm_camera_buf_def_t *bufs); 574 575 mm_camera_vtbl_t *mCameraHandle; 576 uint32_t mChannelId; 577 578 private: 579 int16_t zoomRatios[MAX_ZOOM_RATIOS]; 580 struct camera_size_type default_preview_sizes[PREVIEW_TBL_MAX_SIZE]; 581 struct camera_size_type default_video_sizes[VIDEO_TBL_MAX_SIZE]; 582 struct camera_size_type default_hfr_sizes[HFR_TBL_MAX_SIZE]; 583 struct camera_size_type default_thumbnail_sizes[THUMB_TBL_MAX_SIZE]; 584 unsigned int preview_sizes_count; 585 unsigned int video_sizes_count; 586 unsigned int thumbnail_sizes_count; 587 unsigned int hfr_sizes_count; 588 589 590 bool mUseOverlay; 591 592 void loadTables(); 593 void initDefaultParameters(); 594 bool getMaxPictureDimension(mm_camera_dimension_t *dim); 595 596 status_t updateFocusDistances(); 597 598 bool native_set_parms(mm_camera_parm_type_t type, uint16_t length, void *value); 599 bool native_set_parms( mm_camera_parm_type_t type, uint16_t length, void *value, int *result); 600 601 void hasAutoFocusSupport(); 602 void debugShowPreviewFPS() const; 603 //void prepareSnapshotAndWait(); 604 605 bool isPreviewRunning(); 606 bool isRecordingRunning(); 607 bool isSnapshotRunning(); 608 609 void processChannelEvent(mm_camera_ch_event_t *, app_notify_cb_t *); 610 void processRdiChannelEvent(mm_camera_ch_event_type_t channelEvent, app_notify_cb_t *); 611 void processPreviewChannelEvent(mm_camera_ch_event_type_t channelEvent, app_notify_cb_t *); 612 void processRecordChannelEvent(mm_camera_ch_event_type_t channelEvent, app_notify_cb_t *); 613 void processSnapshotChannelEvent(mm_camera_ch_event_type_t channelEvent, app_notify_cb_t *); 614 void processCtrlEvent(mm_camera_ctrl_event_t *, app_notify_cb_t *); 615 void processStatsEvent(mm_camera_stats_event_t *, app_notify_cb_t *); 616 void processInfoEvent(mm_camera_info_event_t *event, app_notify_cb_t *); 617 void processprepareSnapshotEvent(cam_ctrl_status_t *); 618 void roiEvent(fd_roi_t roi, app_notify_cb_t *); 619 void zoomEvent(cam_ctrl_status_t *status, app_notify_cb_t *); 620 void autofocusevent(cam_ctrl_status_t *status, app_notify_cb_t *); 621 void handleZoomEventForPreview(app_notify_cb_t *); 622 void handleZoomEventForSnapshot(void); 623 status_t autoFocusEvent(cam_ctrl_status_t *, app_notify_cb_t *); 624 625 void filterPictureSizes(); 626 bool supportsSceneDetection(); 627 bool supportsSelectableZoneAf(); 628 bool supportsFaceDetection(); 629 bool supportsRedEyeReduction(); 630 631 void stopPreviewInternal(); 632 void stopRecordingInternal(); 633 status_t cancelPictureInternal(); 634 void pausePreviewForSnapshot(); 635 void restartPreview(); 636 637 status_t runFaceDetection(); 638 639 status_t setParameters(const QCameraParameters& params); 640 QCameraParameters& getParameters() ; 641 642 status_t setCameraMode(const QCameraParameters& params); 643 status_t setPictureSizeTable(void); 644 status_t setPreviewSizeTable(void); 645 status_t setVideoSizeTable(void); 646 status_t setPreviewSize(const QCameraParameters& params); 647 status_t setJpegThumbnailSize(const QCameraParameters& params); 648 status_t setPreviewFpsRange(const QCameraParameters& params); 649 status_t setPreviewFrameRate(const QCameraParameters& params); 650 status_t setPreviewFrameRateMode(const QCameraParameters& params); 651 status_t setVideoSize(const QCameraParameters& params); 652 status_t setPictureSize(const QCameraParameters& params); 653 status_t setJpegQuality(const QCameraParameters& params); 654 status_t setNumOfSnapshot(const QCameraParameters& params); 655 status_t setJpegRotation(int isZSL); 656 int getJpegRotation(void); 657 int getISOSpeedValue(); 658 int getAutoFlickerMode(); 659 status_t setAntibanding(const QCameraParameters& params); 660 status_t setEffect(const QCameraParameters& params); 661 status_t setExposureCompensation(const QCameraParameters ¶ms); 662 status_t setAutoExposure(const QCameraParameters& params); 663 status_t setWhiteBalance(const QCameraParameters& params); 664 status_t setFlash(const QCameraParameters& params); 665 status_t setGpsLocation(const QCameraParameters& params); 666 status_t setRotation(const QCameraParameters& params); 667 status_t setZoom(const QCameraParameters& params); 668 status_t setFocusMode(const QCameraParameters& params); 669 status_t setBrightness(const QCameraParameters& params); 670 status_t setSkinToneEnhancement(const QCameraParameters& params); 671 status_t setOrientation(const QCameraParameters& params); 672 status_t setLensshadeValue(const QCameraParameters& params); 673 status_t setMCEValue(const QCameraParameters& params); 674 status_t setISOValue(const QCameraParameters& params); 675 status_t setPictureFormat(const QCameraParameters& params); 676 status_t setSharpness(const QCameraParameters& params); 677 status_t setContrast(const QCameraParameters& params); 678 status_t setSaturation(const QCameraParameters& params); 679 status_t setWaveletDenoise(const QCameraParameters& params); 680 status_t setSceneMode(const QCameraParameters& params); 681 status_t setContinuousAf(const QCameraParameters& params); 682 status_t setFaceDetection(const char *str); 683 status_t setSceneDetect(const QCameraParameters& params); 684 status_t setStrTextures(const QCameraParameters& params); 685 status_t setPreviewFormat(const QCameraParameters& params); 686 status_t setSelectableZoneAf(const QCameraParameters& params); 687 status_t setOverlayFormats(const QCameraParameters& params); 688 status_t setHighFrameRate(const QCameraParameters& params); 689 status_t setRedeyeReduction(const QCameraParameters& params); 690 status_t setAEBracket(const QCameraParameters& params); 691 status_t setFaceDetect(const QCameraParameters& params); 692 status_t setDenoise(const QCameraParameters& params); 693 status_t setAecAwbLock(const QCameraParameters & params); 694 status_t setHistogram(int histogram_en); 695 status_t setRecordingHint(const QCameraParameters& params); 696 status_t setRecordingHintValue(const int32_t value); 697 status_t setFocusAreas(const QCameraParameters& params); 698 status_t setMeteringAreas(const QCameraParameters& params); 699 status_t setFullLiveshot(void); 700 status_t setDISMode(void); 701 status_t setCaptureBurstExp(void); 702 status_t setPowerMode(const QCameraParameters& params); 703 void takePicturePrepareHardware( ); 704 status_t setNoDisplayMode(const QCameraParameters& params); 705 status_t setDimension(); 706 status_t setRDIMode(const QCameraParameters& params); 707 status_t setMobiCat(const QCameraParameters& params); 708 709 isp3a_af_mode_t getAutoFocusMode(const QCameraParameters& params); 710 bool isValidDimension(int w, int h); 711 712 String8 create_values_str(const str_map *values, int len); 713 714 void setMyMode(int mode); 715 bool isZSLMode(); 716 bool isWDenoiseEnabled(); 717 void wdenoiseEvent(cam_ctrl_status_t status, void *cookie); 718 bool isLowPowerCamcorder(); 719 void freePictureTable(void); 720 void freeVideoSizeTable(void); 721 722 int32_t createPreview(); 723 int32_t createRecord(); 724 int32_t createSnapshot(); 725 int32_t createRdi(); 726 727 int getHDRMode(); 728 //EXIF 729 void addExifTag(exif_tag_id_t tagid, exif_tag_type_t type, 730 uint32_t count, uint8_t copy, void *data); 731 void setExifTags(); 732 void initExifData(); 733 void deinitExifData(); 734 void setExifTagsGPS(); 735 exif_tags_info_t* getExifData(){ return mExifData; } 736 int getExifTableNumEntries() { return mExifTableNumEntries; } 737 void parseGPSCoordinate(const char *latlonString, rat_t* coord); 738 //added to support hdr 739 bool getHdrInfoAndSetExp(int max_num_frm, int *num_frame, int *exp); 740 status_t initHistogramBuffers(); 741 status_t deInitHistogramBuffers(); 742 mm_jpeg_color_format getColorfmtFromImgFmt(uint32_t img_fmt); 743 744 void notifyHdrEvent(cam_ctrl_status_t status, void * cookie); 745 void initHdrInfoForSnapshot(bool Hdr_on, int number_frames, int *exp ); 746 void doHdrProcessing(); 747 748 int mCameraId; 749 camera_mode_t myMode; 750 751 mm_camear_mem_vtbl_t mem_hooks; 752 753 QCameraParameters mParameters; 754 int32_t mMsgEnabled; 755 756 camera_notify_callback mNotifyCb; 757 camera_data_callback mDataCb; 758 camera_data_timestamp_callback mDataCbTimestamp; 759 camera_request_memory mGetMemory; 760 void *mCallbackCookie; 761 762 mutable Mutex mLock; 763 Mutex mPreviewMemoryLock; 764 Mutex mAutofocusLock; 765 Mutex mRecordFrameLock; 766 Condition mRecordWait; 767 pthread_mutex_t mAsyncCmdMutex; 768 pthread_cond_t mAsyncCmdWait; 769 770 QCameraStream * mStreams[MM_CAMERA_IMG_MODE_MAX]; 771 cam_ctrl_dimension_t mDimension; 772 int mPreviewWidth, mPreviewHeight; 773 int mPictureWidth, mPictureHeight; 774 int videoWidth, videoHeight; 775 int thumbnailWidth, thumbnailHeight; 776 int maxSnapshotWidth, maxSnapshotHeight; 777 int mRdiWidth,mRdiHeight; 778 int mPreviewFormat; 779 int mFps; 780 int mDebugFps; 781 int mBrightness; 782 int mContrast; 783 int mBestShotMode; 784 int mEffects; 785 int mColorEffects; 786 int mSkinToneEnhancement; 787 int mDenoiseValue; 788 int mHJR; 789 int mRotation; 790 int mJpegQuality; 791 int mThumbnailQuality; 792 int mTargetSmoothZoom; 793 int mSmoothZoomStep; 794 int mMaxZoom; 795 int mCurrentZoom; 796 int mSupportedPictureSizesCount; 797 int mFaceDetectOn; 798 int mDumpFrmCnt; 799 int mDumpSkipCnt; 800 int mFocusMode; 801 int rdiMode; 802 803 unsigned int mPictureSizeCount; 804 unsigned int mPreviewSizeCount; 805 int mPowerMode; 806 unsigned int mVideoSizeCount; 807 808 bool mAutoFocusRunning; 809 bool mNeedToUnlockCaf; 810 bool mMultiTouch; 811 bool mHasAutoFocusSupport; 812 bool mInitialized; 813 bool mDisEnabled; 814 bool strTexturesOn; 815 bool mIs3DModeOn; 816 bool mSmoothZoomRunning; 817 bool mPreparingSnapshot; 818 bool mParamStringInitialized; 819 bool mZoomSupported; 820 bool mSendMetaData; 821 bool mFullLiveshotEnabled; 822 bool mRecordingHint; 823 bool mStartRecording; 824 bool mReleasedRecordingFrame; 825 int mHdrMode; 826 int mSnapshotFormat; 827 int mZslInterval; 828 bool mRestartPreview; 829 bool mMobiCatEnabled; 830 /*for histogram*/ 831 int mStatsOn; 832 int mCurrentHisto; 833 bool mSendData; 834 sp<AshmemPool> mStatHeap; 835 camera_memory_t *mStatsMapped[3]; 836 QCameraStatHeap_t mHistServer; 837 int32_t mStatSize; 838 839 bool mZslLookBackMode; 840 int mZslLookBackValue; 841 int mHFRLevel; 842 bool mZslEmptyQueueFlag; 843 String8 mEffectValues; 844 String8 mIsoValues; 845 String8 mSceneModeValues; 846 String8 mSceneDetectValues; 847 String8 mFocusModeValues; 848 String8 mSelectableZoneAfValues; 849 String8 mAutoExposureValues; 850 String8 mWhitebalanceValues; 851 String8 mAntibandingValues; 852 String8 mFrameRateModeValues; 853 String8 mTouchAfAecValues; 854 String8 mPreviewSizeValues; 855 String8 mPictureSizeValues; 856 String8 mVideoSizeValues; 857 String8 mFlashValues; 858 String8 mLensShadeValues; 859 String8 mMceValues; 860 String8 mHistogramValues; 861 String8 mSkinToneEnhancementValues; 862 String8 mPictureFormatValues; 863 String8 mDenoiseValues; 864 String8 mZoomRatioValues; 865 String8 mPreviewFrameRateValues; 866 String8 mPreviewFormatValues; 867 String8 mFaceDetectionValues; 868 String8 mHfrValues; 869 String8 mHfrSizeValues; 870 String8 mRedeyeReductionValues; 871 String8 denoise_value; 872 String8 mFpsRangesSupportedValues; 873 String8 mZslValues; 874 String8 mFocusDistance; 875 876 friend class QCameraStream; 877 friend class QCameraStream_record; 878 friend class QCameraStream_preview; 879 friend class QCameraStream_SnapshotMain; 880 friend class QCameraStream_SnapshotThumbnail; 881 friend class QCameraStream_Rdi; 882 883 android :: FPSRange* mSupportedFpsRanges; 884 int mSupportedFpsRangesCount; 885 886 camera_size_type* mPictureSizes; 887 camera_size_type* mPreviewSizes; 888 camera_size_type* mVideoSizes; 889 const camera_size_type * mPictureSizesPtr; 890 HAL_camera_state_type_t mCameraState; 891 892 int mStoreMetaDataInFrame; 893 preview_stream_ops_t *mPreviewWindow; 894 Mutex mStateLock; 895 int mPreviewState; 896 /*preview memory with display case: memory is allocated and freed via 897 gralloc */ 898 QCameraHalMemory_t mPreviewMemory; 899 900 /*preview memory without display case: memory is allocated 901 directly by camera */ 902 QCameraHalHeap_t mNoDispPreviewMemory; 903 QCameraHalHeap_t mRdiMemory; 904 QCameraHalHeap_t mSnapshotMemory; 905 QCameraHalHeap_t mThumbnailMemory; 906 QCameraHalHeap_t mRecordingMemory; 907 QCameraHalHeap_t mJpegMemory; 908 QCameraHalHeap_t mRawMemory; 909 camera_frame_metadata_t mMetadata; 910 camera_face_t mFace[MAX_ROI]; 911 preview_format_info_t mPreviewFormatInfo; 912 friend void stream_cb_routine(mm_camera_super_buf_t *bufs, void *userdata); 913 //EXIF 914 exif_tags_info_t mExifData[MAX_EXIF_TABLE_ENTRIES]; //Exif tags for JPEG encoder 915 exif_values_t mExifValues; //Exif values in usable format 916 int mExifTableNumEntries; //NUmber of entries in mExifData 917 int mNoDisplayMode; 918 QCameraQueue mSuperBufQueue; /* queue for raw super buf */ 919 QCameraQueue mNotifyDataQueue; /* queue for data notify */ 920 QCameraCmdThread *mNotifyTh; /* thread for data notify */ 921 QCameraCmdThread *mDataProcTh; /* thread for data process (jpeg encoding) */ 922 mm_jpeg_ops_t mJpegHandle; 923 uint32_t mJpegClientHandle; 924 snap_hdr_record_t mHdrInfo; 925 power_module_t* mPowerModule; 926 cam_sensor_fps_range_t mSensorFpsRange; 927 928 static void *dataNotifyRoutine(void *data); 929 static void *dataProcessRoutine(void *data); 930 static void snapshot_jpeg_cb(jpeg_job_status_t status, 931 uint8_t thumbnailDroppedFlag, 932 uint32_t client_hdl, 933 uint32_t jobId, 934 uint8_t* out_data, 935 uint32_t data_size, 936 void *userdata); 937 static void receiveCompleteJpegPicture(jpeg_job_status_t status, 938 uint8_t thumbnailDroppedFlag, 939 uint32_t client_hdl, 940 uint32_t jobId, 941 uint8_t* out_data, 942 uint32_t data_size, 943 QCameraHardwareInterface* pme); 944 static void superbuf_cb_routine(mm_camera_super_buf_t *recvd_frame, 945 void *userdata); 946 static void receiveRawPicture(mm_camera_super_buf_t* recvd_frame, 947 QCameraHardwareInterface *pme); 948 status_t encodeData(mm_camera_super_buf_t* recvd_frame, 949 uint32_t *jobId); 950 void notifyShutter(bool play_shutter_sound); 951 status_t sendDataNotify(int32_t msg_type, 952 camera_memory_t *data, 953 uint8_t index, 954 camera_frame_metadata_t *metadata, 955 QCameraHalHeap_t *heap); 956 957 void releaseSuperBuf(mm_camera_super_buf_t *super_buf); 958 void releaseAppCBData(app_notify_cb_t *app_cb); 959 static void releaseNofityData(void *data, void *user_data); 960 static void releaseProcData(void *data, void *user_data); 961 uint8_t canTakeFullSizeLiveshot(); 962 }; 963 964 }; // namespace android 965 966 #endif 967