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
|
2013-10-19 20:38:31 +04:00
|
|
|
* Copyright 2012-2013 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
2011-08-15 11:08:23 +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.
|
|
|
|
*/
|
|
|
|
|
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-11-20 00:31:38 +04:00
|
|
|
#include <winpr/wlog.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>
|
2013-10-20 00:20:31 +04:00
|
|
|
#include <winpr/thread.h>
|
|
|
|
#include <winpr/stream.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>
|
2014-08-11 11:12:01 +04:00
|
|
|
#include <freerdp/channels/log.h>
|
2013-02-21 19:46:11 +04:00
|
|
|
#include <freerdp/utils/signal.h>
|
2011-08-15 11:08:23 +04:00
|
|
|
|
|
|
|
#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
|
|
|
|
{
|
2013-10-20 00:20:31 +04:00
|
|
|
CHANNEL_DEF channelDef;
|
2014-02-17 02:38:59 +04:00
|
|
|
CHANNEL_ENTRY_POINTS_FREERDP channelEntryPoints;
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2013-02-21 06:34:47 +04:00
|
|
|
HANDLE thread;
|
2013-10-20 00:20:31 +04:00
|
|
|
wStream* data_in;
|
|
|
|
void* InitHandle;
|
2014-02-17 02:27:36 +04:00
|
|
|
DWORD OpenHandle;
|
2013-10-20 00:20:31 +04:00
|
|
|
wMessagePipe* MsgPipe;
|
|
|
|
|
2013-11-20 00:31:38 +04:00
|
|
|
wLog* log;
|
2015-01-20 13:53:12 +03:00
|
|
|
HANDLE stopEvent;
|
2013-10-20 00:20:31 +04:00
|
|
|
HANDLE ScheduleThread;
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE cBlockNo;
|
2013-11-19 23:29:31 +04:00
|
|
|
UINT16 wQualityMode;
|
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-11-20 00:31:38 +04:00
|
|
|
static void rdpsnd_confirm_wave(rdpsndPlugin* rdpsnd, RDPSND_WAVE* wave);
|
2013-02-26 06:46:48 +04:00
|
|
|
|
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;
|
2015-01-20 13:53:12 +03:00
|
|
|
HANDLE events[2];
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2015-01-20 13:53:12 +03:00
|
|
|
events[0] = MessageQueue_Event(rdpsnd->MsgPipe->Out);
|
|
|
|
events[1] = rdpsnd->stopEvent;
|
2013-02-21 06:34:47 +04:00
|
|
|
|
2015-01-20 13:53:12 +03:00
|
|
|
while (WaitForMultipleObjects(2, events, FALSE, INFINITE) == WAIT_OBJECT_0)
|
|
|
|
{
|
2013-10-20 00:42:42 +04:00
|
|
|
if (!MessageQueue_Peek(rdpsnd->MsgPipe->Out, &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-11-20 00:31:38 +04:00
|
|
|
rdpsnd_confirm_wave(rdpsnd, wave);
|
|
|
|
|
2013-09-27 13:45:53 +04:00
|
|
|
message.wParam = NULL;
|
2013-11-20 00:31:38 +04:00
|
|
|
free(wave);
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
|
|
|
|
2015-01-20 13:53:12 +03:00
|
|
|
ExitThread(0);
|
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
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
pdu = Stream_New(NULL, 8);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(pdu, SNDC_QUALITYMODE); /* msgType */
|
|
|
|
Stream_Write_UINT8(pdu, 0); /* bPad */
|
|
|
|
Stream_Write_UINT16(pdu, 4); /* BodySize */
|
2013-11-19 23:29:31 +04:00
|
|
|
Stream_Write_UINT16(pdu, rdpsnd->wQualityMode); /* wQualityMode */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT16(pdu, 0); /* Reserved */
|
2013-02-21 22:25:43 +04:00
|
|
|
|
2013-11-20 00:31:38 +04:00
|
|
|
WLog_Print(rdpsnd->log, WLOG_DEBUG, "QualityMode: %d", rdpsnd->wQualityMode);
|
|
|
|
|
2013-10-20 00:20:31 +04:00
|
|
|
rdpsnd_virtual_channel_write(rdpsnd, pdu);
|
2013-02-21 22:25:43 +04:00
|
|
|
}
|
|
|
|
|
2015-01-20 13:53:12 +03:00
|
|
|
static void rdpsnd_select_supported_audio_formats(rdpsndPlugin* rdpsnd)
|
2013-02-22 03:41:41 +04:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
AUDIO_FORMAT* serverFormat;
|
|
|
|
AUDIO_FORMAT* clientFormat;
|
|
|
|
|
|
|
|
rdpsnd_free_audio_formats(rdpsnd->ClientFormats, rdpsnd->NumberOfClientFormats);
|
|
|
|
rdpsnd->NumberOfClientFormats = 0;
|
|
|
|
rdpsnd->ClientFormats = NULL;
|
|
|
|
|
2013-08-30 16:19:50 +04:00
|
|
|
if (!rdpsnd->NumberOfServerFormats)
|
|
|
|
return;
|
2013-02-20 02:47:55 +04:00
|
|
|
|
2013-08-30 16:19:50 +04:00
|
|
|
rdpsnd->ClientFormats = (AUDIO_FORMAT*) malloc(sizeof(AUDIO_FORMAT) * rdpsnd->NumberOfServerFormats);
|
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
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "Server ");
|
2013-02-28 05:46:14 +04:00
|
|
|
rdpsnd_print_audio_formats(rdpsnd->ServerFormats, rdpsnd->NumberOfServerFormats);
|
2015-01-20 13:53:12 +03:00
|
|
|
WLog_ERR(TAG, "");
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "Client ");
|
2013-02-28 05:46:14 +04:00
|
|
|
rdpsnd_print_audio_formats(rdpsnd->ClientFormats, rdpsnd->NumberOfClientFormats);
|
2015-01-20 13:53:12 +03:00
|
|
|
WLog_ERR(TAG, "");
|
2013-02-28 05:46:14 +04:00
|
|
|
#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-05-25 23:49:44 +04:00
|
|
|
dwVolumeLeft = ((50 * 0xFFFF) / 100); /* 50% */
|
|
|
|
dwVolumeRight = ((50 * 0xFFFF) / 100); /* 50% */
|
|
|
|
dwVolume = (dwVolumeLeft << 16) | dwVolumeRight;
|
|
|
|
|
2013-05-20 23:50:22 +04:00
|
|
|
if (rdpsnd->device)
|
2013-02-28 01:57:18 +04:00
|
|
|
{
|
2013-05-20 23:50:22 +04:00
|
|
|
if (rdpsnd->device->GetVolume)
|
|
|
|
dwVolume = rdpsnd->device->GetVolume(rdpsnd->device);
|
2013-02-28 01:57:18 +04:00
|
|
|
}
|
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);
|
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
pdu = Stream_New(NULL, length);
|
2013-02-22 03:41:41 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(pdu, SNDC_FORMATS); /* msgType */
|
|
|
|
Stream_Write_UINT8(pdu, 0); /* bPad */
|
|
|
|
Stream_Write_UINT16(pdu, length - 4); /* BodySize */
|
2013-02-22 03:41:41 +04:00
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT32(pdu, TSSNDCAPS_ALIVE | TSSNDCAPS_VOLUME); /* dwFlags */
|
|
|
|
Stream_Write_UINT32(pdu, dwVolume); /* dwVolume */
|
|
|
|
Stream_Write_UINT32(pdu, 0); /* dwPitch */
|
|
|
|
Stream_Write_UINT16(pdu, 0); /* wDGramPort */
|
|
|
|
Stream_Write_UINT16(pdu, wNumberOfFormats); /* wNumberOfFormats */
|
|
|
|
Stream_Write_UINT8(pdu, 0); /* cLastBlockConfirmed */
|
|
|
|
Stream_Write_UINT16(pdu, 6); /* wVersion */
|
|
|
|
Stream_Write_UINT8(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];
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
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);
|
2013-02-22 03:41:41 +04:00
|
|
|
|
|
|
|
if (clientFormat->cbSize > 0)
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write(pdu, clientFormat->data, clientFormat->cbSize);
|
2013-02-22 03:41:41 +04:00
|
|
|
}
|
2013-02-20 02:47:55 +04:00
|
|
|
|
2013-11-20 00:31:38 +04:00
|
|
|
WLog_Print(rdpsnd->log, WLOG_DEBUG, "Client Audio Formats");
|
|
|
|
|
2013-10-20 00:20:31 +04:00
|
|
|
rdpsnd_virtual_channel_write(rdpsnd, pdu);
|
2013-02-22 03:41:41 +04:00
|
|
|
}
|
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
|
|
|
|
2014-03-12 11:04:33 +04:00
|
|
|
/* http://msdn.microsoft.com/en-us/library/cc240956.aspx */
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek_UINT32(s); /* dwFlags */
|
2014-03-12 11:04:33 +04:00
|
|
|
Stream_Seek_UINT32(s); /* dwVolume */
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek_UINT32(s); /* dwPitch */
|
|
|
|
Stream_Seek_UINT16(s); /* wDGramPort */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, wNumberOfFormats);
|
|
|
|
Stream_Read_UINT8(s, rdpsnd->cBlockNo); /* cLastBlockConfirmed */
|
|
|
|
Stream_Read_UINT16(s, wVersion); /* wVersion */
|
2013-05-09 00:27:21 +04:00
|
|
|
Stream_Seek_UINT8(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];
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
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 */
|
2013-02-22 03:41:41 +04:00
|
|
|
|
2013-11-04 04:10:33 +04:00
|
|
|
if (format->cbSize > 0)
|
|
|
|
{
|
|
|
|
format->data = (BYTE*) malloc(format->cbSize);
|
|
|
|
Stream_Read(s, format->data, format->cbSize);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
format->data = NULL;
|
|
|
|
}
|
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-11-20 00:31:38 +04:00
|
|
|
WLog_Print(rdpsnd->log, WLOG_DEBUG, "Server Audio Formats");
|
|
|
|
|
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
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
pdu = Stream_New(NULL, 8);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(pdu, SNDC_TRAINING); /* msgType */
|
|
|
|
Stream_Write_UINT8(pdu, 0); /* bPad */
|
|
|
|
Stream_Write_UINT16(pdu, 4); /* BodySize */
|
|
|
|
Stream_Write_UINT16(pdu, wTimeStamp);
|
|
|
|
Stream_Write_UINT16(pdu, wPackSize);
|
2013-02-21 22:25:43 +04:00
|
|
|
|
2013-11-20 00:31:38 +04:00
|
|
|
WLog_Print(rdpsnd->log, WLOG_DEBUG, "Training Response: wTimeStamp: %d wPackSize: %d",
|
|
|
|
wTimeStamp, wPackSize);
|
|
|
|
|
2013-10-20 00:20:31 +04:00
|
|
|
rdpsnd_virtual_channel_write(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-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, wTimeStamp);
|
|
|
|
Stream_Read_UINT16(s, wPackSize);
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2013-11-20 00:31:38 +04:00
|
|
|
WLog_Print(rdpsnd->log, WLOG_DEBUG, "Training Request: wTimeStamp: %d wPackSize: %d",
|
|
|
|
wTimeStamp, wPackSize);
|
|
|
|
|
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-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, rdpsnd->wTimeStamp);
|
|
|
|
Stream_Read_UINT16(s, wFormatNo);
|
|
|
|
Stream_Read_UINT8(s, rdpsnd->cBlockNo);
|
2013-04-30 06:35:15 +04:00
|
|
|
Stream_Seek(s, 3); /* bPad */
|
2013-05-09 00:09:16 +04:00
|
|
|
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-11-20 00:31:38 +04:00
|
|
|
WLog_Print(rdpsnd->log, WLOG_DEBUG, "WaveInfo: cBlockNo: %d wFormatNo: %d",
|
|
|
|
rdpsnd->cBlockNo, 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
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
pdu = Stream_New(NULL, 8);
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Write_UINT8(pdu, SNDC_WAVECONFIRM);
|
|
|
|
Stream_Write_UINT8(pdu, 0);
|
|
|
|
Stream_Write_UINT16(pdu, 4);
|
|
|
|
Stream_Write_UINT16(pdu, wTimeStamp);
|
|
|
|
Stream_Write_UINT8(pdu, cConfirmedBlockNo); /* cConfirmedBlockNo */
|
|
|
|
Stream_Write_UINT8(pdu, 0); /* bPad */
|
2013-02-21 22:25:43 +04:00
|
|
|
|
2013-10-20 00:20:31 +04:00
|
|
|
rdpsnd_virtual_channel_write(rdpsnd, pdu);
|
2013-02-21 22:25:43 +04:00
|
|
|
}
|
|
|
|
|
2013-11-20 00:31:38 +04:00
|
|
|
void rdpsnd_confirm_wave(rdpsndPlugin* rdpsnd, RDPSND_WAVE* wave)
|
|
|
|
{
|
|
|
|
WLog_Print(rdpsnd->log, WLOG_DEBUG, "WaveConfirm: cBlockNo: %d wTimeStamp: %d wTimeDiff: %d",
|
|
|
|
wave->cBlockNo, wave->wTimeStampB, wave->wTimeStampB - wave->wTimeStampA);
|
|
|
|
|
|
|
|
rdpsnd_send_wave_confirm_pdu(rdpsnd, wave->wTimeStampB, wave->cBlockNo);
|
|
|
|
}
|
|
|
|
|
2013-09-27 13:45:53 +04:00
|
|
|
static void rdpsnd_device_send_wave_confirm_pdu(rdpsndDevicePlugin* device, RDPSND_WAVE* wave)
|
2013-02-26 02:49:07 +04:00
|
|
|
{
|
2013-12-16 00:59:51 +04:00
|
|
|
if (device->DisableConfirmThread)
|
|
|
|
rdpsnd_confirm_wave(device->rdpsnd, wave);
|
|
|
|
else
|
|
|
|
MessageQueue_Post(device->rdpsnd->MsgPipe->Out, 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.
|
|
|
|
*/
|
|
|
|
|
2013-05-09 00:27:21 +04:00
|
|
|
CopyMemory(Stream_Buffer(s), rdpsnd->waveData, 4);
|
2012-11-26 10:15:11 +04:00
|
|
|
|
2013-05-09 00:27:21 +04:00
|
|
|
data = Stream_Buffer(s);
|
2014-02-10 10:06:11 +04:00
|
|
|
size = (int) Stream_Capacity(s);
|
2013-02-26 02:49:07 +04:00
|
|
|
|
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-12-16 00:59:51 +04:00
|
|
|
wave->AutoConfirm = TRUE;
|
2013-02-26 06:46:48 +04:00
|
|
|
|
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-11-20 00:31:38 +04:00
|
|
|
WLog_Print(rdpsnd->log, WLOG_DEBUG, "Wave: cBlockNo: %d wTimeStamp: %d",
|
|
|
|
wave->cBlockNo, wave->wTimeStampA);
|
|
|
|
|
2013-02-26 06:46:48 +04:00
|
|
|
if (!rdpsnd->device)
|
2013-08-29 17:30:22 +04:00
|
|
|
{
|
2013-12-16 00:59:51 +04:00
|
|
|
wave->wLocalTimeB = wave->wLocalTimeA;
|
|
|
|
wave->wTimeStampB = wave->wTimeStampA;
|
|
|
|
rdpsnd_confirm_wave(rdpsnd, wave);
|
2013-08-29 17:30:22 +04:00
|
|
|
free(wave);
|
2013-02-26 06:46:48 +04:00
|
|
|
return;
|
2013-08-29 17:30:22 +04:00
|
|
|
}
|
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;
|
2013-02-21 23:58:39 +04:00
|
|
|
}
|
2013-12-16 00:59:51 +04:00
|
|
|
|
|
|
|
if (wave->AutoConfirm)
|
|
|
|
rdpsnd->device->WaveConfirm(rdpsnd->device, wave);
|
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
|
|
|
{
|
2013-11-20 00:31:38 +04:00
|
|
|
WLog_Print(rdpsnd->log, WLOG_DEBUG, "Close");
|
|
|
|
|
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-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT32(s, dwVolume);
|
2012-11-26 10:15:11 +04:00
|
|
|
|
2013-11-20 00:31:38 +04:00
|
|
|
WLog_Print(rdpsnd->log, WLOG_DEBUG, "Volume: 0x%04X", dwVolume);
|
|
|
|
|
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-10-20 00:20:31 +04:00
|
|
|
static void rdpsnd_recv_pdu(rdpsndPlugin* rdpsnd, wStream* s)
|
2011-08-15 11:08:23 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE msgType;
|
|
|
|
UINT16 BodySize;
|
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);
|
2013-05-09 01:48:30 +04:00
|
|
|
Stream_Free(s, TRUE);
|
2011-08-15 11:08:23 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT8(s, msgType); /* msgType */
|
2013-05-09 00:27:21 +04:00
|
|
|
Stream_Seek_UINT8(s); /* bPad */
|
2013-05-09 00:09:16 +04:00
|
|
|
Stream_Read_UINT16(s, BodySize);
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2015-01-20 13:53:12 +03:00
|
|
|
//WLog_ERR(TAG, "msgType %d BodySize %d", 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:
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "unknown msgType %d", msgType);
|
2011-08-15 11:08:23 +04:00
|
|
|
break;
|
|
|
|
}
|
2012-02-27 21:12:17 +04:00
|
|
|
|
2013-05-09 01:48:30 +04:00
|
|
|
Stream_Free(s, TRUE);
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void rdpsnd_register_device_plugin(rdpsndPlugin* rdpsnd, rdpsndDevicePlugin* device)
|
|
|
|
{
|
|
|
|
if (rdpsnd->device)
|
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "existing device, abort.");
|
2011-08-15 11:08:23 +04:00
|
|
|
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)
|
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "%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" },
|
2013-11-19 23:29:31 +04:00
|
|
|
{ "quality", COMMAND_LINE_VALUE_REQUIRED, "<quality mode>", NULL, NULL, -1, NULL, "quality mode" },
|
2012-11-19 02:32:18 +04:00
|
|
|
{ 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;
|
|
|
|
|
2013-11-19 23:29:31 +04:00
|
|
|
rdpsnd->wQualityMode = HIGH_QUALITY; /* default quality mode */
|
|
|
|
|
2012-11-19 02:32:18 +04:00
|
|
|
flags = COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON;
|
|
|
|
|
|
|
|
status = CommandLineParseArgumentsA(args->argc, (const char**) args->argv,
|
|
|
|
rdpsnd_args, flags, rdpsnd, NULL, NULL);
|
2013-11-19 23:29:31 +04:00
|
|
|
|
2013-09-20 12:11:05 +04:00
|
|
|
if (status < 0)
|
2013-09-20 12:08:56 +04:00
|
|
|
return;
|
2012-11-19 02:32:18 +04:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2013-11-19 23:29:31 +04:00
|
|
|
CommandLineSwitchCase(arg, "quality")
|
|
|
|
{
|
|
|
|
int wQualityMode = DYNAMIC_QUALITY;
|
|
|
|
|
|
|
|
if (_stricmp(arg->Value, "dynamic") == 0)
|
|
|
|
wQualityMode = DYNAMIC_QUALITY;
|
|
|
|
else if (_stricmp(arg->Value, "medium") == 0)
|
|
|
|
wQualityMode = MEDIUM_QUALITY;
|
|
|
|
else if (_stricmp(arg->Value, "high") == 0)
|
|
|
|
wQualityMode = HIGH_QUALITY;
|
|
|
|
else
|
|
|
|
wQualityMode = atoi(arg->Value);
|
|
|
|
|
|
|
|
if ((wQualityMode < 0) || (wQualityMode > 2))
|
|
|
|
wQualityMode = DYNAMIC_QUALITY;
|
|
|
|
|
|
|
|
rdpsnd->wQualityMode = (UINT16) wQualityMode;
|
|
|
|
}
|
2012-11-19 02:32:18 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-10-20 00:20:31 +04:00
|
|
|
static void rdpsnd_process_connect(rdpsndPlugin* rdpsnd)
|
2011-08-15 11:08:23 +04:00
|
|
|
{
|
2012-11-19 02:32:18 +04:00
|
|
|
ADDIN_ARGV* args;
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2011-09-25 07:41:37 +04:00
|
|
|
rdpsnd->latency = -1;
|
2013-10-20 00:20:31 +04:00
|
|
|
|
|
|
|
args = (ADDIN_ARGV*) rdpsnd->channelEntryPoints.pExtendedData;
|
2012-11-19 02:32:18 +04:00
|
|
|
|
|
|
|
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)
|
2013-12-16 00:59:51 +04:00
|
|
|
{
|
2012-11-21 18:30:06 +04:00
|
|
|
return;
|
2013-12-16 00:59:51 +04:00
|
|
|
}
|
2012-11-21 18:30:06 +04:00
|
|
|
|
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
|
|
|
|
2013-09-23 14:38:05 +04:00
|
|
|
#if defined(WITH_IOSAUDIO)
|
2012-11-19 02:32:18 +04:00
|
|
|
if (!rdpsnd->device)
|
2011-08-15 11:08:23 +04:00
|
|
|
{
|
2013-09-23 14:38:05 +04:00
|
|
|
rdpsnd_set_subsystem(rdpsnd, "ios");
|
2012-11-19 02:32:18 +04:00
|
|
|
rdpsnd_set_device_name(rdpsnd, "");
|
|
|
|
rdpsnd_load_device_plugin(rdpsnd, rdpsnd->subsystem, args);
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
2013-09-23 14:38:05 +04:00
|
|
|
#endif
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2013-09-23 14:38:05 +04:00
|
|
|
#if defined(WITH_OPENSLES)
|
2012-11-19 02:32:18 +04:00
|
|
|
if (!rdpsnd->device)
|
2011-08-15 11:08:23 +04:00
|
|
|
{
|
2013-09-23 14:38:05 +04:00
|
|
|
rdpsnd_set_subsystem(rdpsnd, "opensles");
|
|
|
|
rdpsnd_set_device_name(rdpsnd, "");
|
2012-11-19 02:32:18 +04:00
|
|
|
rdpsnd_load_device_plugin(rdpsnd, rdpsnd->subsystem, args);
|
|
|
|
}
|
2013-09-23 14:38:05 +04:00
|
|
|
#endif
|
2012-08-01 20:50:27 +04:00
|
|
|
|
2013-09-23 14:38:05 +04:00
|
|
|
#if defined(WITH_PULSE)
|
2012-11-19 02:32:18 +04:00
|
|
|
if (!rdpsnd->device)
|
|
|
|
{
|
2013-09-23 14:38:05 +04:00
|
|
|
rdpsnd_set_subsystem(rdpsnd, "pulse");
|
|
|
|
rdpsnd_set_device_name(rdpsnd, "");
|
|
|
|
rdpsnd_load_device_plugin(rdpsnd, rdpsnd->subsystem, args);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(WITH_ALSA)
|
|
|
|
if (!rdpsnd->device)
|
|
|
|
{
|
|
|
|
rdpsnd_set_subsystem(rdpsnd, "alsa");
|
2012-11-19 02:32:18 +04:00
|
|
|
rdpsnd_set_device_name(rdpsnd, "default");
|
|
|
|
rdpsnd_load_device_plugin(rdpsnd, rdpsnd->subsystem, args);
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
2013-09-23 14:38:05 +04:00
|
|
|
#endif
|
2012-11-19 02:32:18 +04:00
|
|
|
|
2013-09-23 14:38:05 +04:00
|
|
|
#if defined(WITH_MACAUDIO)
|
2012-12-27 15:19:52 +04:00
|
|
|
if (!rdpsnd->device)
|
|
|
|
{
|
2013-12-10 01:02:42 +04:00
|
|
|
rdpsnd_set_subsystem(rdpsnd, "mac");
|
2013-09-23 14:38:05 +04:00
|
|
|
rdpsnd_set_device_name(rdpsnd, "default");
|
2012-12-27 15:19:52 +04:00
|
|
|
rdpsnd_load_device_plugin(rdpsnd, rdpsnd->subsystem, args);
|
|
|
|
}
|
2013-09-23 14:38:05 +04:00
|
|
|
#endif
|
2012-12-27 15:19:52 +04:00
|
|
|
|
2013-09-23 14:38:05 +04:00
|
|
|
#if defined(WITH_WINMM)
|
2013-09-19 14:01:14 +04:00
|
|
|
if (!rdpsnd->device)
|
|
|
|
{
|
2013-09-23 14:38:05 +04:00
|
|
|
rdpsnd_set_subsystem(rdpsnd, "winmm");
|
2013-09-19 14:01:14 +04:00
|
|
|
rdpsnd_set_device_name(rdpsnd, "");
|
|
|
|
rdpsnd_load_device_plugin(rdpsnd, rdpsnd->subsystem, args);
|
|
|
|
}
|
2013-09-23 14:38:05 +04:00
|
|
|
#endif
|
2013-09-19 14:01:14 +04:00
|
|
|
|
2013-02-21 00:33:42 +04:00
|
|
|
if (!rdpsnd->device)
|
2011-08-15 11:08:23 +04:00
|
|
|
{
|
2014-09-12 18:19:32 +04:00
|
|
|
WLog_ERR(TAG, "no sound device.");
|
2013-02-21 22:25:43 +04:00
|
|
|
return;
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
2013-12-16 00:59:51 +04:00
|
|
|
|
|
|
|
if (!rdpsnd->device->DisableConfirmThread)
|
|
|
|
{
|
2015-01-20 13:53:12 +03:00
|
|
|
rdpsnd->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
|
2013-12-16 00:59:51 +04:00
|
|
|
rdpsnd->ScheduleThread = CreateThread(NULL, 0,
|
|
|
|
(LPTHREAD_START_ROUTINE) rdpsnd_schedule_thread,
|
|
|
|
(void*) rdpsnd, 0, NULL);
|
|
|
|
}
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
|
|
|
|
2015-01-20 13:53:12 +03:00
|
|
|
static void rdpsnd_process_disconnect(rdpsndPlugin* rdpsnd)
|
|
|
|
{
|
|
|
|
if (rdpsnd->ScheduleThread)
|
|
|
|
{
|
|
|
|
SetEvent(rdpsnd->stopEvent);
|
|
|
|
WaitForSingleObject(rdpsnd->ScheduleThread, INFINITE);
|
|
|
|
CloseHandle(rdpsnd->ScheduleThread);
|
|
|
|
CloseHandle(rdpsnd->stopEvent);
|
|
|
|
}
|
|
|
|
}
|
2012-10-09 03:54:11 +04:00
|
|
|
|
2013-10-20 00:20:31 +04:00
|
|
|
/****************************************************************************************/
|
|
|
|
|
|
|
|
|
2015-01-20 14:31:21 +03:00
|
|
|
static wListDictionary* g_InitHandles = NULL;
|
|
|
|
static wListDictionary* g_OpenHandles = NULL;
|
2013-10-20 00:20:31 +04:00
|
|
|
|
|
|
|
void rdpsnd_add_init_handle_data(void* pInitHandle, void* pUserData)
|
2012-10-09 03:54:11 +04:00
|
|
|
{
|
2013-10-20 00:20:31 +04:00
|
|
|
if (!g_InitHandles)
|
|
|
|
g_InitHandles = ListDictionary_New(TRUE);
|
2012-10-09 03:54:11 +04:00
|
|
|
|
2013-10-20 00:20:31 +04:00
|
|
|
ListDictionary_Add(g_InitHandles, pInitHandle, pUserData);
|
|
|
|
}
|
2012-10-09 03:54:11 +04:00
|
|
|
|
2013-10-20 00:20:31 +04:00
|
|
|
void* rdpsnd_get_init_handle_data(void* pInitHandle)
|
|
|
|
{
|
|
|
|
void* pUserData = NULL;
|
|
|
|
pUserData = ListDictionary_GetItemValue(g_InitHandles, pInitHandle);
|
|
|
|
return pUserData;
|
|
|
|
}
|
2012-10-09 03:54:11 +04:00
|
|
|
|
2013-10-20 00:20:31 +04:00
|
|
|
void rdpsnd_remove_init_handle_data(void* pInitHandle)
|
|
|
|
{
|
|
|
|
ListDictionary_Remove(g_InitHandles, pInitHandle);
|
2015-01-20 14:31:21 +03:00
|
|
|
if (ListDictionary_Count(g_InitHandles) < 1)
|
|
|
|
{
|
|
|
|
ListDictionary_Free(g_InitHandles);
|
|
|
|
g_InitHandles = NULL;
|
|
|
|
}
|
2013-10-20 00:20:31 +04:00
|
|
|
}
|
2012-10-09 03:54:11 +04:00
|
|
|
|
2013-10-20 00:20:31 +04:00
|
|
|
void rdpsnd_add_open_handle_data(DWORD openHandle, void* pUserData)
|
|
|
|
{
|
|
|
|
void* pOpenHandle = (void*) (size_t) openHandle;
|
2012-10-09 03:54:11 +04:00
|
|
|
|
2013-10-20 00:20:31 +04:00
|
|
|
if (!g_OpenHandles)
|
|
|
|
g_OpenHandles = ListDictionary_New(TRUE);
|
|
|
|
|
|
|
|
ListDictionary_Add(g_OpenHandles, pOpenHandle, pUserData);
|
|
|
|
}
|
|
|
|
|
|
|
|
void* rdpsnd_get_open_handle_data(DWORD openHandle)
|
|
|
|
{
|
|
|
|
void* pUserData = NULL;
|
|
|
|
void* pOpenHandle = (void*) (size_t) openHandle;
|
|
|
|
pUserData = ListDictionary_GetItemValue(g_OpenHandles, pOpenHandle);
|
|
|
|
return pUserData;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rdpsnd_remove_open_handle_data(DWORD openHandle)
|
|
|
|
{
|
|
|
|
void* pOpenHandle = (void*) (size_t) openHandle;
|
|
|
|
ListDictionary_Remove(g_OpenHandles, pOpenHandle);
|
2015-01-20 14:31:21 +03:00
|
|
|
if (ListDictionary_Count(g_OpenHandles) < 1)
|
|
|
|
{
|
|
|
|
ListDictionary_Free(g_OpenHandles);
|
|
|
|
g_OpenHandles = NULL;
|
|
|
|
}
|
2013-10-20 00:20:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int rdpsnd_virtual_channel_write(rdpsndPlugin* rdpsnd, wStream* s)
|
|
|
|
{
|
|
|
|
UINT32 status = 0;
|
|
|
|
|
|
|
|
if (!rdpsnd)
|
2014-02-10 10:06:11 +04:00
|
|
|
{
|
2013-10-20 00:20:31 +04:00
|
|
|
status = CHANNEL_RC_BAD_INIT_HANDLE;
|
2014-02-10 10:06:11 +04:00
|
|
|
}
|
2013-10-20 00:20:31 +04:00
|
|
|
else
|
2014-02-10 10:06:11 +04:00
|
|
|
{
|
2013-10-20 00:20:31 +04:00
|
|
|
status = rdpsnd->channelEntryPoints.pVirtualChannelWrite(rdpsnd->OpenHandle,
|
2014-02-10 10:06:11 +04:00
|
|
|
Stream_Buffer(s), (UINT32) Stream_GetPosition(s), s);
|
|
|
|
}
|
2013-10-20 00:20:31 +04:00
|
|
|
|
|
|
|
if (status != CHANNEL_RC_OK)
|
|
|
|
{
|
|
|
|
Stream_Free(s, TRUE);
|
2015-01-20 13:53:12 +03:00
|
|
|
WLog_ERR(TAG, "VirtualChannelWrite failed with %s [%08X]",
|
|
|
|
WTSErrorToString(status), status);
|
2013-10-20 00:20:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void rdpsnd_virtual_channel_event_data_received(rdpsndPlugin* plugin,
|
|
|
|
void* pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
|
|
|
|
{
|
|
|
|
wStream* s;
|
|
|
|
|
|
|
|
if ((dataFlags & CHANNEL_FLAG_SUSPEND) || (dataFlags & CHANNEL_FLAG_RESUME))
|
2013-02-21 19:46:11 +04:00
|
|
|
{
|
2013-10-20 00:20:31 +04:00
|
|
|
return;
|
2013-02-21 19:46:11 +04:00
|
|
|
}
|
2013-10-20 00:20:31 +04:00
|
|
|
|
|
|
|
if (dataFlags & CHANNEL_FLAG_FIRST)
|
|
|
|
{
|
|
|
|
if (plugin->data_in != NULL)
|
|
|
|
Stream_Free(plugin->data_in, TRUE);
|
|
|
|
|
|
|
|
plugin->data_in = Stream_New(NULL, totalLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
s = plugin->data_in;
|
|
|
|
Stream_EnsureRemainingCapacity(s, (int) dataLength);
|
|
|
|
Stream_Write(s, pData, dataLength);
|
|
|
|
|
|
|
|
if (dataFlags & CHANNEL_FLAG_LAST)
|
|
|
|
{
|
|
|
|
if (Stream_Capacity(s) != Stream_GetPosition(s))
|
|
|
|
{
|
2015-01-20 13:53:12 +03:00
|
|
|
WLog_ERR(TAG, "rdpsnd_virtual_channel_event_data_received: read error");
|
2013-10-20 00:20:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
plugin->data_in = NULL;
|
|
|
|
Stream_SealLength(s);
|
|
|
|
Stream_SetPosition(s, 0);
|
|
|
|
|
|
|
|
MessageQueue_Post(plugin->MsgPipe->In, NULL, 0, (void*) s, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
static VOID VCAPITYPE rdpsnd_virtual_channel_open_event(DWORD openHandle, UINT event,
|
2014-02-17 02:27:36 +04:00
|
|
|
LPVOID pData, UINT32 dataLength, UINT32 totalLength, UINT32 dataFlags)
|
2013-10-20 00:20:31 +04:00
|
|
|
{
|
2014-12-27 21:50:50 +03:00
|
|
|
rdpsndPlugin* rdpsnd;
|
2013-10-20 00:20:31 +04:00
|
|
|
|
2014-12-27 21:50:50 +03:00
|
|
|
rdpsnd = (rdpsndPlugin*) rdpsnd_get_open_handle_data(openHandle);
|
2013-10-20 00:20:31 +04:00
|
|
|
|
2014-12-27 21:50:50 +03:00
|
|
|
if (!rdpsnd)
|
2013-10-20 00:20:31 +04:00
|
|
|
{
|
2015-01-20 13:53:12 +03:00
|
|
|
WLog_ERR(TAG, "rdpsnd_virtual_channel_open_event: error no match");
|
2013-10-20 00:20:31 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (event)
|
|
|
|
{
|
|
|
|
case CHANNEL_EVENT_DATA_RECEIVED:
|
2014-12-27 21:50:50 +03:00
|
|
|
rdpsnd_virtual_channel_event_data_received(rdpsnd, pData, dataLength, totalLength, dataFlags);
|
2013-10-20 00:20:31 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CHANNEL_EVENT_WRITE_COMPLETE:
|
|
|
|
Stream_Free((wStream*) pData, TRUE);
|
|
|
|
break;
|
2015-01-20 13:53:12 +03:00
|
|
|
|
|
|
|
case CHANNEL_EVENT_USER:
|
|
|
|
break;
|
2013-10-20 00:20:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void* rdpsnd_virtual_channel_client_thread(void* arg)
|
|
|
|
{
|
|
|
|
wStream* data;
|
|
|
|
wMessage message;
|
2014-12-27 21:50:50 +03:00
|
|
|
rdpsndPlugin* rdpsnd = (rdpsndPlugin*) arg;
|
2013-10-20 00:20:31 +04:00
|
|
|
|
2014-12-27 21:50:50 +03:00
|
|
|
rdpsnd_process_connect(rdpsnd);
|
2013-10-20 00:20:31 +04:00
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
2014-12-27 21:50:50 +03:00
|
|
|
if (!MessageQueue_Wait(rdpsnd->MsgPipe->In))
|
2013-10-20 00:20:31 +04:00
|
|
|
break;
|
|
|
|
|
2014-12-27 21:50:50 +03:00
|
|
|
if (MessageQueue_Peek(rdpsnd->MsgPipe->In, &message, TRUE))
|
2013-10-20 00:20:31 +04:00
|
|
|
{
|
|
|
|
if (message.id == WMQ_QUIT)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (message.id == 0)
|
|
|
|
{
|
|
|
|
data = (wStream*) message.wParam;
|
2014-12-27 21:50:50 +03:00
|
|
|
rdpsnd_recv_pdu(rdpsnd, data);
|
2013-10-20 00:20:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-20 13:53:12 +03:00
|
|
|
rdpsnd_process_disconnect(rdpsnd);
|
2014-12-27 21:50:50 +03:00
|
|
|
|
2013-10-20 00:20:31 +04:00
|
|
|
ExitThread(0);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-02-17 02:27:36 +04:00
|
|
|
static void rdpsnd_virtual_channel_event_connected(rdpsndPlugin* plugin, LPVOID pData, UINT32 dataLength)
|
2013-10-20 00:20:31 +04:00
|
|
|
{
|
|
|
|
UINT32 status;
|
|
|
|
|
|
|
|
status = plugin->channelEntryPoints.pVirtualChannelOpen(plugin->InitHandle,
|
|
|
|
&plugin->OpenHandle, plugin->channelDef.name, rdpsnd_virtual_channel_open_event);
|
|
|
|
|
|
|
|
rdpsnd_add_open_handle_data(plugin->OpenHandle, plugin);
|
|
|
|
|
|
|
|
if (status != CHANNEL_RC_OK)
|
|
|
|
{
|
2015-01-20 13:53:12 +03:00
|
|
|
WLog_ERR(TAG, "pVirtualChannelOpen failed with %s [%08X]",
|
|
|
|
WTSErrorToString(status), status);
|
2013-10-20 00:20:31 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
plugin->MsgPipe = MessagePipe_New();
|
|
|
|
|
|
|
|
plugin->thread = CreateThread(NULL, 0,
|
|
|
|
(LPTHREAD_START_ROUTINE) rdpsnd_virtual_channel_client_thread, (void*) plugin, 0, NULL);
|
|
|
|
}
|
|
|
|
|
2015-01-20 13:53:12 +03:00
|
|
|
static void rdpsnd_virtual_channel_event_disconnected(rdpsndPlugin* rdpsnd)
|
2013-10-20 00:20:31 +04:00
|
|
|
{
|
2015-01-20 13:53:12 +03:00
|
|
|
UINT rc;
|
2014-12-27 21:50:50 +03:00
|
|
|
|
2015-01-20 13:53:12 +03:00
|
|
|
MessagePipe_PostQuit(rdpsnd->MsgPipe, 0);
|
|
|
|
WaitForSingleObject(rdpsnd->thread, INFINITE);
|
2014-12-27 21:50:50 +03:00
|
|
|
|
2015-01-20 13:53:12 +03:00
|
|
|
CloseHandle(rdpsnd->thread);
|
|
|
|
rdpsnd->thread = NULL;
|
2013-10-20 00:20:31 +04:00
|
|
|
|
2015-01-20 13:53:12 +03:00
|
|
|
rc = rdpsnd->channelEntryPoints.pVirtualChannelClose(rdpsnd->OpenHandle);
|
|
|
|
if (CHANNEL_RC_OK != rc)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "pVirtualChannelClose failed with %s [%08X]",
|
|
|
|
WTSErrorToString(rc), rc);
|
|
|
|
}
|
2013-10-20 00:20:31 +04:00
|
|
|
|
2013-11-06 23:31:33 +04:00
|
|
|
if (rdpsnd->data_in)
|
2013-10-20 00:20:31 +04:00
|
|
|
{
|
2013-11-06 23:31:33 +04:00
|
|
|
Stream_Free(rdpsnd->data_in, TRUE);
|
|
|
|
rdpsnd->data_in = NULL;
|
2013-10-20 00:20:31 +04:00
|
|
|
}
|
|
|
|
|
2015-01-20 13:53:12 +03:00
|
|
|
MessagePipe_Free(rdpsnd->MsgPipe);
|
|
|
|
rdpsnd->MsgPipe = NULL;
|
2013-11-06 23:31:33 +04:00
|
|
|
|
2015-01-20 13:53:12 +03:00
|
|
|
rdpsnd_free_audio_formats(rdpsnd->ClientFormats, rdpsnd->NumberOfClientFormats);
|
|
|
|
rdpsnd->NumberOfClientFormats = 0;
|
|
|
|
rdpsnd->ClientFormats = NULL;
|
2013-11-06 23:31:33 +04:00
|
|
|
|
|
|
|
rdpsnd_free_audio_formats(rdpsnd->ServerFormats, rdpsnd->NumberOfServerFormats);
|
|
|
|
rdpsnd->NumberOfServerFormats = 0;
|
|
|
|
rdpsnd->ServerFormats = NULL;
|
|
|
|
|
2015-01-20 13:53:12 +03:00
|
|
|
if (rdpsnd->device)
|
|
|
|
{
|
|
|
|
IFCALL(rdpsnd->device->Free, rdpsnd->device);
|
|
|
|
rdpsnd->device = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rdpsnd->subsystem)
|
|
|
|
{
|
|
|
|
free(rdpsnd->subsystem);
|
|
|
|
rdpsnd->subsystem = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rdpsnd->device_name)
|
|
|
|
{
|
|
|
|
free(rdpsnd->device_name);
|
|
|
|
rdpsnd->device_name = NULL;
|
|
|
|
}
|
2013-10-20 00:20:31 +04:00
|
|
|
|
2013-11-06 23:31:33 +04:00
|
|
|
rdpsnd_remove_open_handle_data(rdpsnd->OpenHandle);
|
2015-01-20 13:53:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void rdpsnd_virtual_channel_event_terminated(rdpsndPlugin* rdpsnd)
|
|
|
|
{
|
2013-11-06 23:31:33 +04:00
|
|
|
rdpsnd_remove_init_handle_data(rdpsnd->InitHandle);
|
2014-12-03 22:17:27 +03:00
|
|
|
|
|
|
|
free(rdpsnd);
|
2013-10-20 00:20:31 +04:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:49:57 +04:00
|
|
|
static VOID VCAPITYPE rdpsnd_virtual_channel_init_event(LPVOID pInitHandle, UINT event, LPVOID pData, UINT dataLength)
|
2013-10-20 00:20:31 +04:00
|
|
|
{
|
|
|
|
rdpsndPlugin* plugin;
|
|
|
|
|
|
|
|
plugin = (rdpsndPlugin*) rdpsnd_get_init_handle_data(pInitHandle);
|
|
|
|
|
|
|
|
if (!plugin)
|
|
|
|
{
|
2015-01-20 13:53:12 +03:00
|
|
|
WLog_ERR(TAG, "rdpsnd_virtual_channel_init_event: error no match");
|
2013-10-20 00:20:31 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (event)
|
|
|
|
{
|
|
|
|
case CHANNEL_EVENT_CONNECTED:
|
|
|
|
rdpsnd_virtual_channel_event_connected(plugin, pData, dataLength);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CHANNEL_EVENT_DISCONNECTED:
|
2015-01-20 13:53:12 +03:00
|
|
|
rdpsnd_virtual_channel_event_disconnected(plugin);
|
2013-10-20 00:20:31 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CHANNEL_EVENT_TERMINATED:
|
|
|
|
rdpsnd_virtual_channel_event_terminated(plugin);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* rdpsnd is always built-in */
|
|
|
|
#define VirtualChannelEntry rdpsnd_VirtualChannelEntry
|
|
|
|
|
2014-03-04 03:28:31 +04:00
|
|
|
BOOL VCAPITYPE VirtualChannelEntry(PCHANNEL_ENTRY_POINTS pEntryPoints)
|
2013-10-20 00:20:31 +04:00
|
|
|
{
|
2015-01-20 13:53:12 +03:00
|
|
|
UINT rc;
|
|
|
|
|
2013-10-20 00:20:31 +04:00
|
|
|
rdpsndPlugin* rdpsnd;
|
|
|
|
|
2014-12-03 22:17:27 +03:00
|
|
|
rdpsnd = (rdpsndPlugin*) calloc(1, sizeof(rdpsndPlugin));
|
2013-10-20 00:20:31 +04:00
|
|
|
|
|
|
|
if (rdpsnd)
|
|
|
|
{
|
|
|
|
#if !defined(_WIN32) && !defined(ANDROID)
|
|
|
|
{
|
|
|
|
sigset_t mask;
|
|
|
|
sigemptyset(&mask);
|
|
|
|
sigaddset(&mask, SIGIO);
|
|
|
|
pthread_sigmask(SIG_BLOCK, &mask, NULL);
|
|
|
|
}
|
2013-02-21 19:46:11 +04:00
|
|
|
#endif
|
|
|
|
|
2013-10-20 00:20:31 +04:00
|
|
|
rdpsnd->channelDef.options =
|
|
|
|
CHANNEL_OPTION_INITIALIZED |
|
|
|
|
CHANNEL_OPTION_ENCRYPT_RDP;
|
|
|
|
|
|
|
|
strcpy(rdpsnd->channelDef.name, "rdpsnd");
|
|
|
|
|
2014-02-17 02:38:59 +04:00
|
|
|
CopyMemory(&(rdpsnd->channelEntryPoints), pEntryPoints, sizeof(CHANNEL_ENTRY_POINTS_FREERDP));
|
2013-10-20 00:20:31 +04:00
|
|
|
|
2013-11-20 00:31:38 +04:00
|
|
|
rdpsnd->log = WLog_Get("com.freerdp.channels.rdpsnd.client");
|
2013-12-16 00:59:51 +04:00
|
|
|
|
2015-01-20 13:53:12 +03:00
|
|
|
rc = rdpsnd->channelEntryPoints.pVirtualChannelInit(&rdpsnd->InitHandle,
|
2013-10-20 00:20:31 +04:00
|
|
|
&rdpsnd->channelDef, 1, VIRTUAL_CHANNEL_VERSION_WIN2000, rdpsnd_virtual_channel_init_event);
|
2015-01-20 13:53:12 +03:00
|
|
|
if (CHANNEL_RC_OK != rc)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "pVirtualChannelInit failed with %s [%08X]",
|
|
|
|
WTSErrorToString(rc), rc);
|
|
|
|
free(rdpsnd);
|
|
|
|
return -1;
|
|
|
|
}
|
2013-10-20 00:20:31 +04:00
|
|
|
|
|
|
|
rdpsnd_add_init_handle_data(rdpsnd->InitHandle, (void*) rdpsnd);
|
|
|
|
}
|
2012-10-09 03:54:11 +04:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|