xref: /OK3568_Linux_fs/external/camera_engine_rkaiq/rkaiq/xcore/poll_thread.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * poll_thread.h - poll thread for event and buffer
3  *
4  *  Copyright (c) 2014-2015 Intel Corporation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * Author: Wind Yuan <feng.yuan@intel.com>
19  */
20 
21 #ifndef XCAM_POLL_THREAD_H
22 #define XCAM_POLL_THREAD_H
23 
24 #include <xcam_std.h>
25 #include <xcam_mutex.h>
26 #include <v4l2_buffer_proxy.h>
27 #include <v4l2_device.h>
28 #include "xcam_thread.h"
29 #include "rk_aiq_types_priv.h"
30 
31 namespace XCam {
32 
33 class PollCallback
34 {
35 public:
PollCallback()36     PollCallback () {}
~PollCallback()37     virtual ~PollCallback() {}
38     virtual XCamReturn poll_buffer_ready (SmartPtr<VideoBuffer> &buf, int type) = 0;
39     virtual XCamReturn poll_buffer_failed (int64_t timestamp, const char *msg) = 0;
40     virtual XCamReturn poll_event_ready (uint32_t sequence, int type) = 0;
41     virtual XCamReturn poll_event_failed (int64_t timestamp, const char *msg) = 0;
42     virtual XCamReturn poll_buffer_ready (SmartPtr<VideoBuffer> &buf) = 0;
43     virtual XCamReturn poll_buffer_ready (SmartPtr<V4l2BufferProxy> &buf, int dev_index) = 0;
44 
45 private:
46     XCAM_DEAD_COPY (PollCallback);
47 
48 };
49 
50 class V4l2Device;
51 class V4l2SubDevice;
52 class IspPollThread;
53 class EventPollThread;
54 class Thread;
55 
56 class PollThread
57 {
58     friend class IspPollThread;
59     friend class EventPollThread;
60     friend class FakePollThread;
61 public:
62     explicit PollThread ();
63     virtual ~PollThread ();
64 
65     bool set_isp_params_devices (SmartPtr<V4l2Device> &params_dev,
66                                  SmartPtr<V4l2Device> &post_params_dev);
67     bool set_event_device (SmartPtr<V4l2SubDevice> &sub_dev);
68     bool set_isp_luma_device (SmartPtr<V4l2Device> &dev);
69     bool set_ispp_stats_device (SmartPtr<V4l2Device> &dev);
70     bool set_isp_stats_device (SmartPtr<V4l2Device> &dev);
71     bool set_poll_callback (PollCallback *callback);
72 
73     virtual XCamReturn start();
74     virtual XCamReturn stop ();
75 
76     static const char* isp_poll_type_to_str[ISP_POLL_POST_MAX];
77 protected:
78     XCamReturn poll_subdev_event_loop ();
79     virtual XCamReturn poll_buffer_loop (int type);
80 
81     virtual XCamReturn handle_events (struct v4l2_event &event);
82     XCamReturn handle_frame_sync_event (struct v4l2_event &event);
83     virtual SmartPtr<VideoBuffer> new_video_buffer(SmartPtr<V4l2Buffer> buf,
84             SmartPtr<V4l2Device> dev,
85             int type);
86     virtual XCamReturn notify_sof (uint64_t time, uint32_t frameid);
87 
88 private:
89     XCamReturn create_stop_fds ();
90     void destroy_stop_fds ();
91 
92 private:
93     XCAM_DEAD_COPY (PollThread);
94 
95 protected:
96     static const int default_poll_timeout;
97 
98     SmartPtr<Thread>      _ispp_stats_loop;
99     SmartPtr<Thread>      _isp_luma_loop;
100     SmartPtr<Thread>      _isp_stats_loop;
101     SmartPtr<Thread>      _event_loop;
102     SmartPtr<Thread>      _isp_params_loop;
103     SmartPtr<Thread>      _isp_pparams_loop;
104 
105     SmartPtr<V4l2SubDevice>          _event_dev;
106     SmartPtr<V4l2Device>             _isp_params_dev;
107     SmartPtr<V4l2Device>             _isp_pparams_dev;
108     SmartPtr<V4l2Device>             _isp_stats_dev;
109     SmartPtr<V4l2Device>             _isp_luma_dev;
110     SmartPtr<V4l2Device>             _ispp_stats_dev;
111 
112     PollCallback                    *_poll_callback;
113 
114     //frame syncronization
115     uint32_t frameid;
116 
117     int _ispp_poll_stop_fd[2];
118     int _luma_poll_stop_fd[2];
119     int _3a_stats_poll_stop_fd[2];
120     int _event_poll_stop_fd[2];
121     int _isp_params_poll_stop_fd[2];
122     int _isp_pparams_poll_stop_fd[2];
123 };
124 
125 }
126 
127 #endif //XCAM_POLL_THREAD_H
128