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
|
|
|
|
|
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>
|
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"
|
|
|
|
|
2011-08-13 12:26:57 +04:00
|
|
|
#include "rfx_sse2.h"
|
2011-08-10 11:13:39 +04:00
|
|
|
#include "rfx_neon.h"
|
|
|
|
|
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
2011-10-29 18:01:50 +04:00
|
|
|
RFX_CONTEXT* rfx_context_new(void)
|
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;
|
|
|
|
|
2012-11-22 05:21:08 +04:00
|
|
|
context = (RFX_CONTEXT*) malloc(sizeof(RFX_CONTEXT));
|
|
|
|
ZeroMemory(context, sizeof(RFX_CONTEXT));
|
|
|
|
|
|
|
|
context->priv = (RFX_CONTEXT_PRIV*) malloc(sizeof(RFX_CONTEXT_PRIV));
|
|
|
|
ZeroMemory(context->priv, sizeof(RFX_CONTEXT_PRIV));
|
|
|
|
|
2013-01-21 05:44:30 +04:00
|
|
|
context->priv->TilePool = Queue_New(TRUE, -1, -1);
|
|
|
|
context->priv->TileQueue = Queue_New(TRUE, -1, -1);
|
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)
|
|
|
|
*
|
|
|
|
* y_r_buffer, cb_g_buffer, cr_b_buffer: 64 * 64 * 4 = 16384 (0x4000)
|
|
|
|
* dwt_buffer: 32 * 32 * 2 * 2 * 4 = 16384, 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-01-23 06:24:04 +04:00
|
|
|
*/
|
|
|
|
|
2013-03-05 20:36:26 +04:00
|
|
|
context->priv->BufferPool = BufferPool_New(TRUE, 16384 + 32, 16);
|
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;
|
|
|
|
|
|
|
|
context->priv->UseThreads = isVistaOrLater;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
context->priv->UseThreads = TRUE;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
GetNativeSystemInfo(&sysinfo);
|
|
|
|
|
|
|
|
context->priv->MinThreadCount = sysinfo.dwNumberOfProcessors;
|
2013-01-23 06:54:13 +04:00
|
|
|
context->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)
|
|
|
|
{
|
|
|
|
if (RegQueryValueEx(hKey, _T("UseThreads"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS)
|
|
|
|
context->priv->UseThreads = dwValue ? 1 : 0;
|
|
|
|
|
|
|
|
if (RegQueryValueEx(hKey, _T("MinThreadCount"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS)
|
|
|
|
context->priv->MinThreadCount = dwValue;
|
|
|
|
|
|
|
|
if (RegQueryValueEx(hKey, _T("MaxThreadCount"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS)
|
|
|
|
context->priv->MaxThreadCount = dwValue;
|
|
|
|
|
|
|
|
RegCloseKey(hKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context->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();
|
|
|
|
|
2013-01-23 03:14:50 +04:00
|
|
|
context->priv->ThreadPool = CreateThreadpool(NULL);
|
|
|
|
InitializeThreadpoolEnvironment(&context->priv->ThreadPoolEnv);
|
|
|
|
SetThreadpoolCallbackPool(&context->priv->ThreadPoolEnv, context->priv->ThreadPool);
|
2013-01-23 06:54:13 +04:00
|
|
|
|
|
|
|
if (context->priv->MinThreadCount)
|
|
|
|
SetThreadpoolThreadMinimum(context->priv->ThreadPool, context->priv->MinThreadCount);
|
|
|
|
|
|
|
|
if (context->priv->MaxThreadCount)
|
|
|
|
SetThreadpoolThreadMaximum(context->priv->ThreadPool, context->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);
|
|
|
|
|
2011-10-29 18:01:50 +04:00
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
2011-08-10 11:13:39 +04:00
|
|
|
void rfx_context_free(RFX_CONTEXT* context)
|
|
|
|
{
|
2012-10-09 07:21:26 +04:00
|
|
|
free(context->quants);
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2013-01-21 05:44:30 +04:00
|
|
|
Queue_Free(context->priv->TilePool);
|
|
|
|
Queue_Free(context->priv->TileQueue);
|
2011-08-10 11:13:39 +04:00
|
|
|
|
|
|
|
rfx_profiler_print(context);
|
|
|
|
rfx_profiler_free(context);
|
|
|
|
|
2013-01-23 06:54:13 +04:00
|
|
|
if (context->priv->UseThreads)
|
2013-01-23 03:14:50 +04:00
|
|
|
{
|
|
|
|
CloseThreadpool(context->priv->ThreadPool);
|
|
|
|
DestroyThreadpoolEnvironment(&context->priv->ThreadPoolEnv);
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2012-10-09 10:31:28 +04:00
|
|
|
context->header_processed = FALSE;
|
2011-09-06 14:50:47 +04:00
|
|
|
context->frame_idx = 0;
|
|
|
|
}
|
|
|
|
|
2013-01-21 05:44:30 +04:00
|
|
|
RFX_TILE* rfx_tile_pool_take(RFX_CONTEXT* context)
|
|
|
|
{
|
|
|
|
RFX_TILE* tile = NULL;
|
|
|
|
|
|
|
|
if (WaitForSingleObject(Queue_Event(context->priv->TilePool), 0) == WAIT_OBJECT_0)
|
|
|
|
tile = Queue_Dequeue(context->priv->TilePool);
|
|
|
|
|
|
|
|
if (!tile)
|
|
|
|
{
|
|
|
|
tile = (RFX_TILE*) malloc(sizeof(RFX_TILE));
|
|
|
|
|
|
|
|
tile->x = tile->y = 0;
|
|
|
|
tile->data = (BYTE*) malloc(4096 * 4); /* 64x64 * 4 */
|
|
|
|
}
|
|
|
|
|
|
|
|
return tile;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rfx_tile_pool_return(RFX_CONTEXT* context, RFX_TILE* tile)
|
|
|
|
{
|
|
|
|
Queue_Enqueue(context->priv->TilePool, tile);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|
2012-10-09 11:26:39 +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
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +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
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG_RFX("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;
|
|
|
|
}
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_BYTE(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;
|
|
|
|
}
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 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 */
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_BYTE(s, context->codec_id); /* codecId (1 byte) */
|
|
|
|
stream_read_BYTE(s, context->codec_version); /* version (2 bytes) */
|
2011-08-10 11:13:39 +04:00
|
|
|
|
|
|
|
DEBUG_RFX("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;
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_BYTE(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;
|
|
|
|
}
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 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 */
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_BYTE(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
|
|
|
|
2011-08-10 11:13:39 +04:00
|
|
|
DEBUG_RFX("numChannels %d id %d, %dx%d.",
|
|
|
|
numChannels, channelId, context->width, context->height);
|
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;
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_BYTE(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
|
|
|
|
|
|
|
DEBUG_RFX("ctxId %d tileSize %d properties 0x%X.", ctxId, tileSize, properties);
|
|
|
|
|
|
|
|
context->properties = properties;
|
|
|
|
context->flags = (properties & 0x0007);
|
|
|
|
|
|
|
|
if (context->flags == CODEC_MODE)
|
|
|
|
DEBUG_RFX("codec is in image mode.");
|
|
|
|
else
|
|
|
|
DEBUG_RFX("codec is in video mode.");
|
|
|
|
|
|
|
|
switch ((properties & 0x1E00) >> 9)
|
|
|
|
{
|
|
|
|
case CLW_ENTROPY_RLGR1:
|
|
|
|
context->mode = RLGR1;
|
|
|
|
DEBUG_RFX("RLGR1.");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CLW_ENTROPY_RLGR3:
|
|
|
|
context->mode = RLGR3;
|
|
|
|
DEBUG_RFX("RLGR3.");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
DEBUG_WARN("unknown RLGR algorithm.");
|
|
|
|
break;
|
|
|
|
}
|
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;
|
|
|
|
}
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_read_UINT32(s, frameIdx); /* frameIdx (4 bytes), if codec is in video mode, must be ignored */
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_UINT16(s, numRegions); /* numRegions (2 bytes) */
|
2011-08-10 11:13:39 +04:00
|
|
|
|
|
|
|
DEBUG_RFX("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
|
|
|
{
|
|
|
|
DEBUG_RFX("RFX_FRAME_END");
|
|
|
|
}
|
|
|
|
|
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-04-30 06:35:15 +04:00
|
|
|
Stream_Seek_BYTE(s); /* regionFlags (1 byte) */
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_UINT16(s, message->num_rects); /* numRects (2 bytes) */
|
2011-08-10 11:13:39 +04:00
|
|
|
|
|
|
|
if (message->num_rects < 1)
|
|
|
|
{
|
|
|
|
DEBUG_WARN("no rects.");
|
2013-01-29 01:23:10 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 8 * message->num_rects)
|
2013-01-29 01:23:10 +04:00
|
|
|
{
|
|
|
|
DEBUG_WARN("RfxMessageRegion packet too small for num_rects=%d", message->num_rects);
|
|
|
|
return FALSE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (message->rects != NULL)
|
2012-10-09 07:21:26 +04:00
|
|
|
message->rects = (RFX_RECT*) realloc(message->rects, message->num_rects * sizeof(RFX_RECT));
|
2011-08-10 11:13:39 +04:00
|
|
|
else
|
2012-10-09 07:21:26 +04:00
|
|
|
message->rects = (RFX_RECT*) malloc(message->num_rects * sizeof(RFX_RECT));
|
2011-08-10 11:13:39 +04:00
|
|
|
|
|
|
|
/* rects */
|
|
|
|
for (i = 0; i < message->num_rects; i++)
|
|
|
|
{
|
|
|
|
/* RFX_RECT */
|
2012-10-09 11:01:37 +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
|
|
|
|
|
|
|
DEBUG_RFX("rect %d (%d %d %d %d).",
|
|
|
|
i, message->rects[i].x, message->rects[i].y, message->rects[i].width, message->rects[i].height);
|
|
|
|
}
|
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_tile(RFX_CONTEXT* context, RFX_TILE* tile, wStream* s)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE quantIdxY;
|
|
|
|
BYTE quantIdxCb;
|
|
|
|
BYTE quantIdxCr;
|
|
|
|
UINT16 xIdx, yIdx;
|
|
|
|
UINT16 YLen, CbLen, CrLen;
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 13)
|
2013-01-29 01:23:10 +04:00
|
|
|
{
|
|
|
|
DEBUG_WARN("RfxMessageTile packet too small");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-08-10 11:13:39 +04:00
|
|
|
/* RFX_TILE */
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_BYTE(s, quantIdxY); /* quantIdxY (1 byte) */
|
|
|
|
stream_read_BYTE(s, quantIdxCb); /* quantIdxCb (1 byte) */
|
|
|
|
stream_read_BYTE(s, quantIdxCr); /* quantIdxCr (1 byte) */
|
|
|
|
stream_read_UINT16(s, xIdx); /* xIdx (2 bytes) */
|
|
|
|
stream_read_UINT16(s, yIdx); /* yIdx (2 bytes) */
|
|
|
|
stream_read_UINT16(s, YLen); /* YLen (2 bytes) */
|
|
|
|
stream_read_UINT16(s, CbLen); /* CbLen (2 bytes) */
|
|
|
|
stream_read_UINT16(s, CrLen); /* CrLen (2 bytes) */
|
2011-08-10 11:13:39 +04:00
|
|
|
|
|
|
|
DEBUG_RFX("quantIdxY:%d quantIdxCb:%d quantIdxCr:%d xIdx:%d yIdx:%d YLen:%d CbLen:%d CrLen:%d",
|
|
|
|
quantIdxY, quantIdxCb, quantIdxCr, xIdx, yIdx, YLen, CbLen, CrLen);
|
|
|
|
|
|
|
|
tile->x = xIdx * 64;
|
|
|
|
tile->y = yIdx * 64;
|
|
|
|
|
2013-01-29 01:23:10 +04:00
|
|
|
return rfx_decode_rgb(context, s,
|
2011-08-10 11:13:39 +04:00
|
|
|
YLen, context->quants + (quantIdxY * 10),
|
|
|
|
CbLen, context->quants + (quantIdxCb * 10),
|
|
|
|
CrLen, context->quants + (quantIdxCr * 10),
|
2013-01-23 06:24:04 +04:00
|
|
|
tile->data, 64 * 4);
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-01-23 03:14:50 +04:00
|
|
|
struct _RFX_TILE_WORK_PARAM
|
|
|
|
{
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream s;
|
2013-01-23 03:14:50 +04:00
|
|
|
RFX_TILE* tile;
|
|
|
|
RFX_CONTEXT* context;
|
|
|
|
};
|
|
|
|
typedef struct _RFX_TILE_WORK_PARAM RFX_TILE_WORK_PARAM;
|
|
|
|
|
|
|
|
void CALLBACK rfx_process_message_tile_work_callback(PTP_CALLBACK_INSTANCE instance, void* context, PTP_WORK work)
|
|
|
|
{
|
|
|
|
RFX_TILE_WORK_PARAM* param = (RFX_TILE_WORK_PARAM*) context;
|
|
|
|
rfx_process_message_tile(param->context, param->tile, &(param->s));
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
int i;
|
2013-01-23 03:14:50 +04:00
|
|
|
int pos;
|
|
|
|
BYTE quant;
|
|
|
|
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;
|
|
|
|
RFX_TILE_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;
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +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
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_BYTE(s, context->num_quants); /* numQuant (1 byte) */
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek_BYTE(s); /* tileSize (1 byte), must be set to 0x40 */
|
2011-08-10 11:13:39 +04:00
|
|
|
|
|
|
|
if (context->num_quants < 1)
|
|
|
|
{
|
|
|
|
DEBUG_WARN("no quantization value.");
|
2013-01-29 01:23:10 +04:00
|
|
|
return TRUE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_UINT16(s, message->num_tiles); /* numTiles (2 bytes) */
|
2011-08-10 11:13:39 +04:00
|
|
|
|
|
|
|
if (message->num_tiles < 1)
|
|
|
|
{
|
|
|
|
DEBUG_WARN("no tiles.");
|
2013-01-29 01:23:10 +04:00
|
|
|
return TRUE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_read_UINT32(s, tilesDataSize); /* tilesDataSize (4 bytes) */
|
2011-08-10 11:13:39 +04:00
|
|
|
|
|
|
|
if (context->quants != NULL)
|
2012-10-09 11:26:39 +04:00
|
|
|
context->quants = (UINT32*) realloc((void*) context->quants, context->num_quants * 10 * sizeof(UINT32));
|
2011-08-10 11:13:39 +04:00
|
|
|
else
|
2012-10-09 11:26:39 +04:00
|
|
|
context->quants = (UINT32*) malloc(context->num_quants * 10 * sizeof(UINT32));
|
2011-08-10 11:13:39 +04:00
|
|
|
quants = context->quants;
|
|
|
|
|
|
|
|
/* quantVals */
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < context->num_quants * 5)
|
2013-01-29 01:23:10 +04:00
|
|
|
{
|
|
|
|
DEBUG_WARN("RfxMessageTileSet packet too small for num_quants=%d", context->num_quants);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-08-10 11:13:39 +04:00
|
|
|
for (i = 0; i < context->num_quants; i++)
|
|
|
|
{
|
|
|
|
/* RFX_CODEC_QUANT */
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_BYTE(s, quant);
|
2011-08-10 11:13:39 +04:00
|
|
|
*quants++ = (quant & 0x0F);
|
|
|
|
*quants++ = (quant >> 4);
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_BYTE(s, quant);
|
2011-08-10 11:13:39 +04:00
|
|
|
*quants++ = (quant & 0x0F);
|
|
|
|
*quants++ = (quant >> 4);
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_BYTE(s, quant);
|
2011-08-10 11:13:39 +04:00
|
|
|
*quants++ = (quant & 0x0F);
|
|
|
|
*quants++ = (quant >> 4);
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_BYTE(s, quant);
|
2011-08-10 11:13:39 +04:00
|
|
|
*quants++ = (quant & 0x0F);
|
|
|
|
*quants++ = (quant >> 4);
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_BYTE(s, quant);
|
2011-08-10 11:13:39 +04:00
|
|
|
*quants++ = (quant & 0x0F);
|
|
|
|
*quants++ = (quant >> 4);
|
|
|
|
|
|
|
|
DEBUG_RFX("quant %d (%d %d %d %d %d %d %d %d %d %d).",
|
|
|
|
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-01-21 05:44:30 +04:00
|
|
|
message->tiles = (RFX_TILE**) malloc(sizeof(RFX_TILE*) * message->num_tiles);
|
|
|
|
ZeroMemory(message->tiles, sizeof(RFX_TILE*) * message->num_tiles);
|
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
|
|
|
{
|
|
|
|
work_objects = (PTP_WORK*) malloc(sizeof(PTP_WORK) * message->num_tiles);
|
|
|
|
params = (RFX_TILE_WORK_PARAM*) malloc(sizeof(RFX_TILE_WORK_PARAM) * message->num_tiles);
|
|
|
|
}
|
|
|
|
|
2011-08-10 11:13:39 +04:00
|
|
|
/* tiles */
|
|
|
|
for (i = 0; i < message->num_tiles; i++)
|
|
|
|
{
|
|
|
|
/* RFX_TILE */
|
2013-04-30 06:35:15 +04:00
|
|
|
if (Stream_GetRemainingLength(s) < 6)
|
2013-01-29 01:23:10 +04:00
|
|
|
{
|
|
|
|
DEBUG_WARN("RfxMessageTileSet packet too small to read tile %d/%d", i, message->num_tiles);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_UINT16(s, blockType); /* blockType (2 bytes), must be set to CBT_TILE (0xCAC3) */
|
2012-10-09 11:26:39 +04:00
|
|
|
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
|
|
|
{
|
|
|
|
DEBUG_WARN("RfxMessageTileSet not enough bytes to read tile %d/%d with blocklen=%d", i, message->num_tiles, blockLen);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
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-01-21 05:44:30 +04:00
|
|
|
message->tiles[i] = rfx_tile_pool_take(context);
|
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
|
|
|
{
|
|
|
|
params[i].context = context;
|
|
|
|
params[i].tile = message->tiles[i];
|
2013-03-21 23:19:33 +04:00
|
|
|
CopyMemory(&(params[i].s), s, sizeof(wStream));
|
2013-01-23 03:14:50 +04:00
|
|
|
|
|
|
|
work_objects[i] = CreateThreadpoolWork((PTP_WORK_CALLBACK) rfx_process_message_tile_work_callback,
|
|
|
|
(void*) ¶ms[i], &context->priv->ThreadPoolEnv);
|
|
|
|
|
|
|
|
SubmitThreadpoolWork(work_objects[i]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rfx_process_message_tile(context, message->tiles[i], s);
|
|
|
|
}
|
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
|
|
|
{
|
|
|
|
for (i = 0; i < message->num_tiles; i++)
|
|
|
|
WaitForThreadpoolWorkCallbacks(work_objects[i], FALSE);
|
|
|
|
|
|
|
|
free(work_objects);
|
|
|
|
free(params);
|
|
|
|
}
|
2013-01-29 01:23:10 +04:00
|
|
|
return TRUE;
|
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));
|
|
|
|
|
2011-09-19 06:34:19 +04:00
|
|
|
s = stream_new(0);
|
|
|
|
stream_attach(s, 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 */
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_UINT16(s, blockType); /* blockType (2 bytes) */
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_read_UINT32(s, blockLen); /* blockLen (4 bytes) */
|
2011-08-10 11:13:39 +04:00
|
|
|
|
|
|
|
DEBUG_RFX("blockType 0x%X blockLen %d", blockType, blockLen);
|
|
|
|
|
|
|
|
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-01-29 01:23:10 +04:00
|
|
|
if (!stream_skip(s, 2))
|
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-09-19 06:47:30 +04:00
|
|
|
stream_detach(s);
|
|
|
|
stream_free(s);
|
|
|
|
|
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
|
|
|
{
|
|
|
|
return message->num_tiles;
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
return message->num_rects;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2011-08-10 11:13:39 +04:00
|
|
|
if (message != NULL)
|
|
|
|
{
|
2012-10-09 07:21:26 +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-01-21 05:44:30 +04:00
|
|
|
for (i = 0; i < message->num_tiles; i++)
|
|
|
|
rfx_tile_pool_return(context, message->tiles[i]);
|
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(message->tiles);
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(message);
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static void rfx_compose_message_sync(RFX_CONTEXT* context, wStream* s)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, WBT_SYNC); /* BlockT.blockType */
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_write_UINT32(s, 12); /* BlockT.blockLen */
|
|
|
|
stream_write_UINT32(s, WF_MAGIC); /* magic */
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, WF_VERSION_1_0); /* version */
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static void rfx_compose_message_codec_versions(RFX_CONTEXT* context, wStream* s)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, WBT_CODEC_VERSIONS); /* BlockT.blockType */
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_write_UINT32(s, 10); /* BlockT.blockLen */
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_BYTE(s, 1); /* numCodecs */
|
|
|
|
stream_write_BYTE(s, 1); /* codecs.codecId */
|
|
|
|
stream_write_UINT16(s, WF_VERSION_1_0); /* codecs.version */
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static void rfx_compose_message_channels(RFX_CONTEXT* context, wStream* s)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, WBT_CHANNELS); /* BlockT.blockType */
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_write_UINT32(s, 12); /* BlockT.blockLen */
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_BYTE(s, 1); /* numChannels */
|
|
|
|
stream_write_BYTE(s, 0); /* Channel.channelId */
|
|
|
|
stream_write_UINT16(s, context->width); /* Channel.width */
|
|
|
|
stream_write_UINT16(s, context->height); /* Channel.height */
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static void rfx_compose_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
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, WBT_CONTEXT); /* CodecChannelT.blockType */
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_write_UINT32(s, 13); /* CodecChannelT.blockLen */
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_BYTE(s, 1); /* CodecChannelT.codecId */
|
|
|
|
stream_write_BYTE(s, 0); /* CodecChannelT.channelId */
|
|
|
|
stream_write_BYTE(s, 0); /* ctxId */
|
|
|
|
stream_write_UINT16(s, CT_TILE_64x64); /* tileSize */
|
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 */
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, properties);
|
2011-08-24 11:18:14 +04:00
|
|
|
|
|
|
|
/* 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 */
|
2011-08-10 11:13:39 +04:00
|
|
|
context->properties = properties;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2011-09-19 06:34:19 +04:00
|
|
|
rfx_compose_message_sync(context, s);
|
|
|
|
rfx_compose_message_context(context, s);
|
|
|
|
rfx_compose_message_codec_versions(context, s);
|
|
|
|
rfx_compose_message_channels(context, s);
|
2011-09-02 05:47:46 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
context->header_processed = TRUE;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static void rfx_compose_message_frame_begin(RFX_CONTEXT* context, wStream* s)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2013-05-02 02:15:55 +04:00
|
|
|
Stream_EnsureRemainingCapacity(s, 14);
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, WBT_FRAME_BEGIN); /* CodecChannelT.blockType */
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_write_UINT32(s, 14); /* CodecChannelT.blockLen */
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_BYTE(s, 1); /* CodecChannelT.codecId */
|
|
|
|
stream_write_BYTE(s, 0); /* CodecChannelT.channelId */
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_write_UINT32(s, context->frame_idx); /* frameIdx */
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, 1); /* numRegions */
|
2011-08-25 12:52:49 +04:00
|
|
|
|
|
|
|
context->frame_idx++;
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static void rfx_compose_message_region(RFX_CONTEXT* context, wStream* s,
|
2011-08-10 11:13:39 +04:00
|
|
|
const RFX_RECT* rects, int num_rects)
|
|
|
|
{
|
|
|
|
int size;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
size = 15 + num_rects * 8;
|
2013-05-02 02:15:55 +04:00
|
|
|
Stream_EnsureRemainingCapacity(s, size);
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, WBT_REGION); /* CodecChannelT.blockType */
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_write_UINT32(s, size); /* set CodecChannelT.blockLen later */
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_BYTE(s, 1); /* CodecChannelT.codecId */
|
|
|
|
stream_write_BYTE(s, 0); /* CodecChannelT.channelId */
|
|
|
|
stream_write_BYTE(s, 1); /* regionFlags */
|
|
|
|
stream_write_UINT16(s, num_rects); /* numRects */
|
2011-08-10 11:13:39 +04:00
|
|
|
|
|
|
|
for (i = 0; i < num_rects; i++)
|
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, rects[i].x);
|
|
|
|
stream_write_UINT16(s, rects[i].y);
|
|
|
|
stream_write_UINT16(s, rects[i].width);
|
|
|
|
stream_write_UINT16(s, rects[i].height);
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, CBT_REGION); /* regionType */
|
|
|
|
stream_write_UINT16(s, 1); /* numTilesets */
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static void rfx_compose_message_tile(RFX_CONTEXT* context, wStream* s,
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* tile_data, int tile_width, int tile_height, int rowstride,
|
2012-10-09 11:26:39 +04:00
|
|
|
const UINT32* quantVals, int quantIdxY, int quantIdxCb, int quantIdxCr,
|
2011-08-10 11:13:39 +04:00
|
|
|
int xIdx, int yIdx)
|
|
|
|
{
|
|
|
|
int YLen = 0;
|
|
|
|
int CbLen = 0;
|
|
|
|
int CrLen = 0;
|
|
|
|
int start_pos, end_pos;
|
|
|
|
|
2013-05-02 02:15:55 +04:00
|
|
|
Stream_EnsureRemainingCapacity(s, 19);
|
2013-04-30 06:35:15 +04:00
|
|
|
start_pos = Stream_GetPosition(s);
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, CBT_TILE); /* BlockT.blockType */
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek_UINT32(s); /* set BlockT.blockLen later */
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_BYTE(s, quantIdxY);
|
|
|
|
stream_write_BYTE(s, quantIdxCb);
|
|
|
|
stream_write_BYTE(s, quantIdxCr);
|
|
|
|
stream_write_UINT16(s, xIdx);
|
|
|
|
stream_write_UINT16(s, yIdx);
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek(s, 6); /* YLen, CbLen, CrLen */
|
2011-08-10 11:13:39 +04:00
|
|
|
|
|
|
|
rfx_encode_rgb(context, tile_data, tile_width, tile_height, rowstride,
|
|
|
|
quantVals + quantIdxY * 10, quantVals + quantIdxCb * 10, quantVals + quantIdxCr * 10,
|
2011-09-19 06:34:19 +04:00
|
|
|
s, &YLen, &CbLen, &CrLen);
|
2011-08-10 11:13:39 +04:00
|
|
|
|
|
|
|
DEBUG_RFX("xIdx=%d yIdx=%d width=%d height=%d YLen=%d CbLen=%d CrLen=%d",
|
|
|
|
xIdx, yIdx, tile_width, tile_height, YLen, CbLen, CrLen);
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
end_pos = Stream_GetPosition(s);
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(s, start_pos + 2);
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_write_UINT32(s, 19 + YLen + CbLen + CrLen); /* BlockT.blockLen */
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(s, start_pos + 13);
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, YLen);
|
|
|
|
stream_write_UINT16(s, CbLen);
|
|
|
|
stream_write_UINT16(s, CrLen);
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(s, end_pos);
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static void rfx_compose_message_tileset(RFX_CONTEXT* context, wStream* s,
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* image_data, int width, int height, int rowstride)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2013-01-21 05:44:30 +04:00
|
|
|
int i;
|
2011-08-10 11:13:39 +04:00
|
|
|
int size;
|
|
|
|
int start_pos, end_pos;
|
|
|
|
int numQuants;
|
2012-10-09 11:26:39 +04:00
|
|
|
const UINT32* quantVals;
|
|
|
|
const UINT32* quantValsPtr;
|
2011-08-10 11:13:39 +04:00
|
|
|
int quantIdxY;
|
|
|
|
int quantIdxCb;
|
|
|
|
int quantIdxCr;
|
|
|
|
int numTiles;
|
|
|
|
int numTilesX;
|
|
|
|
int numTilesY;
|
|
|
|
int xIdx;
|
|
|
|
int yIdx;
|
|
|
|
int tilesDataSize;
|
|
|
|
|
|
|
|
if (context->num_quants == 0)
|
|
|
|
{
|
|
|
|
numQuants = 1;
|
|
|
|
quantVals = rfx_default_quantization_values;
|
|
|
|
quantIdxY = 0;
|
|
|
|
quantIdxCb = 0;
|
|
|
|
quantIdxCr = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
numQuants = context->num_quants;
|
|
|
|
quantVals = context->quants;
|
|
|
|
quantIdxY = context->quant_idx_y;
|
|
|
|
quantIdxCb = context->quant_idx_cb;
|
|
|
|
quantIdxCr = context->quant_idx_cr;
|
|
|
|
}
|
|
|
|
|
|
|
|
numTilesX = (width + 63) / 64;
|
|
|
|
numTilesY = (height + 63) / 64;
|
|
|
|
numTiles = numTilesX * numTilesY;
|
|
|
|
|
|
|
|
size = 22 + numQuants * 5;
|
2013-05-02 02:15:55 +04:00
|
|
|
Stream_EnsureRemainingCapacity(s, size);
|
2013-04-30 06:35:15 +04:00
|
|
|
start_pos = Stream_GetPosition(s);
|
2011-09-19 06:34:19 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, WBT_EXTENSION); /* CodecChannelT.blockType */
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek_UINT32(s); /* set CodecChannelT.blockLen later */
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_BYTE(s, 1); /* CodecChannelT.codecId */
|
|
|
|
stream_write_BYTE(s, 0); /* CodecChannelT.channelId */
|
|
|
|
stream_write_UINT16(s, CBT_TILESET); /* subtype */
|
|
|
|
stream_write_UINT16(s, 0); /* idx */
|
|
|
|
stream_write_UINT16(s, context->properties); /* properties */
|
|
|
|
stream_write_BYTE(s, numQuants); /* numQuants */
|
|
|
|
stream_write_BYTE(s, 0x40); /* tileSize */
|
|
|
|
stream_write_UINT16(s, numTiles); /* numTiles */
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek_UINT32(s); /* set tilesDataSize later */
|
2011-08-10 11:13:39 +04:00
|
|
|
|
|
|
|
quantValsPtr = quantVals;
|
|
|
|
for (i = 0; i < numQuants * 5; i++)
|
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_BYTE(s, quantValsPtr[0] + (quantValsPtr[1] << 4));
|
2011-08-10 11:13:39 +04:00
|
|
|
quantValsPtr += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG_RFX("width:%d height:%d rowstride:%d", width, height, rowstride);
|
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
end_pos = Stream_GetPosition(s);
|
2011-08-10 11:13:39 +04:00
|
|
|
for (yIdx = 0; yIdx < numTilesY; yIdx++)
|
|
|
|
{
|
|
|
|
for (xIdx = 0; xIdx < numTilesX; xIdx++)
|
|
|
|
{
|
2011-09-19 06:34:19 +04:00
|
|
|
rfx_compose_message_tile(context, s,
|
2011-09-14 21:48:08 +04:00
|
|
|
image_data + yIdx * 64 * rowstride + xIdx * 8 * context->bits_per_pixel,
|
2012-02-05 03:18:46 +04:00
|
|
|
(xIdx < numTilesX - 1) ? 64 : width - xIdx * 64,
|
|
|
|
(yIdx < numTilesY - 1) ? 64 : height - yIdx * 64,
|
2011-08-10 11:13:39 +04:00
|
|
|
rowstride, quantVals, quantIdxY, quantIdxCb, quantIdxCr, xIdx, yIdx);
|
|
|
|
}
|
|
|
|
}
|
2013-04-30 06:35:15 +04:00
|
|
|
tilesDataSize = Stream_GetPosition(s) - end_pos;
|
2011-08-10 11:13:39 +04:00
|
|
|
size += tilesDataSize;
|
2013-04-30 06:35:15 +04:00
|
|
|
end_pos = Stream_GetPosition(s);
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(s, start_pos + 2);
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_write_UINT32(s, size); /* CodecChannelT.blockLen */
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(s, start_pos + 18);
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_write_UINT32(s, tilesDataSize);
|
2011-08-10 11:13:39 +04:00
|
|
|
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_SetPosition(s, end_pos);
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static void rfx_compose_message_frame_end(RFX_CONTEXT* context, wStream* s)
|
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
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(s, WBT_FRAME_END); /* CodecChannelT.blockType */
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_write_UINT32(s, 8); /* CodecChannelT.blockLen */
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_BYTE(s, 1); /* CodecChannelT.codecId */
|
|
|
|
stream_write_BYTE(s, 0); /* CodecChannelT.channelId */
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static void rfx_compose_message_data(RFX_CONTEXT* context, wStream* s,
|
2012-10-09 11:01:37 +04:00
|
|
|
const RFX_RECT* rects, int num_rects, BYTE* image_data, int width, int height, int rowstride)
|
2011-08-10 11:13:39 +04:00
|
|
|
{
|
2011-09-19 06:34:19 +04:00
|
|
|
rfx_compose_message_frame_begin(context, s);
|
|
|
|
rfx_compose_message_region(context, s, rects, num_rects);
|
|
|
|
rfx_compose_message_tileset(context, s, image_data, width, height, rowstride);
|
|
|
|
rfx_compose_message_frame_end(context, s);
|
2011-08-10 11:13:39 +04:00
|
|
|
}
|
2011-08-25 13:25:10 +04:00
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
FREERDP_API void rfx_compose_message(RFX_CONTEXT* context, wStream* s,
|
2012-10-09 11:01:37 +04:00
|
|
|
const RFX_RECT* rects, int num_rects, BYTE* image_data, int width, int height, int rowstride)
|
2011-08-25 13:25:10 +04:00
|
|
|
{
|
|
|
|
/* Only the first frame should send the RemoteFX header */
|
2011-09-02 05:47:46 +04:00
|
|
|
if (context->frame_idx == 0 && !context->header_processed)
|
2011-09-19 06:34:19 +04:00
|
|
|
rfx_compose_message_header(context, s);
|
2011-08-25 13:25:10 +04:00
|
|
|
|
2011-09-19 06:34:19 +04:00
|
|
|
rfx_compose_message_data(context, s, rects, num_rects, image_data, width, height, rowstride);
|
2011-08-25 13:25:10 +04:00
|
|
|
}
|
|
|
|
|