Fixed codec reset, now resetting resolution too.
authorArmin Novak <armin.novak@thincast.com>
Tue, 1 Mar 2016 15:17:28 +0000 (16:17 +0100)
committerArmin Novak <armin.novak@thincast.com>
Wed, 2 Mar 2016 13:46:33 +0000 (14:46 +0100)
H264 and others require the surface resolution to work properly.
This initializes the codecs and the resolution on reset.

20 files changed:
client/X11/xf_gfx.c
include/freerdp/codec/clear.h
include/freerdp/codec/h264.h
include/freerdp/codec/interleaved.h
include/freerdp/codec/nsc.h
include/freerdp/codec/planar.h
include/freerdp/codec/progressive.h
include/freerdp/codec/rfx.h
include/freerdp/codecs.h
libfreerdp/codec/clear.c
libfreerdp/codec/h264.c
libfreerdp/codec/interleaved.c
libfreerdp/codec/nsc.c
libfreerdp/codec/planar.c
libfreerdp/codec/progressive.c
libfreerdp/codec/rfx.c
libfreerdp/core/codecs.c
libfreerdp/gdi/gfx.c
server/Sample/sfreerdp.c
server/shadow/shadow_encoder.c

index a2a8f61..3b63f1f 100644 (file)
@@ -48,14 +48,22 @@ UINT xf_ResetGraphics(RdpgfxClientContext* context, RDPGFX_RESET_GRAPHICS_PDU* r
                if (!surface || !surface->outputMapped)
                        continue;
 
-               freerdp_client_codecs_reset(surface->codecs, FREERDP_CODEC_ALL);
+               if (!freerdp_client_codecs_reset(surface->codecs, FREERDP_CODEC_ALL,
+                                                surface->width, surface->height))
+               {
+                       free(pSurfaceIds);
+                       return ERROR_INTERNAL_ERROR;
+               }
 
                region16_clear(&surface->invalidRegion);
        }
 
        free(pSurfaceIds);
 
-       freerdp_client_codecs_reset(xfc->codecs, FREERDP_CODEC_ALL);
+       if (!freerdp_client_codecs_reset(xfc->codecs, FREERDP_CODEC_ALL,
+                                        xfc->settings->DesktopWidth,
+                                        xfc->settings->DesktopHeight))
+               return ERROR_INTERNAL_ERROR;
 
        xfc->graphicsReset = TRUE;
 
@@ -714,6 +722,13 @@ UINT xf_CreateSurface(RdpgfxClientContext* context, RDPGFX_CREATE_SURFACE_PDU* c
                return CHANNEL_RC_NO_MEMORY;
        }
 
+       if (!freerdp_client_codecs_reset(surface->codecs, FREERDP_CODEC_ALL,
+                                        createSurface->width, createSurface->height))
+       {
+               free (surface);
+               return ERROR_INTERNAL_ERROR;
+       }
+
        surface->surfaceId = createSurface->surfaceId;
        surface->width = (UINT32) createSurface->width;
        surface->height = (UINT32) createSurface->height;
index cc946d5..baca737 100644 (file)
@@ -71,7 +71,7 @@ FREERDP_API int clear_compress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcS
 FREERDP_API int clear_decompress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize,
                BYTE** ppDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, int nWidth, int nHeight);
 
-FREERDP_API int clear_context_reset(CLEAR_CONTEXT* clear);
+FREERDP_API BOOL clear_context_reset(CLEAR_CONTEXT* clear);
 
 FREERDP_API CLEAR_CONTEXT* clear_context_new(BOOL Compressor);
 FREERDP_API void clear_context_free(CLEAR_CONTEXT* clear);
@@ -81,4 +81,4 @@ FREERDP_API void clear_context_free(CLEAR_CONTEXT* clear);
 #endif
 
 #endif /* FREERDP_CODEC_CLEAR_H */
+
index 410ad49..86e2a2c 100644 (file)
@@ -61,7 +61,7 @@ struct _H264_CONTEXT
        FLOAT FrameRate;
        UINT32 QP;
        UINT32 NumberOfThreads;
