22 #include <freerdp/config.h>
29 #include <winpr/crt.h>
30 #include <winpr/stream.h>
31 #include <winpr/cmdline.h>
33 #include <freerdp/types.h>
35 #include "rdpsnd_main.h"
39 rdpsndDevicePlugin device;
45 static BOOL rdpsnd_sndio_open(rdpsndDevicePlugin* device,
AUDIO_FORMAT* format,
int latency)
47 rdpsndSndioPlugin* sndio = (rdpsndSndioPlugin*)device;
49 if (device == NULL || format == NULL)
52 if (sndio->hdl != NULL)
55 sndio->hdl = sio_open(SIO_DEVANY, SIO_PLAY, 0);
56 if (sndio->hdl == NULL)
58 WLog_ERR(TAG,
"could not open audio device");
62 sio_initpar(&sndio->par);
63 sndio->par.bits = format->wBitsPerSample;
64 sndio->par.pchan = format->nChannels;
65 sndio->par.rate = format->nSamplesPerSec;
66 if (!sio_setpar(sndio->hdl, &sndio->par))
68 WLog_ERR(TAG,
"could not set audio parameters");
71 if (!sio_getpar(sndio->hdl, &sndio->par))
73 WLog_ERR(TAG,
"could not get audio parameters");
77 if (!sio_start(sndio->hdl))
79 WLog_ERR(TAG,
"could not start audio device");
86 static void rdpsnd_sndio_close(rdpsndDevicePlugin* device)
88 rdpsndSndioPlugin* sndio = (rdpsndSndioPlugin*)device;
93 if (sndio->hdl != NULL)
96 sio_close(sndio->hdl);
101 static BOOL rdpsnd_sndio_set_volume(rdpsndDevicePlugin* device, UINT32 value)
103 rdpsndSndioPlugin* sndio = (rdpsndSndioPlugin*)device;
105 if (device == NULL || sndio->hdl == NULL)
112 return sio_setvol(sndio->hdl, ((value & 0xFFFF) * SIO_MAXVOL) / 0xFFFF);
115 static void rdpsnd_sndio_free(rdpsndDevicePlugin* device)
117 rdpsndSndioPlugin* sndio = (rdpsndSndioPlugin*)device;
122 rdpsnd_sndio_close(device);
126 static BOOL rdpsnd_sndio_format_supported(rdpsndDevicePlugin* device,
AUDIO_FORMAT* format)
131 return (format->wFormatTag == WAVE_FORMAT_PCM);
134 static void rdpsnd_sndio_play(rdpsndDevicePlugin* device, BYTE* data,
int size)
136 rdpsndSndioPlugin* sndio = (rdpsndSndioPlugin*)device;
138 if (device == NULL || sndio->hdl == NULL)
141 sio_write(sndio->hdl, data, size);
149 static UINT rdpsnd_sndio_parse_addin_args(rdpsndDevicePlugin* device,
ADDIN_ARGV* args)
154 rdpsndSndioPlugin* sndio = (rdpsndSndioPlugin*)device;
157 COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD;
158 status = CommandLineParseArgumentsA(args->argc, (
const char**)args->argv, rdpsnd_sndio_args,
159 flags, sndio, NULL, NULL);
162 return ERROR_INVALID_DATA;
164 arg = rdpsnd_sndio_args;
168 if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT))
171 CommandLineSwitchStart(arg) CommandLineSwitchEnd(arg)
172 }
while ((arg = CommandLineFindNextArgumentA(arg)) != NULL);
174 return CHANNEL_RC_OK;
182 FREERDP_ENTRY_POINT(UINT VCAPITYPE sndio_freerdp_rdpsnd_client_subsystem_entry(
186 rdpsndSndioPlugin* sndio;
187 UINT ret = CHANNEL_RC_OK;
188 sndio = (rdpsndSndioPlugin*)calloc(1,
sizeof(rdpsndSndioPlugin));
191 return CHANNEL_RC_NO_MEMORY;
193 sndio->device.Open = rdpsnd_sndio_open;
194 sndio->device.FormatSupported = rdpsnd_sndio_format_supported;
195 sndio->device.SetVolume = rdpsnd_sndio_set_volume;
196 sndio->device.Play = rdpsnd_sndio_play;
197 sndio->device.Close = rdpsnd_sndio_close;
198 sndio->device.Free = rdpsnd_sndio_free;
199 args = pEntryPoints->args;
203 ret = rdpsnd_sndio_parse_addin_args((rdpsndDevicePlugin*)sndio, args);
205 if (ret != CHANNEL_RC_OK)
207 WLog_ERR(TAG,
"error parsing arguments");
212 pEntryPoints->pRegisterRdpsndDevice(pEntryPoints->rdpsnd, &sndio->device);
215 rdpsnd_sndio_free(&sndio->device);