|
1 | 1 | /* |
2 | 2 | * Copyright (C) 2016 Open Broadcast Systems Ltd |
3 | 3 | * Copyright (C) 2016 OpenHeadend S.A.R.L. |
| 4 | + * Copyright (C) 2025 EasyTools |
| 5 | + * |
4 | 6 | * |
5 | 7 | * Authors: Rafaël Carré |
6 | 8 | * Christophe Massiot |
@@ -215,12 +217,23 @@ static void copy_color(uint8_t **dst, size_t *strides, |
215 | 217 | uint8_t *hsubs, uint8_t *vsubs, const uint8_t *color, |
216 | 218 | unsigned row, unsigned col, unsigned w) |
217 | 219 | { |
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 | + } |
224 | 237 | } |
225 | 238 |
|
226 | 239 | /** @internal @This handles data. |
@@ -262,19 +275,19 @@ static bool upipe_agraph_handle(struct upipe *upipe, struct uref *uref, |
262 | 275 | upipe_agraph->vsize); |
263 | 276 | uref_attach_ubuf(uref, ubuf); |
264 | 277 |
|
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; |
278 | 291 | } |
279 | 292 | } |
280 | 293 |
|
@@ -366,8 +379,10 @@ static bool upipe_agraph_handle(struct upipe *upipe, struct uref *uref, |
366 | 379 | upipe_agraph->hsize); |
367 | 380 | } |
368 | 381 |
|
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 | + |
371 | 386 | uref_pic_set_progressive(uref); |
372 | 387 | upipe_agraph_output(upipe, uref, upump_p); |
373 | 388 | return true; |
@@ -403,11 +418,8 @@ static void upipe_agraph_input(struct upipe *upipe, struct uref *uref, |
403 | 418 | static int upipe_agraph_check_flow_format(struct upipe *upipe, |
404 | 419 | struct uref *flow_format) |
405 | 420 | { |
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) |
409 | 422 | upipe_agraph_require_ubuf_mgr(upipe, flow_format); |
410 | | - } |
411 | 423 |
|
412 | 424 | return UBASE_ERR_NONE; |
413 | 425 | } |
|
0 commit comments