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);
209 callback->formats = audio_formats_new(NumFormats);
211 if (!callback->formats)
213 WLog_Print(audin->log, WLOG_ERROR,
"calloc failed!");
214 return ERROR_INVALID_DATA;
217 wStream* out = Stream_New(NULL, 9);
221 error = CHANNEL_RC_NO_MEMORY;
222 WLog_Print(audin->log, WLOG_ERROR,
"Stream_New failed!");
229 for (UINT32 i = 0; i < NumFormats; i++)
233 if (!audio_format_read(s, &format))
235 error = ERROR_INVALID_DATA;
239 audio_format_print(audin->log, WLOG_DEBUG, &format);
241 if (!audio_format_compatible(audin->fixed_format, &format))
243 audio_format_free(&format);
247 if (freerdp_dsp_supports_format(&format, TRUE) ||
248 audin->device->FormatSupported(audin->device, &format))
251 callback->formats[callback->formats_count++] = format;
253 if (!audio_format_write(out, &format))
255 error = CHANNEL_RC_NO_MEMORY;
256 WLog_Print(audin->log, WLOG_ERROR,
"Stream_EnsureRemainingCapacity failed!");
262 audio_format_free(&format);
266 if ((error = audin_send_incoming_data_pdu(callback)))
268 WLog_Print(audin->log, WLOG_ERROR,
"audin_send_incoming_data_pdu failed!");
272 cbSizeFormatsPacket = (UINT32)Stream_GetPosition(out);
273 Stream_SetPosition(out, 0);
274 Stream_Write_UINT8(out, MSG_SNDIN_FORMATS);
275 Stream_Write_UINT32(out, callback->formats_count);
276 Stream_Write_UINT32(out, cbSizeFormatsPacket);
277 Stream_SetPosition(out, cbSizeFormatsPacket);
278 error = audin_channel_write_and_free(callback, out, FALSE);
281 if (error != CHANNEL_RC_OK)
283 audio_formats_free(callback->formats, NumFormats);
284 callback->formats = NULL;
287 Stream_Free(out, TRUE);
296static UINT audin_send_format_change_pdu(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback,
300 WINPR_ASSERT(callback);
302 wStream* out = Stream_New(NULL, 5);
306 WLog_Print(audin->log, WLOG_ERROR,
"Stream_New failed!");
307 return CHANNEL_RC_OK;
310 Stream_Write_UINT8(out, MSG_SNDIN_FORMATCHANGE);
311 Stream_Write_UINT32(out, NewFormat);
312 return audin_channel_write_and_free(callback, out, TRUE);
320static UINT audin_send_open_reply_pdu(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback,
324 WINPR_ASSERT(callback);
326 wStream* out = Stream_New(NULL, 5);
330 WLog_Print(audin->log, WLOG_ERROR,
"Stream_New failed!");
331 return CHANNEL_RC_NO_MEMORY;
334 Stream_Write_UINT8(out, MSG_SNDIN_OPEN_REPLY);
335 Stream_Write_UINT32(out, Result);
336 return audin_channel_write_and_free(callback, out, TRUE);
344static UINT audin_receive_wave_data(
const AUDIO_FORMAT* format,
const BYTE* data,
size_t size,
347 WINPR_ASSERT(format);
349 UINT error = ERROR_INTERNAL_ERROR;
350 AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*)user_data;
353 return CHANNEL_RC_BAD_CHANNEL_HANDLE;
355 AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)callback->plugin;
358 return CHANNEL_RC_BAD_CHANNEL_HANDLE;
360 if (!audin->attached)
361 return CHANNEL_RC_OK;
363 Stream_SetPosition(audin->data, 0);
365 if (!Stream_EnsureRemainingCapacity(audin->data, 1))
366 return CHANNEL_RC_NO_MEMORY;
368 Stream_Write_UINT8(audin->data, MSG_SNDIN_DATA);
370 const BOOL compatible = audio_format_compatible(format, audin->format);
371 if (compatible && audin->device->FormatSupported(audin->device, audin->format))
373 if (!Stream_EnsureRemainingCapacity(audin->data, size))
374 return CHANNEL_RC_NO_MEMORY;
376 Stream_Write(audin->data, data, size);
380 if (!freerdp_dsp_encode(audin->dsp_context, format, data, size, audin->data))
381 return ERROR_INTERNAL_ERROR;
385 if (Stream_GetPosition(audin->data) <= 1)
386 return CHANNEL_RC_OK;
388 audio_format_print(audin->log, WLOG_TRACE, audin->format);
389 WLog_Print(audin->log, WLOG_TRACE,
"[%" PRIdz
"/%" PRIdz
"]", size,
390 Stream_GetPosition(audin->data) - 1);
392 if ((error = audin_send_incoming_data_pdu(callback)))
394 WLog_Print(audin->log, WLOG_ERROR,
"audin_send_incoming_data_pdu failed!");
398 return audin_channel_write_and_free(callback, audin->data, FALSE);
401static BOOL audin_open_device(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback)
403 UINT error = ERROR_INTERNAL_ERROR;
406 if (!audin || !audin->device)
409 format = *audin->format;
410 const BOOL supported =
411 IFCALLRESULT(FALSE, audin->device->FormatSupported, audin->device, &format);
412 WLog_Print(audin->log, WLOG_DEBUG,
"microphone uses %s codec",
413 audio_format_get_tag_string(format.wFormatTag));
418 const UINT32 samplerates[] = { format.nSamplesPerSec, 96000, 48000, 44100, 22050 };
421 format.wFormatTag = WAVE_FORMAT_PCM;
422 format.wBitsPerSample = 16;
424 for (
size_t x = 0; x < ARRAYSIZE(samplerates); x++)
426 format.nSamplesPerSec = samplerates[x];
427 for (UINT16 y = audin->format->nChannels; y > 0; y--)
429 format.nChannels = y;
430 format.nBlockAlign = 2 * format.nChannels;
431 test = IFCALLRESULT(FALSE, audin->device->FormatSupported, audin->device, &format);
442 IFCALLRET(audin->device->SetFormat, error, audin->device, &format, audin->FramesPerPacket);
444 if (error != CHANNEL_RC_OK)
446 WLog_ERR(TAG,
"SetFormat failed with errorcode %" PRIu32
"", error);
450 if (!freerdp_dsp_context_reset(audin->dsp_context, audin->format, audin->FramesPerPacket))
453 IFCALLRET(audin->device->Open, error, audin->device, audin_receive_wave_data, callback);
455 if (error != CHANNEL_RC_OK)
457 WLog_ERR(TAG,
"Open failed with errorcode %" PRIu32
"", error);
469static UINT audin_process_open(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback,
wStream* s)
471 UINT32 initialFormat = 0;
472 UINT32 FramesPerPacket = 0;
473 UINT error = CHANNEL_RC_OK;
475 if (!Stream_CheckAndLogRequiredLength(TAG, s, 8))
476 return ERROR_INVALID_DATA;
478 Stream_Read_UINT32(s, FramesPerPacket);
479 Stream_Read_UINT32(s, initialFormat);
480 WLog_Print(audin->log, WLOG_DEBUG,
"FramesPerPacket=%" PRIu32
" initialFormat=%" PRIu32
"",
481 FramesPerPacket, initialFormat);
482 audin->FramesPerPacket = FramesPerPacket;
484 if (initialFormat >= callback->formats_count)
486 WLog_Print(audin->log, WLOG_ERROR,
"invalid format index %" PRIu32
" (total %" PRIu32
")",
487 initialFormat, callback->formats_count);
488 return ERROR_INVALID_DATA;
491 audin->format = &callback->formats[initialFormat];
493 if (!audin_open_device(audin, callback))
494 return ERROR_INTERNAL_ERROR;
496 if ((error = audin_send_format_change_pdu(audin, callback, initialFormat)))
498 WLog_Print(audin->log, WLOG_ERROR,
"audin_send_format_change_pdu failed!");
502 if ((error = audin_send_open_reply_pdu(audin, callback, 0)))
503 WLog_Print(audin->log, WLOG_ERROR,
"audin_send_open_reply_pdu failed!");
513static UINT audin_process_format_change(AUDIN_PLUGIN* audin, AUDIN_CHANNEL_CALLBACK* callback,
516 UINT32 NewFormat = 0;
517 UINT error = CHANNEL_RC_OK;
519 if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
520 return ERROR_INVALID_DATA;
522 Stream_Read_UINT32(s, NewFormat);
523 WLog_Print(audin->log, WLOG_DEBUG,
"NewFormat=%" PRIu32
"", NewFormat);
525 if (NewFormat >= callback->formats_count)
527 WLog_Print(audin->log, WLOG_ERROR,
"invalid format index %" PRIu32
" (total %" PRIu32
")",
528 NewFormat, callback->formats_count);
529 return ERROR_INVALID_DATA;
532 audin->format = &callback->formats[NewFormat];
536 IFCALLRET(audin->device->Close, error, audin->device);
538 if (error != CHANNEL_RC_OK)
540 WLog_ERR(TAG,
"Close failed with errorcode %" PRIu32
"", error);
545 if (!audin_open_device(audin, callback))
546 return ERROR_INTERNAL_ERROR;
548 if ((error = audin_send_format_change_pdu(audin, callback, NewFormat)))
549 WLog_ERR(TAG,
"audin_send_format_change_pdu failed!");
559static UINT audin_on_data_received(IWTSVirtualChannelCallback* pChannelCallback,
wStream* data)
563 AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*)pChannelCallback;
565 if (!callback || !data)
566 return ERROR_INVALID_PARAMETER;
568 AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)callback->plugin;
571 return ERROR_INTERNAL_ERROR;
573 if (!Stream_CheckAndLogRequiredCapacity(TAG, data, 1))
574 return ERROR_NO_DATA;
576 Stream_Read_UINT8(data, MessageId);
577 WLog_Print(audin->log, WLOG_DEBUG,
"MessageId=0x%02" PRIx8
"", MessageId);
581 case MSG_SNDIN_VERSION:
582 error = audin_process_version(audin, callback, data);
585 case MSG_SNDIN_FORMATS:
586 error = audin_process_formats(audin, callback, data);
590 error = audin_process_open(audin, callback, data);
593 case MSG_SNDIN_FORMATCHANGE:
594 error = audin_process_format_change(audin, callback, data);
598 WLog_Print(audin->log, WLOG_ERROR,
"unknown MessageId=0x%02" PRIx8
"", MessageId);
599 error = ERROR_INVALID_DATA;
611static UINT audin_on_close(IWTSVirtualChannelCallback* pChannelCallback)
613 AUDIN_CHANNEL_CALLBACK* callback = (AUDIN_CHANNEL_CALLBACK*)pChannelCallback;
614 WINPR_ASSERT(callback);
616 AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)callback->plugin;
619 UINT error = CHANNEL_RC_OK;
620 WLog_Print(audin->log, WLOG_TRACE,
"...");
624 IFCALLRET(audin->device->Close, error, audin->device);
626 if (error != CHANNEL_RC_OK)
627 WLog_Print(audin->log, WLOG_ERROR,
"Close failed with errorcode %" PRIu32
"", error);
630 audin->format = NULL;
631 audio_formats_free(callback->formats, callback->formats_count);
641static UINT audin_on_new_channel_connection(IWTSListenerCallback* pListenerCallback,
642 IWTSVirtualChannel* pChannel,
643 WINPR_ATTR_UNUSED BYTE* Data,
644 WINPR_ATTR_UNUSED BOOL* pbAccept,
645 IWTSVirtualChannelCallback** ppCallback)
649 if (!listener_callback || !listener_callback->plugin)
650 return ERROR_INTERNAL_ERROR;
652 AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)listener_callback->plugin;
653 WLog_Print(audin->log, WLOG_TRACE,
"...");
654 AUDIN_CHANNEL_CALLBACK* callback =
655 (AUDIN_CHANNEL_CALLBACK*)calloc(1,
sizeof(AUDIN_CHANNEL_CALLBACK));
659 WLog_Print(audin->log, WLOG_ERROR,
"calloc failed!");
660 return CHANNEL_RC_NO_MEMORY;
663 callback->iface.OnDataReceived = audin_on_data_received;
664 callback->iface.OnClose = audin_on_close;
665 callback->plugin = listener_callback->plugin;
666 callback->channel_mgr = listener_callback->channel_mgr;
667 callback->channel = pChannel;
668 *ppCallback = (IWTSVirtualChannelCallback*)callback;
669 return CHANNEL_RC_OK;
677static UINT audin_plugin_initialize(IWTSPlugin* pPlugin, IWTSVirtualChannelManager* pChannelMgr)
679 AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pPlugin;
682 return CHANNEL_RC_BAD_CHANNEL_HANDLE;
685 return ERROR_INVALID_PARAMETER;
687 if (audin->initialized)
689 WLog_ERR(TAG,
"[%s] channel initialized twice, aborting", AUDIN_DVC_CHANNEL_NAME);
690 return ERROR_INVALID_DATA;
693 WLog_Print(audin->log, WLOG_TRACE,
"...");
694 audin->listener_callback =
697 if (!audin->listener_callback)
699 WLog_Print(audin->log, WLOG_ERROR,
"calloc failed!");
700 return CHANNEL_RC_NO_MEMORY;
703 audin->listener_callback->iface.OnNewChannelConnection = audin_on_new_channel_connection;
704 audin->listener_callback->plugin = pPlugin;
705 audin->listener_callback->channel_mgr = pChannelMgr;
706 const UINT rc = pChannelMgr->CreateListener(pChannelMgr, AUDIN_DVC_CHANNEL_NAME, 0,
707 &audin->listener_callback->iface, &audin->listener);
709 audin->initialized = rc == CHANNEL_RC_OK;
718static UINT audin_plugin_terminated(IWTSPlugin* pPlugin)
720 AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pPlugin;
721 UINT error = CHANNEL_RC_OK;
724 return CHANNEL_RC_BAD_CHANNEL_HANDLE;
726 WLog_Print(audin->log, WLOG_TRACE,
"...");
728 if (audin->listener_callback)
730 IWTSVirtualChannelManager* mgr = audin->listener_callback->channel_mgr;
732 IFCALL(mgr->DestroyListener, mgr, audin->listener);
734 audio_formats_free(audin->fixed_format, 1);
738 IFCALLRET(audin->device->Free, error, audin->device);
740 if (error != CHANNEL_RC_OK)
742 WLog_Print(audin->log, WLOG_ERROR,
"Free failed with errorcode %" PRIu32
"", error);
746 audin->device = NULL;
749 freerdp_dsp_context_free(audin->dsp_context);
750 Stream_Free(audin->data, TRUE);
751 free(audin->subsystem);
752 free(audin->device_name);
753 free(audin->listener_callback);
755 return CHANNEL_RC_OK;
758static UINT audin_plugin_attached(IWTSPlugin* pPlugin)
760 AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pPlugin;
761 UINT error = CHANNEL_RC_OK;
764 return CHANNEL_RC_BAD_CHANNEL_HANDLE;
766 audin->attached = TRUE;
770static UINT audin_plugin_detached(IWTSPlugin* pPlugin)
772 AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pPlugin;
773 UINT error = CHANNEL_RC_OK;
776 return CHANNEL_RC_BAD_CHANNEL_HANDLE;
778 audin->attached = FALSE;
787static UINT audin_register_device_plugin(IWTSPlugin* pPlugin, IAudinDevice* device)
789 AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pPlugin;
795 WLog_Print(audin->log, WLOG_ERROR,
"existing device, abort.");
796 return ERROR_ALREADY_EXISTS;
799 WLog_Print(audin->log, WLOG_DEBUG,
"device registered.");
800 audin->device = device;
801 return CHANNEL_RC_OK;
809static UINT audin_load_device_plugin(AUDIN_PLUGIN* audin,
const char* name,
const ADDIN_ARGV* args)
814 UINT error = ERROR_INTERNAL_ERROR;
816 PVIRTUALCHANNELENTRY pvce = freerdp_load_channel_addin_entry(AUDIN_CHANNEL_NAME, name, NULL, 0);
817 PFREERDP_AUDIN_DEVICE_ENTRY entry = WINPR_FUNC_PTR_CAST(pvce, PFREERDP_AUDIN_DEVICE_ENTRY);
821 WLog_Print(audin->log, WLOG_ERROR,
822 "freerdp_load_channel_addin_entry did not return any function pointers for %s ",
824 return ERROR_INVALID_FUNCTION;
827 entryPoints.plugin = &audin->iface;
828 entryPoints.pRegisterAudinDevice = audin_register_device_plugin;
829 entryPoints.args = args;
830 entryPoints.rdpcontext = audin->rdpcontext;
832 error = entry(&entryPoints);
835 WLog_Print(audin->log, WLOG_ERROR,
"%s entry returned error %" PRIu32
".", name, error);
839 WLog_Print(audin->log, WLOG_INFO,
"Loaded %s backend for audin", name);
840 return CHANNEL_RC_OK;
848static UINT audin_set_subsystem(AUDIN_PLUGIN* audin,
const char* subsystem)
852 free(audin->subsystem);
853 audin->subsystem = _strdup(subsystem);
855 if (!audin->subsystem)
857 WLog_Print(audin->log, WLOG_ERROR,
"_strdup failed!");
858 return ERROR_NOT_ENOUGH_MEMORY;
861 return CHANNEL_RC_OK;
869static UINT audin_set_device_name(AUDIN_PLUGIN* audin,
const char* device_name)
873 free(audin->device_name);
874 audin->device_name = _strdup(device_name);
876 if (!audin->device_name)
878 WLog_Print(audin->log, WLOG_ERROR,
"_strdup failed!");
879 return ERROR_NOT_ENOUGH_MEMORY;
882 return CHANNEL_RC_OK;
885BOOL audin_process_addin_args(AUDIN_PLUGIN* audin,
const ADDIN_ARGV* args)
888 {
"sys", COMMAND_LINE_VALUE_REQUIRED,
"<subsystem>", NULL, NULL, -1, NULL,
"subsystem" },
889 {
"dev", COMMAND_LINE_VALUE_REQUIRED,
"<device>", NULL, NULL, -1, NULL,
"device" },
890 {
"format", COMMAND_LINE_VALUE_REQUIRED,
"<format>", NULL, NULL, -1, NULL,
"format" },
891 {
"rate", COMMAND_LINE_VALUE_REQUIRED,
"<rate>", NULL, NULL, -1, NULL,
"rate" },
892 {
"channel", COMMAND_LINE_VALUE_REQUIRED,
"<channel>", NULL, NULL, -1, NULL,
"channel" },
893 { NULL, 0, NULL, NULL, NULL, -1, NULL, NULL }
896 if (!args || args->argc == 1)
900 COMMAND_LINE_SIGIL_NONE | COMMAND_LINE_SEPARATOR_COLON | COMMAND_LINE_IGN_UNKNOWN_KEYWORD;
902 CommandLineParseArgumentsA(args->argc, args->argv, audin_args, flags, audin, NULL, NULL);
912 if (!(arg->Flags & COMMAND_LINE_VALUE_PRESENT))
915 CommandLineSwitchStart(arg) CommandLineSwitchCase(arg,
"sys")
917 const UINT error = audin_set_subsystem(audin, arg->Value);
918 if (error != CHANNEL_RC_OK)
920 WLog_Print(audin->log, WLOG_ERROR,
921 "audin_set_subsystem failed with error %" PRIu32
"!", error);
925 CommandLineSwitchCase(arg,
"dev")
927 const UINT error = audin_set_device_name(audin, arg->Value);
928 if (error != CHANNEL_RC_OK)
930 WLog_Print(audin->log, WLOG_ERROR,
931 "audin_set_device_name failed with error %" PRIu32
"!", error);
935 CommandLineSwitchCase(arg,
"format")
937 unsigned long val = strtoul(arg->Value, NULL, 0);
939 if ((errno != 0) || (val > UINT16_MAX))
942 audin->fixed_format->wFormatTag = (UINT16)val;
944 CommandLineSwitchCase(arg,
"rate")
946 unsigned long val = strtoul(arg->Value, NULL, 0);
948 if ((errno != 0) || (val == 0) || (val > UINT32_MAX))
951 audin->fixed_format->nSamplesPerSec = (UINT32)val;
953 CommandLineSwitchCase(arg,
"channel")
955 unsigned long val = strtoul(arg->Value, NULL, 0);
957 if ((errno != 0) || (val <= UINT16_MAX))
958 audin->fixed_format->nChannels = (UINT16)val;
960 CommandLineSwitchDefault(arg)
963 CommandLineSwitchEnd(arg)
964 }
while ((arg = CommandLineFindNextArgumentA(arg)) != NULL);
974FREERDP_ENTRY_POINT(UINT VCAPITYPE audin_DVCPluginEntry(IDRDYNVC_ENTRY_POINTS* pEntryPoints))
976 struct SubsystemEntry
981 UINT error = CHANNEL_RC_INITIALIZATION_ERROR;
982 struct SubsystemEntry entries[] =
984#if defined(WITH_PULSE)
988 {
"oss",
"default" },
990#if defined(WITH_ALSA)
991 {
"alsa",
"default" },
993#if defined(WITH_OPENSLES)
994 {
"opensles",
"default" },
996#if defined(WITH_WINMM)
997 {
"winmm",
"default" },
999#if defined(WITH_MACAUDIO)
1000 {
"mac",
"default" },
1002#if defined(WITH_IOSAUDIO)
1003 {
"ios",
"default" },
1005#if defined(WITH_SNDIO)
1006 {
"sndio",
"default" },
1010 struct SubsystemEntry* entry = &entries[0];
1011 WINPR_ASSERT(pEntryPoints);
1012 WINPR_ASSERT(pEntryPoints->GetPlugin);
1013 AUDIN_PLUGIN* audin = (AUDIN_PLUGIN*)pEntryPoints->GetPlugin(pEntryPoints, AUDIN_CHANNEL_NAME);
1016 return CHANNEL_RC_ALREADY_INITIALIZED;
1018 audin = (AUDIN_PLUGIN*)calloc(1,
sizeof(AUDIN_PLUGIN));
1022 WLog_ERR(TAG,
"calloc failed!");
1023 return CHANNEL_RC_NO_MEMORY;
1026 audin->log = WLog_Get(TAG);
1027 audin->data = Stream_New(NULL, 4096);
1028 audin->fixed_format = audio_format_new();
1030 if (!audin->fixed_format)
1036 audin->dsp_context = freerdp_dsp_context_new(TRUE);
1038 if (!audin->dsp_context)
1041 audin->attached = TRUE;
1042 audin->iface.Initialize = audin_plugin_initialize;
1043 audin->iface.Connected = NULL;
1044 audin->iface.Disconnected = NULL;
1045 audin->iface.Terminated = audin_plugin_terminated;
1046 audin->iface.Attached = audin_plugin_attached;
1047 audin->iface.Detached = audin_plugin_detached;
1049 const ADDIN_ARGV* args = pEntryPoints->GetPluginData(pEntryPoints);
1050 audin->rdpcontext = pEntryPoints->GetRdpContext(pEntryPoints);
1054 if (!audin_process_addin_args(audin, args))
1058 if (audin->subsystem)
1060 if ((error = audin_load_device_plugin(audin, audin->subsystem, args)))
1063 audin->log, WLOG_ERROR,
1064 "Unable to load microphone redirection subsystem %s because of error %" PRIu32
"",
1065 audin->subsystem, error);
1071 while (entry && entry->subsystem && !audin->device)
1073 if ((error = audin_set_subsystem(audin, entry->subsystem)))
1075 WLog_Print(audin->log, WLOG_ERROR,
1076 "audin_set_subsystem for %s failed with error %" PRIu32
"!",
1077 entry->subsystem, error);
1079 else if ((error = audin_set_device_name(audin, entry->device)))
1081 WLog_Print(audin->log, WLOG_ERROR,
1082 "audin_set_device_name for %s failed with error %" PRIu32
"!",
1083 entry->subsystem, error);
1085 else if ((error = audin_load_device_plugin(audin, audin->subsystem, args)))
1087 WLog_Print(audin->log, WLOG_ERROR,
1088 "audin_load_device_plugin %s failed with error %" PRIu32
"!",
1089 entry->subsystem, error);
1096 if (audin->device == NULL)
1100 WLog_Print(audin->log, WLOG_ERROR,
"No microphone device could be found.");
1101 error = CHANNEL_RC_OK;
1105 error = pEntryPoints->RegisterPlugin(pEntryPoints, AUDIN_CHANNEL_NAME, &audin->iface);
1106 if (error == CHANNEL_RC_OK)
1110 audin_plugin_terminated(&audin->iface);