Using wlog for server now.

This commit is contained in:
Armin Novak 2014-09-12 17:38:12 +02:00
parent 7913a57bc5
commit 5b5791c8d7
31 changed files with 1986 additions and 1958 deletions

View File

@ -25,6 +25,9 @@
#include "mf_audin.h" #include "mf_audin.h"
#include <freerdp/log.h>
#define TAG SERVER_TAG("mac")
static const AUDIO_FORMAT supported_audio_formats[] = static const AUDIO_FORMAT supported_audio_formats[] =
{ {
@ -34,19 +37,19 @@ static const AUDIO_FORMAT supported_audio_formats[] =
static void mf_peer_audin_opening(audin_server_context* context) static void mf_peer_audin_opening(audin_server_context* context)
{ {
DEBUG_WARN( "AUDIN opening.\n"); WLog_INFO(TAG, "AUDIN opening.");
/* Simply choose the first format supported by the client. */ /* Simply choose the first format supported by the client. */
context->SelectFormat(context, 0); context->SelectFormat(context, 0);
} }
static void mf_peer_audin_open_result(audin_server_context* context, UINT32 result) static void mf_peer_audin_open_result(audin_server_context* context, UINT32 result)
{ {
DEBUG_WARN( "AUDIN open result %d.\n", result); WLog_INFO(TAG, "AUDIN open result %d.", result);
} }
static void mf_peer_audin_receive_samples(audin_server_context* context, const void* buf, int nframes) static void mf_peer_audin_receive_samples(audin_server_context* context, const void* buf, int nframes)
{ {
DEBUG_WARN( "AUDIN receive %d frames.\n", nframes); WLog_INFO(TAG, "AUDIN receive %d frames.", nframes);
} }
void mf_peer_audin_init(mfPeerContext* context) void mf_peer_audin_init(mfPeerContext* context)

View File

@ -30,6 +30,9 @@
#include "mf_event.h" #include "mf_event.h"
#include <freerdp/log.h>
#define TAG SERVER_TAG("mac")
int mf_is_event_set(mfEventQueue* event_queue) int mf_is_event_set(mfEventQueue* event_queue)
{ {
fd_set rfds; fd_set rfds;
@ -51,7 +54,7 @@ void mf_signal_event(mfEventQueue* event_queue)
length = write(event_queue->pipe_fd[1], "sig", 4); length = write(event_queue->pipe_fd[1], "sig", 4);
if (length != 4) if (length != 4)
DEBUG_WARN( "mf_signal_event: error\n"); WLog_ERR(TAG, "mf_signal_event: error");
} }
void mf_set_event(mfEventQueue* event_queue) void mf_set_event(mfEventQueue* event_queue)
@ -61,7 +64,7 @@ void mf_set_event(mfEventQueue* event_queue)
length = write(event_queue->pipe_fd[1], "sig", 4); length = write(event_queue->pipe_fd[1], "sig", 4);
if (length != 4) if (length != 4)
DEBUG_WARN( "mf_set_event: error\n"); WLog_ERR(TAG, "mf_set_event: error");
} }
void mf_clear_events(mfEventQueue* event_queue) void mf_clear_events(mfEventQueue* event_queue)
@ -73,7 +76,7 @@ void mf_clear_events(mfEventQueue* event_queue)
length = read(event_queue->pipe_fd[0], &length, 4); length = read(event_queue->pipe_fd[0], &length, 4);
if (length != 4) if (length != 4)
DEBUG_WARN( "mf_clear_event: error\n"); WLog_ERR(TAG, "mf_clear_event: error");
} }
} }
@ -84,7 +87,7 @@ void mf_clear_event(mfEventQueue* event_queue)
length = read(event_queue->pipe_fd[0], &length, 4); length = read(event_queue->pipe_fd[0], &length, 4);
if (length != 4) if (length != 4)
DEBUG_WARN( "mf_clear_event: error\n"); WLog_ERR(TAG, "mf_clear_event: error");
} }
void mf_event_push(mfEventQueue* event_queue, mfEvent* event) void mf_event_push(mfEventQueue* event_queue, mfEvent* event)
@ -188,8 +191,8 @@ mfEventQueue* mf_event_queue_new()
event_queue->events = (mfEvent**) malloc(sizeof(mfEvent*) * event_queue->size); event_queue->events = (mfEvent**) malloc(sizeof(mfEvent*) * event_queue->size);
if (pipe(event_queue->pipe_fd) < 0) if (pipe(event_queue->pipe_fd) < 0)
DEBUG_WARN( "mf_event_queue_new: pipe failed\n"); WLog_ERR(TAG, "mf_event_queue_new: pipe failed");
pthread_mutex_init(&(event_queue->mutex), NULL); pthread_mutex_init(&(event_queue->mutex), NULL);
} }

View File

@ -1,309 +1,312 @@
/** /**
* FreeRDP: A Remote Desktop Protocol Client * FreeRDP: A Remote Desktop Protocol Client
* FreeRDP Mac OS X Server * FreeRDP Mac OS X Server
* *
* Copyright 2012 Corey Clayton <can.of.tuna@gmail.com> * Copyright 2012 Corey Clayton <can.of.tuna@gmail.com>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#include "mf_info.h" #include "mf_info.h"
#include "mf_mountain_lion.h" #include "mf_mountain_lion.h"
//#include "mf_update.h" //#include "mf_update.h"
static mfInfo* mfInfoInstance = NULL; #include <freerdp/log.h>
//static int _IDcount = 0; #define TAG SERVER_TAG("mac")
int mf_info_lock(mfInfo* mfi) static mfInfo* mfInfoInstance = NULL;
{ //static int _IDcount = 0;
int mf_info_lock(mfInfo* mfi)
{
int status = pthread_mutex_lock(&mfi->mutex); int status = pthread_mutex_lock(&mfi->mutex);
switch (status) { switch (status) {
case 0: case 0:
return TRUE; return TRUE;
break; break;
default: default:
DEBUG_MSG("mf_info_lock failed with %#X\n", status); WLog_ERR(TAG, "mf_info_lock failed with %#X", status);
return -1; return -1;
break; break;
} }
} }
int mf_info_try_lock(mfInfo* mfi, UINT32 ms) int mf_info_try_lock(mfInfo* mfi, UINT32 ms)
{ {
int status = pthread_mutex_trylock(&mfi->mutex); int status = pthread_mutex_trylock(&mfi->mutex);
switch (status) { switch (status) {
case 0: case 0:
return TRUE; return TRUE;
break; break;
case EBUSY: case EBUSY:
return FALSE; return FALSE;
break; break;
default: default:
DEBUG_MSG("mf_info_try_lock failed with %#X\n", status); WLog_ERR(TAG, "mf_info_try_lock failed with %#X", status);
return -1; return -1;
break; break;
} }
} }
int mf_info_unlock(mfInfo* mfi) int mf_info_unlock(mfInfo* mfi)
{ {
int status = pthread_mutex_unlock(&mfi->mutex); int status = pthread_mutex_unlock(&mfi->mutex);
switch (status) { switch (status) {
case 0: case 0:
return TRUE; return TRUE;
break; break;
default: default:
DEBUG_MSG("mf_info_unlock failed with %#X\n", status); WLog_ERR(TAG, "mf_info_unlock failed with %#X", status);
return -1; return -1;
break; break;
} }
} }
mfInfo* mf_info_init() mfInfo* mf_info_init()
{ {
mfInfo* mfi; mfInfo* mfi;
mfi = (mfInfo*) malloc(sizeof(mfInfo)); mfi = (mfInfo*) malloc(sizeof(mfInfo));
memset(mfi, 0, sizeof(mfInfo)); memset(mfi, 0, sizeof(mfInfo));
if (mfi != NULL) if (mfi != NULL)
{ {
/* HKEY hKey; /* HKEY hKey;
LONG status; LONG status;
DWORD dwType; DWORD dwType;
DWORD dwSize; DWORD dwSize;
DWORD dwValue; DWORD dwValue;
*/ */
int mutexInitStatus = pthread_mutex_init(&mfi->mutex, NULL); int mutexInitStatus = pthread_mutex_init(&mfi->mutex, NULL);
if (mutexInitStatus != 0) if (mutexInitStatus != 0)
{ {
DEBUG_MSG(_T("CreateMutex error: %#X\n"), mutexInitStatus); WLog_ERR(TAG, _T("CreateMutex error: %#X"), mutexInitStatus);
} }
mfi->peers = (freerdp_peer**) malloc(sizeof(freerdp_peer*) * MF_INFO_MAXPEERS); mfi->peers = (freerdp_peer**) malloc(sizeof(freerdp_peer*) * MF_INFO_MAXPEERS);
memset(mfi->peers, 0, sizeof(freerdp_peer*) * MF_INFO_MAXPEERS); memset(mfi->peers, 0, sizeof(freerdp_peer*) * MF_INFO_MAXPEERS);
//Set FPS //Set FPS
mfi->framesPerSecond = MF_INFO_DEFAULT_FPS; mfi->framesPerSecond = MF_INFO_DEFAULT_FPS;
/*status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), 0, KEY_READ | KEY_WOW64_64KEY, &hKey); /*status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
if (status == ERROR_SUCCESS) if (status == ERROR_SUCCESS)
{ {
if (RegQueryValueEx(hKey, _T("FramesPerSecond"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS) if (RegQueryValueEx(hKey, _T("FramesPerSecond"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS)
mfi->framesPerSecond = dwValue; mfi->framesPerSecond = dwValue;
} }
RegCloseKey(hKey);*/ RegCloseKey(hKey);*/
//Set input toggle //Set input toggle
mfi->input_disabled = FALSE; mfi->input_disabled = FALSE;
/*status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), 0, KEY_READ | KEY_WOW64_64KEY, &hKey); /*status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
if (status == ERROR_SUCCESS) if (status == ERROR_SUCCESS)
{ {
if (RegQueryValueEx(hKey, _T("DisableInput"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS) if (RegQueryValueEx(hKey, _T("DisableInput"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS)
{ {
if (dwValue != 0) if (dwValue != 0)
mfi->input_disabled = TRUE; mfi->input_disabled = TRUE;
} }
} }
RegCloseKey(hKey);*/ RegCloseKey(hKey);*/
} }
return mfi; return mfi;
} }
mfInfo* mf_info_get_instance() mfInfo* mf_info_get_instance()
{ {
if (mfInfoInstance == NULL) if (mfInfoInstance == NULL)
mfInfoInstance = mf_info_init(); mfInfoInstance = mf_info_init();
return mfInfoInstance; return mfInfoInstance;
} }
void mf_info_peer_register(mfInfo* mfi, mfPeerContext* context) void mf_info_peer_register(mfInfo* mfi, mfPeerContext* context)
{ {
if (mf_info_lock(mfi) > 0) if (mf_info_lock(mfi) > 0)
{ {
int i; int i;
int peerId; int peerId;
if (mfi->peerCount == MF_INFO_MAXPEERS) if (mfi->peerCount == MF_INFO_MAXPEERS)
{ {
DEBUG_MSG("TODO: socketClose on OS X\n"); WLog_ERR(TAG, "TODO: socketClose on OS X");
//context->socketClose = TRUE; //context->socketClose = TRUE;
mf_info_unlock(mfi); mf_info_unlock(mfi);
return; return;
} }
context->info = mfi; context->info = mfi;
//get the offset of the top left corner of selected screen //get the offset of the top left corner of selected screen
//EnumDisplayMonitors(NULL, NULL, mf_info_monEnumCB, 0); //EnumDisplayMonitors(NULL, NULL, mf_info_monEnumCB, 0);
//_IDcount = 0; //_IDcount = 0;
//initialize screen capture //initialize screen capture
if (mfi->peerCount == 0) if (mfi->peerCount == 0)
{ {
mf_mlion_display_info(&mfi->servscreen_width, &mfi->servscreen_height, &mfi->scale); mf_mlion_display_info(&mfi->servscreen_width, &mfi->servscreen_height, &mfi->scale);
mf_mlion_screen_updates_init(); mf_mlion_screen_updates_init();
mf_mlion_start_getting_screen_updates(); mf_mlion_start_getting_screen_updates();
} }
//look trhough the array of peers until an empty slot //look trhough the array of peers until an empty slot
peerId = NULL; peerId = NULL;
for(i=0; i<MF_INFO_MAXPEERS; ++i) for(i=0; i<MF_INFO_MAXPEERS; ++i)
{ {
//empty index will be our peer id //empty index will be our peer id
if (mfi->peers[i] == NULL) if (mfi->peers[i] == NULL)
{ {
peerId = i; peerId = i;
break; break;
} }
} }
mfi->peers[peerId] = ((rdpContext*) context)->peer; mfi->peers[peerId] = ((rdpContext*) context)->peer;
mfi->peers[peerId]->pId = peerId; mfi->peers[peerId]->pId = peerId;
mfi->peerCount++; mfi->peerCount++;
//printf("Registering Peer: id=%d #=%d\n", peerId, mfi->peerCount); //WLog_DBG(TAG, "Registering Peer: id=%d #=%d\n", peerId, mfi->peerCount);
mf_info_unlock(mfi); mf_info_unlock(mfi);
//mfreerdp_server_peer_callback_event(peerId, MF_SRV_CALLBACK_EVENT_CONNECT); //mfreerdp_server_peer_callback_event(peerId, MF_SRV_CALLBACK_EVENT_CONNECT);
} }
} }
void mf_info_peer_unregister(mfInfo* mfi, mfPeerContext* context) void mf_info_peer_unregister(mfInfo* mfi, mfPeerContext* context)
{ {
if (mf_info_lock(mfi) > 0) if (mf_info_lock(mfi) > 0)
{ {
int peerId; int peerId;
peerId = ((rdpContext*) context)->peer->pId; peerId = ((rdpContext*) context)->peer->pId;
mfi->peers[peerId] = NULL; mfi->peers[peerId] = NULL;
mfi->peerCount--; mfi->peerCount--;
//printf("Unregistering Peer: id=%d, #=%d\n", peerId, mfi->peerCount); //WLog_DBG(TAG, "Unregistering Peer: id=%d, #=%d\n", peerId, mfi->peerCount);
//screen capture cleanup //screen capture cleanup
if (mfi->peerCount == 0) if (mfi->peerCount == 0)
{ {
mf_mlion_stop_getting_screen_updates(); mf_mlion_stop_getting_screen_updates();
} }
mf_info_unlock(mfi); mf_info_unlock(mfi);
//mfreerdp_server_peer_callback_event(peerId, MF_SRV_CALLBACK_EVENT_DISCONNECT); //mfreerdp_server_peer_callback_event(peerId, MF_SRV_CALLBACK_EVENT_DISCONNECT);
} }
} }
BOOL mf_info_have_updates(mfInfo* mfi) BOOL mf_info_have_updates(mfInfo* mfi)
{ {
if(mfi->framesWaiting == 0) if(mfi->framesWaiting == 0)
return FALSE; return FALSE;
return TRUE; return TRUE;
} }
void mf_info_update_changes(mfInfo* mfi) void mf_info_update_changes(mfInfo* mfi)
{ {
/*#ifdef WITH_WIN8 /*#ifdef WITH_WIN8
mf_dxgi_nextFrame(mfi, mfi->framesPerSecond * 1000); mf_dxgi_nextFrame(mfi, mfi->framesPerSecond * 1000);
#else #else
GETCHANGESBUF* buf; GETCHANGESBUF* buf;
buf = (GETCHANGESBUF*) mfi->changeBuffer; buf = (GETCHANGESBUF*) mfi->changeBuffer;
mfi->nextUpdate = buf->buffer->counter; mfi->nextUpdate = buf->buffer->counter;
#endif*/ #endif*/
} }
void mf_info_find_invalid_region(mfInfo* mfi) void mf_info_find_invalid_region(mfInfo* mfi)
{ {
mf_mlion_get_dirty_region(&mfi->invalid); mf_mlion_get_dirty_region(&mfi->invalid);
} }
void mf_info_clear_invalid_region(mfInfo* mfi) void mf_info_clear_invalid_region(mfInfo* mfi)
{ {
mf_mlion_clear_dirty_region(); mf_mlion_clear_dirty_region();
mfi->invalid.height = 0; mfi->invalid.height = 0;
mfi->invalid.width = 0; mfi->invalid.width = 0;
} }
void mf_info_invalidate_full_screen(mfInfo* mfi) void mf_info_invalidate_full_screen(mfInfo* mfi)
{ {
mfi->invalid.x = 0; mfi->invalid.x = 0;
mfi->invalid.y = 0; mfi->invalid.y = 0;
mfi->invalid.height = mfi->servscreen_height; mfi->invalid.height = mfi->servscreen_height;
mfi->invalid.height = mfi->servscreen_width; mfi->invalid.height = mfi->servscreen_width;
} }
BOOL mf_info_have_invalid_region(mfInfo* mfi) BOOL mf_info_have_invalid_region(mfInfo* mfi)
{ {
if (mfi->invalid.width * mfi->invalid.height == 0) { if (mfi->invalid.width * mfi->invalid.height == 0) {
return FALSE; return FALSE;
} }
return TRUE; return TRUE;
} }
void mf_info_getScreenData(mfInfo* mfi, long* width, long* height, BYTE** pBits, int* pitch) void mf_info_getScreenData(mfInfo* mfi, long* width, long* height, BYTE** pBits, int* pitch)
{ {
*width = mfi->invalid.width / mfi->scale; *width = mfi->invalid.width / mfi->scale;
*height = mfi->invalid.height / mfi->scale; *height = mfi->invalid.height / mfi->scale;
*pitch = mfi->servscreen_width * mfi->scale * 4; *pitch = mfi->servscreen_width * mfi->scale * 4;
mf_mlion_get_pixelData(mfi->invalid.x / mfi->scale, mfi->invalid.y / mfi->scale, *width, *height, pBits); mf_mlion_get_pixelData(mfi->invalid.x / mfi->scale, mfi->invalid.y / mfi->scale, *width, *height, pBits);
*pBits = *pBits + (mfi->invalid.x * 4) + (*pitch * mfi->invalid.y); *pBits = *pBits + (mfi->invalid.x * 4) + (*pitch * mfi->invalid.y);
} }
/* /*
BOOL CALLBACK mf_info_monEnumCB(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) BOOL CALLBACK mf_info_monEnumCB(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
{ {
mfInfo * mfi; mfInfo * mfi;
mfi = mf_info_get_instance(); mfi = mf_info_get_instance();
if(_IDcount == mfi->screenID) if(_IDcount == mfi->screenID)
{ {
mfi->servscreen_xoffset = lprcMonitor->left; mfi->servscreen_xoffset = lprcMonitor->left;
mfi->servscreen_yoffset = lprcMonitor->top; mfi->servscreen_yoffset = lprcMonitor->top;
} }
_IDcount++; _IDcount++;
return TRUE; return TRUE;
} }
*/ */

View File

