Fixed mac server compilation.
authorArmin Novak <armin.novak@thincast.com>
Fri, 24 Nov 2017 11:46:01 +0000 (12:46 +0100)
committerArmin Novak <armin.novak@thincast.com>
Fri, 24 Nov 2017 12:21:43 +0000 (13:21 +0100)
server/CMakeLists.txt
server/Mac/mf_info.c
server/Mac/mf_input.c
server/Mac/mf_input.h
server/Mac/mf_peer.c
server/Mac/mf_peer.h
server/Mac/mf_rdpsnd.c

index 24f7bb1..65e5c51 100644 (file)
@@ -27,7 +27,7 @@ if(FREERDP_VENDOR)
 
        if(NOT WIN32)
                if(APPLE AND (NOT IOS))
-                       #add_subdirectory(Mac)
+                       add_subdirectory(Mac)
                endif()
        else()
                #add_subdirectory(Windows)
index 1325444..da7b44d 100644 (file)
@@ -28,6 +28,9 @@
 #include "mf_info.h"
 #include "mf_mountain_lion.h"
 
+#define MF_INFO_DEFAULT_FPS 30
+#define MF_INFO_MAXPEERS    32
+
 static mfInfo* mfInfoInstance = NULL;
 
 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();
                }
                
-               peerId = NULL;
+               peerId = 0;
 
                for(i=0; i<MF_INFO_MAXPEERS; ++i)
                {
index 0b02daf..bd1c2a0 100644 (file)
@@ -291,59 +291,59 @@ static const CGKeyCode keymap[256] =
        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;
        CGEventRef kbEvent;
        CGKeyCode kCode = 0xFF;
-       
+
        if (flags & KBD_FLAGS_RELEASE)
        {
                keyDown = FALSE;
        }
-       
+
        if (flags & KBD_FLAGS_EXTENDED)
        {
-               switch (code) {
+               switch (code)
+               {
                        //case 0x52: //insert
                        case 0x53:
                                kCode = kVK_ForwardDelete;
                                break;
-                               
+
                        case 0x4B:
                                kCode = kVK_LeftArrow;
                                break;
-                               
+
                        case 0x47:
                                kCode = kVK_Home;
                                break;
-                               
+
                        case 0x4F:
                                kCode = kVK_End;
                                break;
-                               
+
                        case 0x48:
                                kCode = kVK_UpArrow;
                                break;
-                               
+
                        case 0x50:
                                kCode = kVK_DownArrow;
                                break;
-                               
+
                        case 0x49:
                                kCode = kVK_PageUp;
                                break;
-                               
+
                        case 0x51:
                                kCode = kVK_PageDown;
                                break;
-                               
+
                        case 0x4D:
                                kCode = kVK_RightArrow;
                                break;
-                               
+
                        default:
                                break;
                }
@@ -352,22 +352,22 @@ void mf_input_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
        {
                kCode = keymap[code];
        }
-       
+
        kbEvent = CGEventCreateKeyboardEvent(source, kCode, keyDown);
        CGEventPost(kCGHIDEventTap, kbEvent);
        CFRelease(kbEvent);
        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;
-
        CGWheelCount wheelCount = 2;
        INT32 scroll_x = 0;
        INT32 scroll_y = 0;
@@ -386,35 +386,29 @@ void mf_input_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
                else
                        scroll_x = scroll;
 
-               CGEventSourceRef source = CGEventSourceCreate (kCGEventSourceStateHIDSystemState);
-               CGEventRef scroll = CGEventCreateScrollWheelEvent(source,
-                                                                 kCGScrollEventUnitLine,
-                                                                 wheelCount,
-                                                                 scroll_y,
-                                                                 scroll_x);
-               CGEventPost(kCGHIDEventTap, scroll);
-
-               CFRelease(scroll);
+               CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
+               CGEventRef scrollEvent = CGEventCreateScrollWheelEvent(source,
+                                        kCGScrollEventUnitLine,
+                                        wheelCount,
+                                        scroll_y,
+                                        scroll_x);
+               CGEventPost(kCGHIDEventTap, scrollEvent);
+               CFRelease(scrollEvent);
                CFRelease(source);
        }
        else
        {
-
-               mfInfo * mfi;
-               CGEventSourceRef source = CGEventSourceCreate (kCGEventSourceStateHIDSystemState);
+               mfInfo* mfi;
+               CGEventSourceRef source = CGEventSourceCreate(kCGEventSourceStateHIDSystemState);
                CGEventType mouseType = kCGEventNull;
                CGMouseButton mouseButton = kCGMouseButtonLeft;
-
-
                mfi = mf_info_get_instance();
-
                //width and height of primary screen (even in multimon setups
                width = (float) mfi->servscreen_width;
                height = (float) mfi->servscreen_height;
-               
                x += mfi->servscreen_xoffset;
                y += mfi->servscreen_yoffset;
-               
+
                if (flags & PTR_FLAGS_MOVE)
                {
                        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;
                        }
-                       
+
                        CGEventRef move = CGEventCreateMouseEvent(source,
-                                                                 mouseType,
-                                                                 CGPointMake(x, y),
-                                                                 mouseButton // ignored for just movement
-                                                                 );
-                       
+                                         mouseType,
+                                         CGPointMake(x, y),
+                                         mouseButton // ignored for just movement
+                                                                );
                        CGEventPost(kCGHIDEventTap, move);
-                       
                        CFRelease(move);
                }
-               
+
                if (flags & PTR_FLAGS_BUTTON1)
                {
                        mouseButton = kCGMouseButtonLeft;
+
                        if (flags & PTR_FLAGS_DOWN)
                        {
                                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)
                {
                        mouseButton = kCGMouseButtonRight;
+
                        if (flags & PTR_FLAGS_DOWN)
                        {
                                mouseType = kCGEventRightMouseDown;
@@ -472,11 +466,11 @@ void mf_input_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
                                mouseType = kCGEventRightMouseUp;
                                mfi->mouse_down_right = FALSE;
                        }
-                       
                }
                else if (flags & PTR_FLAGS_BUTTON3)
                {
                        mouseButton = kCGMouseButtonCenter;
+
                        if (flags & PTR_FLAGS_DOWN)
                        {
                                mouseType = kCGEventOtherMouseDown;
@@ -487,40 +481,43 @@ void mf_input_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
                                mouseType = kCGEventOtherMouseUp;
                                mfi->mouse_down_other = FALSE;
                        }
-                       
                }
-               
-               
+
                CGEventRef mouseEvent = CGEventCreateMouseEvent(source,
-                                                               mouseType,
-                                                               CGPointMake(x, y),
-                                                               mouseButton
-                                                               );
+                                       mouseType,
+                                       CGPointMake(x, y),
+                                       mouseButton
+                                                              );
                CGEventPost(kCGHIDEventTap, mouseEvent);
-               
                CFRelease(mouseEvent);
                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;
 }
