liyujie
2025-08-28 786ff4f4ca2374bdd9177f2e24b503d43e7a3b93
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
/*
 * poll_thread.h - poll thread for event and buffer
 *
 *  Copyright (c) 2014-2015 Intel 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.
 *
 * Author: Wind Yuan <feng.yuan@intel.com>
 */
 
#ifndef XCAM_POLL_THREAD_H
#define XCAM_POLL_THREAD_H
 
#include <xcam_std.h>
#include <xcam_mutex.h>
#include <x3a_event.h>
#include <v4l2_buffer_proxy.h>
#include <x3a_stats_pool.h>
#include <v4l2_device.h>
#include <stats_callback_interface.h>
 
namespace XCam {
 
class PollCallback
{
public:
    PollCallback () {}
    virtual ~PollCallback() {}
    virtual XCamReturn poll_buffer_ready (SmartPtr<VideoBuffer> &buf) = 0;
    virtual XCamReturn poll_buffer_failed (int64_t timestamp, const char *msg) = 0;
 
private:
    XCAM_DEAD_COPY (PollCallback);
 
};
 
class V4l2Device;
class V4l2SubDevice;
class EventPollThread;
class CapturePollThread;
 
class PollThread
{
    friend class EventPollThread;
    friend class CapturePollThread;
    friend class FakePollThread;
public:
    explicit PollThread ();
    virtual ~PollThread ();
 
    bool set_capture_device (SmartPtr<V4l2Device> &dev);
    bool set_event_device (SmartPtr<V4l2SubDevice> &sub_dev);
    bool set_poll_callback (PollCallback *callback);
    bool set_stats_callback (StatsCallback *callback);
 
    virtual XCamReturn start();
    virtual XCamReturn stop ();
 
protected:
    XCamReturn poll_subdev_event_loop ();
    virtual XCamReturn poll_buffer_loop ();
 
    virtual XCamReturn handle_events (struct v4l2_event &event);
    XCamReturn handle_3a_stats_event (struct v4l2_event &event);
 
private:
    virtual XCamReturn init_3a_stats_pool ();
    virtual XCamReturn capture_3a_stats (SmartPtr<X3aStats> &stats);
 
private:
    XCAM_DEAD_COPY (PollThread);
 
private:
    static const int default_subdev_event_timeout;
    static const int default_capture_event_timeout;
 
    SmartPtr<EventPollThread>        _event_loop;
    SmartPtr<CapturePollThread>      _capture_loop;
 
    SmartPtr<V4l2SubDevice>          _event_dev;
    SmartPtr<V4l2Device>             _capture_dev;
 
    PollCallback                    *_poll_callback;
    StatsCallback                   *_stats_callback;
};
 
};
 
#endif //XCAM_POLL_THREAD_H