1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
/**
* FreeRDP: A Remote Desktop Protocol Implementation
* Audio Output Virtual Channel
*
* Copyright 2019 Armin Novak <armin.novak@thincast.com>
* Copyright 2019 Thincast Technologies GmbH
* Copyright 2020 Ingo Feinerer <feinerer@logic.at>
*
* 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.
*/
#include <freerdp/config.h>
#include <sndio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <winpr/crt.h>
#include <winpr/stream.h>
#include <winpr/cmdline.h>
#include <freerdp/types.h>
#include "rdpsnd_main.h"
typedef struct
{
rdpsndDevicePlugin device;
struct sio_hdl* hdl;
struct sio_par par;
} rdpsndSndioPlugin;
static BOOL rdpsnd_sndio_open(rdpsndDevicePlugin* device, AUDIO_FORMAT* format, int latency)
{
rdpsndSndioPlugin* sndio = (rdpsndSndioPlugin*)device;
if (device == NULL || format == NULL)
return FALSE;
if (sndio->hdl != NULL)
return TRUE;
sndio->hdl = sio_open(SIO_DEVANY, SIO_PLAY, 0);
if (sndio->hdl == NULL)
{
WLog_ERR(TAG, "could not open audio device");
return FALSE;
}
sio_initpar(&sndio->par);
sndio->par.bits = format->wBitsPerSample;
sndio->par.pchan = format->nChannels;
sndio->par.rate = format->nSamplesPerSec;
if (!sio_setpar(sndio->hdl, &sndio->par))
{
WLog_ERR(TAG, "could not set audio parameters");
return FALSE;
}
if (!sio_getpar(sndio->hdl, &sndio->par))
{
WLog_ERR(TAG, "could not get audio parameters");
return FALSE;
}
if (!sio_start(sndio->hdl))
{
WLog_ERR(TAG, "could not start audio device");
return FALSE;
}
return TRUE;
}
static void rdpsnd_sndio_close(rdpsndDevicePlugin* device)
{
rdpsndSndioPlugin* sndio = (rdpsndSndioPlugin*)device;
if (device == NULL)
return;
if (sndio->hdl != NULL)
{
sio_stop(sndio->hdl);
sio_close(sndio->hdl);
sndio->hdl = NULL;
}
}
static BOOL rdpsnd_sndio_set_volume(rdpsndDevicePlugin* device, UINT32 value)
{
rdpsndSndioPlugin* sndio = (rdpsndSndioPlugin*)device;
if (device == NULL || sndio->hdl == NULL)
return FALSE;
/*
* Low-order word contains the left-channel volume setting.
* We ignore the right-channel volume setting in the high-order word.
*/
return sio_setvol(sndio->hdl, ((value & 0xFFFF) * SIO_MAXVOL) / 0xFFFF);
}
static void rdpsnd_sndio_free(rdpsndDevicePlugin* device)
{
rdpsndSndioPlugin* sndio = (rdpsndSndioPlugin*)device;
if (device == NULL)
return;
rdpsnd_sndio_close(device);
free(sndio);
}
static BOOL rdpsnd_sndio_format_supported(rdpsndDevicePlugin* device, AUDIO_FORMAT* format)
{
if (format == NULL)
return FALSE;
return (format->wFormatTag == WAVE_FORMAT_PCM);
}
static void rdpsnd_sndio_play(rdpsndDevicePlugin* device, BYTE* data, int size)
{
rdpsndSndioPlugin* sndio = (rdpsndSndioPlugin*)device;
if (device == NULL || sndio->hdl == NULL)
return;
sio_write(sndio->hdl, data, size);
}
/**
* Function description
*
* @return 0 on success, otherwise a Win32 error code
*/
static UINT rdpsnd_sndio_parse_addin_args(rdpsndDevicePlugin* device, ADDIN_ARGV* args)
{
int status;
DWORD flags;
COMMAND_LINE_ARGUMENT_A* arg;
rdpsndSndioPlugin* sndio = (rdpsndSndioPlugin*)device;
COMMAND_LINE_ARGUMENT_A rdpsnd_sndio_args[] = { { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL } };
flags =
COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD;
status = CommandLineParseArgumentsA(args->argc, (const char**)args->argv, rdpsnd_sndio_args,
flags, sndio, NULL, NULL);
if (status < 0)
return ERROR_INVALID_DATA;
arg = rdpsnd_sndio_args;
do
{
if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT))
continue;
CommandLineSwitchStart(arg) CommandLineSwitchEnd(arg)
} while ((arg = CommandLineFindNextArgumentA(arg)) != NULL);
return CHANNEL_RC_OK;
}
/**
* Function description
*
* @return 0 on success, otherwise a Win32 error code
*/
FREERDP_ENTRY_POINT(UINT sndio_freerdp_rdpsnd_client_subsystem_entry(
PFREERDP_RDPSND_DEVICE_ENTRY_POINTS pEntryPoints))
{
ADDIN_ARGV* args;
rdpsndSndioPlugin* sndio;
UINT ret = CHANNEL_RC_OK;
sndio = (rdpsndSndioPlugin*)calloc(1, sizeof(rdpsndSndioPlugin));
if (sndio == NULL)
return CHANNEL_RC_NO_MEMORY;
sndio->device.Open = rdpsnd_sndio_open;
sndio->device.FormatSupported = rdpsnd_sndio_format_supported;
sndio->device.SetVolume = rdpsnd_sndio_set_volume;
sndio->device.Play = rdpsnd_sndio_play;
sndio->device.Close = rdpsnd_sndio_close;
sndio->device.Free = rdpsnd_sndio_free;
args = pEntryPoints->args;
if (args->argc > 1)
{
ret = rdpsnd_sndio_parse_addin_args((rdpsndDevicePlugin*)sndio, args);
if (ret != CHANNEL_RC_OK)
{
WLog_ERR(TAG, "error parsing arguments");
goto error;
}
}
pEntryPoints->pRegisterRdpsndDevice(pEntryPoints->rdpsnd, &sndio->device);
return ret;
error:
rdpsnd_sndio_free(&sndio->device);
return ret;
}
|