Skip to content

Commit 519dc37

Browse files
quariumcmassiot
authored andcommitted
upipe_audio_graph: support nv12 format
1 parent e835423 commit 519dc37

File tree

1 file changed

+37
-25
lines changed

1 file changed

+37
-25
lines changed

lib/upipe-filters/upipe_audio_graph.c

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/*
22
* Copyright (C) 2016 Open Broadcast Systems Ltd
33
* Copyright (C) 2016 OpenHeadend S.A.R.L.
4+
* Copyright (C) 2025 EasyTools
5+
*
46
*
57
* Authors: Rafaël Carré
68
* Christophe Massiot
@@ -215,12 +217,23 @@ static void copy_color(uint8_t **dst, size_t *strides,
215217
uint8_t *hsubs, uint8_t *vsubs, const uint8_t *color,
216218
unsigned row, unsigned col, unsigned w)
217219
{
218-
memset(&dst[0][(row / vsubs[0]) * strides[0] + col / hsubs[0]],
219-
color[0], w / hsubs[0]); // y8
220-
memset(&dst[1][(row / vsubs[1]) * strides[1] + col / hsubs[1]],
221-
color[1], w / hsubs[1]); // u8
222-
memset(&dst[2][(row / vsubs[2]) * strides[2] + col / hsubs[2]],
223-
color[2], w / hsubs[2]); // v8
220+
if (dst[0] != NULL)
221+
memset(&dst[0][(row / vsubs[0]) * strides[0] + col / hsubs[0]],
222+
color[0], w / hsubs[0]); // y8
223+
if (dst[1] != NULL)
224+
memset(&dst[1][(row / vsubs[1]) * strides[1] + col / hsubs[1]],
225+
color[1], w / hsubs[1]); // u8
226+
if (dst[2] != NULL)
227+
memset(&dst[2][(row / vsubs[2]) * strides[2] + col / hsubs[2]],
228+
color[2], w / hsubs[2]); // v8
229+
if (dst[3] != NULL) { // u8v8
230+
uint8_t *p =
231+
&dst[3][(row / vsubs[3]) * strides[3] + 2 * col / hsubs[3]];
232+
for (int i = 0; i < w / hsubs[3]; i++) {
233+
p[i * 2] = color[1];
234+
p[i * 2 + 1] = color[2];
235+
}
236+
}
224237
}
225238

226239
/** @internal @This handles data.
@@ -262,19 +275,19 @@ static bool upipe_agraph_handle(struct upipe *upipe, struct uref *uref,
262275
upipe_agraph->vsize);
263276
uref_attach_ubuf(uref, ubuf);
264277

265-
uint8_t *dst[4];
266-
size_t strides[4];
267-
uint8_t hsubs[4];
268-
uint8_t vsubs[4];
269-
static const char *chroma[3] = { "y8", "u8", "v8" };
270-
for (int i = 0; i < 3; i++) {
271-
if (unlikely(!ubase_check(uref_pic_plane_write(uref, chroma[i],
272-
0, 0, -1, -1, &dst[i])) ||
273-
!ubase_check(uref_pic_plane_size(uref, chroma[i],
274-
&strides[i], &hsubs[i], &vsubs[i], NULL)))) {
275-
upipe_throw_fatal(upipe, UBASE_ERR_ALLOC);
276-
uref_free(uref);
277-
return true;
278+
static const char *chroma[4] = { "y8", "u8", "v8", "u8v8" };
279+
#define NR_CHROMA UBASE_ARRAY_SIZE(chroma)
280+
uint8_t *dst[NR_CHROMA];
281+
size_t strides[NR_CHROMA];
282+
uint8_t hsubs[NR_CHROMA];
283+
uint8_t vsubs[NR_CHROMA];
284+
for (int i = 0; i < NR_CHROMA; i++) {
285+
if (unlikely(
286+
!ubase_check(uref_pic_plane_size(uref, chroma[i], &strides[i],
287+
&hsubs[i], &vsubs[i], NULL)) ||
288+
!ubase_check(uref_pic_plane_write(uref, chroma[i], 0, 0, -1, -1,
289+
&dst[i])))) {
290+
dst[i] = NULL;
278291
}
279292
}
280293

@@ -366,8 +379,10 @@ static bool upipe_agraph_handle(struct upipe *upipe, struct uref *uref,
366379
upipe_agraph->hsize);
367380
}
368381

369-
for (int i = 0; i < 3; i++)
370-
ubuf_pic_plane_unmap(ubuf, chroma[i], 0, 0, -1, -1);
382+
for (int i = 0; i < NR_CHROMA; i++)
383+
if (dst[i])
384+
ubuf_pic_plane_unmap(ubuf, chroma[i], 0, 0, -1, -1);
385+
371386
uref_pic_set_progressive(uref);
372387
upipe_agraph_output(upipe, uref, upump_p);
373388
return true;
@@ -403,11 +418,8 @@ static void upipe_agraph_input(struct upipe *upipe, struct uref *uref,
403418
static int upipe_agraph_check_flow_format(struct upipe *upipe,
404419
struct uref *flow_format)
405420
{
406-
if (flow_format != NULL) {
407-
if (unlikely(!ubase_check(uref_pic_flow_check_yuv420p(flow_format))))
408-
uref_pic_flow_set_yuv420p(flow_format);
421+
if (flow_format != NULL)
409422
upipe_agraph_require_ubuf_mgr(upipe, flow_format);
410-
}
411423

412424
return UBASE_ERR_NONE;
413425
}

0 commit comments

Comments
 (0)