• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 __QCAMERA_POSTPROC_H__
31 #define __QCAMERA_POSTPROC_H__
32 
33 // Camera dependencies
34 #include "QCamera2HWI.h"
35 
36 extern "C" {
37 #include "mm_camera_interface.h"
38 #include "mm_jpeg_interface.h"
39 }
40 
41 #define MAX_JPEG_BURST 2
42 #define CAM_PP_CHANNEL_MAX 8
43 
44 namespace qcamera {
45 
46 class QCameraExif;
47 class QCamera2HardwareInterface;
48 
49 typedef struct {
50     uint32_t jobId;                  // job ID
51     uint32_t client_hdl;             // handle of jpeg client (obtained when open jpeg)
52     mm_camera_super_buf_t *src_frame;// source frame (need to be returned back to kernel
53                                      //after done)
54     mm_camera_super_buf_t *src_reproc_frame; // original source
55                                              //frame for reproc if not NULL
56     metadata_buffer_t *metadata;     // source frame metadata
57     bool reproc_frame_release;       // false release original buffer, true don't release it
58     mm_camera_buf_def_t *src_reproc_bufs;
59     QCameraExif *pJpegExifObj;
60     uint8_t offline_buffer;
61     mm_camera_buf_def_t *offline_reproc_buf; //HAL processed buffer
62 } qcamera_jpeg_data_t;
63 
64 
65 typedef struct {
66     int8_t reprocCount;
67     mm_camera_super_buf_t *src_frame;    // source frame that needs post process
68     mm_camera_super_buf_t *src_reproc_frame;// source frame (need to be
69                                             //returned back to kernel after done)
70 }qcamera_pp_request_t;
71 
72 typedef struct {
73     uint32_t jobId;                  // job ID
74     int8_t reprocCount;              //Current pass count
75     int8_t ppChannelIndex;           //Reprocess channel object index
76     mm_camera_super_buf_t *src_frame;// source frame
77     bool reproc_frame_release;       // false release original buffer
78                                      // true don't release it
79     mm_camera_buf_def_t *src_reproc_bufs;
80     mm_camera_super_buf_t *src_reproc_frame;// source frame (need to be
81                                             //returned back to kernel after done)
82     uint8_t offline_buffer;
83     mm_camera_buf_def_t *offline_reproc_buf; //HAL processed buffer
84 } qcamera_pp_data_t;
85 
86 typedef struct {
87     uint32_t jobId;                  // job ID (obtained when start_jpeg_job)
88     jpeg_job_status_t status;        // jpeg encoding status
89     mm_jpeg_output_t out_data;         // ptr to jpeg output buf
90 } qcamera_jpeg_evt_payload_t;
91 
92 typedef struct {
93     camera_memory_t *        data;     // ptr to data memory struct
94     mm_camera_super_buf_t *  frame;    // ptr to frame
95     QCameraMemory *          streamBufs; //ptr to stream buffers
96     bool                     unlinkFile; // unlink any stored buffers on error
97 } qcamera_release_data_t;
98 
99 typedef struct {
100     int32_t                  msg_type; // msg type of data notify
101     camera_memory_t *        data;     // ptr to data memory struct
102     unsigned int             index;    // index of the buf in the whole buffer
103     camera_frame_metadata_t *metadata; // ptr to meta data
104     qcamera_release_data_t   release_data; // any data needs to be release after notify
105 } qcamera_data_argm_t;
106 
107 #define MAX_EXIF_TABLE_ENTRIES 17
108 class QCameraExif
109 {
110 public:
111     QCameraExif();
112     virtual ~QCameraExif();
113 
114     int32_t addEntry(exif_tag_id_t tagid,
115                      exif_tag_type_t type,
116                      uint32_t count,
117                      void *data);
getNumOfEntries()118     uint32_t getNumOfEntries() {return m_nNumEntries;};
getEntries()119     QEXIF_INFO_DATA *getEntries() {return m_Entries;};
120 
121 private:
122     QEXIF_INFO_DATA m_Entries[MAX_EXIF_TABLE_ENTRIES];  // exif tags for JPEG encoder
123     uint32_t  m_nNumEntries;                            // number of valid entries
124 };
125 
126 class QCameraPostProcessor
127 {
128 public:
129     QCameraPostProcessor(QCamera2HardwareInterface *cam_ctrl);
130     virtual ~QCameraPostProcessor();
131 
132     int32_t init(jpeg_encode_callback_t jpeg_cb, void *user_data);
133     int32_t deinit();
134     int32_t start(QCameraChannel *pSrcChannel);
135     int32_t stop();
136     bool validatePostProcess(mm_camera_super_buf_t *frame);
137     int32_t processData(mm_camera_super_buf_t *frame);
138     int32_t processRawData(mm_camera_super_buf_t *frame);
139     int32_t processPPData(mm_camera_super_buf_t *frame);
140     int32_t processJpegEvt(qcamera_jpeg_evt_payload_t *evt);
141     int32_t getJpegPaddingReq(cam_padding_info_t &padding_info);
142     QCameraReprocessChannel * getReprocChannel(uint8_t index);
getJpegMemOpt()143     inline bool getJpegMemOpt() {return mJpegMemOpt;}
setJpegMemOpt(bool val)144     inline void setJpegMemOpt(bool val) {mJpegMemOpt = val;}
145     int32_t setJpegHandle(mm_jpeg_ops_t *pJpegHandle,
146             mm_jpeg_mpo_ops_t* pJpegMpoHandle, uint32_t clientHandle);
147     int32_t createJpegSession(QCameraChannel *pSrcChannel);
148 
getPPChannelCount()149     int8_t getPPChannelCount() {return mPPChannelCount;};
150     mm_camera_buf_def_t *getOfflinePPInputBuffer(
151             mm_camera_super_buf_t *src_frame);
152     QCameraMemory *mOfflineDataBufs;
153 
154 private:
155     int32_t sendDataNotify(int32_t msg_type,
156             camera_memory_t *data,
157             uint8_t index,
158             camera_frame_metadata_t *metadata,
159             qcamera_release_data_t *release_data,
160             uint32_t super_buf_frame_idx = 0);
161     int32_t sendEvtNotify(int32_t msg_type, int32_t ext1, int32_t ext2);
162     qcamera_jpeg_data_t *findJpegJobByJobId(uint32_t jobId);
163     mm_jpeg_color_format getColorfmtFromImgFmt(cam_format_t img_fmt);
164     mm_jpeg_format_t getJpegImgTypeFromImgFmt(cam_format_t img_fmt);
165     int32_t getJpegEncodingConfig(mm_jpeg_encode_params_t& encode_parm,
166                                   QCameraStream *main_stream,
167                                   QCameraStream *thumb_stream);
168     int32_t encodeData(qcamera_jpeg_data_t *jpeg_job_data,
169                        uint8_t &needNewSess);
170     int32_t queryStreams(QCameraStream **main,
171             QCameraStream **thumb,
172             QCameraStream **reproc,
173             mm_camera_buf_def_t **main_image,
174             mm_camera_buf_def_t **thumb_image,
175             mm_camera_super_buf_t *main_frame,
176             mm_camera_super_buf_t *reproc_frame);
177     int32_t syncStreamParams(mm_camera_super_buf_t *frame,
178             mm_camera_super_buf_t *reproc_frame);
179     void releaseSuperBuf(mm_camera_super_buf_t *super_buf);
180     void releaseSuperBuf(mm_camera_super_buf_t *super_buf,
181             cam_stream_type_t stream_type);
182     static void releaseNotifyData(void *user_data,
183                                   void *cookie,
184                                   int32_t cb_status);
185     void releaseJpegJobData(qcamera_jpeg_data_t *job);
186     static void releaseSaveJobData(void *data, void *user_data);
187     static void releaseRawData(void *data, void *user_data);
188     int32_t processRawImageImpl(mm_camera_super_buf_t *recvd_frame);
189 
190     static void releaseJpegData(void *data, void *user_data);
191     static void releasePPInputData(void *data, void *user_data);
192     static void releaseOngoingPPData(void *data, void *user_data);
193 
194     static void *dataProcessRoutine(void *data);
195     static void *dataSaveRoutine(void *data);
196 
197     int32_t setYUVFrameInfo(mm_camera_super_buf_t *recvd_frame);
198     static bool matchJobId(void *data, void *user_data, void *match_data);
199     static int getJpegMemory(omx_jpeg_ouput_buf_t *out_buf);
200     static int releaseJpegMemory(omx_jpeg_ouput_buf_t *out_buf);
201 
202     int32_t doReprocess();
203     int32_t stopCapture();
204 private:
205     QCamera2HardwareInterface *m_parent;
206     jpeg_encode_callback_t     mJpegCB;
207     void *                     mJpegUserData;
208     mm_jpeg_ops_t              mJpegHandle;
209     mm_jpeg_mpo_ops_t          mJpegMpoHandle; // handle for mpo composition for dualcam
210     uint32_t                   mJpegClientHandle;
211     uint32_t                   mJpegSessionId;
212 
213     void *                     m_pJpegOutputMem[MM_JPEG_MAX_BUF];
214     QCameraExif *              m_pJpegExifObj;
215     uint32_t                   m_bThumbnailNeeded;
216 
217     int8_t                     mPPChannelCount;
218     QCameraReprocessChannel    *mPPChannels[CAM_PP_CHANNEL_MAX];
219 
220     camera_memory_t *          m_DataMem; // save frame mem pointer
221 
222     int8_t                     m_bInited; // if postproc is inited
223 
224     QCameraQueue m_inputPPQ;            // input queue for postproc
225     QCameraQueue m_ongoingPPQ;          // ongoing postproc queue
226     QCameraQueue m_inputJpegQ;          // input jpeg job queue
227     QCameraQueue m_ongoingJpegQ;        // ongoing jpeg job queue
228     QCameraQueue m_inputRawQ;           // input raw job queue
229     QCameraQueue m_inputSaveQ;          // input save job queue
230     QCameraCmdThread m_dataProcTh;      // thread for data processing
231     QCameraCmdThread m_saveProcTh;      // thread for storing buffers
232     uint32_t mSaveFrmCnt;               // save frame counter
233     static const char *STORE_LOCATION;  // path for storing buffers
234     bool mUseSaveProc;                  // use store thread
235     bool mUseJpegBurst;                 // use jpeg burst encoding mode
236     bool mJpegMemOpt;
237     uint32_t   m_JpegOutputMemCount;
238     uint8_t mNewJpegSessionNeeded;
239     int32_t m_bufCountPPQ;
240     Vector<mm_camera_buf_def_t *> m_InputMetadata; // store input metadata buffers for AOST cases
241     size_t m_PPindex;                   // counter for each incoming AOST buffer
242     pthread_mutex_t m_reprocess_lock;   // lock to ensure reprocess job is not freed early.
243 
244 public:
245     cam_dimension_t m_dst_dim;
246 };
247 
248 }; // namespace qcamera
249 
250 #endif /* __QCAMERA_POSTPROC_H__ */
251