2011-08-15 11:08:23 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-08-15 11:08:23 +04:00
|
|
|
* Audio Output Virtual Channel
|
|
|
|
*
|
|
|
|
* Copyright 2009-2011 Jay Sorg
|
|
|
|
* Copyright 2010-2011 Vic Lee
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2011-08-17 07:54:42 +04:00
|
|
|
#ifndef _WIN32
|
|
|
|
#include <sys/time.h>
|
2013-02-28 14:47:09 +04:00
|
|
|
#include <signal.h>
|
2011-08-17 07:54:42 +04:00
|
|
|
#endif
|
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2012-08-15 01:09:01 +04:00
|
|
|
|
2012-10-09 03:54:11 +04:00
|
|
|
#include <winpr/crt.h>
|
2013-02-20 07:36:04 +04:00
|
|
|
#include <winpr/synch.h>
|
2013-02-27 02:54:16 +04:00
|
|
|
#include <winpr/print.h>
|
2012-11-19 02:32:18 +04:00
|
|
|
#include <winpr/cmdline.h>
|
2013-02-20 06:21:20 +04:00
|
|
|
#include <winpr/sysinfo.h>
|
2013-02-20 07:36:04 +04:00
|
|
|
#include <winpr/collections.h>
|
2012-10-09 03:54:11 +04:00
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
#include <freerdp/types.h>
|
2012-11-18 07:03:04 +04:00
|
|
|
#include <freerdp/addin.h>
|
|
|
|
#include <freerdp/constants.h>
|
2013-03-22 00:45:25 +04:00
|
|
|
#include <winpr/stream.h>
|
2013-02-21 19:46:11 +04:00
|
|
|
#include <freerdp/utils/signal.h>
|
2011-08-15 11:08:23 +04:00
|
|
|
#include <freerdp/utils/svc_plugin.h>
|
|
|
|
|
|
|
|
#include "rdpsnd_main.h"
|
|
|
|
|
2013-02-26 02:49:07 +04:00
|
|
|
#define TIME_DELAY_MS 65
|
2013-02-21 06:34:47 +04:00
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
struct rdpsnd_plugin
|
|
|
|
{
|
|
|
|
rdpSvcPlugin plugin;
|
|
|
|
|
2013-02-21 06:34:47 +04:00
|
|
|
HANDLE thread;
|
2013-02-26 20:16:33 +04:00
|
|
|
wMessageQueue* queue;
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE cBlockNo;
|
2013-02-26 02:49:07 +04:00
|
|
|
int wCurrentFormatNo;
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2013-02-22 03:41:41 +04:00
|
|
|
AUDIO_FORMAT* ServerFormats;
|
|
|
|
UINT16 NumberOfServerFormats;
|
|
|
|
|
|
|
|
AUDIO_FORMAT* ClientFormats;
|
|
|
|
UINT16 NumberOfClientFormats;
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL expectingWave;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE waveData[4];
|
|
|
|
UINT16 waveDataSize;
|
2013-02-26 02:49:07 +04:00
|
|
|
UINT32 wTimeStamp;
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2011-09-25 07:41:37 +04:00
|
|
|
int latency;
|
2013-02-28 00:10:35 +04:00
|
|
|
BOOL isOpen;
|
2013-02-26 20:16:33 +04:00
|
|
|
UINT16 fixedFormat;
|
|
|
|
UINT16 fixedChannel;
|
|
|
|
UINT32 fixedRate;
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2012-11-19 02:32:18 +04:00
|
|
|
char* subsystem;
|
|
|
|
char* device_name;
|
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
/* Device plugin */
|
|
|
|
rdpsndDevicePlugin* device;
|
|
|
|
};
|
|
|
|
|
2013-02-26 06:46:48 +04:00
|
|
|
void rdpsnd_send_wave_confirm_pdu(rdpsndPlugin* rdpsnd, UINT16 wTimeStamp, BYTE cConfirmedBlockNo);
|
|
|
|
|
2013-02-21 06:34:47 +04:00
|
|
|
static void* rdpsnd_schedule_thread(void* arg)
|
2011-08-15 11:08:23 +04:00
|
|
|
{
|
2013-02-20 07:36:04 +04:00
|
|
|
wMessage message;
|
2013-02-21 06:34:47 +04:00
|
|
|
UINT16 wTimeDiff;
|
2013-02-20 07:36:04 +04:00
|
|
|
UINT16 wTimeStamp;
|
|
|
|
UINT16 wCurrentTime;
|
2013-02-26 06:46:48 +04:00
|
|
|
RDPSND_WAVE* wave;
|
2013-02-21 06:34:47 +04:00
|
|
|
rdpsndPlugin* rdpsnd = (rdpsndPlugin*) arg;
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2013-02-21 06:34:47 +04:00
|
|
|
while (1)
|
2011-08-15 11:08:23 +04:00
|
|
|
{
|
2013-02-26 20:16:33 +04:00
|
|
|
if (!MessageQueue_Wait(rdpsnd->queue))
|
2013-02-21 06:34:47 +04:00
|
|
|
break;
|
|
|
|
|
2013-02-26 20:16:33 +04:00
|
|
|
if (!MessageQueue_Peek(rdpsnd->queue, &message, TRUE))
|
2013-02-21 06:34:47 +04:00
|
|
|
break;
|
|
|
|
|
2013-02-20 07:36:04 +04:00
|
|
|
if (message.id == WMQ_QUIT)
|
|
|
|
break;
|
2012-10-03 07:01:16 +04:00
|
|
|
|
2013-02-26 06:46:48 +04:00
|
|
|
wave = (RDPSND_WAVE*) message.wParam;
|
2013-02-20 07:36:04 +04:00
|
|
|
wCurrentTime = (UINT16) GetTickCount();
|
2013-02-26 06:46:48 +04:00
|
|
|
wTimeStamp = wave->wLocalTimeB;
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2013-02-21 06:34:47 +04:00
|
|
|
if (wCurrentTime <= wTimeStamp)
|
2013-02-20 21:11:19 +04:00
|
|
|
{
|
2013-02-21 06:34:47 +04:00
|
|
|
wTimeDiff = wTimeStamp - wCurrentTime;
|
|
|
|
Sleep(wTimeDiff);
|
2013-02-20 21:11:19 +04:00
|
|
|
}
|
2013-02-21 06:34:47 +04:00
|
|
|
|
2013-02-26 06:46:48 +04:00
|
|
|
rdpsnd_send_wave_confirm_pdu(rdpsnd, wave->wTimeStampB, wave->cBlockNo);
|
|
|
|
free(wave);
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
|
|
|
|
2013-02-21 06:34:47 +04:00
|
|
|
return NULL;
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
|
|
|
|
2013-02-21 22:25:43 +04:00
|
|
|
void rdpsnd_send_quality_mode_pdu(rdpsndPlugin* rdpsnd)
|
2011-08-15 11:08:23 +04:00
|
|
|
{
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* pdu;
|
2013-02-21 22:25:43 +04:00
|
|
|
|
|
|
|
pdu = stream_new(8);
|
|
|
|
stream_write_BYTE(pdu, SNDC_QUALITYMODE); /* msgType */
|
|
|
|
stream_write_BYTE(pdu, 0); /* bPad */
|
|
|
|
stream_write_UINT16(pdu, 4); /* BodySize */
|
|
|
|
stream_write_UINT16(pdu, HIGH_QUALITY); /* wQualityMode */
|
|
|
|
stream_write_UINT16(pdu, 0); /* Reserved */
|
|
|
|
|
|
|
|
svc_plugin_send((rdpSvcPlugin*) rdpsnd, pdu);
|
|
|
|
}
|
|
|
|
|
2013-02-22 03:41:41 +04:00
|
|
|
void rdpsnd_select_supported_audio_formats(rdpsndPlugin* rdpsnd)
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
AUDIO_FORMAT* serverFormat;
|
|
|
|
AUDIO_FORMAT* clientFormat;
|
|
|
|
|
|
|
|
rdpsnd_free_audio_formats(rdpsnd->ClientFormats, rdpsnd->NumberOfClientFormats);
|
|
|
|
rdpsnd->NumberOfClientFormats = 0;
|
|
|
|
rdpsnd->ClientFormats = NULL;
|
|
|
|
|
|
|
|
rdpsnd->ClientFormats = (AUDIO_FORMAT*) malloc(sizeof(AUDIO_FORMAT) * rdpsnd->NumberOfServerFormats);
|
2013-02-20 02:47:55 +04:00
|
|
|
|
2013-02-22 03:41:41 +04:00
|
|
|
for (index = 0; index < (int) rdpsnd->NumberOfServerFormats; index++)
|
2011-08-15 11:08:23 +04:00
|
|
|
{
|
2013-02-22 03:41:41 +04:00
|
|
|
serverFormat = &rdpsnd->ServerFormats[index];
|
|
|
|
|
2013-02-26 20:16:33 +04:00
|
|
|
if (rdpsnd->fixedFormat > 0 && (rdpsnd->fixedFormat != serverFormat->wFormatTag))
|
2013-02-22 03:41:41 +04:00
|
|
|
continue;
|
|
|
|
|
2013-02-26 20:16:33 +04:00
|
|
|
if (rdpsnd->fixedChannel > 0 && (rdpsnd->fixedChannel != serverFormat->nChannels))
|
2013-02-22 03:41:41 +04:00
|
|
|
continue;
|
|
|
|
|
2013-02-26 20:16:33 +04:00
|
|
|
if (rdpsnd->fixedRate > 0 && (rdpsnd->fixedRate != serverFormat->nSamplesPerSec))
|
2013-02-22 03:41:41 +04:00
|
|
|
continue;
|
|
|
|
|
2013-02-26 06:46:48 +04:00
|
|
|
if (rdpsnd->device && rdpsnd->device->FormatSupported(rdpsnd->device, serverFormat))
|
2013-02-22 03:41:41 +04:00
|
|
|
{
|
|
|
|
clientFormat = &rdpsnd->ClientFormats[rdpsnd->NumberOfClientFormats++];
|
|
|
|
|
|
|
|
CopyMemory(clientFormat, serverFormat, sizeof(AUDIO_FORMAT));
|
|
|
|
clientFormat->cbSize = 0;
|
|
|
|
|
|
|
|
if (serverFormat->cbSize > 0)
|
|
|
|
{
|
|
|
|
clientFormat->data = (BYTE*) malloc(serverFormat->cbSize);
|
|
|
|
CopyMemory(clientFormat->data, serverFormat->data, serverFormat->cbSize);
|
|
|
|
clientFormat->cbSize = serverFormat->cbSize;
|
|
|
|
}
|
|
|
|
}
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
2013-02-28 05:46:14 +04:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
printf("Server ");
|
|
|
|
rdpsnd_print_audio_formats(rdpsnd->ServerFormats, rdpsnd->NumberOfServerFormats);
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
printf("Client ");
|
|
|
|
rdpsnd_print_audio_formats(rdpsnd->ClientFormats, rdpsnd->NumberOfClientFormats);
|
|
|
|
printf("\n");
|
|
|
|
#endif
|
2013-02-22 03:41:41 +04:00
|
|
|
}
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2013-02-22 03:41:41 +04:00
|
|
|
void rdpsnd_send_client_audio_formats(rdpsndPlugin* rdpsnd)
|
|
|
|
{
|
|
|
|
int index;
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* pdu;
|
2013-02-22 03:41:41 +04:00
|
|
|
UINT16 length;
|
|
|
|
UINT32 dwVolume;
|
|
|
|
UINT16 dwVolumeLeft;
|
|
|
|
UINT16 dwVolumeRight;
|
|
|
|
UINT16 wNumberOfFormats;
|
|
|
|
AUDIO_FORMAT* clientFormat;
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2013-02-28 01:57:18 +04:00
|
|
|
if (rdpsnd->device->GetVolume)
|
|
|
|
{
|
|
|
|
dwVolume = rdpsnd->device->GetVolume(rdpsnd->device);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dwVolumeLeft = ((50 * 0xFFFF) / 100); /* 50% */
|
|
|
|
dwVolumeRight = ((50 * 0xFFFF) / 100); /* 50% */
|
|
|
|
dwVolume = (dwVolumeLeft << 16) | dwVolumeRight;
|
|
|
|
}
|
2013-02-20 06:21:20 +04:00
|
|
|
|
2013-02-22 03:41:41 +04:00
|
|
|
wNumberOfFormats = rdpsnd->NumberOfClientFormats;
|
|
|
|
|
|
|
|
length = 4 + 20;
|
|
|
|
|
|
|
|
for (index = 0; index < (int) wNumberOfFormats; index++)
|
|
|
|
length += (18 + rdpsnd->ClientFormats[index].cbSize);
|
|
|
|
|
|
|
|
pdu = stream_new(length);
|
|
|
|
|
2013-02-21 22:25:43 +04:00
|
|
|
stream_write_BYTE(pdu, SNDC_FORMATS); /* msgType */
|
|
|
|
stream_write_BYTE(pdu, 0); /* bPad */
|
2013-02-22 03:41:41 +04:00
|
|
|
stream_write_UINT16(pdu, length - 4); /* BodySize */
|
|
|
|
|
2013-02-21 22:25:43 +04:00
|
|
|
stream_write_UINT32(pdu, TSSNDCAPS_ALIVE | TSSNDCAPS_VOLUME); /* dwFlags */
|
|
|
|
stream_write_UINT32(pdu, dwVolume); /* dwVolume */
|
|
|
|
stream_write_UINT32(pdu, 0); /* dwPitch */
|
2013-02-22 03:41:41 +04:00
|
|
|
stream_write_UINT16(pdu, 0); /* wDGramPort */
|
|
|
|
stream_write_UINT16(pdu, wNumberOfFormats); /* wNumberOfFormats */
|
2013-02-21 22:25:43 +04:00
|
|
|
stream_write_BYTE(pdu, 0); /* cLastBlockConfirmed */
|
|
|
|
stream_write_UINT16(pdu, 6); /* wVersion */
|
|
|
|
stream_write_BYTE(pdu, 0); /* bPad */
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2013-02-22 03:41:41 +04:00
|
|
|
for (index = 0; index < (int) wNumberOfFormats; index++)
|
2011-08-15 11:08:23 +04:00
|
|
|
{
|
2013-02-22 03:41:41 +04:00
|
|
|
clientFormat = &rdpsnd->ClientFormats[index];
|
|
|
|
|
|
|
|
stream_write_UINT16(pdu, clientFormat->wFormatTag);
|
|
|
|
stream_write_UINT16(pdu, clientFormat->nChannels);
|
|
|
|
stream_write_UINT32(pdu, clientFormat->nSamplesPerSec);
|
|
|
|
stream_write_UINT32(pdu, clientFormat->nAvgBytesPerSec);
|
|
|
|
stream_write_UINT16(pdu, clientFormat->nBlockAlign);
|
|
|
|
stream_write_UINT16(pdu, clientFormat->wBitsPerSample);
|
|
|
|
stream_write_UINT16(pdu, clientFormat->cbSize);
|
|
|
|
|
|
|
|
if (clientFormat->cbSize > 0)
|
|
|
|
stream_write(pdu, clientFormat->data, clientFormat->cbSize);
|
|
|
|
}
|
2013-02-20 02:47:55 +04:00
|
|
|
|
2013-02-22 03:41:41 +04:00
|
|
|
svc_plugin_send((rdpSvcPlugin*) rdpsnd, pdu);
|
|
|
|
}
|
2011-08-15 12:28:52 +04:00
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
void rdpsnd_recv_server_audio_formats_pdu(rdpsndPlugin* rdpsnd, wStream* s)
|
2013-02-22 03:41:41 +04:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
UINT16 wVersion;
|
|
|
|
AUDIO_FORMAT* format;
|
|
|
|
UINT16 wNumberOfFormats;
|
2013-02-20 02:47:55 +04:00
|
|
|
|
2013-02-22 03:41:41 +04:00
|
|
|
rdpsnd_free_audio_formats(rdpsnd->ServerFormats, rdpsnd->NumberOfServerFormats);
|
|
|
|
rdpsnd->NumberOfServerFormats = 0;
|
|
|
|
rdpsnd->ServerFormats = NULL;
|
2013-02-20 02:47:55 +04:00
|
|
|
|
2013-02-22 03:41:41 +04:00
|
|
|
stream_seek_UINT32(s); /* dwFlags */
|
|
|
|
stream_seek_UINT32(s); /* dwVolume */
|
|
|
|
stream_seek_UINT32(s); /* dwPitch */
|
|
|
|
stream_seek_UINT16(s); /* wDGramPort */
|
|
|
|
stream_read_UINT16(s, wNumberOfFormats);
|
|
|
|
stream_read_BYTE(s, rdpsnd->cBlockNo); /* cLastBlockConfirmed */
|
|
|
|
stream_read_UINT16(s, wVersion); /* wVersion */
|
|
|
|
stream_seek_BYTE(s); /* bPad */
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2013-02-22 03:41:41 +04:00
|
|
|
rdpsnd->NumberOfServerFormats = wNumberOfFormats;
|
|
|
|
rdpsnd->ServerFormats = (AUDIO_FORMAT*) malloc(sizeof(AUDIO_FORMAT) * wNumberOfFormats);
|
2013-02-20 02:47:55 +04:00
|
|
|
|
2013-02-22 03:41:41 +04:00
|
|
|
for (index = 0; index < (int) wNumberOfFormats; index++)
|
2011-08-15 11:08:23 +04:00
|
|
|
{
|
2013-02-22 03:41:41 +04:00
|
|
|
format = &rdpsnd->ServerFormats[index];
|
|
|
|
|
|
|
|
stream_read_UINT16(s, format->wFormatTag); /* wFormatTag */
|
|
|
|
stream_read_UINT16(s, format->nChannels); /* nChannels */
|
|
|
|
stream_read_UINT32(s, format->nSamplesPerSec); /* nSamplesPerSec */
|
|
|
|
stream_read_UINT32(s, format->nAvgBytesPerSec); /* nAvgBytesPerSec */
|
|
|
|
stream_read_UINT16(s, format->nBlockAlign); /* nBlockAlign */
|
|
|
|
stream_read_UINT16(s, format->wBitsPerSample); /* wBitsPerSample */
|
|
|
|
stream_read_UINT16(s, format->cbSize); /* cbSize */
|
|
|
|
|
|
|
|
format->data = (BYTE*) malloc(format->cbSize);
|
|
|
|
stream_read(s, format->data, format->cbSize);
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
|
|
|
|
2013-02-22 03:41:41 +04:00
|
|
|
rdpsnd_select_supported_audio_formats(rdpsnd);
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2013-02-22 03:41:41 +04:00
|
|
|
rdpsnd_send_client_audio_formats(rdpsnd);
|
2011-08-15 11:08:23 +04:00
|
|
|
|
|
|
|
if (wVersion >= 6)
|
2013-02-21 22:25:43 +04:00
|
|
|
rdpsnd_send_quality_mode_pdu(rdpsnd);
|
|
|
|
}
|
|
|
|
|
|
|
|
void rdpsnd_send_training_confirm_pdu(rdpsndPlugin* rdpsnd, UINT16 wTimeStamp, UINT16 wPackSize)
|
|
|
|
{
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* pdu;
|
2013-02-21 22:25:43 +04:00
|
|
|
|
|
|
|
pdu = stream_new(8);
|
|
|
|
stream_write_BYTE(pdu, SNDC_TRAINING); /* msgType */
|
|
|
|
stream_write_BYTE(pdu, 0); /* bPad */
|
|
|
|
stream_write_UINT16(pdu, 4); /* BodySize */
|
|
|
|
stream_write_UINT16(pdu, wTimeStamp);
|
|
|
|
stream_write_UINT16(pdu, wPackSize);
|
|
|
|
|
|
|
|
svc_plugin_send((rdpSvcPlugin*) rdpsnd, pdu);
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static void rdpsnd_recv_training_pdu(rdpsndPlugin* rdpsnd, wStream* s)
|
2011-08-15 11:08:23 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 wTimeStamp;
|
|
|
|
UINT16 wPackSize;
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2013-02-21 22:25:43 +04:00
|
|
|
stream_read_UINT16(s, wTimeStamp);
|
|
|
|
stream_read_UINT16(s, wPackSize);
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2013-02-21 22:25:43 +04:00
|
|
|
rdpsnd_send_training_confirm_pdu(rdpsnd, wTimeStamp, wPackSize);
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static void rdpsnd_recv_wave_info_pdu(rdpsndPlugin* rdpsnd, wStream* s, UINT16 BodySize)
|
2011-08-15 11:08:23 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 wFormatNo;
|
2013-02-22 03:41:41 +04:00
|
|
|
AUDIO_FORMAT* format;
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2013-02-28 00:10:35 +04:00
|
|
|
rdpsnd->expectingWave = TRUE;
|
|
|
|
|
2013-02-22 03:41:41 +04:00
|
|
|
stream_read_UINT16(s, rdpsnd->wTimeStamp);
|
|
|
|
stream_read_UINT16(s, wFormatNo);
|
|
|
|
stream_read_BYTE(s, rdpsnd->cBlockNo);
|
|
|
|
stream_seek(s, 3); /* bPad */
|
|
|
|
stream_read(s, rdpsnd->waveData, 4);
|
2013-02-20 06:21:20 +04:00
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
rdpsnd->waveDataSize = BodySize - 8;
|
2012-11-26 10:15:11 +04:00
|
|
|
|
2013-02-22 03:41:41 +04:00
|
|
|
format = &rdpsnd->ClientFormats[wFormatNo];
|
|
|
|
|
2013-02-26 20:16:33 +04:00
|
|
|
if (!rdpsnd->isOpen)
|
2011-08-15 11:08:23 +04:00
|
|
|
{
|
2013-02-26 20:16:33 +04:00
|
|
|
rdpsnd->isOpen = TRUE;
|
2013-02-26 02:49:07 +04:00
|
|
|
rdpsnd->wCurrentFormatNo = wFormatNo;
|
2012-11-26 10:15:11 +04:00
|
|
|
|
2013-02-28 05:46:14 +04:00
|
|
|
//rdpsnd_print_audio_format(format);
|
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
if (rdpsnd->device)
|
2012-11-26 10:15:11 +04:00
|
|
|
{
|
2013-02-26 06:46:48 +04:00
|
|
|
IFCALL(rdpsnd->device->Open, rdpsnd->device, format, rdpsnd->latency);
|
2012-11-26 10:15:11 +04:00
|
|
|
}
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
2013-02-26 02:49:07 +04:00
|
|
|
else if (wFormatNo != rdpsnd->wCurrentFormatNo)
|
2011-08-15 11:08:23 +04:00
|
|
|
{
|
2013-02-26 02:49:07 +04:00
|
|
|
rdpsnd->wCurrentFormatNo = wFormatNo;
|
2012-11-26 10:15:11 +04:00
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
if (rdpsnd->device)
|
2012-11-26 10:15:11 +04:00
|
|
|
{
|
2013-02-26 06:46:48 +04:00
|
|
|
IFCALL(rdpsnd->device->SetFormat, rdpsnd->device, format, rdpsnd->latency);
|
2012-11-26 10:15:11 +04:00
|
|
|
}
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-21 22:25:43 +04:00
|
|
|
void rdpsnd_send_wave_confirm_pdu(rdpsndPlugin* rdpsnd, UINT16 wTimeStamp, BYTE cConfirmedBlockNo)
|
|
|
|
{
|
2013-03-21 23:19:33 +04:00
|
|
|
wStream* pdu;
|
2013-02-21 22:25:43 +04:00
|
|
|
|
|
|
|
pdu = stream_new(8);
|
|
|
|
stream_write_BYTE(pdu, SNDC_WAVECONFIRM);
|
|
|
|
stream_write_BYTE(pdu, 0);
|
|
|
|
stream_write_UINT16(pdu, 4);
|
|
|
|
stream_write_UINT16(pdu, wTimeStamp);
|
|
|
|
stream_write_BYTE(pdu, cConfirmedBlockNo); /* cConfirmedBlockNo */
|
|
|
|
stream_write_BYTE(pdu, 0); /* bPad */
|
|
|
|
|
|
|
|
svc_plugin_send((rdpSvcPlugin*) rdpsnd, pdu);
|
|
|
|
}
|
|
|
|
|
2013-02-26 06:46:48 +04:00
|
|
|
void rdpsnd_device_send_wave_confirm_pdu(rdpsndDevicePlugin* device, RDPSND_WAVE* wave)
|
2013-02-26 02:49:07 +04:00
|
|
|
{
|
2013-02-26 20:16:33 +04:00
|
|
|
MessageQueue_Post(device->rdpsnd->queue, NULL, 0, (void*) wave, NULL);
|
2013-02-26 02:49:07 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static void rdpsnd_recv_wave_pdu(rdpsndPlugin* rdpsnd, wStream* s)
|
2011-08-15 11:08:23 +04:00
|
|
|
{
|
2013-02-26 02:49:07 +04:00
|
|
|
int size;
|
|
|
|
BYTE* data;
|
2013-02-26 06:46:48 +04:00
|
|
|
RDPSND_WAVE* wave;
|
2013-02-26 02:49:07 +04:00
|
|
|
AUDIO_FORMAT* format;
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2013-02-21 11:56:57 +04:00
|
|
|
rdpsnd->expectingWave = FALSE;
|
2012-11-26 10:15:11 +04:00
|
|
|
|
2013-02-21 22:25:43 +04:00
|
|
|
/**
|
|
|
|
* The Wave PDU is a special case: it is always sent after a Wave Info PDU,
|
|
|
|
* and we do not process its header. Instead, the header is pad that needs
|
|
|
|
* to be filled with the first four bytes of the audio sample data sent as
|
|
|
|
* part of the preceding Wave Info PDU.
|
|
|
|
*/
|
|
|
|
|
|
|
|
CopyMemory(stream_get_head(s), rdpsnd->waveData, 4);
|
2012-11-26 10:15:11 +04:00
|
|
|
|
2013-02-26 02:49:07 +04:00
|
|
|
data = stream_get_head(s);
|
|
|
|
size = stream_get_size(s);
|
|
|
|
|
2013-02-26 06:46:48 +04:00
|
|
|
wave = (RDPSND_WAVE*) malloc(sizeof(RDPSND_WAVE));
|
|
|
|
|
|
|
|
wave->wLocalTimeA = GetTickCount();
|
|
|
|
wave->wTimeStampA = rdpsnd->wTimeStamp;
|
|
|
|
wave->wFormatNo = rdpsnd->wCurrentFormatNo;
|
|
|
|
wave->cBlockNo = rdpsnd->cBlockNo;
|
|
|
|
|
|
|
|
wave->data = data;
|
|
|
|
wave->length = size;
|
|
|
|
|
2013-02-26 02:49:07 +04:00
|
|
|
format = &rdpsnd->ClientFormats[rdpsnd->wCurrentFormatNo];
|
2013-02-26 06:46:48 +04:00
|
|
|
wave->wAudioLength = rdpsnd_compute_audio_time_length(format, size);
|
2013-02-26 02:49:07 +04:00
|
|
|
|
2013-02-26 06:46:48 +04:00
|
|
|
if (!rdpsnd->device)
|
|
|
|
return;
|
2012-11-26 10:15:11 +04:00
|
|
|
|
2013-02-26 06:46:48 +04:00
|
|
|
if (rdpsnd->device->WaveDecode)
|
2012-11-26 10:15:11 +04:00
|
|
|
{
|
2013-02-26 06:46:48 +04:00
|
|
|
IFCALL(rdpsnd->device->WaveDecode, rdpsnd->device, wave);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rdpsnd->device->WavePlay)
|
|
|
|
{
|
|
|
|
IFCALL(rdpsnd->device->WavePlay, rdpsnd->device, wave);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IFCALL(rdpsnd->device->Play, rdpsnd->device, data, size);
|
2012-11-26 10:15:11 +04:00
|
|
|
}
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2013-02-21 23:58:39 +04:00
|
|
|
if (!rdpsnd->device->WavePlay)
|
|
|
|
{
|
2013-02-26 06:46:48 +04:00
|
|
|
wave->wTimeStampB = rdpsnd->wTimeStamp + wave->wAudioLength + TIME_DELAY_MS;
|
|
|
|
wave->wLocalTimeB = wave->wLocalTimeA + wave->wAudioLength + TIME_DELAY_MS;
|
|
|
|
rdpsnd->device->WaveConfirm(rdpsnd->device, wave);
|
2013-02-21 23:58:39 +04:00
|
|
|
}
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
|
|
|
|
2013-02-21 22:25:43 +04:00
|
|
|
static void rdpsnd_recv_close_pdu(rdpsndPlugin* rdpsnd)
|
2011-08-15 11:08:23 +04:00
|
|
|
{
|
|
|
|
DEBUG_SVC("server closes.");
|
2012-11-26 10:15:11 +04:00
|
|
|
|
2011-08-15 12:58:07 +04:00
|
|
|
if (rdpsnd->device)
|
2012-11-26 10:15:11 +04:00
|
|
|
{
|
2013-02-28 00:10:35 +04:00
|
|
|
IFCALL(rdpsnd->device->Close, rdpsnd->device);
|
2012-11-26 10:15:11 +04:00
|
|
|
}
|
2013-02-28 00:10:35 +04:00
|
|
|
|
|
|
|
rdpsnd->isOpen = FALSE;
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static void rdpsnd_recv_volume_pdu(rdpsndPlugin* rdpsnd, wStream* s)
|
2011-08-15 11:08:23 +04:00
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 dwVolume;
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2013-02-22 03:41:41 +04:00
|
|
|
stream_read_UINT32(s, dwVolume);
|
2011-08-15 11:08:23 +04:00
|
|
|
DEBUG_SVC("dwVolume 0x%X", dwVolume);
|
2012-11-26 10:15:11 +04:00
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
if (rdpsnd->device)
|
2012-11-26 10:15:11 +04:00
|
|
|
{
|
2011-08-15 11:08:23 +04:00
|
|
|
IFCALL(rdpsnd->device->SetVolume, rdpsnd->device, dwVolume);
|
2012-11-26 10:15:11 +04:00
|
|
|
}
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
|
|
|
|
2013-03-21 23:19:33 +04:00
|
|
|
static void rdpsnd_recv_pdu(rdpSvcPlugin* plugin, wStream* s)
|
2011-08-15 11:08:23 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE msgType;
|
|
|
|
UINT16 BodySize;
|
2013-02-21 19:46:11 +04:00
|
|
|
rdpsndPlugin* rdpsnd = (rdpsndPlugin*) plugin;
|
2011-08-15 11:08:23 +04:00
|
|
|
|
|
|
|
if (rdpsnd->expectingWave)
|
|
|
|
{
|
2013-02-22 03:41:41 +04:00
|
|
|
rdpsnd_recv_wave_pdu(rdpsnd, s);
|
|
|
|
stream_free(s);
|
2011-08-15 11:08:23 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-22 03:41:41 +04:00
|
|
|
stream_read_BYTE(s, msgType); /* msgType */
|
|
|
|
stream_seek_BYTE(s); /* bPad */
|
|
|
|
stream_read_UINT16(s, BodySize);
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2013-02-28 00:10:35 +04:00
|
|
|
//printf("msgType %d BodySize %d\n", msgType, BodySize);
|
2011-08-15 11:08:23 +04:00
|
|
|
|
|
|
|
switch (msgType)
|
|
|
|
{
|
|
|
|
case SNDC_FORMATS:
|
2013-02-22 03:41:41 +04:00
|
|
|
rdpsnd_recv_server_audio_formats_pdu(rdpsnd, s);
|
2011-08-15 11:08:23 +04:00
|
|
|
break;
|
2012-11-26 10:15:11 +04:00
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
case SNDC_TRAINING:
|
2013-02-22 03:41:41 +04:00
|
|
|
rdpsnd_recv_training_pdu(rdpsnd, s);
|
2011-08-15 11:08:23 +04:00
|
|
|
break;
|
2012-11-26 10:15:11 +04:00
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
case SNDC_WAVE:
|
2013-02-22 03:41:41 +04:00
|
|
|
rdpsnd_recv_wave_info_pdu(rdpsnd, s, BodySize);
|
2011-08-15 11:08:23 +04:00
|
|
|
break;
|
2012-11-26 10:15:11 +04:00
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
case SNDC_CLOSE:
|
2013-02-21 22:25:43 +04:00
|
|
|
rdpsnd_recv_close_pdu(rdpsnd);
|
2011-08-15 11:08:23 +04:00
|
|
|
break;
|
2012-11-26 10:15:11 +04:00
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
case SNDC_SETVOLUME:
|
2013-02-22 03:41:41 +04:00
|
|
|
rdpsnd_recv_volume_pdu(rdpsnd, s);
|
2011-08-15 11:08:23 +04:00
|
|
|
break;
|
2012-11-26 10:15:11 +04:00
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
default:
|
|
|
|
DEBUG_WARN("unknown msgType %d", msgType);
|
|
|
|
break;
|
|
|
|
}
|
2012-02-27 21:12:17 +04:00
|
|
|
|
2013-02-22 03:41:41 +04:00
|
|
|
stream_free(s);
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void rdpsnd_register_device_plugin(rdpsndPlugin* rdpsnd, rdpsndDevicePlugin* device)
|
|
|
|
{
|
|
|
|
if (rdpsnd->device)
|
|
|
|
{
|
|
|
|
DEBUG_WARN("existing device, abort.");
|
|
|
|
return;
|
|
|
|
}
|
2013-02-21 22:25:43 +04:00
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
rdpsnd->device = device;
|
2013-02-21 22:25:43 +04:00
|
|
|
device->rdpsnd = rdpsnd;
|
|
|
|
|
|
|
|
device->WaveConfirm = rdpsnd_device_send_wave_confirm_pdu;
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
|
|
|
|
2012-11-19 02:32:18 +04:00
|
|
|
static BOOL rdpsnd_load_device_plugin(rdpsndPlugin* rdpsnd, const char* name, ADDIN_ARGV* args)
|
2011-08-15 11:08:23 +04:00
|
|
|
{
|
|
|
|
PFREERDP_RDPSND_DEVICE_ENTRY entry;
|
2012-11-18 07:03:04 +04:00
|
|
|
FREERDP_RDPSND_DEVICE_ENTRY_POINTS entryPoints;
|
|
|
|
|
|
|
|
entry = (PFREERDP_RDPSND_DEVICE_ENTRY) freerdp_load_channel_addin_entry("rdpsnd", (LPSTR) name, NULL, 0);
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2013-02-21 22:25:43 +04:00
|
|
|
if (!entry)
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-15 11:08:23 +04:00
|
|
|
|
|
|
|
entryPoints.rdpsnd = rdpsnd;
|
|
|
|
entryPoints.pRegisterRdpsndDevice = rdpsnd_register_device_plugin;
|
2012-11-19 02:32:18 +04:00
|
|
|
entryPoints.args = args;
|
2012-11-03 03:42:57 +04:00
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
if (entry(&entryPoints) != 0)
|
|
|
|
{
|
|
|
|
DEBUG_WARN("%s entry returns error.", name);
|
2012-10-09 10:31:28 +04:00
|
|
|
return FALSE;
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
2012-11-03 03:42:57 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
return TRUE;
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
|
|
|
|
2012-11-19 02:32:18 +04:00
|
|
|
void rdpsnd_set_subsystem(rdpsndPlugin* rdpsnd, char* subsystem)
|
2011-08-15 11:08:23 +04:00
|
|
|
{
|
2012-11-19 02:32:18 +04:00
|
|
|
if (rdpsnd->subsystem)
|
|
|
|
free(rdpsnd->subsystem);
|
|
|
|
|
|
|
|
rdpsnd->subsystem = _strdup(subsystem);
|
|
|
|
}
|
|
|
|
|
|
|
|
void rdpsnd_set_device_name(rdpsndPlugin* rdpsnd, char* device_name)
|
|
|
|
{
|
|
|
|
if (rdpsnd->device_name)
|
|
|
|
free(rdpsnd->device_name);
|
|
|
|
|
|
|
|
rdpsnd->device_name = _strdup(device_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
COMMAND_LINE_ARGUMENT_A rdpsnd_args[] =
|
|
|
|
{
|
|
|
|
{ "sys", COMMAND_LINE_VALUE_REQUIRED, "<subsystem>", NULL, NULL, -1, NULL, "subsystem" },
|
|
|
|
{ "dev", COMMAND_LINE_VALUE_REQUIRED, "<device>", NULL, NULL, -1, NULL, "device" },
|
|
|
|
{ "format", COMMAND_LINE_VALUE_REQUIRED, "<format>", NULL, NULL, -1, NULL, "format" },
|
|
|
|
{ "rate", COMMAND_LINE_VALUE_REQUIRED, "<rate>", NULL, NULL, -1, NULL, "rate" },
|
|
|
|
{ "channel", COMMAND_LINE_VALUE_REQUIRED, "<channel>", NULL, NULL, -1, NULL, "channel" },
|
|
|
|
{ "latency", COMMAND_LINE_VALUE_REQUIRED, "<latency>", NULL, NULL, -1, NULL, "latency" },
|
|
|
|
{ NULL, 0, NULL, NULL, NULL, -1, NULL, NULL }
|
|
|
|
};
|
|
|
|
|
|
|
|
static void rdpsnd_process_addin_args(rdpsndPlugin* rdpsnd, ADDIN_ARGV* args)
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
DWORD flags;
|
|
|
|
COMMAND_LINE_ARGUMENT_A* arg;
|
|
|
|
|
|
|
|
flags = COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON;
|
|
|
|
|
|
|
|
status = CommandLineParseArgumentsA(args->argc, (const char**) args->argv,
|
|
|
|
rdpsnd_args, flags, rdpsnd, NULL, NULL);
|
|
|
|
|
|
|
|
arg = rdpsnd_args;
|
|
|
|
|
|
|
|
do
|
2011-08-15 11:08:23 +04:00
|
|
|
{
|
2012-11-19 02:32:18 +04:00
|
|
|
if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
CommandLineSwitchStart(arg)
|
|
|
|
|
|
|
|
CommandLineSwitchCase(arg, "sys")
|
|
|
|
{
|
|
|
|
rdpsnd_set_subsystem(rdpsnd, arg->Value);
|
|
|
|
}
|
|
|
|
CommandLineSwitchCase(arg, "dev")
|
|
|
|
{
|
|
|
|
rdpsnd_set_device_name(rdpsnd, arg->Value);
|
|
|
|
}
|
|
|
|
CommandLineSwitchCase(arg, "format")
|
|
|
|
{
|
2013-02-26 20:16:33 +04:00
|
|
|
rdpsnd->fixedFormat = atoi(arg->Value);
|
2012-11-19 02:32:18 +04:00
|
|
|
}
|
|
|
|
CommandLineSwitchCase(arg, "rate")
|
|
|
|
{
|
2013-02-26 20:16:33 +04:00
|
|
|
rdpsnd->fixedRate = atoi(arg->Value);
|
2012-11-19 02:32:18 +04:00
|
|
|
}
|
|
|
|
CommandLineSwitchCase(arg, "channel")
|
|
|
|
{
|
2013-02-26 20:16:33 +04:00
|
|
|
rdpsnd->fixedChannel = atoi(arg->Value);
|
2012-11-19 02:32:18 +04:00
|
|
|
}
|
|
|
|
CommandLineSwitchCase(arg, "latency")
|
|
|
|
{
|
|
|
|
rdpsnd->latency = atoi(arg->Value);
|
|
|
|
}
|
|
|
|
CommandLineSwitchDefault(arg)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
CommandLineSwitchEnd(arg)
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
2012-11-19 02:32:18 +04:00
|
|
|
while ((arg = CommandLineFindNextArgumentA(arg)) != NULL);
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void rdpsnd_process_connect(rdpSvcPlugin* plugin)
|
|
|
|
{
|
2012-11-19 02:32:18 +04:00
|
|
|
ADDIN_ARGV* args;
|
2012-07-29 06:24:14 +04:00
|
|
|
rdpsndPlugin* rdpsnd = (rdpsndPlugin*) plugin;
|
2011-08-15 11:08:23 +04:00
|
|
|
|
|
|
|
DEBUG_SVC("connecting");
|
|
|
|
|
2011-09-25 07:41:37 +04:00
|
|
|
rdpsnd->latency = -1;
|
2013-02-26 20:16:33 +04:00
|
|
|
rdpsnd->queue = MessageQueue_New();
|
2013-02-21 06:34:47 +04:00
|
|
|
rdpsnd->thread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) rdpsnd_schedule_thread, (void*) plugin, 0, NULL);
|
2013-02-20 07:36:04 +04:00
|
|
|
|
2012-11-19 02:32:18 +04:00
|
|
|
args = (ADDIN_ARGV*) plugin->channel_entry_points.pExtendedData;
|
|
|
|
|
|
|
|
if (args)
|
|
|
|
rdpsnd_process_addin_args(rdpsnd, args);
|
2012-07-29 06:24:14 +04:00
|
|
|
|
2012-11-19 02:32:18 +04:00
|
|
|
if (rdpsnd->subsystem)
|
2012-11-21 18:30:06 +04:00
|
|
|
{
|
|
|
|
if (strcmp(rdpsnd->subsystem, "fake") == 0)
|
|
|
|
return;
|
|
|
|
|
2012-11-19 02:32:18 +04:00
|
|
|
rdpsnd_load_device_plugin(rdpsnd, rdpsnd->subsystem, args);
|
2012-11-21 18:30:06 +04:00
|
|
|
}
|
2012-11-19 02:32:18 +04:00
|
|
|
|
|
|
|
if (!rdpsnd->device)
|
2011-08-15 11:08:23 +04:00
|
|
|
{
|
2012-11-19 02:32:18 +04:00
|
|
|
rdpsnd_set_subsystem(rdpsnd, "pulse");
|
|
|
|
rdpsnd_set_device_name(rdpsnd, "");
|
|
|
|
rdpsnd_load_device_plugin(rdpsnd, rdpsnd->subsystem, args);
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
|
|
|
|
2012-11-19 02:32:18 +04:00
|
|
|
if (!rdpsnd->device)
|
2011-08-15 11:08:23 +04:00
|
|
|
{
|
2012-11-19 02:32:18 +04:00
|
|
|
rdpsnd_set_subsystem(rdpsnd, "alsa");
|
|
|
|
rdpsnd_set_device_name(rdpsnd, "default");
|
|
|
|
rdpsnd_load_device_plugin(rdpsnd, rdpsnd->subsystem, args);
|
|
|
|
}
|
2012-08-01 20:50:27 +04:00
|
|
|
|
2012-11-19 02:32:18 +04:00
|
|
|
if (!rdpsnd->device)
|
|
|
|
{
|
|
|
|
rdpsnd_set_subsystem(rdpsnd, "macaudio");
|
|
|
|
rdpsnd_set_device_name(rdpsnd, "default");
|
|
|
|
rdpsnd_load_device_plugin(rdpsnd, rdpsnd->subsystem, args);
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
2012-11-19 02:32:18 +04:00
|
|
|
|
2012-12-27 15:19:52 +04:00
|
|
|
if (!rdpsnd->device)
|
|
|
|
{
|
|
|
|
rdpsnd_set_subsystem(rdpsnd, "winmm");
|
|
|
|
rdpsnd_set_device_name(rdpsnd, "");
|
|
|
|
rdpsnd_load_device_plugin(rdpsnd, rdpsnd->subsystem, args);
|
|
|
|
}
|
|
|
|
|
2013-02-21 00:33:42 +04:00
|
|
|
if (!rdpsnd->device)
|
2011-08-15 11:08:23 +04:00
|
|
|
{
|
|
|
|
DEBUG_WARN("no sound device.");
|
2013-02-21 22:25:43 +04:00
|
|
|
return;
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-18 01:28:26 +04:00
|
|
|
static void rdpsnd_process_event(rdpSvcPlugin* plugin, RDP_EVENT* event)
|
2011-08-15 11:08:23 +04:00
|
|
|
{
|
|
|
|
freerdp_event_free(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rdpsnd_process_terminate(rdpSvcPlugin* plugin)
|
|
|
|
{
|
2012-10-03 07:01:16 +04:00
|
|
|
rdpsndPlugin* rdpsnd = (rdpsndPlugin*) plugin;
|
2011-08-15 11:08:23 +04:00
|
|
|
|
|
|
|
if (rdpsnd->device)
|
|
|
|
IFCALL(rdpsnd->device->Free, rdpsnd->device);
|
|
|
|
|
2013-02-26 20:16:33 +04:00
|
|
|
MessageQueue_PostQuit(rdpsnd->queue, 0);
|
|
|
|
WaitForSingleObject(rdpsnd->thread, INFINITE);
|
|
|
|
|
|
|
|
MessageQueue_Free(rdpsnd->queue);
|
|
|
|
CloseHandle(rdpsnd->thread);
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2012-11-19 22:26:56 +04:00
|
|
|
if (rdpsnd->subsystem)
|
|
|
|
free(rdpsnd->subsystem);
|
|
|
|
|
|
|
|
if (rdpsnd->device_name)
|
|
|
|
free(rdpsnd->device_name);
|
|
|
|
|
2013-02-22 04:20:13 +04:00
|
|
|
rdpsnd_free_audio_formats(rdpsnd->ServerFormats, rdpsnd->NumberOfServerFormats);
|
|
|
|
rdpsnd->NumberOfServerFormats = 0;
|
|
|
|
rdpsnd->ServerFormats = NULL;
|
|
|
|
|
|
|
|
rdpsnd_free_audio_formats(rdpsnd->ClientFormats, rdpsnd->NumberOfClientFormats);
|
|
|
|
rdpsnd->NumberOfClientFormats = 0;
|
|
|
|
rdpsnd->ClientFormats = NULL;
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 06:48:17 +04:00
|
|
|
/* rdpsnd is always built-in */
|
2012-10-09 03:54:11 +04:00
|
|
|
#define VirtualChannelEntry rdpsnd_VirtualChannelEntry
|
|
|
|
|
2012-11-01 07:04:31 +04:00
|
|
|
int VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints)
|
2012-10-09 03:54:11 +04:00
|
|
|
{
|
|
|
|
rdpsndPlugin* _p;
|
|
|
|
|
|
|
|
_p = (rdpsndPlugin*) malloc(sizeof(rdpsndPlugin));
|
|
|
|
ZeroMemory(_p, sizeof(rdpsndPlugin));
|
|
|
|
|
|
|
|
_p->plugin.channel_def.options =
|
|
|
|
CHANNEL_OPTION_INITIALIZED |
|
|
|
|
CHANNEL_OPTION_ENCRYPT_RDP;
|
|
|
|
|
|
|
|
strcpy(_p->plugin.channel_def.name, "rdpsnd");
|
|
|
|
|
|
|
|
_p->plugin.connect_callback = rdpsnd_process_connect;
|
2013-02-21 22:25:43 +04:00
|
|
|
_p->plugin.receive_callback = rdpsnd_recv_pdu;
|
2012-10-09 03:54:11 +04:00
|
|
|
_p->plugin.event_callback = rdpsnd_process_event;
|
|
|
|
_p->plugin.terminate_callback = rdpsnd_process_terminate;
|
|
|
|
|
2013-02-28 14:47:09 +04:00
|
|
|
#if !defined(_WIN32) && !defined(ANDROID)
|
2013-02-21 19:46:11 +04:00
|
|
|
{
|
|
|
|
sigset_t mask;
|
|
|
|
sigemptyset(&mask);
|
|
|
|
sigaddset(&mask, SIGIO);
|
|
|
|
pthread_sigmask(SIG_BLOCK, &mask, NULL);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-10-09 03:54:11 +04:00
|
|
|
svc_plugin_init((rdpSvcPlugin*) _p, pEntryPoints);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|