Fixed codec reset, now resetting resolution too.

H264 and others require the surface resolution to work properly.
This initializes the codecs and the resolution on reset.
This commit is contained in:
Armin Novak 2016-03-01 16:17:28 +01:00
parent 857c37393b
commit 2e110c7f35
20 changed files with 138 additions and 57 deletions

View 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;

View 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 */

View 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);

View 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);

View 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);

View 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);

View 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 */

View 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);

View 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);

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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)

View 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;

View 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;

View 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)