@ -29,7 +29,11 @@
#include "mf_input.h" #include "mf_input.h"
#include "mf_info.h" #include "mf_info.h"
static const CGKeyCode keymap[256] = { #include <freerdp/log.h>
#define TAG SERVER_TAG("mac")
static const CGKeyCode keymap[256] =
{
0xFF, //0x0 0xFF, //0x0
kVK_Escape, //0x1 kVK_Escape, //0x1
kVK_ANSI_1, //0x2 kVK_ANSI_1, //0x2
@ -356,8 +360,8 @@ void mf_input_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
/* /*
if (flags & KBD_FLAGS_EXTENDED) if (flags & KBD_FLAGS_EXTENDED)
DEBUG_WARN( "extended "); WLog_ERR(TAG, "extended ");
DEBUG_WARN( "keypress: down = %d, SCAN=%#0X, VK=%#0X\n", keyDown, code, keymap[code]); WLog_ERR(TAG, "keypress: down = %d, SCAN=%#0X, VK=%#0X", keyDown, code, keymap[code]);
*/ */
} }
@ -548,7 +552,7 @@ 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) void mf_input_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
{ {
DEBUG_WARN( "Unhandled mouse event!!!\n"); WLog_ERR(TAG, "Unhandled mouse event!!!");
/* /*
if ((flags & PTR_XFLAGS_BUTTON1) || (flags & PTR_XFLAGS_BUTTON2)) if ((flags & PTR_XFLAGS_BUTTON1) || (flags & PTR_XFLAGS_BUTTON2))
{ {

View File

@ -25,6 +25,9 @@
#include "mf_mountain_lion.h" #include "mf_mountain_lion.h"
#include <freerdp/log.h>
#define TAG SERVER_TAG("mac")
dispatch_semaphore_t region_sem; dispatch_semaphore_t region_sem;
dispatch_semaphore_t data_sem; dispatch_semaphore_t data_sem;
dispatch_queue_t screen_update_q; dispatch_queue_t screen_update_q;
@ -86,21 +89,20 @@ void (^streamHandler)(CGDisplayStreamFrameStatus, uint64_t, IOSurfaceRef, CGDisp
switch(status) switch(status)
{ {
case kCGDisplayStreamFrameStatusFrameIdle: case kCGDisplayStreamFrameStatusFrameIdle:
DEBUG_MSG("kCGDisplayStreamFrameStatusFrameIdle\n"); WLog_DBG(TAG, "kCGDisplayStreamFrameStatusFrameIdle");
break; break;
case kCGDisplayStreamFrameStatusStopped: case kCGDisplayStreamFrameStatusStopped:
//we dont need to clean up //we dont need to clean up
//printf("kCGDisplayStreamFrameStatusStopped\n"); //WLog_DBG(TAG, "kCGDisplayStreamFrameStatusStopped");
break; break;
case kCGDisplayStreamFrameStatusFrameBlank: case kCGDisplayStreamFrameStatusFrameBlank:
DEBUG_MSG("kCGDisplayStreamFrameStatusFrameBlank\n"); WLog_DBG(TAG, "kCGDisplayStreamFrameStatusFrameBlank");
break; break;
default: default:
DEBUG_MSG("Unhandled Frame Status!!!\n"); WLog_WARN(TAG, "Unhandled Frame Status!!!");
} }
} }
else if (lastUpdate == NULL) else if (lastUpdate == NULL)
@ -193,7 +195,7 @@ int mf_mlion_start_getting_screen_updates()
err = CGDisplayStreamStart(stream); err = CGDisplayStreamStart(stream);
if(err != kCGErrorSuccess) if(err != kCGErrorSuccess)
{ {
DEBUG_MSG("Failed to start displaystream!! err = %d\n", err); WLog_WARN(TAG, "Failed to start displaystream!! err = %d", err);
return 1; return 1;
} }
@ -207,13 +209,11 @@ int mf_mlion_stop_getting_screen_updates()
err = CGDisplayStreamStop(stream); err = CGDisplayStreamStop(stream);
if(err != kCGErrorSuccess) if(err != kCGErrorSuccess)
{ {
DEBUG_MSG("Failed to stop displaystream!! err = %d\n", err); WLog_WARN(TAG, "Failed to stop displaystream!! err = %d", err);
return 1; return 1;
} }
return 0; return 0;
return 0;
} }
int mf_mlion_get_dirty_region(RFX_RECT* invalid) int mf_mlion_get_dirty_region(RFX_RECT* invalid)

View File

@ -1,501 +1,498 @@
/** /**
* FreeRDP: A Remote Desktop Protocol Client * FreeRDP: A Remote Desktop Protocol Client
* FreeRDP Mac OS X Server * FreeRDP Mac OS X Server
* *
* Copyright 2012 Corey Clayton <can.of.tuna@gmail.com> * Copyright 2012 Corey Clayton <can.of.tuna@gmail.com>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
#include <freerdp/listener.h> #include <freerdp/listener.h>
#include <freerdp/codec/rfx.h> #include <freerdp/codec/rfx.h>
#include <winpr/stream.h> #include <winpr/stream.h>
#include <winpr/crt.h> #include <winpr/crt.h>
#include "mf_peer.h" #include "mf_peer.h"
#include "mf_info.h" #include "mf_info.h"
#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 <mach/clock.h> #include <mach/clock.h>
#include <mach/mach.h> #include <mach/mach.h>
#include <dispatch/dispatch.h> #include <dispatch/dispatch.h>
#include "OpenGL/OpenGL.h" #include "OpenGL/OpenGL.h"
#include "OpenGL/gl.h" #include "OpenGL/gl.h"
#include "CoreVideo/CoreVideo.h" #include "CoreVideo/CoreVideo.h"
//refactor these #include <freerdp/log.h>
int info_last_sec = 0; #define TAG SERVER_TAG("mac")
int info_last_nsec = 0;
//refactor these
dispatch_source_t info_timer; int info_last_sec = 0;
dispatch_queue_t info_queue; int info_last_nsec = 0;
mfEventQueue* info_event_queue; dispatch_source_t info_timer;
dispatch_queue_t info_queue;
CGLContextObj glContext; mfEventQueue* info_event_queue;
CGContextRef bmp;
CGImageRef img;
CGLContextObj glContext;
CGContextRef bmp;
CGImageRef img;
BOOL mf_peer_get_fds(freerdp_peer* client, void** rfds, int* rcount)
{
if (info_event_queue->pipe_fd[0] == -1)
return TRUE; BOOL mf_peer_get_fds(freerdp_peer* client, void** rfds, int* rcount)
{
if (info_event_queue->pipe_fd[0] == -1)
return TRUE;
rfds[*rcount] = (void *)(long) info_event_queue->pipe_fd[0]; rfds[*rcount] = (void *)(long) info_event_queue->pipe_fd[0];
(*rcount)++; (*rcount)++;
return TRUE; return TRUE;
} }
BOOL mf_peer_check_fds(freerdp_peer* client) BOOL mf_peer_check_fds(freerdp_peer* client)
{ {
mfPeerContext* context = (mfPeerContext*) client->context; mfPeerContext* context = (mfPeerContext*) client->context;
mfEvent* event; mfEvent* event;
if (context->activated == FALSE) if (context->activated == FALSE)
return TRUE; return TRUE;
event = mf_event_peek(info_event_queue); event = mf_event_peek(info_event_queue);
if (event != NULL) if (event != NULL)
{ {
if (event->type == MF_EVENT_TYPE_REGION) if (event->type == MF_EVENT_TYPE_REGION)
{ {
DEBUG_WARN( "unhandled event\n"); WLog_ERR(TAG, "unhandled event");
} }
else if (event->type == MF_EVENT_TYPE_FRAME_TICK) else if (event->type == MF_EVENT_TYPE_FRAME_TICK)
{ {
event = mf_event_pop(info_event_queue); event = mf_event_pop(info_event_queue);
mf_peer_rfx_update(client); mf_peer_rfx_update(client);
mf_event_free(event); mf_event_free(event);
} }
} }
return TRUE; return TRUE;
} }
void mf_peer_rfx_update(freerdp_peer* client) void mf_peer_rfx_update(freerdp_peer* client)
{ {
//check //check
mfInfo* mfi = mf_info_get_instance(); mfInfo* mfi = mf_info_get_instance();
mf_info_find_invalid_region(mfi); mf_info_find_invalid_region(mfi);
if (mf_info_have_invalid_region(mfi) == false) { if (mf_info_have_invalid_region(mfi) == false) {
return; return;
} }
long width; long width;
long height; long height;
int pitch; int pitch;
BYTE* dataBits = NULL; BYTE* dataBits = NULL;
mf_info_getScreenData(mfi, &width, &height, &dataBits, &pitch); mf_info_getScreenData(mfi, &width, &height, &dataBits, &pitch);
mf_info_clear_invalid_region(mfi); mf_info_clear_invalid_region(mfi);
//encode //encode
wStream* s; wStream* s;
RFX_RECT rect; RFX_RECT rect;
rdpUpdate* update; rdpUpdate* update;
mfPeerContext* mfp; mfPeerContext* mfp;
SURFACE_BITS_COMMAND* cmd; SURFACE_BITS_COMMAND* cmd;
update = client->update; update = client->update;
mfp = (mfPeerContext*) client->context; mfp = (mfPeerContext*) client->context;
cmd = &update->surface_bits_command; cmd = &update->surface_bits_command;
s = mfp->s; s = mfp->s;
Stream_Clear(s); Stream_Clear(s);
Stream_SetPosition(s, 0); Stream_SetPosition(s, 0);
UINT32 x = mfi->invalid.x / mfi->scale; UINT32 x = mfi->invalid.x / mfi->scale;
UINT32 y = mfi->invalid.y / mfi->scale; UINT32 y = mfi->invalid.y / mfi->scale;
rect.x = 0; rect.x = 0;
rect.y = 0; rect.y = 0;
rect.width = width; rect.width = width;
rect.height = height; rect.height = height;
mfp->rfx_context->width = mfi->servscreen_width; mfp->rfx_context->width = mfi->servscreen_width;
mfp->rfx_context->height = mfi->servscreen_height; mfp->rfx_context->height = mfi->servscreen_height;
rfx_compose_message(mfp->rfx_context, s, &rect, 1, rfx_compose_message(mfp->rfx_context, s, &rect, 1,
(BYTE*) dataBits, rect.width, rect.height, pitch); (BYTE*) dataBits, rect.width, rect.height, pitch);
cmd->destLeft = x; cmd->destLeft = x;
cmd->destTop = y; cmd->destTop = y;
cmd->destRight = x + rect.width; cmd->destRight = x + rect.width;
cmd->destBottom = y + rect.height; cmd->destBottom = y + rect.height;
cmd->bpp = 32; cmd->bpp = 32;
cmd->codecID = 3; cmd->codecID = 3;
cmd->width = rect.width; cmd->width = rect.width;
cmd->height = rect.height; cmd->height = rect.height;
cmd->bitmapDataLength = Stream_GetPosition(s); cmd->bitmapDataLength = Stream_GetPosition(s);
cmd->bitmapData = Stream_Buffer(s); cmd->bitmapData = Stream_Buffer(s);
//send //send
update->SurfaceBits(update->context, cmd); update->SurfaceBits(update->context, cmd);
//clean up... maybe? //clean up... maybe?
} }
/* Called when we have a new peer connecting */
int mf_peer_context_new(freerdp_peer* client, mfPeerContext* context)
{
context->info = mf_info_get_instance();
context->rfx_context = rfx_context_new(TRUE);
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_B8G8R8A8);
//context->nsc_context = nsc_context_new();
//nsc_context_set_pixel_format(context->nsc_context, RDP_PIXEL_FORMAT_B8G8R8A8);
context->s = Stream_New(NULL, 0xFFFF);
context->vcm = WTSOpenServerA((LPSTR) client->context);
mf_info_peer_register(context->info, context);
/* Called when we have a new peer connecting */ return 0;
int mf_peer_context_new(freerdp_peer* client, mfPeerContext* context) }
{
context->info = mf_info_get_instance(); /* Called after a peer disconnects */
context->rfx_context = rfx_context_new(TRUE); void mf_peer_context_free(freerdp_peer* client, mfPeerContext* context)
context->rfx_context->mode = RLGR3; {
context->rfx_context->width = client->settings->DesktopWidth; if (context)
context->rfx_context->height = client->settings->DesktopHeight; {
rfx_context_set_pixel_format(context->rfx_context, RDP_PIXEL_FORMAT_B8G8R8A8); mf_info_peer_unregister(context->info, context);
//context->nsc_context = nsc_context_new();
//nsc_context_set_pixel_format(context->nsc_context, RDP_PIXEL_FORMAT_B8G8R8A8);
context->s = Stream_New(NULL, 0xFFFF);
context->vcm = WTSOpenServerA((LPSTR) client->context);
mf_info_peer_register(context->info, context);
return 0;
}
/* Called after a peer disconnects */
void mf_peer_context_free(freerdp_peer* client, mfPeerContext* context)
{
if (context)
{
mf_info_peer_unregister(context->info, context);
dispatch_suspend(info_timer); dispatch_suspend(info_timer);
Stream_Free(context->s, TRUE); Stream_Free(context->s, TRUE);
rfx_context_free(context->rfx_context); rfx_context_free(context->rfx_context);
//nsc_context_free(context->nsc_context); //nsc_context_free(context->nsc_context);
#ifdef CHANNEL_AUDIN_SERVER #ifdef CHANNEL_AUDIN_SERVER
if (context->audin) if (context->audin)
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 */
void mf_peer_init(freerdp_peer* client) void 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;
client->ContextFree = (psPeerContextFree) mf_peer_context_free; client->ContextFree = (psPeerContextFree) mf_peer_context_free;
freerdp_peer_context_new(client); freerdp_peer_context_new(client);
info_event_queue = mf_event_queue_new(); info_event_queue = mf_event_queue_new();
info_queue = dispatch_queue_create("FreeRDP.update.timer", DISPATCH_QUEUE_SERIAL); info_queue = dispatch_queue_create("FreeRDP.update.timer", DISPATCH_QUEUE_SERIAL);
info_timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, info_queue); info_timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, info_queue);
if(info_timer) if(info_timer)
{ {
//DEBUG_WARN( "created timer\n"); //WLog_ERR(TAG, "created timer");
dispatch_source_set_timer(info_timer, DISPATCH_TIME_NOW, 42ull * NSEC_PER_MSEC, 100ull * NSEC_PER_MSEC); dispatch_source_set_timer(info_timer, DISPATCH_TIME_NOW, 42ull * NSEC_PER_MSEC, 100ull * NSEC_PER_MSEC);
dispatch_source_set_event_handler(info_timer, ^{ dispatch_source_set_event_handler(info_timer, ^{
//DEBUG_WARN( "dispatch\n"); //WLog_ERR(TAG, "dispatch");
mfEvent* event = mf_event_new(MF_EVENT_TYPE_FRAME_TICK); mfEvent* event = mf_event_new(MF_EVENT_TYPE_FRAME_TICK);
mf_event_push(info_event_queue, (mfEvent*) event);} mf_event_push(info_event_queue, (mfEvent*) event);}
); );
dispatch_resume(info_timer); dispatch_resume(info_timer);
} }
} }
BOOL mf_peer_post_connect(freerdp_peer* client) 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;
WLog_INFO(TAG, "Client %s post connect", client->hostname);
if (client->settings->AutoLogonEnabled)
{
WLog_INFO(TAG, " and wants to login automatically as %s\\%s",
client->settings->Domain ? client->settings->Domain : "",
client->settings->Username);
/* A real server may perform OS login here if NLA is not executed previously. */
}
mfInfo* mfi = mf_info_get_instance();
mfi->scale = 1;
DEBUG_WARN( "Client %s post connect\n", client->hostname); //mfi->servscreen_width = 2880 / mfi->scale;
//mfi->servscreen_height = 1800 / mfi->scale;
UINT32 bitsPerPixel = 32;
if (client->settings->AutoLogonEnabled) if ((settings->DesktopWidth != mfi->servscreen_width) || (settings->DesktopHeight != mfi->servscreen_height))
{ {
DEBUG_WARN( " and wants to login automatically as %s\\%s", WLog_INFO(TAG, "Client requested resolution %dx%d, but will resize to %dx%d",
client->settings->Domain ? client->settings->Domain : "", settings->DesktopWidth, settings->DesktopHeight, mfi->servscreen_width, mfi->servscreen_height);
client->settings->Username); }
settings->DesktopWidth = mfi->servscreen_width;
settings->DesktopHeight = mfi->servscreen_height;
settings->ColorDepth = bitsPerPixel;
client->update->DesktopResize(client->update->context);
mfi->mouse_down_left = FALSE;
mfi->mouse_down_right = FALSE;
mfi->mouse_down_other = FALSE;
if (WTSVirtualChannelManagerIsChannelJoined(context->vcm, "rdpsnd"))
{
mf_peer_rdpsnd_init(context); /* Audio Output */
}
/* Dynamic Virtual Channels */
#ifdef CHANNEL_AUDIN_SERVER
mf_peer_audin_init(context); /* Audio Input */
#endif
return TRUE;
}
BOOL mf_peer_activate(freerdp_peer* client)
{
mfPeerContext* context = (mfPeerContext*) client->context;
rfx_context_reset(context->rfx_context);
context->activated = TRUE;
return TRUE;
}
void mf_peer_synchronize_event(rdpInput* input, UINT32 flags)
{
WLog_WARN(TAG, "Client sent a synchronize event (flags:0x%08X)", flags);
}
void mf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
{
WLog_INFO(TAG, "Client sent a keyboard event (flags:0x%04X code:0x%04X)", flags, code);
UINT16 down = 0x4000;
//UINT16 up = 0x8000;
bool state_down = FALSE;
if (flags == down)
{
state_down = TRUE;
}
/*
CGEventRef event;
event = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)code, state_down);
CGEventPost(kCGHIDEventTap, event);
CFRelease(event);
*/
}
void mf_peer_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
{
WLog_ERR(TAG, "Client sent a unicode keyboard event (flags:0x%04X code:0x%04X)", flags, code);
}
/*void mf_peer_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
{
//WLog_ERR(TAG, "Client sent a mouse event (flags:0x%04X pos: %d,%d)", flags, x, y);
}
void mf_peer_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
{
//WLog_ERR(TAG, "Client sent an extended mouse event (flags:0x%04X pos: %d,%d)", flags, x, y);
}
*/
/*static void mf_peer_refresh_rect(rdpContext* context, BYTE count, RECTANGLE_16* areas)
{
BYTE i;
WLog_ERR(TAG, "Client requested to refresh:");
for (i = 0; i < count; i++)
{
WLog_ERR(TAG, " (%d, %d) (%d, %d)", areas[i].left, areas[i].top, areas[i].right, areas[i].bottom);
}
}*/
static void mf_peer_suppress_output(rdpContext* context, BYTE allow, RECTANGLE_16* area)
{
if (allow > 0)
{
WLog_WARN(TAG, "Client restore output (%d, %d) (%d, %d).", area->left, area->top, area->right, area->bottom);
}
else
{
WLog_WARN(TAG, "Client minimized and suppress output.");
}
}
void mf_peer_accepted(freerdp_listener* instance, freerdp_peer* client)
{
pthread_t th;
pthread_create(&th, 0, mf_peer_main_loop, client);
pthread_detach(th);
}
void* mf_peer_main_loop(void* arg)
{
int i;
int fds;
int max_fds;
int rcount;
void* rfds[32];
fd_set rfds_set;
mfPeerContext* context;
freerdp_peer* client = (freerdp_peer*) arg;
memset(rfds, 0, sizeof(rfds));
mf_peer_init(client);
/* Initialize the real server settings here */
client->settings->CertificateFile = _strdup("server.crt");
client->settings->PrivateKeyFile = _strdup("server.key");
client->settings->NlaSecurity = FALSE;
client->settings->RemoteFxCodec = TRUE;
client->settings->ColorDepth = 32;
client->settings->SuppressOutput = TRUE;
client->settings->RefreshRect = FALSE;
client->PostConnect = mf_peer_post_connect;
client->Activate = mf_peer_activate;
client->input->SynchronizeEvent = mf_peer_synchronize_event;
client->input->KeyboardEvent = mf_input_keyboard_event;//mf_peer_keyboard_event;
client->input->UnicodeKeyboardEvent = mf_peer_unicode_keyboard_event;
client->input->MouseEvent = mf_input_mouse_event;
client->input->ExtendedMouseEvent = mf_input_extended_mouse_event;
//client->update->RefreshRect = mf_peer_refresh_rect;
client->update->SuppressOutput = mf_peer_suppress_output;
client->Initialize(client);
context = (mfPeerContext*) client->context;
WLog_INFO(TAG, "We've got a client %s", client->local ? "(local)" : client->hostname);
while (1)
{
rcount = 0;
/* A real server may perform OS login here if NLA is not executed previously. */ if (client->GetFileDescriptor(client, rfds, &rcount) != TRUE)
} {
DEBUG_WARN( "\n"); WLog_ERR(TAG, "Failed to get FreeRDP file descriptor");
break;
mfInfo* mfi = mf_info_get_instance(); }
mfi->scale = 1; if (mf_peer_get_fds(client, rfds, &rcount) != TRUE)
{
//mfi->servscreen_width = 2880 / mfi->scale; WLog_ERR(TAG, "Failed to get mfreerdp file descriptor");
//mfi->servscreen_height = 1800 / mfi->scale; break;
UINT32 bitsPerPixel = 32; }
if ((settings->DesktopWidth != mfi->servscreen_width) || (settings->DesktopHeight != mfi->servscreen_height))
{
DEBUG_WARN( "Client requested resolution %dx%d, but will resize to %dx%d\n",
settings->DesktopWidth, settings->DesktopHeight, mfi->servscreen_width, mfi->servscreen_height);
}
settings->DesktopWidth = mfi->servscreen_width;
settings->DesktopHeight = mfi->servscreen_height;
settings->ColorDepth = bitsPerPixel;
client->update->DesktopResize(client->update->context);
mfi->mouse_down_left = FALSE;
mfi->mouse_down_right = FALSE;
mfi->mouse_down_other = FALSE;
if (WTSVirtualChannelManagerIsChannelJoined(context->vcm, "rdpsnd"))
{
mf_peer_rdpsnd_init(context); /* Audio Output */
}
/* Dynamic Virtual Channels */
#ifdef CHANNEL_AUDIN_SERVER
mf_peer_audin_init(context); /* Audio Input */
#endif
return TRUE;
}
BOOL mf_peer_activate(freerdp_peer* client)
{
mfPeerContext* context = (mfPeerContext*) client->context;
rfx_context_reset(context->rfx_context);
context->activated = TRUE;
return TRUE;
}
void mf_peer_synchronize_event(rdpInput* input, UINT32 flags)
{
DEBUG_WARN( "Client sent a synchronize event (flags:0x%08X)\n", flags);
}
void mf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
{
DEBUG_WARN( "Client sent a keyboard event (flags:0x%04X code:0x%04X)\n", flags, code);
UINT16 down = 0x4000;
//UINT16 up = 0x8000;
bool state_down = FALSE;
if (flags == down)
{
state_down = TRUE;
}
/*
CGEventRef event;
event = CGEventCreateKeyboardEvent(NULL, (CGKeyCode)code, state_down);
CGEventPost(kCGHIDEventTap, event);
CFRelease(event);
*/
}
void mf_peer_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
{
DEBUG_WARN( "Client sent a unicode keyboard event (flags:0x%04X code:0x%04X)\n", flags, code);
}
/*void mf_peer_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
{
//DEBUG_WARN( "Client sent a mouse event (flags:0x%04X pos: %d,%d)\n", flags, x, y);
}
void mf_peer_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
{
//DEBUG_WARN( "Client sent an extended mouse event (flags:0x%04X pos: %d,%d)\n", flags, x, y);
}
*/
/*static void mf_peer_refresh_rect(rdpContext* context, BYTE count, RECTANGLE_16* areas)
{
BYTE i;
DEBUG_WARN( "Client requested to refresh:\n");
for (i = 0; i < count; i++)
{
DEBUG_WARN( " (%d, %d) (%d, %d)\n", areas[i].left, areas[i].top, areas[i].right, areas[i].bottom);
}
}*/
static void mf_peer_suppress_output(rdpContext* context, BYTE allow, RECTANGLE_16* area)
{
if (allow > 0)
{
DEBUG_WARN( "Client restore output (%d, %d) (%d, %d).\n", area->left, area->top, area->right, area->bottom);
}
else
{
DEBUG_WARN( "Client minimized and suppress output.\n");
}
}
void mf_peer_accepted(freerdp_listener* instance, freerdp_peer* client)
{
pthread_t th;
pthread_create(&th, 0, mf_peer_main_loop, client);
pthread_detach(th);
}
void* mf_peer_main_loop(void* arg)
{
int i;
int fds;
int max_fds;
int rcount;
void* rfds[32];
fd_set rfds_set;
mfPeerContext* context;
freerdp_peer* client = (freerdp_peer*) arg;
memset(rfds, 0, sizeof(rfds));
mf_peer_init(client);
/* Initialize the real server settings here */
client->settings->CertificateFile = _strdup("server.crt");
client->settings->PrivateKeyFile = _strdup("server.key");
client->settings->NlaSecurity = FALSE;
client->settings->RemoteFxCodec = TRUE;
client->settings->ColorDepth = 32;
client->settings->SuppressOutput = TRUE;
client->settings->RefreshRect = FALSE;
client->PostConnect = mf_peer_post_connect;
client->Activate = mf_peer_activate;
client->input->SynchronizeEvent = mf_peer_synchronize_event;
client->input->KeyboardEvent = mf_input_keyboard_event;//mf_peer_keyboard_event;
client->input->UnicodeKeyboardEvent = mf_peer_unicode_keyboard_event;
client->input->MouseEvent = mf_input_mouse_event;
client->input->ExtendedMouseEvent = mf_input_extended_mouse_event;
//client->update->RefreshRect = mf_peer_refresh_rect;
client->update->SuppressOutput = mf_peer_suppress_output;
client->Initialize(client);
context = (mfPeerContext*) client->context;
DEBUG_WARN( "We've got a client %s\n", client->local ? "(local)" : client->hostname);
while (1)
{
rcount = 0;
if (client->GetFileDescriptor(client, rfds, &rcount) != TRUE) WTSVirtualChannelManagerGetFileDescriptor(context->vcm, rfds, &rcount);
{
DEBUG_WARN( "Failed to get FreeRDP file descriptor\n");
break;
}
if (mf_peer_get_fds(client, rfds, &rcount) != TRUE)
{
DEBUG_WARN( "Failed to get mfreerdp file descriptor\n");
break;
}
WTSVirtualChannelManagerGetFileDescriptor(context->vcm, rfds, &rcount); max_fds = 0;
FD_ZERO(&rfds_set);
max_fds = 0; for (i = 0; i < rcount; i++)
FD_ZERO(&rfds_set); {
fds = (int)(long)(rfds[i]);
for (i = 0; i < rcount; i++)
{
fds = (int)(long)(rfds[i]);
if (fds > max_fds) if (fds > max_fds)
max_fds = fds; max_fds = fds;
FD_SET(fds, &rfds_set); FD_SET(fds, &rfds_set);
} }
if (max_fds == 0) if (max_fds == 0)
break; break;
if (select(max_fds + 1, &rfds_set, NULL, NULL, NULL) == -1) if (select(max_fds + 1, &rfds_set, NULL, NULL, NULL) == -1)
{ {
/* these are not really errors */ /* these are not really errors */
if (!((errno == EAGAIN) || if (!((errno == EAGAIN) ||
(errno == EWOULDBLOCK) || (errno == EWOULDBLOCK) ||
(errno == EINPROGRESS) || (errno == EINPROGRESS) ||
(errno == EINTR))) /* signal occurred */ (errno == EINTR))) /* signal occurred */
{ {
DEBUG_WARN( "select failed\n"); WLog_ERR(TAG, "select failed");
break; break;
} }
} }
if (client->CheckFileDescriptor(client) != TRUE) if (client->CheckFileDescriptor(client) != TRUE)
{ {
DEBUG_WARN( "Failed to check freerdp file descriptor\n"); WLog_ERR(TAG, "Failed to check freerdp file descriptor");
break; break;
} }
if ((mf_peer_check_fds(client)) != TRUE) if ((mf_peer_check_fds(client)) != TRUE)
{ {
DEBUG_WARN( "Failed to check mfreerdp file descriptor\n"); WLog_ERR(TAG, "Failed to check mfreerdp file descriptor");
break; break;
} }
if (WTSVirtualChannelManagerCheckFileDescriptor(context->vcm) != TRUE) if (WTSVirtualChannelManagerCheckFileDescriptor(context->vcm) != TRUE)
{ {
break; break;
} }
} }
WLog_INFO(TAG, "Client %s disconnected.", client->local ? "(local)" : client->hostname);
client->Disconnect(client);
freerdp_peer_context_free(client);
freerdp_peer_free(client);
DEBUG_WARN( "Client %s disconnected.\n", client->local ? "(local)" : client->hostname); return NULL;
}
client->Disconnect(client);
freerdp_peer_context_free(client);
freerdp_peer_free(client);
return NULL;
}

View File

@ -21,14 +21,14 @@
#include "config.h" #include "config.h"
#endif #endif
#include <winpr/crt.h>
#include <winpr/sysinfo.h>
#include <freerdp/server/rdpsnd.h> #include <freerdp/server/rdpsnd.h>
#include "mf_info.h" #include "mf_info.h"
#include "mf_rdpsnd.h" #include "mf_rdpsnd.h"
#include <freerdp/log.h>
#define TAG SERVER_TAG("mac")
AQRecorderState recorderState; AQRecorderState recorderState;
static const AUDIO_FORMAT supported_audio_formats[] = static const AUDIO_FORMAT supported_audio_formats[] =
@ -46,9 +46,8 @@ static void mf_peer_rdpsnd_activated(RdpsndServerContext* context)
//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);
DEBUG_MSG("Client supports the following %d formats: \n", context->num_client_formats);
for (i = 0; i < context->num_client_formats; i++) for (i = 0; i < context->num_client_formats; i++)
{ {
/* TODO: improve the way we agree on a format */ /* TODO: improve the way we agree on a format */
@ -58,7 +57,7 @@ static void mf_peer_rdpsnd_activated(RdpsndServerContext* context)
(context->client_formats[i].nChannels == context->server_formats[j].nChannels) && (context->client_formats[i].nChannels == context->server_formats[j].nChannels) &&
(context->client_formats[i].nSamplesPerSec == context->server_formats[j].nSamplesPerSec)) (context->client_formats[i].nSamplesPerSec == context->server_formats[j].nSamplesPerSec))
{ {
DEBUG_MSG("agreed on format!\n"); WLog_DBG(TAG, "agreed on format!");
formatAgreed = TRUE; formatAgreed = TRUE;
agreedFormat = (AUDIO_FORMAT*)&context->server_formats[j]; agreedFormat = (AUDIO_FORMAT*)&context->server_formats[j];
break; break;
@ -71,10 +70,10 @@ static void mf_peer_rdpsnd_activated(RdpsndServerContext* context)
if (formatAgreed == FALSE) if (formatAgreed == FALSE)
{ {
DEBUG_MSG("Could not agree on a audio format with the server\n"); WLog_DBG(TAG, "Could not agree on a audio format with the server");
return; return;
} }
context->SelectFormat(context, i); context->SelectFormat(context, i);
context->SetVolume(context, 0x7FFF, 0x7FFF); context->SetVolume(context, 0x7FFF, 0x7FFF);
@ -114,7 +113,7 @@ static void mf_peer_rdpsnd_activated(RdpsndServerContext* context)
if (status != noErr) if (status != noErr)
{ {
DEBUG_MSG("Failed to create a new Audio Queue. Status code: %d\n", status); WLog_DBG(TAG, "Failed to create a new Audio Queue. Status code: %d", status);
} }
@ -211,7 +210,7 @@ void mf_peer_rdpsnd_input_callback (void *inUserD
if (status != noErr) if (status != noErr)
{ {
DEBUG_MSG("AudioQueueEnqueueBuffer() returned status = %d\n", status); WLog_DBG(TAG, "AudioQueueEnqueueBuffer() returned status = %d", status);
} }
} }

View File

@ -43,6 +43,9 @@
#include "mfreerdp.h" #include "mfreerdp.h"
#include "mf_peer.h" #include "mf_peer.h"
#include <freerdp/log.h>
#define TAG SERVER_TAG("mac")
static void mf_server_main_loop(freerdp_listener* instance) static void mf_server_main_loop(freerdp_listener* instance)
{ {
int i; int i;
@ -60,7 +63,7 @@ static void mf_server_main_loop(freerdp_listener* instance)
if (instance->GetFileDescriptor(instance, rfds, &rcount) != TRUE) if (instance->GetFileDescriptor(instance, rfds, &rcount) != TRUE)
{ {
DEBUG_WARN( "Failed to get FreeRDP file descriptor\n"); WLog_ERR(TAG, "Failed to get FreeRDP file descriptor");
break; break;
} }
@ -88,14 +91,14 @@ static void mf_server_main_loop(freerdp_listener* instance)
(errno == EINPROGRESS) || (errno == EINPROGRESS) ||
(errno == EINTR))) /* signal occurred */ (errno == EINTR))) /* signal occurred */
{ {
DEBUG_WARN( "select failed\n"); WLog_ERR(TAG, "select failed");
break; break;
} }
} }
if (instance->CheckFileDescriptor(instance) != TRUE) if (instance->CheckFileDescriptor(instance) != TRUE)
{ {
DEBUG_WARN( "Failed to check FreeRDP file descriptor\n"); WLog_ERR(TAG, "Failed to check FreeRDP file descriptor");
break; break;
} }
} }

View File

@ -21,12 +21,15 @@
#include "config.h" #include "config.h"
#endif #endif
#include <freerdp/utils/debug.h>
#include "sfreerdp.h" #include "sfreerdp.h"
#include "sf_audin.h" #include "sf_audin.h"
#include <freerdp/log.h>
#define TAG SERVER_TAG("sample")
static const AUDIO_FORMAT test_audio_formats[] = static const 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 },
@ -35,19 +38,19 @@ static const AUDIO_FORMAT test_audio_formats[] =
static void sf_peer_audin_opening(audin_server_context* context) static void sf_peer_audin_opening(audin_server_context* context)
{ {
DEBUG_MSG("AUDIN opening.\n"); WLog_DBG(TAG, "AUDIN opening.");
/* Simply choose the first format supported by the client. */ /* Simply choose the first format supported by the client. */
context->SelectFormat(context, 0); context->SelectFormat(context, 0);
} }
static void sf_peer_audin_open_result(audin_server_context* context, UINT32 result) static void sf_peer_audin_open_result(audin_server_context* context, UINT32 result)
{ {
DEBUG_MSG("AUDIN open result %d.\n", result); WLog_DBG(TAG, "AUDIN open result %d.", result);
} }
static void sf_peer_audin_receive_samples(audin_server_context* context, const void* buf, int nframes) static void sf_peer_audin_receive_samples(audin_server_context* context, const void* buf, int nframes)
{ {
DEBUG_MSG("AUDIN receive %d frames.\n", nframes); WLog_DBG(TAG, "AUDIN receive %d frames.", nframes);
} }
void sf_peer_audin_init(testPeerContext* context) void sf_peer_audin_init(testPeerContext* context)