index 8e8903c..336ac24 100644 (file)
 
 #include "mf_interface.h"
 
-void mf_input_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code);
-void mf_input_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code);
-void 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_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code);
+BOOL mf_input_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code);
+BOOL mf_input_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
-void mf_input_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT16 code);
-void 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);
-void mf_input_extended_mouse_event_dummy(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y);
+BOOL mf_input_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT16 code);
+BOOL mf_input_unicode_keyboard_event_dummy(rdpInput* input, UINT16 flags, UINT16 code);
+BOOL mf_input_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 */
\ No newline at end of file
+#endif /* FREERDP_SERVER_MAC_INPUT_H */
index bcc0914..feafe12 100644 (file)
@@ -25,6 +25,7 @@
 #include <freerdp/codec/rfx.h>
 #include <winpr/stream.h>
 #include <freerdp/peer.h>
+#include <freerdp/codec/color.h>
 
 #include <winpr/crt.h>
 
@@ -33,6 +34,7 @@
 #include "mf_input.h"
 #include "mf_event.h"
 #include "mf_rdpsnd.h"
+#include "mf_audin.h"
 
 #include <mach/clock.h>
 #include <mach/mach.h>
 #include "CoreVideo/CoreVideo.h"
 
 //refactor these
-int info_last_sec = 0;
-int info_last_nsec = 0;
+static int info_last_sec = 0;
+static int info_last_nsec = 0;
 
-dispatch_source_t info_timer;
-dispatch_queue_t info_queue;
+static dispatch_source_t info_timer;
+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;
-CGContextRef bmp;
-CGImageRef img;
-
-
-
-BOOL mf_peer_get_fds(freerdp_peer* client, void** rfds, int* rcount)
+static BOOL mf_peer_get_fds(freerdp_peer* client, void** rfds, int* rcount)
 {
        if (info_event_queue->pipe_fd[0] == -1)
                return TRUE;
@@ -69,33 +68,8 @@ BOOL mf_peer_get_fds(freerdp_peer* client, void** rfds, int* rcount)
        return TRUE;
 }
 
