From 3e4dc732805498d07c422f50afb7819a0e1da131 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= Date: Tue, 13 Aug 2013 10:09:32 -0400 Subject: [PATCH] libfreerdp-codec: split stream parsing from tile decoding --- include/freerdp/codec/rfx.h | 12 +++++ libfreerdp/codec/rfx.c | 65 +++++++++----------------- libfreerdp/codec/rfx_decode.c | 87 ++++------------------------------- libfreerdp/codec/rfx_decode.h | 6 +-- 4 files changed, 45 insertions(+), 125 deletions(-) diff --git a/include/freerdp/codec/rfx.h b/include/freerdp/codec/rfx.h index 7e47616d0..22517e793 100644 --- a/include/freerdp/codec/rfx.h +++ b/include/freerdp/codec/rfx.h @@ -52,6 +52,18 @@ struct _RFX_TILE UINT16 x; UINT16 y; BYTE* data; + + BYTE quantIdxY; + BYTE quantIdxCb; + BYTE quantIdxCr; + UINT16 xIdx; + UINT16 yIdx; + UINT16 YLen; + UINT16 CbLen; + UINT16 CrLen; + BYTE* YData; + BYTE* CbData; + BYTE* CrData; }; typedef struct _RFX_TILE RFX_TILE; diff --git a/libfreerdp/codec/rfx.c b/libfreerdp/codec/rfx.c index 9ed0d8dbe..9706aca2e 100644 --- a/libfreerdp/codec/rfx.c +++ b/libfreerdp/codec/rfx.c @@ -561,46 +561,8 @@ static BOOL rfx_process_message_region(RFX_CONTEXT* context, RFX_MESSAGE* messag return TRUE; } -static BOOL rfx_process_message_tile(RFX_CONTEXT* context, RFX_TILE* tile, wStream* s) -{ - BYTE quantIdxY; - BYTE quantIdxCb; - BYTE quantIdxCr; - UINT16 xIdx, yIdx; - UINT16 YLen, CbLen, CrLen; - - if (Stream_GetRemainingLength(s) < 13) - { - DEBUG_WARN("RfxMessageTile packet too small"); - return FALSE; - } - - /* RFX_TILE */ - Stream_Read_UINT8(s, quantIdxY); /* quantIdxY (1 byte) */ - Stream_Read_UINT8(s, quantIdxCb); /* quantIdxCb (1 byte) */ - Stream_Read_UINT8(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) */ - - 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; - - return rfx_decode_rgb(context, s, - YLen, context->quants + (quantIdxY * 10), - CbLen, context->quants + (quantIdxCb * 10), - CrLen, context->quants + (quantIdxCr * 10), - tile->data, 64 * 4); -} - struct _RFX_TILE_PROCESS_WORK_PARAM { - wStream s; RFX_TILE* tile; RFX_CONTEXT* context; }; @@ -609,7 +571,7 @@ typedef struct _RFX_TILE_PROCESS_WORK_PARAM RFX_TILE_PROCESS_WORK_PARAM; void CALLBACK rfx_process_message_tile_work_callback(PTP_CALLBACK_INSTANCE instance, void* context, PTP_WORK work) { RFX_TILE_PROCESS_WORK_PARAM* param = (RFX_TILE_PROCESS_WORK_PARAM*) context; - rfx_process_message_tile(param->context, param->tile, &(param->s)); + rfx_decode_rgb(param->context, param->tile, param->tile->data, 64 * 4); } static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* message, wStream* s) @@ -617,6 +579,7 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* messa int i; int pos; BYTE quant; + RFX_TILE* tile; UINT32* quants; UINT16 subtype; UINT32 blockLen; @@ -713,6 +676,8 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* messa /* tiles */ for (i = 0; i < message->num_tiles; i++) { + tile = message->tiles[i] = (RFX_TILE*) ObjectPool_Take(context->priv->TilePool); + /* RFX_TILE */ if (Stream_GetRemainingLength(s) < 6) { @@ -737,13 +702,29 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* messa break; } - message->tiles[i] = (RFX_TILE*) ObjectPool_Take(context->priv->TilePool); + 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; if (context->priv->UseThreads) { params[i].context = context; params[i].tile = message->tiles[i]; - CopyMemory(&(params[i].s), s, sizeof(wStream)); work_objects[i] = CreateThreadpoolWork((PTP_WORK_CALLBACK) rfx_process_message_tile_work_callback, (void*) ¶ms[i], &context->priv->ThreadPoolEnv); @@ -752,7 +733,7 @@ static BOOL rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* messa } else { - rfx_process_message_tile(context, message->tiles[i], s); + rfx_decode_rgb(context, tile, tile->data, 64 * 4); } Stream_SetPosition(s, pos); diff --git a/libfreerdp/codec/rfx_decode.c b/libfreerdp/codec/rfx_decode.c index ff6161590..2a642f9da 100644 --- a/libfreerdp/codec/rfx_decode.c +++ b/libfreerdp/codec/rfx_decode.c @@ -125,98 +125,29 @@ static void rfx_decode_component(RFX_CONTEXT* context, const UINT32* quantizatio /* rfx_decode_ycbcr_to_rgb code now resides in the primitives library. */ -struct _RFX_COMPONENT_WORK_PARAM -{ - int size; - INT16* buffer; - const BYTE* data; - RFX_CONTEXT* context; - const UINT32* quantization_values; -}; -typedef struct _RFX_COMPONENT_WORK_PARAM RFX_COMPONENT_WORK_PARAM; - -void CALLBACK rfx_decode_component_work_callback(PTP_CALLBACK_INSTANCE instance, void* context, PTP_WORK work) -{ - RFX_COMPONENT_WORK_PARAM* param = (RFX_COMPONENT_WORK_PARAM*) context; - rfx_decode_component(param->context, param->quantization_values, param->data, param->size, param->buffer); -} - /* stride is bytes between rows in the output buffer. */ -BOOL rfx_decode_rgb(RFX_CONTEXT* context, wStream* data_in, - int y_size, const UINT32* y_quants, - int cb_size, const UINT32* cb_quants, - int cr_size, const UINT32* cr_quants, BYTE* rgb_buffer, int stride) +BOOL rfx_decode_rgb(RFX_CONTEXT* context, RFX_TILE* tile, BYTE* rgb_buffer, int stride) { INT16* pSrcDst[3]; + UINT32 *y_quants, *cb_quants, *cr_quants; static const prim_size_t roi_64x64 = { 64, 64 }; const primitives_t *prims = primitives_get(); PROFILER_ENTER(context->priv->prof_rfx_decode_rgb); + y_quants = context->quants + (tile->quantIdxY * 10); + cb_quants = context->quants + (tile->quantIdxCb * 10); + cr_quants = context->quants + (tile->quantIdxCr * 10); + pSrcDst[0] = (INT16*)((BYTE*)BufferPool_Take(context->priv->BufferPool, -1) + 16); /* y_r_buffer */ pSrcDst[1] = (INT16*)((BYTE*)BufferPool_Take(context->priv->BufferPool, -1) + 16); /* cb_g_buffer */ pSrcDst[2] = (INT16*)((BYTE*)BufferPool_Take(context->priv->BufferPool, -1) + 16); /* cr_b_buffer */ -#if 0 - if (context->priv->UseThreads) - { - PTP_WORK work_objects[3]; - RFX_COMPONENT_WORK_PARAM params[3]; + rfx_decode_component(context, y_quants, tile->YData, tile->YLen, pSrcDst[0]); /* YData */ - params[0].context = context; - params[0].quantization_values = y_quants; - params[0].buffer = Stream_Pointer(data_in); - params[0].capacity = y_size; - params[0].buffer = pSrcDst[0]; - Stream_Seek(data_in, y_size); + rfx_decode_component(context, cb_quants, tile->CbData, tile->CbLen, pSrcDst[1]); /* CbData */ - params[1].context = context; - params[1].quantization_values = cb_quants; - params[1].buffer = Stream_Pointer(data_in); - params[1].capacity = cb_size; - params[1].buffer = pSrcDst[1]; - Stream_Seek(data_in, cb_size); - - params[2].context = context; - params[2].quantization_values = cr_quants; - params[2].buffer = Stream_Pointer(data_in); - params[2].capacity = cr_size; - params[2].buffer = pSrcDst[2]; - Stream_Seek(data_in, cr_size); - - work_objects[0] = CreateThreadpoolWork((PTP_WORK_CALLBACK) rfx_decode_component_work_callback, - (void*) ¶ms[0], &context->priv->ThreadPoolEnv); - work_objects[1] = CreateThreadpoolWork((PTP_WORK_CALLBACK) rfx_decode_component_work_callback, - (void*) ¶ms[1], &context->priv->ThreadPoolEnv); - work_objects[2] = CreateThreadpoolWork((PTP_WORK_CALLBACK) rfx_decode_component_work_callback, - (void*) ¶ms[2], &context->priv->ThreadPoolEnv); - - SubmitThreadpoolWork(work_objects[0]); - SubmitThreadpoolWork(work_objects[1]); - SubmitThreadpoolWork(work_objects[2]); - - WaitForThreadpoolWorkCallbacks(work_objects[0], FALSE); - WaitForThreadpoolWorkCallbacks(work_objects[1], FALSE); - WaitForThreadpoolWorkCallbacks(work_objects[2], FALSE); - } - else -#endif - { - if (Stream_GetRemainingLength(data_in) < y_size + cb_size + cr_size) - { - DEBUG_WARN("rfx_decode_rgb: packet too small for y_size+cb_size+cr_size"); - return FALSE; - } - - rfx_decode_component(context, y_quants, Stream_Pointer(data_in), y_size, pSrcDst[0]); /* YData */ - Stream_Seek(data_in, y_size); - - rfx_decode_component(context, cb_quants, Stream_Pointer(data_in), cb_size, pSrcDst[1]); /* CbData */ - Stream_Seek(data_in, cb_size); - - rfx_decode_component(context, cr_quants, Stream_Pointer(data_in), cr_size, pSrcDst[2]); /* CrData */ - Stream_Seek(data_in, cr_size); - } + rfx_decode_component(context, cr_quants, tile->CrData, tile->CrLen, pSrcDst[2]); /* CrData */ PROFILER_ENTER(context->priv->prof_rfx_ycbcr_to_rgb); prims->yCbCrToRGB_16s16s_P3P3((const INT16**) pSrcDst, 64 * sizeof(INT16), diff --git a/libfreerdp/codec/rfx_decode.h b/libfreerdp/codec/rfx_decode.h index 469c2a576..f5da4f933 100644 --- a/libfreerdp/codec/rfx_decode.h +++ b/libfreerdp/codec/rfx_decode.h @@ -23,11 +23,7 @@ #include /* stride is bytes between rows in the output buffer. */ -BOOL rfx_decode_rgb(RFX_CONTEXT* context, wStream* data_in, - int y_size, const UINT32 * y_quants, - int cb_size, const UINT32 * cb_quants, - int cr_size, const UINT32 * cr_quants, BYTE* rgb_buffer, - int stride); +BOOL rfx_decode_rgb(RFX_CONTEXT* context, RFX_TILE* tile, BYTE* rgb_buffer, int stride); #endif /* __RFX_DECODE_H */