UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
from_lavc_vid_conv.c
Go to the documentation of this file.
1
6/*
7 * Copyright (c) 2013-2024 CESNET, z. s. p. o.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, is permitted provided that the following conditions
12 * are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 *
21 * 3. Neither the name of CESNET nor the names of its contributors may be
22 * used to endorse or promote products derived from this software without
23 * specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
27 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
28 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
29 * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
30 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
35 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
36 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */
47#include <assert.h>
48#include <libavutil/pixfmt.h>
49#include <libavutil/hwcontext_drm.h>
50#include <stdbool.h>
51#include <stdint.h>
52
53#include "color.h"
54#include "compat/qsort_s.h"
55#include "debug.h"
56#include "host.h"
57#include "hwaccel_vdpau.h"
58#include "hwaccel_drm.h"
62#include "pixfmt_conv.h"
63#include "utils/macros.h" // OPTIMIZED_FOR
64#include "utils/misc.h" // get_cpu_core_count
65#include "utils/worker.h" // task_run_parallel
66#include "video.h"
67
68#ifdef __SSE3__
69#include "pmmintrin.h"
70#endif
71
72#define MOD_NAME "[from_lavc_vid_conv] "
73
74#ifdef WORDS_BIGENDIAN
75#define BYTE_SWAP(x) (3 - x)
76#else
77#define BYTE_SWAP(x) x
78#endif
79
80// shortcuts
81#define R R_SHIFT_IDX
82#define G G_SHIFT_IDX
83#define B B_SHIFT_IDX
84
85#define MK_RGBA(r, g, b, alpha_mask, depth) \
86 FORMAT_RGBA((r), (g), (b), (rgb_shift)[R], (rgb_shift)[G], \
87 (rgb_shift)[B], (alpha_mask), (depth))
88
89#pragma GCC diagnostic push
90#pragma GCC diagnostic ignored "-Wunknown-pragmas"
91#pragma clang diagnostic warning "-Wpass-failed"
92
93static void nv12_to_uyvy(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
94 int width, int height, int pitch, const int * __restrict rgb_shift)
95{
96 UNUSED(rgb_shift);
97 for(int y = 0; y < (int) height; ++y) {
98 char *src_y = (char *) in_frame->data[0] + in_frame->linesize[0] * y;
99 char *src_cbcr = (char *) in_frame->data[1] + in_frame->linesize[1] * (y / 2);
100 char *dst = dst_buffer + pitch * y;
101
102 OPTIMIZED_FOR (int x = 0; x < width / 2; ++x) {
103 *dst++ = *src_cbcr++;
104 *dst++ = *src_y++;
105 *dst++ = *src_cbcr++;
106 *dst++ = *src_y++;
107 }
108 }
109}
110
111static void rgb24_to_uyvy(char * __restrict dst_buffer, AVFrame * __restrict frame,
112 int width, int height, int pitch, const int * __restrict rgb_shift)
113{
114 UNUSED(rgb_shift);
116 for (int y = 0; y < height; ++y) {
117 vc_copylineRGBtoUYVY((unsigned char *) dst_buffer + y * pitch, frame->data[0] + y * frame->linesize[0], vc_get_linesize(width, UYVY), 0, 0, 0);
118 }
119}
120
121static void memcpy_data(char * __restrict dst_buffer, AVFrame * __restrict frame,
122 int width, int height, int pitch, const int * __restrict rgb_shift) __attribute__((unused));
123static void memcpy_data(char * __restrict dst_buffer, AVFrame * __restrict frame,
124 int width, int height, int pitch, const int * __restrict rgb_shift)
125{
126 UNUSED(rgb_shift);
127 UNUSED(width);
128 for (int comp = 0; comp < AV_NUM_DATA_POINTERS; ++comp) {
129 if (frame->data[comp] == NULL) {
130 break;
131 }
132 for (int y = 0; y < height; ++y) {
133 memcpy(dst_buffer + y * pitch, frame->data[comp] + y * frame->linesize[comp],
134 frame->linesize[comp]);
135 }
136 }
137}
138
139static void rgb24_to_rgb32(char * __restrict dst_buffer, AVFrame * __restrict frame,
140 int width, int height, int pitch, const int * __restrict rgb_shift)
141{
142 for (int y = 0; y < height; ++y) {
143 vc_copylineRGBtoRGBA((unsigned char *) dst_buffer + y * pitch, frame->data[0] + y * frame->linesize[0],
144 vc_get_linesize(width, RGBA), rgb_shift[0], rgb_shift[1], rgb_shift[2]);
145 }
146}
147
148static void gbrp_to_rgb(char * __restrict dst_buffer, AVFrame * __restrict frame,
149 int width, int height, int pitch, const int * __restrict rgb_shift)
150{
151 UNUSED(rgb_shift);
152 for (int y = 0; y < height; ++y) {
153
154 OPTIMIZED_FOR (int x = 0; x < width; ++x) {
155 uint8_t *buf = (uint8_t *) dst_buffer + y * pitch + x * 3;
156 int src_idx = y * frame->linesize[0] + x;
157 buf[0] = frame->data[2][src_idx]; // R
158 buf[1] = frame->data[0][src_idx]; // G
159 buf[2] = frame->data[1][src_idx]; // B
160 }
161 }
162}
163
164static void gbrp_to_rgba(char * __restrict dst_buffer, AVFrame * __restrict frame,
165 int width, int height, int pitch, const int * __restrict rgb_shift)
166{
167 assert((uintptr_t) dst_buffer % 4 == 0);
168 uint32_t alpha_mask = 0xFFFFFFFFU ^ (0xFFU << rgb_shift[R]) ^ (0xFFU << rgb_shift[G]) ^ (0xFFU << rgb_shift[B]);
169
170 for (int y = 0; y < height; ++y) {
171 uint32_t *line = (uint32_t *)(void *) (dst_buffer + y * pitch);
172 int src_idx = y * frame->linesize[0];
173
174 OPTIMIZED_FOR (int x = 0; x < width; ++x) {
175 *line++ = alpha_mask |
176 frame->data[2][src_idx] << rgb_shift[R] |
177 frame->data[0][src_idx] << rgb_shift[G] |
178 frame->data[1][src_idx] << rgb_shift[B];
179 src_idx += 1;
180 }
181 }
182}
183
184#if defined __GNUC__
185static inline void gbrap_to_rgb_rgba(char * __restrict dst_buffer, AVFrame * __restrict frame,
186 int width, int height, int pitch, const int * __restrict rgb_shift, int comp_count)
187 __attribute__((always_inline));
188#endif
189static inline void gbrap_to_rgb_rgba(char * __restrict dst_buffer, AVFrame * __restrict frame,
190 int width, int height, int pitch, const int * __restrict rgb_shift, int comp_count)
191{
192 assert(rgb_shift[R] == DEFAULT_R_SHIFT && rgb_shift[G] == DEFAULT_G_SHIFT && rgb_shift[B] == DEFAULT_B_SHIFT);
193 for (int y = 0; y < height; ++y) {
194 OPTIMIZED_FOR (int x = 0; x < width; ++x) {
195 uint8_t *buf = (uint8_t *) dst_buffer + y * pitch + x * comp_count;
196 int src_idx = y * frame->linesize[0] + x;
197 buf[0] = frame->data[2][src_idx]; // R
198 buf[1] = frame->data[0][src_idx]; // G
199 buf[2] = frame->data[1][src_idx]; // B
200 if (comp_count == 4) {
201 buf[3] = frame->data[3][src_idx]; // A
202 }
203 }
204 }
205}
206
207static void gbrap_to_rgba(char * __restrict dst_buffer, AVFrame * __restrict frame,
208 int width, int height, int pitch, const int * __restrict rgb_shift)
209{
210 gbrap_to_rgb_rgba(dst_buffer, frame, width, height, pitch, rgb_shift, 4);
211}
212
213static void gbrap_to_rgb(char * __restrict dst_buffer, AVFrame * __restrict frame,
214 int width, int height, int pitch, const int * __restrict rgb_shift)
215{
216 gbrap_to_rgb_rgba(dst_buffer, frame, width, height, pitch, rgb_shift, 3);
217}
218
219#if defined __GNUC__
220static inline void gbrpXXle_to_r10k(char * __restrict dst_buffer, AVFrame * __restrict frame,
221 int width, int height, int pitch, const int * __restrict rgb_shift, unsigned int in_depth)
222 __attribute__((always_inline));
223#endif
224static inline void gbrpXXle_to_r10k(char * __restrict dst_buffer, AVFrame * __restrict frame,
225 int width, int height, int pitch, const int * __restrict rgb_shift, unsigned int in_depth)
226{
227 assert((uintptr_t) frame->linesize[0] % 2 == 0);
228 assert((uintptr_t) frame->linesize[1] % 2 == 0);
229 assert((uintptr_t) frame->linesize[2] % 2 == 0);
230
231 UNUSED(rgb_shift);
232 for (int y = 0; y < height; ++y) {
233 uint16_t *src_g = (uint16_t *)(void *) (frame->data[0] + frame->linesize[0] * y);
234 uint16_t *src_b = (uint16_t *)(void *) (frame->data[1] + frame->linesize[1] * y);
235 uint16_t *src_r = (uint16_t *)(void *) (frame->data[2] + frame->linesize[2] * y);
236 unsigned char *dst = (unsigned char *) dst_buffer + y * pitch;
237
238 OPTIMIZED_FOR (int x = 0; x < width; ++x) {
239 *dst++ = *src_r >> (in_depth - 8U);
240 *dst++ = ((*src_r++ >> (in_depth - 10U)) & 0x3U) << 6U | *src_g >> (in_depth - 6U);
241 *dst++ = ((*src_g++ >> (in_depth - 10U)) & 0xFU) << 4U | *src_b >> (in_depth - 4U);
242 *dst++ = ((*src_b++ >> (in_depth - 10U)) & 0x3FU) << 2U | 0x3U;
243 }
244 }
245}
246
247static void gbrp10le_to_r10k(char * __restrict dst_buffer, AVFrame * __restrict frame,
248 int width, int height, int pitch, const int * __restrict rgb_shift)
249{
250 gbrpXXle_to_r10k(dst_buffer, frame, width, height, pitch, rgb_shift, 10U);
251}
252
253static void gbrp16le_to_r10k(char * __restrict dst_buffer, AVFrame * __restrict frame,
254 int width, int height, int pitch, const int * __restrict rgb_shift)
255{
256 gbrpXXle_to_r10k(dst_buffer, frame, width, height, pitch, rgb_shift, 16U);
257}
258
259#if defined __GNUC__
260static inline void yuv444pXXle_to_r10k(int depth, char * __restrict dst_buffer, AVFrame * __restrict frame,
261 int width, int height, int pitch, const int * __restrict rgb_shift)
262 __attribute__((always_inline));
263#endif
264static inline void yuv444pXXle_to_r10k(int depth, char * __restrict dst_buffer, AVFrame * __restrict frame,
265 int width, int height, int pitch, const int * __restrict rgb_shift)
266{
267 assert((uintptr_t) frame->linesize[0] % 2 == 0);
268 assert((uintptr_t) frame->linesize[1] % 2 == 0);
269 assert((uintptr_t) frame->linesize[2] % 2 == 0);
270
271 UNUSED(rgb_shift);
272 for (int y = 0; y < height; ++y) {
273 uint16_t *src_y = (uint16_t *)(void *) (frame->data[0] + frame->linesize[0] * y);
274 uint16_t *src_cb = (uint16_t *)(void *) (frame->data[1] + frame->linesize[1] * y);
275 uint16_t *src_cr = (uint16_t *)(void *) (frame->data[2] + frame->linesize[2] * y);
276 unsigned char *dst = (unsigned char *) dst_buffer + y * pitch;
277
278 OPTIMIZED_FOR (int x = 0; x < width; ++x) {
279 comp_type_t y = (Y_SCALE(depth) * (*src_y++ - (1<<(depth-4))));
280 comp_type_t cr = *src_cr++ - (1<<(depth-1));
281 comp_type_t cb = *src_cb++ - (1<<(depth-1));
282
283 comp_type_t r = YCBCR_TO_R_709_SCALED(depth, y, cb, cr) >> (COMP_BASE-10+depth);
284 comp_type_t g = YCBCR_TO_G_709_SCALED(depth, y, cb, cr) >> (COMP_BASE-10+depth);
285 comp_type_t b = YCBCR_TO_B_709_SCALED(depth, y, cb, cr) >> (COMP_BASE-10+depth);
286 // r g b is now on 10 bit scale
287
288 r = CLAMP_FULL(r, 10);
289 g = CLAMP_FULL(g, 10);
290 b = CLAMP_FULL(b, 10);
291
292 *dst++ = r >> 2;
293 *dst++ = (r & 0x3) << 6 | g >> 4;
294 *dst++ = (g & 0xF) << 4 | b >> 6;
295 *dst++ = (b & 0x3F) << 2 | 0x3U;
296 }
297 }
298}
299
300static void yuv444p10le_to_r10k(char * __restrict dst_buffer, AVFrame * __restrict frame,
301 int width, int height, int pitch, const int * __restrict rgb_shift)
302{
303 yuv444pXXle_to_r10k(10, dst_buffer, frame, width, height, pitch, rgb_shift);
304}
305
306static void yuv444p12le_to_r10k(char * __restrict dst_buffer, AVFrame * __restrict frame,
307 int width, int height, int pitch, const int * __restrict rgb_shift)
308{
309 yuv444pXXle_to_r10k(12, dst_buffer, frame, width, height, pitch, rgb_shift);
310}
311
312static void yuv444p16le_to_r10k(char * __restrict dst_buffer, AVFrame * __restrict frame,
313 int width, int height, int pitch, const int * __restrict rgb_shift)
314{
315 yuv444pXXle_to_r10k(16, dst_buffer, frame, width, height, pitch, rgb_shift);
316}
317
318#if defined __GNUC__
319static inline void yuv444pXXle_to_r12l(int depth, char * __restrict dst_buffer, AVFrame * __restrict frame,
320 int width, int height, int pitch, const int * __restrict rgb_shift)
321 __attribute__((always_inline));
322#endif
323static inline void yuv444pXXle_to_r12l(int depth, char * __restrict dst_buffer, AVFrame * __restrict frame,
324 int width, int height, int pitch, const int * __restrict rgb_shift)
325{
326 assert((uintptr_t) frame->linesize[0] % 2 == 0);
327 assert((uintptr_t) frame->linesize[1] % 2 == 0);
328 assert((uintptr_t) frame->linesize[2] % 2 == 0);
329
330 UNUSED(rgb_shift);
331 for (int y = 0; y < height; ++y) {
332 uint16_t *src_y = (uint16_t *)(void *) (frame->data[0] + frame->linesize[0] * y);
333 uint16_t *src_cb = (uint16_t *)(void *) (frame->data[1] + frame->linesize[1] * y);
334 uint16_t *src_cr = (uint16_t *)(void *) (frame->data[2] + frame->linesize[2] * y);
335 unsigned char *dst = (unsigned char *) dst_buffer + y * pitch;
336
337 for (int x = 0; x < width; x += 8) {
338 comp_type_t r[8];
339 comp_type_t g[8];
340 comp_type_t b[8];
341 OPTIMIZED_FOR (int j = 0; j < 8; ++j) {
342 comp_type_t y = (Y_SCALE(depth) * (*src_y++ - (1<<(depth-4))));
343 comp_type_t cr = *src_cr++ - (1<<(depth-1));
344 comp_type_t cb = *src_cb++ - (1<<(depth-1));
345 comp_type_t rr = YCBCR_TO_R_709_SCALED(depth, y, cb, cr) >> (COMP_BASE-12+depth);
346 comp_type_t gg = YCBCR_TO_G_709_SCALED(depth, y, cb, cr) >> (COMP_BASE-12+depth);
347 comp_type_t bb = YCBCR_TO_B_709_SCALED(depth, y, cb, cr) >> (COMP_BASE-12+depth);
348 r[j] = CLAMP_FULL(rr, 12);
349 g[j] = CLAMP_FULL(gg, 12);
350 b[j] = CLAMP_FULL(bb, 12);
351 }
352
353 dst[BYTE_SWAP(0)] = r[0] & 0xff;
354 dst[BYTE_SWAP(1)] = (g[0] & 0xf) << 4 | r[0] >> 8;
355 dst[BYTE_SWAP(2)] = g[0] >> 4;
356 dst[BYTE_SWAP(3)] = b[0] & 0xff;
357 dst[4 + BYTE_SWAP(0)] = (r[1] & 0xf) << 4 | b[0] >> 8;
358 dst[4 + BYTE_SWAP(1)] = r[1] >> 4;
359 dst[4 + BYTE_SWAP(2)] = g[1] & 0xff;
360 dst[4 + BYTE_SWAP(3)] = (b[1] & 0xf) << 4 | g[1] >> 8;
361 dst[8 + BYTE_SWAP(0)] = b[1] >> 4;
362 dst[8 + BYTE_SWAP(1)] = r[2] & 0xff;
363 dst[8 + BYTE_SWAP(2)] = (g[2] & 0xf) << 4 | r[2] >> 8;
364 dst[8 + BYTE_SWAP(3)] = g[2] >> 4;
365 dst[12 + BYTE_SWAP(0)] = b[2] & 0xff;
366 dst[12 + BYTE_SWAP(1)] = (r[3] & 0xf) << 4 | b[2] >> 8;
367 dst[12 + BYTE_SWAP(2)] = r[3] >> 4;
368 dst[12 + BYTE_SWAP(3)] = g[3] & 0xff;
369 dst[16 + BYTE_SWAP(0)] = (b[3] & 0xf) << 4 | g[3] >> 8;
370 dst[16 + BYTE_SWAP(1)] = b[3] >> 4;
371 dst[16 + BYTE_SWAP(2)] = r[4] & 0xff;
372 dst[16 + BYTE_SWAP(3)] = (g[4] & 0xf) << 4 | r[4] >> 8;
373 dst[20 + BYTE_SWAP(0)] = g[4] >> 4;
374 dst[20 + BYTE_SWAP(1)] = b[4] & 0xff;
375 dst[20 + BYTE_SWAP(2)] = (r[5] & 0xf) << 4 | b[4] >> 8;
376 dst[20 + BYTE_SWAP(3)] = r[5] >> 4;;
377 dst[24 + BYTE_SWAP(0)] = g[5] & 0xff;
378 dst[24 + BYTE_SWAP(1)] = (b[5] & 0xf) << 4 | g[5] >> 8;
379 dst[24 + BYTE_SWAP(2)] = b[5] >> 4;
380 dst[24 + BYTE_SWAP(3)] = r[6] & 0xff;
381 dst[28 + BYTE_SWAP(0)] = (g[6] & 0xf) << 4 | r[6] >> 8;
382 dst[28 + BYTE_SWAP(1)] = g[6] >> 4;
383 dst[28 + BYTE_SWAP(2)] = b[6] & 0xff;
384 dst[28 + BYTE_SWAP(3)] = (r[7] & 0xf) << 4 | b[6] >> 8;
385 dst[32 + BYTE_SWAP(0)] = r[7] >> 4;
386 dst[32 + BYTE_SWAP(1)] = g[7] & 0xff;
387 dst[32 + BYTE_SWAP(2)] = (b[7] & 0xf) << 4 | g[7] >> 8;
388 dst[32 + BYTE_SWAP(3)] = b[7] >> 4;
389 dst += 36;
390 }
391 }
392}
393
394static void yuv444p10le_to_r12l(char * __restrict dst_buffer, AVFrame * __restrict frame,
395 int width, int height, int pitch, const int * __restrict rgb_shift)
396{
397 yuv444pXXle_to_r12l(10, dst_buffer, frame, width, height, pitch, rgb_shift);
398}
399
400static void yuv444p12le_to_r12l(char * __restrict dst_buffer, AVFrame * __restrict frame,
401 int width, int height, int pitch, const int * __restrict rgb_shift)
402{
403 yuv444pXXle_to_r12l(12, dst_buffer, frame, width, height, pitch, rgb_shift);
404}
405
406static void yuv444p16le_to_r12l(char * __restrict dst_buffer, AVFrame * __restrict frame,
407 int width, int height, int pitch, const int * __restrict rgb_shift)
408{
409 yuv444pXXle_to_r12l(16, dst_buffer, frame, width, height, pitch, rgb_shift);
410}
411
412#if defined __GNUC__
413static inline void yuv444pXXle_to_rg48(int depth, char * __restrict dst_buffer, AVFrame * __restrict frame,
414 int width, int height, int pitch, const int * __restrict rgb_shift)
415 __attribute__((always_inline));
416#endif
417static inline void yuv444pXXle_to_rg48(int depth, char * __restrict dst_buffer, AVFrame * __restrict frame,
418 int width, int height, int pitch, const int * __restrict rgb_shift)
419{
420 assert((uintptr_t) dst_buffer % 2 == 0);
421 assert((uintptr_t) frame->linesize[0] % 2 == 0);
422 assert((uintptr_t) frame->linesize[1] % 2 == 0);
423 assert((uintptr_t) frame->linesize[2] % 2 == 0);
424
425 UNUSED(rgb_shift);
426 for (int y = 0; y < height; ++y) {
427 uint16_t *src_y = (uint16_t *)(void *) (frame->data[0] + frame->linesize[0] * y);
428 uint16_t *src_cb = (uint16_t *)(void *) (frame->data[1] + frame->linesize[1] * y);
429 uint16_t *src_cr = (uint16_t *)(void *) (frame->data[2] + frame->linesize[2] * y);
430 uint16_t *dst = (uint16_t *)(void *) (dst_buffer + y * pitch);
431
432 OPTIMIZED_FOR (int x = 0; x < width; ++x) {
433 comp_type_t y = (Y_SCALE(depth) * (*src_y++ - (1<<(depth-4))));
434 comp_type_t cr = *src_cr++ - (1<<(depth-1));
435 comp_type_t cb = *src_cb++ - (1<<(depth-1));
436
437 comp_type_t r = YCBCR_TO_R_709_SCALED(depth, y, cb, cr) >> (COMP_BASE-16+depth);
438 comp_type_t g = YCBCR_TO_G_709_SCALED(depth, y, cb, cr) >> (COMP_BASE-16+depth);
439 comp_type_t b = YCBCR_TO_B_709_SCALED(depth, y, cb, cr) >> (COMP_BASE-16+depth);
440 // r g b is now on 16 bit scale
441
442 *dst++ = CLAMP_FULL(r, 16);
443 *dst++ = CLAMP_FULL(g, 16);
444 *dst++ = CLAMP_FULL(b, 16);
445 }
446 }
447}
448
449static void yuv444p10le_to_rg48(char * __restrict dst_buffer, AVFrame * __restrict frame,
450 int width, int height, int pitch, const int * __restrict rgb_shift)
451{
452 yuv444pXXle_to_rg48(10, dst_buffer, frame, width, height, pitch, rgb_shift);
453}
454
455static void yuv444p12le_to_rg48(char * __restrict dst_buffer, AVFrame * __restrict frame,
456 int width, int height, int pitch, const int * __restrict rgb_shift)
457{
458 yuv444pXXle_to_rg48(12, dst_buffer, frame, width, height, pitch, rgb_shift);
459}
460
461static void yuv444p16le_to_rg48(char * __restrict dst_buffer, AVFrame * __restrict frame,
462 int width, int height, int pitch, const int * __restrict rgb_shift)
463{
464 yuv444pXXle_to_rg48(16, dst_buffer, frame, width, height, pitch, rgb_shift);
465}
466
467#if defined __GNUC__
468static inline void gbrpXXle_to_r12l(char * __restrict dst_buffer, AVFrame * __restrict frame,
469 int width, int height, int pitch, const int * __restrict rgb_shift, unsigned int in_depth)
470 __attribute__((always_inline));
471#endif
472static inline void gbrpXXle_to_r12l(char * __restrict dst_buffer, AVFrame * __restrict frame,
473 int width, int height, int pitch, const int * __restrict rgb_shift, unsigned int in_depth)
474{
475 assert((uintptr_t) frame->linesize[0] % 2 == 0);
476 assert((uintptr_t) frame->linesize[1] % 2 == 0);
477 assert((uintptr_t) frame->linesize[2] % 2 == 0);
478
479#undef S
480#define S(x) ((x) >> (in_depth - 12))
481
482 UNUSED(rgb_shift);
483 for (int y = 0; y < height; ++y) {
484 uint16_t *src_g = (uint16_t *)(void *) (frame->data[0] + frame->linesize[0] * y);
485 uint16_t *src_b = (uint16_t *)(void *) (frame->data[1] + frame->linesize[1] * y);
486 uint16_t *src_r = (uint16_t *)(void *) (frame->data[2] + frame->linesize[2] * y);
487 unsigned char *dst = (unsigned char *) dst_buffer + y * pitch;
488
489 OPTIMIZED_FOR (int x = 0; x < width; x += 8) {
490 dst[BYTE_SWAP(0)] = S(*src_r) & 0xff;
491 dst[BYTE_SWAP(1)] = (S(*src_g) & 0xf) << 4 | S(*src_r++) >> 8;
492 dst[BYTE_SWAP(2)] = S(*src_g++) >> 4;
493 dst[BYTE_SWAP(3)] = S(*src_b) & 0xff;
494 dst[4 + BYTE_SWAP(0)] = (S(*src_r) & 0xf) << 4 | S(*src_b++) >> 8;
495 dst[4 + BYTE_SWAP(1)] = S(*src_r++) >> 4;
496 dst[4 + BYTE_SWAP(2)] = S(*src_g) & 0xff;
497 dst[4 + BYTE_SWAP(3)] = (S(*src_b) & 0xf) << 4 | S(*src_g++) >> 8;
498 dst[8 + BYTE_SWAP(0)] = S(*src_b++) >> 4;
499 dst[8 + BYTE_SWAP(1)] = S(*src_r) & 0xff;
500 dst[8 + BYTE_SWAP(2)] = (S(*src_g) & 0xf) << 4 | S(*src_r++) >> 8;
501 dst[8 + BYTE_SWAP(3)] = S(*src_g++) >> 4;
502 dst[12 + BYTE_SWAP(0)] = S(*src_b) & 0xff;
503 dst[12 + BYTE_SWAP(1)] = (S(*src_r) & 0xf) << 4 | S(*src_b++) >> 8;
504 dst[12 + BYTE_SWAP(2)] = S(*src_r++) >> 4;
505 dst[12 + BYTE_SWAP(3)] = S(*src_g) & 0xff;
506 dst[16 + BYTE_SWAP(0)] = (S(*src_b) & 0xf) << 4 | S(*src_g++) >> 8;
507 dst[16 + BYTE_SWAP(1)] = S(*src_b++) >> 4;
508 dst[16 + BYTE_SWAP(2)] = S(*src_r) & 0xff;
509 dst[16 + BYTE_SWAP(3)] = (S(*src_g) & 0xf) << 4 | S(*src_r++) >> 8;
510 dst[20 + BYTE_SWAP(0)] = S(*src_g++) >> 4;
511 dst[20 + BYTE_SWAP(1)] = S(*src_b) & 0xff;
512 dst[20 + BYTE_SWAP(2)] = (S(*src_r) & 0xf) << 4 | S(*src_b++) >> 8;
513 dst[20 + BYTE_SWAP(3)] = S(*src_r++) >> 4;;
514 dst[24 + BYTE_SWAP(0)] = S(*src_g) & 0xff;
515 dst[24 + BYTE_SWAP(1)] = (S(*src_b) & 0xf) << 4 | S(*src_g++) >> 8;
516 dst[24 + BYTE_SWAP(2)] = S(*src_b++) >> 4;
517 dst[24 + BYTE_SWAP(3)] = S(*src_r) & 0xff;
518 dst[28 + BYTE_SWAP(0)] = (S(*src_g) & 0xf) << 4 | S(*src_r++) >> 8;
519 dst[28 + BYTE_SWAP(1)] = S(*src_g++) >> 4;
520 dst[28 + BYTE_SWAP(2)] = S(*src_b) & 0xff;
521 dst[28 + BYTE_SWAP(3)] = (S(*src_r) & 0xf) << 4 | S(*src_b++) >> 8;
522 dst[32 + BYTE_SWAP(0)] = S(*src_r++) >> 4;
523 dst[32 + BYTE_SWAP(1)] = S(*src_g) & 0xff;
524 dst[32 + BYTE_SWAP(2)] = (S(*src_b) & 0xf) << 4 | S(*src_g++) >> 8;
525 dst[32 + BYTE_SWAP(3)] = S(*src_b++) >> 4;
526 dst += 36;
527 }
528 }
529}
530
531#if defined __GNUC__
532static inline void gbrpXXle_to_rgb(char * __restrict dst_buffer, AVFrame * __restrict frame,
533 int width, int height, int pitch, const int * __restrict rgb_shift, unsigned int in_depth)
534 __attribute__((always_inline));
535#endif
536static inline void gbrpXXle_to_rgb(char * __restrict dst_buffer, AVFrame * __restrict frame,
537 int width, int height, int pitch, const int * __restrict rgb_shift, unsigned int in_depth)
538{
539 assert((uintptr_t) frame->linesize[0] % 2 == 0);
540 assert((uintptr_t) frame->linesize[1] % 2 == 0);
541 assert((uintptr_t) frame->linesize[2] % 2 == 0);
542
543 UNUSED(rgb_shift);
544 for (int y = 0; y < height; ++y) {
545 uint16_t *src_g = (uint16_t *)(void *) (frame->data[0] + frame->linesize[0] * y);
546 uint16_t *src_b = (uint16_t *)(void *) (frame->data[1] + frame->linesize[1] * y);
547 uint16_t *src_r = (uint16_t *)(void *) (frame->data[2] + frame->linesize[2] * y);
548 unsigned char *dst = (unsigned char *) dst_buffer + y * pitch;
549
550 OPTIMIZED_FOR (int x = 0; x < width; ++x) {
551 *dst++ = *src_r++ >> (in_depth - 8U);
552 *dst++ = *src_g++ >> (in_depth - 8U);
553 *dst++ = *src_b++ >> (in_depth - 8U);
554 }
555 }
556}
557
558#if defined __GNUC__
559static inline void gbrpXXle_to_rgba(char * __restrict dst_buffer, AVFrame * __restrict frame,
560 int width, int height, int pitch, const int * __restrict rgb_shift, unsigned int in_depth)
561 __attribute__((always_inline));
562#endif
563static inline void gbrpXXle_to_rgba(char * __restrict dst_buffer, AVFrame * __restrict frame,
564 int width, int height, int pitch, const int * __restrict rgb_shift, unsigned int in_depth)
565{
566 assert((uintptr_t) dst_buffer % 4 == 0);
567 assert((uintptr_t) frame->data[0] % 2 == 0);
568 assert((uintptr_t) frame->data[1] % 2 == 0);
569 assert((uintptr_t) frame->data[2] % 2 == 0);
570
571 uint32_t alpha_mask = 0xFFFFFFFFU ^ (0xFFU << rgb_shift[R]) ^ (0xFFU << rgb_shift[G]) ^ (0xFFU << rgb_shift[B]);
572
573 for (int y = 0; y < height; ++y) {
574 uint16_t *src_g = (uint16_t *)(void *) (frame->data[0] + frame->linesize[0] * y);
575 uint16_t *src_b = (uint16_t *)(void *) (frame->data[1] + frame->linesize[1] * y);
576 uint16_t *src_r = (uint16_t *)(void *) (frame->data[2] + frame->linesize[2] * y);
577 uint32_t *dst = (uint32_t *)(void *) (dst_buffer + y * pitch);
578
579 OPTIMIZED_FOR (int x = 0; x < width; ++x) {
580 *dst++ = alpha_mask | (*src_r++ >> (in_depth - 8U)) << rgb_shift[0] | (*src_g++ >> (in_depth - 8U)) << rgb_shift[1] |
581 (*src_b++ >> (in_depth - 8U)) << rgb_shift[2];
582 }
583 }
584}
585
586static void gbrp10le_to_rgb(char * __restrict dst_buffer, AVFrame * __restrict frame,
587 int width, int height, int pitch, const int * __restrict rgb_shift)
588{
589 gbrpXXle_to_rgb(dst_buffer, frame, width, height, pitch, rgb_shift, 10);
590}
591
592static void gbrp10le_to_rgba(char * __restrict dst_buffer, AVFrame * __restrict frame,
593 int width, int height, int pitch, const int * __restrict rgb_shift)
594{
595 gbrpXXle_to_rgba(dst_buffer, frame, width, height, pitch, rgb_shift, 10);
596}
597
598static void gbrp12le_to_r12l(char * __restrict dst_buffer, AVFrame * __restrict frame,
599 int width, int height, int pitch, const int * __restrict rgb_shift)
600{
601 gbrpXXle_to_r12l(dst_buffer, frame, width, height, pitch, rgb_shift, 12U);
602}
603
604static void gbrp12le_to_r10k(char * __restrict dst_buffer, AVFrame * __restrict frame,
605 int width, int height, int pitch, const int * __restrict rgb_shift)
606{
607 gbrpXXle_to_r10k(dst_buffer, frame, width, height, pitch, rgb_shift, 12U);
608}
609
610static void gbrp12le_to_rgb(char * __restrict dst_buffer, AVFrame * __restrict frame,
611 int width, int height, int pitch, const int * __restrict rgb_shift)
612{
613 gbrpXXle_to_rgb(dst_buffer, frame, width, height, pitch, rgb_shift, 12U);
614}
615
616static void gbrp12le_to_rgba(char * __restrict dst_buffer, AVFrame * __restrict frame,
617 int width, int height, int pitch, const int * __restrict rgb_shift)
618{
619 gbrpXXle_to_rgba(dst_buffer, frame, width, height, pitch, rgb_shift, 12U);
620}
621
622static void gbrp16le_to_r12l(char * __restrict dst_buffer, AVFrame * __restrict frame,
623 int width, int height, int pitch, const int * __restrict rgb_shift)
624{
625 gbrpXXle_to_r12l(dst_buffer, frame, width, height, pitch, rgb_shift, 16U);
626}
627
628static void gbrp16le_to_rgb(char * __restrict dst_buffer, AVFrame * __restrict frame,
629 int width, int height, int pitch, const int * __restrict rgb_shift)
630{
631 gbrpXXle_to_rgb(dst_buffer, frame, width, height, pitch, rgb_shift, 16U);
632}
633
634static void gbrp16le_to_rgba(char * __restrict dst_buffer, AVFrame * __restrict frame,
635 int width, int height, int pitch, const int * __restrict rgb_shift)
636{
637 gbrpXXle_to_rgba(dst_buffer, frame, width, height, pitch, rgb_shift, 16U);
638}
639
640#if defined __GNUC__
641static inline void gbrpXXle_to_rg48(char * __restrict dst_buffer, AVFrame * __restrict frame,
642 int width, int height, int pitch, unsigned int in_depth)
643 __attribute__((always_inline));
644#endif
645static inline void gbrpXXle_to_rg48(char * __restrict dst_buffer, AVFrame * __restrict frame,
646 int width, int height, int pitch, unsigned int in_depth)
647{
648 assert((uintptr_t) dst_buffer % 2 == 0);
649 assert((uintptr_t) frame->data[0] % 2 == 0);
650 assert((uintptr_t) frame->data[1] % 2 == 0);
651 assert((uintptr_t) frame->data[2] % 2 == 0);
652
653 for (ptrdiff_t y = 0; y < height; ++y) {
654 uint16_t *src_g = (void *) (frame->data[0] + frame->linesize[0] * y);
655 uint16_t *src_b = (void *) (frame->data[1] + frame->linesize[1] * y);
656 uint16_t *src_r = (void *) (frame->data[2] + frame->linesize[2] * y);
657 uint16_t *dst = (void *) (dst_buffer + y * pitch);
658
659 OPTIMIZED_FOR (int x = 0; x < width; ++x) {
660 *dst++ = *src_r++ << (16U - in_depth);
661 *dst++ = *src_g++ << (16U - in_depth);
662 *dst++ = *src_b++ << (16U - in_depth);
663 }
664 }
665}
666
667static void gbrp10le_to_rg48(char * __restrict dst_buffer, AVFrame * __restrict frame,
668 int width, int height, int pitch, const int * __restrict rgb_shift)
669{
670 (void) rgb_shift;
671 gbrpXXle_to_rg48(dst_buffer, frame, width, height, pitch, 10);
672}
673
674static void gbrp12le_to_rg48(char * __restrict dst_buffer, AVFrame * __restrict frame,
675 int width, int height, int pitch, const int * __restrict rgb_shift)
676{
677 (void) rgb_shift;
678 gbrpXXle_to_rg48(dst_buffer, frame, width, height, pitch, 12);
679}
680
681static void gbrp16le_to_rg48(char * __restrict dst_buffer, AVFrame * __restrict frame,
682 int width, int height, int pitch, const int * __restrict rgb_shift)
683{
684 (void) rgb_shift;
685 gbrpXXle_to_rg48(dst_buffer, frame, width, height, pitch, 16);
686}
687
688static void rgb48le_to_rgba(char * __restrict dst_buffer, AVFrame * __restrict frame,
689 int width, int height, int pitch, const int * __restrict rgb_shift)
690{
692 for (int y = 0; y < height; ++y) {
693 vc_copylineRG48toRGBA((unsigned char *) dst_buffer + y * pitch, frame->data[0] + y * frame->linesize[0],
694 vc_get_linesize(width, RGBA), rgb_shift[0], rgb_shift[1], rgb_shift[2]);
695 }
696}
697
698static void rgb48le_to_r12l(char * __restrict dst_buffer, AVFrame * __restrict frame,
699 int width, int height, int pitch, const int * __restrict rgb_shift)
700{
702
703 for (int y = 0; y < height; ++y) {
704 vc_copylineRG48toR12L((unsigned char *) dst_buffer + y * pitch, frame->data[0] + y * frame->linesize[0],
705 vc_get_linesize(width, R12L), rgb_shift[0], rgb_shift[1], rgb_shift[2]);
706 }
707}
708
709static void yuv420p_to_uyvy(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
710 int width, int height, int pitch, const int * __restrict rgb_shift)
711{
712 UNUSED(rgb_shift);
713 for(int y = 0; y < (height + 1) / 2; ++y) {
714 int scnd_row = y * 2 + 1;
715 if (scnd_row == height) {
716 scnd_row = height - 1;
717 }
718 char *src_y1 = (char *) in_frame->data[0] + in_frame->linesize[0] * y * 2;
719 char *src_y2 = (char *) in_frame->data[0] + in_frame->linesize[0] * scnd_row;
720 char *src_cb = (char *) in_frame->data[1] + in_frame->linesize[1] * y;
721 char *src_cr = (char *) in_frame->data[2] + in_frame->linesize[2] * y;
722 char *dst1 = dst_buffer + (y * 2) * pitch;
723 char *dst2 = dst_buffer + scnd_row * pitch;
724
725 int x = 0;
726
727#ifdef __SSE3__
728 __m128i y1;
729 __m128i y2;
730 __m128i u1;
731 __m128i u2;
732 __m128i v1;
733 __m128i v2;
734 __m128i out1l;
735 __m128i out1h;
736 __m128i out2l;
737 __m128i out2h;
738 __m128i zero = _mm_set1_epi32(0);
739
740 for (; x < width - 15; x += 16){
741 y1 = _mm_lddqu_si128((__m128i const*)(const void *) src_y1);
742 y2 = _mm_lddqu_si128((__m128i const*)(const void *) src_y2);
743 src_y1 += 16;
744 src_y2 += 16;
745
746 out1l = _mm_unpacklo_epi8(zero, y1);
747 out1h = _mm_unpackhi_epi8(zero, y1);
748 out2l = _mm_unpacklo_epi8(zero, y2);
749 out2h = _mm_unpackhi_epi8(zero, y2);
750
751 u1 = _mm_lddqu_si128((__m128i const*)(const void *) src_cb);
752 v1 = _mm_lddqu_si128((__m128i const*)(const void *) src_cr);
753 src_cb += 8;
754 src_cr += 8;
755
756 u1 = _mm_unpacklo_epi8(u1, zero);
757 v1 = _mm_unpacklo_epi8(v1, zero);
758 u2 = _mm_unpackhi_epi8(u1, zero);
759 v2 = _mm_unpackhi_epi8(v1, zero);
760 u1 = _mm_unpacklo_epi8(u1, zero);
761 v1 = _mm_unpacklo_epi8(v1, zero);
762
763 v1 = _mm_bslli_si128(v1, 2);
764 v2 = _mm_bslli_si128(v2, 2);
765
766 u1 = _mm_or_si128(u1, v1);
767 u2 = _mm_or_si128(u2, v2);
768
769 out1l = _mm_or_si128(out1l, u1);
770 out1h = _mm_or_si128(out1h, u2);
771 out2l = _mm_or_si128(out2l, u1);
772 out2h = _mm_or_si128(out2h, u2);
773
774 _mm_storeu_si128((__m128i *)(void *) dst1, out1l);
775 dst1 += 16;
776 _mm_storeu_si128((__m128i *)(void *) dst1, out1h);
777 dst1 += 16;
778 _mm_storeu_si128((__m128i *)(void *) dst2, out2l);
779 dst2 += 16;
780 _mm_storeu_si128((__m128i *)(void *) dst2, out2h);
781 dst2 += 16;
782 }
783#endif
784
785
786 OPTIMIZED_FOR (; x < width - 1; x += 2) {
787 *dst1++ = *src_cb;
788 *dst1++ = *src_y1++;
789 *dst1++ = *src_cr;
790 *dst1++ = *src_y1++;
791
792 *dst2++ = *src_cb++;
793 *dst2++ = *src_y2++;
794 *dst2++ = *src_cr++;
795 *dst2++ = *src_y2++;
796 }
797 if (x < width) {
798 *dst1++ = *src_cb;
799 *dst1++ = *src_y1++;
800 *dst1++ = *src_cr;
801 *dst1++ = 0;
802
803 *dst2++ = *src_cb++;
804 *dst2++ = *src_y2++;
805 *dst2++ = *src_cr++;
806 *dst2++ = 0;
807 }
808 }
809}
810
811static void yuv420p_to_v210(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
812 int width, int height, int pitch, const int * __restrict rgb_shift)
813{
814 UNUSED(rgb_shift);
815 for(int y = 0; y < height / 2; ++y) {
816 uint8_t *src_y1 = (in_frame->data[0] + in_frame->linesize[0] * y * 2);
817 uint8_t *src_y2 = (in_frame->data[0] + in_frame->linesize[0] * (y * 2 + 1));
818 uint8_t *src_cb = (in_frame->data[1] + in_frame->linesize[1] * y);
819 uint8_t *src_cr = (in_frame->data[2] + in_frame->linesize[2] * y);
820 uint32_t *dst1 = (uint32_t *)(void *)(dst_buffer + (y * 2) * pitch);
821 uint32_t *dst2 = (uint32_t *)(void *)(dst_buffer + (y * 2 + 1) * pitch);
822
823 OPTIMIZED_FOR (int x = 0; x < width / 6; ++x) {
824 uint32_t w0_0, w0_1, w0_2, w0_3;
825 uint32_t w1_0, w1_1, w1_2, w1_3;
826
827 w0_0 = *src_cb << 2;
828 w1_0 = *src_cb << 2;
829 src_cb++;
830 w0_0 = w0_0 | (*src_y1++ << 2) << 10;
831 w1_0 = w1_0 | (*src_y2++ << 2) << 10;
832 w0_0 = w0_0 | (*src_cr << 2) << 20;
833 w1_0 = w1_0 | (*src_cr << 2) << 20;
834 src_cr++;
835
836 w0_1 = *src_y1++ << 2;
837 w1_1 = *src_y2++ << 2;
838 w0_1 = w0_1 | (*src_cb << 2) << 10;
839 w1_1 = w1_1 | (*src_cb << 2) << 10;
840 src_cb++;
841 w0_1 = w0_1 | (*src_y1++ << 2) << 20;
842 w1_1 = w1_1 | (*src_y2++ << 2) << 20;
843
844 w0_2 = *src_cr << 2;
845 w1_2 = *src_cr << 2;
846 src_cr++;
847 w0_2 = w0_2 | (*src_y1++ << 2) << 10;
848 w1_2 = w1_2 | (*src_y2++ << 2) << 10;
849 w0_2 = w0_2 | (*src_cb << 2) << 20;
850 w1_2 = w1_2 | (*src_cb << 2) << 20;
851 src_cb++;
852
853 w0_3 = *src_y1++;
854 w1_3 = *src_y2++;
855 w0_3 = w0_3 | (*src_cr << 2) << 10;
856 w1_3 = w1_3 | (*src_cr << 2) << 10;
857 src_cr++;
858 w0_3 = w0_3 | (*src_y1++ << 2) << 20;
859 w1_3 = w1_3 | (*src_y2++ << 2) << 20;
860
861 *dst1++ = w0_0;
862 *dst1++ = w0_1;
863 *dst1++ = w0_2;
864 *dst1++ = w0_3;
865
866 *dst2++ = w1_0;
867 *dst2++ = w1_1;
868 *dst2++ = w1_2;
869 *dst2++ = w1_3;
870 }
871 }
872}
873
874static void yuv422p_to_uyvy(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
875 int width, int height, int pitch, const int * __restrict rgb_shift)
876{
877 UNUSED(rgb_shift);
878 for(int y = 0; y < height; ++y) {
879 char *src_y = (char *) in_frame->data[0] + in_frame->linesize[0] * y;
880 char *src_cb = (char *) in_frame->data[1] + in_frame->linesize[1] * y;
881 char *src_cr = (char *) in_frame->data[2] + in_frame->linesize[2] * y;
882 char *dst = dst_buffer + pitch * y;
883
884 OPTIMIZED_FOR (int x = 0; x < width / 2; ++x) {
885 *dst++ = *src_cb++;
886 *dst++ = *src_y++;
887 *dst++ = *src_cr++;
888 *dst++ = *src_y++;
889 }
890 }
891}
892
893static void yuv422p_to_v210(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
894 int width, int height, int pitch, const int * __restrict rgb_shift)
895{
896 UNUSED(rgb_shift);
897 for(int y = 0; y < height; ++y) {
898 uint8_t *src_y = (in_frame->data[0] + in_frame->linesize[0] * y);
899 uint8_t *src_cb = (in_frame->data[1] + in_frame->linesize[1] * y);
900 uint8_t *src_cr = (in_frame->data[2] + in_frame->linesize[2] * y);
901 uint32_t *dst = (uint32_t *)(void *)(dst_buffer + y * pitch);
902
903 OPTIMIZED_FOR (int x = 0; x < width / 6; ++x) {
904 uint32_t w0_0, w0_1, w0_2, w0_3;
905
906 w0_0 = *src_cb++ << 2;
907 w0_0 = w0_0 | (*src_y++ << 2) << 10;
908 w0_0 = w0_0 | (*src_cr++ << 2) << 20;
909
910 w0_1 = *src_y++ << 2;
911 w0_1 = w0_1 | (*src_cb++ << 2) << 10;
912 w0_1 = w0_1 | (*src_y++ << 2) << 20;
913
914 w0_2 = *src_cr++ << 2;
915 w0_2 = w0_2 | (*src_y++ << 2) << 10;
916 w0_2 = w0_2 | (*src_cb++ << 2) << 20;
917
918 w0_3 = *src_y++ << 2;
919 w0_3 = w0_3 | (*src_cr++ << 2) << 10;
920 w0_3 = w0_3 | (*src_y++ << 2) << 20;
921
922 *dst++ = w0_0;
923 *dst++ = w0_1;
924 *dst++ = w0_2;
925 *dst++ = w0_3;
926 }
927 }
928}
929
930static void yuv444p_to_uyvy(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
931 int width, int height, int pitch, const int * __restrict rgb_shift)
932{
933 UNUSED(rgb_shift);
934 for(int y = 0; y < height; ++y) {
935 char *src_y = (char *) in_frame->data[0] + in_frame->linesize[0] * y;
936 unsigned char *src_cb = (unsigned char *) in_frame->data[1] + in_frame->linesize[1] * y;
937 unsigned char *src_cr = (unsigned char *) in_frame->data[2] + in_frame->linesize[2] * y;
938 char *dst = dst_buffer + pitch * y;
939
940 OPTIMIZED_FOR (int x = 0; x < width / 2; ++x) {
941 *dst++ = (*src_cb + *(src_cb + 1)) / 2;
942 src_cb += 2;
943 *dst++ = *src_y++;
944 *dst++ = (*src_cr + *(src_cr + 1)) / 2;
945 src_cr += 2;
946 *dst++ = *src_y++;
947 }
948 }
949}
950
951static void yuv444p16le_to_uyvy(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
952 int width, int height, int pitch, const int * __restrict rgb_shift)
953{
954 UNUSED(rgb_shift);
955 for(int y = 0; y < height; ++y) {
956 unsigned char *src_y = (unsigned char *) in_frame->data[0] + in_frame->linesize[0] * y + 1;
957 unsigned char *src_cb = (unsigned char *) in_frame->data[1] + in_frame->linesize[1] * y + 1;
958 unsigned char *src_cr = (unsigned char *) in_frame->data[2] + in_frame->linesize[2] * y + 1;
959 unsigned char *dst = (unsigned char *) dst_buffer + pitch * y;
960
961 OPTIMIZED_FOR (int x = 0; x < width / 2; ++x) {
962 *dst++ = (*src_cb + *(src_cb + 2)) / 2;
963 src_cb += 4;
964 *dst++ = *src_y;
965 src_y += 2;
966 *dst++ = (*src_cr + *(src_cr + 2)) / 2;
967 src_cr += 4;
968 *dst++ = *src_y;
969 src_y += 2;
970 }
971 }
972}
973
974static void yuv444p_to_v210(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
975 int width, int height, int pitch, const int * __restrict rgb_shift)
976{
977 UNUSED(rgb_shift);
978 for(int y = 0; y < height; ++y) {
979 uint8_t *src_y = (in_frame->data[0] + in_frame->linesize[0] * y);
980 uint8_t *src_cb = (in_frame->data[1] + in_frame->linesize[1] * y);
981 uint8_t *src_cr = (in_frame->data[2] + in_frame->linesize[2] * y);
982 uint32_t *dst = (uint32_t *)(void *)(dst_buffer + y * pitch);
983
984 OPTIMIZED_FOR (int x = 0; x < width / 6; ++x) {
985 uint32_t w0_0, w0_1, w0_2, w0_3;
986
987 w0_0 = ((src_cb[0] << 2) + (src_cb[1] << 2)) / 2;
988 w0_0 = w0_0 | (*src_y++ << 2) << 10;
989 w0_0 = w0_0 | ((src_cr[0] << 2) + (src_cr[1] << 2)) / 2 << 20;
990 src_cb += 2;
991 src_cr += 2;
992
993 w0_1 = *src_y++ << 2;
994 w0_1 = w0_1 | ((src_cb[0] << 2) + (src_cb[1] << 2)) / 2 << 10;
995 w0_1 = w0_1 | (*src_y++ << 2) << 20;
996 src_cb += 2;
997
998 w0_2 = ((src_cr[0] << 2) + (src_cr[1] << 2)) / 2;
999 w0_2 = w0_2 | (*src_y++ << 2) << 10;
1000 w0_2 = w0_2 | ((src_cb[0] << 2) + (src_cb[1] << 2)) / 2 << 20;
1001 src_cr += 2;
1002 src_cb += 2;
1003
1004 w0_3 = *src_y++ << 2;
1005 w0_3 = w0_3 | ((src_cr[0] << 2) + (src_cr[1] << 2)) / 2 << 10;
1006 w0_3 = w0_3 | (*src_y++ << 2) << 20;
1007 src_cr += 2;
1008
1009 *dst++ = w0_0;
1010 *dst++ = w0_1;
1011 *dst++ = w0_2;
1012 *dst++ = w0_3;
1013 }
1014 }
1015}
1016
1021#if defined __GNUC__
1022static inline void nv12_to_rgb(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1023 int width, int height, int pitch, const int * __restrict rgb_shift, bool rgba)
1024 __attribute__((always_inline));
1025#endif
1026static inline void nv12_to_rgb(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1027 int width, int height, int pitch, const int * __restrict rgb_shift, bool rgba)
1028{
1029 enum {
1030 S_DEPTH = 8,
1031 };
1032 assert((uintptr_t) dst_buffer % 4 == 0);
1033
1034 uint32_t alpha_mask = 0xFFFFFFFFU ^ (0xFFU << rgb_shift[R]) ^ (0xFFU << rgb_shift[G]) ^ (0xFFU << rgb_shift[B]);
1035
1036 for(int y = 0; y < height; ++y) {
1037 unsigned char *src_y = (unsigned char *) in_frame->data[0] + in_frame->linesize[0] * y;
1038 unsigned char *src_cbcr = (unsigned char *) in_frame->data[1] + in_frame->linesize[1] * (y / 2);
1039 unsigned char *dst = (unsigned char *) dst_buffer + pitch * y;
1040
1041 OPTIMIZED_FOR (int x = 0; x < width / 2; ++x) {
1042 comp_type_t cb = *src_cbcr++ - 128;
1043 comp_type_t cr = *src_cbcr++ - 128;
1044 comp_type_t y = (*src_y++ - 16) * Y_SCALE(S_DEPTH);
1045 comp_type_t r = YCBCR_TO_R_709_SCALED(S_DEPTH, y, cb, cr) >> COMP_BASE;
1046 comp_type_t g = YCBCR_TO_G_709_SCALED(S_DEPTH, y, cb, cr) >> COMP_BASE;
1047 comp_type_t b = YCBCR_TO_B_709_SCALED(S_DEPTH, y, cb, cr) >> COMP_BASE;
1048 if (rgba) {
1049 *((uint32_t *)(void *) dst) = MK_RGBA(r, g, b, alpha_mask, 8);
1050 dst += 4;
1051 } else {
1052 *dst++ = CLAMP_FULL(r, 8);
1053 *dst++ = CLAMP_FULL(g, 8);
1054 *dst++ = CLAMP_FULL(b, 8);
1055 }
1056
1057 y = (*src_y++ - 16) * Y_SCALE(S_DEPTH);
1058 if (rgba) {
1059 *((uint32_t *)(void *) dst) = MK_RGBA(r, g, b, alpha_mask, 8);
1060 dst += 4;
1061 } else {
1062 *dst++ = CLAMP_FULL(r, 8);
1063 *dst++ = CLAMP_FULL(g, 8);
1064 *dst++ = CLAMP_FULL(b, 8);
1065 }
1066 }
1067 }
1068}
1069
1070static void nv12_to_rgb24(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1071 int width, int height, int pitch, const int * __restrict rgb_shift)
1072{
1073 nv12_to_rgb(dst_buffer, in_frame, width, height, pitch, rgb_shift, false);
1074}
1075
1076static void nv12_to_rgb32(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1077 int width, int height, int pitch, const int * __restrict rgb_shift)
1078{
1079 nv12_to_rgb(dst_buffer, in_frame, width, height, pitch, rgb_shift, true);
1080}
1081
1082#if defined __GNUC__
1083static inline void yuv8p_to_rgb(int subsampling, char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1084 int width, int height, int pitch, const int * __restrict rgb_shift, bool rgba) __attribute__((always_inline));
1085#endif
1090static inline void yuv8p_to_rgb(int subsampling, char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1091 int width, int height, int pitch, const int * __restrict rgb_shift, bool rgba)
1092{
1093 enum {
1094 S_DEPTH = 8,
1095 };
1096 uint32_t alpha_mask = 0xFFFFFFFFU ^ (0xFFU << rgb_shift[R]) ^ (0xFFU << rgb_shift[G]) ^ (0xFFU << rgb_shift[B]);
1097
1098 for(int y = 0; y < height / 2; ++y) {
1099 unsigned char *src_y1 = (unsigned char *) in_frame->data[0] + in_frame->linesize[0] * y * 2;
1100 unsigned char *src_y2 = (unsigned char *) in_frame->data[0] + in_frame->linesize[0] * (y * 2 + 1);
1101 unsigned char *dst1 = (unsigned char *) dst_buffer + pitch * (y * 2);
1102 unsigned char *dst2 = (unsigned char *) dst_buffer + pitch * (y * 2 + 1);
1103
1104 unsigned char *src_cb1 = NULL;
1105 unsigned char *src_cr1 = NULL;
1106 unsigned char *src_cb2 = NULL;
1107 unsigned char *src_cr2 = NULL;
1108 if (subsampling == 420) {
1109 src_cb1 = (unsigned char *) in_frame->data[1] + in_frame->linesize[1] * y;
1110 src_cr1 = (unsigned char *) in_frame->data[2] + in_frame->linesize[2] * y;
1111 } else {
1112 src_cb1 = (unsigned char *) in_frame->data[1] + in_frame->linesize[1] * (y * 2);
1113 src_cr1 = (unsigned char *) in_frame->data[2] + in_frame->linesize[2] * (y * 2);
1114 src_cb2 = (unsigned char *) in_frame->data[1] + in_frame->linesize[1] * (y * 2 + 1);
1115 src_cr2 = (unsigned char *) in_frame->data[2] + in_frame->linesize[2] * (y * 2 + 1);
1116 }
1117
1118#define WRITE_RES_YUV8P_TO_RGB(DST) {\
1119 r >>= COMP_BASE;\
1120 g >>= COMP_BASE;\
1121 b >>= COMP_BASE;\
1122 if (rgba) {\
1123 *((uint32_t *)(void *) DST) = MK_RGBA(r, g, b, alpha_mask, 8);\
1124 DST += 4;\
1125 } else {\
1126 *DST++ = CLAMP_FULL(r, 8);\
1127 *DST++ = CLAMP_FULL(g, 8);\
1128 *DST++ = CLAMP_FULL(b, 8);\
1129 }\
1130 }\
1131
1132 OPTIMIZED_FOR (int x = 0; x < width / 2; ++x) {
1133 comp_type_t cb = *src_cb1++ - 128;
1134 comp_type_t cr = *src_cr1++ - 128;
1135 comp_type_t y = (*src_y1++ - 16) * Y_SCALE(S_DEPTH);
1136 comp_type_t r = YCBCR_TO_R_709_SCALED(S_DEPTH, y, cb, cr);
1137 comp_type_t g = YCBCR_TO_G_709_SCALED(S_DEPTH, y, cb, cr);
1138 comp_type_t b = YCBCR_TO_B_709_SCALED(S_DEPTH, y, cb, cr);
1140
1141 y = (*src_y1++ - 16) * Y_SCALE(S_DEPTH);
1142 r = YCBCR_TO_R_709_SCALED(S_DEPTH, y, cb, cr);
1143 g = YCBCR_TO_G_709_SCALED(S_DEPTH, y, cb, cr);
1144 b = YCBCR_TO_B_709_SCALED(S_DEPTH, y, cb, cr);
1146
1147 if (subsampling == 422) {
1148 cb = *src_cb2++ - 128;
1149 cr = *src_cr2++ - 128;
1150 }
1151 y = (*src_y2++ - 16) * Y_SCALE(S_DEPTH);
1152 r = YCBCR_TO_R_709_SCALED(S_DEPTH, y, cb, cr);
1153 g = YCBCR_TO_G_709_SCALED(S_DEPTH, y, cb, cr);
1154 b = YCBCR_TO_B_709_SCALED(S_DEPTH, y, cb, cr);
1156
1157 y = (*src_y2++ - 16) * Y_SCALE(S_DEPTH);
1158 r = YCBCR_TO_R_709_SCALED(S_DEPTH, y, cb, cr);
1159 g = YCBCR_TO_G_709_SCALED(S_DEPTH, y, cb, cr);
1160 b = YCBCR_TO_B_709_SCALED(S_DEPTH, y, cb, cr);
1162 }
1163 }
1164}
1165
1166static void yuv420p_to_rgb24(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1167 int width, int height, int pitch, const int * __restrict rgb_shift)
1168{
1169 yuv8p_to_rgb(420, dst_buffer, in_frame, width, height, pitch, rgb_shift, false);
1170}
1171
1172static void yuv420p_to_rgb32(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1173 int width, int height, int pitch, const int * __restrict rgb_shift)
1174{
1175 yuv8p_to_rgb(420, dst_buffer, in_frame, width, height, pitch, rgb_shift, true);
1176}
1177
1178static void yuv422p_to_rgb24(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1179 int width, int height, int pitch, const int * __restrict rgb_shift)
1180{
1181 yuv8p_to_rgb(422, dst_buffer, in_frame, width, height, pitch, rgb_shift, false);
1182}
1183
1184static void yuv422p_to_rgb32(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1185 int width, int height, int pitch, const int * __restrict rgb_shift)
1186{
1187 yuv8p_to_rgb(422, dst_buffer, in_frame, width, height, pitch, rgb_shift, true);
1188}
1189
1190
1194#if defined __GNUC__
1195static inline void yuv444p_to_rgb(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1196 int width, int height, int pitch, const int * __restrict rgb_shift, bool rgba)
1197 __attribute__((always_inline));
1198#endif
1199static inline void yuv444p_to_rgb(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1200 int width, int height, int pitch, const int * __restrict rgb_shift, bool rgba)
1201{
1202 enum {
1203 S_DEPTH = 8,
1204 };
1205 assert((uintptr_t) dst_buffer % 4 == 0);
1206
1207 uint32_t alpha_mask = 0xFFFFFFFFU ^ (0xFFU << rgb_shift[R]) ^ (0xFFU << rgb_shift[G]) ^ (0xFFU << rgb_shift[B]);
1208
1209 for(int y = 0; y < height; ++y) {
1210 unsigned char *src_y = (unsigned char *) in_frame->data[0] + in_frame->linesize[0] * y;
1211 unsigned char *src_cb = (unsigned char *) in_frame->data[1] + in_frame->linesize[1] * y;
1212 unsigned char *src_cr = (unsigned char *) in_frame->data[2] + in_frame->linesize[2] * y;
1213 unsigned char *dst = (unsigned char *) dst_buffer + pitch * y;
1214
1215 OPTIMIZED_FOR (int x = 0; x < width; ++x) {
1216 int cb = *src_cb++ - 128;
1217 int cr = *src_cr++ - 128;
1218 int y = *src_y++ * Y_SCALE(S_DEPTH);
1219 comp_type_t r = YCBCR_TO_R_709_SCALED(S_DEPTH, y, cb, cr) >> COMP_BASE;
1220 comp_type_t g = YCBCR_TO_G_709_SCALED(S_DEPTH, y, cb, cr) >> COMP_BASE;
1221 comp_type_t b = YCBCR_TO_B_709_SCALED(S_DEPTH, y, cb, cr) >> COMP_BASE;
1222 if (rgba) {
1223 *((uint32_t *)(void *) dst) = MK_RGBA(r, g, b, alpha_mask, 8);
1224 dst += 4;
1225 } else {
1226 *dst++ = CLAMP(r, 1, 254);
1227 *dst++ = CLAMP(g, 1, 254);
1228 *dst++ = CLAMP(b, 1, 254);
1229 }
1230 }
1231 }
1232}
1233
1234static void yuv444p_to_rgb24(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1235 int width, int height, int pitch, const int * __restrict rgb_shift)
1236{
1237 yuv444p_to_rgb(dst_buffer, in_frame, width, height, pitch, rgb_shift, false);
1238}
1239
1240static void yuv444p_to_rgb32(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1241 int width, int height, int pitch, const int * __restrict rgb_shift)
1242{
1243 yuv444p_to_rgb(dst_buffer, in_frame, width, height, pitch, rgb_shift, true);
1244}
1245
1246static void yuv420p10le_to_v210(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1247 int width, int height, int pitch, const int * __restrict rgb_shift)
1248{
1249 UNUSED(rgb_shift);
1250 for(int y = 0; y < height / 2; ++y) {
1251 uint16_t *src_y1 = (uint16_t *)(void *)(in_frame->data[0] + in_frame->linesize[0] * y * 2);
1252 uint16_t *src_y2 = (uint16_t *)(void *)(in_frame->data[0] + in_frame->linesize[0] * (y * 2 + 1));
1253 uint16_t *src_cb = (uint16_t *)(void *)(in_frame->data[1] + in_frame->linesize[1] * y);
1254 uint16_t *src_cr = (uint16_t *)(void *)(in_frame->data[2] + in_frame->linesize[2] * y);
1255 uint32_t *dst1 = (uint32_t *)(void *)(dst_buffer + (y * 2) * pitch);
1256 uint32_t *dst2 = (uint32_t *)(void *)(dst_buffer + (y * 2 + 1) * pitch);
1257
1258 OPTIMIZED_FOR (int x = 0; x < width / 6; ++x) {
1259 uint32_t w0_0, w0_1, w0_2, w0_3;
1260 uint32_t w1_0, w1_1, w1_2, w1_3;
1261
1262 w0_0 = *src_cb;
1263 w1_0 = *src_cb;
1264 src_cb++;
1265 w0_0 = w0_0 | (*src_y1++) << 10;
1266 w1_0 = w1_0 | (*src_y2++) << 10;
1267 w0_0 = w0_0 | (*src_cr) << 20;
1268 w1_0 = w1_0 | (*src_cr) << 20;
1269 src_cr++;
1270
1271 w0_1 = *src_y1++;
1272 w1_1 = *src_y2++;
1273 w0_1 = w0_1 | (*src_cb) << 10;
1274 w1_1 = w1_1 | (*src_cb) << 10;
1275 src_cb++;
1276 w0_1 = w0_1 | (*src_y1++) << 20;
1277 w1_1 = w1_1 | (*src_y2++) << 20;
1278
1279 w0_2 = *src_cr;
1280 w1_2 = *src_cr;
1281 src_cr++;
1282 w0_2 = w0_2 | (*src_y1++) << 10;
1283 w1_2 = w1_2 | (*src_y2++) << 10;
1284 w0_2 = w0_2 | (*src_cb) << 20;
1285 w1_2 = w1_2 | (*src_cb) << 20;
1286 src_cb++;
1287
1288 w0_3 = *src_y1++;
1289 w1_3 = *src_y2++;
1290 w0_3 = w0_3 | (*src_cr) << 10;
1291 w1_3 = w1_3 | (*src_cr) << 10;
1292 src_cr++;
1293 w0_3 = w0_3 | (*src_y1++) << 20;
1294 w1_3 = w1_3 | (*src_y2++) << 20;
1295
1296 *dst1++ = w0_0;
1297 *dst1++ = w0_1;
1298 *dst1++ = w0_2;
1299 *dst1++ = w0_3;
1300
1301 *dst2++ = w1_0;
1302 *dst2++ = w1_1;
1303 *dst2++ = w1_2;
1304 *dst2++ = w1_3;
1305 }
1306 }
1307}
1308
1309static void yuv422p10le_to_v210(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1310 int width, int height, int pitch, const int * __restrict rgb_shift)
1311{
1312 UNUSED(rgb_shift);
1313 for(int y = 0; y < height; ++y) {
1314 uint16_t *src_y = (uint16_t *)(void *)(in_frame->data[0] + in_frame->linesize[0] * y);
1315 uint16_t *src_cb = (uint16_t *)(void *)(in_frame->data[1] + in_frame->linesize[1] * y);
1316 uint16_t *src_cr = (uint16_t *)(void *)(in_frame->data[2] + in_frame->linesize[2] * y);
1317 uint32_t *dst = (uint32_t *)(void *)(dst_buffer + y * pitch);
1318
1319 OPTIMIZED_FOR (int x = 0; x < width / 6; ++x) {
1320 uint32_t w0_0, w0_1, w0_2, w0_3;
1321
1322 w0_0 = *src_cb++;
1323 w0_0 = w0_0 | (*src_y++) << 10;
1324 w0_0 = w0_0 | (*src_cr++) << 20;
1325
1326 w0_1 = *src_y++;
1327 w0_1 = w0_1 | (*src_cb++) << 10;
1328 w0_1 = w0_1 | (*src_y++) << 20;
1329
1330 w0_2 = *src_cr++;
1331 w0_2 = w0_2 | (*src_y++) << 10;
1332 w0_2 = w0_2 | (*src_cb++) << 20;
1333
1334 w0_3 = *src_y++;
1335 w0_3 = w0_3 | (*src_cr++) << 10;
1336 w0_3 = w0_3 | (*src_y++) << 20;
1337
1338 *dst++ = w0_0;
1339 *dst++ = w0_1;
1340 *dst++ = w0_2;
1341 *dst++ = w0_3;
1342 }
1343 }
1344}
1345
1346#if defined __GNUC__
1347static inline void yuv444p1Xle_to_v210(unsigned in_depth, char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1348 int width, int height, int pitch, const int * __restrict rgb_shift)
1349 __attribute__((always_inline));
1350#endif
1351static inline void yuv444p1Xle_to_v210(unsigned in_depth, char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1352 int width, int height, int pitch, const int * __restrict rgb_shift)
1353{
1354 UNUSED(rgb_shift);
1355 for(int y = 0; y < height; ++y) {
1356 uint16_t *src_y = (uint16_t *)(void *)(in_frame->data[0] + in_frame->linesize[0] * y);
1357 uint16_t *src_cb = (uint16_t *)(void *)(in_frame->data[1] + in_frame->linesize[1] * y);
1358 uint16_t *src_cr = (uint16_t *)(void *)(in_frame->data[2] + in_frame->linesize[2] * y);
1359 uint32_t *dst = (uint32_t *)(void *)(dst_buffer + y * pitch);
1360
1361 OPTIMIZED_FOR (int x = 0; x < width / 6; ++x) {
1362 uint32_t w0_0, w0_1, w0_2, w0_3;
1363
1364 w0_0 = ((src_cb[0] >> (in_depth - 10U)) + (src_cb[1] >> (in_depth - 10U))) / 2;
1365 w0_0 = w0_0 | (*src_y++ >> (in_depth - 10U)) << 10U;
1366 w0_0 = w0_0 | ((src_cr[0] >> (in_depth - 10U)) + (src_cr[1] >> (in_depth - 10U))) / 2 << 20U;
1367 src_cb += 2;
1368 src_cr += 2;
1369
1370 w0_1 = *src_y++;
1371 w0_1 = w0_1 | ((src_cb[0] >> (in_depth - 10U)) + (src_cb[1] >> (in_depth - 10U))) / 2 << 10U;
1372 w0_1 = w0_1 | (*src_y++ >> (in_depth - 10U)) << 20U;
1373 src_cb += 2;
1374
1375 w0_2 = ((src_cr[0] >> (in_depth - 10U)) + (src_cr[1] >> (in_depth - 10U))) / 2;
1376 w0_2 = w0_2 | (*src_y++ >> (in_depth - 10U)) << 10U;
1377 w0_2 = w0_2 | ((src_cb[0] >> (in_depth - 10U)) + (src_cb[1] >> (in_depth - 10U))) / 2 << 20U;
1378 src_cr += 2;
1379 src_cb += 2;
1380
1381 w0_3 = *src_y++;
1382 w0_3 = w0_3 | ((src_cr[0] >> (in_depth - 10U)) + (src_cr[1] >> (in_depth - 10U))) / 2 << 10U;
1383 w0_3 = w0_3 | ((*src_y++ >> (in_depth - 10U))) << 20U;
1384 src_cr += 2;
1385
1386 *dst++ = w0_0;
1387 *dst++ = w0_1;
1388 *dst++ = w0_2;
1389 *dst++ = w0_3;
1390 }
1391 }
1392}
1393
1394static void yuv444p10le_to_v210(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1395 int width, int height, int pitch, const int * __restrict rgb_shift) {
1396 yuv444p1Xle_to_v210(10, dst_buffer, in_frame, width, height, pitch, rgb_shift);
1397}
1398
1399static void yuv444p12le_to_v210(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1400 int width, int height, int pitch, const int * __restrict rgb_shift) {
1401 yuv444p1Xle_to_v210(12, dst_buffer, in_frame, width, height, pitch, rgb_shift);
1402}
1403
1404static void yuv444p16le_to_v210(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1405 int width, int height, int pitch, const int * __restrict rgb_shift) {
1406 yuv444p1Xle_to_v210(16, dst_buffer, in_frame, width, height, pitch, rgb_shift);
1407}
1408
1409static void yuv420p10le_to_uyvy(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1410 int width, int height, int pitch, const int * __restrict rgb_shift)
1411{
1412 UNUSED(rgb_shift);
1413 for(int y = 0; y < height / 2; ++y) {
1414 uint16_t *src_y1 = (uint16_t *)(void *)(in_frame->data[0] + in_frame->linesize[0] * y * 2);
1415 uint16_t *src_y2 = (uint16_t *)(void *)(in_frame->data[0] + in_frame->linesize[0] * (y * 2 + 1));
1416 uint16_t *src_cb = (uint16_t *)(void *)(in_frame->data[1] + in_frame->linesize[1] * y);
1417 uint16_t *src_cr = (uint16_t *)(void *)(in_frame->data[2] + in_frame->linesize[2] * y);
1418 uint8_t *dst1 = (uint8_t *)(void *)(dst_buffer + (y * 2) * pitch);
1419 uint8_t *dst2 = (uint8_t *)(void *)(dst_buffer + (y * 2 + 1) * pitch);
1420
1421 OPTIMIZED_FOR (int x = 0; x < width / 2; ++x) {
1422 uint8_t tmp;
1423 // U
1424 tmp = *src_cb++ >> 2;
1425 *dst1++ = tmp;
1426 *dst2++ = tmp;
1427 // Y
1428 *dst1++ = *src_y1++ >> 2;
1429 *dst2++ = *src_y2++ >> 2;
1430 // V
1431 tmp = *src_cr++ >> 2;
1432 *dst1++ = tmp;
1433 *dst2++ = tmp;
1434 // Y
1435 *dst1++ = *src_y1++ >> 2;
1436 *dst2++ = *src_y2++ >> 2;
1437 }
1438 }
1439}
1440
1441static void yuv422p10le_to_uyvy(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1442 int width, int height, int pitch, const int * __restrict rgb_shift)
1443{
1444 UNUSED(rgb_shift);
1445 for(int y = 0; y < height; ++y) {
1446 uint16_t *src_y = (uint16_t *)(void *)(in_frame->data[0] + in_frame->linesize[0] * y);
1447 uint16_t *src_cb = (uint16_t *)(void *)(in_frame->data[1] + in_frame->linesize[1] * y);
1448 uint16_t *src_cr = (uint16_t *)(void *)(in_frame->data[2] + in_frame->linesize[2] * y);
1449 uint8_t *dst = (uint8_t *)(void *)(dst_buffer + y * pitch);
1450
1451 for(int x = 0; x < width / 2; ++x) {
1452 *dst++ = *src_cb++ >> 2;
1453 *dst++ = *src_y++ >> 2;
1454 *dst++ = *src_cr++ >> 2;
1455 *dst++ = *src_y++ >> 2;
1456 }
1457 }
1458}
1459
1460#if defined __GNUC__
1461static inline void yuv444p1Xle_to_uyvy(unsigned in_depth, char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1462 int width, int height, int pitch, const int * __restrict rgb_shift)
1463 __attribute__((always_inline));
1464#endif
1465static inline void yuv444p1Xle_to_uyvy(unsigned in_depth, char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1466 int width, int height, int pitch, const int * __restrict rgb_shift)
1467{
1468 UNUSED(rgb_shift);
1469 for(int y = 0; y < (int) height; ++y) {
1470 uint16_t *src_y = (uint16_t *)(void *)(in_frame->data[0] + in_frame->linesize[0] * y);
1471 uint16_t *src_cb = (uint16_t *)(void *)(in_frame->data[1] + in_frame->linesize[1] * y);
1472 uint16_t *src_cr = (uint16_t *)(void *)(in_frame->data[2] + in_frame->linesize[2] * y);
1473 uint8_t *dst = (uint8_t *)(void *)(dst_buffer + y * pitch);
1474
1475 OPTIMIZED_FOR (int x = 0; x < width / 2; ++x) {
1476 *dst++ = (src_cb[0] + src_cb[1] + 1) / 2 >> (in_depth - 8U);
1477 *dst++ = *src_y++ >> (in_depth - 8U);
1478 *dst++ = (src_cr[0] + src_cr[1] + 1) / 2 >> (in_depth - 8U);
1479 *dst++ = *src_y++ >> (in_depth - 8U);
1480 src_cb += 2;
1481 src_cr += 2;
1482 }
1483 }
1484}
1485
1486static void yuv444p10le_to_uyvy(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1487 int width, int height, int pitch, const int * __restrict rgb_shift)
1488{
1489 yuv444p1Xle_to_uyvy(10, dst_buffer, in_frame, width, height, pitch, rgb_shift);
1490}
1491
1492static void yuv444p12le_to_uyvy(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1493 int width, int height, int pitch, const int * __restrict rgb_shift)
1494{
1495 yuv444p1Xle_to_uyvy(12, dst_buffer, in_frame, width, height, pitch, rgb_shift);
1496}
1497
1498#if defined __GNUC__
1499static inline void yuv444p1Xle_to_y416(unsigned in_depth, char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1500 int width, int height, int pitch, const int * __restrict rgb_shift)
1501 __attribute__((always_inline));
1502#endif
1503static void yuv444p1Xle_to_y416(unsigned in_depth, char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1504 int width, int height, int pitch, const int * __restrict rgb_shift)
1505{
1506 assert((uintptr_t) dst_buffer % 2 == 0);
1507 assert((uintptr_t) in_frame->data[0] % 2 == 0);
1508 assert((uintptr_t) in_frame->data[1] % 2 == 0);
1509 assert((uintptr_t) in_frame->data[2] % 2 == 0);
1510 UNUSED(rgb_shift);
1511 for(int y = 0; y < (int) height; ++y) {
1512 uint16_t *src_y = (uint16_t *)(void *)(in_frame->data[0] + in_frame->linesize[0] * y);
1513 uint16_t *src_cb = (uint16_t *)(void *)(in_frame->data[1] + in_frame->linesize[1] * y);
1514 uint16_t *src_cr = (uint16_t *)(void *)(in_frame->data[2] + in_frame->linesize[2] * y);
1515 uint16_t *dst = (uint16_t *)(void *)(dst_buffer + y * pitch);
1516
1517 OPTIMIZED_FOR (int x = 0; x < width; ++x) {
1518 *dst++ = *src_cb++ << (16U - in_depth); // U
1519 *dst++ = *src_y++ << (16U - in_depth); // Y
1520 *dst++ = *src_cr++ << (16U - in_depth); // V
1521 *dst++ = 0xFFFFU; // A
1522 }
1523 }
1524}
1525
1526static void yuv444p10le_to_y416(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1527 int width, int height, int pitch, const int * __restrict rgb_shift)
1528{
1529 yuv444p1Xle_to_y416(10, dst_buffer, in_frame, width, height, pitch, rgb_shift);
1530}
1531
1532static void yuv444p12le_to_y416(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1533 int width, int height, int pitch, const int * __restrict rgb_shift)
1534{
1535 yuv444p1Xle_to_y416(12, dst_buffer, in_frame, width, height, pitch, rgb_shift);
1536}
1537
1538static void yuv444p16le_to_y416(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1539 int width, int height, int pitch, const int * __restrict rgb_shift)
1540{
1541 yuv444p1Xle_to_y416(16, dst_buffer, in_frame, width, height, pitch, rgb_shift);
1542}
1543
1544#if defined __GNUC__
1545static inline void yuvp10le_to_rgb(int subsampling, char * __restrict dst_buffer, AVFrame * __restrict frame,
1546 int width, int height, int pitch, const int * __restrict rgb_shift, int out_bit_depth) __attribute__((always_inline));
1547#endif
1548static inline void yuvp10le_to_rgb(int subsampling, char * __restrict dst_buffer, AVFrame * __restrict frame,
1549 int width, int height, int pitch, const int * __restrict rgb_shift, int out_bit_depth)
1550{
1551 enum {
1552 S_DEPTH = 10,
1553 };
1554 assert((uintptr_t) dst_buffer % 4 == 0);
1555 assert((uintptr_t) frame->linesize[0] % 2 == 0);
1556 assert((uintptr_t) frame->linesize[1] % 2 == 0);
1557 assert((uintptr_t) frame->linesize[2] % 2 == 0);
1558
1559 assert(subsampling == 422 || subsampling == 420);
1560 assert(out_bit_depth == 24 || out_bit_depth == 30 || out_bit_depth == 32);
1561 uint32_t alpha_mask = 0xFFFFFFFFU ^ (0xFFU << rgb_shift[R]) ^ (0xFFU << rgb_shift[G]) ^ (0xFFU << rgb_shift[B]);
1562 const int bpp = out_bit_depth == 30 ? 10 : 8;
1563
1564 for (int y = 0; y < height / 2; ++y) {
1565 uint16_t * __restrict src_y1 = (uint16_t *)(void *) (frame->data[0] + frame->linesize[0] * 2 * y);
1566 uint16_t * __restrict src_y2 = (uint16_t *)(void *) (frame->data[0] + frame->linesize[0] * (2 * y + 1));
1567 uint16_t * __restrict src_cb1;
1568 uint16_t * __restrict src_cr1;
1569 uint16_t * __restrict src_cb2;
1570 uint16_t * __restrict src_cr2;
1571 if (subsampling == 420) {
1572 src_cb1 = src_cb2 = (uint16_t *)(void *) (frame->data[1] + frame->linesize[1] * y);
1573 src_cr1 = src_cr2 = (uint16_t *)(void *) (frame->data[2] + frame->linesize[2] * y);
1574 } else {
1575 src_cb1 = (uint16_t *)(void *) (frame->data[1] + frame->linesize[1] * (2 * y));
1576 src_cb2 = (uint16_t *)(void *) (frame->data[1] + frame->linesize[1] * (2 * y + 1));
1577 src_cr1 = (uint16_t *)(void *) (frame->data[2] + frame->linesize[2] * (2 * y));
1578 src_cr2 = (uint16_t *)(void *) (frame->data[2] + frame->linesize[2] * (2 * y + 1));
1579 }
1580 unsigned char *dst1 = (unsigned char *) dst_buffer + (2 * y) * pitch;
1581 unsigned char *dst2 = (unsigned char *) dst_buffer + (2 * y + 1) * pitch;
1582
1583 OPTIMIZED_FOR (int x = 0; x < width / 2; ++x) {
1584 comp_type_t cr = *src_cr1++ - (1<<9);
1585 comp_type_t cb = *src_cb1++ - (1<<9);
1586 comp_type_t rr = YCBCR_TO_R_709_SCALED(S_DEPTH, 0, cb, cr) >> (COMP_BASE + (10 - bpp));
1587 comp_type_t gg = YCBCR_TO_G_709_SCALED(S_DEPTH, 0, cb, cr) >> (COMP_BASE + (10 - bpp));
1588 comp_type_t bb = YCBCR_TO_B_709_SCALED(S_DEPTH, 0, cb, cr) >> (COMP_BASE + (10 - bpp));
1589
1590# define WRITE_RES_YUV10P_TO_RGB(Y, DST) {\
1591 comp_type_t r = Y + rr;\
1592 comp_type_t g = Y + gg;\
1593 comp_type_t b = Y + bb;\
1594 r = CLAMP_FULL(r, bpp);\
1595 g = CLAMP_FULL(g, bpp);\
1596 b = CLAMP_FULL(b, bpp);\
1597 if (out_bit_depth == 32) {\
1598 *((uint32_t *)(void *) DST) = alpha_mask | (r << rgb_shift[R] | g << rgb_shift[G] | b << rgb_shift[B]);\
1599 DST += 4;\
1600 } else if (out_bit_depth == 24) {\
1601 *DST++ = r;\
1602 *DST++ = g;\
1603 *DST++ = b;\
1604 } else {\
1605 *((uint32_t *)(void *) (DST)) = r >> 2U | (r & 0x3U) << 14 | g >> 4U << 8U | (g & 0xFU) << 20U | b >> 6U << 16U | (b & 0x3FU) << 26U | 0x3U << 24U;\
1606 /* == htonl(r << 22U | g << 12U | b << 2U) */ \
1607 DST += 4;\
1608 }\
1609 }
1610
1611 comp_type_t y1 = (Y_SCALE(S_DEPTH) * (*src_y1++ - (1<<6))) >> (COMP_BASE + (10 - bpp));
1612 WRITE_RES_YUV10P_TO_RGB(y1, dst1)
1613
1614 comp_type_t y11 = (Y_SCALE(S_DEPTH) * (*src_y1++ - (1<<6))) >> (COMP_BASE + (10 - bpp));
1615 WRITE_RES_YUV10P_TO_RGB(y11, dst1)
1616
1617 if (subsampling == 422) {
1618 cr = *src_cr2++ - (1<<9);
1619 cb = *src_cb2++ - (1<<9);
1620 rr = YCBCR_TO_R_709_SCALED(S_DEPTH, 0, cb, cr) >> (COMP_BASE + (10 - bpp));
1621 gg = YCBCR_TO_G_709_SCALED(S_DEPTH, 0, cb, cr) >> (COMP_BASE + (10 - bpp));
1622 bb = YCBCR_TO_B_709_SCALED(S_DEPTH, 0, cb, cr) >> (COMP_BASE + (10 - bpp));
1623 }
1624
1625 comp_type_t y2 = (Y_SCALE(S_DEPTH) * (*src_y2++ - (1<<6))) >> (COMP_BASE + (10 - bpp));
1626 WRITE_RES_YUV10P_TO_RGB(y2, dst2)
1627
1628 comp_type_t y22 = (Y_SCALE(S_DEPTH) * (*src_y2++ - (1<<6))) >> (COMP_BASE + (10 - bpp));
1629 WRITE_RES_YUV10P_TO_RGB(y22, dst2)
1630 }
1631 }
1632}
1633
1634#define MAKE_YUV_TO_RGB_FUNCTION_NAME(subs, out_bit_depth) yuv ## subs ## p10le_to_rgb ## out_bit_depth
1635
1636#define MAKE_YUV_TO_RGB_FUNCTION(subs, out_bit_depth) static void MAKE_YUV_TO_RGB_FUNCTION_NAME(subs, out_bit_depth)(char * __restrict dst_buffer, AVFrame * __restrict in_frame,\
1637 int width, int height, int pitch, const int * __restrict rgb_shift) {\
1638 yuvp10le_to_rgb(subs, dst_buffer, in_frame, width, height, pitch, rgb_shift, out_bit_depth);\
1639}
1640
1647
1648#if defined __GNUC__
1649static inline void yuv444p10le_to_rgb(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1650 int width, int height, int pitch, const int * __restrict rgb_shift, bool rgba)
1651 __attribute__((always_inline));
1652#endif
1653static inline void yuv444p10le_to_rgb(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1654 int width, int height, int pitch, const int * __restrict rgb_shift, bool rgba)
1655{
1656 enum {
1657 S_DEPTH = 10,
1658 };
1659 uint32_t alpha_mask = 0xFFFFFFFFU ^ (0xFFU << rgb_shift[R]) ^ (0xFFU << rgb_shift[G]) ^ (0xFFU << rgb_shift[B]);
1660
1661 for (int y = 0; y < height; y++) {
1662 uint16_t *src_y = (uint16_t *)(void *)(in_frame->data[0] + in_frame->linesize[0] * y);
1663 uint16_t *src_cb = (uint16_t *)(void *)(in_frame->data[1] + in_frame->linesize[1] * y);
1664 uint16_t *src_cr = (uint16_t *)(void *)(in_frame->data[2] + in_frame->linesize[2] * y);
1665 uint8_t *dst = (uint8_t *)(void *)(dst_buffer + y * pitch);
1666
1667 OPTIMIZED_FOR (int x = 0; x < width; ++x) {
1668 comp_type_t cb = *src_cb++ - (1 << (S_DEPTH - 1));
1669 comp_type_t cr = *src_cr++ - (1 << (S_DEPTH - 1));
1670 comp_type_t y =
1671 (*src_y++ - (1 << (S_DEPTH - 4))) * Y_SCALE(S_DEPTH);
1672 comp_type_t r =
1673 YCBCR_TO_R_709_SCALED(S_DEPTH, y, cb, cr) >>
1674 (COMP_BASE + 2);
1675 comp_type_t g =
1676 YCBCR_TO_G_709_SCALED(S_DEPTH, y, cb, cr) >>
1677 (COMP_BASE + 2);
1678 comp_type_t b =
1679 YCBCR_TO_B_709_SCALED(S_DEPTH, y, cb, cr) >>
1680 (COMP_BASE + 2);
1681 if (rgba) {
1682 *(uint32_t *)(void *) dst = MK_RGBA(r, g, b, alpha_mask, 8);
1683 dst += 4;
1684 } else {
1685 *dst++ = CLAMP_FULL(r, 8);
1686 *dst++ = CLAMP_FULL(g, 8);
1687 *dst++ = CLAMP_FULL(b, 8);
1688 }
1689 }
1690 }
1691}
1692
1693static void yuv444p10le_to_rgb24(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1694 int width, int height, int pitch, const int * __restrict rgb_shift)
1695{
1696 yuv444p10le_to_rgb(dst_buffer, in_frame, width, height, pitch, rgb_shift, false);
1697}
1698
1699static void yuv444p10le_to_rgb32(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1700 int width, int height, int pitch, const int * __restrict rgb_shift)
1701{
1702 yuv444p10le_to_rgb(dst_buffer, in_frame, width, height, pitch, rgb_shift, true);
1703}
1704
1705#if P210_PRESENT
1706static void p210le_to_v210(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1707 int width, int height, int pitch, const int * __restrict rgb_shift)
1708{
1709 UNUSED(rgb_shift);
1710 assert((uintptr_t) in_frame->data[0] % 2 == 0);
1711 assert((uintptr_t) in_frame->data[1] % 2 == 0);
1712 assert((uintptr_t) dst_buffer % 4 == 0);
1713 for(int y = 0; y < height; ++y) {
1714 uint16_t *src_y = (uint16_t *)(void *)(in_frame->data[0] + in_frame->linesize[0] * y);
1715 uint16_t *src_cbcr = (uint16_t *)(void *)(in_frame->data[1] + in_frame->linesize[1] * y);
1716 uint32_t *dst = (uint32_t *)(void *)(dst_buffer + y * pitch);
1717
1718 OPTIMIZED_FOR (int x = 0; x < width / 6; ++x) {
1719 uint32_t w0_0 = *src_cbcr >> 6; // Cb0
1720 src_cbcr++; // Cr0
1721 w0_0 = w0_0 | (*src_y++ >> 6) << 10;
1722 w0_0 = w0_0 | (*src_cbcr >> 6) << 20;
1723 src_cbcr++; // Cb1
1724
1725 uint32_t w0_1 = *src_y++ >> 6;
1726 w0_1 = w0_1 | (*src_cbcr >> 6) << 10;
1727 src_cbcr++; // Cr1
1728 w0_1 = w0_1 | (*src_y++ >> 6) << 20;
1729
1730 uint32_t w0_2 = *src_cbcr >> 6;
1731 src_cbcr++;
1732 w0_2 = w0_2 | (*src_y++ >> 6) << 10;
1733 w0_2 = w0_2 | (*src_cbcr >> 6) << 20;
1734 src_cbcr++;
1735
1736 uint32_t w0_3 = *src_y++ >> 6;
1737 w0_3 = w0_3 | (*src_cbcr >> 6) << 10;
1738 src_cbcr++;
1739 w0_3 = w0_3 | (*src_y++ >> 6) << 20;
1740
1741 *dst++ = w0_0;
1742 *dst++ = w0_1;
1743 *dst++ = w0_2;
1744 *dst++ = w0_3;
1745 }
1746 }
1747}
1748#endif
1749
1750static void p010le_to_v210(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1751 int width, int height, int pitch, const int * __restrict rgb_shift)
1752{
1753 UNUSED(rgb_shift);
1754 assert((uintptr_t) in_frame->data[0] % 2 == 0);
1755 assert((uintptr_t) in_frame->data[1] % 2 == 0);
1756 assert((uintptr_t) dst_buffer % 4 == 0 && pitch % 4 == 0);
1757 for(int y = 0; y < height / 2; ++y) {
1758 uint16_t *src_y1 = (uint16_t *)(void *) (in_frame->data[0] + in_frame->linesize[0] * y * 2);
1759 uint16_t *src_y2 = (uint16_t *)(void *) (in_frame->data[0] + in_frame->linesize[0] * (y * 2 + 1));
1760 uint16_t *src_cbcr = (uint16_t *)(void *) (in_frame->data[1] + in_frame->linesize[1] * y);
1761 uint32_t *dst1 = (uint32_t *)(void *)(dst_buffer + (y * 2) * pitch);
1762 uint32_t *dst2 = (uint32_t *)(void *)(dst_buffer + (y * 2 + 1) * pitch);
1763
1764 OPTIMIZED_FOR (int x = 0; x < width / 6; ++x) {
1765 uint32_t w0_0, w0_1, w0_2, w0_3;
1766 uint32_t w1_0, w1_1, w1_2, w1_3;
1767
1768 w0_0 = *src_cbcr >> 6; // Cb0
1769 w1_0 = *src_cbcr >> 6;
1770 src_cbcr++; // Cr0
1771 w0_0 = w0_0 | (*src_y1++ >> 6) << 10;
1772 w1_0 = w1_0 | (*src_y2++ >> 6) << 10;
1773 w0_0 = w0_0 | (*src_cbcr >> 6) << 20;
1774 w1_0 = w1_0 | (*src_cbcr >> 6) << 20;
1775 src_cbcr++; // Cb1
1776
1777 w0_1 = *src_y1++ >> 6;
1778 w1_1 = *src_y2++ >> 6;
1779 w0_1 = w0_1 | (*src_cbcr >> 6) << 10;
1780 w1_1 = w1_1 | (*src_cbcr >> 6) << 10;
1781 src_cbcr++; // Cr1
1782 w0_1 = w0_1 | (*src_y1++ >> 6) << 20;
1783 w1_1 = w1_1 | (*src_y2++ >> 6) << 20;
1784
1785 w0_2 = *src_cbcr >> 6;
1786 w1_2 = *src_cbcr >> 6;
1787 src_cbcr++;
1788 w0_2 = w0_2 | (*src_y1++ >> 6) << 10;
1789 w1_2 = w1_2 | (*src_y2++ >> 6) << 10;
1790 w0_2 = w0_2 | (*src_cbcr >> 6) << 20;
1791 w1_2 = w1_2 | (*src_cbcr >> 6) << 20;
1792 src_cbcr++;
1793
1794 w0_3 = *src_y1++ >> 6;
1795 w1_3 = *src_y2++ >> 6;
1796 w0_3 = w0_3 | (*src_cbcr >> 6) << 10;
1797 w1_3 = w1_3 | (*src_cbcr >> 6) << 10;
1798 src_cbcr++;
1799 w0_3 = w0_3 | (*src_y1++ >> 6) << 20;
1800 w1_3 = w1_3 | (*src_y2++ >> 6) << 20;
1801
1802 *dst1++ = w0_0;
1803 *dst1++ = w0_1;
1804 *dst1++ = w0_2;
1805 *dst1++ = w0_3;
1806
1807 *dst2++ = w1_0;
1808 *dst2++ = w1_1;
1809 *dst2++ = w1_2;
1810 *dst2++ = w1_3;
1811 }
1812 }
1813}
1814
1815static void p010le_to_uyvy(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1816 int width, int height, int pitch, const int * __restrict rgb_shift)
1817{
1818 UNUSED(rgb_shift);
1819 for(int y = 0; y < height / 2; ++y) {
1820 uint16_t *src_y1 = (uint16_t *)(void *)(in_frame->data[0] + in_frame->linesize[0] * y * 2);
1821 uint16_t *src_y2 = (uint16_t *)(void *)(in_frame->data[0] + in_frame->linesize[0] * (y * 2 + 1));
1822 uint16_t *src_cbcr = (uint16_t *)(void *)(in_frame->data[1] + in_frame->linesize[1] * y);
1823 uint8_t *dst1 = (uint8_t *)(void *)(dst_buffer + (y * 2) * pitch);
1824 uint8_t *dst2 = (uint8_t *)(void *)(dst_buffer + (y * 2 + 1) * pitch);
1825
1826 OPTIMIZED_FOR (int x = 0; x < width / 2; ++x) {
1827 uint8_t tmp;
1828 // U
1829 tmp = *src_cbcr++ >> 8;
1830 *dst1++ = tmp;
1831 *dst2++ = tmp;
1832 // Y
1833 *dst1++ = *src_y1++ >> 8;
1834 *dst2++ = *src_y2++ >> 8;
1835 // V
1836 tmp = *src_cbcr++ >> 8;
1837 *dst1++ = tmp;
1838 *dst2++ = tmp;
1839 // Y
1840 *dst1++ = *src_y1++ >> 8;
1841 *dst2++ = *src_y2++ >> 8;
1842 }
1843 }
1844}
1845
1846#if P210_PRESENT
1847static void p210le_to_uyvy(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1848 int width, int height, int pitch, const int * __restrict rgb_shift)
1849{
1850 UNUSED(rgb_shift);
1851 assert((uintptr_t) in_frame->data[0] % 2 == 0);
1852 assert((uintptr_t) in_frame->data[1] % 2 == 0);
1853 for(int y = 0; y < height; ++y) {
1854 uint16_t *src_y = (uint16_t *)(void *)(in_frame->data[0] + in_frame->linesize[0] * y);
1855 uint16_t *src_cbcr = (uint16_t *)(void *)(in_frame->data[1] + in_frame->linesize[1] * y);
1856 uint8_t *dst = (uint8_t *)(void *)(dst_buffer + y * pitch);
1857
1858 OPTIMIZED_FOR (int x = 0; x < width / 2; ++x) {
1859 *dst = *src_cbcr++ >> 8;
1860 *dst++ = *src_y++ >> 8;
1861 *dst++ = *src_cbcr++ >> 8;
1862 *dst++ = *src_y++ >> 8;
1863 }
1864 }
1865}
1866#endif
1867
1868#if XV3X_PRESENT
1869static void xv30_to_uyvy(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1870 int width, int height, int pitch, const int * __restrict rgb_shift)
1871{
1872 UNUSED(rgb_shift);
1873 assert((uintptr_t) in_frame->data[0] % 4 == 0);
1874 for (ptrdiff_t y = 0; y < height; ++y) {
1875 uint32_t *src = (void *)(in_frame->data[0] + in_frame->linesize[0] * y);
1876 uint8_t *dst = (void *)(dst_buffer + y * pitch);
1877 int x = 0;
1878 OPTIMIZED_FOR ( ; x < width - 1; x += 2) {
1879 uint32_t in1 = *src++;
1880 uint32_t in2 = *src++;
1881 *dst++ = (((in1 >> 2U) & 0xFFU) + (((in2 >> 2U) & 0xFFU) + 1)) >> 1;
1882 *dst++ = (in1 >> 12U) & 0xFFU;
1883 *dst++ = (((in1 >> 22U) & 0xFFU) + (((in2 >> 22U) & 0xFFU) + 1)) >> 1;
1884 *dst++ = (in2 >> 12U) & 0xFFU;
1885 }
1886 if (x < width) {
1887 uint32_t last = *src++;
1888 *dst++ = (last >> 2U) & 0xFFU;
1889 *dst++ = (last >> 12U) & 0xFFU;
1890 *dst++ = (last >> 22U) & 0xFFU;
1891 *dst++ = 0;
1892 }
1893 }
1894}
1895
1896static void xv30_to_v210(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1897 int width, int height, int pitch, const int * __restrict rgb_shift)
1898{
1899 UNUSED(rgb_shift);
1900 assert((uintptr_t) in_frame->data[0] % 4 == 0);
1901 assert((uintptr_t) dst_buffer % 4 == 0 && pitch % 4 == 0);
1902 for(int y = 0; y < height; ++y) {
1903 uint32_t *src = (uint32_t *)(void *) (in_frame->data[0] + in_frame->linesize[0] * y);
1904 uint32_t *dst = (uint32_t *)(void *)(dst_buffer + y * pitch);
1905
1906#define FETCH_IN \
1907 in0 = *src++; \
1908 in1 = *src++; \
1909 u = ((in0 & 0x3FFU) + (in1 & 0x3FFU) + 1) >> 1; \
1910 y0 = (in0 >> 10U) & 0x3FFU; \
1911 v = ((in0 >> 20U & 0x3FFU) + ((in1 >> 20U & 0x3FFU) + 1)) >> 1; \
1912 y1 = (in1 >> 10U) & 0x3FFU; \
1913
1914 OPTIMIZED_FOR (int x = 0; x < width / 6; ++x) {
1915 uint32_t in0, in1;
1916 uint32_t u, y0, v, y1;
1917
1918 FETCH_IN
1919 *dst++ = v << 20U | y0 << 10U | u;
1920 uint32_t tmp = y1;
1921 FETCH_IN
1922 *dst++ = y0 << 20U | u << 10U | tmp;
1923 tmp = y1 << 10U | v;
1924 FETCH_IN
1925 *dst++ = u << 20U | tmp;
1926 *dst++ = y1 << 20U | v << 10U | y0;
1927 }
1928 }
1929#undef FETCH_IN
1930}
1931
1932static void xv30_to_y416(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1933 int width, int height, int pitch, const int * __restrict rgb_shift)
1934{
1935 UNUSED(rgb_shift);
1936 assert((uintptr_t) in_frame->data[0] % 4 == 0);
1937 assert((uintptr_t) dst_buffer % 2 == 0 && pitch % 2 == 0);
1938 for (ptrdiff_t y = 0; y < height; ++y) {
1939 uint32_t *src = (void *)(in_frame->data[0] + in_frame->linesize[0] * y);
1940 uint16_t *dst = (void *)(dst_buffer + y * pitch);
1941 OPTIMIZED_FOR (int x = 0; x < width; x += 1) {
1942 uint32_t in = *src++;
1943 *dst++ = (in & 0x3FFU) << 6U;
1944 *dst++ = ((in >> 10U) & 0x3FFU) << 6U;
1945 *dst++ = ((in >> 20U) & 0x3FFU) << 6U;
1946 *dst++ = 0xFFFFU;
1947 }
1948 }
1949}
1950#endif // XV3X_PRESENT
1951
1952#if Y210_PRESENT
1953static void y210_to_v210(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1954 int width, int height, int pitch, const int * __restrict rgb_shift)
1955{
1956 UNUSED(rgb_shift);
1957 assert((uintptr_t) in_frame->data[0] % 2 == 0);
1958 assert((uintptr_t) dst_buffer % 4 == 0 && pitch % 4 == 0);
1959 for(int y = 0; y < height; ++y) {
1960 uint16_t *src = (uint16_t *)(void *) (in_frame->data[0] + in_frame->linesize[0] * y);
1961 uint32_t *dst = (uint32_t *)(void *)(dst_buffer + y * pitch);
1962
1963 // Y210 is like YUYV but with 10-bit in high bits of 16-bit container
1964#define FETCH_IN \
1965 y0 = *src++ >> 6U; \
1966 u = *src++ >> 6U; \
1967 y1 = *src++ >> 6U; \
1968 v = *src++ >> 6U;
1969
1970 OPTIMIZED_FOR (int x = 0; x < (width + 5) / 6; ++x) {
1971 unsigned y0, u, y1, v;
1972 unsigned tmp;
1973
1974 FETCH_IN
1975 *dst++ = v << 20U | y0 << 10U | u;
1976 tmp = y1;
1977 FETCH_IN
1978 *dst++ = y0 << 20U | u << 10U | tmp;
1979 tmp = y1 << 10U | v;
1980 FETCH_IN
1981 *dst++ = u << 20U | tmp;
1982 *dst++ = y1 << 20U | v << 10U | y0;
1983 }
1984 }
1985#undef FETCH_IN
1986}
1987
1988static void y210_to_y416(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
1989 int width, int height, int pitch, const int * __restrict rgb_shift)
1990{
1991 UNUSED(rgb_shift);
1992 assert((uintptr_t) in_frame->data[0] % 2 == 0);
1993 assert((uintptr_t) dst_buffer % 2 == 0 && pitch % 2 == 0);
1994 for(int y = 0; y < height; ++y) {
1995 uint16_t *src = (void *) (in_frame->data[0] + in_frame->linesize[0] * y);
1996 uint16_t *dst = (void *) (dst_buffer + y * pitch);
1997
1998 OPTIMIZED_FOR (int x = 0; x < (width + 1) / 2; ++x) {
1999 unsigned y0, u, y1, v;
2000 y0 = *src++;
2001 u = *src++;
2002 y1 = *src++;
2003 v = *src++;
2004
2005 *dst++ = u;
2006 *dst++ = y0;
2007 *dst++ = v;
2008 *dst++ = 0xFFFFU;
2009 *dst++ = u;
2010 *dst++ = y1;
2011 *dst++ = v;
2012 *dst++ = 0xFFFFU;
2013 }
2014 }
2015}
2016
2017static void y210_to_uyvy(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
2018 int width, int height, int pitch, const int * __restrict rgb_shift)
2019{
2020 UNUSED(rgb_shift);
2021 for(int y = 0; y < height; ++y) {
2022 uint8_t *src = (void *) (in_frame->data[0] + in_frame->linesize[0] * y);
2023 uint8_t *dst = (void *) (dst_buffer + y * pitch);
2024
2025 OPTIMIZED_FOR (int x = 0; x < (width + 1) / 2; ++x) {
2026 unsigned y0, u, y1, v;
2027 y0 = src[1];
2028 u = src[3];
2029 y1 = src[5];
2030 v = src[7];
2031 src += 8;
2032
2033 *dst++ = u;
2034 *dst++ = y0;
2035 *dst++ = v;
2036 *dst++ = y1;
2037 }
2038 }
2039}
2040#endif // Y210_PRESENT
2041
2042#ifdef HWACC_VDPAU
2043static void av_vdpau_to_ug_vdpau(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
2044 int width, int height, int pitch, const int * __restrict rgb_shift)
2045{
2046 UNUSED(width);
2047 UNUSED(height);
2048 UNUSED(pitch);
2049 UNUSED(rgb_shift);
2050
2051 struct video_frame_callbacks *callbacks = in_frame->opaque;
2052
2053 hw_vdpau_frame *out = (hw_vdpau_frame *)(void *) dst_buffer;
2054
2056
2057 hw_vdpau_frame_from_avframe(out, in_frame);
2058
2059 callbacks->recycle = hw_vdpau_recycle_callback;
2060 callbacks->copy = hw_vdpau_copy_callback;
2061}
2062#endif
2063
2065 for(unsigned i = 0; i < frame->tile_count; i++){
2066 struct drm_prime_frame *drm_frame = (struct drm_prime_frame *)(void *) frame->tiles[i].data;
2067 av_frame_free(&drm_frame->av_frame);
2068 memset(drm_frame, 0, sizeof(struct drm_prime_frame));
2069 }
2070
2071 frame->callbacks.recycle = NULL;
2072}
2073
2074static void av_drm_prime_to_ug_drm_prime(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
2075 int width, int height, int pitch, const int * __restrict rgb_shift)
2076{
2077 UNUSED(width);
2078 UNUSED(height);
2079 UNUSED(pitch);
2080 UNUSED(rgb_shift);
2081
2082 struct video_frame_callbacks *callbacks = in_frame->opaque;
2083
2084 struct drm_prime_frame *out = (struct drm_prime_frame *)(void *) dst_buffer;
2085 memset(out, 0, sizeof(struct drm_prime_frame));
2086
2087
2088 AVDRMFrameDescriptor *av_drm_frame = (struct AVDRMFrameDescriptor *) in_frame->data[0];
2089 assert(av_drm_frame->nb_layers == 1);
2090 AVDRMLayerDescriptor *layer = &av_drm_frame->layers[0];
2091
2092 out->fd_count = av_drm_frame->nb_objects;
2093
2094 for(int i = 0; i < av_drm_frame->nb_objects; i++){
2095 out->dmabuf_fds[i] = av_drm_frame->objects[i].fd;
2096 }
2097
2098 out->planes = layer->nb_planes;
2099 out->drm_format = layer->format;
2100
2101 for(int i = 0; i < layer->nb_planes; i++){
2102 out->fd_indices[i] = layer->planes[i].object_index;
2103 out->modifiers[i] = av_drm_frame->objects[layer->planes[i].object_index].format_modifier;
2104 out->offsets[i] = layer->planes[i].offset;
2105 out->pitches[i] = layer->planes[i].pitch;
2106 }
2107
2108 out->av_frame = av_frame_clone(in_frame);
2109 callbacks->recycle = hw_drm_recycle_callback;
2110}
2111
2112static void ayuv64_to_uyvy(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
2113 int width, int height, int pitch, const int * __restrict rgb_shift)
2114{
2115 UNUSED(rgb_shift);
2116 for(int y = 0; y < height; ++y) {
2117 uint8_t *src = (uint8_t *)(void *)(in_frame->data[0] + in_frame->linesize[0] * y);
2118 uint8_t *dst = (uint8_t *)(void *)(dst_buffer + y * pitch);
2119
2120 OPTIMIZED_FOR (int x = 0; x < ((width + 1) & ~1); ++x) {
2121 *dst++ = (src[1] + src[9] / 2); // U
2122 *dst++ = src[3]; // Y
2123 *dst++ = (src[5] + src[13] / 2); // V
2124 *dst++ = src[11]; // Y
2125 }
2126 }
2127}
2128
2129static void ayuv64_to_y416(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
2130 int width, int height, int pitch, const int * __restrict rgb_shift)
2131{
2132 UNUSED(rgb_shift);
2133 assert((uintptr_t) in_frame->data[0] % 2 == 0);
2134 assert((uintptr_t) dst_buffer % 2 == 0);
2135 for(int y = 0; y < height; ++y) {
2136 uint16_t *src = (uint16_t *)(void *)(in_frame->data[0] + in_frame->linesize[0] * y);
2137 uint16_t *dst = (uint16_t *)(void *)(dst_buffer + y * pitch);
2138
2139 OPTIMIZED_FOR (int x = 0; x < width; ++x) {
2140 *dst++ = src[2]; // U
2141 *dst++ = src[1]; // Y
2142 *dst++ = src[3]; // V
2143 *dst++ = src[0]; // A
2144 src += 4;
2145 }
2146 }
2147}
2148
2149static void ayuv64_to_v210(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
2150 int width, int height, int pitch, const int * __restrict rgb_shift)
2151{
2152 UNUSED(rgb_shift);
2153 assert((uintptr_t) in_frame->data[0] % 2 == 0);
2154 assert((uintptr_t) dst_buffer % 4 == 0);
2155 for(int y = 0; y < height; ++y) {
2156 uint16_t *src = (uint16_t *)(void *)(in_frame->data[0] + in_frame->linesize[0] * y);
2157 uint32_t *dst = (uint32_t *)(void *)(dst_buffer + y * pitch);
2158
2159 OPTIMIZED_FOR (int x = 0; x < (width + 5) / 6; ++x) {
2160 uint32_t w;
2161
2162 w = ((src[2] >> 6U) + (src[6] >> 6U)) / 2; // U0
2163 w = w | (src[1] >> 6U) << 10U; // U0 Y0a
2164 w = w | ((src[3] >> 6U) + (src[7] >> 6U)) / 2 << 20U; // U0 Y0a V0
2165 *dst++ = w; // flush output
2166
2167 w = src[5]; // Y0b |
2168 src += 8; // move to next 2 words
2169 w = w | ((src[2] >> 6U) + (src[6] >> 6U)) / 2 << 10U; // Y0b | U1
2170 w = w | (src[1] >> 6U) << 20U; // Y0b | U1 Y1a
2171 *dst++ = w;
2172
2173 w = ((src[3] >> 6U) + (src[7] >> 6U)) / 2; // V1
2174 w = w | (src[5] >> 6U) << 10U; // V1 Y1a |
2175 src += 8;
2176 w = w | ((src[2] >> 6U) + (src[6] >> 6U)) / 2 << 20U; // V1 Y1a | U2
2177 *dst++ = w;
2178
2179 w = src[1]; // Y2a
2180 w = w | ((src[3] >> 6U) + (src[7] >> 6U)) / 2 << 10U; // Y2a V2
2181 w = w | ((src[5] >> 6U)) << 20U; // Y2a V2 Y2b |
2182 *dst++ = w;
2183 src += 8;
2184 }
2185 }
2186}
2187
2188static void vuya_to_uyvy(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
2189 int width, int height, int pitch, const int * __restrict rgb_shift) __attribute__((unused));
2190static void vuya_to_uyvy(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
2191 int width, int height, int pitch, const int * __restrict rgb_shift)
2192{
2193 (void) rgb_shift;
2194 for (ptrdiff_t y = 0; y < height; ++y) {
2195 unsigned char *src = in_frame->data[0] + in_frame->linesize[0] * y;
2196 unsigned char *dst = (void *) (dst_buffer + pitch * y);
2197
2198 OPTIMIZED_FOR (int x = 0; x < width / 2; x += 1) {
2199 *dst++ = (src[1] + src[5] + 1U) >> 1U;
2200 *dst++ = src[2];
2201 *dst++ = (src[0] + src[4] + 1U) >> 1U;
2202 *dst++ = src[6];
2203 src += 8;
2204 }
2205 if (width % 2 == 1) {
2206 *dst++ = src[1];
2207 *dst++ = src[2];
2208 *dst++ = src[0];
2209 *dst++ = 0;
2210 }
2211 }
2212}
2213
2214#if defined __GNUC__
2215static inline void vuyax_to_y416(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
2216 int width, int height, int pitch, bool use_alpha)
2217 __attribute__((always_inline));
2218#endif
2219static inline void vuyax_to_y416(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
2220 int width, int height, int pitch, bool use_alpha)
2221{
2222 assert((uintptr_t) dst_buffer % 2 == 0);
2223 for (ptrdiff_t y = 0; y < height; ++y) {
2224 unsigned char *src = in_frame->data[0] + in_frame->linesize[0] * y;
2225 uint16_t *dst = (void *) (dst_buffer + pitch * y);
2226
2227 OPTIMIZED_FOR (int x = 0; x < width; x += 1) {
2228 *dst++ = src[1] << 8U;
2229 *dst++ = src[2] << 8U;
2230 *dst++ = src[0] << 8U;
2231 *dst++ = use_alpha ? src[3] << 8U : 0xFFFF;
2232 src += 4;
2233 }
2234 }
2235}
2236static void vuya_to_y416(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
2237 int width, int height, int pitch, const int * __restrict rgb_shift) __attribute__((unused));
2238static void vuya_to_y416(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
2239 int width, int height, int pitch, const int * __restrict rgb_shift) {
2240 (void) rgb_shift;
2241 vuyax_to_y416(dst_buffer, in_frame, width, height, pitch, true);
2242}
2243static void vuyx_to_y416(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
2244 int width, int height, int pitch, const int * __restrict rgb_shift) __attribute__((unused));
2245static void vuyx_to_y416(char * __restrict dst_buffer, AVFrame * __restrict in_frame,
2246 int width, int height, int pitch, const int * __restrict rgb_shift) {
2247 (void) rgb_shift;
2248 vuyax_to_y416(dst_buffer, in_frame, width, height, pitch, false);
2249}
2250
2251typedef void av_to_uv_convert_f(char * __restrict dst_buffer, AVFrame * __restrict in_frame, int width, int height, int pitch, const int * __restrict rgb_shift);
2253
2261
2267
2269 // 10-bit YUV
2270 {AV_PIX_FMT_YUV420P10LE, v210, yuv420p10le_to_v210},
2271 {AV_PIX_FMT_YUV420P10LE, UYVY, yuv420p10le_to_uyvy},
2272 {AV_PIX_FMT_YUV420P10LE, RGB, yuv420p10le_to_rgb24},
2273 {AV_PIX_FMT_YUV420P10LE, RGBA, yuv420p10le_to_rgb32},
2274 {AV_PIX_FMT_YUV420P10LE, R10k, yuv420p10le_to_rgb30},
2275 {AV_PIX_FMT_YUV422P10LE, v210, yuv422p10le_to_v210},
2276 {AV_PIX_FMT_YUV422P10LE, UYVY, yuv422p10le_to_uyvy},
2277 {AV_PIX_FMT_YUV422P10LE, RGB, yuv422p10le_to_rgb24},
2278 {AV_PIX_FMT_YUV422P10LE, RGBA, yuv422p10le_to_rgb32},
2279 {AV_PIX_FMT_YUV422P10LE, R10k, yuv422p10le_to_rgb30},
2280 {AV_PIX_FMT_YUV444P10LE, v210, yuv444p10le_to_v210},
2281 {AV_PIX_FMT_YUV444P10LE, UYVY, yuv444p10le_to_uyvy},
2282 {AV_PIX_FMT_YUV444P10LE, R10k, yuv444p10le_to_r10k},
2283 {AV_PIX_FMT_YUV444P10LE, RGB, yuv444p10le_to_rgb24},
2284 {AV_PIX_FMT_YUV444P10LE, RGBA, yuv444p10le_to_rgb32},
2285 {AV_PIX_FMT_YUV444P10LE, R12L, yuv444p10le_to_r12l},
2286 {AV_PIX_FMT_YUV444P10LE, RG48, yuv444p10le_to_rg48},
2287 {AV_PIX_FMT_YUV444P10LE, Y416, yuv444p10le_to_y416},
2288#if P210_PRESENT
2289 {AV_PIX_FMT_P210LE, v210, p210le_to_v210},
2290 {AV_PIX_FMT_P210LE, UYVY, p210le_to_uyvy},
2291#endif
2292#if XV3X_PRESENT
2293 {AV_PIX_FMT_XV30, UYVY, xv30_to_uyvy},
2294 {AV_PIX_FMT_XV30, v210, xv30_to_v210},
2295 {AV_PIX_FMT_XV30, Y416, xv30_to_y416},
2296 {AV_PIX_FMT_Y212, UYVY, y210_to_uyvy},
2297 {AV_PIX_FMT_Y212, v210, y210_to_v210},
2298 {AV_PIX_FMT_Y212, Y416, y210_to_y416},
2299 {AV_PIX_FMT_Y212, Y216, memcpy_data},
2300#endif
2301#if Y210_PRESENT
2302 {AV_PIX_FMT_Y210, UYVY, y210_to_uyvy},
2303 {AV_PIX_FMT_Y210, v210, y210_to_v210},
2304 {AV_PIX_FMT_Y210, Y416, y210_to_y416},
2305 {AV_PIX_FMT_Y210, Y216, memcpy_data},
2306#endif
2307 {AV_PIX_FMT_P010LE, v210, p010le_to_v210},
2308 {AV_PIX_FMT_P010LE, UYVY, p010le_to_uyvy},
2309 // 8-bit YUV
2310 {AV_PIX_FMT_YUV420P, v210, yuv420p_to_v210},
2311 {AV_PIX_FMT_YUV420P, UYVY, yuv420p_to_uyvy},
2312 {AV_PIX_FMT_YUV420P, RGB, yuv420p_to_rgb24},
2313 {AV_PIX_FMT_YUV420P, RGBA, yuv420p_to_rgb32},
2314 {AV_PIX_FMT_YUV422P, v210, yuv422p_to_v210},
2315 {AV_PIX_FMT_YUV422P, UYVY, yuv422p_to_uyvy},
2316 {AV_PIX_FMT_YUV422P, RGB, yuv422p_to_rgb24},
2317 {AV_PIX_FMT_YUV422P, RGBA, yuv422p_to_rgb32},
2318 {AV_PIX_FMT_YUV444P, v210, yuv444p_to_v210},
2319 {AV_PIX_FMT_YUV444P, UYVY, yuv444p_to_uyvy},
2320 {AV_PIX_FMT_YUV444P, RGB, yuv444p_to_rgb24},
2321 {AV_PIX_FMT_YUV444P, RGBA, yuv444p_to_rgb32},
2322 // 8-bit YUV - this should be supposedly full range JPEG but lavd decoder doesn't honor
2323 // GPUJPEG's SPIFF header indicating YUV BT.709 limited range. The YUVJ pixel formats
2324 // are detected only for GPUJPEG generated JPEGs.
2325 {AV_PIX_FMT_YUVJ420P, v210, yuv420p_to_v210},
2326 {AV_PIX_FMT_YUVJ420P, UYVY, yuv420p_to_uyvy},
2327 {AV_PIX_FMT_YUVJ420P, RGB, yuv420p_to_rgb24},
2328 {AV_PIX_FMT_YUVJ420P, RGBA, yuv420p_to_rgb32},
2329 {AV_PIX_FMT_YUVJ422P, v210, yuv422p_to_v210},
2330 {AV_PIX_FMT_YUVJ422P, UYVY, yuv422p_to_uyvy},
2331 {AV_PIX_FMT_YUVJ422P, RGB, yuv422p_to_rgb24},
2332 {AV_PIX_FMT_YUVJ422P, RGBA, yuv422p_to_rgb32},
2333 {AV_PIX_FMT_YUVJ444P, v210, yuv444p_to_v210},
2334 {AV_PIX_FMT_YUVJ444P, UYVY, yuv444p_to_uyvy},
2335 {AV_PIX_FMT_YUVJ444P, RGB, yuv444p_to_rgb24},
2336 {AV_PIX_FMT_YUVJ444P, RGBA, yuv444p_to_rgb32},
2337#if VUYX_PRESENT
2338 {AV_PIX_FMT_VUYA, UYVY, vuya_to_uyvy},
2339 {AV_PIX_FMT_VUYX, UYVY, vuya_to_uyvy},
2340 {AV_PIX_FMT_VUYA, Y416, vuya_to_y416},
2341 {AV_PIX_FMT_VUYX, Y416, vuyx_to_y416},
2342#endif
2343 // 8-bit YUV (NV12)
2344 {AV_PIX_FMT_NV12, UYVY, nv12_to_uyvy},
2345 {AV_PIX_FMT_NV12, RGB, nv12_to_rgb24},
2346 {AV_PIX_FMT_NV12, RGBA, nv12_to_rgb32},
2347 // 12-bit YUV
2348 {AV_PIX_FMT_YUV444P12LE, R10k, yuv444p12le_to_r10k},
2349 {AV_PIX_FMT_YUV444P12LE, R12L, yuv444p12le_to_r12l},
2350 {AV_PIX_FMT_YUV444P12LE, RG48, yuv444p12le_to_rg48},
2351 {AV_PIX_FMT_YUV444P12LE, UYVY, yuv444p12le_to_uyvy},
2352 {AV_PIX_FMT_YUV444P12LE, v210, yuv444p12le_to_v210},
2353 {AV_PIX_FMT_YUV444P12LE, Y416, yuv444p12le_to_y416},
2354 // 16-bit YUV
2355 {AV_PIX_FMT_YUV444P16LE, R10k, yuv444p16le_to_r10k},
2356 {AV_PIX_FMT_YUV444P16LE, R12L, yuv444p16le_to_r12l},
2357 {AV_PIX_FMT_YUV444P16LE, RG48, yuv444p16le_to_rg48},
2358 {AV_PIX_FMT_YUV444P16LE, UYVY, yuv444p16le_to_uyvy},
2359 {AV_PIX_FMT_YUV444P16LE, v210, yuv444p16le_to_v210},
2360 {AV_PIX_FMT_YUV444P16LE, Y416, yuv444p16le_to_y416},
2361 {AV_PIX_FMT_AYUV64, UYVY, ayuv64_to_uyvy},
2362 {AV_PIX_FMT_AYUV64, v210, ayuv64_to_v210},
2363 {AV_PIX_FMT_AYUV64, Y416, ayuv64_to_y416},
2364 // RGB
2365 {AV_PIX_FMT_GBRAP, RGB, gbrap_to_rgb},
2366 {AV_PIX_FMT_GBRAP, RGBA, gbrap_to_rgba},
2367 {AV_PIX_FMT_GBRP, RGB, gbrp_to_rgb},
2368 {AV_PIX_FMT_GBRP, RGBA, gbrp_to_rgba},
2369 {AV_PIX_FMT_RGB24, UYVY, rgb24_to_uyvy},
2370 {AV_PIX_FMT_RGB24, RGBA, rgb24_to_rgb32},
2371 {AV_PIX_FMT_GBRP10LE, R10k, gbrp10le_to_r10k},
2372 {AV_PIX_FMT_GBRP10LE, RGB, gbrp10le_to_rgb},
2373 {AV_PIX_FMT_GBRP10LE, RGBA, gbrp10le_to_rgba},
2374 {AV_PIX_FMT_GBRP10LE, RG48, gbrp10le_to_rg48},
2375 {AV_PIX_FMT_GBRP12LE, R12L, gbrp12le_to_r12l},
2376 {AV_PIX_FMT_GBRP12LE, R10k, gbrp12le_to_r10k},
2377 {AV_PIX_FMT_GBRP12LE, RGB, gbrp12le_to_rgb},
2378 {AV_PIX_FMT_GBRP12LE, RGBA, gbrp12le_to_rgba},
2379 {AV_PIX_FMT_GBRP12LE, RG48, gbrp12le_to_rg48},
2380 {AV_PIX_FMT_GBRP16LE, R12L, gbrp16le_to_r12l},
2381 {AV_PIX_FMT_GBRP16LE, R10k, gbrp16le_to_r10k},
2382 {AV_PIX_FMT_GBRP16LE, RG48, gbrp16le_to_rg48},
2383 {AV_PIX_FMT_GBRP12LE, RGB, gbrp16le_to_rgb},
2384 {AV_PIX_FMT_GBRP12LE, RGBA, gbrp16le_to_rgba},
2385 {AV_PIX_FMT_RGB48LE, R12L, rgb48le_to_r12l},
2386 {AV_PIX_FMT_RGB48LE, RGBA, rgb48le_to_rgba},
2387#ifdef HWACC_VDPAU
2388 // HW acceleration
2389 {AV_PIX_FMT_VDPAU, HW_VDPAU, av_vdpau_to_ug_vdpau},
2390#endif
2391 {AV_PIX_FMT_DRM_PRIME, DRM_PRIME, av_drm_prime_to_ug_drm_prime},
2392};
2393#define AV_TO_UV_CONVERSION_COUNT (sizeof av_to_uv_conversions / sizeof av_to_uv_conversions[0])
2395
2396static QSORT_S_COMP_DEFINE(compare_convs, a, b, orig_c) {
2397 const struct av_to_uv_conversion *conv_a = a;
2398 const struct av_to_uv_conversion *conv_b = b;
2399 const struct pixfmt_desc *src_desc = orig_c;
2400 struct pixfmt_desc desc_a = get_pixfmt_desc(conv_a->uv_codec);
2401 struct pixfmt_desc desc_b = get_pixfmt_desc(conv_b->uv_codec);
2402
2403 int ret = compare_pixdesc(&desc_a, &desc_b, src_desc);
2404 return ret != 0 ? ret : (int) conv_a->uv_codec - (int) conv_b->uv_codec;
2405}
2406
2407static QSORT_S_COMP_DEFINE(compare_codecs, a, b, orig_c)
2408{
2409 const codec_t *codec_a = a;
2410 const codec_t *codec_b = b;
2411 const struct pixfmt_desc *src_desc = orig_c;
2412 const struct pixfmt_desc desc_a = get_pixfmt_desc(*codec_a);
2413 const struct pixfmt_desc desc_b = get_pixfmt_desc(*codec_b);
2414
2415 const int ret = compare_pixdesc(&desc_a, &desc_b, src_desc);
2416 return ret != 0 ? ret : (int) *codec_a - (int) *codec_b;
2417}
2418
2419static decoder_t get_av_and_uv_conversion(enum AVPixelFormat av_codec, codec_t uv_codec,
2420 codec_t *intermediate_c, av_to_uv_convert_fp *av_convert) {
2422 size_t convs_count = 0;
2423 for (const struct av_to_uv_conversion *c = av_to_uv_conversions; c < av_to_uv_conversions_end; c++) {
2424 if (c->av_codec == av_codec) {
2425 memcpy(convs + convs_count++, c, sizeof av_to_uv_conversions[0]);
2426 }
2427 }
2428 struct pixfmt_desc src_desc = av_pixfmt_get_desc(av_codec);
2429 qsort_s(convs, convs_count, sizeof convs[0], compare_convs, &src_desc);
2430 for (size_t i = 0; i < convs_count; ++i) {
2431 decoder_t dec = get_decoder_from_to(convs[i].uv_codec, uv_codec);
2432 if (dec != NULL) {
2433 if (av_convert) {
2434 *av_convert = convs[i].convert;
2435 }
2436 if (intermediate_c) {
2437 *intermediate_c = convs[i].uv_codec;
2438 }
2439 return dec;
2440 }
2441 }
2442 return NULL;
2443}
2444
2445void
2447{
2448 if (s == NULL || *s == NULL) {
2449 return;
2450 }
2451 av_to_uv_conversion_cuda_destroy(&(*s)->cuda_conv_state);
2452 free(*s);
2453 *s = NULL;
2454}
2455
2456static bool
2458{
2459 if (!cuda_devices_explicit) {
2460 return false;
2461 }
2462 struct av_to_uv_convert_cuda *s =
2463 get_av_to_uv_cuda_conversion(AV_PIX_FMT_YUV422P, UYVY);
2464 if (s == NULL) {
2465 return false;
2466 }
2468 return true;
2469}
2470
2471static enum AVPixelFormat
2472get_first_supported_cuda(const enum AVPixelFormat *fmts)
2473{
2474 for (; *fmts != AV_PIX_FMT_NONE; fmts++) {
2475 for (unsigned i = 0;
2476 i < sizeof from_lavc_cuda_supp_formats /
2478 ++i) {
2479 if (*fmts == from_lavc_cuda_supp_formats[i]) {
2480 return *fmts;
2481 }
2482 }
2483 }
2484 return AV_PIX_FMT_NONE;
2485}
2486
2488 av_to_uv_convert_t *ret = calloc(1, sizeof *ret);
2489 ret->dst_pixfmt = uv_codec;
2490
2491 if (cuda_conv_enabled()) {
2492 enum AVPixelFormat f[2] = { av_codec, AV_PIX_FMT_NONE };
2493 if (get_first_supported_cuda(f) != AV_PIX_FMT_NONE) {
2494 ret->cuda_conv_state =
2495 get_av_to_uv_cuda_conversion(av_codec, uv_codec);
2496 if (ret->cuda_conv_state != NULL) {
2497 MSG(NOTICE, "Using CUDA FFmpeg conversions.\n");
2498 return ret;
2499 }
2500 MSG(ERROR, "Unable to initialize CUDA conv state!\n");
2501 }
2502 }
2503
2504 codec_t mapped_pix_fmt = get_av_to_ug_pixfmt(av_codec);
2505 if (mapped_pix_fmt == uv_codec) {
2506 if (codec_is_planar(uv_codec)) {
2507 log_msg(LOG_LEVEL_ERROR, "Planar pixfmts not support here, please report a bug!\n");
2508 free(ret);
2509 return NULL;
2510 }
2511 return ret;
2512 }
2513 if (mapped_pix_fmt != VC_NONE) {
2514 decoder_t dec = get_decoder_from_to(mapped_pix_fmt, uv_codec);
2515 if (dec) {
2516 ret->dec = dec;
2517 return ret;
2518 }
2519 }
2520
2521 for (const struct av_to_uv_conversion *conversions = av_to_uv_conversions;
2522 conversions < av_to_uv_conversions_end; conversions++) {
2523 if (conversions->av_codec == av_codec &&
2524 conversions->uv_codec == uv_codec) {
2525 ret->convert = conversions->convert;
2527 return ret;
2528 }
2529 }
2530
2531 av_to_uv_convert_fp av_convert = NULL;
2532 codec_t intermediate = VC_NONE;
2533 decoder_t dec = get_av_and_uv_conversion(av_codec, uv_codec,
2534 &intermediate, &av_convert);
2535 if (!dec) {
2536 free(ret);
2537 return NULL;
2538 }
2539 ret->dec = dec;
2540 ret->convert = av_convert;
2541 ret->src_pixfmt = intermediate;
2544
2545 return ret;
2546}
2547
2557static enum AVPixelFormat get_ug_codec_to_av(const enum AVPixelFormat *fmt, codec_t *ugc, bool use_hwaccel) {
2558 // directly mapped UG codecs
2559 for (const enum AVPixelFormat *fmt_it = fmt; *fmt_it != AV_PIX_FMT_NONE; fmt_it++) {
2560 //If hwaccel is not enabled skip hw accel pixfmts even if there are convert functions
2561 if (!use_hwaccel && (av_pix_fmt_desc_get(*fmt_it)->flags & AV_PIX_FMT_FLAG_HWACCEL)) {
2562 continue;
2563 }
2564
2565 codec_t mapped_pix_fmt = get_av_to_ug_pixfmt(*fmt_it);
2566 if (mapped_pix_fmt != VIDEO_CODEC_NONE) {
2567 if (*ugc == VIDEO_CODEC_NONE) { // just probing internal format
2568 *ugc = mapped_pix_fmt;
2569 return AV_PIX_FMT_NONE;
2570 }
2571 if (*ugc == mapped_pix_fmt || get_decoder_from_to(mapped_pix_fmt, *ugc)) { // either mapped or convertible
2572 return *fmt_it;
2573 }
2574 }
2575
2576 if (*ugc != VIDEO_CODEC_NONE) {
2577 for (const struct av_to_uv_conversion *c = av_to_uv_conversions; c < av_to_uv_conversions_end; c++) {
2578 if (c->av_codec == *fmt_it && *ugc == c->uv_codec) {
2579 return *fmt_it;
2580 }
2581 }
2582
2583 // AV+UV conversion needed
2584 codec_t c;
2585 if (get_av_and_uv_conversion(*fmt_it, *ugc, &c, NULL)) {
2586 log_msg(LOG_LEVEL_VERBOSE, __FILE__ ": selected conversion from %s to %s with %s intermediate.\n",
2587 av_get_pix_fmt_name(*fmt_it), get_codec_name(*ugc), get_codec_name(c));
2588 return *fmt_it;
2589 }
2590 } else { // probe
2591 struct av_to_uv_conversion usable_convs[sizeof av_to_uv_conversions / sizeof av_to_uv_conversions[0]];
2592 int usable_convs_count = 0;
2593 for (const struct av_to_uv_conversion *c = av_to_uv_conversions; c < av_to_uv_conversions_end; c++) {
2594 if (c->av_codec == *fmt_it) {
2595 memcpy(usable_convs + usable_convs_count++, c, sizeof av_to_uv_conversions[0]);
2596 }
2597 }
2598 if (usable_convs_count == 0) {
2599 continue;
2600 }
2601 struct pixfmt_desc src_desc = av_pixfmt_get_desc(*fmt_it);
2602 qsort_s(usable_convs, usable_convs_count, sizeof usable_convs[0], compare_convs, &src_desc);
2603 *ugc = usable_convs[0].uv_codec;
2604 return AV_PIX_FMT_NONE;
2605 }
2606 }
2607 return AV_PIX_FMT_NONE;
2608}
2609
2610static codec_t
2611probe_cuda_ug_to_av(const enum AVPixelFormat *fmts)
2612{
2613 const enum AVPixelFormat sel_fmt = get_first_supported_cuda(fmts);
2614 if (sel_fmt == AV_PIX_FMT_NONE) {
2615 return VIDEO_CODEC_NONE;
2616 }
2617
2618 codec_t ug_codecs[VC_COUNT];
2619 int ugc_count = 0;
2620 for (codec_t c = VC_FIRST; c < VC_END; ++c) {
2621 if (!is_codec_opaque(c)) {
2622 ug_codecs[ugc_count++] = c;
2623 }
2624 }
2625
2626 struct pixfmt_desc src_desc = av_pixfmt_get_desc(sel_fmt);
2627
2628 qsort_s(ug_codecs, ugc_count, sizeof ug_codecs[0], compare_codecs,
2629 &src_desc);
2630 return ug_codecs[0];
2631}
2632
2633codec_t get_best_ug_codec_to_av(const enum AVPixelFormat *fmt, bool use_hwaccel) {
2635 return probe_cuda_ug_to_av(fmt);
2636 }
2638 get_ug_codec_to_av(fmt, &c, use_hwaccel);
2639 return c;
2640}
2641
2642enum AVPixelFormat lavd_get_av_to_ug_codec(const enum AVPixelFormat *fmt, codec_t c, bool use_hwaccel) {
2643 if (cuda_conv_enabled() &&
2644 get_first_supported_cuda(fmt) != AV_PIX_FMT_NONE) {
2646 }
2647 return get_ug_codec_to_av(fmt, &c, use_hwaccel);
2648}
2649
2650enum AVPixelFormat
2652{
2653 *av_conv = calloc(1, sizeof **av_conv);
2654 (*av_conv)->dst_pixfmt = color_spec;
2655
2656 if (get_ug_to_av_pixfmt(color_spec) != AV_PIX_FMT_NONE) {
2657 return get_ug_to_av_pixfmt(color_spec);
2658 }
2659
2660 struct pixfmt_desc out_desc = get_pixfmt_desc(color_spec);
2661 decoder_t dec;
2662 if (out_desc.rgb) {
2663 if (out_desc.depth > 8 && (dec = get_decoder_from_to(RG48, color_spec))) {
2664 (*av_conv)->dec = dec;
2665 return AV_PIX_FMT_RGB48LE;
2666 } else if ((dec = get_decoder_from_to(RGB, color_spec))) {
2667 (*av_conv)->dec = dec;
2668 return AV_PIX_FMT_RGB24;
2669 }
2670 }
2671#if XV3X_PRESENT
2672 if (out_desc.depth > 8 && (dec = get_decoder_from_to(Y416, color_spec))) {
2673 (*av_conv)->dec = dec;
2674 return AV_PIX_FMT_XV36;
2675 }
2676#endif
2677 if ((dec = get_decoder_from_to(UYVY, color_spec))) {
2678 (*av_conv)->dec = dec;
2679 return AV_PIX_FMT_UYVY422;
2680 }
2681 for (const struct av_to_uv_conversion *c = av_to_uv_conversions; c < av_to_uv_conversions_end; c++) {
2682 if (c->uv_codec == color_spec) { // pick any (first usable)
2683 memset(*av_conv, 0, sizeof **av_conv);
2684 (*av_conv)->convert = c->convert;
2685 return c->av_codec;
2686 }
2687 }
2688 free(*av_conv);
2689 *av_conv = NULL;
2690 return AV_PIX_FMT_NONE;
2691}
2692
2693static void
2694do_av_to_uv_convert(const av_to_uv_convert_t *s, char *__restrict dst_buffer,
2695 AVFrame *__restrict in_frame, int width, int height, int pitch,
2696 const int *__restrict rgb_shift)
2697{
2698 unsigned char *dec_input = in_frame->data[0];
2699 size_t src_linesize = in_frame->linesize[0];
2700 unsigned char *tmp = NULL;
2701 if (s->convert) {
2702 DEBUG_TIMER_START(lavd_av_to_uv);
2703 if (!s->dec) {
2704 s->convert(dst_buffer, in_frame, width, height, pitch, rgb_shift);
2705 DEBUG_TIMER_STOP(lavd_av_to_uv);
2706 return;
2707 }
2708 src_linesize = vc_get_linesize(width, s->src_pixfmt);
2709 dec_input = tmp = malloc(
2710 vc_get_datalen(width, height, s->src_pixfmt) + MAX_PADDING);
2711 int default_rgb_shift[] = { DEFAULT_R_SHIFT, DEFAULT_G_SHIFT,
2713 s->convert((char *) dec_input, in_frame, width, height,
2714 src_linesize, default_rgb_shift);
2715 DEBUG_TIMER_STOP(lavd_av_to_uv);
2716 }
2717 if (s->dec) {
2718 DEBUG_TIMER_START(lavd_dec);
2719 int dst_size = vc_get_size(width, s->dst_pixfmt);
2720 for (ptrdiff_t i = 0; i < height; ++i) {
2721 s->dec((unsigned char *) dst_buffer + i * pitch,
2722 dec_input + i * src_linesize, dst_size,
2723 rgb_shift[0], rgb_shift[1], rgb_shift[2]);
2724 }
2725 DEBUG_TIMER_STOP(lavd_dec);
2726 free(tmp);
2727 return;
2728 }
2729
2730 // memcpy only
2731 int linesize = vc_get_linesize(width, s->dst_pixfmt);
2732 for (ptrdiff_t i = 0; i < height; ++i) {
2733 memcpy(dst_buffer + i * pitch, in_frame->data[0] + i * in_frame->linesize[0], linesize);
2734 }
2735}
2736
2739 unsigned char *out_data;
2740 AVFrame *in_frame;
2744 const int *rgb_shift;
2745};
2746
2747static void *
2749{
2750 struct convert_task_data *d = arg;
2751 do_av_to_uv_convert(d->convert, (char *) d->out_data, d->in_frame,
2752 d->width, d->height, d->pitch, d->rgb_shift);
2753 return NULL;
2754}
2755
2756void
2758 char *dst, AVFrame *in, int width, int height, int pitch,
2759 const int rgb_shift[3])
2760{
2761 if (convert->cuda_conv_state != NULL) {
2762 av_to_uv_convert_cuda(convert->cuda_conv_state, dst, in, width,
2764 return;
2765 }
2766
2767 if (codec_is_const_size(convert->dst_pixfmt)) { // VAAPI etc
2769 rgb_shift);
2770 return;
2771 }
2772
2773 const int cpu_count = get_cpu_core_count();
2774
2775 struct convert_task_data d[cpu_count];
2776 AVFrame parts[cpu_count];
2777 for (int i = 0; i < cpu_count; ++i) {
2778 int row_height = (height / cpu_count) & ~1; // needs to be even
2779 unsigned char *part_dst =
2780 (unsigned char *) dst + (size_t) i * row_height * pitch;
2781 memcpy(parts[i].linesize, in->linesize, sizeof in->linesize);
2782 const AVPixFmtDescriptor *fmt_desc =
2783 av_pix_fmt_desc_get(in->format);
2784 for (int plane = 0; plane < AV_NUM_DATA_POINTERS; ++plane) {
2785 if (in->data[plane] == NULL) {
2786 break;
2787 }
2788 parts[i].data[plane] =
2789 in->data[plane] +
2790 ((i * row_height * in->linesize[plane]) >>
2791 (plane == 0 ? 0 : fmt_desc->log2_chroma_h));
2792 }
2793 if (i == cpu_count - 1) {
2794 row_height = height - row_height * (cpu_count - 1);
2795 }
2796 d[i] =
2797 (struct convert_task_data){ convert, part_dst, &parts[i],
2798 width, row_height, pitch,
2799 rgb_shift };
2800 }
2801 task_run_parallel(convert_task, cpu_count, d, sizeof d[0], NULL);
2802}
2803
2804#pragma GCC diagnostic pop
2805
2806/* vi: set expandtab sw=8: */
convert_t convert
#define UNUSED(x)
struct video_frame * frame
const char * fmt
int vc_get_linesize(unsigned int width, codec_t codec)
const char * get_codec_name(codec_t codec)
#define Y_SCALE(in_depth)
Definition color.h:151
int32_t comp_type_t
Definition color.h:65
#define YCBCR_TO_R_709_SCALED(in_depth, y, cb, cr)
Definition color.h:154
#define YCBCR_TO_G_709_SCALED(in_depth, y, cb, cr)
Definition color.h:156
#define COMP_BASE
Definition color.h:66
#define CLAMP_FULL(val, depth)
Definition color.h:163
#define YCBCR_TO_B_709_SCALED(in_depth, y, cb, cr)
Definition color.h:159
void log_msg(int level, const char *format,...)
Definition debug.cpp:130
#define DEBUG_TIMER_START(name)
Definition debug.h:324
#define DEBUG_TIMER_STOP(name)
Definition debug.h:325
#define LOG_LEVEL_ERROR
general errors
Definition debug.h:59
#define LOG_LEVEL_VERBOSE
Definition debug.h:63
#define MSG(l, fmt,...)
Definition debug.h:96
static void gbrp16le_to_rgba(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void yuv420p10le_to_v210(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void yuv444p10le_to_rgb(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift, bool rgba)
av_to_uv_convert_t * get_av_to_uv_conversion(int av_codec, codec_t uv_codec)
static decoder_t get_av_and_uv_conversion(enum AVPixelFormat av_codec, codec_t uv_codec, codec_t *intermediate_c, av_to_uv_convert_fp *av_convert)
static void * convert_task(void *arg)
void av_to_uv_convert_f(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
enum AVPixelFormat lavd_get_av_to_ug_codec(const enum AVPixelFormat *fmt, codec_t c, bool use_hwaccel)
codec_t get_best_ug_codec_to_av(const enum AVPixelFormat *fmt, bool use_hwaccel)
static void yuvp10le_to_rgb(int subsampling, char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift, int out_bit_depth)
static void yuv422p_to_rgb32(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
void av_to_uv_conversion_destroy(av_to_uv_convert_t **s)
static void gbrpXXle_to_rg48(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, unsigned int in_depth)
static void nv12_to_rgb24(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void yuv422p10le_to_v210(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
#define B
static void yuv444p10le_to_rg48(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void gbrp16le_to_rgb(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
enum AVPixelFormat pick_av_convertible_to_ug(codec_t color_spec, av_to_uv_convert_t **av_conv)
static void yuv444p10le_to_v210(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void gbrp_to_rgb(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void yuv444p12le_to_v210(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void gbrp12le_to_rgb(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void yuv444p10le_to_r10k(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
#define AV_TO_UV_CONVERSION_COUNT
static void yuv444p10le_to_r12l(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static const struct av_to_uv_conversion * av_to_uv_conversions_end
static void gbrp10le_to_rg48(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void yuv444p12le_to_r10k(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void yuv444p10le_to_rgb32(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void vuyx_to_y416(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift) __attribute__((unused))
static void rgb24_to_rgb32(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void yuv444p16le_to_v210(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void yuv422p10le_to_uyvy(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void yuv444p12le_to_r12l(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static enum AVPixelFormat get_ug_codec_to_av(const enum AVPixelFormat *fmt, codec_t *ugc, bool use_hwaccel)
static void yuv444p16le_to_r12l(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void rgb48le_to_r12l(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void yuv444pXXle_to_rg48(int depth, char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void yuv444p_to_rgb24(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void gbrp16le_to_rg48(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void gbrp10le_to_rgb(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static codec_t probe_cuda_ug_to_av(const enum AVPixelFormat *fmts)
#define MAKE_YUV_TO_RGB_FUNCTION(subs, out_bit_depth)
static void yuv420p_to_uyvy(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void nv12_to_rgb(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift, bool rgba)
static void ayuv64_to_y416(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void hw_drm_recycle_callback(struct video_frame *frame)
static void yuv444p10le_to_y416(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
#define R
static void gbrpXXle_to_rgb(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift, unsigned int in_depth)
static void vuya_to_uyvy(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift) __attribute__((unused))
static void gbrap_to_rgb_rgba(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift, int comp_count)
static void yuv444p12le_to_uyvy(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void nv12_to_rgb32(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void yuv444p_to_v210(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void yuv444p16le_to_uyvy(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void gbrp16le_to_r12l(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void vuya_to_y416(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift) __attribute__((unused))
static const struct av_to_uv_conversion av_to_uv_conversions[]
static void memcpy_data(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift) __attribute__((unused))
#define BYTE_SWAP(x)
static void yuv420p10le_to_uyvy(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void yuv444pXXle_to_r10k(int depth, char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void yuv420p_to_v210(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void ayuv64_to_uyvy(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void yuv422p_to_v210(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void vuyax_to_y416(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, bool use_alpha)
static void yuv444p16le_to_y416(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void yuv444p1Xle_to_y416(unsigned in_depth, char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void gbrp_to_rgba(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static enum AVPixelFormat get_first_supported_cuda(const enum AVPixelFormat *fmts)
#define WRITE_RES_YUV8P_TO_RGB(DST)
#define MOD_NAME
static void yuv444p16le_to_rg48(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void gbrp10le_to_rgba(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void av_drm_prime_to_ug_drm_prime(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void yuv420p_to_rgb24(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
#define S(x)
static void nv12_to_uyvy(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void gbrp16le_to_r10k(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void yuv444p_to_rgb32(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static bool cuda_conv_enabled()
static void gbrp12le_to_rgba(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void gbrp12le_to_r10k(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void yuv444p_to_rgb(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift, bool rgba)
static void rgb24_to_uyvy(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void ayuv64_to_v210(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void yuv420p_to_rgb32(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
#define WRITE_RES_YUV10P_TO_RGB(Y, DST)
static void yuv444p1Xle_to_v210(unsigned in_depth, char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void yuv8p_to_rgb(int subsampling, char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift, bool rgba)
static void yuv444p_to_uyvy(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void gbrp12le_to_rg48(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void gbrap_to_rgba(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void yuv444p12le_to_y416(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void gbrpXXle_to_rgba(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift, unsigned int in_depth)
static void yuv444p16le_to_r10k(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void gbrpXXle_to_r10k(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift, unsigned int in_depth)
static void yuv444p1Xle_to_uyvy(unsigned in_depth, char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void p010le_to_uyvy(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
void av_to_uv_convert(const av_to_uv_convert_t *convert, char *dst, AVFrame *in, int width, int height, int pitch, const int rgb_shift[3])
#define MK_RGBA(r, g, b, alpha_mask, depth)
static void gbrap_to_rgb(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void do_av_to_uv_convert(const av_to_uv_convert_t *s, char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void yuv422p_to_rgb24(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
#define G
static void gbrp12le_to_r12l(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
av_to_uv_convert_f * av_to_uv_convert_fp
static void gbrp10le_to_r10k(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void p010le_to_v210(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void yuv444p12le_to_rg48(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void gbrpXXle_to_r12l(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift, unsigned int in_depth)
static void yuv444p10le_to_uyvy(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void yuv444pXXle_to_r12l(int depth, char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void yuv422p_to_uyvy(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void rgb48le_to_rgba(char *__restrict dst_buffer, AVFrame *__restrict frame, int width, int height, int pitch, const int *__restrict rgb_shift)
static void yuv444p10le_to_rgb24(char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
void av_to_uv_convert_cuda(struct av_to_uv_convert_cuda *state, char *__restrict dst_buffer, AVFrame *__restrict in_frame, int width, int height, int pitch, const int *__restrict rgb_shift)
struct av_to_uv_convert_cuda * get_av_to_uv_cuda_conversion(enum AVPixelFormat av_codec, codec_t uv_codec)
void av_to_uv_conversion_cuda_destroy(struct av_to_uv_convert_cuda **s)
static enum AVPixelFormat from_lavc_cuda_supp_formats[]
bool cuda_devices_explicit
–cuda-device/-D specified expilcitly
Definition host.cpp:169
void hw_vdpau_recycle_callback(struct video_frame *frame)
void hw_vdpau_copy_callback(struct video_frame *frame)
void hw_vdpau_frame_init(hw_vdpau_frame *frame)
hw_vdpau_frame * hw_vdpau_frame_from_avframe(hw_vdpau_frame *dst, const AVFrame *src)
This file contains functions related to hw acceleration.
struct pixfmt_desc av_pixfmt_get_desc(enum AVPixelFormat pixfmt)
#define CLAMP(x, low, high)
Definition macros.h:67
#define OPTIMIZED_FOR
Definition macros.h:127
int get_cpu_core_count(void)
Definition misc.cpp:218
static void vc_copylineRGBtoUYVY(unsigned char *__restrict dst, const unsigned char *__restrict src, int dst_len, int rshift, int gshift, int bshift)
Converts RGB to UYVY.
decoder_t get_decoder_from_to(codec_t in, codec_t out)
static void vc_copylineRG48toR12L(unsigned char *__restrict dst, const unsigned char *__restrict src, int dst_len, int rshift, int gshift, int bshift)
Converts RG48 to R12L. Converts 16-bit RGB to 12-bit packed RGB in full range (compatible with SMPTE ...
static void vc_copylineRG48toRGBA(unsigned char *__restrict dst, const unsigned char *__restrict src, int dst_len, int rshift, int gshift, int bshift)
#define DEFAULT_B_SHIFT
Definition pixfmt_conv.h:72
decoder_func_t vc_copylineRGBtoRGBA
#define DEFAULT_R_SHIFT
Definition pixfmt_conv.h:70
decoder_func_t * decoder_t
Definition pixfmt_conv.h:96
#define DEFAULT_G_SHIFT
Definition pixfmt_conv.h:71
#define qsort_s
Definition qsort_s.h:63
#define QSORT_S_COMP_DEFINE(name, a, b, context)
Definition qsort_s.h:71
struct __attribute__((packed))
Definition rtp.h:88
av_to_uv_convert_fp convert
enum AVPixelFormat av_codec
av_to_uv_convert_fp convert
struct av_to_uv_convert_cuda * cuda_conv_state
const av_to_uv_convert_t * convert
unsigned char * out_data
uint32_t offsets[4]
Definition hwaccel_drm.h:18
uint32_t pitches[4]
Definition hwaccel_drm.h:17
uint32_t fd_indices[4]
Definition hwaccel_drm.h:16
uint32_t drm_format
Definition hwaccel_drm.h:10
uint64_t modifiers[4]
Definition hwaccel_drm.h:19
struct AVFrame * av_frame
Definition hwaccel_drm.h:21
int depth
bit depth; 0 means that whole struct is undefined
Definition types.h:140
bool rgb
Definition types.h:142
char * data
Raw tile data. Pointer must be at least 4B aligned.
Definition types.h:287
Struct containing callbacks of a video_frame.
Definition types.h:230
void(* recycle)(struct video_frame *)
Definition types.h:263
void(* copy)(struct video_frame *)
Definition types.h:271
Struct video_frame represents a video frame and contains video description.
Definition types.h:305
struct tile tiles[FLEXIBLE_ARRAY_MEMBER]
Definition types.h:345
unsigned int tile_count
Definition types.h:344
struct video_frame_callbacks callbacks
Definition types.h:324
depth
Definition types.h:125
subsampling
Definition types.h:132
codec_t
Definition types.h:65
@ R10k
RGB 10-bit packed - RGBX, big-endian (2 bit padding)
Definition types.h:73
@ RGB
RGB 8-bit (packed into 24-bit word)
Definition types.h:80
@ UYVY
YCbCr 422 8-bit - Cb Y0 Cr Y1.
Definition types.h:71
@ VIDEO_CODEC_NONE
dummy color spec
Definition types.h:66
@ HW_VDPAU
VDPAU hardware surface.
Definition types.h:91
@ VC_FIRST
Definition types.h:69
@ RG48
16-bit RGB little-endian (RlRhGl...)
Definition types.h:95
@ Y416
interleaved little-endian YCbCr 4444 16-bit - UYVA
Definition types.h:99
@ VC_NONE
Definition types.h:67
@ Y216
YCbCr 422 16-bit little-endian - Y0 Cb Y1 Cr.
Definition types.h:98
@ R12L
RGB 12-bit packed, little-endian.
Definition types.h:74
@ DRM_PRIME
DRM Prime buffer, data contains struct drm_prime_frame.
Definition types.h:107
@ VC_COUNT
Definition types.h:109
@ RGBA
RGBA 8-bit, big-endian.
Definition types.h:70
@ v210
YCbCr 422 10-bit - xVY0U|xY2UY1|xUY3V|xY5VY4, little-endian (2 bit padding /'x'/),...
Definition types.h:75
@ VC_END
Definition types.h:110
enum AVPixelFormat get_ug_to_av_pixfmt(codec_t ug_codec)
Definition utils.c:84
codec_t get_av_to_ug_pixfmt(enum AVPixelFormat av_pixfmt)
Definition utils.c:75
This is an umbrella header for video functions.
struct pixfmt_desc get_pixfmt_desc(codec_t pixfmt)
bool is_codec_opaque(codec_t codec)
int vc_get_size(unsigned int width, codec_t codec)
void watch_pixfmt_degrade(const char *mod_name, struct pixfmt_desc desc_src, struct pixfmt_desc desc_dst)
bool codec_is_const_size(codec_t codec)
Returns TRUE if specified pixelformat has constant size regardles of resolution. If so the block_size...
bool codec_is_planar(codec_t codec)
int compare_pixdesc(const struct pixfmt_desc *desc_a, const struct pixfmt_desc *desc_b, const struct pixfmt_desc *src_desc)
size_t vc_get_datalen(unsigned int width, unsigned int height, codec_t codec)
#define MAX_PADDING
Definition video_codec.h:63
void task_run_parallel(runnable_t task, int worker_count, void *data, size_t data_size, void **res)
Definition worker.cpp:294