xref: /OK3568_Linux_fs/external/camera_engine_rkaiq/rkaiq/hwi/isp20/RawStreamProcUnit.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 _RAW_STREAM_PROC_UNIT_H_
18 #define _RAW_STREAM_PROC_UNIT_H_
19 
20 #include <v4l2_device.h>
21 
22 #include <map>
23 
24 #include "poll_thread.h"
25 #include "safe_queue.h"
26 #include "xcam_mutex.h"
27 #include "Stream.h"
28 #include "CaptureRawData.h"
29 
30 using namespace XCam;
31 
32 namespace RkCam {
33 
34 class CamHwIsp20;
35 class EmptyClass;
36 class RawProcThread;
37 class RawStreamProcUnit : public PollCallback
38 {
39 public:
40     explicit RawStreamProcUnit      ();
41     explicit RawStreamProcUnit(const rk_sensor_full_info_t* s_info, bool linked_to_isp,
42                                int tx_buf_cnt);
43     virtual ~RawStreamProcUnit ();
44     virtual XCamReturn start        (int mode);
45     virtual XCamReturn stop         ();
46     void set_working_mode           (int mode);
47     XCamReturn prepare(int idx);
48     void set_rx_devices             (SmartPtr<V4l2Device> mipi_rx_devs[3]);
49     SmartPtr<V4l2Device> get_rx_device (int index);
50     XCamReturn set_rx_format              (const struct v4l2_subdev_format& sns_sd_fmt, uint32_t sns_v4l_pix_fmt);
51     XCamReturn set_rx_format              (const struct v4l2_subdev_selection& sns_sd_sel, uint32_t sns_v4l_pix_fmt);
52     void set_devices                (SmartPtr<V4l2SubDevice> ispdev, CamHwIsp20* handle);
53     void set_hdr_frame_readback_infos(uint32_t frame_id, int times);
54     void set_hdr_global_tmo_mode(uint32_t frame_id, bool mode);
55     void notify_sof(uint64_t time, uint32_t frameid);
56     void send_sync_buf(SmartPtr<V4l2BufferProxy> &buf_s, SmartPtr<V4l2BufferProxy> &buf_m, SmartPtr<V4l2BufferProxy> &buf_l);
57     bool raw_buffer_proc();
setMulCamConc(bool cc)58     void setMulCamConc(bool cc) {
59         _is_multi_cam_conc = cc;
60     }
61     enum {
62         ISP_MIPI_HDR_S = 0,
63         ISP_MIPI_HDR_M,
64         ISP_MIPI_HDR_L,
65         ISP_MIPI_HDR_MAX,
66     };
67     // notify CamHwIsp one frame has been processed
setPollCallback(PollCallback * cb)68     void setPollCallback(PollCallback* cb) { _PollCallback = cb; }
69     // from PollCallback
poll_buffer_ready(SmartPtr<VideoBuffer> & buf,int type)70     virtual XCamReturn poll_buffer_ready (SmartPtr<VideoBuffer> &buf, int type) { return XCAM_RETURN_ERROR_FAILED; }
poll_buffer_failed(int64_t timestamp,const char * msg)71     virtual XCamReturn poll_buffer_failed (int64_t timestamp, const char *msg) { return XCAM_RETURN_ERROR_FAILED; }
poll_buffer_ready(SmartPtr<VideoBuffer> & buf)72     virtual XCamReturn poll_buffer_ready (SmartPtr<VideoBuffer> &buf) { return XCAM_RETURN_ERROR_FAILED; }
73     virtual XCamReturn poll_buffer_ready (SmartPtr<V4l2BufferProxy> &buf, int dev_index);
poll_event_ready(uint32_t sequence,int type)74     virtual XCamReturn poll_event_ready (uint32_t sequence, int type) { return XCAM_RETURN_ERROR_FAILED; }
poll_event_failed(int64_t timestamp,const char * msg)75     virtual XCamReturn poll_event_failed (int64_t timestamp, const char *msg) { return XCAM_RETURN_ERROR_FAILED; }
setCamPhyId(int phyId)76     void setCamPhyId(int phyId) {
77         mCamPhyId = phyId;
78     }
setSensorCategory(bool sensorState)79     void setSensorCategory(bool sensorState) {
80         _is_1608_sensor = sensorState;
81     }
82     XCamReturn capture_raw_ctl(capture_raw_t type, int count = 0, const char* capture_dir = nullptr, char* output_dir = nullptr) {
83         if (!_rawCap)
84             return XCAM_RETURN_ERROR_FAILED;
85         return _rawCap->capture_raw_ctl(type, count, capture_dir, output_dir);
86     }
87 
notify_capture_raw()88     XCamReturn notify_capture_raw() {
89         if (!_rawCap)
90             return XCAM_RETURN_ERROR_FAILED;
91         return _rawCap->notify_capture_raw();
92     }
93     XCamReturn set_csi_mem_word_big_align(uint32_t width, uint32_t height, uint32_t sns_v4l_pix_fmt, int8_t sns_bpp);
94 
95 protected:
96     XCAM_DEAD_COPY (RawStreamProcUnit);
97 
98     void trigger_isp_readback           ();
99     void match_lumadetect_map           (uint32_t sequence, sint32_t &additional_times);
100     void match_globaltmostate_map(uint32_t sequence, bool &isHdrGlobalTmo);
101     XCamReturn match_sof_timestamp_map(sint32_t sequence, uint64_t &timestamp);
102     int mCamPhyId;
103 protected:
104     SmartPtr<V4l2Device> _dev[3];
105     int _dev_index[3];
106     SmartPtr<RKStream> _stream[3];
107     int _working_mode;
108     int _mipi_dev_max;
109     bool _is_multi_cam_conc;
110     //
111     Mutex _buf_mutex;
112     std::map<uint32_t, int> _isp_hdr_fid2times_map;
113     std::map<uint32_t, bool> _isp_hdr_fid2ready_map;
114     std::map<uint32_t, bool> _hdr_global_tmo_state_map;
115     std::map<sint32_t, uint64_t> _sof_timestamp_map;
116     SafeList<V4l2BufferProxy> buf_list[3];
117     SafeList<V4l2BufferProxy> cache_list[3];
118 
119     SmartPtr<RawProcThread> _raw_proc_thread;
120     CamHwIsp20* _camHw;
121     SmartPtr<V4l2SubDevice> _isp_core_dev;
122     bool _first_trigger;
123     Mutex _mipi_trigger_mutex;
124     SafeQueue<int> _msg_queue;
125     PollCallback* _PollCallback;
126     CaptureRawData* _rawCap;
127     bool     _is_1608_sensor;
128 };
129 
130 class RawProcThread
131     : public Thread
132 {
133 public:
RawProcThread(RawStreamProcUnit * handle)134     RawProcThread (RawStreamProcUnit *handle)
135         : Thread ("RawProcThread")
136         , _handle (handle)
137     {}
138 
139 protected:
loop()140     virtual bool loop () {
141         return  _handle->raw_buffer_proc ();
142     }
143 
144 private:
145     RawStreamProcUnit *_handle;
146 };
147 
148 }
149 #endif
150 
151 
152