23#include <freerdp/config.h>
26#include <winpr/assert.h>
32#include <winpr/cmdline.h>
33#include <winpr/wlog.h>
35#include <freerdp/addin.h>
37#include <winpr/stream.h>
38#include <freerdp/freerdp.h>
39#include <freerdp/codec/dsp.h>
40#include <freerdp/client/channels.h>
41#include <freerdp/channels/audin.h>
43#include "audin_main.h"
45#define SNDIN_VERSION 0x02
49 MSG_SNDIN_VERSION = 0x01,
50 MSG_SNDIN_FORMATS = 0x02,
51 MSG_SNDIN_OPEN = 0x03,
52 MSG_SNDIN_OPEN_REPLY = 0x04,
53 MSG_SNDIN_DATA_INCOMING = 0x05,
54 MSG_SNDIN_DATA = 0x06,
55 MSG_SNDIN_FORMATCHANGE = 0x07,
60 IWTSVirtualChannelCallback iface;
63 IWTSVirtualChannelManager* channel_mgr;
64 IWTSVirtualChannel* channel;
73} AUDIN_CHANNEL_CALLBACK;
89 rdpContext* rdpcontext;
93 UINT32 FramesPerPacket;
95 FREERDP_DSP_CONTEXT* dsp_context;
98 IWTSListener* listener;
104static BOOL audin_process_addin_args(AUDIN_PLUGIN* audin,
const ADDIN_ARGV* args);
106static UINT audin_channel_write_and_free(AUDIN_CHANNEL_CALLBACK* callback,
wStream* out,
109 if (!callback || !out)
110 return ERROR_INVALID_PARAMETER;
112 if (!callback->channel || !callback->channel->Write)
113 return ERROR_INTERNAL_ERROR;
115 Stream_SealLength(out);
116 WINPR_ASSERT(Stream_Length(out) <= UINT32_MAX);
117 const UINT error = callback->channel->Write(callback->channel, (ULONG)Stream_Length(out),
118 Stream_Buffer(out), NULL);
121 Stream_Free(out, TRUE);
131static UINT audin_process_version(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback,
wStream* s)
134 UINT32 ServerVersion = 0;
136 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
137 return ERROR_INVALID_DATA;
139 Stream_Read_UINT32(s, ServerVersion);
140 WLog_Print(audin->log, WLOG_DEBUG,
"ServerVersion=%" PRIu32
", ClientVersion=%" PRIu32,
141 ServerVersion, ClientVersion);
144 if (ServerVersion > ClientVersion)
146 WLog_Print(audin->log, WLOG_WARN,
147 "Incompatible channel version server=%" PRIu32
148 ", client supports version=%" PRIu32,
149 ServerVersion, ClientVersion);
150 return CHANNEL_RC_OK;
152 audin->version = ServerVersion;
154 wStream* out = Stream_New(NULL, 5);
158 WLog_Print(audin->log, WLOG_ERROR,
"Stream_New failed!");
159 return ERROR_OUTOFMEMORY;
162 Stream_Write_UINT8(out, MSG_SNDIN_VERSION);
163 Stream_Write_UINT32(out, ClientVersion);
164 return audin_channel_write_and_free(callback, out, TRUE);
172static UINT audin_send_incoming_data_pdu(AUDIN_CHANNEL_CALLBACK* callback)
174 BYTE out_data[1] = { MSG_SNDIN_DATA_INCOMING };
176 if (!callback || !callback->channel || !callback->channel->Write)
177 return ERROR_INTERNAL_ERROR;
179 return callback->channel->Write(callback->channel, 1, out_data, NULL);
187static UINT audin_process_formats(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback,
wStream* s)
189 UINT error = ERROR_INTERNAL_ERROR;
190 UINT32 NumFormats = 0;
191 UINT32 cbSizeFormatsPacket = 0;
194 WINPR_ASSERT(callback);
196 if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
197 return ERROR_INVALID_DATA;
199 Stream_Read_UINT32(s, NumFormats);
200 WLog_Print(audin->log, WLOG_DEBUG,
"NumFormats %" PRIu32
"", NumFormats);
202 if ((NumFormats < 1) || (NumFormats > 1000))
204 WLog_Print(audin->log, WLOG_ERROR,
"bad NumFormats %" PRIu32
"", NumFormats);
205 return ERROR_INVALID_DATA;
208 Stream_Seek_UINT32(s);
210 audin->format = NULL;
211 audio_formats_free(callback->formats, callback->formats_count);
212 callback->formats_count = 0;
214 callback->formats = audio_formats_new(NumFormats);
216 if (!callback->formats)
218 WLog_Print(audin->log, WLOG_ERROR,
"calloc failed!");
219 return ERROR_INVALID_DATA;
222 wStream* out = Stream_New(NULL, 9);
226 error = CHANNEL_RC_NO_MEMORY;
227 WLog_Print(audin->log, WLOG_ERROR,
"Stream_New failed!");
234 for (UINT32 i = 0; i < NumFormats; i++)
238 if (!audio_format_read(s, &format))
240 error = ERROR_INVALID_DATA;
244 audio_format_print(audin->log, WLOG_DEBUG, &format);
246 if (!audio_format_compatible(audin->fixed_format, &format))
248 audio_format_free(&format);
252 if (freerdp_dsp_supports_format(&format, TRUE) ||
253 audin->device->FormatSupported(audin->device, &format))
256 callback->formats[callback->formats_count++] = format;
258 if (!audio_format_write(out, &format))
260 error = CHANNEL_RC_NO_MEMORY;
261 WLog_Print(audin->log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
267 audio_format_free(&format);
271 if ((error = audin_send_incoming_data_pdu(callback)))
273 WLog_Print(audin->log, WLOG_ERROR,
"audin_send_incoming_data_pdu failed!");
277 cbSizeFormatsPacket = (UINT32)Stream_GetPosition(out);
278 Stream_SetPosition(out, 0);
279 Stream_Write_UINT8(out, MSG_SNDIN_FORMATS);
280 Stream_Write_UINT32(out, callback->formats_count);
281 Stream_Write_UINT32(out, cbSizeFormatsPacket);
282 Stream_SetPosition(out, cbSizeFormatsPacket);
283 error = audin_channel_write_and_free(callback, out, FALSE);
286 if (error != CHANNEL_RC_OK)
288 audin->format = NULL;
289 audio_formats_free(callback->formats, NumFormats);
290 callback->formats = NULL;
293 Stream_Free(out, TRUE);
302static UINT audin_send_format_change_pdu(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback,
306 WINPR_ASSERT(callback);
308 wStream* out = Stream_New(NULL, 5);
312 WLog_Print(audin->log, WLOG_ERROR,
"Stream_New failed!");
313 return CHANNEL_RC_OK;
316 Stream_Write_UINT8(out, MSG_SNDIN_FORMATCHANGE);
317 Stream_Write_UINT32(out, NewFormat);
318 return audin_channel_write_and_free(callback, out, TRUE);
326static UINT audin_send_open_reply_pdu(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback,
330 WINPR_ASSERT(callback);
332 wStream* out = Stream_New(NULL, 5);
336 WLog_Print(audin->log, WLOG_ERROR,
"Stream_New failed!");
337 return CHANNEL_RC_NO_MEMORY;
340 Stream_Write_UINT8(out, MSG_SNDIN_OPEN_REPLY);
341 Stream_Write_UINT32(out, Result);
342 return audin_channel_write_and_free(callback, out, TRUE);
350static UINT audin_receive_wave_data(
const AUDIO_FORMAT* format,
const BYTE* data,
size_t size,
353 WINPR_ASSERT(format);
355 UINT error = ERROR_INTERNAL_ERROR;
356 AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*)user_data;
359 return CHANNEL_RC_BAD_CHANNEL_HANDLE;
361 AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)callback->plugin;
364 return CHANNEL_RC_BAD_CHANNEL_HANDLE;
366 if (!audin->attached)
367 return CHANNEL_RC_OK;
369 Stream_SetPosition(audin->data, 0);
371 if (!Stream_EnsureRemainingCapacity(audin->data, 1))
372 return CHANNEL_RC_NO_MEMORY;
374 Stream_Write_UINT8(audin->data, MSG_SNDIN_DATA);
376 const BOOL compatible = audio_format_compatible(format, audin->format);
377 if (compatible && audin->device->FormatSupported(audin->device, audin->format))
379 if (!Stream_EnsureRemainingCapacity(audin->data, size))
380 return CHANNEL_RC_NO_MEMORY;
382 Stream_Write(audin->data, data, size);
386 if (!freerdp_dsp_encode(audin->dsp_context, format, data, size, audin->data))
387 return ERROR_INTERNAL_ERROR;
391 if (Stream_GetPosition(audin->data) <= 1)
392 return CHANNEL_RC_OK;
394 audio_format_print(audin->log, WLOG_TRACE, audin->format);
395 WLog_Print(audin->log, WLOG_TRACE,
"[%" PRIuz
"/%" PRIuz
"]", size,
396 Stream_GetPosition(audin->data) - 1);
398 if ((error = audin_send_incoming_data_pdu(callback)))
400 WLog_Print(audin->log, WLOG_ERROR,
"audin_send_incoming_data_pdu failed!");
404 return audin_channel_write_and_free(callback, audin->data, FALSE);
407static BOOL audin_open_device(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback)
409 UINT error = ERROR_INTERNAL_ERROR;
412 if (!audin || !audin->device)
415 format = *audin->format;
416 const BOOL supported =
417 IFCALLRESULT(FALSE, audin->device->FormatSupported, audin->device, &format);
418 WLog_Print(audin->log, WLOG_DEBUG,
"microphone uses %s codec",
419 audio_format_get_tag_string(format.wFormatTag));
424 const UINT32 samplerates[] = { format.nSamplesPerSec, 96000, 48000, 44100, 22050 };
427 format.wFormatTag = WAVE_FORMAT_PCM;
428 format.wBitsPerSample = 16;
430 for (
size_t x = 0; x < ARRAYSIZE(samplerates); x++)
432 format.nSamplesPerSec = samplerates[x];
433 for (UINT16 y = audin->format->nChannels; y > 0; y--)
435 format.nChannels = y;
436 format.nBlockAlign = 2 * format.nChannels;
437 test = IFCALLRESULT(FALSE, audin->device->FormatSupported, audin->device, &format);
448 IFCALLRET(audin->device->SetFormat, error, audin->device, &format, audin->FramesPerPacket);
450 if (error != CHANNEL_RC_OK)
452 WLog_ERR(TAG,
"SetFormat failed with errorcode %" PRIu32
"", error);
456 if (!freerdp_dsp_context_reset(audin->dsp_context, audin->format, audin->FramesPerPacket))
459 IFCALLRET(audin->device->Open, error, audin->device, audin_receive_wave_data, callback);
461 if (error != CHANNEL_RC_OK)
463 WLog_ERR(TAG,
"Open failed with errorcode %" PRIu32
"", error);
475static UINT audin_process_open(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback,
wStream* s)
477 UINT32 initialFormat = 0;
478 UINT32 FramesPerPacket = 0;
479 UINT error = CHANNEL_RC_OK;
481 if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
482 return ERROR_INVALID_DATA;
484 Stream_Read_UINT32(s, FramesPerPacket);
485 Stream_Read_UINT32(s, initialFormat);
486 WLog_Print(audin->log, WLOG_DEBUG,
"FramesPerPacket=%" PRIu32
" initialFormat=%" PRIu32
"",
487 FramesPerPacket, initialFormat);
488 audin->FramesPerPacket = FramesPerPacket;
490 if (initialFormat >= callback->formats_count)
492 WLog_Print(audin->log, WLOG_ERROR,
"invalid format index %" PRIu32
" (total %" PRIu32
")",
493 initialFormat, callback->formats_count);
494 return ERROR_INVALID_DATA;
497 audin->format = &callback->formats[initialFormat];
499 if (!audin_open_device(audin, callback))
500 return ERROR_INTERNAL_ERROR;
502 if ((error = audin_send_format_change_pdu(audin, callback, initialFormat)))
504 WLog_Print(audin->log, WLOG_ERROR,
"audin_send_format_change_pdu failed!");
508 if ((error = audin_send_open_reply_pdu(audin, callback, 0)))
509 WLog_Print(audin->log, WLOG_ERROR,
"audin_send_open_reply_pdu failed!");
519static UINT audin_process_format_change(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback,
522 UINT32 NewFormat = 0;
523 UINT error = CHANNEL_RC_OK;
525 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
526 return ERROR_INVALID_DATA;
528 Stream_Read_UINT32(s, NewFormat);
529 WLog_Print(audin->log, WLOG_DEBUG,
"NewFormat=%" PRIu32
"", NewFormat);
531 if (NewFormat >= callback->formats_count)
533 WLog_Print(audin->log, WLOG_ERROR,
"invalid format index %" PRIu32
" (total %" PRIu32
")",
534 NewFormat, callback->formats_count);
535 return ERROR_INVALID_DATA;
538 audin->format = &callback->formats[NewFormat];
542 IFCALLRET(audin->device->Close, error, audin->device);
544 if (error != CHANNEL_RC_OK)
546 WLog_ERR(TAG,
"Close failed with errorcode %" PRIu32
"", error);
551 if (!audin_open_device(audin, callback))
552 return ERROR_INTERNAL_ERROR;
554 if ((error = audin_send_format_change_pdu(audin, callback, NewFormat)))
555 WLog_ERR(TAG,
"audin_send_format_change_pdu failed!");
565static UINT audin_on_data_received(IWTSVirtualChannelCallback* pChannelCallback,
wStream* data)
569 AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*)pChannelCallback;
571 if (!callback || !data)
572 return ERROR_INVALID_PARAMETER;
574 AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)callback->plugin;
577 return ERROR_INTERNAL_ERROR;
579 if (!Stream_CheckAndLogRequiredCapacity(TAG, data, 1))
580 return ERROR_NO_DATA;
582 Stream_Read_UINT8(data, MessageId);
583 WLog_Print(audin->log, WLOG_DEBUG,
"MessageId=0x%02" PRIx8
"", MessageId);
587 case MSG_SNDIN_VERSION:
588 error = audin_process_version(audin, callback, data);
591 case MSG_SNDIN_FORMATS:
592 error = audin_process_formats(audin, callback, data);
596 error = audin_process_open(audin, callback, data);
599 case MSG_SNDIN_FORMATCHANGE:
600 error = audin_process_format_change(audin, callback, data);
604 WLog_Print(audin->log, WLOG_ERROR,
"unknown MessageId=0x%02" PRIx8
"", MessageId);
605 error = ERROR_INVALID_DATA;
617static UINT audin_on_close(IWTSVirtualChannelCallback* pChannelCallback)
619 AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*)pChannelCallback;
620 WINPR_ASSERT(callback);
622 AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)callback->plugin;
625 UINT error = CHANNEL_RC_OK;
626 WLog_Print(audin->log, WLOG_TRACE,
"...");
630 IFCALLRET(audin->device->Close, error, audin->device);
632 if (error != CHANNEL_RC_OK)
633 WLog_Print(audin->log, WLOG_ERROR,
"Close failed with errorcode %" PRIu32
"", error);
636 audin->format = NULL;
637 audio_formats_free(callback->formats, callback->formats_count);
647static UINT audin_on_new_channel_connection(IWTSListenerCallback* pListenerCallback,
648 IWTSVirtualChannel* pChannel,
649 WINPR_ATTR_UNUSED BYTE* Data,
650 WINPR_ATTR_UNUSED BOOL* pbAccept,
651 IWTSVirtualChannelCallback** ppCallback)
655 if (!listener_callback || !listener_callback->plugin)
656 return ERROR_INTERNAL_ERROR;
658 AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)listener_callback->plugin;
659 WLog_Print(audin->log, WLOG_TRACE,
"...");
660 AUDIN_CHANNEL_CALLBACK* callback =
661 (AUDIN_CHANNEL_CALLBACK*)calloc(1,
sizeof(AUDIN_CHANNEL_CALLBACK));
665 WLog_Print(audin->log, WLOG_ERROR,
"calloc failed!");
666 return CHANNEL_RC_NO_MEMORY;
669 callback->iface.OnDataReceived = audin_on_data_received;
670 callback->iface.OnClose = audin_on_close;
671 callback->plugin = listener_callback->plugin;
672 callback->channel_mgr = listener_callback->channel_mgr;
673 callback->channel = pChannel;
674 *ppCallback = &callback->iface;
675 return CHANNEL_RC_OK;
683static UINT audin_plugin_initialize(IWTSPlugin* pPlugin, IWTSVirtualChannelManager* pChannelMgr)
685 AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pPlugin;
688 return CHANNEL_RC_BAD_CHANNEL_HANDLE;
691 return ERROR_INVALID_PARAMETER;
693 if (audin->initialized)
695 WLog_ERR(TAG,
"[%s] channel initialized twice, aborting", AUDIN_DVC_CHANNEL_NAME);
696 return ERROR_INVALID_DATA;
699 WLog_Print(audin->log, WLOG_TRACE,
"...");
700 audin->listener_callback =
703 if (!audin->listener_callback)
705 WLog_Print(audin->log, WLOG_ERROR,
"calloc failed!");
706 return CHANNEL_RC_NO_MEMORY;
709 audin->listener_callback->iface.OnNewChannelConnection = audin_on_new_channel_connection;
710 audin->listener_callback->plugin = pPlugin;
711 audin->listener_callback->channel_mgr = pChannelMgr;
712 const UINT rc = pChannelMgr->CreateListener(pChannelMgr, AUDIN_DVC_CHANNEL_NAME, 0,
713 &audin->listener_callback->iface, &audin->listener);
715 audin->initialized = rc == CHANNEL_RC_OK;
724static UINT audin_plugin_terminated(IWTSPlugin* pPlugin)
726 AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pPlugin;
727 UINT error = CHANNEL_RC_OK;
730 return CHANNEL_RC_BAD_CHANNEL_HANDLE;
732 WLog_Print(audin->log, WLOG_TRACE,
"...");
734 if (audin->listener_callback)
736 IWTSVirtualChannelManager* mgr = audin->listener_callback->channel_mgr;
738 IFCALL(mgr->DestroyListener, mgr, audin->listener);
740 audio_formats_free(audin->fixed_format, 1);
744 IFCALLRET(audin->device->Free, error, audin->device);
746 if (error != CHANNEL_RC_OK)
748 WLog_Print(audin->log, WLOG_ERROR,
"Free failed with errorcode %" PRIu32
"", error);
752 audin->device = NULL;
755 freerdp_dsp_context_free(audin->dsp_context);
756 Stream_Free(audin->data, TRUE);
757 free(audin->subsystem);
758 free(audin->device_name);
759 free(audin->listener_callback);
761 return CHANNEL_RC_OK;
764static UINT audin_plugin_attached(IWTSPlugin* pPlugin)
766 AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pPlugin;
767 UINT error = CHANNEL_RC_OK;
770 return CHANNEL_RC_BAD_CHANNEL_HANDLE;
772 audin->attached = TRUE;
776static UINT audin_plugin_detached(IWTSPlugin* pPlugin)
778 AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pPlugin;
779 UINT error = CHANNEL_RC_OK;
782 return CHANNEL_RC_BAD_CHANNEL_HANDLE;
784 audin->attached = FALSE;
793static UINT audin_register_device_plugin(IWTSPlugin* pPlugin, IAudinDevice* device)
795 AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pPlugin;
801 WLog_Print(audin->log, WLOG_ERROR,
"existing device, abort.");
802 return ERROR_ALREADY_EXISTS;
805 WLog_Print(audin->log, WLOG_DEBUG,
"device registered.");
806 audin->device = device;
807 return CHANNEL_RC_OK;
815static UINT audin_load_device_plugin(AUDIN_PLUGIN* audin,
const char* name,
const ADDIN_ARGV* args)
820 UINT error = ERROR_INTERNAL_ERROR;
822 PVIRTUALCHANNELENTRY pvce = freerdp_load_channel_addin_entry(AUDIN_CHANNEL_NAME, name, NULL, 0);
823 PFREERDP_AUDIN_DEVICE_ENTRY entry = WINPR_FUNC_PTR_CAST(pvce, PFREERDP_AUDIN_DEVICE_ENTRY);
827 WLog_Print(audin->log, WLOG_ERROR,
828 "freerdp_load_channel_addin_entry did not return any function pointers for %s ",
830 return ERROR_INVALID_FUNCTION;
833 entryPoints.plugin = &audin->iface;
834 entryPoints.pRegisterAudinDevice = audin_register_device_plugin;
835 entryPoints.args = args;
836 entryPoints.rdpcontext = audin->rdpcontext;
838 error = entry(&entryPoints);
841 WLog_Print(audin->log, WLOG_ERROR,
"%s entry returned error %" PRIu32
".", name, error);
845 WLog_Print(audin->log, WLOG_INFO,
"Loaded %s backend for audin", name);
846 return CHANNEL_RC_OK;
854static UINT audin_set_subsystem(AUDIN_PLUGIN* audin,
const char* subsystem)
858 free(audin->subsystem);
859 audin->subsystem = _strdup(subsystem);
861 if (!audin->subsystem)
863 WLog_Print(audin->log, WLOG_ERROR,
"_strdup failed!");
864 return ERROR_NOT_ENOUGH_MEMORY;
867 return CHANNEL_RC_OK;
875static UINT audin_set_device_name(AUDIN_PLUGIN* audin,
const char* device_name)
879 free(audin->device_name);
880 audin->device_name = _strdup(device_name);
882 if (!audin->device_name)
884 WLog_Print(audin->log, WLOG_ERROR,
"_strdup failed!");
885 return ERROR_NOT_ENOUGH_MEMORY;
888 return CHANNEL_RC_OK;
891BOOL audin_process_addin_args(AUDIN_PLUGIN* audin,
const ADDIN_ARGV* args)
894 {
"sys", COMMAND_LINE_VALUE_REQUIRED,
"<subsystem>", NULL, NULL, -1, NULL,
"subsystem" },
895 {
"dev", COMMAND_LINE_VALUE_REQUIRED,
"<device>", NULL, NULL, -1, NULL,
"device" },
896 {
"format", COMMAND_LINE_VALUE_REQUIRED,
"<format>", NULL, NULL, -1, NULL,
"format" },
897 {
"rate", COMMAND_LINE_VALUE_REQUIRED,
"<rate>", NULL, NULL, -1, NULL,
"rate" },
898 {
"channel", COMMAND_LINE_VALUE_REQUIRED,
"<channel>", NULL, NULL, -1, NULL,
"channel" },
899 { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL }
902 if (!args || args->argc == 1)
906 COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD;
908 CommandLineParseArgumentsA(args->argc, args->argv, audin_args, flags, audin, NULL, NULL);
918 if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT))
921 CommandLineSwitchStart(arg) CommandLineSwitchCase(arg,
"sys")
923 const UINT error = audin_set_subsystem(audin, arg->Value);
924 if (error != CHANNEL_RC_OK)
926 WLog_Print(audin->log, WLOG_ERROR,
927 "audin_set_subsystem failed with error %" PRIu32
"!", error);
931 CommandLineSwitchCase(arg,
"dev")
933 const UINT error = audin_set_device_name(audin, arg->Value);
934 if (error != CHANNEL_RC_OK)
936 WLog_Print(audin->log, WLOG_ERROR,
937 "audin_set_device_name failed with error %" PRIu32
"!", error);
941 CommandLineSwitchCase(arg,
"format")
943 unsigned long val = strtoul(arg->Value, NULL, 0);
945 if ((errno != 0) || (val > UINT16_MAX))
948 audin->fixed_format->wFormatTag = (UINT16)val;
950 CommandLineSwitchCase(arg,
"rate")
952 unsigned long val = strtoul(arg->Value, NULL, 0);
954 if ((errno != 0) || (val == 0) || (val > UINT32_MAX))
957 audin->fixed_format->nSamplesPerSec = (UINT32)val;
959 CommandLineSwitchCase(arg,
"channel")
961 unsigned long val = strtoul(arg->Value, NULL, 0);
963 if ((errno != 0) || (val <= UINT16_MAX))
964 audin->fixed_format->nChannels = (UINT16)val;
966 CommandLineSwitchDefault(arg)
969 CommandLineSwitchEnd(arg)
970 }
while ((arg = CommandLineFindNextArgumentA(arg)) != NULL);
980FREERDP_ENTRY_POINT(UINT VCAPITYPE audin_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints))
982 struct SubsystemEntry
987 UINT error = CHANNEL_RC_INITIALIZATION_ERROR;
988 struct SubsystemEntry entries[] = {
989#if defined(WITH_PULSE)
993 {
"oss",
"default" },
995#if defined(WITH_ALSA)
996 {
"alsa",
"default" },
998#if defined(WITH_OPENSLES)
999 {
"opensles",
"default" },
1001#if defined(WITH_WINMM)
1002 {
"winmm",
"default" },
1004#if defined(WITH_MACAUDIO)
1005 {
"mac",
"default" },
1007#if defined(WITH_IOSAUDIO)
1008 {
"ios",
"default" },
1010#if defined(WITH_SNDIO)
1011 {
"sndio",
"default" },
1015 struct SubsystemEntry* entry = &entries[0];
1016 WINPR_ASSERT(pEntryPoints);
1017 WINPR_ASSERT(pEntryPoints->GetPlugin);
1018 AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pEntryPoints->GetPlugin(pEntryPoints, AUDIN_CHANNEL_NAME);
1021 return CHANNEL_RC_ALREADY_INITIALIZED;
1023 audin = (AUDIN_PLUGIN*)calloc(1,
sizeof(AUDIN_PLUGIN));
1027 WLog_ERR(TAG,
"calloc failed!");
1028 return CHANNEL_RC_NO_MEMORY;
1031 audin->log = WLog_Get(TAG);
1032 audin->data = Stream_New(NULL, 4096);
1033 audin->fixed_format = audio_format_new();
1035 if (!audin->fixed_format)
1041 audin->dsp_context = freerdp_dsp_context_new(TRUE);
1043 if (!audin->dsp_context)
1046 audin->attached = TRUE;
1047 audin->iface.Initialize = audin_plugin_initialize;
1048 audin->iface.Connected = NULL;
1049 audin->iface.Disconnected = NULL;
1050 audin->iface.Terminated = audin_plugin_terminated;
1051 audin->iface.Attached = audin_plugin_attached;
1052 audin->iface.Detached = audin_plugin_detached;
1055 const ADDIN_ARGV* args = pEntryPoints->GetPluginData(pEntryPoints);
1056 audin->rdpcontext = pEntryPoints->GetRdpContext(pEntryPoints);
1060 if (!audin_process_addin_args(audin, args))
1064 if (audin->subsystem)
1066 if ((error = audin_load_device_plugin(audin, audin->subsystem, args)))
1069 audin->log, WLOG_ERROR,
1070 "Unable to load microphone redirection subsystem %s because of error %" PRIu32
1072 audin->subsystem, error);
1078 while (entry && entry->subsystem && !audin->device)
1080 if ((error = audin_set_subsystem(audin, entry->subsystem)))
1082 WLog_Print(audin->log, WLOG_ERROR,
1083 "audin_set_subsystem for %s failed with error %" PRIu32
"!",
1084 entry->subsystem, error);
1086 else if ((error = audin_set_device_name(audin, entry->device)))
1088 WLog_Print(audin->log, WLOG_ERROR,
1089 "audin_set_device_name for %s failed with error %" PRIu32
"!",
1090 entry->subsystem, error);
1092 else if ((error = audin_load_device_plugin(audin, audin->subsystem, args)))
1094 WLog_Print(audin->log, WLOG_ERROR,
1095 "audin_load_device_plugin %s failed with error %" PRIu32
"!",
1096 entry->subsystem, error);
1104 if (audin->device == NULL)
1108 WLog_Print(audin->log, WLOG_ERROR,
"No microphone device could be found.");
1109 error = CHANNEL_RC_OK;
1113 error = pEntryPoints->RegisterPlugin(pEntryPoints, AUDIN_CHANNEL_NAME, &audin->iface);
1114 if (error == CHANNEL_RC_OK)
1118 audin_plugin_terminated(&audin->iface);