-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupipe-helper.c
188 lines (149 loc) · 4.73 KB
/
upipe-helper.c
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#include <upipe/upipe_helper_upipe.h>
#include <upipe/upipe_helper_urefcount.h>
#include <upipe/upipe_helper_output.h>
#include <upipe/upipe_helper_output_size.h>
#include <upipe/upipe_helper_input.h>
#include <upipe/upipe_helper_uclock.h>
#include <upipe/upipe_helper_upump_mgr.h>
#include <upipe/upipe_helper_uref_mgr.h>
#include <upipe/upipe_helper_ubuf_mgr.h>
#include <upipe/upipe_helper_bin_input.h>
#include <upipe/upipe_helper_bin_output.h>
#include <upipe/upipe_helper_sync.h>
#include <upipe/upipe_helper_uref_stream.h>
#include <upipe/upipe_helper_flow_def.h>
#include <upipe/upipe_helper_upump.h>
struct upipe_helper_mgr {
struct upipe_mgr mgr;
struct urefcount refcount;
urefcount_cb refcount_cb;
// uclock
upipe_helper_uclock_check uclock_check;
// uref_mgr
upipe_helper_uref_mgr_check uref_check;
// ubuf_mgr
upipe_helper_ubuf_mgr_check ubuf_check;
// input
bool (*output)(struct upipe *, struct uref *, struct upump **);
// uref_stream
void (*stream_append_cb)(struct upipe *);
};
struct upipe_helper {
// upipe
struct upipe upipe;
// urefcount
struct urefcount urefcount;
// output
struct upipe *output;
struct uref *flow_def;
enum upipe_helper_output_state output_state;
struct uchain request_list;
// output_size
unsigned int output_size;
// input
struct uchain urefs;
unsigned int nb_urefs;
unsigned int max_urefs;
struct uchain blockers;
// uclock
struct uclock *uclock;
struct urequest uclock_request;
// upump_mgr
struct upump_mgr *upump_mgr;
// uref_mgr
struct uref_mgr *uref_mgr;
struct urequest uref_mgr_request;
// ubuf_mgr
struct ubuf_mgr *ubuf_mgr;
struct uref *flow_format;
struct urequest ubuf_mgr_request;
// bin_input
struct upipe *first_inner;
struct uchain input_request_list;
// bin_output
struct uprobe last_inner_probe;
struct upipe *last_inner;
// sync
bool acquired;
// uref_stream
struct uref *next_uref;
size_t next_uref_size;
struct uchain stream_urefs;
// flow_def
struct uref *flow_def_input;
struct uref *flow_def_attr;
// upump
struct upump *upump;
};
static struct upipe_helper_mgr *upipe_helper_mgr(struct upipe *upipe)
{
return container_of(upipe->mgr, struct upipe_helper_mgr, mgr);
}
static bool output(struct upipe *upipe,
struct uref *uref,
struct upump **upump_p)
{
struct upipe_helper_mgr *mgr = upipe_helper_mgr(upipe);
if (mgr->output != NULL)
return mgr->output(upipe, uref, upump_p);
return false;
}
void upipe_helper_free(struct upipe *upipe)
{
struct upipe_helper_mgr *mgr = upipe_helper_mgr(upipe);
if (mgr->refcount_cb != NULL)
return mgr->refcount_cb(upipe->refcount);
}
static int check_uclock(struct upipe *upipe, struct uref *uref)
{
struct upipe_helper_mgr *mgr = upipe_helper_mgr(upipe);
if (mgr->uclock_check != NULL)
return mgr->uclock_check(upipe, uref);
return UBASE_ERR_NONE;
}
static int check_uref(struct upipe *upipe, struct uref *uref)
{
struct upipe_helper_mgr *mgr = upipe_helper_mgr(upipe);
if (mgr->uref_check != NULL)
return mgr->uref_check(upipe, uref);
return UBASE_ERR_NONE;
}
static int check_ubuf(struct upipe *upipe, struct uref *uref)
{
struct upipe_helper_mgr *mgr = upipe_helper_mgr(upipe);
if (mgr->ubuf_check != NULL)
return mgr->ubuf_check(upipe, uref);
return UBASE_ERR_NONE;
}
static void append_cb(struct upipe *upipe)
{
struct upipe_helper_mgr *mgr = upipe_helper_mgr(upipe);
if (mgr->stream_append_cb != NULL)
mgr->stream_append_cb(upipe);
}
UPIPE_HELPER_UPIPE(upipe_helper, upipe, upipe->mgr->signature);
UPIPE_HELPER_UREFCOUNT(upipe_helper, urefcount, upipe_helper_free);
UPIPE_HELPER_OUTPUT(upipe_helper, output, flow_def, output_state, request_list);
UPIPE_HELPER_OUTPUT_SIZE(upipe_helper, output_size);
UPIPE_HELPER_INPUT(upipe_helper, urefs, nb_urefs, max_urefs, blockers, output);
UPIPE_HELPER_UCLOCK(upipe_helper, uclock, uclock_request,
check_uclock,
upipe_helper_register_output_request,
upipe_helper_unregister_output_request);
UPIPE_HELPER_UPUMP_MGR(upipe_helper, upump_mgr);
UPIPE_HELPER_UREF_MGR(upipe_helper, uref_mgr, uref_mgr_request,
check_uref,
upipe_helper_register_output_request,
upipe_helper_unregister_output_request);
UPIPE_HELPER_UBUF_MGR(upipe_helper, ubuf_mgr, flow_format, ubuf_mgr_request,
check_ubuf,
upipe_helper_register_output_request,
upipe_helper_unregister_output_request);
UPIPE_HELPER_BIN_INPUT(upipe_helper, first_inner, input_request_list);
UPIPE_HELPER_BIN_OUTPUT(upipe_helper, last_inner_probe, last_inner,
output, request_list);
UPIPE_HELPER_SYNC(upipe_helper, acquired);
UPIPE_HELPER_UREF_STREAM(upipe_helper, next_uref, next_uref_size, stream_urefs,
append_cb);
UPIPE_HELPER_FLOW_DEF(upipe_helper, flow_def_input, flow_def_attr);
UPIPE_HELPER_UPUMP(upipe_helper, upump, upump_mgr);