FreeRDP/include/freerdp/codec/rfx.h

208 lines
5.4 KiB
C
Raw Normal View History

2011-08-10 11:13:39 +04:00
/**
2012-10-09 07:02:04 +04:00
* FreeRDP: A Remote Desktop Protocol Implementation
* RemoteFX Codec
2011-08-10 11:13:39 +04:00
*
* Copyright 2011 Vic Lee
* Copyright 2016 Armin Novak <armin.novak@thincast.com>
* Copyright 2016 Thincast Technologies GmbH
2011-08-10 11:13:39 +04:00
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
2012-12-14 09:25:48 +04:00
#ifndef FREERDP_CODEC_REMOTEFX_H
#define FREERDP_CODEC_REMOTEFX_H
2011-08-10 11:13:39 +04:00
typedef struct _RFX_RECT RFX_RECT;
typedef struct _RFX_TILE RFX_TILE;
typedef struct _RFX_MESSAGE RFX_MESSAGE;
typedef struct _RFX_CONTEXT RFX_CONTEXT;
#include <freerdp/api.h>
2011-08-10 11:13:39 +04:00
#include <freerdp/types.h>
#include <freerdp/freerdp.h>
2012-03-13 15:02:19 +04:00
#include <freerdp/constants.h>
#include <freerdp/codec/region.h>
#include <winpr/stream.h>
2011-08-10 11:13:39 +04:00
#ifdef __cplusplus
extern "C" {
#endif
enum _RLGR_MODE
{
RLGR1,
RLGR3
};
2014-09-25 22:15:57 +04:00
typedef enum _RLGR_MODE RLGR_MODE;
2011-08-10 11:13:39 +04:00
struct _RFX_RECT
{
UINT16 x;
UINT16 y;
UINT16 width;
UINT16 height;
2011-08-10 11:13:39 +04:00
};
struct _RFX_TILE
{
UINT16 x;
UINT16 y;
UINT32 width;
UINT32 height;
BYTE* data;
UINT32 scanline;
BOOL allocated;
BYTE quantIdxY;
BYTE quantIdxCb;
BYTE quantIdxCr;
UINT16 xIdx;
UINT16 yIdx;
UINT16 YLen;
UINT16 CbLen;
UINT16 CrLen;
BYTE* YData;
BYTE* CbData;
BYTE* CrData;
BYTE* YCbCrData;
2011-08-10 11:13:39 +04:00
};
struct _RFX_MESSAGE
{
UINT32 frameIdx;
2011-08-10 11:13:39 +04:00
/**
* The rects array represents the updated region of the frame. The UI
* requires to clip drawing destination base on the union of the rects.
*/
2013-08-14 01:18:59 +04:00
UINT16 numRects;
2011-08-10 11:13:39 +04:00
RFX_RECT* rects;
BOOL freeRects;
2011-08-10 11:13:39 +04:00
/**
* The tiles array represents the actual frame data. Each tile is always
* 64x64. Note that only pixels inside the updated region (represented as
* rects described above) are valid. Pixels outside of the region may
* contain arbitrary data.
*/
2013-08-14 01:18:59 +04:00
UINT16 numTiles;
2011-08-10 11:13:39 +04:00
RFX_TILE** tiles;
2013-08-14 01:18:59 +04:00
UINT16 numQuant;
UINT32* quantVals;
UINT32 tilesDataSize;
BOOL freeArray;
2011-08-10 11:13:39 +04:00
};
typedef struct _RFX_CONTEXT_PRIV RFX_CONTEXT_PRIV;
2013-08-14 01:18:59 +04:00
enum _RFX_STATE
{
RFX_STATE_INITIAL,
RFX_STATE_SERVER_UNINITIALIZED,
RFX_STATE_SEND_HEADERS,
RFX_STATE_SEND_FRAME_DATA,
RFX_STATE_FRAME_DATA_SENT,
RFX_STATE_FINAL
};
typedef enum _RFX_STATE RFX_STATE;
#define _RFX_DECODED_SYNC 0x00000001
#define _RFX_DECODED_CONTEXT 0x00000002
#define _RFX_DECODED_VERSIONS 0x00000004
#define _RFX_DECODED_CHANNELS 0x00000008
#define _RFX_DECODED_HEADERS 0x0000000F
2011-08-10 11:13:39 +04:00
struct _RFX_CONTEXT
{
2013-08-14 01:18:59 +04:00
RFX_STATE state;
BOOL encoder;
UINT16 flags;
UINT16 properties;
UINT16 width;
UINT16 height;
2011-08-10 11:13:39 +04:00
RLGR_MODE mode;
2012-10-09 11:26:39 +04:00
UINT32 version;
UINT32 codec_id;
UINT32 codec_version;
UINT32 pixel_format;
BYTE bits_per_pixel;
/* color palette allocated by the application */
const BYTE* palette;
2011-08-10 11:13:39 +04:00
/* temporary data within a frame */
2013-08-14 01:18:59 +04:00
UINT32 frameIdx;
BYTE numQuant;
2012-10-09 11:26:39 +04:00
UINT32* quants;
BYTE quantIdxY;
BYTE quantIdxCb;
BYTE quantIdxCr;
2011-08-10 11:13:39 +04:00
/* decoded header blocks */
UINT32 decodedHeaderBlocks;
2011-08-10 11:13:39 +04:00
/* routines */
2012-10-09 11:26:39 +04:00
void (*quantization_decode)(INT16* buffer, const UINT32* quantization_values);
void (*quantization_encode)(INT16* buffer, const UINT32* quantization_values);
void (*dwt_2d_decode)(INT16* buffer, INT16* dwt_buffer);
void (*dwt_2d_encode)(INT16* buffer, INT16* dwt_buffer);
int (*rlgr_decode)(RLGR_MODE mode, const BYTE* data, UINT32 data_size, INT16* buffer, UINT32 buffer_size);
int (*rlgr_encode)(RLGR_MODE mode, const INT16* data, UINT32 data_size, BYTE* buffer, UINT32 buffer_size);
2011-08-10 11:13:39 +04:00
/* private definitions */
RFX_CONTEXT_PRIV* priv;
};
FREERDP_API void rfx_context_set_pixel_format(RFX_CONTEXT* context,
2016-10-04 10:00:01 +03:00
UINT32 pixel_format);
2011-08-10 11:13:39 +04:00
FREERDP_API BOOL rfx_process_message(RFX_CONTEXT* context, const BYTE* data, UINT32 length,
2016-10-04 10:00:01 +03:00
UINT32 left, UINT32 top,
BYTE* dst, UINT32 dstFormat,
UINT32 dstStride, UINT32 dstHeight,
REGION16* invalidRegion);
FREERDP_API UINT16 rfx_message_get_tile_count(RFX_MESSAGE* message);
FREERDP_API UINT16 rfx_message_get_rect_count(RFX_MESSAGE* message);
FREERDP_API void rfx_message_free(RFX_CONTEXT* context, RFX_MESSAGE* message);
2011-08-10 11:13:39 +04:00
codec/rfx: error checking and various fixes - removed some unneeded null checks for free() - fixed a memory leak in shadow_client - removed rfx_compose_message_header from API Changed the following functions to BOOL, check the result where they are called and handle failures: - rfx_compose_message - rfx_compose_message_header - rfx_write_tile - rfx_write_message_tileset - rfx_write_message_frame_begin - rfx_write_message_region - rfx_write_message_frame_end - rfx_write_message rfx_process_message: - check memory allocation failures - verify protocol-conform order of data messages to prevents memory leaks caused by repeated allocations - verify that header messages were parsed/received before the data messages - treat unknown rlgr mode as error - fixed/added error handling - fixed all callers to check/handle result rfx_encode_message: - fixed incorrect usage of realloc - missing malloc check - missing check of CreateThreadpoolWork - correct cleanup on failure (threadpool, memory) - check rfx_encode_message result rfx_encode_messages: - check rfx_split_message result - correct cleanup on failure - prevent memory leak on failure rfx_write_message_context: - fixed invalid channelId value (must be 0xFF for WBT_CONTEXT) rfx_process_message_codec_versions: - fixed invalid read size of codec_version (it is 16bit) rfx_process_message_channels: - verify protocol conform channelId value rfx_process_message_region: - replaced invalid reallocs with malloc - read and verify regionType and numTileSets from stream rfx_process_message_tileset: - check allocation results - fixed incorrect usages of realloc setupWorkers: - fixed incorrect usages of realloc rfx_split_message: - removed dead code - missing malloc check rfx_compose_message: - fixed a memory leak - check/handle rfx_encode_message result
2015-04-23 16:42:21 +03:00
FREERDP_API BOOL rfx_compose_message(RFX_CONTEXT* context, wStream* s,
2016-10-04 10:00:01 +03:00
const RFX_RECT* rects, int num_rects, BYTE* image_data, int width, int height,
int rowstride);
FREERDP_API RFX_MESSAGE* rfx_encode_message(RFX_CONTEXT* context,
2016-10-04 10:00:01 +03:00
const RFX_RECT* rects,
int numRects, BYTE* data, int width, int height, int scanline);
FREERDP_API RFX_MESSAGE* rfx_encode_messages(RFX_CONTEXT* context,
2016-10-04 10:00:01 +03:00
const RFX_RECT* rects, int numRects,
BYTE* data, int width, int height, int scanline, int* numMessages,
int maxDataSize);
FREERDP_API BOOL rfx_write_message(RFX_CONTEXT* context, wStream* s,
2016-10-04 10:00:01 +03:00
RFX_MESSAGE* message);
FREERDP_API BOOL rfx_context_reset(RFX_CONTEXT* context, UINT32 width,
2016-10-04 10:00:01 +03:00
UINT32 height);
FREERDP_API RFX_CONTEXT* rfx_context_new(BOOL encoder);
FREERDP_API void rfx_context_free(RFX_CONTEXT* context);
2011-08-10 11:13:39 +04:00
#ifdef __cplusplus
}
#endif
2012-12-14 09:25:48 +04:00
#endif /* FREERDP_CODEC_REMOTEFX_H */