22#include <freerdp/config.h>
28#include <winpr/assert.h>
29#include <winpr/cast.h>
31#include <winpr/tchar.h>
32#include <winpr/sysinfo.h>
33#include <winpr/registry.h>
35#include <freerdp/log.h>
36#include <freerdp/settings.h>
37#include <freerdp/codec/rfx.h>
38#include <freerdp/constants.h>
39#include <freerdp/primitives.h>
40#include <freerdp/codec/region.h>
41#include <freerdp/build-config.h>
43#include "rfx_constants.h"
45#include "rfx_decode.h"
46#include "rfx_encode.h"
47#include "rfx_quantization.h"
51#include "sse/rfx_sse2.h"
52#include "neon/rfx_neon.h"
54#define TAG FREERDP_TAG("codec")
56#define RFX_KEY "Software\\" FREERDP_VENDOR_STRING "\\" FREERDP_PRODUCT_STRING "\\RemoteFX"
70static const UINT32 rfx_default_quantization_values[] = { 6, 6, 6, 6, 7, 7, 8, 8, 8, 9 };
72static inline BOOL rfx_write_progressive_tile_simple(RFX_CONTEXT* WINPR_RESTRICT rfx,
74 const RFX_TILE* WINPR_RESTRICT tile);
76static inline void rfx_profiler_create(RFX_CONTEXT* WINPR_RESTRICT context)
78 if (!context || !context->priv)
80 PROFILER_CREATE(context->priv->prof_rfx_decode_rgb,
"rfx_decode_rgb")
81 PROFILER_CREATE(context->priv->prof_rfx_decode_component, "rfx_decode_component")
82 PROFILER_CREATE(context->priv->prof_rfx_rlgr_decode, "rfx_rlgr_decode")
83 PROFILER_CREATE(context->priv->prof_rfx_differential_decode, "rfx_differential_decode")
84 PROFILER_CREATE(context->priv->prof_rfx_quantization_decode, "rfx_quantization_decode")
85 PROFILER_CREATE(context->priv->prof_rfx_dwt_2d_decode, "rfx_dwt_2d_decode")
86 PROFILER_CREATE(context->priv->prof_rfx_ycbcr_to_rgb, "prims->yCbCrToRGB")
87 PROFILER_CREATE(context->priv->prof_rfx_encode_rgb, "rfx_encode_rgb")
88 PROFILER_CREATE(context->priv->prof_rfx_encode_component, "rfx_encode_component")
89 PROFILER_CREATE(context->priv->prof_rfx_rlgr_encode, "rfx_rlgr_encode")
90 PROFILER_CREATE(context->priv->prof_rfx_differential_encode, "rfx_differential_encode")
91 PROFILER_CREATE(context->priv->prof_rfx_quantization_encode, "rfx_quantization_encode")
92 PROFILER_CREATE(context->priv->prof_rfx_dwt_2d_encode, "rfx_dwt_2d_encode")
93 PROFILER_CREATE(context->priv->prof_rfx_rgb_to_ycbcr, "prims->RGBToYCbCr")
94 PROFILER_CREATE(context->priv->prof_rfx_encode_format_rgb, "rfx_encode_format_rgb")
97static inline
void rfx_profiler_free(RFX_CONTEXT* WINPR_RESTRICT context)
99 if (!context || !context->priv)
101 PROFILER_FREE(context->priv->prof_rfx_decode_rgb)
102 PROFILER_FREE(context->priv->prof_rfx_decode_component)
103 PROFILER_FREE(context->priv->prof_rfx_rlgr_decode)
104 PROFILER_FREE(context->priv->prof_rfx_differential_decode)
105 PROFILER_FREE(context->priv->prof_rfx_quantization_decode)
106 PROFILER_FREE(context->priv->prof_rfx_dwt_2d_decode)
107 PROFILER_FREE(context->priv->prof_rfx_ycbcr_to_rgb)
108 PROFILER_FREE(context->priv->prof_rfx_encode_rgb)
109 PROFILER_FREE(context->priv->prof_rfx_encode_component)
110 PROFILER_FREE(context->priv->prof_rfx_rlgr_encode)
111 PROFILER_FREE(context->priv->prof_rfx_differential_encode)
112 PROFILER_FREE(context->priv->prof_rfx_quantization_encode)
113 PROFILER_FREE(context->priv->prof_rfx_dwt_2d_encode)
114 PROFILER_FREE(context->priv->prof_rfx_rgb_to_ycbcr)
115 PROFILER_FREE(context->priv->prof_rfx_encode_format_rgb)
118static inline
void rfx_profiler_print(RFX_CONTEXT* WINPR_RESTRICT context)
120 if (!context || !context->priv)
123 PROFILER_PRINT_HEADER
124 PROFILER_PRINT(context->priv->prof_rfx_decode_rgb)
125 PROFILER_PRINT(context->priv->prof_rfx_decode_component)
126 PROFILER_PRINT(context->priv->prof_rfx_rlgr_decode)
127 PROFILER_PRINT(context->priv->prof_rfx_differential_decode)
128 PROFILER_PRINT(context->priv->prof_rfx_quantization_decode)
129 PROFILER_PRINT(context->priv->prof_rfx_dwt_2d_decode)
130 PROFILER_PRINT(context->priv->prof_rfx_ycbcr_to_rgb)
131 PROFILER_PRINT(context->priv->prof_rfx_encode_rgb)
132 PROFILER_PRINT(context->priv->prof_rfx_encode_component)
133 PROFILER_PRINT(context->priv->prof_rfx_rlgr_encode)
134 PROFILER_PRINT(context->priv->prof_rfx_differential_encode)
135 PROFILER_PRINT(context->priv->prof_rfx_quantization_encode)
136 PROFILER_PRINT(context->priv->prof_rfx_dwt_2d_encode)
137 PROFILER_PRINT(context->priv->prof_rfx_rgb_to_ycbcr)
138 PROFILER_PRINT(context->priv->prof_rfx_encode_format_rgb)
139 PROFILER_PRINT_FOOTER
142static inline
void rfx_tile_init(
void* obj)
158static inline void* rfx_decoder_tile_new(
const void* val)
160 const size_t size = 4ULL * 64ULL * 64ULL;
167 if (!(tile->data = (BYTE*)winpr_aligned_malloc(size, 16)))
169 winpr_aligned_free(tile);
172 memset(tile->data, 0xff, size);
173 tile->allocated = TRUE;
177static inline void rfx_decoder_tile_free(
void* obj)
184 winpr_aligned_free(tile->data);
186 winpr_aligned_free(tile);
190static inline void* rfx_encoder_tile_new(
const void* val)
193 return winpr_aligned_calloc(1,
sizeof(
RFX_TILE), 32);
196static inline void rfx_encoder_tile_free(
void* obj)
198 winpr_aligned_free(obj);
201RFX_CONTEXT* rfx_context_new(BOOL encoder)
203 return rfx_context_new_ex(encoder, 0);
206RFX_CONTEXT* rfx_context_new_ex(BOOL encoder, UINT32 ThreadingFlags)
208 RFX_CONTEXT_PRIV* priv = NULL;
209 RFX_CONTEXT* context = (RFX_CONTEXT*)winpr_aligned_calloc(1,
sizeof(RFX_CONTEXT), 32);
214 context->encoder = encoder;
215 context->currentMessage.freeArray = TRUE;
216 context->priv = priv = (RFX_CONTEXT_PRIV*)winpr_aligned_calloc(1,
sizeof(RFX_CONTEXT_PRIV), 32);
221 priv->log = WLog_Get(
"com.freerdp.codec.rfx");
222 WLog_OpenAppender(priv->log);
223 priv->TilePool = ObjectPool_New(TRUE);
229 wObject* pool = ObjectPool_Object(priv->TilePool);
230 pool->fnObjectInit = rfx_tile_init;
232 if (context->encoder)
234 pool->fnObjectNew = rfx_encoder_tile_new;
235 pool->fnObjectFree = rfx_encoder_tile_free;
239 pool->fnObjectNew = rfx_decoder_tile_new;
240 pool->fnObjectFree = rfx_decoder_tile_free;
257 priv->BufferPool = BufferPool_New(TRUE, (8192ULL + 32ULL) * 3ULL, 16);
259 if (!priv->BufferPool)
262 if (!(ThreadingFlags & THREADING_FLAGS_DISABLE_THREADS))
265 priv->UseThreads = TRUE;
268 RegOpenKeyExA(HKEY_LOCAL_MACHINE, RFX_KEY, 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
270 if (status == ERROR_SUCCESS)
274 DWORD dwSize =
sizeof(dwValue);
276 if (RegQueryValueEx(hKey, _T(
"UseThreads"), NULL, &dwType, (BYTE*)&dwValue, &dwSize) ==
278 priv->UseThreads = dwValue ? 1 : 0;
285 priv->UseThreads = FALSE;
288 if (priv->UseThreads)
297 rfx_context_set_pixel_format(context, PIXEL_FORMAT_BGRX32);
299 rfx_profiler_create(context);
301 context->quantization_decode = rfx_quantization_decode;
302 context->quantization_encode = rfx_quantization_encode;
303 context->dwt_2d_decode = rfx_dwt_2d_decode;
304 context->dwt_2d_extrapolate_decode = rfx_dwt_2d_extrapolate_decode;
305 context->dwt_2d_encode = rfx_dwt_2d_encode;
306 context->rlgr_decode = rfx_rlgr_decode;
307 context->rlgr_encode = rfx_rlgr_encode;
308 rfx_init_sse2(context);
309 rfx_init_neon(context);
310 context->state = RFX_STATE_SEND_HEADERS;
311 context->expectedDataBlockType = WBT_FRAME_BEGIN;
314 WINPR_PRAGMA_DIAG_PUSH
315 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
316 rfx_context_free(context);
317 WINPR_PRAGMA_DIAG_POP
321void rfx_context_free(RFX_CONTEXT* context)
323 RFX_CONTEXT_PRIV* priv = NULL;
328 WINPR_ASSERT(NULL != context);
330 priv = context->priv;
331 WINPR_ASSERT(NULL != priv);
332 WINPR_ASSERT(NULL != priv->TilePool);
333 WINPR_ASSERT(NULL != priv->BufferPool);
336 rfx_message_free(context, &context->currentMessage);
337 winpr_aligned_free(context->quants);
338 rfx_profiler_print(context);
339 rfx_profiler_free(context);
343 ObjectPool_Free(priv->TilePool);
344 if (priv->UseThreads)
346 winpr_aligned_free((
void*)priv->workObjects);
347 winpr_aligned_free(priv->tileWorkParams);
351 "WARNING: Profiling results probably unusable with multithreaded RemoteFX codec!");
355 BufferPool_Free(priv->BufferPool);
356 winpr_aligned_free(priv);
358 winpr_aligned_free(context);
361static inline RFX_TILE* rfx_message_get_tile(RFX_MESSAGE* WINPR_RESTRICT message, UINT32 index)
363 WINPR_ASSERT(message);
364 WINPR_ASSERT(message->tiles);
365 WINPR_ASSERT(index < message->numTiles);
366 return message->tiles[index];
369static inline const RFX_RECT* rfx_message_get_rect_const(
const RFX_MESSAGE* WINPR_RESTRICT message,
372 WINPR_ASSERT(message);
373 WINPR_ASSERT(message->rects);
374 WINPR_ASSERT(index < message->numRects);
375 return &message->rects[index];
378static inline RFX_RECT* rfx_message_get_rect(RFX_MESSAGE* WINPR_RESTRICT message, UINT32 index)
380 WINPR_ASSERT(message);
381 WINPR_ASSERT(message->rects);
382 WINPR_ASSERT(index < message->numRects);
383 return &message->rects[index];
386void rfx_context_set_pixel_format(RFX_CONTEXT* WINPR_RESTRICT context, UINT32 pixel_format)
388 WINPR_ASSERT(context);
389 context->pixel_format = pixel_format;
390 const UINT32 bpp = FreeRDPGetBitsPerPixel(pixel_format);
391 context->bits_per_pixel = WINPR_ASSERTING_INT_CAST(UINT8, bpp);
394UINT32 rfx_context_get_pixel_format(RFX_CONTEXT* WINPR_RESTRICT context)
396 WINPR_ASSERT(context);
397 return context->pixel_format;
400void rfx_context_set_palette(RFX_CONTEXT* WINPR_RESTRICT context,
401 const BYTE* WINPR_RESTRICT palette)
403 WINPR_ASSERT(context);
404 context->palette = palette;
407const BYTE* rfx_context_get_palette(RFX_CONTEXT* WINPR_RESTRICT context)
409 WINPR_ASSERT(context);
410 return context->palette;
413BOOL rfx_context_reset(RFX_CONTEXT* WINPR_RESTRICT context, UINT32 width, UINT32 height)
418 context->width = WINPR_ASSERTING_INT_CAST(UINT16, width);
419 context->height = WINPR_ASSERTING_INT_CAST(UINT16, height);
420 context->state = RFX_STATE_SEND_HEADERS;
421 context->expectedDataBlockType = WBT_FRAME_BEGIN;
422 context->frameIdx = 0;
426static inline BOOL rfx_process_message_sync(RFX_CONTEXT* WINPR_RESTRICT context,
431 WINPR_ASSERT(context);
432 WINPR_ASSERT(context->priv);
433 context->decodedHeaderBlocks &= (uint32_t)~RFX_DECODED_SYNC;
436 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 6))
439 Stream_Read_UINT32(s, magic);
440 if (magic != WF_MAGIC)
442 WLog_Print(context->priv->log, WLOG_ERROR,
"invalid magic number 0x%08" PRIX32
"", magic);
446 Stream_Read_UINT16(s, context->version);
447 if (context->version != WF_VERSION_1_0)
449 WLog_Print(context->priv->log, WLOG_ERROR,
"invalid version number 0x%08" PRIX32
"",
454 WLog_Print(context->priv->log, WLOG_DEBUG,
"version 0x%08" PRIX32
"", context->version);
455 context->decodedHeaderBlocks |= RFX_DECODED_SYNC;
459static inline BOOL rfx_process_message_codec_versions(RFX_CONTEXT* WINPR_RESTRICT context,
464 WINPR_ASSERT(context);
465 WINPR_ASSERT(context->priv);
466 context->decodedHeaderBlocks &= (uint32_t)~RFX_DECODED_VERSIONS;
468 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 4))
471 Stream_Read_UINT8(s, numCodecs);
472 Stream_Read_UINT8(s, context->codec_id);
474 s, context->codec_version);
478 WLog_Print(context->priv->log, WLOG_ERROR,
"numCodes is 0x%02" PRIX8
" (must be 0x01)",
483 if (context->codec_id != 0x01)
485 WLog_Print(context->priv->log, WLOG_ERROR,
"invalid codec id (0x%02" PRIX32
")",
490 if (context->codec_version != WF_VERSION_1_0)
492 WLog_Print(context->priv->log, WLOG_ERROR,
"invalid codec version (0x%08" PRIX32
")",
493 context->codec_version);
497 WLog_Print(context->priv->log, WLOG_DEBUG,
"id %" PRIu32
" version 0x%" PRIX32
".",
498 context->codec_id, context->codec_version);
499 context->decodedHeaderBlocks |= RFX_DECODED_VERSIONS;
503static inline BOOL rfx_process_message_channels(RFX_CONTEXT* WINPR_RESTRICT context,
507 BYTE numChannels = 0;
509 WINPR_ASSERT(context);
510 WINPR_ASSERT(context->priv);
511 context->decodedHeaderBlocks &= (uint32_t)~RFX_DECODED_CHANNELS;
513 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 1))
516 Stream_Read_UINT8(s, numChannels);
523 WLog_Print(context->priv->log, WLOG_ERROR,
"no channels announced");
527 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(context->priv->log, s, numChannels, 5ull))
531 Stream_Read_UINT8(s, channelId);
533 if (channelId != 0x00)
535 WLog_Print(context->priv->log, WLOG_ERROR,
"channelId:0x%02" PRIX8
", expected:0x00",
540 Stream_Read_UINT16(s, context->width);
541 Stream_Read_UINT16(s, context->height);
543 if (!context->width || !context->height)
545 WLog_Print(context->priv->log, WLOG_ERROR,
546 "invalid channel with/height: %" PRIu16
"x%" PRIu16
"", context->width,
552 Stream_Seek(s, 5ULL * (numChannels - 1));
553 WLog_Print(context->priv->log, WLOG_DEBUG,
554 "numChannels %" PRIu8
" id %" PRIu8
", %" PRIu16
"x%" PRIu16
".", numChannels,
555 channelId, context->width, context->height);
556 context->decodedHeaderBlocks |= RFX_DECODED_CHANNELS;
560static inline BOOL rfx_process_message_context(RFX_CONTEXT* WINPR_RESTRICT context,
565 UINT16 properties = 0;
567 WINPR_ASSERT(context);
568 WINPR_ASSERT(context->priv);
569 context->decodedHeaderBlocks &= (uint32_t)~RFX_DECODED_CONTEXT;
571 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 5))
574 Stream_Read_UINT8(s, ctxId);
575 Stream_Read_UINT16(s, tileSize);
576 Stream_Read_UINT16(s, properties);
577 WLog_Print(context->priv->log, WLOG_DEBUG,
578 "ctxId %" PRIu8
" tileSize %" PRIu16
" properties 0x%04" PRIX16
".", ctxId, tileSize,
580 context->properties = properties;
581 context->flags = (properties & 0x0007);
583 if (context->flags == CODEC_MODE)
585 WLog_Print(context->priv->log, WLOG_DEBUG,
"codec is in image mode.");
589 WLog_Print(context->priv->log, WLOG_DEBUG,
"codec is in video mode.");
592 switch ((properties & 0x1E00) >> 9)
594 case CLW_ENTROPY_RLGR1:
595 context->mode = RLGR1;
596 WLog_Print(context->priv->log, WLOG_DEBUG,
"RLGR1.");
599 case CLW_ENTROPY_RLGR3:
600 context->mode = RLGR3;
601 WLog_Print(context->priv->log, WLOG_DEBUG,
"RLGR3.");
605 WLog_Print(context->priv->log, WLOG_ERROR,
"unknown RLGR algorithm.");
609 context->decodedHeaderBlocks |= RFX_DECODED_CONTEXT;
613static inline BOOL rfx_process_message_frame_begin(
614 RFX_CONTEXT* WINPR_RESTRICT context, WINPR_ATTR_UNUSED RFX_MESSAGE* WINPR_RESTRICT message,
615 wStream* WINPR_RESTRICT s, UINT16* WINPR_RESTRICT pExpectedBlockType)
618 UINT16 numRegions = 0;
620 WINPR_ASSERT(context);
621 WINPR_ASSERT(context->priv);
622 WINPR_ASSERT(message);
623 WINPR_ASSERT(pExpectedBlockType);
625 if (*pExpectedBlockType != WBT_FRAME_BEGIN)
627 WLog_Print(context->priv->log, WLOG_ERROR,
"message unexpected wants WBT_FRAME_BEGIN");
631 *pExpectedBlockType = WBT_REGION;
633 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 6))
638 Stream_Read_UINT16(s, numRegions);
639 WLog_Print(context->priv->log, WLOG_DEBUG,
640 "RFX_FRAME_BEGIN: frameIdx: %" PRIu32
" numRegions: %" PRIu16
"", frameIdx,
645static inline BOOL rfx_process_message_frame_end(
646 RFX_CONTEXT* WINPR_RESTRICT context, WINPR_ATTR_UNUSED RFX_MESSAGE* WINPR_RESTRICT message,
647 WINPR_ATTR_UNUSED
wStream* WINPR_RESTRICT s, UINT16* WINPR_RESTRICT pExpectedBlockType)
649 WINPR_ASSERT(context);
650 WINPR_ASSERT(context->priv);
651 WINPR_ASSERT(message);
653 WINPR_ASSERT(pExpectedBlockType);
655 if (*pExpectedBlockType != WBT_FRAME_END)
657 WLog_Print(context->priv->log, WLOG_ERROR,
"message unexpected, wants WBT_FRAME_END");
661 *pExpectedBlockType = WBT_FRAME_BEGIN;
662 WLog_Print(context->priv->log, WLOG_DEBUG,
"RFX_FRAME_END");
666static inline BOOL rfx_resize_rects(RFX_MESSAGE* WINPR_RESTRICT message)
668 WINPR_ASSERT(message);
671 winpr_aligned_recalloc(message->rects, message->numRects,
sizeof(
RFX_RECT), 32);
674 message->rects = tmpRects;
678static inline BOOL rfx_process_message_region(RFX_CONTEXT* WINPR_RESTRICT context,
679 RFX_MESSAGE* WINPR_RESTRICT message,
681 UINT16* WINPR_RESTRICT pExpectedBlockType)
683 UINT16 regionType = 0;
684 UINT16 numTileSets = 0;
686 WINPR_ASSERT(context);
687 WINPR_ASSERT(context->priv);
688 WINPR_ASSERT(message);
689 WINPR_ASSERT(pExpectedBlockType);
691 if (*pExpectedBlockType != WBT_REGION)
693 WLog_Print(context->priv->log, WLOG_ERROR,
"message unexpected wants WBT_REGION");
697 *pExpectedBlockType = WBT_EXTENSION;
699 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 3))
702 Stream_Seek_UINT8(s);
703 Stream_Read_UINT16(s, message->numRects);
705 if (message->numRects < 1)
713 message->numRects = 1;
714 if (!rfx_resize_rects(message))
717 message->rects->x = 0;
718 message->rects->y = 0;
719 message->rects->width = context->width;
720 message->rects->height = context->height;
724 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(context->priv->log, s, message->numRects, 8ull))
727 if (!rfx_resize_rects(message))
731 for (UINT16 i = 0; i < message->numRects; i++)
733 RFX_RECT* rect = rfx_message_get_rect(message, i);
735 Stream_Read_UINT16(s, rect->x);
736 Stream_Read_UINT16(s, rect->y);
737 Stream_Read_UINT16(s, rect->width);
738 Stream_Read_UINT16(s, rect->height);
739 WLog_Print(context->priv->log, WLOG_DEBUG,
740 "rect %" PRIu16
" (x,y=%" PRIu16
",%" PRIu16
" w,h=%" PRIu16
" %" PRIu16
").", i,
741 rect->x, rect->y, rect->width, rect->height);
744 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 4))
747 Stream_Read_UINT16(s, regionType);
748 Stream_Read_UINT16(s, numTileSets);
750 if (regionType != CBT_REGION)
752 WLog_Print(context->priv->log, WLOG_ERROR,
"invalid region type 0x%04" PRIX16
"",
757 if (numTileSets != 0x0001)
759 WLog_Print(context->priv->log, WLOG_ERROR,
"invalid number of tilesets (%" PRIu16
")",
770 RFX_CONTEXT* context;
771} RFX_TILE_PROCESS_WORK_PARAM;
773static inline void CALLBACK
774rfx_process_message_tile_work_callback(WINPR_ATTR_UNUSED PTP_CALLBACK_INSTANCE instance,
775 void* context, WINPR_ATTR_UNUSED PTP_WORK work)
777 RFX_TILE_PROCESS_WORK_PARAM* param = (RFX_TILE_PROCESS_WORK_PARAM*)context;
779 rfx_decode_rgb(param->context, param->tile, param->tile->data, 64 * 4);
782static inline BOOL rfx_allocate_tiles(RFX_MESSAGE* WINPR_RESTRICT message,
size_t count,
785 WINPR_ASSERT(message);
788 (
RFX_TILE**)winpr_aligned_recalloc((
void*)message->tiles, count,
sizeof(
RFX_TILE*), 32);
789 if (!tmpTiles && (count != 0))
792 message->tiles = tmpTiles;
794 message->numTiles = WINPR_ASSERTING_INT_CAST(UINT16, count);
797 WINPR_ASSERT(message->numTiles <= count);
799 message->allocatedTiles = count;
804static inline BOOL rfx_process_message_tileset(RFX_CONTEXT* WINPR_RESTRICT context,
805 RFX_MESSAGE* WINPR_RESTRICT message,
807 UINT16* WINPR_RESTRICT pExpectedBlockType)
810 size_t close_cnt = 0;
813 UINT32* quants = NULL;
817 UINT32 blockType = 0;
818 UINT32 tilesDataSize = 0;
819 PTP_WORK* work_objects = NULL;
820 RFX_TILE_PROCESS_WORK_PARAM* params = NULL;
823 WINPR_ASSERT(context);
824 WINPR_ASSERT(context->priv);
825 WINPR_ASSERT(message);
826 WINPR_ASSERT(pExpectedBlockType);
828 if (*pExpectedBlockType != WBT_EXTENSION)
830 WLog_Print(context->priv->log, WLOG_ERROR,
"message unexpected wants a tileset");
834 *pExpectedBlockType = WBT_FRAME_END;
836 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 14))
839 Stream_Read_UINT16(s, subtype);
840 if (subtype != CBT_TILESET)
842 WLog_Print(context->priv->log, WLOG_ERROR,
"invalid subtype, expected CBT_TILESET.");
846 Stream_Seek_UINT16(s);
847 Stream_Seek_UINT16(s);
848 Stream_Read_UINT8(s, context->numQuant);
849 Stream_Seek_UINT8(s);
851 if (context->numQuant < 1)
853 WLog_Print(context->priv->log, WLOG_ERROR,
"no quantization value.");
857 Stream_Read_UINT16(s, numTiles);
864 Stream_Read_UINT32(s, tilesDataSize);
867 winpr_aligned_recalloc(context->quants, context->numQuant, 10 *
sizeof(UINT32), 32)))
870 quants = context->quants = (UINT32*)pmem;
873 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(context->priv->log, s, context->numQuant, 5ull))
876 for (
size_t i = 0; i < context->numQuant; i++)
879 Stream_Read_UINT8(s, quant);
880 *quants++ = (quant & 0x0F);
881 *quants++ = (quant >> 4);
882 Stream_Read_UINT8(s, quant);
883 *quants++ = (quant & 0x0F);
884 *quants++ = (quant >> 4);
885 Stream_Read_UINT8(s, quant);
886 *quants++ = (quant & 0x0F);
887 *quants++ = (quant >> 4);
888 Stream_Read_UINT8(s, quant);
889 *quants++ = (quant & 0x0F);
890 *quants++ = (quant >> 4);
891 Stream_Read_UINT8(s, quant);
892 *quants++ = (quant & 0x0F);
893 *quants++ = (quant >> 4);
894 WLog_Print(context->priv->log, WLOG_DEBUG,
895 "quant %" PRIuz
" (%" PRIu32
" %" PRIu32
" %" PRIu32
" %" PRIu32
" %" PRIu32
896 " %" PRIu32
" %" PRIu32
" %" PRIu32
" %" PRIu32
" %" PRIu32
").",
897 i, context->quants[i * 10], context->quants[i * 10 + 1],
898 context->quants[i * 10 + 2], context->quants[i * 10 + 3],
899 context->quants[i * 10 + 4], context->quants[i * 10 + 5],
900 context->quants[i * 10 + 6], context->quants[i * 10 + 7],
901 context->quants[i * 10 + 8], context->quants[i * 10 + 9]);
904 for (
size_t i = 0; i < message->numTiles; i++)
906 ObjectPool_Return(context->priv->TilePool, message->tiles[i]);
907 message->tiles[i] = NULL;
910 if (!rfx_allocate_tiles(message, numTiles, FALSE))
913 if (context->priv->UseThreads)
915 work_objects = (PTP_WORK*)winpr_aligned_calloc(message->numTiles,
sizeof(PTP_WORK), 32);
916 params = (RFX_TILE_PROCESS_WORK_PARAM*)winpr_aligned_recalloc(
917 NULL, message->numTiles,
sizeof(RFX_TILE_PROCESS_WORK_PARAM), 32);
921 winpr_aligned_free(params);
927 winpr_aligned_free((
void*)work_objects);
936 if (Stream_GetRemainingLength(s) >= tilesDataSize)
939 for (
size_t i = 0; i < message->numTiles; i++)
944 if (!(tile = (
RFX_TILE*)ObjectPool_Take(context->priv->TilePool)))
946 WLog_Print(context->priv->log, WLOG_ERROR,
947 "RfxMessageTileSet failed to get tile from object pool");
952 message->tiles[i] = tile;
955 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 6))
957 WLog_Print(context->priv->log, WLOG_ERROR,
958 "RfxMessageTileSet packet too small to read tile %" PRIuz
"/%" PRIu16
"",
959 i, message->numTiles);
964 sub = Stream_StaticInit(&subBuffer, Stream_Pointer(s), Stream_GetRemainingLength(s));
967 Stream_Read_UINT32(sub, blockLen);
969 if (!Stream_SafeSeek(s, blockLen))
974 if ((blockLen < 6 + 13) ||
975 (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, sub, blockLen - 6)))
977 WLog_Print(context->priv->log, WLOG_ERROR,
978 "RfxMessageTileSet not enough bytes to read tile %" PRIuz
"/%" PRIu16
979 " with blocklen=%" PRIu32
"",
980 i, message->numTiles, blockLen);
985 if (blockType != CBT_TILE)
987 WLog_Print(context->priv->log, WLOG_ERROR,
988 "unknown block type 0x%" PRIX32
", expected CBT_TILE (0xCAC3).",
994 Stream_Read_UINT8(sub, tile->quantIdxY);
995 Stream_Read_UINT8(sub, tile->quantIdxCb);
996 Stream_Read_UINT8(sub, tile->quantIdxCr);
997 if (tile->quantIdxY >= context->numQuant)
999 WLog_Print(context->priv->log, WLOG_ERROR,
1000 "quantIdxY %" PRIu8
" >= numQuant %" PRIu8, tile->quantIdxY,
1005 if (tile->quantIdxCb >= context->numQuant)
1007 WLog_Print(context->priv->log, WLOG_ERROR,
1008 "quantIdxCb %" PRIu8
" >= numQuant %" PRIu8, tile->quantIdxCb,
1013 if (tile->quantIdxCr >= context->numQuant)
1015 WLog_Print(context->priv->log, WLOG_ERROR,
1016 "quantIdxCr %" PRIu8
" >= numQuant %" PRIu8, tile->quantIdxCr,
1022 Stream_Read_UINT16(sub, tile->xIdx);
1023 Stream_Read_UINT16(sub, tile->yIdx);
1024 Stream_Read_UINT16(sub, tile->YLen);
1025 Stream_Read_UINT16(sub, tile->CbLen);
1026 Stream_Read_UINT16(sub, tile->CrLen);
1027 Stream_GetPointer(sub, tile->YData);
1028 if (!Stream_SafeSeek(sub, tile->YLen))
1033 Stream_GetPointer(sub, tile->CbData);
1034 if (!Stream_SafeSeek(sub, tile->CbLen))
1039 Stream_GetPointer(sub, tile->CrData);
1040 if (!Stream_SafeSeek(sub, tile->CrLen))
1045 tile->x = tile->xIdx * 64;
1046 tile->y = tile->yIdx * 64;
1048 if (context->priv->UseThreads)
1056 params[i].context = context;
1057 params[i].tile = message->tiles[i];
1059 if (!(work_objects[i] = CreateThreadpoolWork(rfx_process_message_tile_work_callback,
1060 (
void*)¶ms[i], NULL)))
1062 WLog_Print(context->priv->log, WLOG_ERROR,
"CreateThreadpoolWork failed.");
1067 SubmitThreadpoolWork(work_objects[i]);
1072 rfx_decode_rgb(context, tile, tile->data, 64 * 4);
1077 if (context->priv->UseThreads)
1079 for (
size_t i = 0; i < close_cnt; i++)
1081 WaitForThreadpoolWorkCallbacks(work_objects[i], FALSE);
1082 CloseThreadpoolWork(work_objects[i]);
1086 winpr_aligned_free((
void*)work_objects);
1087 winpr_aligned_free(params);
1089 for (
size_t i = 0; i < message->numTiles; i++)
1091 if (!(tile = message->tiles[i]))
1094 tile->YLen = tile->CbLen = tile->CrLen = 0;
1095 tile->YData = tile->CbData = tile->CrData = NULL;
1101BOOL rfx_process_message(RFX_CONTEXT* WINPR_RESTRICT context,
const BYTE* WINPR_RESTRICT data,
1102 UINT32 length, UINT32 left, UINT32 top, BYTE* WINPR_RESTRICT dst,
1103 UINT32 dstFormat, UINT32 dstStride, UINT32 dstHeight,
1104 REGION16* WINPR_RESTRICT invalidRegion)
1110 if (!context || !data || !length)
1113 WINPR_ASSERT(context->priv);
1114 RFX_MESSAGE* message = &context->currentMessage;
1116 wStream* s = Stream_StaticConstInit(&inStream, data, length);
1118 while (ok && Stream_GetRemainingLength(s) > 6)
1120 wStream subStreamBuffer = { 0 };
1121 size_t extraBlockLen = 0;
1122 UINT32 blockLen = 0;
1123 UINT32 blockType = 0;
1126 Stream_Read_UINT16(s, blockType);
1127 Stream_Read_UINT32(s, blockLen);
1128 WLog_Print(context->priv->log, WLOG_DEBUG,
"blockType 0x%" PRIX32
" blockLen %" PRIu32
"",
1129 blockType, blockLen);
1133 WLog_Print(context->priv->log, WLOG_ERROR,
"blockLen too small(%" PRIu32
")", blockLen);
1137 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, blockLen - 6))
1140 if (blockType > WBT_CONTEXT && context->decodedHeaderBlocks != RFX_DECODED_HEADERS)
1142 WLog_Print(context->priv->log, WLOG_ERROR,
"incomplete header blocks processing");
1146 if (blockType >= WBT_CONTEXT && blockType <= WBT_EXTENSION)
1150 UINT8 channelId = 0;
1152 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 2))
1156 Stream_Read_UINT8(s, codecId);
1157 Stream_Read_UINT8(s, channelId);
1159 if (codecId != 0x01)
1161 WLog_Print(context->priv->log, WLOG_ERROR,
"invalid codecId 0x%02" PRIX8
"",
1166 if (blockType == WBT_CONTEXT)
1169 if (channelId != 0xFF)
1171 WLog_Print(context->priv->log, WLOG_ERROR,
1172 "invalid channelId 0x%02" PRIX8
" for blockType 0x%08" PRIX32
"",
1173 channelId, blockType);
1180 if (channelId != 0x00)
1182 WLog_Print(context->priv->log, WLOG_ERROR,
1183 "invalid channelId 0x%02" PRIX8
" for blockType WBT_CONTEXT",
1190 const size_t blockLenNoHeader = blockLen - 6;
1191 if (blockLenNoHeader < extraBlockLen)
1193 WLog_Print(context->priv->log, WLOG_ERROR,
1194 "blockLen too small(%" PRIu32
"), must be >= 6 + %" PRIuz, blockLen,
1199 const size_t subStreamLen = blockLenNoHeader - extraBlockLen;
1200 wStream* subStream = Stream_StaticInit(&subStreamBuffer, Stream_Pointer(s), subStreamLen);
1201 Stream_Seek(s, subStreamLen);
1210 ok = rfx_process_message_sync(context, subStream);
1214 ok = rfx_process_message_context(context, subStream);
1217 case WBT_CODEC_VERSIONS:
1218 ok = rfx_process_message_codec_versions(context, subStream);
1222 ok = rfx_process_message_channels(context, subStream);
1232 case WBT_FRAME_BEGIN:
1233 ok = rfx_process_message_frame_begin(context, message, subStream,
1234 &context->expectedDataBlockType);
1238 ok = rfx_process_message_region(context, message, subStream,
1239 &context->expectedDataBlockType);
1243 ok = rfx_process_message_tileset(context, message, subStream,
1244 &context->expectedDataBlockType);
1248 ok = rfx_process_message_frame_end(context, message, subStream,
1249 &context->expectedDataBlockType);
1253 WLog_Print(context->priv->log, WLOG_ERROR,
"unknown blockType 0x%" PRIX32
"",
1261 UINT32 nbUpdateRects = 0;
1264 const DWORD formatSize = FreeRDPGetBytesPerPixel(context->pixel_format);
1265 const UINT32 dstWidth = dstStride / FreeRDPGetBytesPerPixel(dstFormat);
1266 region16_init(&clippingRects);
1268 WINPR_ASSERT(dstWidth <= UINT16_MAX);
1269 WINPR_ASSERT(dstHeight <= UINT16_MAX);
1270 for (UINT32 i = 0; i < message->numRects; i++)
1273 const RFX_RECT* rect = &(message->rects[i]);
1275 WINPR_ASSERT(left + rect->x <= UINT16_MAX);
1276 WINPR_ASSERT(top + rect->y <= UINT16_MAX);
1277 WINPR_ASSERT(clippingRect.left + rect->width <= UINT16_MAX);
1278 WINPR_ASSERT(clippingRect.top + rect->height <= UINT16_MAX);
1280 clippingRect.left = WINPR_ASSERTING_INT_CAST(UINT16, MIN(left + rect->x, dstWidth));
1281 clippingRect.top = WINPR_ASSERTING_INT_CAST(UINT16, MIN(top + rect->y, dstHeight));
1283 const UINT32 rw = 1UL * clippingRect.left + rect->width;
1284 const UINT32 rh = 1UL * clippingRect.top + rect->height;
1285 const uint16_t right = WINPR_ASSERTING_INT_CAST(UINT16, MIN(rw, dstWidth));
1286 const uint16_t bottom = WINPR_ASSERTING_INT_CAST(UINT16, MIN(rh, dstHeight));
1287 clippingRect.right = right;
1288 clippingRect.bottom = bottom;
1289 region16_union_rect(&clippingRects, &clippingRects, &clippingRect);
1292 for (UINT32 i = 0; i < message->numTiles; i++)
1295 const RFX_TILE* tile = rfx_message_get_tile(message, i);
1297 WINPR_ASSERT(left + tile->x <= UINT16_MAX);
1298 WINPR_ASSERT(top + tile->y <= UINT16_MAX);
1300 updateRect.left = (UINT16)left + tile->x;
1301 updateRect.top = (UINT16)top + tile->y;
1302 updateRect.right = updateRect.left + 64;
1303 updateRect.bottom = updateRect.top + 64;
1304 region16_init(&updateRegion);
1305 region16_intersect_rect(&updateRegion, &clippingRects, &updateRect);
1306 updateRects = region16_rects(&updateRegion, &nbUpdateRects);
1308 for (UINT32 j = 0; j < nbUpdateRects; j++)
1311 const UINT32 stride = 64 * formatSize;
1312 const UINT32 nXDst = cur->left;
1313 const UINT32 nYDst = cur->top;
1314 const UINT32 nXSrc = nXDst - updateRect.left;
1315 const UINT32 nYSrc = nYDst - updateRect.top;
1316 const UINT32 nWidth = cur->right - cur->left;
1317 const UINT32 nHeight = cur->bottom - cur->top;
1319 if (!freerdp_image_copy_no_overlap(dst, dstFormat, dstStride, nXDst, nYDst, nWidth,
1320 nHeight, tile->data, context->pixel_format,
1321 stride, nXSrc, nYSrc, NULL, FREERDP_FLIP_NONE))
1323 region16_uninit(&updateRegion);
1324 region16_uninit(&clippingRects);
1325 WLog_Print(context->priv->log, WLOG_ERROR,
1326 "nbUpdateRectx[%" PRIu32
" (%" PRIu32
")] freerdp_image_copy failed",
1332 region16_union_rect(invalidRegion, invalidRegion, cur);
1335 region16_uninit(&updateRegion);
1338 region16_uninit(&clippingRects);
1343 rfx_message_free(context, message);
1344 context->currentMessage.freeArray = TRUE;
1347 WLog_Print(context->priv->log, WLOG_ERROR,
"failed");
1351const UINT32* rfx_message_get_quants(
const RFX_MESSAGE* WINPR_RESTRICT message,
1352 UINT16* WINPR_RESTRICT numQuantVals)
1354 WINPR_ASSERT(message);
1356 *numQuantVals = message->numQuant;
1357 return message->quantVals;
1360const RFX_TILE** rfx_message_get_tiles(
const RFX_MESSAGE* WINPR_RESTRICT message,
1361 UINT16* WINPR_RESTRICT numTiles)
1363 WINPR_ASSERT(message);
1365 *numTiles = message->numTiles;
1372 cnv.pp = message->tiles;
1376UINT16 rfx_message_get_tile_count(
const RFX_MESSAGE* WINPR_RESTRICT message)
1378 WINPR_ASSERT(message);
1379 return message->numTiles;
1382const RFX_RECT* rfx_message_get_rects(
const RFX_MESSAGE* WINPR_RESTRICT message,
1383 UINT16* WINPR_RESTRICT numRects)
1385 WINPR_ASSERT(message);
1387 *numRects = message->numRects;
1388 return message->rects;
1391UINT16 rfx_message_get_rect_count(
const RFX_MESSAGE* WINPR_RESTRICT message)
1393 WINPR_ASSERT(message);
1394 return message->numRects;
1397void rfx_message_free(RFX_CONTEXT* WINPR_RESTRICT context, RFX_MESSAGE* WINPR_RESTRICT message)
1402 winpr_aligned_free(message->rects);
1406 for (
size_t i = 0; i < message->numTiles; i++)
1408 RFX_TILE* tile = message->tiles[i];
1412 if (tile->YCbCrData)
1414 BufferPool_Return(context->priv->BufferPool, tile->YCbCrData);
1415 tile->YCbCrData = NULL;
1418 ObjectPool_Return(context->priv->TilePool, (
void*)tile);
1421 rfx_allocate_tiles(message, 0, FALSE);
1424 const BOOL freeArray = message->freeArray;
1425 const RFX_MESSAGE empty = { 0 };
1429 winpr_aligned_free(message);
1432static inline void rfx_update_context_properties(RFX_CONTEXT* WINPR_RESTRICT context)
1434 UINT16 properties = 0;
1436 WINPR_ASSERT(context);
1439 properties |= (context->flags << 1);
1440 properties |= (COL_CONV_ICT << 4);
1441 properties |= (CLW_XFORM_DWT_53_A << 6);
1442 properties |= ((context->mode == RLGR1 ? CLW_ENTROPY_RLGR1 : CLW_ENTROPY_RLGR3) << 10);
1443 properties |= (SCALAR_QUANTIZATION << 14);
1444 context->properties = properties;
1448rfx_write_message_sync(WINPR_ATTR_UNUSED
const RFX_CONTEXT* WINPR_RESTRICT context,
1449 WINPR_ATTR_UNUSED
wStream* WINPR_RESTRICT s)
1451 WINPR_ASSERT(context);
1453 Stream_Write_UINT16(s, WBT_SYNC);
1454 Stream_Write_UINT32(s, 12);
1455 Stream_Write_UINT32(s, WF_MAGIC);
1456 Stream_Write_UINT16(s, WF_VERSION_1_0);
1460rfx_write_message_codec_versions(WINPR_ATTR_UNUSED
const RFX_CONTEXT* WINPR_RESTRICT context,
1463 WINPR_ASSERT(context);
1465 Stream_Write_UINT16(s, WBT_CODEC_VERSIONS);
1466 Stream_Write_UINT32(s, 10);
1467 Stream_Write_UINT8(s, 1);
1468 Stream_Write_UINT8(s, 1);
1469 Stream_Write_UINT16(s, WF_VERSION_1_0);
1472static inline void rfx_write_message_channels(
const RFX_CONTEXT* WINPR_RESTRICT context,
1475 WINPR_ASSERT(context);
1477 Stream_Write_UINT16(s, WBT_CHANNELS);
1478 Stream_Write_UINT32(s, 12);
1479 Stream_Write_UINT8(s, 1);
1480 Stream_Write_UINT8(s, 0);
1481 Stream_Write_UINT16(s, context->width);
1482 Stream_Write_UINT16(s, context->height);
1485static inline void rfx_write_message_context(RFX_CONTEXT* WINPR_RESTRICT context,
1488 UINT16 properties = 0;
1489 WINPR_ASSERT(context);
1491 Stream_Write_UINT16(s, WBT_CONTEXT);
1492 Stream_Write_UINT32(s, 13);
1493 Stream_Write_UINT8(s, 1);
1494 Stream_Write_UINT8(s, 0xFF);
1495 Stream_Write_UINT8(s, 0);
1496 Stream_Write_UINT16(s, CT_TILE_64x64);
1498 properties = context->flags;
1499 properties |= (COL_CONV_ICT << 3);
1500 properties |= (CLW_XFORM_DWT_53_A << 5);
1501 properties |= ((context->mode == RLGR1 ? CLW_ENTROPY_RLGR1 : CLW_ENTROPY_RLGR3) << 9);
1502 properties |= (SCALAR_QUANTIZATION << 13);
1503 Stream_Write_UINT16(s, properties);
1504 rfx_update_context_properties(context);
1507static inline BOOL rfx_compose_message_header(RFX_CONTEXT* WINPR_RESTRICT context,
1510 WINPR_ASSERT(context);
1511 if (!Stream_EnsureRemainingCapacity(s, 12 + 10 + 12 + 13))
1514 rfx_write_message_sync(context, s);
1515 rfx_write_message_context(context, s);
1516 rfx_write_message_codec_versions(context, s);
1517 rfx_write_message_channels(context, s);
1521static inline size_t rfx_tile_length(
const RFX_TILE* WINPR_RESTRICT tile)
1524 return 19ull + tile->YLen + tile->CbLen + tile->CrLen;
1527static inline BOOL rfx_write_tile(
wStream* WINPR_RESTRICT s,
const RFX_TILE* WINPR_RESTRICT tile)
1529 const size_t blockLen = rfx_tile_length(tile);
1530 if (blockLen > UINT32_MAX)
1532 if (!Stream_EnsureRemainingCapacity(s, blockLen))
1535 Stream_Write_UINT16(s, CBT_TILE);
1536 Stream_Write_UINT32(s, (UINT32)blockLen);
1537 Stream_Write_UINT8(s, tile->quantIdxY);
1538 Stream_Write_UINT8(s, tile->quantIdxCb);
1539 Stream_Write_UINT8(s, tile->quantIdxCr);
1540 Stream_Write_UINT16(s, tile->xIdx);
1541 Stream_Write_UINT16(s, tile->yIdx);
1542 Stream_Write_UINT16(s, tile->YLen);
1543 Stream_Write_UINT16(s, tile->CbLen);
1544 Stream_Write_UINT16(s, tile->CrLen);
1545 Stream_Write(s, tile->YData, tile->YLen);
1546 Stream_Write(s, tile->CbData, tile->CbLen);
1547 Stream_Write(s, tile->CrData, tile->CrLen);
1551struct S_RFX_TILE_COMPOSE_WORK_PARAM
1554 RFX_CONTEXT* context;
1557static inline void CALLBACK
1558rfx_compose_message_tile_work_callback(WINPR_ATTR_UNUSED PTP_CALLBACK_INSTANCE instance,
1559 void* context, WINPR_ATTR_UNUSED PTP_WORK work)
1561 RFX_TILE_COMPOSE_WORK_PARAM* param = (RFX_TILE_COMPOSE_WORK_PARAM*)context;
1562 WINPR_ASSERT(param);
1563 rfx_encode_rgb(param->context, param->tile);
1566static inline BOOL computeRegion(
const RFX_RECT* WINPR_RESTRICT rects,
size_t numRects,
1567 REGION16* WINPR_RESTRICT region,
size_t width,
size_t height)
1569 const RECTANGLE_16 mainRect = { 0, 0, WINPR_ASSERTING_INT_CAST(UINT16, width),
1570 WINPR_ASSERTING_INT_CAST(UINT16, height) };
1572 WINPR_ASSERT(rects);
1573 for (
size_t i = 0; i < numRects; i++)
1577 rect16.left = rect->x;
1578 rect16.top = rect->y;
1579 rect16.right = rect->x + rect->width;
1580 rect16.bottom = rect->y + rect->height;
1582 if (!region16_union_rect(region, region, &rect16))
1586 return region16_intersect_rect(region, region, &mainRect);
1589#define TILE_NO(v) ((v) / 64)
1591static inline BOOL setupWorkers(RFX_CONTEXT* WINPR_RESTRICT context,
size_t nbTiles)
1593 WINPR_ASSERT(context);
1595 RFX_CONTEXT_PRIV* priv = context->priv;
1600 if (!context->priv->UseThreads)
1603 if (!(pmem = winpr_aligned_recalloc((
void*)priv->workObjects, nbTiles,
sizeof(PTP_WORK), 32)))
1606 priv->workObjects = (PTP_WORK*)pmem;
1608 if (!(pmem = winpr_aligned_recalloc(priv->tileWorkParams, nbTiles,
1609 sizeof(RFX_TILE_COMPOSE_WORK_PARAM), 32)))
1612 priv->tileWorkParams = (RFX_TILE_COMPOSE_WORK_PARAM*)pmem;
1616static inline BOOL rfx_ensure_tiles(RFX_MESSAGE* WINPR_RESTRICT message,
size_t count)
1618 WINPR_ASSERT(message);
1620 if (message->numTiles + count <= message->allocatedTiles)
1623 const size_t alloc = MAX(message->allocatedTiles + 1024, message->numTiles + count);
1624 return rfx_allocate_tiles(message, alloc, TRUE);
1627RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* WINPR_RESTRICT context,
1628 const RFX_RECT* WINPR_RESTRICT rects,
size_t numRects,
1629 const BYTE* WINPR_RESTRICT data, UINT32 w, UINT32 h,
size_t s)
1631 const UINT32 width = w;
1632 const UINT32 height = h;
1633 const UINT32 scanline = (UINT32)s;
1634 RFX_MESSAGE* message = NULL;
1635 PTP_WORK* workObject = NULL;
1636 RFX_TILE_COMPOSE_WORK_PARAM* workParam = NULL;
1637 BOOL success = FALSE;
1644 WINPR_ASSERT(rects);
1645 WINPR_ASSERT(numRects > 0);
1646 WINPR_ASSERT(w > 0);
1647 WINPR_ASSERT(h > 0);
1648 WINPR_ASSERT(s > 0);
1650 if (!(message = (RFX_MESSAGE*)winpr_aligned_calloc(1,
sizeof(RFX_MESSAGE), 32)))
1653 region16_init(&tilesRegion);
1654 region16_init(&rectsRegion);
1656 if (context->state == RFX_STATE_SEND_HEADERS)
1657 rfx_update_context_properties(context);
1659 message->frameIdx = context->frameIdx++;
1661 if (!context->numQuant)
1663 WINPR_ASSERT(context->quants == NULL);
1664 if (!(context->quants =
1665 (UINT32*)winpr_aligned_malloc(
sizeof(rfx_default_quantization_values), 32)))
1666 goto skip_encoding_loop;
1668 CopyMemory(context->quants, &rfx_default_quantization_values,
1669 sizeof(rfx_default_quantization_values));
1670 context->numQuant = 1;
1671 context->quantIdxY = 0;
1672 context->quantIdxCb = 0;
1673 context->quantIdxCr = 0;
1676 message->numQuant = context->numQuant;
1677 message->quantVals = context->quants;
1680 const UINT32 bytesPerPixel = (context->bits_per_pixel / 8);
1681 if (!computeRegion(rects, numRects, &rectsRegion, width, height))
1682 goto skip_encoding_loop;
1685 const RECTANGLE_16* extents = region16_extents(&rectsRegion);
1686 WINPR_ASSERT((INT32)extents->right - extents->left > 0);
1687 WINPR_ASSERT((INT32)extents->bottom - extents->top > 0);
1688 const UINT32 maxTilesX = 1 + TILE_NO(extents->right - 1) - TILE_NO(extents->left);
1689 const UINT32 maxTilesY = 1 + TILE_NO(extents->bottom - 1) - TILE_NO(extents->top);
1690 const UINT32 maxNbTiles = maxTilesX * maxTilesY;
1692 if (!rfx_ensure_tiles(message, maxNbTiles))
1693 goto skip_encoding_loop;
1695 if (!setupWorkers(context, maxNbTiles))
1696 goto skip_encoding_loop;
1699 if (context->priv->UseThreads)
1701 workObject = context->priv->workObjects;
1702 workParam = context->priv->tileWorkParams;
1706 UINT32 regionNbRects = 0;
1707 regionRect = region16_rects(&rectsRegion, ®ionNbRects);
1709 if (!(message->rects = winpr_aligned_calloc(regionNbRects,
sizeof(
RFX_RECT), 32)))
1710 goto skip_encoding_loop;
1712 message->numRects = WINPR_ASSERTING_INT_CAST(UINT16, regionNbRects);
1714 for (UINT32 i = 0; i < regionNbRects; i++, regionRect++)
1716 RFX_RECT* rfxRect = &message->rects[i];
1717 UINT32 startTileX = regionRect->left / 64;
1718 UINT32 endTileX = (regionRect->right - 1) / 64;
1719 UINT32 startTileY = regionRect->top / 64;
1720 UINT32 endTileY = (regionRect->bottom - 1) / 64;
1721 rfxRect->x = regionRect->left;
1722 rfxRect->y = regionRect->top;
1723 rfxRect->width = (regionRect->right - regionRect->left);
1724 rfxRect->height = (regionRect->bottom - regionRect->top);
1726 for (UINT32 yIdx = startTileY, gridRelY = startTileY * 64; yIdx <= endTileY;
1727 yIdx++, gridRelY += 64)
1729 UINT32 tileHeight = 64;
1731 if ((yIdx == endTileY) && (gridRelY + 64 > height))
1732 tileHeight = height - gridRelY;
1734 currentTileRect.top = WINPR_ASSERTING_INT_CAST(UINT16, gridRelY);
1735 currentTileRect.bottom =
1736 WINPR_ASSERTING_INT_CAST(UINT16, gridRelY + tileHeight);
1738 for (UINT32 xIdx = startTileX, gridRelX = startTileX * 64; xIdx <= endTileX;
1739 xIdx++, gridRelX += 64)
1746 UINT32 tileWidth = 64;
1748 if ((xIdx == endTileX) && (gridRelX + 64 > width))
1750 tileWidth = (width - gridRelX);
1753 currentTileRect.left = WINPR_ASSERTING_INT_CAST(UINT16, gridRelX);
1754 currentTileRect.right =
1755 WINPR_ASSERTING_INT_CAST(UINT16, gridRelX + tileWidth);
1758 if (region16_intersects_rect(&tilesRegion, ¤tTileRect))
1763 goto skip_encoding_loop;
1765 tile->xIdx = WINPR_ASSERTING_INT_CAST(UINT16, xIdx);
1766 tile->yIdx = WINPR_ASSERTING_INT_CAST(UINT16, yIdx);
1767 tile->x = WINPR_ASSERTING_INT_CAST(UINT16, gridRelX);
1768 tile->y = WINPR_ASSERTING_INT_CAST(UINT16, gridRelY);
1769 tile->scanline = scanline;
1771 tile->width = tileWidth;
1772 tile->height = tileHeight;
1773 const UINT32 ax = gridRelX;
1774 const UINT32 ay = gridRelY;
1776 if (tile->data && tile->allocated)
1778 winpr_aligned_free(tile->data);
1779 tile->allocated = FALSE;
1783 cnv.cpv = &data[(ay * scanline) + (ax * bytesPerPixel)];
1784 tile->data = cnv.pv;
1785 tile->quantIdxY = context->quantIdxY;
1786 tile->quantIdxCb = context->quantIdxCb;
1787 tile->quantIdxCr = context->quantIdxCr;
1788 tile->YLen = tile->CbLen = tile->CrLen = 0;
1790 if (!(tile->YCbCrData =
1791 (BYTE*)BufferPool_Take(context->priv->BufferPool, -1)))
1792 goto skip_encoding_loop;
1794 tile->YData = &(tile->YCbCrData[((8192 + 32) * 0) + 16]);
1795 tile->CbData = &(tile->YCbCrData[((8192 + 32) * 1) + 16]);
1796 tile->CrData = &(tile->YCbCrData[((8192 + 32) * 2) + 16]);
1798 if (!rfx_ensure_tiles(message, 1))
1799 goto skip_encoding_loop;
1800 message->tiles[message->numTiles++] = tile;
1802 if (context->priv->UseThreads)
1804 workParam->context = context;
1805 workParam->tile = tile;
1808 CreateThreadpoolWork(rfx_compose_message_tile_work_callback,
1809 (
void*)workParam, NULL)))
1811 goto skip_encoding_loop;
1814 SubmitThreadpoolWork(*workObject);
1820 rfx_encode_rgb(context, tile);
1823 if (!region16_union_rect(&tilesRegion, &tilesRegion, ¤tTileRect))
1824 goto skip_encoding_loop;
1837 message->tilesDataSize = 0;
1838 workObject = context->priv->workObjects;
1840 for (UINT32 i = 0; i < message->numTiles; i++)
1842 if (context->priv->UseThreads)
1846 WaitForThreadpoolWorkCallbacks(*workObject, FALSE);
1847 CloseThreadpoolWork(*workObject);
1853 const RFX_TILE* tile = message->tiles[i];
1854 const size_t tlen = rfx_tile_length(tile);
1855 message->tilesDataSize += WINPR_ASSERTING_INT_CAST(uint32_t, tlen);
1858 region16_uninit(&tilesRegion);
1859 region16_uninit(&rectsRegion);
1864 WLog_Print(context->priv->log, WLOG_ERROR,
"failed");
1866 rfx_message_free(context, message);
1867 region16_uninit(&tilesRegion);
1868 region16_uninit(&rectsRegion);
1872static inline BOOL rfx_clone_rects(RFX_MESSAGE* WINPR_RESTRICT dst,
1873 const RFX_MESSAGE* WINPR_RESTRICT src)
1878 WINPR_ASSERT(dst->rects == NULL);
1879 WINPR_ASSERT(dst->numRects == 0);
1881 if (src->numRects == 0)
1884 dst->rects = winpr_aligned_calloc(src->numRects,
sizeof(
RECTANGLE_16), 32);
1887 dst->numRects = src->numRects;
1888 for (
size_t x = 0; x < src->numRects; x++)
1890 dst->rects[x] = src->rects[x];
1895static inline BOOL rfx_clone_quants(RFX_MESSAGE* WINPR_RESTRICT dst,
1896 const RFX_MESSAGE* WINPR_RESTRICT src)
1901 WINPR_ASSERT(dst->quantVals == NULL);
1902 WINPR_ASSERT(dst->numQuant == 0);
1904 if (src->numQuant == 0)
1908 dst->quantVals = src->quantVals;
1909 dst->numQuant = src->numQuant;
1914static inline RFX_MESSAGE* rfx_split_message(RFX_CONTEXT* WINPR_RESTRICT context,
1915 RFX_MESSAGE* WINPR_RESTRICT message,
1916 size_t* WINPR_RESTRICT numMessages,
size_t maxDataSize)
1918 WINPR_ASSERT(context);
1919 WINPR_ASSERT(message);
1920 WINPR_ASSERT(numMessages);
1922 maxDataSize -= 1024;
1923 *numMessages = ((message->tilesDataSize + maxDataSize) / maxDataSize) * 4ull;
1925 RFX_MESSAGE* messages =
1926 (RFX_MESSAGE*)winpr_aligned_calloc((*numMessages),
sizeof(RFX_MESSAGE), 32);
1931 for (UINT16 i = 0; i < message->numTiles; i++)
1933 RFX_TILE* tile = message->tiles[i];
1934 RFX_MESSAGE* msg = &messages[j];
1939 const size_t tileDataSize = rfx_tile_length(tile);
1941 if ((msg->tilesDataSize + tileDataSize) > ((UINT32)maxDataSize))
1944 if (msg->numTiles == 0)
1946 msg->frameIdx = message->frameIdx + j;
1947 if (!rfx_clone_quants(msg, message))
1949 if (!rfx_clone_rects(msg, message))
1951 msg->freeArray = TRUE;
1952 if (!rfx_allocate_tiles(msg, message->numTiles, TRUE))
1956 msg->tilesDataSize += WINPR_ASSERTING_INT_CAST(uint32_t, tileDataSize);
1958 WINPR_ASSERT(msg->numTiles < msg->allocatedTiles);
1959 msg->tiles[msg->numTiles++] = message->tiles[i];
1960 message->tiles[i] = NULL;
1963 *numMessages = j + 1ULL;
1964 context->frameIdx += j;
1965 message->numTiles = 0;
1969 for (
size_t i = 0; i < j; i++)
1970 rfx_allocate_tiles(&messages[i], 0, FALSE);
1972 winpr_aligned_free(messages);
1976const RFX_MESSAGE* rfx_message_list_get(
const RFX_MESSAGE_LIST* WINPR_RESTRICT messages,
size_t idx)
1978 WINPR_ASSERT(messages);
1979 if (idx >= messages->count)
1981 WINPR_ASSERT(messages->list);
1982 return &messages->list[idx];
1985void rfx_message_list_free(RFX_MESSAGE_LIST* messages)
1989 for (
size_t x = 0; x < messages->count; x++)
1990 rfx_message_free(messages->context, &messages->list[x]);
1994static inline RFX_MESSAGE_LIST* rfx_message_list_new(RFX_CONTEXT* WINPR_RESTRICT context,
1995 RFX_MESSAGE* WINPR_RESTRICT messages,
1998 WINPR_ASSERT(context);
1999 RFX_MESSAGE_LIST* msg = calloc(1,
sizeof(RFX_MESSAGE_LIST));
2002 msg->context = context;
2004 msg->list = messages;
2008RFX_MESSAGE_LIST* rfx_encode_messages(RFX_CONTEXT* WINPR_RESTRICT context,
2009 const RFX_RECT* WINPR_RESTRICT rects,
size_t numRects,
2010 const BYTE* WINPR_RESTRICT data, UINT32 width, UINT32 height,
2011 UINT32 scanline,
size_t* WINPR_RESTRICT numMessages,
2014 WINPR_ASSERT(context);
2015 WINPR_ASSERT(numMessages);
2017 RFX_MESSAGE* message =
2018 rfx_encode_message(context, rects, numRects, data, width, height, scanline);
2022 RFX_MESSAGE* list = rfx_split_message(context, message, numMessages, maxDataSize);
2023 rfx_message_free(context, message);
2027 return rfx_message_list_new(context, list, *numMessages);
2030static inline BOOL rfx_write_message_tileset(RFX_CONTEXT* WINPR_RESTRICT context,
2032 const RFX_MESSAGE* WINPR_RESTRICT message)
2034 WINPR_ASSERT(context);
2035 WINPR_ASSERT(message);
2037 const UINT32 blockLen = 22 + (message->numQuant * 5) + message->tilesDataSize;
2039 if (!Stream_EnsureRemainingCapacity(s, blockLen))
2042 Stream_Write_UINT16(s, WBT_EXTENSION);
2043 Stream_Write_UINT32(s, blockLen);
2044 Stream_Write_UINT8(s, 1);
2045 Stream_Write_UINT8(s, 0);
2046 Stream_Write_UINT16(s, CBT_TILESET);
2047 Stream_Write_UINT16(s, 0);
2048 Stream_Write_UINT16(s, context->properties);
2050 s, WINPR_ASSERTING_INT_CAST(uint8_t, message->numQuant));
2051 Stream_Write_UINT8(s, 0x40);
2052 Stream_Write_UINT16(s, message->numTiles);
2053 Stream_Write_UINT32(s, message->tilesDataSize);
2055 UINT32* quantVals = message->quantVals;
2056 for (
size_t i = 0; i < message->numQuant * 5ul; i++)
2058 WINPR_ASSERT(quantVals);
2059 Stream_Write_UINT8(s,
2060 WINPR_ASSERTING_INT_CAST(uint8_t, quantVals[0] + (quantVals[1] << 4)));
2064 for (
size_t i = 0; i < message->numTiles; i++)
2066 RFX_TILE* tile = message->tiles[i];
2070 if (!rfx_write_tile(s, tile))
2074#ifdef WITH_DEBUG_RFX
2075 WLog_Print(context->priv->log, WLOG_DEBUG,
2076 "numQuant: %" PRIu16
" numTiles: %" PRIu16
" tilesDataSize: %" PRIu32
"",
2077 message->numQuant, message->numTiles, message->tilesDataSize);
2083rfx_write_message_frame_begin(WINPR_ATTR_UNUSED RFX_CONTEXT* WINPR_RESTRICT context,
2084 wStream* WINPR_RESTRICT s,
const RFX_MESSAGE* WINPR_RESTRICT message)
2086 WINPR_ASSERT(context);
2087 WINPR_ASSERT(message);
2089 if (!Stream_EnsureRemainingCapacity(s, 14))
2092 Stream_Write_UINT16(s, WBT_FRAME_BEGIN);
2093 Stream_Write_UINT32(s, 14);
2094 Stream_Write_UINT8(s, 1);
2095 Stream_Write_UINT8(s, 0);
2096 Stream_Write_UINT32(s, message->frameIdx);
2097 Stream_Write_UINT16(s, 1);
2101static inline BOOL rfx_write_message_region(WINPR_ATTR_UNUSED RFX_CONTEXT* WINPR_RESTRICT context,
2103 const RFX_MESSAGE* WINPR_RESTRICT message)
2105 WINPR_ASSERT(context);
2106 WINPR_ASSERT(message);
2108 const size_t blockLen = 15 + (message->numRects * 8);
2109 if (blockLen > UINT32_MAX)
2112 if (!Stream_EnsureRemainingCapacity(s, blockLen))
2115 Stream_Write_UINT16(s, WBT_REGION);
2116 Stream_Write_UINT32(s, (UINT32)blockLen);
2117 Stream_Write_UINT8(s, 1);
2118 Stream_Write_UINT8(s, 0);
2119 Stream_Write_UINT8(s, 1);
2120 Stream_Write_UINT16(s, message->numRects);
2122 for (UINT16 i = 0; i < message->numRects; i++)
2124 const RFX_RECT* rect = rfx_message_get_rect_const(message, i);
2128 Stream_Write_UINT16(s, rect->x);
2129 Stream_Write_UINT16(s, rect->y);
2130 Stream_Write_UINT16(s, rect->width);
2131 Stream_Write_UINT16(s, rect->height);
2134 Stream_Write_UINT16(s, CBT_REGION);
2135 Stream_Write_UINT16(s, 1);
2140rfx_write_message_frame_end(WINPR_ATTR_UNUSED RFX_CONTEXT* WINPR_RESTRICT context,
2142 WINPR_ATTR_UNUSED
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);
2157BOOL 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))
2182BOOL 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);
2198BOOL rfx_context_set_mode(RFX_CONTEXT* WINPR_RESTRICT context, RLGR_MODE mode)
2200 WINPR_ASSERT(context);
2201 context->mode = mode;
2205RLGR_MODE rfx_context_get_mode(RFX_CONTEXT* WINPR_RESTRICT context)
2207 WINPR_ASSERT(context);
2208 return context->mode;
2211UINT32 rfx_context_get_frame_idx(
const RFX_CONTEXT* WINPR_RESTRICT context)
2213 WINPR_ASSERT(context);
2214 return context->frameIdx;
2217UINT32 rfx_message_get_frame_idx(
const RFX_MESSAGE* WINPR_RESTRICT message)
2219 WINPR_ASSERT(message);
2220 return message->frameIdx;
2223static inline BOOL rfx_write_progressive_wb_sync(WINPR_ATTR_UNUSED 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);
2241rfx_write_progressive_wb_context(WINPR_ATTR_UNUSED RFX_CONTEXT* WINPR_RESTRICT rfx,
2244 const UINT32 blockLen = 10;
2248 if (!Stream_EnsureRemainingCapacity(s, blockLen))
2251 Stream_Write_UINT16(s, PROGRESSIVE_WBT_CONTEXT);
2252 Stream_Write_UINT32(s, blockLen);
2253 Stream_Write_UINT8(s, 0);
2254 Stream_Write_UINT16(s, 64);
2255 Stream_Write_UINT8(s, 0);
2259static inline BOOL rfx_write_progressive_region(RFX_CONTEXT* WINPR_RESTRICT rfx,
2261 const RFX_MESSAGE* WINPR_RESTRICT msg)
2264 UINT32 blockLen = 18;
2265 UINT32 tilesDataSize = 0;
2266 const size_t start = Stream_GetPosition(s);
2272 blockLen += msg->numRects * 8;
2273 blockLen += msg->numQuant * 5;
2274 tilesDataSize = msg->numTiles * 22UL;
2275 for (UINT16 i = 0; i < msg->numTiles; i++)
2277 const RFX_TILE* tile = msg->tiles[i];
2279 tilesDataSize += tile->YLen + tile->CbLen + tile->CrLen;
2281 blockLen += tilesDataSize;
2283 if (!Stream_EnsureRemainingCapacity(s, blockLen))
2286 Stream_Write_UINT16(s, PROGRESSIVE_WBT_REGION);
2287 Stream_Write_UINT32(s, blockLen);
2288 Stream_Write_UINT8(s, 64);
2289 Stream_Write_UINT16(s, msg->numRects);
2290 WINPR_ASSERT(msg->numQuant <= UINT8_MAX);
2291 Stream_Write_UINT8(s, (UINT8)msg->numQuant);
2292 Stream_Write_UINT8(s, 0);
2293 Stream_Write_UINT8(s, 0);
2294 Stream_Write_UINT16(s, msg->numTiles);
2295 Stream_Write_UINT32(s, tilesDataSize);
2297 for (UINT16 i = 0; i < msg->numRects; i++)
2300 const RFX_RECT* r = &msg->rects[i];
2301 Stream_Write_UINT16(s, r->x);
2302 Stream_Write_UINT16(s, r->y);
2303 Stream_Write_UINT16(s, r->width);
2304 Stream_Write_UINT16(s, r->height);
2315 for (UINT16 i = 0; i < msg->numQuant; i++)
2317 const UINT32* qv = &msg->quantVals[10ULL * i];
2319 Stream_Write_UINT8(s, (UINT8)(qv[0] + (qv[2] << 4)));
2320 Stream_Write_UINT8(s, (UINT8)(qv[1] + (qv[3] << 4)));
2321 Stream_Write_UINT8(s, (UINT8)(qv[5] + (qv[4] << 4)));
2322 Stream_Write_UINT8(s, (UINT8)(qv[6] + (qv[8] << 4)));
2323 Stream_Write_UINT8(s, (UINT8)(qv[7] + (qv[9] << 4)));
2326 for (UINT16 i = 0; i < msg->numTiles; i++)
2328 const RFX_TILE* tile = msg->tiles[i];
2329 if (!rfx_write_progressive_tile_simple(rfx, s, tile))
2333 const size_t end = Stream_GetPosition(s);
2334 const size_t used = end - start;
2335 return (used == blockLen);
2339rfx_write_progressive_frame_begin(WINPR_ATTR_UNUSED RFX_CONTEXT* WINPR_RESTRICT rfx,
2340 wStream* WINPR_RESTRICT s,
const RFX_MESSAGE* WINPR_RESTRICT msg)
2342 const UINT32 blockLen = 12;
2347 if (!Stream_EnsureRemainingCapacity(s, blockLen))
2350 Stream_Write_UINT16(s, PROGRESSIVE_WBT_FRAME_BEGIN);
2351 Stream_Write_UINT32(s, blockLen);
2352 Stream_Write_UINT32(s, msg->frameIdx);
2353 Stream_Write_UINT16(s, 1);
2359rfx_write_progressive_frame_end(WINPR_ATTR_UNUSED RFX_CONTEXT* WINPR_RESTRICT rfx,
2362 const UINT32 blockLen = 6;
2366 if (!Stream_EnsureRemainingCapacity(s, blockLen))
2369 Stream_Write_UINT16(s, PROGRESSIVE_WBT_FRAME_END);
2370 Stream_Write_UINT32(s, blockLen);
2376rfx_write_progressive_tile_simple(WINPR_ATTR_UNUSED RFX_CONTEXT* WINPR_RESTRICT rfx,
2379 UINT32 blockLen = 0;
2384 blockLen = 22 + tile->YLen + tile->CbLen + tile->CrLen;
2385 if (!Stream_EnsureRemainingCapacity(s, blockLen))
2388 Stream_Write_UINT16(s, PROGRESSIVE_WBT_TILE_SIMPLE);
2389 Stream_Write_UINT32(s, blockLen);
2390 Stream_Write_UINT8(s, tile->quantIdxY);
2391 Stream_Write_UINT8(s, tile->quantIdxCb);
2392 Stream_Write_UINT8(s, tile->quantIdxCr);
2393 Stream_Write_UINT16(s, tile->xIdx);
2394 Stream_Write_UINT16(s, tile->yIdx);
2395 Stream_Write_UINT8(s, 0);
2396 Stream_Write_UINT16(s, tile->YLen);
2397 Stream_Write_UINT16(s, tile->CbLen);
2398 Stream_Write_UINT16(s, tile->CrLen);
2399 Stream_Write_UINT16(s, 0);
2400 Stream_Write(s, tile->YData, tile->YLen);
2401 Stream_Write(s, tile->CbData, tile->CbLen);
2402 Stream_Write(s, tile->CrData, tile->CrLen);
2407const char* rfx_get_progressive_block_type_string(UINT16 blockType)
2411 case PROGRESSIVE_WBT_SYNC:
2412 return "PROGRESSIVE_WBT_SYNC";
2414 case PROGRESSIVE_WBT_FRAME_BEGIN:
2415 return "PROGRESSIVE_WBT_FRAME_BEGIN";
2417 case PROGRESSIVE_WBT_FRAME_END:
2418 return "PROGRESSIVE_WBT_FRAME_END";
2420 case PROGRESSIVE_WBT_CONTEXT:
2421 return "PROGRESSIVE_WBT_CONTEXT";
2423 case PROGRESSIVE_WBT_REGION:
2424 return "PROGRESSIVE_WBT_REGION";
2426 case PROGRESSIVE_WBT_TILE_SIMPLE:
2427 return "PROGRESSIVE_WBT_TILE_SIMPLE";
2429 case PROGRESSIVE_WBT_TILE_FIRST:
2430 return "PROGRESSIVE_WBT_TILE_FIRST";
2432 case PROGRESSIVE_WBT_TILE_UPGRADE:
2433 return "PROGRESSIVE_WBT_TILE_UPGRADE";
2436 return "PROGRESSIVE_WBT_UNKNOWN";
2440BOOL rfx_write_message_progressive_simple(RFX_CONTEXT* WINPR_RESTRICT context,
2442 const RFX_MESSAGE* WINPR_RESTRICT msg)
2446 WINPR_ASSERT(context);
2448 if (context->mode != RLGR1)
2450 WLog_ERR(TAG,
"error, RLGR1 mode is required!");
2454 if (!rfx_write_progressive_wb_sync(context, s))
2457 if (!rfx_write_progressive_wb_context(context, s))
2460 if (!rfx_write_progressive_frame_begin(context, s, msg))
2463 if (!rfx_write_progressive_region(context, s, msg))
2466 if (!rfx_write_progressive_frame_end(context, s))
This struct contains function pointer to initialize/free objects.