Skip to content

Commit 5dbcefb

Browse files
ntocmassiot
authored andcommitted
luajit: add support for flow_format helper
1 parent 23571ce commit 5dbcefb

File tree

3 files changed

+55
-15
lines changed

3 files changed

+55
-15
lines changed

include/upipe/upipe_helper_flow_format.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ typedef int (*upipe_helper_flow_format_register)(struct upipe *,
7777
* Internal function called when the request is answered.
7878
*
7979
* @item @code
80-
* int upipe_foo_require_flow_format(struct upipe *upipe,
81-
* struct uref *flow_format)
80+
* void upipe_foo_require_flow_format(struct upipe *upipe,
81+
* struct uref *flow_format)
8282
* @end code
8383
* Initializes and registers the request to get a flow format. The base flow
8484
* format belongs to the callee and will be eventually freed.

luajit/upipe-helper.c

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "upipe/upipe_helper_sync.h"
1414
#include "upipe/upipe_helper_uref_stream.h"
1515
#include "upipe/upipe_helper_flow_def.h"
16+
#include "upipe/upipe_helper_flow_format.h"
1617
#include "upipe/upipe_helper_upump.h"
1718

1819
struct upipe_helper_mgr {
@@ -24,10 +25,13 @@ struct upipe_helper_mgr {
2425
upipe_helper_uclock_check uclock_check;
2526

2627
// uref_mgr
27-
upipe_helper_uref_mgr_check uref_check;
28+
upipe_helper_uref_mgr_check uref_mgr_check;
2829

2930
// ubuf_mgr
30-
upipe_helper_ubuf_mgr_check ubuf_check;
31+
upipe_helper_ubuf_mgr_check ubuf_mgr_check;
32+
33+
// flow_format
34+
upipe_helper_flow_format_check flow_format_check;
3135

3236
// input
3337
bool (*output)(struct upipe *, struct uref *, struct upump **);
@@ -95,6 +99,9 @@ struct upipe_helper {
9599
struct uref *flow_def_input;
96100
struct uref *flow_def_attr;
97101

102+
// flow_format
103+
struct urequest flow_format_request;
104+
98105
// upump
99106
struct upump *upump;
100107
};
@@ -135,28 +142,39 @@ static int check_uclock(struct upipe *upipe, struct uref *uref)
135142
return UBASE_ERR_NONE;
136143
}
137144

138-
static int check_uref(struct upipe *upipe, struct uref *uref)
145+
static int check_uref_mgr(struct upipe *upipe, struct uref *uref)
139146
{
140147
struct upipe_helper_mgr *mgr = upipe_helper_mgr(upipe);
141148

142-
if (mgr->uref_check != NULL)
143-
return mgr->uref_check(upipe, uref);
149+
if (mgr->uref_mgr_check != NULL)
150+
return mgr->uref_mgr_check(upipe, uref);
144151

145152
uref_free(uref);
146153
return UBASE_ERR_NONE;
147154
}
148155

149-
static int check_ubuf(struct upipe *upipe, struct uref *uref)
156+
static int check_ubuf_mgr(struct upipe *upipe, struct uref *uref)
150157
{
151158
struct upipe_helper_mgr *mgr = upipe_helper_mgr(upipe);
152159

153-
if (mgr->ubuf_check != NULL)
154-
return mgr->ubuf_check(upipe, uref);
160+
if (mgr->ubuf_mgr_check != NULL)
161+
return mgr->ubuf_mgr_check(upipe, uref);
155162

156163
uref_free(uref);
157164
return UBASE_ERR_NONE;
158165
}
159166

167+
static int check_flow_format(struct upipe *upipe, struct uref *flow_format)
168+
{
169+
struct upipe_helper_mgr *mgr = upipe_helper_mgr(upipe);
170+
171+
if (mgr->flow_format_check != NULL)
172+
return mgr->flow_format_check(upipe, flow_format);
173+
174+
uref_free(flow_format);
175+
return UBASE_ERR_NONE;
176+
}
177+
160178
static void append_cb(struct upipe *upipe)
161179
{
162180
struct upipe_helper_mgr *mgr = upipe_helper_mgr(upipe);
@@ -179,11 +197,11 @@ UPIPE_HELPER_UCLOCK(upipe_helper, uclock, uclock_request,
179197
upipe_helper_unregister_output_request);
180198
UPIPE_HELPER_UPUMP_MGR(upipe_helper, upump_mgr);
181199
UPIPE_HELPER_UREF_MGR(upipe_helper, uref_mgr, uref_mgr_request,
182-
check_uref,
200+
check_uref_mgr,
183201
upipe_helper_register_output_request,
184202
upipe_helper_unregister_output_request);
185203
UPIPE_HELPER_UBUF_MGR(upipe_helper, ubuf_mgr, flow_format, ubuf_mgr_request,
186-
check_ubuf,
204+
check_ubuf_mgr,
187205
upipe_helper_register_output_request,
188206
upipe_helper_unregister_output_request);
189207
UPIPE_HELPER_INNER(upipe_helper, first_inner);
@@ -194,4 +212,8 @@ UPIPE_HELPER_SYNC(upipe_helper, acquired);
194212
UPIPE_HELPER_UREF_STREAM(upipe_helper, next_uref, next_uref_size, stream_urefs,
195213
append_cb);
196214
UPIPE_HELPER_FLOW_DEF(upipe_helper, flow_def_input, flow_def_attr);
215+
UPIPE_HELPER_FLOW_FORMAT(upipe_helper, flow_format_request,
216+
check_flow_format,
217+
upipe_helper_register_output_request,
218+
upipe_helper_unregister_output_request);
197219
UPIPE_HELPER_UPUMP(upipe_helper, upump, upump_mgr);

luajit/upipe.lua

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -603,10 +603,24 @@ local function control_args(cmd, args)
603603
return va_args(args, unpack(ctrl_args[cmd]))
604604
end
605605

606+
local function wrap_check(f)
607+
if not f then return end
608+
return wrap_traceback(function (...)
609+
return ubase_err(f(...))
610+
end)
611+
end
612+
606613
local function upipe_helper_alloc(cb)
607614
local ct = ffi.typeof("struct upipe_helper_mgr")
608615
local h_mgr = ffi.cast(ffi.typeof("$ *", ct), C.calloc(1, ffi.sizeof(ct)))
609616

617+
if cb.check then
618+
h_mgr.uclock_check = wrap_check(cb.check.uclock)
619+
h_mgr.uref_mgr_check = wrap_check(cb.check.uref_mgr)
620+
h_mgr.ubuf_mgr_check = wrap_check(cb.check.ubuf_mgr)
621+
h_mgr.flow_format_check = wrap_check(cb.check.flow_format)
622+
end
623+
610624
if cb.input_output then
611625
h_mgr.output = cb.input_output
612626
end
@@ -634,6 +648,7 @@ local function upipe_helper_alloc(cb)
634648
pipe:helper_init_sync()
635649
pipe:helper_init_uref_stream()
636650
pipe:helper_init_flow_def()
651+
pipe:helper_init_flow_format()
637652
pipe:helper_init_upump()
638653
props_init(pipe)
639654
pipe.props.helper = h_pipe
@@ -783,6 +798,7 @@ local function upipe_helper_alloc(cb)
783798
pipe:throw_dead()
784799
props[k] = nil
785800
pipe:helper_clean_upump()
801+
pipe:helper_clean_flow_format()
786802
pipe:helper_clean_flow_def()
787803
pipe:helper_clean_uref_stream()
788804
pipe:helper_clean_sync()
@@ -807,9 +823,11 @@ local function upipe_helper_alloc(cb)
807823
props_destroy(mgr)
808824
mgr.upipe_alloc:free()
809825
mgr.upipe_control:free()
810-
if mgr.upipe_input ~= nil then
811-
mgr.upipe_input:free()
812-
end
826+
if mgr.upipe_input ~= nil then mgr.upipe_input:free() end
827+
if h_mgr.uclock_check ~= nil then h_mgr.uclock_check:free() end
828+
if h_mgr.uref_mgr_check ~= nil then h_mgr.uref_mgr_check:free() end
829+
if h_mgr.ubuf_mgr_check ~= nil then h_mgr.ubuf_mgr_check:free() end
830+
if h_mgr.flow_format_check ~= nil then h_mgr.flow_format_check:free() end
813831
h_mgr.refcount_cb:free()
814832
refcount_cb:free()
815833
C.free(ffi.cast("void *", h_mgr))

0 commit comments

Comments
 (0)