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
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2013-08-30 16:19:50 +04:00
|
|
|
#include <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
|
|
|
|
2012-10-02 10:48:11 +04:00
|
|
|
#ifdef HAVE_STDINT_H
|
2011-08-16 01:19:59 +04:00
|
|
|
#include <stdint.h>
|
2012-10-02 10:48:11 +04:00
|
|
|
#endif
|
2012-08-15 01:09:01 +04:00
|
|
|
|
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
|
|
|
|
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>
|
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-02-04 15:02:55 +04:00
|
|
|
|
2011-08-10 11:13:39 +04:00
|
|
|
#ifndef RFX_INIT_SIMD
|
|
|
|
#define RFX_INIT_SIMD(_rfx_context) do { } while (0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2012-10-09 11:26:39 +04:00
|
|
|
static const UINT32 rfx_default_quantization_values[] =
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
|
|
|
6, 6, 6, 6, 7, 7, 8, 8, 8, 9
|
|
|
|
};
|
|
|
|
|
|
|
|
static void rfx_profiler_create(RFX_CONTEXT* context)
|
|
|
|
{
|
|
|
|
PROFILER_CREATE(context->priv->prof_rfx_decode_rgb, "rfx_decode_rgb");
|
|
|
|
PROFILER_CREATE(context->priv->prof_rfx_decode_component, "rfx_decode_component");
|
|
|
|
PROFILER_CREATE(context->priv->prof_rfx_rlgr_decode, "rfx_rlgr_decode");
|
|
|
|
PROFILER_CREATE(context->priv->prof_rfx_differential_decode, "rfx_differential_decode");
|
|
|
|
PROFILER_CREATE(context->priv->prof_rfx_quantization_decode, "rfx_quantization_decode");
|
|
|
|
PROFILER_CREATE(context->priv->prof_rfx_dwt_2d_decode, "rfx_dwt_2d_decode");
|
2013-01-19 02:32:58 +04:00
|
|
|
PROFILER_CREATE(context->priv->prof_rfx_ycbcr_to_rgb, "prims->yCbCrToRGB");
|
2011-08-10 11:13:39 +04:00
|
|
|
PROFILER_CREATE(context->priv->prof_rfx_decode_format_rgb, "rfx_decode_format_rgb");
|
|
|
|
|
|
|
|
PROFILER_CREATE(context->priv->prof_rfx_encode_rgb, "rfx_encode_rgb");
|
|
|
|
PROFILER_CREATE(context->priv->prof_rfx_encode_component, "rfx_encode_component");
|
|
|
|
PROFILER_CREATE(context->priv->prof_rfx_rlgr_encode, "rfx_rlgr_encode");
|
|
|
|
PROFILER_CREATE(context->priv->prof_rfx_differential_encode, "rfx_differential_encode");
|
|
|
|
PROFILER_CREATE(context->priv->prof_rfx_quantization_encode, "rfx_quantization_encode");
|
|
|
|
PROFILER_CREATE(context->priv->prof_rfx_dwt_2d_encode, "rfx_dwt_2d_encode");
|
2013-01-19 02:32:58 +04:00
|
|
|
PROFILER_CREATE(context->priv->prof_rfx_rgb_to_ycbcr, "prims->RGBToYCbCr");
|
2011-08-10 11:13:39 +04:00
|
|
|
PROFILER_CREATE(context->priv->prof_rfx_encode_format_rgb, "rfx_encode_format_rgb");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rfx_profiler_free(RFX_CONTEXT* context)
|
|
|
|
{
|
|
|
|
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);
|
2013-01-19 02:32:58 +04:00
|
|
|
PROFILER_FREE(context->priv->prof_rfx_ycbcr_to_rgb);
|
2011-08-10 11:13:39 +04:00
|
|
|
PROFILER_FREE(context->priv->prof_rfx_decode_format_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);
|
2013-01-19 02:32:58 +04:00
|
|
|
PROFILER_FREE(context->priv->prof_rfx_rgb_to_ycbcr);
|
2011-08-10 11:13:39 +04:00
|
|
|
PROFILER_FREE(context->priv->prof_rfx_encode_format_rgb);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rfx_profiler_print(RFX_CONTEXT* context)
|
|
|
|
{
|
|
|
|
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);
|
2013-01-19 02:32:58 +04:00
|
|
|
PROFILER_PRINT(context->priv->prof_rfx_ycbcr_to_rgb);
|
2011-08-10 11:13:39 +04:00
|
|
|
PROFILER_PRINT(context->priv->prof_rfx_decode_format_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);
|
2013-01-19 02:32:58 +04:00
|
|
|
PROFILER_PRINT(context->priv->prof_rfx_rgb_to_ycbcr);
|
2011-08-10 11:13:39 +04:00
|
|
|
PROFILER_PRINT(context->priv->prof_rfx_encode_format_rgb);
|
|
|
|
|
|
|
|
PROFILER_PRINT_FOOTER;
|
|
|
|
}
|
|
|
|
|
2013-08-13 17:34:15 +04:00
|
|
|
void rfx_tile_init(RFX_TILE* tile)
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-17 00:46:47 +04:00
|
|
|
RFX_TILE* rfx_decoder_tile_new()
|
2013-08-13 17:34:15 +04:00
|
|
|
{
|
|
|
|
RFX_TILE* tile = NULL;
|
|
|
|
|
|
|
|
tile = (RFX_TILE*) malloc(sizeof(RFX_TILE));
|
|
|
|
|
|
|
|
if (tile)
|
|
|
|
{
|
|
|
|
ZeroMemory(tile, sizeof(RFX_TILE));
|
|
|
|
|
|
|
|
tile->data = (BYTE*) malloc(4096 * 4); /* 64x64 * 4 */
|
2013-09-03 16:27:08 +04:00
|
|
|
tile->allocated = TRUE;
|
2013-08-13 17:34:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return tile;
|
|
|
|
}
|
|
|
|
|
2013-08-17 00:46:47 +04:00
|
|
|
void rfx_decoder_tile_free(RFX_TILE* tile)
|
2013-08-13 17:34:15 +04:00
|
|
|
{
|
|
|
|
if (tile)
|
|
|
|
{
|
2013-09-03 16:27:08 +04:00
|
|
|
if (tile->allocated)
|
|
|
|
free(tile->data);
|
2013-08-13 17:34:15 +04:00
|
|
|
free(tile);
|
|
|
|
}
|
|
|
|
}
|
2013-07-05 14:30:13 +04:00
|
|
|
|
2013-08-17 00:46:47 +04:00
|
|
|
RFX_TILE* rfx_encoder_tile_new()
|
|
|
|
{
|
2014-02-05 18:52:29 +04:00
|
|
|
return (RFX_TILE *)calloc(1, sizeof(RFX_TILE));
|
2013-08-17 00:46:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void rfx_encoder_tile_free(RFX_TILE* tile)
|
|
|
|
{
|
|
|
|
if (tile)
|
|
|
|
free(tile);
|
|
|
|
}
|
|
|
|
|
|
|
|
RFX_CONTEXT* rfx_context_new(BOOL encoder)
|
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;
|
2014-02-04 15:02:55 +04:00
|
|
|
wObject *pool;
|
|
|
|
RFX_CONTEXT_PRIV *priv;
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2014-02-05 18:52:29 +04:00
|
|
|
context = (RFX_CONTEXT*)calloc(1, sizeof(RFX_CONTEXT));
|
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;
|
2014-02-05 18:52:29 +04:00
|
|
|
context->priv = priv = (RFX_CONTEXT_PRIV *)calloc(1, sizeof(RFX_CONTEXT_PRIV) );
|
2014-02-04 15:02:55 +04:00
|
|
|
if (!priv)
|
|
|
|
goto error_priv;
|
2012-11-22 05:21:08 +04:00
|
|
|
|
2013-10-09 04:17:57 +04:00
|
|
|
WLog_Init();
|
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
priv->log = WLog_Get("com.freerdp.codec.rfx");
|
|
|
|
WLog_OpenAppender(priv->log);
|
2013-10-09 04:17:57 +04:00
|
|
|
|
|
|
|
#ifdef WITH_DEBUG_RFX
|
2014-02-04 15:02:55 +04:00
|
|
|
WLog_SetLogLevel(priv->log, WLOG_DEBUG);
|
2013-10-09 04:17:57 +04:00
|
|
|
#endif
|
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
priv->TilePool = ObjectPool_New(TRUE);
|
|
|
|
if (!priv->TilePool)
|
|
|
|
goto error_tilePool;
|
|
|
|
pool = ObjectPool_Object(priv->TilePool);
|
|
|
|
pool->fnObjectInit = (OBJECT_INIT_FN) rfx_tile_init;
|
2013-08-17 00:46:47 +04:00
|
|
|
|
|
|
|
if (context->encoder)
|
|
|
|
{
|
2014-02-04 15:02:55 +04:00
|
|
|
pool->fnObjectNew = (OBJECT_NEW_FN) rfx_encoder_tile_new;
|
|
|
|
pool->fnObjectFree = (OBJECT_FREE_FN) rfx_encoder_tile_free;
|
2013-08-17 00:46:47 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-04 15:02:55 +04:00
|
|
|
pool->fnObjectNew = (OBJECT_NEW_FN) rfx_decoder_tile_new;
|
|
|
|
pool->fnObjectFree = (OBJECT_FREE_FN) 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)
|
|
|
|
* in order to allow optimized functions (SEE, NEON) to read from positions
|
|
|
|
* 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);
|
|
|
|
if (!priv->BufferPool)
|
|
|
|
goto error_BufferPool;
|
2013-01-23 06:24:04 +04:00
|
|
|
|
2013-01-24 04:21:14 +04:00
|
|
|
#ifdef _WIN32
|
|
|
|
{
|
|
|
|
BOOL isVistaOrLater;
|
|
|
|
OSVERSIONINFOA verinfo;
|
|
|
|
|
|
|
|
ZeroMemory(&verinfo, sizeof(OSVERSIONINFOA));
|
|
|
|
verinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA);
|
|
|
|
|
|
|
|
GetVersionExA(&verinfo);
|
|
|
|
isVistaOrLater = ((verinfo.dwMajorVersion >= 6) && (verinfo.dwMinorVersion >= 0)) ? TRUE : FALSE;
|
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
priv->UseThreads = isVistaOrLater;
|
2013-01-24 04:21:14 +04:00
|
|
|
}
|
|
|
|
#else
|
2014-02-04 15:02:55 +04:00
|
|
|
priv->UseThreads = TRUE;
|
2013-01-24 04:21:14 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
GetNativeSystemInfo(&sysinfo);
|
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
priv->MinThreadCount = sysinfo.dwNumberOfProcessors;
|
|
|
|
priv->MaxThreadCount = 0;
|
2013-01-23 03:14:50 +04:00
|
|
|
|
2013-01-23 06:54:13 +04:00
|
|
|
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\RemoteFX"), 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
|
|
|
|
|
|
|
|
if (status == ERROR_SUCCESS)
|
|
|
|
{
|
2013-06-14 08:16:04 +04:00
|
|
|
dwSize = sizeof(dwValue);
|
|
|
|
|
2013-01-23 06:54:13 +04:00
|
|
|
if (RegQueryValueEx(hKey, _T("UseThreads"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS)
|
2014-02-04 15:02:55 +04:00
|
|
|
priv->UseThreads = dwValue ? 1 : 0;
|
2013-01-23 06:54:13 +04:00
|
|
|
|
|
|
|
if (RegQueryValueEx(hKey, _T("MinThreadCount"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS)
|
2014-02-04 15:02:55 +04:00
|
|
|
priv->MinThreadCount = dwValue;
|
2013-01-23 06:54:13 +04:00
|
|
|
|
|
|
|
if (RegQueryValueEx(hKey, _T("MaxThreadCount"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS)
|
2014-02-04 15:02:55 +04:00
|
|
|
priv->MaxThreadCount = dwValue;
|
2013-01-23 06:54:13 +04:00
|
|
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
if (!priv->ThreadPool)
|
|
|
|
goto error_threadPool;
|
|
|
|
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)
|
|
|
|
SetThreadpoolThreadMinimum(priv->ThreadPool, priv->MinThreadCount);
|
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 */
|
2012-03-13 15:02:19 +04:00
|
|
|
rfx_context_set_pixel_format(context, RDP_PIXEL_FORMAT_B8G8R8A8);
|
2011-08-10 11:13:39 +04:00
|
|
|
|
|
|
|
/* create profilers for default decoding routines */
|
|
|
|
rfx_profiler_create(context);
|
|
|
|
|
|
|
|
/* set up default routines */
|
|
|
|
context->quantization_decode = rfx_quantization_decode;
|
|
|
|
context->quantization_encode = rfx_quantization_encode;
|
|
|
|
context->dwt_2d_decode = rfx_dwt_2d_decode;
|
|
|
|
context->dwt_2d_encode = rfx_dwt_2d_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;
|
2011-10-29 18:01:50 +04:00
|
|
|
return context;
|
2014-02-04 15:02:55 +04:00
|
|
|
|
|
|
|
error_threadPool:
|
|
|
|
BufferPool_Free(priv->BufferPool);
|
|
|
|
error_BufferPool:
|
|
|
|
ObjectPool_Free(priv->TilePool);
|
|
|
|
error_tilePool:
|
|
|
|
free(priv);
|
|
|
|
error_priv:
|
|
|
|
free(context);
|
|
|
|
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)
|
|
|
|
{
|
2014-02-04 15:02:55 +04:00
|
|
|
RFX_CONTEXT_PRIV *priv;
|
|
|
|
|
2013-09-02 12:58:07 +04:00
|
|
|
assert(NULL != context);
|
|
|
|
assert(NULL != context->priv);
|
|
|
|
assert(NULL != context->priv->TilePool);
|
|
|
|
assert(NULL != context->priv->BufferPool);
|
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
priv = context->priv;
|
2013-09-06 12:55:26 +04:00
|
|
|
if (context->quants)
|
|
|
|
free(context->quants);
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
ObjectPool_Free(priv->TilePool);
|
2011-08-10 11:13:39 +04:00
|
|
|
|
|
|
|
rfx_profiler_print(context);
|
|
|
|
rfx_profiler_free(context);
|
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
if (priv->UseThreads)
|
2013-01-23 03:14:50 +04:00
|
|
|
{
|
|
|
|
CloseThreadpool(context->priv->ThreadPool);
|
|
|
|
DestroyThreadpoolEnvironment(&context->priv->ThreadPoolEnv);
|
2014-02-04 15:02:55 +04:00
|
|
|
|
|
|
|
if (priv->workObjects)
|
|
|
|
free(priv->workObjects);
|
|
|
|
if (priv->tileWorkParams)
|
|
|
|
free(priv->tileWorkParams);
|
|
|
|
|
2013-06-27 15:43:29 +04:00
|
|
|
#ifdef WITH_PROFILER
|
2014-08-07 18:51:24 +04:00
|
|
|
DEBUG_WARN( "\nWARNING: Profiling results probably unusable with multithreaded RemoteFX codec!\n");
|
2013-06-27 15:43:29 +04:00
|
|
|
#endif
|
2013-01-23 03:14:50 +04:00
|
|
|
}
|
|
|
|
|
2013-01-23 06:24:04 +04:00
|
|
|
BufferPool_Free(context->priv->BufferPool);
|
2013-01-23 03:32:17 +04:00
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(context->priv);
|
|
|
|
free(context);
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2012-03-13 15:02:19 +04:00
|
|
|
void rfx_context_set_pixel_format(RFX_CONTEXT* context, RDP_PIXEL_FORMAT pixel_format)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
|
|
|
context->pixel_format = pixel_format;
|
2013-01-21 05:44:30 +04:00
|
|
|
|
2011-08-10 11:13:39 +04:00
|
|
|
switch (pixel_format)
|
|
|
|
{
|
2012-03-13 15:02:19 +04:00
|
|
|
case RDP_PIXEL_FORMAT_B8G8R8A8:
|
|
|
|
case RDP_PIXEL_FORMAT_R8G8B8A8:
|
2011-09-14 21:48:08 +04:00
|
|
|
context->bits_per_pixel = 32;
|
2011-08-10 11:13:39 +04:00
|
|
|
break;
|
2012-03-13 15:02:19 +04:00
|
|
|
case RDP_PIXEL_FORMAT_B8G8R8:
|
|
|
|
case RDP_PIXEL_FORMAT_R8G8B8:
|
2011-09-14 21:48:08 +04:00
|
|
|
context->bits_per_pixel = 24;
|
2011-08-10 11:13:39 +04:00
|
|
|
break;
|
2012-03-13 15:02:19 +04:00
|
|
|
case RDP_PIXEL_FORMAT_B5G6R5_LE:
|
|
|
|
case RDP_PIXEL_FORMAT_R5G6B5_LE:
|
2011-09-14 21:48:08 +04:00
|
|
|
context->bits_per_pixel = 16;
|
|
|
|
break;
|
2012-03-13 15:02:19 +04:00
|
|
|
case RDP_PIXEL_FORMAT_P4_PLANER:
|
2011-09-14 21:48:08 +04:00
|
|
|
context->bits_per_pixel = 4;
|
|
|
|
break;
|
2012-03-13 15:02:19 +04:00
|
|
|
case RDP_PIXEL_FORMAT_P8:
|
2011-09-14 21:48:08 +04:00
|
|
|
context->bits_per_pixel = 8;
|
2011-09-08 02:53:07 +04:00
|
|
|
break;
|
2011-08-10 11:13:39 +04:00
|
|
|
default:
|
2011-09-14 21:48:08 +04:00
|
|
|
context->bits_per_pixel = 0;
|
2011-08-10 11:13:39 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-06 14:50:47 +04:00
|
|
|
void rfx_context_reset(RFX_CONTEXT* context)
|
|
|
|
{
|
2013-08-14 01:18:59 +04:00
|
|
|
context->state = RFX_STATE_SEND_HEADERS;
|
|
|
|
context->frameIdx = 0;
|
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;
|
2011-08-10 11:13:39 +04:00
|
|
|
|
|
|
|
/* RFX_SYNC */
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 6)
|
2013-01-29 01:23:10 +04:00
|
|
|
{
|
|
|
|
DEBUG_WARN("RfxSync packet too small");
|
|
|
|
return FALSE;
|
|
|
|
}
|
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)
|
|
|
|
{
|
|
|
|
DEBUG_WARN("invalid magic number 0x%X", magic);
|
2013-01-29 01:23:10 +04:00
|
|
|
return FALSE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-05-09 00:09:16 +04: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)
|
|
|
|
{
|
|
|
|
DEBUG_WARN("unknown version number 0x%X", context->version);
|
2013-01-29 01:23:10 +04:00
|
|
|
return FALSE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-10-09 04:17:57 +04:00
|
|
|
WLog_Print(context->priv->log, WLOG_DEBUG, "version 0x%X", context->version);
|
|
|
|
|
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;
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 1)
|
2013-01-29 01:23:10 +04:00
|
|
|
{
|
|
|
|
DEBUG_WARN("RfxCodecVersion packet too small");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, numCodecs); /* numCodecs (1 byte), must be set to 0x01 */
|
2011-08-10 11:13:39 +04:00
|
|
|
|
|
|
|
if (numCodecs != 1)
|
|
|
|
{
|
|
|
|
DEBUG_WARN("numCodecs: %d, expected:1", numCodecs);
|
2013-01-29 01:23:10 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-02-11 07:12:13 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < (size_t) (2 * numCodecs))
|
2013-01-29 01:23:10 +04:00
|
|
|
{
|
|
|
|
DEBUG_WARN("RfxCodecVersion packet too small for numCodecs=%d", numCodecs);
|
|
|
|
return FALSE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* RFX_CODEC_VERSIONT */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, context->codec_id); /* codecId (1 byte) */
|
|
|
|
Stream_Read_UINT8(s, context->codec_version); /* version (2 bytes) */
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2013-10-09 04:17:57 +04:00
|
|
|
WLog_Print(context->priv->log, WLOG_DEBUG, "id %d version 0x%X.", context->codec_id, context->codec_version);
|
|
|
|
|
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;
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 1)
|
2013-01-29 01:23:10 +04:00
|
|
|
{
|
|
|
|
DEBUG_WARN("RfxMessageChannels packet too small");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, numChannels); /* numChannels (1 byte), must bet set to 0x01 */
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2012-01-10 01:18:31 +04:00
|
|
|
/* In RDVH sessions, numChannels will represent the number of virtual monitors
|
|
|
|
* configured and does not always be set to 0x01 as [MS-RDPRFX] said.
|
|
|
|
*/
|
|
|
|
if (numChannels < 1)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
|
|
|
DEBUG_WARN("numChannels:%d, expected:1", numChannels);
|
2013-01-29 01:23:10 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-02-11 07:12:13 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < (size_t) (numChannels * 5))
|
2013-01-29 01:23:10 +04:00
|
|
|
{
|
|
|
|
DEBUG_WARN("RfxMessageChannels packet too small for numChannels=%d", numChannels);
|
|
|
|
return FALSE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* RFX_CHANNELT */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, channelId); /* channelId (1 byte) */
|
|
|
|
Stream_Read_UINT16(s, context->width); /* width (2 bytes) */
|
|
|
|
Stream_Read_UINT16(s, context->height); /* height (2 bytes) */
|
2011-08-10 11:13:39 +04:00
|
|
|
|
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));
|
2012-01-10 01:18:31 +04:00
|
|
|
|
2013-10-09 04:17:57 +04:00
|
|
|
WLog_Print(context->priv->log, WLOG_DEBUG, "numChannels %d id %d, %dx%d.",
|
2011-08-10 11:13:39 +04:00
|
|
|
numChannels, channelId, context->width, context->height);
|
2013-10-09 04:17:57 +04:00
|
|
|
|
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;
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 5)
|
2013-01-29 01:23:10 +04:00
|
|
|
{
|
|
|
|
DEBUG_WARN("RfxMessageContext packet too small");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, ctxId); /* ctxId (1 byte), must be set to 0x00 */
|
|
|
|
Stream_Read_UINT16(s, tileSize); /* tileSize (2 bytes), must be set to CT_TILE_64x64 (0x0040) */
|
|
|
|
Stream_Read_UINT16(s, properties); /* properties (2 bytes) */
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2013-10-09 04:17:57 +04:00
|
|
|
WLog_Print(context->priv->log, WLOG_DEBUG, "ctxId %d tileSize %d properties 0x%X.",
|
|
|
|
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:
|
|
|
|
DEBUG_WARN("unknown RLGR algorithm.");
|
|
|
|
break;
|
|
|
|
}
|
2013-10-09 04:17:57 +04:00
|
|
|
|
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_frame_begin(RFX_CONTEXT* context, RFX_MESSAGE* message, wStream* s)
|
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
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 6)
|
2013-01-29 01:23:10 +04:00
|
|
|
{
|
|
|
|
DEBUG_WARN("RfxMessageFrameBegin packet too small");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-10-09 04:17:57 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, frameIdx); /* frameIdx (4 bytes), if codec is in video mode, must be ignored */
|
|
|
|
Stream_Read_UINT16(s, numRegions); /* numRegions (2 bytes) */
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2013-10-09 04:17:57 +04:00
|
|
|
WLog_Print(context->priv->log, WLOG_DEBUG, "RFX_FRAME_BEGIN: frameIdx: %d numRegions: %d", frameIdx, numRegions);
|
|
|
|
|
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 void rfx_process_message_frame_end(RFX_CONTEXT* context, RFX_MESSAGE* message, wStream* s)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2013-10-09 04:17:57 +04:00
|
|
|
WLog_Print(context->priv->log, WLOG_DEBUG, "RFX_FRAME_END");
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static BOOL rfx_process_message_region(RFX_CONTEXT* context, RFX_MESSAGE* message, wStream* s)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 3)
|
2013-01-29 01:23:10 +04:00
|
|
|
{
|
|
|
|
DEBUG_WARN("RfxMessageRegion packet too small");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-05-09 00:27:21 +04: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
|
|
|
{
|
2014-05-08 20:20:28 +04:00
|
|
|
/* Unfortunately, it isn't documented.
|
|
|
|
It seems that server asks to clip whole session when numRects = 0.
|
|
|
|
Issue: https://github.com/FreeRDP/FreeRDP/issues/1738 */
|
|
|
|
|
|
|
|
DEBUG_WARN("no rects. Clip whole session.");
|
|
|
|
message->numRects = 1;
|
|
|
|
message->rects = (RFX_RECT*) realloc(message->rects, message->numRects * sizeof(RFX_RECT));
|
|
|
|
if (!message->rects)
|
|
|
|
return FALSE;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-02-11 07:12:13 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < (size_t) (8 * message->numRects))
|
2013-01-29 01:23:10 +04:00
|
|
|
{
|
2013-08-14 01:18:59 +04:00
|
|
|
DEBUG_WARN("RfxMessageRegion packet too small for num_rects=%d", message->numRects);
|
2013-01-29 01:23:10 +04:00
|
|
|
return FALSE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
message->rects = (RFX_RECT*) realloc(message->rects, message->numRects * sizeof(RFX_RECT));
|
2014-02-05 18:52:29 +04:00
|
|
|
if (!message->rects)
|
|
|
|
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
|
|
|
{
|
|
|
|
/* RFX_RECT */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, message->rects[i].x); /* x (2 bytes) */
|
|
|
|
Stream_Read_UINT16(s, message->rects[i].y); /* y (2 bytes) */
|
|
|
|
Stream_Read_UINT16(s, message->rects[i].width); /* width (2 bytes) */
|
|
|
|
Stream_Read_UINT16(s, message->rects[i].height); /* height (2 bytes) */
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
WLog_Print(context->priv->log, WLOG_DEBUG, "rect %d (x,y=%d,%d w,h=%d %d).", i,
|
|
|
|
message->rects[i].x, message->rects[i].y,
|
|
|
|
message->rects[i].width, message->rects[i].height);
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
2013-10-09 04:17:57 +04:00
|
|
|
|
2013-01-29 01:23:10 +04:00
|
|
|
return TRUE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-08-04 14:07:53 +04:00
|
|
|
struct _RFX_TILE_PROCESS_WORK_PARAM
|
2013-01-23 03:14:50 +04:00
|
|
|
{
|
|
|
|
RFX_TILE* tile;
|
|
|
|
RFX_CONTEXT* context;
|
|
|
|
};
|
2013-08-04 14:07:53 +04:00
|
|
|
typedef struct _RFX_TILE_PROCESS_WORK_PARAM RFX_TILE_PROCESS_WORK_PARAM;
|
2013-01-23 03:14:50 +04:00
|
|
|
|
|
|
|
void CALLBACK rfx_process_message_tile_work_callback(PTP_CALLBACK_INSTANCE instance, void* context, PTP_WORK work)
|
|
|
|
{
|
2013-08-04 14:07:53 +04:00
|
|
|
RFX_TILE_PROCESS_WORK_PARAM* param = (RFX_TILE_PROCESS_WORK_PARAM*) context;
|
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
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* message, wStream* s)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2013-09-02 17:07:39 +04:00
|
|
|
BOOL rc;
|
2013-08-29 17:30:22 +04:00
|
|
|
int i, close_cnt;
|
2013-01-23 03:14:50 +04:00
|
|
|
int pos;
|
|
|
|
BYTE quant;
|
2013-08-13 18:09:32 +04:00
|
|
|
RFX_TILE* tile;
|
2013-01-23 03:14:50 +04:00
|
|
|
UINT32* quants;
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 subtype;
|
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;
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 14)
|
2013-01-29 01:23:10 +04:00
|
|
|
{
|
|
|
|
DEBUG_WARN("RfxMessageTileSet packet too small");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-05-09 00:09:16 +04: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)
|
|
|
|
{
|
|
|
|
DEBUG_WARN("invalid subtype, expected CBT_TILESET.");
|
2013-01-29 01:23:10 +04:00
|
|
|
return FALSE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek_UINT16(s); /* idx (2 bytes), must be set to 0x0000 */
|
|
|
|
Stream_Seek_UINT16(s); /* properties (2 bytes) */
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2013-08-13 19:09:54 +04:00
|
|
|
Stream_Read_UINT8(s, context->numQuant); /* numQuant (1 byte) */
|
2013-05-09 00:27:21 +04: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
|
|
|
{
|
|
|
|
DEBUG_WARN("no quantization value.");
|
2013-01-29 01:23:10 +04:00
|
|
|
return TRUE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-08-14 01:18:59 +04:00
|
|
|
Stream_Read_UINT16(s, message->numTiles); /* numTiles (2 bytes) */
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2013-08-14 01:18:59 +04:00
|
|
|
if (message->numTiles < 1)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
|
|
|
DEBUG_WARN("no tiles.");
|
2013-01-29 01:23:10 +04:00
|
|
|
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
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
context->quants = (UINT32 *)realloc((void*) context->quants, context->numQuant * 10 * sizeof(UINT32));
|
2013-10-09 04:17:57 +04:00
|
|
|
|
2011-08-10 11:13:39 +04:00
|
|
|
quants = context->quants;
|
|
|
|
|
|
|
|
/* quantVals */
|
2014-02-11 07:12:13 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < (size_t) (context->numQuant * 5))
|
2013-01-29 01:23:10 +04:00
|
|
|
{
|
2013-08-13 19:09:54 +04:00
|
|
|
DEBUG_WARN("RfxMessageTileSet packet too small for num_quants=%d", context->numQuant);
|
2013-01-29 01:23:10 +04:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2013-08-13 19:09:54 +04:00
|
|
|
for (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);
|
|
|
|
|
2013-10-09 04:17:57 +04:00
|
|
|
WLog_Print(context->priv->log, WLOG_DEBUG, "quant %d (%d %d %d %d %d %d %d %d %d %d).",
|
2011-08-10 11:13:39 +04: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]);
|
|
|
|
}
|
|
|
|
|
2013-08-14 01:18:59 +04:00
|
|
|
message->tiles = (RFX_TILE**) malloc(sizeof(RFX_TILE*) * message->numTiles);
|
|
|
|
ZeroMemory(message->tiles, sizeof(RFX_TILE*) * message->numTiles);
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2013-01-23 06:54:13 +04:00
|
|
|
if (context->priv->UseThreads)
|
2013-01-23 03:14:50 +04:00
|
|
|
{
|
2013-08-14 01:18:59 +04:00
|
|
|
work_objects = (PTP_WORK*) malloc(sizeof(PTP_WORK) * message->numTiles);
|
2013-08-29 12:37:14 +04:00
|
|
|
params = (RFX_TILE_PROCESS_WORK_PARAM*)
|
|
|
|
malloc(sizeof(RFX_TILE_PROCESS_WORK_PARAM) * message->numTiles);
|
|
|
|
|
|
|
|
if (!work_objects)
|
|
|
|
{
|
|
|
|
if (params)
|
|
|
|
free(params);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-10-09 04:17:57 +04:00
|
|
|
|
2013-08-29 12:37:14 +04:00
|
|
|
if (!params)
|
|
|
|
{
|
|
|
|
if (work_objects)
|
|
|
|
free(work_objects);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2013-10-09 04:17:57 +04:00
|
|
|
|
2013-08-29 17:30:22 +04:00
|
|
|
ZeroMemory(work_objects, sizeof(PTP_WORK) * message->numTiles);
|
|
|
|
ZeroMemory(params, sizeof(RFX_TILE_PROCESS_WORK_PARAM) * message->numTiles);
|
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;
|
2013-09-02 17:07:39 +04:00
|
|
|
rc = TRUE;
|
2013-08-14 01:18:59 +04:00
|
|
|
for (i = 0; i < message->numTiles; i++)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2013-08-13 18:09:32 +04:00
|
|
|
tile = message->tiles[i] = (RFX_TILE*) ObjectPool_Take(context->priv->TilePool);
|
|
|
|
|
2011-08-10 11:13:39 +04:00
|
|
|
/* RFX_TILE */
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 6)
|
2013-01-29 01:23:10 +04:00
|
|
|
{
|
2013-08-14 01:18:59 +04:00
|
|
|
DEBUG_WARN("RfxMessageTileSet packet too small to read tile %d/%d", i, message->numTiles);
|
2013-09-02 17:07:39 +04:00
|
|
|
rc = FALSE;
|
|
|
|
break;
|
2013-01-29 01:23:10 +04:00
|
|
|
}
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, blockType); /* blockType (2 bytes), must be set to CBT_TILE (0xCAC3) */
|
|
|
|
Stream_Read_UINT32(s, blockLen); /* blockLen (4 bytes) */
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < blockLen - 6)
|
2013-01-29 01:23:10 +04:00
|
|
|
{
|
2013-08-28 18:19:33 +04:00
|
|
|
DEBUG_WARN("RfxMessageTileSet not enough bytes to read tile %d/%d with blocklen=%d",
|
|
|
|
i, message->numTiles, blockLen);
|
2013-09-02 17:07:39 +04:00
|
|
|
rc = FALSE;
|
|
|
|
break;
|
2013-01-29 01:23:10 +04:00
|
|
|
}
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
pos = Stream_GetPosition(s) - 6 + blockLen;
|
2011-08-10 11:13:39 +04:00
|
|
|
|
|
|
|
if (blockType != CBT_TILE)
|
|
|
|
{
|
|
|
|
DEBUG_WARN("unknown block type 0x%X, expected CBT_TILE (0xCAC3).", blockType);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-08-13 18:09:32 +04:00
|
|
|
Stream_Read_UINT8(s, tile->quantIdxY); /* quantIdxY (1 byte) */
|
|
|
|
Stream_Read_UINT8(s, tile->quantIdxCb); /* quantIdxCb (1 byte) */
|
|
|
|
Stream_Read_UINT8(s, tile->quantIdxCr); /* quantIdxCr (1 byte) */
|
|
|
|
Stream_Read_UINT16(s, tile->xIdx); /* xIdx (2 bytes) */
|
|
|
|
Stream_Read_UINT16(s, tile->yIdx); /* yIdx (2 bytes) */
|
|
|
|
Stream_Read_UINT16(s, tile->YLen); /* YLen (2 bytes) */
|
|
|
|
Stream_Read_UINT16(s, tile->CbLen); /* CbLen (2 bytes) */
|
|
|
|
Stream_Read_UINT16(s, tile->CrLen); /* CrLen (2 bytes) */
|
|
|
|
|
|
|
|
Stream_GetPointer(s, tile->YData);
|
|
|
|
Stream_Seek(s, tile->YLen);
|
|
|
|
Stream_GetPointer(s, tile->CbData);
|
|
|
|
Stream_Seek(s, tile->CbLen);
|
|
|
|
Stream_GetPointer(s, tile->CrData);
|
|
|
|
Stream_Seek(s, tile->CrLen);
|
|
|
|
|
|
|
|
tile->x = tile->xIdx * 64;
|
|
|
|
tile->y = tile->yIdx * 64;
|
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
|
|
|
{
|
2013-08-30 16:19:50 +04:00
|
|
|
assert(params);
|
|
|
|
|
2013-01-23 03:14:50 +04:00
|
|
|
params[i].context = context;
|
|
|
|
params[i].tile = message->tiles[i];
|
|
|
|
|
|
|
|
work_objects[i] = CreateThreadpoolWork((PTP_WORK_CALLBACK) rfx_process_message_tile_work_callback,
|
|
|
|
(void*) ¶ms[i], &context->priv->ThreadPoolEnv);
|
|
|
|
|
|
|
|
SubmitThreadpoolWork(work_objects[i]);
|
2013-08-29 17:30:22 +04:00
|
|
|
close_cnt = i + 1;
|
2013-01-23 03:14:50 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-08-13 18:09:32 +04:00
|
|
|
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-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(s, pos);
|
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
|
|
|
{
|
2013-08-29 17:30:22 +04:00
|
|
|
for (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]);
|
|
|
|
}
|
2013-08-29 17:30:22 +04:00
|
|
|
}
|
2013-01-23 03:14:50 +04:00
|
|
|
|
2013-08-29 17:30:22 +04:00
|
|
|
if (work_objects)
|
2013-01-23 03:14:50 +04:00
|
|
|
free(work_objects);
|
2013-08-29 17:30:22 +04:00
|
|
|
if (params)
|
2013-01-23 03:14:50 +04:00
|
|
|
free(params);
|
2013-08-14 01:18:59 +04:00
|
|
|
|
|
|
|
for (i = 0; i < message->numTiles; i++)
|
|
|
|
{
|
|
|
|
tile = message->tiles[i];
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
RFX_MESSAGE* rfx_process_message(RFX_CONTEXT* context, BYTE* data, UINT32 length)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2011-09-19 06:34:19 +04:00
|
|
|
int pos;
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* s;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 blockLen;
|
|
|
|
UINT32 blockType;
|
2011-08-10 11:13:39 +04:00
|
|
|
RFX_MESSAGE* message;
|
|
|
|
|
2012-11-22 05:21:08 +04:00
|
|
|
message = (RFX_MESSAGE*) malloc(sizeof(RFX_MESSAGE));
|
|
|
|
ZeroMemory(message, sizeof(RFX_MESSAGE));
|
|
|
|
|
2013-08-14 18:14:47 +04:00
|
|
|
message->freeRects = TRUE;
|
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
s = Stream_New(data, length);
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
while (Stream_GetRemainingLength(s) > 6)
|
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) */
|
|
|
|
Stream_Read_UINT32(s, blockLen); /* blockLen (4 bytes) */
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2013-10-09 04:17:57 +04:00
|
|
|
WLog_Print(context->priv->log, WLOG_DEBUG, "blockType 0x%X blockLen %d", blockType, blockLen);
|
2011-08-10 11:13:39 +04:00
|
|
|
|
|
|
|
if (blockLen == 0)
|
|
|
|
{
|
|
|
|
DEBUG_WARN("zero blockLen");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < blockLen - 6)
|
2013-01-29 01:23:10 +04:00
|
|
|
{
|
|
|
|
DEBUG_WARN("rfx_process_message: packet too small for blocklen=%d", blockLen);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
pos = Stream_GetPosition(s) - 6 + blockLen;
|
2011-08-10 11:13:39 +04:00
|
|
|
|
|
|
|
if (blockType >= WBT_CONTEXT && blockType <= WBT_EXTENSION)
|
|
|
|
{
|
|
|
|
/* RFX_CODEC_CHANNELT */
|
|
|
|
/* codecId (1 byte) must be set to 0x01 */
|
|
|
|
/* channelId (1 byte) must be set to 0x00 */
|
2013-05-09 01:48:30 +04:00
|
|
|
if (!Stream_SafeSeek(s, 2))
|
2013-01-29 01:23:10 +04:00
|
|
|
{
|
|
|
|
DEBUG_WARN("rfx_process_message: unable to skip RFX_CODEC_CHANNELT");
|
|
|
|
break;
|
|
|
|
}
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (blockType)
|
|
|
|
{
|
|
|
|
case WBT_SYNC:
|
2011-09-19 06:34:19 +04:00
|
|
|
rfx_process_message_sync(context, s);
|
2011-08-10 11:13:39 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WBT_CODEC_VERSIONS:
|
2011-09-19 06:34:19 +04:00
|
|
|
rfx_process_message_codec_versions(context, s);
|
2011-08-10 11:13:39 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WBT_CHANNELS:
|
2011-09-19 06:34:19 +04:00
|
|
|
rfx_process_message_channels(context, s);
|
2011-08-10 11:13:39 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WBT_CONTEXT:
|
2011-09-19 06:34:19 +04:00
|
|
|
rfx_process_message_context(context, s);
|
2011-08-10 11:13:39 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WBT_FRAME_BEGIN:
|
2011-09-19 06:34:19 +04:00
|
|
|
rfx_process_message_frame_begin(context, message, s);
|
2011-08-10 11:13:39 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WBT_FRAME_END:
|
2011-09-19 06:34:19 +04:00
|
|
|
rfx_process_message_frame_end(context, message, s);
|
2011-08-10 11:13:39 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WBT_REGION:
|
2011-09-19 06:34:19 +04:00
|
|
|
rfx_process_message_region(context, message, s);
|
2011-08-10 11:13:39 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WBT_EXTENSION:
|
2011-09-19 06:34:19 +04:00
|
|
|
rfx_process_message_tileset(context, message, s);
|
2011-08-10 11:13:39 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
DEBUG_WARN("unknown blockType 0x%X", blockType);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(s, pos);
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
Stream_Free(s, FALSE);
|
2011-09-19 06:47:30 +04:00
|
|
|
|
2011-08-10 11:13:39 +04:00
|
|
|
return message;
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 rfx_message_get_tile_count(RFX_MESSAGE* message)
|
2011-09-19 06:34:19 +04:00
|
|
|
{
|
2013-08-14 01:18:59 +04:00
|
|
|
return message->numTiles;
|
2011-09-19 06:34:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
RFX_TILE* rfx_message_get_tile(RFX_MESSAGE* message, int index)
|
|
|
|
{
|
|
|
|
return message->tiles[index];
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 rfx_message_get_rect_count(RFX_MESSAGE* message)
|
2011-09-19 06:34:19 +04:00
|
|
|
{
|
2013-08-14 01:18:59 +04:00
|
|
|
return message->numRects;
|
2011-09-19 06:34:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
RFX_RECT* rfx_message_get_rect(RFX_MESSAGE* message, int index)
|
|
|
|
{
|
|
|
|
return &message->rects[index];
|
|
|
|
}
|
|
|
|
|
2011-08-10 11:13:39 +04:00
|
|
|
void rfx_message_free(RFX_CONTEXT* context, RFX_MESSAGE* message)
|
|
|
|
{
|
2013-01-21 05:44:30 +04:00
|
|
|
int i;
|
2013-08-14 01:18:59 +04:00
|
|
|
RFX_TILE* tile;
|
2013-01-21 05:44:30 +04:00
|
|
|
|
2013-08-14 01:18:59 +04:00
|
|
|
if (message)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2013-08-14 18:14:47 +04:00
|
|
|
if ((message->rects) && (message->freeRects))
|
2013-08-14 01:18:59 +04:00
|
|
|
{
|
|
|
|
free(message->rects);
|
|
|
|
}
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2013-01-21 05:44:30 +04:00
|
|
|
if (message->tiles)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2013-08-14 01:18:59 +04:00
|
|
|
for (i = 0; i < message->numTiles; i++)
|
2013-08-13 17:34:15 +04:00
|
|
|
{
|
2013-08-14 01:18:59 +04:00
|
|
|
tile = message->tiles[i];
|
|
|
|
|
2013-08-20 02:39:19 +04:00
|
|
|
if (tile->YCbCrData)
|
|
|
|
{
|
|
|
|
BufferPool_Return(context->priv->BufferPool, tile->YCbCrData);
|
|
|
|
tile->YCbCrData = NULL;
|
|
|
|
}
|
2013-08-14 01:18:59 +04:00
|
|
|
|
|
|
|
ObjectPool_Return(context->priv->TilePool, (void*) tile);
|
2013-08-13 17:34:15 +04:00
|
|
|
}
|
2013-01-21 05:44:30 +04:00
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(message->tiles);
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-08-14 21:19:01 +04:00
|
|
|
if (!message->freeArray)
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
UINT16 properties;
|
|
|
|
|
|
|
|
/* properties in tilesets: note that this has different format from the one in TS_RFX_CONTEXT */
|
|
|
|
properties = 1; /* lt */
|
|
|
|
properties |= (context->flags << 1); /* flags */
|
|
|
|
properties |= (COL_CONV_ICT << 4); /* cct */
|
|
|
|
properties |= (CLW_XFORM_DWT_53_A << 6); /* xft */
|
|
|
|
properties |= ((context->mode == RLGR1 ? CLW_ENTROPY_RLGR1 : CLW_ENTROPY_RLGR3) << 10); /* et */
|
|
|
|
properties |= (SCALAR_QUANTIZATION << 14); /* qt */
|
|
|
|
|
|
|
|
context->properties = properties;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rfx_write_message_sync(RFX_CONTEXT* context, wStream* s)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2013-08-14 18:14:47 +04: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) */
|
|
|
|
Stream_Write_UINT16(s, WF_VERSION_1_0); /* version (2 bytes) */
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-08-14 18:14:47 +04:00
|
|
|
static void rfx_write_message_codec_versions(RFX_CONTEXT* context, wStream* s)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2013-08-14 18:14:47 +04:00
|
|
|
Stream_Write_UINT16(s, WBT_CODEC_VERSIONS); /* BlockT.blockType (2 bytes) */
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-08-14 18:14:47 +04:00
|
|
|
static void rfx_write_message_channels(RFX_CONTEXT* context, wStream* s)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2013-08-14 18:14:47 +04: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) */
|
|
|
|
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
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 properties;
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2013-08-14 18:14:47 +04: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, 0); /* CodecChannelT.channelId (1 byte) */
|
|
|
|
Stream_Write_UINT8(s, 0); /* ctxId (1 byte) */
|
|
|
|
Stream_Write_UINT16(s, CT_TILE_64x64); /* tileSize (2 bytes) */
|
2011-08-10 11:13:39 +04:00
|
|
|
|
|
|
|
/* properties */
|
|
|
|
properties = context->flags; /* flags */
|
|
|
|
properties |= (COL_CONV_ICT << 3); /* cct */
|
|
|
|
properties |= (CLW_XFORM_DWT_53_A << 5); /* xft */
|
|
|
|
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) */
|
2011-08-24 11:18:14 +04:00
|
|
|
|
2013-08-14 18:14:47 +04:00
|
|
|
rfx_update_context_properties(context);
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
void rfx_compose_message_header(RFX_CONTEXT* context, wStream* s)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2013-05-02 02:15:55 +04:00
|
|
|
Stream_EnsureRemainingCapacity(s, 12 + 10 + 12 + 13);
|
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);
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-08-14 01:18:59 +04:00
|
|
|
static int rfx_tile_length(RFX_TILE* tile)
|
|
|
|
{
|
|
|
|
return 19 + tile->YLen + tile->CbLen + tile->CrLen;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-08-13 22:13:05 +04:00
|
|
|
static void rfx_write_tile(RFX_CONTEXT* context, wStream* s, RFX_TILE* tile)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2013-08-13 22:13:05 +04:00
|
|
|
UINT32 blockLen;
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2013-08-14 01:18:59 +04:00
|
|
|
blockLen = rfx_tile_length(tile);
|
2013-08-13 22:13:05 +04:00
|
|
|
Stream_EnsureRemainingCapacity(s, blockLen);
|
|
|
|
|
|
|
|
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 */
|
|
|
|
Stream_Write(s, tile->CbData, tile->CbLen); /* CbData */
|
|
|
|
Stream_Write(s, tile->CrData, tile->CrLen); /* CrData */
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-08-04 14:07:53 +04:00
|
|
|
struct _RFX_TILE_COMPOSE_WORK_PARAM
|
|
|
|
{
|
2013-08-13 18:30:22 +04:00
|
|
|
RFX_TILE* tile;
|
2013-08-04 14:07:53 +04:00
|
|
|
RFX_CONTEXT* context;
|
|
|
|
};
|
|
|
|
|
|
|
|
void CALLBACK rfx_compose_message_tile_work_callback(PTP_CALLBACK_INSTANCE instance, void* context, PTP_WORK work)
|
|
|
|
{
|
|
|
|
RFX_TILE_COMPOSE_WORK_PARAM* param = (RFX_TILE_COMPOSE_WORK_PARAM*) context;
|
2013-08-13 22:13:05 +04:00
|
|
|
rfx_encode_rgb(param->context, param->tile);
|
2013-08-04 14:07:53 +04:00
|
|
|
}
|
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
|
2014-02-07 19:43:48 +04:00
|
|
|
static BOOL computeRegion(const RFX_RECT* rects, int numRects, REGION16 *region, int width, int height)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2014-02-04 15:02:55 +04:00
|
|
|
int i;
|
|
|
|
const RFX_RECT *rect = rects;
|
2014-02-07 19:43:48 +04:00
|
|
|
const RECTANGLE_16 mainRect = { 0, 0, width, height };
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
for(i = 0; i < numRects; i++, rect++) {
|
|
|
|
RECTANGLE_16 rect16;
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
BOOL setupWorkers(RFX_CONTEXT *context, int nbTiles)
|
|
|
|
{
|
|
|
|
RFX_CONTEXT_PRIV *priv = context->priv;
|
|
|
|
|
|
|
|
if (!context->priv->UseThreads)
|
|
|
|
return TRUE;
|
|
|
|
|
2014-07-08 23:07:19 +04:00
|
|
|
priv->workObjects = (PTP_WORK*) realloc(priv->workObjects, sizeof(PTP_WORK) * nbTiles);
|
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
if (!priv->workObjects)
|
2014-07-08 23:07:19 +04:00
|
|
|
return FALSE;
|
2013-10-09 04:17:57 +04:00
|
|
|
|
2014-07-08 23:07:19 +04:00
|
|
|
priv->tileWorkParams = (RFX_TILE_COMPOSE_WORK_PARAM*)
|
2014-02-04 15:02:55 +04:00
|
|
|
realloc(priv->tileWorkParams, sizeof(RFX_TILE_COMPOSE_WORK_PARAM) * nbTiles);
|
2014-07-08 23:07:19 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
if (!priv->tileWorkParams)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context, const RFX_RECT* rects, int numRects,
|
|
|
|
BYTE* data, int width, int height, int scanline)
|
|
|
|
{
|
|
|
|
int i, maxNbTiles, maxTilesX, maxTilesY;
|
|
|
|
int xIdx, yIdx, regionNbRects;
|
|
|
|
int gridRelX, gridRelY, ax, ay, bytesPerPixel;
|
2013-08-13 18:30:22 +04:00
|
|
|
RFX_TILE* tile;
|
2014-02-04 15:02:55 +04:00
|
|
|
RFX_RECT* rfxRect;
|
2013-08-14 01:18:59 +04:00
|
|
|
RFX_MESSAGE* message = NULL;
|
2014-02-05 17:07:22 +04:00
|
|
|
PTP_WORK* workObject = NULL;
|
|
|
|
RFX_TILE_COMPOSE_WORK_PARAM *workParam = NULL;
|
2014-02-04 15:02:55 +04:00
|
|
|
|
|
|
|
REGION16 rectsRegion, tilesRegion;
|
|
|
|
RECTANGLE_16 currentTileRect;
|
|
|
|
const RECTANGLE_16 *regionRect;
|
|
|
|
const RECTANGLE_16 *extents;
|
|
|
|
|
2014-02-07 19:43:48 +04:00
|
|
|
assert(data);
|
|
|
|
assert(rects);
|
|
|
|
assert(numRects > 0);
|
|
|
|
assert(width > 0);
|
|
|
|
assert(height > 0);
|
|
|
|
assert(scanline > 0);
|
|
|
|
|
2014-07-08 23:07:19 +04:00
|
|
|
message = (RFX_MESSAGE*)calloc(1, sizeof(RFX_MESSAGE));
|
|
|
|
|
2013-08-29 17:30:22 +04:00
|
|
|
if (!message)
|
|
|
|
return NULL;
|
|
|
|
|
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
|
|
|
{
|
2013-08-13 19:09:54 +04:00
|
|
|
context->numQuant = 1;
|
2013-08-17 00:46:47 +04:00
|
|
|
context->quants = (UINT32*) malloc(sizeof(rfx_default_quantization_values));
|
|
|
|
CopyMemory(context->quants, &rfx_default_quantization_values, sizeof(rfx_default_quantization_values));
|
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;
|
2013-08-13 19:09:54 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
bytesPerPixel = (context->bits_per_pixel / 8);
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
region16_init(&rectsRegion);
|
2014-07-08 23:07:19 +04:00
|
|
|
|
2014-02-07 19:43:48 +04:00
|
|
|
if (!computeRegion(rects, numRects, &rectsRegion, width, height))
|
2014-02-04 15:02:55 +04:00
|
|
|
goto out_free_message;
|
2014-02-07 19:43:48 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
extents = region16_extents(&rectsRegion);
|
2014-02-07 19:43:48 +04:00
|
|
|
assert(extents->right - extents->left > 0);
|
|
|
|
assert(extents->bottom - extents->top > 0);
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2014-02-05 17:07:22 +04:00
|
|
|
maxTilesX = 1 + TILE_NO(extents->right - 1) - TILE_NO(extents->left);
|
|
|
|
maxTilesY = 1 + TILE_NO(extents->bottom - 1) - TILE_NO(extents->top);
|
2014-02-04 15:02:55 +04:00
|
|
|
maxNbTiles = maxTilesX * maxTilesY;
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2014-02-05 18:52:29 +04:00
|
|
|
message->tiles = calloc(maxNbTiles, sizeof(RFX_TILE*));
|
2014-07-08 23:07:19 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
if (!message->tiles)
|
|
|
|
goto out_free_message;
|
|
|
|
|
|
|
|
if (!setupWorkers(context, maxNbTiles))
|
|
|
|
goto out_clean_tiles;
|
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
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
regionRect = region16_rects(&rectsRegion, ®ionNbRects);
|
2014-02-05 18:52:29 +04:00
|
|
|
message->rects = rfxRect = calloc(regionNbRects, sizeof(RFX_RECT));
|
2014-07-08 23:07:19 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
if (!message->rects)
|
|
|
|
goto out_clean_tiles;
|
2014-07-08 23:07:19 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
message->numRects = regionNbRects;
|
|
|
|
|
|
|
|
region16_init(&tilesRegion);
|
|
|
|
|
|
|
|
for (i = 0; i < regionNbRects; i++, regionRect++, rfxRect++)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2014-02-04 15:02:55 +04:00
|
|
|
int startTileX = regionRect->left / 64;
|
|
|
|
int endTileX = (regionRect->right - 1) / 64;
|
|
|
|
|
|
|
|
int startTileY = regionRect->top / 64;
|
|
|
|
int endTileY = (regionRect->bottom - 1) / 64;
|
|
|
|
|
|
|
|
rfxRect->x = regionRect->left;
|
|
|
|
rfxRect->y = regionRect->top;
|
|
|
|
rfxRect->width = (regionRect->right - regionRect->left);
|
|
|
|
rfxRect->height = (regionRect->bottom - regionRect->top);
|
|
|
|
|
2013-08-13 18:30:22 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
for (yIdx = startTileY, gridRelY = startTileY * 64; yIdx <= endTileY; yIdx++, gridRelY += 64 )
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2014-02-04 15:02:55 +04:00
|
|
|
int 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
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
for (xIdx = startTileX, gridRelX = startTileX * 64; xIdx <= endTileX; xIdx++, gridRelX += 64)
|
2013-09-03 16:27:08 +04:00
|
|
|
{
|
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
|
|
|
|
2014-07-08 23:07:19 +04:00
|
|
|
tile = (RFX_TILE*) ObjectPool_Take(context->priv->TilePool);
|
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
if (!tile)
|
|
|
|
goto out_clean_rects;;
|
|
|
|
|
|
|
|
tile->xIdx = xIdx;
|
|
|
|
tile->yIdx = yIdx;
|
|
|
|
tile->x = gridRelX;
|
|
|
|
tile->y = gridRelY;
|
|
|
|
tile->scanline = scanline;
|
|
|
|
tile->width = tileWidth;
|
|
|
|
tile->height = tileHeight;
|
|
|
|
|
|
|
|
ax = gridRelX;
|
|
|
|
ay = gridRelY;
|
2014-07-08 23:07:19 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
if (tile->data && tile->allocated)
|
|
|
|
{
|
|
|
|
free(tile->data);
|
|
|
|
tile->allocated = FALSE;
|
|
|
|
}
|
|
|
|
tile->data = &data[(ay * scanline) + (ax * bytesPerPixel)];
|
2013-08-15 04:35:00 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
tile->quantIdxY = context->quantIdxY;
|
|
|
|
tile->quantIdxCb = context->quantIdxCb;
|
|
|
|
tile->quantIdxCr = context->quantIdxCr;
|
2013-08-15 04:35:00 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
tile->YLen = tile->CbLen = tile->CrLen = 0;
|
2013-08-20 02:39:19 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
tile->YCbCrData = (BYTE *)BufferPool_Take(context->priv->BufferPool, -1);
|
|
|
|
if (!tile->YCbCrData)
|
|
|
|
goto out_clean_rects;
|
2013-08-20 02:39:19 +04:00
|
|
|
|
2014-02-04 15:02:55 +04: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]);
|
2013-08-04 14:07:53 +04: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
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
*workObject = CreateThreadpoolWork(
|
|
|
|
(PTP_WORK_CALLBACK)rfx_compose_message_tile_work_callback,
|
2014-07-08 23:07:19 +04:00
|
|
|
(void*) workParam,
|
2014-02-04 15:02:55 +04:00
|
|
|
&context->priv->ThreadPoolEnv
|
|
|
|
);
|
2013-08-04 14:07:53 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
SubmitThreadpoolWork(*workObject);
|
2013-08-04 14:07:53 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
workObject++;
|
|
|
|
workParam++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rfx_encode_rgb(context, tile);
|
|
|
|
}
|
|
|
|
|
|
|
|
message->tiles[message->numTiles] = tile;
|
|
|
|
message->numTiles++;
|
|
|
|
|
|
|
|
if (!region16_union_rect(&tilesRegion, &tilesRegion, ¤tTileRect))
|
|
|
|
goto out_clean_rects;
|
|
|
|
} /* xIdx */
|
|
|
|
} /* yIdx */
|
|
|
|
} /* rects */
|
|
|
|
|
|
|
|
if (message->numTiles != maxNbTiles)
|
|
|
|
{
|
2014-07-08 23:07:19 +04:00
|
|
|
message->tiles = realloc(message->tiles, sizeof(RFX_TILE*) * message->numTiles);
|
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
if (!message->tiles)
|
|
|
|
goto out_clean_rects;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
2013-08-04 14:07:53 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
region16_uninit(&tilesRegion);
|
2013-08-12 21:13:27 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
/* when using threads ensure all computations are done */
|
|
|
|
message->tilesDataSize = 0;
|
|
|
|
workObject = context->priv->workObjects;
|
2014-07-08 23:07:19 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
for (i = 0; i < message->numTiles; i++)
|
2013-08-14 01:18:59 +04:00
|
|
|
{
|
|
|
|
tile = message->tiles[i];
|
2014-02-04 15:02:55 +04:00
|
|
|
if (context->priv->UseThreads)
|
2013-08-14 01:18:59 +04:00
|
|
|
{
|
2014-02-04 15:02:55 +04:00
|
|
|
WaitForThreadpoolWorkCallbacks(*workObject, FALSE);
|
|
|
|
CloseThreadpoolWork(*workObject);
|
|
|
|
workObject++;
|
2013-08-04 14:07:53 +04:00
|
|
|
}
|
2013-08-14 01:18:59 +04:00
|
|
|
|
|
|
|
message->tilesDataSize += rfx_tile_length(tile);
|
2013-08-13 22:13:05 +04:00
|
|
|
}
|
2013-08-12 21:13:27 +04:00
|
|
|
|
2013-08-13 22:13:05 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
region16_uninit(&rectsRegion);
|
2013-08-14 01:18:59 +04:00
|
|
|
return message;
|
2014-02-04 15:02:55 +04:00
|
|
|
|
|
|
|
out_clean_rects:
|
|
|
|
free(message->rects);
|
|
|
|
out_clean_tiles:
|
|
|
|
free(message->tiles);
|
|
|
|
region16_uninit(&tilesRegion);
|
|
|
|
out_free_message:
|
2014-08-07 18:51:24 +04:00
|
|
|
DEBUG_WARN( "remoteFx error\n");
|
2014-02-04 15:02:55 +04:00
|
|
|
region16_uninit(&rectsRegion);
|
|
|
|
free(message);
|
|
|
|
return 0;
|
2013-08-14 01:18:59 +04:00
|
|
|
}
|
2013-08-04 14:07:53 +04:00
|
|
|
|
2014-02-04 15:02:55 +04:00
|
|
|
|
2013-08-14 21:19:01 +04:00
|
|
|
RFX_MESSAGE* rfx_split_message(RFX_CONTEXT* context, RFX_MESSAGE* message, int* numMessages, int maxDataSize)
|
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
UINT32 tileDataSize;
|
|
|
|
RFX_MESSAGE* messages;
|
|
|
|
|
|
|
|
maxDataSize -= 1024; /* reserve enough space for headers */
|
|
|
|
|
|
|
|
*numMessages = ((message->tilesDataSize + maxDataSize) / maxDataSize) * 4;
|
|
|
|
|
2014-07-08 23:07:19 +04:00
|
|
|
messages = (RFX_MESSAGE*) calloc((*numMessages), sizeof(RFX_MESSAGE));
|
|
|
|
|
|
|
|
if (!messages)
|
|
|
|
return NULL;
|
2013-08-14 21:19:01 +04:00
|
|
|
|
|
|
|
j = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < message->numTiles; i++)
|
|
|
|
{
|
|
|
|
tileDataSize = rfx_tile_length(message->tiles[i]);
|
|
|
|
|
2014-02-11 07:12:13 +04:00
|
|
|
if ((messages[j].tilesDataSize + tileDataSize) > ((UINT32) maxDataSize))
|
2013-08-14 21:19:01 +04:00
|
|
|
j++;
|
|
|
|
|
|
|
|
if (!messages[j].numTiles)
|
|
|
|
{
|
|
|
|
messages[j].frameIdx = message->frameIdx + j;
|
|
|
|
messages[j].numQuant = message->numQuant;
|
|
|
|
messages[j].quantVals = message->quantVals;
|
|
|
|
messages[j].numRects = message->numRects;
|
|
|
|
messages[j].rects = message->rects;
|
|
|
|
messages[j].tiles = (RFX_TILE**) malloc(sizeof(RFX_TILE*) * message->numTiles);
|
2013-08-15 04:35:00 +04:00
|
|
|
messages[j].freeRects = FALSE;
|
2013-08-14 21:19:01 +04:00
|
|
|
messages[j].freeArray = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
messages[j].tilesDataSize += tileDataSize;
|
|
|
|
messages[j].tiles[messages[j].numTiles++] = message->tiles[i];
|
|
|
|
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;
|
|
|
|
|
2013-08-15 04:35:00 +04:00
|
|
|
for (i = 0; i < *numMessages; i++)
|
|
|
|
{
|
|
|
|
for (j = 0; j < messages[i].numTiles; j++)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-14 21:19:01 +04:00
|
|
|
return messages;
|
|
|
|
}
|
|
|
|
|
|
|
|
RFX_MESSAGE* rfx_encode_messages(RFX_CONTEXT* context, const RFX_RECT* rects, int numRects,
|
|
|
|
BYTE* data, int width, int height, int scanline, int* numMessages, int maxDataSize)
|
|
|
|
{
|
|
|
|
RFX_MESSAGE* message;
|
|
|
|
RFX_MESSAGE* messages;
|
|
|
|
|
|
|
|
message = rfx_encode_message(context, rects, numRects, data, width, height, scanline);
|
|
|
|
messages = rfx_split_message(context, message, numMessages, maxDataSize);
|
|
|
|
rfx_message_free(context, message);
|
|
|
|
|
|
|
|
return messages;
|
|
|
|
}
|
|
|
|
|
2013-08-14 01:18:59 +04:00
|
|
|
static void rfx_write_message_tileset(RFX_CONTEXT* context, wStream* s, RFX_MESSAGE* message)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
RFX_TILE* tile;
|
|
|
|
UINT32 blockLen;
|
|
|
|
UINT32* quantVals;
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2013-08-14 01:18:59 +04:00
|
|
|
blockLen = 22 + (message->numQuant * 5) + message->tilesDataSize;
|
|
|
|
Stream_EnsureRemainingCapacity(s, blockLen);
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2013-08-14 01:18:59 +04: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
|
|
|
|
|
|
|
quantVals = message->quantVals;
|
|
|
|
|
|
|
|
for (i = 0; i < message->numQuant * 5; i++)
|
|
|
|
{
|
|
|
|
Stream_Write_UINT8(s, quantVals[0] + (quantVals[1] << 4));
|
|
|
|
quantVals += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < message->numTiles; i++)
|
|
|
|
{
|
|
|
|
tile = message->tiles[i];
|
|
|
|
rfx_write_tile(context, s, tile);
|
|
|
|
}
|
|
|
|
|
2013-10-09 04:17:57 +04:00
|
|
|
WLog_Print(context->priv->log, WLOG_DEBUG, "numQuant: %d numTiles: %d tilesDataSize: %d",
|
2013-08-14 01:18:59 +04:00
|
|
|
message->numQuant, message->numTiles, message->tilesDataSize);
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-08-14 01:50:05 +04:00
|
|
|
void rfx_write_message_frame_begin(RFX_CONTEXT* context, wStream* s, RFX_MESSAGE* message)
|
|
|
|
{
|
|
|
|
Stream_EnsureRemainingCapacity(s, 14);
|
|
|
|
|
|
|
|
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 */
|
|
|
|
Stream_Write_UINT32(s, message->frameIdx); /* frameIdx */
|
|
|
|
Stream_Write_UINT16(s, 1); /* numRegions */
|
|
|
|
}
|
|
|
|
|
|
|
|
void rfx_write_message_region(RFX_CONTEXT* context, wStream* s, RFX_MESSAGE* message)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
UINT32 blockLen;
|
|
|
|
|
|
|
|
blockLen = 15 + (message->numRects * 8);
|
|
|
|
Stream_EnsureRemainingCapacity(s, blockLen);
|
|
|
|
|
|
|
|
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) */
|
|
|
|
Stream_Write_UINT16(s, message->numRects); /* numRects (2 bytes) */
|
|
|
|
|
|
|
|
for (i = 0; i < message->numRects; i++)
|
|
|
|
{
|
2013-08-15 04:35:00 +04:00
|
|
|
/* Clipping rectangles are relative to destLeft, destTop */
|
|
|
|
|
|
|
|
Stream_Write_UINT16(s, message->rects[i].x); /* x (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, message->rects[i].y); /* y (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, message->rects[i].width); /* width (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, message->rects[i].height); /* height (2 bytes) */
|
2013-08-14 01:50:05 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Write_UINT16(s, CBT_REGION); /* regionType (2 bytes) */
|
|
|
|
Stream_Write_UINT16(s, 1); /* numTilesets (2 bytes) */
|
|
|
|
}
|
|
|
|
|
|
|
|
void rfx_write_message_frame_end(RFX_CONTEXT* context, wStream* s, RFX_MESSAGE* message)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2013-05-02 02:15:55 +04:00
|
|
|
Stream_EnsureRemainingCapacity(s, 8);
|
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 */
|
|
|
|
Stream_Write_UINT32(s, 8); /* CodecChannelT.blockLen */
|
|
|
|
Stream_Write_UINT8(s, 1); /* CodecChannelT.codecId */
|
|
|
|
Stream_Write_UINT8(s, 0); /* CodecChannelT.channelId */
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-08-14 18:14:47 +04:00
|
|
|
void rfx_write_message(RFX_CONTEXT* context, wStream* s, RFX_MESSAGE* message)
|
2011-08-25 13:25:10 +04:00
|
|
|
{
|
2013-08-14 18:14:47 +04:00
|
|
|
if (context->state == RFX_STATE_SEND_HEADERS)
|
2013-08-14 01:18:59 +04:00
|
|
|
{
|
2011-09-19 06:34:19 +04:00
|
|
|
rfx_compose_message_header(context, s);
|
2013-08-14 01:18:59 +04:00
|
|
|
context->state = RFX_STATE_SEND_FRAME_DATA;
|
|
|
|
}
|
|
|
|
|
2013-08-14 01:50:05 +04:00
|
|
|
rfx_write_message_frame_begin(context, s, message);
|
|
|
|
rfx_write_message_region(context, s, message);
|
2013-08-14 01:18:59 +04:00
|
|
|
rfx_write_message_tileset(context, s, message);
|
2013-08-14 01:50:05 +04:00
|
|
|
rfx_write_message_frame_end(context, s, message);
|
2013-08-14 18:14:47 +04:00
|
|
|
}
|
2013-08-14 01:18:59 +04:00
|
|
|
|
2013-08-14 18:14:47 +04:00
|
|
|
void rfx_compose_message(RFX_CONTEXT* context, wStream* s,
|
|
|
|
const RFX_RECT* rects, int numRects, BYTE* data, int width, int height, int scanline)
|
|
|
|
{
|
|
|
|
RFX_MESSAGE* message;
|
|
|
|
|
|
|
|
message = rfx_encode_message(context, rects, numRects, data, width, height, scanline);
|
|
|
|
|
|
|
|
rfx_write_message(context, s, message);
|
2011-08-25 13:25:10 +04:00
|
|
|
|
2013-08-14 01:18:59 +04:00
|
|
|
rfx_message_free(context, message);
|
2011-08-25 13:25:10 +04:00
|
|
|
}
|