1 /* Copyright (c) 2012-2014, The Linux Foundataion. All rights reserved. 2 * 3 * Redistribution and use in source and binary forms, with or without 4 * modification, are permitted provided that the following conditions are 5 * met: 6 * * Redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer. 8 * * Redistributions in binary form must reproduce the above 9 * copyright notice, this list of conditions and the following 10 * disclaimer in the documentation and/or other materials provided 11 * with the distribution. 12 * * Neither the name of The Linux Foundation nor the names of its 13 * contributors may be used to endorse or promote products derived 14 * from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 */ 29 30 #ifndef __QCamera3_POSTPROC_H__ 31 #define __QCamera3_POSTPROC_H__ 32 33 extern "C" { 34 #include <mm_camera_interface.h> 35 #include <mm_jpeg_interface.h> 36 } 37 #include <hardware/camera3.h> 38 //#include "QCamera3HWI.h" 39 #include "QCameraQueue.h" 40 #include "QCameraCmdThread.h" 41 #include "QCamera3HALHeader.h" 42 43 namespace qcamera { 44 45 class QCamera3Exif; 46 class QCamera3Channel; 47 class QCamera3PicChannel; 48 class QCamera3ReprocessChannel; 49 class QCamera3Stream; 50 class QCamera3Memory; 51 52 typedef struct { 53 camera3_stream_buffer_t src_frame;// source frame 54 mm_camera_buf_def_t metadata_buffer; 55 mm_camera_buf_def_t input_buffer; 56 reprocess_config_t reproc_config; 57 } qcamera_fwk_input_pp_data_t; 58 59 typedef struct { 60 uint32_t jobId; // job ID 61 uint32_t client_hdl; // handle of jpeg client (obtained when open jpeg) 62 mm_camera_super_buf_t *src_frame;// source frame (need to be returned back to kernel after done) 63 mm_camera_super_buf_t *src_reproc_frame; // original source frame for reproc if not NULL 64 qcamera_fwk_input_pp_data_t *fwk_frame; // source framework buffer 65 qcamera_fwk_input_pp_data_t *fwk_src_buffer; // original framework source frame for reproc 66 QCamera3Exif *pJpegExifObj; 67 metadata_buffer_t *metadata; 68 mm_camera_super_buf_t *src_metadata; 69 jpeg_settings_t *jpeg_settings; 70 } qcamera_hal3_jpeg_data_t; 71 72 typedef struct { 73 uint32_t jobId; // job ID 74 mm_camera_super_buf_t *src_frame;// source frame (need to be returned back to kernel after done) 75 qcamera_fwk_input_pp_data_t *fwk_src_frame;// source frame 76 metadata_buffer_t *metadata; 77 jpeg_settings_t *jpeg_settings; 78 mm_camera_super_buf_t *src_metadata; 79 } qcamera_hal3_pp_data_t; 80 81 #define MAX_HAL3_EXIF_TABLE_ENTRIES 22 82 class QCamera3Exif 83 { 84 public: 85 QCamera3Exif(); 86 virtual ~QCamera3Exif(); 87 88 int32_t addEntry(exif_tag_id_t tagid, 89 exif_tag_type_t type, 90 uint32_t count, 91 void *data); getNumOfEntries()92 uint32_t getNumOfEntries() {return m_nNumEntries;}; getEntries()93 QEXIF_INFO_DATA *getEntries() {return m_Entries;}; 94 95 private: 96 QEXIF_INFO_DATA m_Entries[MAX_HAL3_EXIF_TABLE_ENTRIES]; // exif tags for JPEG encoder 97 uint32_t m_nNumEntries; // number of valid entries 98 }; 99 100 class QCamera3PostProcessor 101 { 102 public: 103 QCamera3PostProcessor(QCamera3PicChannel *ch_ctrl); 104 virtual ~QCamera3PostProcessor(); 105 106 int32_t init(QCamera3Memory *mMemory, 107 jpeg_encode_callback_t jpeg_cb, 108 uint32_t postprocess_mask, 109 void *user_data); 110 int32_t deinit(); 111 int32_t start(const reprocess_config_t &config, 112 metadata_buffer_t *metadata); 113 int32_t stop(); 114 int32_t processData(qcamera_fwk_input_pp_data_t *frame); 115 int32_t processData(mm_camera_super_buf_t *frame); 116 int32_t processRawData(mm_camera_super_buf_t *frame); 117 int32_t processPPData(mm_camera_super_buf_t *frame); 118 int32_t processPPMetadata(mm_camera_super_buf_t *reproc_meta); 119 int32_t processJpegSettingData(jpeg_settings_t *jpeg_settings); 120 qcamera_hal3_jpeg_data_t *findJpegJobByJobId(uint32_t jobId); 121 void releaseJpegJobData(qcamera_hal3_jpeg_data_t *job); 122 int32_t releaseOfflineBuffers(); 123 124 private: 125 int32_t sendEvtNotify(int32_t msg_type, int32_t ext1, int32_t ext2); 126 mm_jpeg_color_format getColorfmtFromImgFmt(cam_format_t img_fmt); 127 mm_jpeg_format_t getJpegImgTypeFromImgFmt(cam_format_t img_fmt); 128 int32_t getJpegEncodeConfig(mm_jpeg_encode_params_t& encode_parm, 129 QCamera3Stream *main_stream, 130 jpeg_settings_t *jpeg_settings); 131 int32_t getFWKJpegEncodeConfig(mm_jpeg_encode_params_t& encode_parm, 132 qcamera_fwk_input_pp_data_t *frame, 133 jpeg_settings_t *jpeg_settings); 134 int32_t encodeData(qcamera_hal3_jpeg_data_t *jpeg_job_data, 135 uint8_t &needNewSess); 136 int32_t encodeFWKData(qcamera_hal3_jpeg_data_t *jpeg_job_data, 137 uint8_t &needNewSess); 138 void releaseSuperBuf(mm_camera_super_buf_t *super_buf); 139 static void releaseNotifyData(void *user_data, void *cookie); 140 int32_t processRawImageImpl(mm_camera_super_buf_t *recvd_frame); 141 142 static void releaseJpegData(void *data, void *user_data); 143 static void releasePPInputData(void *data, void *user_data); 144 static void releaseMetadata(void *data, void *user_data); 145 static void releaseOngoingPPData(void *data, void *user_data); 146 147 static void *dataProcessRoutine(void *data); 148 149 private: 150 QCamera3PicChannel *m_parent; 151 jpeg_encode_callback_t mJpegCB; 152 void * mJpegUserData; 153 mm_jpeg_ops_t mJpegHandle; 154 uint32_t mJpegClientHandle; 155 uint32_t mJpegSessionId; 156 uint32_t mPostProcMask; 157 158 int8_t m_bThumbnailNeeded; 159 QCamera3Memory *mJpegMem; 160 QCamera3ReprocessChannel * m_pReprocChannel; 161 162 QCameraQueue m_inputPPQ; // input queue for postproc 163 QCameraQueue m_inputFWKPPQ; // framework input queue for postproc 164 QCameraQueue m_ongoingPPQ; // ongoing postproc queue 165 QCameraQueue m_inputJpegQ; // input jpeg job queue 166 QCameraQueue m_ongoingJpegQ; // ongoing jpeg job queue 167 QCameraQueue m_inputRawQ; // input raw job queue 168 QCameraQueue m_inputMetaQ; // input meta queue 169 QCameraQueue m_jpegSettingsQ; // input jpeg setting queue 170 QCameraCmdThread m_dataProcTh; // thread for data processing 171 172 pthread_mutex_t mReprocJobLock; 173 }; 174 175 }; // namespace qcamera 176 177 #endif /* __QCamera3_POSTPROC_H__ */ 178