-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 == 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)
+static void mf_peer_rfx_update(freerdp_peer* client)
 {
        //check
        mfInfo* mfi = mf_info_get_instance();
@@ -154,8 +128,34 @@ void mf_peer_rfx_update(freerdp_peer* client)
        //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 */
-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()))
                return FALSE;
@@ -166,7 +166,7 @@ BOOL mf_peer_context_new(freerdp_peer* client, mfPeerContext* context)
        context->rfx_context->mode = RLGR3;
        context->rfx_context->width = client->settings->DesktopWidth;
        context->rfx_context->height = client->settings->DesktopHeight;
-       rfx_context_set_pixel_format(context->rfx_context, RDP_PIXEL_FORMAT_BGRA32);
+       rfx_context_set_pixel_format(context->rfx_context, PIXEL_FORMAT_BGRA32);
 
        if (!(context->s = Stream_New(NULL, 0xFFFF)))
                goto fail_stream_new;
@@ -189,7 +189,7 @@ fail_rfx_context:
 }
 
 /* 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)
        {
@@ -204,19 +204,19 @@ void mf_peer_context_free(freerdp_peer* client, mfPeerContext* context)
                        audin_server_context_free(context->audin);
 
 #endif
-               //#ifdef CHANNEL_RDPSND_SERVER
+#ifdef CHANNEL_RDPSND_SERVER
                mf_peer_rdpsnd_stop();
 
                if (context->rdpsnd)
                        rdpsnd_server_context_free(context->rdpsnd);
 
-               //#endif
+#endif
                WTSCloseServer(context->vcm);
        }
 }
 
 /* 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->ContextNew = (psPeerContextNew) mf_peer_context_new;
@@ -239,7 +239,7 @@ BOOL mf_peer_init(freerdp_peer* client)
                dispatch_source_set_event_handler(info_timer, ^
                {
                        //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);
                }
                                                 );
@@ -249,7 +249,7 @@ BOOL mf_peer_init(freerdp_peer* client)
        return TRUE;
 }
 
-BOOL mf_peer_post_connect(freerdp_peer* client)
+static BOOL mf_peer_post_connect(freerdp_peer* client)
 {
        mfPeerContext* context = (mfPeerContext*) client->context;
        rdpSettings* settings = client->settings;
@@ -271,12 +271,14 @@ BOOL mf_peer_post_connect(freerdp_peer* client)
        mfi->mouse_down_left = FALSE;
        mfi->mouse_down_right = FALSE;
        mfi->mouse_down_other = FALSE;
+#ifdef CHANNEL_RDPSND_SERVER
 
        if (WTSVirtualChannelManagerIsChannelJoined(context->vcm, "rdpsnd"))
        {
                mf_peer_rdpsnd_init(context); /* Audio Output */
        }
 
+#endif
        /* Dynamic Virtual Channels */
 #ifdef CHANNEL_AUDIN_SERVER
        mf_peer_audin_init(context); /* Audio Input */
@@ -284,16 +286,18 @@ BOOL mf_peer_post_connect(freerdp_peer* client)
        return TRUE;
 }
 
-BOOL mf_peer_activate(freerdp_peer* client)
+static BOOL mf_peer_activate(freerdp_peer* client)
 {
        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;
        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)
@@ -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 void mf_peer_suppress_output(rdpContext* context, BYTE allow,
-                                    RECTANGLE_16* area)
+static BOOL mf_peer_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
 {
+       return FALSE;
 }
 
-BOOL mf_peer_accepted(freerdp_listener* instance, freerdp_peer* client)
+static BOOL mf_peer_suppress_output(rdpContext* context, BYTE allow,
+                                    const RECTANGLE_16* area)
 {
-       pthread_t th;
-
-       if (pthread_create(&th, 0, mf_peer_main_loop, client) == 0)
-       {
-               pthread_detach(th);
-               return TRUE;
-       }
-
        return FALSE;
 }
 
-void* mf_peer_main_loop(void* arg)
+
+static void* mf_peer_main_loop(void* arg)
 {
        int i;
        int fds;
@@ -439,3 +433,16 @@ void* mf_peer_main_loop(void* arg)
        freerdp_peer_free(client);
        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;
+}
index 9b137db..3e14ccd 100644 (file)
 
 #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);
 
-void* mf_peer_main_loop(void* arg);
-
 #endif /* FREERDP_SERVER_MAC_PEER_H */
