From 231eda37cd58d119ea18d3fe3fa81b630c239ff1 Mon Sep 17 00:00:00 2001 From: Corey C Date: Fri, 15 Feb 2013 20:39:31 -0500 Subject: [PATCH 1/5] wfreerdp-server: sound latency tweaks --- server/Windows/wf_wasapi.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/server/Windows/wf_wasapi.c b/server/Windows/wf_wasapi.c index aee0b8716..0631bbaed 100644 --- a/server/Windows/wf_wasapi.c +++ b/server/Windows/wf_wasapi.c @@ -7,8 +7,15 @@ #include #include -#define REFTIMES_PER_SEC 10000000 -#define REFTIMES_PER_MILLISEC 10000 +//#define REFTIMES_PER_SEC 10000000 +//#define REFTIMES_PER_MILLISEC 10000 + +//#define REFTIMES_PER_SEC 100000 +//#define REFTIMES_PER_MILLISEC 100 + +#define REFTIMES_PER_SEC 50000 +#define REFTIMES_PER_MILLISEC 50 + DEFINE_GUID(CLSID_MMDeviceEnumerator, 0xBCDE0395, 0xE52F, 0x467C, 0x8E, 0x3D, 0xC4, 0x57, 0x92, 0x91, 0x69, 0x2E); @@ -119,8 +126,6 @@ int wf_wasapi_get_device_string(LPWSTR pattern, LPWSTR * deviceStr) exit(1); } - - //do this a more reliable way if (wcscmp(pattern, nameVar.pwszVal) < 0) { @@ -262,7 +267,7 @@ DWORD WINAPI wf_rdpsnd_wasapi_thread(LPVOID lpParam) Sleep(hnsActualDuration/REFTIMES_PER_MILLISEC/2); - + hr = pCaptureClient->lpVtbl->GetNextPacketSize(pCaptureClient, &packetLength); if (FAILED(hr)) { @@ -281,7 +286,8 @@ DWORD WINAPI wf_rdpsnd_wasapi_thread(LPVOID lpParam) //write data here //fwrite(pData, 1, packetLength * 4, pFile); - context->rdpsnd->SendSamples(context->rdpsnd, pData, packetLength); + if (!(flags & AUDCLNT_BUFFERFLAGS_SILENT)) + context->rdpsnd->SendSamples(context->rdpsnd, pData, packetLength); hr = pCaptureClient->lpVtbl->ReleaseBuffer(pCaptureClient, numFramesAvailable); if (FAILED(hr)) From be7a84ec7289e4ca01df81c4005f8c86d0c1784c Mon Sep 17 00:00:00 2001 From: Corey C Date: Mon, 18 Feb 2013 09:52:28 -0500 Subject: [PATCH 2/5] wfreerdp-server: removed cruft --- server/Windows/wf_wasapi.c | 6 ------ server/Windows/wf_wasapi.h | 3 --- 2 files changed, 9 deletions(-) diff --git a/server/Windows/wf_wasapi.c b/server/Windows/wf_wasapi.c index 0631bbaed..f610c9122 100644 --- a/server/Windows/wf_wasapi.c +++ b/server/Windows/wf_wasapi.c @@ -27,12 +27,6 @@ DEFINE_GUID(IID_IAudioCaptureClient, 0xc8adbd64, 0xe71e, 0x48a0, 0xa4,0xde, 0x18 LPWSTR devStr = NULL; wfPeerContext* latestPeer = NULL; -int wf_wasapi_set_latest_peer(wfPeerContext* peer) -{ - latestPeer = peer; - return 0; -} - int wf_wasapi_activate(rdpsnd_server_context* context) { wchar_t * pattern = L"Stereo Mix"; diff --git a/server/Windows/wf_wasapi.h b/server/Windows/wf_wasapi.h index 52c6c6ea0..3b7cd7d36 100644 --- a/server/Windows/wf_wasapi.h +++ b/server/Windows/wf_wasapi.h @@ -4,9 +4,6 @@ #include #include "wf_interface.h" -//TODO: fix how this is handled -int wf_wasapi_set_latest_peer(wfPeerContext* peer); - int wf_wasapi_activate(rdpsnd_server_context* context); int wf_wasapi_get_device_string(LPWSTR pattern, LPWSTR * deviceStr); From 6176085ea1c984fde8e789d2b225c5dad6b7e8fe Mon Sep 17 00:00:00 2001 From: Corey C Date: Mon, 18 Feb 2013 14:40:37 -0500 Subject: [PATCH 3/5] wfreerdp-server: make rdpsnd backend selectable at build time --- config.h.in | 1 + server/Windows/CMakeLists.txt | 26 ++++++++++++++++++++------ server/Windows/wf_rdpsnd.c | 25 +++++++++++++++++-------- server/Windows/wf_wasapi.c | 12 ++++++------ 4 files changed, 44 insertions(+), 20 deletions(-) diff --git a/config.h.in b/config.h.in index 8cbaf2620..862573382 100644 --- a/config.h.in +++ b/config.h.in @@ -40,6 +40,7 @@ #cmakedefine WITH_NATIVE_SSPI #cmakedefine WITH_JPEG #cmakedefine WITH_WIN8 +#cmakedefine WITH_RDPSND_DSOUND /* Plugins */ #cmakedefine STATIC_CHANNELS diff --git a/server/Windows/CMakeLists.txt b/server/Windows/CMakeLists.txt index 83c606f99..b817e8121 100644 --- a/server/Windows/CMakeLists.txt +++ b/server/Windows/CMakeLists.txt @@ -33,16 +33,30 @@ set(${MODULE_PREFIX}_SRCS wf_mirage.h wf_peer.c wf_peer.h - wf_rdpsnd.c - wf_rdpsnd.h - wf_directsound.c - wf_directsound.h - wf_wasapi.c - wf_wasapi.h wf_settings.c wf_settings.h wf_info.c wf_info.h) + +if(CHANNEL_RDPSND AND NOT WITH_RDPSND_DSOUND) + set(${MODULE_PREFIX}_SRCS + ${${MODULE_PREFIX}_SRCS} + wf_rdpsnd.c + wf_rdpsnd.h + wf_wasapi.c + wf_wasapi.h + ) +endif() + +if(CHANNEL_RDPSND AND WITH_RDPSND_DSOUND) + set(${MODULE_PREFIX}_SRCS + ${${MODULE_PREFIX}_SRCS} + wf_rdpsnd.c + wf_rdpsnd.h + wf_directsound.c + wf_directsound.h + ) +endif() if(WITH_SERVER_INTERFACE) add_library(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS}) diff --git a/server/Windows/wf_rdpsnd.c b/server/Windows/wf_rdpsnd.c index 6f0e5fb5e..b06bcf29d 100644 --- a/server/Windows/wf_rdpsnd.c +++ b/server/Windows/wf_rdpsnd.c @@ -27,6 +27,7 @@ #include +/* #define INITGUID #include #include @@ -37,18 +38,21 @@ #include +*/ + #include "wf_rdpsnd.h" -#include "wf_directsound.h" -#include "wf_wasapi.h" #include "wf_info.h" +#ifdef WITH_RDPSND_DSOUND +#include "wf_directsound.h" +#else -//#define BYTESPERSEC 176400 +#include "wf_wasapi.h" + +#endif -//FIXME support multiple clients -//wfPeerContext* latestPeer; static const rdpsndFormat test_audio_formats[] = { @@ -66,9 +70,16 @@ static const rdpsndFormat test_audio_formats[] = static void wf_peer_rdpsnd_activated(rdpsnd_server_context* context) { +#ifdef WITH_RDPSND_DSOUND + + wf_directsound_activate(context); + +#else - //wf_directsound_activate(context); wf_wasapi_activate(context); + +#endif + } int wf_rdpsnd_lock() @@ -138,8 +149,6 @@ BOOL wf_peer_rdpsnd_init(wfPeerContext* context) context->rdpsnd->Initialize(context->rdpsnd); - wf_directsound_set_latest_peer(context); - wfi->snd_stop = FALSE; return TRUE; } diff --git a/server/Windows/wf_wasapi.c b/server/Windows/wf_wasapi.c index f610c9122..9f36c486d 100644 --- a/server/Windows/wf_wasapi.c +++ b/server/Windows/wf_wasapi.c @@ -10,11 +10,11 @@ //#define REFTIMES_PER_SEC 10000000 //#define REFTIMES_PER_MILLISEC 10000 -//#define REFTIMES_PER_SEC 100000 -//#define REFTIMES_PER_MILLISEC 100 +#define REFTIMES_PER_SEC 100000 +#define REFTIMES_PER_MILLISEC 100 -#define REFTIMES_PER_SEC 50000 -#define REFTIMES_PER_MILLISEC 50 +//#define REFTIMES_PER_SEC 50000 +//#define REFTIMES_PER_MILLISEC 50 DEFINE_GUID(CLSID_MMDeviceEnumerator, 0xBCDE0395, 0xE52F, 0x467C, @@ -278,8 +278,8 @@ DWORD WINAPI wf_rdpsnd_wasapi_thread(LPVOID lpParam) exit(1); } - //write data here - //fwrite(pData, 1, packetLength * 4, pFile); + //Here we are writing the audio data + //not sure if this flag is ever set by the system; msdn is not clear about it if (!(flags & AUDCLNT_BUFFERFLAGS_SILENT)) context->rdpsnd->SendSamples(context->rdpsnd, pData, packetLength); From 561e49009c7b10aa7f0a003890566d1d3d559717 Mon Sep 17 00:00:00 2001 From: Corey C Date: Mon, 18 Feb 2013 14:58:26 -0500 Subject: [PATCH 4/5] wfreerdp-server: one liner -- it builds --- server/Windows/wf_wasapi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/Windows/wf_wasapi.c b/server/Windows/wf_wasapi.c index 9f36c486d..2273667cb 100644 --- a/server/Windows/wf_wasapi.c +++ b/server/Windows/wf_wasapi.c @@ -245,7 +245,7 @@ DWORD WINAPI wf_rdpsnd_wasapi_thread(LPVOID lpParam) } - hnsActualDuration = (double)REFTIMES_PER_SEC * bufferFrameCount / pwfx->nSamplesPerSec; + hnsActualDuration = (UINT32)REFTIMES_PER_SEC * bufferFrameCount / pwfx->nSamplesPerSec; hr = pAudioClient->lpVtbl->Start(pAudioClient); if (FAILED(hr)) From 64a67b5cd0565a4322555363d81c3a6e01278d19 Mon Sep 17 00:00:00 2001 From: Corey C Date: Mon, 18 Feb 2013 16:01:37 -0500 Subject: [PATCH 5/5] wfreerdp-server: fix regression that I made earlier --- server/Windows/wf_directsound.c | 2 +- server/Windows/wf_directsound.h | 2 +- server/Windows/wf_rdpsnd.c | 15 ++------------- server/Windows/wf_wasapi.c | 7 +++++++ server/Windows/wf_wasapi.h | 2 ++ 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/server/Windows/wf_directsound.c b/server/Windows/wf_directsound.c index 45a576b3f..5963d32b3 100644 --- a/server/Windows/wf_directsound.c +++ b/server/Windows/wf_directsound.c @@ -20,7 +20,7 @@ DSCBUFFERDESC dscbd; DWORD lastPos; wfPeerContext* latestPeer; -int wf_directsound_set_latest_peer(wfPeerContext* peer) +int wf_rdpsnd_set_latest_peer(wfPeerContext* peer) { latestPeer = peer; return 0; diff --git a/server/Windows/wf_directsound.h b/server/Windows/wf_directsound.h index f4198f4b6..f88e7dfb0 100644 --- a/server/Windows/wf_directsound.h +++ b/server/Windows/wf_directsound.h @@ -4,7 +4,7 @@ #include #include "wf_interface.h" -int wf_directsound_set_latest_peer(wfPeerContext* peer); +int wf_rdpsnd_set_latest_peer(wfPeerContext* peer); int wf_directsound_activate(rdpsnd_server_context* context); diff --git a/server/Windows/wf_rdpsnd.c b/server/Windows/wf_rdpsnd.c index b06bcf29d..fa90456ac 100644 --- a/server/Windows/wf_rdpsnd.c +++ b/server/Windows/wf_rdpsnd.c @@ -27,19 +27,6 @@ #include -/* -#define INITGUID -#include -#include - -#define CINTERFACE -#include -#include - -#include - -*/ - #include "wf_rdpsnd.h" #include "wf_info.h" @@ -149,6 +136,8 @@ BOOL wf_peer_rdpsnd_init(wfPeerContext* context) context->rdpsnd->Initialize(context->rdpsnd); + wf_rdpsnd_set_latest_peer(context); + wfi->snd_stop = FALSE; return TRUE; } diff --git a/server/Windows/wf_wasapi.c b/server/Windows/wf_wasapi.c index 2273667cb..7c3586678 100644 --- a/server/Windows/wf_wasapi.c +++ b/server/Windows/wf_wasapi.c @@ -27,6 +27,13 @@ DEFINE_GUID(IID_IAudioCaptureClient, 0xc8adbd64, 0xe71e, 0x48a0, 0xa4,0xde, 0x18 LPWSTR devStr = NULL; wfPeerContext* latestPeer = NULL; +int wf_rdpsnd_set_latest_peer(wfPeerContext* peer) +{ + latestPeer = peer; + return 0; +} + + int wf_wasapi_activate(rdpsnd_server_context* context) { wchar_t * pattern = L"Stereo Mix"; diff --git a/server/Windows/wf_wasapi.h b/server/Windows/wf_wasapi.h index 3b7cd7d36..78cd0cbf6 100644 --- a/server/Windows/wf_wasapi.h +++ b/server/Windows/wf_wasapi.h @@ -4,6 +4,8 @@ #include #include "wf_interface.h" +int wf_rdpsnd_set_latest_peer(wfPeerContext* peer); + int wf_wasapi_activate(rdpsnd_server_context* context); int wf_wasapi_get_device_string(LPWSTR pattern, LPWSTR * deviceStr);