View File

@ -22,10 +22,13 @@
#endif #endif
#include <freerdp/server/audin.h> #include <freerdp/server/audin.h>
#include <freerdp/utils/debug.h>
#include "sf_rdpsnd.h" #include "sf_rdpsnd.h"
#include <freerdp/log.h>
#define TAG SERVER_TAG("sample")
static const AUDIO_FORMAT test_audio_formats[] = static const 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 },
@ -34,7 +37,7 @@ static const AUDIO_FORMAT test_audio_formats[] =
static void sf_peer_rdpsnd_activated(RdpsndServerContext* context) static void sf_peer_rdpsnd_activated(RdpsndServerContext* context)
{ {
DEBUG_MSG("RDPSND Activated\n"); WLog_DBG(TAG, "RDPSND Activated");
} }
BOOL sf_peer_rdpsnd_init(testPeerContext* context) BOOL sf_peer_rdpsnd_init(testPeerContext* context)

View File

@ -33,7 +33,7 @@
#include <freerdp/channels/wtsvc.h> #include <freerdp/channels/wtsvc.h>
#include <freerdp/channels/channels.h> #include <freerdp/channels/channels.h>
#include <freerdp/utils/debug.h>
#include <freerdp/constants.h> #include <freerdp/constants.h>
#include <freerdp/utils/tcp.h> #include <freerdp/utils/tcp.h>
@ -45,6 +45,9 @@
#include "sfreerdp.h" #include "sfreerdp.h"
#include <freerdp/log.h>
#define TAG SERVER_TAG("sample")
#define SAMPLE_SERVER_USE_CLIENT_RESOLUTION 1 #define SAMPLE_SERVER_USE_CLIENT_RESOLUTION 1
#define SAMPLE_SERVER_DEFAULT_WIDTH 1024 #define SAMPLE_SERVER_DEFAULT_WIDTH 1024
#define SAMPLE_SERVER_DEFAULT_HEIGHT 768 #define SAMPLE_SERVER_DEFAULT_HEIGHT 768
@ -342,7 +345,7 @@ static BOOL test_sleep_tsdiff(UINT32 *old_sec, UINT32 *old_usec, UINT32 new_sec,
if ((sec < 0) || ((sec == 0) && (usec < 0))) if ((sec < 0) || ((sec == 0) && (usec < 0)))
{ {
DEBUG_MSG("Invalid time stamp detected.\n"); WLog_ERR(TAG, "Invalid time stamp detected.");
return FALSE; return FALSE;
} }
@ -451,8 +454,7 @@ static void* tf_debug_channel_thread_func(void* arg)
} }
Stream_SetPosition(s, BytesReturned); Stream_SetPosition(s, BytesReturned);
WLog_DBG(TAG, "got %lu bytes", BytesReturned);
DEBUG_MSG("got %lu bytes\n", BytesReturned);
} }
Stream_Free(s, TRUE); Stream_Free(s, TRUE);
@ -470,31 +472,28 @@ BOOL tf_peer_post_connect(freerdp_peer* client)
* The server may start sending graphics output and receiving keyboard/mouse input after this * The server may start sending graphics output and receiving keyboard/mouse input after this
* callback returns. * callback returns.
*/ */
WLog_DBG(TAG, "Client %s is activated (osMajorType %d osMinorType %d)", client->local ? "(local)" : client->hostname,
DEBUG_MSG("Client %s is activated (osMajorType %d osMinorType %d)", client->local ? "(local)" : client->hostname, client->settings->OsMajorType, client->settings->OsMinorType);
client->settings->OsMajorType, client->settings->OsMinorType);
if (client->settings->AutoLogonEnabled) if (client->settings->AutoLogonEnabled)
{ {
DEBUG_MSG(" and wants to login automatically as %s\\%s", WLog_DBG(TAG, " and wants to login automatically as %s\\%s",
client->settings->Domain ? client->settings->Domain : "", client->settings->Domain ? client->settings->Domain : "",
client->settings->Username); client->settings->Username);
/* A real server may perform OS login here if NLA is not executed previously. */ /* A real server may perform OS login here if NLA is not executed previously. */
} }
DEBUG_MSG("\n");
DEBUG_MSG("Client requested desktop: %dx%dx%d\n",
client->settings->DesktopWidth, client->settings->DesktopHeight, client->settings->ColorDepth);
WLog_DBG(TAG, "");
WLog_DBG(TAG, "Client requested desktop: %dx%dx%d",
client->settings->DesktopWidth, client->settings->DesktopHeight, client->settings->ColorDepth);
#if (SAMPLE_SERVER_USE_CLIENT_RESOLUTION == 1) #if (SAMPLE_SERVER_USE_CLIENT_RESOLUTION == 1)
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;
DEBUG_MSG("Using resolution requested by client.\n"); WLog_DBG(TAG, "Using resolution requested by client.");
#else #else
client->settings->DesktopWidth = context->rfx_context->width; client->settings->DesktopWidth = context->rfx_context->width;
client->settings->DesktopHeight = context->rfx_context->height; client->settings->DesktopHeight = context->rfx_context->height;
DEBUG_MSG("Resizing client to %dx%d\n", client->settings->DesktopWidth, client->settings->DesktopHeight); WLog_DBG(TAG, "Resizing client to %dx%d", client->settings->DesktopWidth, client->settings->DesktopHeight);
client->update->DesktopResize(client->update->context); client->update->DesktopResize(client->update->context);
#endif #endif
@ -507,8 +506,7 @@ BOOL tf_peer_post_connect(freerdp_peer* client)
if (context->debug_channel != NULL) if (context->debug_channel != NULL)
{ {
DEBUG_MSG("Open channel rdpdbg.\n"); WLog_DBG(TAG, "Open channel rdpdbg.");
context->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL); context->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
context->debug_channel_thread = CreateThread(NULL, 0, context->debug_channel_thread = CreateThread(NULL, 0,
@ -562,7 +560,7 @@ BOOL tf_peer_activate(freerdp_peer* client)
void tf_peer_synchronize_event(rdpInput* input, UINT32 flags) void tf_peer_synchronize_event(rdpInput* input, UINT32 flags)
{ {
DEBUG_MSG("Client sent a synchronize event (flags:0x%X)\n", flags); WLog_DBG(TAG, "Client sent a synchronize event (flags:0x%X)", flags);
} }
void tf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) void tf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
@ -570,8 +568,7 @@ void tf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
freerdp_peer* client = input->context->peer; freerdp_peer* client = input->context->peer;
rdpUpdate* update = client->update; rdpUpdate* update = client->update;
testPeerContext* context = (testPeerContext*) input->context; testPeerContext* context = (testPeerContext*) input->context;
WLog_DBG(TAG, "Client sent a keyboard event (flags:0x%X code:0x%X)", flags, code);
DEBUG_MSG("Client sent a keyboard event (flags:0x%X code:0x%X)\n", flags, code);
if ((flags & 0x4000) && code == 0x22) /* 'g' key */ if ((flags & 0x4000) && code == 0x22) /* 'g' key */
{ {
@ -623,30 +620,28 @@ void tf_peer_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
void tf_peer_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code) void tf_peer_unicode_keyboard_event(rdpInput* input, UINT16 flags, UINT16 code)
{ {
DEBUG_MSG("Client sent a unicode keyboard event (flags:0x%X code:0x%X)\n", flags, code); WLog_DBG(TAG, "Client sent a unicode keyboard event (flags:0x%X code:0x%X)", flags, code);
} }
void tf_peer_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) void tf_peer_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
{ {
//printf("Client sent a mouse event (flags:0x%X pos:%d,%d)\n", flags, x, y); //WLog_DBG(TAG, "Client sent a mouse event (flags:0x%X pos:%d,%d)", flags, x, y);
test_peer_draw_icon(input->context->peer, x + 10, y); test_peer_draw_icon(input->context->peer, x + 10, y);
} }
void tf_peer_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y) void tf_peer_extended_mouse_event(rdpInput* input, UINT16 flags, UINT16 x, UINT16 y)
{ {
//printf("Client sent an extended mouse event (flags:0x%X pos:%d,%d)\n", flags, x, y); //WLog_DBG(TAG, "Client sent an extended mouse event (flags:0x%X pos:%d,%d)", flags, x, y);
} }
static void tf_peer_refresh_rect(rdpContext* context, BYTE count, RECTANGLE_16* areas) static void tf_peer_refresh_rect(rdpContext* context, BYTE count, RECTANGLE_16* areas)
{ {
BYTE i; BYTE i;
WLog_DBG(TAG, "Client requested to refresh:");
DEBUG_MSG("Client requested to refresh:\n");
for (i = 0; i < count; i++) for (i = 0; i < count; i++)
{ {
DEBUG_MSG(" (%d, %d) (%d, %d)\n", areas[i].left, areas[i].top, areas[i].right, areas[i].bottom); WLog_DBG(TAG, " (%d, %d) (%d, %d)", areas[i].left, areas[i].top, areas[i].right, areas[i].bottom);
} }
} }
@ -654,11 +649,11 @@ static void tf_peer_suppress_output(rdpContext* context, BYTE allow, RECTANGLE_1
{ {
if (allow > 0) if (allow > 0)
{ {
DEBUG_MSG("Client restore output (%d, %d) (%d, %d).\n", area->left, area->top, area->right, area->bottom); WLog_DBG(TAG, "Client restore output (%d, %d) (%d, %d).", area->left, area->top, area->right, area->bottom);
} }
else else
{ {
DEBUG_MSG("Client minimized and suppress output.\n"); WLog_DBG(TAG, "Client minimized and suppress output.");
} }
} }
@ -700,8 +695,7 @@ static void* test_peer_mainloop(void* arg)
client->Initialize(client); client->Initialize(client);
context = (testPeerContext*) client->context; context = (testPeerContext*) client->context;
WLog_INFO(TAG, "We've got a client %s", client->local ? "(local)" : client->hostname);
DEBUG_MSG("We've got a client %s\n", client->local ? "(local)" : client->hostname);
while (1) while (1)
{ {
@ -710,7 +704,7 @@ static void* test_peer_mainloop(void* arg)
memset(rfds, 0, sizeof(rfds)); memset(rfds, 0, sizeof(rfds));
if (client->GetFileDescriptor(client, rfds, &rcount) != TRUE) if (client->GetFileDescriptor(client, rfds, &rcount) != TRUE)
{ {
DEBUG_MSG("Failed to get FreeRDP file descriptor\n"); WLog_ERR(TAG, "Failed to get FreeRDP file descriptor");
break; break;
} }
@ -744,7 +738,7 @@ static void* test_peer_mainloop(void* arg)
(wsa_error == WSAEINPROGRESS) || (wsa_error == WSAEINPROGRESS) ||
(wsa_error == WSAEINTR))) (wsa_error == WSAEINTR)))
{ {
DEBUG_MSG("select failed (WSAGetLastError: %d)\n", wsa_error); WLog_ERR(TAG, "select failed (WSAGetLastError: %d)", wsa_error);
break; break;
} }
#else #else
@ -754,7 +748,7 @@ static void* test_peer_mainloop(void* arg)
(errno == EINPROGRESS) || (errno == EINPROGRESS) ||
(errno == EINTR))) /* signal occurred */ (errno == EINTR))) /* signal occurred */
{ {
DEBUG_MSG("select failed (errno: %d)\n", errno); WLog_ERR(TAG, "select failed (errno: %d)", errno);
break; break;
} }
#endif #endif
@ -767,8 +761,7 @@ static void* test_peer_mainloop(void* arg)
break; break;
} }
DEBUG_MSG("Client %s disconnected.\n", client->local ? "(local)" : client->hostname); WLog_INFO(TAG, "Client %s disconnected.", client->local ? "(local)" : client->hostname);
client->Disconnect(client); client->Disconnect(client);
freerdp_peer_context_free(client); freerdp_peer_context_free(client);
freerdp_peer_free(client); freerdp_peer_free(client);
@ -800,7 +793,7 @@ static void test_server_mainloop(freerdp_listener* instance)
memset(rfds, 0, sizeof(rfds)); memset(rfds, 0, sizeof(rfds));
if (instance->GetFileDescriptor(instance, rfds, &rcount) != TRUE) if (instance->GetFileDescriptor(instance, rfds, &rcount) != TRUE)
{ {
DEBUG_MSG("Failed to get FreeRDP file descriptor\n"); WLog_ERR(TAG, "Failed to get FreeRDP file descriptor");
break; break;
} }
@ -828,14 +821,14 @@ static void test_server_mainloop(freerdp_listener* instance)
(errno == EINPROGRESS) || (errno == EINPROGRESS) ||
(errno == EINTR))) /* signal occurred */ (errno == EINTR))) /* signal occurred */
{ {
DEBUG_MSG("select failed\n"); WLog_ERR(TAG, "select failed");
break; break;
} }
} }
if (instance->CheckFileDescriptor(instance) != TRUE) if (instance->CheckFileDescriptor(instance) != TRUE)
{ {
DEBUG_MSG("Failed to check FreeRDP file descriptor\n"); WLog_ERR(TAG, "Failed to check FreeRDP file descriptor");
break; break;
} }
} }

View File

@ -32,14 +32,16 @@
#include "wfreerdp.h" #include "wfreerdp.h"
#include <freerdp/log.h>
#define TAG SERVER_TAG("windows")
int IDcount = 0; int IDcount = 0;
BOOL CALLBACK moncb(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) BOOL CALLBACK moncb(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
{ {
DEBUG_MSG("%d\t(%d, %d), (%d, %d)\n", WLog_DBG(TAG, "%d\t(%d, %d), (%d, %d)",
IDcount, lprcMonitor->left, lprcMonitor->top, IDcount, lprcMonitor->left, lprcMonitor->top,
lprcMonitor->right, lprcMonitor->bottom); lprcMonitor->right, lprcMonitor->bottom);
IDcount++; IDcount++;
return TRUE; return TRUE;
@ -67,10 +69,9 @@ int main(int argc, char* argv[])
int height; int height;
int bpp; int bpp;
int i; int i;
WLog_INFO(TAG, "Detecting screens...");
WLog_INFO(TAG, "ID\tResolution\t\tName (Interface)");
_tprintf(_T("Detecting screens...\n"));
_tprintf(_T("\nID\tResolution\t\tName (Interface)\n\n"));
for (i=0; ; i++) for (i=0; ; i++)
{ {
if (get_screen_info(i, name, &width, &height, &bpp) != 0) if (get_screen_info(i, name, &width, &height, &bpp) != 0)
@ -78,8 +79,8 @@ int main(int argc, char* argv[])
if ( (width * height * bpp) == 0 ) if ( (width * height * bpp) == 0 )
continue; continue;
_tprintf(_T("%d\t%dx%dx%d\t"), i, width, height, bpp); WLog_INFO(TAG, "%d\t%dx%dx%d\t", i, width, height, bpp);
_tprintf(_T("%s\n"), name); WLog_INFO(TAG, "%s", name);
} }
else else
{ {
@ -92,11 +93,10 @@ int main(int argc, char* argv[])
int vscreen_h; int vscreen_h;
vscreen_w = GetSystemMetrics(SM_CXVIRTUALSCREEN); vscreen_w = GetSystemMetrics(SM_CXVIRTUALSCREEN);
vscreen_h = GetSystemMetrics(SM_CYVIRTUALSCREEN); vscreen_h = GetSystemMetrics(SM_CYVIRTUALSCREEN);
WLog_INFO(TAG, "");
DEBUG_MSG("\n");
EnumDisplayMonitors(NULL, NULL, moncb, 0); EnumDisplayMonitors(NULL, NULL, moncb, 0);
IDcount = 0; IDcount = 0;
DEBUG_MSG("\nVirtual Screen = %dx%d\n", vscreen_w, vscreen_h); WLog_INFO(TAG, "Virtual Screen = %dx%d", vscreen_w, vscreen_h);
} }
return 0; return 0;
@ -108,7 +108,7 @@ int main(int argc, char* argv[])
index++; index++;
if (index == argc) if (index == argc)
{ {
DEBUG_MSG("missing screen id parameter\n"); WLog_INFO(TAG, "missing screen id parameter");
return 0; return 0;
} }
@ -130,10 +130,9 @@ int main(int argc, char* argv[])
int height; int height;
int bpp; int bpp;
int i; int i;
WLog_INFO(TAG, "screen id not provided. attempting to detect...");
_tprintf(_T("screen id not provided. attempting to detect...\n")); WLog_INFO(TAG, "Detecting screens...");
_tprintf(_T("Detecting screens...\n")); WLog_INFO(TAG, "ID\tResolution\t\tName (Interface)");
_tprintf(_T("\nID\tResolution\t\tName (Interface)\n\n"));
for (i=0; ; i++) for (i=0; ; i++)
{ {
@ -142,8 +141,8 @@ int main(int argc, char* argv[])
if ( (width * height * bpp) == 0 ) if ( (width * height * bpp) == 0 )
continue; continue;
_tprintf(_T("%d\t%dx%dx%d\t"), i, width, height, bpp); WLog_INFO(TAG, "%d\t%dx%dx%d\t", i, width, height, bpp);
_tprintf(_T("%s\n"), name); WLog_INFO(TAG, "%s", name);
set_screen_id(i); set_screen_id(i);
break; break;
} }
@ -154,14 +153,11 @@ int main(int argc, char* argv[])
} }
} }
DEBUG_MSG("Starting server\n"); WLog_INFO(TAG, "Starting server");
wfreerdp_server_start(server); wfreerdp_server_start(server);
WaitForSingleObject(server->thread, INFINITE); WaitForSingleObject(server->thread, INFINITE);
WLog_INFO(TAG, "Stopping server");
DEBUG_MSG("Stopping server\n");
wfreerdp_server_stop(server); wfreerdp_server_stop(server);
wfreerdp_server_free(server); wfreerdp_server_free(server);

View File