index 6ae987a..55900db 100644 (file)
@@ -28,6 +28,7 @@
 #include "mf_info.h"
 #include "mf_rdpsnd.h"
 
+#include <winpr/sysinfo.h>
 #include <freerdp/log.h>
 #define TAG SERVER_TAG("mac")
 
@@ -45,7 +46,6 @@ static void mf_peer_rdpsnd_activated(RdpsndServerContext* context)
        int i, j;
        BOOL formatAgreed = FALSE;
        AUDIO_FORMAT* agreedFormat = NULL;
-       
        //we should actually loop through the list of client formats here
        //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);
@@ -65,11 +65,11 @@ static void mf_peer_rdpsnd_activated(RdpsndServerContext* context)
                                break;
                        }
                }
+
                if (formatAgreed == TRUE)
                        break;
-               
        }
-       
+
        if (formatAgreed == FALSE)
        {
                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->SetVolume(context, 0x7FFF, 0x7FFF);
-       
+
        switch (agreedFormat->wFormatTag)
        {
                case WAVE_FORMAT_ALAW:
                        recorderState.dataFormat.mFormatID = kAudioFormatDVIIntelIMA;
                        break;
-                       
+
                case WAVE_FORMAT_PCM:
                        recorderState.dataFormat.mFormatID = kAudioFormatLinearPCM;
                        break;
-                       
+
                default:
                        recorderState.dataFormat.mFormatID = kAudioFormatLinearPCM;
                        break;
        }
-       
+
        recorderState.dataFormat.mSampleRate = agreedFormat->nSamplesPerSec;
-       recorderState.dataFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger | kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked;;
+       recorderState.dataFormat.mFormatFlags = kAudioFormatFlagIsSignedInteger |
+                                               kAudioFormatFlagsNativeEndian | kAudioFormatFlagIsPacked;;
        recorderState.dataFormat.mBytesPerPacket = 4;
        recorderState.dataFormat.mFramesPerPacket = 1;
        recorderState.dataFormat.mBytesPerFrame = 4;
        recorderState.dataFormat.mChannelsPerFrame = agreedFormat->nChannels;
        recorderState.dataFormat.mBitsPerChannel = agreedFormat->wBitsPerSample;
-       
-       
        recorderState.snd_context = context;
-       
        status = AudioQueueNewInput(&recorderState.dataFormat,
-                                   mf_peer_rdpsnd_input_callback,
-                                   &recorderState,
-                                   NULL,
-                                   kCFRunLoopCommonModes,
-                                   0,
-                                   &recorderState.queue);
-       
+                                   mf_peer_rdpsnd_input_callback,
+                                   &recorderState,
+                                   NULL,
+                                   kCFRunLoopCommonModes,
+                                   0,
+                                   &recorderState.queue);
+
        if (status != noErr)
        {
                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,
-                             kAudioConverterCurrentInputStreamDescription,
-                             &recorderState.dataFormat,
-                             &dataFormatSize);
-       
-       
-       mf_rdpsnd_derive_buffer_size(recorderState.queue, &recorderState.dataFormat, 0.05, &recorderState.bufferByteSize);
-       
-               
+                             kAudioConverterCurrentInputStreamDescription,
+                             &recorderState.dataFormat,
+                             &dataFormatSize);
+       mf_rdpsnd_derive_buffer_size(recorderState.queue, &recorderState.dataFormat, 0.05,
+                                    &recorderState.bufferByteSize);
+
        for (i = 0; i < SND_NUMBUFFERS; ++i)
        {
                AudioQueueAllocateBuffer(recorderState.queue,
-                                        recorderState.bufferByteSize,
-                                        &recorderState.buffers[i]);
-               
+                                        recorderState.bufferByteSize,
+                                        &recorderState.buffers[i]);
                AudioQueueEnqueueBuffer(recorderState.queue,
-                                       recorderState.buffers[i],
-                                       0,
-                                       NULL);
+                                       recorderState.buffers[i],
+                                       0,
+                                       NULL);
        }
-       
-       
+
        recorderState.currentPacket = 0;
        recorderState.isRunning = true;
-       
-       AudioQueueStart (recorderState.queue, NULL);
-       
+       AudioQueueStart(recorderState.queue, NULL);
 }
 
 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->rdpcontext = &context->_p;
        context->rdpsnd->data = context;
