1#include <winpr/sysinfo.h>
2#include <winpr/assert.h>
6#include <freerdp/settings.h>
7#include <freerdp/codec/region.h>
8#include <freerdp/primitives.h>
9#include <freerdp/log.h>
10#include <freerdp/codec/yuv.h>
12#define TAG FREERDP_TAG("codec")
19 const BYTE* pYUVData[3];
25} YUV_PROCESS_WORK_PARAM;
30 const BYTE* pYUVData[3];
36} YUV_COMBINE_WORK_PARAM;
48 BYTE* pYUVLumaData[3];
49 BYTE* pYUVChromaData[3];
51} YUV_ENCODE_WORK_PARAM;
60 UINT32 work_object_count;
61 PTP_WORK* work_objects;
62 YUV_ENCODE_WORK_PARAM* work_enc_params;
63 YUV_PROCESS_WORK_PARAM* work_dec_params;
64 YUV_COMBINE_WORK_PARAM* work_combined_params;
67static INLINE BOOL avc420_yuv_to_rgb(
const BYTE* WINPR_RESTRICT pYUVData[3],
68 const UINT32 iStride[3],
69 const RECTANGLE_16* WINPR_RESTRICT rect, UINT32 nDstStep,
70 BYTE* WINPR_RESTRICT pDstData, DWORD DstFormat)
74 const BYTE* pYUVPoint[3];
76 WINPR_ASSERT(pYUVData);
77 WINPR_ASSERT(iStride);
79 WINPR_ASSERT(pDstData);
81 const INT32 width = rect->right - rect->left;
82 const INT32 height = rect->bottom - rect->top;
83 BYTE* pDstPoint = pDstData + 1ULL * rect->top * nDstStep +
84 1ULL * rect->left * FreeRDPGetBytesPerPixel(DstFormat);
86 pYUVPoint[0] = pYUVData[0] + 1ULL * rect->top * iStride[0] + rect->left;
87 pYUVPoint[1] = pYUVData[1] + 1ULL * rect->top / 2 * iStride[1] + rect->left / 2;
88 pYUVPoint[2] = pYUVData[2] + 1ULL * rect->top / 2 * iStride[2] + rect->left / 2;
90 roi.width = WINPR_ASSERTING_INT_CAST(uint32_t, width);
91 roi.height = WINPR_ASSERTING_INT_CAST(uint32_t, height);
93 if (prims->YUV420ToRGB_8u_P3AC4R(pYUVPoint, iStride, pDstPoint, nDstStep, DstFormat, &roi) !=
100static INLINE BOOL avc444_yuv_to_rgb(
const BYTE* WINPR_RESTRICT pYUVData[3],
101 const UINT32 iStride[3],
102 const RECTANGLE_16* WINPR_RESTRICT rect, UINT32 nDstStep,
103 BYTE* WINPR_RESTRICT pDstData, DWORD DstFormat)
107 const BYTE* pYUVPoint[3];
109 WINPR_ASSERT(pYUVData);
110 WINPR_ASSERT(iStride);
112 WINPR_ASSERT(pDstData);
114 const INT32 width = rect->right - rect->left;
115 const INT32 height = rect->bottom - rect->top;
116 BYTE* pDstPoint = pDstData + 1ULL * rect->top * nDstStep +
117 1ULL * rect->left * FreeRDPGetBytesPerPixel(DstFormat);
119 pYUVPoint[0] = pYUVData[0] + 1ULL * rect->top * iStride[0] + rect->left;
120 pYUVPoint[1] = pYUVData[1] + 1ULL * rect->top * iStride[1] + rect->left;
121 pYUVPoint[2] = pYUVData[2] + 1ULL * rect->top * iStride[2] + rect->left;
123 roi.width = WINPR_ASSERTING_INT_CAST(uint32_t, width);
124 roi.height = WINPR_ASSERTING_INT_CAST(uint32_t, height);
126 if (prims->YUV444ToRGB_8u_P3AC4R(pYUVPoint, iStride, pDstPoint, nDstStep, DstFormat, &roi) !=
133static void CALLBACK yuv420_process_work_callback(PTP_CALLBACK_INSTANCE instance,
void* context,
136 YUV_PROCESS_WORK_PARAM* param = (YUV_PROCESS_WORK_PARAM*)context;
137 WINPR_UNUSED(instance);
141 if (!avc420_yuv_to_rgb(param->pYUVData, param->iStride, ¶m->rect, param->nDstStep,
142 param->dest, param->DstFormat))
143 WLog_WARN(TAG,
"avc420_yuv_to_rgb failed");
146static void CALLBACK yuv444_process_work_callback(PTP_CALLBACK_INSTANCE instance,
void* context,
149 YUV_PROCESS_WORK_PARAM* param = (YUV_PROCESS_WORK_PARAM*)context;
150 WINPR_UNUSED(instance);
154 if (!avc444_yuv_to_rgb(param->pYUVData, param->iStride, ¶m->rect, param->nDstStep,
155 param->dest, param->DstFormat))
156 WLog_WARN(TAG,
"avc444_yuv_to_rgb failed");
159BOOL yuv_context_reset(YUV_CONTEXT* WINPR_RESTRICT context, UINT32 width, UINT32 height)
162 WINPR_ASSERT(context);
164 context->width = width;
165 context->height = height;
167 context->heightStep = height;
169 if (context->useThreads)
171 context->heightStep = 16;
177 const size_t pw = (width + TILE_SIZE - width % TILE_SIZE) / 16;
178 const size_t ph = (height + TILE_SIZE - height % TILE_SIZE) / 16;
180 const size_t count = pw * ph;
182 context->work_object_count = 0;
183 if (context->encoder)
185 void* tmp = winpr_aligned_recalloc(context->work_enc_params, count,
186 sizeof(YUV_ENCODE_WORK_PARAM), 32);
189 memset(tmp, 0, count *
sizeof(YUV_ENCODE_WORK_PARAM));
191 context->work_enc_params = tmp;
195 void* tmp = winpr_aligned_recalloc(context->work_dec_params, count,
196 sizeof(YUV_PROCESS_WORK_PARAM), 32);
199 memset(tmp, 0, count *
sizeof(YUV_PROCESS_WORK_PARAM));
201 context->work_dec_params = tmp;
203 void* ctmp = winpr_aligned_recalloc(context->work_combined_params, count,
204 sizeof(YUV_COMBINE_WORK_PARAM), 32);
207 memset(ctmp, 0, count *
sizeof(YUV_COMBINE_WORK_PARAM));
209 context->work_combined_params = ctmp;
213 winpr_aligned_recalloc((
void*)context->work_objects, count,
sizeof(PTP_WORK), 32);
216 memset(wtmp, 0, count *
sizeof(PTP_WORK));
218 context->work_objects = (PTP_WORK*)wtmp;
219 context->work_object_count = WINPR_ASSERTING_INT_CAST(uint32_t, count);
226YUV_CONTEXT* yuv_context_new(BOOL encoder, UINT32 ThreadingFlags)
229 YUV_CONTEXT* ret = winpr_aligned_calloc(1,
sizeof(*ret), 32);
236 ret->encoder = encoder;
237 if (!(ThreadingFlags & THREADING_FLAGS_DISABLE_THREADS))
239 GetNativeSystemInfo(&sysInfos);
240 ret->useThreads = (sysInfos.dwNumberOfProcessors > 1);
246void yuv_context_free(YUV_CONTEXT* context)
250 if (context->useThreads)
252 winpr_aligned_free((
void*)context->work_objects);
253 winpr_aligned_free(context->work_combined_params);
254 winpr_aligned_free(context->work_enc_params);
255 winpr_aligned_free(context->work_dec_params);
257 winpr_aligned_free(context);
260static INLINE YUV_PROCESS_WORK_PARAM pool_decode_param(
const RECTANGLE_16* WINPR_RESTRICT rect,
261 YUV_CONTEXT* WINPR_RESTRICT context,
262 const BYTE* WINPR_RESTRICT pYUVData[3],
263 const UINT32 iStride[3], UINT32 DstFormat,
264 BYTE* WINPR_RESTRICT dest, UINT32 nDstStep)
266 YUV_PROCESS_WORK_PARAM current = { 0 };
269 WINPR_ASSERT(context);
270 WINPR_ASSERT(pYUVData);
271 WINPR_ASSERT(iStride);
274 current.context = context;
275 current.DstFormat = DstFormat;
276 current.pYUVData[0] = pYUVData[0];
277 current.pYUVData[1] = pYUVData[1];
278 current.pYUVData[2] = pYUVData[2];
279 current.iStride[0] = iStride[0];
280 current.iStride[1] = iStride[1];
281 current.iStride[2] = iStride[2];
282 current.nDstStep = nDstStep;
284 current.rect = *rect;
288static BOOL submit_object(PTP_WORK* WINPR_RESTRICT work_object, PTP_WORK_CALLBACK cb,
289 const void* WINPR_RESTRICT param, YUV_CONTEXT* WINPR_RESTRICT context)
304 if (!param || !context)
307 *work_object = CreateThreadpoolWork(cb, cnv.pv, NULL);
311 SubmitThreadpoolWork(*work_object);
315static void free_objects(PTP_WORK* work_objects, UINT32 waitCount)
317 WINPR_ASSERT(work_objects || (waitCount == 0));
319 for (UINT32 i = 0; i < waitCount; i++)
321 PTP_WORK cur = work_objects[i];
322 work_objects[i] = NULL;
327 WaitForThreadpoolWorkCallbacks(cur, FALSE);
328 CloseThreadpoolWork(cur);
332static BOOL intersects(UINT32 pos,
const RECTANGLE_16* WINPR_RESTRICT regionRects,
333 UINT32 numRegionRects)
335 WINPR_ASSERT(regionRects || (numRegionRects == 0));
337 for (UINT32 x = pos + 1; x < numRegionRects; x++)
342 if (rectangles_intersects(what, rect))
344 WLog_WARN(TAG,
"YUV decoder: intersecting rectangles, aborting");
352static RECTANGLE_16 clamp(YUV_CONTEXT* WINPR_RESTRICT context,
353 const RECTANGLE_16* WINPR_RESTRICT rect, UINT32 srcHeight)
355 WINPR_ASSERT(context);
359 const UINT32 height = MIN(context->height, srcHeight);
361 c.top = WINPR_ASSERTING_INT_CAST(UINT16, height);
362 if (c.bottom > height)
363 c.bottom = WINPR_ASSERTING_INT_CAST(UINT16, height);
367static BOOL pool_decode(YUV_CONTEXT* WINPR_RESTRICT context, PTP_WORK_CALLBACK cb,
368 const BYTE* WINPR_RESTRICT pYUVData[3],
const UINT32 iStride[3],
369 UINT32 yuvHeight, UINT32 DstFormat, BYTE* WINPR_RESTRICT dest,
370 UINT32 nDstStep,
const RECTANGLE_16* WINPR_RESTRICT regionRects,
371 UINT32 numRegionRects)
374 UINT32 waitCount = 0;
377 WINPR_ASSERT(context);
379 WINPR_ASSERT(pYUVData);
380 WINPR_ASSERT(iStride);
382 WINPR_ASSERT(regionRects || (numRegionRects == 0));
384 if (context->encoder)
386 WLog_ERR(TAG,
"YUV context set up for encoding, can not decode with it, aborting");
390 if (!context->useThreads || (primitives_flags(prims) & PRIM_FLAGS_HAVE_EXTGPU))
392 for (UINT32 y = 0; y < numRegionRects; y++)
394 const RECTANGLE_16 rect = clamp(context, ®ionRects[y], yuvHeight);
395 YUV_PROCESS_WORK_PARAM current =
396 pool_decode_param(&rect, context, pYUVData, iStride, DstFormat, dest, nDstStep);
397 cb(NULL, ¤t, NULL);
403 for (UINT32 x = 0; x < numRegionRects; x++)
405 RECTANGLE_16 r = clamp(context, ®ionRects[x], yuvHeight);
407 if (intersects(x, regionRects, numRegionRects))
410 while (r.left < r.right)
413 y.right = MIN(r.right, r.left + TILE_SIZE);
415 while (y.top < y.bottom)
419 if (context->work_object_count <= waitCount)
421 free_objects(context->work_objects, context->work_object_count);
425 YUV_PROCESS_WORK_PARAM* cur = &context->work_dec_params[waitCount];
426 z.bottom = MIN(z.bottom, z.top + TILE_SIZE);
427 if (rectangle_is_empty(&z))
429 *cur = pool_decode_param(&z, context, pYUVData, iStride, DstFormat, dest, nDstStep);
430 if (!submit_object(&context->work_objects[waitCount], cb, cur, context))
441 free_objects(context->work_objects, context->work_object_count);
445static INLINE BOOL check_rect(
const YUV_CONTEXT* WINPR_RESTRICT yuv,
446 const RECTANGLE_16* WINPR_RESTRICT rect, UINT32 nDstWidth,
453 if ((rect->right > yuv->width) || (rect->left > yuv->width))
456 if ((rect->top > yuv->height) || (rect->bottom > yuv->height))
460 if ((rect->right > nDstWidth) || (rect->left > nDstWidth))
463 if ((rect->bottom > nDstHeight) || (rect->top > nDstHeight))
469static void CALLBACK yuv444_combine_work_callback(PTP_CALLBACK_INSTANCE instance,
void* context,
472 YUV_COMBINE_WORK_PARAM* param = (YUV_COMBINE_WORK_PARAM*)context;
476 YUV_CONTEXT* yuv = param->context;
482 const UINT32 alignedWidth = yuv->width + ((yuv->width % 16 != 0) ? 16 - yuv->width % 16 : 0);
483 const UINT32 alignedHeight =
484 yuv->height + ((yuv->height % 16 != 0) ? 16 - yuv->height % 16 : 0);
486 WINPR_UNUSED(instance);
489 if (!check_rect(param->context, rect, yuv->width, yuv->height))
492 if (prims->YUV420CombineToYUV444(param->type, param->pYUVData, param->iStride, alignedWidth,
493 alignedHeight, param->pYUVDstData, param->iDstStride,
494 rect) != PRIMITIVES_SUCCESS)
495 WLog_WARN(TAG,
"YUV420CombineToYUV444 failed");
498static INLINE YUV_COMBINE_WORK_PARAM
499pool_decode_rect_param(
const RECTANGLE_16* WINPR_RESTRICT rect, YUV_CONTEXT* WINPR_RESTRICT context,
500 BYTE type,
const BYTE* WINPR_RESTRICT pYUVData[3],
const UINT32 iStride[3],
501 BYTE* WINPR_RESTRICT pYUVDstData[3],
const UINT32 iDstStride[3])
503 YUV_COMBINE_WORK_PARAM current = { 0 };
506 WINPR_ASSERT(context);
507 WINPR_ASSERT(pYUVData);
508 WINPR_ASSERT(iStride);
509 WINPR_ASSERT(pYUVDstData);
510 WINPR_ASSERT(iDstStride);
512 current.context = context;
513 current.pYUVData[0] = pYUVData[0];
514 current.pYUVData[1] = pYUVData[1];
515 current.pYUVData[2] = pYUVData[2];
516 current.pYUVDstData[0] = pYUVDstData[0];
517 current.pYUVDstData[1] = pYUVDstData[1];
518 current.pYUVDstData[2] = pYUVDstData[2];
519 current.iStride[0] = iStride[0];
520 current.iStride[1] = iStride[1];
521 current.iStride[2] = iStride[2];
522 current.iDstStride[0] = iDstStride[0];
523 current.iDstStride[1] = iDstStride[1];
524 current.iDstStride[2] = iDstStride[2];
526 current.rect = *rect;
530static BOOL pool_decode_rect(YUV_CONTEXT* WINPR_RESTRICT context, BYTE type,
531 const BYTE* WINPR_RESTRICT pYUVData[3],
const UINT32 iStride[3],
532 BYTE* WINPR_RESTRICT pYUVDstData[3],
const UINT32 iDstStride[3],
533 const RECTANGLE_16* WINPR_RESTRICT regionRects, UINT32 numRegionRects)
536 UINT32 waitCount = 0;
537 PTP_WORK_CALLBACK cb = yuv444_combine_work_callback;
540 WINPR_ASSERT(context);
541 WINPR_ASSERT(pYUVData);
542 WINPR_ASSERT(iStride);
543 WINPR_ASSERT(pYUVDstData);
544 WINPR_ASSERT(iDstStride);
545 WINPR_ASSERT(regionRects || (numRegionRects == 0));
547 if (!context->useThreads || (primitives_flags(prims) & PRIM_FLAGS_HAVE_EXTGPU))
549 for (UINT32 y = 0; y < numRegionRects; y++)
551 YUV_COMBINE_WORK_PARAM current = pool_decode_rect_param(
552 ®ionRects[y], context, type, pYUVData, iStride, pYUVDstData, iDstStride);
553 cb(NULL, ¤t, NULL);
559 for (waitCount = 0; waitCount < numRegionRects; waitCount++)
561 YUV_COMBINE_WORK_PARAM* current = NULL;
563 if (context->work_object_count <= waitCount)
565 free_objects(context->work_objects, context->work_object_count);
568 current = &context->work_combined_params[waitCount];
569 *current = pool_decode_rect_param(®ionRects[waitCount], context, type, pYUVData, iStride,
570 pYUVDstData, iDstStride);
572 if (!submit_object(&context->work_objects[waitCount], cb, current, context))
578 free_objects(context->work_objects, context->work_object_count);
582BOOL yuv444_context_decode(YUV_CONTEXT* WINPR_RESTRICT context, BYTE type,
583 const BYTE* WINPR_RESTRICT pYUVData[3],
const UINT32 iStride[3],
584 UINT32 srcYuvHeight, BYTE* WINPR_RESTRICT pYUVDstData[3],
585 const UINT32 iDstStride[3], DWORD DstFormat, BYTE* WINPR_RESTRICT dest,
586 UINT32 nDstStep,
const RECTANGLE_16* WINPR_RESTRICT regionRects,
587 UINT32 numRegionRects)
589 const BYTE* pYUVCDstData[3];
591 WINPR_ASSERT(context);
592 WINPR_ASSERT(pYUVData);
593 WINPR_ASSERT(iStride);
594 WINPR_ASSERT(pYUVDstData);
595 WINPR_ASSERT(iDstStride);
597 WINPR_ASSERT(regionRects || (numRegionRects == 0));
599 if (context->encoder)
601 WLog_ERR(TAG,
"YUV context set up for encoding, can not decode with it, aborting");
604 if (!pool_decode_rect(context, type, pYUVData, iStride, pYUVDstData, iDstStride, regionRects,
608 pYUVCDstData[0] = pYUVDstData[0];
609 pYUVCDstData[1] = pYUVDstData[1];
610 pYUVCDstData[2] = pYUVDstData[2];
611 return pool_decode(context, yuv444_process_work_callback, pYUVCDstData, iDstStride,
612 srcYuvHeight, DstFormat, dest, nDstStep, regionRects, numRegionRects);
615BOOL yuv420_context_decode(YUV_CONTEXT* WINPR_RESTRICT context,
616 const BYTE* WINPR_RESTRICT pYUVData[3],
const UINT32 iStride[3],
617 UINT32 yuvHeight, DWORD DstFormat, BYTE* WINPR_RESTRICT dest,
618 UINT32 nDstStep,
const RECTANGLE_16* WINPR_RESTRICT regionRects,
619 UINT32 numRegionRects)
621 return pool_decode(context, yuv420_process_work_callback, pYUVData, iStride, yuvHeight,
622 DstFormat, dest, nDstStep, regionRects, numRegionRects);
625static void CALLBACK yuv420_encode_work_callback(PTP_CALLBACK_INSTANCE instance,
void* context,
629 YUV_ENCODE_WORK_PARAM* param = (YUV_ENCODE_WORK_PARAM*)context;
632 const BYTE* src = NULL;
634 WINPR_UNUSED(instance);
638 roi.width = param->rect.right - param->rect.left;
639 roi.height = param->rect.bottom - param->rect.top;
640 src = param->pSrcData + 1ULL * param->nSrcStep * param->rect.top +
641 1ULL * param->rect.left * FreeRDPGetBytesPerPixel(param->SrcFormat);
643 param->pYUVLumaData[0] + 1ULL * param->rect.top * param->iStride[0] + param->rect.left;
644 pYUVData[1] = param->pYUVLumaData[1] + 1ULL * param->rect.top / 2 * param->iStride[1] +
645 param->rect.left / 2;
646 pYUVData[2] = param->pYUVLumaData[2] + 1ULL * param->rect.top / 2 * param->iStride[2] +
647 param->rect.left / 2;
649 if (prims->RGBToYUV420_8u_P3AC4R(src, param->SrcFormat, param->nSrcStep, pYUVData,
650 param->iStride, &roi) != PRIMITIVES_SUCCESS)
652 WLog_ERR(TAG,
"error when decoding lines");
656static void CALLBACK yuv444v1_encode_work_callback(PTP_CALLBACK_INSTANCE instance,
void* context,
660 YUV_ENCODE_WORK_PARAM* param = (YUV_ENCODE_WORK_PARAM*)context;
662 BYTE* pYUVLumaData[3];
663 BYTE* pYUVChromaData[3];
664 const BYTE* src = NULL;
666 WINPR_UNUSED(instance);
670 roi.width = param->rect.right - param->rect.left;
671 roi.height = param->rect.bottom - param->rect.top;
672 src = param->pSrcData + 1ULL * param->nSrcStep * param->rect.top +
673 1ULL * param->rect.left * FreeRDPGetBytesPerPixel(param->SrcFormat);
675 param->pYUVLumaData[0] + 1ULL * param->rect.top * param->iStride[0] + param->rect.left;
676 pYUVLumaData[1] = param->pYUVLumaData[1] + 1ULL * param->rect.top / 2 * param->iStride[1] +
677 param->rect.left / 2;
678 pYUVLumaData[2] = param->pYUVLumaData[2] + 1ULL * param->rect.top / 2 * param->iStride[2] +
679 param->rect.left / 2;
681 param->pYUVChromaData[0] + 1ULL * param->rect.top * param->iStride[0] + param->rect.left;
682 pYUVChromaData[1] = param->pYUVChromaData[1] + 1ULL * param->rect.top / 2 * param->iStride[1] +
683 param->rect.left / 2;
684 pYUVChromaData[2] = param->pYUVChromaData[2] + 1ULL * param->rect.top / 2 * param->iStride[2] +
685 param->rect.left / 2;
686 if (prims->RGBToAVC444YUV(src, param->SrcFormat, param->nSrcStep, pYUVLumaData, param->iStride,
687 pYUVChromaData, param->iStride, &roi) != PRIMITIVES_SUCCESS)
689 WLog_ERR(TAG,
"error when decoding lines");
693static void CALLBACK yuv444v2_encode_work_callback(PTP_CALLBACK_INSTANCE instance,
void* context,
697 YUV_ENCODE_WORK_PARAM* param = (YUV_ENCODE_WORK_PARAM*)context;
699 BYTE* pYUVLumaData[3];
700 BYTE* pYUVChromaData[3];
701 const BYTE* src = NULL;
703 WINPR_UNUSED(instance);
707 roi.width = param->rect.right - param->rect.left;
708 roi.height = param->rect.bottom - param->rect.top;
709 src = param->pSrcData + 1ULL * param->nSrcStep * param->rect.top +
710 1ULL * param->rect.left * FreeRDPGetBytesPerPixel(param->SrcFormat);
712 param->pYUVLumaData[0] + 1ULL * param->rect.top * param->iStride[0] + param->rect.left;
713 pYUVLumaData[1] = param->pYUVLumaData[1] + 1ULL * param->rect.top / 2 * param->iStride[1] +
714 param->rect.left / 2;
715 pYUVLumaData[2] = param->pYUVLumaData[2] + 1ULL * param->rect.top / 2 * param->iStride[2] +
716 param->rect.left / 2;
718 param->pYUVChromaData[0] + 1ULL * param->rect.top * param->iStride[0] + param->rect.left;
719 pYUVChromaData[1] = param->pYUVChromaData[1] + 1ULL * param->rect.top / 2 * param->iStride[1] +
720 param->rect.left / 2;
721 pYUVChromaData[2] = param->pYUVChromaData[2] + 1ULL * param->rect.top / 2 * param->iStride[2] +
722 param->rect.left / 2;
723 if (prims->RGBToAVC444YUVv2(src, param->SrcFormat, param->nSrcStep, pYUVLumaData,
724 param->iStride, pYUVChromaData, param->iStride,
725 &roi) != PRIMITIVES_SUCCESS)
727 WLog_ERR(TAG,
"error when decoding lines");
731static INLINE YUV_ENCODE_WORK_PARAM pool_encode_fill(
732 const RECTANGLE_16* WINPR_RESTRICT rect, YUV_CONTEXT* WINPR_RESTRICT context,
733 const BYTE* WINPR_RESTRICT pSrcData, UINT32 nSrcStep, UINT32 SrcFormat,
const UINT32 iStride[],
734 BYTE* WINPR_RESTRICT pYUVLumaData[], BYTE* WINPR_RESTRICT pYUVChromaData[])
736 YUV_ENCODE_WORK_PARAM current = { 0 };
739 WINPR_ASSERT(context);
740 WINPR_ASSERT(pSrcData);
741 WINPR_ASSERT(iStride);
742 WINPR_ASSERT(pYUVLumaData);
744 current.context = context;
745 current.pSrcData = pSrcData;
746 current.SrcFormat = SrcFormat;
747 current.nSrcStep = nSrcStep;
748 current.pYUVLumaData[0] = pYUVLumaData[0];
749 current.pYUVLumaData[1] = pYUVLumaData[1];
750 current.pYUVLumaData[2] = pYUVLumaData[2];
753 current.pYUVChromaData[0] = pYUVChromaData[0];
754 current.pYUVChromaData[1] = pYUVChromaData[1];
755 current.pYUVChromaData[2] = pYUVChromaData[2];
757 current.iStride[0] = iStride[0];
758 current.iStride[1] = iStride[1];
759 current.iStride[2] = iStride[2];
761 current.rect = *rect;
766static uint32_t getSteps(uint32_t height, uint32_t step)
768 const uint32_t steps = (height + step / 2 + 1) / step;
774static BOOL pool_encode(YUV_CONTEXT* WINPR_RESTRICT context, PTP_WORK_CALLBACK cb,
775 const BYTE* WINPR_RESTRICT pSrcData, UINT32 nSrcStep, UINT32 SrcFormat,
776 const UINT32 iStride[], BYTE* WINPR_RESTRICT pYUVLumaData[],
777 BYTE* WINPR_RESTRICT pYUVChromaData[],
778 const RECTANGLE_16* WINPR_RESTRICT regionRects, UINT32 numRegionRects)
782 UINT32 waitCount = 0;
784 WINPR_ASSERT(context);
786 WINPR_ASSERT(pSrcData);
787 WINPR_ASSERT(iStride);
788 WINPR_ASSERT(regionRects || (numRegionRects == 0));
790 if (!context->encoder)
793 WLog_ERR(TAG,
"YUV context set up for decoding, can not encode with it, aborting");
797 if (!context->useThreads || (primitives_flags(prims) & PRIM_FLAGS_HAVE_EXTGPU))
799 for (UINT32 x = 0; x < numRegionRects; x++)
801 YUV_ENCODE_WORK_PARAM current =
802 pool_encode_fill(®ionRects[x], context, pSrcData, nSrcStep, SrcFormat, iStride,
803 pYUVLumaData, pYUVChromaData);
804 cb(NULL, ¤t, NULL);
810 for (UINT32 x = 0; x < numRegionRects; x++)
813 const UINT32 height = rect->bottom - rect->top;
814 const UINT32 steps = getSteps(height, context->heightStep);
819 for (UINT32 x = 0; x < numRegionRects; x++)
822 const UINT32 height = rect->bottom - rect->top;
823 const UINT32 steps = getSteps(height, context->heightStep);
825 for (UINT32 y = 0; y < steps; y++)
828 YUV_ENCODE_WORK_PARAM* current = NULL;
830 if (context->work_object_count <= waitCount)
832 free_objects(context->work_objects, context->work_object_count);
836 current = &context->work_enc_params[waitCount];
837 r.top += y * context->heightStep;
838 *current = pool_encode_fill(&r, context, pSrcData, nSrcStep, SrcFormat, iStride,
839 pYUVLumaData, pYUVChromaData);
840 if (!submit_object(&context->work_objects[waitCount], cb, current, context))
848 free_objects(context->work_objects, context->work_object_count);
852BOOL yuv420_context_encode(YUV_CONTEXT* WINPR_RESTRICT context,
const BYTE* WINPR_RESTRICT pSrcData,
853 UINT32 nSrcStep, UINT32 SrcFormat,
const UINT32 iStride[3],
854 BYTE* WINPR_RESTRICT pYUVData[3],
855 const RECTANGLE_16* WINPR_RESTRICT regionRects, UINT32 numRegionRects)
857 if (!context || !pSrcData || !iStride || !pYUVData || !regionRects)
860 return pool_encode(context, yuv420_encode_work_callback, pSrcData, nSrcStep, SrcFormat, iStride,
861 pYUVData, NULL, regionRects, numRegionRects);
864BOOL yuv444_context_encode(YUV_CONTEXT* WINPR_RESTRICT context, BYTE version,
865 const BYTE* WINPR_RESTRICT pSrcData, UINT32 nSrcStep, UINT32 SrcFormat,
866 const UINT32 iStride[3], BYTE* WINPR_RESTRICT pYUVLumaData[3],
867 BYTE* WINPR_RESTRICT pYUVChromaData[3],
868 const RECTANGLE_16* WINPR_RESTRICT regionRects, UINT32 numRegionRects)
870 PTP_WORK_CALLBACK cb = NULL;
874 cb = yuv444v1_encode_work_callback;
877 cb = yuv444v2_encode_work_callback;
883 return pool_encode(context, cb, pSrcData, nSrcStep, SrcFormat, iStride, pYUVLumaData,
884 pYUVChromaData, regionRects, numRegionRects);