void test_nsc_encode(void) { int i; uint8* rgb_data; STREAM* enc_stream; NSC_CONTEXT* context; rgb_data = (uint8 *) malloc(64 * 64 * 3); for (i = 0; i < 64; i++) memcpy(rgb_data + i * 64 * 3, rgb_scanline_data, 64 * 3); context = nsc_context_new(); nsc_context_set_cpu_opt(context, CPU_SSE2); nsc_context_set_pixel_format(context, RDP_PIXEL_FORMAT_R8G8B8); enc_stream = stream_new(65536); stream_clear(enc_stream); for (i = 0; i < 30000; i++) { stream_set_pos(enc_stream, 0); nsc_compose_message(context, enc_stream, rgb_data, 64, 64, 64 * 3); } /*freerdp_hexdump(stream_get_head(enc_stream), stream_get_length(enc_stream));*/ nsc_process_message(context, 32, 64, 64, stream_get_head(enc_stream), stream_get_length(enc_stream)); /*freerdp_hexdump(context->bmpdata, 64 * 64 * 4);*/ stream_free(enc_stream); nsc_context_free(context); }
static int shadow_encoder_init_nsc(rdpShadowEncoder* encoder) { rdpContext* context = (rdpContext*) encoder->client; rdpSettings* settings = context->settings; if (!encoder->nsc) encoder->nsc = nsc_context_new(); if (!encoder->nsc) goto fail; if (!nsc_context_reset(encoder->nsc, encoder->width, encoder->height)) goto fail; encoder->nsc->ColorLossLevel = settings->NSCodecColorLossLevel; encoder->nsc->ChromaSubsamplingLevel = settings->NSCodecAllowSubsampling ? 1 : 0; encoder->nsc->DynamicColorFidelity = settings->NSCodecAllowDynamicColorFidelity; nsc_context_set_pixel_format(encoder->nsc, PIXEL_FORMAT_BGRX32); encoder->codecs |= FREERDP_CODEC_NSCODEC; return 1; fail: nsc_context_free(encoder->nsc); return -1; }
int shadow_encoder_init_nsc(rdpShadowEncoder* encoder) { rdpContext* context = (rdpContext*) encoder->client; rdpSettings* settings = context->settings; if (!encoder->nsc) encoder->nsc = nsc_context_new(); if (!encoder->nsc) return -1; nsc_context_set_pixel_format(encoder->nsc, RDP_PIXEL_FORMAT_B8G8R8A8); encoder->fps = 16; encoder->maxFps = 32; encoder->frameId = 0; encoder->lastAckframeId = 0; encoder->frameAck = settings->SurfaceFrameMarkerEnabled; encoder->nsc->ColorLossLevel = settings->NSCodecColorLossLevel; encoder->nsc->ChromaSubsamplingLevel = settings->NSCodecAllowSubsampling ? 1 : 0; encoder->nsc->DynamicColorFidelity = settings->NSCodecAllowDynamicColorFidelity; encoder->codecs |= FREERDP_CODEC_NSCODEC; return 1; }
void test_nsc_encode(void) { int i; BYTE* rgb_data; wStream* enc_stream; NSC_CONTEXT* context; rgb_data = (BYTE *) malloc(64 * 64 * 3); for (i = 0; i < 64; i++) memcpy(rgb_data + i * 64 * 3, rgb_scanline_data, 64 * 3); context = nsc_context_new(); nsc_context_set_pixel_format(context, RDP_PIXEL_FORMAT_R8G8B8); enc_stream = stream_new(65536); stream_clear(enc_stream); for (i = 0; i < 30000; i++) { Stream_SetPosition(enc_stream, 0); nsc_compose_message(context, enc_stream, rgb_data, 64, 64, 64 * 3); } /*winpr_HexDump(Stream_Buffer(enc_stream), Stream_GetPosition(enc_stream));*/ nsc_process_message(context, 32, 64, 64, Stream_Buffer(enc_stream), Stream_GetPosition(enc_stream)); /*winpr_HexDump(context->bmpdata, 64 * 64 * 4);*/ stream_free(enc_stream); nsc_context_free(context); }
int freerds_encoder_init_nsc(rdsEncoder* encoder) { rdpSettings* settings = encoder->connection->settings; if (!encoder->nsc) encoder->nsc = nsc_context_new(); if (!encoder->nsc) return -1; nsc_context_set_pixel_format(encoder->nsc, RDP_PIXEL_FORMAT_B8G8R8A8); if (!encoder->frameList) { encoder->fps = 16; encoder->maxFps = 32; encoder->frameId = 0; encoder->frameList = ListDictionary_New(TRUE); encoder->frameAck = settings->SurfaceFrameMarkerEnabled; } encoder->nsc->ColorLossLevel = settings->NSCodecColorLossLevel; encoder->nsc->ChromaSubsamplingLevel = settings->NSCodecAllowSubsampling ? 1 : 0; encoder->nsc->DynamicColorFidelity = settings->NSCodecAllowDynamicColorFidelity; encoder->codecs |= FREERDP_CODEC_NSCODEC; return 1; }
int xf_ResetGraphics(RdpgfxClientContext* context, RDPGFX_RESET_GRAPHICS_PDU* resetGraphics) { xfContext* xfc = (xfContext*) context->custom; if (xfc->codecs->rfx) { rfx_context_free(xfc->codecs->rfx); xfc->codecs->rfx = NULL; } xfc->codecs->rfx = rfx_context_new(FALSE); xfc->codecs->rfx->width = resetGraphics->width; xfc->codecs->rfx->height = resetGraphics->height; rfx_context_set_pixel_format(xfc->codecs->rfx, RDP_PIXEL_FORMAT_B8G8R8A8); if (xfc->codecs->nsc) { nsc_context_free(xfc->codecs->nsc); xfc->codecs->nsc = NULL; } xfc->codecs->nsc = nsc_context_new(); xfc->codecs->nsc->width = resetGraphics->width; xfc->codecs->nsc->height = resetGraphics->height; nsc_context_set_pixel_format(xfc->codecs->nsc, RDP_PIXEL_FORMAT_B8G8R8A8); if (xfc->codecs->clear) { clear_context_free(xfc->codecs->clear); xfc->codecs->clear = NULL; } xfc->codecs->clear = clear_context_new(FALSE); if (xfc->codecs->h264) { h264_context_free(xfc->codecs->h264); xfc->codecs->h264 = NULL; } xfc->codecs->h264 = h264_context_new(FALSE); if (xfc->codecs->progressive) { progressive_context_free(xfc->codecs->progressive); xfc->codecs->progressive = NULL; } xfc->codecs->progressive = progressive_context_new(TRUE); region16_init(&(xfc->invalidRegion)); xfc->graphicsReset = TRUE; return 1; }
void test_nsc_decode(void) { int i; NSC_CONTEXT* context; context = nsc_context_new(); nsc_process_message(context, 32, 15, 10, (BYTE*) nsc_data, sizeof(nsc_data)); /*winpr_HexDump(context->bmpdata, 15 * 10 * 4);*/ for (i = 0; i < 30000; i++) { nsc_process_message(context, 32, 54, 44, (BYTE*) nsc_stress_data, sizeof(nsc_stress_data)); } nsc_context_free(context); }
void test_nsc_decode(void) { int i; NSC_CONTEXT* context; context = nsc_context_new(); nsc_context_set_cpu_opt(context, CPU_SSE2); nsc_process_message(context, 32, 15, 10, (uint8*) nsc_data, sizeof(nsc_data)); /*freerdp_hexdump(context->bmpdata, 15 * 10 * 4);*/ for (i = 0; i < 30000; i++) { nsc_process_message(context, 32, 54, 44, (uint8*) nsc_stress_data, sizeof(nsc_stress_data)); } nsc_context_free(context); }
void mf_peer_context_new(freerdp_peer* client, mfPeerContext* context) { context->rfx_context = rfx_context_new(); context->rfx_context->mode = RLGR3; context->rfx_context->width = client->settings->DesktopWidth; context->rfx_context->height = client->settings->DesktopHeight; rfx_context_set_pixel_format(context->rfx_context, RDP_PIXEL_FORMAT_R8G8B8); context->nsc_context = nsc_context_new(); nsc_context_set_pixel_format(context->nsc_context, RDP_PIXEL_FORMAT_R8G8B8); context->s = stream_new(0xFFFF); context->vcm = WTSCreateVirtualChannelManager(client); }
void test_peer_context_new(freerdp_peer* client, testPeerContext* context) { context->rfx_context = rfx_context_new(TRUE); 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); context->nsc_context = nsc_context_new(); nsc_context_set_pixel_format(context->nsc_context, RDP_PIXEL_FORMAT_R8G8B8); context->s = Stream_New(NULL, 65536); context->icon_x = -1; context->icon_y = -1; context->vcm = WTSOpenServerA((LPSTR) client->context); }
void test_peer_context_new(freerdp_peer* client, testPeerContext* context) { context->rfx_context = rfx_context_new(); 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); context->nsc_context = nsc_context_new(); nsc_context_set_pixel_format(context->nsc_context, RDP_PIXEL_FORMAT_R8G8B8); context->s = Stream_New(NULL, 65536); context->icon_x = -1; context->icon_y = -1; context->vcm = WTSCreateVirtualChannelManager(client); }
void test_peer_context_new(freerdp_peer* client, testPeerContext* context) { context->rfx_context = rfx_context_new(); context->rfx_context->mode = RLGR3; context->rfx_context->width = client->settings->width; context->rfx_context->height = client->settings->height; rfx_context_set_pixel_format(context->rfx_context, RDP_PIXEL_FORMAT_R8G8B8); context->nsc_context = nsc_context_new(); nsc_context_set_pixel_format(context->nsc_context, RDP_PIXEL_FORMAT_R8G8B8); context->s = stream_new(65536); context->icon_x = -1; context->icon_y = -1; context->vcm = WTSCreateVirtualChannelManager(client); }
BOOL test_peer_context_new(freerdp_peer* client, testPeerContext* context) { if (!(context->rfx_context = rfx_context_new(TRUE))) 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())) goto fail_nsc_context; nsc_context_set_pixel_format(context->nsc_context, RDP_PIXEL_FORMAT_R8G8B8); if (!(context->s = Stream_New(NULL, 65536))) goto fail_stream_new; context->icon_x = -1; context->icon_y = -1; context->vcm = WTSOpenServerA((LPSTR) client->context); if (!context->vcm || context->vcm == INVALID_HANDLE_VALUE) goto fail_open_server; return TRUE; fail_open_server: context->vcm = NULL; Stream_Free(context->s, TRUE); context->s = NULL; fail_stream_new: nsc_context_free(context->nsc_context); context->nsc_context = NULL; fail_nsc_context: rfx_context_free(context->rfx_context); context->rfx_context = NULL; fail_rfx_context: return FALSE; }
int shadow_encoder_init_nsc(rdpShadowEncoder* encoder) { if (!encoder->nsc) encoder->nsc = nsc_context_new(); if (!encoder->nsc) return -1; nsc_context_set_pixel_format(encoder->nsc, RDP_PIXEL_FORMAT_B8G8R8A8); if (!encoder->frameList) { encoder->fps = 16; encoder->maxFps = 32; encoder->frameId = 0; encoder->frameAck = TRUE; encoder->frameList = ListDictionary_New(TRUE); } encoder->codecs |= SHADOW_CODEC_NSCODEC; return 1; }
BOOL freerdp_client_codecs_prepare(rdpCodecs* codecs, UINT32 flags) { if ((flags & FREERDP_CODEC_INTERLEAVED) && !codecs->interleaved) { if (!(codecs->interleaved = bitmap_interleaved_context_new(FALSE))) { WLog_ERR(TAG, "Failed to create interleaved codec context"); return FALSE; } } if ((flags & FREERDP_CODEC_PLANAR) && !codecs->planar) { if (!(codecs->planar = freerdp_bitmap_planar_context_new(FALSE, 64, 64))) { WLog_ERR(TAG, "Failed to create planar bitmap codec context"); return FALSE; } } if ((flags & FREERDP_CODEC_NSCODEC) && !codecs->nsc) { if (!(codecs->nsc = nsc_context_new())) { WLog_ERR(TAG, "Failed to create nsc codec context"); return FALSE; } } if ((flags & FREERDP_CODEC_REMOTEFX) && !codecs->rfx) { if (!(codecs->rfx = rfx_context_new(FALSE))) { WLog_ERR(TAG, "Failed to create rfx codec context"); return FALSE; } } if ((flags & FREERDP_CODEC_CLEARCODEC) && !codecs->clear) { if (!(codecs->clear = clear_context_new(FALSE))) { WLog_ERR(TAG, "Failed to create clear codec context"); return FALSE; } } if (flags & FREERDP_CODEC_ALPHACODEC) { } if ((flags & FREERDP_CODEC_PROGRESSIVE) && !codecs->progressive) { if (!(codecs->progressive = progressive_context_new(FALSE))) { WLog_ERR(TAG, "Failed to create progressive codec context"); return FALSE; } } if ((flags & (FREERDP_CODEC_AVC420 | FREERDP_CODEC_AVC444)) && !codecs->h264) { if (!(codecs->h264 = h264_context_new(FALSE))) { WLog_ERR(TAG, "Failed to create h264 codec context"); return FALSE; } } return TRUE; }
boolean wf_post_connect(freerdp* instance) { rdpGdi* gdi; wfInfo* wfi; rdpCache* cache; wfContext* context; int width, height; wchar_t win_title[64]; rdpSettings* settings; settings = instance->settings; context = (wfContext*) instance->context; cache = instance->context->cache; wfi = context->wfi; wfi->dstBpp = 32; width = settings->width; height = settings->height; if (wfi->sw_gdi) { gdi_init(instance, CLRCONV_ALPHA | CLRCONV_INVERT | CLRBUF_32BPP, NULL); gdi = instance->context->gdi; wfi->hdc = gdi->primary->hdc; wfi->primary = wf_image_new(wfi, width, height, wfi->dstBpp, gdi->primary_buffer); rfx_context_set_cpu_opt(gdi->rfx_context, wfi_detect_cpu()); } else { wf_gdi_register_update_callbacks(instance->update); wfi->srcBpp = instance->settings->color_depth; wfi->primary = wf_image_new(wfi, width, height, wfi->dstBpp, NULL); wfi->hdc = gdi_GetDC(); wfi->hdc->bitsPerPixel = wfi->dstBpp; wfi->hdc->bytesPerPixel = wfi->dstBpp / 8; wfi->hdc->alpha = wfi->clrconv->alpha; wfi->hdc->invert = wfi->clrconv->invert; wfi->hdc->hwnd = (HGDI_WND) xmalloc(sizeof(GDI_WND)); wfi->hdc->hwnd->invalid = gdi_CreateRectRgn(0, 0, 0, 0); wfi->hdc->hwnd->invalid->null = 1; wfi->hdc->hwnd->count = 32; wfi->hdc->hwnd->cinvalid = (HGDI_RGN) xmalloc(sizeof(GDI_RGN) * wfi->hdc->hwnd->count); wfi->hdc->hwnd->ninvalid = 0; wfi->image = wf_bitmap_new(wfi, 64, 64, 32, NULL); wfi->image->_bitmap.data = NULL; if (settings->rfx_codec) { wfi->tile = wf_bitmap_new(wfi, 64, 64, 32, NULL); wfi->rfx_context = rfx_context_new(); rfx_context_set_cpu_opt(wfi->rfx_context, wfi_detect_cpu()); } if (settings->ns_codec) wfi->nsc_context = nsc_context_new(); } if (settings->window_title != NULL) _snwprintf(win_title, sizeof(win_title), L"%S", settings->window_title); else if (settings->port == 3389) _snwprintf(win_title, ARRAY_SIZE(win_title), L"FreeRDP: %S", settings->hostname); else _snwprintf(win_title, ARRAY_SIZE(win_title), L"FreeRDP: %S:%d", settings->hostname, settings->port); if (wfi->hwnd == 0) { wfi->hwnd = CreateWindowEx((DWORD) NULL, g_wnd_class_name, win_title, 0, 0, 0, 0, 0, NULL, NULL, g_hInstance, NULL); SetWindowLongPtr(wfi->hwnd, GWLP_USERDATA, (LONG_PTR) wfi); } if (wfi->fullscreen) { SetWindowLongPtr(wfi->hwnd, GWL_STYLE, WS_POPUP); SetWindowPos(wfi->hwnd, HWND_TOP, 0, 0, width, height, SWP_FRAMECHANGED); } else { POINT diff; RECT rc_client, rc_wnd; SetWindowLongPtr(wfi->hwnd, GWL_STYLE, WS_CAPTION | WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX); /* Now resize to get full canvas size and room for caption and borders */ SetWindowPos(wfi->hwnd, HWND_TOP, 10, 10, width, height, SWP_FRAMECHANGED); GetClientRect(wfi->hwnd, &rc_client); GetWindowRect(wfi->hwnd, &rc_wnd); diff.x = (rc_wnd.right - rc_wnd.left) - rc_client.right; diff.y = (rc_wnd.bottom - rc_wnd.top) - rc_client.bottom; SetWindowPos(wfi->hwnd, HWND_TOP, -1, -1, width + diff.x, height + diff.y, SWP_NOMOVE | SWP_FRAMECHANGED); } BitBlt(wfi->primary->hdc, 0, 0, width, height, NULL, 0, 0, BLACKNESS); wfi->drawing = wfi->primary; ShowWindow(wfi->hwnd, SW_SHOWNORMAL); UpdateWindow(wfi->hwnd); if (wfi->sw_gdi) { instance->update->BeginPaint = wf_sw_begin_paint; instance->update->EndPaint = wf_sw_end_paint; } else { instance->update->BeginPaint = wf_hw_begin_paint; instance->update->EndPaint = wf_hw_end_paint; } pointer_cache_register_callbacks(instance->update); if (wfi->sw_gdi != true) { brush_cache_register_callbacks(instance->update); bitmap_cache_register_callbacks(instance->update); offscreen_cache_register_callbacks(instance->update); } wf_register_graphics(instance->context->graphics); freerdp_channels_post_connect(instance->context->channels, instance); return true; }
BOOL wf_post_connect(freerdp* instance) { rdpGdi* gdi; wfInfo* wfi; rdpCache* cache; wfContext* context; WCHAR lpWindowName[64]; rdpSettings* settings; settings = instance->settings; context = (wfContext*) instance->context; cache = instance->context->cache; wfi = context->wfi; wfi->dstBpp = 32; wfi->width = settings->DesktopWidth; wfi->height = settings->DesktopHeight; if (wfi->sw_gdi) { gdi_init(instance, CLRCONV_ALPHA | CLRCONV_INVERT | CLRBUF_32BPP, NULL); gdi = instance->context->gdi; wfi->hdc = gdi->primary->hdc; wfi->primary = wf_image_new(wfi, wfi->width, wfi->height, wfi->dstBpp, gdi->primary_buffer); } else { wf_gdi_register_update_callbacks(instance->update); wfi->srcBpp = instance->settings->ColorDepth; wfi->primary = wf_image_new(wfi, wfi->width, wfi->height, wfi->dstBpp, NULL); wfi->hdc = gdi_GetDC(); wfi->hdc->bitsPerPixel = wfi->dstBpp; wfi->hdc->bytesPerPixel = wfi->dstBpp / 8; wfi->hdc->alpha = wfi->clrconv->alpha; wfi->hdc->invert = wfi->clrconv->invert; wfi->hdc->hwnd = (HGDI_WND) malloc(sizeof(GDI_WND)); wfi->hdc->hwnd->invalid = gdi_CreateRectRgn(0, 0, 0, 0); wfi->hdc->hwnd->invalid->null = 1; wfi->hdc->hwnd->count = 32; wfi->hdc->hwnd->cinvalid = (HGDI_RGN) malloc(sizeof(GDI_RGN) * wfi->hdc->hwnd->count); wfi->hdc->hwnd->ninvalid = 0; if (settings->RemoteFxCodec) { wfi->tile = wf_image_new(wfi, 64, 64, 32, NULL); wfi->rfx_context = rfx_context_new(); } if (settings->NSCodec) { wfi->nsc_context = nsc_context_new(); } } if (settings->WindowTitle != NULL) _snwprintf(lpWindowName, ARRAYSIZE(lpWindowName), L"%S", settings->WindowTitle); else if (settings->ServerPort == 3389) _snwprintf(lpWindowName, ARRAYSIZE(lpWindowName), L"FreeRDP: %S", settings->ServerHostname); else _snwprintf(lpWindowName, ARRAYSIZE(lpWindowName), L"FreeRDP: %S:%d", settings->ServerHostname, settings->ServerPort); if (!wfi->hwnd) { wfi->hwnd = CreateWindowEx((DWORD) NULL, wfi->wndClassName, lpWindowName, 0, 0, 0, 0, 0, wfi->hWndParent, NULL, wfi->hInstance, NULL); SetWindowLongPtr(wfi->hwnd, GWLP_USERDATA, (LONG_PTR) wfi); } wf_resize_window(wfi); BitBlt(wfi->primary->hdc, 0, 0, wfi->width, wfi->height, NULL, 0, 0, BLACKNESS); wfi->drawing = wfi->primary; ShowWindow(wfi->hwnd, SW_SHOWNORMAL); UpdateWindow(wfi->hwnd); if (wfi->sw_gdi) { instance->update->BeginPaint = wf_sw_begin_paint; instance->update->EndPaint = wf_sw_end_paint; instance->update->DesktopResize = wf_sw_desktop_resize; } else { instance->update->BeginPaint = wf_hw_begin_paint; instance->update->EndPaint = wf_hw_end_paint; instance->update->DesktopResize = wf_hw_desktop_resize; } pointer_cache_register_callbacks(instance->update); if (wfi->sw_gdi != TRUE) { brush_cache_register_callbacks(instance->update); bitmap_cache_register_callbacks(instance->update); offscreen_cache_register_callbacks(instance->update); } wf_register_graphics(instance->context->graphics); freerdp_channels_post_connect(instance->context->channels, instance); wf_cliprdr_init(wfi, instance->context->channels); return TRUE; }