@ -14,6 +14,9 @@
#include <mmsystem.h> #include <mmsystem.h>
#include <dsound.h> #include <dsound.h>
#include <freerdp/log.h>
#define TAG SERVER_TAG("windows")
IDirectSoundCapture8* cap; IDirectSoundCapture8* cap;
IDirectSoundCaptureBuffer8* capBuf; IDirectSoundCaptureBuffer8* capBuf;
DSCBUFFERDESC dscbd; DSCBUFFERDESC dscbd;
@ -34,18 +37,16 @@ int wf_directsound_activate(RdpsndServerContext* context)
LPDIRECTSOUNDCAPTUREBUFFER pDSCB; LPDIRECTSOUNDCAPTUREBUFFER pDSCB;
wfi = wf_info_get_instance(); wfi = wf_info_get_instance();
WLog_DBG(TAG, "RDPSND (direct sound) Activated");
DEBUG_MSG("RDPSND (direct sound) Activated\n");
hr = DirectSoundCaptureCreate8(NULL, &cap, NULL); hr = DirectSoundCaptureCreate8(NULL, &cap, NULL);
if (FAILED(hr)) if (FAILED(hr))
{ {
_tprintf(_T("Failed to create sound capture device\n")); WLog_ERR(TAG, "Failed to create sound capture device");
return 1; return 1;
} }
_tprintf(_T("Created sound capture device\n"));
WLog_INFO(TAG, "Created sound capture device");
dscbd.dwSize = sizeof(DSCBUFFERDESC); dscbd.dwSize = sizeof(DSCBUFFERDESC);
dscbd.dwFlags = 0; dscbd.dwFlags = 0;
dscbd.dwBufferBytes = wfi->agreed_format->nAvgBytesPerSec; dscbd.dwBufferBytes = wfi->agreed_format->nAvgBytesPerSec;
@ -58,18 +59,17 @@ int wf_directsound_activate(RdpsndServerContext* context)
if (FAILED(hr)) if (FAILED(hr))
{ {
_tprintf(_T("Failed to create capture buffer\n")); WLog_ERR(TAG, "Failed to create capture buffer");
} }
_tprintf(_T("Created capture buffer"));
WLog_INFO(TAG, "Created capture buffer");
hr = pDSCB->lpVtbl->QueryInterface(pDSCB, &IID_IDirectSoundCaptureBuffer8, (LPVOID*)&capBuf); hr = pDSCB->lpVtbl->QueryInterface(pDSCB, &IID_IDirectSoundCaptureBuffer8, (LPVOID*)&capBuf);
if (FAILED(hr)) if (FAILED(hr))
{ {
_tprintf(_T("Failed to QI capture buffer\n")); WLog_ERR(TAG, "Failed to QI capture buffer");
} }
_tprintf(_T("Created IDirectSoundCaptureBuffer8\n")); WLog_INFO(TAG, "Created IDirectSoundCaptureBuffer8");
pDSCB->lpVtbl->Release(pDSCB); pDSCB->lpVtbl->Release(pDSCB);
lastPos = 0; lastPos = 0;
CreateThread(NULL, 0, wf_rdpsnd_directsound_thread, latestPeer, 0, NULL); CreateThread(NULL, 0, wf_rdpsnd_directsound_thread, latestPeer, 0, NULL);
@ -98,14 +98,13 @@ DWORD WINAPI wf_rdpsnd_directsound_thread(LPVOID lpParam)
context = (wfPeerContext*)lpParam; context = (wfPeerContext*)lpParam;
rate = 1000 / 24; rate = 1000 / 24;
WLog_INFO(TAG, "Trying to start capture");
_tprintf(_T("Trying to start capture\n"));
hr = capBuf->lpVtbl->Start(capBuf, DSCBSTART_LOOPING); hr = capBuf->lpVtbl->Start(capBuf, DSCBSTART_LOOPING);
if (FAILED(hr)) if (FAILED(hr))
{ {
_tprintf(_T("Failed to start capture\n")); WLog_ERR(TAG, "Failed to start capture");
} }
_tprintf(_T("Capture started\n")); WLog_INFO(TAG, "Capture started");
while (1) while (1)
{ {
@ -132,7 +131,7 @@ DWORD WINAPI wf_rdpsnd_directsound_thread(LPVOID lpParam)
hr = capBuf->lpVtbl->GetCurrentPosition(capBuf, NULL, &dwReadPos); hr = capBuf->lpVtbl->GetCurrentPosition(capBuf, NULL, &dwReadPos);
if (FAILED(hr)) if (FAILED(hr))
{ {
_tprintf(_T("Failed to get read pos\n")); WLog_ERR(TAG, "Failed to get read pos");
wf_rdpsnd_unlock(); wf_rdpsnd_unlock();
break; break;
} }
@ -140,9 +139,9 @@ DWORD WINAPI wf_rdpsnd_directsound_thread(LPVOID lpParam)
lLockSize = dwReadPos - lastPos;//dscbd.dwBufferBytes; lLockSize = dwReadPos - lastPos;//dscbd.dwBufferBytes;
if (lLockSize < 0) lLockSize += dscbd.dwBufferBytes; if (lLockSize < 0) lLockSize += dscbd.dwBufferBytes;
//printf("Last, read, lock = [%d, %d, %d]\n", lastPos, dwReadPos, lLockSize); //WLog_DBG(TAG, "Last, read, lock = [%d, %d, %d]\n", lastPos, dwReadPos, lLockSize);
if (lLockSize == 0) if (lLockSize == 0)
{ {
wf_rdpsnd_unlock(); wf_rdpsnd_unlock();
continue; continue;
@ -152,7 +151,7 @@ DWORD WINAPI wf_rdpsnd_directsound_thread(LPVOID lpParam)
hr = capBuf->lpVtbl->Lock(capBuf, lastPos, lLockSize, &pbCaptureData, &dwCaptureLength, &pbCaptureData2, &dwCaptureLength2, 0L); hr = capBuf->lpVtbl->Lock(capBuf, lastPos, lLockSize, &pbCaptureData, &dwCaptureLength, &pbCaptureData2, &dwCaptureLength2, 0L);
if (FAILED(hr)) if (FAILED(hr))
{ {
_tprintf(_T("Failed to lock sound capture buffer\n")); WLog_ERR(TAG, "Failed to lock sound capture buffer");
wf_rdpsnd_unlock(); wf_rdpsnd_unlock();
break; break;
} }
@ -169,7 +168,7 @@ DWORD WINAPI wf_rdpsnd_directsound_thread(LPVOID lpParam)
hr = capBuf->lpVtbl->Unlock(capBuf, pbCaptureData, dwCaptureLength, pbCaptureData2, dwCaptureLength2); hr = capBuf->lpVtbl->Unlock(capBuf, pbCaptureData, dwCaptureLength, pbCaptureData2, dwCaptureLength2);
if (FAILED(hr)) if (FAILED(hr))
{ {
_tprintf(_T("Failed to unlock sound capture buffer\n")); WLog_ERR(TAG, "Failed to unlock sound capture buffer");
wf_rdpsnd_unlock(); wf_rdpsnd_unlock();
return 0; return 0;
} }
@ -186,13 +185,14 @@ DWORD WINAPI wf_rdpsnd_directsound_thread(LPVOID lpParam)
} }
_tprintf(_T("Trying to stop sound capture\n")); WLog_INFO(TAG, "Trying to stop sound capture");
hr = capBuf->lpVtbl->Stop(capBuf); hr = capBuf->lpVtbl->Stop(capBuf);
if (FAILED(hr)) if (FAILED(hr))
{ {
_tprintf(_T("Failed to stop capture\n")); WLog_ERR(TAG, "Failed to stop capture");
} }
_tprintf(_T("Capture stopped\n"));
WLog_INFO(TAG, "Capture stopped");
capBuf->lpVtbl->Release(capBuf); capBuf->lpVtbl->Release(capBuf);
cap->lpVtbl->Release(cap); cap->lpVtbl->Release(cap);

View File

@ -33,6 +33,9 @@
#include <tchar.h> #include <tchar.h>
#include "wf_dxgi.h" #include "wf_dxgi.h"
#include <freerdp/log.h>
#define TAG SERVER_TAG("windows")
/* Driver types supported */ /* Driver types supported */
D3D_DRIVER_TYPE DriverTypes[] = D3D_DRIVER_TYPE DriverTypes[] =
{ {
@ -94,12 +97,12 @@ int wf_dxgi_createDevice(wfInfo* wfi)
if (SUCCEEDED(status)) if (SUCCEEDED(status))
break; break;
_tprintf(_T("D3D11CreateDevice returned [%d] for Driver Type %d\n"), status, DriverTypes[DriverTypeIndex]); WLog_INFO(TAG, "D3D11CreateDevice returned [%d] for Driver Type %d", status, DriverTypes[DriverTypeIndex]);
} }
if (FAILED(status)) if (FAILED(status))
{ {
_tprintf(_T("Failed to create device in InitializeDx\n")); WLog_ERR(TAG, "Failed to create device in InitializeDx");
return 1; return 1;
} }
@ -121,7 +124,7 @@ int wf_dxgi_getDuplication(wfInfo* wfi)
if (FAILED(status)) if (FAILED(status))
{ {
_tprintf(_T("Failed to get QI for DXGI Device\n")); WLog_ERR(TAG, "Failed to get QI for DXGI Device");
return 1; return 1;
} }
@ -131,7 +134,7 @@ int wf_dxgi_getDuplication(wfInfo* wfi)
if (FAILED(status)) if (FAILED(status))
{ {
_tprintf(_T("Failed to get parent DXGI Adapter\n")); WLog_ERR(TAG, "Failed to get parent DXGI Adapter");
return 1; return 1;
} }
@ -146,11 +149,11 @@ int wf_dxgi_getDuplication(wfInfo* wfi)
if (FAILED(status)) if (FAILED(status))
{ {
_tprintf(_T("Failed to get description\n")); WLog_ERR(TAG, "Failed to get description");
return 1; return 1;
} }
_tprintf(_T("Output %d: [%s] [%d]\n"), i, pDesc->DeviceName, pDesc->AttachedToDesktop); WLog_INFO(TAG, "Output %d: [%s] [%d]", i, pDesc->DeviceName, pDesc->AttachedToDesktop);
if (pDesc->AttachedToDesktop) if (pDesc->AttachedToDesktop)
dTop = i; dTop = i;
@ -167,7 +170,7 @@ int wf_dxgi_getDuplication(wfInfo* wfi)
if (FAILED(status)) if (FAILED(status))
{ {
_tprintf(_T("Failed to get output\n")); WLog_ERR(TAG, "Failed to get output");
return 1; return 1;
} }
@ -177,7 +180,7 @@ int wf_dxgi_getDuplication(wfInfo* wfi)
if (FAILED(status)) if (FAILED(status))
{ {
_tprintf(_T("Failed to get IDXGIOutput1\n")); WLog_ERR(TAG, "Failed to get IDXGIOutput1");
return 1; return 1;
} }
@ -189,11 +192,11 @@ int wf_dxgi_getDuplication(wfInfo* wfi)
{ {
if (status == DXGI_ERROR_NOT_CURRENTLY_AVAILABLE) if (status == DXGI_ERROR_NOT_CURRENTLY_AVAILABLE)
{ {
_tprintf(_T("There is already the maximum number of applications using the Desktop Duplication API running, please close one of those applications and then try again.\n")); WLog_ERR(TAG, "There is already the maximum number of applications using the Desktop Duplication API running, please close one of those applications and then try again."));
return 1; return 1;
} }
_tprintf(_T("Failed to get duplicate output. Status = %#X\n"), status); WLog_ERR(TAG, "Failed to get duplicate output. Status = %#X", status);
return 1; return 1;
} }
@ -265,8 +268,9 @@ int wf_dxgi_nextFrame(wfInfo* wfi, UINT timeout)
{ {
if (status == DXGI_ERROR_ACCESS_LOST) if (status == DXGI_ERROR_ACCESS_LOST)
{ {
_tprintf(_T("Failed to acquire next frame with status=%#X\n"), status); WLog_ERR(TAG, "Failed to acquire next frame with status=%#X", status);
_tprintf(_T("Trying to reinitialize due to ACCESS LOST...")); WLog_ERR(TAG, "Trying to reinitialize due to ACCESS LOST...");
if (gAcquiredDesktopImage) if (gAcquiredDesktopImage)
{ {
gAcquiredDesktopImage->lpVtbl->Release(gAcquiredDesktopImage); gAcquiredDesktopImage->lpVtbl->Release(gAcquiredDesktopImage);
@ -285,13 +289,12 @@ int wf_dxgi_nextFrame(wfInfo* wfi, UINT timeout)
} }
else else
{ {
_tprintf(_T("Failed to acquire next frame with status=%#X\n"), status); WLog_ERR(TAG, "Failed to acquire next frame with status=%#X", status);
status = gOutputDuplication->lpVtbl->ReleaseFrame(gOutputDuplication); status = gOutputDuplication->lpVtbl->ReleaseFrame(gOutputDuplication);
if (FAILED(status)) if (FAILED(status))
{ {
_tprintf(_T("Failed to release frame with status=%d\n"), status); WLog_ERR(TAG, "Failed to release frame with status=%d", status);
} }
return 1; return 1;
@ -315,7 +318,7 @@ int wf_dxgi_nextFrame(wfInfo* wfi, UINT timeout)
if (FAILED(status)) if (FAILED(status))
{ {
_tprintf(_T("Failed to release frame with status=%d\n"), status); WLog_ERR(TAG, "Failed to release frame with status=%d", status);
} }
} }
@ -352,7 +355,7 @@ int wf_dxgi_getPixelData(wfInfo* wfi, BYTE** data, int* pitch, RECT* invalid)
if (FAILED(status)) if (FAILED(status))
{ {
_tprintf(_T("Failed to create staging surface\n")); WLog_ERR(TAG, "Failed to create staging surface");
exit(1); exit(1);
return 1; return 1;
} }
@ -363,7 +366,7 @@ int wf_dxgi_getPixelData(wfInfo* wfi, BYTE** data, int* pitch, RECT* invalid)
if (FAILED(status)) if (FAILED(status))
{ {
_tprintf(_T("Failed to QI staging surface\n")); WLog_ERR(TAG, "Failed to QI staging surface");
exit(1); exit(1);
return 1; return 1;
} }
@ -372,7 +375,7 @@ int wf_dxgi_getPixelData(wfInfo* wfi, BYTE** data, int* pitch, RECT* invalid)
if (FAILED(status)) if (FAILED(status))
{ {
_tprintf(_T("Failed to map staging surface\n")); WLog_ERR(TAG, "Failed to map staging surface");
exit(1); exit(1);
return 1; return 1;
} }
@ -397,7 +400,7 @@ int wf_dxgi_releasePixelData(wfInfo* wfi)
if (FAILED(status)) if (FAILED(status))
{ {
_tprintf(_T("Failed to release frame\n")); WLog_ERR(TAG, "Failed to release frame");
return 1; return 1;
} }
@ -438,7 +441,7 @@ int wf_dxgi_getInvalidRegion(RECT* invalid)
if (!DataBuffer) if (!DataBuffer)
{ {
DataBufferSize = 0; DataBufferSize = 0;
_tprintf(_T("Failed to allocate memory for metadata\n")); WLog_ERR(TAG, "Failed to allocate memory for metadata");
exit(1); exit(1);
} }
@ -451,7 +454,7 @@ int wf_dxgi_getInvalidRegion(RECT* invalid)
if (FAILED(status)) if (FAILED(status))
{ {
_tprintf(_T("Failed to get frame move rects\n")); WLog_ERR(TAG, "Failed to get frame move rects");
return 1; return 1;
} }
@ -462,7 +465,7 @@ int wf_dxgi_getInvalidRegion(RECT* invalid)
if (FAILED(status)) if (FAILED(status))
{ {
_tprintf(_T("Failed to get frame dirty rects\n")); WLog_ERR(TAG, "Failed to get frame dirty rects");
return 1; return 1;
} }
dirty = BufSize / sizeof(RECT); dirty = BufSize / sizeof(RECT);

View File

@ -1,47 +1,50 @@
/** /**
* FreeRDP: A Remote Desktop Protocol Client * FreeRDP: A Remote Desktop Protocol Client
* FreeRDP Windows Server * FreeRDP Windows Server
* *
* Copyright 2012 Corey Clayton <can.of.tuna@gmail.com> * Copyright 2012 Corey Clayton <can.of.tuna@gmail.com>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdlib.h>
#include <winpr/tchar.h>
#include <winpr/windows.h>
#include "wf_info.h"
#include "wf_update.h"
#include "wf_mirage.h"
#include "wf_dxgi.h"
#include <freerdp/log.h>
#define TAG SERVER_TAG("windows")
static wfInfo* wfInfoInstance = NULL;
static int _IDcount = 0;
int wf_info_lock(wfInfo* wfi)
{
DWORD dRes;
#ifdef HAVE_CONFIG_H dRes = WaitForSingleObject(wfi->mutex, INFINITE);
#include "config.h"
#endif switch (dRes)
{
#include <stdlib.h>
#include <winpr/tchar.h>
#include <winpr/windows.h>
#include "wf_info.h"
#include "wf_update.h"
#include "wf_mirage.h"
#include "wf_dxgi.h"
static wfInfo* wfInfoInstance = NULL;
static int _IDcount = 0;
int wf_info_lock(wfInfo* wfi)
{
DWORD dRes;
dRes = WaitForSingleObject(wfi->mutex, INFINITE);
switch (dRes)
{
case WAIT_ABANDONED: case WAIT_ABANDONED:
case WAIT_OBJECT_0: case WAIT_OBJECT_0:
return TRUE; return TRUE;
@ -52,22 +55,22 @@ int wf_info_lock(wfInfo* wfi)
break; break;
case WAIT_FAILED: case WAIT_FAILED:
DEBUG_WARN("wf_info_lock failed with 0x%08X\n", GetLastError()); WLog_ERR(TAG, "wf_info_lock failed with 0x%08X", GetLastError());
return -1; return -1;
break; break;
} }
return -1;
}
int wf_info_try_lock(wfInfo* wfi, DWORD dwMilliseconds)
{
DWORD dRes;
return -1; dRes = WaitForSingleObject(wfi->mutex, dwMilliseconds);
}
switch (dRes)
int wf_info_try_lock(wfInfo* wfi, DWORD dwMilliseconds) {
{
DWORD dRes;
dRes = WaitForSingleObject(wfi->mutex, dwMilliseconds);
switch (dRes)
{
case WAIT_ABANDONED: case WAIT_ABANDONED:
case WAIT_OBJECT_0: case WAIT_OBJECT_0:
return TRUE; return TRUE;
@ -78,293 +81,291 @@ int wf_info_try_lock(wfInfo* wfi, DWORD dwMilliseconds)
break; break;
case WAIT_FAILED: case WAIT_FAILED:
DEBUG_WARN("wf_info_try_lock failed with 0x%08X\n", GetLastError()); WLog_ERR(TAG, "wf_info_try_lock failed with 0x%08X", GetLastError());
return -1; return -1;
break; break;
} }
return -1;
}
int wf_info_unlock(wfInfo* wfi)
{
if (ReleaseMutex(wfi->mutex) == 0)
{
WLog_ERR(TAG, "wf_info_unlock failed with 0x%08X", GetLastError());
return -1;
}
return TRUE;
}
wfInfo* wf_info_init()
{
wfInfo* wfi;
return -1; wfi = (wfInfo*) malloc(sizeof(wfInfo));
} ZeroMemory(wfi, sizeof(wfInfo));
int wf_info_unlock(wfInfo* wfi) if (wfi != NULL)
{ {
if (ReleaseMutex(wfi->mutex) == 0) HKEY hKey;
{ LONG status;
DEBUG_WARN("wf_info_unlock failed with 0x%08X\n", GetLastError()); DWORD dwType;
return -1; DWORD dwSize;
} DWORD dwValue;
return TRUE;
}
wfInfo* wf_info_init()
{
wfInfo* wfi;
wfi = (wfInfo*) malloc(sizeof(wfInfo));
ZeroMemory(wfi, sizeof(wfInfo));
if (wfi != NULL)
{
HKEY hKey;
LONG status;
DWORD dwType;
DWORD dwSize;
DWORD dwValue;
wfi->mutex = CreateMutex(NULL, FALSE, NULL);
wfi->mutex = CreateMutex(NULL, FALSE, NULL);
if (wfi->mutex == NULL) if (wfi->mutex == NULL)
{ {
_tprintf(_T("CreateMutex error: %d\n"), GetLastError()); WLog_ERR(TAG, "CreateMutex error: %d", GetLastError());
} }
wfi->updateSemaphore = CreateSemaphore(NULL, 0, 32, NULL);
wfi->updateSemaphore = CreateSemaphore(NULL, 0, 32, NULL); wfi->updateThread = CreateThread(NULL, 0, wf_update_thread, wfi, CREATE_SUSPENDED, NULL);
if (!wfi->updateThread)
{
WLog_ERR(TAG, "Failed to create update thread");
}
wfi->peers = (freerdp_peer**) malloc(sizeof(freerdp_peer*) * WF_INFO_MAXPEERS);
memset(wfi->peers, 0, sizeof(freerdp_peer*) * WF_INFO_MAXPEERS);
wfi->updateThread = CreateThread(NULL, 0, wf_update_thread, wfi, CREATE_SUSPENDED, NULL); //Set FPS
wfi->framesPerSecond = WF_INFO_DEFAULT_FPS;
if (!wfi->updateThread) status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
{ if (status == ERROR_SUCCESS)
_tprintf(_T("Failed to create update thread\n")); {
} if (RegQueryValueEx(hKey, _T("FramesPerSecond"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS)
wfi->peers = (freerdp_peer**) malloc(sizeof(freerdp_peer*) * WF_INFO_MAXPEERS);
memset(wfi->peers, 0, sizeof(freerdp_peer*) * WF_INFO_MAXPEERS);
//Set FPS
wfi->framesPerSecond = WF_INFO_DEFAULT_FPS;
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
if (status == ERROR_SUCCESS)
{
if (RegQueryValueEx(hKey, _T("FramesPerSecond"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS)
wfi->framesPerSecond = dwValue; wfi->framesPerSecond = dwValue;
} }
RegCloseKey(hKey); RegCloseKey(hKey);
//Set input toggle
wfi->input_disabled = FALSE;
//Set input toggle status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), 0, KEY_READ | KEY_WOW64_64KEY, &hKey);
wfi->input_disabled = FALSE; if (status == ERROR_SUCCESS)
{
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), 0, KEY_READ | KEY_WOW64_64KEY, &hKey); if (RegQueryValueEx(hKey, _T("DisableInput"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS)
if (status == ERROR_SUCCESS) {
{ if (dwValue != 0)
if (RegQueryValueEx(hKey, _T("DisableInput"), NULL, &dwType, (BYTE*) &dwValue, &dwSize) == ERROR_SUCCESS) wfi->input_disabled = TRUE;
{ }
if (dwValue != 0) }
wfi->input_disabled = TRUE; RegCloseKey(hKey);
} }
}
RegCloseKey(hKey); return wfi;
} }
return wfi; wfInfo* wf_info_get_instance()
} {
if (wfInfoInstance == NULL)
wfInfo* wf_info_get_instance() wfInfoInstance = wf_info_init();
{
if (wfInfoInstance == NULL) return wfInfoInstance;
wfInfoInstance = wf_info_init(); }
return wfInfoInstance; void wf_info_peer_register(wfInfo* wfi, wfPeerContext* context)
} {
if (wf_info_lock(wfi) > 0)
void wf_info_peer_register(wfInfo* wfi, wfPeerContext* context) {
{ int i;
if (wf_info_lock(wfi) > 0) int peerId;
{ if (wfi->peerCount == WF_INFO_MAXPEERS)
int i; {
int peerId; context->socketClose = TRUE;
if (wfi->peerCount == WF_INFO_MAXPEERS) wf_info_unlock(wfi);
{ return;
context->socketClose = TRUE; }
wf_info_unlock(wfi);
return; context->info = wfi;
} context->updateEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
context->info = wfi;
context->updateEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
//get the offset of the top left corner of selected screen
EnumDisplayMonitors(NULL, NULL, wf_info_monEnumCB, 0);
_IDcount = 0;
//get the offset of the top left corner of selected screen
EnumDisplayMonitors(NULL, NULL, wf_info_monEnumCB, 0);
_IDcount = 0;
#ifdef WITH_DXGI_1_2 #ifdef WITH_DXGI_1_2
if (wfi->peerCount == 0) if (wfi->peerCount == 0)
wf_dxgi_init(wfi); wf_dxgi_init(wfi);
#else #else
if (wf_mirror_driver_activate(wfi) == FALSE) if (wf_mirror_driver_activate(wfi) == FALSE)
{ {
context->socketClose = TRUE; context->socketClose = TRUE;
wf_info_unlock(wfi); wf_info_unlock(wfi);
return; return;
} }
#endif #endif
//look trhough the array of peers until an empty slot //look trhough the array of peers until an empty slot
for(i=0; i<WF_INFO_MAXPEERS; ++i) for(i=0; i<WF_INFO_MAXPEERS; ++i)
{ {
//empty index will be our peer id //empty index will be our peer id
if (wfi->peers[i] == NULL) if (wfi->peers[i] == NULL)
{ {
peerId = i; peerId = i;
break; break;
} }
} }
wfi->peers[peerId] = ((rdpContext*) context)->peer;
wfi->peers[peerId]->pId = peerId;
wfi->peerCount++;
WLog_INFO(TAG, "Registering Peer: id=%d #=%d", peerId, wfi->peerCount);
wf_info_unlock(wfi);
wfi->peers[peerId] = ((rdpContext*) context)->peer; wfreerdp_server_peer_callback_event(peerId, WF_SRV_CALLBACK_EVENT_CONNECT);
wfi->peers[peerId]->pId = peerId; }
wfi->peerCount++; }
DEBUG_WARN("Registering Peer: id=%d #=%d\n", peerId, wfi->peerCount);
void wf_info_peer_unregister(wfInfo* wfi, wfPeerContext* context)
{
if (wf_info_lock(wfi) > 0)
{
int peerId;
wf_info_unlock(wfi); peerId = ((rdpContext*) context)->peer->pId;
wfi->peers[peerId] = NULL;
wfi->peerCount--;
CloseHandle(context->updateEvent);
WLog_INFO(TAG, "Unregistering Peer: id=%d, #=%d", peerId, wfi->peerCount);
#ifdef WITH_DXGI_1_2
if (wfi->peerCount == 0)
wf_dxgi_cleanup(wfi);
#endif
wf_info_unlock(wfi);
wfreerdp_server_peer_callback_event(peerId, WF_SRV_CALLBACK_EVENT_CONNECT); wfreerdp_server_peer_callback_event(peerId, WF_SRV_CALLBACK_EVENT_DISCONNECT);
} }
} }
void wf_info_peer_unregister(wfInfo* wfi, wfPeerContext* context) BOOL wf_info_have_updates(wfInfo* wfi)
{ {
if (wf_info_lock(wfi) > 0)
{
int peerId;
peerId = ((rdpContext*) context)->peer->pId;
wfi->peers[peerId] = NULL;
wfi->peerCount--;
CloseHandle(context->updateEvent);
DEBUG_WARN("Unregistering Peer: id=%d, #=%d\n", peerId, wfi->peerCount);
#ifdef WITH_DXGI_1_2
if (wfi->peerCount == 0)
wf_dxgi_cleanup(wfi);
#endif
wf_info_unlock(wfi);
wfreerdp_server_peer_callback_event(peerId, WF_SRV_CALLBACK_EVENT_DISCONNECT);
}
}
BOOL wf_info_have_updates(wfInfo* wfi)
{
#ifdef WITH_DXGI_1_2 #ifdef WITH_DXGI_1_2
if(wfi->framesWaiting == 0) if(wfi->framesWaiting == 0)
return FALSE; return FALSE;
#else #else
if (wfi->nextUpdate == wfi->lastUpdate) if (wfi->nextUpdate == wfi->lastUpdate)
return FALSE; return FALSE;
#endif #endif
return TRUE; return TRUE;
} }
void wf_info_update_changes(wfInfo* wfi) void wf_info_update_changes(wfInfo* wfi)
{ {
#ifdef WITH_DXGI_1_2 #ifdef WITH_DXGI_1_2
wf_dxgi_nextFrame(wfi, wfi->framesPerSecond * 1000); wf_dxgi_nextFrame(wfi, wfi->framesPerSecond * 1000);
#else #else
GETCHANGESBUF* buf; GETCHANGESBUF* buf;
buf = (GETCHANGESBUF*) wfi->changeBuffer; buf = (GETCHANGESBUF*) wfi->changeBuffer;
wfi->nextUpdate = buf->buffer->counter; wfi->nextUpdate = buf->buffer->counter;
#endif #endif
} }
void wf_info_find_invalid_region(wfInfo* wfi) void wf_info_find_invalid_region(wfInfo* wfi)
{ {
#ifdef WITH_DXGI_1_2 #ifdef WITH_DXGI_1_2
wf_dxgi_getInvalidRegion(&wfi->invalid); wf_dxgi_getInvalidRegion(&wfi->invalid);
#else #else
int i; int i;
GETCHANGESBUF* buf; GETCHANGESBUF* buf;
buf = (GETCHANGESBUF*) wfi->changeBuffer; buf = (GETCHANGESBUF*) wfi->changeBuffer;
for (i = wfi->lastUpdate; i != wfi->nextUpdate; i = (i + 1) % MAXCHANGES_BUF) for (i = wfi->lastUpdate; i != wfi->nextUpdate; i = (i + 1) % MAXCHANGES_BUF)
{ {
LPRECT lpR = &buf->buffer->pointrect[i].rect; LPRECT lpR = &buf->buffer->pointrect[i].rect;
//need to make sure we only get updates from the selected screen //need to make sure we only get updates from the selected screen
if ( (lpR->left >= wfi->servscreen_xoffset) && if ( (lpR->left >= wfi->servscreen_xoffset) &&
(lpR->right <= (wfi->servscreen_xoffset + wfi->servscreen_width) ) && (lpR->right <= (wfi->servscreen_xoffset + wfi->servscreen_width) ) &&
(lpR->top >= wfi->servscreen_yoffset) && (lpR->top >= wfi->servscreen_yoffset) &&
(lpR->bottom <= (wfi->servscreen_yoffset + wfi->servscreen_height) ) ) (lpR->bottom <= (wfi->servscreen_yoffset + wfi->servscreen_height) ) )
{ {
UnionRect(&wfi->invalid, &wfi->invalid, lpR); UnionRect(&wfi->invalid, &wfi->invalid, lpR);
} }
else else
{ {
continue; continue;
} }
} }
#endif #endif
if (wfi->invalid.left < 0) if (wfi->invalid.left < 0)
wfi->invalid.left = 0; wfi->invalid.left = 0;
if (wfi->invalid.top < 0) if (wfi->invalid.top < 0)
wfi->invalid.top = 0; wfi->invalid.top = 0;
if (wfi->invalid.right >= wfi->servscreen_width) if (wfi->invalid.right >= wfi->servscreen_width)
wfi->invalid.right = wfi->servscreen_width - 1; wfi->invalid.right = wfi->servscreen_width - 1;
if (wfi->invalid.bottom >= wfi->servscreen_height) if (wfi->invalid.bottom >= wfi->servscreen_height)
wfi->invalid.bottom = wfi->servscreen_height - 1; wfi->invalid.bottom = wfi->servscreen_height - 1;
//printf("invalid region: (%d, %d), (%d, %d)\n", wfi->invalid.left, wfi->invalid.top, wfi->invalid.right, wfi->invalid.bottom); //WLog_DBG(TAG, "invalid region: (%d, %d), (%d, %d)", wfi->invalid.left, wfi->invalid.top, wfi->invalid.right, wfi->invalid.bottom);
} }
void wf_info_clear_invalid_region(wfInfo* wfi) void wf_info_clear_invalid_region(wfInfo* wfi)
{ {
wfi->lastUpdate = wfi->nextUpdate; wfi->lastUpdate = wfi->nextUpdate;
SetRectEmpty(&wfi->invalid); SetRectEmpty(&wfi->invalid);
} }
void wf_info_invalidate_full_screen(wfInfo* wfi) void wf_info_invalidate_full_screen(wfInfo* wfi)
{ {
SetRect(&wfi->invalid, 0, 0, wfi->servscreen_width, wfi->servscreen_height); SetRect(&wfi->invalid, 0, 0, wfi->servscreen_width, wfi->servscreen_height);
} }
BOOL wf_info_have_invalid_region(wfInfo* wfi) BOOL wf_info_have_invalid_region(wfInfo* wfi)
{ {
return IsRectEmpty(&wfi->invalid); return IsRectEmpty(&wfi->invalid);
} }
void wf_info_getScreenData(wfInfo* wfi, long* width, long* height, BYTE** pBits, int* pitch) void wf_info_getScreenData(wfInfo* wfi, long* width, long* height, BYTE** pBits, int* pitch)
{ {
*width = (wfi->invalid.right - wfi->invalid.left); *width = (wfi->invalid.right - wfi->invalid.left);
*height = (wfi->invalid.bottom - wfi->invalid.top); *height = (wfi->invalid.bottom - wfi->invalid.top);
#ifdef WITH_DXGI_1_2 #ifdef WITH_DXGI_1_2
wf_dxgi_getPixelData(wfi, pBits, pitch, &wfi->invalid); wf_dxgi_getPixelData(wfi, pBits, pitch, &wfi->invalid);
#else #else
{ {
long offset; long offset;
GETCHANGESBUF* changes; GETCHANGESBUF* changes;
changes = (GETCHANGESBUF*) wfi->changeBuffer; changes = (GETCHANGESBUF*) wfi->changeBuffer;
*width += 1; *width += 1;
*height += 1; *height += 1;
offset = (4 * wfi->invalid.left) + (wfi->invalid.top * wfi->virtscreen_width * 4); offset = (4 * wfi->invalid.left) + (wfi->invalid.top * wfi->virtscreen_width * 4);
*pBits = ((BYTE*) (changes->Userbuffer)) + offset; *pBits = ((BYTE*) (changes->Userbuffer)) + offset;
*pitch = wfi->virtscreen_width * 4; *pitch = wfi->virtscreen_width * 4;
} }
#endif #endif
} }
BOOL CALLBACK wf_info_monEnumCB(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData) BOOL CALLBACK wf_info_monEnumCB(HMONITOR hMonitor, HDC hdcMonitor, LPRECT lprcMonitor, LPARAM dwData)
{ {
wfInfo * wfi; wfInfo * wfi;
wfi = wf_info_get_instance(); wfi = wf_info_get_instance();
if(_IDcount == wfi->screenID) if(_IDcount == wfi->screenID)
{ {
wfi->servscreen_xoffset = lprcMonitor->left; wfi->servscreen_xoffset = lprcMonitor->left;
wfi->servscreen_yoffset = lprcMonitor->top; wfi->servscreen_yoffset = lprcMonitor->top;
} }
_IDcount++; _IDcount++;
return TRUE; return TRUE;
} }

View File

@ -102,7 +102,7 @@ DWORD WINAPI wf_server_main_loop(LPVOID lpParam)
if (instance->GetFileDescriptor(instance, rfds, &rcount) != TRUE) if (instance->GetFileDescriptor(instance, rfds, &rcount) != TRUE)
{ {
DEBUG_WARN("Failed to get FreeRDP file descriptor\n"); WLog_ERR(TAG, "Failed to get FreeRDP file descriptor");
break; break;
} }
@ -127,13 +127,12 @@ DWORD WINAPI wf_server_main_loop(LPVOID lpParam)
if (instance->CheckFileDescriptor(instance) != TRUE) if (instance->CheckFileDescriptor(instance) != TRUE)
{ {
DEBUG_WARN("Failed to check FreeRDP file descriptor\n"); WLog_ERR(TAG, "Failed to check FreeRDP file descriptor");
break; break;
} }
} }
DEBUG_WARN("wf_server_main_loop terminating\n"); WLog_INFO(TAG, "wf_server_main_loop terminating");
instance->Close(instance); instance->Close(instance);
return 0; return 0;
@ -163,8 +162,7 @@ BOOL wfreerdp_server_stop(wfServer* server)
wfInfo* wfi; wfInfo* wfi;
wfi = wf_info_get_instance(); wfi = wf_info_get_instance();
WLog_INFO(TAG, "Stopping server");
DEBUG_WARN("Stopping server\n");
wfi->force_all_disconnect = TRUE; wfi->force_all_disconnect = TRUE;
server->instance->Close(server->instance); server->instance->Close(server->instance);
return TRUE; return TRUE;
@ -210,7 +208,7 @@ FREERDP_API BOOL wfreerdp_server_is_running(wfServer* server)
bRet = GetExitCodeThread(server->thread, &tStatus); bRet = GetExitCodeThread(server->thread, &tStatus);
if (bRet == 0) if (bRet == 0)
{ {
DEBUG_WARN("Error in call to GetExitCodeThread\n"); WLog_ERR(TAG, "Error in call to GetExitCodeThread");
return FALSE; return FALSE;
} }
@ -245,7 +243,7 @@ FREERDP_API UINT32 wfreerdp_server_get_peer_hostname(int pId, wchar_t * dstStr)
} }
else else
{ {
DEBUG_WARN("nonexistent peer id=%d\n", pId); WLog_WARN(TAG, "nonexistent peer id=%d", pId);
return 0; return 0;
} }
} }

View File

@ -29,7 +29,6 @@
#include <freerdp/freerdp.h> #include <freerdp/freerdp.h>
#include <freerdp/codec/rfx.h> #include <freerdp/codec/rfx.h>
#include <freerdp/utils/debug.h>
#include <freerdp/server/rdpsnd.h> #include <freerdp/server/rdpsnd.h>

View File

@ -1,366 +1,368 @@
/** /**
* FreeRDP: A Remote Desktop Protocol Implementation * FreeRDP: A Remote Desktop Protocol Implementation
* FreeRDP Windows Server * FreeRDP Windows Server
* *
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com> * Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
* Copyright 2012-2013 Corey Clayton <can.of.tuna@gmail.com> * Copyright 2012-2013 Corey Clayton <can.of.tuna@gmail.com>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include <winpr/tchar.h>
#include <winpr/windows.h>
#include "wf_mirage.h"
#define DEVICE_KEY_PREFIX _T("\\Registry\\Machine\\")
/*
This function will iterate over the loaded display devices until it finds
the mirror device we want to load. If found, it will then copy the registry
key corresponding to the device to the wfi and returns TRUE. Otherwise
the function returns FALSE.
*/
BOOL wf_mirror_driver_find_display_device(wfInfo* wfi)
{
BOOL result;
BOOL devFound;
DWORD deviceNumber;
DISPLAY_DEVICE deviceInfo;
#include <winpr/tchar.h> devFound = FALSE;
#include <winpr/windows.h> deviceNumber = 0;
deviceInfo.cb = sizeof(deviceInfo);
while (result = EnumDisplayDevices(NULL, deviceNumber, &deviceInfo, 0))
{
if (_tcscmp(deviceInfo.DeviceString, _T("Mirage Driver")) == 0)
{
int deviceKeyLength;
int deviceKeyPrefixLength;
#include "wf_mirage.h" deviceKeyPrefixLength = _tcslen(DEVICE_KEY_PREFIX);
if (_tcsnicmp(deviceInfo.DeviceKey, DEVICE_KEY_PREFIX, deviceKeyPrefixLength) == 0)
{
deviceKeyLength = _tcslen(deviceInfo.DeviceKey) - deviceKeyPrefixLength;
wfi->deviceKey = (LPTSTR) malloc((deviceKeyLength + 1) * sizeof(TCHAR));
#define DEVICE_KEY_PREFIX _T("\\Registry\\Machine\\") _tcsncpy_s(wfi->deviceKey, deviceKeyLength + 1,
/*
This function will iterate over the loaded display devices until it finds
the mirror device we want to load. If found, it will then copy the registry
key corresponding to the device to the wfi and returns TRUE. Otherwise
the function returns FALSE.
*/
BOOL wf_mirror_driver_find_display_device(wfInfo* wfi)
{
BOOL result;
BOOL devFound;
DWORD deviceNumber;
DISPLAY_DEVICE deviceInfo;
devFound = FALSE;
deviceNumber = 0;
deviceInfo.cb = sizeof(deviceInfo);
while (result = EnumDisplayDevices(NULL, deviceNumber, &deviceInfo, 0))
{
if (_tcscmp(deviceInfo.DeviceString, _T("Mirage Driver")) == 0)
{
int deviceKeyLength;
int deviceKeyPrefixLength;
deviceKeyPrefixLength = _tcslen(DEVICE_KEY_PREFIX);
if (_tcsnicmp(deviceInfo.DeviceKey, DEVICE_KEY_PREFIX, deviceKeyPrefixLength) == 0)
{
deviceKeyLength = _tcslen(deviceInfo.DeviceKey) - deviceKeyPrefixLength;
wfi->deviceKey = (LPTSTR) malloc((deviceKeyLength + 1) * sizeof(TCHAR));
_tcsncpy_s(wfi->deviceKey, deviceKeyLength + 1,
&deviceInfo.DeviceKey[deviceKeyPrefixLength], deviceKeyLength); &deviceInfo.DeviceKey[deviceKeyPrefixLength], deviceKeyLength);
} }
_tcsncpy_s(wfi->deviceName, 32, deviceInfo.DeviceName, _tcslen(deviceInfo.DeviceName)); _tcsncpy_s(wfi->deviceName, 32, deviceInfo.DeviceName, _tcslen(deviceInfo.DeviceName));
return TRUE; return TRUE;
} }
deviceNumber++; deviceNumber++;
} }
return FALSE; return FALSE;
} }
/** /**
* This function will attempt to access the the windows registry using the device * This function will attempt to access the the windows registry using the device
* key stored in the current wfi. It will attempt to read the value of the * key stored in the current wfi. It will attempt to read the value of the
* "Attach.ToDesktop" subkey and will return TRUE if the value is already set to * "Attach.ToDesktop" subkey and will return TRUE if the value is already set to
* val. If unable to read the subkey, this function will return FALSE. If the * val. If unable to read the subkey, this function will return FALSE. If the
* subkey is not set to val it will then attempt to set it to val and return TRUE. If * subkey is not set to val it will then attempt to set it to val and return TRUE. If
* unsuccessful or an unexpected value is encountered, the function returns * unsuccessful or an unexpected value is encountered, the function returns
* FALSE. * FALSE.
*/ */
BOOL wf_mirror_driver_display_device_attach(wfInfo* wfi, DWORD mode)
{
HKEY hKey;
LONG status;
DWORD dwType;
DWORD dwSize;
DWORD dwValue;
BOOL wf_mirror_driver_display_device_attach(wfInfo* wfi, DWORD mode) status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, wfi->deviceKey,
{
HKEY hKey;
LONG status;
DWORD dwType;
DWORD dwSize;
DWORD dwValue;
status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, wfi->deviceKey,
0, KEY_ALL_ACCESS | KEY_WOW64_64KEY, &hKey); 0, KEY_ALL_ACCESS | KEY_WOW64_64KEY, &hKey);
if (status != ERROR_SUCCESS) if (status != ERROR_SUCCESS)
{ {
DEBUG_WARN("Error opening RegKey: status=%0X\n", status); WLog_DBG(TAG, "Error opening RegKey: status=%0X", status);
if (status == ERROR_ACCESS_DENIED)
DEBUG_WARN("access denied. Do you have admin privleges?\n"); if (status == ERROR_ACCESS_DENIED)
return FALSE; WLog_DBG(TAG, "access denied. Do you have admin privleges?");
}
return FALSE;
dwSize = sizeof(DWORD); }
status = RegQueryValueEx(hKey, _T("Attach.ToDesktop"),
dwSize = sizeof(DWORD);
status = RegQueryValueEx(hKey, _T("Attach.ToDesktop"),
NULL, &dwType, (BYTE*) &dwValue, &dwSize); NULL, &dwType, (BYTE*) &dwValue, &dwSize);
if (status != ERROR_SUCCESS)
{
WLog_DBG(TAG, "Error querying RegKey: status=%0X", status);
if (status == ERROR_ACCESS_DENIED)
WLog_DBG(TAG, "access denied. Do you have admin privleges?");
return FALSE;
}
if (dwValue ^ mode) //only if we want to change modes
{
dwValue = mode;
dwSize = sizeof(DWORD);
if (status != ERROR_SUCCESS) status = RegSetValueEx(hKey, _T("Attach.ToDesktop"),
{
DEBUG_WARN("Error querying RegKey: status=%0X\n", status);
if (status == ERROR_ACCESS_DENIED)
DEBUG_WARN("access denied. Do you have admin privleges?\n");
return FALSE;
}
if (dwValue ^ mode) //only if we want to change modes
{
dwValue = mode;
dwSize = sizeof(DWORD);
status = RegSetValueEx(hKey, _T("Attach.ToDesktop"),
0, REG_DWORD, (BYTE*) &dwValue, dwSize); 0, REG_DWORD, (BYTE*) &dwValue, dwSize);
if (status != ERROR_SUCCESS)
{
WLog_DBG(TAG, "Error writing registry key: %d ", status);
if (status == ERROR_ACCESS_DENIED)
WLog_DBG(TAG, "access denied. Do you have admin privleges?");
WLog_DBG(TAG, "");
return FALSE;
}
}
return TRUE;
}
void wf_mirror_driver_print_display_change_status(LONG status)
{
TCHAR disp_change[64];
switch (status)
{
case DISP_CHANGE_SUCCESSFUL:
_tcscpy(disp_change, _T("DISP_CHANGE_SUCCESSFUL"));
break;
if (status != ERROR_SUCCESS) case DISP_CHANGE_BADDUALVIEW:
{ _tcscpy(disp_change, _T("DISP_CHANGE_BADDUALVIEW"));
DEBUG_WARN("Error writing registry key: %d ", status); break;
if (status == ERROR_ACCESS_DENIED)
DEBUG_WARN("access denied. Do you have admin privleges?");
DEBUG_WARN("\n");
return FALSE;
}
}
return TRUE; case DISP_CHANGE_BADFLAGS:
} _tcscpy(disp_change, _T("DISP_CHANGE_BADFLAGS"));
break;
void wf_mirror_driver_print_display_change_status(LONG status) case DISP_CHANGE_BADMODE:
{ _tcscpy(disp_change, _T("DISP_CHANGE_BADMODE"));
TCHAR disp_change[64]; break;
switch (status) case DISP_CHANGE_BADPARAM:
{ _tcscpy(disp_change, _T("DISP_CHANGE_BADPARAM"));
case DISP_CHANGE_SUCCESSFUL: break;
_tcscpy(disp_change, _T("DISP_CHANGE_SUCCESSFUL"));
break;
case DISP_CHANGE_BADDUALVIEW: case DISP_CHANGE_FAILED:
_tcscpy(disp_change, _T("DISP_CHANGE_BADDUALVIEW")); _tcscpy(disp_change, _T("DISP_CHANGE_FAILED"));
break; break;
case DISP_CHANGE_BADFLAGS: case DISP_CHANGE_NOTUPDATED:
_tcscpy(disp_change, _T("DISP_CHANGE_BADFLAGS")); _tcscpy(disp_change, _T("DISP_CHANGE_NOTUPDATED"));
break; break;
case DISP_CHANGE_BADMODE: case DISP_CHANGE_RESTART:
_tcscpy(disp_change, _T("DISP_CHANGE_BADMODE")); _tcscpy(disp_change, _T("DISP_CHANGE_RESTART"));
break; break;
case DISP_CHANGE_BADPARAM: default:
_tcscpy(disp_change, _T("DISP_CHANGE_BADPARAM")); _tcscpy(disp_change, _T("DISP_CHANGE_UNKNOWN"));
break; break;
}
case DISP_CHANGE_FAILED:
_tcscpy(disp_change, _T("DISP_CHANGE_FAILED")); if (status != DISP_CHANGE_SUCCESSFUL)
break; WLog_ERR(TAG, "ChangeDisplaySettingsEx() failed with %s (%d)", disp_change, status);
else
case DISP_CHANGE_NOTUPDATED: WLog_INFO(TAG, "ChangeDisplaySettingsEx() succeeded with %s (%d)", disp_change, status);
_tcscpy(disp_change, _T("DISP_CHANGE_NOTUPDATED")); }
break;
/**
case DISP_CHANGE_RESTART:
_tcscpy(disp_change, _T("DISP_CHANGE_RESTART"));
break;
default:
_tcscpy(disp_change, _T("DISP_CHANGE_UNKNOWN"));
break;
}
if (status != DISP_CHANGE_SUCCESSFUL)
_tprintf(_T("ChangeDisplaySettingsEx() failed with %s (%d)\n"), disp_change, status);
else
_tprintf(_T("ChangeDisplaySettingsEx() succeeded with %s (%d)\n"), disp_change, status);
}
/**
* This function will attempt to apply the currently configured display settings * This function will attempt to apply the currently configured display settings
* in the registry to the display driver. It will return TRUE if successful * in the registry to the display driver. It will return TRUE if successful
* otherwise it returns FALSE. * otherwise it returns FALSE.
* If mode is MIRROR_UNLOAD then the the driver will be asked to remove itself. * If mode is MIRROR_UNLOAD then the the driver will be asked to remove itself.
*/ */
BOOL wf_mirror_driver_update(wfInfo* wfi, int mode) BOOL wf_mirror_driver_update(wfInfo* wfi, int mode)
{ {
HDC dc; HDC dc;
BOOL status; BOOL status;
DWORD* extHdr; DWORD* extHdr;
WORD drvExtraSaved; WORD drvExtraSaved;
DEVMODE* deviceMode; DEVMODE* deviceMode;
LONG disp_change_status; LONG disp_change_status;
DWORD dmf_devmodewext_magic_sig = 0xDF20C0DE; DWORD dmf_devmodewext_magic_sig = 0xDF20C0DE;
if ( (mode != MIRROR_LOAD) && (mode != MIRROR_UNLOAD) ) if ( (mode != MIRROR_LOAD) && (mode != MIRROR_UNLOAD) )
{ {
DEBUG_WARN("Invalid mirror mode!\n"); WLog_DBG(TAG, "Invalid mirror mode!");
return FALSE; return FALSE;
} }
deviceMode = (DEVMODE*) malloc(sizeof(DEVMODE) + EXT_DEVMODE_SIZE_MAX); deviceMode = (DEVMODE*) malloc(sizeof(DEVMODE) + EXT_DEVMODE_SIZE_MAX);
deviceMode->dmDriverExtra = 2 * sizeof(DWORD); deviceMode->dmDriverExtra = 2 * sizeof(DWORD);
extHdr = (DWORD*)((BYTE*) &deviceMode + sizeof(DEVMODE)); extHdr = (DWORD*)((BYTE*) &deviceMode + sizeof(DEVMODE));
extHdr[0] = dmf_devmodewext_magic_sig; extHdr[0] = dmf_devmodewext_magic_sig;
extHdr[1] = 0; extHdr[1] = 0;
drvExtraSaved = deviceMode->dmDriverExtra; drvExtraSaved = deviceMode->dmDriverExtra;
memset(deviceMode, 0, sizeof(DEVMODE) + EXT_DEVMODE_SIZE_MAX); memset(deviceMode, 0, sizeof(DEVMODE) + EXT_DEVMODE_SIZE_MAX);
deviceMode->dmSize = sizeof(DEVMODE); deviceMode->dmSize = sizeof(DEVMODE);
deviceMode->dmDriverExtra = drvExtraSaved; deviceMode->dmDriverExtra = drvExtraSaved;
if (mode == MIRROR_LOAD)
{
wfi->virtscreen_width = GetSystemMetrics(SM_CXVIRTUALSCREEN);
wfi->virtscreen_height = GetSystemMetrics(SM_CYVIRTUALSCREEN);
if (mode == MIRROR_LOAD) deviceMode->dmPelsWidth = wfi->virtscreen_width;
{ deviceMode->dmPelsHeight = wfi->virtscreen_height;
wfi->virtscreen_width = GetSystemMetrics(SM_CXVIRTUALSCREEN); deviceMode->dmBitsPerPel = wfi->bitsPerPixel;
wfi->virtscreen_height = GetSystemMetrics(SM_CYVIRTUALSCREEN); deviceMode->dmPosition.x = wfi->servscreen_xoffset;
deviceMode->dmPosition.y = wfi->servscreen_yoffset;
}
deviceMode->dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_POSITION;
deviceMode->dmPelsWidth = wfi->virtscreen_width; _tcsncpy_s(deviceMode->dmDeviceName, 32, wfi->deviceName, _tcslen(wfi->deviceName));
deviceMode->dmPelsHeight = wfi->virtscreen_height;
deviceMode->dmBitsPerPel = wfi->bitsPerPixel;
deviceMode->dmPosition.x = wfi->servscreen_xoffset;
deviceMode->dmPosition.y = wfi->servscreen_yoffset;
}
deviceMode->dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_POSITION; disp_change_status = ChangeDisplaySettingsEx(wfi->deviceName, deviceMode, NULL, CDS_UPDATEREGISTRY, NULL);
_tcsncpy_s(deviceMode->dmDeviceName, 32, wfi->deviceName, _tcslen(wfi->deviceName)); status = (disp_change_status == DISP_CHANGE_SUCCESSFUL) ? TRUE : FALSE;
disp_change_status = ChangeDisplaySettingsEx(wfi->deviceName, deviceMode, NULL, CDS_UPDATEREGISTRY, NULL); if (!status)
wf_mirror_driver_print_display_change_status(disp_change_status);
status = (disp_change_status == DISP_CHANGE_SUCCESSFUL) ? TRUE : FALSE;
if (!status)
wf_mirror_driver_print_display_change_status(disp_change_status);
return status; return status;
} }
BOOL wf_mirror_driver_map_memory(wfInfo* wfi)
{
int status;
BOOL wf_mirror_driver_map_memory(wfInfo* wfi) wfi->driverDC = CreateDC(wfi->deviceName, NULL, NULL, NULL);
{
int status; if (wfi->driverDC == NULL)
{
wfi->driverDC = CreateDC(wfi->deviceName, NULL, NULL, NULL); WLog_ERR(TAG, "Could not create device driver context!");
{
if (wfi->driverDC == NULL) LPVOID lpMsgBuf;
{
_tprintf(_T("Could not create device driver context!\n"));
{
LPVOID lpMsgBuf;
DWORD dw = GetLastError(); DWORD dw = GetLastError();
FormatMessage( FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS, FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, NULL,
dw, dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf, (LPTSTR) &lpMsgBuf,
0, NULL ); 0, NULL );
// Display the error message and exit the process // Display the error message and exit the process
WLog_ERR(TAG, "CreateDC failed on device [%s] with error %d: %s", wfi->deviceName, dw, lpMsgBuf);
LocalFree(lpMsgBuf);
}
_tprintf(_T("CreateDC failed on device [%s] with error %d: %s\n"), wfi->deviceName, dw, lpMsgBuf); return FALSE;
}
wfi->changeBuffer = malloc(sizeof(GETCHANGESBUF));
ZeroMemory(wfi->changeBuffer, sizeof(GETCHANGESBUF));
LocalFree(lpMsgBuf); status = ExtEscape(wfi->driverDC, dmf_esc_usm_pipe_map, 0, 0, sizeof(GETCHANGESBUF), (LPSTR) wfi->changeBuffer);
}
if (status <= 0)
{
WLog_ERR(TAG, "Failed to map shared memory from the driver! code %d", status);
return FALSE;
}
return TRUE;
}
/* Unmap the shared memory and release the DC */
BOOL wf_mirror_driver_cleanup(wfInfo* wfi)
{
int status;
return FALSE; status = ExtEscape(wfi->driverDC, dmf_esc_usm_pipe_unmap, sizeof(GETCHANGESBUF), (LPSTR) wfi->changeBuffer, 0, 0);
}
wfi->changeBuffer = malloc(sizeof(GETCHANGESBUF));
ZeroMemory(wfi->changeBuffer, sizeof(GETCHANGESBUF));
status = ExtEscape(wfi->driverDC, dmf_esc_usm_pipe_map, 0, 0, sizeof(GETCHANGESBUF), (LPSTR) wfi->changeBuffer);
if (status <= 0)
{
_tprintf(_T("Failed to map shared memory from the driver! code %d\n"), status);
return FALSE;
}
return TRUE;
}
/* Unmap the shared memory and release the DC */
BOOL wf_mirror_driver_cleanup(wfInfo* wfi)
{
int status;
status = ExtEscape(wfi->driverDC, dmf_esc_usm_pipe_unmap, sizeof(GETCHANGESBUF), (LPSTR) wfi->changeBuffer, 0, 0);
if (status <= 0) if (status <= 0)
{ {
_tprintf(_T("Failed to unmap shared memory from the driver! code %d\n"), status); WLog_ERR(TAG, "Failed to unmap shared memory from the driver! code %d", status);
} }
if (wfi->driverDC != NULL)
{
status = DeleteDC(wfi->driverDC);
if (status == 0)
{
WLog_ERR(TAG, "Failed to release DC!"));
}
}
free(wfi->changeBuffer);
if (wfi->driverDC != NULL) return TRUE;
{ }
status = DeleteDC(wfi->driverDC);
BOOL wf_mirror_driver_activate(wfInfo* wfi)
if (status == 0) {
{ if (!wfi->mirrorDriverActive)
_tprintf(_T("Failed to release DC!\n")); {
} WLog_DBG(TAG, "Activating Mirror Driver");
}
if (wf_mirror_driver_find_display_device(wfi) == FALSE)
free(wfi->changeBuffer); {
WLog_DBG(TAG, "Could not find dfmirage mirror driver! Is it installed?");
return TRUE; return FALSE;
} }
BOOL wf_mirror_driver_activate(wfInfo* wfi) if (wf_mirror_driver_display_device_attach(wfi, 1) == FALSE)
{ {
if (!wfi->mirrorDriverActive) WLog_DBG(TAG, "Could not attach display device!");
{ return FALSE;
DEBUG_WARN("Activating Mirror Driver\n"); }
if (wf_mirror_driver_find_display_device(wfi) == FALSE) if (wf_mirror_driver_update(wfi, MIRROR_LOAD) == FALSE)
{ {
DEBUG_WARN("Could not find dfmirage mirror driver! Is it installed?\n"); WLog_DBG(TAG, "could not update system with new display settings!");
return FALSE; return FALSE;
} }
if (wf_mirror_driver_display_device_attach(wfi, 1) == FALSE) if (wf_mirror_driver_map_memory(wfi) == FALSE)
{ {
DEBUG_WARN("Could not attach display device!\n"); WLog_DBG(TAG, "Unable to map memory for mirror driver!");
return FALSE; return FALSE;
} }
wfi->mirrorDriverActive = TRUE;
if (wf_mirror_driver_update(wfi, MIRROR_LOAD) == FALSE) }
{
DEBUG_WARN("could not update system with new display settings!\n"); return TRUE;
return FALSE; }
}
void wf_mirror_driver_deactivate(wfInfo* wfi)
if (wf_mirror_driver_map_memory(wfi) == FALSE) {
{ if (wfi->mirrorDriverActive)
DEBUG_WARN("Unable to map memory for mirror driver!\n"); {
return FALSE; WLog_DBG(TAG, "Deactivating Mirror Driver");
} wf_mirror_driver_cleanup(wfi);
wfi->mirrorDriverActive = TRUE; wf_mirror_driver_display_device_attach(wfi, 0);
} wf_mirror_driver_update(wfi, MIRROR_UNLOAD);
wfi->mirrorDriverActive = FALSE;
return TRUE; }
}
void wf_mirror_driver_deactivate(wfInfo* wfi)
{
if (wfi->mirrorDriverActive)
{
DEBUG_WARN("Deactivating Mirror Driver\n");
wf_mirror_driver_cleanup(wfi);
wf_mirror_driver_display_device_attach(wfi, 0);
wf_mirror_driver_update(wfi, MIRROR_UNLOAD);
wfi->mirrorDriverActive = FALSE;
}
} }

View File

@ -1,331 +1,329 @@
/** /**
* FreeRDP: A Remote Desktop Protocol Client * FreeRDP: A Remote Desktop Protocol Client
* FreeRDP Windows Server * FreeRDP Windows Server
* *
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com> * Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
* Copyright 2012 Corey Clayton <can.of.tuna@gmail.com> * Copyright 2012 Corey Clayton <can.of.tuna@gmail.com>
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <winpr/tchar.h>
#include <winpr/stream.h>
#include <winpr/windows.h>
#include <freerdp/listener.h>
#include <freerdp/codec/rfx.h>
#include "wf_info.h"
#include "wf_input.h"
#include "wf_mirage.h"
#include "wf_update.h"
#include "wf_settings.h"
#include "wf_rdpsnd.h"
#include "wf_peer.h"
void wf_peer_context_new(freerdp_peer* client, wfPeerContext* context)
{
context->info = wf_info_get_instance();
context->vcm = WTSOpenServerA((LPSTR) client->context);
wf_info_peer_register(context->info, context);
}
void wf_peer_context_free(freerdp_peer* client, wfPeerContext* context)
{
wf_info_peer_unregister(context->info, context);
if (context->rdpsnd)
{
wf_rdpsnd_lock();
context->info->snd_stop = TRUE;
rdpsnd_server_context_free(context->rdpsnd);
wf_rdpsnd_unlock();
}
WTSCloseServer(context->vcm);
}
void wf_peer_init(freerdp_peer* client)
{
client->ContextSize = sizeof(wfPeerContext);
client->ContextNew = (psPeerContextNew) wf_peer_context_new;
client->ContextFree = (psPeerContextFree) wf_peer_context_free;
#ifdef HAVE_CONFIG_H freerdp_peer_context_new(client);
#include "config.h" }
#endif
BOOL wf_peer_post_connect(freerdp_peer* client)
{
int i;
wfInfo* wfi;
rdpSettings* settings;
wfPeerContext* context = (wfPeerContext*) client->context;
#include <winpr/tchar.h> wfi = context->info;
#include <winpr/stream.h> settings = client->settings;
#include <winpr/windows.h>
if ((get_screen_info(wfi->screenID, NULL, &wfi->servscreen_width, &wfi->servscreen_height, &wfi->bitsPerPixel) == 0) ||
#include <freerdp/listener.h>
#include <freerdp/codec/rfx.h>
#include "wf_info.h"
#include "wf_input.h"
#include "wf_mirage.h"
#include "wf_update.h"
#include "wf_settings.h"
#include "wf_rdpsnd.h"
#include "wf_peer.h"
void wf_peer_context_new(freerdp_peer* client, wfPeerContext* context)
{
context->info = wf_info_get_instance();
context->vcm = WTSOpenServerA((LPSTR) client->context);
wf_info_peer_register(context->info, context);
}
void wf_peer_context_free(freerdp_peer* client, wfPeerContext* context)
{
wf_info_peer_unregister(context->info, context);
if (context->rdpsnd)
{
wf_rdpsnd_lock();
context->info->snd_stop = TRUE;
rdpsnd_server_context_free(context->rdpsnd);
wf_rdpsnd_unlock();
}
WTSCloseServer(context->vcm);
}
void wf_peer_init(freerdp_peer* client)
{
client->ContextSize = sizeof(wfPeerContext);
client->ContextNew = (psPeerContextNew) wf_peer_context_new;
client->ContextFree = (psPeerContextFree) wf_peer_context_free;
freerdp_peer_context_new(client);
}
BOOL wf_peer_post_connect(freerdp_peer* client)
{
int i;
wfInfo* wfi;
rdpSettings* settings;
wfPeerContext* context = (wfPeerContext*) client->context;
wfi = context->info;
settings = client->settings;
if ((get_screen_info(wfi->screenID, NULL, &wfi->servscreen_width, &wfi->servscreen_height, &wfi->bitsPerPixel) == 0) ||
(wfi->servscreen_width == 0) || (wfi->servscreen_width == 0) ||
(wfi->servscreen_height == 0) || (wfi->servscreen_height == 0) ||
(wfi->bitsPerPixel == 0) ) (wfi->bitsPerPixel == 0) )
{ {
_tprintf(_T("postconnect: error getting screen info for screen %d\n"), wfi->screenID); WLog_ERR(TAG, "postconnect: error getting screen info for screen %d", wfi->screenID);
_tprintf(_T("\t%dx%dx%d\n"), wfi->servscreen_height, wfi->servscreen_width, wfi->bitsPerPixel); WLog_ERR(TAG, "\t%dx%dx%d", wfi->servscreen_height, wfi->servscreen_width, wfi->bitsPerPixel);
return FALSE; return FALSE;
} }
if ((settings->DesktopWidth != wfi->servscreen_width) || (settings->DesktopHeight != wfi->servscreen_height))
{
/*
WLog_DBG(TAG, "Client requested resolution %dx%d, but will resize to %dx%d",
settings->DesktopWidth, settings->DesktopHeight, wfi->servscreen_width, wfi->servscreen_height);
*/
if ((settings->DesktopWidth != wfi->servscreen_width) || (settings->DesktopHeight != wfi->servscreen_height)) settings->DesktopWidth = wfi->servscreen_width;
{ settings->DesktopHeight = wfi->servscreen_height;
/* settings->ColorDepth = wfi->bitsPerPixel;
DEBUG_WARN("Client requested resolution %dx%d, but will resize to %dx%d\n",
settings->DesktopWidth, settings->DesktopHeight, wfi->servscreen_width, wfi->servscreen_height);
*/
settings->DesktopWidth = wfi->servscreen_width; client->update->DesktopResize(client->update->context);
settings->DesktopHeight = wfi->servscreen_height; }
settings->ColorDepth = wfi->bitsPerPixel;
if (WTSVirtualChannelManagerIsChannelJoined(context->vcm, "rdpsnd"))
{
wf_peer_rdpsnd_init(context); /* Audio Output */
}
return TRUE;
}
BOOL wf_peer_activate(freerdp_peer* client)
{
wfInfo* wfi;
wfPeerContext* context = (wfPeerContext*) client->context;
client->update->DesktopResize(client->update->context); wfi = context->info;
} client->activated = TRUE;
wf_update_peer_activate(wfi, context);
if (WTSVirtualChannelManagerIsChannelJoined(context->vcm, "rdpsnd")) wfreerdp_server_peer_callback_event(((rdpContext*) context)->peer->pId, WF_SRV_CALLBACK_EVENT_ACTIVATE);
{
wf_peer_rdpsnd_init(context); /* Audio Output */
}
return TRUE; return TRUE;
} }
BOOL wf_peer_logon(freerdp_peer* client, SEC_WINNT_AUTH_IDENTITY* identity, BOOL automatic)
{
wfreerdp_server_peer_callback_event(((rdpContext*) client->context)->peer->pId, WF_SRV_CALLBACK_EVENT_AUTH);
return TRUE;
}
void wf_peer_synchronize_event(rdpInput* input, UINT32 flags)
{
BOOL wf_peer_activate(freerdp_peer* client) }
{
wfInfo* wfi; void wf_peer_accepted(freerdp_listener* instance, freerdp_peer* client)
wfPeerContext* context = (wfPeerContext*) client->context; {
CreateThread(NULL, 0, wf_peer_main_loop, client, 0, NULL);
}
DWORD WINAPI wf_peer_socket_listener(LPVOID lpParam)
{
int i, fds;
int rcount;
int max_fds;
void* rfds[32];
fd_set rfds_set;
wfPeerContext* context;
freerdp_peer* client = (freerdp_peer*) lpParam;
wfi = context->info; ZeroMemory(rfds, sizeof(rfds));
client->activated = TRUE; context = (wfPeerContext*) client->context;
wf_update_peer_activate(wfi, context);
while (1)
{
rcount = 0;
if (client->GetFileDescriptor(client, rfds, &rcount) != TRUE)
{
WLog_ERR(TAG, "Failed to get peer file descriptor");
break;
}
max_fds = 0;
FD_ZERO(&rfds_set);
for (i = 0; i < rcount; i++)
{
fds = (int)(long)(rfds[i]);
if (fds > max_fds)
max_fds = fds;
FD_SET(fds, &rfds_set);
}
if (max_fds == 0)
break;
select(max_fds + 1, &rfds_set, NULL, NULL, NULL);
wfreerdp_server_peer_callback_event(((rdpContext*) context)->peer->pId, WF_SRV_CALLBACK_EVENT_ACTIVATE); SetEvent(context->socketEvent);
WaitForSingleObject(context->socketSemaphore, INFINITE);
if (context->socketClose)
break;
}
return 0;
}
void wf_peer_read_settings(freerdp_peer* client)
{
if (!wf_settings_read_string_ascii(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), _T("CertificateFile"), &(client->settings->CertificateFile)))
client->settings->CertificateFile = _strdup("server.crt");
if (!wf_settings_read_string_ascii(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), _T("PrivateKeyFile"), &(client->settings->PrivateKeyFile)))
client->settings->PrivateKeyFile = _strdup("server.key");
}
DWORD WINAPI wf_peer_main_loop(LPVOID lpParam)
{
wfInfo* wfi;
DWORD nCount;
DWORD status;
HANDLE handles[32];
rdpSettings* settings;
wfPeerContext* context;
freerdp_peer* client = (freerdp_peer*) lpParam;
if (!getenv("HOME"))
{
char home[MAX_PATH * 2] = "HOME=";
strcat(home, getenv("HOMEDRIVE"));
strcat(home, getenv("HOMEPATH"));
_putenv(home);
}
wf_peer_init(client);
return TRUE; settings = client->settings;
} settings->RemoteFxCodec = TRUE;
settings->ColorDepth = 32;
settings->NSCodec = FALSE;
settings->JpegCodec = FALSE;
wf_peer_read_settings(client);
BOOL wf_peer_logon(freerdp_peer* client, SEC_WINNT_AUTH_IDENTITY* identity, BOOL automatic) client->PostConnect = wf_peer_post_connect;
{ client->Activate = wf_peer_activate;
wfreerdp_server_peer_callback_event(((rdpContext*) client->context)->peer->pId, WF_SRV_CALLBACK_EVENT_AUTH); client->Logon = wf_peer_logon;
return TRUE;
}
void wf_peer_synchronize_event(rdpInput* input, UINT32 flags) client->input->SynchronizeEvent = wf_peer_synchronize_event;
{ client->input->KeyboardEvent = wf_peer_keyboard_event;
client->input->UnicodeKeyboardEvent = wf_peer_unicode_keyboard_event;
client->input->MouseEvent = wf_peer_mouse_event;
client->input->ExtendedMouseEvent = wf_peer_extended_mouse_event;
} client->Initialize(client);
context = (wfPeerContext*) client->context;
void wf_peer_accepted(freerdp_listener* instance, freerdp_peer* client)
{ if (context->socketClose)
CreateThread(NULL, 0, wf_peer_main_loop, client, 0, NULL); return 0;
}
wfi = context->info;
DWORD WINAPI wf_peer_socket_listener(LPVOID lpParam)
{ if (wfi->input_disabled)
int i, fds; {
int rcount; WLog_INFO(TAG, "client input is disabled");
int max_fds; client->input->KeyboardEvent = wf_peer_keyboard_event_dummy;
void* rfds[32]; client->input->UnicodeKeyboardEvent = wf_peer_unicode_keyboard_event_dummy;
fd_set rfds_set; client->input->MouseEvent = wf_peer_mouse_event_dummy;
wfPeerContext* context; client->input->ExtendedMouseEvent = wf_peer_extended_mouse_event_dummy;
freerdp_peer* client = (freerdp_peer*) lpParam; }
ZeroMemory(rfds, sizeof(rfds)); context->socketEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
context = (wfPeerContext*) client->context;
while (1)
{
rcount = 0;
if (client->GetFileDescriptor(client, rfds, &rcount) != TRUE)
{
//printf("Failed to get peer file descriptor\n");
break;
}
max_fds = 0;
FD_ZERO(&rfds_set);
for (i = 0; i < rcount; i++)
{
fds = (int)(long)(rfds[i]);
if (fds > max_fds)
max_fds = fds;
FD_SET(fds, &rfds_set);
}
if (max_fds == 0)
break;
select(max_fds + 1, &rfds_set, NULL, NULL, NULL);
SetEvent(context->socketEvent);
WaitForSingleObject(context->socketSemaphore, INFINITE);
if (context->socketClose)
break;
}
return 0;
}
void wf_peer_read_settings(freerdp_peer* client)
{
if (!wf_settings_read_string_ascii(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), _T("CertificateFile"), &(client->settings->CertificateFile)))
client->settings->CertificateFile = _strdup("server.crt");
if (!wf_settings_read_string_ascii(HKEY_LOCAL_MACHINE, _T("Software\\FreeRDP\\Server"), _T("PrivateKeyFile"), &(client->settings->PrivateKeyFile)))
client->settings->PrivateKeyFile = _strdup("server.key");
}
DWORD WINAPI wf_peer_main_loop(LPVOID lpParam)
{
wfInfo* wfi;
DWORD nCount;
DWORD status;
HANDLE handles[32];
rdpSettings* settings;
wfPeerContext* context;
freerdp_peer* client = (freerdp_peer*) lpParam;
if (!getenv("HOME"))
{
char home[MAX_PATH * 2] = "HOME=";
strcat(home, getenv("HOMEDRIVE"));
strcat(home, getenv("HOMEPATH"));
_putenv(home);
}
wf_peer_init(client);
settings = client->settings;
settings->RemoteFxCodec = TRUE;
settings->ColorDepth = 32;
settings->NSCodec = FALSE;
settings->JpegCodec = FALSE;
wf_peer_read_settings(client);
client->PostConnect = wf_peer_post_connect;
client->Activate = wf_peer_activate;
client->Logon = wf_peer_logon;
client->input->SynchronizeEvent = wf_peer_synchronize_event;
client->input->KeyboardEvent = wf_peer_keyboard_event;
client->input->UnicodeKeyboardEvent = wf_peer_unicode_keyboard_event;
client->input->MouseEvent = wf_peer_mouse_event;
client->input->ExtendedMouseEvent = wf_peer_extended_mouse_event;
client->Initialize(client);
context = (wfPeerContext*) client->context;
if (context->socketClose)
return 0;
wfi = context->info;
if (wfi->input_disabled)
{
DEBUG_WARN("client input is disabled\n");
client->input->KeyboardEvent = wf_peer_keyboard_event_dummy;
client->input->UnicodeKeyboardEvent = wf_peer_unicode_keyboard_event_dummy;
client->input->MouseEvent = wf_peer_mouse_event_dummy;
client->input->ExtendedMouseEvent = wf_peer_extended_mouse_event_dummy;
}
context->socketEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
context->socketSemaphore = CreateSemaphore(NULL, 0, 1, NULL); context->socketSemaphore = CreateSemaphore(NULL, 0, 1, NULL);
context->socketThread = CreateThread(NULL, 0, wf_peer_socket_listener, client, 0, NULL); context->socketThread = CreateThread(NULL, 0, wf_peer_socket_listener, client, 0, NULL);
WLog_INFO(TAG, "We've got a client %s", client->local ? "(local)" : client->hostname);
nCount = 0;
handles[nCount++] = context->updateEvent;
handles[nCount++] = context->socketEvent;
while (1)
{
status = WaitForMultipleObjects(nCount, handles, FALSE, INFINITE);
if ((status == WAIT_FAILED) || (status == WAIT_TIMEOUT))
{
WLog_ERR(TAG, "WaitForMultipleObjects failed");
break;
}
if (WaitForSingleObject(context->updateEvent, 0) == 0)
{
if (client->activated)
wf_update_peer_send(wfi, context);
ResetEvent(context->updateEvent);
ReleaseSemaphore(wfi->updateSemaphore, 1, NULL);
}
if (WaitForSingleObject(context->socketEvent, 0) == 0)
{
if (client->CheckFileDescriptor(client) != TRUE)
{
WLog_ERR(TAG, "Failed to check peer file descriptor");
context->socketClose = TRUE;
}
ResetEvent(context->socketEvent);
ReleaseSemaphore(context->socketSemaphore, 1, NULL);
if (context->socketClose)
break;
}
//force disconnect
if (wfi->force_all_disconnect == TRUE)
{
WLog_INFO(TAG, "Forcing Disconnect -> ");
break;
}
/* FIXME: we should wait on this, instead of calling it every time */
if (WTSVirtualChannelManagerCheckFileDescriptor(context->vcm) != TRUE)
break;
}
WLog_INFO(TAG, "Client %s disconnected.", client->local ? "(local)" : client->hostname);
if (WaitForSingleObject(context->updateEvent, 0) == 0)
{
ResetEvent(context->updateEvent);
ReleaseSemaphore(wfi->updateSemaphore, 1, NULL);
}
wf_update_peer_deactivate(wfi, context);
DEBUG_WARN("We've got a client %s\n", client->local ? "(local)" : client->hostname); client->Disconnect(client);
nCount = 0; freerdp_peer_context_free(client);
handles[nCount++] = context->updateEvent; freerdp_peer_free(client);
handles[nCount++] = context->socketEvent;
while (1) return 0;
{ }
status = WaitForMultipleObjects(nCount, handles, FALSE, INFINITE);
if ((status == WAIT_FAILED) || (status == WAIT_TIMEOUT))
{
DEBUG_WARN("WaitForMultipleObjects failed\n");
break;
}
if (WaitForSingleObject(context->updateEvent, 0) == 0)
{
if (client->activated)
wf_update_peer_send(wfi, context);
ResetEvent(context->updateEvent);
ReleaseSemaphore(wfi->updateSemaphore, 1, NULL);
}
if (WaitForSingleObject(context->socketEvent, 0) == 0)
{
if (client->CheckFileDescriptor(client) != TRUE)
{
//printf("Failed to check peer file descriptor\n");
context->socketClose = TRUE;
}
ResetEvent(context->socketEvent);
ReleaseSemaphore(context->socketSemaphore, 1, NULL);
if (context->socketClose)
break;
}
//force disconnect
if (wfi->force_all_disconnect == TRUE)
{
DEBUG_WARN("Forcing Disconnect -> ");
break;
}
/* FIXME: we should wait on this, instead of calling it every time */
if (WTSVirtualChannelManagerCheckFileDescriptor(context->vcm) != TRUE)
break;
}
DEBUG_WARN("Client %s disconnected.\n", client->local ? "(local)" : client->hostname);
if (WaitForSingleObject(context->updateEvent, 0) == 0)
{
ResetEvent(context->updateEvent);
ReleaseSemaphore(wfi->updateSemaphore, 1, NULL);
}
wf_update_peer_deactivate(wfi, context);
client->Disconnect(client);
freerdp_peer_context_free(client);
freerdp_peer_free(client);
return 0;
}

