21 #include <freerdp/config.h>
26 #include <winpr/windows.h>
27 #include <freerdp/server/server-common.h>
29 #include "wf_rdpsnd.h"
32 #ifdef WITH_RDPSND_DSOUND
34 #include "wf_directsound.h"
38 #include "wf_wasapi.h"
42 #include <freerdp/log.h>
43 #define TAG SERVER_TAG("windows")
45 static void wf_peer_rdpsnd_activated(RdpsndServerContext* context)
48 wfi = wf_info_get_instance();
49 wfi->agreed_format = NULL;
50 WLog_DBG(TAG,
"Client supports the following %d formats:", context->num_client_formats);
53 for (; i < context->num_client_formats; i++)
56 for (
size_t j = 0; j < context->num_server_formats; j++)
58 if ((context->client_formats[i].wFormatTag == context->server_formats[j].wFormatTag) &&
59 (context->client_formats[i].nChannels == context->server_formats[j].nChannels) &&
60 (context->client_formats[i].nSamplesPerSec ==
61 context->server_formats[j].nSamplesPerSec))
63 WLog_DBG(TAG,
"agreed on format!");
64 wfi->agreed_format = (
AUDIO_FORMAT*)&context->server_formats[j];
69 if (wfi->agreed_format != NULL)
73 if (wfi->agreed_format == NULL)
75 WLog_ERR(TAG,
"Could not agree on a audio format with the server");
79 context->SelectFormat(context, i);
80 context->SetVolume(context, 0x7FFF, 0x7FFF);
81 #ifdef WITH_RDPSND_DSOUND
82 wf_directsound_activate(context);
84 wf_wasapi_activate(context);
92 wfi = wf_info_get_instance();
93 dRes = WaitForSingleObject(wfi->snd_mutex, INFINITE);
107 WLog_ERR(TAG,
"wf_rdpsnd_lock failed with 0x%08lX", GetLastError());
115 int wf_rdpsnd_unlock()
118 wfi = wf_info_get_instance();
120 if (ReleaseMutex(wfi->snd_mutex) == 0)
122 WLog_DBG(TAG,
"wf_rdpsnd_unlock failed with 0x%08lX", GetLastError());
129 BOOL wf_peer_rdpsnd_init(wfPeerContext* context)
131 wfInfo* wfi = wf_info_get_instance();
136 if (!(wfi->snd_mutex = CreateMutex(NULL, FALSE, NULL)))
139 context->rdpsnd = rdpsnd_server_context_new(context->vcm);
140 context->rdpsnd->rdpcontext = &context->_p;
141 context->rdpsnd->data = context;
142 context->rdpsnd->num_server_formats =
143 server_rdpsnd_get_formats(&context->rdpsnd->server_formats);
145 if (context->rdpsnd->num_server_formats > 0)
146 context->rdpsnd->src_format = &context->rdpsnd->server_formats[0];
148 context->rdpsnd->Activated = wf_peer_rdpsnd_activated;
149 context->rdpsnd->Initialize(context->rdpsnd, TRUE);
150 wf_rdpsnd_set_latest_peer(context);
151 wfi->snd_stop = FALSE;