FreeRDP
Loading...
Searching...
No Matches
av1.c
1
20
21#include <winpr/sysinfo.h>
22
23#include <freerdp/codec/av1.h>
24#include <freerdp/primitives.h>
25#include <freerdp/log.h>
26#include <freerdp/codec/region.h>
27
28#define TAG FREERDP_TAG("codec.av1")
29
30#if defined(WITH_LIBAOM)
31#include <aom/aom.h>
32
33#include <aom/aom_decoder.h>
34#include <aom/aom_encoder.h>
35
36#include <aom/aom_image.h>
37#include <aom/aomcx.h>
38#include <aom/aomdx.h>
39#endif
40
41#include "h264.h"
42
43#if defined(WITH_DAV1D)
44#include <dav1d/dav1d.h>
45#endif
46
47#if defined(WITH_AV1_WEBCODECS)
48#include "av1_webcodecs.h"
49#endif
50
51#if defined(WITH_AV1_VIDEOTOOLBOX)
52#include "av1_videotoolbox.h"
53#endif
54
55#if defined(WITH_LIBAOM) || defined(WITH_DAV1D)
56
57#if defined(WITH_LIBYUV)
58#include <libyuv.h>
59#endif
60
61struct S_FREERDP_AV1_CONTEXT
62{
63 wLog* log;
64 bool encoder;
65 bool initialized;
66#if defined(WITH_LIBAOM)
67 aom_codec_ctx_t ctx;
68 aom_codec_enc_cfg_t ecfg;
69 aom_codec_pts_t framecount;
70 aom_enc_frame_flags_t eflags;
71 aom_codec_flags_t flags;
72 aom_codec_iface_t* iface;
73 /* the next frame converts the whole surface to YUV (after a reset or a failure) */
74 bool fullFrameNext;
75 UINT32 cqLevel; /* FREERDP_AV1_CONTEXT_OPTION_CQ_LEVEL, 0: libaom's */
76 UINT32 speed; /* FREERDP_AV1_CONTEXT_OPTION_SPEED */
77 /* encoder statistics, see av1_encoder_stats() */
78 struct
79 {
80 UINT64 startNS;
81 UINT64 encodeNS;
82 UINT64 maxEncodeNS;
83 UINT64 bytes;
84 UINT32 frames;
85 } stats;
86#endif
87#if defined(WITH_LIBAOM) && !defined(WITH_DAV1D)
88 aom_codec_dec_cfg_t dcfg;
89#endif
90#if defined(WITH_DAV1D)
91 Dav1dContext* dav1d;
92#endif
93#if defined(WITH_AV1_WEBCODECS)
94 int webcodecs; /* VideoDecoder handle, 0 if unused */
95#endif
96#if defined(WITH_AV1_VIDEOTOOLBOX)
97 AV1_VT* vt; /* nullptr without a hardware AV1 decoder */
98 bool vtStream; /* the current stream is VideoToolbox's (else the software decoder's) */
99#endif
100 BYTE* yuvdata[3];
101 UINT32 yuvWidth;
102 UINT32 yuvStride[3];
103 UINT32 yuvHeight;
104};
105
106#if defined(WITH_LIBAOM)
107static void av1_aom_destroy(FREERDP_AV1_CONTEXT* av1)
108{
109 const aom_codec_err_t rc = aom_codec_destroy(&av1->ctx);
110 if (rc != AOM_CODEC_OK)
111 WLog_Print(av1->log, WLOG_WARN, "aom_codec_destroy: %s", aom_codec_err_to_string(rc));
112}
113
114/* Speed preset for AOM_USAGE_REALTIME, 0 (slowest) to 12 (fastest). libaom defaults to 0 and
115 * raises it to 7 only for frames of 1080 lines or more, so smaller desktops got the slowest
116 * search. */
117#define AV1_AOM_RT_SPEED 10
118
119/* libaom encodes on one thread by default; more than 4 did not make 1080p faster. */
120#define AV1_AOM_MAX_THREADS 4
121
122static unsigned int av1_aom_threads(void)
123{
124 SYSTEM_INFO sysInfo = WINPR_C_ARRAY_INIT;
125 GetNativeSystemInfo(&sysInfo);
126 if (sysInfo.dwNumberOfProcessors < 1)
127 return 1;
128 if (sysInfo.dwNumberOfProcessors > AV1_AOM_MAX_THREADS)
129 return AV1_AOM_MAX_THREADS;
130 return sysInfo.dwNumberOfProcessors;
131}
132
133/* aom_codec_enc_init() starts from the defaults again, so apply these after every init. */
134WINPR_ATTR_NODISCARD
135static BOOL av1_aom_apply_controls(FREERDP_AV1_CONTEXT* av1)
136{
137 const struct
138 {
139 int id;
140 int value;
141 const char* name;
142 } controls[] = {
143 { AOME_SET_CPUUSED, (int)av1->speed, "AOME_SET_CPUUSED" },
144 /* screen content tools (palette, intra block copy): sharp text at a lower bit rate */
145 { AV1E_SET_TUNE_CONTENT, AOM_CONTENT_SCREEN, "AV1E_SET_TUNE_CONTENT" },
146 { AV1E_SET_ROW_MT, 1, "AV1E_SET_ROW_MT" },
147 /* the quality the two quality modes keep; the other modes ignore it */
148 { AOME_SET_CQ_LEVEL, (int)av1->cqLevel, "AOME_SET_CQ_LEVEL" },
149 };
150
151 const bool quality = (av1->ecfg.rc_end_usage == AOM_Q) || (av1->ecfg.rc_end_usage == AOM_CQ);
152 for (size_t x = 0; x < ARRAYSIZE(controls); x++)
153 {
154 if ((controls[x].id == AOME_SET_CQ_LEVEL) && (!quality || (av1->cqLevel == 0)))
155 continue;
156 const aom_codec_err_t rc = aom_codec_control(&av1->ctx, controls[x].id, controls[x].value);
157 if (rc != AOM_CODEC_OK)
158 {
159 WLog_Print(av1->log, WLOG_WARN, "aom_codec_control(%s, %d): %s", controls[x].name,
160 controls[x].value, aom_codec_err_to_string(rc));
161 return FALSE;
162 }
163 }
164 return TRUE;
165}
166
167/* Clip the damaged rectangle to the frame and round it out to even coordinates, so the
168 * I420 chroma samples it touches are whole. FALSE: encode the whole frame. */
169WINPR_ATTR_NODISCARD
170static BOOL av1_aom_damage(const FREERDP_AV1_CONTEXT* av1, const RECTANGLE_16* regionRect,
171 UINT32 width, UINT32 height, RECTANGLE_16* damage)
172{
173 if (av1->fullFrameNext || !regionRect)
174 return FALSE;
175
176 const UINT32 left = regionRect->left & ~1u;
177 const UINT32 top = regionRect->top & ~1u;
178 const UINT32 right = MIN(width, (regionRect->right + 1u) & ~1u);
179 const UINT32 bottom = MIN(height, (regionRect->bottom + 1u) & ~1u);
180 if ((left >= right) || (top >= bottom))
181 return FALSE;
182 if ((left == 0) && (top == 0) && (right == width) && (bottom == height))
183 return FALSE;
184
185 damage->left = (UINT16)left;
186 damage->top = (UINT16)top;
187 damage->right = (UINT16)right;
188 damage->bottom = (UINT16)bottom;
189 return TRUE;
190}
191
192#endif
193
194BOOL freerdp_av1_context_set_option(FREERDP_AV1_CONTEXT* av1, FREERDP_AV1_CONTEXT_OPTION option,
195 UINT32 value)
196{
197#if defined(WITH_LIBAOM)
198 switch (option)
199 {
200 case FREERDP_AV1_CONTEXT_OPTION_PROFILE:
201 if (!av1->encoder)
202 return FALSE;
203
204 av1->ecfg.g_profile = value;
205 break;
206
207 case FREERDP_AV1_CONTEXT_OPTION_RATECONTROL:
208 if (!av1->encoder)
209 return FALSE;
210 switch (value)
211 {
212 case FREERDP_AV1_VBR:
213 case FREERDP_AV1_CBR:
214 case FREERDP_AV1_CQ:
215 case FREERDP_AV1_Q:
216 break;
217 default:
218 WLog_Print(av1->log, WLOG_WARN,
219 "Unknown FREERDP_AV1_CONTEXT_OPTION_RATECONTROL value [0x%08" PRIx32
220 "]",
221 value);
222 return FALSE;
223 }
224 av1->ecfg.rc_end_usage = WINPR_ASSERTING_INT_CAST(enum aom_rc_mode, value);
225 break;
226 case FREERDP_AV1_CONTEXT_OPTION_BITRATE:
227 if (!av1->encoder)
228 return FALSE;
229 av1->ecfg.rc_target_bitrate = value;
230 break;
231 case FREERDP_AV1_CONTEXT_OPTION_USAGETYPE:
232 if (!av1->encoder)
233 return FALSE;
234 av1->ecfg.g_usage = value;
235 break;
236 case FREERDP_AV1_CONTEXT_OPTION_CQ_LEVEL:
237 if (!av1->encoder || (value > 63))
238 return FALSE;
239 av1->cqLevel = value;
240 break;
241 case FREERDP_AV1_CONTEXT_OPTION_THREADS:
242 if (!av1->encoder || (value > 64))
243 return FALSE;
244 av1->ecfg.g_threads = (value > 0) ? value : av1_aom_threads();
245 break;
246 case FREERDP_AV1_CONTEXT_OPTION_SPEED:
247 if (!av1->encoder || (value > 12))
248 return FALSE;
249 av1->speed = value;
250 break;
251 default:
252 WLog_Print(av1->log, WLOG_ERROR, "Unknown FREERDP_AV1_CONTEXT_OPTION[0x%08" PRIx32 "]",
253 option);
254 return TRUE;
255 }
256 /* before the first reset only kept: the encoder starts once, with all of them */
257 if (!av1->initialized)
258 return TRUE;
259 return freerdp_av1_context_reset(av1, av1->ecfg.g_w, av1->ecfg.g_h);
260#else
261 WLog_Print(av1->log, WLOG_WARN, "AV1 encoder requires libaom, recompile with '-DWITH_AOM=ON'");
262 WINPR_UNUSED(option);
263 WINPR_UNUSED(value);
264 return FALSE;
265#endif
266}
267
268UINT32 freerdp_av1_context_get_option(FREERDP_AV1_CONTEXT* av1, FREERDP_AV1_CONTEXT_OPTION option)
269{
270#if defined(WITH_LIBAOM)
271 switch (option)
272 {
273 case FREERDP_AV1_CONTEXT_OPTION_PROFILE:
274 if (!av1->encoder)
275 return 0;
276 return av1->ecfg.g_profile;
277 case FREERDP_AV1_CONTEXT_OPTION_RATECONTROL:
278 if (!av1->encoder)
279 return 0;
280 return av1->ecfg.rc_end_usage;
281 case FREERDP_AV1_CONTEXT_OPTION_BITRATE:
282 if (!av1->encoder)
283 return 0;
284 return av1->ecfg.rc_target_bitrate;
285 case FREERDP_AV1_CONTEXT_OPTION_USAGETYPE:
286 if (!av1->encoder)
287 return 0;
288 return av1->ecfg.g_usage;
289 case FREERDP_AV1_CONTEXT_OPTION_CQ_LEVEL:
290 if (!av1->encoder)
291 return 0;
292 return av1->cqLevel;
293 case FREERDP_AV1_CONTEXT_OPTION_THREADS:
294 if (!av1->encoder)
295 return 0;
296 return av1->ecfg.g_threads;
297 case FREERDP_AV1_CONTEXT_OPTION_SPEED:
298 if (!av1->encoder)
299 return 0;
300 return av1->speed;
301 default:
302 WLog_Print(av1->log, WLOG_ERROR, "Unknown FREERDP_AV1_CONTEXT_OPTION[0x%08" PRIx32 "]",
303 option);
304 return 0;
305 }
306#else
307 WINPR_UNUSED(option);
308 return 0;
309#endif
310}
311
312#if defined(WITH_LIBAOM)
313/* Encoder statistics, logged every few seconds at debug level to com.freerdp.codec.av1
314 * (e.g. with WLOG_LEVEL=DEBUG) */
315#define AV1_STATS_INTERVAL_NS (5ull * 1000ull * 1000ull * 1000ull)
316
317static void av1_encoder_stats(FREERDP_AV1_CONTEXT* av1, UINT64 startNS, size_t bytes)
318{
319 WINPR_ASSERT(av1);
320
321 if (!WLog_IsLevelActive(av1->log, WLOG_DEBUG))
322 return;
323
324 const UINT64 endNS = winpr_GetTickCount64NS();
325 const UINT64 encodeNS = endNS - startNS;
326 if (av1->stats.frames == 0)
327 av1->stats.startNS = startNS;
328 av1->stats.frames++;
329 av1->stats.encodeNS += encodeNS;
330 av1->stats.bytes += bytes;
331 if (encodeNS > av1->stats.maxEncodeNS)
332 av1->stats.maxEncodeNS = encodeNS;
333
334 const UINT64 elapsedNS = endNS - av1->stats.startNS;
335 if (elapsedNS < AV1_STATS_INTERVAL_NS)
336 return;
337
338 const double seconds = (double)elapsedNS / 1e9;
339 WLog_Print(av1->log, WLOG_DEBUG,
340 "AV1 %" PRIu32 "x%" PRIu32 " %s: %" PRIu32 " frames in %.1f s (%.1f fps), "
341 "encode avg %.1f ms max %.1f ms, %.0f kbit/s",
342 av1->yuvWidth, av1->yuvHeight, (av1->ecfg.g_profile == 1) ? "I444" : "I420",
343 av1->stats.frames, seconds, av1->stats.frames / seconds,
344 (double)av1->stats.encodeNS / av1->stats.frames / 1e6,
345 (double)av1->stats.maxEncodeNS / 1e6,
346 (double)av1->stats.bytes * 8.0 / 1000.0 / seconds);
347
348 av1->stats.frames = 0;
349 av1->stats.encodeNS = 0;
350 av1->stats.maxEncodeNS = 0;
351 av1->stats.bytes = 0;
352}
353#endif
354
355INT32 freerdp_av1_compress(FREERDP_AV1_CONTEXT* av1, const BYTE* pSrcData, DWORD SrcFormat,
356 UINT32 nSrcStep, UINT32 nSrcWidth, UINT32 nSrcHeight,
357 const RECTANGLE_16* regionRect, BYTE** ppDstData, UINT32* pDstSize,
359{
360 *ppDstData = nullptr;
361 *pDstSize = 0;
362
363 if (!av1->encoder)
364 {
365 WLog_Print(av1->log, WLOG_ERROR, "av1->encoder: %d", av1->encoder);
366 return -1;
367 }
368
369 if ((nSrcWidth == 0) || (nSrcWidth > UINT16_MAX) || (nSrcHeight == 0) ||
370 (nSrcHeight > UINT16_MAX))
371 {
372 WLog_Print(av1->log, WLOG_ERROR, "%" PRIu32 "x%" PRIu32 " out of range, maximum %dx%d",
373 nSrcWidth, nSrcHeight, UINT16_MAX, UINT16_MAX);
374 return -1;
375 }
376
377#if defined(WITH_LIBAOM)
378 const UINT64 startNS = winpr_GetTickCount64NS();
379 primitives_t* primitives = primitives_get();
380 if (!primitives)
381 {
382 WLog_Print(av1->log, WLOG_ERROR, "primitives_get(): nullptr");
383 return -1;
384 }
385
386 if (av1->yuvWidth != nSrcWidth)
387 {
388 WLog_Print(av1->log, WLOG_ERROR, "av1->yuvWidth[%" PRIu32 "] != nSrcWidth[%" PRIu32 "]",
389 av1->yuvWidth, nSrcWidth);
390 return -1;
391 }
392
393 if (av1->yuvHeight != nSrcHeight)
394 {
395 WLog_Print(av1->log, WLOG_ERROR, "av1->yuvHeight[%" PRIu32 "] != nSrcHeight[%" PRIu32 "]",
396 av1->yuvHeight, nSrcHeight);
397 return -1;
398 }
399
400 /* Only the damaged part is converted: the YUV planes still hold the previous frame. */
401 RECTANGLE_16 damage = WINPR_C_ARRAY_INIT;
402 const BOOL partial = av1_aom_damage(av1, regionRect, nSrcWidth, nSrcHeight, &damage);
403 if (!partial)
404 {
405 damage.left = 0;
406 damage.top = 0;
407 damage.right = WINPR_ASSERTING_INT_CAST(UINT16, nSrcWidth);
408 damage.bottom = WINPR_ASSERTING_INT_CAST(UINT16, nSrcHeight);
409 }
410
411 const UINT32 bpp = FreeRDPGetBytesPerPixel(SrcFormat);
412 if (bpp == 0)
413 {
414 WLog_Print(av1->log, WLOG_ERROR, "Unsupported source format %s",
415 FreeRDPGetColorFormatName(SrcFormat));
416 return -1;
417 }
418
419 const prim_size_t roi = { .width = damage.right - damage.left,
420 .height = damage.bottom - damage.top };
421 const UINT32 chromaShift = (av1->ecfg.g_profile == 0) ? 1 : 0;
422 const size_t chromaX = damage.left >> chromaShift;
423 const size_t chromaY = damage.top >> chromaShift;
424 const BYTE* pSrc = &pSrcData[1ull * damage.top * nSrcStep + 1ull * damage.left * bpp];
425 BYTE* pDst[3] = { &av1->yuvdata[0][1ull * damage.top * av1->yuvStride[0] + damage.left],
426 &av1->yuvdata[1][chromaY * av1->yuvStride[1] + chromaX],
427 &av1->yuvdata[2][chromaY * av1->yuvStride[2] + chromaX] };
428
429 aom_image_t buffer = WINPR_C_ARRAY_INIT;
430
431 aom_image_t* img = &buffer;
432 pstatus_t rec = -1;
433#if defined(WITH_LIBYUV)
434 /* ARGBToI420()/ARGBToI444() always read pSrcData as packed BGRA8888 regardless of
435 * SrcFormat, so the fast path only applies for that layout; anything else must go
436 * through the format-aware primitives conversion below. */
437 if ((SrcFormat == PIXEL_FORMAT_BGRA32) || (SrcFormat == PIXEL_FORMAT_BGRX32))
438 {
439 switch (av1->ecfg.g_profile)
440 {
441 case 0:
442 img->fmt = AOM_IMG_FMT_I420;
443 img->x_chroma_shift = 1;
444 img->y_chroma_shift = 1;
445 rec = ARGBToI420(pSrc, nSrcStep, pDst[0], av1->yuvStride[0], pDst[1],
446 av1->yuvStride[1], pDst[2],
447 WINPR_ASSERTING_INT_CAST(int, av1->yuvStride[2]),
448 WINPR_ASSERTING_INT_CAST(int, roi.width),
449 WINPR_ASSERTING_INT_CAST(int, roi.height));
450 break;
451 case 1:
452 img->fmt = AOM_IMG_FMT_I444;
453 rec = ARGBToI444(pSrc, nSrcStep, pDst[0], av1->yuvStride[0], pDst[1],
454 av1->yuvStride[1], pDst[2],
455 WINPR_ASSERTING_INT_CAST(int, av1->yuvStride[2]),
456 WINPR_ASSERTING_INT_CAST(int, roi.width),
457 WINPR_ASSERTING_INT_CAST(int, roi.height));
458 break;
459 default:
460 WLog_Print(av1->log, WLOG_ERROR, "Unsupoorted AV1 profile %" PRIu32,
461 av1->ecfg.g_profile);
462 return -1;
463 }
464 }
465 else
466#endif
467 {
468 switch (av1->ecfg.g_profile)
469 {
470 case 0:
471 img->fmt = AOM_IMG_FMT_I420;
472 img->x_chroma_shift = 1;
473 img->y_chroma_shift = 1;
474 rec = primitives->RGBToYUV420_8u_P3AC4R(pSrc, SrcFormat, nSrcStep, pDst,
475 av1->yuvStride, &roi);
476 break;
477 case 1:
478 img->fmt = AOM_IMG_FMT_I444;
479 rec =
480 primitives->RGBToI444_8u(pSrc, SrcFormat, nSrcStep, pDst, av1->yuvStride, &roi);
481 break;
482 default:
483 WLog_Print(av1->log, WLOG_ERROR, "Unsupoorted AV1 profile %" PRIu32,
484 av1->ecfg.g_profile);
485 return -1;
486 }
487 }
488 if (rec != 0)
489 {
490 WLog_Print(av1->log, WLOG_ERROR, "RGB to YUV conversion failed: %d", rec);
491 av1->fullFrameNext = true;
492 return -1;
493 }
494 av1->fullFrameNext = false;
495 img->bit_depth = 8;
496 img->d_w = img->r_w = img->w = nSrcWidth;
497 img->d_h = img->r_h = img->h = nSrcHeight;
498 img->stride[0] = WINPR_ASSERTING_INT_CAST(int, av1->yuvStride[0]);
499 img->stride[1] = WINPR_ASSERTING_INT_CAST(int, av1->yuvStride[1]);
500 img->stride[2] = WINPR_ASSERTING_INT_CAST(int, av1->yuvStride[2]);
501 img->planes[0] = av1->yuvdata[0];
502 img->planes[1] = av1->yuvdata[1];
503 img->planes[2] = av1->yuvdata[2];
504
505 const aom_codec_err_t rc = aom_codec_encode(&av1->ctx, img, ++av1->framecount, 1, av1->eflags);
506 aom_img_free(img);
507
508 if (rc != AOM_CODEC_OK)
509 {
510 WLog_Print(av1->log, WLOG_WARN, "aom_codec_encode: %s", aom_codec_err_to_string(rc));
511 return -1;
512 }
513
514 aom_codec_iter_t iter = nullptr;
515 const aom_codec_cx_pkt_t* pkt = nullptr;
516 while ((pkt = aom_codec_get_cx_data(&av1->ctx, &iter)) != nullptr)
517 {
518 if (pkt->kind != AOM_CODEC_CX_FRAME_PKT)
519 continue;
520
521 if (pkt->data.frame.sz > UINT32_MAX)
522 return -1;
523 *ppDstData = pkt->data.frame.buf;
524 *pDstSize = WINPR_ASSERTING_INT_CAST(UINT32, pkt->data.frame.sz);
525 }
526 if (*pDstSize == 0)
527 return 0;
528
529 av1_encoder_stats(av1, startNS, *pDstSize);
530
531 RECTANGLE_16* rect = calloc(1, sizeof(RECTANGLE_16));
532 if (rect)
533 {
534 rect->right = WINPR_ASSERTING_INT_CAST(UINT16, nSrcWidth);
535 rect->bottom = WINPR_ASSERTING_INT_CAST(UINT16, nSrcHeight);
536 }
537 return allocate_h264_metablock(10, rect, meta, 1);
538#else
539 WLog_Print(av1->log, WLOG_ERROR, "AV1 encoder requires libaom, recompile with '-DWITH_AOM=ON'");
540 WINPR_UNUSED(pSrcData);
541 WINPR_UNUSED(SrcFormat);
542 WINPR_UNUSED(nSrcStep);
543 WINPR_UNUSED(nSrcWidth);
544 WINPR_UNUSED(nSrcHeight);
545 WINPR_UNUSED(regionRect);
546 WINPR_UNUSED(meta);
547 return -1;
548#endif
549}
550
551static BOOL isRectValid(UINT32 width, UINT32 height, const RECTANGLE_16* rect)
552{
553 WINPR_ASSERT(rect);
554 if (rect->left > width)
555 return FALSE;
556 if (rect->right > width)
557 return FALSE;
558 if (rect->left >= rect->right)
559 return FALSE;
560 if (rect->top > height)
561 return FALSE;
562 if (rect->bottom > height)
563 return FALSE;
564 if (rect->top >= rect->bottom)
565 return FALSE;
566 return TRUE;
567}
568
569static BOOL areRectsValid(wLog* log, UINT32 width, UINT32 height, const RECTANGLE_16* rects,
570 UINT32 count)
571{
572 WINPR_ASSERT(rects || (count == 0));
573 for (size_t x = 0; x < count; x++)
574 {
575 const RECTANGLE_16* rect = &rects[x];
576 if (!isRectValid(width, height, rect))
577 {
578 char buffer[64] = WINPR_C_ARRAY_INIT;
579 WLog_Print(log, WLOG_WARN,
580 "Rectangle %" PRIuz " %s outside of bounding frame %" PRIu32 "x%" PRIu32, x,
581 rectangle_to_string(rect, buffer, sizeof(buffer)), width, height);
582 return FALSE;
583 }
584 }
585 return TRUE;
586}
587
588#if defined(WITH_DAV1D) || defined(WITH_AV1_VIDEOTOOLBOX)
589/* Convert a decoded 8 bit 4:2:0 or 4:4:4 picture to RGB, bounded to the destination surface */
590static INT32 av1_convert_planar(FREERDP_AV1_CONTEXT* av1, BOOL i444, const BYTE* const planes[3],
591 const UINT32 strides[3], UINT32 dw, UINT32 dh, BYTE* pDstData,
592 DWORD DstFormat, UINT32 nDstStep, UINT32 nDstWidth,
593 UINT32 nDstHeight, const RECTANGLE_16* regionRects,
594 UINT32 numRegionRect)
595{
596 /* The decoded frame may be smaller than the destination surface, so
597 * bound the converted region to it. Otherwise the colour conversion
598 * reads past the decoded image planes. */
599 const UINT32 nWidth = (dw < nDstWidth) ? dw : nDstWidth;
600 const UINT32 nHeight = (dh < nDstHeight) ? dh : nDstHeight;
601 const prim_size_t roi = { .width = nWidth, .height = nHeight };
602
603 if (!areRectsValid(av1->log, roi.width, roi.height, regionRects, numRegionRect))
604 return -2;
605
606 pstatus_t rec = -1;
607#if defined(WITH_LIBYUV)
608 /* J420ToARGB()/J444ToARGB() always write pDstData as packed BGRA8888 regardless of
609 * DstFormat, so the fast path only applies for that layout; anything else must go
610 * through the format-aware primitives conversion below. */
611 if ((DstFormat == PIXEL_FORMAT_BGRA32) || (DstFormat == PIXEL_FORMAT_BGRX32))
612 {
613 const int stride0 = WINPR_ASSERTING_INT_CAST(int, strides[0]);
614 const int stride1 = WINPR_ASSERTING_INT_CAST(int, strides[1]);
615 const int stride2 = WINPR_ASSERTING_INT_CAST(int, strides[2]);
616 const int iWidth = WINPR_ASSERTING_INT_CAST(int, nWidth);
617 const int iHeight = WINPR_ASSERTING_INT_CAST(int, nHeight);
618 const int iDstStep = WINPR_ASSERTING_INT_CAST(int, nDstStep);
619
620 if (i444)
621 rec = J444ToARGB(planes[0], stride0, planes[1], stride1, planes[2], stride2, pDstData,
622 iDstStep, iWidth, iHeight);
623 else
624 rec = J420ToARGB(planes[0], stride0, planes[1], stride1, planes[2], stride2, pDstData,
625 iDstStep, iWidth, iHeight);
626 }
627 else
628#endif
629 {
630 primitives_t* primitives = primitives_get();
631 if (!primitives)
632 {
633 WLog_Print(av1->log, WLOG_ERROR, "primitives_get(): nullptr");
634 return -1;
635 }
636
637 const BYTE* pSrc[] = { planes[0], planes[1], planes[2] };
638 if (i444)
639 rec = primitives->I444ToRGB_8u(pSrc, strides, pDstData, nDstStep, DstFormat, &roi);
640 else
641 rec = primitives->YUV420ToRGB_8u_P3AC4R(pSrc, strides, pDstData, nDstStep, DstFormat,
642 &roi);
643 }
644 if (rec != 0)
645 {
646 WLog_Print(av1->log, WLOG_ERROR, "YUV to RGB conversion failed: %d", rec);
647 return -1;
648 }
649 return TRUE;
650}
651#endif
652
653#if defined(WITH_DAV1D)
654static void av1_dav1d_data_free(WINPR_ATTR_UNUSED const uint8_t* buf,
655 WINPR_ATTR_UNUSED void* cookie)
656{
657 /* pSrcData is owned by the caller of freerdp_av1_decompress(), dav1d must not free it. */
658}
659
660static INT32 av1_dav1d_convert(FREERDP_AV1_CONTEXT* av1, const Dav1dPicture* pic, BYTE* pDstData,
661 DWORD DstFormat, UINT32 nDstStep, UINT32 nDstWidth,
662 UINT32 nDstHeight, const RECTANGLE_16* regionRects,
663 UINT32 numRegionRect)
664{
665 if (pic->p.bpc != 8)
666 {
667 WLog_Print(av1->log, WLOG_ERROR, "dav1d picture bpc %d not supported", pic->p.bpc);
668 return -1;
669 }
670 if ((pic->p.layout != DAV1D_PIXEL_LAYOUT_I420) && (pic->p.layout != DAV1D_PIXEL_LAYOUT_I444))
671 {
672 WLog_Print(av1->log, WLOG_ERROR, "dav1d picture layout %u not supported", pic->p.layout);
673 return -1;
674 }
675
676 const BYTE* const planes[] = { pic->data[0], pic->data[1], pic->data[2] };
677 const UINT32 strides[] = { WINPR_ASSERTING_INT_CAST(UINT32, pic->stride[0]),
678 WINPR_ASSERTING_INT_CAST(UINT32, pic->stride[1]),
679 WINPR_ASSERTING_INT_CAST(UINT32, pic->stride[1]) };
680 return av1_convert_planar(av1, pic->p.layout == DAV1D_PIXEL_LAYOUT_I444, planes, strides,
681 WINPR_ASSERTING_INT_CAST(UINT32, pic->p.w),
682 WINPR_ASSERTING_INT_CAST(UINT32, pic->p.h), pDstData, DstFormat,
683 nDstStep, nDstWidth, nDstHeight, regionRects, numRegionRect);
684}
685
686/* Return: TRUE if a picture was converted, FALSE if none was ready (EAGAIN), <0 on error. */
687static INT32 av1_dav1d_drain_one(FREERDP_AV1_CONTEXT* av1, BYTE* pDstData, DWORD DstFormat,
688 UINT32 nDstStep, UINT32 nDstWidth, UINT32 nDstHeight,
689 const RECTANGLE_16* regionRects, UINT32 numRegionRect)
690{
691 Dav1dPicture pic = WINPR_C_ARRAY_INIT;
692 const int prc = dav1d_get_picture(av1->dav1d, &pic);
693 if (prc == DAV1D_ERR(EAGAIN))
694 return FALSE;
695 if (prc < 0)
696 {
697 WLog_Print(av1->log, WLOG_WARN, "dav1d_get_picture: %d", prc);
698 return -1;
699 }
700
701 const INT32 rc = av1_dav1d_convert(av1, &pic, pDstData, DstFormat, nDstStep, nDstWidth,
702 nDstHeight, regionRects, numRegionRect);
703 dav1d_picture_unref(&pic);
704 return (rc == TRUE) ? TRUE : rc;
705}
706#endif
707
708INT32 freerdp_av1_decompress(FREERDP_AV1_CONTEXT* av1, const BYTE* pSrcData, UINT32 SrcSize,
709 BYTE* pDstData, DWORD DstFormat, UINT32 nDstStep, UINT32 nDstWidth,
710 UINT32 nDstHeight, const RECTANGLE_16* regionRects,
711 UINT32 numRegionRect)
712{
713 WINPR_ASSERT(av1);
714 if (av1->encoder)
715 {
716 WLog_Print(av1->log, WLOG_ERROR, "av1->encoder: %d", av1->encoder);
717 return -1;
718 }
719
720 if (!areRectsValid(av1->log, nDstWidth, nDstHeight, regionRects, numRegionRect))
721 return -2;
722
723#if defined(WITH_AV1_VIDEOTOOLBOX)
724 if (av1->vt && av1->vtStream)
725 {
726 AV1_VT_PICTURE pic = WINPR_C_ARRAY_INIT;
727 const INT32 vrc = av1_vt_decode(av1->vt, pSrcData, SrcSize, &pic);
728 if (vrc == TRUE)
729 return av1_convert_planar(av1, pic.i444, pic.planes, pic.strides, pic.width, pic.height,
730 pDstData, DstFormat, nDstStep, nDstWidth, nDstHeight,
731 regionRects, numRegionRect);
732 if (vrc == FALSE)
733 return TRUE;
734 /* bad input: refused, the stream stays with VideoToolbox */
735 if (vrc == AV1_VT_INVALID)
736 return -1;
737
738 /* The software decoder takes the rest of this stream (until the next reset). */
739 av1->vtStream = false;
740 if (vrc != AV1_VT_UNSUPPORTED)
741 {
742 /* In the middle of the stream: the software decoder has none of its references,
743 * it only picks up at a new sequence header. */
744 WLog_Print(av1->log, WLOG_WARN,
745 "VideoToolbox AV1 decode failed (%" PRId32 "), software decoder from the "
746 "next sequence header",
747 vrc);
748 return vrc;
749 }
750 /* This temporal unit starts the stream, the software decoder starts with it. */
751 }
752#endif
753
754#if defined(WITH_AV1_WEBCODECS)
755 if (av1->webcodecs > 0)
756 {
757 const INT32 wrc = av1_wc_decode(av1->webcodecs, pSrcData, SrcSize, pDstData, DstFormat,
758 nDstStep, nDstWidth, nDstHeight);
759 if (wrc >= 0)
760 return TRUE;
761 /* fall back to the software decoder for the rest of the session */
762 if (wrc == AV1_WC_UNSUPPORTED)
763 WLog_Print(av1->log, WLOG_DEBUG, "surface format needs dav1d instead of WebCodecs");
764 else
765 WLog_Print(av1->log, WLOG_WARN,
766 "WebCodecs AV1 decode failed (%" PRId32 "), using dav1d", wrc);
767 av1_wc_close(av1->webcodecs);
768 av1->webcodecs = 0;
769 }
770#endif
771
772#if defined(WITH_DAV1D)
773 Dav1dData data = WINPR_C_ARRAY_INIT;
774 const int wrc = dav1d_data_wrap(&data, pSrcData, SrcSize, av1_dav1d_data_free, nullptr);
775 if (wrc < 0)
776 {
777 WLog_Print(av1->log, WLOG_WARN, "dav1d_data_wrap: %d", wrc);
778 return -1;
779 }
780
781 while (data.sz > 0)
782 {
783 const int src = dav1d_send_data(av1->dav1d, &data);
784 if ((src < 0) && (src != DAV1D_ERR(EAGAIN)))
785 {
786 WLog_Print(av1->log, WLOG_WARN, "dav1d_send_data: %d", src);
787 dav1d_data_unref(&data);
788 return -1;
789 }
790
791 const INT32 rc = av1_dav1d_drain_one(av1, pDstData, DstFormat, nDstStep, nDstWidth,
792 nDstHeight, regionRects, numRegionRect);
793 if ((rc != TRUE) && (rc != FALSE))
794 {
795 dav1d_data_unref(&data);
796 return rc;
797 }
798 }
799 dav1d_data_unref(&data);
800
801 /* Drain any picture the decoder buffered internally before it consumed the last input. */
802 for (;;)
803 {
804 const INT32 rc = av1_dav1d_drain_one(av1, pDstData, DstFormat, nDstStep, nDstWidth,
805 nDstHeight, regionRects, numRegionRect);
806 if (rc == FALSE)
807 break;
808 if (rc != TRUE)
809 return rc;
810 }
811
812 return TRUE;
813#elif defined(WITH_LIBAOM)
814 const aom_codec_err_t rc = aom_codec_decode(&av1->ctx, pSrcData, SrcSize, nullptr);
815 if (rc != AOM_CODEC_OK)
816 {
817 WLog_Print(av1->log, WLOG_WARN, "aom_codec_decode: %s", aom_codec_err_to_string(rc));
818 return -1;
819 }
820
821 aom_image_t* img = nullptr;
822 aom_codec_iter_t iter = nullptr;
823 while ((img = aom_codec_get_frame(&av1->ctx, &iter)) != nullptr)
824 {
825 /* The decoded frame may be smaller than the destination surface, so
826 * bound the converted region to it. Otherwise the colour conversion
827 * reads past the decoded image planes. */
828 const UINT32 nWidth = (img->d_w < nDstWidth) ? img->d_w : nDstWidth;
829 const UINT32 nHeight = (img->d_h < nDstHeight) ? img->d_h : nDstHeight;
830 const prim_size_t roi = { .width = nWidth, .height = nHeight };
831
832 if (!areRectsValid(av1->log, roi.width, roi.height, regionRects, numRegionRect))
833 return -2;
834
835 pstatus_t rec = -1;
836#if defined(WITH_LIBYUV)
837 /* J420ToARGB()/J444ToARGB() always write pDstData as packed BGRA8888 regardless of
838 * DstFormat, so the fast path only applies for that layout; anything else must go
839 * through the format-aware primitives conversion below. */
840 if ((DstFormat == PIXEL_FORMAT_BGRA32) || (DstFormat == PIXEL_FORMAT_BGRX32))
841 {
842 switch (img->fmt)
843 {
844 case AOM_IMG_FMT_I420:
845 rec = J420ToARGB(img->planes[0], img->stride[0], img->planes[1], img->stride[1],
846 img->planes[2], img->stride[2], pDstData, nDstStep, nWidth,
847 nHeight);
848 break;
849 case AOM_IMG_FMT_I444:
850 rec = J444ToARGB(img->planes[0], img->stride[0], img->planes[1], img->stride[1],
851 img->planes[2], img->stride[2], pDstData, nDstStep, nWidth,
852 nHeight);
853 break;
854 default:
855 WLog_Print(av1->log, WLOG_ERROR, "img->fmt %d not supported", img->fmt);
856 return -1;
857 }
858 }
859 else
860#endif
861 {
862 const BYTE* pSrc[] = { img->planes[0], img->planes[1], img->planes[2] };
863 const UINT32 strides[] = { img->stride[0], img->stride[1], img->stride[2] };
864
865 primitives_t* primitives = primitives_get();
866 if (!primitives)
867 {
868 WLog_Print(av1->log, WLOG_ERROR, "primitives_get(): nullptr");
869 return FALSE;
870 }
871
872 switch (img->fmt)
873 {
874 case AOM_IMG_FMT_I420:
875 rec = primitives->YUV420ToRGB_8u_P3AC4R(pSrc, strides, pDstData, nDstStep,
876 DstFormat, &roi);
877 break;
878 case AOM_IMG_FMT_I444:
879 rec = primitives->I444ToRGB_8u(pSrc, strides, pDstData, nDstStep, DstFormat,
880 &roi);
881 break;
882 default:
883 WLog_Print(av1->log, WLOG_ERROR, "img->fmt %d not supported", img->fmt);
884 return -1;
885 }
886 }
887 if (rec != 0)
888 {
889 WLog_Print(av1->log, WLOG_ERROR, "RGB to YUV conversion failed: %d", rec);
890 return -1;
891 }
892 }
893
894 return TRUE;
895#endif
896}
897
898BOOL freerdp_av1_context_reset(FREERDP_AV1_CONTEXT* av1, UINT32 width, UINT32 height)
899{
900 if (av1->encoder)
901 {
902#if defined(WITH_LIBAOM)
903 av1->ecfg.g_w = width;
904 av1->ecfg.g_h = height;
905
906 if (av1->initialized)
907 {
908 const aom_codec_err_t rc = aom_codec_destroy(&av1->ctx);
909 av1->initialized = false;
910 if (rc != AOM_CODEC_OK)
911 {
912 WLog_Print(av1->log, WLOG_WARN, "aom_codec_destroy: %s",
913 aom_codec_err_to_string(rc));
914 return FALSE;
915 }
916 }
917
918 const aom_codec_err_t rc =
919 aom_codec_enc_init(&av1->ctx, av1->iface, &av1->ecfg, av1->flags);
920 if (rc != AOM_CODEC_OK)
921 {
922 WLog_Print(av1->log, WLOG_WARN, "aom_codec_enc_init: %s", aom_codec_err_to_string(rc));
923 return FALSE;
924 }
925
926 av1->framecount = 0;
927 av1->eflags = 0; // AOM_EFLAG_FORCE_KF;
928 av1->initialized = true;
929 av1->fullFrameNext = true;
930
931 if (!av1_aom_apply_controls(av1))
932 return FALSE;
933#else
934 WLog_Print(av1->log, WLOG_ERROR,
935 "AV1 encoder requires libaom, recompile with '-DWITH_AOM=ON'");
936 return FALSE;
937#endif
938 }
939 else
940 {
941#if defined(WITH_AV1_VIDEOTOOLBOX)
942 if (!av1->vt)
943 {
944 av1->vt = av1_vt_new(av1->log);
945 WLog_Print(av1->log, WLOG_INFO, "AV1 decoder: %s",
946 av1->vt ? "VideoToolbox (hardware), software as fallback"
947 : "software (no VideoToolbox AV1 decoder)");
948 }
949 else
950 av1_vt_reset(av1->vt);
951 av1->vtStream = (av1->vt != nullptr);
952#endif
953#if defined(WITH_AV1_WEBCODECS)
954 if (av1->webcodecs == 0)
955 {
956 av1->webcodecs = av1_wc_open();
957 WLog_Print(av1->log, WLOG_INFO, "AV1 decoder: %s",
958 av1->webcodecs > 0 ? "WebCodecs (browser), dav1d as fallback" : "dav1d");
959 }
960#endif
961#if defined(WITH_DAV1D)
962 if (av1->initialized)
963 {
964 dav1d_close(&av1->dav1d);
965 av1->initialized = false;
966 }
967
968 Dav1dSettings settings = WINPR_C_ARRAY_INIT;
969 dav1d_default_settings(&settings);
970 /* Single-threaded: freerdp_av1_decompress() needs its picture back synchronously,
971 * not held back by frame-parallel decoding. */
972 settings.n_threads = 1;
973 settings.max_frame_delay = 1;
974
975 const int rc = dav1d_open(&av1->dav1d, &settings);
976 if (rc < 0)
977 {
978 WLog_Print(av1->log, WLOG_WARN, "dav1d_open: %d", rc);
979 return FALSE;
980 }
981 av1->initialized = true;
982#elif defined(WITH_LIBAOM)
983 av1->dcfg.w = width;
984 av1->dcfg.h = height;
985 av1->dcfg.allow_lowbitdepth = 1;
986 const aom_codec_err_t rc =
987 aom_codec_dec_init(&av1->ctx, av1->iface, &av1->dcfg, av1->flags);
988 if (rc != AOM_CODEC_OK)
989 {
990 WLog_Print(av1->log, WLOG_WARN, "aom_codec_dec_init: %s", aom_codec_err_to_string(rc));
991 return FALSE;
992 }
993 av1->initialized = true;
994#else
995 WLog_Print(av1->log, WLOG_WARN,
996 "This build does not support AV1 decoding. Recompile with '-DWITH_DAV1D=ON' "
997 "or '-DWITH_AOM=ON'");
998 return FALSE;
999#endif
1000 }
1001
1002 av1->yuvWidth = width;
1003 av1->yuvStride[0] = width;
1004
1005 const size_t pad = av1->yuvStride[0] % 16;
1006 if (pad != 0)
1007 av1->yuvStride[0] += 16 - pad;
1008 av1->yuvStride[0] *= 3;
1009 av1->yuvStride[1] = width;
1010 av1->yuvStride[2] = width;
1011
1012 av1->yuvHeight = height;
1013 winpr_aligned_free(av1->yuvdata[0]);
1014 winpr_aligned_free(av1->yuvdata[1]);
1015 winpr_aligned_free(av1->yuvdata[2]);
1016 av1->yuvdata[0] = winpr_aligned_malloc(1ull * av1->yuvStride[0] * av1->yuvHeight, 64);
1017 av1->yuvdata[1] = winpr_aligned_malloc(1ull * av1->yuvStride[1] * av1->yuvHeight, 64);
1018 av1->yuvdata[2] = winpr_aligned_malloc(1ull * av1->yuvStride[2] * av1->yuvHeight, 64);
1019 return av1->yuvdata[0] != nullptr;
1020}
1021
1022void freerdp_av1_context_free(FREERDP_AV1_CONTEXT* av1)
1023{
1024 if (!av1)
1025 return;
1026
1027 if (av1->initialized)
1028 {
1029 if (av1->encoder)
1030 {
1031#if defined(WITH_LIBAOM)
1032 av1_aom_destroy(av1);
1033#endif
1034 }
1035 else
1036 {
1037#if defined(WITH_DAV1D)
1038 dav1d_close(&av1->dav1d);
1039#elif defined(WITH_LIBAOM)
1040 av1_aom_destroy(av1);
1041#endif
1042 }
1043 }
1044#if defined(WITH_AV1_WEBCODECS)
1045 av1_wc_close(av1->webcodecs);
1046#endif
1047#if defined(WITH_AV1_VIDEOTOOLBOX)
1048 av1_vt_free(av1->vt);
1049#endif
1050 winpr_aligned_free(av1->yuvdata[0]);
1051 winpr_aligned_free(av1->yuvdata[1]);
1052 winpr_aligned_free(av1->yuvdata[2]);
1053 free(av1);
1054}
1055
1056FREERDP_AV1_CONTEXT* freerdp_av1_context_new(BOOL Compressor)
1057{
1058 FREERDP_AV1_CONTEXT* ctx = calloc(1, sizeof(FREERDP_AV1_CONTEXT));
1059 if (!ctx)
1060 return nullptr;
1061 ctx->encoder = Compressor;
1062 ctx->log = WLog_Get(TAG);
1063 if (!ctx->log)
1064 goto fail;
1065
1066 if (Compressor)
1067 {
1068#if defined(WITH_LIBAOM)
1069 ctx->iface = aom_codec_av1_cx();
1070 if (!ctx->iface)
1071 {
1072 WLog_Print(ctx->log, WLOG_ERROR, "aom_codec_av1_cx() nullptr");
1073 goto fail;
1074 }
1075
1076 const aom_codec_err_t rc =
1077 aom_codec_enc_config_default(ctx->iface, &ctx->ecfg, AOM_USAGE_REALTIME);
1078 if (rc != AOM_CODEC_OK)
1079 {
1080 WLog_Print(ctx->log, WLOG_ERROR, "aom_codec_enc_config_default() %s",
1081 aom_codec_err_to_string(rc));
1082 goto fail;
1083 }
1084 ctx->ecfg.g_threads = av1_aom_threads();
1085 ctx->speed = AV1_AOM_RT_SPEED;
1086#else
1087 WLog_Print(ctx->log, WLOG_ERROR,
1088 "AV1 encoder requires libaom, recompile with '-DWITH_AOM=ON'");
1089 goto fail;
1090#endif
1091 }
1092#if defined(WITH_LIBAOM) && !defined(WITH_DAV1D)
1093 else
1094 {
1095 ctx->iface = aom_codec_av1_dx();
1096 if (!ctx->iface)
1097 {
1098 WLog_Print(ctx->log, WLOG_ERROR, "aom_codec_av1_dx() nullptr");
1099 goto fail;
1100 }
1101 }
1102#endif
1103
1104 return ctx;
1105
1106fail:
1107 freerdp_av1_context_free(ctx);
1108 return nullptr;
1109}
1110#else
1111
1112struct S_FREERDP_AV1_CONTEXT
1113{
1114 BOOL Compressor;
1115 wLog* log;
1116};
1117
1118BOOL freerdp_av1_context_set_option(WINPR_ATTR_UNUSED FREERDP_AV1_CONTEXT* av1,
1119 WINPR_ATTR_UNUSED FREERDP_AV1_CONTEXT_OPTION option,
1120 WINPR_ATTR_UNUSED UINT32 value)
1121{
1122 return FALSE;
1123}
1124
1125UINT32 freerdp_av1_context_get_option(WINPR_ATTR_UNUSED FREERDP_AV1_CONTEXT* av1,
1126 WINPR_ATTR_UNUSED FREERDP_AV1_CONTEXT_OPTION option)
1127{
1128 return 0;
1129}
1130
1131INT32 freerdp_av1_compress(WINPR_ATTR_UNUSED FREERDP_AV1_CONTEXT* av1,
1132 WINPR_ATTR_UNUSED const BYTE* pSrcData,
1133 WINPR_ATTR_UNUSED DWORD SrcFormat, WINPR_ATTR_UNUSED UINT32 nSrcStep,
1134 WINPR_ATTR_UNUSED UINT32 nSrcWidth, WINPR_ATTR_UNUSED UINT32 nSrcHeight,
1135 WINPR_ATTR_UNUSED const RECTANGLE_16* regionRect,
1136 WINPR_ATTR_UNUSED BYTE** ppDstData, WINPR_ATTR_UNUSED UINT32* pDstSize,
1137 WINPR_ATTR_UNUSED RDPGFX_H264_METABLOCK* meta)
1138{
1139 WINPR_ASSERT(av1);
1140 WLog_Print(av1->log, WLOG_ERROR,
1141 "This build does not support AV1 codec. Recompile with '-DWITH_AOM=ON' or "
1142 "'-DWITH_DAV1D=ON'");
1143 return -1;
1144}
1145
1146INT32 freerdp_av1_decompress(WINPR_ATTR_UNUSED FREERDP_AV1_CONTEXT* av1,
1147 WINPR_ATTR_UNUSED const BYTE* pSrcData,
1148 WINPR_ATTR_UNUSED UINT32 SrcSize, WINPR_ATTR_UNUSED BYTE* pDstData,
1149 WINPR_ATTR_UNUSED DWORD DstFormat, WINPR_ATTR_UNUSED UINT32 nDstStep,
1150 WINPR_ATTR_UNUSED UINT32 nDstWidth,
1151 WINPR_ATTR_UNUSED UINT32 nDstHeight,
1152 WINPR_ATTR_UNUSED const RECTANGLE_16* regionRects,
1153 WINPR_ATTR_UNUSED UINT32 numRegionRect)
1154{
1155 WINPR_ASSERT(av1);
1156 WLog_Print(av1->log, WLOG_ERROR,
1157 "This build does not support AV1 codec. Recompile with '-DWITH_AOM=ON' or "
1158 "'-DWITH_DAV1D=ON'");
1159 return -1;
1160}
1161
1162BOOL freerdp_av1_context_reset(WINPR_ATTR_UNUSED FREERDP_AV1_CONTEXT* av1,
1163 WINPR_ATTR_UNUSED UINT32 width, WINPR_ATTR_UNUSED UINT32 height)
1164{
1165 WINPR_ASSERT(av1);
1166 WLog_Print(av1->log, WLOG_WARN,
1167 "This build does not support AV1 codec. Recompile with '-DWITH_AOM=ON' or "
1168 "'-DWITH_DAV1D=ON'");
1169 return FALSE;
1170}
1171
1172void freerdp_av1_context_free(WINPR_ATTR_UNUSED FREERDP_AV1_CONTEXT* av1)
1173{
1174 free(av1);
1175}
1176
1177FREERDP_AV1_CONTEXT* freerdp_av1_context_new(BOOL Compressor)
1178{
1179 FREERDP_AV1_CONTEXT* ctx = calloc(1, sizeof(FREERDP_AV1_CONTEXT));
1180 if (!ctx)
1181 return nullptr;
1182 ctx->Compressor = Compressor;
1183 ctx->log = WLog_Get(TAG);
1184 return ctx;
1185}
1186#endif
WINPR_ATTR_NODISCARD fn_RGBToYUV444_8u_P3AC4R_t RGBToI444_8u
Definition primitives.h:305
WINPR_ATTR_NODISCARD fn_YUV444ToRGB_8u_P3AC4R_t I444ToRGB_8u
Convert a plain YUV444 picture (e.g. decoded AV1) to RGB. Unlike YUV444ToRGB_8u_P3AC4R this does not ...
Definition primitives.h:310