Mac fixes

This commit is contained in:
Armin Novak 2018-09-25 15:46:36 +02:00
parent e61219eb58
commit 5e14bb1b11
4 changed files with 79 additions and 36 deletions

View File

@ -32,7 +32,7 @@
#include <freerdp/log.h> #include <freerdp/log.h>
#define TAG SERVER_TAG("sample") #define TAG SERVER_TAG("sample")
static const AUDIO_FORMAT test_audio_formats[] = static AUDIO_FORMAT test_audio_formats[] =
{ {
{ WAVE_FORMAT_PCM, 2, 44100, 176400, 4, 16, 0, NULL }, { WAVE_FORMAT_PCM, 2, 44100, 176400, 4, 16, 0, NULL },
{ WAVE_FORMAT_ALAW, 2, 22050, 44100, 2, 8, 0, NULL } { WAVE_FORMAT_ALAW, 2, 22050, 44100, 2, 8, 0, NULL }

View File

@ -26,6 +26,7 @@ if(POLICY CMP0022)
endif() endif()
set(${MODULE_PREFIX}_SRCS set(${MODULE_PREFIX}_SRCS
server.h
server.c) server.c)
foreach(FREERDP_CHANNELS_SERVER_SRC ${FREERDP_CHANNELS_SERVER_SRCS}) foreach(FREERDP_CHANNELS_SERVER_SRC ${FREERDP_CHANNELS_SERVER_SRCS})

24
server/common/server.h Normal file
View File

@ -0,0 +1,24 @@
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* FreeRDP Server Common
*
* Copyright 2018 Armin Novak <armin.novak@thincast.com>
* Copyright 2018 Thincast Technologies GmbH
*
* 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.
*/
#ifndef FREERDP_SERVER_COMMON_SERVER_H
#define FREERDP_SERVER_COMMON_SERVER_H
#endif /* FREERDP_SERVER_COMMON_SERVER_H */

View File

@ -32,12 +32,16 @@
static macShadowSubsystem* g_Subsystem = NULL; static macShadowSubsystem* g_Subsystem = NULL;
static void mac_shadow_input_synchronize_event(macShadowSubsystem* subsystem, static BOOL mac_shadow_input_synchronize_event(rdpShadowSubsystem* subsystem,
rdpShadowClient* client, UINT32 flags) rdpShadowClient* client, UINT32 flags)
{ {
if (!subsystem || !client)
return FALSE;
return TRUE;
} }
static void mac_shadow_input_keyboard_event(macShadowSubsystem* subsystem, static BOOL mac_shadow_input_keyboard_event(rdpShadowSubsystem* subsystem,
rdpShadowClient* client, UINT16 flags, UINT16 code) rdpShadowClient* client, UINT16 flags, UINT16 code)
{ {
DWORD vkcode; DWORD vkcode;
@ -47,6 +51,9 @@ static void mac_shadow_input_keyboard_event(macShadowSubsystem* subsystem,
CGEventSourceRef source; CGEventSourceRef source;
extended = (flags & KBD_FLAGS_EXTENDED) ? TRUE : FALSE; extended = (flags & KBD_FLAGS_EXTENDED) ? TRUE : FALSE;
if (!subsystem || !client)
return FALSE;
if (extended) if (extended)
code |= KBDEXT; code |= KBDEXT;
@ -58,7 +65,7 @@ static void mac_shadow_input_keyboard_event(macShadowSubsystem* subsystem,
keycode = GetKeycodeFromVirtualKeyCode(vkcode, KEYCODE_TYPE_APPLE); keycode = GetKeycodeFromVirtualKeyCode(vkcode, KEYCODE_TYPE_APPLE);
if (keycode < 8) if (keycode < 8)
return; return TRUE;
keycode -= 8; keycode -= 8;
source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState); source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
@ -77,20 +84,29 @@ static void mac_shadow_input_keyboard_event(macShadowSubsystem* subsystem,
} }
CFRelease(source); CFRelease(source);
return TRUE;
} }
static void mac_shadow_input_unicode_keyboard_event(macShadowSubsystem* static BOOL mac_shadow_input_unicode_keyboard_event(rdpShadowSubsystem*
subsystem, rdpShadowClient* client, UINT16 flags, UINT16 code) subsystem, rdpShadowClient* client, UINT16 flags, UINT16 code)
{ {
if (!subsystem || !client)
return FALSE;
return TRUE;
} }
static void mac_shadow_input_mouse_event(macShadowSubsystem* subsystem, static BOOL mac_shadow_input_mouse_event(rdpShadowSubsystem* subsystem,
rdpShadowClient* client, UINT16 flags, UINT16 x, UINT16 y) rdpShadowClient* client, UINT16 flags, UINT16 x, UINT16 y)
{ {
macShadowSubsystem* mac = (macShadowSubsystem*)subsystem;
UINT32 scrollX = 0; UINT32 scrollX = 0;
UINT32 scrollY = 0; UINT32 scrollY = 0;
CGWheelCount wheelCount = 2; CGWheelCount wheelCount = 2;
if (!subsystem || !client)
return FALSE;
if (flags & PTR_FLAGS_WHEEL) if (flags & PTR_FLAGS_WHEEL)
{ {
scrollY = flags & WheelRotationMask; scrollY = flags & WheelRotationMask;
@ -122,11 +138,11 @@ static void mac_shadow_input_mouse_event(macShadowSubsystem* subsystem,
if (flags & PTR_FLAGS_MOVE) if (flags & PTR_FLAGS_MOVE)
{ {
if (subsystem->mouseDownLeft) if (mac->mouseDownLeft)
mouseType = kCGEventLeftMouseDragged; mouseType = kCGEventLeftMouseDragged;
else if (subsystem->mouseDownRight) else if (mac->mouseDownRight)
mouseType = kCGEventRightMouseDragged; mouseType = kCGEventRightMouseDragged;
else if (subsystem->mouseDownOther) else if (mac->mouseDownOther)
mouseType = kCGEventOtherMouseDragged; mouseType = kCGEventOtherMouseDragged;
else else
mouseType = kCGEventMouseMoved; mouseType = kCGEventMouseMoved;
@ -144,12 +160,12 @@ static void mac_shadow_input_mouse_event(macShadowSubsystem* subsystem,
if (flags & PTR_FLAGS_DOWN) if (flags & PTR_FLAGS_DOWN)
{ {
mouseType = kCGEventLeftMouseDown; mouseType = kCGEventLeftMouseDown;
subsystem->mouseDownLeft = TRUE; mac->mouseDownLeft = TRUE;
} }
else else
{ {
mouseType = kCGEventLeftMouseUp; mouseType = kCGEventLeftMouseUp;
subsystem->mouseDownLeft = FALSE; mac->mouseDownLeft = FALSE;
} }
} }
else if (flags & PTR_FLAGS_BUTTON2) else if (flags & PTR_FLAGS_BUTTON2)
@ -159,12 +175,12 @@ static void mac_shadow_input_mouse_event(macShadowSubsystem* subsystem,
if (flags & PTR_FLAGS_DOWN) if (flags & PTR_FLAGS_DOWN)
{ {
mouseType = kCGEventRightMouseDown; mouseType = kCGEventRightMouseDown;
subsystem->mouseDownRight = TRUE; mac->mouseDownRight = TRUE;
} }
else else
{ {
mouseType = kCGEventRightMouseUp; mouseType = kCGEventRightMouseUp;
subsystem->mouseDownRight = FALSE; mac->mouseDownRight = FALSE;
} }
} }
else if (flags & PTR_FLAGS_BUTTON3) else if (flags & PTR_FLAGS_BUTTON3)
@ -174,12 +190,12 @@ static void mac_shadow_input_mouse_event(macShadowSubsystem* subsystem,
if (flags & PTR_FLAGS_DOWN) if (flags & PTR_FLAGS_DOWN)
{ {
mouseType = kCGEventOtherMouseDown; mouseType = kCGEventOtherMouseDown;
subsystem->mouseDownOther = TRUE; mac->mouseDownOther = TRUE;
} }
else else
{ {
mouseType = kCGEventOtherMouseUp; mouseType = kCGEventOtherMouseUp;
subsystem->mouseDownOther = FALSE; mac->mouseDownOther = FALSE;
} }
} }
@ -189,11 +205,17 @@ static void mac_shadow_input_mouse_event(macShadowSubsystem* subsystem,
CFRelease(mouseEvent); CFRelease(mouseEvent);
CFRelease(source); CFRelease(source);
} }
return TRUE;
} }
static void mac_shadow_input_extended_mouse_event(macShadowSubsystem* subsystem, static BOOL mac_shadow_input_extended_mouse_event(rdpShadowSubsystem* subsystem,
rdpShadowClient* client, UINT16 flags, UINT16 x, UINT16 y) rdpShadowClient* client, UINT16 flags, UINT16 x, UINT16 y)
{ {
if (!subsystem || !client)
return FALSE;
return TRUE;
} }
static int mac_shadow_detect_monitors(macShadowSubsystem* subsystem) static int mac_shadow_detect_monitors(macShadowSubsystem* subsystem)
@ -221,8 +243,8 @@ static int mac_shadow_detect_monitors(macShadowSubsystem* subsystem)
subsystem->height = subsystem->pixelHeight; subsystem->height = subsystem->pixelHeight;
} }
subsystem->numMonitors = 1; subsystem->common.numMonitors = 1;
monitor = &(subsystem->monitors[0]); monitor = &(subsystem->common.monitors[0]);
monitor->left = 0; monitor->left = 0;
monitor->top = 0; monitor->top = 0;
monitor->right = subsystem->width; monitor->right = subsystem->width;
@ -259,7 +281,7 @@ static int mac_shadow_capture_get_dirty_region(macShadowSubsystem* subsystem)
size_t numRects; size_t numRects;
const CGRect* rects; const CGRect* rects;
RECTANGLE_16 invalidRect; RECTANGLE_16 invalidRect;
rdpShadowSurface* surface = subsystem->server->surface; rdpShadowSurface* surface = subsystem->common.server->surface;
rects = CGDisplayStreamUpdateGetRects(subsystem->lastUpdate, rects = CGDisplayStreamUpdateGetRects(subsystem->lastUpdate,
kCGDisplayStreamUpdateDirtyRects, &numRects); kCGDisplayStreamUpdateDirtyRects, &numRects);
@ -359,7 +381,7 @@ static void (^mac_capture_stream_handler)(CGDisplayStreamFrameStatus, uint64_t,
RECTANGLE_16 surfaceRect; RECTANGLE_16 surfaceRect;
const RECTANGLE_16* extents; const RECTANGLE_16* extents;
macShadowSubsystem* subsystem = g_Subsystem; macShadowSubsystem* subsystem = g_Subsystem;
rdpShadowServer* server = subsystem->server; rdpShadowServer* server = subsystem->common.server;
rdpShadowSurface* surface = server->surface; rdpShadowSurface* surface = server->surface;
count = ArrayList_Count(server->clients); count = ArrayList_Count(server->clients);
@ -401,7 +423,7 @@ static void (^mac_capture_stream_handler)(CGDisplayStreamFrameStatus, uint64_t,
ArrayList_Lock(server->clients); ArrayList_Lock(server->clients);
count = ArrayList_Count(server->clients); count = ArrayList_Count(server->clients);
EnterCriticalSection(&(surface->lock)); EnterCriticalSection(&(surface->lock));
shadow_subsystem_frame_update((rdpShadowSubsystem*)subsystem); shadow_subsystem_frame_update(&subsystem->common);
LeaveCriticalSection(&(surface->lock)); LeaveCriticalSection(&(surface->lock));
if (count == 1) if (count == 1)
@ -411,7 +433,7 @@ static void (^mac_capture_stream_handler)(CGDisplayStreamFrameStatus, uint64_t,
if (client) if (client)
{ {
subsystem->captureFrameRate = shadow_encoder_preferred_fps(client->encoder); subsystem->common.captureFrameRate = shadow_encoder_preferred_fps(client->encoder);
} }
} }
@ -477,7 +499,7 @@ static int mac_shadow_screen_grab(macShadowSubsystem* subsystem)
static int mac_shadow_subsystem_process_message(macShadowSubsystem* subsystem, static int mac_shadow_subsystem_process_message(macShadowSubsystem* subsystem,
wMessage* message) wMessage* message)
{ {
rdpShadowServer* server = subsystem->server; rdpShadowServer* server = subsystem->common.server;
rdpShadowSurface* surface = server->surface; rdpShadowSurface* surface = server->surface;
switch (message->id) switch (message->id)
@ -511,11 +533,11 @@ static DWORD WINAPI mac_shadow_subsystem_thread(LPVOID arg)
HANDLE events[32]; HANDLE events[32];
wMessage message; wMessage message;
wMessagePipe* MsgPipe; wMessagePipe* MsgPipe;
MsgPipe = subsystem->MsgPipe; MsgPipe = subsystem->common.MsgPipe;
nCount = 0; nCount = 0;
events[nCount++] = MessageQueue_Event(MsgPipe->In); events[nCount++] = MessageQueue_Event(MsgPipe->In);
subsystem->captureFrameRate = 16; subsystem->common.captureFrameRate = 16;
dwInterval = 1000 / subsystem->captureFrameRate; dwInterval = 1000 / subsystem->common.captureFrameRate;
frameTime = GetTickCount64() + dwInterval; frameTime = GetTickCount64() + dwInterval;
while (1) while (1)
@ -538,7 +560,7 @@ static DWORD WINAPI mac_shadow_subsystem_thread(LPVOID arg)
if ((status == WAIT_TIMEOUT) || (GetTickCount64() > frameTime)) if ((status == WAIT_TIMEOUT) || (GetTickCount64() > frameTime))
{ {
mac_shadow_screen_grab(subsystem); mac_shadow_screen_grab(subsystem);
dwInterval = 1000 / subsystem->captureFrameRate; dwInterval = 1000 / subsystem->common.captureFrameRate;
frameTime += dwInterval; frameTime += dwInterval;
} }
} }
@ -636,15 +658,11 @@ static macShadowSubsystem* mac_shadow_subsystem_new(void)
if (!subsystem) if (!subsystem)
return NULL; return NULL;
subsystem->SynchronizeEvent = (pfnShadowSynchronizeEvent) subsystem->common.SynchronizeEvent = mac_shadow_input_synchronize_event;
mac_shadow_input_synchronize_event; subsystem->common.KeyboardEvent = mac_shadow_input_keyboard_event;
subsystem->KeyboardEvent = (pfnShadowKeyboardEvent) subsystem->common.UnicodeKeyboardEvent = mac_shadow_input_unicode_keyboard_event;
mac_shadow_input_keyboard_event; subsystem->common.MouseEvent = mac_shadow_input_mouse_event;
subsystem->UnicodeKeyboardEvent = (pfnShadowUnicodeKeyboardEvent) subsystem->common.ExtendedMouseEvent = mac_shadow_input_extended_mouse_event;
mac_shadow_input_unicode_keyboard_event;
subsystem->MouseEvent = (pfnShadowMouseEvent) mac_shadow_input_mouse_event;
subsystem->ExtendedMouseEvent = (pfnShadowExtendedMouseEvent)
mac_shadow_input_extended_mouse_event;
return subsystem; return subsystem;
} }