View File

@ -54,8 +54,9 @@ static void wf_peer_rdpsnd_activated(RdpsndServerContext* context)
wfi = wf_info_get_instance(); wfi = wf_info_get_instance();
wfi->agreed_format = NULL; wfi->agreed_format = NULL;
DEBUG_WARN("Client supports the following %d formats: \n", context->num_client_formats); WLog_DBG(TAG, "Client supports the following %d formats:", context->num_client_formats);
for(i = 0; i < context->num_client_formats; i++)
for (i = 0; i < context->num_client_formats; i++)
{ {
//TODO: improve the way we agree on a format //TODO: improve the way we agree on a format
for (j = 0; j < context->num_server_formats; j++) for (j = 0; j < context->num_server_formats; j++)
@ -64,7 +65,7 @@ static void wf_peer_rdpsnd_activated(RdpsndServerContext* context)
(context->client_formats[i].nChannels == context->server_formats[j].nChannels) && (context->client_formats[i].nChannels == context->server_formats[j].nChannels) &&
(context->client_formats[i].nSamplesPerSec == context->server_formats[j].nSamplesPerSec)) (context->client_formats[i].nSamplesPerSec == context->server_formats[j].nSamplesPerSec))
{ {
DEBUG_WARN("agreed on format!\n"); WLog_DBG(TAG, "agreed on format!");
wfi->agreed_format = (AUDIO_FORMAT*) &context->server_formats[j]; wfi->agreed_format = (AUDIO_FORMAT*) &context->server_formats[j];
break; break;
} }
@ -76,7 +77,7 @@ static void wf_peer_rdpsnd_activated(RdpsndServerContext* context)
if (wfi->agreed_format == NULL) if (wfi->agreed_format == NULL)
{ {
DEBUG_WARN("Could not agree on a audio format with the server\n"); WLog_ERR(TAG, "Could not agree on a audio format with the server");
return; return;
} }
@ -116,7 +117,7 @@ int wf_rdpsnd_lock()
break; break;
case WAIT_FAILED: case WAIT_FAILED:
DEBUG_WARN("wf_rdpsnd_lock failed with 0x%08X\n", GetLastError()); WLog_ERR(TAG, "wf_rdpsnd_lock failed with 0x%08X", GetLastError());
return -1; return -1;
break; break;
} }
@ -132,7 +133,7 @@ int wf_rdpsnd_unlock()
if (ReleaseMutex(wfi->snd_mutex) == 0) if (ReleaseMutex(wfi->snd_mutex) == 0)
{ {
DEBUG_WARN("wf_rdpsnd_unlock failed with 0x%08X\n", GetLastError()); WLog_DBG(TAG, "wf_rdpsnd_unlock failed with 0x%08X", GetLastError());
return -1; return -1;
} }

