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 __QCamera3_POSTPROC_H__ 31 #define __QCamera3_POSTPROC_H__ 32 33 // Camera dependencies 34 #include "hardware/camera3.h" 35 #include "QCamera3HALHeader.h" 36 #include "QCameraCmdThread.h" 37 #include "QCameraQueue.h" 38 #include "QCameraPerf.h" 39 40 extern "C" { 41 #include "mm_camera_interface.h" 42 #include "mm_jpeg_interface.h" 43 } 44 45 namespace qcamera { 46 47 class QCamera3Exif; 48 class QCamera3ProcessingChannel; 49 class QCamera3ReprocessChannel; 50 class QCamera3Stream; 51 class QCamera3StreamMem; 52 53 typedef struct { 54 camera3_stream_buffer_t src_frame;// source frame 55 mm_camera_buf_def_t metadata_buffer; 56 mm_camera_buf_def_t input_buffer; 57 reprocess_config_t reproc_config; 58 buffer_handle_t *output_buffer; 59 uint32_t frameNumber; 60 } qcamera_fwk_input_pp_data_t; 61 62 typedef struct { 63 uint32_t jobId; // job ID 64 uint32_t client_hdl; // handle of jpeg client (obtained when open jpeg) 65 mm_camera_super_buf_t *src_frame;// source frame (need to be returned back to kernel after done) 66 mm_camera_super_buf_t *src_reproc_frame; // original source frame for reproc if not NULL 67 qcamera_fwk_input_pp_data_t *fwk_frame; // source framework buffer 68 qcamera_fwk_input_pp_data_t *fwk_src_buffer; // original framework source frame for reproc 69 QCamera3Exif *pJpegExifObj; 70 metadata_buffer_t *metadata; 71 mm_camera_super_buf_t *src_metadata; 72 jpeg_settings_t *jpeg_settings; 73 bool hdr_plus_processing; 74 } qcamera_hal3_jpeg_data_t; 75 76 typedef struct { 77 uint32_t jobId; // job ID 78 mm_camera_super_buf_t *src_frame;// source frame (need to be returned back to kernel after done) 79 qcamera_fwk_input_pp_data_t *fwk_src_frame;// source frame 80 metadata_buffer_t *metadata; 81 jpeg_settings_t *jpeg_settings; 82 mm_camera_super_buf_t *src_metadata; 83 } qcamera_hal3_pp_data_t; 84 85 typedef struct { 86 mm_camera_super_buf_t *input; 87 buffer_handle_t *output; 88 uint32_t frameNumber; 89 } qcamera_hal3_pp_buffer_t; 90 91 #define MAX_HAL3_EXIF_TABLE_ENTRIES 23 92 class QCamera3Exif 93 { 94 public: 95 QCamera3Exif(); 96 virtual ~QCamera3Exif(); 97 98 int32_t addEntry(exif_tag_id_t tagid, 99 exif_tag_type_t type, 100 uint32_t count, 101 void *data); getNumOfEntries()102 uint32_t getNumOfEntries() {return m_nNumEntries;}; getEntries()103 QEXIF_INFO_DATA *getEntries() {return m_Entries;}; 104 105 private: 106 QEXIF_INFO_DATA m_Entries[MAX_HAL3_EXIF_TABLE_ENTRIES]; // exif tags for JPEG encoder 107 uint32_t m_nNumEntries; // number of valid entries 108 }; 109 110 class QCamera3PostProcessor 111 { 112 public: 113 QCamera3PostProcessor(QCamera3ProcessingChannel *ch_ctrl); 114 virtual ~QCamera3PostProcessor(); 115 116 int32_t init(QCamera3StreamMem *mMemory); 117 int32_t initJpeg(jpeg_encode_callback_t jpeg_cb, 118 cam_dimension_t *m_max_pic_dim, 119 void *user_data); 120 int32_t deinit(); 121 int32_t start(const reprocess_config_t &config); 122 int32_t stop(); 123 int32_t flush(); 124 int32_t processData(qcamera_fwk_input_pp_data_t *frame); 125 int32_t processData(mm_camera_super_buf_t *input, 126 buffer_handle_t *output, uint32_t frameNumber); 127 int32_t processData(mm_camera_super_buf_t *input); 128 int32_t processJpegJob(qcamera_hal3_jpeg_data_t *job); 129 int32_t processPPData(mm_camera_super_buf_t *frame); 130 int32_t processPPMetadata(mm_camera_super_buf_t *reproc_meta); 131 int32_t processJpegSettingData(jpeg_settings_t *jpeg_settings); 132 qcamera_hal3_pp_data_t *dequeuePPJob(uint32_t frameNumber); 133 qcamera_hal3_jpeg_data_t *findJpegJobByJobId(uint32_t jobId); 134 void releaseJpegJobData(qcamera_hal3_jpeg_data_t *job); 135 int32_t releaseOfflineBuffers(bool all); 136 void releasePPJobData(qcamera_hal3_pp_data_t *job); 137 138 private: 139 int32_t sendEvtNotify(int32_t msg_type, int32_t ext1, int32_t ext2); 140 mm_jpeg_color_format getColorfmtFromImgFmt(cam_format_t img_fmt); 141 mm_jpeg_format_t getJpegImgTypeFromImgFmt(cam_format_t img_fmt); 142 int32_t getJpegEncodeConfig(mm_jpeg_encode_params_t& encode_parm, 143 QCamera3Stream *main_stream, 144 jpeg_settings_t *jpeg_settings); 145 int32_t getFWKJpegEncodeConfig(mm_jpeg_encode_params_t& encode_parm, 146 qcamera_fwk_input_pp_data_t *frame, 147 jpeg_settings_t *jpeg_settings); 148 QCamera3Exif * getExifData(metadata_buffer_t *metadata, 149 jpeg_settings_t *jpeg_settings, bool needJpegExifRotation); 150 int32_t encodeData(qcamera_hal3_jpeg_data_t *jpeg_job_data, 151 uint8_t &needNewSess); 152 int32_t encodeFWKData(qcamera_hal3_jpeg_data_t *jpeg_job_data, 153 uint8_t &needNewSess); 154 void releaseSuperBuf(mm_camera_super_buf_t *super_buf); 155 static void releaseNotifyData(void *user_data, void *cookie); 156 int32_t processRawImageImpl(mm_camera_super_buf_t *recvd_frame); 157 158 static void releaseJpegData(void *data, void *user_data); 159 static void releasePPInputData(void *data, void *user_data); 160 static void releaseMetadata(void *data, void *user_data); 161 static void releaseOngoingPPData(void *data, void *user_data); 162 163 static void *dataProcessRoutine(void *data); 164 165 bool needsReprocess(qcamera_fwk_input_pp_data_t *frame); 166 167 private: 168 QCamera3ProcessingChannel *m_parent; 169 jpeg_encode_callback_t mJpegCB; 170 void * mJpegUserData; 171 mm_jpeg_ops_t mJpegHandle; 172 uint32_t mJpegClientHandle; 173 uint32_t mJpegSessionId; 174 cam_jpeg_metadata_t mJpegMetadata; 175 176 uint32_t m_bThumbnailNeeded; 177 QCamera3StreamMem *mOutputMem; 178 QCamera3ReprocessChannel * m_pReprocChannel; 179 180 QCameraQueue m_inputPPQ; // input queue for postproc 181 QCameraQueue m_inputFWKPPQ; // framework input queue for postproc 182 QCameraQueue m_ongoingPPQ; // ongoing postproc queue 183 QCameraQueue m_inputJpegQ; // input jpeg job queue 184 QCameraQueue m_ongoingJpegQ; // ongoing jpeg job queue 185 QCameraQueue m_inputRawQ; // input raw job queue 186 QCameraQueue m_inputMetaQ; // input meta queue 187 QCameraQueue m_jpegSettingsQ; // input jpeg setting queue 188 QCameraCmdThread m_dataProcTh; // thread for data processing 189 190 QCameraPerfLockMgr mPerfLockMgr; 191 pthread_mutex_t mReprocJobLock; 192 }; 193 194 }; // namespace qcamera 195 196 #endif /* __QCamera3_POSTPROC_H__ */ 197