Fixed mac server compilation.

This commit is contained in:
Armin Novak 2017-11-24 12:46:01 +01:00
parent d982cf0e90
commit 8eaba5b002
7 changed files with 210 additions and 238 deletions

View File

@ -27,7 +27,7 @@ if(FREERDP_VENDOR)
if(NOT WIN32) if(NOT WIN32)
if(APPLE AND (NOT IOS)) if(APPLE AND (NOT IOS))
#add_subdirectory(Mac) add_subdirectory(Mac)
endif() endif()
else() else()
#add_subdirectory(Windows) #add_subdirectory(Windows)

View File

@ -28,6 +28,9 @@
#include "mf_info.h" #include "mf_info.h"
#include "mf_mountain_lion.h" #include "mf_mountain_lion.h"
#define MF_INFO_DEFAULT_FPS 30
#define MF_INFO_MAXPEERS 32
static mfInfo* mfInfoInstance = NULL; static mfInfo* mfInfoInstance = NULL;
int mf_info_lock(mfInfo* mfi) int mf_info_lock(mfInfo* mfi)
@ -142,7 +145,7 @@ void mf_info_peer_register(mfInfo* mfi, mfPeerContext* context)
mf_mlion_start_getting_screen_updates(); mf_mlion_start_getting_screen_updates();
} }
peerId = NULL; peerId = 0;
for(i=0; i<MF_INFO_MAXPEERS; ++i) for(i=0; i<MF_INFO_MAXPEERS; ++i)
{ {

View File

@ -291,59 +291,59 @@ static const CGKeyCode keymap[256] =
0xFF, //0xfe 0xFF, //0xfe
}; };
void mf_input_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) BOOL mf_input_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
{ {
CGEventSourceRef source = CGEventSourceCreate (kCGEventSourceStateHIDSystemState); CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
BOOL keyDown = TRUE; BOOL keyDown = TRUE;
CGEventRef kbEvent; CGEventRef kbEvent;
CGKeyCode kCode = 0xFF; CGKeyCode kCode = 0xFF;
if (flags & KBD_FLAGS_RELEASE) if (flags & KBD_FLAGS_RELEASE)
{ {
keyDown = FALSE; keyDown = FALSE;
} }
if (flags & KBD_FLAGS_EXTENDED) if (flags & KBD_FLAGS_EXTENDED)
{ {
switch (code) { switch (code)
{
//case 0x52: //insert //case 0x52: //insert
case 0x53: case 0x53:
kCode = kVK_ForwardDelete; kCode = kVK_ForwardDelete;
break; break;
case 0x4B: case 0x4B:
kCode = kVK_LeftArrow; kCode = kVK_LeftArrow;
break; break;
case 0x47: case 0x47:
kCode = kVK_Home; kCode = kVK_Home;
break; break;
case 0x4F: case 0x4F:
kCode = kVK_End; kCode = kVK_End;
break; break;
case 0x48: case 0x48:
kCode = kVK_UpArrow; kCode = kVK_UpArrow;
break; break;
case 0x50: case 0x50:
kCode = kVK_DownArrow; kCode = kVK_DownArrow;
break; break;
case 0x49: case 0x49:
kCode = kVK_PageUp; kCode = kVK_PageUp;
break; break;
case 0x51: case 0x51:
kCode = kVK_PageDown; kCode = kVK_PageDown;
break; break;
case 0x4D: case 0x4D:
kCode = kVK_RightArrow; kCode = kVK_RightArrow;
break; break;
default: default:
break; break;
} }
@ -352,22 +352,22 @@ void mf_input_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
{ {
kCode = keymap[code]; kCode = keymap[code];
} }
kbEvent = CGEventCreateKeyboardEvent(source, kCode, keyDown); kbEvent = CGEventCreateKeyboardEvent(source, kCode, keyDown);
CGEventPost(kCGHIDEventTap, kbEvent); CGEventPost(kCGHIDEventTap, kbEvent);
CFRelease(kbEvent); CFRelease(kbEvent);
CFRelease(source); CFRelease(source);
return TRUE;
} }
void mf_input_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) BOOL mf_input_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
{ {
return FALSE;
} }
void mf_input_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) BOOL mf_input_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
{ {
float width, height; float width, height;
CGWheelCount wheelCount = 2; CGWheelCount wheelCount = 2;
INT32 scroll_x = 0; INT32 scroll_x = 0;
INT32 scroll_y = 0; INT32 scroll_y = 0;
@ -386,35 +386,29 @@ void mf_input_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
else else
scroll_x = scroll; scroll_x = scroll;
CGEventSourceRef source = CGEventSourceCreate (kCGEventSourceStateHIDSystemState); CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
CGEventRef scroll = CGEventCreateScrollWheelEvent(source, CGEventRef scrollEvent = CGEventCreateScrollWheelEvent(source,
kCGScrollEventUnitLine, kCGScrollEventUnitLine,
wheelCount, wheelCount,
scroll_y, scroll_y,
scroll_x); scroll_x);
CGEventPost(kCGHIDEventTap, scroll); CGEventPost(kCGHIDEventTap, scrollEvent);
CFRelease(scrollEvent);
CFRelease(scroll);
CFRelease(source); CFRelease(source);
} }
else else
{ {
mfInfo* mfi;
mfInfo * mfi; CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
CGEventSourceRef source = CGEventSourceCreate (kCGEventSourceStateHIDSystemState);
CGEventType mouseType = kCGEventNull; CGEventType mouseType = kCGEventNull;
CGMouseButton mouseButton = kCGMouseButtonLeft; CGMouseButton mouseButton = kCGMouseButtonLeft;
mfi = mf_info_get_instance(); mfi = mf_info_get_instance();
//width and height of primary screen (even in multimon setups //width and height of primary screen (even in multimon setups
width = (float) mfi->servscreen_width; width = (float) mfi->servscreen_width;
height = (float) mfi->servscreen_height; height = (float) mfi->servscreen_height;
x += mfi->servscreen_xoffset; x += mfi->servscreen_xoffset;
y += mfi->servscreen_yoffset; y += mfi->servscreen_yoffset;
if (flags & PTR_FLAGS_MOVE) if (flags & PTR_FLAGS_MOVE)
{ {
if (mfi->mouse_down_left == TRUE) if (mfi->mouse_down_left == TRUE)
@ -433,21 +427,20 @@ void mf_input_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
{ {
mouseType = kCGEventMouseMoved; mouseType = kCGEventMouseMoved;
} }
CGEventRef move = CGEventCreateMouseEvent(source, CGEventRef move = CGEventCreateMouseEvent(source,
mouseType, mouseType,
CGPointMake(x, y), CGPointMake(x, y),
mouseButton // ignored for just movement mouseButton // ignored for just movement
); );
CGEventPost(kCGHIDEventTap, move); CGEventPost(kCGHIDEventTap, move);
CFRelease(move); CFRelease(move);
} }
if (flags & PTR_FLAGS_BUTTON1) if (flags & PTR_FLAGS_BUTTON1)
{ {
mouseButton = kCGMouseButtonLeft; mouseButton = kCGMouseButtonLeft;
if (flags & PTR_FLAGS_DOWN) if (flags & PTR_FLAGS_DOWN)
{ {
mouseType = kCGEventLeftMouseDown; mouseType = kCGEventLeftMouseDown;
@ -462,6 +455,7 @@ void mf_input_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
else if (flags & PTR_FLAGS_BUTTON2) else if (flags & PTR_FLAGS_BUTTON2)
{ {
mouseButton = kCGMouseButtonRight; mouseButton = kCGMouseButtonRight;
if (flags & PTR_FLAGS_DOWN) if (flags & PTR_FLAGS_DOWN)
{ {
mouseType = kCGEventRightMouseDown; mouseType = kCGEventRightMouseDown;
@ -472,11 +466,11 @@ void mf_input_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
mouseType = kCGEventRightMouseUp; mouseType = kCGEventRightMouseUp;
mfi->mouse_down_right = FALSE; mfi->mouse_down_right = FALSE;
} }
} }
else if (flags & PTR_FLAGS_BUTTON3) else if (flags & PTR_FLAGS_BUTTON3)
{ {
mouseButton = kCGMouseButtonCenter; mouseButton = kCGMouseButtonCenter;
if (flags & PTR_FLAGS_DOWN) if (flags & PTR_FLAGS_DOWN)
{ {
mouseType = kCGEventOtherMouseDown; mouseType = kCGEventOtherMouseDown;
@ -487,40 +481,43 @@ void mf_input_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
mouseType = kCGEventOtherMouseUp; mouseType = kCGEventOtherMouseUp;
mfi->mouse_down_other = FALSE; mfi->mouse_down_other = FALSE;
} }
} }
CGEventRef mouseEvent = CGEventCreateMouseEvent(source, CGEventRef mouseEvent = CGEventCreateMouseEvent(source,
mouseType, mouseType,
CGPointMake(x, y), CGPointMake(x, y),
mouseButton mouseButton
); );
CGEventPost(kCGHIDEventTap, mouseEvent); CGEventPost(kCGHIDEventTap, mouseEvent);
CFRelease(mouseEvent); CFRelease(mouseEvent);
CFRelease(source); CFRelease(source);
} }
return TRUE;
} }
void mf_input_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) BOOL mf_input_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
{ {
return FALSE;
} }
void mf_input_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT16 code) BOOL mf_input_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT16 code)
{ {
return FALSE;
} }
void mf_input_unicode_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT16 code) BOOL mf_input_unicode_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT16 code)
{ {
return FALSE;
} }
void mf_input_mouse_event_dummy(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) BOOL mf_input_mouse_event_dummy(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
{ {
return FALSE;
} }
void mf_input_extended_mouse_event_dummy(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) BOOL mf_input_extended_mouse_event_dummy(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
{ {
return FALSE;
} }

View File

@ -22,15 +22,15 @@
#include "mf_interface.h" #include "mf_interface.h"
void mf_input_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code); BOOL mf_input_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code);
void mf_input_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code); BOOL mf_input_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code);
void mf_input_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y); BOOL mf_input_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y);
void mf_input_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y); BOOL mf_input_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y);
//dummy versions //dummy versions
void mf_input_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT16 code); BOOL mf_input_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT16 code);
void mf_input_unicode_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT16 code); BOOL mf_input_unicode_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT16 code);
void mf_input_mouse_event_dummy(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y); BOOL mf_input_mouse_event_dummy(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y);
void mf_input_extended_mouse_event_dummy(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y); BOOL mf_input_extended_mouse_event_dummy(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y);
#endif /* FREERDP_SERVER_MAC_INPUT_H */ #endif /* FREERDP_SERVER_MAC_INPUT_H */

