hc
2023-02-15 9c2dfff96adcfcdf2a1143893a7dd749b9f3677a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
 *  Copyright (c) 2019 Rockchip Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */
 
#ifndef _FAKE_SENSOR_HW_BASE_H_
#define _FAKE_SENSOR_HW_BASE_H_
 
#include <pthread.h>
#include <sys/time.h>
#include "SensorHw.h"
 
using namespace XCam;
 
namespace RkCam {
#define FAKECAM_SUBM (0x40)
 
class CTimer;
class FakeSensorHw : public BaseSensorHw {
friend class CTimer;
public:
    explicit FakeSensorHw();
    virtual ~FakeSensorHw();
 
    virtual XCamReturn setExposureParams(SmartPtr<RkAiqExpParamsProxy>& expPar);
    virtual XCamReturn getSensorModeData(const char* sns_ent_name,
                                 rk_aiq_exposure_sensor_descriptor& sns_des);
 
    virtual XCamReturn handle_sof(int64_t time, int frameid);
    virtual int get_pixel(rk_aiq_exposure_sensor_descriptor* sns_des);
    virtual int get_blank(rk_aiq_exposure_sensor_descriptor* sns_des);
    virtual int get_exposure_range(rk_aiq_exposure_sensor_descriptor* sns_des);
    virtual int get_format(rk_aiq_exposure_sensor_descriptor* sns_des);
 
    virtual XCamReturn get_sensor_descriptor (rk_aiq_exposure_sensor_descriptor* sns_des);
    virtual XCamReturn getEffectiveExpParams(SmartPtr<RkAiqExpParamsProxy>& ExpParams, int frame_id);
    virtual XCamReturn set_working_mode(int mode);
    virtual XCamReturn set_exp_delay_info(int time_delay, int gain_delay, int hcg_lcg_mode_delay);
    virtual XCamReturn set_mirror_flip(bool mirror, bool flip, int32_t& skip_frame_sequence);
    virtual XCamReturn get_mirror_flip(bool& mirror, bool& flip);
    virtual XCamReturn start();
    virtual XCamReturn stop();
    virtual XCamReturn get_selection (int pad, uint32_t target, struct v4l2_subdev_selection &select);
    virtual XCamReturn getFormat(struct v4l2_subdev_format &aFormat);
    XCamReturn prepare(rk_aiq_raw_prop_t prop);
    XCamReturn set_mipi_tx_devs(SmartPtr<V4l2Device> mipi_tx_devs[3]);
    XCamReturn enqueue_rawbuffer(struct rk_aiq_vbuf *vbuf, bool sync);
    virtual XCamReturn on_dqueue(int dev_idx, SmartPtr<V4l2BufferProxy> buf_proxy);
    XCamReturn register_rawdata_callback(void (*callback)(void *));
    virtual bool is_virtual_sensor() { return true; }
 
private:
    XCAM_DEAD_COPY (FakeSensorHw);
    Mutex _mutex;
    Mutex _map_mutex;
    int _working_mode;
    bool _first;
    std::map<int, SmartPtr<RkAiqExpParamsProxy>> _effecting_exp_map;
    std::string _sns_entity_name;
    int get_sensor_fps(float& fps);
    int get_nr_switch(rk_aiq_sensor_nr_switch_t* nr_switch);
    int _width;
    int _height;
    uint32_t _fmt_code;
    rk_aiq_rawbuf_type_t _rawbuf_type;
    std::list<struct rk_aiq_vbuf> _vbuf_list;
    SmartPtr<RkAiqExpParamsPool> mAiqExpParamsPool;
    SmartPtr<V4l2Device>  _mipi_tx_dev[3];
    CTimer *_timer;
    void (*pFunc)(void *addr);
    Mutex _sync_mutex;
    Cond _sync_cond;
    bool _need_sync;
};
 
class CTimer
{
public:
    CTimer(FakeSensorHw *dev);
    virtual ~CTimer();
    void SetTimer(long second,long microsecond);
    void StartTimer();
    void StopTimer();
private:
    pthread_t thread_timer;
    long m_second, m_microsecond;
    static void *OnTimer_stub(void *p)
    {
        (static_cast<CTimer*>(p))->thread_proc();
        return NULL;
    }
    void thread_proc();
    void OnTimer();
    FakeSensorHw *_dev;
};
}; //namespace RkCam
 
#endif