2012-10-11 04:44:27 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* FreeRDP Windows Server (Audio Output)
|
|
|
|
*
|
|
|
|
* Copyright 2012 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2013-02-16 01:53:32 +04:00
|
|
|
* Copyright 2013 Corey Clayton <can.of.tuna@gmail.com>
|
2012-10-11 04:44:27 +04:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-02-16 13:20:38 +03:00
|
|
|
#include <freerdp/config.h>
|
2012-10-11 04:44:27 +04:00
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2013-01-03 20:13:13 +04:00
|
|
|
#include <winpr/windows.h>
|
2018-09-25 18:05:12 +03:00
|
|
|
#include <freerdp/server/server-common.h>
|
2013-01-03 20:13:13 +04:00
|
|
|
|
2012-10-11 04:44:27 +04:00
|
|
|
#include "wf_rdpsnd.h"
|
2012-10-13 05:02:42 +04:00
|
|
|
#include "wf_info.h"
|
2012-10-12 18:37:19 +04:00
|
|
|
|
2013-02-18 23:40:37 +04:00
|
|
|
#ifdef WITH_RDPSND_DSOUND
|
2012-10-12 18:37:19 +04:00
|
|
|
|
2013-02-18 23:40:37 +04:00
|
|
|
#include "wf_directsound.h"
|
2013-02-16 01:53:32 +04:00
|
|
|
|
2013-02-18 23:40:37 +04:00
|
|
|
#else
|
2013-02-16 01:53:32 +04:00
|
|
|
|
2013-02-18 23:40:37 +04:00
|
|
|
#include "wf_wasapi.h"
|
|
|
|
|
|
|
|
#endif
|
2012-10-12 18:37:19 +04:00
|
|
|
|
2022-04-28 06:43:31 +03:00
|
|
|
#include <freerdp/log.h>
|
2017-02-21 07:43:53 +03:00
|
|
|
#define TAG SERVER_TAG("windows")
|
|
|
|
|
2013-08-19 05:52:55 +04:00
|
|
|
static void wf_peer_rdpsnd_activated(RdpsndServerContext* context)
|
2012-10-11 04:44:27 +04:00
|
|
|
{
|
2013-03-16 05:04:50 +04:00
|
|
|
wfInfo* wfi;
|
2021-06-16 15:50:14 +03:00
|
|
|
size_t i;
|
2013-03-16 05:04:50 +04:00
|
|
|
wfi = wf_info_get_instance();
|
|
|
|
wfi->agreed_format = NULL;
|
2014-09-12 19:38:12 +04:00
|
|
|
WLog_DBG(TAG, "Client supports the following %d formats:", context->num_client_formats);
|
|
|
|
|
|
|
|
for (i = 0; i < context->num_client_formats; i++)
|
2013-03-16 05:04:50 +04:00
|
|
|
{
|
2021-06-16 15:50:14 +03:00
|
|
|
size_t j;
|
2019-11-06 17:24:51 +03:00
|
|
|
// TODO: improve the way we agree on a format
|
2013-03-16 05:04:50 +04:00
|
|
|
for (j = 0; j < context->num_server_formats; j++)
|
|
|
|
{
|
|
|
|
if ((context->client_formats[i].wFormatTag == context->server_formats[j].wFormatTag) &&
|
|
|
|
(context->client_formats[i].nChannels == context->server_formats[j].nChannels) &&
|
2019-11-06 17:24:51 +03:00
|
|
|
(context->client_formats[i].nSamplesPerSec ==
|
|
|
|
context->server_formats[j].nSamplesPerSec))
|
2013-03-16 05:04:50 +04:00
|
|
|
{
|
2014-09-12 19:38:12 +04:00
|
|
|
WLog_DBG(TAG, "agreed on format!");
|
2019-11-06 17:24:51 +03:00
|
|
|
wfi->agreed_format = (AUDIO_FORMAT*)&context->server_formats[j];
|
2013-03-16 05:04:50 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-09-25 18:05:12 +03:00
|
|
|
|
2013-03-16 05:04:50 +04:00
|
|
|
if (wfi->agreed_format != NULL)
|
|
|
|
break;
|
|
|
|
}
|
2018-09-25 18:05:12 +03:00
|
|
|
|
2013-03-16 05:04:50 +04:00
|
|
|
if (wfi->agreed_format == NULL)
|
|
|
|
{
|
2014-09-12 19:38:12 +04:00
|
|
|
WLog_ERR(TAG, "Could not agree on a audio format with the server");
|
2013-03-16 05:04:50 +04:00
|
|
|
return;
|
|
|
|
}
|
2018-09-25 18:05:12 +03:00
|
|
|
|
2013-03-16 05:04:50 +04:00
|
|
|
context->SelectFormat(context, i);
|
|
|
|
context->SetVolume(context, 0x7FFF, 0x7FFF);
|
2013-02-18 23:40:37 +04:00
|
|
|
#ifdef WITH_RDPSND_DSOUND
|
|
|
|
wf_directsound_activate(context);
|
|
|
|
#else
|
2013-02-16 03:50:00 +04:00
|
|
|
wf_wasapi_activate(context);
|
2013-02-18 23:40:37 +04:00
|
|
|
#endif
|
2012-10-13 05:02:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int wf_rdpsnd_lock()
|
|
|
|
{
|
|
|
|
DWORD dRes;
|
|
|
|
wfInfo* wfi;
|
|
|
|
wfi = wf_info_get_instance();
|
|
|
|
dRes = WaitForSingleObject(wfi->snd_mutex, INFINITE);
|
|
|
|
|
|
|
|
switch (dRes)
|
|
|
|
{
|
2018-09-25 18:05:12 +03:00
|
|
|
case WAIT_ABANDONED:
|
|
|
|
case WAIT_OBJECT_0:
|
|
|
|
return TRUE;
|
|
|
|
break;
|
2012-10-13 05:02:42 +04:00
|
|
|
|
2018-09-25 18:05:12 +03:00
|
|
|
case WAIT_TIMEOUT:
|
|
|
|
return FALSE;
|
|
|
|
break;
|
2012-10-13 05:02:42 +04:00
|
|
|
|
2018-09-25 18:05:12 +03:00
|
|
|
case WAIT_FAILED:
|
|
|
|
WLog_ERR(TAG, "wf_rdpsnd_lock failed with 0x%08lX", GetLastError());
|
|
|
|
return -1;
|
|
|
|
break;
|
2012-10-13 05:02:42 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int wf_rdpsnd_unlock()
|
|
|
|
{
|
|
|
|
wfInfo* wfi;
|
|
|
|
wfi = wf_info_get_instance();
|
2012-10-12 18:37:19 +04:00
|
|
|
|
2012-10-13 05:02:42 +04:00
|
|
|
if (ReleaseMutex(wfi->snd_mutex) == 0)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_DBG(TAG, "wf_rdpsnd_unlock failed with 0x%08lX", GetLastError());
|
2012-10-13 05:02:42 +04:00
|
|
|
return -1;
|
|
|
|
}
|
2012-10-12 18:37:19 +04:00
|
|
|
|
2012-10-13 05:02:42 +04:00
|
|
|
return TRUE;
|
2012-10-11 04:44:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL wf_peer_rdpsnd_init(wfPeerContext* context)
|
|
|
|
{
|
2015-05-05 18:25:17 +03:00
|
|
|
wfInfo* wfi = wf_info_get_instance();
|
2018-09-25 18:05:12 +03:00
|
|
|
|
2015-05-05 18:25:17 +03:00
|
|
|
if (!wfi)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!(wfi->snd_mutex = CreateMutex(NULL, FALSE, NULL)))
|
|
|
|
return FALSE;
|
2012-10-13 05:02:42 +04:00
|
|
|
|
2012-10-11 04:44:27 +04:00
|
|
|
context->rdpsnd = rdpsnd_server_context_new(context->vcm);
|
2015-07-15 10:50:35 +03:00
|
|
|
context->rdpsnd->rdpcontext = &context->_p;
|
2012-10-11 04:44:27 +04:00
|
|
|
context->rdpsnd->data = context;
|
2019-11-06 17:24:51 +03:00
|
|
|
context->rdpsnd->num_server_formats =
|
|
|
|
server_rdpsnd_get_formats(&context->rdpsnd->server_formats);
|
2012-10-11 04:44:27 +04:00
|
|
|
|
2018-09-25 18:05:12 +03:00
|
|
|
if (context->rdpsnd->num_server_formats > 0)
|
|
|
|
context->rdpsnd->src_format = &context->rdpsnd->server_formats[0];
|
2012-10-11 04:44:27 +04:00
|
|
|
|
|
|
|
context->rdpsnd->Activated = wf_peer_rdpsnd_activated;
|
2014-07-14 16:00:38 +04:00
|
|
|
context->rdpsnd->Initialize(context->rdpsnd, TRUE);
|
2013-02-19 01:01:37 +04:00
|
|
|
wf_rdpsnd_set_latest_peer(context);
|
2012-10-13 05:02:42 +04:00
|
|
|
wfi->snd_stop = FALSE;
|
2012-10-11 04:44:27 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|