/** * Function description * * @return 0 on success, otherwise a Win32 error code */ static UINT rdpgfx_on_close(IWTSVirtualChannelCallback* pChannelCallback) { int count; int index; ULONG_PTR* pKeys = NULL; RDPGFX_CHANNEL_CALLBACK* callback = (RDPGFX_CHANNEL_CALLBACK*) pChannelCallback; RDPGFX_PLUGIN* gfx = (RDPGFX_PLUGIN*) callback->plugin; RdpgfxClientContext* context = (RdpgfxClientContext*) gfx->iface.pInterface; WLog_DBG(TAG, "OnClose"); free(callback); gfx->UnacknowledgedFrames = 0; gfx->TotalDecodedFrames = 0; if (gfx->zgfx) { zgfx_context_free(gfx->zgfx); gfx->zgfx = zgfx_context_new(FALSE); if (!gfx->zgfx) return CHANNEL_RC_NO_MEMORY; } count = HashTable_GetKeys(gfx->SurfaceTable, &pKeys); for (index = 0; index < count; index++) { RDPGFX_DELETE_SURFACE_PDU pdu; pdu.surfaceId = ((UINT16) pKeys[index]) - 1; if (context && context->DeleteSurface) { context->DeleteSurface(context, &pdu); } } free(pKeys); for (index = 0; index < gfx->MaxCacheSlot; index++) { if (gfx->CacheSlots[index]) { RDPGFX_EVICT_CACHE_ENTRY_PDU pdu; pdu.cacheSlot = (UINT16) index; if (context && context->EvictCacheEntry) { context->EvictCacheEntry(context, &pdu); } gfx->CacheSlots[index] = NULL; } } return CHANNEL_RC_OK; }
static int test_ZGfxDecompressFoxSingle(void) { int rc = -1; int status; UINT32 Flags; BYTE* pSrcData; UINT32 SrcSize; UINT32 DstSize; BYTE* pDstData = NULL; ZGFX_CONTEXT* zgfx; UINT32 expectedSize; zgfx = zgfx_context_new(TRUE); if (!zgfx) return -1; SrcSize = sizeof(TEST_FOX_DATA_SINGLE) - 1; pSrcData = (BYTE*) TEST_FOX_DATA_SINGLE; Flags = 0; expectedSize = sizeof(TEST_FOX_DATA) - 1; status = zgfx_decompress(zgfx, pSrcData, SrcSize, &pDstData, &DstSize, Flags); if (status < 0) goto fail; printf("flags: 0x%08"PRIX32" size: %"PRIu32"\n", Flags, DstSize); if (DstSize != expectedSize) { printf("test_ZGfxDecompressFoxSingle: output size mismatch: Actual: %"PRIu32", Expected: %"PRIu32"\n", DstSize, expectedSize); goto fail; } if (memcmp(pDstData, TEST_FOX_DATA, DstSize) != 0) { printf("test_ZGfxDecompressFoxSingle: output mismatch\n"); printf("Actual\n"); BitDump(__FUNCTION__, WLOG_INFO, pDstData, DstSize * 8, 0); printf("Expected\n"); BitDump(__FUNCTION__, WLOG_INFO, TEST_FOX_DATA, DstSize * 8, 0); goto fail; } rc = 0; fail: free(pDstData); zgfx_context_free(zgfx); return rc; }
int DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints) { int status = 0; RDPGFX_PLUGIN* gfx; RdpgfxClientContext* context; gfx = (RDPGFX_PLUGIN*) pEntryPoints->GetPlugin(pEntryPoints, "rdpgfx"); if (!gfx) { gfx = (RDPGFX_PLUGIN*) calloc(1, sizeof(RDPGFX_PLUGIN)); if (!gfx) return -1; gfx->log = WLog_Get(TAG); gfx->settings = (rdpSettings*) pEntryPoints->GetRdpSettings(pEntryPoints); gfx->iface.Initialize = rdpgfx_plugin_initialize; gfx->iface.Connected = NULL; gfx->iface.Disconnected = NULL; gfx->iface.Terminated = rdpgfx_plugin_terminated; gfx->SurfaceTable = HashTable_New(TRUE); if (!gfx->SurfaceTable) { free (gfx); return -1; } gfx->ThinClient = gfx->settings->GfxThinClient; gfx->SmallCache = gfx->settings->GfxSmallCache; gfx->Progressive = gfx->settings->GfxProgressive; gfx->ProgressiveV2 = gfx->settings->GfxProgressiveV2; gfx->H264 = gfx->settings->GfxH264; if (gfx->H264) gfx->SmallCache = TRUE; if (gfx->SmallCache) gfx->ThinClient = FALSE; gfx->MaxCacheSlot = (gfx->ThinClient) ? 4096 : 25600; context = (RdpgfxClientContext*) calloc(1, sizeof(RdpgfxClientContext)); if (!context) { free(gfx); return -1; } context->handle = (void*) gfx; context->SetSurfaceData = rdpgfx_set_surface_data; context->GetSurfaceData = rdpgfx_get_surface_data; context->SetCacheSlotData = rdpgfx_set_cache_slot_data; context->GetCacheSlotData = rdpgfx_get_cache_slot_data; gfx->iface.pInterface = (void*) context; gfx->zgfx = zgfx_context_new(FALSE); if (!gfx->zgfx) { free(gfx); free(context); return -1; } status = pEntryPoints->RegisterPlugin(pEntryPoints, "rdpgfx", (IWTSPlugin*) gfx); } return status; }
static BOOL rdpgfx_server_open(RdpgfxServerContext* context) { RdpgfxServerPrivate* priv = (RdpgfxServerPrivate*) context->priv; void* buffer = NULL; if (!priv->isOpened) { PULONG pSessionId = NULL; DWORD BytesReturned = 0; priv->SessionId = WTS_CURRENT_SESSION; if (WTSQuerySessionInformationA(context->vcm, WTS_CURRENT_SESSION, WTSSessionId, (LPSTR*) &pSessionId, &BytesReturned) == FALSE) { WLog_ERR(TAG, "WTSQuerySessionInformationA failed!"); return FALSE; } priv->SessionId = (DWORD) * pSessionId; WTSFreeMemory(pSessionId); priv->rdpgfx_channel = WTSVirtualChannelOpenEx(priv->SessionId, RDPGFX_DVC_CHANNEL_NAME, WTS_CHANNEL_OPTION_DYNAMIC); if (!priv->rdpgfx_channel) { WLog_ERR(TAG, "WTSVirtualChannelOpenEx failed!"); return FALSE; } /* Query for channel event handle */ if (!WTSVirtualChannelQuery(priv->rdpgfx_channel, WTSVirtualEventHandle, &buffer, &BytesReturned) || (BytesReturned != sizeof(HANDLE))) { WLog_ERR(TAG, "WTSVirtualChannelQuery failed " "or invalid returned size(%d)", BytesReturned); if (buffer) WTSFreeMemory(buffer); goto out_close; } CopyMemory(&priv->channelEvent, buffer, sizeof(HANDLE)); WTSFreeMemory(buffer); if (!(priv->zgfx = zgfx_context_new(TRUE))) { WLog_ERR(TAG, "Create zgfx context failed!"); goto out_close; } if (priv->ownThread) { if (!(priv->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL))) { WLog_ERR(TAG, "CreateEvent failed!"); goto out_zgfx; } if (!(priv->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) rdpgfx_server_thread_func, (void*) context, 0, NULL))) { WLog_ERR(TAG, "CreateThread failed!"); goto out_stopEvent; } } priv->isOpened = TRUE; priv->isReady = FALSE; return TRUE; } WLog_ERR(TAG, "RDPGFX channel is already opened!"); return FALSE; out_stopEvent: CloseHandle(priv->stopEvent); priv->stopEvent = NULL; out_zgfx: zgfx_context_free(priv->zgfx); priv->zgfx = NULL; out_close: WTSVirtualChannelClose(priv->rdpgfx_channel); priv->rdpgfx_channel = NULL; priv->channelEvent = NULL; return FALSE; }
static int test_ZGfxCompressConsistent(void) { int rc = -1; int status; UINT32 Flags; BYTE* pSrcData; UINT32 SrcSize; UINT32 DstSize; BYTE* pDstData = NULL; UINT32 DstSize2; BYTE* pDstData2 = NULL; ZGFX_CONTEXT* zgfx; UINT32 expectedSize; BYTE BigBuffer[65536]; memset(BigBuffer, 0xaa, sizeof(BigBuffer)); memcpy(BigBuffer, TEST_FOX_DATA, sizeof(TEST_FOX_DATA) - 1); zgfx = zgfx_context_new(TRUE); if (!zgfx) return -1; /* Compress */ expectedSize = SrcSize = sizeof(BigBuffer); pSrcData = (BYTE*) BigBuffer; Flags = 0; status = zgfx_compress(zgfx, pSrcData, SrcSize, &pDstData2, &DstSize2, &Flags); if (status < 0) goto fail; printf("Compress: flags: 0x%08"PRIX32" size: %"PRIu32"\n", Flags, DstSize2); /* Decompress */ status = zgfx_decompress(zgfx, pDstData2, DstSize2, &pDstData, &DstSize, Flags); if (status < 0) goto fail; printf("Decompress: flags: 0x%08"PRIX32" size: %"PRIu32"\n", Flags, DstSize); if (DstSize != expectedSize) { printf("test_ZGfxDecompressFoxSingle: output size mismatch: Actual: %"PRIu32", Expected: %"PRIu32"\n", DstSize, expectedSize); goto fail; } if (memcmp(pDstData, BigBuffer, DstSize) != 0) { printf("test_ZGfxDecompressFoxSingle: output mismatch\n"); printf("Actual\n"); BitDump(__FUNCTION__, WLOG_INFO, pDstData, 64 * 8, 0); printf("...\n"); BitDump(__FUNCTION__, WLOG_INFO, pDstData + DstSize - 64, 64 * 8, 0); printf("Expected\n"); BitDump(__FUNCTION__, WLOG_INFO, BigBuffer, 64 * 8, 0); printf("...\n"); BitDump(__FUNCTION__, WLOG_INFO, BigBuffer + DstSize - 64, 64 * 8, 0); printf("Middle Result\n"); BitDump(__FUNCTION__, WLOG_INFO, pDstData2, 64 * 8, 0); printf("...\n"); BitDump(__FUNCTION__, WLOG_INFO, pDstData2 + DstSize2 - 64, 64 * 8, 0); goto fail; } rc = 0; fail: free(pDstData); free(pDstData2); zgfx_context_free(zgfx); return rc; }
/** * Function description * * @return 0 on success, otherwise a Win32 error code */ UINT DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints) { UINT error = CHANNEL_RC_OK; RDPGFX_PLUGIN* gfx; RdpgfxClientContext* context; gfx = (RDPGFX_PLUGIN*) pEntryPoints->GetPlugin(pEntryPoints, "rdpgfx"); if (!gfx) { gfx = (RDPGFX_PLUGIN*) calloc(1, sizeof(RDPGFX_PLUGIN)); if (!gfx) { WLog_ERR(TAG, "calloc failed!"); return CHANNEL_RC_NO_MEMORY; } gfx->log = WLog_Get(TAG); if (!gfx->log) { free(gfx); WLog_ERR(TAG, "Failed to acquire reference to WLog %s", TAG); return ERROR_INTERNAL_ERROR; } gfx->settings = (rdpSettings*) pEntryPoints->GetRdpSettings(pEntryPoints); gfx->iface.Initialize = rdpgfx_plugin_initialize; gfx->iface.Connected = NULL; gfx->iface.Disconnected = NULL; gfx->iface.Terminated = rdpgfx_plugin_terminated; gfx->rdpcontext = ((freerdp *)gfx->settings->instance)->context; gfx->SurfaceTable = HashTable_New(TRUE); if (!gfx->SurfaceTable) { free(gfx); WLog_ERR(TAG, "HashTable_New failed!"); return CHANNEL_RC_NO_MEMORY; } gfx->ThinClient = gfx->settings->GfxThinClient; gfx->SmallCache = gfx->settings->GfxSmallCache; gfx->Progressive = gfx->settings->GfxProgressive; gfx->ProgressiveV2 = gfx->settings->GfxProgressiveV2; gfx->H264 = gfx->settings->GfxH264; gfx->AVC444 = gfx->settings->GfxAVC444; gfx->SendQoeAck = gfx->settings->GfxSendQoeAck; if (gfx->H264) gfx->SmallCache = TRUE; gfx->MaxCacheSlot = gfx->SmallCache ? 4096 : 25600; context = (RdpgfxClientContext *)calloc(1, sizeof(RdpgfxClientContext)); if (!context) { free(gfx); WLog_ERR(TAG, "calloc failed!"); return CHANNEL_RC_NO_MEMORY; } context->handle = (void*) gfx; context->GetSurfaceIds = rdpgfx_get_surface_ids; context->SetSurfaceData = rdpgfx_set_surface_data; context->GetSurfaceData = rdpgfx_get_surface_data; context->SetCacheSlotData = rdpgfx_set_cache_slot_data; context->GetCacheSlotData = rdpgfx_get_cache_slot_data; gfx->iface.pInterface = (void*) context; gfx->zgfx = zgfx_context_new(FALSE); if (!gfx->zgfx) { free(gfx); free(context); WLog_ERR(TAG, "zgfx_context_new failed!"); return CHANNEL_RC_NO_MEMORY; } error = pEntryPoints->RegisterPlugin(pEntryPoints, "rdpgfx", (IWTSPlugin*) gfx); } return error; }