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

@ -207,6 +207,7 @@ BOOL rfx_decode_rgb(RFX_CONTEXT* context, wStream* data_in,
DEBUG_WARN("rfx_decode_rgb: packet too small for y_size+cb_size+cr_size"); DEBUG_WARN("rfx_decode_rgb: packet too small for y_size+cb_size+cr_size");
return FALSE; return FALSE;
} }
rfx_decode_component(context, y_quants, stream_get_tail(data_in), y_size, pSrcDst[0]); /* YData */ rfx_decode_component(context, y_quants, stream_get_tail(data_in), y_size, pSrcDst[0]); /* YData */
stream_seek(data_in, y_size); 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[0] - 16);
BufferPool_Return(context->priv->BufferPool, (BYTE*)pSrcDst[1] - 16); BufferPool_Return(context->priv->BufferPool, (BYTE*)pSrcDst[1] - 16);
BufferPool_Return(context->priv->BufferPool, (BYTE*)pSrcDst[2] - 16); BufferPool_Return(context->priv->BufferPool, (BYTE*)pSrcDst[2] - 16);
return TRUE; return TRUE;
} }

View File

@ -171,6 +171,7 @@ static BOOL fastpath_recv_update_common(rdpFastPath* fastpath, wStream* s)
if (stream_get_left(s) < 2) if (stream_get_left(s) < 2)
return FALSE; return FALSE;
stream_read_UINT16(s, updateType); /* updateType (2 bytes) */ stream_read_UINT16(s, updateType); /* updateType (2 bytes) */
switch (updateType) switch (updateType)
@ -328,6 +329,7 @@ static int fastpath_recv_update_data(rdpFastPath* fastpath, wStream* s)
} }
update_stream = NULL; update_stream = NULL;
if (fragmentation == FASTPATH_FRAGMENT_SINGLE) if (fragmentation == FASTPATH_FRAGMENT_SINGLE)
{ {
totalSize = size; totalSize = size;
@ -340,6 +342,7 @@ static int fastpath_recv_update_data(rdpFastPath* fastpath, wStream* s)
stream_check_size(fastpath->updateData, size); stream_check_size(fastpath->updateData, size);
stream_copy(fastpath->updateData, comp_stream, size); stream_copy(fastpath->updateData, comp_stream, size);
if (stream_get_length(fastpath->updateData) > rdp->settings->MultifragMaxRequestSize) if (stream_get_length(fastpath->updateData) > rdp->settings->MultifragMaxRequestSize)
{ {
fprintf(stderr, "fastpath PDU is bigger than MultifragMaxRequestSize\n"); fprintf(stderr, "fastpath PDU is bigger than MultifragMaxRequestSize\n");

View File

@ -21,11 +21,18 @@
#include "config.h" #include "config.h"
#endif #endif
#include "rdp.h"
#include "message.h" #include "message.h"
#include "transport.h"
#include <freerdp/freerdp.h>
#include <winpr/crt.h> #include <winpr/crt.h>
#include <winpr/stream.h>
#include <winpr/collections.h> #include <winpr/collections.h>
//#define WITH_STREAM_POOL 1
/* Update */ /* Update */
static void update_message_BeginPaint(rdpContext* context) 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); wParam->rectangles = (BITMAP_DATA*) malloc(sizeof(BITMAP_DATA) * wParam->number);
CopyMemory(wParam->rectangles, bitmap->rectangles, 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++) 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); wParam->rectangles[index].bitmapDataStream = (BYTE*) malloc(wParam->rectangles[index].bitmapLength);
CopyMemory(wParam->rectangles[index].bitmapDataStream, bitmap->rectangles[index].bitmapDataStream, CopyMemory(wParam->rectangles[index].bitmapDataStream, bitmap->rectangles[index].bitmapDataStream,
wParam->rectangles[index].bitmapLength); wParam->rectangles[index].bitmapLength);
#endif
} }
MessageQueue_Post(context->update->queue, (void*) context, 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)); wParam = (SURFACE_BITS_COMMAND*) malloc(sizeof(SURFACE_BITS_COMMAND));
CopyMemory(wParam, surfaceBitsCommand, 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); wParam->bitmapData = (BYTE*) malloc(wParam->bitmapDataLength);
CopyMemory(wParam->bitmapData, surfaceBitsCommand->bitmapData, wParam->bitmapDataLength); CopyMemory(wParam->bitmapData, surfaceBitsCommand->bitmapData, wParam->bitmapDataLength);
#endif
MessageQueue_Post(context->update->queue, (void*) context, MessageQueue_Post(context->update->queue, (void*) context,
MakeMessageId(Update, SurfaceBits), (void*) wParam, NULL); 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; BITMAP_UPDATE* wParam = (BITMAP_UPDATE*) msg->wParam;
for (index = 0; index < wParam->number; index++) 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); free(wParam->rectangles[index].bitmapDataStream);
#endif
}
free(wParam); free(wParam);
} }
@ -993,9 +1013,15 @@ int update_message_process_update_class(rdpUpdateProxy* proxy, wMessage* msg, in
case Update_SurfaceBits: case Update_SurfaceBits:
IFCALL(proxy->SurfaceBits, msg->context, (SURFACE_BITS_COMMAND*) msg->wParam); 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; SURFACE_BITS_COMMAND* wParam = (SURFACE_BITS_COMMAND*) msg->wParam;
free(wParam->bitmapData); free(wParam->bitmapData);
free(wParam); free(wParam);
#endif
} }
break; break;

View File

@ -50,11 +50,11 @@ static int update_recv_surfcmd_surface_bits(rdpUpdate* update, wStream* s, UINT3
pos = stream_get_pos(s) + cmd->bitmapDataLength; pos = stream_get_pos(s) + cmd->bitmapDataLength;
cmd->bitmapData = stream_get_tail(s); cmd->bitmapData = stream_get_tail(s);
IFCALL(update->SurfaceBits, update->context, cmd);
stream_set_pos(s, pos); stream_set_pos(s, pos);
*length = 20 + cmd->bitmapDataLength; *length = 20 + cmd->bitmapDataLength;
IFCALL(update->SurfaceBits, update->context, cmd);
return 0; return 0;
} }

View File

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