22 #include <freerdp/config.h>
24 #include <winpr/assert.h>
29 #include <winpr/crt.h>
30 #include <winpr/tchar.h>
31 #include <winpr/sysinfo.h>
32 #include <winpr/registry.h>
34 #include <freerdp/log.h>
35 #include <freerdp/settings.h>
36 #include <freerdp/codec/rfx.h>
37 #include <freerdp/constants.h>
38 #include <freerdp/primitives.h>
39 #include <freerdp/codec/region.h>
40 #include <freerdp/build-config.h>
42 #include "rfx_constants.h"
43 #include "rfx_types.h"
44 #include "rfx_decode.h"
45 #include "rfx_encode.h"
46 #include "rfx_quantization.h"
50 #include "sse/rfx_sse2.h"
51 #include "neon/rfx_neon.h"
53 #define TAG FREERDP_TAG("codec")
55 #define RFX_KEY "Software\\" FREERDP_VENDOR_STRING "\\" FREERDP_PRODUCT_STRING "\\RemoteFX"
69 static const UINT32 rfx_default_quantization_values[] = { 6, 6, 6, 6, 7, 7, 8, 8, 8, 9 };
71 static INLINE BOOL rfx_write_progressive_tile_simple(RFX_CONTEXT* WINPR_RESTRICT rfx,
73 const RFX_TILE* WINPR_RESTRICT tile);
75 static INLINE
void rfx_profiler_create(RFX_CONTEXT* WINPR_RESTRICT context)
77 if (!context || !context->priv)
79 PROFILER_CREATE(context->priv->prof_rfx_decode_rgb,
"rfx_decode_rgb")
80 PROFILER_CREATE(context->priv->prof_rfx_decode_component, "rfx_decode_component")
81 PROFILER_CREATE(context->priv->prof_rfx_rlgr_decode, "rfx_rlgr_decode")
82 PROFILER_CREATE(context->priv->prof_rfx_differential_decode, "rfx_differential_decode")
83 PROFILER_CREATE(context->priv->prof_rfx_quantization_decode, "rfx_quantization_decode")
84 PROFILER_CREATE(context->priv->prof_rfx_dwt_2d_decode, "rfx_dwt_2d_decode")
85 PROFILER_CREATE(context->priv->prof_rfx_ycbcr_to_rgb, "prims->yCbCrToRGB")
86 PROFILER_CREATE(context->priv->prof_rfx_encode_rgb, "rfx_encode_rgb")
87 PROFILER_CREATE(context->priv->prof_rfx_encode_component, "rfx_encode_component")
88 PROFILER_CREATE(context->priv->prof_rfx_rlgr_encode, "rfx_rlgr_encode")
89 PROFILER_CREATE(context->priv->prof_rfx_differential_encode, "rfx_differential_encode")
90 PROFILER_CREATE(context->priv->prof_rfx_quantization_encode, "rfx_quantization_encode")
91 PROFILER_CREATE(context->priv->prof_rfx_dwt_2d_encode, "rfx_dwt_2d_encode")
92 PROFILER_CREATE(context->priv->prof_rfx_rgb_to_ycbcr, "prims->RGBToYCbCr")
93 PROFILER_CREATE(context->priv->prof_rfx_encode_format_rgb, "rfx_encode_format_rgb")
96 static INLINE
void rfx_profiler_free(RFX_CONTEXT* WINPR_RESTRICT context)
98 if (!context || !context->priv)
100 PROFILER_FREE(context->priv->prof_rfx_decode_rgb)
101 PROFILER_FREE(context->priv->prof_rfx_decode_component)
102 PROFILER_FREE(context->priv->prof_rfx_rlgr_decode)
103 PROFILER_FREE(context->priv->prof_rfx_differential_decode)
104 PROFILER_FREE(context->priv->prof_rfx_quantization_decode)
105 PROFILER_FREE(context->priv->prof_rfx_dwt_2d_decode)
106 PROFILER_FREE(context->priv->prof_rfx_ycbcr_to_rgb)
107 PROFILER_FREE(context->priv->prof_rfx_encode_rgb)
108 PROFILER_FREE(context->priv->prof_rfx_encode_component)
109 PROFILER_FREE(context->priv->prof_rfx_rlgr_encode)
110 PROFILER_FREE(context->priv->prof_rfx_differential_encode)
111 PROFILER_FREE(context->priv->prof_rfx_quantization_encode)
112 PROFILER_FREE(context->priv->prof_rfx_dwt_2d_encode)
113 PROFILER_FREE(context->priv->prof_rfx_rgb_to_ycbcr)
114 PROFILER_FREE(context->priv->prof_rfx_encode_format_rgb)
117 static INLINE
void rfx_profiler_print(RFX_CONTEXT* WINPR_RESTRICT context)
119 if (!context || !context->priv)
122 PROFILER_PRINT_HEADER
123 PROFILER_PRINT(context->priv->prof_rfx_decode_rgb)
124 PROFILER_PRINT(context->priv->prof_rfx_decode_component)
125 PROFILER_PRINT(context->priv->prof_rfx_rlgr_decode)
126 PROFILER_PRINT(context->priv->prof_rfx_differential_decode)
127 PROFILER_PRINT(context->priv->prof_rfx_quantization_decode)
128 PROFILER_PRINT(context->priv->prof_rfx_dwt_2d_decode)
129 PROFILER_PRINT(context->priv->prof_rfx_ycbcr_to_rgb)
130 PROFILER_PRINT(context->priv->prof_rfx_encode_rgb)
131 PROFILER_PRINT(context->priv->prof_rfx_encode_component)
132 PROFILER_PRINT(context->priv->prof_rfx_rlgr_encode)
133 PROFILER_PRINT(context->priv->prof_rfx_differential_encode)
134 PROFILER_PRINT(context->priv->prof_rfx_quantization_encode)
135 PROFILER_PRINT(context->priv->prof_rfx_dwt_2d_encode)
136 PROFILER_PRINT(context->priv->prof_rfx_rgb_to_ycbcr)
137 PROFILER_PRINT(context->priv->prof_rfx_encode_format_rgb)
138 PROFILER_PRINT_FOOTER
141 static INLINE
void rfx_tile_init(
void* obj)
157 static INLINE
void* rfx_decoder_tile_new(
const void* val)
159 const size_t size = 4ULL * 64ULL * 64ULL;
166 if (!(tile->data = (BYTE*)winpr_aligned_malloc(size, 16)))
168 winpr_aligned_free(tile);
171 memset(tile->data, 0xff, size);
172 tile->allocated = TRUE;
176 static INLINE
void rfx_decoder_tile_free(
void* obj)
183 winpr_aligned_free(tile->data);
185 winpr_aligned_free(tile);
189 static INLINE
void* rfx_encoder_tile_new(
const void* val)
192 return winpr_aligned_calloc(1,
sizeof(
RFX_TILE), 32);
195 static INLINE
void rfx_encoder_tile_free(
void* obj)
197 winpr_aligned_free(obj);
200 RFX_CONTEXT* rfx_context_new(BOOL encoder)
202 return rfx_context_new_ex(encoder, 0);
205 RFX_CONTEXT* rfx_context_new_ex(BOOL encoder, UINT32 ThreadingFlags)
213 RFX_CONTEXT* context = NULL;
215 RFX_CONTEXT_PRIV* priv = NULL;
216 context = (RFX_CONTEXT*)winpr_aligned_calloc(1,
sizeof(RFX_CONTEXT), 32);
221 context->encoder = encoder;
222 context->currentMessage.freeArray = TRUE;
223 context->priv = priv = (RFX_CONTEXT_PRIV*)winpr_aligned_calloc(1,
sizeof(RFX_CONTEXT_PRIV), 32);
228 priv->log = WLog_Get(
"com.freerdp.codec.rfx");
229 WLog_OpenAppender(priv->log);
230 priv->TilePool = ObjectPool_New(TRUE);
235 pool = ObjectPool_Object(priv->TilePool);
236 pool->fnObjectInit = rfx_tile_init;
238 if (context->encoder)
240 pool->fnObjectNew = rfx_encoder_tile_new;
241 pool->fnObjectFree = rfx_encoder_tile_free;
245 pool->fnObjectNew = rfx_decoder_tile_new;
246 pool->fnObjectFree = rfx_decoder_tile_free;
262 priv->BufferPool = BufferPool_New(TRUE, (8192ULL + 32ULL) * 3ULL, 16);
264 if (!priv->BufferPool)
267 if (!(ThreadingFlags & THREADING_FLAGS_DISABLE_THREADS))
269 priv->UseThreads = TRUE;
271 GetNativeSystemInfo(&sysinfo);
272 priv->MinThreadCount = sysinfo.dwNumberOfProcessors;
273 priv->MaxThreadCount = 0;
274 status = RegOpenKeyExA(HKEY_LOCAL_MACHINE, RFX_KEY, 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
276 if (status == ERROR_SUCCESS)
278 dwSize =
sizeof(dwValue);
280 if (RegQueryValueEx(hKey, _T(
"UseThreads"), NULL, &dwType, (BYTE*)&dwValue, &dwSize) ==
282 priv->UseThreads = dwValue ? 1 : 0;
284 if (RegQueryValueEx(hKey, _T(
"MinThreadCount"), NULL, &dwType, (BYTE*)&dwValue,
285 &dwSize) == ERROR_SUCCESS)
286 priv->MinThreadCount = dwValue;
288 if (RegQueryValueEx(hKey, _T(
"MaxThreadCount"), NULL, &dwType, (BYTE*)&dwValue,
289 &dwSize) == ERROR_SUCCESS)
290 priv->MaxThreadCount = dwValue;
297 priv->UseThreads = FALSE;
300 if (priv->UseThreads)
306 priv->ThreadPool = CreateThreadpool(NULL);
308 if (!priv->ThreadPool)
311 InitializeThreadpoolEnvironment(&priv->ThreadPoolEnv);
312 SetThreadpoolCallbackPool(&priv->ThreadPoolEnv, priv->ThreadPool);
314 if (priv->MinThreadCount)
315 if (!SetThreadpoolThreadMinimum(priv->ThreadPool, priv->MinThreadCount))
318 if (priv->MaxThreadCount)
319 SetThreadpoolThreadMaximum(priv->ThreadPool, priv->MaxThreadCount);
323 rfx_context_set_pixel_format(context, PIXEL_FORMAT_BGRX32);
325 rfx_profiler_create(context);
327 context->quantization_decode = rfx_quantization_decode;
328 context->quantization_encode = rfx_quantization_encode;
329 context->dwt_2d_decode = rfx_dwt_2d_decode;
330 context->dwt_2d_extrapolate_decode = rfx_dwt_2d_extrapolate_decode;
331 context->dwt_2d_encode = rfx_dwt_2d_encode;
332 context->rlgr_decode = rfx_rlgr_decode;
333 context->rlgr_encode = rfx_rlgr_encode;
334 rfx_init_sse2(context);
335 rfx_init_neon(context);
336 context->state = RFX_STATE_SEND_HEADERS;
337 context->expectedDataBlockType = WBT_FRAME_BEGIN;
340 WINPR_PRAGMA_DIAG_PUSH
341 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
342 rfx_context_free(context);
343 WINPR_PRAGMA_DIAG_POP
347 void rfx_context_free(RFX_CONTEXT* context)
349 RFX_CONTEXT_PRIV* priv = NULL;
354 WINPR_ASSERT(NULL != context);
356 priv = context->priv;
357 WINPR_ASSERT(NULL != priv);
358 WINPR_ASSERT(NULL != priv->TilePool);
359 WINPR_ASSERT(NULL != priv->BufferPool);
362 rfx_message_free(context, &context->currentMessage);
363 winpr_aligned_free(context->quants);
364 rfx_profiler_print(context);
365 rfx_profiler_free(context);
369 ObjectPool_Free(priv->TilePool);
370 if (priv->UseThreads)
372 if (priv->ThreadPool)
373 CloseThreadpool(priv->ThreadPool);
374 DestroyThreadpoolEnvironment(&priv->ThreadPoolEnv);
375 winpr_aligned_free(priv->workObjects);
376 winpr_aligned_free(priv->tileWorkParams);
380 "WARNING: Profiling results probably unusable with multithreaded RemoteFX codec!");
384 BufferPool_Free(priv->BufferPool);
385 winpr_aligned_free(priv);
387 winpr_aligned_free(context);
390 static INLINE
RFX_TILE* rfx_message_get_tile(RFX_MESSAGE* WINPR_RESTRICT message, UINT32 index)
392 WINPR_ASSERT(message);
393 WINPR_ASSERT(message->tiles);
394 WINPR_ASSERT(index < message->numTiles);
395 return message->tiles[index];
398 static INLINE
const RFX_RECT* rfx_message_get_rect_const(
const RFX_MESSAGE* WINPR_RESTRICT message,
401 WINPR_ASSERT(message);
402 WINPR_ASSERT(message->rects);
403 WINPR_ASSERT(index < message->numRects);
404 return &message->rects[index];
407 static INLINE
RFX_RECT* rfx_message_get_rect(RFX_MESSAGE* WINPR_RESTRICT message, UINT32 index)
409 WINPR_ASSERT(message);
410 WINPR_ASSERT(message->rects);
411 WINPR_ASSERT(index < message->numRects);
412 return &message->rects[index];
415 void rfx_context_set_pixel_format(RFX_CONTEXT* WINPR_RESTRICT context, UINT32 pixel_format)
417 WINPR_ASSERT(context);
418 context->pixel_format = pixel_format;
419 context->bits_per_pixel = FreeRDPGetBitsPerPixel(pixel_format);
422 UINT32 rfx_context_get_pixel_format(RFX_CONTEXT* WINPR_RESTRICT context)
424 WINPR_ASSERT(context);
425 return context->pixel_format;
428 void rfx_context_set_palette(RFX_CONTEXT* WINPR_RESTRICT context,
429 const BYTE* WINPR_RESTRICT palette)
431 WINPR_ASSERT(context);
432 context->palette = palette;
435 const BYTE* rfx_context_get_palette(RFX_CONTEXT* WINPR_RESTRICT context)
437 WINPR_ASSERT(context);
438 return context->palette;
441 BOOL rfx_context_reset(RFX_CONTEXT* WINPR_RESTRICT context, UINT32 width, UINT32 height)
446 context->width = width;
447 context->height = height;
448 context->state = RFX_STATE_SEND_HEADERS;
449 context->expectedDataBlockType = WBT_FRAME_BEGIN;
450 context->frameIdx = 0;
454 static INLINE BOOL rfx_process_message_sync(RFX_CONTEXT* WINPR_RESTRICT context,
459 WINPR_ASSERT(context);
460 WINPR_ASSERT(context->priv);
461 context->decodedHeaderBlocks &= ~RFX_DECODED_SYNC;
464 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 6))
467 Stream_Read_UINT32(s, magic);
468 if (magic != WF_MAGIC)
470 WLog_Print(context->priv->log, WLOG_ERROR,
"invalid magic number 0x%08" PRIX32
"", magic);
474 Stream_Read_UINT16(s, context->version);
475 if (context->version != WF_VERSION_1_0)
477 WLog_Print(context->priv->log, WLOG_ERROR,
"invalid version number 0x%08" PRIX32
"",
482 WLog_Print(context->priv->log, WLOG_DEBUG,
"version 0x%08" PRIX32
"", context->version);
483 context->decodedHeaderBlocks |= RFX_DECODED_SYNC;
487 static INLINE BOOL rfx_process_message_codec_versions(RFX_CONTEXT* WINPR_RESTRICT context,
492 WINPR_ASSERT(context);
493 WINPR_ASSERT(context->priv);
494 context->decodedHeaderBlocks &= ~RFX_DECODED_VERSIONS;
496 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 4))
499 Stream_Read_UINT8(s, numCodecs);
500 Stream_Read_UINT8(s, context->codec_id);
502 s, context->codec_version);
506 WLog_Print(context->priv->log, WLOG_ERROR,
"numCodes is 0x%02" PRIX8
" (must be 0x01)",
511 if (context->codec_id != 0x01)
513 WLog_Print(context->priv->log, WLOG_ERROR,
"invalid codec id (0x%02" PRIX32
")",
518 if (context->codec_version != WF_VERSION_1_0)
520 WLog_Print(context->priv->log, WLOG_ERROR,
"invalid codec version (0x%08" PRIX32
")",
521 context->codec_version);
525 WLog_Print(context->priv->log, WLOG_DEBUG,
"id %" PRIu32
" version 0x%" PRIX32
".",
526 context->codec_id, context->codec_version);
527 context->decodedHeaderBlocks |= RFX_DECODED_VERSIONS;
531 static INLINE BOOL rfx_process_message_channels(RFX_CONTEXT* WINPR_RESTRICT context,
535 BYTE numChannels = 0;
537 WINPR_ASSERT(context);
538 WINPR_ASSERT(context->priv);
539 context->decodedHeaderBlocks &= ~RFX_DECODED_CHANNELS;
541 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 1))
544 Stream_Read_UINT8(s, numChannels);
551 WLog_Print(context->priv->log, WLOG_ERROR,
"no channels announced");
555 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(context->priv->log, s, numChannels, 5ull))
559 Stream_Read_UINT8(s, channelId);
561 if (channelId != 0x00)
563 WLog_Print(context->priv->log, WLOG_ERROR,
"channelId:0x%02" PRIX8
", expected:0x00",
568 Stream_Read_UINT16(s, context->width);
569 Stream_Read_UINT16(s, context->height);
571 if (!context->width || !context->height)
573 WLog_Print(context->priv->log, WLOG_ERROR,
574 "invalid channel with/height: %" PRIu16
"x%" PRIu16
"", context->width,
580 Stream_Seek(s, 5ULL * (numChannels - 1));
581 WLog_Print(context->priv->log, WLOG_DEBUG,
582 "numChannels %" PRIu8
" id %" PRIu8
", %" PRIu16
"x%" PRIu16
".", numChannels,
583 channelId, context->width, context->height);
584 context->decodedHeaderBlocks |= RFX_DECODED_CHANNELS;
588 static INLINE BOOL rfx_process_message_context(RFX_CONTEXT* WINPR_RESTRICT context,
593 UINT16 properties = 0;
595 WINPR_ASSERT(context);
596 WINPR_ASSERT(context->priv);
597 context->decodedHeaderBlocks &= ~RFX_DECODED_CONTEXT;
599 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 5))
602 Stream_Read_UINT8(s, ctxId);
603 Stream_Read_UINT16(s, tileSize);
604 Stream_Read_UINT16(s, properties);
605 WLog_Print(context->priv->log, WLOG_DEBUG,
606 "ctxId %" PRIu8
" tileSize %" PRIu16
" properties 0x%04" PRIX16
".", ctxId, tileSize,
608 context->properties = properties;
609 context->flags = (properties & 0x0007);
611 if (context->flags == CODEC_MODE)
613 WLog_Print(context->priv->log, WLOG_DEBUG,
"codec is in image mode.");
617 WLog_Print(context->priv->log, WLOG_DEBUG,
"codec is in video mode.");
620 switch ((properties & 0x1E00) >> 9)
622 case CLW_ENTROPY_RLGR1:
623 context->mode = RLGR1;
624 WLog_Print(context->priv->log, WLOG_DEBUG,
"RLGR1.");
627 case CLW_ENTROPY_RLGR3:
628 context->mode = RLGR3;
629 WLog_Print(context->priv->log, WLOG_DEBUG,
"RLGR3.");
633 WLog_Print(context->priv->log, WLOG_ERROR,
"unknown RLGR algorithm.");
637 context->decodedHeaderBlocks |= RFX_DECODED_CONTEXT;
641 static INLINE BOOL rfx_process_message_frame_begin(RFX_CONTEXT* WINPR_RESTRICT context,
642 RFX_MESSAGE* WINPR_RESTRICT message,
644 UINT16* WINPR_RESTRICT pExpectedBlockType)
647 UINT16 numRegions = 0;
649 WINPR_ASSERT(context);
650 WINPR_ASSERT(context->priv);
651 WINPR_ASSERT(message);
652 WINPR_ASSERT(pExpectedBlockType);
654 if (*pExpectedBlockType != WBT_FRAME_BEGIN)
656 WLog_Print(context->priv->log, WLOG_ERROR,
"message unexpected wants WBT_FRAME_BEGIN");
660 *pExpectedBlockType = WBT_REGION;
662 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 6))
667 Stream_Read_UINT16(s, numRegions);
668 WLog_Print(context->priv->log, WLOG_DEBUG,
669 "RFX_FRAME_BEGIN: frameIdx: %" PRIu32
" numRegions: %" PRIu16
"", frameIdx,
674 static INLINE BOOL rfx_process_message_frame_end(RFX_CONTEXT* WINPR_RESTRICT context,
675 RFX_MESSAGE* WINPR_RESTRICT message,
677 UINT16* WINPR_RESTRICT pExpectedBlockType)
679 WINPR_ASSERT(context);
680 WINPR_ASSERT(context->priv);
681 WINPR_ASSERT(message);
683 WINPR_ASSERT(pExpectedBlockType);
685 if (*pExpectedBlockType != WBT_FRAME_END)
687 WLog_Print(context->priv->log, WLOG_ERROR,
"message unexpected, wants WBT_FRAME_END");
691 *pExpectedBlockType = WBT_FRAME_BEGIN;
692 WLog_Print(context->priv->log, WLOG_DEBUG,
"RFX_FRAME_END");
696 static INLINE BOOL rfx_resize_rects(RFX_MESSAGE* WINPR_RESTRICT message)
698 WINPR_ASSERT(message);
701 winpr_aligned_recalloc(message->rects, message->numRects,
sizeof(
RFX_RECT), 32);
704 message->rects = tmpRects;
708 static INLINE BOOL rfx_process_message_region(RFX_CONTEXT* WINPR_RESTRICT context,
709 RFX_MESSAGE* WINPR_RESTRICT message,
711 UINT16* WINPR_RESTRICT pExpectedBlockType)
713 UINT16 regionType = 0;
714 UINT16 numTileSets = 0;
716 WINPR_ASSERT(context);
717 WINPR_ASSERT(context->priv);
718 WINPR_ASSERT(message);
719 WINPR_ASSERT(pExpectedBlockType);
721 if (*pExpectedBlockType != WBT_REGION)
723 WLog_Print(context->priv->log, WLOG_ERROR,
"message unexpected wants WBT_REGION");
727 *pExpectedBlockType = WBT_EXTENSION;
729 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 3))
732 Stream_Seek_UINT8(s);
733 Stream_Read_UINT16(s, message->numRects);
735 if (message->numRects < 1)
743 message->numRects = 1;
744 if (!rfx_resize_rects(message))
747 message->rects->x = 0;
748 message->rects->y = 0;
749 message->rects->width = context->width;
750 message->rects->height = context->height;
754 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(context->priv->log, s, message->numRects, 8ull))
757 if (!rfx_resize_rects(message))
761 for (UINT16 i = 0; i < message->numRects; i++)
763 RFX_RECT* rect = rfx_message_get_rect(message, i);
765 Stream_Read_UINT16(s, rect->x);
766 Stream_Read_UINT16(s, rect->y);
767 Stream_Read_UINT16(s, rect->width);
768 Stream_Read_UINT16(s, rect->height);
769 WLog_Print(context->priv->log, WLOG_DEBUG,
770 "rect %" PRIu16
" (x,y=%" PRIu16
",%" PRIu16
" w,h=%" PRIu16
" %" PRIu16
").", i,
771 rect->x, rect->y, rect->width, rect->height);
774 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 4))
777 Stream_Read_UINT16(s, regionType);
778 Stream_Read_UINT16(s, numTileSets);
780 if (regionType != CBT_REGION)
782 WLog_Print(context->priv->log, WLOG_ERROR,
"invalid region type 0x%04" PRIX16
"",
787 if (numTileSets != 0x0001)
789 WLog_Print(context->priv->log, WLOG_ERROR,
"invalid number of tilesets (%" PRIu16
")",
800 RFX_CONTEXT* context;
801 } RFX_TILE_PROCESS_WORK_PARAM;
803 static INLINE
void CALLBACK rfx_process_message_tile_work_callback(PTP_CALLBACK_INSTANCE instance,
804 void* context, PTP_WORK work)
806 RFX_TILE_PROCESS_WORK_PARAM* param = (RFX_TILE_PROCESS_WORK_PARAM*)context;
808 rfx_decode_rgb(param->context, param->tile, param->tile->data, 64 * 4);
811 static INLINE BOOL rfx_allocate_tiles(RFX_MESSAGE* WINPR_RESTRICT message,
size_t count,
814 WINPR_ASSERT(message);
816 RFX_TILE** tmpTiles = winpr_aligned_recalloc(message->tiles, count,
sizeof(
RFX_TILE*), 32);
817 if (!tmpTiles && (count != 0))
820 message->tiles = tmpTiles;
822 message->numTiles = count;
825 WINPR_ASSERT(message->numTiles <= count);
827 message->allocatedTiles = count;
832 static INLINE BOOL rfx_process_message_tileset(RFX_CONTEXT* WINPR_RESTRICT context,
833 RFX_MESSAGE* WINPR_RESTRICT message,
835 UINT16* WINPR_RESTRICT pExpectedBlockType)
838 size_t close_cnt = 0;
841 UINT32* quants = NULL;
845 UINT32 blockType = 0;
846 UINT32 tilesDataSize = 0;
847 PTP_WORK* work_objects = NULL;
848 RFX_TILE_PROCESS_WORK_PARAM* params = NULL;
851 WINPR_ASSERT(context);
852 WINPR_ASSERT(context->priv);
853 WINPR_ASSERT(message);
854 WINPR_ASSERT(pExpectedBlockType);
856 if (*pExpectedBlockType != WBT_EXTENSION)
858 WLog_Print(context->priv->log, WLOG_ERROR,
"message unexpected wants a tileset");
862 *pExpectedBlockType = WBT_FRAME_END;
864 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 14))
867 Stream_Read_UINT16(s, subtype);
868 if (subtype != CBT_TILESET)
870 WLog_Print(context->priv->log, WLOG_ERROR,
"invalid subtype, expected CBT_TILESET.");
874 Stream_Seek_UINT16(s);
875 Stream_Seek_UINT16(s);
876 Stream_Read_UINT8(s, context->numQuant);
877 Stream_Seek_UINT8(s);
879 if (context->numQuant < 1)
881 WLog_Print(context->priv->log, WLOG_ERROR,
"no quantization value.");
885 Stream_Read_UINT16(s, numTiles);
892 Stream_Read_UINT32(s, tilesDataSize);
895 winpr_aligned_recalloc(context->quants, context->numQuant, 10 *
sizeof(UINT32), 32)))
898 quants = context->quants = (UINT32*)pmem;
901 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(context->priv->log, s, context->numQuant, 5ull))
904 for (
size_t i = 0; i < context->numQuant; i++)
907 Stream_Read_UINT8(s, quant);
908 *quants++ = (quant & 0x0F);
909 *quants++ = (quant >> 4);
910 Stream_Read_UINT8(s, quant);
911 *quants++ = (quant & 0x0F);
912 *quants++ = (quant >> 4);
913 Stream_Read_UINT8(s, quant);
914 *quants++ = (quant & 0x0F);
915 *quants++ = (quant >> 4);
916 Stream_Read_UINT8(s, quant);
917 *quants++ = (quant & 0x0F);
918 *quants++ = (quant >> 4);
919 Stream_Read_UINT8(s, quant);
920 *quants++ = (quant & 0x0F);
921 *quants++ = (quant >> 4);
922 WLog_Print(context->priv->log, WLOG_DEBUG,
923 "quant %d (%" PRIu32
" %" PRIu32
" %" PRIu32
" %" PRIu32
" %" PRIu32
" %" PRIu32
924 " %" PRIu32
" %" PRIu32
" %" PRIu32
" %" PRIu32
").",
925 i, context->quants[i * 10], context->quants[i * 10 + 1],
926 context->quants[i * 10 + 2], context->quants[i * 10 + 3],
927 context->quants[i * 10 + 4], context->quants[i * 10 + 5],
928 context->quants[i * 10 + 6], context->quants[i * 10 + 7],
929 context->quants[i * 10 + 8], context->quants[i * 10 + 9]);
932 for (
size_t i = 0; i < message->numTiles; i++)
934 ObjectPool_Return(context->priv->TilePool, message->tiles[i]);
935 message->tiles[i] = NULL;
938 if (!rfx_allocate_tiles(message, numTiles, FALSE))
941 if (context->priv->UseThreads)
943 work_objects = (PTP_WORK*)winpr_aligned_calloc(message->numTiles,
sizeof(PTP_WORK), 32);
944 params = (RFX_TILE_PROCESS_WORK_PARAM*)winpr_aligned_recalloc(
945 NULL, message->numTiles,
sizeof(RFX_TILE_PROCESS_WORK_PARAM), 32);
949 winpr_aligned_free(params);
955 winpr_aligned_free(work_objects);
964 if (Stream_GetRemainingLength(s) >= tilesDataSize)
967 for (
size_t i = 0; i < message->numTiles; i++)
972 if (!(tile = (
RFX_TILE*)ObjectPool_Take(context->priv->TilePool)))
974 WLog_Print(context->priv->log, WLOG_ERROR,
975 "RfxMessageTileSet failed to get tile from object pool");
980 message->tiles[i] = tile;
983 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 6))
985 WLog_Print(context->priv->log, WLOG_ERROR,
986 "RfxMessageTileSet packet too small to read tile %d/%" PRIu16
"", i,
992 sub = Stream_StaticInit(&subBuffer, Stream_Pointer(s), Stream_GetRemainingLength(s));
995 Stream_Read_UINT32(sub, blockLen);
997 if (!Stream_SafeSeek(s, blockLen))
1002 if ((blockLen < 6 + 13) ||
1003 (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, sub, blockLen - 6)))
1005 WLog_Print(context->priv->log, WLOG_ERROR,
1006 "RfxMessageTileSet not enough bytes to read tile %d/%" PRIu16
1007 " with blocklen=%" PRIu32
"",
1008 i, message->numTiles, blockLen);
1013 if (blockType != CBT_TILE)
1015 WLog_Print(context->priv->log, WLOG_ERROR,
1016 "unknown block type 0x%" PRIX32
", expected CBT_TILE (0xCAC3).",
1022 Stream_Read_UINT8(sub, tile->quantIdxY);
1023 Stream_Read_UINT8(sub, tile->quantIdxCb);
1024 Stream_Read_UINT8(sub, tile->quantIdxCr);
1025 if (tile->quantIdxY >= context->numQuant)
1027 WLog_Print(context->priv->log, WLOG_ERROR,
1028 "quantIdxY %" PRIu8
" >= numQuant %" PRIu8, tile->quantIdxY,
1033 if (tile->quantIdxCb >= context->numQuant)
1035 WLog_Print(context->priv->log, WLOG_ERROR,
1036 "quantIdxCb %" PRIu8
" >= numQuant %" PRIu8, tile->quantIdxCb,
1041 if (tile->quantIdxCr >= context->numQuant)
1043 WLog_Print(context->priv->log, WLOG_ERROR,
1044 "quantIdxCr %" PRIu8
" >= numQuant %" PRIu8, tile->quantIdxCr,
1050 Stream_Read_UINT16(sub, tile->xIdx);
1051 Stream_Read_UINT16(sub, tile->yIdx);
1052 Stream_Read_UINT16(sub, tile->YLen);
1053 Stream_Read_UINT16(sub, tile->CbLen);
1054 Stream_Read_UINT16(sub, tile->CrLen);
1055 Stream_GetPointer(sub, tile->YData);
1056 if (!Stream_SafeSeek(sub, tile->YLen))
1061 Stream_GetPointer(sub, tile->CbData);
1062 if (!Stream_SafeSeek(sub, tile->CbLen))
1067 Stream_GetPointer(sub, tile->CrData);
1068 if (!Stream_SafeSeek(sub, tile->CrLen))
1073 tile->x = tile->xIdx * 64;
1074 tile->y = tile->yIdx * 64;
1076 if (context->priv->UseThreads)
1084 params[i].context = context;
1085 params[i].tile = message->tiles[i];
1087 if (!(work_objects[i] =
1088 CreateThreadpoolWork(rfx_process_message_tile_work_callback,
1089 (
void*)¶ms[i], &context->priv->ThreadPoolEnv)))
1091 WLog_Print(context->priv->log, WLOG_ERROR,
"CreateThreadpoolWork failed.");
1096 SubmitThreadpoolWork(work_objects[i]);
1101 rfx_decode_rgb(context, tile, tile->data, 64 * 4);
1106 if (context->priv->UseThreads)
1108 for (
size_t i = 0; i < close_cnt; i++)
1110 WaitForThreadpoolWorkCallbacks(work_objects[i], FALSE);
1111 CloseThreadpoolWork(work_objects[i]);
1115 winpr_aligned_free(work_objects);
1116 winpr_aligned_free(params);
1118 for (
size_t i = 0; i < message->numTiles; i++)
1120 if (!(tile = message->tiles[i]))
1123 tile->YLen = tile->CbLen = tile->CrLen = 0;
1124 tile->YData = tile->CbData = tile->CrData = NULL;
1130 BOOL rfx_process_message(RFX_CONTEXT* WINPR_RESTRICT context,
const BYTE* WINPR_RESTRICT data,
1131 UINT32 length, UINT32 left, UINT32 top, BYTE* WINPR_RESTRICT dst,
1132 UINT32 dstFormat, UINT32 dstStride, UINT32 dstHeight,
1133 REGION16* WINPR_RESTRICT invalidRegion)
1139 if (!context || !data || !length)
1142 WINPR_ASSERT(context->priv);
1143 RFX_MESSAGE* message = &context->currentMessage;
1145 wStream* s = Stream_StaticConstInit(&inStream, data, length);
1147 while (ok && Stream_GetRemainingLength(s) > 6)
1149 wStream subStreamBuffer = { 0 };
1150 size_t extraBlockLen = 0;
1151 UINT32 blockLen = 0;
1152 UINT32 blockType = 0;
1155 Stream_Read_UINT16(s, blockType);
1156 Stream_Read_UINT32(s, blockLen);
1157 WLog_Print(context->priv->log, WLOG_DEBUG,
"blockType 0x%" PRIX32
" blockLen %" PRIu32
"",
1158 blockType, blockLen);
1162 WLog_Print(context->priv->log, WLOG_ERROR,
"blockLen too small(%" PRIu32
")", blockLen);
1166 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, blockLen - 6))
1169 if (blockType > WBT_CONTEXT && context->decodedHeaderBlocks != RFX_DECODED_HEADERS)
1171 WLog_Print(context->priv->log, WLOG_ERROR,
"incomplete header blocks processing");
1175 if (blockType >= WBT_CONTEXT && blockType <= WBT_EXTENSION)
1179 UINT8 channelId = 0;
1181 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 2))
1185 Stream_Read_UINT8(s, codecId);
1186 Stream_Read_UINT8(s, channelId);
1188 if (codecId != 0x01)
1190 WLog_Print(context->priv->log, WLOG_ERROR,
"invalid codecId 0x%02" PRIX8
"",
1195 if (blockType == WBT_CONTEXT)
1198 if (channelId != 0xFF)
1200 WLog_Print(context->priv->log, WLOG_ERROR,
1201 "invalid channelId 0x%02" PRIX8
" for blockType 0x%08" PRIX32
"",
1202 channelId, blockType);
1209 if (channelId != 0x00)
1211 WLog_Print(context->priv->log, WLOG_ERROR,
1212 "invalid channelId 0x%02" PRIX8
" for blockType WBT_CONTEXT",
1219 const size_t blockLenNoHeader = blockLen - 6;
1220 if (blockLenNoHeader < extraBlockLen)
1222 WLog_Print(context->priv->log, WLOG_ERROR,
1223 "blockLen too small(%" PRIu32
"), must be >= 6 + %" PRIu16, blockLen,
1228 const size_t subStreamLen = blockLenNoHeader - extraBlockLen;
1229 wStream* subStream = Stream_StaticInit(&subStreamBuffer, Stream_Pointer(s), subStreamLen);
1230 Stream_Seek(s, subStreamLen);
1239 ok = rfx_process_message_sync(context, subStream);
1243 ok = rfx_process_message_context(context, subStream);
1246 case WBT_CODEC_VERSIONS:
1247 ok = rfx_process_message_codec_versions(context, subStream);
1251 ok = rfx_process_message_channels(context, subStream);
1261 case WBT_FRAME_BEGIN:
1262 ok = rfx_process_message_frame_begin(context, message, subStream,
1263 &context->expectedDataBlockType);
1267 ok = rfx_process_message_region(context, message, subStream,
1268 &context->expectedDataBlockType);
1272 ok = rfx_process_message_tileset(context, message, subStream,
1273 &context->expectedDataBlockType);
1277 ok = rfx_process_message_frame_end(context, message, subStream,
1278 &context->expectedDataBlockType);
1282 WLog_Print(context->priv->log, WLOG_ERROR,
"unknown blockType 0x%" PRIX32
"",
1290 UINT32 nbUpdateRects = 0;
1293 const DWORD formatSize = FreeRDPGetBytesPerPixel(context->pixel_format);
1294 const UINT32 dstWidth = dstStride / FreeRDPGetBytesPerPixel(dstFormat);
1295 region16_init(&clippingRects);
1297 WINPR_ASSERT(dstWidth <= UINT16_MAX);
1298 WINPR_ASSERT(dstHeight <= UINT16_MAX);
1299 for (UINT32 i = 0; i < message->numRects; i++)
1302 const RFX_RECT* rect = &(message->rects[i]);
1304 WINPR_ASSERT(left + rect->x <= UINT16_MAX);
1305 WINPR_ASSERT(top + rect->y <= UINT16_MAX);
1306 WINPR_ASSERT(clippingRect.left + rect->width <= UINT16_MAX);
1307 WINPR_ASSERT(clippingRect.top + rect->height <= UINT16_MAX);
1309 clippingRect.left = (UINT16)MIN(left + rect->x, dstWidth);
1310 clippingRect.top = (UINT16)MIN(top + rect->y, dstHeight);
1311 clippingRect.right = (UINT16)MIN(clippingRect.left + rect->width, dstWidth);
1312 clippingRect.bottom = (UINT16)MIN(clippingRect.top + rect->height, dstHeight);
1313 region16_union_rect(&clippingRects, &clippingRects, &clippingRect);
1316 for (UINT32 i = 0; i < message->numTiles; i++)
1319 const RFX_TILE* tile = rfx_message_get_tile(message, i);
1321 WINPR_ASSERT(left + tile->x <= UINT16_MAX);
1322 WINPR_ASSERT(top + tile->y <= UINT16_MAX);
1324 updateRect.left = (UINT16)left + tile->x;
1325 updateRect.top = (UINT16)top + tile->y;
1326 updateRect.right = updateRect.left + 64;
1327 updateRect.bottom = updateRect.top + 64;
1328 region16_init(&updateRegion);
1329 region16_intersect_rect(&updateRegion, &clippingRects, &updateRect);
1330 updateRects = region16_rects(&updateRegion, &nbUpdateRects);
1332 for (UINT32 j = 0; j < nbUpdateRects; j++)
1334 const UINT32 stride = 64 * formatSize;
1335 const UINT32 nXDst = updateRects[j].left;
1336 const UINT32 nYDst = updateRects[j].top;
1337 const UINT32 nXSrc = nXDst - updateRect.left;
1338 const UINT32 nYSrc = nYDst - updateRect.top;
1339 const UINT32 nWidth = updateRects[j].right - updateRects[j].left;
1340 const UINT32 nHeight = updateRects[j].bottom - updateRects[j].top;
1342 if (!freerdp_image_copy_no_overlap(dst, dstFormat, dstStride, nXDst, nYDst, nWidth,
1343 nHeight, tile->data, context->pixel_format,
1344 stride, nXSrc, nYSrc, NULL, FREERDP_FLIP_NONE))
1346 region16_uninit(&updateRegion);
1347 WLog_Print(context->priv->log, WLOG_ERROR,
1348 "nbUpdateRectx[%" PRIu32
" (%" PRIu32
")] freerdp_image_copy failed",
1354 region16_union_rect(invalidRegion, invalidRegion, &updateRects[j]);
1357 region16_uninit(&updateRegion);
1360 region16_uninit(&clippingRects);
1365 rfx_message_free(context, message);
1366 context->currentMessage.freeArray = TRUE;
1369 WLog_Print(context->priv->log, WLOG_ERROR,
"failed");
1373 const UINT32* rfx_message_get_quants(
const RFX_MESSAGE* WINPR_RESTRICT message,
1374 UINT16* WINPR_RESTRICT numQuantVals)
1376 WINPR_ASSERT(message);
1378 *numQuantVals = message->numQuant;
1379 return message->quantVals;
1382 const RFX_TILE** rfx_message_get_tiles(
const RFX_MESSAGE* WINPR_RESTRICT message,
1383 UINT16* WINPR_RESTRICT numTiles)
1385 WINPR_ASSERT(message);
1387 *numTiles = message->numTiles;
1394 cnv.pp = message->tiles;
1398 UINT16 rfx_message_get_tile_count(
const RFX_MESSAGE* WINPR_RESTRICT message)
1400 WINPR_ASSERT(message);
1401 return message->numTiles;
1404 const RFX_RECT* rfx_message_get_rects(
const RFX_MESSAGE* WINPR_RESTRICT message,
1405 UINT16* WINPR_RESTRICT numRects)
1407 WINPR_ASSERT(message);
1409 *numRects = message->numRects;
1410 return message->rects;
1413 UINT16 rfx_message_get_rect_count(
const RFX_MESSAGE* WINPR_RESTRICT message)
1415 WINPR_ASSERT(message);
1416 return message->numRects;
1419 void rfx_message_free(RFX_CONTEXT* WINPR_RESTRICT context, RFX_MESSAGE* WINPR_RESTRICT message)
1424 winpr_aligned_free(message->rects);
1428 for (
size_t i = 0; i < message->numTiles; i++)
1430 RFX_TILE* tile = message->tiles[i];
1434 if (tile->YCbCrData)
1436 BufferPool_Return(context->priv->BufferPool, tile->YCbCrData);
1437 tile->YCbCrData = NULL;
1440 ObjectPool_Return(context->priv->TilePool, (
void*)tile);
1443 rfx_allocate_tiles(message, 0, FALSE);
1446 const BOOL freeArray = message->freeArray;
1447 const RFX_MESSAGE empty = { 0 };
1451 winpr_aligned_free(message);
1454 static INLINE
void rfx_update_context_properties(RFX_CONTEXT* WINPR_RESTRICT context)
1456 UINT16 properties = 0;
1458 WINPR_ASSERT(context);
1461 properties |= (context->flags << 1);
1462 properties |= (COL_CONV_ICT << 4);
1463 properties |= (CLW_XFORM_DWT_53_A << 6);
1464 properties |= ((context->mode == RLGR1 ? CLW_ENTROPY_RLGR1 : CLW_ENTROPY_RLGR3) << 10);
1465 properties |= (SCALAR_QUANTIZATION << 14);
1466 context->properties = properties;
1469 static INLINE
void rfx_write_message_sync(
const RFX_CONTEXT* WINPR_RESTRICT context,
1472 WINPR_ASSERT(context);
1474 Stream_Write_UINT16(s, WBT_SYNC);
1475 Stream_Write_UINT32(s, 12);
1476 Stream_Write_UINT32(s, WF_MAGIC);
1477 Stream_Write_UINT16(s, WF_VERSION_1_0);
1480 static INLINE
void rfx_write_message_codec_versions(
const RFX_CONTEXT* WINPR_RESTRICT context,
1483 WINPR_ASSERT(context);
1485 Stream_Write_UINT16(s, WBT_CODEC_VERSIONS);
1486 Stream_Write_UINT32(s, 10);
1487 Stream_Write_UINT8(s, 1);
1488 Stream_Write_UINT8(s, 1);
1489 Stream_Write_UINT16(s, WF_VERSION_1_0);
1492 static INLINE
void rfx_write_message_channels(
const RFX_CONTEXT* WINPR_RESTRICT context,
1495 WINPR_ASSERT(context);
1497 Stream_Write_UINT16(s, WBT_CHANNELS);
1498 Stream_Write_UINT32(s, 12);
1499 Stream_Write_UINT8(s, 1);
1500 Stream_Write_UINT8(s, 0);
1501 Stream_Write_UINT16(s, context->width);
1502 Stream_Write_UINT16(s, context->height);
1505 static INLINE
void rfx_write_message_context(RFX_CONTEXT* WINPR_RESTRICT context,
1508 UINT16 properties = 0;
1509 WINPR_ASSERT(context);
1511 Stream_Write_UINT16(s, WBT_CONTEXT);
1512 Stream_Write_UINT32(s, 13);
1513 Stream_Write_UINT8(s, 1);
1514 Stream_Write_UINT8(s, 0xFF);
1515 Stream_Write_UINT8(s, 0);
1516 Stream_Write_UINT16(s, CT_TILE_64x64);
1518 properties = context->flags;
1519 properties |= (COL_CONV_ICT << 3);
1520 properties |= (CLW_XFORM_DWT_53_A << 5);
1521 properties |= ((context->mode == RLGR1 ? CLW_ENTROPY_RLGR1 : CLW_ENTROPY_RLGR3) << 9);
1522 properties |= (SCALAR_QUANTIZATION << 13);
1523 Stream_Write_UINT16(s, properties);
1524 rfx_update_context_properties(context);
1527 static INLINE BOOL rfx_compose_message_header(RFX_CONTEXT* WINPR_RESTRICT context,
1530 WINPR_ASSERT(context);
1531 if (!Stream_EnsureRemainingCapacity(s, 12 + 10 + 12 + 13))
1534 rfx_write_message_sync(context, s);
1535 rfx_write_message_context(context, s);
1536 rfx_write_message_codec_versions(context, s);
1537 rfx_write_message_channels(context, s);
1541 static INLINE
size_t rfx_tile_length(
const RFX_TILE* WINPR_RESTRICT tile)
1544 return 19ull + tile->YLen + tile->CbLen + tile->CrLen;
1547 static INLINE BOOL rfx_write_tile(
wStream* WINPR_RESTRICT s,
const RFX_TILE* WINPR_RESTRICT tile)
1549 const size_t blockLen = rfx_tile_length(tile);
1550 if (blockLen > UINT32_MAX)
1552 if (!Stream_EnsureRemainingCapacity(s, blockLen))
1555 Stream_Write_UINT16(s, CBT_TILE);
1556 Stream_Write_UINT32(s, (UINT32)blockLen);
1557 Stream_Write_UINT8(s, tile->quantIdxY);
1558 Stream_Write_UINT8(s, tile->quantIdxCb);
1559 Stream_Write_UINT8(s, tile->quantIdxCr);
1560 Stream_Write_UINT16(s, tile->xIdx);
1561 Stream_Write_UINT16(s, tile->yIdx);
1562 Stream_Write_UINT16(s, tile->YLen);
1563 Stream_Write_UINT16(s, tile->CbLen);
1564 Stream_Write_UINT16(s, tile->CrLen);
1565 Stream_Write(s, tile->YData, tile->YLen);
1566 Stream_Write(s, tile->CbData, tile->CbLen);
1567 Stream_Write(s, tile->CrData, tile->CrLen);
1571 struct S_RFX_TILE_COMPOSE_WORK_PARAM
1574 RFX_CONTEXT* context;
1577 static INLINE
void CALLBACK rfx_compose_message_tile_work_callback(PTP_CALLBACK_INSTANCE instance,
1578 void* context, PTP_WORK work)
1580 RFX_TILE_COMPOSE_WORK_PARAM* param = (RFX_TILE_COMPOSE_WORK_PARAM*)context;
1581 WINPR_ASSERT(param);
1582 rfx_encode_rgb(param->context, param->tile);
1585 static INLINE BOOL computeRegion(
const RFX_RECT* WINPR_RESTRICT rects,
size_t numRects,
1586 REGION16* WINPR_RESTRICT region,
size_t width,
size_t height)
1590 WINPR_ASSERT(rects);
1591 for (
size_t i = 0; i < numRects; i++)
1595 rect16.left = rect->x;
1596 rect16.top = rect->y;
1597 rect16.right = rect->x + rect->width;
1598 rect16.bottom = rect->y + rect->height;
1600 if (!region16_union_rect(region, region, &rect16))
1604 return region16_intersect_rect(region, region, &mainRect);
1607 #define TILE_NO(v) ((v) / 64)
1609 static INLINE BOOL setupWorkers(RFX_CONTEXT* WINPR_RESTRICT context,
size_t nbTiles)
1611 WINPR_ASSERT(context);
1613 RFX_CONTEXT_PRIV* priv = context->priv;
1618 if (!context->priv->UseThreads)
1621 if (!(pmem = winpr_aligned_recalloc(priv->workObjects, nbTiles,
sizeof(PTP_WORK), 32)))
1624 priv->workObjects = (PTP_WORK*)pmem;
1626 if (!(pmem = winpr_aligned_recalloc(priv->tileWorkParams, nbTiles,
1627 sizeof(RFX_TILE_COMPOSE_WORK_PARAM), 32)))
1630 priv->tileWorkParams = (RFX_TILE_COMPOSE_WORK_PARAM*)pmem;
1634 static INLINE BOOL rfx_ensure_tiles(RFX_MESSAGE* WINPR_RESTRICT message,
size_t count)
1636 WINPR_ASSERT(message);
1638 if (message->numTiles + count <= message->allocatedTiles)
1641 const size_t alloc = MAX(message->allocatedTiles + 1024, message->numTiles + count);
1642 return rfx_allocate_tiles(message, alloc, TRUE);
1645 RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* WINPR_RESTRICT context,
1646 const RFX_RECT* WINPR_RESTRICT rects,
size_t numRects,
1647 const BYTE* WINPR_RESTRICT data, UINT32 w, UINT32 h,
size_t s)
1649 const UINT32 width = w;
1650 const UINT32 height = h;
1651 const UINT32 scanline = (UINT32)s;
1652 RFX_MESSAGE* message = NULL;
1653 PTP_WORK* workObject = NULL;
1654 RFX_TILE_COMPOSE_WORK_PARAM* workParam = NULL;
1655 BOOL success = FALSE;
1662 WINPR_ASSERT(rects);
1663 WINPR_ASSERT(numRects > 0);
1664 WINPR_ASSERT(w > 0);
1665 WINPR_ASSERT(h > 0);
1666 WINPR_ASSERT(s > 0);
1668 if (!(message = (RFX_MESSAGE*)winpr_aligned_calloc(1,
sizeof(RFX_MESSAGE), 32)))
1671 region16_init(&tilesRegion);
1672 region16_init(&rectsRegion);
1674 if (context->state == RFX_STATE_SEND_HEADERS)
1675 rfx_update_context_properties(context);
1677 message->frameIdx = context->frameIdx++;
1679 if (!context->numQuant)
1681 WINPR_ASSERT(context->quants == NULL);
1682 if (!(context->quants =
1683 (UINT32*)winpr_aligned_malloc(
sizeof(rfx_default_quantization_values), 32)))
1684 goto skip_encoding_loop;
1686 CopyMemory(context->quants, &rfx_default_quantization_values,
1687 sizeof(rfx_default_quantization_values));
1688 context->numQuant = 1;
1689 context->quantIdxY = 0;
1690 context->quantIdxCb = 0;
1691 context->quantIdxCr = 0;
1694 message->numQuant = context->numQuant;
1695 message->quantVals = context->quants;
1696 const UINT32 bytesPerPixel = (context->bits_per_pixel / 8);
1698 if (!computeRegion(rects, numRects, &rectsRegion, width, height))
1699 goto skip_encoding_loop;
1701 const RECTANGLE_16* extents = region16_extents(&rectsRegion);
1702 WINPR_ASSERT((INT32)extents->right - extents->left > 0);
1703 WINPR_ASSERT((INT32)extents->bottom - extents->top > 0);
1704 const UINT32 maxTilesX = 1 + TILE_NO(extents->right - 1) - TILE_NO(extents->left);
1705 const UINT32 maxTilesY = 1 + TILE_NO(extents->bottom - 1) - TILE_NO(extents->top);
1706 const UINT32 maxNbTiles = maxTilesX * maxTilesY;
1708 if (!rfx_ensure_tiles(message, maxNbTiles))
1709 goto skip_encoding_loop;
1711 if (!setupWorkers(context, maxNbTiles))
1712 goto skip_encoding_loop;
1714 if (context->priv->UseThreads)
1716 workObject = context->priv->workObjects;
1717 workParam = context->priv->tileWorkParams;
1720 UINT32 regionNbRects = 0;
1721 regionRect = region16_rects(&rectsRegion, ®ionNbRects);
1723 if (!(message->rects = winpr_aligned_calloc(regionNbRects,
sizeof(
RFX_RECT), 32)))
1724 goto skip_encoding_loop;
1726 message->numRects = regionNbRects;
1728 for (UINT32 i = 0; i < regionNbRects; i++, regionRect++)
1730 RFX_RECT* rfxRect = &message->rects[i];
1731 UINT32 startTileX = regionRect->left / 64;
1732 UINT32 endTileX = (regionRect->right - 1) / 64;
1733 UINT32 startTileY = regionRect->top / 64;
1734 UINT32 endTileY = (regionRect->bottom - 1) / 64;
1735 rfxRect->x = regionRect->left;
1736 rfxRect->y = regionRect->top;
1737 rfxRect->width = (regionRect->right - regionRect->left);
1738 rfxRect->height = (regionRect->bottom - regionRect->top);
1740 for (UINT32 yIdx = startTileY, gridRelY = startTileY * 64; yIdx <= endTileY;
1741 yIdx++, gridRelY += 64)
1743 UINT32 tileHeight = 64;
1745 if ((yIdx == endTileY) && (gridRelY + 64 > height))
1746 tileHeight = height - gridRelY;
1748 currentTileRect.top = gridRelY;
1749 currentTileRect.bottom = gridRelY + tileHeight;
1751 for (UINT32 xIdx = startTileX, gridRelX = startTileX * 64; xIdx <= endTileX;
1752 xIdx++, gridRelX += 64)
1761 if ((xIdx == endTileX) && (gridRelX + 64 > width))
1762 tileWidth = width - gridRelX;
1764 currentTileRect.left = gridRelX;
1765 currentTileRect.right = gridRelX + tileWidth;
1768 if (region16_intersects_rect(&tilesRegion, ¤tTileRect))
1773 goto skip_encoding_loop;
1779 tile->scanline = scanline;
1780 tile->width = tileWidth;
1781 tile->height = tileHeight;
1782 const UINT32 ax = gridRelX;
1783 const UINT32 ay = gridRelY;
1785 if (tile->data && tile->allocated)
1787 winpr_aligned_free(tile->data);
1788 tile->allocated = FALSE;
1792 cnv.cpv = &data[(ay * scanline) + (ax * bytesPerPixel)];
1793 tile->data = cnv.pv;
1794 tile->quantIdxY = context->quantIdxY;
1795 tile->quantIdxCb = context->quantIdxCb;
1796 tile->quantIdxCr = context->quantIdxCr;
1797 tile->YLen = tile->CbLen = tile->CrLen = 0;
1799 if (!(tile->YCbCrData = (BYTE*)BufferPool_Take(context->priv->BufferPool, -1)))
1800 goto skip_encoding_loop;
1802 tile->YData = &(tile->YCbCrData[((8192 + 32) * 0) + 16]);
1803 tile->CbData = &(tile->YCbCrData[((8192 + 32) * 1) + 16]);
1804 tile->CrData = &(tile->YCbCrData[((8192 + 32) * 2) + 16]);
1806 if (!rfx_ensure_tiles(message, 1))
1807 goto skip_encoding_loop;
1808 message->tiles[message->numTiles++] = tile;
1810 if (context->priv->UseThreads)
1812 workParam->context = context;
1813 workParam->tile = tile;
1815 if (!(*workObject = CreateThreadpoolWork(rfx_compose_message_tile_work_callback,
1817 &context->priv->ThreadPoolEnv)))
1819 goto skip_encoding_loop;
1822 SubmitThreadpoolWork(*workObject);
1828 rfx_encode_rgb(context, tile);
1831 if (!region16_union_rect(&tilesRegion, &tilesRegion, ¤tTileRect))
1832 goto skip_encoding_loop;
1843 message->tilesDataSize = 0;
1844 workObject = context->priv->workObjects;
1846 for (UINT32 i = 0; i < message->numTiles; i++)
1848 if (context->priv->UseThreads)
1852 WaitForThreadpoolWorkCallbacks(*workObject, FALSE);
1853 CloseThreadpoolWork(*workObject);
1859 const RFX_TILE* tile = message->tiles[i];
1860 message->tilesDataSize += rfx_tile_length(tile);
1863 region16_uninit(&tilesRegion);
1864 region16_uninit(&rectsRegion);
1869 WLog_Print(context->priv->log, WLOG_ERROR,
"failed");
1871 rfx_message_free(context, message);
1875 static INLINE BOOL rfx_clone_rects(RFX_MESSAGE* WINPR_RESTRICT dst,
1876 const RFX_MESSAGE* WINPR_RESTRICT src)
1881 WINPR_ASSERT(dst->rects == NULL);
1882 WINPR_ASSERT(dst->numRects == 0);
1884 if (src->numRects == 0)
1887 dst->rects = winpr_aligned_calloc(src->numRects,
sizeof(
RECTANGLE_16), 32);
1890 dst->numRects = src->numRects;
1891 for (
size_t x = 0; x < src->numRects; x++)
1893 dst->rects[x] = src->rects[x];
1898 static INLINE BOOL rfx_clone_quants(RFX_MESSAGE* WINPR_RESTRICT dst,
1899 const RFX_MESSAGE* WINPR_RESTRICT src)
1904 WINPR_ASSERT(dst->quantVals == NULL);
1905 WINPR_ASSERT(dst->numQuant == 0);
1907 if (src->numQuant == 0)
1911 dst->quantVals = src->quantVals;
1912 dst->numQuant = src->numQuant;
1917 static INLINE RFX_MESSAGE* rfx_split_message(RFX_CONTEXT* WINPR_RESTRICT context,
1918 RFX_MESSAGE* WINPR_RESTRICT message,
1919 size_t* WINPR_RESTRICT numMessages,
size_t maxDataSize)
1921 WINPR_ASSERT(context);
1922 WINPR_ASSERT(message);
1923 WINPR_ASSERT(numMessages);
1925 maxDataSize -= 1024;
1926 *numMessages = ((message->tilesDataSize + maxDataSize) / maxDataSize) * 4ull;
1928 RFX_MESSAGE* messages =
1929 (RFX_MESSAGE*)winpr_aligned_calloc((*numMessages),
sizeof(RFX_MESSAGE), 32);
1934 for (UINT16 i = 0; i < message->numTiles; i++)
1936 RFX_TILE* tile = message->tiles[i];
1937 RFX_MESSAGE* msg = &messages[j];
1942 const size_t tileDataSize = rfx_tile_length(tile);
1944 if ((msg->tilesDataSize + tileDataSize) > ((UINT32)maxDataSize))
1947 if (msg->numTiles == 0)
1949 msg->frameIdx = message->frameIdx + j;
1950 if (!rfx_clone_quants(msg, message))
1952 if (!rfx_clone_rects(msg, message))
1954 msg->freeArray = TRUE;
1955 if (!rfx_allocate_tiles(msg, message->numTiles, TRUE))
1959 msg->tilesDataSize += tileDataSize;
1961 WINPR_ASSERT(msg->numTiles < msg->allocatedTiles);
1962 msg->tiles[msg->numTiles++] = message->tiles[i];
1963 message->tiles[i] = NULL;
1966 *numMessages = j + 1ULL;
1967 context->frameIdx += j;
1968 message->numTiles = 0;
1972 for (
size_t i = 0; i < j; i++)
1973 rfx_allocate_tiles(&messages[i], 0, FALSE);
1975 winpr_aligned_free(messages);
1979 const RFX_MESSAGE* rfx_message_list_get(
const RFX_MESSAGE_LIST* WINPR_RESTRICT messages,
size_t idx)
1981 WINPR_ASSERT(messages);
1982 if (idx >= messages->count)
1984 WINPR_ASSERT(messages->list);
1985 return &messages->list[idx];
1988 void rfx_message_list_free(RFX_MESSAGE_LIST* messages)
1992 for (
size_t x = 0; x < messages->count; x++)
1993 rfx_message_free(messages->context, &messages->list[x]);
1997 static INLINE RFX_MESSAGE_LIST* rfx_message_list_new(RFX_CONTEXT* WINPR_RESTRICT context,
1998 RFX_MESSAGE* WINPR_RESTRICT messages,
2001 WINPR_ASSERT(context);
2002 RFX_MESSAGE_LIST* msg = calloc(1,
sizeof(RFX_MESSAGE_LIST));
2005 msg->context = context;
2007 msg->list = messages;
2011 RFX_MESSAGE_LIST* rfx_encode_messages(RFX_CONTEXT* WINPR_RESTRICT context,
2012 const RFX_RECT* WINPR_RESTRICT rects,
size_t numRects,
2013 const BYTE* WINPR_RESTRICT data, UINT32 width, UINT32 height,
2014 UINT32 scanline,
size_t* WINPR_RESTRICT numMessages,
2017 WINPR_ASSERT(context);
2018 WINPR_ASSERT(numMessages);
2020 RFX_MESSAGE* message =
2021 rfx_encode_message(context, rects, numRects, data, width, height, scanline);
2025 RFX_MESSAGE* list = rfx_split_message(context, message, numMessages, maxDataSize);
2026 rfx_message_free(context, message);
2030 return rfx_message_list_new(context, list, *numMessages);
2033 static INLINE BOOL rfx_write_message_tileset(RFX_CONTEXT* WINPR_RESTRICT context,
2035 const RFX_MESSAGE* WINPR_RESTRICT message)
2037 WINPR_ASSERT(context);
2038 WINPR_ASSERT(message);
2040 const UINT32 blockLen = 22 + (message->numQuant * 5) + message->tilesDataSize;
2042 if (!Stream_EnsureRemainingCapacity(s, blockLen))
2045 Stream_Write_UINT16(s, WBT_EXTENSION);
2046 Stream_Write_UINT32(s, blockLen);
2047 Stream_Write_UINT8(s, 1);
2048 Stream_Write_UINT8(s, 0);
2049 Stream_Write_UINT16(s, CBT_TILESET);
2050 Stream_Write_UINT16(s, 0);
2051 Stream_Write_UINT16(s, context->properties);
2052 Stream_Write_UINT8(s, message->numQuant);
2053 Stream_Write_UINT8(s, 0x40);
2054 Stream_Write_UINT16(s, message->numTiles);
2055 Stream_Write_UINT32(s, message->tilesDataSize);
2057 UINT32* quantVals = message->quantVals;
2058 for (
size_t i = 0; i < message->numQuant * 5ul; i++)
2060 WINPR_ASSERT(quantVals);
2061 Stream_Write_UINT8(s, quantVals[0] + (quantVals[1] << 4));
2065 for (
size_t i = 0; i < message->numTiles; i++)
2067 RFX_TILE* tile = message->tiles[i];
2071 if (!rfx_write_tile(s, tile))
2075 #ifdef WITH_DEBUG_RFX
2076 WLog_Print(context->priv->log, WLOG_DEBUG,
2077 "numQuant: %" PRIu16
" numTiles: %" PRIu16
" tilesDataSize: %" PRIu32
"",
2078 message->numQuant, message->numTiles, message->tilesDataSize);
2083 static INLINE BOOL rfx_write_message_frame_begin(RFX_CONTEXT* WINPR_RESTRICT context,
2085 const RFX_MESSAGE* WINPR_RESTRICT message)
2087 WINPR_ASSERT(context);
2088 WINPR_ASSERT(message);
2090 if (!Stream_EnsureRemainingCapacity(s, 14))
2093 Stream_Write_UINT16(s, WBT_FRAME_BEGIN);
2094 Stream_Write_UINT32(s, 14);
2095 Stream_Write_UINT8(s, 1);
2096 Stream_Write_UINT8(s, 0);
2097 Stream_Write_UINT32(s, message->frameIdx);
2098 Stream_Write_UINT16(s, 1);
2102 static INLINE BOOL rfx_write_message_region(RFX_CONTEXT* WINPR_RESTRICT context,
2104 const RFX_MESSAGE* WINPR_RESTRICT message)
2106 WINPR_ASSERT(context);
2107 WINPR_ASSERT(message);
2109 const size_t blockLen = 15 + (message->numRects * 8);
2110 if (blockLen > UINT32_MAX)
2113 if (!Stream_EnsureRemainingCapacity(s, blockLen))
2116 Stream_Write_UINT16(s, WBT_REGION);
2117 Stream_Write_UINT32(s, (UINT32)blockLen);
2118 Stream_Write_UINT8(s, 1);
2119 Stream_Write_UINT8(s, 0);
2120 Stream_Write_UINT8(s, 1);
2121 Stream_Write_UINT16(s, message->numRects);
2123 for (UINT16 i = 0; i < message->numRects; i++)
2125 const RFX_RECT* rect = rfx_message_get_rect_const(message, i);
2129 Stream_Write_UINT16(s, rect->x);
2130 Stream_Write_UINT16(s, rect->y);
2131 Stream_Write_UINT16(s, rect->width);
2132 Stream_Write_UINT16(s, rect->height);
2135 Stream_Write_UINT16(s, CBT_REGION);
2136 Stream_Write_UINT16(s, 1);
2140 static INLINE BOOL rfx_write_message_frame_end(RFX_CONTEXT* WINPR_RESTRICT context,
2142 const RFX_MESSAGE* WINPR_RESTRICT message)
2144 WINPR_ASSERT(context);
2145 WINPR_ASSERT(message);
2147 if (!Stream_EnsureRemainingCapacity(s, 8))
2150 Stream_Write_UINT16(s, WBT_FRAME_END);
2151 Stream_Write_UINT32(s, 8);
2152 Stream_Write_UINT8(s, 1);
2153 Stream_Write_UINT8(s, 0);
2157 BOOL rfx_write_message(RFX_CONTEXT* WINPR_RESTRICT context,
wStream* WINPR_RESTRICT s,
2158 const RFX_MESSAGE* WINPR_RESTRICT message)
2160 WINPR_ASSERT(context);
2161 WINPR_ASSERT(message);
2163 if (context->state == RFX_STATE_SEND_HEADERS)
2165 if (!rfx_compose_message_header(context, s))
2168 context->state = RFX_STATE_SEND_FRAME_DATA;
2171 if (!rfx_write_message_frame_begin(context, s, message) ||
2172 !rfx_write_message_region(context, s, message) ||
2173 !rfx_write_message_tileset(context, s, message) ||
2174 !rfx_write_message_frame_end(context, s, message))
2182 BOOL rfx_compose_message(RFX_CONTEXT* WINPR_RESTRICT context,
wStream* WINPR_RESTRICT s,
2183 const RFX_RECT* WINPR_RESTRICT rects,
size_t numRects,
2184 const BYTE* WINPR_RESTRICT data, UINT32 width, UINT32 height,
2187 WINPR_ASSERT(context);
2188 RFX_MESSAGE* message =
2189 rfx_encode_message(context, rects, numRects, data, width, height, scanline);
2193 const BOOL ret = rfx_write_message(context, s, message);
2194 rfx_message_free(context, message);
2198 BOOL rfx_context_set_mode(RFX_CONTEXT* WINPR_RESTRICT context, RLGR_MODE mode)
2200 WINPR_ASSERT(context);
2201 context->mode = mode;
2205 RLGR_MODE rfx_context_get_mode(RFX_CONTEXT* WINPR_RESTRICT context)
2207 WINPR_ASSERT(context);
2208 return context->mode;
2211 UINT32 rfx_context_get_frame_idx(
const RFX_CONTEXT* WINPR_RESTRICT context)
2213 WINPR_ASSERT(context);
2214 return context->frameIdx;
2217 UINT32 rfx_message_get_frame_idx(
const RFX_MESSAGE* WINPR_RESTRICT message)
2219 WINPR_ASSERT(message);
2220 return message->frameIdx;
2223 static INLINE BOOL rfx_write_progressive_wb_sync(RFX_CONTEXT* WINPR_RESTRICT rfx,
2226 const UINT32 blockLen = 12;
2230 if (!Stream_EnsureRemainingCapacity(s, blockLen))
2233 Stream_Write_UINT16(s, PROGRESSIVE_WBT_SYNC);
2234 Stream_Write_UINT32(s, blockLen);
2235 Stream_Write_UINT32(s, 0xCACCACCA);
2236 Stream_Write_UINT16(s, 0x0100);
2240 static INLINE BOOL rfx_write_progressive_wb_context(RFX_CONTEXT* WINPR_RESTRICT rfx,
2243 const UINT32 blockLen = 10;
2247 if (!Stream_EnsureRemainingCapacity(s, blockLen))
2250 Stream_Write_UINT16(s, PROGRESSIVE_WBT_CONTEXT);
2251 Stream_Write_UINT32(s, blockLen);
2252 Stream_Write_UINT8(s, 0);
2253 Stream_Write_UINT16(s, 64);
2254 Stream_Write_UINT8(s, 0);
2258 static INLINE BOOL rfx_write_progressive_region(RFX_CONTEXT* WINPR_RESTRICT rfx,
2260 const RFX_MESSAGE* WINPR_RESTRICT msg)
2263 UINT32 blockLen = 18;
2264 UINT32 tilesDataSize = 0;
2265 const size_t start = Stream_GetPosition(s);
2271 blockLen += msg->numRects * 8;
2272 blockLen += msg->numQuant * 5;
2273 tilesDataSize = msg->numTiles * 22UL;
2274 for (UINT16 i = 0; i < msg->numTiles; i++)
2276 const RFX_TILE* tile = msg->tiles[i];
2278 tilesDataSize += tile->YLen + tile->CbLen + tile->CrLen;
2280 blockLen += tilesDataSize;
2282 if (!Stream_EnsureRemainingCapacity(s, blockLen))
2285 Stream_Write_UINT16(s, PROGRESSIVE_WBT_REGION);
2286 Stream_Write_UINT32(s, blockLen);
2287 Stream_Write_UINT8(s, 64);
2288 Stream_Write_UINT16(s, msg->numRects);
2289 WINPR_ASSERT(msg->numQuant <= UINT8_MAX);
2290 Stream_Write_UINT8(s, (UINT8)msg->numQuant);
2291 Stream_Write_UINT8(s, 0);
2292 Stream_Write_UINT8(s, 0);
2293 Stream_Write_UINT16(s, msg->numTiles);
2294 Stream_Write_UINT32(s, tilesDataSize);
2296 for (UINT16 i = 0; i < msg->numRects; i++)
2299 const RFX_RECT* r = &msg->rects[i];
2300 Stream_Write_UINT16(s, r->x);
2301 Stream_Write_UINT16(s, r->y);
2302 Stream_Write_UINT16(s, r->width);
2303 Stream_Write_UINT16(s, r->height);
2314 for (UINT16 i = 0; i < msg->numQuant; i++)
2316 const UINT32* qv = &msg->quantVals[10ULL * i];
2318 Stream_Write_UINT8(s, (UINT8)(qv[0] + (qv[2] << 4)));
2319 Stream_Write_UINT8(s, (UINT8)(qv[1] + (qv[3] << 4)));
2320 Stream_Write_UINT8(s, (UINT8)(qv[5] + (qv[4] << 4)));
2321 Stream_Write_UINT8(s, (UINT8)(qv[6] + (qv[8] << 4)));
2322 Stream_Write_UINT8(s, (UINT8)(qv[7] + (qv[9] << 4)));
2325 for (UINT16 i = 0; i < msg->numTiles; i++)
2327 const RFX_TILE* tile = msg->tiles[i];
2328 if (!rfx_write_progressive_tile_simple(rfx, s, tile))
2332 const size_t end = Stream_GetPosition(s);
2333 const size_t used = end - start;
2334 return (used == blockLen);
2337 static INLINE BOOL rfx_write_progressive_frame_begin(RFX_CONTEXT* WINPR_RESTRICT rfx,
2339 const RFX_MESSAGE* WINPR_RESTRICT msg)
2341 const UINT32 blockLen = 12;
2346 if (!Stream_EnsureRemainingCapacity(s, blockLen))
2349 Stream_Write_UINT16(s, PROGRESSIVE_WBT_FRAME_BEGIN);
2350 Stream_Write_UINT32(s, blockLen);
2351 Stream_Write_UINT32(s, msg->frameIdx);
2352 Stream_Write_UINT16(s, 1);
2357 static INLINE BOOL rfx_write_progressive_frame_end(RFX_CONTEXT* WINPR_RESTRICT rfx,
2360 const UINT32 blockLen = 6;
2364 if (!Stream_EnsureRemainingCapacity(s, blockLen))
2367 Stream_Write_UINT16(s, PROGRESSIVE_WBT_FRAME_END);
2368 Stream_Write_UINT32(s, blockLen);
2373 static INLINE BOOL rfx_write_progressive_tile_simple(RFX_CONTEXT* WINPR_RESTRICT rfx,
2375 const RFX_TILE* WINPR_RESTRICT tile)
2377 UINT32 blockLen = 0;
2382 blockLen = 22 + tile->YLen + tile->CbLen + tile->CrLen;
2383 if (!Stream_EnsureRemainingCapacity(s, blockLen))
2386 Stream_Write_UINT16(s, PROGRESSIVE_WBT_TILE_SIMPLE);
2387 Stream_Write_UINT32(s, blockLen);
2388 Stream_Write_UINT8(s, tile->quantIdxY);
2389 Stream_Write_UINT8(s, tile->quantIdxCb);
2390 Stream_Write_UINT8(s, tile->quantIdxCr);
2391 Stream_Write_UINT16(s, tile->xIdx);
2392 Stream_Write_UINT16(s, tile->yIdx);
2393 Stream_Write_UINT8(s, 0);
2394 Stream_Write_UINT16(s, tile->YLen);
2395 Stream_Write_UINT16(s, tile->CbLen);
2396 Stream_Write_UINT16(s, tile->CrLen);
2397 Stream_Write_UINT16(s, 0);
2398 Stream_Write(s, tile->YData, tile->YLen);
2399 Stream_Write(s, tile->CbData, tile->CbLen);
2400 Stream_Write(s, tile->CrData, tile->CrLen);
2405 const char* rfx_get_progressive_block_type_string(UINT16 blockType)
2409 case PROGRESSIVE_WBT_SYNC:
2410 return "PROGRESSIVE_WBT_SYNC";
2412 case PROGRESSIVE_WBT_FRAME_BEGIN:
2413 return "PROGRESSIVE_WBT_FRAME_BEGIN";
2415 case PROGRESSIVE_WBT_FRAME_END:
2416 return "PROGRESSIVE_WBT_FRAME_END";
2418 case PROGRESSIVE_WBT_CONTEXT:
2419 return "PROGRESSIVE_WBT_CONTEXT";
2421 case PROGRESSIVE_WBT_REGION:
2422 return "PROGRESSIVE_WBT_REGION";
2424 case PROGRESSIVE_WBT_TILE_SIMPLE:
2425 return "PROGRESSIVE_WBT_TILE_SIMPLE";
2427 case PROGRESSIVE_WBT_TILE_FIRST:
2428 return "PROGRESSIVE_WBT_TILE_FIRST";
2430 case PROGRESSIVE_WBT_TILE_UPGRADE:
2431 return "PROGRESSIVE_WBT_TILE_UPGRADE";
2434 return "PROGRESSIVE_WBT_UNKNOWN";
2438 BOOL rfx_write_message_progressive_simple(RFX_CONTEXT* WINPR_RESTRICT context,
2440 const RFX_MESSAGE* WINPR_RESTRICT msg)
2444 WINPR_ASSERT(context);
2446 if (context->mode != RLGR1)
2448 WLog_ERR(TAG,
"error, RLGR1 mode is required!");
2452 if (!rfx_write_progressive_wb_sync(context, s))
2455 if (!rfx_write_progressive_wb_context(context, s))
2458 if (!rfx_write_progressive_frame_begin(context, s, msg))
2461 if (!rfx_write_progressive_region(context, s, msg))
2464 if (!rfx_write_progressive_frame_end(context, s))
This struct contains function pointer to initialize/free objects.