View File

@ -25,6 +25,7 @@
#include <freerdp/codec/rfx.h> #include <freerdp/codec/rfx.h>
#include <winpr/stream.h> #include <winpr/stream.h>
#include <freerdp/peer.h> #include <freerdp/peer.h>
#include <freerdp/codec/color.h>
#include <winpr/crt.h> #include <winpr/crt.h>
@ -33,6 +34,7 @@
#include "mf_input.h" #include "mf_input.h"
#include "mf_event.h" #include "mf_event.h"
#include "mf_rdpsnd.h" #include "mf_rdpsnd.h"
#include "mf_audin.h"
#include <mach/clock.h> #include <mach/clock.h>
#include <mach/mach.h> #include <mach/mach.h>
@ -44,22 +46,19 @@
#include "CoreVideo/CoreVideo.h" #include "CoreVideo/CoreVideo.h"
//refactor these //refactor these
int info_last_sec = 0; static int info_last_sec = 0;
int info_last_nsec = 0; static int info_last_nsec = 0;
dispatch_source_t info_timer; static dispatch_source_t info_timer;
dispatch_queue_t info_queue; static dispatch_queue_t info_queue;
mfEventQueue* info_event_queue; static mfEventQueue* info_event_queue;
static CGLContextObj glContext;
static CGContextRef bmp;
static CGImageRef img;
CGLContextObj glContext; static BOOL mf_peer_get_fds(freerdp_peer* client, void** rfds, int* rcount)
CGContextRef bmp;
CGImageRef img;
BOOL mf_peer_get_fds(freerdp_peer* client, void** rfds, int* rcount)
{ {
if (info_event_queue->pipe_fd[0] == -1) if (info_event_queue->pipe_fd[0] == -1)
return TRUE; return TRUE;
@ -69,33 +68,8 @@ BOOL mf_peer_get_fds(freerdp_peer* client, void** rfds, int* rcount)
return TRUE; return TRUE;
} }
BOOL mf_peer_check_fds(freerdp_peer* client)
{
mfPeerContext* context = (mfPeerContext*) client->context;
mfEvent* event;
if (context->activated == FALSE) static void mf_peer_rfx_update(freerdp_peer* client)
return TRUE;
event = mf_event_peek(info_event_queue);
if (event != NULL)
{
if (event->type == MF_EVENT_TYPE_REGION)
{
}
else if (event->type == MF_EVENT_TYPE_FRAME_TICK)
{
event = mf_event_pop(info_event_queue);
mf_peer_rfx_update(client);
mf_event_free(event);
}
}
return TRUE;
}
void mf_peer_rfx_update(freerdp_peer* client)
{ {
//check //check
mfInfo* mfi = mf_info_get_instance(); mfInfo* mfi = mf_info_get_instance();
@ -154,8 +128,34 @@ void mf_peer_rfx_update(freerdp_peer* client)
//clean up... maybe? //clean up... maybe?
} }
static BOOL mf_peer_check_fds(freerdp_peer* client)
{
mfPeerContext* context = (mfPeerContext*) client->context;
mfEvent* event;
if (context->activated == FALSE)
return TRUE;
event = mf_event_peek(info_event_queue);
if (event != NULL)
{
if (event->type == FREERDP_SERVER_MAC_EVENT_TYPE_REGION)
{
}
else if (event->type == FREERDP_SERVER_MAC_EVENT_TYPE_FRAME_TICK)
{
event = mf_event_pop(info_event_queue);
mf_peer_rfx_update(client);
mf_event_free(event);
}
}
return TRUE;
}
/* Called when we have a new peer connecting */ /* Called when we have a new peer connecting */
BOOL mf_peer_context_new(freerdp_peer* client, mfPeerContext* context) static BOOL mf_peer_context_new(freerdp_peer* client, mfPeerContext* context)
{ {
if (!(context->info = mf_info_get_instance())) if (!(context->info = mf_info_get_instance()))
return FALSE; return FALSE;
@ -166,7 +166,7 @@ BOOL mf_peer_context_new(freerdp_peer* client, mfPeerContext* context)
context->rfx_context->mode = RLGR3; context->rfx_context->mode = RLGR3;
context->rfx_context->width = client->settings->DesktopWidth; context->rfx_context->width = client->settings->DesktopWidth;
context->rfx_context->height = client->settings->DesktopHeight; context->rfx_context->height = client->settings->DesktopHeight;
rfx_context_set_pixel_format(context->rfx_context, RDP_PIXEL_FORMAT_BGRA32); rfx_context_set_pixel_format(context->rfx_context, PIXEL_FORMAT_BGRA32);
if (!(context->s = Stream_New(NULL, 0xFFFF))) if (!(context->s = Stream_New(NULL, 0xFFFF)))
goto fail_stream_new; goto fail_stream_new;
@ -189,7 +189,7 @@ fail_rfx_context:
} }
/* Called after a peer disconnects */ /* Called after a peer disconnects */
void mf_peer_context_free(freerdp_peer* client, mfPeerContext* context) static void mf_peer_context_free(freerdp_peer* client, mfPeerContext* context)
{ {
if (context) if (context)
{ {
@ -204,19 +204,19 @@ void mf_peer_context_free(freerdp_peer* client, mfPeerContext* context)
audin_server_context_free(context->audin); audin_server_context_free(context->audin);
#endif #endif
//#ifdef CHANNEL_RDPSND_SERVER #ifdef CHANNEL_RDPSND_SERVER
mf_peer_rdpsnd_stop(); mf_peer_rdpsnd_stop();
if (context->rdpsnd) if (context->rdpsnd)
rdpsnd_server_context_free(context->rdpsnd); rdpsnd_server_context_free(context->rdpsnd);
//#endif #endif
WTSCloseServer(context->vcm); WTSCloseServer(context->vcm);
} }
} }
/* Called when a new client connects */ /* Called when a new client connects */
BOOL mf_peer_init(freerdp_peer* client) static BOOL mf_peer_init(freerdp_peer* client)
{ {
client->ContextSize = sizeof(mfPeerContext); client->ContextSize = sizeof(mfPeerContext);
client->ContextNew = (psPeerContextNew) mf_peer_context_new; client->ContextNew = (psPeerContextNew) mf_peer_context_new;
@ -239,7 +239,7 @@ BOOL mf_peer_init(freerdp_peer* client)
dispatch_source_set_event_handler(info_timer, ^ dispatch_source_set_event_handler(info_timer, ^
{ {
//DEBUG_WARN( "dispatch\n"); //DEBUG_WARN( "dispatch\n");
mfEvent* event = mf_event_new(MF_EVENT_TYPE_FRAME_TICK); mfEvent* event = mf_event_new(FREERDP_SERVER_MAC_EVENT_TYPE_FRAME_TICK);
mf_event_push(info_event_queue, (mfEvent*) event); mf_event_push(info_event_queue, (mfEvent*) event);
} }
); );
@ -249,7 +249,7 @@ BOOL mf_peer_init(freerdp_peer* client)
return TRUE; return TRUE;
} }
BOOL mf_peer_post_connect(freerdp_peer* client) static BOOL mf_peer_post_connect(freerdp_peer* client)
{ {
mfPeerContext* context = (mfPeerContext*) client->context; mfPeerContext* context = (mfPeerContext*) client->context;
rdpSettings* settings = client->settings; rdpSettings* settings = client->settings;
@ -271,12 +271,14 @@ BOOL mf_peer_post_connect(freerdp_peer* client)
mfi->mouse_down_left = FALSE; mfi->mouse_down_left = FALSE;
mfi->mouse_down_right = FALSE; mfi->mouse_down_right = FALSE;
mfi->mouse_down_other = FALSE; mfi->mouse_down_other = FALSE;
#ifdef CHANNEL_RDPSND_SERVER
if (WTSVirtualChannelManagerIsChannelJoined(context->vcm, "rdpsnd")) if (WTSVirtualChannelManagerIsChannelJoined(context->vcm, "rdpsnd"))
{ {
mf_peer_rdpsnd_init(context); /* Audio Output */ mf_peer_rdpsnd_init(context); /* Audio Output */
} }
#endif
/* Dynamic Virtual Channels */ /* Dynamic Virtual Channels */
#ifdef CHANNEL_AUDIN_SERVER #ifdef CHANNEL_AUDIN_SERVER
mf_peer_audin_init(context); /* Audio Input */ mf_peer_audin_init(context); /* Audio Input */
@ -284,16 +286,18 @@ BOOL mf_peer_post_connect(freerdp_peer* client)
return TRUE; return TRUE;
} }
BOOL mf_peer_activate(freerdp_peer* client) static BOOL mf_peer_activate(freerdp_peer* client)
{ {
mfPeerContext* context = (mfPeerContext*) client->context; mfPeerContext* context = (mfPeerContext*) client->context;
rfx_context_reset(context->rfx_context); rfx_context_reset(context->rfx_context, client->settings->DesktopWidth,
client->settings->DesktopHeight);
context->activated = TRUE; context->activated = TRUE;
return TRUE; return TRUE;
} }
void mf_peer_synchronize_event(rdpInput* input, UINT32 flags) static BOOL mf_peer_synchronize_event(rdpInput* input, UINT32 flags)
{ {
return TRUE;
} }
void mf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) void mf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
@ -308,29 +312,19 @@ void mf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
} }
} }
void mf_peer_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) static BOOL mf_peer_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
{ {
}
static void mf_peer_suppress_output(rdpContext* context, BYTE allow,
RECTANGLE_16* area)
{
}
BOOL mf_peer_accepted(freerdp_listener* instance, freerdp_peer* client)
{
pthread_t th;
if (pthread_create(&th, 0, mf_peer_main_loop, client) == 0)
{
pthread_detach(th);
return TRUE;
}
return FALSE; return FALSE;
} }
void* mf_peer_main_loop(void* arg) static BOOL mf_peer_suppress_output(rdpContext* context, BYTE allow,
const RECTANGLE_16* area)
{
return FALSE;
}
static void* mf_peer_main_loop(void* arg)
{ {
int i; int i;
int fds; int fds;
@ -439,3 +433,16 @@ void* mf_peer_main_loop(void* arg)
freerdp_peer_free(client); freerdp_peer_free(client);
return NULL; return NULL;
} }
BOOL mf_peer_accepted(freerdp_listener* instance, freerdp_peer* client)
{
pthread_t th;
if (pthread_create(&th, 0, mf_peer_main_loop, client) == 0)
{
pthread_detach(th);
return TRUE;
}
return FALSE;
}

