2014-07-11 01:20:41 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
*
|
|
|
|
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2017-02-20 20:31:58 +03:00
|
|
|
* Copyright 2017 Armin Novak <armin.novak@thincast.com>
|
|
|
|
* Copyright 2017 Thincast Technologies GmbH
|
2014-07-11 01:20:41 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2022-02-16 13:20:38 +03:00
|
|
|
#include <freerdp/config.h>
|
2014-07-11 01:20:41 +04:00
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
2021-06-18 11:00:43 +03:00
|
|
|
#include <winpr/assert.h>
|
2014-07-11 01:20:41 +04:00
|
|
|
#include <winpr/file.h>
|
|
|
|
#include <winpr/path.h>
|
|
|
|
#include <winpr/synch.h>
|
|
|
|
#include <winpr/thread.h>
|
2014-07-14 03:42:57 +04:00
|
|
|
#include <winpr/sysinfo.h>
|
2015-04-08 21:13:52 +03:00
|
|
|
#include <winpr/interlocked.h>
|
2014-07-11 01:20:41 +04:00
|
|
|
|
2014-09-12 19:38:12 +04:00
|
|
|
#include <freerdp/log.h>
|
2021-08-25 11:02:46 +03:00
|
|
|
#include <freerdp/channels/drdynvc.h>
|
2014-09-12 19:38:12 +04:00
|
|
|
|
2014-07-11 01:20:41 +04:00
|
|
|
#include "shadow.h"
|
|
|
|
|
2014-09-12 19:38:12 +04:00
|
|
|
#define TAG CLIENT_TAG("shadow")
|
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
typedef struct
|
2016-04-23 20:49:10 +03:00
|
|
|
{
|
|
|
|
BOOL gfxOpened;
|
|
|
|
BOOL gfxSurfaceCreated;
|
2022-02-14 16:59:22 +03:00
|
|
|
} SHADOW_GFX_STATUS;
|
2016-04-23 20:49:10 +03:00
|
|
|
|
2024-08-08 09:37:07 +03:00
|
|
|
/* See https://github.com/FreeRDP/FreeRDP/issues/10413
|
|
|
|
*
|
|
|
|
* Microsoft ditched support for RFX and multiple rectangles in BitmapUpdate for
|
|
|
|
* windows 11 24H2.
|
|
|
|
*
|
|
|
|
* So send all updates only with a single rectangle.
|
|
|
|
*/
|
|
|
|
#define BitmapUpdateProxy(update, context, bitmap) \
|
|
|
|
BitmapUpdateProxyEx((update), (context), (bitmap), __FILE__, __LINE__, __func__)
|
|
|
|
static BOOL BitmapUpdateProxyEx(rdpUpdate* update, rdpContext* context, const BITMAP_UPDATE* bitmap,
|
|
|
|
const char* file, size_t line, const char* fkt)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(update);
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
WINPR_ASSERT(bitmap);
|
|
|
|
|
|
|
|
for (UINT32 x = 0; x < bitmap->number; x++)
|
|
|
|
{
|
|
|
|
BITMAP_UPDATE cur = { 0 };
|
|
|
|
BITMAP_DATA* bmp = &bitmap->rectangles[x];
|
|
|
|
cur.rectangles = bmp;
|
|
|
|
cur.number = 1;
|
|
|
|
cur.skipCompression = bitmap->skipCompression;
|
|
|
|
const BOOL rc = IFCALLRESULT(FALSE, update->BitmapUpdate, context, &cur);
|
|
|
|
if (!rc)
|
|
|
|
{
|
|
|
|
WLog_Print(WLog_Get(TAG), WLOG_ERROR, line, file, fkt,
|
|
|
|
"BitmapUpdate[%" PRIu32 "] failed", x);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-09-20 10:25:13 +03:00
|
|
|
static INLINE BOOL shadow_client_rdpgfx_new_surface(rdpShadowClient* client)
|
2016-04-23 20:49:10 +03:00
|
|
|
{
|
2016-05-03 19:48:59 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2016-04-23 20:49:10 +03:00
|
|
|
RDPGFX_CREATE_SURFACE_PDU createSurface;
|
|
|
|
RDPGFX_MAP_SURFACE_TO_OUTPUT_PDU surfaceToOutput;
|
2024-01-23 18:49:54 +03:00
|
|
|
RdpgfxServerContext* context = NULL;
|
|
|
|
rdpSettings* settings = NULL;
|
2021-06-18 11:00:43 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(client);
|
|
|
|
context = client->rdpgfx;
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
settings = ((rdpContext*)client)->settings;
|
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
2023-10-13 13:04:24 +03:00
|
|
|
WINPR_ASSERT(freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth) <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight) <= UINT16_MAX);
|
|
|
|
createSurface.width = (UINT16)freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
|
|
|
|
createSurface.height = (UINT16)freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
|
2016-08-25 10:47:50 +03:00
|
|
|
createSurface.pixelFormat = GFX_PIXEL_FORMAT_XRGB_8888;
|
2021-07-01 13:59:16 +03:00
|
|
|
createSurface.surfaceId = client->surfaceId;
|
2016-04-23 20:49:10 +03:00
|
|
|
surfaceToOutput.outputOriginX = 0;
|
|
|
|
surfaceToOutput.outputOriginY = 0;
|
2021-07-01 13:59:16 +03:00
|
|
|
surfaceToOutput.surfaceId = client->surfaceId;
|
2016-04-23 20:49:10 +03:00
|
|
|
surfaceToOutput.reserved = 0;
|
2016-08-25 10:47:50 +03:00
|
|
|
IFCALLRET(context->CreateSurface, error, context, &createSurface);
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2016-05-03 19:48:59 +03:00
|
|
|
if (error)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "CreateSurface failed with error %" PRIu32 "", error);
|
2016-05-03 19:48:59 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-08-25 10:47:50 +03:00
|
|
|
IFCALLRET(context->MapSurfaceToOutput, error, context, &surfaceToOutput);
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2016-05-03 19:48:59 +03:00
|
|
|
if (error)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "MapSurfaceToOutput failed with error %" PRIu32 "", error);
|
2016-05-03 19:48:59 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2016-04-23 20:49:10 +03:00
|
|
|
}
|
|
|
|
|
2016-09-20 10:25:13 +03:00
|
|
|
static INLINE BOOL shadow_client_rdpgfx_release_surface(rdpShadowClient* client)
|
2016-04-23 20:49:10 +03:00
|
|
|
{
|
2016-05-03 19:48:59 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2016-04-23 20:49:10 +03:00
|
|
|
RDPGFX_DELETE_SURFACE_PDU pdu;
|
2024-01-23 18:49:54 +03:00
|
|
|
RdpgfxServerContext* context = NULL;
|
2021-07-01 09:01:54 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(client);
|
|
|
|
|
|
|
|
context = client->rdpgfx;
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
|
2021-07-01 13:59:16 +03:00
|
|
|
pdu.surfaceId = client->surfaceId++;
|
2016-05-03 19:48:59 +03:00
|
|
|
IFCALLRET(context->DeleteSurface, error, context, &pdu);
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2016-05-03 19:48:59 +03:00
|
|
|
if (error)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "DeleteSurface failed with error %" PRIu32 "", error);
|
2016-05-03 19:48:59 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2016-04-23 20:49:10 +03:00
|
|
|
}
|
|
|
|
|
2016-09-20 10:25:13 +03:00
|
|
|
static INLINE BOOL shadow_client_rdpgfx_reset_graphic(rdpShadowClient* client)
|
2016-04-23 20:49:10 +03:00
|
|
|
{
|
2016-05-03 19:48:59 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2021-07-01 09:01:54 +03:00
|
|
|
RDPGFX_RESET_GRAPHICS_PDU pdu = { 0 };
|
2024-01-23 18:49:54 +03:00
|
|
|
RdpgfxServerContext* context = NULL;
|
|
|
|
rdpSettings* settings = NULL;
|
2021-07-01 09:01:54 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(client);
|
2021-07-28 10:09:07 +03:00
|
|
|
WINPR_ASSERT(client->rdpgfx);
|
2021-07-01 09:01:54 +03:00
|
|
|
|
|
|
|
context = client->rdpgfx;
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
|
|
|
|
settings = client->context.settings;
|
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
2023-10-13 13:04:24 +03:00
|
|
|
pdu.width = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
|
|
|
|
pdu.height = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
|
2016-04-23 20:49:10 +03:00
|
|
|
pdu.monitorCount = client->subsystem->numMonitors;
|
|
|
|
pdu.monitorDefArray = client->subsystem->monitors;
|
2016-05-03 19:48:59 +03:00
|
|
|
IFCALLRET(context->ResetGraphics, error, context, &pdu);
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2016-05-03 19:48:59 +03:00
|
|
|
if (error)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "ResetGraphics failed with error %" PRIu32 "", error);
|
2016-05-03 19:48:59 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-07-01 11:43:19 +03:00
|
|
|
client->first_frame = TRUE;
|
2016-05-03 19:48:59 +03:00
|
|
|
return TRUE;
|
2016-04-23 20:49:10 +03:00
|
|
|
}
|
|
|
|
|
2016-09-20 10:25:13 +03:00
|
|
|
static INLINE void shadow_client_free_queued_message(void* obj)
|
2015-04-08 21:13:52 +03:00
|
|
|
{
|
2016-09-20 10:25:13 +03:00
|
|
|
wMessage* message = (wMessage*)obj;
|
|
|
|
|
2021-07-01 09:01:54 +03:00
|
|
|
WINPR_ASSERT(message);
|
2015-04-08 21:13:52 +03:00
|
|
|
if (message->Free)
|
|
|
|
{
|
|
|
|
message->Free(message);
|
|
|
|
message->Free = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-28 15:33:35 +03:00
|
|
|
static void shadow_client_context_free(freerdp_peer* peer, rdpContext* context)
|
|
|
|
{
|
|
|
|
rdpShadowClient* client = (rdpShadowClient*)context;
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpShadowServer* server = NULL;
|
2023-01-28 15:33:35 +03:00
|
|
|
|
|
|
|
WINPR_UNUSED(peer);
|
|
|
|
if (!client)
|
|
|
|
return;
|
|
|
|
|
|
|
|
server = client->server;
|
|
|
|
if (server && server->clients)
|
|
|
|
ArrayList_Remove(server->clients, (void*)client);
|
|
|
|
|
2023-03-13 17:50:51 +03:00
|
|
|
shadow_encoder_free(client->encoder);
|
2023-01-28 15:33:35 +03:00
|
|
|
|
|
|
|
/* Clear queued messages and free resource */
|
|
|
|
MessageQueue_Free(client->MsgQueue);
|
2024-08-29 12:11:11 +03:00
|
|
|
WTSCloseServer(client->vcm);
|
2023-01-28 15:33:35 +03:00
|
|
|
region16_uninit(&(client->invalidRegion));
|
|
|
|
DeleteCriticalSection(&(client->lock));
|
2023-03-13 17:50:51 +03:00
|
|
|
|
|
|
|
client->MsgQueue = NULL;
|
|
|
|
client->encoder = NULL;
|
|
|
|
client->vcm = NULL;
|
2023-01-28 15:33:35 +03:00
|
|
|
}
|
|
|
|
|
2021-06-30 14:04:22 +03:00
|
|
|
static BOOL shadow_client_context_new(freerdp_peer* peer, rdpContext* context)
|
2014-07-11 01:20:41 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
BOOL NSCodec = 0;
|
2020-05-05 09:35:19 +03:00
|
|
|
const char bind_address[] = "bind-address,";
|
2021-06-30 14:04:22 +03:00
|
|
|
rdpShadowClient* client = (rdpShadowClient*)context;
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpSettings* settings = NULL;
|
|
|
|
const rdpSettings* srvSettings = NULL;
|
|
|
|
rdpShadowServer* server = NULL;
|
2015-04-08 21:13:52 +03:00
|
|
|
const wObject cb = { NULL, NULL, NULL, shadow_client_free_queued_message, NULL };
|
2021-06-30 14:04:22 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(client);
|
|
|
|
WINPR_ASSERT(peer);
|
2022-03-23 15:18:35 +03:00
|
|
|
WINPR_ASSERT(peer->context);
|
2021-06-30 14:04:22 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
server = (rdpShadowServer*)peer->ContextExtra;
|
2021-06-30 14:04:22 +03:00
|
|
|
WINPR_ASSERT(server);
|
|
|
|
|
2021-07-01 12:40:41 +03:00
|
|
|
srvSettings = server->settings;
|
|
|
|
WINPR_ASSERT(srvSettings);
|
|
|
|
|
2021-07-01 13:59:16 +03:00
|
|
|
client->surfaceId = 1;
|
2014-07-12 03:30:40 +04:00
|
|
|
client->server = server;
|
2014-09-19 01:22:44 +04:00
|
|
|
client->subsystem = server->subsystem;
|
2021-06-30 14:04:22 +03:00
|
|
|
WINPR_ASSERT(client->subsystem);
|
|
|
|
|
2022-03-23 15:18:35 +03:00
|
|
|
settings = peer->context->settings;
|
2021-06-30 14:04:22 +03:00
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
2022-06-22 13:42:48 +03:00
|
|
|
if (!freerdp_settings_set_uint32(settings, FreeRDP_ColorDepth,
|
|
|
|
freerdp_settings_get_uint32(srvSettings, FreeRDP_ColorDepth)))
|
|
|
|
return FALSE;
|
2021-07-01 12:40:41 +03:00
|
|
|
NSCodec = freerdp_settings_get_bool(srvSettings, FreeRDP_NSCodec);
|
2023-10-13 13:04:24 +03:00
|
|
|
if (!freerdp_settings_set_bool(settings, FreeRDP_NSCodec, NSCodec))
|
|
|
|
return FALSE;
|
|
|
|
if (!freerdp_settings_set_bool(settings, FreeRDP_RemoteFxCodec,
|
|
|
|
freerdp_settings_get_bool(srvSettings, FreeRDP_RemoteFxCodec)))
|
|
|
|
return FALSE;
|
2024-07-24 14:18:30 +03:00
|
|
|
if (!freerdp_settings_set_uint32(
|
|
|
|
settings, FreeRDP_RemoteFxRlgrMode,
|
|
|
|
freerdp_settings_get_uint32(srvSettings, FreeRDP_RemoteFxRlgrMode)))
|
|
|
|
return FALSE;
|
2023-10-13 13:04:24 +03:00
|
|
|
if (!freerdp_settings_set_bool(settings, FreeRDP_BitmapCacheV3Enabled, TRUE))
|
|
|
|
return FALSE;
|
|
|
|
if (!freerdp_settings_set_bool(settings, FreeRDP_FrameMarkerCommandEnabled, TRUE))
|
|
|
|
return FALSE;
|
|
|
|
if (!freerdp_settings_set_bool(settings, FreeRDP_SurfaceFrameMarkerEnabled, TRUE))
|
|
|
|
return FALSE;
|
2024-07-23 17:38:18 +03:00
|
|
|
if (!freerdp_settings_set_bool(
|
|
|
|
settings, FreeRDP_SupportGraphicsPipeline,
|
|
|
|
freerdp_settings_get_bool(srvSettings, FreeRDP_SupportGraphicsPipeline)))
|
2023-10-13 13:04:24 +03:00
|
|
|
return FALSE;
|
|
|
|
if (!freerdp_settings_set_bool(settings, FreeRDP_GfxH264,
|
|
|
|
freerdp_settings_get_bool(srvSettings, FreeRDP_GfxH264)))
|
|
|
|
return FALSE;
|
|
|
|
if (!freerdp_settings_set_bool(settings, FreeRDP_DrawAllowSkipAlpha, TRUE))
|
|
|
|
return FALSE;
|
|
|
|
if (!freerdp_settings_set_bool(settings, FreeRDP_DrawAllowColorSubsampling, TRUE))
|
|
|
|
return FALSE;
|
|
|
|
if (!freerdp_settings_set_bool(settings, FreeRDP_DrawAllowDynamicColorFidelity, TRUE))
|
|
|
|
return FALSE;
|
|
|
|
if (!freerdp_settings_set_uint32(settings, FreeRDP_CompressionLevel, PACKET_COMPR_TYPE_RDP8))
|
|
|
|
return FALSE;
|
2014-11-07 21:51:10 +03:00
|
|
|
|
2020-05-05 09:35:19 +03:00
|
|
|
if (server->ipcSocket && (strncmp(bind_address, server->ipcSocket,
|
|
|
|
strnlen(bind_address, sizeof(bind_address))) != 0))
|
2014-11-21 23:10:39 +03:00
|
|
|
{
|
2023-10-13 13:04:24 +03:00
|
|
|
if (!freerdp_settings_set_bool(settings, FreeRDP_LyncRdpMode, TRUE))
|
|
|
|
return FALSE;
|
|
|
|
if (!freerdp_settings_set_bool(settings, FreeRDP_CompressionEnabled, FALSE))
|
|
|
|
return FALSE;
|
2014-11-21 23:10:39 +03:00
|
|
|
}
|
|
|
|
|
2014-07-15 02:01:29 +04:00
|
|
|
client->inLobby = TRUE;
|
|
|
|
client->mayView = server->mayView;
|
|
|
|
client->mayInteract = server->mayInteract;
|
|
|
|
|
2015-04-28 18:00:41 +03:00
|
|
|
if (!InitializeCriticalSectionAndSpinCount(&(client->lock), 4000))
|
2023-01-28 15:33:35 +03:00
|
|
|
goto fail;
|
2014-07-19 01:26:21 +04:00
|
|
|
|
|
|
|
region16_init(&(client->invalidRegion));
|
2024-03-18 12:25:00 +03:00
|
|
|
client->vcm = WTSOpenServerA((LPSTR)peer->context);
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2015-04-28 18:00:41 +03:00
|
|
|
if (!client->vcm || client->vcm == INVALID_HANDLE_VALUE)
|
2023-01-28 15:33:35 +03:00
|
|
|
goto fail;
|
2014-07-15 02:01:29 +04:00
|
|
|
|
2015-04-08 21:13:52 +03:00
|
|
|
if (!(client->MsgQueue = MessageQueue_New(&cb)))
|
2023-01-28 15:33:35 +03:00
|
|
|
goto fail;
|
2014-07-19 01:26:21 +04:00
|
|
|
|
2015-04-28 18:00:41 +03:00
|
|
|
if (!(client->encoder = shadow_encoder_new(client)))
|
2023-01-28 15:33:35 +03:00
|
|
|
goto fail;
|
2014-07-11 01:20:41 +04:00
|
|
|
|
2023-01-28 15:33:35 +03:00
|
|
|
if (!ArrayList_Append(server->clients, (void*)client))
|
|
|
|
goto fail;
|
2021-06-30 14:04:22 +03:00
|
|
|
|
2023-01-28 15:33:35 +03:00
|
|
|
return TRUE;
|
2016-04-23 20:49:10 +03:00
|
|
|
|
2023-01-28 15:33:35 +03:00
|
|
|
fail:
|
2023-01-30 15:00:13 +03:00
|
|
|
shadow_client_context_free(peer, context);
|
2023-01-28 15:33:35 +03:00
|
|
|
return FALSE;
|
2014-07-11 01:20:41 +04:00
|
|
|
}
|
|
|
|
|
2021-06-18 11:00:43 +03:00
|
|
|
static INLINE void shadow_client_mark_invalid(rdpShadowClient* client, UINT32 numRects,
|
2019-11-06 17:24:51 +03:00
|
|
|
const RECTANGLE_16* rects)
|
2014-07-11 01:20:41 +04:00
|
|
|
{
|
2016-04-23 20:49:10 +03:00
|
|
|
RECTANGLE_16 screenRegion;
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpSettings* settings = NULL;
|
2021-07-01 09:01:54 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(client);
|
|
|
|
WINPR_ASSERT(rects || (numRects == 0));
|
|
|
|
|
|
|
|
settings = client->context.settings;
|
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
2016-04-23 20:49:10 +03:00
|
|
|
EnterCriticalSection(&(client->lock));
|
2015-06-28 11:20:49 +03:00
|
|
|
|
2016-04-23 20:49:10 +03:00
|
|
|
/* Mark client invalid region. No rectangle means full screen */
|
|
|
|
if (numRects > 0)
|
2015-06-28 11:20:49 +03:00
|
|
|
{
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 index = 0; index < numRects; index++)
|
2016-04-23 20:49:10 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
region16_union_rect(&(client->invalidRegion), &(client->invalidRegion), &rects[index]);
|
2016-04-23 20:49:10 +03:00
|
|
|
}
|
2015-06-28 11:20:49 +03:00
|
|
|
}
|
2016-04-23 20:49:10 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
screenRegion.left = 0;
|
|
|
|
screenRegion.top = 0;
|
2023-10-13 13:04:24 +03:00
|
|
|
WINPR_ASSERT(freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth) <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight) <= UINT16_MAX);
|
|
|
|
screenRegion.right = (UINT16)freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
|
|
|
|
screenRegion.bottom = (UINT16)freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
|
2019-11-06 17:24:51 +03:00
|
|
|
region16_union_rect(&(client->invalidRegion), &(client->invalidRegion), &screenRegion);
|
2016-04-23 20:49:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
LeaveCriticalSection(&(client->lock));
|
2014-07-11 01:20:41 +04:00
|
|
|
}
|
|
|
|
|
2016-04-23 20:49:10 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
2016-05-03 19:48:59 +03:00
|
|
|
* Recalculate client desktop size and update to rdpSettings
|
2016-04-23 20:49:10 +03:00
|
|
|
*
|
|
|
|
* @return TRUE if width/height changed.
|
|
|
|
*/
|
2016-05-03 19:48:59 +03:00
|
|
|
static INLINE BOOL shadow_client_recalc_desktop_size(rdpShadowClient* client)
|
2015-04-11 21:57:16 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
INT32 width = 0;
|
|
|
|
INT32 height = 0;
|
|
|
|
rdpShadowServer* server = NULL;
|
|
|
|
rdpSettings* settings = NULL;
|
2021-06-18 11:00:43 +03:00
|
|
|
RECTANGLE_16 viewport = { 0 };
|
|
|
|
|
|
|
|
WINPR_ASSERT(client);
|
|
|
|
server = client->server;
|
|
|
|
settings = client->context.settings;
|
|
|
|
|
|
|
|
WINPR_ASSERT(server);
|
|
|
|
WINPR_ASSERT(server->surface);
|
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
|
|
|
WINPR_ASSERT(server->surface->width <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(server->surface->height <= UINT16_MAX);
|
|
|
|
viewport.right = (UINT16)server->surface->width;
|
|
|
|
viewport.bottom = (UINT16)server->surface->height;
|
2015-04-11 21:57:16 +03:00
|
|
|
|
|
|
|
if (server->shareSubRect)
|
|
|
|
{
|
2016-05-03 19:48:59 +03:00
|
|
|
rectangles_intersection(&viewport, &(server->subRect), &viewport);
|
2015-04-11 21:57:16 +03:00
|
|
|
}
|
|
|
|
|
2016-04-23 20:49:10 +03:00
|
|
|
width = viewport.right - viewport.left;
|
|
|
|
height = viewport.bottom - viewport.top;
|
|
|
|
|
2021-06-18 11:00:43 +03:00
|
|
|
WINPR_ASSERT(width >= 0);
|
|
|
|
WINPR_ASSERT(width <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(height >= 0);
|
|
|
|
WINPR_ASSERT(height <= UINT16_MAX);
|
2023-10-13 13:04:24 +03:00
|
|
|
if (freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth) != (UINT32)width ||
|
|
|
|
freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight) != (UINT32)height)
|
2016-04-23 20:49:10 +03:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL shadow_client_capabilities(freerdp_peer* peer)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpShadowSubsystem* subsystem = NULL;
|
|
|
|
rdpShadowClient* client = NULL;
|
2016-05-03 19:48:59 +03:00
|
|
|
BOOL ret = TRUE;
|
2021-07-01 09:01:54 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(peer);
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
client = (rdpShadowClient*)peer->context;
|
2021-07-01 09:01:54 +03:00
|
|
|
WINPR_ASSERT(client);
|
|
|
|
WINPR_ASSERT(client->server);
|
|
|
|
|
2016-04-23 20:49:10 +03:00
|
|
|
subsystem = client->server->subsystem;
|
2021-07-01 09:01:54 +03:00
|
|
|
WINPR_ASSERT(subsystem);
|
|
|
|
|
2016-05-03 19:48:59 +03:00
|
|
|
IFCALLRET(subsystem->ClientCapabilities, ret, subsystem, client);
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2016-05-03 19:48:59 +03:00
|
|
|
if (!ret)
|
|
|
|
WLog_WARN(TAG, "subsystem->ClientCapabilities failed");
|
2016-04-23 20:49:10 +03:00
|
|
|
|
2016-05-03 19:48:59 +03:00
|
|
|
return ret;
|
2015-04-11 21:57:16 +03:00
|
|
|
}
|
|
|
|
|
2022-12-18 19:23:14 +03:00
|
|
|
static void shadow_reset_desktop_resize(rdpShadowClient* client)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(client);
|
|
|
|
client->resizeRequested = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL shadow_send_desktop_resize(rdpShadowClient* client)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
BOOL rc = 0;
|
|
|
|
rdpUpdate* update = NULL;
|
|
|
|
rdpSettings* settings = NULL;
|
|
|
|
const freerdp_peer* peer = NULL;
|
2022-12-18 19:23:14 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(client);
|
|
|
|
|
|
|
|
settings = client->context.settings;
|
|
|
|
peer = client->context.peer;
|
|
|
|
WINPR_ASSERT(peer);
|
|
|
|
WINPR_ASSERT(client->server);
|
|
|
|
WINPR_ASSERT(client->server->surface);
|
|
|
|
|
|
|
|
const UINT32 resizeWidth = client->server->surface->width;
|
|
|
|
const UINT32 resizeHeight = client->server->surface->height;
|
|
|
|
|
|
|
|
if (client->resizeRequested)
|
|
|
|
{
|
|
|
|
if ((resizeWidth == client->resizeWidth) && (resizeHeight == client->resizeHeight))
|
|
|
|
{
|
|
|
|
const UINT32 w = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
|
|
|
|
const UINT32 h = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
|
|
|
|
WLog_WARN(TAG,
|
|
|
|
"detected previous resize request for resolution %" PRIu32 "x%" PRIu32
|
|
|
|
", still have %" PRIu32 "x%" PRIu32 ", disconnecting peer",
|
|
|
|
resizeWidth, resizeHeight, w, h);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
update = client->context.update;
|
|
|
|
WINPR_ASSERT(update);
|
|
|
|
WINPR_ASSERT(update->DesktopResize);
|
|
|
|
|
|
|
|
// Update peer resolution, required so that during disconnect/reconnect the correct resolution
|
|
|
|
// is sent to the client.
|
|
|
|
if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopWidth, resizeWidth))
|
|
|
|
return FALSE;
|
|
|
|
if (!freerdp_settings_set_uint32(settings, FreeRDP_DesktopHeight, resizeHeight))
|
|
|
|
return FALSE;
|
|
|
|
rc = update->DesktopResize(update->context);
|
|
|
|
WLog_INFO(TAG, "Client %s resize requested (%" PRIu32 "x%" PRIu32 "@%" PRIu32 ")",
|
|
|
|
peer->hostname, resizeWidth, resizeHeight,
|
|
|
|
freerdp_settings_get_uint32(settings, FreeRDP_ColorDepth));
|
|
|
|
client->resizeRequested = TRUE;
|
|
|
|
client->resizeWidth = resizeWidth;
|
|
|
|
client->resizeHeight = resizeHeight;
|
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2016-04-23 20:49:10 +03:00
|
|
|
static BOOL shadow_client_post_connect(freerdp_peer* peer)
|
2014-07-11 01:20:41 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
int authStatus = 0;
|
|
|
|
rdpSettings* settings = NULL;
|
|
|
|
rdpShadowClient* client = NULL;
|
|
|
|
rdpShadowServer* server = NULL;
|
|
|
|
rdpShadowSubsystem* subsystem = NULL;
|
2021-07-01 09:01:54 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(peer);
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
client = (rdpShadowClient*)peer->context;
|
2021-07-01 09:01:54 +03:00
|
|
|
WINPR_ASSERT(client);
|
|
|
|
|
2022-03-23 15:18:35 +03:00
|
|
|
settings = peer->context->settings;
|
2021-07-01 09:01:54 +03:00
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
2014-09-11 00:27:24 +04:00
|
|
|
server = client->server;
|
2021-07-01 09:01:54 +03:00
|
|
|
WINPR_ASSERT(server);
|
|
|
|
|
2014-09-27 03:03:48 +04:00
|
|
|
subsystem = server->subsystem;
|
2021-07-01 09:01:54 +03:00
|
|
|
WINPR_ASSERT(subsystem);
|
2014-09-11 00:27:24 +04:00
|
|
|
|
2022-06-22 13:42:48 +03:00
|
|
|
if (freerdp_settings_get_uint32(settings, FreeRDP_ColorDepth) == 24)
|
|
|
|
{
|
|
|
|
if (!freerdp_settings_set_uint32(settings, FreeRDP_ColorDepth, 16)) /* disable 24bpp */
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-07-16 23:12:20 +04:00
|
|
|
|
2023-10-13 13:04:24 +03:00
|
|
|
const UINT32 MultifragMaxRequestSize =
|
|
|
|
freerdp_settings_get_uint32(settings, FreeRDP_MultifragMaxRequestSize);
|
|
|
|
if (MultifragMaxRequestSize < 0x3F0000)
|
2021-07-01 12:40:41 +03:00
|
|
|
{
|
|
|
|
BOOL rc = freerdp_settings_set_bool(
|
|
|
|
settings, FreeRDP_NSCodec,
|
|
|
|
FALSE); /* NSCodec compressor does not support fragmentation yet */
|
|
|
|
WINPR_ASSERT(rc);
|
|
|
|
}
|
2014-10-25 23:36:36 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_INFO(TAG, "Client from %s is activated (%" PRIu32 "x%" PRIu32 "@%" PRIu32 ")",
|
2023-10-13 13:04:24 +03:00
|
|
|
peer->hostname, freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth),
|
|
|
|
freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight),
|
2022-06-22 13:42:48 +03:00
|
|
|
freerdp_settings_get_uint32(settings, FreeRDP_ColorDepth));
|
2014-07-11 01:20:41 +04:00
|
|
|
|
2016-03-07 14:54:49 +03:00
|
|
|
if (shadow_client_channels_post_connect(client) != CHANNEL_RC_OK)
|
|
|
|
return FALSE;
|
2014-07-15 02:01:29 +04:00
|
|
|
|
2016-04-23 20:49:10 +03:00
|
|
|
shadow_client_mark_invalid(client, 0, NULL);
|
2014-09-27 03:03:48 +04:00
|
|
|
authStatus = -1;
|
|
|
|
|
2023-10-13 13:04:24 +03:00
|
|
|
const char* Username = freerdp_settings_get_string(settings, FreeRDP_Username);
|
|
|
|
const char* Domain = freerdp_settings_get_string(settings, FreeRDP_Domain);
|
|
|
|
const char* Password = freerdp_settings_get_string(settings, FreeRDP_Password);
|
2014-09-27 03:03:48 +04:00
|
|
|
|
2023-10-13 13:04:24 +03:00
|
|
|
if (Username && Password)
|
|
|
|
{
|
|
|
|
if (!freerdp_settings_set_bool(settings, FreeRDP_AutoLogonEnabled, TRUE))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (server->authentication && !freerdp_settings_get_bool(settings, FreeRDP_NlaSecurity))
|
2014-09-27 03:03:48 +04:00
|
|
|
{
|
|
|
|
if (subsystem->Authenticate)
|
|
|
|
{
|
2023-10-13 13:04:24 +03:00
|
|
|
authStatus = subsystem->Authenticate(subsystem, client, Username, Domain, Password);
|
2014-09-27 03:03:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (authStatus < 0)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "client authentication failure: %d", authStatus);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-08 20:37:41 +03:00
|
|
|
if (subsystem->ClientConnect)
|
|
|
|
{
|
2015-06-15 14:37:26 +03:00
|
|
|
return subsystem->ClientConnect(subsystem, client);
|
2015-04-08 20:37:41 +03:00
|
|
|
}
|
|
|
|
|
2014-07-11 01:20:41 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2015-04-11 21:57:16 +03:00
|
|
|
/* Convert rects in sub rect coordinate to client/surface coordinate */
|
2019-11-06 17:24:51 +03:00
|
|
|
static INLINE void shadow_client_convert_rects(rdpShadowClient* client, RECTANGLE_16* dst,
|
|
|
|
const RECTANGLE_16* src, UINT32 numRects)
|
2015-04-11 21:57:16 +03:00
|
|
|
{
|
2021-07-01 09:01:54 +03:00
|
|
|
WINPR_ASSERT(client);
|
|
|
|
WINPR_ASSERT(client->server);
|
|
|
|
WINPR_ASSERT(dst);
|
|
|
|
WINPR_ASSERT(src || (numRects == 0));
|
|
|
|
|
2015-04-11 21:57:16 +03:00
|
|
|
if (client->server->shareSubRect)
|
|
|
|
{
|
|
|
|
UINT16 offsetX = client->server->subRect.left;
|
|
|
|
UINT16 offsetY = client->server->subRect.top;
|
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 i = 0; i < numRects; i++)
|
2015-04-11 21:57:16 +03:00
|
|
|
{
|
2021-07-01 09:01:54 +03:00
|
|
|
const RECTANGLE_16* s = &src[i];
|
|
|
|
RECTANGLE_16* d = &dst[i];
|
|
|
|
|
|
|
|
d->left = s->left + offsetX;
|
|
|
|
d->right = s->right + offsetX;
|
|
|
|
d->top = s->top + offsetY;
|
|
|
|
d->bottom = s->bottom + offsetY;
|
2015-04-11 21:57:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-23 20:49:10 +03:00
|
|
|
if (src != dst)
|
|
|
|
{
|
|
|
|
CopyMemory(dst, src, numRects * sizeof(RECTANGLE_16));
|
|
|
|
}
|
2015-04-11 21:57:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-23 20:49:10 +03:00
|
|
|
static BOOL shadow_client_refresh_request(rdpShadowClient* client)
|
2014-09-19 01:22:44 +04:00
|
|
|
{
|
2014-09-19 06:18:58 +04:00
|
|
|
wMessage message = { 0 };
|
2024-01-23 18:49:54 +03:00
|
|
|
wMessagePipe* MsgPipe = NULL;
|
2021-07-01 09:01:54 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(client);
|
|
|
|
WINPR_ASSERT(client->subsystem);
|
|
|
|
|
|
|
|
MsgPipe = client->subsystem->MsgPipe;
|
|
|
|
WINPR_ASSERT(MsgPipe);
|
|
|
|
|
2016-04-23 20:49:10 +03:00
|
|
|
message.id = SHADOW_MSG_IN_REFRESH_REQUEST_ID;
|
|
|
|
message.wParam = NULL;
|
|
|
|
message.lParam = NULL;
|
2019-11-06 17:24:51 +03:00
|
|
|
message.context = (void*)client;
|
2016-04-23 20:49:10 +03:00
|
|
|
message.Free = NULL;
|
|
|
|
return MessageQueue_Dispatch(MsgPipe->In, &message);
|
|
|
|
}
|
2014-09-19 06:18:58 +04:00
|
|
|
|
2020-03-03 15:02:22 +03:00
|
|
|
static BOOL shadow_client_refresh_rect(rdpContext* context, BYTE count, const RECTANGLE_16* areas)
|
2016-04-23 20:49:10 +03:00
|
|
|
{
|
2020-03-03 15:02:22 +03:00
|
|
|
rdpShadowClient* client = (rdpShadowClient*)context;
|
2024-01-23 18:49:54 +03:00
|
|
|
RECTANGLE_16* rects = NULL;
|
2016-04-23 20:49:10 +03:00
|
|
|
|
|
|
|
/* It is invalid if we have area count but no actual area */
|
|
|
|
if (count && !areas)
|
|
|
|
return FALSE;
|
2014-09-19 01:22:44 +04:00
|
|
|
|
2016-04-23 20:49:10 +03:00
|
|
|
if (count)
|
2014-09-19 06:18:58 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
rects = (RECTANGLE_16*)calloc(count, sizeof(RECTANGLE_16));
|
2014-09-19 06:18:58 +04:00
|
|
|
|
2016-04-23 20:49:10 +03:00
|
|
|
if (!rects)
|
2014-11-17 02:21:04 +03:00
|
|
|
{
|
2015-05-23 23:47:18 +03:00
|
|
|
return FALSE;
|
2014-11-17 02:21:04 +03:00
|
|
|
}
|
2014-09-19 06:18:58 +04:00
|
|
|
|
2016-04-23 20:49:10 +03:00
|
|
|
shadow_client_convert_rects(client, rects, areas, count);
|
|
|
|
shadow_client_mark_invalid(client, count, rects);
|
|
|
|
free(rects);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
shadow_client_mark_invalid(client, 0, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return shadow_client_refresh_request(client);
|
2014-09-19 01:22:44 +04:00
|
|
|
}
|
|
|
|
|
2020-03-03 15:02:22 +03:00
|
|
|
static BOOL shadow_client_suppress_output(rdpContext* context, BYTE allow, const RECTANGLE_16* area)
|
2014-09-19 01:22:44 +04:00
|
|
|
{
|
2020-03-03 15:02:22 +03:00
|
|
|
rdpShadowClient* client = (rdpShadowClient*)context;
|
2016-04-23 20:49:10 +03:00
|
|
|
RECTANGLE_16 region;
|
2021-07-01 09:01:54 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(client);
|
|
|
|
|
2016-04-23 20:49:10 +03:00
|
|
|
client->suppressOutput = allow ? FALSE : TRUE;
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2016-04-23 20:49:10 +03:00
|
|
|
if (allow)
|
|
|
|
{
|
|
|
|
if (area)
|
|
|
|
{
|
|
|
|
shadow_client_convert_rects(client, ®ion, area, 1);
|
|
|
|
shadow_client_mark_invalid(client, 1, ®ion);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
shadow_client_mark_invalid(client, 0, NULL);
|
|
|
|
}
|
|
|
|
}
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2016-04-23 20:49:10 +03:00
|
|
|
return shadow_client_refresh_request(client);
|
2014-09-19 01:22:44 +04:00
|
|
|
}
|
|
|
|
|
2016-04-23 20:49:10 +03:00
|
|
|
static BOOL shadow_client_activate(freerdp_peer* peer)
|
2014-07-11 01:20:41 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpSettings* settings = NULL;
|
|
|
|
rdpShadowClient* client = NULL;
|
2021-07-01 09:01:54 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(peer);
|
|
|
|
|
|
|
|
client = (rdpShadowClient*)peer->context;
|
|
|
|
WINPR_ASSERT(client);
|
2014-07-12 08:01:29 +04:00
|
|
|
|
2022-03-23 15:18:35 +03:00
|
|
|
settings = peer->context->settings;
|
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
2022-12-21 19:22:43 +03:00
|
|
|
/* Resize client if necessary */
|
|
|
|
if (shadow_client_recalc_desktop_size(client))
|
|
|
|
return shadow_send_desktop_resize(client);
|
|
|
|
|
|
|
|
shadow_reset_desktop_resize(client);
|
2014-07-12 08:01:29 +04:00
|
|
|
client->activated = TRUE;
|
2014-07-15 02:01:29 +04:00
|
|
|
client->inLobby = client->mayView ? FALSE : TRUE;
|
2014-07-12 08:01:29 +04:00
|
|
|
|
2016-05-03 19:48:59 +03:00
|
|
|
if (shadow_encoder_reset(client->encoder) < 0)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to reset encoder");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-07-15 20:50:47 +04:00
|
|
|
|
2016-04-23 20:49:10 +03:00
|
|
|
/* Update full screen in next update */
|
2020-03-03 15:02:22 +03:00
|
|
|
return shadow_client_refresh_rect(&client->context, 0, NULL);
|
2014-07-11 01:20:41 +04:00
|
|
|
}
|
|
|
|
|
2021-08-27 13:47:46 +03:00
|
|
|
static BOOL shadow_client_logon(freerdp_peer* peer, const SEC_WINNT_AUTH_IDENTITY* identity,
|
2016-09-20 10:25:13 +03:00
|
|
|
BOOL automatic)
|
2016-07-22 00:53:20 +03:00
|
|
|
{
|
2022-03-24 13:05:28 +03:00
|
|
|
BOOL rc = FALSE;
|
2016-07-22 00:53:20 +03:00
|
|
|
char* user = NULL;
|
|
|
|
char* domain = NULL;
|
|
|
|
char* password = NULL;
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpSettings* settings = NULL;
|
2021-07-01 09:01:54 +03:00
|
|
|
|
2021-08-25 11:34:55 +03:00
|
|
|
WINPR_UNUSED(automatic);
|
|
|
|
|
2021-07-01 09:01:54 +03:00
|
|
|
WINPR_ASSERT(peer);
|
|
|
|
WINPR_ASSERT(identity);
|
|
|
|
|
2022-03-23 15:18:35 +03:00
|
|
|
WINPR_ASSERT(peer->context);
|
|
|
|
|
|
|
|
settings = peer->context->settings;
|
2021-07-01 09:01:54 +03:00
|
|
|
WINPR_ASSERT(settings);
|
2016-07-22 00:53:20 +03:00
|
|
|
|
|
|
|
if (identity->Flags & SEC_WINNT_AUTH_IDENTITY_UNICODE)
|
|
|
|
{
|
|
|
|
if (identity->User)
|
2022-10-28 09:09:27 +03:00
|
|
|
user = ConvertWCharNToUtf8Alloc(identity->User, identity->UserLength, NULL);
|
2016-07-22 00:53:20 +03:00
|
|
|
|
|
|
|
if (identity->Domain)
|
2022-10-28 09:09:27 +03:00
|
|
|
domain = ConvertWCharNToUtf8Alloc(identity->Domain, identity->DomainLength, NULL);
|
2016-07-22 00:53:20 +03:00
|
|
|
|
|
|
|
if (identity->Password)
|
2022-10-28 09:09:27 +03:00
|
|
|
password = ConvertWCharNToUtf8Alloc(identity->Password, identity->PasswordLength, NULL);
|
2016-07-22 00:53:20 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (identity->User)
|
2019-11-06 17:24:51 +03:00
|
|
|
user = _strdup((char*)identity->User);
|
2016-07-22 00:53:20 +03:00
|
|
|
|
|
|
|
if (identity->Domain)
|
2019-11-06 17:24:51 +03:00
|
|
|
domain = _strdup((char*)identity->Domain);
|
2016-07-22 00:53:20 +03:00
|
|
|
|
|
|
|
if (identity->Password)
|
2019-11-06 17:24:51 +03:00
|
|
|
password = _strdup((char*)identity->Password);
|
2016-07-22 00:53:20 +03:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if ((identity->User && !user) || (identity->Domain && !domain) ||
|
|
|
|
(identity->Password && !password))
|
2022-03-24 13:05:28 +03:00
|
|
|
goto fail;
|
2016-07-22 16:06:07 +03:00
|
|
|
|
2016-07-22 00:53:20 +03:00
|
|
|
if (user)
|
2022-03-24 13:05:28 +03:00
|
|
|
freerdp_settings_set_string(settings, FreeRDP_Username, user);
|
2016-07-22 00:53:20 +03:00
|
|
|
|
|
|
|
if (domain)
|
2022-03-24 13:05:28 +03:00
|
|
|
freerdp_settings_set_string(settings, FreeRDP_Domain, domain);
|
2016-07-22 00:53:20 +03:00
|
|
|
|
|
|
|
if (password)
|
2022-03-24 13:05:28 +03:00
|
|
|
freerdp_settings_set_string(settings, FreeRDP_Password, password);
|
2016-07-22 00:53:20 +03:00
|
|
|
|
2022-03-24 13:05:28 +03:00
|
|
|
rc = TRUE;
|
|
|
|
fail:
|
2016-07-22 00:53:20 +03:00
|
|
|
free(user);
|
|
|
|
free(domain);
|
|
|
|
free(password);
|
2022-03-24 13:05:28 +03:00
|
|
|
return rc;
|
2016-07-22 00:53:20 +03:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static INLINE void shadow_client_common_frame_acknowledge(rdpShadowClient* client, UINT32 frameId)
|
2014-07-14 03:42:57 +04:00
|
|
|
{
|
2015-04-09 21:33:54 +03:00
|
|
|
/*
|
2016-09-20 10:25:13 +03:00
|
|
|
* Record the last client acknowledged frame id to
|
2015-04-09 21:33:54 +03:00
|
|
|
* calculate how much frames are in progress.
|
2016-05-03 19:48:59 +03:00
|
|
|
* Some rdp clients (win7 mstsc) skips frame ACK if it is
|
|
|
|
* inactive, we should not expect ACK for each frame.
|
2015-04-09 21:33:54 +03:00
|
|
|
* So it is OK to calculate inflight frame count according to
|
|
|
|
* a latest acknowledged frame id.
|
2016-09-20 10:25:13 +03:00
|
|
|
*/
|
2021-07-01 09:01:54 +03:00
|
|
|
WINPR_ASSERT(client);
|
|
|
|
WINPR_ASSERT(client->encoder);
|
2015-04-09 21:33:54 +03:00
|
|
|
client->encoder->lastAckframeId = frameId;
|
2016-05-03 19:48:59 +03:00
|
|
|
}
|
2014-07-14 03:42:57 +04:00
|
|
|
|
2020-03-03 15:02:22 +03:00
|
|
|
static BOOL shadow_client_surface_frame_acknowledge(rdpContext* context, UINT32 frameId)
|
2016-05-03 19:48:59 +03:00
|
|
|
{
|
2020-03-03 15:02:22 +03:00
|
|
|
rdpShadowClient* client = (rdpShadowClient*)context;
|
2016-05-03 19:48:59 +03:00
|
|
|
shadow_client_common_frame_acknowledge(client, frameId);
|
2016-12-09 21:25:50 +03:00
|
|
|
/*
|
|
|
|
* Reset queueDepth for legacy none RDPGFX acknowledge
|
|
|
|
*/
|
2021-07-01 09:01:54 +03:00
|
|
|
WINPR_ASSERT(client);
|
|
|
|
WINPR_ASSERT(client->encoder);
|
2016-12-09 21:25:50 +03:00
|
|
|
client->encoder->queueDepth = QUEUE_DEPTH_UNAVAILABLE;
|
2015-05-23 23:47:18 +03:00
|
|
|
return TRUE;
|
2014-07-14 03:42:57 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static UINT
|
|
|
|
shadow_client_rdpgfx_frame_acknowledge(RdpgfxServerContext* context,
|
|
|
|
const RDPGFX_FRAME_ACKNOWLEDGE_PDU* frameAcknowledge)
|
2014-07-14 03:42:57 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpShadowClient* client = NULL;
|
2021-07-01 09:01:54 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
WINPR_ASSERT(frameAcknowledge);
|
|
|
|
|
|
|
|
client = (rdpShadowClient*)context->custom;
|
2016-12-09 21:25:50 +03:00
|
|
|
shadow_client_common_frame_acknowledge(client, frameAcknowledge->frameId);
|
2021-07-01 09:01:54 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(client);
|
|
|
|
WINPR_ASSERT(client->encoder);
|
2016-12-09 21:25:50 +03:00
|
|
|
client->encoder->queueDepth = frameAcknowledge->queueDepth;
|
2016-08-20 20:02:13 +03:00
|
|
|
return CHANNEL_RC_OK;
|
|
|
|
}
|
2014-07-14 03:42:57 +04:00
|
|
|
|
2019-05-08 12:43:22 +03:00
|
|
|
static BOOL shadow_are_caps_filtered(const rdpSettings* settings, UINT32 caps)
|
|
|
|
{
|
2022-05-25 14:11:29 +03:00
|
|
|
const UINT32 capList[] = { RDPGFX_CAPVERSION_8, RDPGFX_CAPVERSION_81,
|
|
|
|
RDPGFX_CAPVERSION_10, RDPGFX_CAPVERSION_101,
|
|
|
|
RDPGFX_CAPVERSION_102, RDPGFX_CAPVERSION_103,
|
|
|
|
RDPGFX_CAPVERSION_104, RDPGFX_CAPVERSION_105,
|
|
|
|
RDPGFX_CAPVERSION_106, RDPGFX_CAPVERSION_106_ERR,
|
2022-05-24 08:45:03 +03:00
|
|
|
RDPGFX_CAPVERSION_107 };
|
2019-05-08 12:43:22 +03:00
|
|
|
|
2021-07-01 09:01:54 +03:00
|
|
|
WINPR_ASSERT(settings);
|
2023-10-13 13:04:24 +03:00
|
|
|
const UINT32 filter = freerdp_settings_get_uint32(settings, FreeRDP_GfxCapsFilter);
|
2021-07-01 09:01:54 +03:00
|
|
|
|
2023-10-13 13:04:24 +03:00
|
|
|
for (UINT32 x = 0; x < ARRAYSIZE(capList); x++)
|
2019-05-08 12:43:22 +03:00
|
|
|
{
|
|
|
|
if (caps == capList[x])
|
|
|
|
return (filter & (1 << x)) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-07-31 15:01:01 +03:00
|
|
|
static UINT shadow_client_send_caps_confirm(RdpgfxServerContext* context, rdpShadowClient* client,
|
|
|
|
const RDPGFX_CAPS_CONFIRM_PDU* pdu)
|
|
|
|
{
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
WINPR_ASSERT(client);
|
|
|
|
WINPR_ASSERT(pdu);
|
|
|
|
|
|
|
|
WINPR_ASSERT(context->CapsConfirm);
|
2024-01-29 17:02:25 +03:00
|
|
|
UINT rc = context->CapsConfirm(context, pdu);
|
|
|
|
client->areGfxCapsReady = (rc == CHANNEL_RC_OK);
|
|
|
|
return rc;
|
2023-07-31 15:01:01 +03:00
|
|
|
}
|
|
|
|
|
2021-06-30 14:04:22 +03:00
|
|
|
static BOOL shadow_client_caps_test_version(RdpgfxServerContext* context, rdpShadowClient* client,
|
|
|
|
BOOL h264, const RDPGFX_CAPSET* capsSets,
|
|
|
|
UINT32 capsSetCount, UINT32 capsVersion, UINT* rc)
|
2016-09-09 10:31:21 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
const rdpSettings* srvSettings = NULL;
|
|
|
|
rdpSettings* clientSettings = NULL;
|
2021-06-30 14:04:22 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
WINPR_ASSERT(client);
|
|
|
|
WINPR_ASSERT(capsSets || (capsSetCount == 0));
|
|
|
|
WINPR_ASSERT(rc);
|
|
|
|
|
|
|
|
WINPR_ASSERT(context->rdpcontext);
|
|
|
|
srvSettings = context->rdpcontext->settings;
|
|
|
|
WINPR_ASSERT(srvSettings);
|
2016-10-16 11:28:06 +03:00
|
|
|
|
2021-06-30 14:04:22 +03:00
|
|
|
clientSettings = client->context.settings;
|
|
|
|
WINPR_ASSERT(clientSettings);
|
|
|
|
|
|
|
|
if (shadow_are_caps_filtered(srvSettings, capsVersion))
|
2019-05-08 12:43:22 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 index = 0; index < capsSetCount; index++)
|
2017-07-17 12:37:53 +03:00
|
|
|
{
|
2019-05-07 11:22:02 +03:00
|
|
|
const RDPGFX_CAPSET* currentCaps = &capsSets[index];
|
2017-07-17 12:37:53 +03:00
|
|
|
|
2019-05-07 11:22:02 +03:00
|
|
|
if (currentCaps->version == capsVersion)
|
2019-02-27 18:36:15 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 flags = 0;
|
2021-07-01 11:43:19 +03:00
|
|
|
BOOL planar = FALSE;
|
|
|
|
BOOL rfx = FALSE;
|
2021-06-30 14:04:22 +03:00
|
|
|
BOOL avc444v2 = FALSE;
|
|
|
|
BOOL avc444 = FALSE;
|
|
|
|
BOOL avc420 = FALSE;
|
|
|
|
BOOL progressive = FALSE;
|
2019-02-27 18:36:15 +03:00
|
|
|
RDPGFX_CAPSET caps = *currentCaps;
|
2021-06-30 14:04:22 +03:00
|
|
|
RDPGFX_CAPS_CONFIRM_PDU pdu = { 0 };
|
2019-02-27 18:36:15 +03:00
|
|
|
pdu.capsSet = ∩︀
|
|
|
|
|
2021-06-30 14:04:22 +03:00
|
|
|
flags = pdu.capsSet->flags;
|
2019-10-07 10:47:03 +03:00
|
|
|
|
2023-10-13 13:04:24 +03:00
|
|
|
if (!freerdp_settings_set_bool(clientSettings, FreeRDP_GfxSmallCache,
|
|
|
|
(flags & RDPGFX_CAPS_FLAG_SMALL_CACHE) ? TRUE : FALSE))
|
|
|
|
return FALSE;
|
2021-06-30 14:04:22 +03:00
|
|
|
|
|
|
|
avc444v2 = avc444 = !(flags & RDPGFX_CAPS_FLAG_AVC_DISABLED);
|
|
|
|
if (!freerdp_settings_get_bool(srvSettings, FreeRDP_GfxAVC444v2) || !h264)
|
|
|
|
avc444v2 = FALSE;
|
2023-10-13 13:04:24 +03:00
|
|
|
if (!freerdp_settings_set_bool(clientSettings, FreeRDP_GfxAVC444v2, avc444v2))
|
|
|
|
return FALSE;
|
2021-06-30 14:04:22 +03:00
|
|
|
if (!freerdp_settings_get_bool(srvSettings, FreeRDP_GfxAVC444) || !h264)
|
|
|
|
avc444 = FALSE;
|
2023-10-13 13:04:24 +03:00
|
|
|
if (!freerdp_settings_set_bool(clientSettings, FreeRDP_GfxAVC444, avc444))
|
|
|
|
return FALSE;
|
2021-06-30 14:04:22 +03:00
|
|
|
if (!freerdp_settings_get_bool(srvSettings, FreeRDP_GfxH264) || !h264)
|
|
|
|
avc420 = FALSE;
|
2023-10-13 13:04:24 +03:00
|
|
|
if (!freerdp_settings_set_bool(clientSettings, FreeRDP_GfxH264, avc420))
|
|
|
|
return FALSE;
|
2019-02-27 18:36:15 +03:00
|
|
|
|
2021-06-30 14:04:22 +03:00
|
|
|
progressive = freerdp_settings_get_bool(srvSettings, FreeRDP_GfxProgressive);
|
2023-10-13 13:04:24 +03:00
|
|
|
if (!freerdp_settings_set_bool(clientSettings, FreeRDP_GfxProgressive, progressive))
|
|
|
|
return FALSE;
|
2021-06-30 14:04:22 +03:00
|
|
|
progressive = freerdp_settings_get_bool(srvSettings, FreeRDP_GfxProgressiveV2);
|
2023-10-13 13:04:24 +03:00
|
|
|
if (!freerdp_settings_set_bool(clientSettings, FreeRDP_GfxProgressiveV2, progressive))
|
|
|
|
return FALSE;
|
2021-06-30 14:04:22 +03:00
|
|
|
|
2021-07-01 11:43:19 +03:00
|
|
|
rfx = freerdp_settings_get_bool(srvSettings, FreeRDP_RemoteFxCodec);
|
2023-10-13 13:04:24 +03:00
|
|
|
if (!freerdp_settings_set_bool(clientSettings, FreeRDP_RemoteFxCodec, rfx))
|
|
|
|
return FALSE;
|
2021-07-01 11:43:19 +03:00
|
|
|
|
|
|
|
planar = freerdp_settings_get_bool(srvSettings, FreeRDP_GfxPlanar);
|
2023-10-13 13:04:24 +03:00
|
|
|
if (!freerdp_settings_set_bool(clientSettings, FreeRDP_GfxPlanar, planar))
|
|
|
|
return FALSE;
|
2021-07-01 11:43:19 +03:00
|
|
|
|
2021-06-30 14:04:22 +03:00
|
|
|
if (!avc444v2 && !avc444 && !avc420)
|
|
|
|
pdu.capsSet->flags |= RDPGFX_CAPS_FLAG_AVC_DISABLED;
|
|
|
|
|
2023-07-31 15:01:01 +03:00
|
|
|
*rc = shadow_client_send_caps_confirm(context, client, &pdu);
|
2019-05-07 11:22:02 +03:00
|
|
|
return TRUE;
|
2017-07-17 12:37:53 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-07 11:22:02 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
2016-10-16 11:28:06 +03:00
|
|
|
|
2019-05-07 11:22:02 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return 0 on success, otherwise a Win32 error code
|
|
|
|
*/
|
|
|
|
static UINT shadow_client_rdpgfx_caps_advertise(RdpgfxServerContext* context,
|
2019-11-06 17:24:51 +03:00
|
|
|
const RDPGFX_CAPS_ADVERTISE_PDU* capsAdvertise)
|
2019-05-07 11:22:02 +03:00
|
|
|
{
|
2019-10-07 10:47:03 +03:00
|
|
|
UINT rc = ERROR_INTERNAL_ERROR;
|
2024-01-23 18:49:54 +03:00
|
|
|
const rdpSettings* srvSettings = NULL;
|
|
|
|
rdpSettings* clientSettings = NULL;
|
2019-10-07 10:47:03 +03:00
|
|
|
BOOL h264 = FALSE;
|
2021-06-30 14:04:22 +03:00
|
|
|
|
2019-05-07 11:22:02 +03:00
|
|
|
UINT32 flags = 0;
|
2019-10-07 10:47:03 +03:00
|
|
|
|
2021-06-30 14:04:22 +03:00
|
|
|
WINPR_ASSERT(context);
|
|
|
|
WINPR_ASSERT(capsAdvertise);
|
|
|
|
|
2024-01-29 17:02:25 +03:00
|
|
|
rdpShadowClient* client = (rdpShadowClient*)context->custom;
|
2021-06-30 14:04:22 +03:00
|
|
|
WINPR_ASSERT(client);
|
|
|
|
WINPR_ASSERT(context->rdpcontext);
|
2019-10-07 10:47:03 +03:00
|
|
|
|
2021-06-30 14:04:22 +03:00
|
|
|
srvSettings = context->rdpcontext->settings;
|
|
|
|
WINPR_ASSERT(srvSettings);
|
|
|
|
|
|
|
|
clientSettings = client->context.settings;
|
|
|
|
WINPR_ASSERT(clientSettings);
|
|
|
|
|
|
|
|
#ifdef WITH_GFX_H264
|
|
|
|
h264 =
|
|
|
|
(shadow_encoder_prepare(client->encoder, FREERDP_CODEC_AVC420 | FREERDP_CODEC_AVC444) >= 0);
|
|
|
|
#else
|
|
|
|
freerdp_settings_set_bool(clientSettings, FreeRDP_GfxAVC444v2, FALSE);
|
|
|
|
freerdp_settings_set_bool(clientSettings, FreeRDP_GfxAVC444, FALSE);
|
|
|
|
freerdp_settings_set_bool(clientSettings, FreeRDP_GfxH264, FALSE);
|
2019-10-07 10:47:03 +03:00
|
|
|
#endif
|
|
|
|
|
2019-05-07 11:22:02 +03:00
|
|
|
/* Request full screen update for new gfx channel */
|
2020-03-03 15:02:22 +03:00
|
|
|
if (!shadow_client_refresh_rect(&client->context, 0, NULL))
|
2019-10-07 10:47:03 +03:00
|
|
|
return rc;
|
2017-07-17 10:00:57 +03:00
|
|
|
|
2022-05-24 08:45:03 +03:00
|
|
|
if (shadow_client_caps_test_version(context, client, h264, capsAdvertise->capsSets,
|
|
|
|
capsAdvertise->capsSetCount, RDPGFX_CAPVERSION_107, &rc))
|
|
|
|
return rc;
|
|
|
|
|
2021-06-30 14:04:22 +03:00
|
|
|
if (shadow_client_caps_test_version(context, client, h264, capsAdvertise->capsSets,
|
2019-11-06 17:24:51 +03:00
|
|
|
capsAdvertise->capsSetCount, RDPGFX_CAPVERSION_106, &rc))
|
2019-05-07 11:22:02 +03:00
|
|
|
return rc;
|
2016-10-16 11:28:06 +03:00
|
|
|
|
2022-05-25 14:11:29 +03:00
|
|
|
if (shadow_client_caps_test_version(context, client, h264, capsAdvertise->capsSets,
|
|
|
|
capsAdvertise->capsSetCount, RDPGFX_CAPVERSION_106_ERR,
|
|
|
|
&rc))
|
|
|
|
return rc;
|
|
|
|
|
2021-06-30 14:04:22 +03:00
|
|
|
if (shadow_client_caps_test_version(context, client, h264, capsAdvertise->capsSets,
|
2019-11-06 17:24:51 +03:00
|
|
|
capsAdvertise->capsSetCount, RDPGFX_CAPVERSION_105, &rc))
|
2019-05-07 11:22:02 +03:00
|
|
|
return rc;
|
2016-09-09 10:31:21 +03:00
|
|
|
|
2021-06-30 14:04:22 +03:00
|
|
|
if (shadow_client_caps_test_version(context, client, h264, capsAdvertise->capsSets,
|
2019-11-06 17:24:51 +03:00
|
|
|
capsAdvertise->capsSetCount, RDPGFX_CAPVERSION_104, &rc))
|
2019-05-07 11:22:02 +03:00
|
|
|
return rc;
|
2016-10-16 11:28:06 +03:00
|
|
|
|
2021-06-30 14:04:22 +03:00
|
|
|
if (shadow_client_caps_test_version(context, client, h264, capsAdvertise->capsSets,
|
2019-11-06 17:24:51 +03:00
|
|
|
capsAdvertise->capsSetCount, RDPGFX_CAPVERSION_103, &rc))
|
2019-05-07 11:22:02 +03:00
|
|
|
return rc;
|
2017-07-17 10:00:57 +03:00
|
|
|
|
2021-06-30 14:04:22 +03:00
|
|
|
if (shadow_client_caps_test_version(context, client, h264, capsAdvertise->capsSets,
|
2019-11-06 17:24:51 +03:00
|
|
|
capsAdvertise->capsSetCount, RDPGFX_CAPVERSION_102, &rc))
|
2019-05-07 11:22:02 +03:00
|
|
|
return rc;
|
2016-09-09 10:31:21 +03:00
|
|
|
|
2021-06-30 14:04:22 +03:00
|
|
|
if (shadow_client_caps_test_version(context, client, h264, capsAdvertise->capsSets,
|
2019-11-06 17:24:51 +03:00
|
|
|
capsAdvertise->capsSetCount, RDPGFX_CAPVERSION_101, &rc))
|
2019-05-07 11:22:02 +03:00
|
|
|
return rc;
|
|
|
|
|
2021-06-30 14:04:22 +03:00
|
|
|
if (shadow_client_caps_test_version(context, client, h264, capsAdvertise->capsSets,
|
2019-11-06 17:24:51 +03:00
|
|
|
capsAdvertise->capsSetCount, RDPGFX_CAPVERSION_10, &rc))
|
2019-05-07 11:22:02 +03:00
|
|
|
return rc;
|
2016-10-16 11:28:06 +03:00
|
|
|
|
2021-06-30 14:04:22 +03:00
|
|
|
if (!shadow_are_caps_filtered(srvSettings, RDPGFX_CAPVERSION_81))
|
2016-09-09 10:31:21 +03:00
|
|
|
{
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 index = 0; index < capsAdvertise->capsSetCount; index++)
|
2018-01-31 17:08:11 +03:00
|
|
|
{
|
2019-05-08 12:43:22 +03:00
|
|
|
const RDPGFX_CAPSET* currentCaps = &capsAdvertise->capsSets[index];
|
2017-07-17 10:00:57 +03:00
|
|
|
|
2019-05-08 12:43:22 +03:00
|
|
|
if (currentCaps->version == RDPGFX_CAPVERSION_81)
|
2016-09-09 10:31:21 +03:00
|
|
|
{
|
2019-05-08 12:43:22 +03:00
|
|
|
RDPGFX_CAPSET caps = *currentCaps;
|
|
|
|
RDPGFX_CAPS_CONFIRM_PDU pdu;
|
|
|
|
pdu.capsSet = ∩︀
|
|
|
|
|
2021-07-01 09:08:27 +03:00
|
|
|
flags = pdu.capsSet->flags;
|
2021-06-30 14:04:22 +03:00
|
|
|
|
2021-07-01 09:08:27 +03:00
|
|
|
freerdp_settings_set_bool(clientSettings, FreeRDP_GfxAVC444v2, FALSE);
|
|
|
|
freerdp_settings_set_bool(clientSettings, FreeRDP_GfxAVC444, FALSE);
|
2021-06-30 14:04:22 +03:00
|
|
|
|
2021-07-01 09:08:27 +03:00
|
|
|
freerdp_settings_set_bool(clientSettings, FreeRDP_GfxThinClient,
|
2023-07-04 10:26:52 +03:00
|
|
|
(flags & RDPGFX_CAPS_FLAG_THINCLIENT) ? TRUE : FALSE);
|
2021-07-01 09:08:27 +03:00
|
|
|
freerdp_settings_set_bool(clientSettings, FreeRDP_GfxSmallCache,
|
2023-07-04 10:26:52 +03:00
|
|
|
(flags & RDPGFX_CAPS_FLAG_SMALL_CACHE) ? TRUE : FALSE);
|
2021-06-30 14:04:22 +03:00
|
|
|
|
2017-07-17 10:00:57 +03:00
|
|
|
#ifndef WITH_GFX_H264
|
2021-07-01 09:08:27 +03:00
|
|
|
freerdp_settings_set_bool(clientSettings, FreeRDP_GfxH264, FALSE);
|
|
|
|
pdu.capsSet->flags &= ~RDPGFX_CAPS_FLAG_AVC420_ENABLED;
|
2017-07-17 10:00:57 +03:00
|
|
|
#else
|
2021-06-30 14:04:22 +03:00
|
|
|
|
2021-07-01 09:08:27 +03:00
|
|
|
if (h264)
|
|
|
|
freerdp_settings_set_bool(clientSettings, FreeRDP_GfxH264,
|
2023-07-04 10:26:52 +03:00
|
|
|
(flags & RDPGFX_CAPS_FLAG_AVC420_ENABLED) ? TRUE
|
|
|
|
: FALSE);
|
2021-07-01 09:08:27 +03:00
|
|
|
else
|
|
|
|
freerdp_settings_set_bool(clientSettings, FreeRDP_GfxH264, FALSE);
|
2017-07-17 10:00:57 +03:00
|
|
|
#endif
|
2016-09-09 10:31:21 +03:00
|
|
|
|
2023-07-31 15:01:01 +03:00
|
|
|
return shadow_client_send_caps_confirm(context, client, &pdu);
|
2019-05-08 12:43:22 +03:00
|
|
|
}
|
2016-09-09 10:31:21 +03:00
|
|
|
}
|
|
|
|
}
|
2016-10-16 11:28:06 +03:00
|
|
|
|
2021-06-30 14:04:22 +03:00
|
|
|
if (!shadow_are_caps_filtered(srvSettings, RDPGFX_CAPVERSION_8))
|
2016-09-09 10:31:21 +03:00
|
|
|
{
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 index = 0; index < capsAdvertise->capsSetCount; index++)
|
2016-09-09 10:31:21 +03:00
|
|
|
{
|
2019-05-08 12:43:22 +03:00
|
|
|
const RDPGFX_CAPSET* currentCaps = &capsAdvertise->capsSets[index];
|
2017-07-17 10:00:57 +03:00
|
|
|
|
2019-05-08 12:43:22 +03:00
|
|
|
if (currentCaps->version == RDPGFX_CAPVERSION_8)
|
2016-09-09 10:31:21 +03:00
|
|
|
{
|
2019-05-08 12:43:22 +03:00
|
|
|
RDPGFX_CAPSET caps = *currentCaps;
|
|
|
|
RDPGFX_CAPS_CONFIRM_PDU pdu;
|
|
|
|
pdu.capsSet = ∩︀
|
2021-06-30 14:04:22 +03:00
|
|
|
flags = pdu.capsSet->flags;
|
2019-05-08 12:43:22 +03:00
|
|
|
|
2021-06-30 14:04:22 +03:00
|
|
|
freerdp_settings_set_bool(clientSettings, FreeRDP_GfxAVC444v2, FALSE);
|
|
|
|
freerdp_settings_set_bool(clientSettings, FreeRDP_GfxAVC444, FALSE);
|
|
|
|
freerdp_settings_set_bool(clientSettings, FreeRDP_GfxH264, FALSE);
|
2019-05-08 12:43:22 +03:00
|
|
|
|
2021-06-30 14:04:22 +03:00
|
|
|
freerdp_settings_set_bool(clientSettings, FreeRDP_GfxThinClient,
|
2023-07-04 10:26:52 +03:00
|
|
|
(flags & RDPGFX_CAPS_FLAG_THINCLIENT) ? TRUE : FALSE);
|
2021-06-30 14:04:22 +03:00
|
|
|
freerdp_settings_set_bool(clientSettings, FreeRDP_GfxSmallCache,
|
2023-07-04 10:26:52 +03:00
|
|
|
(flags & RDPGFX_CAPS_FLAG_SMALL_CACHE) ? TRUE : FALSE);
|
2021-06-30 14:04:22 +03:00
|
|
|
|
2023-07-31 15:01:01 +03:00
|
|
|
return shadow_client_send_caps_confirm(context, client, &pdu);
|
2016-09-09 10:31:21 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return CHANNEL_RC_UNSUPPORTED_VERSION;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static INLINE UINT32 rdpgfx_estimate_h264_avc420(RDPGFX_AVC420_BITMAP_STREAM* havc420)
|
2017-08-02 10:42:04 +03:00
|
|
|
{
|
|
|
|
/* H264 metadata + H264 stream. See rdpgfx_write_h264_avc420 */
|
2021-07-01 09:01:54 +03:00
|
|
|
WINPR_ASSERT(havc420);
|
2017-08-02 10:42:04 +03:00
|
|
|
return sizeof(UINT32) /* numRegionRects */
|
2024-08-26 17:33:59 +03:00
|
|
|
+ 10ULL /* regionRects + quantQualityVals */
|
2019-11-06 17:24:51 +03:00
|
|
|
* havc420->meta.numRegionRects +
|
|
|
|
havc420->length;
|
2017-08-02 10:42:04 +03:00
|
|
|
}
|
2016-09-09 10:31:21 +03:00
|
|
|
|
2016-05-03 19:48:59 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return TRUE on success
|
|
|
|
*/
|
2021-07-01 11:43:19 +03:00
|
|
|
static BOOL shadow_client_send_surface_gfx(rdpShadowClient* client, const BYTE* pSrcData,
|
2021-07-01 09:08:27 +03:00
|
|
|
UINT32 nSrcStep, UINT32 SrcFormat, UINT16 nXSrc,
|
|
|
|
UINT16 nYSrc, UINT16 nWidth, UINT16 nHeight)
|
2016-04-23 20:49:10 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 id = 0;
|
2016-05-03 19:48:59 +03:00
|
|
|
UINT error = CHANNEL_RC_OK;
|
2021-06-30 14:04:22 +03:00
|
|
|
const rdpContext* context = (const rdpContext*)client;
|
2024-01-23 18:49:54 +03:00
|
|
|
const rdpSettings* settings = NULL;
|
|
|
|
rdpShadowEncoder* encoder = NULL;
|
2021-07-01 13:59:16 +03:00
|
|
|
RDPGFX_SURFACE_COMMAND cmd = { 0 };
|
|
|
|
RDPGFX_START_FRAME_PDU cmdstart = { 0 };
|
|
|
|
RDPGFX_END_FRAME_PDU cmdend = { 0 };
|
|
|
|
SYSTEMTIME sTime = { 0 };
|
2016-12-14 00:47:08 +03:00
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
if (!context || !pSrcData)
|
|
|
|
return FALSE;
|
|
|
|
|
2016-04-23 20:49:10 +03:00
|
|
|
settings = context->settings;
|
|
|
|
encoder = client->encoder;
|
2016-12-14 00:47:08 +03:00
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
if (!settings || !encoder)
|
|
|
|
return FALSE;
|
|
|
|
|
2021-07-01 11:43:19 +03:00
|
|
|
if (client->first_frame)
|
|
|
|
{
|
|
|
|
rfx_context_reset(encoder->rfx, nWidth, nHeight);
|
|
|
|
client->first_frame = FALSE;
|
|
|
|
}
|
|
|
|
|
2016-04-23 20:49:10 +03:00
|
|
|
cmdstart.frameId = shadow_encoder_create_frame_id(encoder);
|
|
|
|
GetSystemTime(&sTime);
|
2021-06-18 11:00:43 +03:00
|
|
|
cmdstart.timestamp = (UINT32)(sTime.wHour << 22U | sTime.wMinute << 16U | sTime.wSecond << 10U |
|
|
|
|
sTime.wMilliseconds);
|
2016-04-23 20:49:10 +03:00
|
|
|
cmdend.frameId = cmdstart.frameId;
|
2021-07-01 13:59:16 +03:00
|
|
|
cmd.surfaceId = client->surfaceId;
|
2016-09-20 10:25:13 +03:00
|
|
|
cmd.format = PIXEL_FORMAT_BGRX32;
|
2016-04-23 20:49:10 +03:00
|
|
|
cmd.left = nXSrc;
|
|
|
|
cmd.top = nYSrc;
|
|
|
|
cmd.right = cmd.left + nWidth;
|
|
|
|
cmd.bottom = cmd.top + nHeight;
|
|
|
|
cmd.width = nWidth;
|
|
|
|
cmd.height = nHeight;
|
|
|
|
|
2021-07-01 11:43:19 +03:00
|
|
|
id = freerdp_settings_get_uint32(settings, FreeRDP_RemoteFxCodecId);
|
2023-03-06 15:07:11 +03:00
|
|
|
#ifdef WITH_GFX_H264
|
2023-10-13 13:04:24 +03:00
|
|
|
const BOOL GfxH264 = freerdp_settings_get_bool(settings, FreeRDP_GfxH264);
|
|
|
|
const BOOL GfxAVC444 = freerdp_settings_get_bool(settings, FreeRDP_GfxAVC444);
|
|
|
|
const BOOL GfxAVC444v2 = freerdp_settings_get_bool(settings, FreeRDP_GfxAVC444v2);
|
|
|
|
if (GfxAVC444 || GfxAVC444v2)
|
2017-08-02 10:42:04 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
INT32 rc = 0;
|
2020-11-20 14:37:21 +03:00
|
|
|
RDPGFX_AVC444_BITMAP_STREAM avc444 = { 0 };
|
|
|
|
RECTANGLE_16 regionRect = { 0 };
|
2023-10-13 13:04:24 +03:00
|
|
|
BYTE version = GfxAVC444v2 ? 2 : 1;
|
2017-08-02 10:42:04 +03:00
|
|
|
|
|
|
|
if (shadow_encoder_prepare(encoder, FREERDP_CODEC_AVC444) < 0)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to prepare encoder FREERDP_CODEC_AVC444");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2021-06-18 11:00:43 +03:00
|
|
|
WINPR_ASSERT(cmd.left <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(cmd.top <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(cmd.right <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(cmd.bottom <= UINT16_MAX);
|
|
|
|
regionRect.left = (UINT16)cmd.left;
|
|
|
|
regionRect.top = (UINT16)cmd.top;
|
|
|
|
regionRect.right = (UINT16)cmd.right;
|
|
|
|
regionRect.bottom = (UINT16)cmd.bottom;
|
2020-11-20 14:37:21 +03:00
|
|
|
rc = avc444_compress(encoder->h264, pSrcData, cmd.format, nSrcStep, nWidth, nHeight,
|
|
|
|
version, ®ionRect, &avc444.LC, &avc444.bitstream[0].data,
|
|
|
|
&avc444.bitstream[0].length, &avc444.bitstream[1].data,
|
|
|
|
&avc444.bitstream[1].length, &avc444.bitstream[0].meta,
|
|
|
|
&avc444.bitstream[1].meta);
|
|
|
|
if (rc < 0)
|
2017-08-18 20:19:44 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "avc420_compress failed for avc444");
|
2017-08-02 10:42:04 +03:00
|
|
|
return FALSE;
|
2017-08-18 20:19:44 +03:00
|
|
|
}
|
2017-08-02 10:42:04 +03:00
|
|
|
|
2020-11-20 14:37:21 +03:00
|
|
|
/* rc > 0 means new data */
|
|
|
|
if (rc > 0)
|
|
|
|
{
|
|
|
|
avc444.cbAvc420EncodedBitstream1 = rdpgfx_estimate_h264_avc420(&avc444.bitstream[0]);
|
2023-10-13 13:04:24 +03:00
|
|
|
cmd.codecId = GfxAVC444v2 ? RDPGFX_CODECID_AVC444v2 : RDPGFX_CODECID_AVC444;
|
2020-11-20 14:37:21 +03:00
|
|
|
cmd.extra = (void*)&avc444;
|
|
|
|
IFCALLRET(client->rdpgfx->SurfaceFrameCommand, error, client->rdpgfx, &cmd, &cmdstart,
|
|
|
|
&cmdend);
|
|
|
|
}
|
2017-08-02 10:42:04 +03:00
|
|
|
|
2020-11-20 14:37:21 +03:00
|
|
|
free_h264_metablock(&avc444.bitstream[0].meta);
|
|
|
|
free_h264_metablock(&avc444.bitstream[1].meta);
|
2017-08-02 10:42:04 +03:00
|
|
|
if (error)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "SurfaceFrameCommand failed with error %" PRIu32 "", error);
|
2017-08-02 10:42:04 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2023-10-13 13:04:24 +03:00
|
|
|
else if (GfxH264)
|
2016-04-23 20:49:10 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
INT32 rc = 0;
|
2020-11-20 14:37:21 +03:00
|
|
|
RDPGFX_AVC420_BITMAP_STREAM avc420 = { 0 };
|
2016-04-23 20:49:10 +03:00
|
|
|
RECTANGLE_16 regionRect;
|
|
|
|
|
2016-05-03 19:48:59 +03:00
|
|
|
if (shadow_encoder_prepare(encoder, FREERDP_CODEC_AVC420) < 0)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to prepare encoder FREERDP_CODEC_AVC420");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2016-04-23 20:49:10 +03:00
|
|
|
|
2021-06-18 11:00:43 +03:00
|
|
|
WINPR_ASSERT(cmd.left <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(cmd.top <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(cmd.right <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(cmd.bottom <= UINT16_MAX);
|
|
|
|
regionRect.left = (UINT16)cmd.left;
|
|
|
|
regionRect.top = (UINT16)cmd.top;
|
|
|
|
regionRect.right = (UINT16)cmd.right;
|
|
|
|
regionRect.bottom = (UINT16)cmd.bottom;
|
2020-11-20 14:37:21 +03:00
|
|
|
rc = avc420_compress(encoder->h264, pSrcData, cmd.format, nSrcStep, nWidth, nHeight,
|
|
|
|
®ionRect, &avc420.data, &avc420.length, &avc420.meta);
|
|
|
|
if (rc < 0)
|
2017-08-18 20:19:44 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "avc420_compress failed");
|
2017-08-02 10:42:04 +03:00
|
|
|
return FALSE;
|
2017-08-18 20:19:44 +03:00
|
|
|
}
|
2017-08-02 10:42:04 +03:00
|
|
|
|
2020-11-20 14:37:21 +03:00
|
|
|
/* rc > 0 means new data */
|
|
|
|
if (rc > 0)
|
|
|
|
{
|
|
|
|
cmd.codecId = RDPGFX_CODECID_AVC420;
|
|
|
|
cmd.extra = (void*)&avc420;
|
|
|
|
|
|
|
|
IFCALLRET(client->rdpgfx->SurfaceFrameCommand, error, client->rdpgfx, &cmd, &cmdstart,
|
|
|
|
&cmdend);
|
|
|
|
}
|
|
|
|
free_h264_metablock(&avc420.meta);
|
2016-04-23 20:49:10 +03:00
|
|
|
|
2016-05-03 19:48:59 +03:00
|
|
|
if (error)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "SurfaceFrameCommand failed with error %" PRIu32 "", error);
|
2016-05-03 19:48:59 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
2016-04-23 20:49:10 +03:00
|
|
|
}
|
2023-03-06 15:07:11 +03:00
|
|
|
else
|
|
|
|
#endif
|
|
|
|
if (freerdp_settings_get_bool(settings, FreeRDP_RemoteFxCodec) && (id != 0))
|
2021-07-01 11:43:19 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
BOOL rc = 0;
|
|
|
|
wStream* s = NULL;
|
2021-08-25 11:34:55 +03:00
|
|
|
RFX_RECT rect;
|
2021-07-01 11:43:19 +03:00
|
|
|
|
|
|
|
if (shadow_encoder_prepare(encoder, FREERDP_CODEC_REMOTEFX) < 0)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to prepare encoder FREERDP_CODEC_REMOTEFX");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
s = Stream_New(NULL, 1024);
|
|
|
|
WINPR_ASSERT(s);
|
|
|
|
|
|
|
|
WINPR_ASSERT(cmd.left <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(cmd.top <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(cmd.right <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(cmd.bottom <= UINT16_MAX);
|
2021-08-25 11:34:55 +03:00
|
|
|
rect.x = (UINT16)cmd.left;
|
|
|
|
rect.y = (UINT16)cmd.top;
|
|
|
|
rect.width = (UINT16)cmd.right - cmd.left;
|
|
|
|
rect.height = (UINT16)cmd.bottom - cmd.top;
|
2021-07-01 11:43:19 +03:00
|
|
|
|
|
|
|
rc = rfx_compose_message(encoder->rfx, s, &rect, 1, pSrcData, nWidth, nHeight, nSrcStep);
|
|
|
|
|
|
|
|
if (!rc)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "rfx_compose_message failed");
|
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* rc > 0 means new data */
|
|
|
|
if (rc > 0)
|
|
|
|
{
|
2021-08-25 11:34:55 +03:00
|
|
|
const size_t pos = Stream_GetPosition(s);
|
|
|
|
WINPR_ASSERT(pos <= UINT32_MAX);
|
|
|
|
|
2021-07-01 11:43:19 +03:00
|
|
|
cmd.codecId = RDPGFX_CODECID_CAVIDEO;
|
|
|
|
cmd.data = Stream_Buffer(s);
|
2021-08-25 11:34:55 +03:00
|
|
|
cmd.length = (UINT32)pos;
|
2021-07-01 11:43:19 +03:00
|
|
|
|
|
|
|
IFCALLRET(client->rdpgfx->SurfaceFrameCommand, error, client->rdpgfx, &cmd, &cmdstart,
|
|
|
|
&cmdend);
|
|
|
|
}
|
|
|
|
|
|
|
|
Stream_Free(s, TRUE);
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "SurfaceFrameCommand failed with error %" PRIu32 "", error);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2021-06-30 14:04:22 +03:00
|
|
|
else if (freerdp_settings_get_bool(settings, FreeRDP_GfxProgressive))
|
2021-06-28 15:45:19 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
INT32 rc = 0;
|
2021-06-28 15:45:19 +03:00
|
|
|
REGION16 region;
|
|
|
|
RECTANGLE_16 regionRect;
|
2014-07-14 03:42:57 +04:00
|
|
|
|
2021-06-28 15:45:19 +03:00
|
|
|
if (shadow_encoder_prepare(encoder, FREERDP_CODEC_PROGRESSIVE) < 0)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to prepare encoder FREERDP_CODEC_PROGRESSIVE");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
WINPR_ASSERT(cmd.left <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(cmd.top <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(cmd.right <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(cmd.bottom <= UINT16_MAX);
|
|
|
|
regionRect.left = (UINT16)cmd.left;
|
|
|
|
regionRect.top = (UINT16)cmd.top;
|
|
|
|
regionRect.right = (UINT16)cmd.right;
|
|
|
|
regionRect.bottom = (UINT16)cmd.bottom;
|
|
|
|
region16_init(®ion);
|
|
|
|
region16_union_rect(®ion, ®ion, ®ionRect);
|
|
|
|
rc = progressive_compress(encoder->progressive, pSrcData, nSrcStep * nHeight, cmd.format,
|
|
|
|
nWidth, nHeight, nSrcStep, ®ion, &cmd.data, &cmd.length);
|
|
|
|
region16_uninit(®ion);
|
|
|
|
if (rc < 0)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "progressive_compress failed");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* rc > 0 means new data */
|
|
|
|
if (rc > 0)
|
|
|
|
{
|
|
|
|
cmd.codecId = RDPGFX_CODECID_CAPROGRESSIVE;
|
|
|
|
|
|
|
|
IFCALLRET(client->rdpgfx->SurfaceFrameCommand, error, client->rdpgfx, &cmd, &cmdstart,
|
|
|
|
&cmdend);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "SurfaceFrameCommand failed with error %" PRIu32 "", error);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2021-07-01 11:43:19 +03:00
|
|
|
else if (freerdp_settings_get_bool(settings, FreeRDP_GfxPlanar))
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
BOOL rc = 0;
|
2021-07-01 11:43:19 +03:00
|
|
|
const UINT32 w = cmd.right - cmd.left;
|
|
|
|
const UINT32 h = cmd.bottom - cmd.top;
|
2022-04-28 06:43:31 +03:00
|
|
|
const BYTE* src =
|
|
|
|
&pSrcData[cmd.top * nSrcStep + cmd.left * FreeRDPGetBytesPerPixel(SrcFormat)];
|
2021-07-01 11:43:19 +03:00
|
|
|
if (shadow_encoder_prepare(encoder, FREERDP_CODEC_PLANAR) < 0)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to prepare encoder FREERDP_CODEC_PLANAR");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
rc = freerdp_bitmap_planar_context_reset(encoder->planar, w, h);
|
|
|
|
WINPR_ASSERT(rc);
|
2021-07-02 09:49:07 +03:00
|
|
|
freerdp_planar_topdown_image(encoder->planar, TRUE);
|
2021-07-01 11:43:19 +03:00
|
|
|
|
2021-07-02 09:49:07 +03:00
|
|
|
cmd.data = freerdp_bitmap_compress_planar(encoder->planar, src, SrcFormat, w, h, nSrcStep,
|
|
|
|
NULL, &cmd.length);
|
2021-07-01 11:43:19 +03:00
|
|
|
WINPR_ASSERT(cmd.data || (cmd.length == 0));
|
|
|
|
|
|
|
|
cmd.codecId = RDPGFX_CODECID_PLANAR;
|
|
|
|
|
|
|
|
IFCALLRET(client->rdpgfx->SurfaceFrameCommand, error, client->rdpgfx, &cmd, &cmdstart,
|
|
|
|
&cmdend);
|
|
|
|
free(cmd.data);
|
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "SurfaceFrameCommand failed with error %" PRIu32 "", error);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2021-06-30 14:04:22 +03:00
|
|
|
else
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
BOOL rc = 0;
|
2021-07-01 09:08:27 +03:00
|
|
|
const UINT32 w = cmd.right - cmd.left;
|
|
|
|
const UINT32 h = cmd.bottom - cmd.top;
|
|
|
|
const UINT32 length = w * 4 * h;
|
|
|
|
BYTE* data = malloc(length);
|
|
|
|
|
2021-07-01 11:43:19 +03:00
|
|
|
WINPR_ASSERT(data);
|
|
|
|
|
2024-05-23 11:07:14 +03:00
|
|
|
rc = freerdp_image_copy_no_overlap(data, PIXEL_FORMAT_BGRA32, 0, 0, 0, w, h, pSrcData,
|
|
|
|
SrcFormat, nSrcStep, cmd.left, cmd.top, NULL, 0);
|
2021-07-01 09:08:27 +03:00
|
|
|
WINPR_ASSERT(rc);
|
|
|
|
|
|
|
|
cmd.data = data;
|
|
|
|
cmd.length = length;
|
2021-06-30 14:04:22 +03:00
|
|
|
cmd.codecId = RDPGFX_CODECID_UNCOMPRESSED;
|
|
|
|
|
|
|
|
IFCALLRET(client->rdpgfx->SurfaceFrameCommand, error, client->rdpgfx, &cmd, &cmdstart,
|
|
|
|
&cmdend);
|
2021-07-01 09:08:27 +03:00
|
|
|
free(data);
|
2021-06-30 14:04:22 +03:00
|
|
|
if (error)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "SurfaceFrameCommand failed with error %" PRIu32 "", error);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2016-05-03 19:48:59 +03:00
|
|
|
return TRUE;
|
2014-07-14 03:42:57 +04:00
|
|
|
}
|
|
|
|
|
2024-07-24 15:24:12 +03:00
|
|
|
static BOOL stream_surface_bits_supported(const rdpSettings* settings)
|
|
|
|
{
|
|
|
|
const UINT32 supported =
|
|
|
|
freerdp_settings_get_uint32(settings, FreeRDP_SurfaceCommandsSupported);
|
|
|
|
return ((supported & SURFCMDS_STREAM_SURFACE_BITS) != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL set_surface_bits_supported(const rdpSettings* settings)
|
|
|
|
{
|
|
|
|
const UINT32 supported =
|
|
|
|
freerdp_settings_get_uint32(settings, FreeRDP_SurfaceCommandsSupported);
|
|
|
|
return ((supported & SURFCMDS_SET_SURFACE_BITS) != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL is_surface_command_supported(const rdpSettings* settings)
|
|
|
|
{
|
|
|
|
if (stream_surface_bits_supported(settings))
|
|
|
|
{
|
|
|
|
const UINT32 rfxID = freerdp_settings_get_uint32(settings, FreeRDP_RemoteFxCodecId);
|
|
|
|
const BOOL supported = freerdp_settings_get_bool(settings, FreeRDP_RemoteFxCodec);
|
|
|
|
if (supported && (rfxID != 0))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
if (set_surface_bits_supported(settings))
|
|
|
|
{
|
|
|
|
const UINT32 nsID = freerdp_settings_get_uint32(settings, FreeRDP_NSCodecId);
|
|
|
|
const BOOL supported = freerdp_settings_get_bool(settings, FreeRDP_NSCodec);
|
|
|
|
if (supported && (nsID != 0))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-05-03 19:48:59 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return TRUE on success
|
|
|
|
*/
|
2021-06-18 11:00:43 +03:00
|
|
|
static BOOL shadow_client_send_surface_bits(rdpShadowClient* client, BYTE* pSrcData,
|
|
|
|
UINT32 nSrcStep, UINT16 nXSrc, UINT16 nYSrc,
|
|
|
|
UINT16 nWidth, UINT16 nHeight)
|
2014-07-12 08:01:29 +04:00
|
|
|
{
|
2016-05-03 19:48:59 +03:00
|
|
|
BOOL ret = TRUE;
|
2024-01-23 18:49:54 +03:00
|
|
|
BOOL first = 0;
|
|
|
|
BOOL last = 0;
|
|
|
|
wStream* s = NULL;
|
|
|
|
size_t numMessages = 0;
|
2014-07-14 03:42:57 +04:00
|
|
|
UINT32 frameId = 0;
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpUpdate* update = NULL;
|
2019-11-06 17:24:51 +03:00
|
|
|
rdpContext* context = (rdpContext*)client;
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpSettings* settings = NULL;
|
|
|
|
rdpShadowEncoder* encoder = NULL;
|
2018-02-28 12:10:09 +03:00
|
|
|
SURFACE_BITS_COMMAND cmd = { 0 };
|
2017-02-20 20:31:58 +03:00
|
|
|
|
|
|
|
if (!context || !pSrcData)
|
|
|
|
return FALSE;
|
|
|
|
|
2014-07-12 08:01:29 +04:00
|
|
|
update = context->update;
|
|
|
|
settings = context->settings;
|
2014-07-19 01:26:21 +04:00
|
|
|
encoder = client->encoder;
|
2014-07-15 02:01:29 +04:00
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
if (!update || !settings || !encoder)
|
|
|
|
return FALSE;
|
|
|
|
|
2014-07-14 03:42:57 +04:00
|
|
|
if (encoder->frameAck)
|
2015-04-09 21:33:54 +03:00
|
|
|
frameId = shadow_encoder_create_frame_id(encoder);
|
2014-07-14 03:42:57 +04:00
|
|
|
|
2024-07-24 14:18:30 +03:00
|
|
|
// TODO: Check FreeRDP_RemoteFxCodecMode if we should send RFX IMAGE or VIDEO data
|
|
|
|
const UINT32 nsID = freerdp_settings_get_uint32(settings, FreeRDP_NSCodecId);
|
|
|
|
const UINT32 rfxID = freerdp_settings_get_uint32(settings, FreeRDP_RemoteFxCodecId);
|
2024-07-24 15:24:12 +03:00
|
|
|
if (stream_surface_bits_supported(settings) &&
|
|
|
|
freerdp_settings_get_bool(settings, FreeRDP_RemoteFxCodec) && (rfxID != 0))
|
2014-07-12 08:01:29 +04:00
|
|
|
{
|
2023-04-05 14:47:59 +03:00
|
|
|
RFX_RECT rect = { 0 };
|
2014-07-12 08:01:29 +04:00
|
|
|
|
2016-05-03 19:48:59 +03:00
|
|
|
if (shadow_encoder_prepare(encoder, FREERDP_CODEC_REMOTEFX) < 0)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to prepare encoder FREERDP_CODEC_REMOTEFX");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-09-20 23:25:33 +04:00
|
|
|
|
2014-07-16 22:11:37 +04:00
|
|
|
s = encoder->bs;
|
2014-07-12 08:01:29 +04:00
|
|
|
rect.x = nXSrc;
|
|
|
|
rect.y = nYSrc;
|
|
|
|
rect.width = nWidth;
|
|
|
|
rect.height = nHeight;
|
|
|
|
|
2023-10-13 13:04:24 +03:00
|
|
|
const UINT32 MultifragMaxRequestSize =
|
|
|
|
freerdp_settings_get_uint32(settings, FreeRDP_MultifragMaxRequestSize);
|
|
|
|
RFX_MESSAGE_LIST* messages =
|
|
|
|
rfx_encode_messages(encoder->rfx, &rect, 1, pSrcData,
|
|
|
|
freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth),
|
|
|
|
freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight),
|
|
|
|
nSrcStep, &numMessages, MultifragMaxRequestSize);
|
2023-04-05 14:47:59 +03:00
|
|
|
if (!messages)
|
2015-04-23 16:42:21 +03:00
|
|
|
{
|
2016-05-03 19:48:59 +03:00
|
|
|
WLog_ERR(TAG, "rfx_encode_messages failed");
|
|
|
|
return FALSE;
|
2015-04-23 16:42:21 +03:00
|
|
|
}
|
2014-07-12 08:01:29 +04:00
|
|
|
|
2020-04-03 15:04:12 +03:00
|
|
|
cmd.cmdType = CMDTYPE_STREAM_SURFACE_BITS;
|
2021-07-01 12:40:41 +03:00
|
|
|
WINPR_ASSERT(rfxID <= UINT16_MAX);
|
|
|
|
cmd.bmp.codecID = (UINT16)rfxID;
|
2014-07-12 08:01:29 +04:00
|
|
|
cmd.destLeft = 0;
|
|
|
|
cmd.destTop = 0;
|
2023-10-13 13:04:24 +03:00
|
|
|
cmd.destRight = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
|
|
|
|
cmd.destBottom = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
|
2018-02-28 12:10:09 +03:00
|
|
|
cmd.bmp.bpp = 32;
|
|
|
|
cmd.bmp.flags = 0;
|
2023-10-13 13:04:24 +03:00
|
|
|
WINPR_ASSERT(freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth) <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight) <= UINT16_MAX);
|
|
|
|
cmd.bmp.width = (UINT16)freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
|
|
|
|
cmd.bmp.height = (UINT16)freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
|
2015-05-22 12:12:41 +03:00
|
|
|
cmd.skipCompression = TRUE;
|
2014-07-12 08:01:29 +04:00
|
|
|
|
2023-04-05 14:47:59 +03:00
|
|
|
for (size_t i = 0; i < numMessages; i++)
|
2014-07-12 08:01:29 +04:00
|
|
|
{
|
|
|
|
Stream_SetPosition(s, 0);
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2023-04-05 14:47:59 +03:00
|
|
|
const RFX_MESSAGE* msg = rfx_message_list_get(messages, i);
|
|
|
|
if (!rfx_write_message(encoder->rfx, s, msg))
|
2015-04-23 16:42:21 +03:00
|
|
|
{
|
2016-05-03 19:48:59 +03:00
|
|
|
WLog_ERR(TAG, "rfx_write_message failed");
|
|
|
|
ret = FALSE;
|
2015-04-23 16:42:21 +03:00
|
|
|
break;
|
|
|
|
}
|
2014-07-12 08:01:29 +04:00
|
|
|
|
2021-06-16 13:59:25 +03:00
|
|
|
WINPR_ASSERT(Stream_GetPosition(s) <= UINT32_MAX);
|
|
|
|
cmd.bmp.bitmapDataLength = (UINT32)Stream_GetPosition(s);
|
2018-02-28 12:10:09 +03:00
|
|
|
cmd.bmp.bitmapData = Stream_Buffer(s);
|
2014-09-19 22:23:17 +04:00
|
|
|
first = (i == 0) ? TRUE : FALSE;
|
|
|
|
last = ((i + 1) == numMessages) ? TRUE : FALSE;
|
|
|
|
|
|
|
|
if (!encoder->frameAck)
|
2016-05-03 19:48:59 +03:00
|
|
|
IFCALLRET(update->SurfaceBits, ret, update->context, &cmd);
|
2014-09-19 22:23:17 +04:00
|
|
|
else
|
2016-09-20 10:25:13 +03:00
|
|
|
IFCALLRET(update->SurfaceFrameBits, ret, update->context, &cmd, first, last,
|
|
|
|
frameId);
|
2016-05-03 19:48:59 +03:00
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Send surface bits(RemoteFxCodec) failed");
|
|
|
|
break;
|
|
|
|
}
|
2014-07-12 08:01:29 +04:00
|
|
|
}
|
|
|
|
|
2023-04-05 14:47:59 +03:00
|
|
|
rfx_message_list_free(messages);
|
2014-07-12 08:01:29 +04:00
|
|
|
}
|
2024-07-24 15:24:12 +03:00
|
|
|
else if (set_surface_bits_supported(settings) &&
|
|
|
|
freerdp_settings_get_bool(settings, FreeRDP_NSCodec) && (nsID != 0))
|
2014-07-12 08:01:29 +04:00
|
|
|
{
|
2016-05-03 19:48:59 +03:00
|
|
|
if (shadow_encoder_prepare(encoder, FREERDP_CODEC_NSCODEC) < 0)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to prepare encoder FREERDP_CODEC_NSCODEC");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-09-20 23:25:33 +04:00
|
|
|
|
2014-07-16 22:11:37 +04:00
|
|
|
s = encoder->bs;
|
2014-09-24 20:10:02 +04:00
|
|
|
Stream_SetPosition(s, 0);
|
|
|
|
pSrcData = &pSrcData[(nYSrc * nSrcStep) + (nXSrc * 4)];
|
|
|
|
nsc_compose_message(encoder->nsc, s, pSrcData, nWidth, nHeight, nSrcStep);
|
2020-03-19 11:04:59 +03:00
|
|
|
cmd.cmdType = CMDTYPE_SET_SURFACE_BITS;
|
2018-02-28 12:10:09 +03:00
|
|
|
cmd.bmp.bpp = 32;
|
2021-07-01 12:40:41 +03:00
|
|
|
WINPR_ASSERT(nsID <= UINT16_MAX);
|
|
|
|
cmd.bmp.codecID = (UINT16)nsID;
|
2014-09-24 20:10:02 +04:00
|
|
|
cmd.destLeft = nXSrc;
|
|
|
|
cmd.destTop = nYSrc;
|
|
|
|
cmd.destRight = cmd.destLeft + nWidth;
|
|
|
|
cmd.destBottom = cmd.destTop + nHeight;
|
2018-02-28 12:10:09 +03:00
|
|
|
cmd.bmp.width = nWidth;
|
|
|
|
cmd.bmp.height = nHeight;
|
2021-06-16 13:59:25 +03:00
|
|
|
WINPR_ASSERT(Stream_GetPosition(s) <= UINT32_MAX);
|
|
|
|
cmd.bmp.bitmapDataLength = (UINT32)Stream_GetPosition(s);
|
2018-02-28 12:10:09 +03:00
|
|
|
cmd.bmp.bitmapData = Stream_Buffer(s);
|
2014-09-24 20:10:02 +04:00
|
|
|
first = TRUE;
|
|
|
|
last = TRUE;
|
|
|
|
|
|
|
|
if (!encoder->frameAck)
|
2016-05-03 19:48:59 +03:00
|
|
|
IFCALLRET(update->SurfaceBits, ret, update->context, &cmd);
|
2014-09-24 20:10:02 +04:00
|
|
|
else
|
2019-11-06 17:24:51 +03:00
|
|
|
IFCALLRET(update->SurfaceFrameBits, ret, update->context, &cmd, first, last, frameId);
|
2016-05-03 19:48:59 +03:00
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Send surface bits(NSCodec) failed");
|
|
|
|
}
|
2014-07-12 08:01:29 +04:00
|
|
|
}
|
|
|
|
|
2016-05-03 19:48:59 +03:00
|
|
|
return ret;
|
2014-07-12 08:01:29 +04:00
|
|
|
}
|
|
|
|
|
2016-05-03 19:48:59 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return TRUE on success
|
|
|
|
*/
|
2021-06-18 11:00:43 +03:00
|
|
|
static BOOL shadow_client_send_bitmap_update(rdpShadowClient* client, BYTE* pSrcData,
|
|
|
|
UINT32 nSrcStep, UINT16 nXSrc, UINT16 nYSrc,
|
|
|
|
UINT16 nWidth, UINT16 nHeight)
|
2014-07-11 01:20:41 +04:00
|
|
|
{
|
2016-05-03 19:48:59 +03:00
|
|
|
BOOL ret = TRUE;
|
2024-01-23 18:49:54 +03:00
|
|
|
BYTE* data = NULL;
|
|
|
|
BYTE* buffer = NULL;
|
|
|
|
UINT32 k = 0;
|
|
|
|
UINT32 yIdx = 0;
|
|
|
|
UINT32 xIdx = 0;
|
|
|
|
UINT32 rows = 0;
|
|
|
|
UINT32 cols = 0;
|
|
|
|
UINT32 DstSize = 0;
|
|
|
|
UINT32 SrcFormat = 0;
|
|
|
|
BITMAP_DATA* bitmap = NULL;
|
2019-11-06 17:24:51 +03:00
|
|
|
rdpContext* context = (rdpContext*)client;
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 totalBitmapSize = 0;
|
|
|
|
UINT32 updateSizeEstimate = 0;
|
|
|
|
BITMAP_DATA* bitmapData = NULL;
|
2024-08-08 09:37:07 +03:00
|
|
|
BITMAP_UPDATE bitmapUpdate = { 0 };
|
2017-02-20 20:31:58 +03:00
|
|
|
|
|
|
|
if (!context || !pSrcData)
|
|
|
|
return FALSE;
|
|
|
|
|
2024-08-08 09:37:07 +03:00
|
|
|
rdpUpdate* update = context->update;
|
|
|
|
rdpSettings* settings = context->settings;
|
|
|
|
rdpShadowEncoder* encoder = client->encoder;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
|
|
|
if (!update || !settings || !encoder)
|
|
|
|
return FALSE;
|
|
|
|
|
2023-10-13 13:04:24 +03:00
|
|
|
const UINT32 maxUpdateSize =
|
|
|
|
freerdp_settings_get_uint32(settings, FreeRDP_MultifragMaxRequestSize);
|
2022-06-22 13:42:48 +03:00
|
|
|
if (freerdp_settings_get_uint32(settings, FreeRDP_ColorDepth) < 32)
|
2016-05-03 19:48:59 +03:00
|
|
|
{
|
|
|
|
if (shadow_encoder_prepare(encoder, FREERDP_CODEC_INTERLEAVED) < 0)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to prepare encoder FREERDP_CODEC_INTERLEAVED");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2014-09-20 23:25:33 +04:00
|
|
|
else
|
2016-05-03 19:48:59 +03:00
|
|
|
{
|
|
|
|
if (shadow_encoder_prepare(encoder, FREERDP_CODEC_PLANAR) < 0)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to prepare encoder FREERDP_CODEC_PLANAR");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2014-09-20 23:25:33 +04:00
|
|
|
|
2016-09-20 10:25:13 +03:00
|
|
|
SrcFormat = PIXEL_FORMAT_BGRX32;
|
2014-07-11 01:20:41 +04:00
|
|
|
|
2014-07-15 02:44:15 +04:00
|
|
|
if ((nXSrc % 4) != 0)
|
|
|
|
{
|
|
|
|
nWidth += (nXSrc % 4);
|
|
|
|
nXSrc -= (nXSrc % 4);
|
|
|
|
}
|
2014-07-11 01:20:41 +04:00
|
|
|
|
2014-07-15 02:44:15 +04:00
|
|
|
if ((nYSrc % 4) != 0)
|
2014-07-11 01:20:41 +04:00
|
|
|
{
|
2014-07-15 02:44:15 +04:00
|
|
|
nHeight += (nYSrc % 4);
|
|
|
|
nYSrc -= (nYSrc % 4);
|
|
|
|
}
|
2014-07-11 01:20:41 +04:00
|
|
|
|
2014-09-24 21:17:52 +04:00
|
|
|
rows = (nHeight / 64) + ((nHeight % 64) ? 1 : 0);
|
|
|
|
cols = (nWidth / 64) + ((nWidth % 64) ? 1 : 0);
|
2014-07-15 02:44:15 +04:00
|
|
|
k = 0;
|
2014-09-21 00:29:13 +04:00
|
|
|
totalBitmapSize = 0;
|
2022-01-27 11:24:47 +03:00
|
|
|
bitmapUpdate.number = rows * cols;
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!(bitmapData = (BITMAP_DATA*)calloc(bitmapUpdate.number, sizeof(BITMAP_DATA))))
|
2016-05-03 19:48:59 +03:00
|
|
|
return FALSE;
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2015-06-17 23:08:02 +03:00
|
|
|
bitmapUpdate.rectangles = bitmapData;
|
2014-07-15 02:44:15 +04:00
|
|
|
|
|
|
|
if ((nWidth % 4) != 0)
|
|
|
|
{
|
2015-09-24 20:29:40 +03:00
|
|
|
nWidth += (4 - (nWidth % 4));
|
2014-07-11 01:20:41 +04:00
|
|
|
}
|
|
|
|
|
2014-07-15 02:44:15 +04:00
|
|
|
if ((nHeight % 4) != 0)
|
|
|
|
{
|
2015-09-24 20:29:40 +03:00
|
|
|
nHeight += (4 - (nHeight % 4));
|
2014-07-15 02:44:15 +04:00
|
|
|
}
|
|
|
|
|
2014-09-24 21:17:52 +04:00
|
|
|
for (yIdx = 0; yIdx < rows; yIdx++)
|
2014-07-15 02:44:15 +04:00
|
|
|
{
|
2014-09-24 21:17:52 +04:00
|
|
|
for (xIdx = 0; xIdx < cols; xIdx++)
|
2014-07-15 02:44:15 +04:00
|
|
|
{
|
2014-09-24 21:17:52 +04:00
|
|
|
bitmap = &bitmapData[k];
|
|
|
|
bitmap->width = 64;
|
|
|
|
bitmap->height = 64;
|
|
|
|
bitmap->destLeft = nXSrc + (xIdx * 64);
|
|
|
|
bitmap->destTop = nYSrc + (yIdx * 64);
|
|
|
|
|
2019-02-07 16:20:24 +03:00
|
|
|
if ((INT64)(bitmap->destLeft + bitmap->width) > (nXSrc + nWidth))
|
|
|
|
bitmap->width = (UINT32)(nXSrc + nWidth) - bitmap->destLeft;
|
2014-09-24 21:17:52 +04:00
|
|
|
|
2019-02-07 16:20:24 +03:00
|
|
|
if ((INT64)(bitmap->destTop + bitmap->height) > (nYSrc + nHeight))
|
|
|
|
bitmap->height = (UINT32)(nYSrc + nHeight) - bitmap->destTop;
|
2014-09-24 21:17:52 +04:00
|
|
|
|
|
|
|
bitmap->destRight = bitmap->destLeft + bitmap->width - 1;
|
|
|
|
bitmap->destBottom = bitmap->destTop + bitmap->height - 1;
|
|
|
|
bitmap->compressed = TRUE;
|
|
|
|
|
|
|
|
if ((bitmap->width < 4) || (bitmap->height < 4))
|
|
|
|
continue;
|
|
|
|
|
2022-06-22 13:42:48 +03:00
|
|
|
if (freerdp_settings_get_uint32(settings, FreeRDP_ColorDepth) < 32)
|
2014-07-15 02:44:15 +04:00
|
|
|
{
|
2022-06-22 13:42:48 +03:00
|
|
|
UINT32 bitsPerPixel = freerdp_settings_get_uint32(settings, FreeRDP_ColorDepth);
|
2021-06-18 11:00:43 +03:00
|
|
|
UINT32 bytesPerPixel = (bitsPerPixel + 7) / 8;
|
2014-09-24 21:17:52 +04:00
|
|
|
DstSize = 64 * 64 * 4;
|
|
|
|
buffer = encoder->grid[k];
|
2016-09-20 10:25:13 +03:00
|
|
|
interleaved_compress(encoder->interleaved, buffer, &DstSize, bitmap->width,
|
2019-11-06 17:24:51 +03:00
|
|
|
bitmap->height, pSrcData, SrcFormat, nSrcStep,
|
|
|
|
bitmap->destLeft, bitmap->destTop, NULL, bitsPerPixel);
|
2014-09-24 21:17:52 +04:00
|
|
|
bitmap->bitmapDataStream = buffer;
|
|
|
|
bitmap->bitmapLength = DstSize;
|
|
|
|
bitmap->bitsPerPixel = bitsPerPixel;
|
|
|
|
bitmap->cbScanWidth = bitmap->width * bytesPerPixel;
|
|
|
|
bitmap->cbUncompressedSize = bitmap->width * bitmap->height * bytesPerPixel;
|
2014-07-15 02:44:15 +04:00
|
|
|
}
|
2014-09-24 21:17:52 +04:00
|
|
|
else
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 dstSize = 0;
|
2014-09-24 21:17:52 +04:00
|
|
|
buffer = encoder->grid[k];
|
|
|
|
data = &pSrcData[(bitmap->destTop * nSrcStep) + (bitmap->destLeft * 4)];
|
2021-07-01 11:43:19 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
buffer =
|
|
|
|
freerdp_bitmap_compress_planar(encoder->planar, data, SrcFormat, bitmap->width,
|
|
|
|
bitmap->height, nSrcStep, buffer, &dstSize);
|
2014-09-24 21:17:52 +04:00
|
|
|
bitmap->bitmapDataStream = buffer;
|
|
|
|
bitmap->bitmapLength = dstSize;
|
|
|
|
bitmap->bitsPerPixel = 32;
|
|
|
|
bitmap->cbScanWidth = bitmap->width * 4;
|
|
|
|
bitmap->cbUncompressedSize = bitmap->width * bitmap->height * 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
bitmap->cbCompFirstRowSize = 0;
|
|
|
|
bitmap->cbCompMainBodySize = bitmap->bitmapLength;
|
|
|
|
totalBitmapSize += bitmap->bitmapLength;
|
|
|
|
k++;
|
2014-07-15 02:44:15 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-27 11:24:47 +03:00
|
|
|
bitmapUpdate.number = k;
|
|
|
|
updateSizeEstimate = totalBitmapSize + (k * bitmapUpdate.number) + 16;
|
2014-09-21 00:29:13 +04:00
|
|
|
|
|
|
|
if (updateSizeEstimate > maxUpdateSize)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 i = 0;
|
|
|
|
UINT32 j = 0;
|
|
|
|
UINT32 updateSize = 0;
|
|
|
|
UINT32 newUpdateSize = 0;
|
2015-09-01 13:05:22 +03:00
|
|
|
BITMAP_DATA* fragBitmapData = NULL;
|
|
|
|
|
|
|
|
if (k > 0)
|
2019-11-06 17:24:51 +03:00
|
|
|
fragBitmapData = (BITMAP_DATA*)calloc(k, sizeof(BITMAP_DATA));
|
2014-10-25 23:36:36 +04:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!fragBitmapData)
|
|
|
|
{
|
2016-05-03 19:48:59 +03:00
|
|
|
WLog_ERR(TAG, "Failed to allocate memory for fragBitmapData");
|
|
|
|
ret = FALSE;
|
|
|
|
goto out;
|
2015-06-16 16:42:07 +03:00
|
|
|
}
|
2014-09-21 00:29:13 +04:00
|
|
|
|
2016-09-20 10:25:13 +03:00
|
|
|
bitmapUpdate.rectangles = fragBitmapData;
|
2014-10-25 23:36:36 +04:00
|
|
|
i = j = 0;
|
|
|
|
updateSize = 1024;
|
|
|
|
|
|
|
|
while (i < k)
|
|
|
|
{
|
|
|
|
newUpdateSize = updateSize + (bitmapData[i].bitmapLength + 16);
|
|
|
|
|
2017-07-04 18:48:07 +03:00
|
|
|
if (newUpdateSize < maxUpdateSize)
|
2014-10-25 23:36:36 +04:00
|
|
|
{
|
|
|
|
CopyMemory(&fragBitmapData[j++], &bitmapData[i++], sizeof(BITMAP_DATA));
|
|
|
|
updateSize = newUpdateSize;
|
|
|
|
}
|
2016-05-03 19:48:59 +03:00
|
|
|
|
2017-07-04 18:48:07 +03:00
|
|
|
if ((newUpdateSize >= maxUpdateSize) || (i + 1) >= k)
|
|
|
|
{
|
2022-01-27 11:24:47 +03:00
|
|
|
bitmapUpdate.number = j;
|
2024-08-08 09:37:07 +03:00
|
|
|
ret = BitmapUpdateProxy(update, context, &bitmapUpdate);
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2016-05-03 19:48:59 +03:00
|
|
|
if (!ret)
|
|
|
|
break;
|
|
|
|
|
2014-10-25 23:36:36 +04:00
|
|
|
updateSize = 1024;
|
|
|
|
j = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
free(fragBitmapData);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-08-08 09:37:07 +03:00
|
|
|
ret = BitmapUpdateProxy(update, context, &bitmapUpdate);
|
2014-10-25 23:36:36 +04:00
|
|
|
}
|
2014-07-11 01:20:41 +04:00
|
|
|
|
2016-05-03 19:48:59 +03:00
|
|
|
out:
|
2014-07-15 02:44:15 +04:00
|
|
|
free(bitmapData);
|
2016-05-03 19:48:59 +03:00
|
|
|
return ret;
|
2014-07-15 02:44:15 +04:00
|
|
|
}
|
|
|
|
|
2016-05-03 19:48:59 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
*
|
|
|
|
* @return TRUE on success (or nothing need to be updated)
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL shadow_client_send_surface_update(rdpShadowClient* client, SHADOW_GFX_STATUS* pStatus)
|
2014-07-15 02:44:15 +04:00
|
|
|
{
|
2016-05-03 19:48:59 +03:00
|
|
|
BOOL ret = TRUE;
|
2024-01-23 18:49:54 +03:00
|
|
|
INT64 nXSrc = 0;
|
|
|
|
INT64 nYSrc = 0;
|
|
|
|
INT64 nWidth = 0;
|
|
|
|
INT64 nHeight = 0;
|
2019-11-06 17:24:51 +03:00
|
|
|
rdpContext* context = (rdpContext*)client;
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpSettings* settings = NULL;
|
|
|
|
rdpShadowServer* server = NULL;
|
|
|
|
rdpShadowSurface* surface = NULL;
|
2014-07-19 01:26:21 +04:00
|
|
|
REGION16 invalidRegion;
|
2014-07-15 02:44:15 +04:00
|
|
|
RECTANGLE_16 surfaceRect;
|
2024-01-23 18:49:54 +03:00
|
|
|
const RECTANGLE_16* extents = NULL;
|
|
|
|
BYTE* pSrcData = NULL;
|
|
|
|
UINT32 nSrcStep = 0;
|
|
|
|
UINT32 SrcFormat = 0;
|
2016-08-25 10:47:50 +03:00
|
|
|
UINT32 numRects = 0;
|
2024-01-23 18:49:54 +03:00
|
|
|
const RECTANGLE_16* rects = NULL;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
|
|
|
if (!context || !pStatus)
|
|
|
|
return FALSE;
|
|
|
|
|
2014-07-15 02:44:15 +04:00
|
|
|
settings = context->settings;
|
|
|
|
server = client->server;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
|
|
|
if (!settings || !server)
|
|
|
|
return FALSE;
|
|
|
|
|
2015-04-11 21:57:16 +03:00
|
|
|
surface = client->inLobby ? server->lobby : server->surface;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
|
|
|
if (!surface)
|
|
|
|
return FALSE;
|
|
|
|
|
2014-07-19 01:26:21 +04:00
|
|
|
EnterCriticalSection(&(client->lock));
|
|
|
|
region16_init(&invalidRegion);
|
|
|
|
region16_copy(&invalidRegion, &(client->invalidRegion));
|
|
|
|
region16_clear(&(client->invalidRegion));
|
|
|
|
LeaveCriticalSection(&(client->lock));
|
2020-05-27 11:01:04 +03:00
|
|
|
|
|
|
|
EnterCriticalSection(&surface->lock);
|
2016-04-23 20:49:10 +03:00
|
|
|
rects = region16_rects(&(surface->invalidRegion), &numRects);
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 index = 0; index < numRects; index++)
|
2016-04-23 20:49:10 +03:00
|
|
|
region16_union_rect(&invalidRegion, &invalidRegion, &rects[index]);
|
|
|
|
|
2014-09-10 22:58:14 +04:00
|
|
|
surfaceRect.left = 0;
|
|
|
|
surfaceRect.top = 0;
|
2021-06-18 11:00:43 +03:00
|
|
|
WINPR_ASSERT(surface->width <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(surface->height <= UINT16_MAX);
|
|
|
|
surfaceRect.right = (UINT16)surface->width;
|
|
|
|
surfaceRect.bottom = (UINT16)surface->height;
|
2014-07-19 01:26:21 +04:00
|
|
|
region16_intersect_rect(&invalidRegion, &invalidRegion, &surfaceRect);
|
2014-07-15 02:44:15 +04:00
|
|
|
|
2014-09-11 00:27:24 +04:00
|
|
|
if (server->shareSubRect)
|
|
|
|
{
|
|
|
|
region16_intersect_rect(&invalidRegion, &invalidRegion, &(server->subRect));
|
|
|
|
}
|
|
|
|
|
2014-07-19 01:26:21 +04:00
|
|
|
if (region16_is_empty(&invalidRegion))
|
|
|
|
{
|
2016-05-03 19:48:59 +03:00
|
|
|
/* No image region need to be updated. Success */
|
|
|
|
goto out;
|
2014-07-19 01:26:21 +04:00
|
|
|
}
|
2014-07-15 02:44:15 +04:00
|
|
|
|
2014-07-19 01:26:21 +04:00
|
|
|
extents = region16_extents(&invalidRegion);
|
2016-04-23 20:49:10 +03:00
|
|
|
nXSrc = extents->left;
|
|
|
|
nYSrc = extents->top;
|
2014-07-15 02:44:15 +04:00
|
|
|
nWidth = extents->right - extents->left;
|
|
|
|
nHeight = extents->bottom - extents->top;
|
2016-04-23 20:49:10 +03:00
|
|
|
pSrcData = surface->data;
|
|
|
|
nSrcStep = surface->scanline;
|
2021-07-01 09:08:27 +03:00
|
|
|
SrcFormat = surface->format;
|
2016-04-23 20:49:10 +03:00
|
|
|
|
|
|
|
/* Move to new pSrcData / nXSrc / nYSrc according to sub rect */
|
|
|
|
if (server->shareSubRect)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
INT32 subX = 0;
|
|
|
|
INT32 subY = 0;
|
2016-04-23 20:49:10 +03:00
|
|
|
subX = server->subRect.left;
|
|
|
|
subY = server->subRect.top;
|
|
|
|
nXSrc -= subX;
|
|
|
|
nYSrc -= subY;
|
2021-06-18 11:00:43 +03:00
|
|
|
WINPR_ASSERT(nXSrc >= 0);
|
|
|
|
WINPR_ASSERT(nXSrc <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(nYSrc >= 0);
|
|
|
|
WINPR_ASSERT(nYSrc <= UINT16_MAX);
|
|
|
|
pSrcData = &pSrcData[((UINT16)subY * nSrcStep) + ((UINT16)subX * 4U)];
|
2016-04-23 20:49:10 +03:00
|
|
|
}
|
|
|
|
|
2022-09-29 15:55:27 +03:00
|
|
|
// WLog_INFO(TAG, "shadow_client_send_surface_update: x: %" PRId64 " y: %" PRId64 " width: %"
|
|
|
|
// PRId64 " height: %" PRId64 " right: %" PRId64 " bottom: %" PRId64, nXSrc, nYSrc, nWidth,
|
|
|
|
// nHeight, nXSrc + nWidth, nYSrc + nHeight);
|
2014-07-18 08:20:55 +04:00
|
|
|
|
2023-10-13 13:04:24 +03:00
|
|
|
if (freerdp_settings_get_bool(settings, FreeRDP_SupportGraphicsPipeline))
|
2016-04-23 20:49:10 +03:00
|
|
|
{
|
2024-01-29 17:02:25 +03:00
|
|
|
if (pStatus->gfxOpened && client->areGfxCapsReady)
|
2016-04-23 20:49:10 +03:00
|
|
|
{
|
2023-03-06 15:35:16 +03:00
|
|
|
/* GFX/h264 always full screen encoded */
|
2023-10-13 13:04:24 +03:00
|
|
|
nWidth = freerdp_settings_get_uint32(settings, FreeRDP_DesktopWidth);
|
|
|
|
nHeight = freerdp_settings_get_uint32(settings, FreeRDP_DesktopHeight);
|
2016-05-03 19:48:59 +03:00
|
|
|
|
2023-03-06 15:35:16 +03:00
|
|
|
/* Create primary surface if have not */
|
|
|
|
if (!pStatus->gfxSurfaceCreated)
|
|
|
|
{
|
|
|
|
/* Only init surface when we have h264 supported */
|
|
|
|
if (!(ret = shadow_client_rdpgfx_reset_graphic(client)))
|
|
|
|
goto out;
|
2016-05-03 19:48:59 +03:00
|
|
|
|
2023-03-06 15:35:16 +03:00
|
|
|
if (!(ret = shadow_client_rdpgfx_new_surface(client)))
|
|
|
|
goto out;
|
2016-04-23 20:49:10 +03:00
|
|
|
|
2023-03-06 15:35:16 +03:00
|
|
|
pStatus->gfxSurfaceCreated = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
WINPR_ASSERT(nWidth >= 0);
|
|
|
|
WINPR_ASSERT(nWidth <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(nHeight >= 0);
|
|
|
|
WINPR_ASSERT(nHeight <= UINT16_MAX);
|
|
|
|
ret = shadow_client_send_surface_gfx(client, pSrcData, nSrcStep, SrcFormat, 0, 0,
|
|
|
|
(UINT16)nWidth, (UINT16)nHeight);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
2016-04-23 20:49:10 +03:00
|
|
|
}
|
2024-07-24 15:24:12 +03:00
|
|
|
else if (is_surface_command_supported(settings))
|
2014-07-15 02:44:15 +04:00
|
|
|
{
|
2021-06-18 11:00:43 +03:00
|
|
|
WINPR_ASSERT(nXSrc >= 0);
|
|
|
|
WINPR_ASSERT(nXSrc <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(nYSrc >= 0);
|
|
|
|
WINPR_ASSERT(nYSrc <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(nWidth >= 0);
|
|
|
|
WINPR_ASSERT(nWidth <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(nHeight >= 0);
|
|
|
|
WINPR_ASSERT(nHeight <= UINT16_MAX);
|
|
|
|
ret = shadow_client_send_surface_bits(client, pSrcData, nSrcStep, (UINT16)nXSrc,
|
|
|
|
(UINT16)nYSrc, (UINT16)nWidth, (UINT16)nHeight);
|
2014-07-15 02:44:15 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-18 11:00:43 +03:00
|
|
|
WINPR_ASSERT(nXSrc >= 0);
|
|
|
|
WINPR_ASSERT(nXSrc <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(nYSrc >= 0);
|
|
|
|
WINPR_ASSERT(nYSrc <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(nWidth >= 0);
|
|
|
|
WINPR_ASSERT(nWidth <= UINT16_MAX);
|
|
|
|
WINPR_ASSERT(nHeight >= 0);
|
|
|
|
WINPR_ASSERT(nHeight <= UINT16_MAX);
|
|
|
|
ret = shadow_client_send_bitmap_update(client, pSrcData, nSrcStep, (UINT16)nXSrc,
|
|
|
|
(UINT16)nYSrc, (UINT16)nWidth, (UINT16)nHeight);
|
2014-07-15 02:44:15 +04:00
|
|
|
}
|
|
|
|
|
2016-05-03 19:48:59 +03:00
|
|
|
out:
|
2020-05-27 11:01:04 +03:00
|
|
|
LeaveCriticalSection(&surface->lock);
|
2014-07-19 01:26:21 +04:00
|
|
|
region16_uninit(&invalidRegion);
|
2016-05-03 19:48:59 +03:00
|
|
|
return ret;
|
2014-07-11 01:20:41 +04:00
|
|
|
}
|
|
|
|
|
2016-05-03 19:48:59 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
* Notify client for resize. The new desktop width/height
|
|
|
|
* should have already been updated in rdpSettings.
|
|
|
|
*
|
|
|
|
* @return TRUE on success
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL shadow_client_send_resize(rdpShadowClient* client, SHADOW_GFX_STATUS* pStatus)
|
2014-07-19 01:26:21 +04:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
rdpContext* context = (rdpContext*)client;
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpSettings* settings = NULL;
|
|
|
|
freerdp_peer* peer = NULL;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
|
|
|
if (!context || !pStatus)
|
|
|
|
return FALSE;
|
|
|
|
|
2016-04-23 20:49:10 +03:00
|
|
|
peer = context->peer;
|
|
|
|
settings = context->settings;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
|
|
|
if (!peer || !settings)
|
|
|
|
return FALSE;
|
|
|
|
|
2016-04-23 20:49:10 +03:00
|
|
|
/**
|
|
|
|
* Unset client activated flag to avoid sending update message during
|
2016-05-03 19:48:59 +03:00
|
|
|
* resize. DesktopResize will reactive the client and
|
2016-04-23 20:49:10 +03:00
|
|
|
* shadow_client_activate would be invoked later.
|
|
|
|
*/
|
|
|
|
client->activated = FALSE;
|
2014-07-19 01:26:21 +04:00
|
|
|
|
2016-04-23 20:49:10 +03:00
|
|
|
/* Close Gfx surfaces */
|
|
|
|
if (pStatus->gfxSurfaceCreated)
|
2014-07-19 01:26:21 +04:00
|
|
|
{
|
2016-05-03 19:48:59 +03:00
|
|
|
if (!shadow_client_rdpgfx_release_surface(client))
|
|
|
|
return FALSE;
|
|
|
|
|
2016-04-23 20:49:10 +03:00
|
|
|
pStatus->gfxSurfaceCreated = FALSE;
|
2014-07-19 01:26:21 +04:00
|
|
|
}
|
|
|
|
|
2016-04-23 20:49:10 +03:00
|
|
|
/* Send Resize */
|
2022-12-18 19:23:14 +03:00
|
|
|
if (!shadow_send_desktop_resize(client))
|
2016-05-03 19:48:59 +03:00
|
|
|
return FALSE;
|
2022-12-18 19:23:14 +03:00
|
|
|
shadow_reset_desktop_resize(client);
|
2016-04-23 20:49:10 +03:00
|
|
|
|
|
|
|
/* Clear my invalidRegion. shadow_client_activate refreshes fullscreen */
|
|
|
|
EnterCriticalSection(&(client->lock));
|
|
|
|
region16_clear(&(client->invalidRegion));
|
2014-07-19 01:26:21 +04:00
|
|
|
LeaveCriticalSection(&(client->lock));
|
2016-05-03 19:48:59 +03:00
|
|
|
return TRUE;
|
2016-04-23 20:49:10 +03:00
|
|
|
}
|
|
|
|
|
2016-05-03 19:48:59 +03:00
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
* Mark invalid region for client
|
|
|
|
*
|
|
|
|
* @return TRUE on success
|
|
|
|
*/
|
2019-11-20 13:30:14 +03:00
|
|
|
static BOOL shadow_client_surface_update(rdpShadowClient* client, REGION16* region)
|
2016-04-23 20:49:10 +03:00
|
|
|
{
|
2016-08-25 10:47:50 +03:00
|
|
|
UINT32 numRects = 0;
|
2024-01-23 18:49:54 +03:00
|
|
|
const RECTANGLE_16* rects = NULL;
|
2016-04-23 20:49:10 +03:00
|
|
|
rects = region16_rects(region, &numRects);
|
|
|
|
shadow_client_mark_invalid(client, numRects, rects);
|
2016-05-03 19:48:59 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function description
|
|
|
|
* Only union invalid region from server surface
|
|
|
|
*
|
|
|
|
* @return TRUE on success
|
|
|
|
*/
|
2016-09-20 10:25:13 +03:00
|
|
|
static INLINE BOOL shadow_client_no_surface_update(rdpShadowClient* client,
|
2019-11-06 17:24:51 +03:00
|
|
|
SHADOW_GFX_STATUS* pStatus)
|
2016-05-03 19:48:59 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpShadowServer* server = NULL;
|
|
|
|
rdpShadowSurface* surface = NULL;
|
2019-02-07 19:42:11 +03:00
|
|
|
WINPR_UNUSED(pStatus);
|
2021-07-01 09:01:54 +03:00
|
|
|
WINPR_ASSERT(client);
|
2016-05-03 19:48:59 +03:00
|
|
|
server = client->server;
|
2021-07-01 09:01:54 +03:00
|
|
|
WINPR_ASSERT(server);
|
2016-05-03 19:48:59 +03:00
|
|
|
surface = client->inLobby ? server->lobby : server->surface;
|
2024-04-15 10:51:06 +03:00
|
|
|
EnterCriticalSection(&surface->lock);
|
|
|
|
const BOOL rc = shadow_client_surface_update(client, &(surface->invalidRegion));
|
|
|
|
LeaveCriticalSection(&surface->lock);
|
|
|
|
return rc;
|
2014-07-19 01:26:21 +04:00
|
|
|
}
|
|
|
|
|
2021-08-25 11:34:55 +03:00
|
|
|
static int shadow_client_subsystem_process_message(rdpShadowClient* client, wMessage* message)
|
2014-11-07 01:25:41 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
rdpContext* context = (rdpContext*)client;
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpUpdate* update = NULL;
|
2021-07-01 09:01:54 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(message);
|
|
|
|
WINPR_ASSERT(context);
|
|
|
|
update = context->update;
|
|
|
|
WINPR_ASSERT(update);
|
2014-11-07 01:25:41 +03:00
|
|
|
|
|
|
|
/* FIXME: the pointer updates appear to be broken when used with bulk compression and mstsc */
|
|
|
|
|
2016-09-20 10:25:13 +03:00
|
|
|
switch (message->id)
|
2014-11-07 01:25:41 +03:00
|
|
|
{
|
2015-06-15 18:54:30 +03:00
|
|
|
case SHADOW_MSG_OUT_POINTER_POSITION_UPDATE_ID:
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
|
|
|
POINTER_POSITION_UPDATE pointerPosition;
|
2021-07-01 09:01:54 +03:00
|
|
|
const SHADOW_MSG_OUT_POINTER_POSITION_UPDATE* msg =
|
|
|
|
(const SHADOW_MSG_OUT_POINTER_POSITION_UPDATE*)message->wParam;
|
2019-11-06 17:24:51 +03:00
|
|
|
pointerPosition.xPos = msg->xPos;
|
|
|
|
pointerPosition.yPos = msg->yPos;
|
|
|
|
|
2021-07-01 09:01:54 +03:00
|
|
|
WINPR_ASSERT(client->server);
|
2019-11-06 17:24:51 +03:00
|
|
|
if (client->server->shareSubRect)
|
2015-04-11 21:57:16 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
pointerPosition.xPos -= client->server->subRect.left;
|
|
|
|
pointerPosition.yPos -= client->server->subRect.top;
|
|
|
|
}
|
2015-04-11 21:57:16 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (client->activated)
|
|
|
|
{
|
|
|
|
if ((msg->xPos != client->pointerX) || (msg->yPos != client->pointerY))
|
2015-06-15 18:54:30 +03:00
|
|
|
{
|
2021-07-01 09:01:54 +03:00
|
|
|
WINPR_ASSERT(update->pointer);
|
2019-11-06 17:24:51 +03:00
|
|
|
IFCALL(update->pointer->PointerPosition, context, &pointerPosition);
|
|
|
|
client->pointerX = msg->xPos;
|
|
|
|
client->pointerY = msg->yPos;
|
2015-06-15 18:54:30 +03:00
|
|
|
}
|
2016-09-20 10:25:13 +03:00
|
|
|
}
|
2014-11-07 21:51:10 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-09-20 10:25:13 +03:00
|
|
|
case SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE_ID:
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
2021-07-01 09:01:54 +03:00
|
|
|
POINTER_NEW_UPDATE pointerNew = { 0 };
|
|
|
|
POINTER_COLOR_UPDATE* pointerColor = { 0 };
|
|
|
|
POINTER_CACHED_UPDATE pointerCached = { 0 };
|
|
|
|
const SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE* msg =
|
|
|
|
(const SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE*)message->wParam;
|
|
|
|
|
|
|
|
WINPR_ASSERT(msg);
|
2019-11-06 17:24:51 +03:00
|
|
|
pointerNew.xorBpp = 24;
|
|
|
|
pointerColor = &(pointerNew.colorPtrAttr);
|
|
|
|
pointerColor->cacheIndex = 0;
|
2023-04-14 08:35:21 +03:00
|
|
|
pointerColor->hotSpotX = msg->xHot;
|
|
|
|
pointerColor->hotSpotY = msg->yHot;
|
2019-11-06 17:24:51 +03:00
|
|
|
pointerColor->width = msg->width;
|
|
|
|
pointerColor->height = msg->height;
|
|
|
|
pointerColor->lengthAndMask = msg->lengthAndMask;
|
|
|
|
pointerColor->lengthXorMask = msg->lengthXorMask;
|
|
|
|
pointerColor->xorMaskData = msg->xorMaskData;
|
|
|
|
pointerColor->andMaskData = msg->andMaskData;
|
|
|
|
pointerCached.cacheIndex = pointerColor->cacheIndex;
|
|
|
|
|
|
|
|
if (client->activated)
|
2015-06-15 18:54:30 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
IFCALL(update->pointer->PointerNew, context, &pointerNew);
|
|
|
|
IFCALL(update->pointer->PointerCached, context, &pointerCached);
|
2015-06-15 18:54:30 +03:00
|
|
|
}
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
|
|
|
}
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case SHADOW_MSG_OUT_AUDIO_OUT_SAMPLES_ID:
|
|
|
|
{
|
2021-07-01 09:01:54 +03:00
|
|
|
const SHADOW_MSG_OUT_AUDIO_OUT_SAMPLES* msg =
|
|
|
|
(const SHADOW_MSG_OUT_AUDIO_OUT_SAMPLES*)message->wParam;
|
|
|
|
|
|
|
|
WINPR_ASSERT(msg);
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (client->activated && client->rdpsnd && client->rdpsnd->Activated)
|
|
|
|
{
|
|
|
|
client->rdpsnd->src_format = msg->audio_format;
|
|
|
|
IFCALL(client->rdpsnd->SendSamples, client->rdpsnd, msg->buf, msg->nFrames,
|
|
|
|
msg->wTimestamp);
|
2015-06-15 18:54:30 +03:00
|
|
|
}
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
|
|
|
}
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
case SHADOW_MSG_OUT_AUDIO_OUT_VOLUME_ID:
|
|
|
|
{
|
2021-07-01 09:01:54 +03:00
|
|
|
const SHADOW_MSG_OUT_AUDIO_OUT_VOLUME* msg =
|
|
|
|
(const SHADOW_MSG_OUT_AUDIO_OUT_VOLUME*)message->wParam;
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (client->activated && client->rdpsnd && client->rdpsnd->Activated)
|
|
|
|
{
|
|
|
|
IFCALL(client->rdpsnd->SetVolume, client->rdpsnd, msg->left, msg->right);
|
2015-06-15 18:54:30 +03:00
|
|
|
}
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-06-15 18:54:30 +03:00
|
|
|
default:
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "Unknown message id: %" PRIu32 "", message->id);
|
2015-06-15 18:54:30 +03:00
|
|
|
break;
|
2014-11-07 01:25:41 +03:00
|
|
|
}
|
|
|
|
|
2015-04-08 21:13:52 +03:00
|
|
|
shadow_client_free_queued_message(message);
|
2014-11-07 01:25:41 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-03-07 14:03:10 +03:00
|
|
|
static DWORD WINAPI shadow_client_thread(LPVOID arg)
|
2014-07-11 01:20:41 +04:00
|
|
|
{
|
2018-03-07 14:03:10 +03:00
|
|
|
rdpShadowClient* client = (rdpShadowClient*)arg;
|
2023-06-05 13:16:57 +03:00
|
|
|
BOOL rc = FALSE;
|
|
|
|
DWORD status = 0;
|
|
|
|
wMessage message = { 0 };
|
|
|
|
wMessage pointerPositionMsg = { 0 };
|
|
|
|
wMessage pointerAlphaMsg = { 0 };
|
|
|
|
wMessage audioVolumeMsg = { 0 };
|
|
|
|
HANDLE ChannelEvent = 0;
|
|
|
|
void* UpdateSubscriber = NULL;
|
|
|
|
HANDLE UpdateEvent = 0;
|
|
|
|
freerdp_peer* peer = NULL;
|
|
|
|
rdpContext* context = NULL;
|
|
|
|
rdpSettings* settings = NULL;
|
|
|
|
rdpShadowServer* server = NULL;
|
|
|
|
rdpShadowSubsystem* subsystem = NULL;
|
|
|
|
wMessageQueue* MsgQueue = NULL;
|
2016-04-23 20:49:10 +03:00
|
|
|
/* This should only be visited in client thread */
|
2021-07-01 09:01:54 +03:00
|
|
|
SHADOW_GFX_STATUS gfxstatus = { 0 };
|
2023-06-05 13:16:57 +03:00
|
|
|
rdpUpdate* update = NULL;
|
2021-07-01 09:01:54 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(client);
|
|
|
|
|
|
|
|
MsgQueue = client->MsgQueue;
|
|
|
|
WINPR_ASSERT(MsgQueue);
|
|
|
|
|
2014-07-12 09:18:08 +04:00
|
|
|
server = client->server;
|
2021-07-01 09:01:54 +03:00
|
|
|
WINPR_ASSERT(server);
|
2014-07-12 09:18:08 +04:00
|
|
|
subsystem = server->subsystem;
|
2019-11-06 17:24:51 +03:00
|
|
|
context = (rdpContext*)client;
|
2014-09-19 01:22:44 +04:00
|
|
|
peer = context->peer;
|
2021-07-01 09:01:54 +03:00
|
|
|
WINPR_ASSERT(peer);
|
2021-09-03 12:24:55 +03:00
|
|
|
WINPR_ASSERT(peer->context);
|
2021-07-01 09:01:54 +03:00
|
|
|
|
2022-03-23 15:18:35 +03:00
|
|
|
settings = peer->context->settings;
|
2021-07-01 09:01:54 +03:00
|
|
|
WINPR_ASSERT(settings);
|
|
|
|
|
2014-07-12 03:30:40 +04:00
|
|
|
peer->Capabilities = shadow_client_capabilities;
|
|
|
|
peer->PostConnect = shadow_client_post_connect;
|
|
|
|
peer->Activate = shadow_client_activate;
|
2016-07-22 00:53:20 +03:00
|
|
|
peer->Logon = shadow_client_logon;
|
2021-09-03 12:24:55 +03:00
|
|
|
shadow_input_register_callbacks(peer->context->input);
|
2021-07-01 09:01:54 +03:00
|
|
|
|
|
|
|
rc = peer->Initialize(peer);
|
2023-01-19 16:46:47 +03:00
|
|
|
if (!rc)
|
|
|
|
goto out;
|
2021-07-01 09:01:54 +03:00
|
|
|
|
2022-03-23 15:18:35 +03:00
|
|
|
update = peer->context->update;
|
|
|
|
WINPR_ASSERT(update);
|
|
|
|
|
|
|
|
update->RefreshRect = shadow_client_refresh_rect;
|
|
|
|
update->SuppressOutput = shadow_client_suppress_output;
|
|
|
|
update->SurfaceFrameAcknowledge = shadow_client_surface_frame_acknowledge;
|
2014-07-14 03:42:57 +04:00
|
|
|
|
2015-04-08 21:13:52 +03:00
|
|
|
if ((!client->vcm) || (!subsystem->updateEvent))
|
2015-05-10 19:00:02 +03:00
|
|
|
goto out;
|
|
|
|
|
|
|
|
UpdateSubscriber = shadow_multiclient_get_subscriber(subsystem->updateEvent);
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2015-05-10 19:00:02 +03:00
|
|
|
if (!UpdateSubscriber)
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
UpdateEvent = shadow_multiclient_getevent(UpdateSubscriber);
|
2021-07-01 09:01:54 +03:00
|
|
|
WINPR_ASSERT(UpdateEvent);
|
|
|
|
|
2014-07-16 02:38:32 +04:00
|
|
|
ChannelEvent = WTSVirtualChannelManagerGetEventHandle(client->vcm);
|
2021-07-01 09:01:54 +03:00
|
|
|
WINPR_ASSERT(ChannelEvent);
|
|
|
|
|
|
|
|
rc = freerdp_settings_set_bool(settings, FreeRDP_UnicodeInput, TRUE);
|
|
|
|
WINPR_ASSERT(rc);
|
|
|
|
rc = freerdp_settings_set_bool(settings, FreeRDP_HasHorizontalWheel, TRUE);
|
|
|
|
WINPR_ASSERT(rc);
|
|
|
|
rc = freerdp_settings_set_bool(settings, FreeRDP_HasExtendedMouseEvent, TRUE);
|
|
|
|
WINPR_ASSERT(rc);
|
2023-07-04 21:25:51 +03:00
|
|
|
rc = freerdp_settings_set_bool(settings, FreeRDP_SupportMonitorLayoutPdu, TRUE);
|
|
|
|
WINPR_ASSERT(rc);
|
2014-07-11 01:20:41 +04:00
|
|
|
while (1)
|
|
|
|
{
|
2023-07-31 15:21:18 +03:00
|
|
|
HANDLE events[MAXIMUM_WAIT_OBJECTS] = { 0 };
|
|
|
|
DWORD nCount = 0;
|
2014-08-09 02:47:46 +04:00
|
|
|
events[nCount++] = UpdateEvent;
|
2016-10-27 18:43:09 +03:00
|
|
|
{
|
|
|
|
DWORD tmp = peer->GetEventHandles(peer, &events[nCount], 64 - nCount);
|
|
|
|
|
|
|
|
if (tmp == 0)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to get FreeRDP transport event handles");
|
2018-09-25 12:13:32 +03:00
|
|
|
goto fail;
|
2016-10-27 18:43:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nCount += tmp;
|
|
|
|
}
|
2014-07-16 02:38:32 +04:00
|
|
|
events[nCount++] = ChannelEvent;
|
2015-04-08 21:13:52 +03:00
|
|
|
events[nCount++] = MessageQueue_Event(MsgQueue);
|
2023-07-31 15:21:18 +03:00
|
|
|
|
2024-06-12 10:26:48 +03:00
|
|
|
#if defined(CHANNEL_RDPGFX_SERVER)
|
2023-07-31 15:21:18 +03:00
|
|
|
HANDLE gfxevent = rdpgfx_server_get_event_handle(client->rdpgfx);
|
|
|
|
|
|
|
|
if (gfxevent)
|
|
|
|
events[nCount++] = gfxevent;
|
2024-06-12 10:26:48 +03:00
|
|
|
#endif
|
2023-07-31 15:21:18 +03:00
|
|
|
|
2014-08-09 02:47:46 +04:00
|
|
|
status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE);
|
2014-07-11 01:20:41 +04:00
|
|
|
|
2017-02-20 20:31:58 +03:00
|
|
|
if (status == WAIT_FAILED)
|
2018-09-25 12:13:32 +03:00
|
|
|
goto fail;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
2014-08-09 02:47:46 +04:00
|
|
|
if (WaitForSingleObject(UpdateEvent, 0) == WAIT_OBJECT_0)
|
|
|
|
{
|
2016-04-23 20:49:10 +03:00
|
|
|
/* The UpdateEvent means to start sending current frame. It is
|
|
|
|
* triggered from subsystem implementation and it should ensure
|
|
|
|
* that the screen and primary surface meta data (width, height,
|
|
|
|
* scanline, invalid region, etc) is not changed until it is reset
|
|
|
|
* (at shadow_multiclient_consume). As best practice, subsystem
|
|
|
|
* implementation should invoke shadow_subsystem_frame_update which
|
|
|
|
* triggers the event and then wait for completion */
|
|
|
|
if (client->activated && !client->suppressOutput)
|
2014-08-09 02:47:46 +04:00
|
|
|
{
|
2016-04-23 20:49:10 +03:00
|
|
|
/* Send screen update or resize to this client */
|
2014-08-09 02:47:46 +04:00
|
|
|
|
2015-04-11 21:57:16 +03:00
|
|
|
/* Check resize */
|
2016-04-23 20:49:10 +03:00
|
|
|
if (shadow_client_recalc_desktop_size(client))
|
2014-08-09 02:47:46 +04:00
|
|
|
{
|
2015-04-11 21:57:16 +03:00
|
|
|
/* Screen size changed, do resize */
|
2016-05-03 19:48:59 +03:00
|
|
|
if (!shadow_client_send_resize(client, &gfxstatus))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to send resize message");
|
|
|
|
break;
|
|
|
|
}
|
2014-08-09 02:47:46 +04:00
|
|
|
}
|
2016-05-03 19:48:59 +03:00
|
|
|
else
|
2015-04-11 21:57:16 +03:00
|
|
|
{
|
|
|
|
/* Send frame */
|
2016-05-03 19:48:59 +03:00
|
|
|
if (!shadow_client_send_surface_update(client, &gfxstatus))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to send surface update");
|
|
|
|
break;
|
|
|
|
}
|
2015-04-11 21:57:16 +03:00
|
|
|
}
|
2014-08-09 02:47:46 +04:00
|
|
|
}
|
2016-04-23 20:49:10 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Our client don't receive graphic updates. Just save the invalid region */
|
2016-05-03 19:48:59 +03:00
|
|
|
if (!shadow_client_no_surface_update(client, &gfxstatus))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to handle surface update");
|
|
|
|
break;
|
|
|
|
}
|
2016-04-23 20:49:10 +03:00
|
|
|
}
|
2014-08-09 02:47:46 +04:00
|
|
|
|
2016-05-03 19:48:59 +03:00
|
|
|
/*
|
2016-08-25 10:47:50 +03:00
|
|
|
* The return value of shadow_multiclient_consume is whether or not
|
2016-05-03 19:48:59 +03:00
|
|
|
* the subscriber really consumes the event. It's not cared currently.
|
2015-05-10 19:00:02 +03:00
|
|
|
*/
|
|
|
|
(void)shadow_multiclient_consume(UpdateSubscriber);
|
2014-08-09 02:47:46 +04:00
|
|
|
}
|
|
|
|
|
2021-07-01 09:01:54 +03:00
|
|
|
WINPR_ASSERT(peer->CheckFileDescriptor);
|
2016-10-27 18:43:09 +03:00
|
|
|
if (!peer->CheckFileDescriptor(peer))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to check FreeRDP file descriptor");
|
2018-09-25 12:13:32 +03:00
|
|
|
goto fail;
|
2016-10-27 18:43:09 +03:00
|
|
|
}
|
2022-08-18 10:20:51 +03:00
|
|
|
|
|
|
|
if (client->activated &&
|
|
|
|
WTSVirtualChannelManagerIsChannelJoined(client->vcm, DRDYNVC_SVC_CHANNEL_NAME))
|
2014-07-11 01:20:41 +04:00
|
|
|
{
|
2022-08-18 10:20:51 +03:00
|
|
|
switch (WTSVirtualChannelManagerGetDrdynvcState(client->vcm))
|
2016-04-23 20:49:10 +03:00
|
|
|
{
|
2022-08-18 10:20:51 +03:00
|
|
|
/* Dynamic channel status may have been changed after processing */
|
|
|
|
case DRDYNVC_STATE_NONE:
|
|
|
|
|
|
|
|
/* Call this routine to Initialize drdynvc channel */
|
|
|
|
if (!WTSVirtualChannelManagerCheckFileDescriptor(client->vcm))
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Failed to initialize drdynvc channel");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
2018-09-25 12:13:32 +03:00
|
|
|
|
2022-08-18 10:20:51 +03:00
|
|
|
case DRDYNVC_STATE_READY:
|
2023-03-06 14:42:04 +03:00
|
|
|
#if defined(CHANNEL_AUDIN_SERVER)
|
2022-08-18 10:20:51 +03:00
|
|
|
if (client->audin && !IFCALLRESULT(TRUE, client->audin->IsOpen, client->audin))
|
|
|
|
{
|
|
|
|
if (!IFCALLRESULT(FALSE, client->audin->Open, client->audin))
|
2018-09-25 12:13:32 +03:00
|
|
|
{
|
2022-08-18 10:20:51 +03:00
|
|
|
WLog_ERR(TAG, "Failed to initialize audin channel");
|
2018-09-25 12:13:32 +03:00
|
|
|
goto fail;
|
|
|
|
}
|
2022-08-18 10:20:51 +03:00
|
|
|
}
|
2023-03-06 14:42:04 +03:00
|
|
|
#endif
|
2018-09-25 12:13:32 +03:00
|
|
|
|
2022-08-18 10:20:51 +03:00
|
|
|
/* Init RDPGFX dynamic channel */
|
2023-10-13 13:04:24 +03:00
|
|
|
if (freerdp_settings_get_bool(settings, FreeRDP_SupportGraphicsPipeline) &&
|
|
|
|
client->rdpgfx && !gfxstatus.gfxOpened)
|
2022-08-18 10:20:51 +03:00
|
|
|
{
|
|
|
|
client->rdpgfx->FrameAcknowledge = shadow_client_rdpgfx_frame_acknowledge;
|
|
|
|
client->rdpgfx->CapsAdvertise = shadow_client_rdpgfx_caps_advertise;
|
2016-09-09 10:31:21 +03:00
|
|
|
|
2022-08-18 10:20:51 +03:00
|
|
|
if (!client->rdpgfx->Open(client->rdpgfx))
|
2016-04-23 20:49:10 +03:00
|
|
|
{
|
2022-08-18 10:20:51 +03:00
|
|
|
WLog_WARN(TAG, "Failed to open GraphicsPipeline");
|
2023-10-13 13:04:24 +03:00
|
|
|
if (!freerdp_settings_set_bool(settings,
|
|
|
|
FreeRDP_SupportGraphicsPipeline, FALSE))
|
|
|
|
goto fail;
|
2016-04-23 20:49:10 +03:00
|
|
|
}
|
2022-08-18 10:20:51 +03:00
|
|
|
else
|
2018-09-25 12:13:32 +03:00
|
|
|
{
|
2022-08-18 10:20:51 +03:00
|
|
|
gfxstatus.gfxOpened = TRUE;
|
|
|
|
WLog_INFO(TAG, "Gfx Pipeline Opened");
|
2018-09-25 12:13:32 +03:00
|
|
|
}
|
2022-08-18 10:20:51 +03:00
|
|
|
}
|
2018-09-25 12:13:32 +03:00
|
|
|
|
2022-08-18 10:20:51 +03:00
|
|
|
break;
|
2018-09-25 12:13:32 +03:00
|
|
|
|
2022-08-18 10:20:51 +03:00
|
|
|
default:
|
|
|
|
break;
|
2016-04-23 20:49:10 +03:00
|
|
|
}
|
2014-07-11 01:20:41 +04:00
|
|
|
}
|
2014-07-12 08:01:29 +04:00
|
|
|
|
2014-07-16 02:38:32 +04:00
|
|
|
if (WaitForSingleObject(ChannelEvent, 0) == WAIT_OBJECT_0)
|
|
|
|
{
|
2014-11-07 01:25:41 +03:00
|
|
|
if (!WTSVirtualChannelManagerCheckFileDescriptor(client->vcm))
|
2014-07-16 02:38:32 +04:00
|
|
|
{
|
2014-09-12 19:38:12 +04:00
|
|
|
WLog_ERR(TAG, "WTSVirtualChannelManagerCheckFileDescriptor failure");
|
2018-09-25 12:13:32 +03:00
|
|
|
goto fail;
|
2014-07-16 02:38:32 +04:00
|
|
|
}
|
|
|
|
}
|
2014-11-07 01:25:41 +03:00
|
|
|
|
2024-06-12 10:26:48 +03:00
|
|
|
#if defined(CHANNEL_RDPGFX_SERVER)
|
2023-07-31 15:21:18 +03:00
|
|
|
if (gfxevent)
|
|
|
|
{
|
|
|
|
if (WaitForSingleObject(gfxevent, 0) == WAIT_OBJECT_0)
|
|
|
|
{
|
|
|
|
rdpgfx_server_handle_messages(client->rdpgfx);
|
|
|
|
}
|
|
|
|
}
|
2024-06-12 10:26:48 +03:00
|
|
|
#endif
|
2023-07-31 15:21:18 +03:00
|
|
|
|
2015-04-08 21:13:52 +03:00
|
|
|
if (WaitForSingleObject(MessageQueue_Event(MsgQueue), 0) == WAIT_OBJECT_0)
|
2014-11-07 01:25:41 +03:00
|
|
|
{
|
2015-04-08 21:13:52 +03:00
|
|
|
/* Drain messages. Pointer update could be accumulated. */
|
|
|
|
pointerPositionMsg.id = 0;
|
2016-09-20 10:25:13 +03:00
|
|
|
pointerPositionMsg.Free = NULL;
|
2015-04-08 21:13:52 +03:00
|
|
|
pointerAlphaMsg.id = 0;
|
|
|
|
pointerAlphaMsg.Free = NULL;
|
|
|
|
audioVolumeMsg.id = 0;
|
|
|
|
audioVolumeMsg.Free = NULL;
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2015-04-08 21:13:52 +03:00
|
|
|
while (MessageQueue_Peek(MsgQueue, &message, TRUE))
|
2014-11-07 01:25:41 +03:00
|
|
|
{
|
|
|
|
if (message.id == WMQ_QUIT)
|
2015-04-08 21:13:52 +03:00
|
|
|
{
|
2014-11-07 01:25:41 +03:00
|
|
|
break;
|
2015-04-08 21:13:52 +03:00
|
|
|
}
|
2014-11-07 01:25:41 +03:00
|
|
|
|
2016-09-20 10:25:13 +03:00
|
|
|
switch (message.id)
|
2015-04-08 21:13:52 +03:00
|
|
|
{
|
2015-06-15 18:54:30 +03:00
|
|
|
case SHADOW_MSG_OUT_POINTER_POSITION_UPDATE_ID:
|
|
|
|
/* Abandon previous message */
|
|
|
|
shadow_client_free_queued_message(&pointerPositionMsg);
|
2021-07-01 09:01:54 +03:00
|
|
|
pointerPositionMsg = message;
|
2015-06-15 18:54:30 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SHADOW_MSG_OUT_POINTER_ALPHA_UPDATE_ID:
|
|
|
|
/* Abandon previous message */
|
|
|
|
shadow_client_free_queued_message(&pointerAlphaMsg);
|
2021-07-01 09:01:54 +03:00
|
|
|
pointerAlphaMsg = message;
|
2015-06-15 18:54:30 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SHADOW_MSG_OUT_AUDIO_OUT_VOLUME_ID:
|
|
|
|
/* Abandon previous message */
|
|
|
|
shadow_client_free_queued_message(&audioVolumeMsg);
|
2021-07-01 09:01:54 +03:00
|
|
|
audioVolumeMsg = message;
|
2015-06-15 18:54:30 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
shadow_client_subsystem_process_message(client, &message);
|
|
|
|
break;
|
2015-04-08 21:13:52 +03:00
|
|
|
}
|
|
|
|
}
|
2014-11-07 01:25:41 +03:00
|
|
|
|
2015-04-08 21:13:52 +03:00
|
|
|
if (message.id == WMQ_QUIT)
|
|
|
|
{
|
|
|
|
/* Release stored message */
|
|
|
|
shadow_client_free_queued_message(&pointerPositionMsg);
|
|
|
|
shadow_client_free_queued_message(&pointerAlphaMsg);
|
|
|
|
shadow_client_free_queued_message(&audioVolumeMsg);
|
2018-09-25 12:13:32 +03:00
|
|
|
goto fail;
|
2015-04-08 21:13:52 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Process accumulated messages if needed */
|
|
|
|
if (pointerPositionMsg.id)
|
|
|
|
{
|
|
|
|
shadow_client_subsystem_process_message(client, &pointerPositionMsg);
|
|
|
|
}
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2015-04-08 21:13:52 +03:00
|
|
|
if (pointerAlphaMsg.id)
|
|
|
|
{
|
|
|
|
shadow_client_subsystem_process_message(client, &pointerAlphaMsg);
|
|
|
|
}
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2015-04-08 21:13:52 +03:00
|
|
|
if (audioVolumeMsg.id)
|
|
|
|
{
|
|
|
|
shadow_client_subsystem_process_message(client, &audioVolumeMsg);
|
|
|
|
}
|
2014-11-07 01:25:41 +03:00
|
|
|
}
|
|
|
|
}
|
2014-07-11 01:20:41 +04:00
|
|
|
}
|
|
|
|
|
2018-09-25 12:13:32 +03:00
|
|
|
fail:
|
|
|
|
|
2015-04-08 21:13:52 +03:00
|
|
|
/* Free channels early because we establish channels in post connect */
|
2023-03-06 14:42:04 +03:00
|
|
|
#if defined(CHANNEL_AUDIN_SERVER)
|
2018-09-25 12:13:32 +03:00
|
|
|
if (client->audin && !IFCALLRESULT(TRUE, client->audin->IsOpen, client->audin))
|
|
|
|
{
|
|
|
|
if (!IFCALLRESULT(FALSE, client->audin->Close, client->audin))
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "AUDIN shutdown failure!");
|
|
|
|
}
|
|
|
|
}
|
2023-03-06 14:42:04 +03:00
|
|
|
#endif
|
2018-09-25 12:13:32 +03:00
|
|
|
|
2016-04-23 20:49:10 +03:00
|
|
|
if (gfxstatus.gfxOpened)
|
|
|
|
{
|
|
|
|
if (gfxstatus.gfxSurfaceCreated)
|
|
|
|
{
|
2016-05-03 19:48:59 +03:00
|
|
|
if (!shadow_client_rdpgfx_release_surface(client))
|
|
|
|
WLog_WARN(TAG, "GFX release surface failure!");
|
2016-04-23 20:49:10 +03:00
|
|
|
}
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2021-07-01 09:01:54 +03:00
|
|
|
WINPR_ASSERT(client->rdpgfx);
|
|
|
|
WINPR_ASSERT(client->rdpgfx->Close);
|
|
|
|
rc = client->rdpgfx->Close(client->rdpgfx);
|
|
|
|
WINPR_ASSERT(rc);
|
2016-04-23 20:49:10 +03:00
|
|
|
}
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2015-04-08 21:13:52 +03:00
|
|
|
shadow_client_channels_free(client);
|
|
|
|
|
2015-05-10 19:00:02 +03:00
|
|
|
if (UpdateSubscriber)
|
|
|
|
{
|
|
|
|
shadow_multiclient_release_subscriber(UpdateSubscriber);
|
|
|
|
UpdateSubscriber = NULL;
|
|
|
|
}
|
|
|
|
|
2015-04-08 20:37:41 +03:00
|
|
|
if (peer->connected && subsystem->ClientDisconnect)
|
|
|
|
{
|
2015-06-15 14:37:26 +03:00
|
|
|
subsystem->ClientDisconnect(subsystem, client);
|
2015-04-08 20:37:41 +03:00
|
|
|
}
|
|
|
|
|
2015-05-10 19:00:02 +03:00
|
|
|
out:
|
2021-07-01 09:01:54 +03:00
|
|
|
WINPR_ASSERT(peer->Disconnect);
|
2014-07-12 03:30:40 +04:00
|
|
|
peer->Disconnect(peer);
|
|
|
|
freerdp_peer_context_free(peer);
|
|
|
|
freerdp_peer_free(peer);
|
2014-07-11 01:20:41 +04:00
|
|
|
ExitThread(0);
|
2018-03-07 14:03:10 +03:00
|
|
|
return 0;
|
2014-07-11 01:20:41 +04:00
|
|
|
}
|
|
|
|
|
2015-04-28 18:00:41 +03:00
|
|
|
BOOL shadow_client_accepted(freerdp_listener* listener, freerdp_peer* peer)
|
2014-07-11 01:20:41 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
rdpShadowClient* client = NULL;
|
|
|
|
rdpShadowServer* server = NULL;
|
2017-02-20 20:31:58 +03:00
|
|
|
|
|
|
|
if (!listener || !peer)
|
|
|
|
return FALSE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
server = (rdpShadowServer*)listener->info;
|
2021-07-01 09:01:54 +03:00
|
|
|
WINPR_ASSERT(server);
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
peer->ContextExtra = (void*)server;
|
2014-07-12 03:30:40 +04:00
|
|
|
peer->ContextSize = sizeof(rdpShadowClient);
|
2021-06-30 14:04:22 +03:00
|
|
|
peer->ContextNew = shadow_client_context_new;
|
|
|
|
peer->ContextFree = shadow_client_context_free;
|
2016-07-22 00:53:20 +03:00
|
|
|
|
2022-03-23 15:18:35 +03:00
|
|
|
if (!freerdp_peer_context_new_ex(peer, server->settings))
|
2015-04-28 18:00:41 +03:00
|
|
|
return FALSE;
|
2014-07-12 03:30:40 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
client = (rdpShadowClient*)peer->context;
|
2021-07-01 09:01:54 +03:00
|
|
|
WINPR_ASSERT(client);
|
2014-07-11 01:20:41 +04:00
|
|
|
|
2018-03-07 14:03:10 +03:00
|
|
|
if (!(client->thread = CreateThread(NULL, 0, shadow_client_thread, client, 0, NULL)))
|
2015-05-05 14:55:48 +03:00
|
|
|
{
|
|
|
|
freerdp_peer_context_free(peer);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2017-04-10 21:25:36 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Close the thread handle to make it detached. */
|
|
|
|
CloseHandle(client->thread);
|
|
|
|
client->thread = NULL;
|
|
|
|
}
|
2015-04-28 18:00:41 +03:00
|
|
|
|
|
|
|
return TRUE;
|
2014-07-11 01:20:41 +04:00
|
|
|
}
|
2015-04-08 21:13:52 +03:00
|
|
|
|
|
|
|
static void shadow_msg_out_addref(wMessage* message)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
SHADOW_MSG_OUT* msg = NULL;
|
2021-07-01 09:01:54 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(message);
|
|
|
|
msg = (SHADOW_MSG_OUT*)message->wParam;
|
|
|
|
WINPR_ASSERT(msg);
|
|
|
|
|
2015-04-08 21:13:52 +03:00
|
|
|
InterlockedIncrement(&(msg->refCount));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void shadow_msg_out_release(wMessage* message)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
SHADOW_MSG_OUT* msg = NULL;
|
2021-07-01 09:01:54 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(message);
|
|
|
|
msg = (SHADOW_MSG_OUT*)message->wParam;
|
|
|
|
WINPR_ASSERT(msg);
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2015-04-08 21:13:52 +03:00
|
|
|
if (InterlockedDecrement(&(msg->refCount)) <= 0)
|
|
|
|
{
|
2021-07-01 09:01:54 +03:00
|
|
|
IFCALL(msg->Free, message->id, msg);
|
2015-04-08 21:13:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL shadow_client_dispatch_msg(rdpShadowClient* client, wMessage* message)
|
2015-04-08 21:13:52 +03:00
|
|
|
{
|
2017-02-20 20:31:58 +03:00
|
|
|
if (!client || !message)
|
|
|
|
return FALSE;
|
|
|
|
|
2015-04-08 21:13:52 +03:00
|
|
|
/* Add reference when it is posted */
|
|
|
|
shadow_msg_out_addref(message);
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2021-07-01 09:01:54 +03:00
|
|
|
WINPR_ASSERT(client->MsgQueue);
|
2015-04-08 21:13:52 +03:00
|
|
|
if (MessageQueue_Dispatch(client->MsgQueue, message))
|
|
|
|
return TRUE;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Release the reference since post failed */
|
|
|
|
shadow_msg_out_release(message);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-20 10:25:13 +03:00
|
|
|
BOOL shadow_client_post_msg(rdpShadowClient* client, void* context, UINT32 type,
|
|
|
|
SHADOW_MSG_OUT* msg, void* lParam)
|
2015-04-08 21:13:52 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
wMessage message = { 0 };
|
2015-04-08 21:13:52 +03:00
|
|
|
message.context = context;
|
|
|
|
message.id = type;
|
2016-09-20 10:25:13 +03:00
|
|
|
message.wParam = (void*)msg;
|
2015-04-08 21:13:52 +03:00
|
|
|
message.lParam = lParam;
|
|
|
|
message.Free = shadow_msg_out_release;
|
|
|
|
return shadow_client_dispatch_msg(client, &message);
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
int shadow_client_boardcast_msg(rdpShadowServer* server, void* context, UINT32 type,
|
|
|
|
SHADOW_MSG_OUT* msg, void* lParam)
|
2015-04-08 21:13:52 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
wMessage message = { 0 };
|
2015-04-08 21:13:52 +03:00
|
|
|
rdpShadowClient* client = NULL;
|
|
|
|
int count = 0;
|
2021-07-01 09:01:54 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(server);
|
|
|
|
WINPR_ASSERT(msg);
|
|
|
|
|
2015-04-08 21:13:52 +03:00
|
|
|
message.context = context;
|
|
|
|
message.id = type;
|
2016-09-20 10:25:13 +03:00
|
|
|
message.wParam = (void*)msg;
|
2015-04-08 21:13:52 +03:00
|
|
|
message.lParam = lParam;
|
|
|
|
message.Free = shadow_msg_out_release;
|
|
|
|
/* First add reference as we reference it in this function.
|
2016-09-20 10:25:13 +03:00
|
|
|
* Therefore it would not be free'ed during post. */
|
2015-04-08 21:13:52 +03:00
|
|
|
shadow_msg_out_addref(&message);
|
2021-07-01 09:01:54 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(server->clients);
|
2015-04-08 21:13:52 +03:00
|
|
|
ArrayList_Lock(server->clients);
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (size_t index = 0; index < ArrayList_Count(server->clients); index++)
|
2015-04-08 21:13:52 +03:00
|
|
|
{
|
|
|
|
client = (rdpShadowClient*)ArrayList_GetItem(server->clients, index);
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2015-04-08 21:13:52 +03:00
|
|
|
if (shadow_client_dispatch_msg(client, &message))
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-20 10:25:13 +03:00
|
|
|
ArrayList_Unlock(server->clients);
|
|
|
|
/* Release the reference for this function */
|
2015-04-08 21:13:52 +03:00
|
|
|
shadow_msg_out_release(&message);
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
|
|
|
int shadow_client_boardcast_quit(rdpShadowServer* server, int nExitCode)
|
|
|
|
{
|
|
|
|
wMessageQueue* queue = NULL;
|
|
|
|
int count = 0;
|
2021-07-01 09:01:54 +03:00
|
|
|
|
|
|
|
WINPR_ASSERT(server);
|
|
|
|
WINPR_ASSERT(server->clients);
|
|
|
|
|
2015-04-08 21:13:52 +03:00
|
|
|
ArrayList_Lock(server->clients);
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (size_t index = 0; index < ArrayList_Count(server->clients); index++)
|
2015-04-08 21:13:52 +03:00
|
|
|
{
|
|
|
|
queue = ((rdpShadowClient*)ArrayList_GetItem(server->clients, index))->MsgQueue;
|
2016-09-20 10:25:13 +03:00
|
|
|
|
2015-04-08 21:13:52 +03:00
|
|
|
if (MessageQueue_PostQuit(queue, nExitCode))
|
|
|
|
{
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-20 10:25:13 +03:00
|
|
|
ArrayList_Unlock(server->clients);
|
2015-04-08 21:13:52 +03:00
|
|
|
return count;
|
|
|
|
}
|