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>
|
|
|
|
#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>
|
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>
|
2011-08-15 11:08:23 +04:00
|
|
|
#include <freerdp/utils/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-21 06:34:47 +04:00
|
|
|
#define TIME_DELAY_MS 250
|
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
struct rdpsnd_plugin
|
|
|
|
{
|
|
|
|
rdpSvcPlugin plugin;
|
|
|
|
|
2013-02-21 00:33:42 +04:00
|
|
|
wMessagePipe* MsgPipe;
|
2013-02-21 06:34:47 +04:00
|
|
|
HANDLE thread;
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE cBlockNo;
|
2011-08-15 11:08:23 +04:00
|
|
|
rdpsndFormat* supported_formats;
|
|
|
|
int n_supported_formats;
|
|
|
|
int current_format;
|
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL expectingWave;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE waveData[4];
|
|
|
|
UINT16 waveDataSize;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 wTimeStamp; /* server timestamp */
|
|
|
|
UINT32 wave_timestamp; /* client timestamp */
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2012-10-09 10:38:39 +04:00
|
|
|
BOOL is_open;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 close_timestamp;
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 fixed_format;
|
|
|
|
UINT16 fixed_channel;
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 fixed_rate;
|
2011-09-25 07:41:37 +04:00
|
|
|
int latency;
|
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-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
|
|
|
STREAM* data;
|
|
|
|
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-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-21 06:34:47 +04:00
|
|
|
if (!MessageQueue_Wait(rdpsnd->MsgPipe->Out))
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!MessageQueue_Peek(rdpsnd->MsgPipe->Out, &message, TRUE))
|
|
|
|
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-20 07:36:04 +04:00
|
|
|
wTimeStamp = (UINT16) (size_t) message.lParam;
|
|
|
|
wCurrentTime = (UINT16) GetTickCount();
|
2012-10-03 07:01:16 +04:00
|
|
|
|
2013-02-21 06:34:47 +04:00
|
|
|
//printf("wTimeStamp: %d wCurrentTime: %d\n", wTimeStamp, wCurrentTime);
|
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;
|
|
|
|
//printf("Sleeping %d ms\n", wTimeDiff);
|
|
|
|
Sleep(wTimeDiff);
|
2013-02-20 21:11:19 +04:00
|
|
|
}
|
2013-02-21 06:34:47 +04:00
|
|
|
|
|
|
|
data = (STREAM*) message.wParam;
|
|
|
|
svc_plugin_send((rdpSvcPlugin*) rdpsnd, data);
|
|
|
|
DEBUG_SVC("processed output data");
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
|
|
|
|
2013-02-21 06:34:47 +04:00
|
|
|
#if 0
|
2013-02-20 06:21:20 +04:00
|
|
|
if (rdpsnd->is_open && (rdpsnd->close_timestamp > 0))
|
2011-08-15 11:08:23 +04:00
|
|
|
{
|
2013-02-20 07:36:04 +04:00
|
|
|
if (GetTickCount() > rdpsnd->close_timestamp)
|
2011-08-15 11:08:23 +04:00
|
|
|
{
|
|
|
|
if (rdpsnd->device)
|
|
|
|
IFCALL(rdpsnd->device->Close, rdpsnd->device);
|
2013-02-19 21:29:15 +04:00
|
|
|
|
2012-10-09 10:31:28 +04:00
|
|
|
rdpsnd->is_open = FALSE;
|
2011-08-15 11:08:23 +04:00
|
|
|
rdpsnd->close_timestamp = 0;
|
|
|
|
|
|
|
|
DEBUG_SVC("processed close");
|
|
|
|
}
|
|
|
|
}
|
2013-02-21 06:34:47 +04:00
|
|
|
#endif
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static void rdpsnd_free_supported_formats(rdpsndPlugin* rdpsnd)
|
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 i;
|
2011-08-15 11:08:23 +04:00
|
|
|
|
|
|
|
for (i = 0; i < rdpsnd->n_supported_formats; i++)
|
2012-10-09 07:21:26 +04:00
|
|
|
free(rdpsnd->supported_formats[i].data);
|
2013-02-20 06:21:20 +04:00
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(rdpsnd->supported_formats);
|
2011-08-15 11:08:23 +04:00
|
|
|
|
|
|
|
rdpsnd->supported_formats = NULL;
|
|
|
|
rdpsnd->n_supported_formats = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* receives a list of server supported formats and returns a list
|
|
|
|
of client supported formats */
|
|
|
|
static void rdpsnd_process_message_formats(rdpsndPlugin* rdpsnd, STREAM* data_in)
|
|
|
|
{
|
2013-02-20 06:21:20 +04:00
|
|
|
UINT32 dwVolume;
|
|
|
|
UINT16 dwVolumeLeft;
|
|
|
|
UINT16 dwVolumeRight;
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 wNumberOfFormats;
|
|
|
|
UINT16 nFormat;
|
|
|
|
UINT16 wVersion;
|
2011-08-15 11:08:23 +04:00
|
|
|
STREAM* data_out;
|
|
|
|
rdpsndFormat* out_formats;
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 n_out_formats;
|
2011-08-15 11:08:23 +04:00
|
|
|
rdpsndFormat* format;
|
2012-10-09 11:01:37 +04:00
|
|
|
BYTE* format_mark;
|
|
|
|
BYTE* data_mark;
|
2011-08-15 11:08:23 +04:00
|
|
|
int pos;
|
|
|
|
|
|
|
|
rdpsnd_free_supported_formats(rdpsnd);
|
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_seek_UINT32(data_in); /* dwFlags */
|
|
|
|
stream_seek_UINT32(data_in); /* dwVolume */
|
|
|
|
stream_seek_UINT32(data_in); /* dwPitch */
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_seek_UINT16(data_in); /* wDGramPort */
|
|
|
|
stream_read_UINT16(data_in, wNumberOfFormats);
|
|
|
|
stream_read_BYTE(data_in, rdpsnd->cBlockNo); /* cLastBlockConfirmed */
|
|
|
|
stream_read_UINT16(data_in, wVersion);
|
|
|
|
stream_seek_BYTE(data_in); /* bPad */
|
2011-08-15 11:08:23 +04:00
|
|
|
|
|
|
|
DEBUG_SVC("wNumberOfFormats %d wVersion %d", wNumberOfFormats, wVersion);
|
2013-02-20 02:47:55 +04:00
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
if (wNumberOfFormats < 1)
|
|
|
|
{
|
|
|
|
DEBUG_WARN("wNumberOfFormats is 0");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-11-20 08:49:08 +04:00
|
|
|
out_formats = (rdpsndFormat*) malloc(wNumberOfFormats * sizeof(rdpsndFormat));
|
|
|
|
ZeroMemory(out_formats, wNumberOfFormats * sizeof(rdpsndFormat));
|
2011-08-15 11:08:23 +04:00
|
|
|
n_out_formats = 0;
|
|
|
|
|
2013-02-20 06:21:20 +04:00
|
|
|
dwVolumeLeft = (0xFFFF / 2); /* 50% ? */
|
|
|
|
dwVolumeRight = (0xFFFF / 2); /* 50% ? */
|
|
|
|
dwVolume = (dwVolumeLeft << 16) | dwVolumeRight;
|
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
data_out = stream_new(24);
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_BYTE(data_out, SNDC_FORMATS); /* msgType */
|
|
|
|
stream_write_BYTE(data_out, 0); /* bPad */
|
|
|
|
stream_seek_UINT16(data_out); /* BodySize */
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_write_UINT32(data_out, TSSNDCAPS_ALIVE | TSSNDCAPS_VOLUME); /* dwFlags */
|
2013-02-20 06:21:20 +04:00
|
|
|
stream_write_UINT32(data_out, dwVolume); /* dwVolume */
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_write_UINT32(data_out, 0); /* dwPitch */
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16_be(data_out, 0); /* wDGramPort */
|
|
|
|
stream_seek_UINT16(data_out); /* wNumberOfFormats */
|
|
|
|
stream_write_BYTE(data_out, 0); /* cLastBlockConfirmed */
|
|
|
|
stream_write_UINT16(data_out, 6); /* wVersion */
|
|
|
|
stream_write_BYTE(data_out, 0); /* bPad */
|
2011-08-15 11:08:23 +04:00
|
|
|
|
|
|
|
for (nFormat = 0; nFormat < wNumberOfFormats; nFormat++)
|
|
|
|
{
|
|
|
|
stream_get_mark(data_in, format_mark);
|
|
|
|
format = &out_formats[n_out_formats];
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_UINT16(data_in, format->wFormatTag);
|
|
|
|
stream_read_UINT16(data_in, format->nChannels);
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_read_UINT32(data_in, format->nSamplesPerSec);
|
|
|
|
stream_seek_UINT32(data_in); /* nAvgBytesPerSec */
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_UINT16(data_in, format->nBlockAlign);
|
|
|
|
stream_read_UINT16(data_in, format->wBitsPerSample);
|
|
|
|
stream_read_UINT16(data_in, format->cbSize);
|
2011-08-15 11:08:23 +04:00
|
|
|
stream_get_mark(data_in, data_mark);
|
|
|
|
stream_seek(data_in, format->cbSize);
|
|
|
|
format->data = NULL;
|
|
|
|
|
2011-08-15 12:28:52 +04:00
|
|
|
DEBUG_SVC("wFormatTag=%d nChannels=%d nSamplesPerSec=%d nBlockAlign=%d wBitsPerSample=%d",
|
|
|
|
format->wFormatTag, format->nChannels, format->nSamplesPerSec,
|
|
|
|
format->nBlockAlign, format->wBitsPerSample);
|
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
if (rdpsnd->fixed_format > 0 && rdpsnd->fixed_format != format->wFormatTag)
|
|
|
|
continue;
|
2013-02-20 02:47:55 +04:00
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
if (rdpsnd->fixed_channel > 0 && rdpsnd->fixed_channel != format->nChannels)
|
|
|
|
continue;
|
2013-02-20 02:47:55 +04:00
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
if (rdpsnd->fixed_rate > 0 && rdpsnd->fixed_rate != format->nSamplesPerSec)
|
|
|
|
continue;
|
2013-02-20 02:47:55 +04:00
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
if (rdpsnd->device && rdpsnd->device->FormatSupported(rdpsnd->device, format))
|
|
|
|
{
|
2011-08-15 12:28:52 +04:00
|
|
|
DEBUG_SVC("format supported.");
|
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
stream_check_size(data_out, 18 + format->cbSize);
|
|
|
|
stream_write(data_out, format_mark, 18 + format->cbSize);
|
2013-02-20 02:47:55 +04:00
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
if (format->cbSize > 0)
|
|
|
|
{
|
2012-10-09 07:21:26 +04:00
|
|
|
format->data = malloc(format->cbSize);
|
2013-02-20 02:47:55 +04:00
|
|
|
CopyMemory(format->data, data_mark, format->cbSize);
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
2013-02-20 02:47:55 +04:00
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
n_out_formats++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
rdpsnd->n_supported_formats = n_out_formats;
|
2013-02-20 02:47:55 +04:00
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
if (n_out_formats > 0)
|
|
|
|
{
|
|
|
|
rdpsnd->supported_formats = out_formats;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-10-09 07:21:26 +04:00
|
|
|
free(out_formats);
|
2011-08-15 11:08:23 +04:00
|
|
|
DEBUG_WARN("no formats supported");
|
|
|
|
}
|
|
|
|
|
|
|
|
pos = stream_get_pos(data_out);
|
|
|
|
stream_set_pos(data_out, 2);
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(data_out, pos - 4);
|
2011-08-15 11:08:23 +04:00
|
|
|
stream_set_pos(data_out, 18);
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_UINT16(data_out, n_out_formats);
|
2011-08-15 11:08:23 +04:00
|
|
|
stream_set_pos(data_out, pos);
|
|
|
|
|
2013-02-20 06:21:20 +04:00
|
|
|
svc_plugin_send((rdpSvcPlugin*) rdpsnd, data_out);
|
2011-08-15 11:08:23 +04:00
|
|
|
|
|
|
|
if (wVersion >= 6)
|
|
|
|
{
|
|
|
|
data_out = stream_new(8);
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_BYTE(data_out, SNDC_QUALITYMODE); /* msgType */
|
|
|
|
stream_write_BYTE(data_out, 0); /* bPad */
|
|
|
|
stream_write_UINT16(data_out, 4); /* BodySize */
|
|
|
|
stream_write_UINT16(data_out, HIGH_QUALITY); /* wQualityMode */
|
|
|
|
stream_write_UINT16(data_out, 0); /* Reserved */
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2013-02-20 06:21:20 +04:00
|
|
|
svc_plugin_send((rdpSvcPlugin*) rdpsnd, data_out);
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* server is getting a feel of the round trip time */
|
|
|
|
static void rdpsnd_process_message_training(rdpsndPlugin* rdpsnd, STREAM* data_in)
|
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 wTimeStamp;
|
|
|
|
UINT16 wPackSize;
|
2011-08-15 11:08:23 +04:00
|
|
|
STREAM* data_out;
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_UINT16(data_in, wTimeStamp);
|
|
|
|
stream_read_UINT16(data_in, wPackSize);
|
2011-08-15 11:08:23 +04:00
|
|
|
|
|
|
|
data_out = stream_new(8);
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_write_BYTE(data_out, SNDC_TRAINING); /* msgType */
|
|
|
|
stream_write_BYTE(data_out, 0); /* bPad */
|
|
|
|
stream_write_UINT16(data_out, 4); /* BodySize */
|
|
|
|
stream_write_UINT16(data_out, wTimeStamp);
|
|
|
|
stream_write_UINT16(data_out, wPackSize);
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2013-02-20 06:21:20 +04:00
|
|
|
svc_plugin_send((rdpSvcPlugin*) rdpsnd, data_out);
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
static void rdpsnd_process_message_wave_info(rdpsndPlugin* rdpsnd, STREAM* data_in, UINT16 BodySize)
|
2011-08-15 11:08:23 +04:00
|
|
|
{
|
2012-10-09 11:01:37 +04:00
|
|
|
UINT16 wFormatNo;
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_UINT16(data_in, rdpsnd->wTimeStamp);
|
|
|
|
stream_read_UINT16(data_in, wFormatNo);
|
|
|
|
stream_read_BYTE(data_in, rdpsnd->cBlockNo);
|
2011-08-15 11:08:23 +04:00
|
|
|
stream_seek(data_in, 3); /* bPad */
|
|
|
|
stream_read(data_in, rdpsnd->waveData, 4);
|
2013-02-20 06:21:20 +04:00
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
rdpsnd->waveDataSize = BodySize - 8;
|
2013-02-20 06:21:20 +04:00
|
|
|
rdpsnd->wave_timestamp = GetTickCount();
|
2012-10-09 10:31:28 +04:00
|
|
|
rdpsnd->expectingWave = TRUE;
|
2011-08-15 11:08:23 +04:00
|
|
|
|
|
|
|
DEBUG_SVC("waveDataSize %d wFormatNo %d", rdpsnd->waveDataSize, wFormatNo);
|
|
|
|
|
2011-08-16 05:23:29 +04:00
|
|
|
rdpsnd->close_timestamp = 0;
|
2012-11-26 10:15:11 +04:00
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
if (!rdpsnd->is_open)
|
|
|
|
{
|
|
|
|
rdpsnd->current_format = wFormatNo;
|
2012-10-09 10:31:28 +04:00
|
|
|
rdpsnd->is_open = TRUE;
|
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-09-25 07:41:37 +04:00
|
|
|
IFCALL(rdpsnd->device->Open, rdpsnd->device, &rdpsnd->supported_formats[wFormatNo],
|
|
|
|
rdpsnd->latency);
|
2012-11-26 10:15:11 +04:00
|
|
|
}
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
|
|
|
else if (wFormatNo != rdpsnd->current_format)
|
|
|
|
{
|
|
|
|
rdpsnd->current_format = 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
|
|
|
{
|
2011-09-25 07:41:37 +04:00
|
|
|
IFCALL(rdpsnd->device->SetFormat, rdpsnd->device, &rdpsnd->supported_formats[wFormatNo],
|
|
|
|
rdpsnd->latency);
|
2012-11-26 10:15:11 +04:00
|
|
|
}
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* header is not removed from data in this function */
|
|
|
|
static void rdpsnd_process_message_wave(rdpsndPlugin* rdpsnd, STREAM* data_in)
|
|
|
|
{
|
2013-02-20 07:36:04 +04:00
|
|
|
STREAM* data;
|
|
|
|
UINT16 wTimeStamp;
|
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-20 02:47:55 +04:00
|
|
|
CopyMemory(stream_get_head(data_in), rdpsnd->waveData, 4);
|
2012-11-26 10:15:11 +04:00
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
if (stream_get_size(data_in) != rdpsnd->waveDataSize)
|
|
|
|
{
|
|
|
|
DEBUG_WARN("size error");
|
|
|
|
return;
|
|
|
|
}
|
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->Play, rdpsnd->device, stream_get_head(data_in), stream_get_size(data_in));
|
2012-11-26 10:15:11 +04:00
|
|
|
}
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2013-02-21 06:34:47 +04:00
|
|
|
wTimeStamp = rdpsnd->wTimeStamp + TIME_DELAY_MS;
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2013-02-20 07:36:04 +04:00
|
|
|
data = stream_new(8);
|
|
|
|
stream_write_BYTE(data, SNDC_WAVECONFIRM);
|
|
|
|
stream_write_BYTE(data, 0);
|
|
|
|
stream_write_UINT16(data, 4);
|
|
|
|
stream_write_UINT16(data, wTimeStamp);
|
|
|
|
stream_write_BYTE(data, rdpsnd->cBlockNo); /* cConfirmedBlockNo */
|
|
|
|
stream_write_BYTE(data, 0); /* bPad */
|
2012-11-22 05:21:08 +04:00
|
|
|
|
2013-02-21 06:34:47 +04:00
|
|
|
wTimeStamp = rdpsnd->wave_timestamp + TIME_DELAY_MS;
|
2013-02-21 00:33:42 +04:00
|
|
|
MessageQueue_Post(rdpsnd->MsgPipe->Out, NULL, 0, (void*) data, (void*) (size_t) wTimeStamp);
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void rdpsnd_process_message_close(rdpsndPlugin* rdpsnd)
|
|
|
|
{
|
|
|
|
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
|
|
|
{
|
2011-08-15 12:58:07 +04:00
|
|
|
IFCALL(rdpsnd->device->Start, rdpsnd->device);
|
2012-11-26 10:15:11 +04:00
|
|
|
}
|
|
|
|
|
2013-02-20 06:21:20 +04:00
|
|
|
rdpsnd->close_timestamp = GetTickCount() + 2000;
|
2011-08-15 11:08:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void rdpsnd_process_message_setvolume(rdpsndPlugin* rdpsnd, STREAM* data_in)
|
|
|
|
{
|
2012-10-09 11:26:39 +04:00
|
|
|
UINT32 dwVolume;
|
2011-08-15 11:08:23 +04:00
|
|
|
|
2012-10-09 11:26:39 +04:00
|
|
|
stream_read_UINT32(data_in, 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
|
|
|
}
|
|
|
|
|
|
|
|
static void rdpsnd_process_receive(rdpSvcPlugin* plugin, STREAM* data_in)
|
|
|
|
{
|
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)
|
|
|
|
{
|
|
|
|
rdpsnd_process_message_wave(rdpsnd, data_in);
|
2012-02-27 21:12:17 +04:00
|
|
|
stream_free(data_in);
|
2011-08-15 11:08:23 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-09 11:01:37 +04:00
|
|
|
stream_read_BYTE(data_in, msgType); /* msgType */
|
|
|
|
stream_seek_BYTE(data_in); /* bPad */
|
|
|
|
stream_read_UINT16(data_in, BodySize);
|
2011-08-15 11:08:23 +04:00
|
|
|
|
|
|
|
DEBUG_SVC("msgType %d BodySize %d", msgType, BodySize);
|
|
|
|
|
|
|
|
switch (msgType)
|
|
|
|
{
|
|
|
|
case SNDC_FORMATS:
|
|
|
|
rdpsnd_process_message_formats(rdpsnd, data_in);
|
|
|
|
break;
|
2012-11-26 10:15:11 +04:00
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
case SNDC_TRAINING:
|
|
|
|
rdpsnd_process_message_training(rdpsnd, data_in);
|
|
|
|
break;
|
2012-11-26 10:15:11 +04:00
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
case SNDC_WAVE:
|
|
|
|
rdpsnd_process_message_wave_info(rdpsnd, data_in, BodySize);
|
|
|
|
break;
|
2012-11-26 10:15:11 +04:00
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
case SNDC_CLOSE:
|
|
|
|
rdpsnd_process_message_close(rdpsnd);
|
|
|
|
break;
|
2012-11-26 10:15:11 +04:00
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
case SNDC_SETVOLUME:
|
|
|
|
rdpsnd_process_message_setvolume(rdpsnd, data_in);
|
|
|
|
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
|
|
|
|
|
|
|
stream_free(data_in);
|
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;
|
|
|
|
}
|
|
|
|
rdpsnd->device = device;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
if (entry == NULL)
|
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")
|
|
|
|
{
|
|
|
|
rdpsnd->fixed_format = atoi(arg->Value);
|
|
|
|
}
|
|
|
|
CommandLineSwitchCase(arg, "rate")
|
|
|
|
{
|
|
|
|
rdpsnd->fixed_rate = atoi(arg->Value);
|
|
|
|
}
|
|
|
|
CommandLineSwitchCase(arg, "channel")
|
|
|
|
{
|
|
|
|
rdpsnd->fixed_channel = atoi(arg->Value);
|
|
|
|
}
|
|
|
|
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-21 00:33:42 +04:00
|
|
|
rdpsnd->MsgPipe = MessagePipe_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.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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-21 00:33:42 +04:00
|
|
|
MessagePipe_Free(rdpsnd->MsgPipe);
|
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);
|
|
|
|
|
2011-08-15 11:08:23 +04:00
|
|
|
rdpsnd_free_supported_formats(rdpsnd);
|
|
|
|
|
2012-10-09 07:21:26 +04:00
|
|
|
free(plugin);
|
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;
|
|
|
|
_p->plugin.receive_callback = rdpsnd_process_receive;
|
|
|
|
_p->plugin.event_callback = rdpsnd_process_event;
|
|
|
|
_p->plugin.terminate_callback = rdpsnd_process_terminate;
|
|
|
|
|
2013-02-21 19:46:11 +04:00
|
|
|
#ifndef _WIN32
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|