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"
50#include "../core/utils.h"
52#include "sse/rfx_sse2.h"
53#include "neon/rfx_neon.h"
55#define TAG FREERDP_TAG("codec")
57#define RFX_KEY "Software\\%s\\RemoteFX"
71static const UINT32 rfx_default_quantization_values[] = { 6, 6, 6, 6, 7, 7, 8, 8, 8, 9 };
73static inline BOOL rfx_write_progressive_tile_simple(RFX_CONTEXT* WINPR_RESTRICT rfx,
75 const RFX_TILE* WINPR_RESTRICT tile);
77static inline void rfx_profiler_create(RFX_CONTEXT* WINPR_RESTRICT context)
79 if (!context || !context->priv)
81 PROFILER_CREATE(context->priv->prof_rfx_decode_rgb,
"rfx_decode_rgb")
82 PROFILER_CREATE(context->priv->prof_rfx_decode_component, "rfx_decode_component")
83 PROFILER_CREATE(context->priv->prof_rfx_rlgr_decode, "rfx_rlgr_decode")
84 PROFILER_CREATE(context->priv->prof_rfx_differential_decode, "rfx_differential_decode")
85 PROFILER_CREATE(context->priv->prof_rfx_quantization_decode, "rfx_quantization_decode")
86 PROFILER_CREATE(context->priv->prof_rfx_dwt_2d_decode, "rfx_dwt_2d_decode")
87 PROFILER_CREATE(context->priv->prof_rfx_ycbcr_to_rgb, "prims->yCbCrToRGB")
88 PROFILER_CREATE(context->priv->prof_rfx_encode_rgb, "rfx_encode_rgb")
89 PROFILER_CREATE(context->priv->prof_rfx_encode_component, "rfx_encode_component")
90 PROFILER_CREATE(context->priv->prof_rfx_rlgr_encode, "rfx_rlgr_encode")
91 PROFILER_CREATE(context->priv->prof_rfx_differential_encode, "rfx_differential_encode")
92 PROFILER_CREATE(context->priv->prof_rfx_quantization_encode, "rfx_quantization_encode")
93 PROFILER_CREATE(context->priv->prof_rfx_dwt_2d_encode, "rfx_dwt_2d_encode")
94 PROFILER_CREATE(context->priv->prof_rfx_rgb_to_ycbcr, "prims->RGBToYCbCr")
95 PROFILER_CREATE(context->priv->prof_rfx_encode_format_rgb, "rfx_encode_format_rgb")
98static inline
void rfx_profiler_free(RFX_CONTEXT* WINPR_RESTRICT context)
100 if (!context || !context->priv)
102 PROFILER_FREE(context->priv->prof_rfx_decode_rgb)
103 PROFILER_FREE(context->priv->prof_rfx_decode_component)
104 PROFILER_FREE(context->priv->prof_rfx_rlgr_decode)
105 PROFILER_FREE(context->priv->prof_rfx_differential_decode)
106 PROFILER_FREE(context->priv->prof_rfx_quantization_decode)
107 PROFILER_FREE(context->priv->prof_rfx_dwt_2d_decode)
108 PROFILER_FREE(context->priv->prof_rfx_ycbcr_to_rgb)
109 PROFILER_FREE(context->priv->prof_rfx_encode_rgb)
110 PROFILER_FREE(context->priv->prof_rfx_encode_component)
111 PROFILER_FREE(context->priv->prof_rfx_rlgr_encode)
112 PROFILER_FREE(context->priv->prof_rfx_differential_encode)
113 PROFILER_FREE(context->priv->prof_rfx_quantization_encode)
114 PROFILER_FREE(context->priv->prof_rfx_dwt_2d_encode)
115 PROFILER_FREE(context->priv->prof_rfx_rgb_to_ycbcr)
116 PROFILER_FREE(context->priv->prof_rfx_encode_format_rgb)
119static inline
void rfx_profiler_print(RFX_CONTEXT* WINPR_RESTRICT context)
121 if (!context || !context->priv)
124 PROFILER_PRINT_HEADER
125 PROFILER_PRINT(context->priv->prof_rfx_decode_rgb)
126 PROFILER_PRINT(context->priv->prof_rfx_decode_component)
127 PROFILER_PRINT(context->priv->prof_rfx_rlgr_decode)
128 PROFILER_PRINT(context->priv->prof_rfx_differential_decode)
129 PROFILER_PRINT(context->priv->prof_rfx_quantization_decode)
130 PROFILER_PRINT(context->priv->prof_rfx_dwt_2d_decode)
131 PROFILER_PRINT(context->priv->prof_rfx_ycbcr_to_rgb)
132 PROFILER_PRINT(context->priv->prof_rfx_encode_rgb)
133 PROFILER_PRINT(context->priv->prof_rfx_encode_component)
134 PROFILER_PRINT(context->priv->prof_rfx_rlgr_encode)
135 PROFILER_PRINT(context->priv->prof_rfx_differential_encode)
136 PROFILER_PRINT(context->priv->prof_rfx_quantization_encode)
137 PROFILER_PRINT(context->priv->prof_rfx_dwt_2d_encode)
138 PROFILER_PRINT(context->priv->prof_rfx_rgb_to_ycbcr)
139 PROFILER_PRINT(context->priv->prof_rfx_encode_format_rgb)
140 PROFILER_PRINT_FOOTER
143static inline
void rfx_tile_init(
void* obj)
159static inline void* rfx_decoder_tile_new(
const void* val)
161 const size_t size = 4ULL * 64ULL * 64ULL;
168 if (!(tile->data = (BYTE*)winpr_aligned_malloc(size, 16)))
170 winpr_aligned_free(tile);
173 memset(tile->data, 0xff, size);
174 tile->allocated = TRUE;
178static inline void rfx_decoder_tile_free(
void* obj)
185 winpr_aligned_free(tile->data);
187 winpr_aligned_free(tile);
191static inline void* rfx_encoder_tile_new(
const void* val)
194 return winpr_aligned_calloc(1,
sizeof(
RFX_TILE), 32);
197static inline void rfx_encoder_tile_free(
void* obj)
199 winpr_aligned_free(obj);
202RFX_CONTEXT* rfx_context_new(BOOL encoder)
204 return rfx_context_new_ex(encoder, 0);
207RFX_CONTEXT* rfx_context_new_ex(BOOL encoder, UINT32 ThreadingFlags)
209 RFX_CONTEXT_PRIV* priv = NULL;
210 RFX_CONTEXT* context = (RFX_CONTEXT*)winpr_aligned_calloc(1,
sizeof(RFX_CONTEXT), 32);
215 context->encoder = encoder;
216 context->currentMessage.freeArray = TRUE;
217 context->priv = priv = (RFX_CONTEXT_PRIV*)winpr_aligned_calloc(1,
sizeof(RFX_CONTEXT_PRIV), 32);
222 priv->log = WLog_Get(
"com.freerdp.codec.rfx");
223 WLog_OpenAppender(priv->log);
224 priv->TilePool = ObjectPool_New(TRUE);
230 wObject* pool = ObjectPool_Object(priv->TilePool);
233 if (context->encoder)
258 priv->BufferPool = BufferPool_New(TRUE, (8192ULL + 32ULL) * 3ULL, 16);
260 if (!priv->BufferPool)
263 priv->UseThreads = FALSE;
264 if (!(ThreadingFlags & THREADING_FLAGS_DISABLE_THREADS))
265 priv->UseThreads = TRUE;
268 char* key = freerdp_getApplicatonDetailsRegKey(RFX_KEY);
273 RegOpenKeyExA(HKEY_LOCAL_MACHINE, RFX_KEY, 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
276 if (status == ERROR_SUCCESS)
280 DWORD dwSize =
sizeof(dwValue);
282 if (RegQueryValueEx(hKey, _T(
"UseThreads"), NULL, &dwType, (BYTE*)&dwValue,
283 &dwSize) == ERROR_SUCCESS)
284 priv->UseThreads = dwValue ? 1 : 0;
291 if (priv->UseThreads)
300 rfx_context_set_pixel_format(context, PIXEL_FORMAT_BGRX32);
302 rfx_profiler_create(context);
304 context->quantization_decode = rfx_quantization_decode;
305 context->quantization_encode = rfx_quantization_encode;
306 context->dwt_2d_decode = rfx_dwt_2d_decode;
307 context->dwt_2d_extrapolate_decode = rfx_dwt_2d_extrapolate_decode;
308 context->dwt_2d_encode = rfx_dwt_2d_encode;
309 context->rlgr_decode = rfx_rlgr_decode;
310 context->rlgr_encode = rfx_rlgr_encode;
311 rfx_init_sse2(context);
312 rfx_init_neon(context);
313 context->state = RFX_STATE_SEND_HEADERS;
314 context->expectedDataBlockType = WBT_FRAME_BEGIN;
317 WINPR_PRAGMA_DIAG_PUSH
318 WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
319 rfx_context_free(context);
320 WINPR_PRAGMA_DIAG_POP
324void rfx_context_free(RFX_CONTEXT* context)
326 RFX_CONTEXT_PRIV* priv = NULL;
331 WINPR_ASSERT(NULL != context);
333 priv = context->priv;
334 WINPR_ASSERT(NULL != priv);
335 WINPR_ASSERT(NULL != priv->TilePool);
336 WINPR_ASSERT(NULL != priv->BufferPool);
339 rfx_message_free(context, &context->currentMessage);
340 winpr_aligned_free(context->quants);
341 rfx_profiler_print(context);
342 rfx_profiler_free(context);
346 ObjectPool_Free(priv->TilePool);
347 if (priv->UseThreads)
349 winpr_aligned_free((
void*)priv->workObjects);
350 winpr_aligned_free(priv->tileWorkParams);
354 "WARNING: Profiling results probably unusable with multithreaded RemoteFX codec!");
358 BufferPool_Free(priv->BufferPool);
359 winpr_aligned_free(priv);
361 winpr_aligned_free(context);
364static inline RFX_TILE* rfx_message_get_tile(RFX_MESSAGE* WINPR_RESTRICT message, UINT32 index)
366 WINPR_ASSERT(message);
367 WINPR_ASSERT(message->tiles);
368 WINPR_ASSERT(index < message->numTiles);
369 return message->tiles[index];
372static inline const RFX_RECT* rfx_message_get_rect_const(
const RFX_MESSAGE* WINPR_RESTRICT message,
375 WINPR_ASSERT(message);
376 WINPR_ASSERT(message->rects);
377 WINPR_ASSERT(index < message->numRects);
378 return &message->rects[index];
381static inline RFX_RECT* rfx_message_get_rect(RFX_MESSAGE* WINPR_RESTRICT message, UINT32 index)
383 WINPR_ASSERT(message);
384 WINPR_ASSERT(message->rects);
385 WINPR_ASSERT(index < message->numRects);
386 return &message->rects[index];
389void rfx_context_set_pixel_format(RFX_CONTEXT* WINPR_RESTRICT context, UINT32 pixel_format)
391 WINPR_ASSERT(context);
392 context->pixel_format = pixel_format;
393 const UINT32 bpp = FreeRDPGetBitsPerPixel(pixel_format);
394 context->bits_per_pixel = WINPR_ASSERTING_INT_CAST(UINT8, bpp);
397UINT32 rfx_context_get_pixel_format(RFX_CONTEXT* WINPR_RESTRICT context)
399 WINPR_ASSERT(context);
400 return context->pixel_format;
403void rfx_context_set_palette(RFX_CONTEXT* WINPR_RESTRICT context,
404 const BYTE* WINPR_RESTRICT palette)
406 WINPR_ASSERT(context);
407 context->palette = palette;
410const BYTE* rfx_context_get_palette(RFX_CONTEXT* WINPR_RESTRICT context)
412 WINPR_ASSERT(context);
413 return context->palette;
416BOOL rfx_context_reset(RFX_CONTEXT* WINPR_RESTRICT context, UINT32 width, UINT32 height)
421 context->width = WINPR_ASSERTING_INT_CAST(UINT16, width);
422 context->height = WINPR_ASSERTING_INT_CAST(UINT16, height);
423 context->state = RFX_STATE_SEND_HEADERS;
424 context->expectedDataBlockType = WBT_FRAME_BEGIN;
425 context->frameIdx = 0;
429static inline BOOL rfx_process_message_sync(RFX_CONTEXT* WINPR_RESTRICT context,
434 WINPR_ASSERT(context);
435 WINPR_ASSERT(context->priv);
436 context->decodedHeaderBlocks &= (uint32_t)~RFX_DECODED_SYNC;
439 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 6))
442 Stream_Read_UINT32(s, magic);
443 if (magic != WF_MAGIC)
445 WLog_Print(context->priv->log, WLOG_ERROR,
"invalid magic number 0x%08" PRIX32
"", magic);
449 Stream_Read_UINT16(s, context->version);
450 if (context->version != WF_VERSION_1_0)
452 WLog_Print(context->priv->log, WLOG_ERROR,
"invalid version number 0x%08" PRIX32
"",
457 WLog_Print(context->priv->log, WLOG_DEBUG,
"version 0x%08" PRIX32
"", context->version);
458 context->decodedHeaderBlocks |= RFX_DECODED_SYNC;
462static inline BOOL rfx_process_message_codec_versions(RFX_CONTEXT* WINPR_RESTRICT context,
467 WINPR_ASSERT(context);
468 WINPR_ASSERT(context->priv);
469 context->decodedHeaderBlocks &= (uint32_t)~RFX_DECODED_VERSIONS;
471 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 4))
474 Stream_Read_UINT8(s, numCodecs);
475 Stream_Read_UINT8(s, context->codec_id);
477 s, context->codec_version);
481 WLog_Print(context->priv->log, WLOG_ERROR,
"numCodes is 0x%02" PRIX8
" (must be 0x01)",
486 if (context->codec_id != 0x01)
488 WLog_Print(context->priv->log, WLOG_ERROR,
"invalid codec id (0x%02" PRIX32
")",
493 if (context->codec_version != WF_VERSION_1_0)
495 WLog_Print(context->priv->log, WLOG_ERROR,
"invalid codec version (0x%08" PRIX32
")",
496 context->codec_version);
500 WLog_Print(context->priv->log, WLOG_DEBUG,
"id %" PRIu32
" version 0x%" PRIX32
".",
501 context->codec_id, context->codec_version);
502 context->decodedHeaderBlocks |= RFX_DECODED_VERSIONS;
506static inline BOOL rfx_process_message_channels(RFX_CONTEXT* WINPR_RESTRICT context,
510 BYTE numChannels = 0;
512 WINPR_ASSERT(context);
513 WINPR_ASSERT(context->priv);
514 context->decodedHeaderBlocks &= (uint32_t)~RFX_DECODED_CHANNELS;
516 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 1))
519 Stream_Read_UINT8(s, numChannels);
526 WLog_Print(context->priv->log, WLOG_ERROR,
"no channels announced");
530 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(context->priv->log, s, numChannels, 5ull))
534 Stream_Read_UINT8(s, channelId);
536 if (channelId != 0x00)
538 WLog_Print(context->priv->log, WLOG_ERROR,
"channelId:0x%02" PRIX8
", expected:0x00",
543 Stream_Read_UINT16(s, context->width);
544 Stream_Read_UINT16(s, context->height);
546 if (!context->width || !context->height)
548 WLog_Print(context->priv->log, WLOG_ERROR,
549 "invalid channel with/height: %" PRIu16
"x%" PRIu16
"", context->width,
555 Stream_Seek(s, 5ULL * (numChannels - 1));
556 WLog_Print(context->priv->log, WLOG_DEBUG,
557 "numChannels %" PRIu8
" id %" PRIu8
", %" PRIu16
"x%" PRIu16
".", numChannels,
558 channelId, context->width, context->height);
559 context->decodedHeaderBlocks |= RFX_DECODED_CHANNELS;
563static inline BOOL rfx_process_message_context(RFX_CONTEXT* WINPR_RESTRICT context,
568 UINT16 properties = 0;
570 WINPR_ASSERT(context);
571 WINPR_ASSERT(context->priv);
572 context->decodedHeaderBlocks &= (uint32_t)~RFX_DECODED_CONTEXT;
574 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 5))
577 Stream_Read_UINT8(s, ctxId);
578 Stream_Read_UINT16(s, tileSize);
579 Stream_Read_UINT16(s, properties);
580 WLog_Print(context->priv->log, WLOG_DEBUG,
581 "ctxId %" PRIu8
" tileSize %" PRIu16
" properties 0x%04" PRIX16
".", ctxId, tileSize,
583 context->properties = properties;
584 context->flags = (properties & 0x0007);
586 if (context->flags == CODEC_MODE)
588 WLog_Print(context->priv->log, WLOG_DEBUG,
"codec is in image mode.");
592 WLog_Print(context->priv->log, WLOG_DEBUG,
"codec is in video mode.");
595 switch ((properties & 0x1E00) >> 9)
597 case CLW_ENTROPY_RLGR1:
598 context->mode = RLGR1;
599 WLog_Print(context->priv->log, WLOG_DEBUG,
"RLGR1.");
602 case CLW_ENTROPY_RLGR3:
603 context->mode = RLGR3;
604 WLog_Print(context->priv->log, WLOG_DEBUG,
"RLGR3.");
608 WLog_Print(context->priv->log, WLOG_ERROR,
"unknown RLGR algorithm.");
612 context->decodedHeaderBlocks |= RFX_DECODED_CONTEXT;
616static inline BOOL rfx_process_message_frame_begin(
617 RFX_CONTEXT* WINPR_RESTRICT context, WINPR_ATTR_UNUSED RFX_MESSAGE* WINPR_RESTRICT message,
618 wStream* WINPR_RESTRICT s, UINT16* WINPR_RESTRICT pExpectedBlockType)
621 UINT16 numRegions = 0;
623 WINPR_ASSERT(context);
624 WINPR_ASSERT(context->priv);
625 WINPR_ASSERT(message);
626 WINPR_ASSERT(pExpectedBlockType);
628 if (*pExpectedBlockType != WBT_FRAME_BEGIN)
630 WLog_Print(context->priv->log, WLOG_ERROR,
"message unexpected wants WBT_FRAME_BEGIN");
634 *pExpectedBlockType = WBT_REGION;
636 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 6))
641 Stream_Read_UINT16(s, numRegions);
642 WLog_Print(context->priv->log, WLOG_DEBUG,
643 "RFX_FRAME_BEGIN: frameIdx: %" PRIu32
" numRegions: %" PRIu16
"", frameIdx,
648static inline BOOL rfx_process_message_frame_end(
649 RFX_CONTEXT* WINPR_RESTRICT context, WINPR_ATTR_UNUSED RFX_MESSAGE* WINPR_RESTRICT message,
650 WINPR_ATTR_UNUSED
wStream* WINPR_RESTRICT s, UINT16* WINPR_RESTRICT pExpectedBlockType)
652 WINPR_ASSERT(context);
653 WINPR_ASSERT(context->priv);
654 WINPR_ASSERT(message);
656 WINPR_ASSERT(pExpectedBlockType);
658 if (*pExpectedBlockType != WBT_FRAME_END)
660 WLog_Print(context->priv->log, WLOG_ERROR,
"message unexpected, wants WBT_FRAME_END");
664 *pExpectedBlockType = WBT_FRAME_BEGIN;
665 WLog_Print(context->priv->log, WLOG_DEBUG,
"RFX_FRAME_END");
669static inline BOOL rfx_resize_rects(RFX_MESSAGE* WINPR_RESTRICT message)
671 WINPR_ASSERT(message);
674 winpr_aligned_recalloc(message->rects, message->numRects,
sizeof(
RFX_RECT), 32);
677 message->rects = tmpRects;
681static inline BOOL rfx_process_message_region(RFX_CONTEXT* WINPR_RESTRICT context,
682 RFX_MESSAGE* WINPR_RESTRICT message,
684 UINT16* WINPR_RESTRICT pExpectedBlockType)
686 UINT16 regionType = 0;
687 UINT16 numTileSets = 0;
689 WINPR_ASSERT(context);
690 WINPR_ASSERT(context->priv);
691 WINPR_ASSERT(message);
692 WINPR_ASSERT(pExpectedBlockType);
694 if (*pExpectedBlockType != WBT_REGION)
696 WLog_Print(context->priv->log, WLOG_ERROR,
"message unexpected wants WBT_REGION");
700 *pExpectedBlockType = WBT_EXTENSION;
702 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 3))
705 Stream_Seek_UINT8(s);
706 Stream_Read_UINT16(s, message->numRects);
708 if (message->numRects < 1)
716 message->numRects = 1;
717 if (!rfx_resize_rects(message))
720 message->rects->x = 0;
721 message->rects->y = 0;
722 message->rects->width = context->width;
723 message->rects->height = context->height;
727 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(context->priv->log, s, message->numRects, 8ull))
730 if (!rfx_resize_rects(message))
734 for (UINT16 i = 0; i < message->numRects; i++)
736 RFX_RECT* rect = rfx_message_get_rect(message, i);
738 Stream_Read_UINT16(s, rect->x);
739 Stream_Read_UINT16(s, rect->y);
740 Stream_Read_UINT16(s, rect->width);
741 Stream_Read_UINT16(s, rect->height);
742 WLog_Print(context->priv->log, WLOG_DEBUG,
743 "rect %" PRIu16
" (x,y=%" PRIu16
",%" PRIu16
" w,h=%" PRIu16
" %" PRIu16
").", i,
744 rect->x, rect->y, rect->width, rect->height);
747 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 4))
750 Stream_Read_UINT16(s, regionType);
751 Stream_Read_UINT16(s, numTileSets);
753 if (regionType != CBT_REGION)
755 WLog_Print(context->priv->log, WLOG_ERROR,
"invalid region type 0x%04" PRIX16
"",
760 if (numTileSets != 0x0001)
762 WLog_Print(context->priv->log, WLOG_ERROR,
"invalid number of tilesets (%" PRIu16
")",
773 RFX_CONTEXT* context;
774} RFX_TILE_PROCESS_WORK_PARAM;
776static inline void CALLBACK
777rfx_process_message_tile_work_callback(WINPR_ATTR_UNUSED PTP_CALLBACK_INSTANCE instance,
778 void* context, WINPR_ATTR_UNUSED PTP_WORK work)
780 RFX_TILE_PROCESS_WORK_PARAM* param = (RFX_TILE_PROCESS_WORK_PARAM*)context;
782 rfx_decode_rgb(param->context, param->tile, param->tile->data, 64 * 4);
785static inline BOOL rfx_allocate_tiles(RFX_MESSAGE* WINPR_RESTRICT message,
size_t count,
788 WINPR_ASSERT(message);
791 (
RFX_TILE**)winpr_aligned_recalloc((
void*)message->tiles, count,
sizeof(
RFX_TILE*), 32);
792 if (!tmpTiles && (count != 0))
795 message->tiles = tmpTiles;
797 message->numTiles = WINPR_ASSERTING_INT_CAST(UINT16, count);
800 WINPR_ASSERT(message->numTiles <= count);
802 message->allocatedTiles = count;
807static inline BOOL rfx_process_message_tileset(RFX_CONTEXT* WINPR_RESTRICT context,
808 RFX_MESSAGE* WINPR_RESTRICT message,
810 UINT16* WINPR_RESTRICT pExpectedBlockType)
813 size_t close_cnt = 0;
816 UINT32* quants = NULL;
820 UINT32 blockType = 0;
821 UINT32 tilesDataSize = 0;
822 PTP_WORK* work_objects = NULL;
823 RFX_TILE_PROCESS_WORK_PARAM* params = NULL;
826 WINPR_ASSERT(context);
827 WINPR_ASSERT(context->priv);
828 WINPR_ASSERT(message);
829 WINPR_ASSERT(pExpectedBlockType);
831 if (*pExpectedBlockType != WBT_EXTENSION)
833 WLog_Print(context->priv->log, WLOG_ERROR,
"message unexpected wants a tileset");
837 *pExpectedBlockType = WBT_FRAME_END;
839 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 14))
842 Stream_Read_UINT16(s, subtype);
843 if (subtype != CBT_TILESET)
845 WLog_Print(context->priv->log, WLOG_ERROR,
"invalid subtype, expected CBT_TILESET.");
849 Stream_Seek_UINT16(s);
850 Stream_Seek_UINT16(s);
851 Stream_Read_UINT8(s, context->numQuant);
852 Stream_Seek_UINT8(s);
854 if (context->numQuant < 1)
856 WLog_Print(context->priv->log, WLOG_ERROR,
"no quantization value.");
860 Stream_Read_UINT16(s, numTiles);
867 Stream_Read_UINT32(s, tilesDataSize);
870 winpr_aligned_recalloc(context->quants, context->numQuant, 10 *
sizeof(UINT32), 32)))
873 quants = context->quants = (UINT32*)pmem;
876 if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(context->priv->log, s, context->numQuant, 5ull))
879 for (
size_t i = 0; i < context->numQuant; i++)
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 Stream_Read_UINT8(s, quant);
895 *quants++ = (quant & 0x0F);
896 *quants++ = (quant >> 4);
897 WLog_Print(context->priv->log, WLOG_DEBUG,
898 "quant %" PRIuz
" (%" PRIu32
" %" PRIu32
" %" PRIu32
" %" PRIu32
" %" PRIu32
899 " %" PRIu32
" %" PRIu32
" %" PRIu32
" %" PRIu32
" %" PRIu32
").",
900 i, context->quants[i * 10], context->quants[i * 10 + 1],
901 context->quants[i * 10 + 2], context->quants[i * 10 + 3],
902 context->quants[i * 10 + 4], context->quants[i * 10 + 5],
903 context->quants[i * 10 + 6], context->quants[i * 10 + 7],
904 context->quants[i * 10 + 8], context->quants[i * 10 + 9]);
907 for (
size_t i = 0; i < message->numTiles; i++)
909 ObjectPool_Return(context->priv->TilePool, message->tiles[i]);
910 message->tiles[i] = NULL;
913 if (!rfx_allocate_tiles(message, numTiles, FALSE))
916 if (context->priv->UseThreads)
918 work_objects = (PTP_WORK*)winpr_aligned_calloc(message->numTiles,
sizeof(PTP_WORK), 32);
919 params = (RFX_TILE_PROCESS_WORK_PARAM*)winpr_aligned_recalloc(
920 NULL, message->numTiles,
sizeof(RFX_TILE_PROCESS_WORK_PARAM), 32);
924 winpr_aligned_free(params);
930 winpr_aligned_free((
void*)work_objects);
939 if (Stream_GetRemainingLength(s) >= tilesDataSize)
942 for (
size_t i = 0; i < message->numTiles; i++)
947 if (!(tile = (
RFX_TILE*)ObjectPool_Take(context->priv->TilePool)))
949 WLog_Print(context->priv->log, WLOG_ERROR,
950 "RfxMessageTileSet failed to get tile from object pool");
955 message->tiles[i] = tile;
958 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 6))
960 WLog_Print(context->priv->log, WLOG_ERROR,
961 "RfxMessageTileSet packet too small to read tile %" PRIuz
"/%" PRIu16
"",
962 i, message->numTiles);
967 sub = Stream_StaticInit(&subBuffer, Stream_Pointer(s), Stream_GetRemainingLength(s));
970 Stream_Read_UINT32(sub, blockLen);
972 if (!Stream_SafeSeek(s, blockLen))
977 if ((blockLen < 6 + 13) ||
978 (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, sub, blockLen - 6)))
980 WLog_Print(context->priv->log, WLOG_ERROR,
981 "RfxMessageTileSet not enough bytes to read tile %" PRIuz
"/%" PRIu16
982 " with blocklen=%" PRIu32
"",
983 i, message->numTiles, blockLen);
988 if (blockType != CBT_TILE)
990 WLog_Print(context->priv->log, WLOG_ERROR,
991 "unknown block type 0x%" PRIX32
", expected CBT_TILE (0xCAC3).",
997 Stream_Read_UINT8(sub, tile->quantIdxY);
998 Stream_Read_UINT8(sub, tile->quantIdxCb);
999 Stream_Read_UINT8(sub, tile->quantIdxCr);
1000 if (tile->quantIdxY >= context->numQuant)
1002 WLog_Print(context->priv->log, WLOG_ERROR,
1003 "quantIdxY %" PRIu8
" >= numQuant %" PRIu8, tile->quantIdxY,
1008 if (tile->quantIdxCb >= context->numQuant)
1010 WLog_Print(context->priv->log, WLOG_ERROR,
1011 "quantIdxCb %" PRIu8
" >= numQuant %" PRIu8, tile->quantIdxCb,
1016 if (tile->quantIdxCr >= context->numQuant)
1018 WLog_Print(context->priv->log, WLOG_ERROR,
1019 "quantIdxCr %" PRIu8
" >= numQuant %" PRIu8, tile->quantIdxCr,
1025 Stream_Read_UINT16(sub, tile->xIdx);
1026 Stream_Read_UINT16(sub, tile->yIdx);
1027 Stream_Read_UINT16(sub, tile->YLen);
1028 Stream_Read_UINT16(sub, tile->CbLen);
1029 Stream_Read_UINT16(sub, tile->CrLen);
1030 Stream_GetPointer(sub, tile->YData);
1031 if (!Stream_SafeSeek(sub, tile->YLen))
1036 Stream_GetPointer(sub, tile->CbData);
1037 if (!Stream_SafeSeek(sub, tile->CbLen))
1042 Stream_GetPointer(sub, tile->CrData);
1043 if (!Stream_SafeSeek(sub, tile->CrLen))
1048 tile->x = tile->xIdx * 64;
1049 tile->y = tile->yIdx * 64;
1051 if (context->priv->UseThreads)
1059 params[i].context = context;
1060 params[i].tile = message->tiles[i];
1062 if (!(work_objects[i] = CreateThreadpoolWork(rfx_process_message_tile_work_callback,
1063 (
void*)¶ms[i], NULL)))
1065 WLog_Print(context->priv->log, WLOG_ERROR,
"CreateThreadpoolWork failed.");
1070 SubmitThreadpoolWork(work_objects[i]);
1075 rfx_decode_rgb(context, tile, tile->data, 64 * 4);
1080 if (context->priv->UseThreads)
1082 for (
size_t i = 0; i < close_cnt; i++)
1084 WaitForThreadpoolWorkCallbacks(work_objects[i], FALSE);
1085 CloseThreadpoolWork(work_objects[i]);
1089 winpr_aligned_free((
void*)work_objects);
1090 winpr_aligned_free(params);
1092 for (
size_t i = 0; i < message->numTiles; i++)
1094 if (!(tile = message->tiles[i]))
1097 tile->YLen = tile->CbLen = tile->CrLen = 0;
1098 tile->YData = tile->CbData = tile->CrData = NULL;
1104BOOL rfx_process_message(RFX_CONTEXT* WINPR_RESTRICT context,
const BYTE* WINPR_RESTRICT data,
1105 UINT32 length, UINT32 left, UINT32 top, BYTE* WINPR_RESTRICT dst,
1106 UINT32 dstFormat, UINT32 dstStride, UINT32 dstHeight,
1107 REGION16* WINPR_RESTRICT invalidRegion)
1113 if (!context || !data || !length)
1116 WINPR_ASSERT(context->priv);
1117 RFX_MESSAGE* message = &context->currentMessage;
1119 wStream* s = Stream_StaticConstInit(&inStream, data, length);
1121 while (ok && Stream_GetRemainingLength(s) > 6)
1123 wStream subStreamBuffer = { 0 };
1124 size_t extraBlockLen = 0;
1125 UINT32 blockLen = 0;
1126 UINT32 blockType = 0;
1129 Stream_Read_UINT16(s, blockType);
1130 Stream_Read_UINT32(s, blockLen);
1131 WLog_Print(context->priv->log, WLOG_DEBUG,
"blockType 0x%" PRIX32
" blockLen %" PRIu32
"",
1132 blockType, blockLen);
1136 WLog_Print(context->priv->log, WLOG_ERROR,
"blockLen too small(%" PRIu32
")", blockLen);
1140 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, blockLen - 6))
1143 if (blockType > WBT_CONTEXT && context->decodedHeaderBlocks != RFX_DECODED_HEADERS)
1145 WLog_Print(context->priv->log, WLOG_ERROR,
"incomplete header blocks processing");
1149 if (blockType >= WBT_CONTEXT && blockType <= WBT_EXTENSION)
1153 UINT8 channelId = 0;
1155 if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 2))
1159 Stream_Read_UINT8(s, codecId);
1160 Stream_Read_UINT8(s, channelId);
1162 if (codecId != 0x01)
1164 WLog_Print(context->priv->log, WLOG_ERROR,
"invalid codecId 0x%02" PRIX8
"",
1169 if (blockType == WBT_CONTEXT)
1172 if (channelId != 0xFF)
1174 WLog_Print(context->priv->log, WLOG_ERROR,
1175 "invalid channelId 0x%02" PRIX8
" for blockType 0x%08" PRIX32
"",
1176 channelId, blockType);
1183 if (channelId != 0x00)
1185 WLog_Print(context->priv->log, WLOG_ERROR,
1186 "invalid channelId 0x%02" PRIX8
" for blockType WBT_CONTEXT",
1193 const size_t blockLenNoHeader = blockLen - 6;
1194 if (blockLenNoHeader < extraBlockLen)
1196 WLog_Print(context->priv->log, WLOG_ERROR,
1197 "blockLen too small(%" PRIu32
"), must be >= 6 + %" PRIuz, blockLen,
1202 const size_t subStreamLen = blockLenNoHeader - extraBlockLen;
1203 wStream* subStream = Stream_StaticInit(&subStreamBuffer, Stream_Pointer(s), subStreamLen);
1204 Stream_Seek(s, subStreamLen);
1213 ok = rfx_process_message_sync(context, subStream);
1217 ok = rfx_process_message_context(context, subStream);
1220 case WBT_CODEC_VERSIONS:
1221 ok = rfx_process_message_codec_versions(context, subStream);
1225 ok = rfx_process_message_channels(context, subStream);
1235 case WBT_FRAME_BEGIN:
1236 ok = rfx_process_message_frame_begin(context, message, subStream,
1237 &context->expectedDataBlockType);
1241 ok = rfx_process_message_region(context, message, subStream,
1242 &context->expectedDataBlockType);
1246 ok = rfx_process_message_tileset(context, message, subStream,
1247 &context->expectedDataBlockType);
1251 ok = rfx_process_message_frame_end(context, message, subStream,
1252 &context->expectedDataBlockType);
1256 WLog_Print(context->priv->log, WLOG_ERROR,
"unknown blockType 0x%" PRIX32
"",
1264 UINT32 nbUpdateRects = 0;
1267 const DWORD formatSize = FreeRDPGetBytesPerPixel(context->pixel_format);
1268 const UINT32 dstWidth = dstStride / FreeRDPGetBytesPerPixel(dstFormat);
1269 region16_init(&clippingRects);
1271 WINPR_ASSERT(dstWidth <= UINT16_MAX);
1272 WINPR_ASSERT(dstHeight <= UINT16_MAX);
1273 for (UINT32 i = 0; i < message->numRects; i++)
1276 const RFX_RECT* rect = &(message->rects[i]);
1278 WINPR_ASSERT(left + rect->x <= UINT16_MAX);
1279 WINPR_ASSERT(top + rect->y <= UINT16_MAX);
1280 WINPR_ASSERT(clippingRect.left + rect->width <= UINT16_MAX);
1281 WINPR_ASSERT(clippingRect.top + rect->height <= UINT16_MAX);
1283 clippingRect.left = WINPR_ASSERTING_INT_CAST(UINT16, MIN(left + rect->x, dstWidth));
1284 clippingRect.top = WINPR_ASSERTING_INT_CAST(UINT16, MIN(top + rect->y, dstHeight));
1286 const UINT32 rw = 1UL * clippingRect.left + rect->width;
1287 const UINT32 rh = 1UL * clippingRect.top + rect->height;
1288 const uint16_t right = WINPR_ASSERTING_INT_CAST(UINT16, MIN(rw, dstWidth));
1289 const uint16_t bottom = WINPR_ASSERTING_INT_CAST(UINT16, MIN(rh, dstHeight));
1290 clippingRect.right = right;
1291 clippingRect.bottom = bottom;
1292 region16_union_rect(&clippingRects, &clippingRects, &clippingRect);
1295 for (UINT32 i = 0; i < message->numTiles; i++)
1298 const RFX_TILE* tile = rfx_message_get_tile(message, i);
1300 WINPR_ASSERT(left + tile->x <= UINT16_MAX);
1301 WINPR_ASSERT(top + tile->y <= UINT16_MAX);
1303 updateRect.left = (UINT16)left + tile->x;
1304 updateRect.top = (UINT16)top + tile->y;
1305 updateRect.right = updateRect.left + 64;
1306 updateRect.bottom = updateRect.top + 64;
1307 region16_init(&updateRegion);
1308 region16_intersect_rect(&updateRegion, &clippingRects, &updateRect);
1309 updateRects = region16_rects(&updateRegion, &nbUpdateRects);
1311 for (UINT32 j = 0; j < nbUpdateRects; j++)
1314 const UINT32 stride = 64 * formatSize;
1315 const UINT32 nXDst = cur->left;
1316 const UINT32 nYDst = cur->top;
1317 const UINT32 nXSrc = nXDst - updateRect.left;
1318 const UINT32 nYSrc = nYDst - updateRect.top;
1319 const UINT32 nWidth = cur->right - cur->left;
1320 const UINT32 nHeight = cur->bottom - cur->top;
1322 if (!freerdp_image_copy_no_overlap(dst, dstFormat, dstStride, nXDst, nYDst, nWidth,
1323 nHeight, tile->data, context->pixel_format,
1324 stride, nXSrc, nYSrc, NULL, FREERDP_FLIP_NONE))
1326 region16_uninit(&updateRegion);
1327 region16_uninit(&clippingRects);
1328 WLog_Print(context->priv->log, WLOG_ERROR,
1329 "nbUpdateRectx[%" PRIu32
" (%" PRIu32
")] freerdp_image_copy failed",
1335 region16_union_rect(invalidRegion, invalidRegion, cur);
1338 region16_uninit(&updateRegion);
1341 region16_uninit(&clippingRects);
1346 rfx_message_free(context, message);
1347 context->currentMessage.freeArray = TRUE;
1350 WLog_Print(context->priv->log, WLOG_ERROR,
"failed");
1354const UINT32* rfx_message_get_quants(
const RFX_MESSAGE* WINPR_RESTRICT message,
1355 UINT16* WINPR_RESTRICT numQuantVals)
1357 WINPR_ASSERT(message);
1359 *numQuantVals = message->numQuant;
1360 return message->quantVals;
1363const RFX_TILE** rfx_message_get_tiles(
const RFX_MESSAGE* WINPR_RESTRICT message,
1364 UINT16* WINPR_RESTRICT numTiles)
1366 WINPR_ASSERT(message);
1368 *numTiles = message->numTiles;
1375 cnv.pp = message->tiles;
1379UINT16 rfx_message_get_tile_count(
const RFX_MESSAGE* WINPR_RESTRICT message)
1381 WINPR_ASSERT(message);
1382 return message->numTiles;
1385const RFX_RECT* rfx_message_get_rects(
const RFX_MESSAGE* WINPR_RESTRICT message,
1386 UINT16* WINPR_RESTRICT numRects)
1388 WINPR_ASSERT(message);
1390 *numRects = message->numRects;
1391 return message->rects;
1394UINT16 rfx_message_get_rect_count(
const RFX_MESSAGE* WINPR_RESTRICT message)
1396 WINPR_ASSERT(message);
1397 return message->numRects;
1400void rfx_message_free(RFX_CONTEXT* WINPR_RESTRICT context, RFX_MESSAGE* WINPR_RESTRICT message)
1405 winpr_aligned_free(message->rects);
1409 for (
size_t i = 0; i < message->numTiles; i++)
1411 RFX_TILE* tile = message->tiles[i];
1415 if (tile->YCbCrData)
1417 BufferPool_Return(context->priv->BufferPool, tile->YCbCrData);
1418 tile->YCbCrData = NULL;
1421 ObjectPool_Return(context->priv->TilePool, (
void*)tile);
1424 rfx_allocate_tiles(message, 0, FALSE);
1427 const BOOL freeArray = message->freeArray;
1428 const RFX_MESSAGE empty = { 0 };
1432 winpr_aligned_free(message);
1435static inline void rfx_update_context_properties(RFX_CONTEXT* WINPR_RESTRICT context)
1437 UINT16 properties = 0;
1439 WINPR_ASSERT(context);
1442 properties |= (context->flags << 1);
1443 properties |= (COL_CONV_ICT << 4);
1444 properties |= (CLW_XFORM_DWT_53_A << 6);
1445 properties |= ((context->mode == RLGR1 ? CLW_ENTROPY_RLGR1 : CLW_ENTROPY_RLGR3) << 10);
1446 properties |= (SCALAR_QUANTIZATION << 14);
1447 context->properties = properties;
1451rfx_write_message_sync(WINPR_ATTR_UNUSED
const RFX_CONTEXT* WINPR_RESTRICT context,
1452 WINPR_ATTR_UNUSED
wStream* WINPR_RESTRICT s)
1454 WINPR_ASSERT(context);
1456 Stream_Write_UINT16(s, WBT_SYNC);
1457 Stream_Write_UINT32(s, 12);
1458 Stream_Write_UINT32(s, WF_MAGIC);
1459 Stream_Write_UINT16(s, WF_VERSION_1_0);
1463rfx_write_message_codec_versions(WINPR_ATTR_UNUSED
const RFX_CONTEXT* WINPR_RESTRICT context,
1466 WINPR_ASSERT(context);
1468 Stream_Write_UINT16(s, WBT_CODEC_VERSIONS);
1469 Stream_Write_UINT32(s, 10);
1470 Stream_Write_UINT8(s, 1);
1471 Stream_Write_UINT8(s, 1);
1472 Stream_Write_UINT16(s, WF_VERSION_1_0);
1475static inline void rfx_write_message_channels(
const RFX_CONTEXT* WINPR_RESTRICT context,
1478 WINPR_ASSERT(context);
1480 Stream_Write_UINT16(s, WBT_CHANNELS);
1481 Stream_Write_UINT32(s, 12);
1482 Stream_Write_UINT8(s, 1);
1483 Stream_Write_UINT8(s, 0);
1484 Stream_Write_UINT16(s, context->width);
1485 Stream_Write_UINT16(s, context->height);
1488static inline void rfx_write_message_context(RFX_CONTEXT* WINPR_RESTRICT context,
1491 UINT16 properties = 0;
1492 WINPR_ASSERT(context);
1494 Stream_Write_UINT16(s, WBT_CONTEXT);
1495 Stream_Write_UINT32(s, 13);
1496 Stream_Write_UINT8(s, 1);
1497 Stream_Write_UINT8(s, 0xFF);
1498 Stream_Write_UINT8(s, 0);
1499 Stream_Write_UINT16(s, CT_TILE_64x64);
1501 properties = context->flags;
1502 properties |= (COL_CONV_ICT << 3);
1503 properties |= (CLW_XFORM_DWT_53_A << 5);
1504 properties |= ((context->mode == RLGR1 ? CLW_ENTROPY_RLGR1 : CLW_ENTROPY_RLGR3) << 9);
1505 properties |= (SCALAR_QUANTIZATION << 13);
1506 Stream_Write_UINT16(s, properties);
1507 rfx_update_context_properties(context);
1510static inline BOOL rfx_compose_message_header(RFX_CONTEXT* WINPR_RESTRICT context,
1513 WINPR_ASSERT(context);
1514 if (!Stream_EnsureRemainingCapacity(s, 12 + 10 + 12 + 13))
1517 rfx_write_message_sync(context, s);
1518 rfx_write_message_context(context, s);
1519 rfx_write_message_codec_versions(context, s);
1520 rfx_write_message_channels(context, s);
1524static inline size_t rfx_tile_length(
const RFX_TILE* WINPR_RESTRICT tile)
1527 return 19ull + tile->YLen + tile->CbLen + tile->CrLen;
1530static inline BOOL rfx_write_tile(
wStream* WINPR_RESTRICT s,
const RFX_TILE* WINPR_RESTRICT tile)
1532 const size_t blockLen = rfx_tile_length(tile);
1533 if (blockLen > UINT32_MAX)
1535 if (!Stream_EnsureRemainingCapacity(s, blockLen))
1538 Stream_Write_UINT16(s, CBT_TILE);
1539 Stream_Write_UINT32(s, (UINT32)blockLen);
1540 Stream_Write_UINT8(s, tile->quantIdxY);
1541 Stream_Write_UINT8(s, tile->quantIdxCb);
1542 Stream_Write_UINT8(s, tile->quantIdxCr);
1543 Stream_Write_UINT16(s, tile->xIdx);
1544 Stream_Write_UINT16(s, tile->yIdx);
1545 Stream_Write_UINT16(s, tile->YLen);
1546 Stream_Write_UINT16(s, tile->CbLen);
1547 Stream_Write_UINT16(s, tile->CrLen);
1548 Stream_Write(s, tile->YData, tile->YLen);
1549 Stream_Write(s, tile->CbData, tile->CbLen);
1550 Stream_Write(s, tile->CrData, tile->CrLen);
1554struct S_RFX_TILE_COMPOSE_WORK_PARAM
1557 RFX_CONTEXT* context;
1560static inline void CALLBACK
1561rfx_compose_message_tile_work_callback(WINPR_ATTR_UNUSED PTP_CALLBACK_INSTANCE instance,
1562 void* context, WINPR_ATTR_UNUSED PTP_WORK work)
1564 RFX_TILE_COMPOSE_WORK_PARAM* param = (RFX_TILE_COMPOSE_WORK_PARAM*)context;
1565 WINPR_ASSERT(param);
1566 rfx_encode_rgb(param->context, param->tile);
1569static inline BOOL computeRegion(
const RFX_RECT* WINPR_RESTRICT rects,
size_t numRects,
1570 REGION16* WINPR_RESTRICT region,
size_t width,
size_t height)
1572 const RECTANGLE_16 mainRect = { 0, 0, WINPR_ASSERTING_INT_CAST(UINT16, width),
1573 WINPR_ASSERTING_INT_CAST(UINT16, height) };
1575 WINPR_ASSERT(rects);
1576 for (
size_t i = 0; i < numRects; i++)
1580 rect16.left = rect->x;
1581 rect16.top = rect->y;
1582 rect16.right = rect->x + rect->width;
1583 rect16.bottom = rect->y + rect->height;
1585 if (!region16_union_rect(region, region, &rect16))
1589 return region16_intersect_rect(region, region, &mainRect);
1592#define TILE_NO(v) ((v) / 64)
1594static inline BOOL setupWorkers(RFX_CONTEXT* WINPR_RESTRICT context,
size_t nbTiles)
1596 WINPR_ASSERT(context);
1598 RFX_CONTEXT_PRIV* priv = context->priv;
1603 if (!context->priv->UseThreads)
1606 if (!(pmem = winpr_aligned_recalloc((
void*)priv->workObjects, nbTiles,
sizeof(PTP_WORK), 32)))
1609 priv->workObjects = (PTP_WORK*)pmem;
1611 if (!(pmem = winpr_aligned_recalloc(priv->tileWorkParams, nbTiles,
1612 sizeof(RFX_TILE_COMPOSE_WORK_PARAM), 32)))
1615 priv->tileWorkParams = (RFX_TILE_COMPOSE_WORK_PARAM*)pmem;
1619static inline BOOL rfx_ensure_tiles(RFX_MESSAGE* WINPR_RESTRICT message,
size_t count)
1621 WINPR_ASSERT(message);
1623 if (message->numTiles + count <= message->allocatedTiles)
1626 const size_t alloc = MAX(message->allocatedTiles + 1024, message->numTiles + count);
1627 return rfx_allocate_tiles(message, alloc, TRUE);
1630RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* WINPR_RESTRICT context,
1631 const RFX_RECT* WINPR_RESTRICT rects,
size_t numRects,
1632 const BYTE* WINPR_RESTRICT data, UINT32 w, UINT32 h,
size_t s)
1634 const UINT32 width = w;
1635 const UINT32 height = h;
1636 const UINT32 scanline = (UINT32)s;
1637 RFX_MESSAGE* message = NULL;
1638 PTP_WORK* workObject = NULL;
1639 RFX_TILE_COMPOSE_WORK_PARAM* workParam = NULL;
1640 BOOL success = FALSE;
1647 WINPR_ASSERT(rects);
1648 WINPR_ASSERT(numRects > 0);
1649 WINPR_ASSERT(w > 0);
1650 WINPR_ASSERT(h > 0);
1651 WINPR_ASSERT(s > 0);
1653 if (!(message = (RFX_MESSAGE*)winpr_aligned_calloc(1,
sizeof(RFX_MESSAGE), 32)))
1656 region16_init(&tilesRegion);
1657 region16_init(&rectsRegion);
1659 if (context->state == RFX_STATE_SEND_HEADERS)
1660 rfx_update_context_properties(context);
1662 message->frameIdx = context->frameIdx++;
1664 if (!context->numQuant)
1666 WINPR_ASSERT(context->quants == NULL);
1667 if (!(context->quants =
1668 (UINT32*)winpr_aligned_malloc(
sizeof(rfx_default_quantization_values), 32)))
1669 goto skip_encoding_loop;
1671 CopyMemory(context->quants, &rfx_default_quantization_values,
1672 sizeof(rfx_default_quantization_values));
1673 context->numQuant = 1;
1674 context->quantIdxY = 0;
1675 context->quantIdxCb = 0;
1676 context->quantIdxCr = 0;
1679 message->numQuant = context->numQuant;
1680 message->quantVals = context->quants;
1683 const UINT32 bytesPerPixel = (context->bits_per_pixel / 8);
1684 if (!computeRegion(rects, numRects, &rectsRegion, width, height))
1685 goto skip_encoding_loop;
1688 const RECTANGLE_16* extents = region16_extents(&rectsRegion);
1689 WINPR_ASSERT((INT32)extents->right - extents->left > 0);
1690 WINPR_ASSERT((INT32)extents->bottom - extents->top > 0);
1691 const UINT32 maxTilesX = 1 + TILE_NO(extents->right - 1) - TILE_NO(extents->left);
1692 const UINT32 maxTilesY = 1 + TILE_NO(extents->bottom - 1) - TILE_NO(extents->top);
1693 const UINT32 maxNbTiles = maxTilesX * maxTilesY;
1695 if (!rfx_ensure_tiles(message, maxNbTiles))
1696 goto skip_encoding_loop;
1698 if (!setupWorkers(context, maxNbTiles))
1699 goto skip_encoding_loop;
1702 if (context->priv->UseThreads)
1704 workObject = context->priv->workObjects;
1705 workParam = context->priv->tileWorkParams;
1709 UINT32 regionNbRects = 0;
1710 regionRect = region16_rects(&rectsRegion, ®ionNbRects);
1712 if (!(message->rects = winpr_aligned_calloc(regionNbRects,
sizeof(
RFX_RECT), 32)))
1713 goto skip_encoding_loop;
1715 message->numRects = WINPR_ASSERTING_INT_CAST(UINT16, regionNbRects);
1717 for (UINT32 i = 0; i < regionNbRects; i++, regionRect++)
1719 RFX_RECT* rfxRect = &message->rects[i];
1720 UINT32 startTileX = regionRect->left / 64;
1721 UINT32 endTileX = (regionRect->right - 1) / 64;
1722 UINT32 startTileY = regionRect->top / 64;
1723 UINT32 endTileY = (regionRect->bottom - 1) / 64;
1724 rfxRect->x = regionRect->left;
1725 rfxRect->y = regionRect->top;
1726 rfxRect->width = (regionRect->right - regionRect->left);
1727 rfxRect->height = (regionRect->bottom - regionRect->top);
1729 for (UINT32 yIdx = startTileY, gridRelY = startTileY * 64; yIdx <= endTileY;
1730 yIdx++, gridRelY += 64)
1732 UINT32 tileHeight = 64;
1734 if ((yIdx == endTileY) && (gridRelY + 64 > height))
1735 tileHeight = height - gridRelY;
1737 currentTileRect.top = WINPR_ASSERTING_INT_CAST(UINT16, gridRelY);
1738 currentTileRect.bottom =
1739 WINPR_ASSERTING_INT_CAST(UINT16, gridRelY + tileHeight);
1741 for (UINT32 xIdx = startTileX, gridRelX = startTileX * 64; xIdx <= endTileX;
1742 xIdx++, gridRelX += 64)
1749 UINT32 tileWidth = 64;
1751 if ((xIdx == endTileX) && (gridRelX + 64 > width))
1753 tileWidth = (width - gridRelX);
1756 currentTileRect.left = WINPR_ASSERTING_INT_CAST(UINT16, gridRelX);
1757 currentTileRect.right =
1758 WINPR_ASSERTING_INT_CAST(UINT16, gridRelX + tileWidth);
1761 if (region16_intersects_rect(&tilesRegion, ¤tTileRect))
1766 goto skip_encoding_loop;
1768 tile->xIdx = WINPR_ASSERTING_INT_CAST(UINT16, xIdx);
1769 tile->yIdx = WINPR_ASSERTING_INT_CAST(UINT16, yIdx);
1770 tile->x = WINPR_ASSERTING_INT_CAST(UINT16, gridRelX);
1771 tile->y = WINPR_ASSERTING_INT_CAST(UINT16, gridRelY);
1772 tile->scanline = scanline;
1774 tile->width = tileWidth;
1775 tile->height = tileHeight;
1776 const UINT32 ax = gridRelX;
1777 const UINT32 ay = gridRelY;
1779 if (tile->data && tile->allocated)
1781 winpr_aligned_free(tile->data);
1782 tile->allocated = FALSE;
1786 cnv.cpv = &data[(ay * scanline) + (ax * bytesPerPixel)];
1787 tile->data = cnv.pv;
1788 tile->quantIdxY = context->quantIdxY;
1789 tile->quantIdxCb = context->quantIdxCb;
1790 tile->quantIdxCr = context->quantIdxCr;
1791 tile->YLen = tile->CbLen = tile->CrLen = 0;
1793 if (!(tile->YCbCrData =
1794 (BYTE*)BufferPool_Take(context->priv->BufferPool, -1)))
1795 goto skip_encoding_loop;
1797 tile->YData = &(tile->YCbCrData[((8192 + 32) * 0) + 16]);
1798 tile->CbData = &(tile->YCbCrData[((8192 + 32) * 1) + 16]);
1799 tile->CrData = &(tile->YCbCrData[((8192 + 32) * 2) + 16]);
1801 if (!rfx_ensure_tiles(message, 1))
1802 goto skip_encoding_loop;
1803 message->tiles[message->numTiles++] = tile;
1805 if (context->priv->UseThreads)
1807 workParam->context = context;
1808 workParam->tile = tile;
1811 CreateThreadpoolWork(rfx_compose_message_tile_work_callback,
1812 (
void*)workParam, NULL)))
1814 goto skip_encoding_loop;
1817 SubmitThreadpoolWork(*workObject);
1823 rfx_encode_rgb(context, tile);
1826 if (!region16_union_rect(&tilesRegion, &tilesRegion, ¤tTileRect))
1827 goto skip_encoding_loop;
1840 message->tilesDataSize = 0;
1841 workObject = context->priv->workObjects;
1843 for (UINT32 i = 0; i < message->numTiles; i++)
1845 if (context->priv->UseThreads)
1849 WaitForThreadpoolWorkCallbacks(*workObject, FALSE);
1850 CloseThreadpoolWork(*workObject);
1856 const RFX_TILE* tile = message->tiles[i];
1857 const size_t tlen = rfx_tile_length(tile);
1858 message->tilesDataSize += WINPR_ASSERTING_INT_CAST(uint32_t, tlen);
1861 region16_uninit(&tilesRegion);
1862 region16_uninit(&rectsRegion);
1867 WLog_Print(context->priv->log, WLOG_ERROR,
"failed");
1869 rfx_message_free(context, message);
1870 region16_uninit(&tilesRegion);
1871 region16_uninit(&rectsRegion);
1875static 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];
1898static 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;
1917static 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 += WINPR_ASSERTING_INT_CAST(uint32_t, 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);
1979const 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];
1988void 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]);
1997static 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;
2011RFX_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);
2033static 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);
2053 s, WINPR_ASSERTING_INT_CAST(uint8_t, message->numQuant));
2054 Stream_Write_UINT8(s, 0x40);
2055 Stream_Write_UINT16(s, message->numTiles);
2056 Stream_Write_UINT32(s, message->tilesDataSize);
2058 UINT32* quantVals = message->quantVals;
2059 for (
size_t i = 0; i < message->numQuant * 5ul; i++)
2061 WINPR_ASSERT(quantVals);
2062 Stream_Write_UINT8(s,
2063 WINPR_ASSERTING_INT_CAST(uint8_t, quantVals[0] + (quantVals[1] << 4)));
2067 for (
size_t i = 0; i < message->numTiles; i++)
2069 RFX_TILE* tile = message->tiles[i];
2073 if (!rfx_write_tile(s, tile))
2077#ifdef WITH_DEBUG_RFX
2078 WLog_Print(context->priv->log, WLOG_DEBUG,
2079 "numQuant: %" PRIu16
" numTiles: %" PRIu16
" tilesDataSize: %" PRIu32
"",
2080 message->numQuant, message->numTiles, message->tilesDataSize);
2086rfx_write_message_frame_begin(WINPR_ATTR_UNUSED RFX_CONTEXT* WINPR_RESTRICT context,
2087 wStream* WINPR_RESTRICT s,
const RFX_MESSAGE* WINPR_RESTRICT message)
2089 WINPR_ASSERT(context);
2090 WINPR_ASSERT(message);
2092 if (!Stream_EnsureRemainingCapacity(s, 14))
2095 Stream_Write_UINT16(s, WBT_FRAME_BEGIN);
2096 Stream_Write_UINT32(s, 14);
2097 Stream_Write_UINT8(s, 1);
2098 Stream_Write_UINT8(s, 0);
2099 Stream_Write_UINT32(s, message->frameIdx);
2100 Stream_Write_UINT16(s, 1);
2104static inline BOOL rfx_write_message_region(WINPR_ATTR_UNUSED RFX_CONTEXT* WINPR_RESTRICT context,
2106 const RFX_MESSAGE* WINPR_RESTRICT message)
2108 WINPR_ASSERT(context);
2109 WINPR_ASSERT(message);
2111 const size_t blockLen = 15 + (message->numRects * 8);
2112 if (blockLen > UINT32_MAX)
2115 if (!Stream_EnsureRemainingCapacity(s, blockLen))
2118 Stream_Write_UINT16(s, WBT_REGION);
2119 Stream_Write_UINT32(s, (UINT32)blockLen);
2120 Stream_Write_UINT8(s, 1);
2121 Stream_Write_UINT8(s, 0);
2122 Stream_Write_UINT8(s, 1);
2123 Stream_Write_UINT16(s, message->numRects);
2125 for (UINT16 i = 0; i < message->numRects; i++)
2127 const RFX_RECT* rect = rfx_message_get_rect_const(message, i);
2131 Stream_Write_UINT16(s, rect->x);
2132 Stream_Write_UINT16(s, rect->y);
2133 Stream_Write_UINT16(s, rect->width);
2134 Stream_Write_UINT16(s, rect->height);
2137 Stream_Write_UINT16(s, CBT_REGION);
2138 Stream_Write_UINT16(s, 1);
2143rfx_write_message_frame_end(WINPR_ATTR_UNUSED RFX_CONTEXT* WINPR_RESTRICT context,
2145 WINPR_ATTR_UNUSED
const RFX_MESSAGE* WINPR_RESTRICT message)
2147 WINPR_ASSERT(context);
2148 WINPR_ASSERT(message);
2150 if (!Stream_EnsureRemainingCapacity(s, 8))
2153 Stream_Write_UINT16(s, WBT_FRAME_END);
2154 Stream_Write_UINT32(s, 8);
2155 Stream_Write_UINT8(s, 1);
2156 Stream_Write_UINT8(s, 0);
2160BOOL rfx_write_message(RFX_CONTEXT* WINPR_RESTRICT context,
wStream* WINPR_RESTRICT s,
2161 const RFX_MESSAGE* WINPR_RESTRICT message)
2163 WINPR_ASSERT(context);
2164 WINPR_ASSERT(message);
2166 if (context->state == RFX_STATE_SEND_HEADERS)
2168 if (!rfx_compose_message_header(context, s))
2171 context->state = RFX_STATE_SEND_FRAME_DATA;
2174 if (!rfx_write_message_frame_begin(context, s, message) ||
2175 !rfx_write_message_region(context, s, message) ||
2176 !rfx_write_message_tileset(context, s, message) ||
2177 !rfx_write_message_frame_end(context, s, message))
2185BOOL rfx_compose_message(RFX_CONTEXT* WINPR_RESTRICT context,
wStream* WINPR_RESTRICT s,
2186 const RFX_RECT* WINPR_RESTRICT rects,
size_t numRects,
2187 const BYTE* WINPR_RESTRICT data, UINT32 width, UINT32 height,
2190 WINPR_ASSERT(context);
2191 RFX_MESSAGE* message =
2192 rfx_encode_message(context, rects, numRects, data, width, height, scanline);
2196 const BOOL ret = rfx_write_message(context, s, message);
2197 rfx_message_free(context, message);
2201BOOL rfx_context_set_mode(RFX_CONTEXT* WINPR_RESTRICT context, RLGR_MODE mode)
2203 WINPR_ASSERT(context);
2204 context->mode = mode;
2208RLGR_MODE rfx_context_get_mode(RFX_CONTEXT* WINPR_RESTRICT context)
2210 WINPR_ASSERT(context);
2211 return context->mode;
2214UINT32 rfx_context_get_frame_idx(
const RFX_CONTEXT* WINPR_RESTRICT context)
2216 WINPR_ASSERT(context);
2217 return context->frameIdx;
2220UINT32 rfx_message_get_frame_idx(
const RFX_MESSAGE* WINPR_RESTRICT message)
2222 WINPR_ASSERT(message);
2223 return message->frameIdx;
2226static inline BOOL rfx_write_progressive_wb_sync(WINPR_ATTR_UNUSED RFX_CONTEXT* WINPR_RESTRICT rfx,
2229 const UINT32 blockLen = 12;
2233 if (!Stream_EnsureRemainingCapacity(s, blockLen))
2236 Stream_Write_UINT16(s, PROGRESSIVE_WBT_SYNC);
2237 Stream_Write_UINT32(s, blockLen);
2238 Stream_Write_UINT32(s, 0xCACCACCA);
2239 Stream_Write_UINT16(s, 0x0100);
2244rfx_write_progressive_wb_context(WINPR_ATTR_UNUSED RFX_CONTEXT* WINPR_RESTRICT rfx,
2247 const UINT32 blockLen = 10;
2251 if (!Stream_EnsureRemainingCapacity(s, blockLen))
2254 Stream_Write_UINT16(s, PROGRESSIVE_WBT_CONTEXT);
2255 Stream_Write_UINT32(s, blockLen);
2256 Stream_Write_UINT8(s, 0);
2257 Stream_Write_UINT16(s, 64);
2258 Stream_Write_UINT8(s, 0);
2262static inline BOOL rfx_write_progressive_region(RFX_CONTEXT* WINPR_RESTRICT rfx,
2264 const RFX_MESSAGE* WINPR_RESTRICT msg)
2267 UINT32 blockLen = 18;
2268 UINT32 tilesDataSize = 0;
2269 const size_t start = Stream_GetPosition(s);
2275 blockLen += msg->numRects * 8;
2276 blockLen += msg->numQuant * 5;
2277 tilesDataSize = msg->numTiles * 22UL;
2278 for (UINT16 i = 0; i < msg->numTiles; i++)
2280 const RFX_TILE* tile = msg->tiles[i];
2282 tilesDataSize += tile->YLen + tile->CbLen + tile->CrLen;
2284 blockLen += tilesDataSize;
2286 if (!Stream_EnsureRemainingCapacity(s, blockLen))
2289 Stream_Write_UINT16(s, PROGRESSIVE_WBT_REGION);
2290 Stream_Write_UINT32(s, blockLen);
2291 Stream_Write_UINT8(s, 64);
2292 Stream_Write_UINT16(s, msg->numRects);
2293 WINPR_ASSERT(msg->numQuant <= UINT8_MAX);
2294 Stream_Write_UINT8(s, (UINT8)msg->numQuant);
2295 Stream_Write_UINT8(s, 0);
2296 Stream_Write_UINT8(s, 0);
2297 Stream_Write_UINT16(s, msg->numTiles);
2298 Stream_Write_UINT32(s, tilesDataSize);
2300 for (UINT16 i = 0; i < msg->numRects; i++)
2303 const RFX_RECT* r = &msg->rects[i];
2304 Stream_Write_UINT16(s, r->x);
2305 Stream_Write_UINT16(s, r->y);
2306 Stream_Write_UINT16(s, r->width);
2307 Stream_Write_UINT16(s, r->height);
2318 for (UINT16 i = 0; i < msg->numQuant; i++)
2320 const UINT32* qv = &msg->quantVals[10ULL * i];
2322 Stream_Write_UINT8(s, (UINT8)(qv[0] + (qv[2] << 4)));
2323 Stream_Write_UINT8(s, (UINT8)(qv[1] + (qv[3] << 4)));
2324 Stream_Write_UINT8(s, (UINT8)(qv[5] + (qv[4] << 4)));
2325 Stream_Write_UINT8(s, (UINT8)(qv[6] + (qv[8] << 4)));
2326 Stream_Write_UINT8(s, (UINT8)(qv[7] + (qv[9] << 4)));
2329 for (UINT16 i = 0; i < msg->numTiles; i++)
2331 const RFX_TILE* tile = msg->tiles[i];
2332 if (!rfx_write_progressive_tile_simple(rfx, s, tile))
2336 const size_t end = Stream_GetPosition(s);
2337 const size_t used = end - start;
2338 return (used == blockLen);
2342rfx_write_progressive_frame_begin(WINPR_ATTR_UNUSED RFX_CONTEXT* WINPR_RESTRICT rfx,
2343 wStream* WINPR_RESTRICT s,
const RFX_MESSAGE* WINPR_RESTRICT msg)
2345 const UINT32 blockLen = 12;
2350 if (!Stream_EnsureRemainingCapacity(s, blockLen))
2353 Stream_Write_UINT16(s, PROGRESSIVE_WBT_FRAME_BEGIN);
2354 Stream_Write_UINT32(s, blockLen);
2355 Stream_Write_UINT32(s, msg->frameIdx);
2356 Stream_Write_UINT16(s, 1);
2362rfx_write_progressive_frame_end(WINPR_ATTR_UNUSED RFX_CONTEXT* WINPR_RESTRICT rfx,
2365 const UINT32 blockLen = 6;
2369 if (!Stream_EnsureRemainingCapacity(s, blockLen))
2372 Stream_Write_UINT16(s, PROGRESSIVE_WBT_FRAME_END);
2373 Stream_Write_UINT32(s, blockLen);
2379rfx_write_progressive_tile_simple(WINPR_ATTR_UNUSED RFX_CONTEXT* WINPR_RESTRICT rfx,
2382 UINT32 blockLen = 0;
2387 blockLen = 22 + tile->YLen + tile->CbLen + tile->CrLen;
2388 if (!Stream_EnsureRemainingCapacity(s, blockLen))
2391 Stream_Write_UINT16(s, PROGRESSIVE_WBT_TILE_SIMPLE);
2392 Stream_Write_UINT32(s, blockLen);
2393 Stream_Write_UINT8(s, tile->quantIdxY);
2394 Stream_Write_UINT8(s, tile->quantIdxCb);
2395 Stream_Write_UINT8(s, tile->quantIdxCr);
2396 Stream_Write_UINT16(s, tile->xIdx);
2397 Stream_Write_UINT16(s, tile->yIdx);
2398 Stream_Write_UINT8(s, 0);
2399 Stream_Write_UINT16(s, tile->YLen);
2400 Stream_Write_UINT16(s, tile->CbLen);
2401 Stream_Write_UINT16(s, tile->CrLen);
2402 Stream_Write_UINT16(s, 0);
2403 Stream_Write(s, tile->YData, tile->YLen);
2404 Stream_Write(s, tile->CbData, tile->CbLen);
2405 Stream_Write(s, tile->CrData, tile->CrLen);
2410const char* rfx_get_progressive_block_type_string(UINT16 blockType)
2414 case PROGRESSIVE_WBT_SYNC:
2415 return "PROGRESSIVE_WBT_SYNC";
2417 case PROGRESSIVE_WBT_FRAME_BEGIN:
2418 return "PROGRESSIVE_WBT_FRAME_BEGIN";
2420 case PROGRESSIVE_WBT_FRAME_END:
2421 return "PROGRESSIVE_WBT_FRAME_END";
2423 case PROGRESSIVE_WBT_CONTEXT:
2424 return "PROGRESSIVE_WBT_CONTEXT";
2426 case PROGRESSIVE_WBT_REGION:
2427 return "PROGRESSIVE_WBT_REGION";
2429 case PROGRESSIVE_WBT_TILE_SIMPLE:
2430 return "PROGRESSIVE_WBT_TILE_SIMPLE";
2432 case PROGRESSIVE_WBT_TILE_FIRST:
2433 return "PROGRESSIVE_WBT_TILE_FIRST";
2435 case PROGRESSIVE_WBT_TILE_UPGRADE:
2436 return "PROGRESSIVE_WBT_TILE_UPGRADE";
2439 return "PROGRESSIVE_WBT_UNKNOWN";
2443BOOL rfx_write_message_progressive_simple(RFX_CONTEXT* WINPR_RESTRICT context,
2445 const RFX_MESSAGE* WINPR_RESTRICT msg)
2449 WINPR_ASSERT(context);
2451 if (context->mode != RLGR1)
2453 WLog_ERR(TAG,
"error, RLGR1 mode is required!");
2457 if (!rfx_write_progressive_wb_sync(context, s))
2460 if (!rfx_write_progressive_wb_context(context, s))
2463 if (!rfx_write_progressive_frame_begin(context, s, msg))
2466 if (!rfx_write_progressive_region(context, s, msg))
2469 if (!rfx_write_progressive_frame_end(context, s))
This struct contains function pointer to initialize/free objects.
OBJECT_FREE_FN fnObjectFree
OBJECT_INIT_FN fnObjectInit
OBJECT_NEW_FN fnObjectNew