View File

@ -62,8 +62,7 @@ DWORD WINAPI wf_update_thread(LPVOID lpParam)
if (wf_info_have_updates(wfi)) if (wf_info_have_updates(wfi))
{ {
wf_update_encode(wfi); wf_update_encode(wfi);
//WLog_DBG(TAG, "Start of parallel sending");
//printf("Start of parallel sending\n");
index = 0; index = 0;
for (peerindex = 0; peerindex < wfi->peerCount; peerindex++) for (peerindex = 0; peerindex < wfi->peerCount; peerindex++)
{ {
@ -71,7 +70,7 @@ DWORD WINAPI wf_update_thread(LPVOID lpParam)
{ {
if (wfi->peers[index] && wfi->peers[index]->activated) if (wfi->peers[index] && wfi->peers[index]->activated)
{ {
//printf("Setting event for %d of %d\n", index + 1, wfi->activePeerCount); //WLog_DBG(TAG, "Setting event for %d of %d", index + 1, wfi->activePeerCount);
SetEvent(((wfPeerContext*) wfi->peers[index]->context)->updateEvent); SetEvent(((wfPeerContext*) wfi->peers[index]->context)->updateEvent);
} }
} }
@ -80,13 +79,12 @@ DWORD WINAPI wf_update_thread(LPVOID lpParam)
for (index = 0; index < wfi->activePeerCount; index++) for (index = 0; index < wfi->activePeerCount; index++)
{ {
//printf("Waiting for %d of %d\n", index + 1, wfi->activePeerCount); //WLog_DBG(TAG, "Waiting for %d of %d", index + 1, wfi->activePeerCount);
//WaitForSingleObject(wfi->updateSemaphore, INFINITE); //WaitForSingleObject(wfi->updateSemaphore, INFINITE);
WaitForSingleObject(wfi->updateSemaphore, 1000); WaitForSingleObject(wfi->updateSemaphore, 1000);
} }
//printf("End of parallel sending\n"); //WLog_DBG(TAG, "End of parallel sending");
wf_info_clear_invalid_region(wfi); wf_info_clear_invalid_region(wfi);
} }
} }
@ -103,8 +101,7 @@ DWORD WINAPI wf_update_thread(LPVOID lpParam)
} }
} }
//printf("Exiting Update Thread\n"); //WLog_DBG(TAG, "Exiting Update Thread");
return 0; return 0;
} }
@ -129,9 +126,7 @@ void wf_update_encode(wfInfo* wfi)
rect.y = 0; rect.y = 0;
rect.width = (UINT16) width; rect.width = (UINT16) width;
rect.height = (UINT16) height; rect.height = (UINT16) height;
//WLog_DBG(TAG, "x:%d y:%d w:%d h:%d", wfi->invalid.left, wfi->invalid.top, width, height);
//printf("x:%d y:%d w:%d h:%d\n", wfi->invalid.left, wfi->invalid.top, width, height);
Stream_Clear(wfi->s); Stream_Clear(wfi->s);
rfx_compose_message(wfi->rfx_context, wfi->s, &rect, 1, rfx_compose_message(wfi->rfx_context, wfi->s, &rect, 1,
@ -175,9 +170,8 @@ void wf_update_peer_send(wfInfo* wfi, wfPeerContext* context)
return; return;
/* This is an unexpected error condition */ /* This is an unexpected error condition */
WLog_DBG(TAG, "Unexpected Frame Index: Actual: %d Expected: %d",
DEBUG_WARN("Unexpected Frame Index: Actual: %d Expected: %d\n", wfi->frame_idx, context->frame_idx + 1);
wfi->frame_idx, context->frame_idx + 1);
} }
wfi->cmd.codecID = client->settings->RemoteFxCodecId; wfi->cmd.codecID = client->settings->RemoteFxCodecId;
@ -189,7 +183,7 @@ void wf_update_encoder_reset(wfInfo* wfi)
{ {
if (wf_info_lock(wfi) > 0) if (wf_info_lock(wfi) > 0)
{ {
DEBUG_WARN("Resetting encoder\n"); WLog_DBG(TAG, "Resetting encoder");
if (wfi->rfx_context) if (wfi->rfx_context)
{ {
@ -225,9 +219,7 @@ void wf_update_peer_activate(wfInfo* wfi, wfPeerContext* context)
wf_update_encoder_reset(wfi); wf_update_encoder_reset(wfi);
wfi->activePeerCount++; wfi->activePeerCount++;
WLog_DBG(TAG, "Activating Peer Updates: %d", wfi->activePeerCount);
DEBUG_WARN("Activating Peer Updates: %d\n", wfi->activePeerCount);
wf_info_unlock(wfi); wf_info_unlock(wfi);
} }
} }
@ -247,8 +239,7 @@ void wf_update_peer_deactivate(wfInfo* wfi, wfPeerContext* context)
client->activated = FALSE; client->activated = FALSE;
wfi->activePeerCount--; wfi->activePeerCount--;
WLog_DBG(TAG, "Deactivating Peer Updates: %d", wfi->activePeerCount);
DEBUG_WARN("Deactivating Peer Updates: %d\n", wfi->activePeerCount);
} }
wf_info_unlock(wfi); wf_info_unlock(wfi);

View File

