2011-08-10 11:13:39 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-08-10 11:13:39 +04:00
|
|
|
* RemoteFX Codec Library
|
|
|
|
*
|
|
|
|
* Copyright 2011 Vic Lee
|
2015-04-24 18:54:49 +03:00
|
|
|
* Copyright 2015 Thincast Technologies GmbH
|
2015-04-23 16:42:21 +03:00
|
|
|
* Copyright 2015 Norbert Federa <norbert.federa@thincast.com>
|
2011-08-10 11:13:39 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-02-16 13:20:38 +03:00
|
|
|
#include <freerdp/config.h>
|
2012-08-15 01:09:01 +04:00
|
|
|
|
2021-06-09 15:03:34 +03:00
|
|
|
#include <winpr/assert.h>
|
2011-08-10 11:13:39 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2012-11-22 05:21:08 +04:00
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
2013-01-23 20:48:31 +04:00
|
|
|
#include <winpr/tchar.h>
|
2013-01-24 04:21:14 +04:00
|
|
|
#include <winpr/sysinfo.h>
|
2013-01-23 06:54:13 +04:00
|
|
|
#include <winpr/registry.h>
|
2013-01-31 04:56:58 +04:00
|
|
|
#include <winpr/tchar.h>
|
2012-11-22 05:21:08 +04:00
|
|
|
|
2014-09-12 16:36:29 +04:00
|
|
|
#include <freerdp/log.h>
|
2023-03-14 12:39:18 +03:00
|
|
|
#include <freerdp/settings.h>
|
2011-10-03 04:28:20 +04:00
|
|
|
#include <freerdp/codec/rfx.h>
|
2011-10-29 18:01:50 +04:00
|
|
|
#include <freerdp/constants.h>
|
2013-02-22 15:37:39 +04:00
|
|
|
#include <freerdp/primitives.h>
|
2014-02-05 18:52:29 +04:00
|
|
|
#include <freerdp/codec/region.h>
|
2015-11-05 16:02:07 +03:00
|
|
|
#include <freerdp/build-config.h>
|
2016-04-05 18:07:45 +03:00
|
|
|
#include <freerdp/codec/region.h>
|
2011-08-10 11:13:39 +04:00
|
|
|
|
|
|
|
#include "rfx_constants.h"
|
|
|
|
#include "rfx_types.h"
|
|
|
|
#include "rfx_decode.h"
|
|
|
|
#include "rfx_encode.h"
|
|
|
|
#include "rfx_quantization.h"
|
|
|
|
#include "rfx_dwt.h"
|
2013-07-10 09:14:26 +04:00
|
|
|
#include "rfx_rlgr.h"
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2011-08-13 12:26:57 +04:00
|
|
|
#include "rfx_sse2.h"
|
2011-08-10 11:13:39 +04:00
|
|
|
#include "rfx_neon.h"
|
|
|
|
|
2014-09-12 16:36:29 +04:00
|
|
|
#define TAG FREERDP_TAG("codec")
|
2014-02-04 15:02:55 +04:00
|
|
|
|
2011-08-10 11:13:39 +04:00
|
|
|
#ifndef RFX_INIT_SIMD
|
2019-11-06 17:24:51 +03:00
|
|
|
#define RFX_INIT_SIMD(_rfx_context) \
|
|
|
|
do \
|
|
|
|
{ \
|
|
|
|
} while (0)
|
2011-08-10 11:13:39 +04:00
|
|
|
#endif
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
#define RFX_KEY "Software\\" FREERDP_VENDOR_STRING "\\" FREERDP_PRODUCT_STRING "\\RemoteFX"
|
2015-06-24 12:12:59 +03:00
|
|
|
|
2011-08-10 11:13:39 +04:00
|
|
|
/**
|
|
|
|
* The quantization values control the compression rate and quality. The value
|
|
|
|
* range is between 6 and 15. The higher value, the higher compression rate
|
|
|
|
* and lower quality.
|
|
|
|
*
|
|
|
|
* This is the default values being use by the MS RDP server, and we will also
|
|
|
|
* use it as our default values for the encoder. It can be overrided by setting
|
|
|
|
* the context->num_quants and context->quants member.
|
|
|
|
*
|
|
|
|
* The order of the values are:
|
|
|
|
* LL3, LH3, HL3, HH3, LH2, HL2, HH2, LH1, HL1, HH1
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static const UINT32 rfx_default_quantization_values[] = { 6, 6, 6, 6, 7, 7, 8, 8, 8, 9 };
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2023-10-06 14:22:17 +03:00
|
|
|
static INLINE BOOL rfx_write_progressive_tile_simple(RFX_CONTEXT* rfx, wStream* s,
|
|
|
|
const RFX_TILE* tile);
|
|
|
|
|
2011-08-10 11:13:39 +04:00
|
|
|
static void rfx_profiler_create(RFX_CONTEXT* context)
|
|
|
|
{
|
2021-09-07 14:39:50 +03:00
|
|
|
if (!context || !context->priv)
|
|
|
|
return;
|
2018-02-15 12:19:15 +03:00
|
|
|
PROFILER_CREATE(context->priv->prof_rfx_decode_rgb, "rfx_decode_rgb")
|
2018-11-30 13:37:23 +03:00
|
|
|
PROFILER_CREATE(context->priv->prof_rfx_decode_component, "rfx_decode_component")
|
2018-02-15 12:19:15 +03:00
|
|
|
PROFILER_CREATE(context->priv->prof_rfx_rlgr_decode, "rfx_rlgr_decode")
|
2018-11-30 13:37:23 +03:00
|
|
|
PROFILER_CREATE(context->priv->prof_rfx_differential_decode, "rfx_differential_decode")
|
|
|
|
PROFILER_CREATE(context->priv->prof_rfx_quantization_decode, "rfx_quantization_decode")
|
2018-02-15 12:19:15 +03:00
|
|
|
PROFILER_CREATE(context->priv->prof_rfx_dwt_2d_decode, "rfx_dwt_2d_decode")
|
|
|
|
PROFILER_CREATE(context->priv->prof_rfx_ycbcr_to_rgb, "prims->yCbCrToRGB")
|
|
|
|
PROFILER_CREATE(context->priv->prof_rfx_encode_rgb, "rfx_encode_rgb")
|
2018-11-30 13:37:23 +03:00
|
|
|
PROFILER_CREATE(context->priv->prof_rfx_encode_component, "rfx_encode_component")
|
2018-02-15 12:19:15 +03:00
|
|
|
PROFILER_CREATE(context->priv->prof_rfx_rlgr_encode, "rfx_rlgr_encode")
|
2018-11-30 13:37:23 +03:00
|
|
|
PROFILER_CREATE(context->priv->prof_rfx_differential_encode, "rfx_differential_encode")
|
|
|
|
PROFILER_CREATE(context->priv->prof_rfx_quantization_encode, "rfx_quantization_encode")
|
2018-02-15 12:19:15 +03:00
|
|
|
PROFILER_CREATE(context->priv->prof_rfx_dwt_2d_encode, "rfx_dwt_2d_encode")
|
|
|
|
PROFILER_CREATE(context->priv->prof_rfx_rgb_to_ycbcr, "prims->RGBToYCbCr")
|
2018-11-30 13:37:23 +03:00
|
|
|
PROFILER_CREATE(context->priv->prof_rfx_encode_format_rgb, "rfx_encode_format_rgb")
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void rfx_profiler_free(RFX_CONTEXT* context)
|
|
|
|
{
|
2021-09-07 14:39:50 +03:00
|
|
|
if (!context || !context->priv)
|
|
|
|
return;
|
2018-02-15 12:19:15 +03:00
|
|
|
PROFILER_FREE(context->priv->prof_rfx_decode_rgb)
|
|
|
|
PROFILER_FREE(context->priv->prof_rfx_decode_component)
|
|
|
|
PROFILER_FREE(context->priv->prof_rfx_rlgr_decode)
|
|
|
|
PROFILER_FREE(context->priv->prof_rfx_differential_decode)
|
|
|
|
PROFILER_FREE(context->priv->prof_rfx_quantization_decode)
|
|
|
|
PROFILER_FREE(context->priv->prof_rfx_dwt_2d_decode)
|
|
|
|
PROFILER_FREE(context->priv->prof_rfx_ycbcr_to_rgb)
|
|
|
|
PROFILER_FREE(context->priv->prof_rfx_encode_rgb)
|
|
|
|
PROFILER_FREE(context->priv->prof_rfx_encode_component)
|
|
|
|
PROFILER_FREE(context->priv->prof_rfx_rlgr_encode)
|
|
|
|
PROFILER_FREE(context->priv->prof_rfx_differential_encode)
|
|
|
|
PROFILER_FREE(context->priv->prof_rfx_quantization_encode)
|
|
|
|
PROFILER_FREE(context->priv->prof_rfx_dwt_2d_encode)
|
|
|
|
PROFILER_FREE(context->priv->prof_rfx_rgb_to_ycbcr)
|
|
|
|
PROFILER_FREE(context->priv->prof_rfx_encode_format_rgb)
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void rfx_profiler_print(RFX_CONTEXT* context)
|
|
|
|
{
|
2021-09-07 14:39:50 +03:00
|
|
|
if (!context || !context->priv)
|
|
|
|
return;
|
2021-06-18 10:58:18 +03:00
|
|
|
|
2018-02-15 12:19:15 +03:00
|
|
|
PROFILER_PRINT_HEADER
|
|
|
|
PROFILER_PRINT(context->priv->prof_rfx_decode_rgb)
|
|
|
|
PROFILER_PRINT(context->priv->prof_rfx_decode_component)
|
|
|
|
PROFILER_PRINT(context->priv->prof_rfx_rlgr_decode)
|
|
|
|
PROFILER_PRINT(context->priv->prof_rfx_differential_decode)
|
|
|
|
PROFILER_PRINT(context->priv->prof_rfx_quantization_decode)
|
|
|
|
PROFILER_PRINT(context->priv->prof_rfx_dwt_2d_decode)
|
|
|
|
PROFILER_PRINT(context->priv->prof_rfx_ycbcr_to_rgb)
|
|
|
|
PROFILER_PRINT(context->priv->prof_rfx_encode_rgb)
|
|
|
|
PROFILER_PRINT(context->priv->prof_rfx_encode_component)
|
|
|
|
PROFILER_PRINT(context->priv->prof_rfx_rlgr_encode)
|
|
|
|
PROFILER_PRINT(context->priv->prof_rfx_differential_encode)
|
|
|
|
PROFILER_PRINT(context->priv->prof_rfx_quantization_encode)
|
|
|
|
PROFILER_PRINT(context->priv->prof_rfx_dwt_2d_encode)
|
|
|
|
PROFILER_PRINT(context->priv->prof_rfx_rgb_to_ycbcr)
|
|
|
|
PROFILER_PRINT(context->priv->prof_rfx_encode_format_rgb)
|
|
|
|
PROFILER_PRINT_FOOTER
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2018-10-19 12:30:01 +03:00
|
|
|
static void rfx_tile_init(void* obj)
|
2013-08-13 17:34:15 +04:00
|
|
|
{
|
2018-10-19 12:30:01 +03:00
|
|
|
RFX_TILE* tile = (RFX_TILE*)obj;
|
2013-08-13 17:34:15 +04:00
|
|
|
if (tile)
|
|
|
|
{
|
|
|
|
tile->x = 0;
|
|
|
|
tile->y = 0;
|
2013-08-14 01:18:59 +04:00
|
|
|
tile->YLen = 0;
|
|
|
|
tile->YData = NULL;
|
|
|
|
tile->CbLen = 0;
|
|
|
|
tile->CbData = NULL;
|
|
|
|
tile->CrLen = 0;
|
|
|
|
tile->CrData = NULL;
|
2013-08-13 17:34:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
static void* rfx_decoder_tile_new(const void* val)
|
2013-08-13 17:34:15 +04:00
|
|
|
{
|
2021-06-01 13:20:08 +03:00
|
|
|
const size_t size = 4 * 64 * 64;
|
2013-08-13 17:34:15 +04:00
|
|
|
RFX_TILE* tile = NULL;
|
2018-10-19 12:30:01 +03:00
|
|
|
WINPR_UNUSED(val);
|
2013-08-13 17:34:15 +04:00
|
|
|
|
2023-03-24 14:14:38 +03:00
|
|
|
if (!(tile = (RFX_TILE*)winpr_aligned_calloc(1, sizeof(RFX_TILE), 32)))
|
2015-04-23 16:42:21 +03:00
|
|
|
return NULL;
|
2013-08-13 17:34:15 +04:00
|
|
|
|
2022-05-11 12:28:55 +03:00
|
|
|
if (!(tile->data = (BYTE*)winpr_aligned_malloc(size, 16)))
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
2023-03-24 14:14:38 +03:00
|
|
|
winpr_aligned_free(tile);
|
2015-04-24 18:54:49 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
2021-06-01 13:20:08 +03:00
|
|
|
memset(tile->data, 0xff, size);
|
2015-04-23 16:42:21 +03:00
|
|
|
tile->allocated = TRUE;
|
2013-08-13 17:34:15 +04:00
|
|
|
return tile;
|
|
|
|
}
|
|
|
|
|
2018-10-19 12:30:01 +03:00
|
|
|
static void rfx_decoder_tile_free(void* obj)
|
2013-08-13 17:34:15 +04:00
|
|
|
{
|
2018-10-19 12:30:01 +03:00
|
|
|
RFX_TILE* tile = (RFX_TILE*)obj;
|
|
|
|
|
2013-08-13 17:34:15 +04:00
|
|
|
if (tile)
|
|
|
|
{
|
2013-09-03 16:27:08 +04:00
|
|
|
if (tile->allocated)
|
2022-05-11 12:28:55 +03:00
|
|
|
winpr_aligned_free(tile->data);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2023-03-24 14:14:38 +03:00
|
|
|
winpr_aligned_free(tile);
|
2013-08-13 17:34:15 +04:00
|
|
|
}
|
|
|
|
}
|
2013-07-05 14:30:13 +04:00
|
|
|
|
2020-05-12 18:16:14 +03:00
|
|
|
static void* rfx_encoder_tile_new(const void* val)
|
2013-08-17 00:46:47 +04:00
|
|
|
{
|
2018-10-19 12:30:01 +03:00
|
|
|
WINPR_UNUSED(val);
|
2023-03-24 14:14:38 +03:00
|
|
|
return winpr_aligned_calloc(1, sizeof(RFX_TILE), 32);
|
2013-08-17 00:46:47 +04:00
|
|
|
}
|
|
|
|
|
2018-10-19 12:30:01 +03:00
|
|
|
static void rfx_encoder_tile_free(void* obj)
|
2013-08-17 00:46:47 +04:00
|
|
|
{
|
2023-03-24 14:14:38 +03:00
|
|
|
winpr_aligned_free(obj);
|
2013-08-17 00:46:47 +04:00
|
|
|
}
|
|
|
|
|
2021-03-30 11:03:15 +03:00
|
|
|
RFX_CONTEXT* rfx_context_new(BOOL encoder)
|
|
|
|
{
|
|
|
|
return rfx_context_new_ex(encoder, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
RFX_CONTEXT* rfx_context_new_ex(BOOL encoder, UINT32 ThreadingFlags)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2013-01-23 06:54:13 +04:00
|
|
|
HKEY hKey;
|
|
|
|
LONG status;
|
|
|
|
DWORD dwType;
|
|
|
|
DWORD dwSize;
|
|
|
|
DWORD dwValue;
|
2013-01-24 04:21:14 +04:00
|
|
|
SYSTEM_INFO sysinfo;
|
2011-08-10 11:13:39 +04:00
|
|
|
RFX_CONTEXT* context;
|
2016-04-05 18:07:45 +03:00
|
|
|
wObject* pool;
|
|
|
|
RFX_CONTEXT_PRIV* priv;
|
2023-03-24 14:14:38 +03:00
|
|
|
context = (RFX_CONTEXT*)winpr_aligned_calloc(1, sizeof(RFX_CONTEXT), 32);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
if (!context)
|
|
|
|
return NULL;
|
2012-11-22 05:21:08 +04:00
|
|
|
|
2013-08-17 00:46:47 +04:00
|
|
|
context->encoder = encoder;
|
2018-11-30 13:37:23 +03:00
|
|
|
context->currentMessage.freeArray = TRUE;
|
2023-03-24 14:14:38 +03:00
|
|
|
context->priv = priv = (RFX_CONTEXT_PRIV*)winpr_aligned_calloc(1, sizeof(RFX_CONTEXT_PRIV), 32);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
if (!priv)
|
2021-09-07 14:39:50 +03:00
|
|
|
goto fail;
|
2012-11-22 05:21:08 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
priv->log = WLog_Get("com.freerdp.codec.rfx");
|
|
|
|
WLog_OpenAppender(priv->log);
|
|
|
|
priv->TilePool = ObjectPool_New(TRUE);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
if (!priv->TilePool)
|
2021-09-07 14:39:50 +03:00
|
|
|
goto fail;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
pool = ObjectPool_Object(priv->TilePool);
|
2018-10-19 12:30:01 +03:00
|
|
|
pool->fnObjectInit = rfx_tile_init;
|
2013-08-17 00:46:47 +04:00
|
|
|
|
|
|
|
if (context->encoder)
|
|
|
|
{
|
2018-10-19 12:30:01 +03:00
|
|
|
pool->fnObjectNew = rfx_encoder_tile_new;
|
|
|
|
pool->fnObjectFree = rfx_encoder_tile_free;
|
2013-08-17 00:46:47 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-10-19 12:30:01 +03:00
|
|
|
pool->fnObjectNew = rfx_decoder_tile_new;
|
|
|
|
pool->fnObjectFree = rfx_decoder_tile_free;
|
2013-08-17 00:46:47 +04:00
|
|
|
}
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2013-01-23 06:24:04 +04:00
|
|
|
/*
|
|
|
|
* align buffers to 16 byte boundary (needed for SSE/NEON instructions)
|
|
|
|
*
|
2013-07-05 14:30:13 +04:00
|
|
|
* y_r_buffer, cb_g_buffer, cr_b_buffer: 64 * 64 * sizeof(INT16) = 8192 (0x2000)
|
|
|
|
* dwt_buffer: 32 * 32 * 2 * 2 * sizeof(INT16) = 8192, maximum sub-band width is 32
|
2013-03-05 20:36:26 +04:00
|
|
|
*
|
|
|
|
* Additionally we add 32 bytes (16 in front and 16 at the back of the buffer)
|
2015-06-24 12:12:59 +03:00
|
|
|
* in order to allow optimized functions (SEE, NEON) to read from positions
|
2013-03-05 20:36:26 +04:00
|
|
|
* that are actually in front/beyond the buffer. Offset calculations are
|
|
|
|
* performed at the BufferPool_Take function calls in rfx_encode/decode.c.
|
2013-08-20 02:39:19 +04:00
|
|
|
*
|
|
|
|
* We then multiply by 3 to use a single, partioned buffer for all 3 channels.
|
2013-01-23 06:24:04 +04:00
|
|
|
*/
|
2014-02-04 15:02:55 +04:00
|
|
|
priv->BufferPool = BufferPool_New(TRUE, (8192 + 32) * 3, 16);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
if (!priv->BufferPool)
|
2021-09-07 14:39:50 +03:00
|
|
|
goto fail;
|
2013-01-23 06:24:04 +04:00
|
|
|
|
2021-03-12 18:54:45 +03:00
|
|
|
if (!(ThreadingFlags & THREADING_FLAGS_DISABLE_THREADS))
|
|
|
|
{
|
2022-06-23 08:57:38 +03:00
|
|
|
priv->UseThreads = TRUE;
|
2023-07-28 09:02:46 +03:00
|
|
|
|
2022-06-23 08:57:38 +03:00
|
|
|
GetNativeSystemInfo(&sysinfo);
|
|
|
|
priv->MinThreadCount = sysinfo.dwNumberOfProcessors;
|
|
|
|
priv->MaxThreadCount = 0;
|
|
|
|
status = RegOpenKeyExA(HKEY_LOCAL_MACHINE, RFX_KEY, 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
|
2013-01-23 06:54:13 +04:00
|
|
|
|
2022-06-23 08:57:38 +03:00
|
|
|
if (status == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
dwSize = sizeof(dwValue);
|
2013-06-14 08:16:04 +04:00
|
|
|
|
2022-06-23 08:57:38 +03:00
|
|
|
if (RegQueryValueEx(hKey, _T("UseThreads"), NULL, &dwType, (BYTE*)&dwValue, &dwSize) ==
|
|
|
|
ERROR_SUCCESS)
|
|
|
|
priv->UseThreads = dwValue ? 1 : 0;
|
2013-01-23 06:54:13 +04:00
|
|
|
|
2022-06-23 08:57:38 +03:00
|
|
|
if (RegQueryValueEx(hKey, _T("MinThreadCount"), NULL, &dwType, (BYTE*)&dwValue,
|
|
|
|
&dwSize) == ERROR_SUCCESS)
|
|
|
|
priv->MinThreadCount = dwValue;
|
2013-01-23 06:54:13 +04:00
|
|
|
|
2022-06-23 08:57:38 +03:00
|
|
|
if (RegQueryValueEx(hKey, _T("MaxThreadCount"), NULL, &dwType, (BYTE*)&dwValue,
|
|
|
|
&dwSize) == ERROR_SUCCESS)
|
|
|
|
priv->MaxThreadCount = dwValue;
|
2013-01-23 06:54:13 +04:00
|
|
|
|
2022-06-23 08:57:38 +03:00
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
2021-03-12 18:54:45 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
priv->UseThreads = FALSE;
|
|
|
|
}
|
2013-01-23 06:54:13 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
if (priv->UseThreads)
|
2013-01-23 03:14:50 +04:00
|
|
|
{
|
2013-02-22 15:37:39 +04:00
|
|
|
/* Call primitives_get here in order to avoid race conditions when using primitives_get */
|
|
|
|
/* from multiple threads. This call will initialize all function pointers correctly */
|
|
|
|
/* before any decoding threads are started */
|
|
|
|
primitives_get();
|
2014-02-04 15:02:55 +04:00
|
|
|
priv->ThreadPool = CreateThreadpool(NULL);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
if (!priv->ThreadPool)
|
2021-09-07 14:39:50 +03:00
|
|
|
goto fail;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
InitializeThreadpoolEnvironment(&priv->ThreadPoolEnv);
|
|
|
|
SetThreadpoolCallbackPool(&priv->ThreadPoolEnv, priv->ThreadPool);
|
2013-01-23 06:54:13 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
if (priv->MinThreadCount)
|
2015-05-05 14:55:48 +03:00
|
|
|
if (!SetThreadpoolThreadMinimum(priv->ThreadPool, priv->MinThreadCount))
|
2021-09-07 14:39:50 +03:00
|
|
|
goto fail;
|
2013-01-23 06:54:13 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
if (priv->MaxThreadCount)
|
|
|
|
SetThreadpoolThreadMaximum(priv->ThreadPool, priv->MaxThreadCount);
|
2013-01-23 03:14:50 +04:00
|
|
|
}
|
|
|
|
|
2011-08-10 11:13:39 +04:00
|
|
|
/* initialize the default pixel format */
|
2016-04-05 18:07:45 +03:00
|
|
|
rfx_context_set_pixel_format(context, PIXEL_FORMAT_BGRX32);
|
2011-08-10 11:13:39 +04:00
|
|
|
/* create profilers for default decoding routines */
|
|
|
|
rfx_profiler_create(context);
|
|
|
|
/* set up default routines */
|
2015-06-24 12:12:59 +03:00
|
|
|
context->quantization_decode = rfx_quantization_decode;
|
|
|
|
context->quantization_encode = rfx_quantization_encode;
|
2011-08-10 11:13:39 +04:00
|
|
|
context->dwt_2d_decode = rfx_dwt_2d_decode;
|
2023-08-14 09:37:11 +03:00
|
|
|
context->dwt_2d_extrapolate_decode = rfx_dwt_2d_extrapolate_decode;
|
2011-08-10 11:13:39 +04:00
|
|
|
context->dwt_2d_encode = rfx_dwt_2d_encode;
|
2016-11-23 15:21:59 +03:00
|
|
|
context->rlgr_decode = rfx_rlgr_decode;
|
|
|
|
context->rlgr_encode = rfx_rlgr_encode;
|
2013-02-21 19:08:46 +04:00
|
|
|
RFX_INIT_SIMD(context);
|
2013-08-14 01:18:59 +04:00
|
|
|
context->state = RFX_STATE_SEND_HEADERS;
|
2018-11-30 13:37:23 +03:00
|
|
|
context->expectedDataBlockType = WBT_FRAME_BEGIN;
|
2011-10-29 18:01:50 +04:00
|
|
|
return context;
|
2021-09-07 14:39:50 +03:00
|
|
|
fail:
|
|
|
|
rfx_context_free(context);
|
2014-02-04 15:02:55 +04:00
|
|
|
return NULL;
|
2011-10-29 18:01:50 +04:00
|
|
|
}
|
|
|
|
|
2011-08-10 11:13:39 +04:00
|
|
|
void rfx_context_free(RFX_CONTEXT* context)
|
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
RFX_CONTEXT_PRIV* priv;
|
2014-02-04 15:02:55 +04:00
|
|
|
|
2016-03-01 18:17:28 +03:00
|
|
|
if (!context)
|
|
|
|
return;
|
|
|
|
|
2021-06-09 15:03:34 +03:00
|
|
|
WINPR_ASSERT(NULL != context);
|
2023-04-05 11:52:10 +03:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
priv = context->priv;
|
2023-04-05 11:52:10 +03:00
|
|
|
WINPR_ASSERT(NULL != priv);
|
|
|
|
WINPR_ASSERT(NULL != priv->TilePool);
|
|
|
|
WINPR_ASSERT(NULL != priv->BufferPool);
|
|
|
|
|
2021-04-16 11:58:35 +03:00
|
|
|
/* coverity[address_free] */
|
2018-11-30 13:37:23 +03:00
|
|
|
rfx_message_free(context, &context->currentMessage);
|
2023-03-24 14:14:38 +03:00
|
|
|
winpr_aligned_free(context->quants);
|
2011-08-10 11:13:39 +04:00
|
|
|
rfx_profiler_print(context);
|
|
|
|
rfx_profiler_free(context);
|
|
|
|
|
2021-09-07 14:39:50 +03:00
|
|
|
if (priv)
|
2013-01-23 03:14:50 +04:00
|
|
|
{
|
2021-09-07 14:39:50 +03:00
|
|
|
ObjectPool_Free(priv->TilePool);
|
|
|
|
if (priv->UseThreads)
|
|
|
|
{
|
|
|
|
if (priv->ThreadPool)
|
|
|
|
CloseThreadpool(priv->ThreadPool);
|
|
|
|
DestroyThreadpoolEnvironment(&priv->ThreadPoolEnv);
|
2023-03-24 14:14:38 +03:00
|
|
|
winpr_aligned_free(priv->workObjects);
|
|
|
|
winpr_aligned_free(priv->tileWorkParams);
|
2013-06-27 15:43:29 +04:00
|
|
|
#ifdef WITH_PROFILER
|
2022-06-23 08:57:38 +03:00
|
|
|
WLog_VRB(
|
|
|
|
TAG,
|
|
|
|
"WARNING: Profiling results probably unusable with multithreaded RemoteFX codec!");
|
2013-06-27 15:43:29 +04:00
|
|
|
#endif
|
2021-09-07 14:39:50 +03:00
|
|
|
}
|
2013-01-23 03:14:50 +04:00
|
|
|
|
2021-09-07 14:39:50 +03:00
|
|
|
BufferPool_Free(priv->BufferPool);
|
2023-03-24 14:14:38 +03:00
|
|
|
winpr_aligned_free(priv);
|
2021-09-07 14:39:50 +03:00
|
|
|
}
|
2023-03-24 14:14:38 +03:00
|
|
|
winpr_aligned_free(context);
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2016-04-11 18:30:29 +03:00
|
|
|
static RFX_TILE* rfx_message_get_tile(RFX_MESSAGE* message, UINT32 index)
|
|
|
|
{
|
2023-04-04 22:10:50 +03:00
|
|
|
WINPR_ASSERT(message);
|
|
|
|
WINPR_ASSERT(message->tiles);
|
|
|
|
WINPR_ASSERT(index < message->numTiles);
|
2016-04-11 18:30:29 +03:00
|
|
|
return message->tiles[index];
|
|
|
|
}
|
|
|
|
|
2020-12-14 19:44:30 +03:00
|
|
|
static const RFX_RECT* rfx_message_get_rect_const(const RFX_MESSAGE* message, UINT32 index)
|
|
|
|
{
|
2023-04-04 22:10:50 +03:00
|
|
|
WINPR_ASSERT(message);
|
|
|
|
WINPR_ASSERT(message->rects);
|
|
|
|
WINPR_ASSERT(index < message->numRects);
|
2020-12-14 19:44:30 +03:00
|
|
|
return &message->rects[index];
|
|
|
|
}
|
|
|
|
|
2016-04-11 18:30:29 +03:00
|
|
|
static RFX_RECT* rfx_message_get_rect(RFX_MESSAGE* message, UINT32 index)
|
|
|
|
{
|
2023-04-04 22:10:50 +03:00
|
|
|
WINPR_ASSERT(message);
|
|
|
|
WINPR_ASSERT(message->rects);
|
|
|
|
WINPR_ASSERT(index < message->numRects);
|
2016-04-11 18:30:29 +03:00
|
|
|
return &message->rects[index];
|
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
void rfx_context_set_pixel_format(RFX_CONTEXT* context, UINT32 pixel_format)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2023-04-04 22:10:50 +03:00
|
|
|
WINPR_ASSERT(context);
|
2011-08-10 11:13:39 +04:00
|
|
|
context->pixel_format = pixel_format;
|
2022-04-28 06:43:31 +03:00
|
|
|
context->bits_per_pixel = FreeRDPGetBitsPerPixel(pixel_format);
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2023-10-06 14:22:17 +03:00
|
|
|
UINT32 rfx_context_get_pixel_format(RFX_CONTEXT* context)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
return context->pixel_format;
|
|
|
|
}
|
|
|
|
|
2023-06-27 08:21:51 +03:00
|
|
|
void rfx_context_set_palette(RFX_CONTEXT* context, const BYTE* palette)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
context->palette = palette;
|
|
|
|
}
|
|
|
|
|
2023-10-06 14:22:17 +03:00
|
|
|
const BYTE* rfx_context_get_palette(RFX_CONTEXT* context)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
return context->palette;
|
|
|
|
}
|
|
|
|
|
2016-03-01 18:17:28 +03:00
|
|
|
BOOL rfx_context_reset(RFX_CONTEXT* context, UINT32 width, UINT32 height)
|
2011-09-06 14:50:47 +04:00
|
|
|
{
|
2016-03-01 18:17:28 +03:00
|
|
|
if (!context)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
context->width = width;
|
|
|
|
context->height = height;
|
2013-08-14 01:18:59 +04:00
|
|
|
context->state = RFX_STATE_SEND_HEADERS;
|
2018-11-30 13:37:23 +03:00
|
|
|
context->expectedDataBlockType = WBT_FRAME_BEGIN;
|
2013-08-14 01:18:59 +04:00
|
|
|
context->frameIdx = 0;
|
2016-03-01 18:17:28 +03:00
|
|
|
return TRUE;
|
2011-09-06 14:50:47 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static BOOL rfx_process_message_sync(RFX_CONTEXT* context, wStream* s)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 magic;
|
2023-04-04 22:10:50 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(context);
|
2023-04-04 22:37:28 +03:00
|
|
|
WINPR_ASSERT(context->priv);
|
2021-09-08 16:37:45 +03:00
|
|
|
context->decodedHeaderBlocks &= ~RFX_DECODED_SYNC;
|
2015-04-23 16:42:21 +03:00
|
|
|
|
2011-08-10 11:13:39 +04:00
|
|
|
/* RFX_SYNC */
|
2023-04-04 22:10:50 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 6))
|
2013-01-29 01:23:10 +04:00
|
|
|
return FALSE;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, magic); /* magic (4 bytes), 0xCACCACCA */
|
2011-08-10 11:13:39 +04:00
|
|
|
if (magic != WF_MAGIC)
|
|
|
|
{
|
2023-04-04 22:37:28 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR, "invalid magic number 0x%08" PRIX32 "", magic);
|
2013-01-29 01:23:10 +04:00
|
|
|
return FALSE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2018-11-30 13:37:23 +03:00
|
|
|
Stream_Read_UINT16(s, context->version); /* version (2 bytes), WF_VERSION_1_0 (0x0100) */
|
2011-08-10 11:13:39 +04:00
|
|
|
if (context->version != WF_VERSION_1_0)
|
|
|
|
{
|
2023-04-04 22:37:28 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR, "invalid version number 0x%08" PRIX32 "",
|
|
|
|
context->version);
|
2013-01-29 01:23:10 +04:00
|
|
|
return FALSE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_DEBUG, "version 0x%08" PRIX32 "", context->version);
|
2021-09-08 16:37:45 +03:00
|
|
|
context->decodedHeaderBlocks |= RFX_DECODED_SYNC;
|
2013-01-29 01:23:10 +04:00
|
|
|
return TRUE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static BOOL rfx_process_message_codec_versions(RFX_CONTEXT* context, wStream* s)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE numCodecs;
|
2023-04-04 22:10:50 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(context);
|
2023-04-04 22:37:28 +03:00
|
|
|
WINPR_ASSERT(context->priv);
|
2021-09-08 16:37:45 +03:00
|
|
|
context->decodedHeaderBlocks &= ~RFX_DECODED_VERSIONS;
|
2015-04-23 16:42:21 +03:00
|
|
|
|
2023-04-04 22:10:50 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 4))
|
2013-01-29 01:23:10 +04:00
|
|
|
return FALSE;
|
2015-04-24 18:54:49 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT8(s, numCodecs); /* numCodecs (1 byte), must be set to 0x01 */
|
2018-11-30 13:37:23 +03:00
|
|
|
Stream_Read_UINT8(s, context->codec_id); /* codecId (1 byte), must be set to 0x01 */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT16(
|
|
|
|
s, context->codec_version); /* version (2 bytes), must be set to WF_VERSION_1_0 (0x0100) */
|
2011-08-10 11:13:39 +04:00
|
|
|
|
|
|
|
if (numCodecs != 1)
|
|
|
|
{
|
2023-04-04 22:37:28 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR, "numCodes is 0x%02" PRIX8 " (must be 0x01)",
|
|
|
|
numCodecs);
|
2013-01-29 01:23:10 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-04-24 18:54:49 +03:00
|
|
|
if (context->codec_id != 0x01)
|
2013-01-29 01:23:10 +04:00
|
|
|
{
|
2023-04-04 22:37:28 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR, "invalid codec id (0x%02" PRIX32 ")",
|
|
|
|
context->codec_id);
|
2013-01-29 01:23:10 +04:00
|
|
|
return FALSE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2015-04-24 18:54:49 +03:00
|
|
|
if (context->codec_version != WF_VERSION_1_0)
|
|
|
|
{
|
2023-04-04 22:37:28 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR, "invalid codec version (0x%08" PRIX32 ")",
|
|
|
|
context->codec_version);
|
2015-04-24 18:54:49 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_DEBUG, "id %" PRIu32 " version 0x%" PRIX32 ".",
|
2016-10-12 10:21:21 +03:00
|
|
|
context->codec_id, context->codec_version);
|
2021-09-08 16:37:45 +03:00
|
|
|
context->decodedHeaderBlocks |= RFX_DECODED_VERSIONS;
|
2013-01-29 01:23:10 +04:00
|
|
|
return TRUE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static BOOL rfx_process_message_channels(RFX_CONTEXT* context, wStream* s)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE channelId;
|
|
|
|
BYTE numChannels;
|
2023-04-04 22:10:50 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(context);
|
2023-04-04 22:37:28 +03:00
|
|
|
WINPR_ASSERT(context->priv);
|
2021-09-08 16:37:45 +03:00
|
|
|
context->decodedHeaderBlocks &= ~RFX_DECODED_CHANNELS;
|
2015-04-23 16:42:21 +03:00
|
|
|
|
2023-04-04 22:10:50 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 1))
|
2013-01-29 01:23:10 +04:00
|
|
|
return FALSE;
|
|
|
|
|
2018-11-30 13:37:23 +03:00
|
|
|
Stream_Read_UINT8(s, numChannels); /* numChannels (1 byte), must bet set to 0x01 */
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2015-06-24 12:12:59 +03:00
|
|
|
/* In RDVH sessions, numChannels will represent the number of virtual monitors
|
2012-01-10 01:18:31 +04:00
|
|
|
* configured and does not always be set to 0x01 as [MS-RDPRFX] said.
|
|
|
|
*/
|
|
|
|
if (numChannels < 1)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2023-04-04 22:37:28 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR, "no channels announced");
|
2015-04-23 16:42:21 +03:00
|
|
|
return FALSE;
|
2013-01-29 01:23:10 +04:00
|
|
|
}
|
|
|
|
|
2023-04-04 22:37:28 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(context->priv->log, s, numChannels, 5ull))
|
2013-01-29 01:23:10 +04:00
|
|
|
return FALSE;
|
2011-08-10 11:13:39 +04:00
|
|
|
|
|
|
|
/* RFX_CHANNELT */
|
2015-04-23 16:42:21 +03:00
|
|
|
Stream_Read_UINT8(s, channelId); /* channelId (1 byte), must be set to 0x00 */
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-04-23 16:42:21 +03:00
|
|
|
if (channelId != 0x00)
|
|
|
|
{
|
2023-04-04 22:37:28 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR, "channelId:0x%02" PRIX8 ", expected:0x00",
|
|
|
|
channelId);
|
2015-04-23 16:42:21 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT16(s, context->width); /* width (2 bytes) */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, context->height); /* height (2 bytes) */
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2015-04-24 18:54:49 +03:00
|
|
|
if (!context->width || !context->height)
|
|
|
|
{
|
2023-04-04 22:37:28 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR,
|
|
|
|
"invalid channel with/height: %" PRIu16 "x%" PRIu16 "", context->width,
|
|
|
|
context->height);
|
2015-04-24 18:54:49 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-01-10 01:18:31 +04:00
|
|
|
/* Now, only the first monitor can be used, therefore the other channels will be ignored. */
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek(s, 5 * (numChannels - 1));
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_DEBUG,
|
|
|
|
"numChannels %" PRIu8 " id %" PRIu8 ", %" PRIu16 "x%" PRIu16 ".", numChannels,
|
|
|
|
channelId, context->width, context->height);
|
2021-09-08 16:37:45 +03:00
|
|
|
context->decodedHeaderBlocks |= RFX_DECODED_CHANNELS;
|
2013-01-29 01:23:10 +04:00
|
|
|
return TRUE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static BOOL rfx_process_message_context(RFX_CONTEXT* context, wStream* s)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE ctxId;
|
|
|
|
UINT16 tileSize;
|
|
|
|
UINT16 properties;
|
2023-04-04 22:10:50 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
WINPR_ASSERT(context->priv);
|
2021-09-08 16:37:45 +03:00
|
|
|
context->decodedHeaderBlocks &= ~RFX_DECODED_CONTEXT;
|
2015-04-24 18:54:49 +03:00
|
|
|
|
2023-04-04 22:10:50 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 5))
|
2013-01-29 01:23:10 +04:00
|
|
|
return FALSE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT8(s, ctxId); /* ctxId (1 byte), must be set to 0x00 */
|
2018-11-30 13:37:23 +03:00
|
|
|
Stream_Read_UINT16(s, tileSize); /* tileSize (2 bytes), must be set to CT_TILE_64x64 (0x0040) */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, properties); /* properties (2 bytes) */
|
2016-04-05 18:07:45 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_DEBUG,
|
2019-11-06 17:24:51 +03:00
|
|
|
"ctxId %" PRIu8 " tileSize %" PRIu16 " properties 0x%04" PRIX16 ".", ctxId, tileSize,
|
|
|
|
properties);
|
2011-08-10 11:13:39 +04:00
|
|
|
context->properties = properties;
|
|
|
|
context->flags = (properties & 0x0007);
|
|
|
|
|
|
|
|
if (context->flags == CODEC_MODE)
|
2013-10-09 04:17:57 +04:00
|
|
|
{
|
|
|
|
WLog_Print(context->priv->log, WLOG_DEBUG, "codec is in image mode.");
|
|
|
|
}
|
2011-08-10 11:13:39 +04:00
|
|
|
else
|
2013-10-09 04:17:57 +04:00
|
|
|
{
|
|
|
|
WLog_Print(context->priv->log, WLOG_DEBUG, "codec is in video mode.");
|
|
|
|
}
|
2011-08-10 11:13:39 +04:00
|
|
|
|
|
|
|
switch ((properties & 0x1E00) >> 9)
|
|
|
|
{
|
|
|
|
case CLW_ENTROPY_RLGR1:
|
|
|
|
context->mode = RLGR1;
|
2013-10-09 04:17:57 +04:00
|
|
|
WLog_Print(context->priv->log, WLOG_DEBUG, "RLGR1.");
|
2011-08-10 11:13:39 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CLW_ENTROPY_RLGR3:
|
|
|
|
context->mode = RLGR3;
|
2013-10-09 04:17:57 +04:00
|
|
|
WLog_Print(context->priv->log, WLOG_DEBUG, "RLGR3.");
|
2011-08-10 11:13:39 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2023-04-04 22:37:28 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR, "unknown RLGR algorithm.");
|
2015-04-23 16:42:21 +03:00
|
|
|
return FALSE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
2013-10-09 04:17:57 +04:00
|
|
|
|
2021-09-08 16:37:45 +03:00
|
|
|
context->decodedHeaderBlocks |= RFX_DECODED_CONTEXT;
|
2013-01-29 01:23:10 +04:00
|
|
|
return TRUE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL rfx_process_message_frame_begin(RFX_CONTEXT* context, RFX_MESSAGE* message, wStream* s,
|
|
|
|
UINT16* pExpectedBlockType)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 frameIdx;
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 numRegions;
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2023-04-04 22:10:50 +03:00
|
|
|
WINPR_ASSERT(context);
|
|
|
|
WINPR_ASSERT(context->priv);
|
|
|
|
WINPR_ASSERT(message);
|
|
|
|
WINPR_ASSERT(pExpectedBlockType);
|
|
|
|
|
2015-04-23 16:42:21 +03:00
|
|
|
if (*pExpectedBlockType != WBT_FRAME_BEGIN)
|
|
|
|
{
|
2023-04-04 22:37:28 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR, "message unexpected wants WBT_FRAME_BEGIN");
|
2015-04-23 16:42:21 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-04-23 16:42:21 +03:00
|
|
|
*pExpectedBlockType = WBT_REGION;
|
|
|
|
|
2023-04-04 22:10:50 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 6))
|
2013-01-29 01:23:10 +04:00
|
|
|
return FALSE;
|
2013-10-09 04:17:57 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT32(
|
|
|
|
s, frameIdx); /* frameIdx (4 bytes), if codec is in video mode, must be ignored */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, numRegions); /* numRegions (2 bytes) */
|
2016-04-05 18:07:45 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_DEBUG,
|
2019-11-06 17:24:51 +03:00
|
|
|
"RFX_FRAME_BEGIN: frameIdx: %" PRIu32 " numRegions: %" PRIu16 "", frameIdx,
|
|
|
|
numRegions);
|
2013-01-29 01:23:10 +04:00
|
|
|
return TRUE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL rfx_process_message_frame_end(RFX_CONTEXT* context, RFX_MESSAGE* message, wStream* s,
|
|
|
|
UINT16* pExpectedBlockType)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2023-04-04 22:10:50 +03:00
|
|
|
WINPR_ASSERT(context);
|
|
|
|
WINPR_ASSERT(context->priv);
|
|
|
|
WINPR_ASSERT(message);
|
2023-04-05 11:52:10 +03:00
|
|
|
WINPR_ASSERT(s);
|
2023-04-04 22:10:50 +03:00
|
|
|
WINPR_ASSERT(pExpectedBlockType);
|
|
|
|
|
2015-04-23 16:42:21 +03:00
|
|
|
if (*pExpectedBlockType != WBT_FRAME_END)
|
|
|
|
{
|
2023-04-04 22:37:28 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR, "message unexpected, wants WBT_FRAME_END");
|
2015-04-23 16:42:21 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
*pExpectedBlockType = WBT_FRAME_BEGIN;
|
2013-10-09 04:17:57 +04:00
|
|
|
WLog_Print(context->priv->log, WLOG_DEBUG, "RFX_FRAME_END");
|
2015-04-23 16:42:21 +03:00
|
|
|
return TRUE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2023-03-24 14:14:38 +03:00
|
|
|
static BOOL rfx_resize_rects(RFX_MESSAGE* message)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(message);
|
|
|
|
|
|
|
|
RFX_RECT* tmpRects =
|
|
|
|
winpr_aligned_recalloc(message->rects, message->numRects, sizeof(RFX_RECT), 32);
|
|
|
|
if (!tmpRects)
|
|
|
|
return FALSE;
|
|
|
|
message->rects = tmpRects;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL rfx_process_message_region(RFX_CONTEXT* context, RFX_MESSAGE* message, wStream* s,
|
|
|
|
UINT16* pExpectedBlockType)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2020-12-14 19:44:30 +03:00
|
|
|
UINT16 i;
|
2015-04-23 16:42:21 +03:00
|
|
|
UINT16 regionType;
|
|
|
|
UINT16 numTileSets;
|
|
|
|
|
2023-04-04 22:10:50 +03:00
|
|
|
WINPR_ASSERT(context);
|
2023-04-04 22:37:28 +03:00
|
|
|
WINPR_ASSERT(context->priv);
|
2023-04-04 22:10:50 +03:00
|
|
|
WINPR_ASSERT(message);
|
|
|
|
WINPR_ASSERT(pExpectedBlockType);
|
|
|
|
|
2015-04-23 16:42:21 +03:00
|
|
|
if (*pExpectedBlockType != WBT_REGION)
|
|
|
|
{
|
2023-04-04 22:37:28 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR, "message unexpected wants WBT_REGION");
|
2015-04-23 16:42:21 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-04-23 16:42:21 +03:00
|
|
|
*pExpectedBlockType = WBT_EXTENSION;
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2023-04-04 22:10:50 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 3))
|
2013-01-29 01:23:10 +04:00
|
|
|
return FALSE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Seek_UINT8(s); /* regionFlags (1 byte) */
|
2013-08-14 01:18:59 +04:00
|
|
|
Stream_Read_UINT16(s, message->numRects); /* numRects (2 bytes) */
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2013-08-14 01:18:59 +04:00
|
|
|
if (message->numRects < 1)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2015-08-28 11:26:42 +03:00
|
|
|
/*
|
|
|
|
If numRects is zero the decoder must generate a rectangle with
|
|
|
|
coordinates (0, 0, width, height).
|
|
|
|
See [MS-RDPRFX] (revision >= 17.0) 2.2.2.3.3 TS_RFX_REGION
|
|
|
|
https://msdn.microsoft.com/en-us/library/ff635233.aspx
|
|
|
|
*/
|
2023-03-24 14:14:38 +03:00
|
|
|
message->numRects = 1;
|
|
|
|
if (!rfx_resize_rects(message))
|
2014-05-08 20:20:28 +04:00
|
|
|
return FALSE;
|
2015-04-23 16:42:21 +03:00
|
|
|
|
2014-05-08 20:20:28 +04:00
|
|
|
message->rects->x = 0;
|
|
|
|
message->rects->y = 0;
|
|
|
|
message->rects->width = context->width;
|
|
|
|
message->rects->height = context->height;
|
2013-01-29 01:23:10 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-04-04 22:37:28 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(context->priv->log, s, message->numRects, 8ull))
|
2013-01-29 01:23:10 +04:00
|
|
|
return FALSE;
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2023-03-24 14:14:38 +03:00
|
|
|
if (!rfx_resize_rects(message))
|
2014-02-05 18:52:29 +04:00
|
|
|
return FALSE;
|
2011-08-10 11:13:39 +04:00
|
|
|
|
|
|
|
/* rects */
|
2013-08-14 01:18:59 +04:00
|
|
|
for (i = 0; i < message->numRects; i++)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2016-04-11 18:30:29 +03:00
|
|
|
RFX_RECT* rect = rfx_message_get_rect(message, i);
|
2011-08-10 11:13:39 +04:00
|
|
|
/* RFX_RECT */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT16(s, rect->x); /* x (2 bytes) */
|
|
|
|
Stream_Read_UINT16(s, rect->y); /* y (2 bytes) */
|
|
|
|
Stream_Read_UINT16(s, rect->width); /* width (2 bytes) */
|
2016-04-11 18:30:29 +03:00
|
|
|
Stream_Read_UINT16(s, rect->height); /* height (2 bytes) */
|
2017-01-31 14:28:17 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_DEBUG,
|
2022-09-29 15:55:27 +03:00
|
|
|
"rect %" PRIu16 " (x,y=%" PRIu16 ",%" PRIu16 " w,h=%" PRIu16 " %" PRIu16 ").", i,
|
|
|
|
rect->x, rect->y, rect->width, rect->height);
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
2013-10-09 04:17:57 +04:00
|
|
|
|
2023-04-04 22:10:50 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 4))
|
2015-04-23 16:42:21 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT16(s, regionType); /*regionType (2 bytes): MUST be set to CBT_REGION (0xCAC1)*/
|
2018-11-30 13:37:23 +03:00
|
|
|
Stream_Read_UINT16(s, numTileSets); /*numTilesets (2 bytes): MUST be set to 0x0001.*/
|
2015-04-23 16:42:21 +03:00
|
|
|
|
|
|
|
if (regionType != CBT_REGION)
|
|
|
|
{
|
2023-04-04 22:37:28 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR, "invalid region type 0x%04" PRIX16 "",
|
|
|
|
regionType);
|
2015-04-24 18:54:49 +03:00
|
|
|
return TRUE;
|
2015-04-23 16:42:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (numTileSets != 0x0001)
|
|
|
|
{
|
2023-04-04 22:37:28 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR, "invalid number of tilesets (%" PRIu16 ")",
|
|
|
|
numTileSets);
|
2015-04-23 16:42:21 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-01-29 01:23:10 +04:00
|
|
|
return TRUE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
typedef struct
|
2013-01-23 03:14:50 +04:00
|
|
|
{
|
|
|
|
RFX_TILE* tile;
|
|
|
|
RFX_CONTEXT* context;
|
2022-02-14 16:59:22 +03:00
|
|
|
} RFX_TILE_PROCESS_WORK_PARAM;
|
2013-01-23 03:14:50 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static void CALLBACK rfx_process_message_tile_work_callback(PTP_CALLBACK_INSTANCE instance,
|
|
|
|
void* context, PTP_WORK work)
|
2013-01-23 03:14:50 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
RFX_TILE_PROCESS_WORK_PARAM* param = (RFX_TILE_PROCESS_WORK_PARAM*)context;
|
2023-04-04 22:10:50 +03:00
|
|
|
WINPR_ASSERT(param);
|
2013-08-13 18:09:32 +04:00
|
|
|
rfx_decode_rgb(param->context, param->tile, param->tile->data, 64 * 4);
|
2013-01-23 03:14:50 +04:00
|
|
|
}
|
|
|
|
|
2023-06-12 10:33:49 +03:00
|
|
|
static BOOL rfx_allocate_tiles(RFX_MESSAGE* message, size_t count, BOOL allocOnly)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(message);
|
|
|
|
|
|
|
|
RFX_TILE** tmpTiles = winpr_aligned_recalloc(message->tiles, count, sizeof(RFX_TILE*), 32);
|
|
|
|
if (!tmpTiles && (count != 0))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
message->tiles = tmpTiles;
|
|
|
|
if (!allocOnly)
|
|
|
|
message->numTiles = count;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(message->numTiles <= count);
|
|
|
|
}
|
|
|
|
message->allocatedTiles = count;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* message, wStream* s,
|
|
|
|
UINT16* pExpectedBlockType)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2013-09-02 17:07:39 +04:00
|
|
|
BOOL rc;
|
2023-07-27 21:38:51 +03:00
|
|
|
size_t close_cnt = 0;
|
2013-01-23 03:14:50 +04:00
|
|
|
BYTE quant;
|
2013-08-13 18:09:32 +04:00
|
|
|
RFX_TILE* tile;
|
2013-01-23 03:14:50 +04:00
|
|
|
UINT32* quants;
|
2018-11-30 13:37:23 +03:00
|
|
|
UINT16 subtype, numTiles;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 blockLen;
|
|
|
|
UINT32 blockType;
|
|
|
|
UINT32 tilesDataSize;
|
2013-01-23 03:14:50 +04:00
|
|
|
PTP_WORK* work_objects = NULL;
|
2013-08-04 14:07:53 +04:00
|
|
|
RFX_TILE_PROCESS_WORK_PARAM* params = NULL;
|
2016-04-05 18:07:45 +03:00
|
|
|
void* pmem;
|
2015-04-23 16:42:21 +03:00
|
|
|
|
2023-04-04 22:10:50 +03:00
|
|
|
WINPR_ASSERT(context);
|
2023-04-04 22:37:28 +03:00
|
|
|
WINPR_ASSERT(context->priv);
|
2023-04-04 22:10:50 +03:00
|
|
|
WINPR_ASSERT(message);
|
|
|
|
WINPR_ASSERT(pExpectedBlockType);
|
|
|
|
|
2018-11-30 13:37:23 +03:00
|
|
|
if (*pExpectedBlockType != WBT_EXTENSION)
|
2015-04-23 16:42:21 +03:00
|
|
|
{
|
2023-04-04 22:37:28 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR, "message unexpected wants a tileset");
|
2015-04-23 16:42:21 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2018-11-30 13:37:23 +03:00
|
|
|
*pExpectedBlockType = WBT_FRAME_END;
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2023-04-04 22:10:50 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 14))
|
2013-01-29 01:23:10 +04:00
|
|
|
return FALSE;
|
|
|
|
|
2018-11-30 13:37:23 +03:00
|
|
|
Stream_Read_UINT16(s, subtype); /* subtype (2 bytes) must be set to CBT_TILESET (0xCAC2) */
|
2011-08-10 11:13:39 +04:00
|
|
|
if (subtype != CBT_TILESET)
|
|
|
|
{
|
2023-04-04 22:37:28 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR, "invalid subtype, expected CBT_TILESET.");
|
2013-01-29 01:23:10 +04:00
|
|
|
return FALSE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Seek_UINT16(s); /* idx (2 bytes), must be set to 0x0000 */
|
|
|
|
Stream_Seek_UINT16(s); /* properties (2 bytes) */
|
2013-08-13 19:09:54 +04:00
|
|
|
Stream_Read_UINT8(s, context->numQuant); /* numQuant (1 byte) */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Seek_UINT8(s); /* tileSize (1 byte), must be set to 0x40 */
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2013-08-13 19:09:54 +04:00
|
|
|
if (context->numQuant < 1)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2023-04-04 22:37:28 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR, "no quantization value.");
|
2015-04-23 16:42:21 +03:00
|
|
|
return FALSE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2018-11-30 13:37:23 +03:00
|
|
|
Stream_Read_UINT16(s, numTiles); /* numTiles (2 bytes) */
|
|
|
|
if (numTiles < 1)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2016-05-11 20:53:34 +03:00
|
|
|
/* Windows Server 2012 (not R2) can send empty tile sets */
|
|
|
|
return TRUE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, tilesDataSize); /* tilesDataSize (4 bytes) */
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2023-03-24 14:14:38 +03:00
|
|
|
if (!(pmem =
|
|
|
|
winpr_aligned_recalloc(context->quants, context->numQuant, 10 * sizeof(UINT32), 32)))
|
2015-03-11 09:18:45 +03:00
|
|
|
return FALSE;
|
2013-10-09 04:17:57 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
quants = context->quants = (UINT32*)pmem;
|
2011-08-10 11:13:39 +04:00
|
|
|
|
|
|
|
/* quantVals */
|
2023-04-04 22:37:28 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthOfSizeWLog(context->priv->log, s, context->numQuant, 5ull))
|
2013-01-29 01:23:10 +04:00
|
|
|
return FALSE;
|
|
|
|
|
2023-04-05 11:52:10 +03:00
|
|
|
for (size_t i = 0; i < context->numQuant; i++)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
|
|
|
/* RFX_CODEC_QUANT */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, quant);
|
2011-08-10 11:13:39 +04:00
|
|
|
*quants++ = (quant & 0x0F);
|
|
|
|
*quants++ = (quant >> 4);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, quant);
|
2011-08-10 11:13:39 +04:00
|
|
|
*quants++ = (quant & 0x0F);
|
|
|
|
*quants++ = (quant >> 4);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, quant);
|
2011-08-10 11:13:39 +04:00
|
|
|
*quants++ = (quant & 0x0F);
|
|
|
|
*quants++ = (quant >> 4);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, quant);
|
2011-08-10 11:13:39 +04:00
|
|
|
*quants++ = (quant & 0x0F);
|
|
|
|
*quants++ = (quant >> 4);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, quant);
|
2011-08-10 11:13:39 +04:00
|
|
|
*quants++ = (quant & 0x0F);
|
|
|
|
*quants++ = (quant >> 4);
|
2016-04-05 18:07:45 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_DEBUG,
|
2019-11-06 17:24:51 +03:00
|
|
|
"quant %d (%" PRIu32 " %" PRIu32 " %" PRIu32 " %" PRIu32 " %" PRIu32 " %" PRIu32
|
|
|
|
" %" PRIu32 " %" PRIu32 " %" PRIu32 " %" PRIu32 ").",
|
2016-10-12 10:21:21 +03:00
|
|
|
i, context->quants[i * 10], context->quants[i * 10 + 1],
|
|
|
|
context->quants[i * 10 + 2], context->quants[i * 10 + 3],
|
|
|
|
context->quants[i * 10 + 4], context->quants[i * 10 + 5],
|
|
|
|
context->quants[i * 10 + 6], context->quants[i * 10 + 7],
|
|
|
|
context->quants[i * 10 + 8], context->quants[i * 10 + 9]);
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2023-04-05 11:52:10 +03:00
|
|
|
for (size_t i = 0; i < message->numTiles; i++)
|
2015-04-24 18:54:49 +03:00
|
|
|
{
|
2018-11-30 13:37:23 +03:00
|
|
|
ObjectPool_Return(context->priv->TilePool, message->tiles[i]);
|
|
|
|
message->tiles[i] = NULL;
|
2015-04-24 18:54:49 +03:00
|
|
|
}
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2023-06-12 10:33:49 +03:00
|
|
|
if (!rfx_allocate_tiles(message, numTiles, FALSE))
|
2018-11-30 13:37:23 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2013-01-23 06:54:13 +04:00
|
|
|
if (context->priv->UseThreads)
|
2013-01-23 03:14:50 +04:00
|
|
|
{
|
2023-03-24 14:14:38 +03:00
|
|
|
work_objects = (PTP_WORK*)winpr_aligned_calloc(message->numTiles, sizeof(PTP_WORK), 32);
|
|
|
|
params = (RFX_TILE_PROCESS_WORK_PARAM*)winpr_aligned_recalloc(
|
|
|
|
NULL, message->numTiles, sizeof(RFX_TILE_PROCESS_WORK_PARAM), 32);
|
2013-08-29 12:37:14 +04:00
|
|
|
|
|
|
|
if (!work_objects)
|
|
|
|
{
|
2023-03-24 14:14:38 +03:00
|
|
|
winpr_aligned_free(params);
|
2013-08-29 12:37:14 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
2013-10-09 04:17:57 +04:00
|
|
|
|
2013-08-29 12:37:14 +04:00
|
|
|
if (!params)
|
|
|
|
{
|
2023-03-24 14:14:38 +03:00
|
|
|
winpr_aligned_free(work_objects);
|
2013-08-29 12:37:14 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
2013-01-23 03:14:50 +04:00
|
|
|
}
|
|
|
|
|
2011-08-10 11:13:39 +04:00
|
|
|
/* tiles */
|
2013-08-29 17:30:22 +04:00
|
|
|
close_cnt = 0;
|
2021-11-29 16:29:07 +03:00
|
|
|
rc = FALSE;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2021-11-29 16:29:07 +03:00
|
|
|
if (Stream_GetRemainingLength(s) >= tilesDataSize)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2021-11-29 16:29:07 +03:00
|
|
|
rc = TRUE;
|
2023-04-05 11:52:10 +03:00
|
|
|
for (size_t i = 0; i < message->numTiles; i++)
|
2015-04-24 18:54:49 +03:00
|
|
|
{
|
2021-11-29 16:29:07 +03:00
|
|
|
wStream subBuffer;
|
|
|
|
wStream* sub;
|
2015-04-24 18:54:49 +03:00
|
|
|
|
2021-11-29 16:29:07 +03:00
|
|
|
if (!(tile = (RFX_TILE*)ObjectPool_Take(context->priv->TilePool)))
|
|
|
|
{
|
2023-04-04 22:37:28 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR,
|
|
|
|
"RfxMessageTileSet failed to get tile from object pool");
|
2021-11-29 16:29:07 +03:00
|
|
|
rc = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2013-01-29 01:23:10 +04:00
|
|
|
|
2021-11-29 16:29:07 +03:00
|
|
|
message->tiles[i] = tile;
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2021-11-29 16:29:07 +03:00
|
|
|
/* RFX_TILE */
|
2023-04-04 22:10:50 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 6))
|
2021-11-29 16:29:07 +03:00
|
|
|
{
|
2023-04-04 22:37:28 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR,
|
|
|
|
"RfxMessageTileSet packet too small to read tile %d/%" PRIu16 "", i,
|
|
|
|
message->numTiles);
|
2021-11-29 16:29:07 +03:00
|
|
|
rc = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2021-11-29 16:29:07 +03:00
|
|
|
sub = Stream_StaticInit(&subBuffer, Stream_Pointer(s), Stream_GetRemainingLength(s));
|
|
|
|
Stream_Read_UINT16(
|
|
|
|
sub, blockType); /* blockType (2 bytes), must be set to CBT_TILE (0xCAC3) */
|
|
|
|
Stream_Read_UINT32(sub, blockLen); /* blockLen (4 bytes) */
|
2013-01-23 03:14:50 +04:00
|
|
|
|
2021-11-29 16:29:07 +03:00
|
|
|
if (!Stream_SafeSeek(s, blockLen))
|
2020-01-23 11:06:19 +03:00
|
|
|
{
|
|
|
|
rc = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2023-04-04 22:10:50 +03:00
|
|
|
if ((blockLen < 6 + 13) ||
|
|
|
|
(!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, sub, blockLen - 6)))
|
2021-11-29 16:29:07 +03:00
|
|
|
{
|
2023-04-04 22:37:28 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR,
|
|
|
|
"RfxMessageTileSet not enough bytes to read tile %d/%" PRIu16
|
|
|
|
" with blocklen=%" PRIu32 "",
|
|
|
|
i, message->numTiles, blockLen);
|
2021-11-29 16:29:07 +03:00
|
|
|
rc = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2020-01-23 11:06:19 +03:00
|
|
|
|
2021-11-29 16:29:07 +03:00
|
|
|
if (blockType != CBT_TILE)
|
|
|
|
{
|
2023-04-04 22:37:28 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR,
|
|
|
|
"unknown block type 0x%" PRIX32 ", expected CBT_TILE (0xCAC3).",
|
|
|
|
blockType);
|
2021-11-29 16:29:07 +03:00
|
|
|
rc = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2013-01-23 03:14:50 +04:00
|
|
|
|
2021-11-29 16:29:07 +03:00
|
|
|
Stream_Read_UINT8(sub, tile->quantIdxY); /* quantIdxY (1 byte) */
|
|
|
|
Stream_Read_UINT8(sub, tile->quantIdxCb); /* quantIdxCb (1 byte) */
|
|
|
|
Stream_Read_UINT8(sub, tile->quantIdxCr); /* quantIdxCr (1 byte) */
|
2023-08-05 09:57:28 +03:00
|
|
|
if (tile->quantIdxY >= context->numQuant)
|
|
|
|
{
|
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR,
|
|
|
|
"quantIdxY %" PRIu8 " >= numQuant %" PRIu8, tile->quantIdxY,
|
|
|
|
context->numQuant);
|
|
|
|
rc = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (tile->quantIdxCb >= context->numQuant)
|
|
|
|
{
|
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR,
|
|
|
|
"quantIdxCb %" PRIu8 " >= numQuant %" PRIu8, tile->quantIdxCb,
|
|
|
|
context->numQuant);
|
|
|
|
rc = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (tile->quantIdxCr >= context->numQuant)
|
|
|
|
{
|
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR,
|
|
|
|
"quantIdxCr %" PRIu8 " >= numQuant %" PRIu8, tile->quantIdxCr,
|
|
|
|
context->numQuant);
|
|
|
|
rc = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-11-29 16:29:07 +03:00
|
|
|
Stream_Read_UINT16(sub, tile->xIdx); /* xIdx (2 bytes) */
|
|
|
|
Stream_Read_UINT16(sub, tile->yIdx); /* yIdx (2 bytes) */
|
|
|
|
Stream_Read_UINT16(sub, tile->YLen); /* YLen (2 bytes) */
|
|
|
|
Stream_Read_UINT16(sub, tile->CbLen); /* CbLen (2 bytes) */
|
|
|
|
Stream_Read_UINT16(sub, tile->CrLen); /* CrLen (2 bytes) */
|
|
|
|
Stream_GetPointer(sub, tile->YData);
|
|
|
|
if (!Stream_SafeSeek(sub, tile->YLen))
|
2015-04-24 18:54:49 +03:00
|
|
|
{
|
|
|
|
rc = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2021-11-29 16:29:07 +03:00
|
|
|
Stream_GetPointer(sub, tile->CbData);
|
|
|
|
if (!Stream_SafeSeek(sub, tile->CbLen))
|
|
|
|
{
|
|
|
|
rc = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Stream_GetPointer(sub, tile->CrData);
|
|
|
|
if (!Stream_SafeSeek(sub, tile->CrLen))
|
|
|
|
{
|
|
|
|
rc = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
tile->x = tile->xIdx * 64;
|
|
|
|
tile->y = tile->yIdx * 64;
|
2013-01-23 03:14:50 +04:00
|
|
|
|
2021-11-29 16:29:07 +03:00
|
|
|
if (context->priv->UseThreads)
|
|
|
|
{
|
|
|
|
if (!params)
|
|
|
|
{
|
|
|
|
rc = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
params[i].context = context;
|
|
|
|
params[i].tile = message->tiles[i];
|
|
|
|
|
|
|
|
if (!(work_objects[i] =
|
|
|
|
CreateThreadpoolWork(rfx_process_message_tile_work_callback,
|
|
|
|
(void*)¶ms[i], &context->priv->ThreadPoolEnv)))
|
|
|
|
{
|
2023-04-04 22:37:28 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR, "CreateThreadpoolWork failed.");
|
2021-11-29 16:29:07 +03:00
|
|
|
rc = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
SubmitThreadpoolWork(work_objects[i]);
|
|
|
|
close_cnt = i + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rfx_decode_rgb(context, tile, tile->data, 64 * 4);
|
|
|
|
}
|
2013-01-23 03:14:50 +04:00
|
|
|
}
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
2013-01-23 03:14:50 +04:00
|
|
|
|
2013-01-23 06:54:13 +04:00
|
|
|
if (context->priv->UseThreads)
|
2013-01-23 03:14:50 +04:00
|
|
|
{
|
2023-04-05 11:52:10 +03:00
|
|
|
for (size_t i = 0; i < close_cnt; i++)
|
2013-06-20 08:10:01 +04:00
|
|
|
{
|
2013-01-23 03:14:50 +04:00
|
|
|
WaitForThreadpoolWorkCallbacks(work_objects[i], FALSE);
|
2013-06-20 08:10:01 +04:00
|
|
|
CloseThreadpoolWork(work_objects[i]);
|
|
|
|
}
|
2015-04-24 18:54:49 +03:00
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2023-03-24 14:14:38 +03:00
|
|
|
winpr_aligned_free(work_objects);
|
|
|
|
winpr_aligned_free(params);
|
2013-08-14 01:18:59 +04:00
|
|
|
|
2023-04-05 11:52:10 +03:00
|
|
|
for (size_t i = 0; i < message->numTiles; i++)
|
2013-08-14 01:18:59 +04:00
|
|
|
{
|
2015-04-24 18:54:49 +03:00
|
|
|
if (!(tile = message->tiles[i]))
|
|
|
|
continue;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2013-08-14 01:18:59 +04:00
|
|
|
tile->YLen = tile->CbLen = tile->CrLen = 0;
|
|
|
|
tile->YData = tile->CbData = tile->CrData = NULL;
|
|
|
|
}
|
|
|
|
|
2013-09-02 17:07:39 +04:00
|
|
|
return rc;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
BOOL rfx_process_message(RFX_CONTEXT* context, const BYTE* data, UINT32 length, UINT32 left,
|
|
|
|
UINT32 top, BYTE* dst, UINT32 dstFormat, UINT32 dstStride,
|
|
|
|
UINT32 dstHeight, REGION16* invalidRegion)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2023-06-05 13:16:57 +03:00
|
|
|
REGION16 updateRegion = { 0 };
|
|
|
|
wStream inStream = { 0 };
|
2015-04-23 16:42:21 +03:00
|
|
|
BOOL ok = TRUE;
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2015-04-28 18:00:41 +03:00
|
|
|
if (!context || !data || !length)
|
2018-11-30 13:37:23 +03:00
|
|
|
return FALSE;
|
2012-11-22 05:21:08 +04:00
|
|
|
|
2023-04-04 22:10:50 +03:00
|
|
|
WINPR_ASSERT(context->priv);
|
2023-06-05 13:16:57 +03:00
|
|
|
RFX_MESSAGE* message = &context->currentMessage;
|
2019-10-16 19:49:24 +03:00
|
|
|
|
2023-06-05 13:16:57 +03:00
|
|
|
wStream* s = Stream_StaticConstInit(&inStream, data, length);
|
2013-08-14 18:14:47 +04:00
|
|
|
|
2015-04-23 16:42:21 +03:00
|
|
|
while (ok && Stream_GetRemainingLength(s) > 6)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2023-08-04 14:55:40 +03:00
|
|
|
wStream subStreamBuffer = { 0 };
|
2018-11-30 13:37:23 +03:00
|
|
|
size_t extraBlockLen = 0;
|
2023-08-04 14:55:40 +03:00
|
|
|
UINT32 blockLen = 0;
|
|
|
|
UINT32 blockType = 0;
|
2018-11-30 13:37:23 +03:00
|
|
|
|
2011-08-10 11:13:39 +04:00
|
|
|
/* RFX_BLOCKT */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, blockType); /* blockType (2 bytes) */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT32(s, blockLen); /* blockLen (4 bytes) */
|
|
|
|
WLog_Print(context->priv->log, WLOG_DEBUG, "blockType 0x%" PRIX32 " blockLen %" PRIu32 "",
|
2016-10-12 10:21:21 +03:00
|
|
|
blockType, blockLen);
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2018-11-30 13:37:23 +03:00
|
|
|
if (blockLen < 6)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2023-04-04 22:37:28 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR, "blockLen too small(%" PRIu32 ")", blockLen);
|
2018-11-30 13:37:23 +03:00
|
|
|
return FALSE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2023-04-04 22:10:50 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, blockLen - 6))
|
2018-11-30 13:37:23 +03:00
|
|
|
return FALSE;
|
2013-01-29 01:23:10 +04:00
|
|
|
|
2021-09-08 16:37:45 +03:00
|
|
|
if (blockType > WBT_CONTEXT && context->decodedHeaderBlocks != RFX_DECODED_HEADERS)
|
2015-04-23 16:42:21 +03:00
|
|
|
{
|
2023-04-04 22:37:28 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR, "incomplete header blocks processing");
|
2018-11-30 13:37:23 +03:00
|
|
|
return FALSE;
|
2015-04-23 16:42:21 +03:00
|
|
|
}
|
|
|
|
|
2011-08-10 11:13:39 +04:00
|
|
|
if (blockType >= WBT_CONTEXT && blockType <= WBT_EXTENSION)
|
|
|
|
{
|
|
|
|
/* RFX_CODEC_CHANNELT */
|
2023-08-04 14:55:40 +03:00
|
|
|
UINT8 codecId = 0;
|
|
|
|
UINT8 channelId = 0;
|
2015-04-23 16:42:21 +03:00
|
|
|
|
2023-04-04 22:10:50 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthWLog(context->priv->log, s, 2))
|
2018-11-30 13:37:23 +03:00
|
|
|
return FALSE;
|
2015-04-23 16:42:21 +03:00
|
|
|
|
2018-11-30 13:37:23 +03:00
|
|
|
extraBlockLen = 2;
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Read_UINT8(s, codecId); /* codecId (1 byte) must be set to 0x01 */
|
2018-11-30 13:37:23 +03:00
|
|
|
Stream_Read_UINT8(s, channelId); /* channelId (1 byte) 0xFF or 0x00, see below */
|
2015-04-23 16:42:21 +03:00
|
|
|
|
|
|
|
if (codecId != 0x01)
|
2013-01-29 01:23:10 +04:00
|
|
|
{
|
2023-04-04 22:37:28 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR, "invalid codecId 0x%02" PRIX8 "",
|
|
|
|
codecId);
|
2018-11-30 13:37:23 +03:00
|
|
|
return FALSE;
|
2015-04-23 16:42:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (blockType == WBT_CONTEXT)
|
|
|
|
{
|
|
|
|
/* If the blockType is set to WBT_CONTEXT, then channelId MUST be set to 0xFF.*/
|
|
|
|
if (channelId != 0xFF)
|
|
|
|
{
|
2023-04-04 22:37:28 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR,
|
|
|
|
"invalid channelId 0x%02" PRIX8 " for blockType 0x%08" PRIX32 "",
|
|
|
|
channelId, blockType);
|
2018-11-30 13:37:23 +03:00
|
|
|
return FALSE;
|
2015-04-23 16:42:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* For all other values of blockType, channelId MUST be set to 0x00. */
|
|
|
|
if (channelId != 0x00)
|
|
|
|
{
|
2023-04-04 22:37:28 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR,
|
|
|
|
"invalid channelId 0x%02" PRIX8 " for blockType WBT_CONTEXT",
|
|
|
|
channelId);
|
2018-11-30 13:37:23 +03:00
|
|
|
return FALSE;
|
2015-04-23 16:42:21 +03:00
|
|
|
}
|
2013-01-29 01:23:10 +04:00
|
|
|
}
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2023-08-04 14:55:40 +03:00
|
|
|
const size_t blockLenNoHeader = blockLen - 6;
|
|
|
|
if (blockLenNoHeader < extraBlockLen)
|
|
|
|
{
|
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR,
|
|
|
|
"blockLen too small(%" PRIu32 "), must be >= 6 + %" PRIu16, blockLen,
|
|
|
|
extraBlockLen);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
const size_t subStreamLen = blockLenNoHeader - extraBlockLen;
|
|
|
|
wStream* subStream = Stream_StaticInit(&subStreamBuffer, Stream_Pointer(s), subStreamLen);
|
|
|
|
Stream_Seek(s, subStreamLen);
|
2018-11-30 13:37:23 +03:00
|
|
|
|
2011-08-10 11:13:39 +04:00
|
|
|
switch (blockType)
|
|
|
|
{
|
2015-04-23 16:42:21 +03:00
|
|
|
/* Header messages:
|
|
|
|
* The stream MUST start with the header messages and any of these headers can appear
|
|
|
|
* in the stream at a later stage. The header messages can be repeated.
|
|
|
|
*/
|
2011-08-10 11:13:39 +04:00
|
|
|
case WBT_SYNC:
|
2021-10-14 09:42:49 +03:00
|
|
|
ok = rfx_process_message_sync(context, subStream);
|
2015-04-23 16:42:21 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WBT_CONTEXT:
|
2021-10-14 09:42:49 +03:00
|
|
|
ok = rfx_process_message_context(context, subStream);
|
2011-08-10 11:13:39 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WBT_CODEC_VERSIONS:
|
2021-10-14 09:42:49 +03:00
|
|
|
ok = rfx_process_message_codec_versions(context, subStream);
|
2011-08-10 11:13:39 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WBT_CHANNELS:
|
2021-10-14 09:42:49 +03:00
|
|
|
ok = rfx_process_message_channels(context, subStream);
|
2011-08-10 11:13:39 +04:00
|
|
|
break;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
/* Data messages:
|
|
|
|
* The data associated with each encoded frame or image is always bracketed by the
|
|
|
|
* TS_RFX_FRAME_BEGIN (section 2.2.2.3.1) and TS_RFX_FRAME_END (section 2.2.2.3.2)
|
|
|
|
* messages. There MUST only be one TS_RFX_REGION (section 2.2.2.3.3) message per
|
|
|
|
* frame and one TS_RFX_TILESET (section 2.2.2.3.4) message per TS_RFX_REGION.
|
|
|
|
*/
|
2011-08-10 11:13:39 +04:00
|
|
|
|
|
|
|
case WBT_FRAME_BEGIN:
|
2021-10-14 09:42:49 +03:00
|
|
|
ok = rfx_process_message_frame_begin(context, message, subStream,
|
2019-11-06 17:24:51 +03:00
|
|
|
&context->expectedDataBlockType);
|
2011-08-10 11:13:39 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WBT_REGION:
|
2021-10-14 09:42:49 +03:00
|
|
|
ok = rfx_process_message_region(context, message, subStream,
|
2019-11-06 17:24:51 +03:00
|
|
|
&context->expectedDataBlockType);
|
2011-08-10 11:13:39 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WBT_EXTENSION:
|
2021-10-14 09:42:49 +03:00
|
|
|
ok = rfx_process_message_tileset(context, message, subStream,
|
2019-11-06 17:24:51 +03:00
|
|
|
&context->expectedDataBlockType);
|
2011-08-10 11:13:39 +04:00
|
|
|
break;
|
|
|
|
|
2015-04-23 16:42:21 +03:00
|
|
|
case WBT_FRAME_END:
|
2021-10-14 09:42:49 +03:00
|
|
|
ok = rfx_process_message_frame_end(context, message, subStream,
|
2019-11-06 17:24:51 +03:00
|
|
|
&context->expectedDataBlockType);
|
2011-08-10 11:13:39 +04:00
|
|
|
break;
|
2015-04-23 16:42:21 +03:00
|
|
|
|
|
|
|
default:
|
2023-04-04 22:37:28 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR, "unknown blockType 0x%" PRIX32 "",
|
|
|
|
blockType);
|
2018-11-30 13:37:23 +03:00
|
|
|
return FALSE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-23 16:42:21 +03:00
|
|
|
if (ok)
|
|
|
|
{
|
2023-07-27 21:38:51 +03:00
|
|
|
UINT32 nbUpdateRects = 0;
|
|
|
|
REGION16 clippingRects = { 0 };
|
|
|
|
const RECTANGLE_16* updateRects = NULL;
|
2022-04-28 06:43:31 +03:00
|
|
|
const DWORD formatSize = FreeRDPGetBytesPerPixel(context->pixel_format);
|
|
|
|
const UINT32 dstWidth = dstStride / FreeRDPGetBytesPerPixel(dstFormat);
|
2016-04-05 18:07:45 +03:00
|
|
|
region16_init(&clippingRects);
|
|
|
|
|
2023-07-27 21:38:51 +03:00
|
|
|
WINPR_ASSERT(dstWidth <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(dstHeight <= UINT16_MAX);
|
|
|
|
for (UINT32 i = 0; i < message->numRects; i++)
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
2023-07-27 21:38:51 +03:00
|
|
|
RECTANGLE_16 clippingRect = { 0 };
|
2016-04-05 18:07:45 +03:00
|
|
|
const RFX_RECT* rect = &(message->rects[i]);
|
2023-07-27 21:38:51 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(left + rect->x <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(top + rect->y <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(clippingRect.left + rect->width <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(clippingRect.top + rect->height <= UINT16_MAX);
|
|
|
|
|
|
|
|
clippingRect.left = (UINT16)MIN(left + rect->x, dstWidth);
|
|
|
|
clippingRect.top = (UINT16)MIN(top + rect->y, dstHeight);
|
|
|
|
clippingRect.right = (UINT16)MIN(clippingRect.left + rect->width, dstWidth);
|
|
|
|
clippingRect.bottom = (UINT16)MIN(clippingRect.top + rect->height, dstHeight);
|
2016-04-05 18:07:45 +03:00
|
|
|
region16_union_rect(&clippingRects, &clippingRects, &clippingRect);
|
|
|
|
}
|
|
|
|
|
2023-07-27 21:38:51 +03:00
|
|
|
for (UINT32 i = 0; i < message->numTiles; i++)
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
2023-07-27 21:38:51 +03:00
|
|
|
RECTANGLE_16 updateRect = { 0 };
|
2016-04-11 18:30:29 +03:00
|
|
|
const RFX_TILE* tile = rfx_message_get_tile(message, i);
|
2023-07-27 21:38:51 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(left + tile->x <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(top + tile->y <= UINT16_MAX);
|
|
|
|
|
|
|
|
updateRect.left = (UINT16)left + tile->x;
|
|
|
|
updateRect.top = (UINT16)top + tile->y;
|
2016-04-05 18:07:45 +03:00
|
|
|
updateRect.right = updateRect.left + 64;
|
|
|
|
updateRect.bottom = updateRect.top + 64;
|
|
|
|
region16_init(&updateRegion);
|
|
|
|
region16_intersect_rect(&updateRegion, &clippingRects, &updateRect);
|
|
|
|
updateRects = region16_rects(&updateRegion, &nbUpdateRects);
|
|
|
|
|
2023-07-27 21:38:51 +03:00
|
|
|
for (UINT32 j = 0; j < nbUpdateRects; j++)
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
2017-02-11 13:13:14 +03:00
|
|
|
const UINT32 stride = 64 * formatSize;
|
|
|
|
const UINT32 nXDst = updateRects[j].left;
|
|
|
|
const UINT32 nYDst = updateRects[j].top;
|
|
|
|
const UINT32 nXSrc = nXDst - updateRect.left;
|
|
|
|
const UINT32 nYSrc = nYDst - updateRect.top;
|
|
|
|
const UINT32 nWidth = updateRects[j].right - updateRects[j].left;
|
|
|
|
const UINT32 nHeight = updateRects[j].bottom - updateRects[j].top;
|
2017-02-09 14:36:54 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!freerdp_image_copy(dst, dstFormat, dstStride, nXDst, nYDst, nWidth, nHeight,
|
|
|
|
tile->data, context->pixel_format, stride, nXSrc, nYSrc,
|
|
|
|
NULL, FREERDP_FLIP_NONE))
|
2016-12-13 17:36:05 +03:00
|
|
|
{
|
|
|
|
region16_uninit(&updateRegion);
|
2023-04-04 22:37:28 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR,
|
2023-07-28 12:45:58 +03:00
|
|
|
"nbUpdateRectx[%" PRIu32 " (%" PRIu32 ")] freerdp_image_copy failed",
|
2023-04-04 22:37:28 +03:00
|
|
|
j, nbUpdateRects);
|
2018-11-30 13:37:23 +03:00
|
|
|
return FALSE;
|
2016-12-13 17:36:05 +03:00
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
|
|
|
if (invalidRegion)
|
|
|
|
region16_union_rect(invalidRegion, invalidRegion, &updateRects[j]);
|
|
|
|
}
|
|
|
|
|
|
|
|
region16_uninit(&updateRegion);
|
|
|
|
}
|
|
|
|
|
|
|
|
region16_uninit(&clippingRects);
|
|
|
|
return TRUE;
|
2015-04-23 16:42:21 +03:00
|
|
|
}
|
2023-08-05 10:29:19 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
rfx_message_free(context, message);
|
|
|
|
context->currentMessage.freeArray = TRUE;
|
|
|
|
}
|
2015-04-23 16:42:21 +03:00
|
|
|
|
2023-04-04 22:37:28 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR, "failed");
|
2016-04-05 18:07:45 +03:00
|
|
|
return FALSE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2023-04-05 14:47:59 +03:00
|
|
|
const UINT32* rfx_message_get_quants(const RFX_MESSAGE* message, UINT16* numQuantVals)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(message);
|
|
|
|
if (numQuantVals)
|
|
|
|
*numQuantVals = message->numQuant;
|
|
|
|
return message->quantVals;
|
|
|
|
}
|
|
|
|
|
|
|
|
const RFX_TILE** rfx_message_get_tiles(const RFX_MESSAGE* message, UINT16* numTiles)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(message);
|
|
|
|
if (numTiles)
|
|
|
|
*numTiles = message->numTiles;
|
|
|
|
return message->tiles;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT16 rfx_message_get_tile_count(const RFX_MESSAGE* message)
|
2011-09-19 06:34:19 +04:00
|
|
|
{
|
2023-04-04 22:10:50 +03:00
|
|
|
WINPR_ASSERT(message);
|
2013-08-14 01:18:59 +04:00
|
|
|
return message->numTiles;
|
2011-09-19 06:34:19 +04:00
|
|
|
}
|
|
|
|
|
2023-04-05 14:47:59 +03:00
|
|
|
const RFX_RECT* rfx_message_get_rects(const RFX_MESSAGE* message, UINT16* numRects)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(message);
|
|
|
|
if (numRects)
|
|
|
|
*numRects = message->numRects;
|
|
|
|
return message->rects;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT16 rfx_message_get_rect_count(const RFX_MESSAGE* message)
|
2011-09-19 06:34:19 +04:00
|
|
|
{
|
2023-04-04 22:10:50 +03:00
|
|
|
WINPR_ASSERT(message);
|
2013-08-14 01:18:59 +04:00
|
|
|
return message->numRects;
|
2011-09-19 06:34:19 +04:00
|
|
|
}
|
|
|
|
|
2011-08-10 11:13:39 +04:00
|
|
|
void rfx_message_free(RFX_CONTEXT* context, RFX_MESSAGE* message)
|
|
|
|
{
|
2023-04-04 22:10:50 +03:00
|
|
|
if (!message)
|
|
|
|
return;
|
|
|
|
|
2023-06-12 10:33:49 +03:00
|
|
|
winpr_aligned_free(message->rects);
|
2013-01-21 05:44:30 +04:00
|
|
|
|
2023-04-04 22:10:50 +03:00
|
|
|
if (message->tiles)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2023-04-04 22:10:50 +03:00
|
|
|
for (size_t i = 0; i < message->numTiles; i++)
|
2013-08-14 01:18:59 +04:00
|
|
|
{
|
2023-04-04 22:10:50 +03:00
|
|
|
RFX_TILE* tile = message->tiles[i];
|
|
|
|
if (!tile)
|
|
|
|
continue;
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2023-04-04 22:10:50 +03:00
|
|
|
if (tile->YCbCrData)
|
2013-08-13 17:34:15 +04:00
|
|
|
{
|
2023-04-04 22:10:50 +03:00
|
|
|
BufferPool_Return(context->priv->BufferPool, tile->YCbCrData);
|
|
|
|
tile->YCbCrData = NULL;
|
2013-08-13 17:34:15 +04:00
|
|
|
}
|
2013-01-21 05:44:30 +04:00
|
|
|
|
2023-04-04 22:10:50 +03:00
|
|
|
ObjectPool_Return(context->priv->TilePool, (void*)tile);
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2023-06-12 10:33:49 +03:00
|
|
|
rfx_allocate_tiles(message, 0, FALSE);
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
2023-04-04 22:10:50 +03:00
|
|
|
|
2023-06-12 10:33:49 +03:00
|
|
|
const BOOL freeArray = message->freeArray;
|
|
|
|
const RFX_MESSAGE empty = { 0 };
|
|
|
|
*message = empty;
|
|
|
|
|
|
|
|
if (!freeArray)
|
2023-04-04 22:10:50 +03:00
|
|
|
winpr_aligned_free(message);
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-08-14 18:14:47 +04:00
|
|
|
static void rfx_update_context_properties(RFX_CONTEXT* context)
|
|
|
|
{
|
2023-04-04 22:10:50 +03:00
|
|
|
UINT16 properties = 0;
|
|
|
|
|
|
|
|
WINPR_ASSERT(context);
|
2013-08-14 18:14:47 +04:00
|
|
|
/* properties in tilesets: note that this has different format from the one in TS_RFX_CONTEXT */
|
2019-11-06 17:24:51 +03:00
|
|
|
properties = 1; /* lt */
|
|
|
|
properties |= (context->flags << 1); /* flags */
|
|
|
|
properties |= (COL_CONV_ICT << 4); /* cct */
|
2013-08-14 18:14:47 +04:00
|
|
|
properties |= (CLW_XFORM_DWT_53_A << 6); /* xft */
|
2018-11-30 13:37:23 +03:00
|
|
|
properties |= ((context->mode == RLGR1 ? CLW_ENTROPY_RLGR1 : CLW_ENTROPY_RLGR3) << 10); /* et */
|
2019-11-06 17:24:51 +03:00
|
|
|
properties |= (SCALAR_QUANTIZATION << 14); /* qt */
|
2013-08-14 18:14:47 +04:00
|
|
|
context->properties = properties;
|
|
|
|
}
|
|
|
|
|
2023-06-12 10:33:49 +03:00
|
|
|
static void rfx_write_message_sync(const RFX_CONTEXT* context, wStream* s)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2023-04-04 22:10:50 +03:00
|
|
|
WINPR_ASSERT(context);
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT16(s, WBT_SYNC); /* BlockT.blockType (2 bytes) */
|
|
|
|
Stream_Write_UINT32(s, 12); /* BlockT.blockLen (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, WF_MAGIC); /* magic (4 bytes) */
|
2013-08-14 18:14:47 +04:00
|
|
|
Stream_Write_UINT16(s, WF_VERSION_1_0); /* version (2 bytes) */
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2023-06-12 10:33:49 +03:00
|
|
|
static void rfx_write_message_codec_versions(const RFX_CONTEXT* context, wStream* s)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2023-04-04 22:10:50 +03:00
|
|
|
WINPR_ASSERT(context);
|
|
|
|
|
2013-08-14 18:14:47 +04:00
|
|
|
Stream_Write_UINT16(s, WBT_CODEC_VERSIONS); /* BlockT.blockType (2 bytes) */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT32(s, 10); /* BlockT.blockLen (4 bytes) */
|
|
|
|
Stream_Write_UINT8(s, 1); /* numCodecs (1 byte) */
|
|
|
|
Stream_Write_UINT8(s, 1); /* codecs.codecId (1 byte) */
|
|
|
|
Stream_Write_UINT16(s, WF_VERSION_1_0); /* codecs.version (2 bytes) */
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2023-06-12 10:33:49 +03:00
|
|
|
static void rfx_write_message_channels(const RFX_CONTEXT* context, wStream* s)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2023-04-04 22:10:50 +03:00
|
|
|
WINPR_ASSERT(context);
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT16(s, WBT_CHANNELS); /* BlockT.blockType (2 bytes) */
|
|
|
|
Stream_Write_UINT32(s, 12); /* BlockT.blockLen (4 bytes) */
|
|
|
|
Stream_Write_UINT8(s, 1); /* numChannels (1 byte) */
|
|
|
|
Stream_Write_UINT8(s, 0); /* Channel.channelId (1 byte) */
|
|
|
|
Stream_Write_UINT16(s, context->width); /* Channel.width (2 bytes) */
|
2013-08-14 18:14:47 +04:00
|
|
|
Stream_Write_UINT16(s, context->height); /* Channel.height (2 bytes) */
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-08-14 18:14:47 +04:00
|
|
|
static void rfx_write_message_context(RFX_CONTEXT* context, wStream* s)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2023-04-04 22:10:50 +03:00
|
|
|
UINT16 properties = 0;
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT16(s, WBT_CONTEXT); /* CodecChannelT.blockType (2 bytes) */
|
|
|
|
Stream_Write_UINT32(s, 13); /* CodecChannelT.blockLen (4 bytes) */
|
|
|
|
Stream_Write_UINT8(s, 1); /* CodecChannelT.codecId (1 byte) */
|
|
|
|
Stream_Write_UINT8(s, 0xFF); /* CodecChannelT.channelId (1 byte) */
|
|
|
|
Stream_Write_UINT8(s, 0); /* ctxId (1 byte) */
|
2013-08-14 18:14:47 +04:00
|
|
|
Stream_Write_UINT16(s, CT_TILE_64x64); /* tileSize (2 bytes) */
|
2011-08-10 11:13:39 +04:00
|
|
|
/* properties */
|
2019-11-06 17:24:51 +03:00
|
|
|
properties = context->flags; /* flags */
|
|
|
|
properties |= (COL_CONV_ICT << 3); /* cct */
|
2011-08-10 11:13:39 +04:00
|
|
|
properties |= (CLW_XFORM_DWT_53_A << 5); /* xft */
|
2019-11-06 17:24:51 +03:00
|
|
|
properties |= ((context->mode == RLGR1 ? CLW_ENTROPY_RLGR1 : CLW_ENTROPY_RLGR3) << 9); /* et */
|
|
|
|
properties |= (SCALAR_QUANTIZATION << 13); /* qt */
|
2013-08-14 18:14:47 +04:00
|
|
|
Stream_Write_UINT16(s, properties); /* properties (2 bytes) */
|
|
|
|
rfx_update_context_properties(context);
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2015-04-23 16:42:21 +03:00
|
|
|
static BOOL rfx_compose_message_header(RFX_CONTEXT* context, wStream* s)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2023-04-04 22:10:50 +03:00
|
|
|
WINPR_ASSERT(context);
|
2015-03-30 18:15:45 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 12 + 10 + 12 + 13))
|
2015-04-23 16:42:21 +03:00
|
|
|
return FALSE;
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2013-08-14 18:14:47 +04:00
|
|
|
rfx_write_message_sync(context, s);
|
|
|
|
rfx_write_message_context(context, s);
|
|
|
|
rfx_write_message_codec_versions(context, s);
|
|
|
|
rfx_write_message_channels(context, s);
|
2015-04-23 16:42:21 +03:00
|
|
|
return TRUE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2023-06-12 10:33:49 +03:00
|
|
|
static size_t rfx_tile_length(const RFX_TILE* tile)
|
2013-08-14 01:18:59 +04:00
|
|
|
{
|
2023-04-04 22:08:54 +03:00
|
|
|
WINPR_ASSERT(tile);
|
|
|
|
return 19ull + tile->YLen + tile->CbLen + tile->CrLen;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2023-06-12 10:33:49 +03:00
|
|
|
static BOOL rfx_write_tile(wStream* s, const RFX_TILE* tile)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2023-04-04 22:10:50 +03:00
|
|
|
const size_t blockLen = rfx_tile_length(tile);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-03-30 18:15:45 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, blockLen))
|
2015-04-23 16:42:21 +03:00
|
|
|
return FALSE;
|
2013-08-13 22:13:05 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT16(s, CBT_TILE); /* BlockT.blockType (2 bytes) */
|
|
|
|
Stream_Write_UINT32(s, blockLen); /* BlockT.blockLen (4 bytes) */
|
|
|
|
Stream_Write_UINT8(s, tile->quantIdxY); /* quantIdxY (1 byte) */
|
|
|
|
Stream_Write_UINT8(s, tile->quantIdxCb); /* quantIdxCb (1 byte) */
|
|
|
|
Stream_Write_UINT8(s, tile->quantIdxCr); /* quantIdxCr (1 byte) */
|
|
|
|
Stream_Write_UINT16(s, tile->xIdx); /* xIdx (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, tile->yIdx); /* yIdx (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, tile->YLen); /* YLen (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, tile->CbLen); /* CbLen (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, tile->CrLen); /* CrLen (2 bytes) */
|
|
|
|
Stream_Write(s, tile->YData, tile->YLen); /* YData */
|
2013-08-13 22:13:05 +04:00
|
|
|
Stream_Write(s, tile->CbData, tile->CbLen); /* CbData */
|
|
|
|
Stream_Write(s, tile->CrData, tile->CrLen); /* CrData */
|
2015-04-23 16:42:21 +03:00
|
|
|
return TRUE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
struct S_RFX_TILE_COMPOSE_WORK_PARAM
|
2013-08-04 14:07:53 +04:00
|
|
|
{
|
2013-08-13 18:30:22 +04:00
|
|
|
RFX_TILE* tile;
|
2013-08-04 14:07:53 +04:00
|
|
|
RFX_CONTEXT* context;
|
|
|
|
};
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static void CALLBACK rfx_compose_message_tile_work_callback(PTP_CALLBACK_INSTANCE instance,
|
|
|
|
void* context, PTP_WORK work)
|
2013-08-04 14:07:53 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
RFX_TILE_COMPOSE_WORK_PARAM* param = (RFX_TILE_COMPOSE_WORK_PARAM*)context;
|
2023-04-04 22:10:50 +03:00
|
|
|
WINPR_ASSERT(param);
|
2013-08-13 22:13:05 +04:00
|
|
|
rfx_encode_rgb(param->context, param->tile);
|
2013-08-04 14:07:53 +04:00
|
|
|
}
|
|
|
|
|
2023-04-04 22:10:50 +03:00
|
|
|
static BOOL computeRegion(const RFX_RECT* rects, size_t numRects, REGION16* region, size_t width,
|
|
|
|
size_t height)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2014-02-07 19:43:48 +04:00
|
|
|
const RECTANGLE_16 mainRect = { 0, 0, width, height };
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2023-04-04 22:10:50 +03:00
|
|
|
WINPR_ASSERT(rects);
|
|
|
|
for (size_t i = 0; i < numRects; i++)
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
2023-04-04 22:10:50 +03:00
|
|
|
const RFX_RECT* rect = &rects[i];
|
|
|
|
RECTANGLE_16 rect16 = { 0 };
|
2014-02-04 15:02:55 +04:00
|
|
|
rect16.left = rect->x;
|
|
|
|
rect16.top = rect->y;
|
|
|
|
rect16.right = rect->x + rect->width;
|
|
|
|
rect16.bottom = rect->y + rect->height;
|
|
|
|
|
|
|
|
if (!region16_union_rect(region, region, &rect16))
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-02-07 19:43:48 +04:00
|
|
|
|
|
|
|
return region16_intersect_rect(region, region, &mainRect);
|
2014-02-04 15:02:55 +04:00
|
|
|
}
|
|
|
|
|
2014-02-05 17:07:22 +04:00
|
|
|
#define TILE_NO(v) ((v) / 64)
|
2014-02-04 15:02:55 +04:00
|
|
|
|
2023-04-04 22:10:50 +03:00
|
|
|
static BOOL setupWorkers(RFX_CONTEXT* context, size_t nbTiles)
|
2014-02-04 15:02:55 +04:00
|
|
|
{
|
2023-04-04 22:10:50 +03:00
|
|
|
WINPR_ASSERT(context);
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
RFX_CONTEXT_PRIV* priv = context->priv;
|
2023-04-04 22:10:50 +03:00
|
|
|
WINPR_ASSERT(priv);
|
|
|
|
|
2015-04-23 16:42:21 +03:00
|
|
|
void* pmem;
|
2014-02-04 15:02:55 +04:00
|
|
|
|
|
|
|
if (!context->priv->UseThreads)
|
|
|
|
return TRUE;
|
|
|
|
|
2023-03-24 14:14:38 +03:00
|
|
|
if (!(pmem = winpr_aligned_recalloc(priv->workObjects, nbTiles, sizeof(PTP_WORK), 32)))
|
2014-07-08 23:07:19 +04:00
|
|
|
return FALSE;
|
2013-10-09 04:17:57 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
priv->workObjects = (PTP_WORK*)pmem;
|
2014-07-08 23:07:19 +04:00
|
|
|
|
2023-03-24 14:14:38 +03:00
|
|
|
if (!(pmem = winpr_aligned_recalloc(priv->tileWorkParams, nbTiles,
|
|
|
|
sizeof(RFX_TILE_COMPOSE_WORK_PARAM), 32)))
|
2014-02-04 15:02:55 +04:00
|
|
|
return FALSE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
priv->tileWorkParams = (RFX_TILE_COMPOSE_WORK_PARAM*)pmem;
|
2014-02-04 15:02:55 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-04-05 12:23:09 +03:00
|
|
|
static BOOL rfx_ensure_tiles(RFX_MESSAGE* message, size_t count)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(message);
|
|
|
|
|
2023-06-12 10:33:49 +03:00
|
|
|
if (message->numTiles + count <= message->allocatedTiles)
|
2023-04-05 12:23:09 +03:00
|
|
|
return TRUE;
|
|
|
|
|
2023-06-12 10:33:49 +03:00
|
|
|
const size_t alloc = MAX(message->allocatedTiles + 1024, message->numTiles + count);
|
|
|
|
return rfx_allocate_tiles(message, alloc, TRUE);
|
2023-04-05 12:23:09 +03:00
|
|
|
}
|
|
|
|
|
2020-12-14 19:44:30 +03:00
|
|
|
RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects, size_t numRects,
|
|
|
|
const BYTE* data, UINT32 w, UINT32 h, size_t s)
|
2014-02-04 15:02:55 +04:00
|
|
|
{
|
2019-02-07 16:17:35 +03:00
|
|
|
const UINT32 width = (UINT32)w;
|
|
|
|
const UINT32 height = (UINT32)h;
|
|
|
|
const UINT32 scanline = (UINT32)s;
|
2013-08-14 01:18:59 +04:00
|
|
|
RFX_MESSAGE* message = NULL;
|
2014-02-05 17:07:22 +04:00
|
|
|
PTP_WORK* workObject = NULL;
|
2016-04-05 18:07:45 +03:00
|
|
|
RFX_TILE_COMPOSE_WORK_PARAM* workParam = NULL;
|
2015-04-23 16:42:21 +03:00
|
|
|
BOOL success = FALSE;
|
2023-06-12 10:33:49 +03:00
|
|
|
REGION16 rectsRegion = { 0 }, tilesRegion = { 0 };
|
|
|
|
RECTANGLE_16 currentTileRect = { 0 };
|
|
|
|
const RECTANGLE_16* regionRect = NULL;
|
|
|
|
|
2021-06-09 15:03:34 +03:00
|
|
|
WINPR_ASSERT(data);
|
|
|
|
WINPR_ASSERT(rects);
|
|
|
|
WINPR_ASSERT(numRects > 0);
|
|
|
|
WINPR_ASSERT(w > 0);
|
|
|
|
WINPR_ASSERT(h > 0);
|
|
|
|
WINPR_ASSERT(s > 0);
|
2014-02-07 19:43:48 +04:00
|
|
|
|
2023-03-24 14:14:38 +03:00
|
|
|
if (!(message = (RFX_MESSAGE*)winpr_aligned_calloc(1, sizeof(RFX_MESSAGE), 32)))
|
2013-08-29 17:30:22 +04:00
|
|
|
return NULL;
|
|
|
|
|
2015-04-23 16:42:21 +03:00
|
|
|
region16_init(&tilesRegion);
|
|
|
|
region16_init(&rectsRegion);
|
|
|
|
|
2013-08-14 18:14:47 +04:00
|
|
|
if (context->state == RFX_STATE_SEND_HEADERS)
|
|
|
|
rfx_update_context_properties(context);
|
|
|
|
|
2013-08-14 01:50:05 +04:00
|
|
|
message->frameIdx = context->frameIdx++;
|
2014-07-08 23:07:19 +04:00
|
|
|
|
2013-08-13 19:09:54 +04:00
|
|
|
if (!context->numQuant)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2023-06-12 10:33:49 +03:00
|
|
|
WINPR_ASSERT(context->quants == NULL);
|
2023-03-24 14:14:38 +03:00
|
|
|
if (!(context->quants =
|
|
|
|
(UINT32*)winpr_aligned_malloc(sizeof(rfx_default_quantization_values), 32)))
|
2015-04-23 16:42:21 +03:00
|
|
|
goto skip_encoding_loop;
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
CopyMemory(context->quants, &rfx_default_quantization_values,
|
2016-10-12 10:21:21 +03:00
|
|
|
sizeof(rfx_default_quantization_values));
|
2015-04-23 16:42:21 +03:00
|
|
|
context->numQuant = 1;
|
2013-08-13 19:09:54 +04:00
|
|
|
context->quantIdxY = 0;
|
|
|
|
context->quantIdxCb = 0;
|
|
|
|
context->quantIdxCr = 0;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
2014-07-08 23:07:19 +04:00
|
|
|
|
2013-08-14 01:18:59 +04:00
|
|
|
message->numQuant = context->numQuant;
|
|
|
|
message->quantVals = context->quants;
|
2023-06-12 10:33:49 +03:00
|
|
|
const UINT32 bytesPerPixel = (context->bits_per_pixel / 8);
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2014-02-07 19:43:48 +04:00
|
|
|
if (!computeRegion(rects, numRects, &rectsRegion, width, height))
|
2015-04-23 16:42:21 +03:00
|
|
|
goto skip_encoding_loop;
|
2014-02-07 19:43:48 +04:00
|
|
|
|
2023-06-12 10:33:49 +03:00
|
|
|
const RECTANGLE_16* extents = region16_extents(&rectsRegion);
|
|
|
|
WINPR_ASSERT((INT32)extents->right - extents->left > 0);
|
|
|
|
WINPR_ASSERT((INT32)extents->bottom - extents->top > 0);
|
|
|
|
const UINT32 maxTilesX = 1 + TILE_NO(extents->right - 1) - TILE_NO(extents->left);
|
|
|
|
const UINT32 maxTilesY = 1 + TILE_NO(extents->bottom - 1) - TILE_NO(extents->top);
|
|
|
|
const UINT32 maxNbTiles = maxTilesX * maxTilesY;
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2023-04-05 12:23:09 +03:00
|
|
|
if (!rfx_ensure_tiles(message, maxNbTiles))
|
2015-04-23 16:42:21 +03:00
|
|
|
goto skip_encoding_loop;
|
2014-02-04 15:02:55 +04:00
|
|
|
|
|
|
|
if (!setupWorkers(context, maxNbTiles))
|
2015-04-23 16:42:21 +03:00
|
|
|
goto skip_encoding_loop;
|
2013-08-04 14:07:53 +04:00
|
|
|
|
|
|
|
if (context->priv->UseThreads)
|
2013-08-14 01:18:59 +04:00
|
|
|
{
|
2014-02-04 15:02:55 +04:00
|
|
|
workObject = context->priv->workObjects;
|
|
|
|
workParam = context->priv->tileWorkParams;
|
2013-08-14 01:18:59 +04:00
|
|
|
}
|
2013-08-04 14:07:53 +04:00
|
|
|
|
2023-06-12 10:33:49 +03:00
|
|
|
UINT32 regionNbRects = 0;
|
2014-02-04 15:02:55 +04:00
|
|
|
regionRect = region16_rects(&rectsRegion, ®ionNbRects);
|
2014-07-08 23:07:19 +04:00
|
|
|
|
2023-03-24 14:14:38 +03:00
|
|
|
if (!(message->rects = winpr_aligned_calloc(regionNbRects, sizeof(RFX_RECT), 32)))
|
2015-04-23 16:42:21 +03:00
|
|
|
goto skip_encoding_loop;
|
2014-07-08 23:07:19 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
message->numRects = regionNbRects;
|
|
|
|
|
2023-04-05 11:43:03 +03:00
|
|
|
for (UINT32 i = 0; i < regionNbRects; i++, regionRect++)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2023-04-05 11:43:03 +03:00
|
|
|
RFX_RECT* rfxRect = &message->rects[i];
|
2019-02-07 16:17:35 +03:00
|
|
|
UINT32 startTileX = regionRect->left / 64;
|
|
|
|
UINT32 endTileX = (regionRect->right - 1) / 64;
|
|
|
|
UINT32 startTileY = regionRect->top / 64;
|
|
|
|
UINT32 endTileY = (regionRect->bottom - 1) / 64;
|
2014-02-04 15:02:55 +04:00
|
|
|
rfxRect->x = regionRect->left;
|
|
|
|
rfxRect->y = regionRect->top;
|
|
|
|
rfxRect->width = (regionRect->right - regionRect->left);
|
|
|
|
rfxRect->height = (regionRect->bottom - regionRect->top);
|
|
|
|
|
2023-04-05 11:43:03 +03:00
|
|
|
for (UINT32 yIdx = startTileY, gridRelY = startTileY * 64; yIdx <= endTileY;
|
2016-04-05 18:07:45 +03:00
|
|
|
yIdx++, gridRelY += 64)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2019-02-07 16:17:35 +03:00
|
|
|
UINT32 tileHeight = 64;
|
2014-07-08 23:07:19 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
if ((yIdx == endTileY) && (gridRelY + 64 > height))
|
|
|
|
tileHeight = height - gridRelY;
|
2013-08-13 18:30:22 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
currentTileRect.top = gridRelY;
|
|
|
|
currentTileRect.bottom = gridRelY + tileHeight;
|
2013-08-13 18:30:22 +04:00
|
|
|
|
2023-04-05 11:43:03 +03:00
|
|
|
for (UINT32 xIdx = startTileX, gridRelX = startTileX * 64; xIdx <= endTileX;
|
2016-04-05 18:07:45 +03:00
|
|
|
xIdx++, gridRelX += 64)
|
2013-09-03 16:27:08 +04:00
|
|
|
{
|
2022-04-27 22:02:18 +03:00
|
|
|
union
|
|
|
|
{
|
|
|
|
const BYTE* cpv;
|
|
|
|
BYTE* pv;
|
|
|
|
} cnv;
|
2014-02-04 15:02:55 +04:00
|
|
|
int tileWidth = 64;
|
2014-07-08 23:07:19 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
if ((xIdx == endTileX) && (gridRelX + 64 > width))
|
|
|
|
tileWidth = width - gridRelX;
|
|
|
|
|
|
|
|
currentTileRect.left = gridRelX;
|
|
|
|
currentTileRect.right = gridRelX + tileWidth;
|
|
|
|
|
|
|
|
/* checks if this tile is already treated */
|
2014-02-05 17:07:22 +04:00
|
|
|
if (region16_intersects_rect(&tilesRegion, ¤tTileRect))
|
2014-02-04 15:02:55 +04:00
|
|
|
continue;
|
2013-08-15 04:35:00 +04:00
|
|
|
|
2023-04-04 22:08:54 +03:00
|
|
|
RFX_TILE* tile = (RFX_TILE*)ObjectPool_Take(context->priv->TilePool);
|
|
|
|
if (!tile)
|
2015-04-23 16:42:21 +03:00
|
|
|
goto skip_encoding_loop;
|
2014-02-04 15:02:55 +04:00
|
|
|
|
|
|
|
tile->xIdx = xIdx;
|
|
|
|
tile->yIdx = yIdx;
|
|
|
|
tile->x = gridRelX;
|
|
|
|
tile->y = gridRelY;
|
|
|
|
tile->scanline = scanline;
|
|
|
|
tile->width = tileWidth;
|
|
|
|
tile->height = tileHeight;
|
2023-06-12 10:33:49 +03:00
|
|
|
const UINT32 ax = gridRelX;
|
|
|
|
const UINT32 ay = gridRelY;
|
2014-07-08 23:07:19 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
if (tile->data && tile->allocated)
|
|
|
|
{
|
2023-03-24 14:14:38 +03:00
|
|
|
winpr_aligned_free(tile->data);
|
2014-02-04 15:02:55 +04:00
|
|
|
tile->allocated = FALSE;
|
|
|
|
}
|
2013-08-15 04:35:00 +04:00
|
|
|
|
2020-12-14 19:44:30 +03:00
|
|
|
/* Cast away const */
|
2022-04-27 22:02:18 +03:00
|
|
|
cnv.cpv = &data[(ay * scanline) + (ax * bytesPerPixel)];
|
|
|
|
tile->data = cnv.pv;
|
2014-02-04 15:02:55 +04:00
|
|
|
tile->quantIdxY = context->quantIdxY;
|
|
|
|
tile->quantIdxCb = context->quantIdxCb;
|
|
|
|
tile->quantIdxCr = context->quantIdxCr;
|
|
|
|
tile->YLen = tile->CbLen = tile->CrLen = 0;
|
2013-08-20 02:39:19 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (!(tile->YCbCrData = (BYTE*)BufferPool_Take(context->priv->BufferPool, -1)))
|
2015-04-23 16:42:21 +03:00
|
|
|
goto skip_encoding_loop;
|
2013-08-20 02:39:19 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
tile->YData = (BYTE*)&(tile->YCbCrData[((8192 + 32) * 0) + 16]);
|
|
|
|
tile->CbData = (BYTE*)&(tile->YCbCrData[((8192 + 32) * 1) + 16]);
|
|
|
|
tile->CrData = (BYTE*)&(tile->YCbCrData[((8192 + 32) * 2) + 16]);
|
2023-04-05 12:23:09 +03:00
|
|
|
|
|
|
|
if (!rfx_ensure_tiles(message, 1))
|
|
|
|
goto skip_encoding_loop;
|
|
|
|
message->tiles[message->numTiles++] = tile;
|
2015-04-23 16:42:21 +03:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
if (context->priv->UseThreads)
|
|
|
|
{
|
|
|
|
workParam->context = context;
|
|
|
|
workParam->tile = tile;
|
2013-08-30 16:19:50 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!(*workObject = CreateThreadpoolWork(rfx_compose_message_tile_work_callback,
|
|
|
|
(void*)workParam,
|
|
|
|
&context->priv->ThreadPoolEnv)))
|
2015-04-23 16:42:21 +03:00
|
|
|
{
|
|
|
|
goto skip_encoding_loop;
|
|
|
|
}
|
2013-08-04 14:07:53 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
SubmitThreadpoolWork(*workObject);
|
|
|
|
workObject++;
|
|
|
|
workParam++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rfx_encode_rgb(context, tile);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!region16_union_rect(&tilesRegion, &tilesRegion, ¤tTileRect))
|
2015-04-23 16:42:21 +03:00
|
|
|
goto skip_encoding_loop;
|
2014-02-04 15:02:55 +04:00
|
|
|
} /* xIdx */
|
2019-11-06 17:24:51 +03:00
|
|
|
} /* yIdx */
|
|
|
|
} /* rects */
|
2014-02-04 15:02:55 +04:00
|
|
|
|
2015-04-23 16:42:21 +03:00
|
|
|
success = TRUE;
|
|
|
|
skip_encoding_loop:
|
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
/* when using threads ensure all computations are done */
|
2018-03-06 17:34:55 +03:00
|
|
|
if (success)
|
2013-08-14 01:18:59 +04:00
|
|
|
{
|
2018-03-06 17:34:55 +03:00
|
|
|
message->tilesDataSize = 0;
|
|
|
|
workObject = context->priv->workObjects;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2023-04-05 11:43:03 +03:00
|
|
|
for (UINT32 i = 0; i < message->numTiles; i++)
|
2013-08-14 01:18:59 +04:00
|
|
|
{
|
2018-03-06 17:34:55 +03:00
|
|
|
if (context->priv->UseThreads)
|
2015-04-23 16:42:21 +03:00
|
|
|
{
|
2018-03-06 17:34:55 +03:00
|
|
|
if (*workObject)
|
|
|
|
{
|
|
|
|
WaitForThreadpoolWorkCallbacks(*workObject, FALSE);
|
|
|
|
CloseThreadpoolWork(*workObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
workObject++;
|
2015-04-23 16:42:21 +03:00
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2023-06-12 10:33:49 +03:00
|
|
|
const RFX_TILE* tile = message->tiles[i];
|
2018-03-06 17:34:55 +03:00
|
|
|
message->tilesDataSize += rfx_tile_length(tile);
|
2013-08-04 14:07:53 +04:00
|
|
|
}
|
2013-08-14 01:18:59 +04:00
|
|
|
|
2018-03-06 17:34:55 +03:00
|
|
|
region16_uninit(&tilesRegion);
|
|
|
|
region16_uninit(&rectsRegion);
|
2013-08-12 21:13:27 +04:00
|
|
|
|
2015-04-23 16:42:21 +03:00
|
|
|
return message;
|
2018-03-06 17:34:55 +03:00
|
|
|
}
|
2015-04-23 16:42:21 +03:00
|
|
|
|
2023-04-04 22:37:28 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_ERROR, "failed");
|
2023-06-12 10:33:49 +03:00
|
|
|
|
2015-04-23 16:42:21 +03:00
|
|
|
rfx_message_free(context, message);
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-02-04 15:02:55 +04:00
|
|
|
|
2023-06-12 10:33:49 +03:00
|
|
|
static BOOL rfx_clone_rects(RFX_MESSAGE* dst, const RFX_MESSAGE* src)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(dst);
|
|
|
|
WINPR_ASSERT(src);
|
|
|
|
|
|
|
|
WINPR_ASSERT(dst->rects == NULL);
|
|
|
|
WINPR_ASSERT(dst->numRects == 0);
|
|
|
|
|
|
|
|
if (src->numRects == 0)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
dst->rects = winpr_aligned_calloc(src->numRects, sizeof(RECTANGLE_16), 32);
|
|
|
|
if (!dst->rects)
|
|
|
|
return FALSE;
|
|
|
|
dst->numRects = src->numRects;
|
|
|
|
for (size_t x = 0; x < src->numRects; x++)
|
|
|
|
{
|
|
|
|
dst->rects[x] = src->rects[x];
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL rfx_clone_quants(RFX_MESSAGE* dst, const RFX_MESSAGE* src)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(dst);
|
|
|
|
WINPR_ASSERT(src);
|
|
|
|
|
|
|
|
WINPR_ASSERT(dst->quantVals == NULL);
|
|
|
|
WINPR_ASSERT(dst->numQuant == 0);
|
|
|
|
|
|
|
|
if (src->numQuant == 0)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
/* quantVals are part of context */
|
|
|
|
dst->quantVals = src->quantVals;
|
|
|
|
dst->numQuant = src->numQuant;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-12-14 19:44:30 +03:00
|
|
|
static RFX_MESSAGE* rfx_split_message(RFX_CONTEXT* context, RFX_MESSAGE* message,
|
|
|
|
size_t* numMessages, size_t maxDataSize)
|
2013-08-14 21:19:01 +04:00
|
|
|
{
|
2023-04-04 22:10:50 +03:00
|
|
|
WINPR_ASSERT(context);
|
|
|
|
WINPR_ASSERT(message);
|
|
|
|
WINPR_ASSERT(numMessages);
|
|
|
|
|
2013-08-14 21:19:01 +04:00
|
|
|
maxDataSize -= 1024; /* reserve enough space for headers */
|
2023-04-04 22:10:50 +03:00
|
|
|
*numMessages = ((message->tilesDataSize + maxDataSize) / maxDataSize) * 4ull;
|
2013-08-14 21:19:01 +04:00
|
|
|
|
2023-04-04 22:08:54 +03:00
|
|
|
RFX_MESSAGE* messages =
|
|
|
|
(RFX_MESSAGE*)winpr_aligned_calloc((*numMessages), sizeof(RFX_MESSAGE), 32);
|
|
|
|
if (!messages)
|
2014-07-08 23:07:19 +04:00
|
|
|
return NULL;
|
2013-08-14 21:19:01 +04:00
|
|
|
|
2023-04-04 22:08:54 +03:00
|
|
|
size_t j = 0;
|
|
|
|
for (size_t i = 0; i < message->numTiles; i++)
|
2013-08-14 21:19:01 +04:00
|
|
|
{
|
2023-04-04 22:08:54 +03:00
|
|
|
RFX_TILE* tile = message->tiles[i];
|
|
|
|
RFX_MESSAGE* msg = &messages[j];
|
|
|
|
|
2023-04-05 11:52:10 +03:00
|
|
|
WINPR_ASSERT(tile);
|
|
|
|
WINPR_ASSERT(msg);
|
|
|
|
|
2023-06-12 09:13:58 +03:00
|
|
|
const size_t tileDataSize = rfx_tile_length(tile);
|
2013-08-14 21:19:01 +04:00
|
|
|
|
2023-04-04 22:08:54 +03:00
|
|
|
if ((msg->tilesDataSize + tileDataSize) > ((UINT32)maxDataSize))
|
2013-08-14 21:19:01 +04:00
|
|
|
j++;
|
|
|
|
|
2023-06-12 10:33:49 +03:00
|
|
|
if (msg->numTiles == 0)
|
2013-08-14 21:19:01 +04:00
|
|
|
{
|
2023-04-04 22:08:54 +03:00
|
|
|
msg->frameIdx = message->frameIdx + j;
|
2023-06-12 10:33:49 +03:00
|
|
|
if (!rfx_clone_quants(msg, message))
|
|
|
|
goto free_messages;
|
|
|
|
if (!rfx_clone_rects(msg, message))
|
|
|
|
goto free_messages;
|
2023-04-04 22:08:54 +03:00
|
|
|
msg->freeArray = TRUE;
|
2023-06-12 10:33:49 +03:00
|
|
|
if (!rfx_allocate_tiles(msg, message->numTiles, TRUE))
|
2015-04-23 16:42:21 +03:00
|
|
|
goto free_messages;
|
2013-08-14 21:19:01 +04:00
|
|
|
}
|
|
|
|
|
2023-04-04 22:08:54 +03:00
|
|
|
msg->tilesDataSize += tileDataSize;
|
2023-06-12 10:33:49 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(msg->numTiles < msg->allocatedTiles);
|
2023-04-04 22:08:54 +03:00
|
|
|
msg->tiles[msg->numTiles++] = message->tiles[i];
|
2013-08-14 21:19:01 +04:00
|
|
|
message->tiles[i] = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
*numMessages = j + 1;
|
2013-08-15 04:35:00 +04:00
|
|
|
context->frameIdx += j;
|
2013-08-14 21:19:01 +04:00
|
|
|
message->numTiles = 0;
|
2015-04-23 16:42:21 +03:00
|
|
|
return messages;
|
|
|
|
free_messages:
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2023-04-04 22:08:54 +03:00
|
|
|
for (size_t i = 0; i < j; i++)
|
2023-06-12 10:33:49 +03:00
|
|
|
rfx_allocate_tiles(&messages[i], 0, FALSE);
|
2013-08-15 04:35:00 +04:00
|
|
|
|
2023-03-24 14:14:38 +03:00
|
|
|
winpr_aligned_free(messages);
|
2015-04-23 16:42:21 +03:00
|
|
|
return NULL;
|
2013-08-14 21:19:01 +04:00
|
|
|
}
|
|
|
|
|
2023-04-05 14:47:59 +03:00
|
|
|
const RFX_MESSAGE* rfx_message_list_get(const RFX_MESSAGE_LIST* messages, size_t idx)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(messages);
|
|
|
|
if (idx >= messages->count)
|
|
|
|
return NULL;
|
|
|
|
WINPR_ASSERT(messages->list);
|
|
|
|
return &messages->list[idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
void rfx_message_list_free(RFX_MESSAGE_LIST* messages)
|
|
|
|
{
|
|
|
|
if (!messages)
|
|
|
|
return;
|
|
|
|
for (size_t x = 0; x < messages->count; x++)
|
|
|
|
rfx_message_free(messages->context, &messages->list[x]);
|
|
|
|
free(messages);
|
|
|
|
}
|
|
|
|
|
|
|
|
static RFX_MESSAGE_LIST* rfx_message_list_new(RFX_CONTEXT* context, RFX_MESSAGE* messages,
|
|
|
|
size_t count)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
RFX_MESSAGE_LIST* msg = calloc(1, sizeof(RFX_MESSAGE_LIST));
|
|
|
|
WINPR_ASSERT(msg);
|
|
|
|
|
|
|
|
msg->context = context;
|
|
|
|
msg->count = count;
|
|
|
|
msg->list = messages;
|
|
|
|
return msg;
|
|
|
|
}
|
|
|
|
|
|
|
|
RFX_MESSAGE_LIST* rfx_encode_messages(RFX_CONTEXT* context, const RFX_RECT* rects, size_t numRects,
|
|
|
|
const BYTE* data, UINT32 width, UINT32 height,
|
|
|
|
UINT32 scanline, size_t* numMessages, size_t maxDataSize)
|
2013-08-14 21:19:01 +04:00
|
|
|
{
|
2023-04-05 14:47:59 +03:00
|
|
|
WINPR_ASSERT(context);
|
|
|
|
WINPR_ASSERT(numMessages);
|
2013-08-14 21:19:01 +04:00
|
|
|
|
2023-04-04 22:10:50 +03:00
|
|
|
RFX_MESSAGE* message =
|
|
|
|
rfx_encode_message(context, rects, numRects, data, width, height, scanline);
|
|
|
|
if (!message)
|
2015-04-23 16:42:21 +03:00
|
|
|
return NULL;
|
2013-08-14 21:19:01 +04:00
|
|
|
|
2023-04-05 14:47:59 +03:00
|
|
|
RFX_MESSAGE* list = rfx_split_message(context, message, numMessages, maxDataSize);
|
|
|
|
rfx_message_free(context, message);
|
|
|
|
if (!list)
|
2015-04-23 16:42:21 +03:00
|
|
|
return NULL;
|
|
|
|
|
2023-04-05 14:47:59 +03:00
|
|
|
return rfx_message_list_new(context, list, *numMessages);
|
2013-08-14 21:19:01 +04:00
|
|
|
}
|
|
|
|
|
2020-12-14 19:44:30 +03:00
|
|
|
static BOOL rfx_write_message_tileset(RFX_CONTEXT* context, wStream* s, const RFX_MESSAGE* message)
|
2013-08-14 01:18:59 +04:00
|
|
|
{
|
2023-04-04 22:10:50 +03:00
|
|
|
WINPR_ASSERT(context);
|
|
|
|
WINPR_ASSERT(message);
|
|
|
|
|
|
|
|
const UINT32 blockLen = 22 + (message->numQuant * 5) + message->tilesDataSize;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-03-30 18:15:45 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, blockLen))
|
2015-04-23 16:42:21 +03:00
|
|
|
return FALSE;
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT16(s, WBT_EXTENSION); /* CodecChannelT.blockType (2 bytes) */
|
|
|
|
Stream_Write_UINT32(s, blockLen); /* set CodecChannelT.blockLen (4 bytes) */
|
|
|
|
Stream_Write_UINT8(s, 1); /* CodecChannelT.codecId (1 byte) */
|
|
|
|
Stream_Write_UINT8(s, 0); /* CodecChannelT.channelId (1 byte) */
|
|
|
|
Stream_Write_UINT16(s, CBT_TILESET); /* subtype (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, 0); /* idx (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, context->properties); /* properties (2 bytes) */
|
|
|
|
Stream_Write_UINT8(s, message->numQuant); /* numQuant (1 byte) */
|
|
|
|
Stream_Write_UINT8(s, 0x40); /* tileSize (1 byte) */
|
|
|
|
Stream_Write_UINT16(s, message->numTiles); /* numTiles (2 bytes) */
|
2013-08-14 18:14:47 +04:00
|
|
|
Stream_Write_UINT32(s, message->tilesDataSize); /* tilesDataSize (4 bytes) */
|
2013-08-14 01:18:59 +04:00
|
|
|
|
2023-04-04 22:10:50 +03:00
|
|
|
UINT32* quantVals = message->quantVals;
|
2023-07-27 21:38:51 +03:00
|
|
|
for (size_t i = 0; i < message->numQuant * 5ul; i++)
|
2013-08-14 01:18:59 +04:00
|
|
|
{
|
2023-04-05 11:52:10 +03:00
|
|
|
WINPR_ASSERT(quantVals);
|
2013-08-14 01:18:59 +04:00
|
|
|
Stream_Write_UINT8(s, quantVals[0] + (quantVals[1] << 4));
|
|
|
|
quantVals += 2;
|
|
|
|
}
|
|
|
|
|
2023-04-04 22:10:50 +03:00
|
|
|
for (size_t i = 0; i < message->numTiles; i++)
|
2013-08-14 01:18:59 +04:00
|
|
|
{
|
2023-04-04 22:10:50 +03:00
|
|
|
RFX_TILE* tile = message->tiles[i];
|
|
|
|
if (!tile)
|
2015-04-24 18:54:49 +03:00
|
|
|
return FALSE;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2023-06-12 09:13:58 +03:00
|
|
|
if (!rfx_write_tile(s, tile))
|
2015-04-23 16:42:21 +03:00
|
|
|
return FALSE;
|
2013-08-14 01:18:59 +04:00
|
|
|
}
|
|
|
|
|
2015-04-23 16:42:21 +03:00
|
|
|
#ifdef WITH_DEBUG_RFX
|
2016-04-05 18:07:45 +03:00
|
|
|
WLog_Print(context->priv->log, WLOG_DEBUG,
|
2019-11-06 17:24:51 +03:00
|
|
|
"numQuant: %" PRIu16 " numTiles: %" PRIu16 " tilesDataSize: %" PRIu32 "",
|
2016-10-12 10:21:21 +03:00
|
|
|
message->numQuant, message->numTiles, message->tilesDataSize);
|
2015-04-23 16:42:21 +03:00
|
|
|
#endif
|
|
|
|
return TRUE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2020-12-14 19:44:30 +03:00
|
|
|
static BOOL rfx_write_message_frame_begin(RFX_CONTEXT* context, wStream* s,
|
|
|
|
const RFX_MESSAGE* message)
|
2013-08-14 01:50:05 +04:00
|
|
|
{
|
2023-04-04 22:10:50 +03:00
|
|
|
WINPR_ASSERT(context);
|
|
|
|
WINPR_ASSERT(message);
|
|
|
|
|
2015-03-30 18:15:45 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 14))
|
2015-04-23 16:42:21 +03:00
|
|
|
return FALSE;
|
2013-08-14 01:50:05 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT16(s, WBT_FRAME_BEGIN); /* CodecChannelT.blockType */
|
|
|
|
Stream_Write_UINT32(s, 14); /* CodecChannelT.blockLen */
|
|
|
|
Stream_Write_UINT8(s, 1); /* CodecChannelT.codecId */
|
|
|
|
Stream_Write_UINT8(s, 0); /* CodecChannelT.channelId */
|
2013-08-14 01:50:05 +04:00
|
|
|
Stream_Write_UINT32(s, message->frameIdx); /* frameIdx */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT16(s, 1); /* numRegions */
|
2015-04-23 16:42:21 +03:00
|
|
|
return TRUE;
|
2013-08-14 01:50:05 +04:00
|
|
|
}
|
|
|
|
|
2020-12-14 19:44:30 +03:00
|
|
|
static BOOL rfx_write_message_region(RFX_CONTEXT* context, wStream* s, const RFX_MESSAGE* message)
|
2013-08-14 01:50:05 +04:00
|
|
|
{
|
2023-04-04 22:10:50 +03:00
|
|
|
WINPR_ASSERT(context);
|
|
|
|
WINPR_ASSERT(message);
|
|
|
|
|
|
|
|
const size_t blockLen = 15 + (message->numRects * 8);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-03-30 18:15:45 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, blockLen))
|
2015-04-23 16:42:21 +03:00
|
|
|
return FALSE;
|
2013-08-14 01:50:05 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT16(s, WBT_REGION); /* CodecChannelT.blockType (2 bytes) */
|
|
|
|
Stream_Write_UINT32(s, blockLen); /* set CodecChannelT.blockLen (4 bytes) */
|
|
|
|
Stream_Write_UINT8(s, 1); /* CodecChannelT.codecId (1 byte) */
|
|
|
|
Stream_Write_UINT8(s, 0); /* CodecChannelT.channelId (1 byte) */
|
|
|
|
Stream_Write_UINT8(s, 1); /* regionFlags (1 byte) */
|
2013-08-14 01:50:05 +04:00
|
|
|
Stream_Write_UINT16(s, message->numRects); /* numRects (2 bytes) */
|
|
|
|
|
2023-04-04 22:10:50 +03:00
|
|
|
for (size_t i = 0; i < message->numRects; i++)
|
2013-08-14 01:50:05 +04:00
|
|
|
{
|
2020-12-14 19:44:30 +03:00
|
|
|
const RFX_RECT* rect = rfx_message_get_rect_const(message, i);
|
2023-04-04 22:10:50 +03:00
|
|
|
WINPR_ASSERT(rect);
|
|
|
|
|
2013-08-15 04:35:00 +04:00
|
|
|
/* Clipping rectangles are relative to destLeft, destTop */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT16(s, rect->x); /* x (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, rect->y); /* y (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, rect->width); /* width (2 bytes) */
|
2016-04-11 18:30:29 +03:00
|
|
|
Stream_Write_UINT16(s, rect->height); /* height (2 bytes) */
|
2013-08-14 01:50:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Write_UINT16(s, CBT_REGION); /* regionType (2 bytes) */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT16(s, 1); /* numTilesets (2 bytes) */
|
2015-04-23 16:42:21 +03:00
|
|
|
return TRUE;
|
2013-08-14 01:50:05 +04:00
|
|
|
}
|
|
|
|
|
2020-12-14 19:44:30 +03:00
|
|
|
static BOOL rfx_write_message_frame_end(RFX_CONTEXT* context, wStream* s,
|
|
|
|
const RFX_MESSAGE* message)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2023-04-05 11:52:10 +03:00
|
|
|
WINPR_ASSERT(context);
|
|
|
|
WINPR_ASSERT(message);
|
|
|
|
|
2015-03-30 18:15:45 +03:00
|
|
|
if (!Stream_EnsureRemainingCapacity(s, 8))
|
2015-04-23 16:42:21 +03:00
|
|
|
return FALSE;
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT16(s, WBT_FRAME_END); /* CodecChannelT.blockType */
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Write_UINT32(s, 8); /* CodecChannelT.blockLen */
|
|
|
|
Stream_Write_UINT8(s, 1); /* CodecChannelT.codecId */
|
|
|
|
Stream_Write_UINT8(s, 0); /* CodecChannelT.channelId */
|
2015-04-23 16:42:21 +03:00
|
|
|
return TRUE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2020-12-14 19:44:30 +03:00
|
|
|
BOOL rfx_write_message(RFX_CONTEXT* context, wStream* s, const RFX_MESSAGE* message)
|
2011-08-25 13:25:10 +04:00
|
|
|
{
|
2023-04-04 22:10:50 +03:00
|
|
|
WINPR_ASSERT(context);
|
2023-04-05 11:52:10 +03:00
|
|
|
WINPR_ASSERT(message);
|
|
|
|
|
2013-08-14 18:14:47 +04:00
|
|
|
if (context->state == RFX_STATE_SEND_HEADERS)
|
2013-08-14 01:18:59 +04:00
|
|
|
{
|
2015-04-23 16:42:21 +03:00
|
|
|
if (!rfx_compose_message_header(context, s))
|
|
|
|
return FALSE;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2013-08-14 01:18:59 +04:00
|
|
|
context->state = RFX_STATE_SEND_FRAME_DATA;
|
|
|
|
}
|
|
|
|
|
2015-04-23 16:42:21 +03:00
|
|
|
if (!rfx_write_message_frame_begin(context, s, message) ||
|
2016-04-05 18:07:45 +03:00
|
|
|
!rfx_write_message_region(context, s, message) ||
|
|
|
|
!rfx_write_message_tileset(context, s, message) ||
|
|
|
|
!rfx_write_message_frame_end(context, s, message))
|
2015-04-23 16:42:21 +03:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2013-08-14 18:14:47 +04:00
|
|
|
}
|
2013-08-14 01:18:59 +04:00
|
|
|
|
2020-12-14 19:44:30 +03:00
|
|
|
BOOL rfx_compose_message(RFX_CONTEXT* context, wStream* s, const RFX_RECT* rects, size_t numRects,
|
|
|
|
const BYTE* data, UINT32 width, UINT32 height, UINT32 scanline)
|
2013-08-14 18:14:47 +04:00
|
|
|
{
|
2023-04-05 11:52:10 +03:00
|
|
|
WINPR_ASSERT(context);
|
2023-04-04 22:10:50 +03:00
|
|
|
RFX_MESSAGE* message =
|
|
|
|
rfx_encode_message(context, rects, numRects, data, width, height, scanline);
|
|
|
|
if (!message)
|
2015-04-23 16:42:21 +03:00
|
|
|
return FALSE;
|
2013-08-14 18:14:47 +04:00
|
|
|
|
2023-04-05 11:43:03 +03:00
|
|
|
const BOOL ret = rfx_write_message(context, s, message);
|
2013-08-14 01:18:59 +04:00
|
|
|
rfx_message_free(context, message);
|
2015-04-23 16:42:21 +03:00
|
|
|
return ret;
|
2011-08-25 13:25:10 +04:00
|
|
|
}
|
2023-04-05 14:47:59 +03:00
|
|
|
|
|
|
|
BOOL rfx_context_set_mode(RFX_CONTEXT* context, RLGR_MODE mode)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
context->mode = mode;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-10-06 14:22:17 +03:00
|
|
|
RLGR_MODE rfx_context_get_mode(RFX_CONTEXT* context)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
return context->mode;
|
|
|
|
}
|
|
|
|
|
2023-04-05 14:47:59 +03:00
|
|
|
UINT32 rfx_context_get_frame_idx(const RFX_CONTEXT* context)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
return context->frameIdx;
|
|
|
|
}
|
|
|
|
|
2023-10-10 14:26:05 +03:00
|
|
|
UINT32 rfx_message_get_frame_idx(const RFX_MESSAGE* message)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(message);
|
|
|
|
return message->frameIdx;
|
|
|
|
}
|
|
|
|
|
2023-10-06 14:22:17 +03:00
|
|
|
static INLINE BOOL rfx_write_progressive_wb_sync(RFX_CONTEXT* rfx, wStream* s)
|
2023-04-05 14:47:59 +03:00
|
|
|
{
|
2023-10-06 14:22:17 +03:00
|
|
|
const UINT32 blockLen = 12;
|
|
|
|
WINPR_ASSERT(rfx);
|
|
|
|
WINPR_ASSERT(s);
|
|
|
|
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, blockLen))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Write_UINT16(s, PROGRESSIVE_WBT_SYNC); /* blockType (2 bytes) */
|
|
|
|
Stream_Write_UINT32(s, blockLen); /* blockLen (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, 0xCACCACCA); /* magic (4 bytes) */
|
|
|
|
Stream_Write_UINT16(s, 0x0100); /* version (2 bytes) */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static INLINE BOOL rfx_write_progressive_wb_context(RFX_CONTEXT* rfx, wStream* s)
|
|
|
|
{
|
|
|
|
const UINT32 blockLen = 10;
|
|
|
|
WINPR_ASSERT(rfx);
|
|
|
|
WINPR_ASSERT(s);
|
|
|
|
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, blockLen))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Write_UINT16(s, PROGRESSIVE_WBT_CONTEXT); /* blockType (2 bytes) */
|
|
|
|
Stream_Write_UINT32(s, blockLen); /* blockLen (4 bytes) */
|
|
|
|
Stream_Write_UINT8(s, 0); /* ctxId (1 byte) */
|
|
|
|
Stream_Write_UINT16(s, 64); /* tileSize (2 bytes) */
|
|
|
|
Stream_Write_UINT8(s, 0); /* flags (1 byte) */
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static INLINE BOOL rfx_write_progressive_region(RFX_CONTEXT* rfx, wStream* s,
|
|
|
|
const RFX_MESSAGE* msg)
|
|
|
|
{
|
|
|
|
/* RFX_REGION */
|
|
|
|
UINT32 blockLen = 18;
|
|
|
|
UINT32 tilesDataSize = 0;
|
|
|
|
const size_t start = Stream_GetPosition(s);
|
|
|
|
|
|
|
|
WINPR_ASSERT(rfx);
|
|
|
|
WINPR_ASSERT(s);
|
|
|
|
WINPR_ASSERT(msg);
|
|
|
|
|
|
|
|
blockLen += msg->numRects * 8;
|
|
|
|
blockLen += msg->numQuant * 5;
|
|
|
|
tilesDataSize = msg->numTiles * 22UL;
|
|
|
|
for (UINT16 i = 0; i < msg->numTiles; i++)
|
|
|
|
{
|
|
|
|
const RFX_TILE* tile = msg->tiles[i];
|
|
|
|
WINPR_ASSERT(tile);
|
|
|
|
tilesDataSize += tile->YLen + tile->CbLen + tile->CrLen;
|
|
|
|
}
|
|
|
|
blockLen += tilesDataSize;
|
|
|
|
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, blockLen))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Write_UINT16(s, PROGRESSIVE_WBT_REGION); /* blockType (2 bytes) */
|
|
|
|
Stream_Write_UINT32(s, blockLen); /* blockLen (4 bytes) */
|
|
|
|
Stream_Write_UINT8(s, 64); /* tileSize (1 byte) */
|
|
|
|
Stream_Write_UINT16(s, msg->numRects); /* numRects (2 bytes) */
|
|
|
|
WINPR_ASSERT(msg->numQuant <= UINT8_MAX);
|
|
|
|
Stream_Write_UINT8(s, (UINT8)msg->numQuant); /* numQuant (1 byte) */
|
|
|
|
Stream_Write_UINT8(s, 0); /* numProgQuant (1 byte) */
|
|
|
|
Stream_Write_UINT8(s, 0); /* flags (1 byte) */
|
|
|
|
Stream_Write_UINT16(s, msg->numTiles); /* numTiles (2 bytes) */
|
|
|
|
Stream_Write_UINT32(s, tilesDataSize); /* tilesDataSize (4 bytes) */
|
|
|
|
|
|
|
|
for (UINT16 i = 0; i < msg->numRects; i++)
|
|
|
|
{
|
|
|
|
/* TS_RFX_RECT */
|
|
|
|
const RFX_RECT* r = &msg->rects[i];
|
|
|
|
Stream_Write_UINT16(s, r->x); /* x (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, r->y); /* y (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, r->width); /* width (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, r->height); /* height (2 bytes) */
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Note: The RFX_COMPONENT_CODEC_QUANT structure differs from the
|
|
|
|
* TS_RFX_CODEC_QUANT ([MS-RDPRFX] section 2.2.2.1.5) structure with respect
|
|
|
|
* to the order of the bands.
|
|
|
|
* 0 1 2 3 4 5 6 7 8 9
|
|
|
|
* RDPRFX: LL3, LH3, HL3, HH3, LH2, HL2, HH2, LH1, HL1, HH1
|
|
|
|
* RDPEGFX: LL3, HL3, LH3, HH3, HL2, LH2, HH2, HL1, LH1, HH1
|
|
|
|
*/
|
|
|
|
for (UINT16 i = 0; i < msg->numQuant; i++)
|
|
|
|
{
|
|
|
|
const UINT32* qv = &msg->quantVals[i * 10];
|
|
|
|
/* RFX_COMPONENT_CODEC_QUANT */
|
|
|
|
Stream_Write_UINT8(s, (UINT8)(qv[0] + (qv[2] << 4))); /* LL3 (4-bit), HL3 (4-bit) */
|
|
|
|
Stream_Write_UINT8(s, (UINT8)(qv[1] + (qv[3] << 4))); /* LH3 (4-bit), HH3 (4-bit) */
|
|
|
|
Stream_Write_UINT8(s, (UINT8)(qv[5] + (qv[4] << 4))); /* HL2 (4-bit), LH2 (4-bit) */
|
|
|
|
Stream_Write_UINT8(s, (UINT8)(qv[6] + (qv[8] << 4))); /* HH2 (4-bit), HL1 (4-bit) */
|
|
|
|
Stream_Write_UINT8(s, (UINT8)(qv[7] + (qv[9] << 4))); /* LH1 (4-bit), HH1 (4-bit) */
|
|
|
|
}
|
|
|
|
|
|
|
|
for (UINT16 i = 0; i < msg->numTiles; i++)
|
|
|
|
{
|
|
|
|
const RFX_TILE* tile = msg->tiles[i];
|
|
|
|
if (!rfx_write_progressive_tile_simple(rfx, s, tile))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
const size_t end = Stream_GetPosition(s);
|
|
|
|
const size_t used = end - start;
|
|
|
|
return (used == blockLen);
|
|
|
|
}
|
|
|
|
|
|
|
|
static INLINE BOOL rfx_write_progressive_frame_begin(RFX_CONTEXT* rfx, wStream* s,
|
|
|
|
const RFX_MESSAGE* msg)
|
|
|
|
{
|
|
|
|
const UINT32 blockLen = 12;
|
|
|
|
WINPR_ASSERT(rfx);
|
|
|
|
WINPR_ASSERT(s);
|
|
|
|
WINPR_ASSERT(msg);
|
|
|
|
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, blockLen))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Write_UINT16(s, PROGRESSIVE_WBT_FRAME_BEGIN); /* blockType (2 bytes) */
|
|
|
|
Stream_Write_UINT32(s, blockLen); /* blockLen (4 bytes) */
|
|
|
|
Stream_Write_UINT32(s, msg->frameIdx); /* frameIndex (4 bytes) */
|
|
|
|
Stream_Write_UINT16(s, 1); /* regionCount (2 bytes) */
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static INLINE BOOL rfx_write_progressive_frame_end(RFX_CONTEXT* rfx, wStream* s)
|
|
|
|
{
|
|
|
|
const UINT32 blockLen = 6;
|
|
|
|
WINPR_ASSERT(rfx);
|
|
|
|
WINPR_ASSERT(s);
|
|
|
|
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, blockLen))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Write_UINT16(s, PROGRESSIVE_WBT_FRAME_END); /* blockType (2 bytes) */
|
|
|
|
Stream_Write_UINT32(s, blockLen); /* blockLen (4 bytes) */
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static INLINE BOOL rfx_write_progressive_tile_simple(RFX_CONTEXT* rfx, wStream* s,
|
|
|
|
const RFX_TILE* tile)
|
|
|
|
{
|
|
|
|
UINT32 blockLen;
|
|
|
|
WINPR_ASSERT(rfx);
|
|
|
|
WINPR_ASSERT(s);
|
|
|
|
WINPR_ASSERT(tile);
|
|
|
|
|
|
|
|
blockLen = 22 + tile->YLen + tile->CbLen + tile->CrLen;
|
|
|
|
if (!Stream_EnsureRemainingCapacity(s, blockLen))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Write_UINT16(s, PROGRESSIVE_WBT_TILE_SIMPLE); /* blockType (2 bytes) */
|
|
|
|
Stream_Write_UINT32(s, blockLen); /* blockLen (4 bytes) */
|
|
|
|
Stream_Write_UINT8(s, tile->quantIdxY); /* quantIdxY (1 byte) */
|
|
|
|
Stream_Write_UINT8(s, tile->quantIdxCb); /* quantIdxCb (1 byte) */
|
|
|
|
Stream_Write_UINT8(s, tile->quantIdxCr); /* quantIdxCr (1 byte) */
|
|
|
|
Stream_Write_UINT16(s, tile->xIdx); /* xIdx (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, tile->yIdx); /* yIdx (2 bytes) */
|
|
|
|
Stream_Write_UINT8(s, 0); /* flags (1 byte) */
|
|
|
|
Stream_Write_UINT16(s, tile->YLen); /* YLen (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, tile->CbLen); /* CbLen (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, tile->CrLen); /* CrLen (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, 0); /* tailLen (2 bytes) */
|
|
|
|
Stream_Write(s, tile->YData, tile->YLen); /* YData */
|
|
|
|
Stream_Write(s, tile->CbData, tile->CbLen); /* CbData */
|
|
|
|
Stream_Write(s, tile->CrData, tile->CrLen); /* CrData */
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* rfx_get_progressive_block_type_string(UINT16 blockType)
|
|
|
|
{
|
|
|
|
switch (blockType)
|
|
|
|
{
|
|
|
|
case PROGRESSIVE_WBT_SYNC:
|
|
|
|
return "PROGRESSIVE_WBT_SYNC";
|
|
|
|
|
|
|
|
case PROGRESSIVE_WBT_FRAME_BEGIN:
|
|
|
|
return "PROGRESSIVE_WBT_FRAME_BEGIN";
|
|
|
|
|
|
|
|
case PROGRESSIVE_WBT_FRAME_END:
|
|
|
|
return "PROGRESSIVE_WBT_FRAME_END";
|
|
|
|
|
|
|
|
case PROGRESSIVE_WBT_CONTEXT:
|
|
|
|
return "PROGRESSIVE_WBT_CONTEXT";
|
|
|
|
|
|
|
|
case PROGRESSIVE_WBT_REGION:
|
|
|
|
return "PROGRESSIVE_WBT_REGION";
|
|
|
|
|
|
|
|
case PROGRESSIVE_WBT_TILE_SIMPLE:
|
|
|
|
return "PROGRESSIVE_WBT_TILE_SIMPLE";
|
|
|
|
|
|
|
|
case PROGRESSIVE_WBT_TILE_FIRST:
|
|
|
|
return "PROGRESSIVE_WBT_TILE_FIRST";
|
|
|
|
|
|
|
|
case PROGRESSIVE_WBT_TILE_UPGRADE:
|
|
|
|
return "PROGRESSIVE_WBT_TILE_UPGRADE";
|
|
|
|
|
|
|
|
default:
|
|
|
|
return "PROGRESSIVE_WBT_UNKNOWN";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL rfx_write_message_progressive_simple(RFX_CONTEXT* context, wStream* s, const RFX_MESSAGE* msg)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(s);
|
|
|
|
WINPR_ASSERT(msg);
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
|
|
|
|
if (context->mode != RLGR1)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "error, RLGR1 mode is required!");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!rfx_write_progressive_wb_sync(context, s))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!rfx_write_progressive_wb_context(context, s))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!rfx_write_progressive_frame_begin(context, s, msg))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!rfx_write_progressive_region(context, s, msg))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!rfx_write_progressive_frame_end(context, s))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
2023-04-05 14:47:59 +03:00
|
|
|
}
|