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 _PDAF_STREAM_PROC_UNIT_H_ 18 #define _PDAF_STREAM_PROC_UNIT_H_ 19 #include <v4l2_device.h> 20 #include "poll_thread.h" 21 #include "xcam_mutex.h" 22 #include "Stream.h" 23 #include "af_head.h" 24 25 using namespace XCam; 26 27 namespace RkCam { 28 29 class PdafBufferProxy : public V4l2BufferProxy 30 { 31 public: PdafBufferProxy(SmartPtr<V4l2Buffer> & buf,SmartPtr<V4l2Device> & device)32 explicit PdafBufferProxy(SmartPtr<V4l2Buffer> &buf, SmartPtr<V4l2Device> &device) 33 : V4l2BufferProxy(buf, device) 34 { 35 memset(&pdaf_meas, 0, sizeof(pdaf_meas)); 36 } ~PdafBufferProxy()37 virtual ~PdafBufferProxy() {} 38 rk_aiq_isp_pdaf_meas_t pdaf_meas; 39 protected: 40 XCAM_DEAD_COPY (PdafBufferProxy); 41 }; 42 43 class CamHwIsp20; 44 class RKStream; 45 class PdafStreamHelperThd; 46 class PdafStreamProcUnit : public PollCallback 47 { 48 public: 49 explicit PdafStreamProcUnit (int type); 50 virtual ~PdafStreamProcUnit (); 51 virtual void start (); 52 virtual void stop (); 53 54 // from PollCallback poll_buffer_ready(SmartPtr<VideoBuffer> & buf,int type)55 virtual XCamReturn poll_buffer_ready (SmartPtr<VideoBuffer> &buf, int type) { return XCAM_RETURN_ERROR_FAILED; } poll_buffer_failed(int64_t timestamp,const char * msg)56 virtual XCamReturn poll_buffer_failed (int64_t timestamp, const char *msg) { return XCAM_RETURN_ERROR_FAILED; } poll_buffer_ready(SmartPtr<VideoBuffer> & buf)57 virtual XCamReturn poll_buffer_ready (SmartPtr<VideoBuffer> &buf) { return XCAM_RETURN_ERROR_FAILED; } 58 virtual XCamReturn poll_buffer_ready (SmartPtr<V4l2BufferProxy> &buf, int dev_index); poll_event_ready(uint32_t sequence,int type)59 virtual XCamReturn poll_event_ready (uint32_t sequence, int type) { return XCAM_RETURN_ERROR_FAILED; } poll_event_failed(int64_t timestamp,const char * msg)60 virtual XCamReturn poll_event_failed (int64_t timestamp, const char *msg) { return XCAM_RETURN_ERROR_FAILED; } 61 62 void set_devices(CamHwIsp20* camHw); 63 XCamReturn prepare(rk_sensor_pdaf_info_t *pdaf_inf); 64 XCamReturn start_stream(); 65 XCamReturn stop_stream(); 66 XCamReturn deinit(); 67 protected: 68 XCAM_DEAD_COPY (PdafStreamProcUnit); 69 protected: 70 CamHwIsp20* mCamHw; 71 SmartPtr<V4l2Device> mPdafDev; 72 SmartPtr<RKPdafStream> mPdafStream; 73 bool mStartFlag; 74 bool mStartStreamFlag; 75 rk_aiq_isp_pdaf_meas_t mPdafMeas; 76 int mBufType; 77 SmartPtr<PdafStreamHelperThd> mHelperThd; 78 XCam::Mutex mStreamMutex; 79 }; 80 81 typedef struct _PdafStreamParam { 82 bool valid; 83 bool stream_flag; 84 } PdafStreamParam; 85 86 class PdafStreamHelperThd 87 : public XCam::Thread { 88 public: PdafStreamHelperThd(PdafStreamProcUnit * pdafstreamproc)89 PdafStreamHelperThd(PdafStreamProcUnit *pdafstreamproc) 90 : Thread("PdafStreamHelperThd"), mPdafStreamProc(pdafstreamproc) {}; ~PdafStreamHelperThd()91 ~PdafStreamHelperThd() { 92 mAttrQueue.clear (); 93 }; 94 triger_stop()95 void triger_stop() { 96 mAttrQueue.pause_pop (); 97 }; 98 triger_start()99 void triger_start() { 100 mAttrQueue.resume_pop (); 101 }; 102 push_attr(const XCam::SmartPtr<PdafStreamParam> buffer)103 bool push_attr (const XCam::SmartPtr<PdafStreamParam> buffer) { 104 mAttrQueue.push (buffer); 105 return true; 106 }; 107 is_empty()108 bool is_empty () { 109 return mAttrQueue.is_empty(); 110 }; 111 clear_attr()112 void clear_attr () { 113 mAttrQueue.clear (); 114 }; 115 116 protected: 117 //virtual bool started (); stopped()118 virtual void stopped () { 119 mAttrQueue.clear (); 120 }; 121 virtual bool loop (); 122 private: 123 PdafStreamProcUnit *mPdafStreamProc; 124 XCam::SafeList<PdafStreamParam> mAttrQueue; 125 }; 126 127 } 128 #endif 129 130 131