-       
        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.nChannels = 2;
        context->rdpsnd->src_format.nSamplesPerSec = 44100;
        context->rdpsnd->src_format.wBitsPerSample = 16;
-       
        context->rdpsnd->Activated = mf_peer_rdpsnd_activated;
-       
        context->rdpsnd->Initialize(context->rdpsnd, TRUE);
-       
        return TRUE;
 }
 
@@ -174,71 +161,66 @@ BOOL mf_peer_rdpsnd_stop()
 {
        recorderState.isRunning = false;
        AudioQueueStop(recorderState.queue, true);
-       
        return TRUE;
 }
 
-void mf_peer_rdpsnd_input_callback (void                                *inUserData,
-                                    AudioQueueRef                       inAQ,
-                                    AudioQueueBufferRef                 inBuffer,
-                                    const AudioTimeStamp                *inStartTime,
-                                    UInt32                              inNumberPacketDescriptions,
-                                    const AudioStreamPacketDescription  *inPacketDescs)
+void mf_peer_rdpsnd_input_callback(void*                                inUserData,
+                                   AudioQueueRef                       inAQ,
+                                   AudioQueueBufferRef                 inBuffer,
+                                   const AudioTimeStamp*                inStartTime,
+                                   UInt32                              inNumberPacketDescriptions,
+                                   const AudioStreamPacketDescription*  inPacketDescs)
 {
        OSStatus status;
-       AQRecorderState * rState;
+       AQRecorderState* rState;
        rState = inUserData;
-       
-       
+
        if (inNumberPacketDescriptions == 0 && rState->dataFormat.mBytesPerPacket != 0)
        {
                inNumberPacketDescriptions = inBuffer->mAudioDataByteSize / rState->dataFormat.mBytesPerPacket;
        }
-       
-       
+
        if (rState->isRunning == 0)
        {
                return ;
        }
-       
+
        rState->snd_context->SendSamples(rState->snd_context, inBuffer->mAudioData,
-                                                                       inBuffer->mAudioDataByteSize/4, (UINT16)(GetTickCount() & 0xffff));
-       
+                                        inBuffer->mAudioDataByteSize / 4, (UINT16)(GetTickCount() & 0xffff));
        status = AudioQueueEnqueueBuffer(
-                                        rState->queue,
-                                        inBuffer,
-                                        0,
-                                        NULL);
-       
+                    rState->queue,
+                    inBuffer,
+                    0,
+                    NULL);
+
        if (status != noErr)
        {
                WLog_DBG(TAG, "AudioQueueEnqueueBuffer() returned status = %"PRId32"", status);
        }
-       
 }
 
-void mf_rdpsnd_derive_buffer_size (AudioQueueRef                audioQueue,
-                                   AudioStreamBasicDescription  *ASBDescription,
-                                   Float64                      seconds,
-                                   UInt32                       *outBufferSize)
+void mf_rdpsnd_derive_buffer_size(AudioQueueRef                audioQueue,
+                                  AudioStreamBasicDescription*  ASBDescription,
+                                  Float64                      seconds,
+                                  UInt32*                       outBufferSize)
 {
        static const int maxBufferSize = 0x50000;
-       
        int maxPacketSize = ASBDescription->mBytesPerPacket;
+
        if (maxPacketSize == 0)
        {
                UInt32 maxVBRPacketSize = sizeof(maxPacketSize);
-               AudioQueueGetProperty (audioQueue,
-                                      kAudioQueueProperty_MaximumOutputPacketSize,
-                                      // in Mac OS X v10.5, instead use
-                                      //   kAudioConverterPropertyMaximumOutputPacketSize
-                                      &maxPacketSize,
-                                      &maxVBRPacketSize
-                                      );
+               AudioQueueGetProperty(audioQueue,
+                                     kAudioQueueProperty_MaximumOutputPacketSize,
+                                     // in Mac OS X v10.5, instead use
+                                     //   kAudioConverterPropertyMaximumOutputPacketSize
+                                     &maxPacketSize,
+                                     &maxVBRPacketSize
+                                    );
        }
-       
+
        Float64 numBytesForTime =
-       ASBDescription->mSampleRate * maxPacketSize * seconds;
-       *outBufferSize = (UInt32) (numBytesForTime < maxBufferSize ? numBytesForTime : maxBufferSize);
+           ASBDescription->mSampleRate * maxPacketSize * seconds;
+       *outBufferSize = (UInt32)(numBytesForTime < maxBufferSize ? numBytesForTime : maxBufferSize);
 }