libfreerdp-codec: remove old RemoteFX tile pool
authorMarc-André Moreau <marcandre.moreau@gmail.com>
Mon, 21 Jan 2013 01:44:30 +0000 (20:44 -0500)
committerMarc-André Moreau <marcandre.moreau@gmail.com>
Mon, 21 Jan 2013 01:44:30 +0000 (20:44 -0500)
libfreerdp/codec/CMakeLists.txt
libfreerdp/codec/rfx.c
libfreerdp/codec/rfx_pool.c [deleted file]
libfreerdp/codec/rfx_pool.h [deleted file]
libfreerdp/codec/rfx_types.h
winpr/libwinpr/utils/collections/Queue.c
winpr/libwinpr/utils/test/TestQueue.c

index 612fda9..917c43c 100644 (file)
@@ -31,8 +31,6 @@ set(${MODULE_PREFIX}_SRCS
        rfx_dwt.h
        rfx_encode.c
        rfx_encode.h
-       rfx_pool.c
-       rfx_pool.h
        rfx_quantization.c
        rfx_quantization.h
        rfx_rlgr.c
@@ -98,8 +96,11 @@ set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS
        MONOLITHIC ${MONOLITHIC_BUILD} INTERNAL
        MODULE freerdp
        MODULES freerdp-primitives freerdp-utils)
-
-message(STATUS "libfreerdp-codec libs: ${${MODULE_PREFIX}_LIBS}")
+       
+set_complex_link_libraries(VARIABLE ${MODULE_PREFIX}_LIBS
+       MONOLITHIC ${MONOLITHIC_BUILD}
+       MODULE winpr
+       MODULES winpr-crt winpr-utils)
 
 if(MONOLITHIC_BUILD)
        set(FREERDP_LIBS ${FREERDP_LIBS} ${${MODULE_PREFIX}_LIBS} PARENT_SCOPE)
index e30f7f3..2448a78 100644 (file)
@@ -36,7 +36,6 @@
 
 #include "rfx_constants.h"
 #include "rfx_types.h"
-#include "rfx_pool.h"
 #include "rfx_decode.h"
 #include "rfx_encode.h"
 #include "rfx_quantization.h"
@@ -148,7 +147,8 @@ RFX_CONTEXT* rfx_context_new(void)
        context->priv = (RFX_CONTEXT_PRIV*) malloc(sizeof(RFX_CONTEXT_PRIV));
        ZeroMemory(context->priv, sizeof(RFX_CONTEXT_PRIV));
 
-       context->priv->pool = rfx_pool_new();
+       context->priv->TilePool = Queue_New(TRUE, -1, -1);
+       context->priv->TileQueue = Queue_New(TRUE, -1, -1);
 
        /* initialize the default pixel format */
        rfx_context_set_pixel_format(context, RDP_PIXEL_FORMAT_B8G8R8A8);
@@ -183,7 +183,8 @@ void rfx_context_free(RFX_CONTEXT* context)
 {
        free(context->quants);
 
-       rfx_pool_free(context->priv->pool);
+       Queue_Free(context->priv->TilePool);
+       Queue_Free(context->priv->TileQueue);
 
        rfx_profiler_print(context);
        rfx_profiler_free(context);
@@ -195,6 +196,7 @@ void rfx_context_free(RFX_CONTEXT* context)
 void rfx_context_set_pixel_format(RFX_CONTEXT* context, RDP_PIXEL_FORMAT pixel_format)
 {
        context->pixel_format = pixel_format;
+
        switch (pixel_format)
        {
                case RDP_PIXEL_FORMAT_B8G8R8A8:
@@ -227,6 +229,30 @@ void rfx_context_reset(RFX_CONTEXT* context)
        context->frame_idx = 0;
 }
 
+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;
+}
+
 static void rfx_process_message_sync(RFX_CONTEXT* context, STREAM* s)
 {
        UINT32 magic;
@@ -412,7 +438,7 @@ static void rfx_process_message_tile(RFX_CONTEXT* context, RFX_TILE* tile, STREA
                YLen, context->quants + (quantIdxY * 10),
                CbLen, context->quants + (quantIdxCb * 10),
                CrLen, context->quants + (quantIdxCr * 10),
-               tile->data, 64*sizeof(UINT32));
+               tile->data, 64 * sizeof(UINT32));
 }
 
 static void rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* message, STREAM* s)
@@ -490,7 +516,8 @@ static void rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* messa
                        context->quants[i * 10 + 8], context->quants[i * 10 + 9]);
        }
 
