4#include <freerdp/freerdp.h>
5#include <freerdp/codec/color.h>
6#include <freerdp/codec/av1.h>
8static void* allocRGB(uint32_t format, uint32_t width, uint32_t height, uint32_t* pstride)
10 const size_t bpp = FreeRDPGetBytesPerPixel(format);
11 const size_t stride = bpp * width + 32;
12 WINPR_ASSERT(pstride);
13 *pstride = WINPR_ASSERTING_INT_CAST(uint32_t, stride);
15 uint8_t* rgb = calloc(stride, height);
19 for (
size_t x = 0; x < height; x++)
21 if (winpr_RAND(&rgb[x * stride], width * bpp) < 0)
30static BOOL testEncodeDecode(uint32_t format, uint32_t width, uint32_t height)
36 FREERDP_AV1_CONTEXT* enc = freerdp_av1_context_new(TRUE);
37 FREERDP_AV1_CONTEXT* dec = freerdp_av1_context_new(FALSE);
41 if (!freerdp_av1_context_reset(enc, width, height))
43 if (!freerdp_av1_context_reset(dec, width, height))
48 src = allocRGB(format, width, height, &stride);
49 out = allocRGB(format, width, height, &ostride);
50 if (!src || !out || (stride < width) || (stride != ostride))
53 const RECTANGLE_16 rect = { .left = 0, .top = 0, .right = width, .bottom = height };
54 uint8_t* dst =
nullptr;
56 if (freerdp_av1_compress(enc, src, format, stride, width, height, &rect, &dst, &dstsize,
59 if ((dstsize == 0) || !dst)
65 rc = freerdp_av1_decompress(dec, dst, dstsize, out, format, stride, width, height, &rect, 1) >=
69 freerdp_av1_context_free(enc);
70 freerdp_av1_context_free(dec);
71 free_h264_metablock(&meta);
77int TestFreeRDPCodecAV1(
int argc,
char* argv[])
82#if !defined(WITH_LIBAOM)
83 (void)fprintf(stderr,
"[%s] skipping, no AV1 encoder support compiled in\n", __func__);
86 const UINT32 width = 124;
87 const UINT32 height = 54;
88 const UINT32 formats[] = { PIXEL_FORMAT_BGRA32, PIXEL_FORMAT_RGB16 };
90 for (
size_t x = 0; x < ARRAYSIZE(formats); x++)
92 if (!testEncodeDecode(formats[x], width, height))