xref: /OK3568_Linux_fs/external/camera_engine_rkaiq/rkaiq/hwi/isp20/SPStreamProcUnit.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  *  Copyright (c) 2021 Rockchip Corporation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17 #ifndef _SP_STREAM_PROC_UNIT_H_
18 #define _SP_STREAM_PROC_UNIT_H_
19 #include <v4l2_device.h>
20 #include "poll_thread.h"
21 #include "xcam_mutex.h"
22 #include "TnrStatsStream.h"
23 #include "af_head.h"
24 
25 using namespace XCam;
26 
27 namespace RkCam {
28 
29 enum rkisp_isp_ver {
30     ISP_V10 = 0x0,
31     ISP_V11 = 0x1,
32     ISP_V12 = 0x2,
33     ISP_V13 = 0x3,
34     ISP_V20 = 0x4,
35     ISP_V21 = 0x5,
36     ISP_V30 = 0x6,
37     ISP_V32 = 0x7,
38 };
39 
40 class SPImagBufferProxy : public SubV4l2BufferProxy
41 {
42     public:
SPImagBufferProxy(SmartPtr<V4l2Buffer> & buf,SmartPtr<V4l2Device> & device)43     explicit SPImagBufferProxy(SmartPtr<V4l2Buffer> &buf, SmartPtr<V4l2Device> &device)
44              :SubV4l2BufferProxy(buf, device)
45     {
46     }
~SPImagBufferProxy()47     virtual ~SPImagBufferProxy() {}
map()48     virtual uint8_t *map ()
49     {
50         return (uint8_t *)get_v4l2_planar_userptr(0);
51     }
unmap()52     virtual bool unmap ()
53     {
54         return true;
55     }
set_buff_fd(int fd)56     int set_buff_fd(int fd)
57     {
58         _buff_fd = fd;
59         return 0;
60     }
61 protected:
62     XCAM_DEAD_COPY (SPImagBufferProxy);
63 };
64 
65 class CamHwIsp20;
66 class SPStreamProcUnit       : public RKStream, public PollCallback
67 {
68 public:
69     explicit SPStreamProcUnit (SmartPtr<V4l2Device> isp_sp_dev, int type, int isp_ver);
70     virtual ~SPStreamProcUnit ();
71     virtual void start ();
72     virtual void stop ();
73     virtual SmartPtr<VideoBuffer> new_video_buffer(SmartPtr<V4l2Buffer> buf, SmartPtr<V4l2Device> dev);
74     XCamReturn prepare (CalibDbV2_Af_LdgParam_t *ldg_param, CalibDbV2_Af_HighLightParam_t *highlight, int width = 0, int height = 0, int stride = 0);
75     void set_devices (CamHwIsp20* camHw, SmartPtr<V4l2SubDevice> isp_core_dev, SmartPtr<V4l2SubDevice> ispp_dev, SmartPtr<V4l2SubDevice> lensdev);
76     XCamReturn get_sp_resolution(int &width, int &height, int &aligned_w, int &aligned_h);
77     // from PollCallback
poll_buffer_ready(SmartPtr<VideoBuffer> & buf,int type)78     virtual XCamReturn poll_buffer_ready (SmartPtr<VideoBuffer> &buf, int type) { return XCAM_RETURN_ERROR_FAILED; }
poll_buffer_failed(int64_t timestamp,const char * msg)79     virtual XCamReturn poll_buffer_failed (int64_t timestamp, const char *msg) { return XCAM_RETURN_ERROR_FAILED; }
80     virtual XCamReturn poll_buffer_ready (SmartPtr<VideoBuffer> &buf);
poll_buffer_ready(SmartPtr<V4l2BufferProxy> & buf,int dev_index)81     virtual XCamReturn poll_buffer_ready (SmartPtr<V4l2BufferProxy> &buf, int dev_index) { return XCAM_RETURN_ERROR_FAILED; }
poll_event_ready(uint32_t sequence,int type)82     virtual XCamReturn poll_event_ready (uint32_t sequence, int type) { return XCAM_RETURN_ERROR_FAILED; }
poll_event_failed(int64_t timestamp,const char * msg)83     virtual XCamReturn poll_event_failed (int64_t timestamp, const char *msg) { return XCAM_RETURN_ERROR_FAILED; }
84     void update_af_meas_params(rk_aiq_isp_af_meas_t *sp_meas);
85     int get_lowpass_fv(uint32_t sequence, SmartPtr<V4l2BufferProxy> buf_proxy);
86     void set_af_img_size(int w, int h, int w_align, int h_align);
87 protected:
88     XCAM_DEAD_COPY (SPStreamProcUnit);
89     bool init_fbcbuf_fd();
90     bool deinit_fbcbuf_fd();
91     int get_fd_by_index(int index);
92 protected:
93     CamHwIsp20* _camHw;
94     SmartPtr<V4l2SubDevice>  _isp_core_dev;
95     SmartPtr<V4l2SubDevice> _ispp_dev;
96     SmartPtr<V4l2SubDevice> _focus_dev;
97 
98     int _ds_width;
99     int _ds_height;
100     int _ds_width_align;
101     int _ds_height_align;
102     int _src_width;
103     int _src_height;
104     int img_ds_size_x;
105     int img_ds_size_y;
106 
107     std::map<int, int> _buf_fd_map;
108     bool _first;
109     //SmartPtr<TnrStatsStream> _tnr_stream_unit;
110     SmartPtr<SubVideoBuffer> _ispgain;
111 
112     int _isp_ver;
113     XCam::Mutex _afmeas_param_mutex;
114     unsigned char ldg_enable;
115     uint8_t *pAfTmp;
116     uint32_t sub_shp4_4[RKAIQ_RAWAF_ROI_SUBWINS_NUM];
117     uint32_t sub_shp8_8[RKAIQ_RAWAF_ROI_SUBWINS_NUM];
118     uint32_t high_light[RKAIQ_RAWAF_ROI_SUBWINS_NUM];
119     uint32_t high_light2[RKAIQ_RAWAF_ROI_SUBWINS_NUM];
120     rk_aiq_af_algo_meas_t _af_meas_params;
121     rk_aiq_lens_descriptor _lens_des;
122     int af_img_width;
123     int af_img_height;
124     int af_img_width_align;
125     int af_img_height_align;
126 };
127 
128 }
129 #endif
130 
131