22#include <freerdp/config.h>
30#include <winpr/stream.h>
31#include <winpr/cmdline.h>
33#include <freerdp/types.h>
35#include "rdpsnd_main.h"
39 rdpsndDevicePlugin device;
45static BOOL rdpsnd_sndio_open(rdpsndDevicePlugin* device,
AUDIO_FORMAT* format,
int latency)
47 rdpsndSndioPlugin* sndio = (rdpsndSndioPlugin*)device;
49 if (device ==
nullptr || format ==
nullptr)
52 if (sndio->hdl !=
nullptr)
55 sndio->hdl = sio_open(SIO_DEVANY, SIO_PLAY, 0);
56 if (sndio->hdl ==
nullptr)
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");
86static void rdpsnd_sndio_close(rdpsndDevicePlugin* device)
88 rdpsndSndioPlugin* sndio = (rdpsndSndioPlugin*)device;
90 if (device ==
nullptr)
93 if (sndio->hdl !=
nullptr)
96 sio_close(sndio->hdl);
101static BOOL rdpsnd_sndio_set_volume(rdpsndDevicePlugin* device, UINT32 value)
103 rdpsndSndioPlugin* sndio = (rdpsndSndioPlugin*)device;
105 if (device ==
nullptr || sndio->hdl ==
nullptr)
112 return sio_setvol(sndio->hdl, ((value & 0xFFFF) * SIO_MAXVOL) / 0xFFFF);
115static void rdpsnd_sndio_free(rdpsndDevicePlugin* device)
117 rdpsndSndioPlugin* sndio = (rdpsndSndioPlugin*)device;
119 if (device ==
nullptr)
122 rdpsnd_sndio_close(device);
126static BOOL rdpsnd_sndio_format_supported(rdpsndDevicePlugin* device,
AUDIO_FORMAT* format)
128 if (format ==
nullptr)
131 return (format->wFormatTag == WAVE_FORMAT_PCM);
134static void rdpsnd_sndio_play(rdpsndDevicePlugin* device, BYTE* data,
int size)
136 rdpsndSndioPlugin* sndio = (rdpsndSndioPlugin*)device;
138 if (device ==
nullptr || sndio->hdl ==
nullptr)
141 sio_write(sndio->hdl, data, size);
149static UINT rdpsnd_sndio_parse_addin_args(rdpsndDevicePlugin* device,
ADDIN_ARGV* args)
154 rdpsndSndioPlugin* sndio = (rdpsndSndioPlugin*)device;
156 nullptr,
nullptr } };
158 COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD;
159 status = CommandLineParseArgumentsA(args->argc, (
const char**)args->argv, rdpsnd_sndio_args,
160 flags, sndio,
nullptr,
nullptr);
163 return ERROR_INVALID_DATA;
165 arg = rdpsnd_sndio_args;
169 if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT))
172 CommandLineSwitchStart(arg) CommandLineSwitchEnd(arg)
173 }
while ((arg = CommandLineFindNextArgumentA(arg)) !=
nullptr);
175 return CHANNEL_RC_OK;
183FREERDP_ENTRY_POINT(UINT VCAPITYPE sndio_freerdp_rdpsnd_client_subsystem_entry(
187 rdpsndSndioPlugin* sndio;
188 UINT ret = CHANNEL_RC_OK;
189 sndio = (rdpsndSndioPlugin*)calloc(1,
sizeof(rdpsndSndioPlugin));
191 if (sndio ==
nullptr)
192 return CHANNEL_RC_NO_MEMORY;
194 sndio->device.Open = rdpsnd_sndio_open;
195 sndio->device.FormatSupported = rdpsnd_sndio_format_supported;
196 sndio->device.SetVolume = rdpsnd_sndio_set_volume;
197 sndio->device.Play = rdpsnd_sndio_play;
198 sndio->device.Close = rdpsnd_sndio_close;
199 sndio->device.Free = rdpsnd_sndio_free;
200 args = pEntryPoints->args;
204 ret = rdpsnd_sndio_parse_addin_args((rdpsndDevicePlugin*)sndio, args);
206 if (ret != CHANNEL_RC_OK)
208 WLog_ERR(TAG,
"error parsing arguments");
213 pEntryPoints->pRegisterRdpsndDevice(pEntryPoints->rdpsnd, &sndio->device);
216 rdpsnd_sndio_free(&sndio->device);