libfreerdp-core: start using stream pool

This commit is contained in:
Marc-André Moreau 2013-04-12 17:05:42 -04:00
parent d04b76d005
commit d776a2d4ea
5 changed files with 46 additions and 14 deletions

View File

@ -202,11 +202,12 @@ BOOL rfx_decode_rgb(RFX_CONTEXT* context, wStream* data_in,
else
#endif
{
if (stream_get_left(data_in) < y_size+cb_size+cr_size)
if (stream_get_left(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_get_tail(data_in), y_size, pSrcDst[0]); /* YData */
stream_seek(data_in, y_size);
@ -230,5 +231,6 @@ BOOL rfx_decode_rgb(RFX_CONTEXT* context, wStream* data_in,
BufferPool_Return(context->priv->BufferPool, (BYTE*)pSrcDst[0] - 16);
BufferPool_Return(context->priv->BufferPool, (BYTE*)pSrcDst[1] - 16);
BufferPool_Return(context->priv->BufferPool, (BYTE*)pSrcDst[2] - 16);
return TRUE;
}

View File

@ -169,20 +169,21 @@ static BOOL fastpath_recv_update_common(rdpFastPath* fastpath, wStream* s)
rdpUpdate* update = fastpath->rdp->update;
rdpContext* context = update->context;
if(stream_get_left(s) < 2)
if (stream_get_left(s) < 2)
return FALSE;
stream_read_UINT16(s, updateType); /* updateType (2 bytes) */
switch (updateType)
{
case UPDATE_TYPE_BITMAP:
if(!update_read_bitmap(update, s, &update->bitmap_update))
if (!update_read_bitmap(update, s, &update->bitmap_update))
return FALSE;
IFCALL(update->BitmapUpdate, context, &update->bitmap_update);
break;
case UPDATE_TYPE_PALETTE:
if(!update_read_palette(update, s, &update->palette_update))
if (!update_read_palette(update, s, &update->palette_update))
return FALSE;
IFCALL(update->Palette, context, &update->palette_update);
break;
@ -328,6 +329,7 @@ static int fastpath_recv_update_data(rdpFastPath* fastpath, wStream* s)
}
update_stream = NULL;
if (fragmentation == FASTPATH_FRAGMENT_SINGLE)
{
totalSize = size;
@ -340,6 +342,7 @@ static int fastpath_recv_update_data(rdpFastPath* fastpath, wStream* s)
stream_check_size(fastpath->updateData, size);
stream_copy(fastpath->updateData, comp_stream, size);
if (stream_get_length(fastpath->updateData) > rdp->settings->MultifragMaxRequestSize)
{
fprintf(stderr, "fastpath PDU is bigger than MultifragMaxRequestSize\n");

View File

@ -21,11 +21,18 @@
#include "config.h"
#endif
#include "rdp.h"
#include "message.h"
#include "transport.h"
#include <freerdp/freerdp.h>
#include <winpr/crt.h>
#include <winpr/stream.h>
#include <winpr/collections.h>
//#define WITH_STREAM_POOL 1
/* Update */
static void update_message_BeginPaint(rdpContext* context)
@ -79,13 +86,15 @@ static void update_message_BitmapUpdate(rdpContext* context, BITMAP_UPDATE* bitm
wParam->rectangles = (BITMAP_DATA*) malloc(sizeof(BITMAP_DATA) * wParam->number);
CopyMemory(wParam->rectangles, bitmap->rectangles, sizeof(BITMAP_DATA) * wParam->number);
/* TODO: increment reference count to original stream instead of copying */
for (index = 0; index < wParam->number; index++)
{
#ifdef WITH_STREAM_POOL
StreamPool_AddRef(context->rdp->transport->ReceivePool, bitmap->rectangles[index].bitmapDataStream);
#else
wParam->rectangles[index].bitmapDataStream = (BYTE*) malloc(wParam->rectangles[index].bitmapLength);
CopyMemory(wParam->rectangles[index].bitmapDataStream, bitmap->rectangles[index].bitmapDataStream,
wParam->rectangles[index].bitmapLength);
#endif
}
MessageQueue_Post(context->update->queue, (void*) context,
@ -160,8 +169,12 @@ static void update_message_SurfaceBits(rdpContext* context, SURFACE_BITS_COMMAND
wParam = (SURFACE_BITS_COMMAND*) malloc(sizeof(SURFACE_BITS_COMMAND));
CopyMemory(wParam, surfaceBitsCommand, sizeof(SURFACE_BITS_COMMAND));
#ifdef WITH_STREAM_POOL
StreamPool_AddRef(context->rdp->transport->ReceivePool, surfaceBitsCommand->bitmapData);
#else
wParam->bitmapData = (BYTE*) malloc(wParam->bitmapDataLength);
CopyMemory(wParam->bitmapData, surfaceBitsCommand->bitmapData, wParam->bitmapDataLength);
#endif
MessageQueue_Post(context->update->queue, (void*) context,
MakeMessageId(Update, SurfaceBits), (void*) wParam, NULL);
@ -952,7 +965,14 @@ int update_message_process_update_class(rdpUpdateProxy* proxy, wMessage* msg, in
BITMAP_UPDATE* wParam = (BITMAP_UPDATE*) msg->wParam;
for (index = 0; index < wParam->number; index++)
{
#ifdef WITH_STREAM_POOL
rdpContext* context = (rdpContext*) msg->context;
StreamPool_Release(context->rdp->transport->ReceivePool, wParam->rectangles[index].bitmapDataStream);
#else
free(wParam->rectangles[index].bitmapDataStream);
#endif
}
free(wParam);
}
@ -993,9 +1013,15 @@ int update_message_process_update_class(rdpUpdateProxy* proxy, wMessage* msg, in
case Update_SurfaceBits:
IFCALL(proxy->SurfaceBits, msg->context, (SURFACE_BITS_COMMAND*) msg->wParam);
{
#ifdef WITH_STREAM_POOL
rdpContext* context = (rdpContext*) msg->context;
SURFACE_BITS_COMMAND* wParam = (SURFACE_BITS_COMMAND*) msg->wParam;
StreamPool_Release(context->rdp->transport->ReceivePool, wParam->bitmapData);
#else
SURFACE_BITS_COMMAND* wParam = (SURFACE_BITS_COMMAND*) msg->wParam;
free(wParam->bitmapData);
free(wParam);
#endif
}
break;

View File

@ -25,7 +25,7 @@
#include "surface.h"
static int update_recv_surfcmd_surface_bits(rdpUpdate* update, wStream* s, UINT32 *length)
static int update_recv_surfcmd_surface_bits(rdpUpdate* update, wStream* s, UINT32* length)
{
int pos;
SURFACE_BITS_COMMAND* cmd = &update->surface_bits_command;
@ -50,11 +50,11 @@ static int update_recv_surfcmd_surface_bits(rdpUpdate* update, wStream* s, UINT3
pos = stream_get_pos(s) + cmd->bitmapDataLength;
cmd->bitmapData = stream_get_tail(s);
IFCALL(update->SurfaceBits, update->context, cmd);
stream_set_pos(s, pos);
*length = 20 + cmd->bitmapDataLength;
IFCALL(update->SurfaceBits, update->context, cmd);
return 0;
}

View File

@ -704,7 +704,6 @@ int transport_check_fds(rdpTransport** ptransport)
received = transport->ReceiveBuffer;
transport->ReceiveBuffer = StreamPool_Take(transport->ReceivePool, 0);
transport->ReceiveBuffer->pointer = transport->ReceiveBuffer->buffer;
stream_set_pos(received, length);
stream_seal(received);
@ -720,7 +719,7 @@ int transport_check_fds(rdpTransport** ptransport)
recv_status = transport->ReceiveCallback(transport, received, transport->ReceiveExtra);
StreamPool_Return(transport->ReceivePool, received);
Stream_Release(received);
if (recv_status < 0)
status = -1;
@ -823,7 +822,7 @@ rdpTransport* transport_new(rdpSettings* settings)
transport->ReceiveEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
/* buffers for blocking read/write */
transport->ReceiveStream = stream_new(BUFFER_SIZE);
transport->ReceiveStream = StreamPool_Take(transport->ReceivePool, 0);
transport->SendStream = stream_new(BUFFER_SIZE);
transport->blocking = TRUE;
@ -839,11 +838,13 @@ void transport_free(rdpTransport* transport)
if (transport != NULL)
{
if (transport->ReceiveBuffer)
StreamPool_Return(transport->ReceivePool, transport->ReceiveBuffer);
Stream_Release(transport->ReceiveBuffer);
if (transport->ReceiveStream)
Stream_Release(transport->ReceiveStream);
StreamPool_Free(transport->ReceivePool);
stream_free(transport->ReceiveStream);
stream_free(transport->SendStream);
CloseHandle(transport->ReceiveEvent);