-       message->tiles = rfx_pool_get_tiles(context->priv->pool, message->num_tiles);
+       message->tiles = (RFX_TILE**) malloc(sizeof(RFX_TILE*) * message->num_tiles);
+       ZeroMemory(message->tiles, sizeof(RFX_TILE*) * message->num_tiles);
 
        /* tiles */
        for (i = 0; i < message->num_tiles; i++)
@@ -507,6 +534,7 @@ static void rfx_process_message_tileset(RFX_CONTEXT* context, RFX_MESSAGE* messa
                        break;
                }
 
+               message->tiles[i] = rfx_tile_pool_take(context);
                rfx_process_message_tile(context, message->tiles[i], s);
 
                stream_set_pos(s, pos);
@@ -621,13 +649,17 @@ RFX_RECT* rfx_message_get_rect(RFX_MESSAGE* message, int index)
 
 void rfx_message_free(RFX_CONTEXT* context, RFX_MESSAGE* message)
 {
+       int i;
+
        if (message != NULL)
        {
                free(message->rects);
 
-               if (message->tiles != NULL)
+               if (message->tiles)
                {
-                       rfx_pool_put_tiles(context->priv->pool, message->tiles, message->num_tiles);
+                       for (i = 0; i < message->num_tiles; i++)
+                               rfx_tile_pool_return(context, message->tiles[i]);
+
                        free(message->tiles);
                }
 
@@ -790,9 +822,9 @@ static void rfx_compose_message_tile(RFX_CONTEXT* context, STREAM* s,
 static void rfx_compose_message_tileset(RFX_CONTEXT* context, STREAM* s,
        BYTE* image_data, int width, int height, int rowstride)
 {
+       int i;
        int size;
        int start_pos, end_pos;
-       int i;
        int numQuants;
        const UINT32* quantVals;
        const UINT32* quantValsPtr;
diff --git a/libfreerdp/codec/rfx_pool.c b/libfreerdp/codec/rfx_pool.c
deleted file mode 100644 (file)
index b7d630c..0000000
+++ /dev/null
@@ -1,121 +0,0 @@
-/**
- * FreeRDP: A Remote Desktop Protocol Implementation
- * RemoteFX Codec Library - Memory Pool
- *
- * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
- *
- * 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.
- */
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <winpr/crt.h>
-
-#include "rfx_pool.h"
-
-RFX_POOL* rfx_pool_new()
-{
-       RFX_POOL* pool;
-
-       pool = (RFX_POOL*) malloc(sizeof(RFX_POOL));
-       ZeroMemory(pool, sizeof(RFX_POOL));
-
-       pool->size = 64;
-       pool->tiles = (RFX_TILE**) malloc(sizeof(RFX_TILE*) * pool->size);
-       ZeroMemory(pool->tiles, sizeof(RFX_TILE*) * pool->size);
-
-       return pool;
-}
-
-void rfx_pool_free(RFX_POOL* pool)
-{
-       int i;
-       RFX_TILE* tile;
-
-       for (i = 0; i < pool->count; i++)
-       {
-               tile = pool->tiles[i];
-
-               if (tile != NULL)
-               {
-                       if (tile->data != NULL)
-                               free(tile->data);
-
-                       free(tile);
-               }
-       }
-
-       free(pool->tiles);
-       free(pool);
-}
-
-void rfx_pool_put_tile(RFX_POOL* pool, RFX_TILE* tile)
-{
-       if (pool->count >= pool->size)
-       {
-               pool->size *= 2;
-               pool->tiles = (RFX_TILE**) realloc((void*) pool->tiles, sizeof(RFX_TILE*) * pool->size);
-       }
-
-       pool->tiles[(pool->count)++] = tile;
-}
-
-RFX_TILE* rfx_pool_get_tile(RFX_POOL* pool)
-{
-       RFX_TILE* tile;
-
-       if (pool->count < 1)
-       {
-               tile = (RFX_TILE*) malloc(sizeof(RFX_TILE));
-               ZeroMemory(tile, sizeof(RFX_TILE));
-
-               tile->data = (BYTE*) malloc(4096 * 4); /* 64x64 * 4 */
-       }
-       else
-       {
-               tile = pool->tiles[--(pool->count)];
-       }
-
-       return tile;
-}
-
-void rfx_pool_put_tiles(RFX_POOL* pool, RFX_TILE** tiles, int count)
-{
-       int i;
-
-       for (i = 0; i < count; i++)
-       {
-               rfx_pool_put_tile(pool, tiles[i]);
-       }
-}
-
-RFX_TILE** rfx_pool_get_tiles(RFX_POOL* pool, int count)
-{
-       int i;
-       RFX_TILE** tiles;
-
-       tiles = (RFX_TILE**) malloc(sizeof(RFX_TILE*) * count);
-
-       for (i = 0; i < count; i++)
-       {
-               tiles[i] = rfx_pool_get_tile(pool);
-       }
-
-       return tiles;
-}
diff --git a/libfreerdp/codec/rfx_pool.h b/libfreerdp/codec/rfx_pool.h
deleted file mode 100644 (file)
index 787a326..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/**
- * FreeRDP: A Remote Desktop Protocol Implementation
- * RemoteFX Codec Library - Memory Pool
- *
- * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
- *
- * 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.
- */
-
-#ifndef __RFX_POOL_H
-#define __RFX_POOL_H
-
-#include <freerdp/codec/rfx.h>
-
-struct _RFX_POOL
-{
-       int size;
-       int count;
-       RFX_TILE** tiles;
-};
-typedef struct _RFX_POOL RFX_POOL;
-
-RFX_POOL* rfx_pool_new();
-void rfx_pool_free(RFX_POOL* pool);
-void rfx_pool_put_tile(RFX_POOL* pool, RFX_TILE* tile);
-RFX_TILE* rfx_pool_get_tile(RFX_POOL* pool);
-void rfx_pool_put_tiles(RFX_POOL* pool, RFX_TILE** tiles, int count);
-RFX_TILE** rfx_pool_get_tiles(RFX_POOL* pool, int count);
-
-#endif /* __RFX_POOL_H */
index 0d83408..30b2980 100644 (file)
@@ -24,6 +24,9 @@
 #include "config.h"
 #endif
 
+#include <winpr/crt.h>
+#include <winpr/collections.h>
+
 #include <freerdp/utils/debug.h>
 #include <freerdp/utils/profiler.h>
 
 #define DEBUG_RFX(fmt, ...) DEBUG_NULL(fmt, ## __VA_ARGS__)
 #endif
 
-#include "rfx_pool.h"
-
 struct _RFX_CONTEXT_PRIV
 {
        /* pre-allocated buffers */
 
-       RFX_POOL* pool; /* memory pool */
+       wQueue* TilePool;
+       wQueue* TileQueue;
 
        INT16 y_r_mem[4096 + 8]; /* 4096 = 64x64 (+ 8x2 = 16 for mem align) */
        INT16 cb_g_mem[4096 + 8]; /* 4096 = 64x64 (+ 8x2 = 16 for mem align) */
index 2135ae5..841bc49 100644 (file)
@@ -138,8 +138,21 @@ void Queue_Enqueue(wQueue* queue, void* obj)
 
        if (queue->size == queue->capacity)
        {
-               queue->capacity *= queue->growthFactor;
+               int old_capacity;
+               int new_capacity;
+
+               old_capacity = queue->capacity;
+               new_capacity = queue->capacity * queue->growthFactor;
+
+               queue->capacity = new_capacity;
                queue->array = (void**) realloc(queue->array, sizeof(void*) * queue->capacity);
+               ZeroMemory(&(queue->array[old_capacity]), old_capacity * sizeof(void*));
+
+               if (queue->tail < (old_capacity - 1))
+               {
+                       CopyMemory(&(queue->array[old_capacity]), queue->array, queue->tail * sizeof(void*));
+                       queue->tail += old_capacity;
+               }
        }
 
        queue->array[queue->tail] = obj;
index 8f9d6c0..2ef6120 100644 (file)
@@ -18,7 +18,6 @@ int TestQueue(int argc, char* argv[])
        }
 
        count = Queue_Count(queue);
-
        printf("queue count: %d\n", count);
 
        for (index = 1; index <= 10; index++)
@@ -29,6 +28,25 @@ int TestQueue(int argc, char* argv[])
                        return -1;
        }
 
+       count = Queue_Count(queue);
+       printf("queue count: %d\n", count);
+
+       Queue_Enqueue(queue, (void*) (size_t) 1);
+       Queue_Enqueue(queue, (void*) (size_t) 2);
+       Queue_Enqueue(queue, (void*) (size_t) 3);
+
+       Queue_Dequeue(queue);
+       Queue_Dequeue(queue);
+
+       Queue_Enqueue(queue, (void*) (size_t) 4);
+       Queue_Enqueue(queue, (void*) (size_t) 5);
+       Queue_Enqueue(queue, (void*) (size_t) 6);
+
+       Queue_Dequeue(queue);
+       Queue_Dequeue(queue);
+       Queue_Dequeue(queue);
+       Queue_Dequeue(queue);
+
        Queue_Clear(queue);
        Queue_Free(queue);