• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <x3a_event.h>
27 #include <v4l2_buffer_proxy.h>
28 #include <x3a_stats_pool.h>
29 #include <v4l2_device.h>
30 #include <stats_callback_interface.h>
31 
32 namespace XCam {
33 
34 class PollCallback
35 {
36 public:
PollCallback()37     PollCallback () {}
~PollCallback()38     virtual ~PollCallback() {}
39     virtual XCamReturn poll_buffer_ready (SmartPtr<VideoBuffer> &buf) = 0;
40     virtual XCamReturn poll_buffer_failed (int64_t timestamp, const char *msg) = 0;
41 
42 private:
43     XCAM_DEAD_COPY (PollCallback);
44 
45 };
46 
47 class V4l2Device;
48 class V4l2SubDevice;
49 class EventPollThread;
50 class CapturePollThread;
51 
52 class PollThread
53 {
54     friend class EventPollThread;
55     friend class CapturePollThread;
56     friend class FakePollThread;
57 public:
58     explicit PollThread ();
59     virtual ~PollThread ();
60 
61     bool set_capture_device (SmartPtr<V4l2Device> &dev);
62     bool set_event_device (SmartPtr<V4l2SubDevice> &sub_dev);
63     bool set_poll_callback (PollCallback *callback);
64     bool set_stats_callback (StatsCallback *callback);
65 
66     virtual XCamReturn start();
67     virtual XCamReturn stop ();
68 
69 protected:
70     XCamReturn poll_subdev_event_loop ();
71     virtual XCamReturn poll_buffer_loop ();
72 
73     virtual XCamReturn handle_events (struct v4l2_event &event);
74     XCamReturn handle_3a_stats_event (struct v4l2_event &event);
75 
76 private:
77     virtual XCamReturn init_3a_stats_pool ();
78     virtual XCamReturn capture_3a_stats (SmartPtr<X3aStats> &stats);
79 
80 private:
81     XCAM_DEAD_COPY (PollThread);
82 
83 private:
84     static const int default_subdev_event_timeout;
85     static const int default_capture_event_timeout;
86 
87     SmartPtr<EventPollThread>        _event_loop;
88     SmartPtr<CapturePollThread>      _capture_loop;
89 
90     SmartPtr<V4l2SubDevice>          _event_dev;
91     SmartPtr<V4l2Device>             _capture_dev;
92 
93     PollCallback                    *_poll_callback;
94     StatsCallback                   *_stats_callback;
95 };
96 
97 };
98 
99 #endif //XCAM_POLL_THREAD_H
100