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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2013-01-03 20:13:13 +04:00
|
|
|
#include <winpr/windows.h>
|
|
|
|
|
2013-02-18 23:40:37 +04:00
|
|
|
/*
|
2013-01-05 23:58:47 +04:00
|
|
|
#define INITGUID
|
|
|
|
#include <initguid.h>
|
|
|
|
#include <objbase.h>
|
2012-10-20 01:29:44 +04:00
|
|
|
|
2012-10-12 18:37:19 +04:00
|
|
|
#define CINTERFACE
|
|
|
|
#include <mmsystem.h>
|
|
|
|
#include <dsound.h>
|
|
|
|
|
2012-10-11 04:44:27 +04:00
|
|
|
#include <freerdp/server/rdpsnd.h>
|
|
|
|
|
2013-02-18 23:40:37 +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
|
|
|
|
2012-10-13 05:02:42 +04:00
|
|
|
|
2012-10-11 04:44:27 +04:00
|
|
|
static const rdpsndFormat test_audio_formats[] =
|
|
|
|
{
|
|
|
|
{ 0x11, 2, 22050, 1024, 4, 0, NULL }, /* IMA ADPCM, 22050 Hz, 2 channels */
|
|
|
|
{ 0x11, 1, 22050, 512, 4, 0, NULL }, /* IMA ADPCM, 22050 Hz, 1 channels */
|
|
|
|
{ 0x01, 2, 22050, 4, 16, 0, NULL }, /* PCM, 22050 Hz, 2 channels, 16 bits */
|
|
|
|
{ 0x01, 1, 22050, 2, 16, 0, NULL }, /* PCM, 22050 Hz, 1 channels, 16 bits */
|
|
|
|
{ 0x01, 2, 44100, 4, 16, 0, NULL }, /* PCM, 44100 Hz, 2 channels, 16 bits */
|
|
|
|
{ 0x01, 1, 44100, 2, 16, 0, NULL }, /* PCM, 44100 Hz, 1 channels, 16 bits */
|
|
|
|
{ 0x01, 2, 11025, 4, 16, 0, NULL }, /* PCM, 11025 Hz, 2 channels, 16 bits */
|
|
|
|
{ 0x01, 1, 11025, 2, 16, 0, NULL }, /* PCM, 11025 Hz, 1 channels, 16 bits */
|
|
|
|
{ 0x01, 2, 8000, 4, 16, 0, NULL }, /* PCM, 8000 Hz, 2 channels, 16 bits */
|
|
|
|
{ 0x01, 1, 8000, 2, 16, 0, NULL } /* PCM, 8000 Hz, 1 channels, 16 bits */
|
|
|
|
};
|
|
|
|
|
|
|
|
static void wf_peer_rdpsnd_activated(rdpsnd_server_context* context)
|
|
|
|
{
|
2013-02-18 23:40:37 +04:00
|
|
|
#ifdef WITH_RDPSND_DSOUND
|
|
|
|
|
|
|
|
wf_directsound_activate(context);
|
|
|
|
|
|
|
|
#else
|
2012-10-13 05:02:42 +04:00
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
case WAIT_ABANDONED:
|
|
|
|
case WAIT_OBJECT_0:
|
|
|
|
return TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WAIT_TIMEOUT:
|
|
|
|
return FALSE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WAIT_FAILED:
|
|
|
|
printf("wf_rdpsnd_lock failed with 0x%08X\n", GetLastError());
|
|
|
|
return -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
printf("wf_rdpsnd_unlock failed with 0x%08X\n", GetLastError());
|
|
|
|
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)
|
|
|
|
{
|
2012-10-13 05:02:42 +04:00
|
|
|
wfInfo* wfi;
|
|
|
|
|
|
|
|
wfi = wf_info_get_instance();
|
|
|
|
|
|
|
|
wfi->snd_mutex = CreateMutex(NULL, FALSE, NULL);
|
2012-10-11 04:44:27 +04:00
|
|
|
context->rdpsnd = rdpsnd_server_context_new(context->vcm);
|
|
|
|
context->rdpsnd->data = context;
|
|
|
|
|
|
|
|
context->rdpsnd->server_formats = test_audio_formats;
|
|
|
|
context->rdpsnd->num_server_formats =
|
|
|
|
sizeof(test_audio_formats) / sizeof(test_audio_formats[0]);
|
|
|
|
|
|
|
|
context->rdpsnd->src_format.wFormatTag = 1;
|
|
|
|
context->rdpsnd->src_format.nChannels = 2;
|
|
|
|
context->rdpsnd->src_format.nSamplesPerSec = 44100;
|
|
|
|
context->rdpsnd->src_format.wBitsPerSample = 16;
|
|
|
|
|
|
|
|
context->rdpsnd->Activated = wf_peer_rdpsnd_activated;
|
|
|
|
|
|
|
|
context->rdpsnd->Initialize(context->rdpsnd);
|
|
|
|
|
2012-10-13 05:02:42 +04:00
|
|
|
wfi->snd_stop = FALSE;
|
2012-10-11 04:44:27 +04:00
|
|
|
return TRUE;
|
|
|
|
}
|
2012-10-12 18:37:19 +04:00
|
|
|
|