From bee2e1526d158e7cd9f7b626fab1456407e7d32d Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Tue, 15 Dec 2020 18:11:22 +0300 Subject: [PATCH] allow to use in single threaded mode (some client side channels and all server side channels still need to be ported to new api) server: build fix, do not disable threads for rfx encoder cliprdr client channel: implemented support for DisableThreads option looks like thread does not make sense at all for this channel do not initialize disabled image codecs (respect settings) channels: client: rail: added support for DisableThreads setting changed "BOOL DisableThreads" to "UINT32 ThreadingFlags" dropped unnecessary apu changes draft implementation of threading settings aware message handling api for addins/channels rail: use new messaging api fixed memory leak msgs handlers external api changes (as requested) msgs_handlers: init fix fixed memory leak logic fix resolved problems appeared after rebase to master, dropped unnecessary changes git clang-format origin/master fixed TestFreeRDPCodecRemoteFX.c "formatting, run `clang-format` please" properly use new "rfx_context_new(BOOL, UINT32)" everywhere passed Threading Flags to "rfx_context_new" where available in older C standarts veriables declaration must be done before any code requested changes clang-format as requested use broken signatures of standert C functions for m$ s**tos clang-format requested changes requested changes moved ThreadingFlags to stable api zone define type for channel msg handler typo fix clang-format build fix us ThreadingFlags from server settings git clang-format origin/master clang-format --- channels/client/addin.c | 215 ++++++++++++++++++ channels/client/addin.h | 10 + channels/cliprdr/client/cliprdr_main.c | 162 +------------ channels/cliprdr/client/cliprdr_main.h | 4 +- channels/cliprdr/server/cliprdr_main.c | 1 - channels/drdynvc/client/drdynvc_main.c | 24 +- channels/printer/client/printer_main.c | 3 +- channels/rail/client/rail_main.c | 158 +------------ channels/rail/client/rail_main.h | 4 +- channels/rail/client/rail_orders.c | 3 +- channels/rail/client/rail_orders.h | 2 +- channels/rdpdr/client/devman.c | 3 +- .../rdpsnd/client/opensles/rdpsnd_opensles.c | 3 +- channels/rdpsnd/client/proxy/rdpsnd_proxy.c | 1 - channels/serial/client/serial_main.c | 2 +- .../smartcard/client/smartcard_operations.c | 6 +- .../urbdrc/client/libusb/libusb_udevice.c | 1 - channels/video/client/video_main.c | 21 +- client/X11/xf_input.c | 6 +- include/freerdp/codec/rfx.h | 2 +- include/freerdp/codec/yuv.h | 2 +- include/freerdp/settings.h | 42 ++-- libfreerdp/codec/dsp.c | 3 +- libfreerdp/codec/nsc_encode.c | 4 +- libfreerdp/codec/nsc_sse2.c | 4 +- libfreerdp/codec/planar.c | 2 +- libfreerdp/codec/progressive.c | 5 +- libfreerdp/codec/rfx.c | 17 +- .../codec/test/TestFreeRDPCodecRemoteFX.c | 4 +- libfreerdp/codec/yuv.c | 30 ++- libfreerdp/common/settings.c | 15 ++ libfreerdp/core/capabilities.c | 60 ++--- libfreerdp/core/client.c | 3 +- libfreerdp/core/codecs.c | 3 +- libfreerdp/core/connection.c | 4 +- libfreerdp/core/gateway/rpc.h | 3 +- libfreerdp/core/info.c | 9 +- libfreerdp/gdi/gfx.c | 6 +- server/Mac/mf_peer.c | 2 +- server/Sample/sfreerdp.c | 2 +- server/Windows/wf_update.c | 3 +- server/proxy/pf_modules.c | 6 +- server/shadow/shadow_encoder.c | 2 +- uwac/include/uwac/uwac.h | 3 +- winpr/include/winpr/asn1.h | 6 +- winpr/include/winpr/file.h | 3 +- winpr/include/winpr/interlocked.h | 6 +- winpr/include/winpr/io.h | 3 +- winpr/include/winpr/ndr.h | 9 +- winpr/include/winpr/nt.h | 3 +- winpr/include/winpr/pool.h | 3 +- winpr/include/winpr/rpc.h | 15 +- winpr/include/winpr/smartcard.h | 6 +- winpr/include/winpr/synch.h | 3 +- winpr/include/winpr/sysinfo.h | 3 +- winpr/include/winpr/winsock.h | 3 +- winpr/include/winpr/wtsapi.h | 6 +- winpr/libwinpr/registry/registry_reg.h | 3 +- winpr/libwinpr/smartcard/smartcard_pcsc.c | 42 ++-- winpr/libwinpr/utils/trio/trio.c | 15 +- 60 files changed, 527 insertions(+), 467 deletions(-) diff --git a/channels/client/addin.c b/channels/client/addin.c index cd6f90e99..c13b23dd8 100644 --- a/channels/client/addin.c +++ b/channels/client/addin.c @@ -411,3 +411,218 @@ PVIRTUALCHANNELENTRY freerdp_channels_load_static_addin_entry(LPCSTR pszName, LP return NULL; } + +typedef struct +{ + wMessageQueue* queue; + wStream* data_in; + HANDLE thread; + char* channel_name; + rdpContext* ctx; + LPVOID userdata; + MsgHandler msg_handler; +} msg_proc_internals; + +static DWORD WINAPI channel_client_thread_proc(LPVOID userdata) +{ + UINT error = CHANNEL_RC_OK; + wStream* data; + wMessage message; + msg_proc_internals* internals = userdata; + if (!internals) + { + /* TODO: return some error */ + } + while (1) + { + if (!MessageQueue_Wait(internals->queue)) + { + WLog_ERR(TAG, "MessageQueue_Wait failed!"); + error = ERROR_INTERNAL_ERROR; + break; + } + if (!MessageQueue_Peek(internals->queue, &message, TRUE)) + { + WLog_ERR(TAG, "MessageQueue_Peek failed!"); + error = ERROR_INTERNAL_ERROR; + break; + } + + if (message.id == WMQ_QUIT) + break; + + if (message.id == 0) + { + data = (wStream*)message.wParam; + + if ((error = internals->msg_handler(internals->userdata, data))) + { + WLog_ERR(TAG, "msg_handler failed with error %" PRIu32 "!", error); + break; + } + } + } + if (error && internals->ctx) + { + char msg[128]; + _snprintf(msg, 127, + "%s_virtual_channel_client_thread reported an" + " error", + internals->channel_name); + setChannelError(internals->ctx, error, msg); + } + ExitThread(error); + return error; +} + +static void free_msg(void* obj) +{ + wMessage* msg = (wMessage*)obj; + + if (msg) + { + wStream* s = (wStream*)msg->wParam; + Stream_Free(s, TRUE); + } +} + +/* Create message queue and thread or not, depending on settings */ +void* channel_client_create_handler(rdpContext* ctx, LPVOID userdata, MsgHandler msg_handler, + const char* channel_name) +{ + msg_proc_internals* internals = calloc(1, sizeof(msg_proc_internals)); + if (!internals) + { + WLog_ERR(TAG, "calloc failed!"); + return 0; + } + internals->msg_handler = msg_handler; + internals->userdata = userdata; + internals->channel_name = strdup(channel_name); + internals->ctx = ctx; + if (!(ctx->settings->ThreadingFlags & THREADING_FLAGS_DISABLE_THREADS)) + { + wObject obj = { 0 }; + obj.fnObjectFree = free_msg; + internals->queue = MessageQueue_New(&obj); + if (!internals->queue) + { + WLog_ERR(TAG, "MessageQueue_New failed!"); + return 0; + } + + if (!(internals->thread = + CreateThread(NULL, 0, channel_client_thread_proc, (void*)internals, 0, NULL))) + { + WLog_ERR(TAG, "CreateThread failed!"); + MessageQueue_Free(internals->queue); + internals->queue = NULL; + } + } + return internals; +} +/* post a message in the queue or directly call the processing handler */ +UINT channel_client_post_message(void* MsgsHandle, LPVOID pData, UINT32 dataLength, + UINT32 totalLength, UINT32 dataFlags) +{ + msg_proc_internals* internals = MsgsHandle; + wStream* data_in; + + if (!internals) + { + /* TODO: return some error here */ + return CHANNEL_RC_OK; + } + + if ((dataFlags & CHANNEL_FLAG_SUSPEND) || (dataFlags & CHANNEL_FLAG_RESUME)) + { + return CHANNEL_RC_OK; + } + + if (dataFlags & CHANNEL_FLAG_FIRST) + { + if (internals->data_in) + Stream_Free(internals->data_in, TRUE); + + internals->data_in = Stream_New(NULL, totalLength); + } + + if (!(data_in = internals->data_in)) + { + WLog_ERR(TAG, "Stream_New failed!"); + return CHANNEL_RC_NO_MEMORY; + } + + if (!Stream_EnsureRemainingCapacity(data_in, dataLength)) + { + Stream_Free(internals->data_in, TRUE); + internals->data_in = NULL; + return CHANNEL_RC_NO_MEMORY; + } + + Stream_Write(data_in, pData, dataLength); + + if (dataFlags & CHANNEL_FLAG_LAST) + { + if (Stream_Capacity(data_in) != Stream_GetPosition(data_in)) + { + char msg[128]; + _snprintf(msg, 127, "%s_plugin_process_received: read error", internals->channel_name); + WLog_ERR(TAG, msg); + return ERROR_INTERNAL_ERROR; + } + + internals->data_in = NULL; + Stream_SealLength(data_in); + Stream_SetPosition(data_in, 0); + + if (internals->ctx->settings->ThreadingFlags & THREADING_FLAGS_DISABLE_THREADS) + { + UINT error = CHANNEL_RC_OK; + if ((error = internals->msg_handler(internals->userdata, data_in))) + { + WLog_ERR(TAG, + "msg_handler failed with error" + " %" PRIu32 "!", + error); + return ERROR_INTERNAL_ERROR; + } + } + } + return CHANNEL_RC_OK; +} +/* Tear down queue and thread */ +UINT channel_client_quit_handler(void* MsgsHandle) +{ + msg_proc_internals* internals = MsgsHandle; + UINT rc; + if (!internals) + { + /* TODO: return some error here */ + return CHANNEL_RC_OK; + } + if (!(internals->ctx->settings->ThreadingFlags & THREADING_FLAGS_DISABLE_THREADS)) + { + if (MessageQueue_PostQuit(internals->queue, 0) && + (WaitForSingleObject(internals->thread, INFINITE) == WAIT_FAILED)) + { + rc = GetLastError(); + WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", rc); + return rc; + } + MessageQueue_Free(internals->queue); + CloseHandle(internals->thread); + } + if (internals->data_in) + { + Stream_Free(internals->data_in, TRUE); + internals->data_in = NULL; + } + if (internals->channel_name) + { + free(internals->channel_name); + } + + free(internals); + return CHANNEL_RC_OK; +} diff --git a/channels/client/addin.h b/channels/client/addin.h index 849b11f29..693831973 100644 --- a/channels/client/addin.h +++ b/channels/client/addin.h @@ -16,3 +16,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + +typedef UINT (*MsgHandler)(LPVOID userdata, wStream* data); + +FREERDP_API void* channel_client_create_handler(rdpContext* ctx, LPVOID userdata, MsgHandler, + const char* channel_name); + +UINT channel_client_post_message(void* MsgsHandle, LPVOID pData, UINT32 dataLength, + UINT32 totalLength, UINT32 dataFlags); + +UINT channel_client_quit_handler(void* MsgsHandle); diff --git a/channels/cliprdr/client/cliprdr_main.c b/channels/cliprdr/client/cliprdr_main.c index 98527845d..dc08f840d 100644 --- a/channels/cliprdr/client/cliprdr_main.c +++ b/channels/cliprdr/client/cliprdr_main.c @@ -32,6 +32,8 @@ #include #include +#include "../../channels/client/addin.h" + #include "cliprdr_main.h" #include "cliprdr_format.h" #include "../cliprdr_common.h" @@ -445,8 +447,9 @@ static UINT cliprdr_process_unlock_clipdata(cliprdrPlugin* cliprdr, wStream* s, * * @return 0 on success, otherwise a Win32 error code */ -static UINT cliprdr_order_recv(cliprdrPlugin* cliprdr, wStream* s) +static UINT cliprdr_order_recv(LPVOID userdata, wStream* s) { + cliprdrPlugin* cliprdr = userdata; UINT16 msgType; UINT16 msgFlags; UINT32 dataLen; @@ -849,67 +852,6 @@ cliprdr_client_file_contents_response(CliprdrClientContext* context, return cliprdr_packet_send(cliprdr, s); } -/** - * Function description - * - * @return 0 on success, otherwise a Win32 error code - */ -static UINT cliprdr_virtual_channel_event_data_received(cliprdrPlugin* cliprdr, void* pData, - UINT32 dataLength, UINT32 totalLength, - UINT32 dataFlags) -{ - wStream* data_in; - - if ((dataFlags & CHANNEL_FLAG_SUSPEND) || (dataFlags & CHANNEL_FLAG_RESUME)) - { - return CHANNEL_RC_OK; - } - - if (dataFlags & CHANNEL_FLAG_FIRST) - { - if (cliprdr->data_in) - Stream_Free(cliprdr->data_in, TRUE); - - cliprdr->data_in = Stream_New(NULL, totalLength); - } - - if (!(data_in = cliprdr->data_in)) - { - WLog_ERR(TAG, "Stream_New failed!"); - return CHANNEL_RC_NO_MEMORY; - } - - if (!Stream_EnsureRemainingCapacity(data_in, dataLength)) - { - Stream_Free(cliprdr->data_in, TRUE); - cliprdr->data_in = NULL; - return CHANNEL_RC_NO_MEMORY; - } - - Stream_Write(data_in, pData, dataLength); - - if (dataFlags & CHANNEL_FLAG_LAST) - { - if (Stream_Capacity(data_in) != Stream_GetPosition(data_in)) - { - WLog_ERR(TAG, "cliprdr_plugin_process_received: read error"); - return ERROR_INTERNAL_ERROR; - } - - cliprdr->data_in = NULL; - Stream_SealLength(data_in); - Stream_SetPosition(data_in, 0); - - if (!MessageQueue_Post(cliprdr->queue, NULL, 0, (void*)data_in, NULL)) - { - WLog_ERR(TAG, "MessageQueue_Post failed!"); - return ERROR_INTERNAL_ERROR; - } - } - - return CHANNEL_RC_OK; -} - static VOID VCAPITYPE cliprdr_virtual_channel_open_event_ex(LPVOID lpUserParam, DWORD openHandle, UINT event, LPVOID pData, UINT32 dataLength, UINT32 totalLength, @@ -926,8 +868,8 @@ static VOID VCAPITYPE cliprdr_virtual_channel_open_event_ex(LPVOID lpUserParam, WLog_ERR(TAG, "error no match"); return; } - if ((error = cliprdr_virtual_channel_event_data_received(cliprdr, pData, dataLength, - totalLength, dataFlags))) + if ((error = channel_client_post_message(cliprdr->MsgsHandle, pData, dataLength, + totalLength, dataFlags))) WLog_ERR(TAG, "failed with error %" PRIu32 "", error); break; @@ -949,62 +891,6 @@ static VOID VCAPITYPE cliprdr_virtual_channel_open_event_ex(LPVOID lpUserParam, "cliprdr_virtual_channel_open_event_ex reported an error"); } -static DWORD WINAPI cliprdr_virtual_channel_client_thread(LPVOID arg) -{ - wStream* data; - wMessage message; - cliprdrPlugin* cliprdr = (cliprdrPlugin*)arg; - UINT error = CHANNEL_RC_OK; - - while (1) - { - if (!MessageQueue_Wait(cliprdr->queue)) - { - WLog_ERR(TAG, "MessageQueue_Wait failed!"); - error = ERROR_INTERNAL_ERROR; - break; - } - - if (!MessageQueue_Peek(cliprdr->queue, &message, TRUE)) - { - WLog_ERR(TAG, "MessageQueue_Peek failed!"); - error = ERROR_INTERNAL_ERROR; - break; - } - - if (message.id == WMQ_QUIT) - break; - - if (message.id == 0) - { - data = (wStream*)message.wParam; - - if ((error = cliprdr_order_recv(cliprdr, data))) - { - WLog_ERR(TAG, "cliprdr_order_recv failed with error %" PRIu32 "!", error); - break; - } - } - } - - if (error && cliprdr->context->rdpcontext) - setChannelError(cliprdr->context->rdpcontext, error, - "cliprdr_virtual_channel_client_thread reported an error"); - - ExitThread(error); - return error; -} - -static void cliprdr_free_msg(void* obj) -{ - wMessage* msg = (wMessage*)obj; - - if (msg) - { - wStream* s = (wStream*)msg->wParam; - Stream_Free(s, TRUE); - } -} /** * Function description @@ -1015,7 +901,6 @@ static UINT cliprdr_virtual_channel_event_connected(cliprdrPlugin* cliprdr, LPVO UINT32 dataLength) { UINT32 status; - wObject obj = { 0 }; status = cliprdr->channelEntryPoints.pVirtualChannelOpenEx( cliprdr->InitHandle, &cliprdr->OpenHandle, cliprdr->channelDef.name, cliprdr_virtual_channel_open_event_ex); @@ -1027,23 +912,8 @@ static UINT cliprdr_virtual_channel_event_connected(cliprdrPlugin* cliprdr, LPVO return status; } - obj.fnObjectFree = cliprdr_free_msg; - cliprdr->queue = MessageQueue_New(&obj); - - if (!cliprdr->queue) - { - WLog_ERR(TAG, "MessageQueue_New failed!"); - return ERROR_NOT_ENOUGH_MEMORY; - } - - if (!(cliprdr->thread = CreateThread(NULL, 0, cliprdr_virtual_channel_client_thread, - (void*)cliprdr, 0, NULL))) - { - WLog_ERR(TAG, "CreateThread failed!"); - MessageQueue_Free(cliprdr->queue); - cliprdr->queue = NULL; - return ERROR_INTERNAL_ERROR; - } + cliprdr->MsgsHandle = channel_client_create_handler(cliprdr->context->rdpcontext, cliprdr, + cliprdr_order_recv, "cliprdr"); return CHANNEL_RC_OK; } @@ -1060,16 +930,8 @@ static UINT cliprdr_virtual_channel_event_disconnected(cliprdrPlugin* cliprdr) if (cliprdr->OpenHandle == 0) return CHANNEL_RC_OK; - if (MessageQueue_PostQuit(cliprdr->queue, 0) && - (WaitForSingleObject(cliprdr->thread, INFINITE) == WAIT_FAILED)) - { - rc = GetLastError(); - WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", rc); - return rc; - } + channel_client_quit_handler(cliprdr->MsgsHandle); - MessageQueue_Free(cliprdr->queue); - CloseHandle(cliprdr->thread); rc = cliprdr->channelEntryPoints.pVirtualChannelCloseEx(cliprdr->InitHandle, cliprdr->OpenHandle); @@ -1082,12 +944,6 @@ static UINT cliprdr_virtual_channel_event_disconnected(cliprdrPlugin* cliprdr) cliprdr->OpenHandle = 0; - if (cliprdr->data_in) - { - Stream_Free(cliprdr->data_in, TRUE); - cliprdr->data_in = NULL; - } - return CHANNEL_RC_OK; } diff --git a/channels/cliprdr/client/cliprdr_main.h b/channels/cliprdr/client/cliprdr_main.h index b6cd7dbab..8bb718205 100644 --- a/channels/cliprdr/client/cliprdr_main.h +++ b/channels/cliprdr/client/cliprdr_main.h @@ -38,11 +38,9 @@ struct cliprdr_plugin CliprdrClientContext* context; wLog* log; - HANDLE thread; - wStream* data_in; void* InitHandle; DWORD OpenHandle; - wMessageQueue* queue; + void* MsgsHandle; BOOL capabilitiesReceived; BOOL useLongFormatNames; diff --git a/channels/cliprdr/server/cliprdr_main.c b/channels/cliprdr/server/cliprdr_main.c index 7e0b6812e..2cbdcc3e7 100644 --- a/channels/cliprdr/server/cliprdr_main.c +++ b/channels/cliprdr/server/cliprdr_main.c @@ -478,7 +478,6 @@ static UINT cliprdr_server_receive_capabilities(CliprdrServerContext* context, w WINPR_UNUSED(header); - WLog_DBG(TAG, "CliprdrClientCapabilities"); if (Stream_GetRemainingLength(s) < 4) return ERROR_INVALID_DATA; diff --git a/channels/drdynvc/client/drdynvc_main.c b/channels/drdynvc/client/drdynvc_main.c index 69977444a..054a7af23 100644 --- a/channels/drdynvc/client/drdynvc_main.c +++ b/channels/drdynvc/client/drdynvc_main.c @@ -691,7 +691,7 @@ static UINT dvcman_receive_channel_data_first(drdynvcPlugin* drdynvc, */ static UINT dvcman_receive_channel_data(drdynvcPlugin* drdynvc, IWTSVirtualChannelManager* pChannelMgr, UINT32 ChannelId, - wStream* data) + wStream* data, UINT32 ThreadingFlags) { UINT status = CHANNEL_RC_OK; DVCMAN_CHANNEL* channel; @@ -1123,7 +1123,8 @@ static UINT drdynvc_process_create_request(drdynvcPlugin* drdynvc, int Sp, int c * * @return 0 on success, otherwise a Win32 error code */ -static UINT drdynvc_process_data_first(drdynvcPlugin* drdynvc, int Sp, int cbChId, wStream* s) +static UINT drdynvc_process_data_first(drdynvcPlugin* drdynvc, int Sp, int cbChId, wStream* s, + UINT32 ThreadingFlags) { UINT status; UINT32 Length; @@ -1140,7 +1141,8 @@ static UINT drdynvc_process_data_first(drdynvcPlugin* drdynvc, int Sp, int cbChI status = dvcman_receive_channel_data_first(drdynvc, drdynvc->channel_mgr, ChannelId, Length); if (status == CHANNEL_RC_OK) - status = dvcman_receive_channel_data(drdynvc, drdynvc->channel_mgr, ChannelId, s); + status = dvcman_receive_channel_data(drdynvc, drdynvc->channel_mgr, ChannelId, s, + ThreadingFlags); if (status != CHANNEL_RC_OK) status = dvcman_close_channel(drdynvc->channel_mgr, ChannelId, TRUE); @@ -1153,7 +1155,8 @@ static UINT drdynvc_process_data_first(drdynvcPlugin* drdynvc, int Sp, int cbChI * * @return 0 on success, otherwise a Win32 error code */ -static UINT drdynvc_process_data(drdynvcPlugin* drdynvc, int Sp, int cbChId, wStream* s) +static UINT drdynvc_process_data(drdynvcPlugin* drdynvc, int Sp, int cbChId, wStream* s, + UINT32 ThreadingFlags) { UINT32 ChannelId; UINT status; @@ -1164,7 +1167,8 @@ static UINT drdynvc_process_data(drdynvcPlugin* drdynvc, int Sp, int cbChId, wSt ChannelId = drdynvc_read_variable_uint(s, cbChId); WLog_Print(drdynvc->log, WLOG_TRACE, "process_data: Sp=%d cbChId=%d, ChannelId=%" PRIu32 "", Sp, cbChId, ChannelId); - status = dvcman_receive_channel_data(drdynvc, drdynvc->channel_mgr, ChannelId, s); + status = + dvcman_receive_channel_data(drdynvc, drdynvc->channel_mgr, ChannelId, s, ThreadingFlags); if (status != CHANNEL_RC_OK) status = dvcman_close_channel(drdynvc->channel_mgr, ChannelId, TRUE); @@ -1202,7 +1206,7 @@ static UINT drdynvc_process_close_request(drdynvcPlugin* drdynvc, int Sp, int cb * * @return 0 on success, otherwise a Win32 error code */ -static UINT drdynvc_order_recv(drdynvcPlugin* drdynvc, wStream* s) +static UINT drdynvc_order_recv(drdynvcPlugin* drdynvc, wStream* s, UINT32 ThreadingFlags) { int value; int Cmd; @@ -1227,10 +1231,10 @@ static UINT drdynvc_order_recv(drdynvcPlugin* drdynvc, wStream* s) return drdynvc_process_create_request(drdynvc, Sp, cbChId, s); case DATA_FIRST_PDU: - return drdynvc_process_data_first(drdynvc, Sp, cbChId, s); + return drdynvc_process_data_first(drdynvc, Sp, cbChId, s, ThreadingFlags); case DATA_PDU: - return drdynvc_process_data(drdynvc, Sp, cbChId, s); + return drdynvc_process_data(drdynvc, Sp, cbChId, s, ThreadingFlags); case CLOSE_REQUEST_PDU: return drdynvc_process_close_request(drdynvc, Sp, cbChId, s); @@ -1350,6 +1354,7 @@ static void VCAPITYPE drdynvc_virtual_channel_open_event_ex(LPVOID lpUserParam, static DWORD WINAPI drdynvc_virtual_channel_client_thread(LPVOID arg) { + /* TODO: rewrite this */ wStream* data; wMessage message; UINT error = CHANNEL_RC_OK; @@ -1382,9 +1387,10 @@ static DWORD WINAPI drdynvc_virtual_channel_client_thread(LPVOID arg) if (message.id == 0) { + UINT32 ThreadingFlags = TRUE; data = (wStream*)message.wParam; - if ((error = drdynvc_order_recv(drdynvc, data))) + if ((error = drdynvc_order_recv(drdynvc, data, ThreadingFlags))) { WLog_Print(drdynvc->log, WLOG_WARN, "drdynvc_order_recv failed with error %" PRIu32 "!", error); diff --git a/channels/printer/client/printer_main.c b/channels/printer/client/printer_main.c index 416fccaa5..0b9ad0e65 100644 --- a/channels/printer/client/printer_main.c +++ b/channels/printer/client/printer_main.c @@ -941,7 +941,8 @@ error_out: static rdpPrinterDriver* printer_load_backend(const char* backend) { typedef rdpPrinterDriver* (*backend_load_t)(void); - union { + union + { PVIRTUALCHANNELENTRY entry; backend_load_t backend; } fktconv; diff --git a/channels/rail/client/rail_main.c b/channels/rail/client/rail_main.c index e19cb9252..6b1bdab6b 100644 --- a/channels/rail/client/rail_main.c +++ b/channels/rail/client/rail_main.c @@ -35,6 +35,8 @@ #include "rail_orders.h" #include "rail_main.h" +#include "../../channels/client/addin.h" + RailClientContext* rail_get_client_interface(railPlugin* rail) { RailClientContext* pInterface; @@ -513,68 +515,6 @@ static UINT rail_client_snap_arrange(RailClientContext* context, const RAIL_SNAP return rail_send_client_snap_arrange_order(rail, snap); } -/** - * Function description - * - * @return 0 on success, otherwise a Win32 error code - */ -static UINT rail_virtual_channel_event_data_received(railPlugin* rail, void* pData, - UINT32 dataLength, UINT32 totalLength, - UINT32 dataFlags) -{ - wStream* data_in; - - if ((dataFlags & CHANNEL_FLAG_SUSPEND) || (dataFlags & CHANNEL_FLAG_RESUME)) - { - return CHANNEL_RC_OK; - } - - if (dataFlags & CHANNEL_FLAG_FIRST) - { - if (rail->data_in) - Stream_Free(rail->data_in, TRUE); - - rail->data_in = Stream_New(NULL, totalLength); - - if (!rail->data_in) - { - WLog_ERR(TAG, "Stream_New failed!"); - return CHANNEL_RC_NO_MEMORY; - } - } - - data_in = rail->data_in; - - if (!Stream_EnsureRemainingCapacity(data_in, dataLength)) - { - WLog_ERR(TAG, "Stream_EnsureRemainingCapacity failed!"); - return CHANNEL_RC_NO_MEMORY; - } - - Stream_Write(data_in, pData, dataLength); - - if (dataFlags & CHANNEL_FLAG_LAST) - { - if (Stream_Capacity(data_in) != Stream_GetPosition(data_in)) - { - WLog_ERR(TAG, "rail_plugin_process_received: read error"); - return ERROR_INTERNAL_ERROR; - } - - rail->data_in = NULL; - Stream_SealLength(data_in); - Stream_SetPosition(data_in, 0); - - if (!MessageQueue_Post(rail->queue, NULL, 0, (void*)data_in, NULL)) - { - WLog_ERR(TAG, "MessageQueue_Post failed!"); - return ERROR_INTERNAL_ERROR; - } - } - - return CHANNEL_RC_OK; -} - static VOID VCAPITYPE rail_virtual_channel_open_event_ex(LPVOID lpUserParam, DWORD openHandle, UINT event, LPVOID pData, UINT32 dataLength, UINT32 totalLength, @@ -591,11 +531,15 @@ static VOID VCAPITYPE rail_virtual_channel_open_event_ex(LPVOID lpUserParam, DWO WLog_ERR(TAG, "error no match"); return; } - if ((error = rail_virtual_channel_event_data_received(rail, pData, dataLength, - totalLength, dataFlags))) + + if ((error = channel_client_post_message(rail->MsgsHandle, pData, dataLength, + totalLength, dataFlags))) + { WLog_ERR(TAG, - "rail_virtual_channel_event_data_received failed with error %" PRIu32 "!", + "rail_virtual_channel_event_data_received" + " failed with error %" PRIu32 "!", error); + } break; @@ -618,54 +562,6 @@ static VOID VCAPITYPE rail_virtual_channel_open_event_ex(LPVOID lpUserParam, DWO return; } -static DWORD WINAPI rail_virtual_channel_client_thread(LPVOID arg) -{ - wStream* data; - wMessage message; - railPlugin* rail = (railPlugin*)arg; - UINT error = CHANNEL_RC_OK; - - while (1) - { - if (!MessageQueue_Wait(rail->queue)) - { - WLog_ERR(TAG, "MessageQueue_Wait failed!"); - error = ERROR_INTERNAL_ERROR; - break; - } - - if (!MessageQueue_Peek(rail->queue, &message, TRUE)) - { - WLog_ERR(TAG, "MessageQueue_Peek failed!"); - error = ERROR_INTERNAL_ERROR; - break; - } - - if (message.id == WMQ_QUIT) - break; - - if (message.id == 0) - { - data = (wStream*)message.wParam; - error = rail_order_recv(rail, data); - Stream_Free(data, TRUE); - - if (error) - { - WLog_ERR(TAG, "rail_order_recv failed with error %" PRIu32 "!", error); - break; - } - } - } - - if (error && rail->rdpcontext) - setChannelError(rail->rdpcontext, error, - "rail_virtual_channel_client_thread reported an error"); - - ExitThread(error); - return error; -} - /** * Function description * @@ -694,23 +590,8 @@ static UINT rail_virtual_channel_event_connected(railPlugin* rail, LPVOID pData, WLog_ERR(TAG, "context->OnOpen failed with %s [%08" PRIX32 "]", WTSErrorToString(status), status); } - - rail->queue = MessageQueue_New(NULL); - - if (!rail->queue) - { - WLog_ERR(TAG, "MessageQueue_New failed!"); - return CHANNEL_RC_NO_MEMORY; - } - - if (!(rail->thread = - CreateThread(NULL, 0, rail_virtual_channel_client_thread, (void*)rail, 0, NULL))) - { - WLog_ERR(TAG, "CreateThread failed!"); - MessageQueue_Free(rail->queue); - rail->queue = NULL; - return ERROR_INTERNAL_ERROR; - } + rail->MsgsHandle = + channel_client_create_handler(rail->rdpcontext, rail, rail_order_recv, "rail"); return CHANNEL_RC_OK; } @@ -727,18 +608,8 @@ static UINT rail_virtual_channel_event_disconnected(railPlugin* rail) if (rail->OpenHandle == 0) return CHANNEL_RC_OK; - if (MessageQueue_PostQuit(rail->queue, 0) && - (WaitForSingleObject(rail->thread, INFINITE) == WAIT_FAILED)) - { - rc = GetLastError(); - WLog_ERR(TAG, "WaitForSingleObject failed with error %" PRIu32 "", rc); - return rc; - } + channel_client_quit_handler(rail->MsgsHandle); - MessageQueue_Free(rail->queue); - CloseHandle(rail->thread); - rail->queue = NULL; - rail->thread = NULL; rc = rail->channelEntryPoints.pVirtualChannelCloseEx(rail->InitHandle, rail->OpenHandle); if (CHANNEL_RC_OK != rc) @@ -750,11 +621,6 @@ static UINT rail_virtual_channel_event_disconnected(railPlugin* rail) rail->OpenHandle = 0; - if (rail->data_in) - { - Stream_Free(rail->data_in, TRUE); - rail->data_in = NULL; - } return CHANNEL_RC_OK; } diff --git a/channels/rail/client/rail_main.h b/channels/rail/client/rail_main.h index 63e522efb..9ba75cf3c 100644 --- a/channels/rail/client/rail_main.h +++ b/channels/rail/client/rail_main.h @@ -44,11 +44,9 @@ struct rail_plugin RailClientContext* context; wLog* log; - HANDLE thread; - wStream* data_in; void* InitHandle; DWORD OpenHandle; - wMessageQueue* queue; + void* MsgsHandle; rdpContext* rdpcontext; DWORD channelBuildNumber; DWORD channelFlags; diff --git a/channels/rail/client/rail_orders.c b/channels/rail/client/rail_orders.c index c394a5925..afce47895 100644 --- a/channels/rail/client/rail_orders.c +++ b/channels/rail/client/rail_orders.c @@ -909,8 +909,9 @@ static UINT rail_recv_get_application_id_extended_response_order(railPlugin* rai * * @return 0 on success, otherwise a Win32 error code */ -UINT rail_order_recv(railPlugin* rail, wStream* s) +UINT rail_order_recv(LPVOID userdata, wStream* s) { + railPlugin* rail = userdata; UINT16 orderType; UINT16 orderLength; UINT error; diff --git a/channels/rail/client/rail_orders.h b/channels/rail/client/rail_orders.h index 89ba6cc4a..1b15aae8b 100644 --- a/channels/rail/client/rail_orders.h +++ b/channels/rail/client/rail_orders.h @@ -29,7 +29,7 @@ #define TAG CHANNELS_TAG("rail.client") -UINT rail_order_recv(railPlugin* rail, wStream* s); +UINT rail_order_recv(LPVOID userdata, wStream* s); UINT rail_send_pdu(railPlugin* rail, wStream* s, UINT16 orderType); UINT rail_send_handshake_order(railPlugin* rail, const RAIL_HANDSHAKE_ORDER* handshake); diff --git a/channels/rdpdr/client/devman.c b/channels/rdpdr/client/devman.c index af3cdd6b2..e2639a600 100644 --- a/channels/rdpdr/client/devman.c +++ b/channels/rdpdr/client/devman.c @@ -183,7 +183,8 @@ UINT devman_load_device_service(DEVMAN* devman, const RDPDR_DEVICE* device, rdpC const char* ServiceName = NULL; DEVICE_SERVICE_ENTRY_POINTS ep; PDEVICE_SERVICE_ENTRY entry = NULL; - union { + union + { const RDPDR_DEVICE* cdp; RDPDR_DEVICE* dp; } devconv; diff --git a/channels/rdpsnd/client/opensles/rdpsnd_opensles.c b/channels/rdpsnd/client/opensles/rdpsnd_opensles.c index 3481d9130..22ba77377 100644 --- a/channels/rdpsnd/client/opensles/rdpsnd_opensles.c +++ b/channels/rdpsnd/client/opensles/rdpsnd_opensles.c @@ -257,7 +257,8 @@ static BOOL rdpsnd_opensles_set_volume(rdpsndDevicePlugin* device, UINT32 value) static UINT rdpsnd_opensles_play(rdpsndDevicePlugin* device, const BYTE* data, size_t size) { - union { + union + { const BYTE* b; const short* s; } src; diff --git a/channels/rdpsnd/client/proxy/rdpsnd_proxy.c b/channels/rdpsnd/client/proxy/rdpsnd_proxy.c index 58e3019a4..88f7bf5d7 100644 --- a/channels/rdpsnd/client/proxy/rdpsnd_proxy.c +++ b/channels/rdpsnd/client/proxy/rdpsnd_proxy.c @@ -95,7 +95,6 @@ static UINT rdpsnd_proxy_play(rdpsndDevicePlugin* device, const BYTE* data, size return GetTickCount() - start; } - /** * Function description * diff --git a/channels/serial/client/serial_main.c b/channels/serial/client/serial_main.c index afe67b4d3..3444cb69d 100644 --- a/channels/serial/client/serial_main.c +++ b/channels/serial/client/serial_main.c @@ -145,7 +145,7 @@ static UINT serial_process_irp_create(SERIAL_DEVICE* serial, IRP* irp) if (!Stream_SafeSeek(irp->input, PathLength)) /* Path (variable) */ return ERROR_INVALID_DATA; - assert(PathLength == 0); /* MS-RDPESP 2.2.2.2 */ + assert(PathLength == 0); /* MS-RDPESP 2.2.2.2 */ #ifndef _WIN32 /* Windows 2012 server sends on a first call : * DesiredAccess = 0x00100080: SYNCHRONIZE | FILE_READ_ATTRIBUTES diff --git a/channels/smartcard/client/smartcard_operations.c b/channels/smartcard/client/smartcard_operations.c index 4639b1778..91ce31acd 100644 --- a/channels/smartcard/client/smartcard_operations.c +++ b/channels/smartcard/client/smartcard_operations.c @@ -699,12 +699,14 @@ static LONG smartcard_ListReadersW_Call(SMARTCARD_DEVICE* smartcard, SMARTCARD_O DWORD cchReaders = 0; IRP* irp = operation->irp; ListReaders_Call* call = &operation->call.listReaders; - union { + union + { const BYTE* bp; const char* sz; const WCHAR* wz; } string; - union { + union + { WCHAR** ppw; WCHAR* pw; CHAR* pc; diff --git a/channels/urbdrc/client/libusb/libusb_udevice.c b/channels/urbdrc/client/libusb/libusb_udevice.c index 66e1aa01c..84d31ebcd 100644 --- a/channels/urbdrc/client/libusb/libusb_udevice.c +++ b/channels/urbdrc/client/libusb/libusb_udevice.c @@ -517,7 +517,6 @@ static LIBUSB_DEVICE_DESCRIPTOR* udev_new_descript(URBDRC_PLUGIN* urbdrc, LIBUSB return descriptor; } - static int libusb_udev_select_interface(IUDEVICE* idev, BYTE InterfaceNumber, BYTE AlternateSetting) { int error = 0, diff = 0; diff --git a/channels/video/client/video_main.c b/channels/video/client/video_main.c index a21e7cdf2..c788805d2 100644 --- a/channels/video/client/video_main.c +++ b/channels/video/client/video_main.c @@ -76,6 +76,7 @@ struct _VIDEO_PLUGIN VIDEO_LISTENER_CALLBACK* data_callback; VideoClientContext* context; + rdpSettings* settings; BOOL initialized; }; typedef struct _VIDEO_PLUGIN VIDEO_PLUGIN; @@ -219,7 +220,8 @@ error_frames: } static PresentationContext* PresentationContext_new(VideoClientContext* video, BYTE PresentationId, - UINT32 x, UINT32 y, UINT32 width, UINT32 height) + UINT32 x, UINT32 y, UINT32 width, UINT32 height, + BOOL disable_threads) { size_t s; VideoClientContextPriv* priv = video->priv; @@ -264,7 +266,7 @@ static PresentationContext* PresentationContext_new(VideoClientContext* video, B goto error_surface; } - ret->yuv = yuv_context_new(FALSE); + ret->yuv = yuv_context_new(FALSE, disable_threads); if (!ret->yuv) { WLog_ERR(TAG, "unable to create YUV decoder"); @@ -406,7 +408,8 @@ static BOOL video_onMappedGeometryClear(MAPPED_GEOMETRY* geometry) return TRUE; } -static UINT video_PresentationRequest(VideoClientContext* video, TSMM_PRESENTATION_REQUEST* req) +static UINT video_PresentationRequest(VideoClientContext* video, TSMM_PRESENTATION_REQUEST* req, + BOOL disable_threads) { VideoClientContextPriv* priv = video->priv; PresentationContext* presentation; @@ -455,7 +458,7 @@ static UINT video_PresentationRequest(VideoClientContext* video, TSMM_PRESENTATI WLog_DBG(TAG, "creating presentation 0x%x", req->PresentationId); presentation = PresentationContext_new( video, req->PresentationId, geom->topLevelLeft + geom->left, - geom->topLevelTop + geom->top, req->SourceWidth, req->SourceHeight); + geom->topLevelTop + geom->top, req->SourceWidth, req->SourceHeight, disable_threads); if (!presentation) { WLog_ERR(TAG, "unable to create presentation video"); @@ -498,7 +501,8 @@ static UINT video_PresentationRequest(VideoClientContext* video, TSMM_PRESENTATI return ret; } -static UINT video_read_tsmm_presentation_req(VideoClientContext* context, wStream* s) +static UINT video_read_tsmm_presentation_req(VideoClientContext* context, wStream* s, + BOOL disable_threads) { TSMM_PRESENTATION_REQUEST req; @@ -542,7 +546,7 @@ static UINT video_read_tsmm_presentation_req(VideoClientContext* context, wStrea req.SourceHeight, req.ScaledWidth, req.ScaledHeight, req.hnsTimestampOffset, req.GeometryMappingId); - return video_PresentationRequest(context, &req); + return video_PresentationRequest(context, &req, disable_threads); } /** @@ -575,7 +579,8 @@ static UINT video_control_on_data_received(IWTSVirtualChannelCallback* pChannelC switch (packetType) { case TSMM_PACKET_TYPE_PRESENTATION_REQUEST: - ret = video_read_tsmm_presentation_req(context, s); + ret = video_read_tsmm_presentation_req( + context, s, video->settings->ThreadingFlags & THREADING_FLAGS_DISABLE_THREADS); break; default: WLog_ERR(TAG, "not expecting packet type %" PRIu32 "", packetType); @@ -1146,6 +1151,8 @@ UINT DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints) return CHANNEL_RC_NO_MEMORY; } + videoPlugin->settings = pEntryPoints->GetRdpSettings(pEntryPoints); + videoPlugin->wtsPlugin.Initialize = video_plugin_initialize; videoPlugin->wtsPlugin.Connected = NULL; videoPlugin->wtsPlugin.Disconnected = NULL; diff --git a/client/X11/xf_input.c b/client/X11/xf_input.c index 8ad777286..3a875e51d 100644 --- a/client/X11/xf_input.c +++ b/client/X11/xf_input.c @@ -434,7 +434,8 @@ static void xf_input_touch_end(xfContext* xfc, XIDeviceEvent* event) static int xf_input_handle_event_local(xfContext* xfc, const XEvent* event) { - union { + union + { const XGenericEventCookie* cc; XGenericEventCookie* vc; } cookie; @@ -608,7 +609,8 @@ static int xf_input_event(xfContext* xfc, XIDeviceEvent* event, int evtype) static int xf_input_handle_event_remote(xfContext* xfc, const XEvent* event) { - union { + union + { const XGenericEventCookie* cc; XGenericEventCookie* vc; } cookie; diff --git a/include/freerdp/codec/rfx.h b/include/freerdp/codec/rfx.h index ffdbd5e2e..b45a8182b 100644 --- a/include/freerdp/codec/rfx.h +++ b/include/freerdp/codec/rfx.h @@ -199,7 +199,7 @@ extern "C" FREERDP_API BOOL rfx_context_reset(RFX_CONTEXT* context, UINT32 width, UINT32 height); - FREERDP_API RFX_CONTEXT* rfx_context_new(BOOL encoder); + FREERDP_API RFX_CONTEXT* rfx_context_new(BOOL encoder, UINT32 ThreadingFlags); FREERDP_API void rfx_context_free(RFX_CONTEXT* context); #ifdef __cplusplus diff --git a/include/freerdp/codec/yuv.h b/include/freerdp/codec/yuv.h index b23c347f1..fe15c03fb 100644 --- a/include/freerdp/codec/yuv.h +++ b/include/freerdp/codec/yuv.h @@ -38,7 +38,7 @@ extern "C" FREERDP_API void yuv_context_reset(YUV_CONTEXT* context, UINT32 width, UINT32 height); - FREERDP_API YUV_CONTEXT* yuv_context_new(BOOL encoder); + FREERDP_API YUV_CONTEXT* yuv_context_new(BOOL encoder, UINT32 ThreadingFlags); FREERDP_API void yuv_context_free(YUV_CONTEXT* context); #ifdef __cplusplus diff --git a/include/freerdp/settings.h b/include/freerdp/settings.h index dae0a5f95..4591b5567 100644 --- a/include/freerdp/settings.h +++ b/include/freerdp/settings.h @@ -502,6 +502,9 @@ typedef struct _RDPDR_PARALLEL RDPDR_PARALLEL; #define PROXY_TYPE_SOCKS 2 #define PROXY_TYPE_IGNORE 0xFFFF +/* ThreadingFlags */ +#define THREADING_FLAGS_DISABLE_THREADS 0x00000001 + /* Settings */ #ifdef __GNUC__ @@ -925,8 +928,13 @@ struct rdp_settings ALIGN64 UINT32 MaxTimeInCheckLoop; /* 26 */ ALIGN64 char* AcceptedCert; /* 27 */ ALIGN64 UINT32 AcceptedCertLength; /* 28 */ - UINT64 padding0064[64 - 29]; /* 29 */ - UINT64 padding0128[128 - 64]; /* 64 */ + + UINT64 padding0064[64 - 29]; /* 29 */ + + /* resource management related options */ + ALIGN64 UINT32 ThreadingFlags; /* 64 */ + + UINT64 padding0128[128 - 65]; /* 65 */ /** * GCC User Data Blocks @@ -1340,20 +1348,20 @@ struct rdp_settings /* Input Capabilities */ ALIGN64 char* KeyboardRemappingList; /* 2622 */ - ALIGN64 UINT32 KeyboardCodePage; /* 2623 */ - ALIGN64 UINT32 KeyboardLayout; /* 2624 */ - ALIGN64 UINT32 KeyboardType; /* 2625 */ - ALIGN64 UINT32 KeyboardSubType; /* 2626 */ - ALIGN64 UINT32 KeyboardFunctionKey; /* 2627 */ - ALIGN64 char* ImeFileName; /* 2628 */ - ALIGN64 BOOL UnicodeInput; /* 2629 */ - ALIGN64 BOOL FastPathInput; /* 2630 */ - ALIGN64 BOOL MultiTouchInput; /* 2631 */ - ALIGN64 BOOL MultiTouchGestures; /* 2632 */ - ALIGN64 UINT32 KeyboardHook; /* 2633 */ - ALIGN64 BOOL HasHorizontalWheel; /* 2634 */ - ALIGN64 BOOL HasExtendedMouseEvent; /* 2635 */ - UINT64 padding2688[2688 - 2636]; /* 2636 */ + ALIGN64 UINT32 KeyboardCodePage; /* 2623 */ + ALIGN64 UINT32 KeyboardLayout; /* 2624 */ + ALIGN64 UINT32 KeyboardType; /* 2625 */ + ALIGN64 UINT32 KeyboardSubType; /* 2626 */ + ALIGN64 UINT32 KeyboardFunctionKey; /* 2627 */ + ALIGN64 char* ImeFileName; /* 2628 */ + ALIGN64 BOOL UnicodeInput; /* 2629 */ + ALIGN64 BOOL FastPathInput; /* 2630 */ + ALIGN64 BOOL MultiTouchInput; /* 2631 */ + ALIGN64 BOOL MultiTouchGestures; /* 2632 */ + ALIGN64 UINT32 KeyboardHook; /* 2633 */ + ALIGN64 BOOL HasHorizontalWheel; /* 2634 */ + ALIGN64 BOOL HasExtendedMouseEvent; /* 2635 */ + UINT64 padding2688[2688 - 2636]; /* 2636 */ /* Brush Capabilities */ ALIGN64 UINT32 BrushSupportLevel; /* 2688 */ @@ -1564,6 +1572,7 @@ struct rdp_settings default value - currently UNUSED! */ ALIGN64 char* ActionScript; ALIGN64 DWORD Floatbar; + ALIGN64 char* XSelectionAtom; }; typedef struct rdp_settings rdpSettings; @@ -1699,6 +1708,7 @@ extern "C" FREERDP_API SSIZE_T freerdp_settings_get_type_for_name(const char* value); FREERDP_API SSIZE_T freerdp_settings_get_type_for_key(size_t key); FREERDP_API const char* freerdp_settings_get_name_for_key(size_t key); + FREERDP_API UINT32 freerdp_settings_get_codecs_flags(const rdpSettings* settings); #ifdef __cplusplus } diff --git a/libfreerdp/codec/dsp.c b/libfreerdp/codec/dsp.c index a5039cea5..d8a583b69 100644 --- a/libfreerdp/codec/dsp.c +++ b/libfreerdp/codec/dsp.c @@ -61,7 +61,8 @@ #if !defined(WITH_DSP_FFMPEG) -union _ADPCM { +union _ADPCM +{ struct { INT16 last_sample[2]; diff --git a/libfreerdp/codec/nsc_encode.c b/libfreerdp/codec/nsc_encode.c index fd9626a6d..5f21984fa 100644 --- a/libfreerdp/codec/nsc_encode.c +++ b/libfreerdp/codec/nsc_encode.c @@ -289,7 +289,7 @@ static BOOL nsc_encode_subsampling(NSC_CONTEXT* context) if (tempWidth > context->priv->PlaneBuffersLength / tempHeight) return FALSE; - for (y = 0; y> 1; y++) + for (y = 0; y < tempHeight >> 1; y++) { UINT32 x; BYTE* co_dst = context->priv->PlaneBuffers[1] + y * (tempWidth >> 1); @@ -299,7 +299,7 @@ static BOOL nsc_encode_subsampling(NSC_CONTEXT* context) const INT8* cg_src0 = (INT8*)context->priv->PlaneBuffers[2] + (y << 1) * tempWidth; const INT8* cg_src1 = cg_src0 + tempWidth; - for (x = 0; x> 1; x++) + for (x = 0; x < tempWidth >> 1; x++) { *co_dst++ = (BYTE)(((INT16)*co_src0 + (INT16) * (co_src0 + 1) + (INT16)*co_src1 + (INT16) * (co_src1 + 1)) >> diff --git a/libfreerdp/codec/nsc_sse2.c b/libfreerdp/codec/nsc_sse2.c index 7f101652d..8e3e649d5 100644 --- a/libfreerdp/codec/nsc_sse2.c +++ b/libfreerdp/codec/nsc_sse2.c @@ -335,7 +335,7 @@ static void nsc_encode_subsampling_sse2(NSC_CONTEXT* context) tempWidth = ROUND_UP_TO(context->width, 8); tempHeight = ROUND_UP_TO(context->height, 2); - for (y = 0; y> 1; y++) + for (y = 0; y < tempHeight >> 1; y++) { UINT32 x; co_dst = context->priv->PlaneBuffers[1] + y * (tempWidth >> 1); @@ -345,7 +345,7 @@ static void nsc_encode_subsampling_sse2(NSC_CONTEXT* context) cg_src0 = (INT8*)context->priv->PlaneBuffers[2] + (y << 1) * tempWidth; cg_src1 = cg_src0 + tempWidth; - for (x = 0; x> 1; x += 8) + for (x = 0; x < tempWidth >> 1; x += 8) { t = _mm_loadu_si128((__m128i*)co_src0); t = _mm_avg_epu8(t, _mm_loadu_si128((__m128i*)co_src1)); diff --git a/libfreerdp/codec/planar.c b/libfreerdp/codec/planar.c index f31c2d46a..618246862 100644 --- a/libfreerdp/codec/planar.c +++ b/libfreerdp/codec/planar.c @@ -20,7 +20,7 @@ */ #ifdef HAVE_CONFIG_H -# include "config.h" +#include "config.h" #endif #include diff --git a/libfreerdp/codec/progressive.c b/libfreerdp/codec/progressive.c index fed3bddda..bab525873 100644 --- a/libfreerdp/codec/progressive.c +++ b/libfreerdp/codec/progressive.c @@ -2167,7 +2167,8 @@ INT32 progressive_decompress(PROGRESSIVE_CONTEXT* progressive, const BYTE* pSrcD REGION16 clippingRects, updateRegion; PROGRESSIVE_BLOCK_REGION* region = &progressive->region; PROGRESSIVE_SURFACE_CONTEXT* surface = progressive_get_surface_data(progressive, surfaceId); - union { + union + { const BYTE* cbp; BYTE* bp; } sconv; @@ -2602,7 +2603,7 @@ PROGRESSIVE_CONTEXT* progressive_context_new(BOOL Compressor) progressive->log = WLog_Get(TAG); if (!progressive->log) goto fail; - progressive->rfx_context = rfx_context_new(Compressor); + progressive->rfx_context = rfx_context_new(Compressor, 0); if (!progressive->rfx_context) goto fail; progressive->buffer = Stream_New(NULL, 1024); diff --git a/libfreerdp/codec/rfx.c b/libfreerdp/codec/rfx.c index d829ff413..622eddd02 100644 --- a/libfreerdp/codec/rfx.c +++ b/libfreerdp/codec/rfx.c @@ -195,7 +195,7 @@ static void rfx_encoder_tile_free(void* obj) free(obj); } -RFX_CONTEXT* rfx_context_new(BOOL encoder) +RFX_CONTEXT* rfx_context_new(BOOL encoder, UINT32 ThreadingFlags) { HKEY hKey; LONG status; @@ -257,6 +257,8 @@ RFX_CONTEXT* rfx_context_new(BOOL encoder) if (!priv->BufferPool) goto error_BufferPool; + if (!(ThreadingFlags & THREADING_FLAGS_DISABLE_THREADS)) + { #ifdef _WIN32 { BOOL isVistaOrLater; @@ -265,7 +267,7 @@ RFX_CONTEXT* rfx_context_new(BOOL encoder) verinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOA); GetVersionExA(&verinfo); isVistaOrLater = - ((verinfo.dwMajorVersion >= 6) && (verinfo.dwMinorVersion >= 0)) ? TRUE : FALSE; + ((verinfo.dwMajorVersion >= 6) && (verinfo.dwMinorVersion >= 0)) ? TRUE : FALSE; priv->UseThreads = isVistaOrLater; } #else @@ -281,19 +283,24 @@ RFX_CONTEXT* rfx_context_new(BOOL encoder) dwSize = sizeof(dwValue); if (RegQueryValueEx(hKey, _T("UseThreads"), NULL, &dwType, (BYTE*)&dwValue, &dwSize) == - ERROR_SUCCESS) + ERROR_SUCCESS) priv->UseThreads = dwValue ? 1 : 0; if (RegQueryValueEx(hKey, _T("MinThreadCount"), NULL, &dwType, (BYTE*)&dwValue, &dwSize) == - ERROR_SUCCESS) + ERROR_SUCCESS) priv->MinThreadCount = dwValue; if (RegQueryValueEx(hKey, _T("MaxThreadCount"), NULL, &dwType, (BYTE*)&dwValue, &dwSize) == - ERROR_SUCCESS) + ERROR_SUCCESS) priv->MaxThreadCount = dwValue; RegCloseKey(hKey); } + } + else + { + priv->UseThreads = FALSE; + } if (priv->UseThreads) { diff --git a/libfreerdp/codec/test/TestFreeRDPCodecRemoteFX.c b/libfreerdp/codec/test/TestFreeRDPCodecRemoteFX.c index 7c5f0b212..bac10796e 100644 --- a/libfreerdp/codec/test/TestFreeRDPCodecRemoteFX.c +++ b/libfreerdp/codec/test/TestFreeRDPCodecRemoteFX.c @@ -851,7 +851,9 @@ int TestFreeRDPCodecRemoteFX(int argc, char* argv[]) BYTE* dest = NULL; size_t stride = FORMAT_SIZE * IMG_WIDTH; - context = rfx_context_new(FALSE); + /* use default threading options here, pass zero as + * ThreadingFlags */ + context = rfx_context_new(FALSE, 0); if (!context) goto fail; diff --git a/libfreerdp/codec/yuv.c b/libfreerdp/codec/yuv.c index 951bea7dd..957e3bbc4 100644 --- a/libfreerdp/codec/yuv.c +++ b/libfreerdp/codec/yuv.c @@ -54,7 +54,7 @@ void yuv_context_reset(YUV_CONTEXT* context, UINT32 width, UINT32 height) context->heightStep = (height / context->nthreads); } -YUV_CONTEXT* yuv_context_new(BOOL encoder) +YUV_CONTEXT* yuv_context_new(BOOL encoder, UINT32 ThreadingFlags) { SYSTEM_INFO sysInfos; YUV_CONTEXT* ret = calloc(1, sizeof(*ret)); @@ -64,22 +64,30 @@ YUV_CONTEXT* yuv_context_new(BOOL encoder) /** do it here to avoid a race condition between threads */ primitives_get(); - GetNativeSystemInfo(&sysInfos); - ret->useThreads = (sysInfos.dwNumberOfProcessors > 1); - if (ret->useThreads) + if (!(ThreadingFlags & THREADING_FLAGS_DISABLE_THREADS)) { - ret->nthreads = sysInfos.dwNumberOfProcessors; - ret->threadPool = CreateThreadpool(NULL); - if (!ret->threadPool) + GetNativeSystemInfo(&sysInfos); + ret->useThreads = (sysInfos.dwNumberOfProcessors > 1); + if (ret->useThreads) { - goto error_threadpool; - } + ret->nthreads = sysInfos.dwNumberOfProcessors; + ret->threadPool = CreateThreadpool(NULL); + if (!ret->threadPool) + { + goto error_threadpool; + } - InitializeThreadpoolEnvironment(&ret->ThreadPoolEnv); - SetThreadpoolCallbackPool(&ret->ThreadPoolEnv, ret->threadPool); + InitializeThreadpoolEnvironment(&ret->ThreadPoolEnv); + SetThreadpoolCallbackPool(&ret->ThreadPoolEnv, ret->threadPool); + } + else + { + ret->nthreads = 1; + } } else { + ret->useThreads = FALSE; ret->nthreads = 1; } diff --git a/libfreerdp/common/settings.c b/libfreerdp/common/settings.c index b639778b0..882945ff2 100644 --- a/libfreerdp/common/settings.c +++ b/libfreerdp/common/settings.c @@ -925,3 +925,18 @@ BOOL freerdp_settings_set_value_for_name(rdpSettings* settings, const char* name } return FALSE; } + +UINT32 freerdp_settings_get_codecs_flags(const rdpSettings* settings) +{ + UINT32 flags = FREERDP_CODEC_ALL; + if (settings->RemoteFxCodec == FALSE) + { + flags &= ~FREERDP_CODEC_REMOTEFX; + } + if (settings->NSCodec == FALSE) + { + flags &= ~FREERDP_CODEC_NSCODEC; + } + /*TODO: check other codecs flags */ + return flags; +} \ No newline at end of file diff --git a/libfreerdp/core/capabilities.c b/libfreerdp/core/capabilities.c index 30edcbb1c..1a6c823ac 100644 --- a/libfreerdp/core/capabilities.c +++ b/libfreerdp/core/capabilities.c @@ -251,15 +251,15 @@ static BOOL rdp_write_general_capability_set(wStream* s, const rdpSettings* sett settings->OsMajorType, settings->OsMinorType, UINT16_MAX); return FALSE; } - Stream_Write_UINT16(s, (UINT16)settings->OsMajorType); /* osMajorType (2 bytes) */ - Stream_Write_UINT16(s, (UINT16)settings->OsMinorType); /* osMinorType (2 bytes) */ - Stream_Write_UINT16(s, CAPS_PROTOCOL_VERSION); /* protocolVersion (2 bytes) */ - Stream_Write_UINT16(s, 0); /* pad2OctetsA (2 bytes) */ - Stream_Write_UINT16(s, 0); /* generalCompressionTypes (2 bytes) */ - Stream_Write_UINT16(s, extraFlags); /* extraFlags (2 bytes) */ - Stream_Write_UINT16(s, 0); /* updateCapabilityFlag (2 bytes) */ - Stream_Write_UINT16(s, 0); /* remoteUnshareFlag (2 bytes) */ - Stream_Write_UINT16(s, 0); /* generalCompressionLevel (2 bytes) */ + Stream_Write_UINT16(s, (UINT16)settings->OsMajorType); /* osMajorType (2 bytes) */ + Stream_Write_UINT16(s, (UINT16)settings->OsMinorType); /* osMinorType (2 bytes) */ + Stream_Write_UINT16(s, CAPS_PROTOCOL_VERSION); /* protocolVersion (2 bytes) */ + Stream_Write_UINT16(s, 0); /* pad2OctetsA (2 bytes) */ + Stream_Write_UINT16(s, 0); /* generalCompressionTypes (2 bytes) */ + Stream_Write_UINT16(s, extraFlags); /* extraFlags (2 bytes) */ + Stream_Write_UINT16(s, 0); /* updateCapabilityFlag (2 bytes) */ + Stream_Write_UINT16(s, 0); /* remoteUnshareFlag (2 bytes) */ + Stream_Write_UINT16(s, 0); /* generalCompressionLevel (2 bytes) */ Stream_Write_UINT8(s, settings->RefreshRect ? 1 : 0); /* refreshRectSupport (1 byte) */ Stream_Write_UINT8(s, settings->SuppressOutput ? 1 : 0); /* suppressOutputSupport (1 byte) */ return rdp_capability_set_finish(s, (UINT16)header, CAPSET_TYPE_GENERAL); @@ -420,19 +420,19 @@ static BOOL rdp_write_bitmap_capability_set(wStream* s, const rdpSettings* setti else preferredBitsPerPixel = 8; - Stream_Write_UINT16(s, preferredBitsPerPixel); /* preferredBitsPerPixel (2 bytes) */ - Stream_Write_UINT16(s, 1); /* receive1BitPerPixel (2 bytes) */ - Stream_Write_UINT16(s, 1); /* receive4BitsPerPixel (2 bytes) */ - Stream_Write_UINT16(s, 1); /* receive8BitsPerPixel (2 bytes) */ + Stream_Write_UINT16(s, preferredBitsPerPixel); /* preferredBitsPerPixel (2 bytes) */ + Stream_Write_UINT16(s, 1); /* receive1BitPerPixel (2 bytes) */ + Stream_Write_UINT16(s, 1); /* receive4BitsPerPixel (2 bytes) */ + Stream_Write_UINT16(s, 1); /* receive8BitsPerPixel (2 bytes) */ Stream_Write_UINT16(s, (UINT16)settings->DesktopWidth); /* desktopWidth (2 bytes) */ Stream_Write_UINT16(s, (UINT16)settings->DesktopHeight); /* desktopHeight (2 bytes) */ - Stream_Write_UINT16(s, 0); /* pad2Octets (2 bytes) */ + Stream_Write_UINT16(s, 0); /* pad2Octets (2 bytes) */ Stream_Write_UINT16(s, (UINT16)settings->DesktopResize); /* desktopResizeFlag (2 bytes) */ - Stream_Write_UINT16(s, 1); /* bitmapCompressionFlag (2 bytes) */ - Stream_Write_UINT8(s, 0); /* highColorFlags (1 byte) */ - Stream_Write_UINT8(s, drawingFlags); /* drawingFlags (1 byte) */ - Stream_Write_UINT16(s, 1); /* multipleRectangleSupport (2 bytes) */ - Stream_Write_UINT16(s, 0); /* pad2OctetsB (2 bytes) */ + Stream_Write_UINT16(s, 1); /* bitmapCompressionFlag (2 bytes) */ + Stream_Write_UINT8(s, 0); /* highColorFlags (1 byte) */ + Stream_Write_UINT8(s, drawingFlags); /* drawingFlags (1 byte) */ + Stream_Write_UINT16(s, 1); /* multipleRectangleSupport (2 bytes) */ + Stream_Write_UINT16(s, 0); /* pad2OctetsB (2 bytes) */ return rdp_capability_set_finish(s, (UINT16)header, CAPSET_TYPE_BITMAP); } @@ -767,12 +767,12 @@ static BOOL rdp_write_bitmap_cache_capability_set(wStream* s, const rdpSettings* size = bpp * 256; if (size > UINT16_MAX) return FALSE; - Stream_Write_UINT16(s, 200); /* Cache0Entries (2 bytes) */ + Stream_Write_UINT16(s, 200); /* Cache0Entries (2 bytes) */ Stream_Write_UINT16(s, (UINT16)size); /* Cache0MaximumCellSize (2 bytes) */ size = bpp * 1024; if (size > UINT16_MAX) return FALSE; - Stream_Write_UINT16(s, 600); /* Cache1Entries (2 bytes) */ + Stream_Write_UINT16(s, 600); /* Cache1Entries (2 bytes) */ Stream_Write_UINT16(s, (UINT16)size); /* Cache1MaximumCellSize (2 bytes) */ size = bpp * 4096; if (size > UINT16_MAX) @@ -1026,7 +1026,7 @@ static BOOL rdp_write_pointer_capability_set(wStream* s, const rdpSettings* sett return FALSE; colorPointerFlag = (settings->ColorPointerFlag) ? 1 : 0; - Stream_Write_UINT16(s, colorPointerFlag); /* colorPointerFlag (2 bytes) */ + Stream_Write_UINT16(s, colorPointerFlag); /* colorPointerFlag (2 bytes) */ Stream_Write_UINT16(s, (UINT16)settings->PointerCacheSize); /* colorPointerCacheSize (2 bytes) */ @@ -1581,7 +1581,7 @@ static BOOL rdp_write_glyph_cache_capability_set(wStream* s, const rdpSettings* rdp_write_cache_definition(s, &(settings->GlyphCache[9])); /* glyphCache9 (4 bytes) */ rdp_write_cache_definition(s, settings->FragCache); /* fragCache (4 bytes) */ Stream_Write_UINT16(s, (UINT16)settings->GlyphSupportLevel); /* glyphSupportLevel (2 bytes) */ - Stream_Write_UINT16(s, 0); /* pad2Octets (2 bytes) */ + Stream_Write_UINT16(s, 0); /* pad2Octets (2 bytes) */ return rdp_capability_set_finish(s, (UINT16)header, CAPSET_TYPE_GLYPH_CACHE); } @@ -3225,7 +3225,7 @@ static BOOL rdp_print_bitmap_codecs_capability_set(wStream* s) return FALSE; if (Stream_GetRemainingLength(s) < 3) return FALSE; - Stream_Read_UINT8(s, codecId); /* codecId (1 byte) */ + Stream_Read_UINT8(s, codecId); /* codecId (1 byte) */ WLog_INFO(TAG, "\tcodecGuid: 0x"); rdp_print_bitmap_codec_guid(&codecGuid); WLog_INFO(TAG, " (%s)", rdp_get_bitmap_codec_guid_name(&codecGuid)); @@ -4011,9 +4011,9 @@ static BOOL rdp_write_demand_active(wStream* s, rdpSettings* settings) if (lengthCombinedCapabilities > UINT16_MAX) return FALSE; Stream_Write_UINT16( - s, (UINT16)lengthCombinedCapabilities); /* lengthCombinedCapabilities (2 bytes) */ - Stream_SetPosition(s, bm); /* go back to numberCapabilities */ - Stream_Write_UINT16(s, numberCapabilities); /* numberCapabilities (2 bytes) */ + s, (UINT16)lengthCombinedCapabilities); /* lengthCombinedCapabilities (2 bytes) */ + Stream_SetPosition(s, bm); /* go back to numberCapabilities */ + Stream_Write_UINT16(s, numberCapabilities); /* numberCapabilities (2 bytes) */ #ifdef WITH_DEBUG_CAPABILITIES Stream_Seek_UINT16(s); rdp_print_capability_sets(s, numberCapabilities, FALSE); @@ -4243,9 +4243,9 @@ static BOOL rdp_write_confirm_active(wStream* s, rdpSettings* settings) if (lengthCombinedCapabilities > UINT16_MAX) return FALSE; Stream_Write_UINT16( - s, (UINT16)lengthCombinedCapabilities); /* lengthCombinedCapabilities (2 bytes) */ - Stream_SetPosition(s, bm); /* go back to numberCapabilities */ - Stream_Write_UINT16(s, numberCapabilities); /* numberCapabilities (2 bytes) */ + s, (UINT16)lengthCombinedCapabilities); /* lengthCombinedCapabilities (2 bytes) */ + Stream_SetPosition(s, bm); /* go back to numberCapabilities */ + Stream_Write_UINT16(s, numberCapabilities); /* numberCapabilities (2 bytes) */ #ifdef WITH_DEBUG_CAPABILITIES Stream_Seek_UINT16(s); rdp_print_capability_sets(s, numberCapabilities, FALSE); diff --git a/libfreerdp/core/client.c b/libfreerdp/core/client.c index b8ecb4e33..a8f2719f7 100644 --- a/libfreerdp/core/client.c +++ b/libfreerdp/core/client.c @@ -448,7 +448,8 @@ BOOL freerdp_channels_data(freerdp* instance, UINT16 channelId, const BYTE* cdat rdpChannels* channels; rdpMcsChannel* channel = NULL; CHANNEL_OPEN_DATA* pChannelOpenData; - union { + union + { const BYTE* pcb; BYTE* pb; } data; diff --git a/libfreerdp/core/codecs.c b/libfreerdp/core/codecs.c index ee3fbd15e..30aae7ff8 100644 --- a/libfreerdp/core/codecs.c +++ b/libfreerdp/core/codecs.c @@ -65,8 +65,7 @@ BOOL freerdp_client_codecs_prepare(rdpCodecs* codecs, UINT32 flags, UINT32 width if ((flags & FREERDP_CODEC_REMOTEFX)) { rfx_context_free(codecs->rfx); - - if (!(codecs->rfx = rfx_context_new(FALSE))) + if (!(codecs->rfx = rfx_context_new(FALSE, codecs->context->settings->ThreadingFlags))) { WLog_ERR(TAG, "Failed to create rfx codec context"); return FALSE; diff --git a/libfreerdp/core/connection.c b/libfreerdp/core/connection.c index 143a1cbc5..12279705e 100644 --- a/libfreerdp/core/connection.c +++ b/libfreerdp/core/connection.c @@ -200,8 +200,8 @@ static BOOL rdp_client_reset_codecs(rdpContext* context) if (!context->codecs) return FALSE; - if (!freerdp_client_codecs_prepare(context->codecs, FREERDP_CODEC_ALL, settings->DesktopWidth, - settings->DesktopHeight)) + if (!freerdp_client_codecs_prepare(context->codecs, freerdp_settings_get_codecs_flags(settings), + settings->DesktopWidth, settings->DesktopHeight)) return FALSE; /* Runtime H264 detection. (only available if dynamic backend loading is defined) diff --git a/libfreerdp/core/gateway/rpc.h b/libfreerdp/core/gateway/rpc.h index 1a58fe450..81b86135c 100644 --- a/libfreerdp/core/gateway/rpc.h +++ b/libfreerdp/core/gateway/rpc.h @@ -525,7 +525,8 @@ typedef struct rpcconn_common_hdr_t header; } rpcconn_shutdown_hdr_t; -typedef union { +typedef union +{ rpcconn_common_hdr_t common; rpcconn_alter_context_hdr_t alter_context; rpcconn_alter_context_response_hdr_t alter_context_response; diff --git a/libfreerdp/core/info.c b/libfreerdp/core/info.c index 3f8afaef2..88301e743 100644 --- a/libfreerdp/core/info.c +++ b/libfreerdp/core/info.c @@ -466,7 +466,8 @@ fail: static BOOL rdp_read_info_string(UINT32 flags, wStream* s, size_t cbLenNonNull, CHAR** dst, size_t max) { - union { + union + { char c; WCHAR w; BYTE b[2]; @@ -713,7 +714,8 @@ static BOOL rdp_write_info_packet(rdpRdp* rdp, wStream* s) { if (settings->RedirectionPassword && settings->RedirectionPasswordLength > 0) { - union { + union + { BYTE* bp; WCHAR* wp; } ptrconv; @@ -916,7 +918,8 @@ static BOOL rdp_recv_logon_info_v1(rdpRdp* rdp, wStream* s, logon_info* info) { UINT32 cbDomain; UINT32 cbUserName; - union { + union + { BYTE* bp; WCHAR* wp; } ptrconv; diff --git a/libfreerdp/gdi/gfx.c b/libfreerdp/gdi/gfx.c index fa2fde9a0..e254ac55c 100644 --- a/libfreerdp/gdi/gfx.c +++ b/libfreerdp/gdi/gfx.c @@ -96,8 +96,12 @@ static UINT gdi_ResetGraphics(RdpgfxClientContext* context, free(pSurfaceIds); - if (!freerdp_client_codecs_reset(context->codecs, FREERDP_CODEC_ALL, gdi->width, gdi->height)) + if (!freerdp_client_codecs_reset(gdi->context->codecs, + freerdp_settings_get_codecs_flags(settings), gdi->width, + gdi->height)) + { goto fail; + } rc = CHANNEL_RC_OK; fail: diff --git a/server/Mac/mf_peer.c b/server/Mac/mf_peer.c index 5904b4b09..dfaeddd33 100644 --- a/server/Mac/mf_peer.c +++ b/server/Mac/mf_peer.c @@ -158,7 +158,7 @@ static BOOL mf_peer_context_new(freerdp_peer* client, mfPeerContext* context) if (!(context->info = mf_info_get_instance())) return FALSE; - if (!(context->rfx_context = rfx_context_new(TRUE))) + if (!(context->rfx_context = rfx_context_new(TRUE, client->settings->ThreadingFlags))) goto fail_rfx_context; context->rfx_context->mode = RLGR3; diff --git a/server/Sample/sfreerdp.c b/server/Sample/sfreerdp.c index bb9cc2de6..c8490bd22 100644 --- a/server/Sample/sfreerdp.c +++ b/server/Sample/sfreerdp.c @@ -58,7 +58,7 @@ static BOOL test_dump_rfx_realtime = TRUE; static BOOL test_peer_context_new(freerdp_peer* client, rdpContext* ctx) { testPeerContext* context = (testPeerContext*)ctx; - if (!(context->rfx_context = rfx_context_new(TRUE))) + if (!(context->rfx_context = rfx_context_new(TRUE, client->settings->ThreadingFlags))) goto fail_rfx_context; if (!rfx_context_reset(context->rfx_context, SAMPLE_SERVER_DEFAULT_WIDTH, diff --git a/server/Windows/wf_update.c b/server/Windows/wf_update.c index 21a4c72b2..114163f9e 100644 --- a/server/Windows/wf_update.c +++ b/server/Windows/wf_update.c @@ -187,7 +187,8 @@ void wf_update_encoder_reset(wfInfo* wfi) } else { - wfi->rfx_context = rfx_context_new(TRUE); + /* TODO: pass ThreadingFlags somehow */ + wfi->rfx_context = rfx_context_new(TRUE, 0); wfi->rfx_context->mode = RLGR3; wfi->rfx_context->width = wfi->servscreen_width; wfi->rfx_context->height = wfi->servscreen_height; diff --git a/server/proxy/pf_modules.c b/server/proxy/pf_modules.c index 79ffb044c..103a78d0f 100644 --- a/server/proxy/pf_modules.c +++ b/server/proxy/pf_modules.c @@ -204,7 +204,8 @@ BOOL pf_modules_run_filter(PF_FILTER_TYPE type, proxyData* pdata, void* param) */ static BOOL pf_modules_set_plugin_data(const char* plugin_name, proxyData* pdata, void* data) { - union { + union + { const char* ccp; char* cp; } ccharconv; @@ -233,7 +234,8 @@ static BOOL pf_modules_set_plugin_data(const char* plugin_name, proxyData* pdata */ static void* pf_modules_get_plugin_data(const char* plugin_name, proxyData* pdata) { - union { + union + { const char* ccp; char* cp; } ccharconv; diff --git a/server/shadow/shadow_encoder.c b/server/shadow/shadow_encoder.c index 030ef4e6a..40fd5783f 100644 --- a/server/shadow/shadow_encoder.c +++ b/server/shadow/shadow_encoder.c @@ -132,7 +132,7 @@ static int shadow_encoder_uninit_grid(rdpShadowEncoder* encoder) static int shadow_encoder_init_rfx(rdpShadowEncoder* encoder) { if (!encoder->rfx) - encoder->rfx = rfx_context_new(TRUE); + encoder->rfx = rfx_context_new(TRUE, encoder->server->settings->ThreadingFlags); if (!encoder->rfx) goto fail; diff --git a/uwac/include/uwac/uwac.h b/uwac/include/uwac/uwac.h index 819796105..f0d2c50d9 100644 --- a/uwac/include/uwac/uwac.h +++ b/uwac/include/uwac/uwac.h @@ -276,7 +276,8 @@ struct uwac_output_geometry_event typedef struct uwac_output_geometry_event UwacOutputGeometryEvent; /** @brief */ -union uwac_event { +union uwac_event +{ int type; UwacOutputNewEvent output_new; UwacOutputGeometryEvent output_geometry; diff --git a/winpr/include/winpr/asn1.h b/winpr/include/winpr/asn1.h index 6efe2e316..17b252c4d 100644 --- a/winpr/include/winpr/asn1.h +++ b/winpr/include/winpr/asn1.h @@ -168,7 +168,8 @@ extern "C" { ASN1uint32_t length; - union { + union + { void* encoded; void* value; }; @@ -361,7 +362,8 @@ extern "C" { ASN1option_e eOption; - union { + union + { ASN1encodingrule_e eRule; ASN1uint32_t cbRequiredDecodedBufSize; diff --git a/winpr/include/winpr/file.h b/winpr/include/winpr/file.h index b281a809e..2d64d45fb 100644 --- a/winpr/include/winpr/file.h +++ b/winpr/include/winpr/file.h @@ -180,7 +180,8 @@ #define MOVEFILE_CREATE_HARDLINK 0x10 #define MOVEFILE_FAIL_IF_NOT_TRACKABLE 0x20 -typedef union _FILE_SEGMENT_ELEMENT { +typedef union _FILE_SEGMENT_ELEMENT +{ PVOID64 Buffer; ULONGLONG Alignment; } FILE_SEGMENT_ELEMENT, *PFILE_SEGMENT_ELEMENT; diff --git a/winpr/include/winpr/interlocked.h b/winpr/include/winpr/interlocked.h index 5be208598..714827fe7 100644 --- a/winpr/include/winpr/interlocked.h +++ b/winpr/include/winpr/interlocked.h @@ -86,7 +86,8 @@ extern "C" #ifdef _WIN64 - typedef union DECLSPEC_ALIGN(16) _WINPR_SLIST_HEADER { + typedef union DECLSPEC_ALIGN(16) _WINPR_SLIST_HEADER + { struct { ULONGLONG Alignment; @@ -116,7 +117,8 @@ extern "C" #else /* _WIN64 */ - typedef union _WINPR_SLIST_HEADER { + typedef union _WINPR_SLIST_HEADER + { ULONGLONG Alignment; struct diff --git a/winpr/include/winpr/io.h b/winpr/include/winpr/io.h index aee1ee99a..60464310d 100644 --- a/winpr/include/winpr/io.h +++ b/winpr/include/winpr/io.h @@ -35,7 +35,8 @@ typedef struct _OVERLAPPED { ULONG_PTR Internal; ULONG_PTR InternalHigh; - union { + union + { struct { DWORD Offset; diff --git a/winpr/include/winpr/ndr.h b/winpr/include/winpr/ndr.h index 2580a6ce6..0176d1fbc 100644 --- a/winpr/include/winpr/ndr.h +++ b/winpr/include/winpr/ndr.h @@ -28,7 +28,8 @@ #define __RPC_WIN32__ 1 #define TARGET_IS_NT50_OR_LATER 1 -typedef union _CLIENT_CALL_RETURN { +typedef union _CLIENT_CALL_RETURN +{ void* Pointer; LONG_PTR Simple; } CLIENT_CALL_RETURN; @@ -243,7 +244,8 @@ struct _MIDL_STUB_DESC void* (*pfnAllocate)(size_t); void (*pfnFree)(void*); - union { + union + { handle_t* pAutoHandle; handle_t* pPrimitiveHandle; PGENERIC_BINDING_INFO pGenericBindingInfo; @@ -350,7 +352,8 @@ typedef struct PARAM_ATTRIBUTES Attributes; unsigned short StackOffset; - union { + union + { unsigned char FormatChar; unsigned short Offset; } Type; diff --git a/winpr/include/winpr/nt.h b/winpr/include/winpr/nt.h index 0cbcde0be..59bc8cbf3 100644 --- a/winpr/include/winpr/nt.h +++ b/winpr/include/winpr/nt.h @@ -1431,7 +1431,8 @@ typedef OBJECT_ATTRIBUTES* POBJECT_ATTRIBUTES; typedef struct _IO_STATUS_BLOCK { - union { + union + { #ifdef _WIN32 NTSTATUS Status; #else diff --git a/winpr/include/winpr/pool.h b/winpr/include/winpr/pool.h index 62111dcdd..8c194485a 100644 --- a/winpr/include/winpr/pool.h +++ b/winpr/include/winpr/pool.h @@ -56,7 +56,8 @@ typedef struct _TP_CALLBACK_ENVIRON_V1 struct _ACTIVATION_CONTEXT* ActivationContext; PTP_SIMPLE_CALLBACK FinalizationCallback; - union { + union + { DWORD Flags; struct { diff --git a/winpr/include/winpr/rpc.h b/winpr/include/winpr/rpc.h index 7f4be9902..fff06e3c7 100644 --- a/winpr/include/winpr/rpc.h +++ b/winpr/include/winpr/rpc.h @@ -308,7 +308,8 @@ typedef struct _RPC_SECURITY_QOS_V2_W unsigned long IdentityTracking; unsigned long ImpersonationType; unsigned long AdditionalSecurityInfoType; - union { + union + { RPC_HTTP_TRANSPORT_CREDENTIALS_W* HttpCredentials; } u; } RPC_SECURITY_QOS_V2_W, *PRPC_SECURITY_QOS_V2_W; @@ -320,7 +321,8 @@ typedef struct _RPC_SECURITY_QOS_V2_A unsigned long IdentityTracking; unsigned long ImpersonationType; unsigned long AdditionalSecurityInfoType; - union { + union + { RPC_HTTP_TRANSPORT_CREDENTIALS_A* HttpCredentials; } u; } RPC_SECURITY_QOS_V2_A, *PRPC_SECURITY_QOS_V2_A; @@ -334,7 +336,8 @@ typedef struct _RPC_SECURITY_QOS_V3_W unsigned long IdentityTracking; unsigned long ImpersonationType; unsigned long AdditionalSecurityInfoType; - union { + union + { RPC_HTTP_TRANSPORT_CREDENTIALS_W* HttpCredentials; } u; void* Sid; @@ -347,7 +350,8 @@ typedef struct _RPC_SECURITY_QOS_V3_A unsigned long IdentityTracking; unsigned long ImpersonationType; unsigned long AdditionalSecurityInfoType; - union { + union + { RPC_HTTP_TRANSPORT_CREDENTIALS_A* HttpCredentials; } u; void* Sid; @@ -440,7 +444,8 @@ typedef struct _RPC_BINDING_HANDLE_TEMPLATE unsigned long ProtocolSequence; unsigned short* NetworkAddress; unsigned short* StringEndpoint; - union { + union + { unsigned short* Reserved; } u1; UUID ObjectUuid; diff --git a/winpr/include/winpr/smartcard.h b/winpr/include/winpr/smartcard.h index e19a6ee02..4e6a4c3b5 100644 --- a/winpr/include/winpr/smartcard.h +++ b/winpr/include/winpr/smartcard.h @@ -250,7 +250,8 @@ typedef struct { SCARD_IO_REQUEST ioRequest; BYTE bSw1, bSw2; - union { + union + { SCARD_T0_COMMAND CmdBytes; BYTE rgbHeader[5]; } DUMMYUNIONNAME; @@ -472,7 +473,8 @@ typedef struct DWORD dwShareMode; DWORD dwPreferredProtocols; READER_SEL_REQUEST_MATCH_TYPE MatchType; - union { + union + { struct { DWORD cbReaderNameOffset; diff --git a/winpr/include/winpr/synch.h b/winpr/include/winpr/synch.h index 4c75b17ae..06f0fc4bd 100644 --- a/winpr/include/winpr/synch.h +++ b/winpr/include/winpr/synch.h @@ -202,7 +202,8 @@ extern "C" ULONG Version; DWORD Flags; - union { + union + { struct { HMODULE LocalizedReasonModule; diff --git a/winpr/include/winpr/sysinfo.h b/winpr/include/winpr/sysinfo.h index c14e999d9..38d0381db 100644 --- a/winpr/include/winpr/sysinfo.h +++ b/winpr/include/winpr/sysinfo.h @@ -75,7 +75,8 @@ extern "C" typedef struct _SYSTEM_INFO { - union { + union + { DWORD dwOemId; struct diff --git a/winpr/include/winpr/winsock.h b/winpr/include/winpr/winsock.h index 167760920..4d3099321 100644 --- a/winpr/include/winpr/winsock.h +++ b/winpr/include/winpr/winsock.h @@ -178,7 +178,8 @@ struct sockaddr_in6_old IN6_ADDR sin6_addr; }; -typedef union sockaddr_gen { +typedef union sockaddr_gen +{ struct sockaddr Address; struct sockaddr_in AddressIn; struct sockaddr_in6_old AddressIn6; diff --git a/winpr/include/winpr/wtsapi.h b/winpr/include/winpr/wtsapi.h index 21d86fef7..1e376e9a8 100644 --- a/winpr/include/winpr/wtsapi.h +++ b/winpr/include/winpr/wtsapi.h @@ -549,11 +549,13 @@ typedef struct _WTSINFOEX_LEVEL1_A DWORD OutgoingCompressedBytes; } WTSINFOEX_LEVEL1_A, *PWTSINFOEX_LEVEL1_A; -typedef union _WTSINFOEX_LEVEL_W { +typedef union _WTSINFOEX_LEVEL_W +{ WTSINFOEX_LEVEL1_W WTSInfoExLevel1; } WTSINFOEX_LEVEL_W, *PWTSINFOEX_LEVEL_W; -typedef union _WTSINFOEX_LEVEL_A { +typedef union _WTSINFOEX_LEVEL_A +{ WTSINFOEX_LEVEL1_A WTSInfoExLevel1; } WTSINFOEX_LEVEL_A, *PWTSINFOEX_LEVEL_A; diff --git a/winpr/libwinpr/registry/registry_reg.h b/winpr/libwinpr/registry/registry_reg.h index 90db136b4..a4e7e9a6d 100644 --- a/winpr/libwinpr/registry/registry_reg.h +++ b/winpr/libwinpr/registry/registry_reg.h @@ -44,7 +44,8 @@ struct _reg_val RegVal* prev; RegVal* next; - union reg_data { + union reg_data + { DWORD dword; char* string; } data; diff --git a/winpr/libwinpr/smartcard/smartcard_pcsc.c b/winpr/libwinpr/smartcard/smartcard_pcsc.c index 4cf5095ac..ebf454d31 100644 --- a/winpr/libwinpr/smartcard/smartcard_pcsc.c +++ b/winpr/libwinpr/smartcard/smartcard_pcsc.c @@ -764,7 +764,8 @@ static LONG WINAPI PCSC_SCardListReaderGroups_Internal(SCARDCONTEXT hContext, LP PCSC_LONG status = SCARD_S_SUCCESS; BOOL pcchGroupsAlloc = FALSE; PCSC_DWORD pcsc_cchGroups = 0; - union { + union + { LPSTR lpstr; LPSTR* lppstr; } conv; @@ -835,7 +836,8 @@ static LONG WINAPI PCSC_SCardListReaderGroupsW(SCARDCONTEXT hContext, LPWSTR msz LPSTR mszGroupsA = NULL; LPSTR* pMszGroupsA = &mszGroupsA; LONG status = SCARD_S_SUCCESS; - union { + union + { LPWSTR lpstr; LPWSTR* lppstr; } conv; @@ -871,7 +873,8 @@ static LONG WINAPI PCSC_SCardListReaders_Internal(SCARDCONTEXT hContext, LPCSTR PCSC_LONG status = SCARD_S_SUCCESS; BOOL pcchReadersAlloc = FALSE; PCSC_DWORD pcsc_cchReaders = 0; - union { + union + { LPSTR lpstr; LPSTR* lppstr; } conv; @@ -963,7 +966,8 @@ static LONG WINAPI PCSC_SCardListReadersW(SCARDCONTEXT hContext, LPCWSTR mszGrou LPSTR* pMszReadersA = &mszReadersA; LONG status = SCARD_S_SUCCESS; BOOL nullCardContext = FALSE; - union { + union + { LPWSTR lpstr; LPWSTR* lppstr; } conv; @@ -1879,7 +1883,8 @@ static LONG WINAPI PCSC_SCardStatus_Internal(SCARDHANDLE hCard, LPSTR mszReaderN if (tATR) { - union { + union + { BYTE* pb; BYTE** ppb; } conv; @@ -1890,7 +1895,8 @@ static LONG WINAPI PCSC_SCardStatus_Internal(SCARDHANDLE hCard, LPSTR mszReaderN if (tReader) { - union { + union + { CHAR* pc; CHAR** ppc; WCHAR* pw; @@ -2015,7 +2021,8 @@ static LONG WINAPI PCSC_SCardTransmit(SCARDHANDLE hCard, LPCSCARD_IO_REQUEST pio BYTE* pcsc_pbExtraBytes = NULL; PCSC_DWORD pcsc_cbSendLength = (PCSC_DWORD)cbSendLength; PCSC_DWORD pcsc_cbRecvLength = 0; - union { + union + { const PCSC_SCARD_IO_REQUEST* pcs; PCSC_SCARD_IO_REQUEST* ps; LPSCARD_IO_REQUEST lps; @@ -2223,7 +2230,8 @@ static LONG WINAPI PCSC_SCardGetAttrib_Internal(SCARDHANDLE hCard, DWORD dwAttrI PCSC_SCARDHANDLE* pCard = NULL; PCSC_DWORD pcsc_dwAttrId = (PCSC_DWORD)dwAttrId; PCSC_DWORD pcsc_cbAttrLen = 0; - union { + union + { BYTE* pb; BYTE** ppb; } conv; @@ -2295,7 +2303,8 @@ static LONG WINAPI PCSC_SCardGetAttrib_FriendlyName(SCARDHANDLE hCard, DWORD dwA WCHAR* pbAttrW = NULL; SCARDCONTEXT hContext; LONG status = SCARD_S_SUCCESS; - union { + union + { WCHAR** ppw; BYTE* pb; BYTE** ppb; @@ -2400,7 +2409,8 @@ static LONG WINAPI PCSC_SCardGetAttrib(SCARDHANDLE hCard, DWORD dwAttrId, LPBYTE SCARDCONTEXT hContext; BOOL pcbAttrLenAlloc = FALSE; LONG status = SCARD_S_SUCCESS; - union { + union + { BYTE* pb; BYTE** ppb; } conv; @@ -2485,7 +2495,8 @@ static LONG WINAPI PCSC_SCardGetAttrib(SCARDHANDLE hCard, DWORD dwAttrId, LPBYTE if (status == SCARD_S_SUCCESS) { - union { + union + { BYTE* pb; LPDWORD pd; } conv; @@ -2506,7 +2517,8 @@ static LONG WINAPI PCSC_SCardGetAttrib(SCARDHANDLE hCard, DWORD dwAttrId, LPBYTE { UINT32 channelType = 0x20; /* USB */ UINT32 channelNumber = 0; - union { + union + { BYTE* pb; BYTE** ppb; DWORD* ppd; @@ -2689,7 +2701,8 @@ static LONG WINAPI PCSC_SCardReadCacheA(SCARDCONTEXT hContext, UUID* CardIdentif if (*DataLen == SCARD_AUTOALLOCATE) { BYTE* mem; - union { + union + { BYTE* pb; BYTE** ppb; } conv; @@ -2740,7 +2753,8 @@ static LONG WINAPI PCSC_SCardReadCacheW(SCARDCONTEXT hContext, UUID* CardIdentif if (*DataLen == SCARD_AUTOALLOCATE) { BYTE* mem; - union { + union + { BYTE* pb; BYTE** ppb; } conv; diff --git a/winpr/libwinpr/utils/trio/trio.c b/winpr/libwinpr/utils/trio/trio.c index b278f475b..d5fcf9562 100644 --- a/winpr/libwinpr/utils/trio/trio.c +++ b/winpr/libwinpr/utils/trio/trio.c @@ -795,13 +795,15 @@ typedef struct /* Position in the argument list that this parameter refers to */ int position; /* The data from the argument list */ - union { + union + { char* string; #if TRIO_FEATURE_WIDECHAR trio_wchar_t* wstring; #endif trio_pointer_t pointer; - union { + union + { trio_intmax_t as_signed; trio_uintmax_t as_unsigned; } number; @@ -815,7 +817,8 @@ typedef struct } data; #if TRIO_FEATURE_USER_DEFINED /* For the user-defined specifier */ - union { + union + { char namespace[MAX_USER_NAME]; int handler; /* if flags & FLAGS_USER_DEFINED_PARAMETER */ } user_defined; @@ -826,7 +829,8 @@ typedef struct /* Container for customized functions */ typedef struct { - union { + union + { trio_outstream_t out; trio_instream_t in; } stream; @@ -861,7 +865,8 @@ typedef struct _trio_class_t * if there had been sufficient space. */ int processed; - union { + union + { /* * The number of characters that are actually written. Processed and * committed will only differ for the *nprintf functions.