xref: /OK3568_Linux_fs/external/camera_engine_rkaiq/rkaiq/hwi/isp20/RawStreamCapUnit.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_CAP_UNIT_H_
18 #define _RAW_STREAM_CAP_UNIT_H_
19 #include <map>
20 #include <v4l2_device.h>
21 #include "poll_thread.h"
22 #include "xcam_mutex.h"
23 #include "Stream.h"
24 #include "smart_buffer_priv.h"
25 using namespace XCam;
26 
27 namespace RkCam {
28 
29 class RawStreamProcUnit;
30 class RawStreamCapUnit : public PollCallback
31 {
32 public:
33     explicit RawStreamCapUnit ();
34     explicit RawStreamCapUnit (const rk_sensor_full_info_t *s_info, bool linked_to_isp, int tx_buf_cnt);
35     virtual ~RawStreamCapUnit ();
36     virtual XCamReturn start(int mode);
37     virtual XCamReturn stop ();
38     void set_working_mode(int mode);
39     void set_devices(SmartPtr<V4l2SubDevice> ispdev, CamHwIsp20* handle, RawStreamProcUnit *proc);
40     void set_tx_devices(SmartPtr<V4l2Device> mipi_tx_devs[3]);
41     SmartPtr<V4l2Device> get_tx_device (int index);
42     XCamReturn set_tx_format(const struct v4l2_subdev_format& sns_sd_fmt, uint32_t sns_v4l_pix_fmt);
43     XCamReturn set_tx_format(const struct v4l2_subdev_selection& sns_sd_sel, uint32_t sns_v4l_pix_fmt);
44     XCamReturn prepare(int idx);
45     void prepare_cif_mipi();
46     void skip_frames(int skip_num, int32_t skip_seq);
47     // from PollCallback
poll_buffer_ready(SmartPtr<VideoBuffer> & buf,int type)48     virtual XCamReturn poll_buffer_ready (SmartPtr<VideoBuffer> &buf, int type) { return XCAM_RETURN_ERROR_FAILED; }
poll_buffer_failed(int64_t timestamp,const char * msg)49     virtual XCamReturn poll_buffer_failed (int64_t timestamp, const char *msg) { return XCAM_RETURN_ERROR_FAILED; }
poll_buffer_ready(SmartPtr<VideoBuffer> & buf)50     virtual XCamReturn poll_buffer_ready (SmartPtr<VideoBuffer> &buf) { return XCAM_RETURN_ERROR_FAILED; }
51     virtual XCamReturn poll_buffer_ready (SmartPtr<V4l2BufferProxy> &buf, int dev_index);
poll_event_ready(uint32_t sequence,int type)52     virtual XCamReturn poll_event_ready (uint32_t sequence, int type) { return XCAM_RETURN_ERROR_FAILED; }
poll_event_failed(int64_t timestamp,const char * msg)53     virtual XCamReturn poll_event_failed (int64_t timestamp, const char *msg) { return XCAM_RETURN_ERROR_FAILED; }
setCamPhyId(int phyId)54     void setCamPhyId(int phyId) {
55         mCamPhyId = phyId;
56     }
setSensorCategory(bool sensorState)57     void setSensorCategory(bool sensorState) {
58         _is_1608_stream = sensorState;
59     }
60     XCamReturn reset_hardware();
61     XCamReturn set_csi_mem_word_big_align(uint32_t width, uint32_t height, uint32_t sns_v4l_pix_fmt, int8_t sns_bpp);
62 
63     enum {
64         ISP_MIPI_HDR_S = 0,
65         ISP_MIPI_HDR_M,
66         ISP_MIPI_HDR_L,
67         ISP_MIPI_HDR_MAX,
68     };
69     enum RawCapState {
70         RAW_CAP_STATE_INVALID,
71         RAW_CAP_STATE_INITED,
72         RAW_CAP_STATE_PREPARED,
73         RAW_CAP_STATE_STARTED,
74         RAW_CAP_STATE_STOPPED,
75     };
76 
77 protected:
78     XCAM_DEAD_COPY (RawStreamCapUnit);
79     XCamReturn sync_raw_buf(SmartPtr<V4l2BufferProxy> &buf_s, SmartPtr<V4l2BufferProxy> &buf_m, SmartPtr<V4l2BufferProxy> &buf_l);
80     bool check_skip_frame(int32_t buf_seq);
81     int mCamPhyId;
82     bool _is_1608_stream;
83 protected:
84     SmartPtr<V4l2Device> _dev[3];
85     SmartPtr<V4l2Device> _dev_bakup[3];
86     int _dev_index[3];
87     SmartPtr<RKStream> _stream[3];
88     Mutex _buf_mutex;
89     int _working_mode;
90     int _mipi_dev_max;
91     int _skip_num;
92     int64_t _skip_to_seq;
93     Mutex _mipi_mutex;
94     enum RawCapState _state;
95 
96     SafeList<V4l2BufferProxy> buf_list[3];
97     CamHwIsp20* _camHw;
98     SmartPtr<V4l2SubDevice> _isp_core_dev;
99     RawStreamProcUnit *_proc_stream;
100     //
101     SafeList<V4l2BufferProxy> _NrImg_ready_list;
102 };
103 
104 }
105 #endif
106 
107