@ -41,12 +41,11 @@ int wf_wasapi_activate(RdpsndServerContext* context)
if (devStr == NULL) if (devStr == NULL)
{ {
_tprintf(_T("Failed to match for output device! Disabling rdpsnd.\n")); WLog_ERR(TAG, "Failed to match for output device! Disabling rdpsnd.");
return 1; return 1;
} }
DEBUG_WARN("RDPSND (WASAPI) Activated\n"); WLog_DBG(TAG, "RDPSND (WASAPI) Activated");
CreateThread(NULL, 0, wf_rdpsnd_wasapi_thread, latestPeer, 0, NULL); CreateThread(NULL, 0, wf_rdpsnd_wasapi_thread, latestPeer, 0, NULL);
return 0; return 0;
@ -66,23 +65,23 @@ int wf_wasapi_get_device_string(LPWSTR pattern, LPWSTR * deviceStr)
hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, &IID_IMMDeviceEnumerator, (void **) &pEnumerator); hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, &IID_IMMDeviceEnumerator, (void **) &pEnumerator);
if (FAILED(hr)) if (FAILED(hr))
{ {
_tprintf(_T("Failed to cocreate device enumerator\n")); WLog_ERR(TAG, "Failed to cocreate device enumerator");
exit(1); exit(1);
} }
hr = pEnumerator->lpVtbl->EnumAudioEndpoints(pEnumerator, eCapture, DEVICE_STATE_ACTIVE, &pCollection); hr = pEnumerator->lpVtbl->EnumAudioEndpoints(pEnumerator, eCapture, DEVICE_STATE_ACTIVE, &pCollection);
if ( FAILED(hr) ) if ( FAILED(hr) )
{ {
_tprintf(_T("Failed to create endpoint collection\n")); WLog_ERR(TAG, "Failed to create endpoint collection");
exit(1); exit(1);
} }
pCollection->lpVtbl->GetCount(pCollection, &count); pCollection->lpVtbl->GetCount(pCollection, &count);
_tprintf(_T("Num endpoints: %d\n"), count); WLog_INFO(TAG, "Num endpoints: %d", count);
if (count == 0) if (count == 0)
{ {
_tprintf(_T("No endpoints!\n")); WLog_ERR(TAG, "No endpoints!");
exit(1); exit(1);
} }
@ -94,28 +93,28 @@ int wf_wasapi_get_device_string(LPWSTR pattern, LPWSTR * deviceStr)
hr = pCollection->lpVtbl->Item(pCollection, i, &pEndpoint); hr = pCollection->lpVtbl->Item(pCollection, i, &pEndpoint);
if ( FAILED(hr) ) if ( FAILED(hr) )
{ {
_tprintf(_T("Failed to get endpoint %d\n"), i); WLog_ERR(TAG, "Failed to get endpoint %d", i);
exit(1); exit(1);
} }
hr = pEndpoint->lpVtbl->GetId(pEndpoint, &pwszID); hr = pEndpoint->lpVtbl->GetId(pEndpoint, &pwszID);
if ( FAILED(hr) ) if ( FAILED(hr) )
{ {
_tprintf(_T("Failed to get endpoint ID\n")); WLog_ERR(TAG, "Failed to get endpoint ID");
exit(1); exit(1);
} }
hr = pEndpoint->lpVtbl->OpenPropertyStore(pEndpoint, STGM_READ, &pProps); hr = pEndpoint->lpVtbl->OpenPropertyStore(pEndpoint, STGM_READ, &pProps);
if ( FAILED(hr) ) if ( FAILED(hr) )
{ {
_tprintf(_T("Failed to open property store\n")); WLog_ERR(TAG, "Failed to open property store");
exit(1); exit(1);
} }
hr = pProps->lpVtbl->GetValue(pProps, &PKEY_Device_FriendlyName, &nameVar); hr = pProps->lpVtbl->GetValue(pProps, &PKEY_Device_FriendlyName, &nameVar);
if ( FAILED(hr) ) if ( FAILED(hr) )
{ {
_tprintf(_T("Failed to get device friendly name\n")); WLog_ERR(TAG, "Failed to get device friendly name");
exit(1); exit(1);
} }
@ -123,9 +122,8 @@ int wf_wasapi_get_device_string(LPWSTR pattern, LPWSTR * deviceStr)
if (wcscmp(pattern, nameVar.pwszVal) < 0) if (wcscmp(pattern, nameVar.pwszVal) < 0)
{ {
unsigned int devStrLen; unsigned int devStrLen;
_tprintf(_T("Using sound ouput endpoint: [%s] (%s)\n"), nameVar.pwszVal, pwszID); WLog_INFO(TAG, "Using sound ouput endpoint: [%s] (%s)", nameVar.pwszVal, pwszID);
//_tprintf(_T("matched %d characters\n"), wcscmp(pattern, nameVar.pwszVal)); //WLog_INFO(TAG, "matched %d characters", wcscmp(pattern, nameVar.pwszVal);
devStrLen = wcslen(pwszID); devStrLen = wcslen(pwszID);
*deviceStr = (LPWSTR) malloc((devStrLen * 2) + 2); *deviceStr = (LPWSTR) malloc((devStrLen * 2) + 2);
ZeroMemory(*deviceStr, (devStrLen * 2) + 2); ZeroMemory(*deviceStr, (devStrLen * 2) + 2);
@ -179,28 +177,28 @@ DWORD WINAPI wf_rdpsnd_wasapi_thread(LPVOID lpParam)
hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, &IID_IMMDeviceEnumerator, (void **) &pEnumerator); hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL, &IID_IMMDeviceEnumerator, (void **) &pEnumerator);
if (FAILED(hr)) if (FAILED(hr))
{ {
_tprintf(_T("Failed to cocreate device enumerator\n")); WLog_ERR(TAG, "Failed to cocreate device enumerator");
exit(1); exit(1);
} }
hr = pEnumerator->lpVtbl->GetDevice(pEnumerator, devStr, &pDevice); hr = pEnumerator->lpVtbl->GetDevice(pEnumerator, devStr, &pDevice);
if (FAILED(hr)) if (FAILED(hr))
{ {
_tprintf(_T("Failed to cocreate get device\n")); WLog_ERR(TAG, "Failed to cocreate get device");
exit(1); exit(1);
} }
hr = pDevice->lpVtbl->Activate(pDevice, &IID_IAudioClient, CLSCTX_ALL, NULL, (void **)&pAudioClient); hr = pDevice->lpVtbl->Activate(pDevice, &IID_IAudioClient, CLSCTX_ALL, NULL, (void **)&pAudioClient);
if (FAILED(hr)) if (FAILED(hr))
{ {
_tprintf(_T("Failed to activate audio client\n")); WLog_ERR(TAG, "Failed to activate audio client");
exit(1); exit(1);
} }
hr = pAudioClient->lpVtbl->GetMixFormat(pAudioClient, &pwfx); hr = pAudioClient->lpVtbl->GetMixFormat(pAudioClient, &pwfx);
if (FAILED(hr)) if (FAILED(hr))
{ {
_tprintf(_T("Failed to get mix format\n")); WLog_ERR(TAG, "Failed to get mix format");
exit(1); exit(1);
} }
@ -218,21 +216,21 @@ DWORD WINAPI wf_rdpsnd_wasapi_thread(LPVOID lpParam)
if (FAILED(hr)) if (FAILED(hr))
{ {
_tprintf(_T("Failed to initialize the audio client\n")); WLog_ERR(TAG, "Failed to initialize the audio client");
exit(1); exit(1);
} }
hr = pAudioClient->lpVtbl->GetBufferSize(pAudioClient, &bufferFrameCount); hr = pAudioClient->lpVtbl->GetBufferSize(pAudioClient, &bufferFrameCount);
if (FAILED(hr)) if (FAILED(hr))
{ {
_tprintf(_T("Failed to get buffer size\n")); WLog_ERR(TAG, "Failed to get buffer size");
exit(1); exit(1);
} }
hr = pAudioClient->lpVtbl->GetService(pAudioClient, &IID_IAudioCaptureClient, (void **) &pCaptureClient); hr = pAudioClient->lpVtbl->GetService(pAudioClient, &IID_IAudioCaptureClient, (void **) &pCaptureClient);
if (FAILED(hr)) if (FAILED(hr))
{ {
_tprintf(_T("Failed to get the capture client\n")); WLog_ERR(TAG, "Failed to get the capture client");
exit(1); exit(1);
} }
@ -241,12 +239,13 @@ DWORD WINAPI wf_rdpsnd_wasapi_thread(LPVOID lpParam)
hr = pAudioClient->lpVtbl->Start(pAudioClient); hr = pAudioClient->lpVtbl->Start(pAudioClient);
if (FAILED(hr)) if (FAILED(hr))
{ {
_tprintf(_T("Failed to start capture\n")); WLog_ERR(TAG, "Failed to start capture");
exit(1); exit(1);
} }
dCount = 0; dCount = 0;
while(wfi->snd_stop == FALSE)
while (wfi->snd_stop == FALSE)
{ {
DWORD flags; DWORD flags;
@ -255,7 +254,7 @@ DWORD WINAPI wf_rdpsnd_wasapi_thread(LPVOID lpParam)
hr = pCaptureClient->lpVtbl->GetNextPacketSize(pCaptureClient, &packetLength); hr = pCaptureClient->lpVtbl->GetNextPacketSize(pCaptureClient, &packetLength);
if (FAILED(hr)) if (FAILED(hr))
{ {
_tprintf(_T("Failed to get packet length\n")); WLog_ERR(TAG, "Failed to get packet length");
exit(1); exit(1);
} }
@ -264,7 +263,7 @@ DWORD WINAPI wf_rdpsnd_wasapi_thread(LPVOID lpParam)
hr = pCaptureClient->lpVtbl->GetBuffer(pCaptureClient, &pData, &numFramesAvailable, &flags, NULL, NULL); hr = pCaptureClient->lpVtbl->GetBuffer(pCaptureClient, &pData, &numFramesAvailable, &flags, NULL, NULL);
if (FAILED(hr)) if (FAILED(hr))
{ {
_tprintf(_T("Failed to get buffer\n")); WLog_ERR(TAG, "Failed to get buffer");
exit(1); exit(1);
} }
@ -276,14 +275,14 @@ DWORD WINAPI wf_rdpsnd_wasapi_thread(LPVOID lpParam)
hr = pCaptureClient->lpVtbl->ReleaseBuffer(pCaptureClient, numFramesAvailable); hr = pCaptureClient->lpVtbl->ReleaseBuffer(pCaptureClient, numFramesAvailable);
if (FAILED(hr)) if (FAILED(hr))
{ {
_tprintf(_T("Failed to release buffer\n")); WLog_ERR(TAG, "Failed to release buffer");
exit(1); exit(1);
} }
hr = pCaptureClient->lpVtbl->GetNextPacketSize(pCaptureClient, &packetLength); hr = pCaptureClient->lpVtbl->GetNextPacketSize(pCaptureClient, &packetLength);
if (FAILED(hr)) if (FAILED(hr))
{ {
_tprintf(_T("Failed to get packet length\n")); WLog_ERR(TAG, "Failed to get packet length");
exit(1); exit(1);
} }
} }
@ -292,7 +291,7 @@ DWORD WINAPI wf_rdpsnd_wasapi_thread(LPVOID lpParam)
pAudioClient->lpVtbl->Stop(pAudioClient); pAudioClient->lpVtbl->Stop(pAudioClient);
if (FAILED(hr)) if (FAILED(hr))
{ {
_tprintf(_T("Failed to stop audio client\n")); WLog_ERR(TAG, "Failed to stop audio client");
exit(1); exit(1);
} }

View File

@ -22,9 +22,12 @@
#include <winpr/crt.h> #include <winpr/crt.h>
#include <winpr/print.h> #include <winpr/print.h>
#include <freerdp/log.h>
#include "win_dxgi.h" #include "win_dxgi.h"
#define TAG SERVER_TAG("shadow.win")
#ifdef WITH_DXGI_1_2 #ifdef WITH_DXGI_1_2
static D3D_DRIVER_TYPE DriverTypes[] = static D3D_DRIVER_TYPE DriverTypes[] =
@ -247,7 +250,7 @@ int win_shadow_dxgi_init_duplication(winShadowSubsystem* subsystem)
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "ID3D11Device::QueryInterface(IDXGIDevice) failure: %s (0x%04X)\n", WLog_ERR(TAG, "ID3D11Device::QueryInterface(IDXGIDevice) failure: %s (0x%04X)",
GetDxgiErrorString(hr), hr); GetDxgiErrorString(hr), hr);
return -1; return -1;
} }
@ -262,7 +265,7 @@ int win_shadow_dxgi_init_duplication(winShadowSubsystem* subsystem)
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "IDXGIDevice::GetParent(IDXGIAdapter) failure: %s (0x%04X)\n", WLog_ERR(TAG, "IDXGIDevice::GetParent(IDXGIAdapter) failure: %s (0x%04X)",
GetDxgiErrorString(hr), hr); GetDxgiErrorString(hr), hr);
return -1; return -1;
} }
@ -278,7 +281,7 @@ int win_shadow_dxgi_init_duplication(winShadowSubsystem* subsystem)
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "IDXGIOutput::GetDesc failure: %s (0x%04X)\n", WLog_ERR(TAG, "IDXGIOutput::GetDesc failure: %s (0x%04X)",
GetDxgiErrorString(hr), hr); GetDxgiErrorString(hr), hr);
return -1; return -1;
} }
@ -302,7 +305,7 @@ int win_shadow_dxgi_init_duplication(winShadowSubsystem* subsystem)
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "IDXGIAdapter::EnumOutputs failure: %s (0x%04X)\n", WLog_ERR(TAG, "IDXGIAdapter::EnumOutputs failure: %s (0x%04X)",
GetDxgiErrorString(hr), hr); GetDxgiErrorString(hr), hr);
return -1; return -1;
} }
@ -317,7 +320,7 @@ int win_shadow_dxgi_init_duplication(winShadowSubsystem* subsystem)
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "IDXGIOutput::QueryInterface(IDXGIOutput1) failure: %s (0x%04X)\n", WLog_ERR(TAG, "IDXGIOutput::QueryInterface(IDXGIOutput1) failure: %s (0x%04X)",
GetDxgiErrorString(hr), hr); GetDxgiErrorString(hr), hr);
return -1; return -1;
} }
@ -333,7 +336,7 @@ int win_shadow_dxgi_init_duplication(winShadowSubsystem* subsystem)
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "IDXGIOutput1::DuplicateOutput failure: %s (0x%04X)\n", WLog_ERR(TAG, "IDXGIOutput1::DuplicateOutput failure: %s (0x%04X)",
GetDxgiErrorString(hr), hr); GetDxgiErrorString(hr), hr);
return -1; return -1;
} }
@ -355,7 +358,7 @@ int win_shadow_dxgi_init_duplication(winShadowSubsystem* subsystem)
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "ID3D11Device::CreateTexture2D failure: %s (0x%04X)\n", WLog_ERR(TAG, "ID3D11Device::CreateTexture2D failure: %s (0x%04X)",
GetDxgiErrorString(hr), hr); GetDxgiErrorString(hr), hr);
return -1; return -1;
} }
@ -391,7 +394,7 @@ int win_shadow_dxgi_init(winShadowSubsystem* subsystem)
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "D3D11CreateDevice failure: 0x%04X\n", hr); WLog_ERR(TAG, "D3D11CreateDevice failure: 0x%04X", hr);
return -1; return -1;
} }
@ -461,7 +464,7 @@ int win_shadow_dxgi_fetch_frame_data(winShadowSubsystem* subsystem,
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "ID3D11Texture2D::QueryInterface(IDXGISurface) failure: %s 0x%04X\n", WLog_ERR(TAG, "ID3D11Texture2D::QueryInterface(IDXGISurface) failure: %s 0x%04X",
GetDxgiErrorString(hr), hr); GetDxgiErrorString(hr), hr);
return -1; return -1;
} }
@ -470,7 +473,7 @@ int win_shadow_dxgi_fetch_frame_data(winShadowSubsystem* subsystem,
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "IDXGISurface::Map failure: %s 0x%04X\n", WLog_ERR(TAG, "IDXGISurface::Map failure: %s 0x%04X",
GetDxgiErrorString(hr), hr); GetDxgiErrorString(hr), hr);
if (hr == DXGI_ERROR_DEVICE_REMOVED) if (hr == DXGI_ERROR_DEVICE_REMOVED)
@ -558,7 +561,7 @@ int win_shadow_dxgi_get_next_frame(winShadowSubsystem* subsystem)
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "IDXGIOutputDuplication::AcquireNextFrame failure: %s (0x%04X)\n", WLog_ERR(TAG, "IDXGIOutputDuplication::AcquireNextFrame failure: %s (0x%04X)",
GetDxgiErrorString(hr), hr); GetDxgiErrorString(hr), hr);
if (hr == DXGI_ERROR_ACCESS_LOST) if (hr == DXGI_ERROR_ACCESS_LOST)
@ -610,7 +613,7 @@ int win_shadow_dxgi_get_next_frame(winShadowSubsystem* subsystem)
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "IDXGIResource::QueryInterface(ID3D11Texture2D) failure: %s (0x%04X)\n", WLog_ERR(TAG, "IDXGIResource::QueryInterface(ID3D11Texture2D) failure: %s (0x%04X)",
GetDxgiErrorString(hr), hr); GetDxgiErrorString(hr), hr);
return -1; return -1;
} }
@ -666,7 +669,7 @@ int win_shadow_dxgi_get_invalid_region(winShadowSubsystem* subsystem)
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "IDXGIOutputDuplication::GetFrameMoveRects failure: %s (0x%04X) Size: %d Total %d Used: %d\n", WLog_ERR(TAG, "IDXGIOutputDuplication::GetFrameMoveRects failure: %s (0x%04X) Size: %d Total %d Used: %d",
GetDxgiErrorString(hr), hr, MoveRectsBufferSize, MetadataBufferSize, UsedBufferSize); GetDxgiErrorString(hr), hr, MoveRectsBufferSize, MetadataBufferSize, UsedBufferSize);
return -1; return -1;
} }
@ -683,7 +686,7 @@ int win_shadow_dxgi_get_invalid_region(winShadowSubsystem* subsystem)
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "IDXGIOutputDuplication::GetFrameDirtyRects failure: %s (0x%04X) Size: %d Total %d Used: %d\n", WLog_ERR(TAG, "IDXGIOutputDuplication::GetFrameDirtyRects failure: %s (0x%04X) Size: %d Total %d Used: %d",
GetDxgiErrorString(hr), hr, DirtyRectsBufferSize, MetadataBufferSize, UsedBufferSize); GetDxgiErrorString(hr), hr, DirtyRectsBufferSize, MetadataBufferSize, UsedBufferSize);
return -1; return -1;
} }

View File

@ -22,21 +22,24 @@
#include <winpr/crt.h> #include <winpr/crt.h>
#include <winpr/print.h> #include <winpr/print.h>
#include <freerdp/log.h>
#include "win_rdp.h" #include "win_rdp.h"
#define TAG SERVER_TAG("shadow.win")
void shw_OnChannelConnectedEventHandler(rdpContext* context, ChannelConnectedEventArgs* e) void shw_OnChannelConnectedEventHandler(rdpContext* context, ChannelConnectedEventArgs* e)
{ {
shwContext* shw = (shwContext*) context; shwContext* shw = (shwContext*) context;
printf("OnChannelConnected: %s\n", e->name); WLog_INFO(TAG, "OnChannelConnected: %s", e->name);
} }
void shw_OnChannelDisconnectedEventHandler(rdpContext* context, ChannelDisconnectedEventArgs* e) void shw_OnChannelDisconnectedEventHandler(rdpContext* context, ChannelDisconnectedEventArgs* e)
{ {
shwContext* shw = (shwContext*) context; shwContext* shw = (shwContext*) context;
printf("OnChannelDisconnected: %s\n", e->name); WLog_INFO(TAG, "OnChannelDisconnected: %s", e->name);
} }
void shw_begin_paint(rdpContext* context) void shw_begin_paint(rdpContext* context)
@ -106,7 +109,7 @@ int shw_verify_x509_certificate(freerdp* instance, BYTE* data, int length, const
void shw_OnConnectionResultEventHandler(rdpContext* context, ConnectionResultEventArgs* e) void shw_OnConnectionResultEventHandler(rdpContext* context, ConnectionResultEventArgs* e)
{ {
shwContext* shw = (shwContext*) context; shwContext* shw = (shwContext*) context;
printf("OnConnectionResult: %d\n", e->result); WLog_INFO(TAG, "OnConnectionResult: %d", e->result);
} }
BOOL shw_pre_connect(freerdp* instance) BOOL shw_pre_connect(freerdp* instance)
@ -177,7 +180,7 @@ void* shw_client_thread(void* arg)
bSuccess = freerdp_connect(instance); bSuccess = freerdp_connect(instance);
printf("freerdp_connect: %d\n", bSuccess); WLog_INFO(TAG, "freerdp_connect: %d", bSuccess);
if (!bSuccess) if (!bSuccess)
{ {
@ -194,13 +197,13 @@ void* shw_client_thread(void* arg)
if (!freerdp_get_fds(instance, rfds, &rcount, wfds, &wcount)) if (!freerdp_get_fds(instance, rfds, &rcount, wfds, &wcount))
{ {
fprintf(stderr, "Failed to get FreeRDP file descriptor\n"); WLog_ERR(TAG, "Failed to get FreeRDP file descriptor");
break; break;
} }
if (!freerdp_channels_get_fds(channels, instance, rfds, &rcount, wfds, &wcount)) if (!freerdp_channels_get_fds(channels, instance, rfds, &rcount, wfds, &wcount))
{ {
fprintf(stderr, "Failed to get channels file descriptor\n"); WLog_ERR(TAG, "Failed to get channels file descriptor");
break; break;
} }
@ -214,13 +217,13 @@ void* shw_client_thread(void* arg)
if (MsgWaitForMultipleObjects(fds_count, fds, FALSE, 1000, QS_ALLINPUT) == WAIT_FAILED) if (MsgWaitForMultipleObjects(fds_count, fds, FALSE, 1000, QS_ALLINPUT) == WAIT_FAILED)
{ {
fprintf(stderr, "MsgWaitForMultipleObjects failure: 0x%08X", GetLastError()); WLog_ERR(TAG, "MsgWaitForMultipleObjects failure: 0x%08X", GetLastError());
break; break;
} }
if (!freerdp_check_fds(instance)) if (!freerdp_check_fds(instance))
{ {
fprintf(stderr, "Failed to check FreeRDP file descriptor\n"); WLog_ERR(TAG, "Failed to check FreeRDP file descriptor");
break; break;
} }
@ -231,7 +234,7 @@ void* shw_client_thread(void* arg)
if (!freerdp_channels_check_fds(channels, instance)) if (!freerdp_channels_check_fds(channels, instance))
{ {
fprintf(stderr, "Failed to check channels file descriptor\n"); WLog_ERR(TAG, "Failed to check channels file descriptor");
break; break;
} }
} }

View File

@ -22,6 +22,7 @@
#include <freerdp/codec/color.h> #include <freerdp/codec/color.h>
#include <freerdp/codec/region.h> #include <freerdp/codec/region.h>
#include <freerdp/log.h>
#include "../shadow_screen.h" #include "../shadow_screen.h"
#include "../shadow_surface.h" #include "../shadow_surface.h"
@ -29,6 +30,8 @@
#include "win_shadow.h" #include "win_shadow.h"
#define TAG SERVER_TAG("shadow.win")
void win_shadow_input_synchronize_event(winShadowSubsystem* subsystem, UINT32 flags) void win_shadow_input_synchronize_event(winShadowSubsystem* subsystem, UINT32 flags)
{ {
@ -252,7 +255,7 @@ int win_shadow_surface_copy(winShadowSubsystem* subsystem)
height = surface->height; height = surface->height;
} }
printf("SurfaceCopy x: %d y: %d width: %d height: %d right: %d bottom: %d\n", WLog_INFO(TAG, "SurfaceCopy x: %d y: %d width: %d height: %d right: %d bottom: %d",
x, y, width, height, x + width, y + height); x, y, width, height, x + width, y + height);
#if defined(WITH_WDS_API) #if defined(WITH_WDS_API)
@ -441,7 +444,7 @@ int win_shadow_subsystem_init(winShadowSubsystem* subsystem)
subsystem->monitors[0].flags = 1; subsystem->monitors[0].flags = 1;
} }
printf("width: %d height: %d\n", subsystem->width, subsystem->height); WLog_INFO(TAG, "width: %d height: %d", subsystem->width, subsystem->height);
return 1; return 1;
} }

View File

