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 "xcam_thread.h" 22 #include "smartptr.h" 23 #include "safe_list.h" 24 #include "v4l2_device.h" 25 #include "poll_thread.h" 26 #include "xcam_log.h" 27 #include "Stream.h" 28 #include "RawStreamProcUnit.h" 29 #include "rk_aiq_offline_raw.h" 30 #include "rk_vi_user_api2_stream_cfg.h" 31 #include "MediaInfo.h" 32 33 using namespace XCam; 34 35 namespace RkRawStream { 36 37 #ifndef ANDROID_OS 38 typedef int (*on_frame_capture_callback)(uint8_t *data, uint32_t len); 39 #else 40 typedef std::function<int(uint8_t *data, uint32_t len)> on_frame_capture_callback; 41 #endif 42 43 //typedef int (*on_frame_capture_callback)(struct v4l2_buffer *vbuf[3], struct v4l2_format *vfmt[3], int vfd[3], int state); 44 struct _live_rkraw_buf 45 { 46 struct _block_header _header; 47 struct _st_addrinfo_stream _addr; 48 49 }__attribute__ ((packed)); 50 51 struct _live_rkraw_data 52 { 53 unsigned short tag; 54 struct _raw_format _format; 55 struct _live_rkraw_buf normal_buf; 56 struct _live_rkraw_buf hdr_buf0; 57 struct _live_rkraw_buf hdr_buf1; 58 struct _live_rkraw_buf hdr_buf2; 59 rk_aiq_frame_info_t _finfo; 60 unsigned short end; 61 }__attribute__ ((packed)); 62 63 class RawStreamCapUnit : public PollCallback 64 { 65 public: 66 explicit RawStreamCapUnit(char *dev0, char *dev1, char *dev2); 67 explicit RawStreamCapUnit(const rk_sensor_full_info_t *s_info); 68 virtual ~RawStreamCapUnit(); 69 virtual XCamReturn start(); 70 virtual XCamReturn stop (); 71 virtual XCamReturn stop_device (); 72 virtual XCamReturn release_buffer (); 73 XCamReturn prepare(int idx, uint8_t buf_memory_type, uint8_t buf_cnt); 74 void set_tx_format(uint32_t width, uint32_t heigh, uint32_t pix_fmt, int mode); 75 void set_sensor_format(uint32_t width, uint32_t height, uint32_t fps); 76 void set_sensor_mode(uint32_t mode); 77 void set_devices(RawStreamProcUnit *proc); 78 void set_working_mode(int mode); 79 void release_user_taked_buf(int dev_index); 80 void set_dma_buf(int dev_index, int buf_index, int fd); 81 // from PollCallback poll_buffer_ready(SmartPtr<VideoBuffer> & buf,int type)82 virtual XCamReturn poll_buffer_ready (SmartPtr<VideoBuffer> &buf, int type) { return XCAM_RETURN_ERROR_FAILED; } poll_buffer_failed(int64_t timestamp,const char * msg)83 virtual XCamReturn poll_buffer_failed (int64_t timestamp, const char *msg) { return XCAM_RETURN_ERROR_FAILED; } poll_buffer_ready(SmartPtr<VideoBuffer> & buf)84 virtual XCamReturn poll_buffer_ready (SmartPtr<VideoBuffer> &buf) { return XCAM_RETURN_ERROR_FAILED; } 85 virtual XCamReturn poll_buffer_ready (SmartPtr<V4l2BufferProxy> &buf, int dev_index); poll_event_ready(uint32_t sequence,int type)86 virtual XCamReturn poll_event_ready (uint32_t sequence, int type) { return XCAM_RETURN_ERROR_FAILED; } poll_event_failed(int64_t timestamp,const char * msg)87 virtual XCamReturn poll_event_failed (int64_t timestamp, const char *msg) { return XCAM_RETURN_ERROR_FAILED; } 88 89 on_frame_capture_callback user_on_frame_capture_cb; 90 enum { 91 ISP_MIPI_HDR_S = 0, 92 ISP_MIPI_HDR_M, 93 ISP_MIPI_HDR_L, 94 ISP_MIPI_HDR_MAX, 95 }; 96 enum RawCapState { 97 RAW_CAP_STATE_INVALID, 98 RAW_CAP_STATE_INITED, 99 RAW_CAP_STATE_PREPARED, 100 RAW_CAP_STATE_STARTED, 101 RAW_CAP_STATE_STOPPED, 102 }; 103 SmartPtr<V4l2Device> _dev[3]; 104 bool user_takes_buf; 105 protected: 106 XCamReturn sync_raw_buf(SmartPtr<V4l2BufferProxy> &buf_s, SmartPtr<V4l2BufferProxy> &buf_m, SmartPtr<V4l2BufferProxy> &buf_l); 107 XCamReturn do_capture_callback(SmartPtr<V4l2BufferProxy> &buf_s, SmartPtr<V4l2BufferProxy> &buf_m, SmartPtr<V4l2BufferProxy> &buf_l); 108 SmartPtr<V4l2Device> _dev_bakup[3]; 109 int _dev_index[3]; 110 SmartPtr<RKStream> _stream[3]; 111 SmartPtr<V4l2SubDevice> _sensor_dev; 112 int _working_mode; 113 int _mipi_dev_max; 114 int _skip_num; 115 Mutex _mipi_mutex; 116 Mutex _buf_mutex; 117 struct v4l2_format _format; 118 enum RawCapState _state; 119 SafeList<V4l2BufferProxy> buf_list[3]; 120 SafeList<V4l2BufferProxy> user_used_buf_list[3]; 121 RawStreamProcUnit *_proc_stream; 122 struct _live_rkraw_data _rkraw_data[STREAM_VIPCAP_BUF_NUM]; 123 char _sns_name[32]; 124 bool is_multi_isp_mode; 125 enum v4l2_memory _memory_type; 126 }; 127 128 } 129 #endif 130 131