xref: /OK3568_Linux_fs/external/camera_engine_rkaiq/rkaiq/hwi/isp20/RawStreamProcUnit.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  *  Copyright (c) 2021 Rockchip Corporation
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Licensed under the Apache License, Version 2.0 (the "License");
5*4882a593Smuzhiyun  * you may not use this file except in compliance with the License.
6*4882a593Smuzhiyun  * You may obtain a copy of the License at
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  *      http://www.apache.org/licenses/LICENSE-2.0
9*4882a593Smuzhiyun  *
10*4882a593Smuzhiyun  * Unless required by applicable law or agreed to in writing, software
11*4882a593Smuzhiyun  * distributed under the License is distributed on an "AS IS" BASIS,
12*4882a593Smuzhiyun  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*4882a593Smuzhiyun  * See the License for the specific language governing permissions and
14*4882a593Smuzhiyun  * limitations under the License.
15*4882a593Smuzhiyun  *
16*4882a593Smuzhiyun  */
17*4882a593Smuzhiyun #ifndef _RAW_STREAM_PROC_UNIT_H_
18*4882a593Smuzhiyun #define _RAW_STREAM_PROC_UNIT_H_
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun #include <v4l2_device.h>
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun #include <map>
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun #include "poll_thread.h"
25*4882a593Smuzhiyun #include "safe_queue.h"
26*4882a593Smuzhiyun #include "xcam_mutex.h"
27*4882a593Smuzhiyun #include "Stream.h"
28*4882a593Smuzhiyun #include "CaptureRawData.h"
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun using namespace XCam;
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun namespace RkCam {
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun class CamHwIsp20;
35*4882a593Smuzhiyun class EmptyClass;
36*4882a593Smuzhiyun class RawProcThread;
37*4882a593Smuzhiyun class RawStreamProcUnit : public PollCallback
38*4882a593Smuzhiyun {
39*4882a593Smuzhiyun public:
40*4882a593Smuzhiyun     explicit RawStreamProcUnit      ();
41*4882a593Smuzhiyun     explicit RawStreamProcUnit(const rk_sensor_full_info_t* s_info, bool linked_to_isp,
42*4882a593Smuzhiyun                                int tx_buf_cnt);
43*4882a593Smuzhiyun     virtual ~RawStreamProcUnit ();
44*4882a593Smuzhiyun     virtual XCamReturn start        (int mode);
45*4882a593Smuzhiyun     virtual XCamReturn stop         ();
46*4882a593Smuzhiyun     void set_working_mode           (int mode);
47*4882a593Smuzhiyun     XCamReturn prepare(int idx);
48*4882a593Smuzhiyun     void set_rx_devices             (SmartPtr<V4l2Device> mipi_rx_devs[3]);
49*4882a593Smuzhiyun     SmartPtr<V4l2Device> get_rx_device (int index);
50*4882a593Smuzhiyun     XCamReturn set_rx_format              (const struct v4l2_subdev_format& sns_sd_fmt, uint32_t sns_v4l_pix_fmt);
51*4882a593Smuzhiyun     XCamReturn set_rx_format              (const struct v4l2_subdev_selection& sns_sd_sel, uint32_t sns_v4l_pix_fmt);
52*4882a593Smuzhiyun     void set_devices                (SmartPtr<V4l2SubDevice> ispdev, CamHwIsp20* handle);
53*4882a593Smuzhiyun     void set_hdr_frame_readback_infos(uint32_t frame_id, int times);
54*4882a593Smuzhiyun     void set_hdr_global_tmo_mode(uint32_t frame_id, bool mode);
55*4882a593Smuzhiyun     void notify_sof(uint64_t time, uint32_t frameid);
56*4882a593Smuzhiyun     void send_sync_buf(SmartPtr<V4l2BufferProxy> &buf_s, SmartPtr<V4l2BufferProxy> &buf_m, SmartPtr<V4l2BufferProxy> &buf_l);
57*4882a593Smuzhiyun     bool raw_buffer_proc();
setMulCamConc(bool cc)58*4882a593Smuzhiyun     void setMulCamConc(bool cc) {
59*4882a593Smuzhiyun         _is_multi_cam_conc = cc;
60*4882a593Smuzhiyun     }
61*4882a593Smuzhiyun     enum {
62*4882a593Smuzhiyun         ISP_MIPI_HDR_S = 0,
63*4882a593Smuzhiyun         ISP_MIPI_HDR_M,
64*4882a593Smuzhiyun         ISP_MIPI_HDR_L,
65*4882a593Smuzhiyun         ISP_MIPI_HDR_MAX,
66*4882a593Smuzhiyun     };
67*4882a593Smuzhiyun     // notify CamHwIsp one frame has been processed
setPollCallback(PollCallback * cb)68*4882a593Smuzhiyun     void setPollCallback(PollCallback* cb) { _PollCallback = cb; }
69*4882a593Smuzhiyun     // from PollCallback
poll_buffer_ready(SmartPtr<VideoBuffer> & buf,int type)70*4882a593Smuzhiyun     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*4882a593Smuzhiyun     virtual XCamReturn poll_buffer_failed (int64_t timestamp, const char *msg) { return XCAM_RETURN_ERROR_FAILED; }
poll_buffer_ready(SmartPtr<VideoBuffer> & buf)72*4882a593Smuzhiyun     virtual XCamReturn poll_buffer_ready (SmartPtr<VideoBuffer> &buf) { return XCAM_RETURN_ERROR_FAILED; }
73*4882a593Smuzhiyun     virtual XCamReturn poll_buffer_ready (SmartPtr<V4l2BufferProxy> &buf, int dev_index);
poll_event_ready(uint32_t sequence,int type)74*4882a593Smuzhiyun     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*4882a593Smuzhiyun     virtual XCamReturn poll_event_failed (int64_t timestamp, const char *msg) { return XCAM_RETURN_ERROR_FAILED; }
setCamPhyId(int phyId)76*4882a593Smuzhiyun     void setCamPhyId(int phyId) {
77*4882a593Smuzhiyun         mCamPhyId = phyId;
78*4882a593Smuzhiyun     }
setSensorCategory(bool sensorState)79*4882a593Smuzhiyun     void setSensorCategory(bool sensorState) {
80*4882a593Smuzhiyun         _is_1608_sensor = sensorState;
81*4882a593Smuzhiyun     }
82*4882a593Smuzhiyun     XCamReturn capture_raw_ctl(capture_raw_t type, int count = 0, const char* capture_dir = nullptr, char* output_dir = nullptr) {
83*4882a593Smuzhiyun         if (!_rawCap)
84*4882a593Smuzhiyun             return XCAM_RETURN_ERROR_FAILED;
85*4882a593Smuzhiyun         return _rawCap->capture_raw_ctl(type, count, capture_dir, output_dir);
86*4882a593Smuzhiyun     }
87*4882a593Smuzhiyun 
notify_capture_raw()88*4882a593Smuzhiyun     XCamReturn notify_capture_raw() {
89*4882a593Smuzhiyun         if (!_rawCap)
90*4882a593Smuzhiyun             return XCAM_RETURN_ERROR_FAILED;
91*4882a593Smuzhiyun         return _rawCap->notify_capture_raw();
92*4882a593Smuzhiyun     }
93*4882a593Smuzhiyun     XCamReturn set_csi_mem_word_big_align(uint32_t width, uint32_t height, uint32_t sns_v4l_pix_fmt, int8_t sns_bpp);
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun protected:
96*4882a593Smuzhiyun     XCAM_DEAD_COPY (RawStreamProcUnit);
97*4882a593Smuzhiyun 
98*4882a593Smuzhiyun     void trigger_isp_readback           ();
99*4882a593Smuzhiyun     void match_lumadetect_map           (uint32_t sequence, sint32_t &additional_times);
100*4882a593Smuzhiyun     void match_globaltmostate_map(uint32_t sequence, bool &isHdrGlobalTmo);
101*4882a593Smuzhiyun     XCamReturn match_sof_timestamp_map(sint32_t sequence, uint64_t &timestamp);
102*4882a593Smuzhiyun     int mCamPhyId;
103*4882a593Smuzhiyun protected:
104*4882a593Smuzhiyun     SmartPtr<V4l2Device> _dev[3];
105*4882a593Smuzhiyun     int _dev_index[3];
106*4882a593Smuzhiyun     SmartPtr<RKStream> _stream[3];
107*4882a593Smuzhiyun     int _working_mode;
108*4882a593Smuzhiyun     int _mipi_dev_max;
109*4882a593Smuzhiyun     bool _is_multi_cam_conc;
110*4882a593Smuzhiyun     //
111*4882a593Smuzhiyun     Mutex _buf_mutex;
112*4882a593Smuzhiyun     std::map<uint32_t, int> _isp_hdr_fid2times_map;
113*4882a593Smuzhiyun     std::map<uint32_t, bool> _isp_hdr_fid2ready_map;
114*4882a593Smuzhiyun     std::map<uint32_t, bool> _hdr_global_tmo_state_map;
115*4882a593Smuzhiyun     std::map<sint32_t, uint64_t> _sof_timestamp_map;
116*4882a593Smuzhiyun     SafeList<V4l2BufferProxy> buf_list[3];
117*4882a593Smuzhiyun     SafeList<V4l2BufferProxy> cache_list[3];
118*4882a593Smuzhiyun 
119*4882a593Smuzhiyun     SmartPtr<RawProcThread> _raw_proc_thread;
120*4882a593Smuzhiyun     CamHwIsp20* _camHw;
121*4882a593Smuzhiyun     SmartPtr<V4l2SubDevice> _isp_core_dev;
122*4882a593Smuzhiyun     bool _first_trigger;
123*4882a593Smuzhiyun     Mutex _mipi_trigger_mutex;
124*4882a593Smuzhiyun     SafeQueue<int> _msg_queue;
125*4882a593Smuzhiyun     PollCallback* _PollCallback;
126*4882a593Smuzhiyun     CaptureRawData* _rawCap;
127*4882a593Smuzhiyun     bool     _is_1608_sensor;
128*4882a593Smuzhiyun };
129*4882a593Smuzhiyun 
130*4882a593Smuzhiyun class RawProcThread
131*4882a593Smuzhiyun     : public Thread
132*4882a593Smuzhiyun {
133*4882a593Smuzhiyun public:
RawProcThread(RawStreamProcUnit * handle)134*4882a593Smuzhiyun     RawProcThread (RawStreamProcUnit *handle)
135*4882a593Smuzhiyun         : Thread ("RawProcThread")
136*4882a593Smuzhiyun         , _handle (handle)
137*4882a593Smuzhiyun     {}
138*4882a593Smuzhiyun 
139*4882a593Smuzhiyun protected:
loop()140*4882a593Smuzhiyun     virtual bool loop () {
141*4882a593Smuzhiyun         return  _handle->raw_buffer_proc ();
142*4882a593Smuzhiyun     }
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun private:
145*4882a593Smuzhiyun     RawStreamProcUnit *_handle;
146*4882a593Smuzhiyun };
147*4882a593Smuzhiyun 
148*4882a593Smuzhiyun }
149*4882a593Smuzhiyun #endif
150*4882a593Smuzhiyun 
151*4882a593Smuzhiyun 
152