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