View File

@ -22,23 +22,6 @@
#include "mf_interface.h" #include "mf_interface.h"
BOOL mf_peer_get_fds(freerdp_peer* client, void** rfds, int* rcount);
BOOL mf_peer_check_fds(freerdp_peer* client);
void mf_peer_rfx_update(freerdp_peer* client);
BOOL mf_peer_context_new(freerdp_peer* client, mfPeerContext* context);
void mf_peer_context_free(freerdp_peer* client, mfPeerContext* context);
BOOL mf_peer_init(freerdp_peer* client);
BOOL mf_peer_post_connect(freerdp_peer* client);
BOOL mf_peer_activate(freerdp_peer* client);
void mf_peer_synchronize_event(rdpInput* input, UINT32 flags);
BOOL mf_peer_accepted(freerdp_listener* instance, freerdp_peer* client); BOOL mf_peer_accepted(freerdp_listener* instance, freerdp_peer* client);
void* mf_peer_main_loop(void* arg);
#endif /* FREERDP_SERVER_MAC_PEER_H */ #endif /* FREERDP_SERVER_MAC_PEER_H */

View File

@ -28,6 +28,7 @@
#include "mf_info.h" #include "mf_info.h"
#include "mf_rdpsnd.h" #include "mf_rdpsnd.h"
#include <winpr/sysinfo.h>
#include <freerdp/log.h> #include <freerdp/log.h>
#define TAG SERVER_TAG("mac") #define TAG SERVER_TAG("mac")
@ -45,7 +46,6 @@ static void mf_peer_rdpsnd_activated(RdpsndServerContext* context)
int i, j; int i, j;
BOOL formatAgreed = FALSE; BOOL formatAgreed = FALSE;
AUDIO_FORMAT* agreedFormat = NULL; AUDIO_FORMAT* agreedFormat = NULL;
//we should actually loop through the list of client formats here //we should actually loop through the list of client formats here
//and see if we can send the client something that it supports... //and see if we can send the client something that it supports...
WLog_DBG(TAG, "Client supports the following %d formats: ", context->num_client_formats); WLog_DBG(TAG, "Client supports the following %d formats: ", context->num_client_formats);
@ -65,11 +65,11 @@ static void mf_peer_rdpsnd_activated(RdpsndServerContext* context)
break; break;
} }
} }
if (formatAgreed == TRUE) if (formatAgreed == TRUE)
break; break;
} }
if (formatAgreed == FALSE) if (formatAgreed == FALSE)
{ {
WLog_DBG(TAG, "Could not agree on a audio format with the server"); WLog_DBG(TAG, "Could not agree on a audio format with the server");
@ -78,75 +78,66 @@ static void mf_peer_rdpsnd_activated(RdpsndServerContext* context)
context->SelectFormat(context, i); context->SelectFormat(context, i);
context->SetVolume(context, 0x7FFF, 0x7FFF); context->SetVolume(context, 0x7FFF, 0x7FFF);
switch (agreedFormat->wFormatTag) switch (agreedFormat->wFormatTag)
{ {
case WAVE_FORMAT_ALAW: case WAVE_FORMAT_ALAW:
recorderState.dataFormat.mFormatID = kAudioFormatDVIIntelIMA; recorderState.dataFormat.mFormatID = kAudioFormatDVIIntelIMA;
break; break;
case WAVE_FORMAT_PCM: case WAVE_FORMAT_PCM:
recorderState.dataFormat.mFormatID = kAudioFormatLinearPCM; recorderState.dataFormat.mFormatID = kAudioFormatLinearPCM;
break; break;
default: default:
recorderState.dataFormat.mFormatID = kAudioFormatLinearPCM; recorderState.dataFormat.mFormatID = kAudioFormatLinearPCM;
break; break;
} }
recorderState.dataFormat.mSampleRate = agreedFormat->nSamplesPerSec; recorderState.dataFormat.mSampleRate = agreedFormat->nSamplesPerSec;
recorderState.dataFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked;; recorderState.dataFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger |
kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked;;
recorderState.dataFormat.mBytesPerPacket = 4; recorderState.dataFormat.mBytesPerPacket = 4;
recorderState.dataFormat.mFramesPerPacket = 1; recorderState.dataFormat.mFramesPerPacket = 1;
recorderState.dataFormat.mBytesPerFrame = 4; recorderState.dataFormat.mBytesPerFrame = 4;
recorderState.dataFormat.mChannelsPerFrame = agreedFormat->nChannels; recorderState.dataFormat.mChannelsPerFrame = agreedFormat->nChannels;
recorderState.dataFormat.mBitsPerChannel = agreedFormat->wBitsPerSample; recorderState.dataFormat.mBitsPerChannel = agreedFormat->wBitsPerSample;
recorderState.snd_context = context; recorderState.snd_context = context;
status = AudioQueueNewInput(&recorderState.dataFormat, status = AudioQueueNewInput(&recorderState.dataFormat,
mf_peer_rdpsnd_input_callback, mf_peer_rdpsnd_input_callback,
&recorderState, &recorderState,
NULL, NULL,
kCFRunLoopCommonModes, kCFRunLoopCommonModes,
0, 0,
&recorderState.queue); &recorderState.queue);
if (status != noErr) if (status != noErr)
{ {
WLog_DBG(TAG, "Failed to create a new Audio Queue. Status code: %"PRId32"", status); WLog_DBG(TAG, "Failed to create a new Audio Queue. Status code: %"PRId32"", status);
} }
UInt32 dataFormatSize = sizeof (recorderState.dataFormat); UInt32 dataFormatSize = sizeof(recorderState.dataFormat);
AudioQueueGetProperty(recorderState.queue, AudioQueueGetProperty(recorderState.queue,
kAudioConverterCurrentInputStreamDescription, kAudioConverterCurrentInputStreamDescription,
&recorderState.dataFormat, &recorderState.dataFormat,
&dataFormatSize); &dataFormatSize);
mf_rdpsnd_derive_buffer_size(recorderState.queue, &recorderState.dataFormat, 0.05,
&recorderState.bufferByteSize);
mf_rdpsnd_derive_buffer_size(recorderState.queue, &recorderState.dataFormat, 0.05, &recorderState.bufferByteSize);
for (i = 0; i < SND_NUMBUFFERS; ++i) for (i = 0; i < SND_NUMBUFFERS; ++i)
{ {
AudioQueueAllocateBuffer(recorderState.queue, AudioQueueAllocateBuffer(recorderState.queue,
recorderState.bufferByteSize, recorderState.bufferByteSize,
&recorderState.buffers[i]); &recorderState.buffers[i]);
AudioQueueEnqueueBuffer(recorderState.queue, AudioQueueEnqueueBuffer(recorderState.queue,
recorderState.buffers[i], recorderState.buffers[i],
0, 0,
NULL); NULL);
} }
recorderState.currentPacket = 0; recorderState.currentPacket = 0;
recorderState.isRunning = true; recorderState.isRunning = true;
AudioQueueStart(recorderState.queue, NULL);
AudioQueueStart (recorderState.queue, NULL);
} }
BOOL mf_peer_rdpsnd_init(mfPeerContext* context) BOOL mf_peer_rdpsnd_init(mfPeerContext* context)
@ -154,19 +145,15 @@ BOOL mf_peer_rdpsnd_init(mfPeerContext* context)
context->rdpsnd = rdpsnd_server_context_new(context->vcm); context->rdpsnd = rdpsnd_server_context_new(context->vcm);
context->rdpsnd->rdpcontext = &context->_p; context->rdpsnd->rdpcontext = &context->_p;
context->rdpsnd->data = context; context->rdpsnd->data = context;
context->rdpsnd->server_formats = supported_audio_formats; context->rdpsnd->server_formats = supported_audio_formats;
context->rdpsnd->num_server_formats = sizeof(supported_audio_formats) / sizeof(supported_audio_formats[0]); context->rdpsnd->num_server_formats = sizeof(supported_audio_formats) / sizeof(
supported_audio_formats[0]);
context->rdpsnd->src_format.wFormatTag = 1; context->rdpsnd->src_format.wFormatTag = 1;
context->rdpsnd->src_format.nChannels = 2; context->rdpsnd->src_format.nChannels = 2;
context->rdpsnd->src_format.nSamplesPerSec = 44100; context->rdpsnd->src_format.nSamplesPerSec = 44100;
context->rdpsnd->src_format.wBitsPerSample = 16; context->rdpsnd->src_format.wBitsPerSample = 16;
context->rdpsnd->Activated = mf_peer_rdpsnd_activated; context->rdpsnd->Activated = mf_peer_rdpsnd_activated;
context->rdpsnd->Initialize(context->rdpsnd, TRUE); context->rdpsnd->Initialize(context->rdpsnd, TRUE);
return TRUE; return TRUE;
} }
@ -174,71 +161,66 @@ BOOL mf_peer_rdpsnd_stop()
{ {
recorderState.isRunning = false; recorderState.isRunning = false;
AudioQueueStop(recorderState.queue, true); AudioQueueStop(recorderState.queue, true);
return TRUE; return TRUE;
} }
void mf_peer_rdpsnd_input_callback (void *inUserData, void mf_peer_rdpsnd_input_callback(void* inUserData,
AudioQueueRef inAQ, AudioQueueRef inAQ,
AudioQueueBufferRef inBuffer, AudioQueueBufferRef inBuffer,
const AudioTimeStamp *inStartTime, const AudioTimeStamp* inStartTime,
UInt32 inNumberPacketDescriptions, UInt32 inNumberPacketDescriptions,
const AudioStreamPacketDescription *inPacketDescs) const AudioStreamPacketDescription* inPacketDescs)
{ {
OSStatus status; OSStatus status;
AQRecorderState * rState; AQRecorderState* rState;
rState = inUserData; rState = inUserData;
if (inNumberPacketDescriptions == 0 && rState->dataFormat.mBytesPerPacket != 0) if (inNumberPacketDescriptions == 0 && rState->dataFormat.mBytesPerPacket != 0)
{ {
inNumberPacketDescriptions = inBuffer->mAudioDataByteSize / rState->dataFormat.mBytesPerPacket; inNumberPacketDescriptions = inBuffer->mAudioDataByteSize / rState->dataFormat.mBytesPerPacket;
} }
if (rState->isRunning == 0) if (rState->isRunning == 0)
{ {
return ; return ;
} }
rState->snd_context->SendSamples(rState->snd_context, inBuffer->mAudioData, rState->snd_context->SendSamples(rState->snd_context, inBuffer->mAudioData,
inBuffer->mAudioDataByteSize/4, (UINT16)(GetTickCount() & 0xffff)); inBuffer->mAudioDataByteSize / 4, (UINT16)(GetTickCount() & 0xffff));
status = AudioQueueEnqueueBuffer( status = AudioQueueEnqueueBuffer(
rState->queue, rState->queue,
inBuffer, inBuffer,
0, 0,
NULL); NULL);
if (status != noErr) if (status != noErr)
{ {
WLog_DBG(TAG, "AudioQueueEnqueueBuffer() returned status = %"PRId32"", status); WLog_DBG(TAG, "AudioQueueEnqueueBuffer() returned status = %"PRId32"", status);
} }
} }
void mf_rdpsnd_derive_buffer_size (AudioQueueRef audioQueue, void mf_rdpsnd_derive_buffer_size(AudioQueueRef audioQueue,
AudioStreamBasicDescription *ASBDescription, AudioStreamBasicDescription* ASBDescription,
Float64 seconds, Float64 seconds,
UInt32 *outBufferSize) UInt32* outBufferSize)
{ {
static const int maxBufferSize = 0x50000; static const int maxBufferSize = 0x50000;
int maxPacketSize = ASBDescription->mBytesPerPacket; int maxPacketSize = ASBDescription->mBytesPerPacket;
if (maxPacketSize == 0) if (maxPacketSize == 0)
{ {
UInt32 maxVBRPacketSize = sizeof(maxPacketSize); UInt32 maxVBRPacketSize = sizeof(maxPacketSize);
AudioQueueGetProperty (audioQueue, AudioQueueGetProperty(audioQueue,
kAudioQueueProperty_MaximumOutputPacketSize, kAudioQueueProperty_MaximumOutputPacketSize,
// in Mac OS X v10.5, instead use // in Mac OS X v10.5, instead use
// kAudioConverterPropertyMaximumOutputPacketSize // kAudioConverterPropertyMaximumOutputPacketSize
&maxPacketSize, &maxPacketSize,
&maxVBRPacketSize &maxVBRPacketSize
); );
} }
Float64 numBytesForTime = Float64 numBytesForTime =
ASBDescription->mSampleRate * maxPacketSize * seconds; ASBDescription->mSampleRate * maxPacketSize * seconds;
*outBufferSize = (UInt32) (numBytesForTime < maxBufferSize ? numBytesForTime : maxBufferSize); *outBufferSize = (UInt32)(numBytesForTime < maxBufferSize ? numBytesForTime : maxBufferSize);
} }