1 /* Copyright (c) 2012-2013, 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 __QCAMERA_POSTPROC_H__
31 #define __QCAMERA_POSTPROC_H__
32 
33 extern "C" {
34 #include <mm_camera_interface.h>
35 #include <mm_jpeg_interface.h>
36 }
37 #include "QCamera2HWI.h"
38 
39 namespace qcamera {
40 
41 class QCameraExif;
42 
43 typedef struct {
44     uint32_t jobId;                  // job ID
45     uint32_t client_hdl;             // handle of jpeg client (obtained when open jpeg)
46     mm_camera_super_buf_t *src_frame;// source frame (need to be returned back to kernel after done)
47     mm_camera_super_buf_t *src_reproc_frame; // original source frame for reproc if not NULL
48 } qcamera_jpeg_data_t;
49 
50 typedef struct {
51     uint32_t jobId;                  // job ID
52     mm_camera_super_buf_t *src_frame;// source frame (need to be returned back to kernel after done)
53 } qcamera_pp_data_t;
54 
55 typedef struct {
56     mm_camera_super_buf_t *frame;    // source frame that needs post process
57 } qcamera_pp_request_t;
58 
59 typedef struct {
60     uint32_t jobId;                  // job ID (obtained when start_jpeg_job)
61     jpeg_job_status_t status;        // jpeg encoding status
62     mm_jpeg_output_t out_data;         // ptr to jpeg output buf
63 } qcamera_jpeg_evt_payload_t;
64 
65 typedef struct {
66     camera_memory_t *        data;     // ptr to data memory struct
67     mm_camera_super_buf_t *  frame;    // ptr to frame
68 } qcamera_release_data_t;
69 
70 typedef struct {
71     int32_t                  msg_type; // msg type of data notify
72     camera_memory_t *        data;     // ptr to data memory struct
73     unsigned int             index;    // index of the buf in the whole buffer
74     camera_frame_metadata_t *metadata; // ptr to meta data
75     qcamera_release_data_t   release_data; // any data needs to be release after notify
76 } qcamera_data_argm_t;
77 
78 #define MAX_EXIF_TABLE_ENTRIES 17
79 class QCameraExif
80 {
81 public:
82     QCameraExif();
83     virtual ~QCameraExif();
84 
85     int32_t addEntry(exif_tag_id_t tagid,
86                      exif_tag_type_t type,
87                      uint32_t count,
88                      void *data);
getNumOfEntries()89     uint32_t getNumOfEntries() {return m_nNumEntries;};
getEntries()90     QEXIF_INFO_DATA *getEntries() {return m_Entries;};
91 
92 private:
93     QEXIF_INFO_DATA m_Entries[MAX_EXIF_TABLE_ENTRIES];  // exif tags for JPEG encoder
94     uint32_t  m_nNumEntries;                            // number of valid entries
95 };
96 
97 class QCameraPostProcessor
98 {
99 public:
100     QCameraPostProcessor(QCamera2HardwareInterface *cam_ctrl);
101     virtual ~QCameraPostProcessor();
102 
103     int32_t init(jpeg_encode_callback_t jpeg_cb, void *user_data);
104     int32_t deinit();
105     int32_t start(QCameraChannel *pSrcChannel);
106     int32_t stop();
107     int32_t processData(mm_camera_super_buf_t *frame);
108     int32_t processRawData(mm_camera_super_buf_t *frame);
109     int32_t processPPData(mm_camera_super_buf_t *frame);
110     int32_t processJpegEvt(qcamera_jpeg_evt_payload_t *evt);
111     int32_t getJpegPaddingReq(cam_padding_info_t &padding_info);
112 
113 private:
114     int32_t sendDataNotify(int32_t msg_type,
115                            camera_memory_t *data,
116                            uint8_t index,
117                            camera_frame_metadata_t *metadata,
118                            qcamera_release_data_t *release_data);
119     int32_t sendEvtNotify(int32_t msg_type, int32_t ext1, int32_t ext2);
120     qcamera_jpeg_data_t *findJpegJobByJobId(uint32_t jobId);
121     mm_jpeg_color_format getColorfmtFromImgFmt(cam_format_t img_fmt);
122     mm_jpeg_format_t getJpegImgTypeFromImgFmt(cam_format_t img_fmt);
123     int32_t getJpegEncodingConfig(mm_jpeg_encode_params_t& encode_parm,
124                                   QCameraStream *main_stream,
125                                   QCameraStream *thumb_stream);
126     int32_t encodeData(qcamera_jpeg_data_t *jpeg_job_data,
127                        uint8_t &needNewSess);
128     void releaseSuperBuf(mm_camera_super_buf_t *super_buf);
129     static void releaseNotifyData(void *user_data, void *cookie);
130     void releaseJpegJobData(qcamera_jpeg_data_t *job);
131     int32_t processRawImageImpl(mm_camera_super_buf_t *recvd_frame);
132 
133     static void releaseJpegData(void *data, void *user_data);
134     static void releasePPInputData(void *data, void *user_data);
135     static void releaseOngoingPPData(void *data, void *user_data);
136 
137     static void *dataProcessRoutine(void *data);
138 
139 private:
140     QCamera2HardwareInterface *m_parent;
141     jpeg_encode_callback_t     mJpegCB;
142     void *                     mJpegUserData;
143     mm_jpeg_ops_t              mJpegHandle;
144     uint32_t                   mJpegClientHandle;
145     uint32_t                   mJpegSessionId;
146 
147     QCameraStreamMemory *      m_pJpegOutputMem;
148     QCameraExif *              m_pJpegExifObj;
149     int8_t                     m_bThumbnailNeeded;
150     QCameraReprocessChannel *  m_pReprocChannel;
151 
152     QCameraQueue m_inputPPQ;            // input queue for postproc
153     QCameraQueue m_ongoingPPQ;          // ongoing postproc queue
154     QCameraQueue m_inputJpegQ;          // input jpeg job queue
155     QCameraQueue m_ongoingJpegQ;        // ongoing jpeg job queue
156     QCameraQueue m_inputRawQ;           // input raw job queue
157     QCameraCmdThread m_dataProcTh;      // thread for data processing
158 };
159 
160 }; // namespace qcamera
161 
162 #endif /* __QCAMERA_POSTPROC_H__ */
163