1 /* 2 * Copyright (c) 2019 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 18 #ifndef _FAKE_SENSOR_HW_BASE_H_ 19 #define _FAKE_SENSOR_HW_BASE_H_ 20 21 #include <pthread.h> 22 #include <sys/time.h> 23 #include "SensorHw.h" 24 25 using namespace XCam; 26 27 namespace RkCam { 28 #define FAKECAM_SUBM (0x40) 29 30 class CTimer; 31 class FakeSensorHw : public SensorHw { 32 friend class CTimer; 33 public: 34 explicit FakeSensorHw(); 35 virtual ~FakeSensorHw(); 36 37 virtual XCamReturn setExposureParams(SmartPtr<RkAiqExpParamsProxy>& expPar); 38 virtual XCamReturn getSensorModeData(const char* sns_ent_name, 39 rk_aiq_exposure_sensor_descriptor& sns_des); 40 41 virtual XCamReturn handle_sof(int64_t time, uint32_t frameid); 42 virtual int get_pixel(rk_aiq_exposure_sensor_descriptor* sns_des); 43 virtual int get_blank(rk_aiq_exposure_sensor_descriptor* sns_des); 44 virtual int get_exposure_range(rk_aiq_exposure_sensor_descriptor* sns_des); 45 virtual int get_sensor_desc(rk_aiq_exposure_sensor_descriptor* sns_des); 46 47 virtual XCamReturn get_sensor_descriptor (rk_aiq_exposure_sensor_descriptor* sns_des); 48 virtual XCamReturn set_working_mode(int mode); 49 virtual XCamReturn set_exp_delay_info(int time_delay, int gain_delay, int hcg_lcg_mode_delay); 50 virtual XCamReturn set_mirror_flip(bool mirror, bool flip, int32_t& skip_frame_sequence); 51 virtual XCamReturn get_mirror_flip(bool& mirror, bool& flip); 52 virtual XCamReturn start(bool prepared); 53 virtual XCamReturn stop(); 54 virtual XCamReturn get_selection (int pad, uint32_t target, struct v4l2_subdev_selection &select); 55 virtual XCamReturn getFormat(struct v4l2_subdev_format &aFormat); 56 XCamReturn prepare(rk_aiq_raw_prop_t prop); 57 XCamReturn set_mipi_tx_devs(SmartPtr<V4l2Device> mipi_tx_devs[3]); 58 XCamReturn enqueue_rawbuffer(struct rk_aiq_vbuf *vbuf, bool sync); 59 virtual XCamReturn on_dqueue(int dev_idx, SmartPtr<V4l2BufferProxy> buf_proxy); 60 XCamReturn register_rawdata_callback(void (*callback)(void *)); is_virtual_sensor()61 virtual bool is_virtual_sensor() { return true; } 62 63 private: 64 XCAM_DEAD_COPY (FakeSensorHw); 65 int get_sensor_fps(float& fps); 66 int get_nr_switch(rk_aiq_sensor_nr_switch_t* nr_switch); 67 int _width; 68 int _height; 69 uint32_t _fmt_code; 70 rk_aiq_rawbuf_type_t _rawbuf_type; 71 std::list<struct rk_aiq_vbuf> _vbuf_list; 72 SmartPtr<V4l2Device> _mipi_tx_dev[3]; 73 CTimer *_timer; 74 void (*pFunc)(void *addr); 75 Mutex _sync_mutex; 76 Cond _sync_cond; 77 bool _need_sync; 78 }; 79 80 class CTimer 81 { 82 public: 83 CTimer(FakeSensorHw *dev); 84 virtual ~CTimer(); 85 void SetTimer(long second,long microsecond); 86 void StartTimer(); 87 void StopTimer(); 88 private: 89 pthread_t thread_timer; 90 long m_second, m_microsecond; OnTimer_stub(void * p)91 static void *OnTimer_stub(void *p) 92 { 93 (static_cast<CTimer*>(p))->thread_proc(); 94 return NULL; 95 } 96 void thread_proc(); 97 void OnTimer(); 98 FakeSensorHw *_dev; 99 }; 100 } //namespace RkCam 101 102 #endif 103