@ -22,6 +22,7 @@
#include <winpr/crt.h> #include <winpr/crt.h>
#include <winpr/print.h> #include <winpr/print.h>
#include <freerdp/log.h>
#include "win_rdp.h" #include "win_rdp.h"
@ -46,6 +47,8 @@
#include <initguid.h> #include <initguid.h>
#define TAG SERVER_TAG("shadow.win")
DEFINE_GUID(CLSID_RDPSession,0x9B78F0E6,0x3E05,0x4A5B,0xB2,0xE8,0xE7,0x43,0xA8,0x95,0x6B,0x65); DEFINE_GUID(CLSID_RDPSession,0x9B78F0E6,0x3E05,0x4A5B,0xB2,0xE8,0xE7,0x43,0xA8,0x95,0x6B,0x65);
DEFINE_GUID(DIID__IRDPSessionEvents,0x98a97042,0x6698,0x40e9,0x8e,0xfd,0xb3,0x20,0x09,0x90,0x00,0x4b); DEFINE_GUID(DIID__IRDPSessionEvents,0x98a97042,0x6698,0x40e9,0x8e,0xfd,0xb3,0x20,0x09,0x90,0x00,0x4b);
DEFINE_GUID(IID_IRDPSRAPISharingSession,0xeeb20886,0xe470,0x4cf6,0x84,0x2b,0x27,0x39,0xc0,0xec,0x5c,0xfb); DEFINE_GUID(IID_IRDPSRAPISharingSession,0xeeb20886,0xe470,0x4cf6,0x84,0x2b,0x27,0x39,0xc0,0xec,0x5c,0xfb);
@ -213,7 +216,7 @@ static HRESULT STDMETHODCALLTYPE Shadow_IRDPSessionEvents_GetTypeInfoCount(
__RPC__in _IRDPSessionEvents * This, __RPC__in _IRDPSessionEvents * This,
/* [out] */ __RPC__out UINT *pctinfo) /* [out] */ __RPC__out UINT *pctinfo)
{ {
printf("Shadow_IRDPSessionEvents_GetTypeInfoCount\n"); WLog_INFO(TAG, "Shadow_IRDPSessionEvents_GetTypeInfoCount");
*pctinfo = 1; *pctinfo = 1;
return S_OK; return S_OK;
} }
@ -224,7 +227,7 @@ static HRESULT STDMETHODCALLTYPE Shadow_IRDPSessionEvents_GetTypeInfo(
/* [in] */ LCID lcid, /* [in] */ LCID lcid,
/* [out] */ __RPC__deref_out_opt ITypeInfo **ppTInfo) /* [out] */ __RPC__deref_out_opt ITypeInfo **ppTInfo)
{ {
printf("Shadow_IRDPSessionEvents_GetTypeInfo\n"); WLog_INFO(TAG, "Shadow_IRDPSessionEvents_GetTypeInfo");
return E_NOTIMPL; return E_NOTIMPL;
} }
@ -236,7 +239,7 @@ static HRESULT STDMETHODCALLTYPE Shadow_IRDPSessionEvents_GetIDsOfNames(
/* [in] */ LCID lcid, /* [in] */ LCID lcid,
/* [size_is][out] */ __RPC__out_ecount_full(cNames) DISPID *rgDispId) /* [size_is][out] */ __RPC__out_ecount_full(cNames) DISPID *rgDispId)
{ {
printf("Shadow_IRDPSessionEvents_GetIDsOfNames\n"); WLog_INFO(TAG, "Shadow_IRDPSessionEvents_GetIDsOfNames");
return E_NOTIMPL; return E_NOTIMPL;
} }
@ -263,7 +266,7 @@ static HRESULT STDMETHODCALLTYPE Shadow_IRDPSessionEvents_Invoke(
VARIANT vr; VARIANT vr;
UINT uArgErr; UINT uArgErr;
printf("%s (%d)\n", GetRDPSessionEventString(dispIdMember), dispIdMember); WLog_INFO(TAG, "%s (%d)", GetRDPSessionEventString(dispIdMember), dispIdMember);
switch (dispIdMember) switch (dispIdMember)
{ {
@ -280,7 +283,7 @@ static HRESULT STDMETHODCALLTYPE Shadow_IRDPSessionEvents_Invoke(
if (FAILED(hr)) if (FAILED(hr))
{ {
printf("%s DispGetParam(0, VT_DISPATCH) failure: 0x%08X\n", WLog_INFO(TAG, "%s DispGetParam(0, VT_DISPATCH) failure: 0x%08X",
GetRDPSessionEventString(dispIdMember), hr); GetRDPSessionEventString(dispIdMember), hr);
return hr; return hr;
} }
@ -291,7 +294,7 @@ static HRESULT STDMETHODCALLTYPE Shadow_IRDPSessionEvents_Invoke(
if (FAILED(hr)) if (FAILED(hr))
{ {
printf("%s IDispatch::QueryInterface(IRDPSRAPIAttendee) failure: 0x%08X\n", WLog_INFO(TAG, "%s IDispatch::QueryInterface(IRDPSRAPIAttendee) failure: 0x%08X",
GetRDPSessionEventString(dispIdMember), hr); GetRDPSessionEventString(dispIdMember), hr);
return hr; return hr;
} }
@ -303,7 +306,7 @@ static HRESULT STDMETHODCALLTYPE Shadow_IRDPSessionEvents_Invoke(
if (FAILED(hr)) if (FAILED(hr))
{ {
printf("%s IRDPSRAPIAttendee::put_ControlLevel() failure: 0x%08X\n", WLog_INFO(TAG, "%s IRDPSRAPIAttendee::put_ControlLevel() failure: 0x%08X",
GetRDPSessionEventString(dispIdMember), hr); GetRDPSessionEventString(dispIdMember), hr);
return hr; return hr;
} }
@ -346,7 +349,7 @@ static HRESULT STDMETHODCALLTYPE Shadow_IRDPSessionEvents_Invoke(
if (FAILED(hr)) if (FAILED(hr))
{ {
printf("%s DispGetParam(1, VT_INT) failure: 0x%08X\n", WLog_INFO(TAG, "%s DispGetParam(1, VT_INT) failure: 0x%08X",
GetRDPSessionEventString(dispIdMember), hr); GetRDPSessionEventString(dispIdMember), hr);
return hr; return hr;
} }
@ -360,7 +363,7 @@ static HRESULT STDMETHODCALLTYPE Shadow_IRDPSessionEvents_Invoke(
if (FAILED(hr)) if (FAILED(hr))
{ {
printf("%s DispGetParam(0, VT_DISPATCH) failure: 0x%08X\n", WLog_INFO(TAG, "%s DispGetParam(0, VT_DISPATCH) failure: 0x%08X",
GetRDPSessionEventString(dispIdMember), hr); GetRDPSessionEventString(dispIdMember), hr);
return hr; return hr;
} }
@ -371,7 +374,7 @@ static HRESULT STDMETHODCALLTYPE Shadow_IRDPSessionEvents_Invoke(
if (FAILED(hr)) if (FAILED(hr))
{ {
printf("%s IDispatch::QueryInterface(IRDPSRAPIAttendee) failure: 0x%08X\n", WLog_INFO(TAG, "%s IDispatch::QueryInterface(IRDPSRAPIAttendee) failure: 0x%08X",
GetRDPSessionEventString(dispIdMember), hr); GetRDPSessionEventString(dispIdMember), hr);
return hr; return hr;
} }
@ -380,7 +383,7 @@ static HRESULT STDMETHODCALLTYPE Shadow_IRDPSessionEvents_Invoke(
if (FAILED(hr)) if (FAILED(hr))
{ {
printf("%s IRDPSRAPIAttendee::put_ControlLevel() failure: 0x%08X\n", WLog_INFO(TAG, "%s IRDPSRAPIAttendee::put_ControlLevel() failure: 0x%08X",
GetRDPSessionEventString(dispIdMember), hr); GetRDPSessionEventString(dispIdMember), hr);
return hr; return hr;
} }
@ -507,7 +510,7 @@ int win_shadow_wds_wnd_init(winShadowSubsystem* subsystem)
if (!RegisterClassEx(&wndClassEx)) if (!RegisterClassEx(&wndClassEx))
{ {
printf("RegisterClassEx failure\n"); WLog_INFO(TAG, "RegisterClassEx failure");
return -1; return -1;
} }
@ -518,7 +521,7 @@ int win_shadow_wds_wnd_init(winShadowSubsystem* subsystem)
if (!subsystem->hWnd) if (!subsystem->hWnd)
{ {
printf("CreateWindowEx failure\n"); WLog_INFO(TAG, "CreateWindowEx failure");
return -1; return -1;
} }
@ -551,7 +554,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem)
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "OleInitialize() failure\n"); WLog_ERR(TAG, "OleInitialize() failure");
return -1; return -1;
} }
@ -559,7 +562,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem)
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "CoInitialize() failure\n"); WLog_ERR(TAG, "CoInitialize() failure");
return -1; return -1;
} }
@ -568,7 +571,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem)
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "CoCreateInstance(IRDPSRAPISharingSession) failure: 0x%08X\n", hr); WLog_ERR(TAG, "CoCreateInstance(IRDPSRAPISharingSession) failure: 0x%08X", hr);
return -1; return -1;
} }
@ -577,7 +580,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem)
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "QueryInterface(IID_IConnectionPointContainer) failure: 0x%08X\n", hr); WLog_ERR(TAG, "QueryInterface(IID_IConnectionPointContainer) failure: 0x%08X", hr);
return -1; return -1;
} }
@ -585,7 +588,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem)
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "IConnectionPointContainer::FindConnectionPoint(_IRDPSessionEvents) failure: 0x%08X\n", hr); WLog_ERR(TAG, "IConnectionPointContainer::FindConnectionPoint(_IRDPSessionEvents) failure: 0x%08X", hr);
return -1; return -1;
} }
@ -597,7 +600,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem)
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "IConnectionPoint::Advise(Shadow_IRDPSessionEvents) failure: 0x%08X\n", hr); WLog_ERR(TAG, "IConnectionPoint::Advise(Shadow_IRDPSessionEvents) failure: 0x%08X", hr);
return -1; return -1;
} }
@ -605,7 +608,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem)
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "IRDPSRAPISharingSession::put_ColorDepth() failure: 0x%08X\n", hr); WLog_ERR(TAG, "IRDPSRAPISharingSession::put_ColorDepth() failure: 0x%08X", hr);
return -1; return -1;
} }
@ -614,14 +617,14 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem)
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "IRDPSRAPISharingSession::GetDesktopSharedRect() failure: 0x%08X\n", hr); WLog_ERR(TAG, "IRDPSRAPISharingSession::GetDesktopSharedRect() failure: 0x%08X", hr);
return -1; return -1;
} }
width = right - left; width = right - left;
height = bottom - top; height = bottom - top;
printf("GetDesktopSharedRect(): left: %d top: %d right: %d bottom: %d width: %d height: %d\n", WLog_INFO(TAG, "GetDesktopSharedRect(): left: %d top: %d right: %d bottom: %d width: %d height: %d",
left, top, right, bottom, width, height); left, top, right, bottom, width, height);
hr = subsystem->pSharingSession->lpVtbl->get_VirtualChannelManager(subsystem->pSharingSession, hr = subsystem->pSharingSession->lpVtbl->get_VirtualChannelManager(subsystem->pSharingSession,
@ -629,7 +632,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem)
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "IRDPSRAPISharingSession::get_VirtualChannelManager() failure: 0x%08X\n", hr); WLog_ERR(TAG, "IRDPSRAPISharingSession::get_VirtualChannelManager() failure: 0x%08X", hr);
return -1; return -1;
} }
@ -638,7 +641,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem)
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "IRDPSRAPISharingSession::get_ApplicationFilter() failure: 0x%08X\n", hr); WLog_ERR(TAG, "IRDPSRAPISharingSession::get_ApplicationFilter() failure: 0x%08X", hr);
return -1; return -1;
} }
@ -647,7 +650,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem)
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "IRDPSRAPISharingSession::get_Attendees() failure: 0x%08X\n", hr); WLog_ERR(TAG, "IRDPSRAPISharingSession::get_Attendees() failure: 0x%08X", hr);
return -1; return -1;
} }
@ -655,7 +658,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem)
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "IRDPSRAPISharingSession::get_Properties() failure: 0x%08X\n", hr); WLog_ERR(TAG, "IRDPSRAPISharingSession::get_Properties() failure: 0x%08X", hr);
return -1; return -1;
} }
@ -670,7 +673,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem)
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "IRDPSRAPISessionProperties::put_Property(PortId) failure: 0x%08X\n", hr); WLog_ERR(TAG, "IRDPSRAPISessionProperties::put_Property(PortId) failure: 0x%08X", hr);
return -1; return -1;
} }
@ -685,7 +688,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem)
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "IRDPSRAPISessionProperties::put_Property(DrvConAttach) failure: 0x%08X\n", hr); WLog_ERR(TAG, "IRDPSRAPISessionProperties::put_Property(DrvConAttach) failure: 0x%08X", hr);
return -1; return -1;
} }
@ -703,7 +706,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem)
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "IRDPSRAPISessionProperties::put_Property(PortProtocol) failure: 0x%08X\n", hr); WLog_ERR(TAG, "IRDPSRAPISessionProperties::put_Property(PortProtocol) failure: 0x%08X", hr);
return -1; return -1;
} }
@ -711,7 +714,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem)
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "IRDPSRAPISharingSession::Open() failure: 0x%08X\n", hr); WLog_ERR(TAG, "IRDPSRAPISharingSession::Open() failure: 0x%08X", hr);
return -1; return -1;
} }
@ -720,7 +723,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem)
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "IRDPSRAPISharingSession::get_Invitations() failure\n"); WLog_ERR(TAG, "IRDPSRAPISharingSession::get_Invitations() failure");
return -1; return -1;
} }
@ -737,7 +740,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem)
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "IRDPSRAPIInvitationManager::CreateInvitation() failure: 0x%08X\n", hr); WLog_ERR(TAG, "IRDPSRAPIInvitationManager::CreateInvitation() failure: 0x%08X", hr);
return -1; return -1;
} }
@ -745,7 +748,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem)
if (FAILED(hr)) if (FAILED(hr))
{ {
fprintf(stderr, "IRDPSRAPIInvitation::get_ConnectionString() failure: 0x%08X\n", hr); WLog_ERR(TAG, "IRDPSRAPIInvitation::get_ConnectionString() failure: 0x%08X", hr);
return -1; return -1;
} }
@ -759,7 +762,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem)
if (status < 0) if (status < 0)
return -1; return -1;
printf("ConnectionString: %s\n", file->ConnectionString2); WLog_INFO(TAG, "ConnectionString: %s", file->ConnectionString2);
if (0) if (0)
{ {
@ -781,7 +784,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem)
if (status < 0) if (status < 0)
{ {
printf("win_shadow_rdp_init() failure: %d\n", status); WLog_INFO(TAG, "win_shadow_rdp_init() failure: %d", status);
return status; return status;
} }
@ -808,7 +811,7 @@ int win_shadow_wds_init(winShadowSubsystem* subsystem)
if (status < 0) if (status < 0)
{ {
printf("win_shadow_rdp_start() failure: %d\n", status); WLog_INFO(TAG, "win_shadow_rdp_start() failure: %d", status);
return status; return status;
} }

View File

@ -36,6 +36,7 @@
#include <freerdp/codec/color.h> #include <freerdp/codec/color.h>
#include <freerdp/codec/region.h> #include <freerdp/codec/region.h>
#include <freerdp/log.h>
#include "../shadow_screen.h" #include "../shadow_screen.h"
#include "../shadow_capture.h" #include "../shadow_capture.h"
@ -43,6 +44,8 @@
#include "x11_shadow.h" #include "x11_shadow.h"
#define TAG SERVER_TAG("shadow.x11")
void x11_shadow_input_synchronize_event(x11ShadowSubsystem* subsystem, UINT32 flags) void x11_shadow_input_synchronize_event(x11ShadowSubsystem* subsystem, UINT32 flags)
{ {
@ -474,7 +477,7 @@ int x11_shadow_xshm_init(x11ShadowSubsystem* subsystem)
if (!subsystem->fb_image) if (!subsystem->fb_image)
{ {
fprintf(stderr, "XShmCreateImage failed\n"); WLog_ERR(TAG, "XShmCreateImage failed");
return -1; return -1;
} }
@ -483,7 +486,7 @@ int x11_shadow_xshm_init(x11ShadowSubsystem* subsystem)
if (subsystem->fb_shm_info.shmid == -1) if (subsystem->fb_shm_info.shmid == -1)
{ {
fprintf(stderr, "shmget failed\n"); WLog_ERR(TAG, "shmget failed");
return -1; return -1;
} }
@ -492,7 +495,7 @@ int x11_shadow_xshm_init(x11ShadowSubsystem* subsystem)
if (subsystem->fb_shm_info.shmaddr == ((char*) -1)) if (subsystem->fb_shm_info.shmaddr == ((char*) -1))
{ {
fprintf(stderr, "shmat failed\n"); WLog_ERR(TAG, "shmat failed");
return -1; return -1;
} }
@ -556,7 +559,7 @@ int x11_shadow_subsystem_init(x11ShadowSubsystem* subsystem)
if (!subsystem->display) if (!subsystem->display)
{ {
fprintf(stderr, "failed to open display: %s\n", XDisplayName(NULL)); WLog_ERR(TAG, "failed to open display: %s", XDisplayName(NULL));
return -1; return -1;
} }
@ -591,7 +594,7 @@ int x11_shadow_subsystem_init(x11ShadowSubsystem* subsystem)
if (!pfs) if (!pfs)
{ {
fprintf(stderr, "XListPixmapFormats failed\n"); WLog_ERR(TAG, "XListPixmapFormats failed");
return -1; return -1;
} }
@ -616,7 +619,7 @@ int x11_shadow_subsystem_init(x11ShadowSubsystem* subsystem)
if (!vis) if (!vis)
{ {
fprintf(stderr, "XGetVisualInfo failed\n"); WLog_ERR(TAG, "XGetVisualInfo failed");
return -1; return -1;
} }
@ -678,7 +681,7 @@ int x11_shadow_subsystem_init(x11ShadowSubsystem* subsystem)
subsystem->monitors[0].flags = 1; subsystem->monitors[0].flags = 1;
} }
printf("X11 Extensions: XFixes: %d Xinerama: %d XDamage: %d XShm: %d\n", WLog_INFO(TAG, "X11 Extensions: XFixes: %d Xinerama: %d XDamage: %d XShm: %d",
subsystem->use_xfixes, subsystem->use_xinerama, subsystem->use_xdamage, subsystem->use_xshm); subsystem->use_xfixes, subsystem->use_xinerama, subsystem->use_xdamage, subsystem->use_xshm);
return 1; return 1;

View File

@ -23,10 +23,14 @@
#include <winpr/crt.h> #include <winpr/crt.h>
#include <winpr/print.h> #include <winpr/print.h>
#include <freerdp/log.h>
#include "shadow_surface.h" #include "shadow_surface.h"
#include "shadow_capture.h" #include "shadow_capture.h"
#define TAG SERVER_TAG("shadow")
int shadow_capture_align_clip_rect(RECTANGLE_16* rect, RECTANGLE_16* clip) int shadow_capture_align_clip_rect(RECTANGLE_16* rect, RECTANGLE_16* clip)
{ {
int dx, dy; int dx, dy;
@ -177,31 +181,31 @@ int shadow_capture_compare(BYTE* pData1, int nStep1, int nWidth, int nHeight, BY
if (0) if (0)
{ {
printf("\n"); WLog_INFO(TAG, "");
for (tx = 0; tx < ncol; tx++) for (tx = 0; tx < ncol; tx++)
printf("-"); WLog_INFO(TAG, "-");
printf("\n"); WLog_INFO(TAG, "");
for (tx = 0; tx < ncol; tx++) for (tx = 0; tx < ncol; tx++)
printf("%s", cols[tx] ? "O" : "X"); WLog_INFO(TAG, "%s", cols[tx] ? "O" : "X");
printf("\n"); WLog_INFO(TAG, "");
for (tx = 0; tx < ncol; tx++) for (tx = 0; tx < ncol; tx++)
printf("-"); WLog_INFO(TAG, "-");
printf("\n"); WLog_INFO(TAG, "");
for (ty = 0; ty < nrow; ty++) for (ty = 0; ty < nrow; ty++)
{ {
for (tx = 0; tx < ncol; tx++) for (tx = 0; tx < ncol; tx++)
{ {
printf("%s", grid[ty][tx] ? "O" : "X"); WLog_INFO(TAG, "%s", grid[ty][tx] ? "O" : "X");
} }
printf("|%s|\n", rows[ty] ? "O" : "X"); WLog_INFO(TAG, "|%s|", rows[ty] ? "O" : "X");
} }
printf("left: %d top: %d right: %d bottom: %d ncol: %d nrow: %d\n", WLog_INFO(TAG, "left: %d top: %d right: %d bottom: %d ncol: %d nrow: %d",
l, t, r, b, ncol, nrow); l, t, r, b, ncol, nrow);
} }

View File

@ -27,8 +27,12 @@
#include <winpr/thread.h> #include <winpr/thread.h>
#include <winpr/sysinfo.h> #include <winpr/sysinfo.h>
#include <freerdp/log.h>
#include "shadow.h" #include "shadow.h"
#define TAG CLIENT_TAG("shadow")
void shadow_client_context_new(freerdp_peer* peer, rdpShadowClient* client) void shadow_client_context_new(freerdp_peer* peer, rdpShadowClient* client)
{ {
rdpSettings* settings; rdpSettings* settings;
@ -121,7 +125,7 @@ BOOL shadow_client_post_connect(freerdp_peer* peer)
if (settings->ColorDepth == 24) if (settings->ColorDepth == 24)
settings->ColorDepth = 16; /* disable 24bpp */ settings->ColorDepth = 16; /* disable 24bpp */
fprintf(stderr, "Client from %s is activated (%dx%d@%d)\n", WLog_ERR(TAG, "Client from %s is activated (%dx%d@%d)",
peer->hostname, settings->DesktopWidth, settings->DesktopHeight, settings->ColorDepth); peer->hostname, settings->DesktopWidth, settings->DesktopHeight, settings->ColorDepth);
peer->update->DesktopResize(peer->update->context); peer->update->DesktopResize(peer->update->context);
@ -570,7 +574,7 @@ int shadow_client_send_surface_update(rdpShadowClient* client)
nWidth = extents->right - extents->left; nWidth = extents->right - extents->left;
nHeight = extents->bottom - extents->top; nHeight = extents->bottom - extents->top;
//printf("shadow_client_send_surface_update: x: %d y: %d width: %d height: %d right: %d bottom: %d\n", //WLog_INFO(TAG, "shadow_client_send_surface_update: x: %d y: %d width: %d height: %d right: %d bottom: %d",
// nXSrc, nYSrc, nWidth, nHeight, nXSrc + nWidth, nYSrc + nHeight); // nXSrc, nYSrc, nWidth, nHeight, nXSrc + nWidth, nYSrc + nHeight);
if (settings->RemoteFxCodec || settings->NSCodec) if (settings->RemoteFxCodec || settings->NSCodec)
@ -702,7 +706,7 @@ void* shadow_client_thread(rdpShadowClient* client)
{ {
if (!peer->CheckFileDescriptor(peer)) if (!peer->CheckFileDescriptor(peer))
{ {
fprintf(stderr, "Failed to check FreeRDP file descriptor\n"); WLog_ERR(TAG, "Failed to check FreeRDP file descriptor");
break; break;
} }
} }
@ -711,7 +715,7 @@ void* shadow_client_thread(rdpShadowClient* client)
{ {
if (WTSVirtualChannelManagerCheckFileDescriptor(client->vcm) != TRUE) if (WTSVirtualChannelManagerCheckFileDescriptor(client->vcm) != TRUE)
{ {
fprintf(stderr, "WTSVirtualChannelManagerCheckFileDescriptor failure\n"); WLog_ERR(TAG, "WTSVirtualChannelManagerCheckFileDescriptor failure");
break; break;
} }
} }

View File

@ -20,10 +20,13 @@
#include "config.h" #include "config.h"
#endif #endif
#include <freerdp/log.h>
#include "shadow.h" #include "shadow.h"
#include "shadow_encomsp.h" #include "shadow_encomsp.h"
#define TAG SERVER_TAG("shadow")
static int encomsp_change_participant_control_level(EncomspServerContext* context, static int encomsp_change_participant_control_level(EncomspServerContext* context,
ENCOMSP_CHANGE_PARTICIPANT_CONTROL_LEVEL_PDU* pdu) ENCOMSP_CHANGE_PARTICIPANT_CONTROL_LEVEL_PDU* pdu)
{ {
@ -32,7 +35,7 @@ static int encomsp_change_participant_control_level(EncomspServerContext* contex
BOOL mayInteract; BOOL mayInteract;
rdpShadowClient* client = (rdpShadowClient*) context->custom; rdpShadowClient* client = (rdpShadowClient*) context->custom;
printf("ChangeParticipantControlLevel: ParticipantId: %d Flags: 0x%04X\n", WLog_INFO(TAG, "ChangeParticipantControlLevel: ParticipantId: %d Flags: 0x%04X",
pdu->ParticipantId, pdu->Flags); pdu->ParticipantId, pdu->Flags);
mayView = (pdu->Flags & ENCOMSP_MAY_VIEW) ? TRUE : FALSE; mayView = (pdu->Flags & ENCOMSP_MAY_VIEW) ? TRUE : FALSE;

View File

@ -28,6 +28,7 @@
#include <winpr/winsock.h> #include <winpr/winsock.h>
#include <freerdp/version.h> #include <freerdp/version.h>
#include <freerdp/log.h>
#include <winpr/tools/makecert.h> #include <winpr/tools/makecert.h>
@ -42,6 +43,8 @@
#include "shadow.h" #include "shadow.h"
#define TAG SERVER_TAG("shadow")
#ifdef _WIN32 #ifdef _WIN32
static BOOL g_MessagePump = TRUE; static BOOL g_MessagePump = TRUE;
#else #else
@ -78,14 +81,14 @@ int shadow_server_print_command_line_help(int argc, char** argv)
int length; int length;
COMMAND_LINE_ARGUMENT_A* arg; COMMAND_LINE_ARGUMENT_A* arg;
printf("Usage: %s [options]\n", argv[0]); WLog_INFO(TAG, "Usage: %s [options]", argv[0]);
printf("\n"); WLog_INFO(TAG, "");
printf("Syntax:\n"); WLog_INFO(TAG, "Syntax:");
printf(" /flag (enables flag)\n"); WLog_INFO(TAG, " /flag (enables flag)");
printf(" /option:<value> (specifies option with value)\n"); WLog_INFO(TAG, " /option:<value> (specifies option with value)");
printf(" +toggle -toggle (enables or disables toggle, where '/' is a synonym of '+')\n"); WLog_INFO(TAG, " +toggle -toggle (enables or disables toggle, where '/' is a synonym of '+')");
printf("\n"); WLog_INFO(TAG, "");
arg = shadow_args; arg = shadow_args;
@ -93,28 +96,28 @@ int shadow_server_print_command_line_help(int argc, char** argv)
{ {
if (arg->Flags & COMMAND_LINE_VALUE_FLAG) if (arg->Flags & COMMAND_LINE_VALUE_FLAG)
{ {
printf(" %s", "/"); WLog_INFO(TAG, " %s", "/");
printf("%-20s", arg->Name); WLog_INFO(TAG, "%-20s", arg->Name);
printf("\t%s\n", arg->Text); WLog_INFO(TAG, "\t%s", arg->Text);
} }
else if ((arg->Flags & COMMAND_LINE_VALUE_REQUIRED) || (arg->Flags & COMMAND_LINE_VALUE_OPTIONAL)) else if ((arg->Flags & COMMAND_LINE_VALUE_REQUIRED) || (arg->Flags & COMMAND_LINE_VALUE_OPTIONAL))
{ {
printf(" %s", "/"); WLog_INFO(TAG, " %s", "/");
if (arg->Format) if (arg->Format)
{ {
length = (int) (strlen(arg->Name) + strlen(arg->Format) + 2); length = (int) (strlen(arg->Name) + strlen(arg->Format) + 2);
str = (char*) malloc(length + 1); str = (char*) malloc(length + 1);
sprintf_s(str, length + 1, "%s:%s", arg->Name, arg->Format); sprintf_s(str, length + 1, "%s:%s", arg->Name, arg->Format);
printf("%-20s", str); WLog_INFO(TAG, "%-20s", str);
free(str); free(str);
} }
else else
{ {
printf("%-20s", arg->Name); WLog_INFO(TAG, "%-20s", arg->Name);
} }
printf("\t%s\n", arg->Text); WLog_INFO(TAG, "\t%s", arg->Text);
} }
else if (arg->Flags & COMMAND_LINE_VALUE_BOOL) else if (arg->Flags & COMMAND_LINE_VALUE_BOOL)
{ {
@ -123,12 +126,12 @@ int shadow_server_print_command_line_help(int argc, char** argv)
sprintf_s(str, length + 1, "%s (default:%s)", arg->Name, sprintf_s(str, length + 1, "%s (default:%s)", arg->Name,
arg->Default ? "on" : "off"); arg->Default ? "on" : "off");
printf(" %s", arg->Default ? "-" : "+"); WLog_INFO(TAG, " %s", arg->Default ? "-" : "+");
printf("%-20s", str); WLog_INFO(TAG, "%-20s", str);
free(str); free(str);
printf("\t%s\n", arg->Text); WLog_INFO(TAG, "\t%s", arg->Text);
} }
} }
while ((arg = CommandLineFindNextArgumentA(arg)) != NULL); while ((arg = CommandLineFindNextArgumentA(arg)) != NULL);
@ -140,7 +143,7 @@ int shadow_server_command_line_status_print(rdpShadowServer* server, int argc, c
{ {
if (status == COMMAND_LINE_STATUS_PRINT_VERSION) if (status == COMMAND_LINE_STATUS_PRINT_VERSION)
{ {
printf("FreeRDP version %s (git %s)\n", FREERDP_VERSION_FULL, GIT_REVISION); WLog_INFO(TAG, "FreeRDP version %s (git %s)", FREERDP_VERSION_FULL, GIT_REVISION);
return COMMAND_LINE_STATUS_PRINT_VERSION; return COMMAND_LINE_STATUS_PRINT_VERSION;
} }
else if (status == COMMAND_LINE_STATUS_PRINT) else if (status == COMMAND_LINE_STATUS_PRINT)
@ -233,7 +236,7 @@ int shadow_server_parse_command_line(rdpShadowServer* server, int argc, char** a
width = monitor->right - monitor->left; width = monitor->right - monitor->left;
height = monitor->bottom - monitor->top; height = monitor->bottom - monitor->top;
printf(" %s [%d] %dx%d\t+%d+%d\n", WLog_INFO(TAG, " %s [%d] %dx%d\t+%d+%d",
(monitor->flags == 1) ? "*" : " ", index, (monitor->flags == 1) ? "*" : " ", index,
width, height, monitor->left, monitor->top); width, height, monitor->left, monitor->top);
} }
@ -295,7 +298,7 @@ void* shadow_server_thread(rdpShadowServer* server)
if (listener->GetEventHandles(listener, events, &nCount) < 0) if (listener->GetEventHandles(listener, events, &nCount) < 0)
{ {
fprintf(stderr, "Failed to get FreeRDP file descriptor\n"); WLog_ERR(TAG, "Failed to get FreeRDP file descriptor");
break; break;
} }
@ -310,7 +313,7 @@ void* shadow_server_thread(rdpShadowServer* server)
if (!listener->CheckFileDescriptor(listener)) if (!listener->CheckFileDescriptor(listener))
{ {
fprintf(stderr, "Failed to check FreeRDP file descriptor\n"); WLog_ERR(TAG, "Failed to check FreeRDP file descriptor");
break; break;
} }
@ -473,7 +476,7 @@ int shadow_server_init(rdpShadowServer* server)
status = server->subsystem->Init(server->subsystem); status = server->subsystem->Init(server->subsystem);
if (status < 0) if (status < 0)
fprintf(stderr, "subsystem init failure: %d\n", status); WLog_ERR(TAG, "subsystem init failure: %d", status);
} }
server->screen = shadow_screen_new(server); server->screen = shadow_screen_new(server);