-       
+
        int iStride[3];
        BYTE* pYUVData[3];
 
@@ -80,7 +80,7 @@ FREERDP_API int h264_decompress(H264_CONTEXT* h264, BYTE* pSrcData, UINT32 SrcSi
                BYTE** ppDstData, DWORD DstFormat, int nDstStep, int nDstWidth, int nDstHeight,
                RDPGFX_RECT16* regionRects, int numRegionRect);
 
-FREERDP_API int h264_context_reset(H264_CONTEXT* h264);
+FREERDP_API BOOL h264_context_reset(H264_CONTEXT* h264, UINT32 width, UINT32 height);
 
 FREERDP_API H264_CONTEXT* h264_context_new(BOOL Compressor);
 FREERDP_API void h264_context_free(H264_CONTEXT* h264);
index 205bc44..1d75f86 100644 (file)
@@ -48,7 +48,7 @@ FREERDP_API int interleaved_decompress(BITMAP_INTERLEAVED_CONTEXT* interleaved,
 FREERDP_API int interleaved_compress(BITMAP_INTERLEAVED_CONTEXT* interleaved, BYTE* pDstData, UINT32* pDstSize,
                int nWidth, int nHeight, BYTE* pSrcData, DWORD SrcFormat, int nSrcStep, int nXSrc, int nYSrc, BYTE* palette, int bpp);
 
-FREERDP_API int bitmap_interleaved_context_reset(BITMAP_INTERLEAVED_CONTEXT* interleaved);
+FREERDP_API BOOL bitmap_interleaved_context_reset(BITMAP_INTERLEAVED_CONTEXT* interleaved);
 
 FREERDP_API BITMAP_INTERLEAVED_CONTEXT* bitmap_interleaved_context_new(BOOL Compressor);
 FREERDP_API void bitmap_interleaved_context_free(BITMAP_INTERLEAVED_CONTEXT* interleaved);
index 2ba5623..0439308 100644 (file)
@@ -93,7 +93,7 @@ FREERDP_API NSC_MESSAGE* nsc_encode_messages(NSC_CONTEXT* context, BYTE* data, i
 FREERDP_API int nsc_write_message(NSC_CONTEXT* context, wStream* s, NSC_MESSAGE* message);
 FREERDP_API int nsc_message_free(NSC_CONTEXT* context, NSC_MESSAGE* message);
 
-FREERDP_API int nsc_context_reset(NSC_CONTEXT* context);
+FREERDP_API BOOL nsc_context_reset(NSC_CONTEXT* context, UINT32 width, UINT32 height);
 
 FREERDP_API NSC_CONTEXT* nsc_context_new(void);
 FREERDP_API void nsc_context_free(NSC_CONTEXT* context);
index 781ae08..4bc0e24 100644 (file)
@@ -109,7 +109,7 @@ FREERDP_API BOOL freerdp_bitmap_planar_delta_encode_planes(BYTE* inPlanes[4], in
 FREERDP_API BYTE* freerdp_bitmap_compress_planar(BITMAP_PLANAR_CONTEXT* context, BYTE* data, UINT32 format,
                int width, int height, int scanline, BYTE* dstData, int* pDstSize);
 
-FREERDP_API int freerdp_bitmap_planar_context_reset(BITMAP_PLANAR_CONTEXT* context);
+FREERDP_API BOOL freerdp_bitmap_planar_context_reset(BITMAP_PLANAR_CONTEXT* context);
 
 FREERDP_API BITMAP_PLANAR_CONTEXT* freerdp_bitmap_planar_context_new(DWORD flags, int maxWidth, int maxHeight);
 FREERDP_API void freerdp_bitmap_planar_context_free(BITMAP_PLANAR_CONTEXT* context);
index a2cc7ad..cc2d75c 100644 (file)
@@ -242,7 +242,7 @@ FREERDP_API int progressive_decompress(PROGRESSIVE_CONTEXT* progressive, BYTE* p
 FREERDP_API int progressive_create_surface_context(PROGRESSIVE_CONTEXT* progressive, UINT16 surfaceId, UINT32 width, UINT32 height);
 FREERDP_API int progressive_delete_surface_context(PROGRESSIVE_CONTEXT* progressive, UINT16 surfaceId);
 
-FREERDP_API int progressive_context_reset(PROGRESSIVE_CONTEXT* progressive);
+FREERDP_API BOOL progressive_context_reset(PROGRESSIVE_CONTEXT* progressive);
 
 FREERDP_API PROGRESSIVE_CONTEXT* progressive_context_new(BOOL Compressor);
 FREERDP_API void progressive_context_free(PROGRESSIVE_CONTEXT* progressive);
@@ -252,4 +252,4 @@ FREERDP_API void progressive_context_free(PROGRESSIVE_CONTEXT* progressive);
 #endif
 
 #endif /* FREERDP_CODEC_PROGRESSIVE_H */
+
index 9bb2ff4..d9d5a99 100644 (file)
@@ -183,7 +183,7 @@ FREERDP_API RFX_MESSAGE* rfx_encode_messages(RFX_CONTEXT* context, const RFX_REC
                BYTE* data, int width, int height, int scanline, int* numMessages, int maxDataSize);
 FREERDP_API BOOL rfx_write_message(RFX_CONTEXT* context, wStream* s, RFX_MESSAGE* message);
 
-FREERDP_API void rfx_context_reset(RFX_CONTEXT* context);
+FREERDP_API BOOL rfx_context_reset(RFX_CONTEXT* context, UINT32 width, UINT32 height);
 
 FREERDP_API RFX_CONTEXT* rfx_context_new(BOOL encoder);
 FREERDP_API void rfx_context_free(RFX_CONTEXT* context);
index 5298d14..09dd047 100644 (file)
@@ -60,7 +60,8 @@ struct rdp_codecs
 #endif
 
 FREERDP_API BOOL freerdp_client_codecs_prepare(rdpCodecs* codecs, UINT32 flags);
-FREERDP_API BOOL freerdp_client_codecs_reset(rdpCodecs* codecs, UINT32 flags);
+FREERDP_API BOOL freerdp_client_codecs_reset(rdpCodecs* codecs, UINT32 flags,
+                                            UINT32 width, UINT32 height);
 
 FREERDP_API rdpCodecs* codecs_new(rdpContext* context);
 FREERDP_API void codecs_free(rdpCodecs* codecs);
index 922a83a..ab4e5de 100644 (file)
@@ -830,12 +830,16 @@ int clear_compress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize, BYTE**
        return 1;
 }
 
-int clear_context_reset(CLEAR_CONTEXT* clear)
+BOOL clear_context_reset(CLEAR_CONTEXT* clear)
 {
+       if (!clear)
+               return FALSE;
+
        clear->seqNumber = 0;
        clear->VBarStorageCursor = 0;
        clear->ShortVBarStorageCursor = 0;
-       return 1;
+
+       return TRUE;
 }
 
 CLEAR_CONTEXT* clear_context_new(BOOL Compressor)
index da2e083..230b3ab 100644 (file)
@@ -103,17 +103,17 @@ typedef interface IMFDXGIDeviceManager IMFDXGIDeviceManager;
 #define __IMFDXGIDeviceManager_INTERFACE_DEFINED__
 
 typedef struct IMFDXGIDeviceManagerVtbl
-{        
+{
        HRESULT (STDMETHODCALLTYPE * QueryInterface)(IMFDXGIDeviceManager* This, REFIID riid, void** ppvObject);
        ULONG   (STDMETHODCALLTYPE * AddRef)(IMFDXGIDeviceManager* This);
-        ULONG   (STDMETHODCALLTYPE * Release)(IMFDXGIDeviceManager* This);
-        HRESULT (STDMETHODCALLTYPE * CloseDeviceHandle)(IMFDXGIDeviceManager* This, HANDLE hDevice);
-        HRESULT (STDMETHODCALLTYPE * GetVideoService)(IMFDXGIDeviceManager* This, HANDLE hDevice, REFIID riid, void** ppService);
-        HRESULT (STDMETHODCALLTYPE * LockDevice)(IMFDXGIDeviceManager* This, HANDLE hDevice, REFIID riid, void** ppUnkDevice, BOOL fBlock);
-        HRESULT (STDMETHODCALLTYPE * OpenDeviceHandle)(IMFDXGIDeviceManager* This, HANDLE* phDevice);
-        HRESULT (STDMETHODCALLTYPE * ResetDevice)(IMFDXGIDeviceManager* This, IUnknown* pUnkDevice, UINT resetToken);
-        HRESULT (STDMETHODCALLTYPE * TestDevice)(IMFDXGIDeviceManager* This, HANDLE hDevice);
-        HRESULT (STDMETHODCALLTYPE * UnlockDevice)(IMFDXGIDeviceManager* This, HANDLE hDevice, BOOL fSaveState);
+       ULONG   (STDMETHODCALLTYPE * Release)(IMFDXGIDeviceManager* This);
+       HRESULT (STDMETHODCALLTYPE * CloseDeviceHandle)(IMFDXGIDeviceManager* This, HANDLE hDevice);
+       HRESULT (STDMETHODCALLTYPE * GetVideoService)(IMFDXGIDeviceManager* This, HANDLE hDevice, REFIID riid, void** ppService);
+       HRESULT (STDMETHODCALLTYPE * LockDevice)(IMFDXGIDeviceManager* This, HANDLE hDevice, REFIID riid, void** ppUnkDevice, BOOL fBlock);
+       HRESULT (STDMETHODCALLTYPE * OpenDeviceHandle)(IMFDXGIDeviceManager* This, HANDLE* phDevice);
+       HRESULT (STDMETHODCALLTYPE * ResetDevice)(IMFDXGIDeviceManager* This, IUnknown* pUnkDevice, UINT resetToken);
+       HRESULT (STDMETHODCALLTYPE * TestDevice)(IMFDXGIDeviceManager* This, HANDLE hDevice);
+       HRESULT (STDMETHODCALLTYPE * UnlockDevice)(IMFDXGIDeviceManager* This, HANDLE hDevice, BOOL fSaveState);
 }
 IMFDXGIDeviceManagerVtbl;
 
@@ -396,7 +396,7 @@ static int mf_decompress(H264_CONTEXT* h264, BYTE* pSrcData, UINT32 SrcSize)
        }
        else if (hr == MF_E_TRANSFORM_NEED_MORE_INPUT)
        {
-               
+
        }
        else if (FAILED(hr))
        {
@@ -518,7 +518,7 @@ static void mf_uninit(H264_CONTEXT* h264)
                h264->iStride[0] = h264->iStride[1] = h264->iStride[2] = 0;
 
                sys->MFShutdown();
-               
+
                CoUninitialize();
 
                free(sys);
@@ -592,7 +592,7 @@ static BOOL mf_init(H264_CONTEXT* h264)
 
                var.vt = VT_UI4;
                var.ulVal = 1;
-               
+
                hr = sys->codecApi->lpVtbl->SetValue(sys->codecApi, &CODECAPI_AVLowLatencyMode, &var);
 
                if (FAILED(hr))
@@ -618,7 +618,7 @@ static BOOL mf_init(H264_CONTEXT* h264)
                }
 
                hr = sys->inputType->lpVtbl->SetGUID(sys->inputType, &MF_MT_SUBTYPE, &MFVideoFormat_H264);
-               
+
                if (FAILED(hr))
                {
                        WLog_ERR(TAG, "SetGUID(MF_MT_SUBTYPE) failure: 0x%04X", hr);
@@ -1407,7 +1407,7 @@ int h264_decompress(H264_CONTEXT* h264, BYTE* pSrcData, UINT32 SrcSize,
 
                width = rect->right - rect->left;
                height = rect->bottom - rect->top;
-               
+
                pDstPoint = pDstData + rect->top * nDstStep + rect->left * 4;
                pYUVPoint[0] = pYUVData[0] + rect->top * iStride[0] + rect->left;
 
@@ -1514,9 +1514,15 @@ BOOL h264_context_init(H264_CONTEXT* h264)
        return FALSE;
 }
 
-int h264_context_reset(H264_CONTEXT* h264)
+BOOL h264_context_reset(H264_CONTEXT* h264, UINT32 width, UINT32 height)
 {
-       return 1;
+       if (!h264)
+               return FALSE;
+
+       h264->width = width;
+       h264->height = height;
+
+       return TRUE;
 }
 
 H264_CONTEXT* h264_context_new(BOOL Compressor)
index 1da6349..ea269d8 100644 (file)
@@ -413,9 +413,12 @@ int interleaved_compress(BITMAP_INTERLEAVED_CONTEXT* interleaved, BYTE* pDstData
        return status;
 }
 
-int bitmap_interleaved_context_reset(BITMAP_INTERLEAVED_CONTEXT* interleaved)
+BOOL bitmap_interleaved_context_reset(BITMAP_INTERLEAVED_CONTEXT* interleaved)
 {
-       return 1;
+       if (!interleaved)
+               return FALSE;
+
+       return TRUE;
 }
 
 BITMAP_INTERLEAVED_CONTEXT* bitmap_interleaved_context_new(BOOL Compressor)
index cff1768..9d78d78 100644 (file)
@@ -266,9 +266,15 @@ static void nsc_profiler_print(NSC_CONTEXT* context)
        PROFILER_PRINT_FOOTER;
 }
 
-int nsc_context_reset(NSC_CONTEXT* context)
+BOOL nsc_context_reset(NSC_CONTEXT* context, UINT32 width, UINT32 height)
 {
-       return 1;
+       if (!context)
+               return FALSE;
+
+       context->width = width;
+       context->height = height;
+
+       return TRUE;
 }
 
 NSC_CONTEXT* nsc_context_new(void)
index 37bd7bd..9b874b0 100644 (file)
@@ -1160,9 +1160,12 @@ BYTE* freerdp_bitmap_compress_planar(BITMAP_PLANAR_CONTEXT* context, BYTE* data,
        return dstData;
 }
 
-int freerdp_bitmap_planar_context_reset(BITMAP_PLANAR_CONTEXT* context)
+BOOL freerdp_bitmap_planar_context_reset(BITMAP_PLANAR_CONTEXT* context)
 {
-       return 1;
+       if (!context)
+               return FALSE;
+
+       return TRUE;
 }
 
 BITMAP_PLANAR_CONTEXT* freerdp_bitmap_planar_context_new(DWORD flags, int maxWidth, int maxHeight)
index 2923660..2c067f9 100644 (file)
@@ -1880,9 +1880,12 @@ int progressive_compress(PROGRESSIVE_CONTEXT* progressive, BYTE* pSrcData, UINT3
        return 1;
 }
 
-int progressive_context_reset(PROGRESSIVE_CONTEXT* progressive)
+BOOL progressive_context_reset(PROGRESSIVE_CONTEXT* progressive)
 {
-       return 1;
+       if (!progressive)
+               return FALSE;
+
+       return TRUE;
 }
 
 PROGRESSIVE_CONTEXT* progressive_context_new(BOOL Compressor)
index e3a36ba..636b830 100644 (file)
@@ -357,6 +357,9 @@ void rfx_context_free(RFX_CONTEXT* context)
 {
        RFX_CONTEXT_PRIV *priv;
 
+       if (!context)
+               return;
+
        assert(NULL != context);
        assert(NULL != context->priv);
        assert(NULL != context->priv->TilePool);
@@ -419,10 +422,17 @@ void rfx_context_set_pixel_format(RFX_CONTEXT* context, RDP_PIXEL_FORMAT pixel_f
        }
 }
 
-void rfx_context_reset(RFX_CONTEXT* context)
+BOOL rfx_context_reset(RFX_CONTEXT* context, UINT32 width, UINT32 height)
 {
+       if (!context)
+               return FALSE;
+
+       context->width = width;
+       context->height = height;
        context->state = RFX_STATE_SEND_HEADERS;
        context->frameIdx = 0;
+
+       return TRUE;
 }
 
 static BOOL rfx_process_message_sync(RFX_CONTEXT* context, wStream* s)
index 31cdbcd..11fbfa1 100644 (file)
@@ -100,13 +100,19 @@ BOOL freerdp_client_codecs_prepare(rdpCodecs* codecs, UINT32 flags)
        return TRUE;
 }
 
-BOOL freerdp_client_codecs_reset(rdpCodecs* codecs, UINT32 flags)
+BOOL freerdp_client_codecs_reset(rdpCodecs* codecs, UINT32 flags,
+                                UINT32 width, UINT32 height)
 {
+       BOOL rc = TRUE;
+
+       if (!freerdp_client_codecs_prepare(codecs, flags))
+               return FALSE;
+
        if (flags & FREERDP_CODEC_INTERLEAVED)
        {
                if (codecs->interleaved)
                {
-                       bitmap_interleaved_context_reset(codecs->interleaved);
+                       rc &= bitmap_interleaved_context_reset(codecs->interleaved);
                }
        }
 
@@ -114,7 +120,7 @@ BOOL freerdp_client_codecs_reset(rdpCodecs* codecs, UINT32 flags)
        {
                if (codecs->planar)
                {
-                       freerdp_bitmap_planar_context_reset(codecs->planar);
+                       rc &= freerdp_bitmap_planar_context_reset(codecs->planar);
                }
        }
 
@@ -122,7 +128,7 @@ BOOL freerdp_client_codecs_reset(rdpCodecs* codecs, UINT32 flags)
        {
                if (codecs->nsc)
                {
-                       nsc_context_reset(codecs->nsc);
+                       rc &= nsc_context_reset(codecs->nsc, width, height);
                }
        }
 
@@ -130,7 +136,7 @@ BOOL freerdp_client_codecs_reset(rdpCodecs* codecs, UINT32 flags)
        {
                if (codecs->rfx)
                {
-                       rfx_context_reset(codecs->rfx);
+                       rc &= rfx_context_reset(codecs->rfx, width, height);
                }
        }
 
@@ -138,7 +144,7 @@ BOOL freerdp_client_codecs_reset(rdpCodecs* codecs, UINT32 flags)
        {
                if (codecs->clear)
                {
-                       clear_context_reset(codecs->clear);
+                       rc &= clear_context_reset(codecs->clear);
                }
        }
 
@@ -151,7 +157,7 @@ BOOL freerdp_client_codecs_reset(rdpCodecs* codecs, UINT32 flags)
        {
                if (codecs->progressive)
                {
-                       progressive_context_reset(codecs->progressive);
+                       rc &= progressive_context_reset(codecs->progressive);
                }
        }
 
@@ -159,11 +165,11 @@ BOOL freerdp_client_codecs_reset(rdpCodecs* codecs, UINT32 flags)
        {
                if (codecs->h264)
                {
-                       h264_context_reset(codecs->h264);
+                       rc &= h264_context_reset(codecs->h264, width, height);
                }
        }
 
-       return TRUE;
+       return rc;
 }
 
 rdpCodecs* codecs_new(rdpContext* context)
index 5d8ba59..79e744c 100644 (file)
@@ -65,14 +65,21 @@ UINT gdi_ResetGraphics(RdpgfxClientContext* context, RDPGFX_RESET_GRAPHICS_PDU*
                if (!surface || !surface->outputMapped)
                        continue;
 
-               freerdp_client_codecs_reset(surface->codecs, FREERDP_CODEC_ALL);
+               if (!freerdp_client_codecs_reset(surface->codecs, FREERDP_CODEC_ALL,
+                                                surface->width, surface->height))
+               {
+                       free (surface);
+                       return ERROR_INTERNAL_ERROR;
+               }
 
                region16_clear(&surface->invalidRegion);
        }
 
        free(pSurfaceIds);
 
-       freerdp_client_codecs_reset(gdi->codecs, FREERDP_CODEC_ALL);
+       if (!freerdp_client_codecs_reset(gdi->codecs, FREERDP_CODEC_ALL,
+                                        gdi->width, gdi->height))
+               return ERROR_INTERNAL_ERROR;
 
        gdi->graphicsReset = TRUE;
 
@@ -722,6 +729,13 @@ UINT gdi_CreateSurface(RdpgfxClientContext* context, RDPGFX_CREATE_SURFACE_PDU*
                return CHANNEL_RC_NO_MEMORY;
        }
 
+       if (!freerdp_client_codecs_reset(surface->codecs, FREERDP_CODEC_ALL,
+                                        createSurface->width, createSurface->height))
+       {
+               free (surface);
+               return ERROR_INTERNAL_ERROR;
+       }
+
        surface->surfaceId = createSurface->surfaceId;
        surface->width = (UINT32) createSurface->width;
        surface->height = (UINT32) createSurface->height;
index 9095f4a..df33640 100644 (file)
@@ -59,9 +59,12 @@ BOOL test_peer_context_new(freerdp_peer* client, testPeerContext* context)
        if (!(context->rfx_context = rfx_context_new(TRUE)))
                goto fail_rfx_context;
 
+       if (!rfx_context_reset(context->rfx_context, SAMPLE_SERVER_DEFAULT_WIDTH,
+                              SAMPLE_SERVER_DEFAULT_HEIGHT))
+               goto fail_rfx_context;
+
        context->rfx_context->mode = RLGR3;
-       context->rfx_context->width = SAMPLE_SERVER_DEFAULT_WIDTH;
-       context->rfx_context->height = SAMPLE_SERVER_DEFAULT_HEIGHT;
+
        rfx_context_set_pixel_format(context->rfx_context, RDP_PIXEL_FORMAT_R8G8B8);
 
        if (!(context->nsc_context = nsc_context_new()))
@@ -613,7 +616,6 @@ BOOL tf_peer_activate(freerdp_peer* client)
 {
        testPeerContext* context = (testPeerContext*) client->context;
 
-       rfx_context_reset(context->rfx_context);
        context->activated = TRUE;
 
        //client->settings->CompressionLevel = PACKET_COMPR_TYPE_8K;
index 1f3edff..b43e4ca 100644 (file)
@@ -34,9 +34,9 @@ int shadow_encoder_preferred_fps(rdpShadowEncoder* encoder)
 
 UINT32 shadow_encoder_inflight_frames(rdpShadowEncoder* encoder)
 {
-       /* Return inflight frame count = 
+       /* Return inflight frame count =
         * <last sent frame id> - <last client-acknowledged frame id>
-        * Note: This function is exported so that subsystem could 
+        * Note: This function is exported so that subsystem could
         * implement its own strategy to tune fps.
         */
        return encoder->frameId - encoder->lastAckframeId;
@@ -136,8 +136,12 @@ int shadow_encoder_init_rfx(rdpShadowEncoder* encoder)
        if (!encoder->rfx)
                encoder->rfx = rfx_context_new(TRUE);
 
+       if (!rfx_context_reset(encoder->rfx, encoder->width, encoder->height))
+               goto fail;
+
        if (!encoder->rfx)
-               return -1;
+               goto fail;
+
 
        encoder->rfx->mode = RLGR3;
        encoder->rfx->width = encoder->width;
@@ -154,6 +158,10 @@ int shadow_encoder_init_rfx(rdpShadowEncoder* encoder)
        encoder->codecs |= FREERDP_CODEC_REMOTEFX;
 
        return 1;
+
+fail:
+       rfx_context_free(encoder->rfx);
+       return -1;
 }
 
 int shadow_encoder_init_nsc(rdpShadowEncoder* encoder)