23#include <freerdp/config.h>
26#include <winpr/assert.h>
27#include <winpr/synch.h>
28#include <winpr/thread.h>
29#include <winpr/stream.h>
31#include <freerdp/freerdp.h>
32#include <freerdp/server/server-common.h>
33#include <freerdp/server/audin.h>
34#include <freerdp/channels/log.h>
36#define AUDIN_TAG CHANNELS_TAG("audin.server")
38#define SNDIN_HEADER_SIZE 1
42 MSG_SNDIN_VERSION = 0x01,
43 MSG_SNDIN_FORMATS = 0x02,
44 MSG_SNDIN_OPEN = 0x03,
45 MSG_SNDIN_OPEN_REPLY = 0x04,
46 MSG_SNDIN_DATA_INCOMING = 0x05,
47 MSG_SNDIN_DATA = 0x06,
48 MSG_SNDIN_FORMATCHANGE = 0x07,
53 audin_server_context context;
63 UINT32 audin_n_server_formats;
65 UINT32 audin_client_format_idx;
69static UINT audin_server_recv_version(audin_server_context* context,
wStream* s,
72 audin_server* audin = (audin_server*)context;
74 UINT error = CHANNEL_RC_OK;
76 WINPR_ASSERT(context);
81 if (!Stream_CheckAndLogRequiredLengthWLog(audin->log, s, 4))
85 const UINT32 version = Stream_Get_UINT32(s);
88 case SNDIN_VERSION_Version_1:
89 pdu.Version = SNDIN_VERSION_Version_1;
91 case SNDIN_VERSION_Version_2:
92 pdu.Version = SNDIN_VERSION_Version_2;
95 pdu.Version = SNDIN_VERSION_Version_2;
96 WLog_Print(audin->log, WLOG_WARN,
97 "Received unsupported channel version %" PRIu32
98 ", using highest supported version %u",
99 version, pdu.Version);
104 IFCALLRET(context->ReceiveVersion, error, context, &pdu);
106 WLog_Print(audin->log, WLOG_ERROR,
"context->ReceiveVersion failed with error %" PRIu32
"",
112static UINT audin_server_recv_formats(audin_server_context* context,
wStream* s,
115 audin_server* audin = (audin_server*)context;
117 UINT error = CHANNEL_RC_OK;
119 WINPR_ASSERT(context);
120 WINPR_ASSERT(header);
122 pdu.Header = *header;
125 if (!Stream_CheckAndLogRequiredLengthWLog(audin->log, s, 4 + 4 + 18))
126 return ERROR_NO_DATA;
128 Stream_Read_UINT32(s, pdu.NumFormats);
129 Stream_Read_UINT32(s, pdu.cbSizeFormatsPacket);
131 if (pdu.NumFormats == 0)
133 WLog_Print(audin->log, WLOG_ERROR,
"Sound Formats PDU contains no formats");
134 return ERROR_INVALID_DATA;
138 if (!Stream_CheckAndLogRequiredCapacityOfSizeWLog(audin->log, s, pdu.NumFormats,
140 return ERROR_INVALID_DATA;
142 if (pdu.NumFormats > 512)
144 WLog_Print(audin->log, WLOG_ERROR,
145 "Sound Formats PDU contains %" PRIu32
" formats, implausible so discarding",
147 return ERROR_INVALID_DATA;
150 pdu.SoundFormats = audio_formats_new(pdu.NumFormats);
151 if (!pdu.SoundFormats)
153 WLog_Print(audin->log, WLOG_ERROR,
"Failed to allocate %u SoundFormats", pdu.NumFormats);
154 return ERROR_NOT_ENOUGH_MEMORY;
157 for (UINT32 i = 0; i < pdu.NumFormats; ++i)
161 if (!audio_format_read(s, format))
163 WLog_Print(audin->log, WLOG_ERROR,
"Failed to read audio format");
164 error = ERROR_INVALID_DATA;
168 audio_format_print(audin->log, WLOG_DEBUG, format);
171 if (pdu.cbSizeFormatsPacket != Stream_GetPosition(s))
173 WLog_Print(audin->log, WLOG_WARN,
174 "cbSizeFormatsPacket is invalid! Expected: %u Got: %zu. Fixing size",
175 pdu.cbSizeFormatsPacket, Stream_GetPosition(s));
176 const size_t pos = Stream_GetPosition(s);
177 if (pos > UINT32_MAX)
179 WLog_Print(audin->log, WLOG_ERROR,
"Stream too long, %" PRIuz
" exceeds UINT32_MAX",
181 error = ERROR_INVALID_PARAMETER;
184 pdu.cbSizeFormatsPacket = (UINT32)pos;
187 pdu.ExtraDataSize = Stream_GetRemainingLength(s);
189 IFCALLRET(context->ReceiveFormats, error, context, &pdu);
191 WLog_Print(audin->log, WLOG_ERROR,
"context->ReceiveFormats failed with error %" PRIu32
"",
195 audio_formats_free(pdu.SoundFormats, pdu.NumFormats);
200static UINT audin_server_recv_open_reply(audin_server_context* context,
wStream* s,
203 audin_server* audin = (audin_server*)context;
205 UINT error = CHANNEL_RC_OK;
207 WINPR_ASSERT(context);
208 WINPR_ASSERT(header);
210 pdu.Header = *header;
212 if (!Stream_CheckAndLogRequiredLengthWLog(audin->log, s, 4))
213 return ERROR_NO_DATA;
215 Stream_Read_UINT32(s, pdu.Result);
217 IFCALLRET(context->OpenReply, error, context, &pdu);
219 WLog_Print(audin->log, WLOG_ERROR,
"context->OpenReply failed with error %" PRIu32
"",
225static UINT audin_server_recv_data_incoming(audin_server_context* context,
228 audin_server* audin = (audin_server*)context;
230 UINT error = CHANNEL_RC_OK;
232 WINPR_ASSERT(context);
233 WINPR_ASSERT(header);
235 pdu.Header = *header;
237 IFCALLRET(context->IncomingData, error, context, &pdu);
239 WLog_Print(audin->log, WLOG_ERROR,
"context->IncomingData failed with error %" PRIu32
"",
245static UINT audin_server_recv_data(audin_server_context* context,
wStream* s,
248 audin_server* audin = (audin_server*)context;
250 wStream dataBuffer = WINPR_C_ARRAY_INIT;
251 UINT error = CHANNEL_RC_OK;
253 WINPR_ASSERT(context);
254 WINPR_ASSERT(header);
256 pdu.Header = *header;
258 pdu.Data = Stream_StaticInit(&dataBuffer, Stream_Pointer(s), Stream_GetRemainingLength(s));
260 IFCALLRET(context->Data, error, context, &pdu);
262 WLog_Print(audin->log, WLOG_ERROR,
"context->Data failed with error %" PRIu32
"", error);
267static UINT audin_server_recv_format_change(audin_server_context* context,
wStream* s,
270 audin_server* audin = (audin_server*)context;
272 UINT error = CHANNEL_RC_OK;
274 WINPR_ASSERT(context);
275 WINPR_ASSERT(header);
277 pdu.Header = *header;
279 if (!Stream_CheckAndLogRequiredLengthWLog(audin->log, s, 4))
280 return ERROR_NO_DATA;
282 Stream_Read_UINT32(s, pdu.NewFormat);
284 IFCALLRET(context->ReceiveFormatChange, error, context, &pdu);
286 WLog_Print(audin->log, WLOG_ERROR,
287 "context->ReceiveFormatChange failed with error %" PRIu32
"", error);
292static DWORD WINAPI audin_server_thread_func(LPVOID arg)
295 void* buffer =
nullptr;
297 HANDLE events[8] = WINPR_C_ARRAY_INIT;
299 HANDLE ChannelEvent =
nullptr;
300 DWORD BytesReturned = 0;
301 audin_server* audin = (audin_server*)arg;
302 UINT error = CHANNEL_RC_OK;
303 DWORD status = ERROR_INTERNAL_ERROR;
307 if (WTSVirtualChannelQuery(audin->audin_channel, WTSVirtualEventHandle, &buffer,
308 &BytesReturned) == TRUE)
310 if (BytesReturned ==
sizeof(HANDLE))
311 ChannelEvent = *(HANDLE*)buffer;
313 WTSFreeMemory(buffer);
317 WLog_Print(audin->log, WLOG_ERROR,
"WTSVirtualChannelQuery failed");
318 error = ERROR_INTERNAL_ERROR;
323 events[nCount++] = audin->stopEvent;
324 events[nCount++] = ChannelEvent;
330 status = WaitForMultipleObjects(nCount, events, FALSE, 100);
332 if (status == WAIT_FAILED)
334 error = GetLastError();
335 WLog_Print(audin->log, WLOG_ERROR,
336 "WaitForMultipleObjects failed with error %" PRIu32
"", error);
339 if (status == WAIT_OBJECT_0)
342 if (WTSVirtualChannelQuery(audin->audin_channel, WTSVirtualChannelReady, &buffer,
343 &BytesReturned) == FALSE)
345 WLog_Print(audin->log, WLOG_ERROR,
"WTSVirtualChannelQuery failed");
346 error = ERROR_INTERNAL_ERROR;
350 ready = *((BOOL*)buffer);
351 WTSFreeMemory(buffer);
357 s = Stream_New(
nullptr, 4096);
361 WLog_Print(audin->log, WLOG_ERROR,
"Stream_New failed!");
362 error = CHANNEL_RC_NO_MEMORY;
370 version.Version = audin->context.serverVersion;
372 if ((error = audin->context.SendVersion(&audin->context, &version)))
374 WLog_Print(audin->log, WLOG_ERROR,
"SendVersion failed with error %" PRIu32
"!", error);
383 if ((status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE)) == WAIT_OBJECT_0)
386 if (status == WAIT_FAILED)
388 error = GetLastError();
389 WLog_Print(audin->log, WLOG_ERROR,
390 "WaitForMultipleObjects failed with error %" PRIu32
"", error);
393 if (status == WAIT_OBJECT_0)
396 Stream_ResetPosition(s);
398 if (!WTSVirtualChannelRead(audin->audin_channel, 0,
nullptr, 0, &BytesReturned))
400 WLog_Print(audin->log, WLOG_ERROR,
"WTSVirtualChannelRead failed!");
401 error = ERROR_INTERNAL_ERROR;
405 if (BytesReturned < 1)
408 if (!Stream_EnsureRemainingCapacity(s, BytesReturned))
411 const ULONG len = WINPR_ASSERTING_INT_CAST(ULONG, Stream_Capacity(s));
412 if (WTSVirtualChannelRead(audin->audin_channel, 0, Stream_BufferAs(s,
char), len,
413 &BytesReturned) == FALSE)
415 WLog_Print(audin->log, WLOG_ERROR,
"WTSVirtualChannelRead failed!");
416 error = ERROR_INTERNAL_ERROR;
420 if (BytesReturned > len)
422 WLog_Print(audin->log, WLOG_ERROR,
423 "WTSVirtualChannelRead returned an invalid length, got %" PRIu32
424 ", but limit is %" PRIu32,
426 error = ERROR_INTERNAL_ERROR;
430 if (!Stream_SetLength(s, BytesReturned))
432 error = ERROR_INTERNAL_ERROR;
436 if (!Stream_CheckAndLogRequiredLengthWLog(audin->log, s, SNDIN_HEADER_SIZE))
438 error = ERROR_INTERNAL_ERROR;
442 Stream_Read_UINT8(s, header.MessageId);
444 switch (header.MessageId)
446 case MSG_SNDIN_VERSION:
447 error = audin_server_recv_version(&audin->context, s, &header);
449 case MSG_SNDIN_FORMATS:
450 error = audin_server_recv_formats(&audin->context, s, &header);
452 case MSG_SNDIN_OPEN_REPLY:
453 error = audin_server_recv_open_reply(&audin->context, s, &header);
455 case MSG_SNDIN_DATA_INCOMING:
456 error = audin_server_recv_data_incoming(&audin->context, s, &header);
459 error = audin_server_recv_data(&audin->context, s, &header);
461 case MSG_SNDIN_FORMATCHANGE:
462 error = audin_server_recv_format_change(&audin->context, s, &header);
465 WLog_Print(audin->log, WLOG_ERROR,
466 "audin_server_thread_func: unknown or invalid MessageId %" PRIu8
"",
468 error = ERROR_INVALID_DATA;
476 Stream_Free(s, TRUE);
478 (void)WTSVirtualChannelClose(audin->audin_channel);
479 audin->audin_channel =
nullptr;
481 if (error && audin->context.rdpcontext)
482 setChannelError(audin->context.rdpcontext, error,
483 "audin_server_thread_func reported an error");
489static BOOL audin_server_open(audin_server_context* context)
491 audin_server* audin = (audin_server*)context;
496 PULONG pSessionId =
nullptr;
497 DWORD BytesReturned = 0;
498 audin->SessionId = WTS_CURRENT_SESSION;
499 UINT32 channelId = 0;
502 if (WTSQuerySessionInformationA(context->vcm, WTS_CURRENT_SESSION, WTSSessionId,
503 (LPSTR*)&pSessionId, &BytesReturned))
505 audin->SessionId = (DWORD)*pSessionId;
506 WTSFreeMemory(pSessionId);
509 audin->audin_channel = WTSVirtualChannelOpenEx(audin->SessionId, AUDIN_DVC_CHANNEL_NAME,
510 WTS_CHANNEL_OPTION_DYNAMIC);
512 if (!audin->audin_channel)
514 WLog_Print(audin->log, WLOG_ERROR,
"WTSVirtualChannelOpenEx failed!");
518 channelId = WTSChannelGetIdByHandle(audin->audin_channel);
520 IFCALLRET(context->ChannelIdAssigned, status, context, channelId);
523 WLog_Print(audin->log, WLOG_ERROR,
"context->ChannelIdAssigned failed!");
527 if (!(audin->stopEvent = CreateEvent(
nullptr, TRUE, FALSE,
nullptr)))
529 WLog_Print(audin->log, WLOG_ERROR,
"CreateEvent failed!");
533 if (!(audin->thread =
534 CreateThread(
nullptr, 0, audin_server_thread_func, (
void*)audin, 0,
nullptr)))
536 WLog_Print(audin->log, WLOG_ERROR,
"CreateThread failed!");
537 (void)CloseHandle(audin->stopEvent);
538 audin->stopEvent =
nullptr;
545 WLog_Print(audin->log, WLOG_ERROR,
"thread already running!");
549static BOOL audin_server_is_open(audin_server_context* context)
551 audin_server* audin = (audin_server*)context;
554 return audin->thread !=
nullptr;
557static BOOL audin_server_close(audin_server_context* context)
559 audin_server* audin = (audin_server*)context;
564 (void)SetEvent(audin->stopEvent);
566 if (WaitForSingleObject(audin->thread, INFINITE) == WAIT_FAILED)
568 WLog_Print(audin->log, WLOG_ERROR,
"WaitForSingleObject failed with error %" PRIu32
"",
573 (void)CloseHandle(audin->thread);
574 (void)CloseHandle(audin->stopEvent);
575 audin->thread =
nullptr;
576 audin->stopEvent =
nullptr;
579 if (audin->audin_channel)
581 (void)WTSVirtualChannelClose(audin->audin_channel);
582 audin->audin_channel =
nullptr;
585 audin->audin_negotiated_format =
nullptr;
590static wStream* audin_server_packet_new(wLog* log,
size_t size, BYTE MessageId)
595 wStream* s = Stream_New(
nullptr, size + SNDIN_HEADER_SIZE);
598 WLog_Print(log, WLOG_ERROR,
"Stream_New failed!");
602 Stream_Write_UINT8(s, MessageId);
607static UINT audin_server_packet_send(audin_server_context* context,
wStream* s)
609 audin_server* audin = (audin_server*)context;
610 UINT error = CHANNEL_RC_OK;
613 WINPR_ASSERT(context);
616 const size_t pos = Stream_GetPosition(s);
617 WINPR_ASSERT(pos <= UINT32_MAX);
618 if (!WTSVirtualChannelWrite(audin->audin_channel, Stream_BufferAs(s,
char), (UINT32)pos,
621 WLog_Print(audin->log, WLOG_ERROR,
"WTSVirtualChannelWrite failed!");
622 error = ERROR_INTERNAL_ERROR;
626 if (written < Stream_GetPosition(s))
628 WLog_Print(audin->log, WLOG_WARN,
"Unexpected bytes written: %" PRIu32
"/%" PRIuz
"",
629 written, Stream_GetPosition(s));
633 Stream_Free(s, TRUE);
637static UINT audin_server_send_version(audin_server_context* context,
const SNDIN_VERSION* version)
639 audin_server* audin = (audin_server*)context;
641 WINPR_ASSERT(context);
642 WINPR_ASSERT(version);
644 wStream* s = audin_server_packet_new(audin->log, 4, MSG_SNDIN_VERSION);
646 return ERROR_NOT_ENOUGH_MEMORY;
648 Stream_Write_UINT32(s, version->Version);
650 return audin_server_packet_send(context, s);
653static UINT audin_server_send_formats(audin_server_context* context,
const SNDIN_FORMATS* formats)
655 audin_server* audin = (audin_server*)context;
658 WINPR_ASSERT(formats);
660 wStream* s = audin_server_packet_new(audin->log, 4 + 4 + 18, MSG_SNDIN_FORMATS);
662 return ERROR_NOT_ENOUGH_MEMORY;
664 Stream_Write_UINT32(s, formats->NumFormats);
665 Stream_Write_UINT32(s, formats->cbSizeFormatsPacket);
667 for (UINT32 i = 0; i < formats->NumFormats; ++i)
671 if (!audio_format_write(s, format))
673 WLog_Print(audin->log, WLOG_ERROR,
"Failed to write audio format");
674 Stream_Free(s, TRUE);
675 return CHANNEL_RC_NO_MEMORY;
679 return audin_server_packet_send(context, s);
682static UINT audin_server_send_open(audin_server_context* context,
const SNDIN_OPEN* open)
684 audin_server* audin = (audin_server*)context;
688 wStream* s = audin_server_packet_new(audin->log, 4 + 4 + 18 + 22, MSG_SNDIN_OPEN);
690 return ERROR_NOT_ENOUGH_MEMORY;
692 Stream_Write_UINT32(s, open->FramesPerPacket);
693 Stream_Write_UINT32(s, open->initialFormat);
695 Stream_Write_UINT16(s, open->captureFormat.wFormatTag);
696 Stream_Write_UINT16(s, open->captureFormat.nChannels);
697 Stream_Write_UINT32(s, open->captureFormat.nSamplesPerSec);
698 Stream_Write_UINT32(s, open->captureFormat.nAvgBytesPerSec);
699 Stream_Write_UINT16(s, open->captureFormat.nBlockAlign);
700 Stream_Write_UINT16(s, open->captureFormat.wBitsPerSample);
702 if (open->ExtraFormatData)
704 Stream_Write_UINT16(s, 22);
706 Stream_Write_UINT16(s, open->ExtraFormatData->Samples.wReserved);
707 Stream_Write_UINT32(s, open->ExtraFormatData->dwChannelMask);
709 Stream_Write_UINT32(s, open->ExtraFormatData->SubFormat.Data1);
710 Stream_Write_UINT16(s, open->ExtraFormatData->SubFormat.Data2);
711 Stream_Write_UINT16(s, open->ExtraFormatData->SubFormat.Data3);
712 Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[0]);
713 Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[1]);
714 Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[2]);
715 Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[3]);
716 Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[4]);
717 Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[5]);
718 Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[6]);
719 Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[7]);
723 WINPR_ASSERT(open->captureFormat.wFormatTag != WAVE_FORMAT_EXTENSIBLE);
725 Stream_Write_UINT16(s, 0);
728 return audin_server_packet_send(context, s);
731static UINT audin_server_send_format_change(audin_server_context* context,
734 audin_server* audin = (audin_server*)context;
736 WINPR_ASSERT(context);
737 WINPR_ASSERT(format_change);
739 wStream* s = audin_server_packet_new(audin->log, 4, MSG_SNDIN_FORMATCHANGE);
741 return ERROR_NOT_ENOUGH_MEMORY;
743 Stream_Write_UINT32(s, format_change->NewFormat);
745 return audin_server_packet_send(context, s);
748static UINT audin_server_receive_version_default(audin_server_context* audin_ctx,
751 audin_server* audin = (audin_server*)audin_ctx;
755 WINPR_ASSERT(version);
757 if (version->Version == 0)
759 WLog_Print(audin->log, WLOG_ERROR,
"Received invalid AUDIO_INPUT version from client");
760 return ERROR_INVALID_DATA;
763 WLog_Print(audin->log, WLOG_DEBUG,
"AUDIO_INPUT version of client: %u", version->Version);
765 formats.NumFormats = audin->audin_n_server_formats;
766 formats.SoundFormats = audin->audin_server_formats;
768 return audin->context.SendFormats(&audin->context, &formats);
771static UINT send_open(audin_server* audin)
777 open.FramesPerPacket = 441;
778 open.initialFormat = audin->audin_client_format_idx;
779 open.captureFormat.wFormatTag = WAVE_FORMAT_PCM;
780 open.captureFormat.nChannels = 2;
781 open.captureFormat.nSamplesPerSec = 44100;
782 open.captureFormat.nAvgBytesPerSec = 44100 * 2 * 2;
783 open.captureFormat.nBlockAlign = 4;
784 open.captureFormat.wBitsPerSample = 16;
786 WINPR_ASSERT(audin->context.SendOpen);
787 return audin->context.SendOpen(&audin->context, &open);
790static UINT audin_server_receive_formats_default(audin_server_context* context,
793 audin_server* audin = (audin_server*)context;
795 WINPR_ASSERT(formats);
797 if (audin->audin_negotiated_format)
799 WLog_Print(audin->log, WLOG_ERROR,
800 "Received client formats, but negotiation was already done");
801 return ERROR_INVALID_DATA;
804 for (UINT32 i = 0; i < audin->audin_n_server_formats; ++i)
806 for (UINT32 j = 0; j < formats->NumFormats; ++j)
808 if (audio_format_compatible(&audin->audin_server_formats[i], &formats->SoundFormats[j]))
810 audin->audin_negotiated_format = &audin->audin_server_formats[i];
811 audin->audin_client_format_idx = i;
812 return send_open(audin);
817 WLog_Print(audin->log, WLOG_ERROR,
"Could not agree on a audio format with the server");
819 return ERROR_INVALID_DATA;
822static UINT audin_server_receive_format_change_default(audin_server_context* context,
825 audin_server* audin = (audin_server*)context;
828 WINPR_ASSERT(format_change);
830 if (format_change->NewFormat != audin->audin_client_format_idx)
832 WLog_Print(audin->log, WLOG_ERROR,
833 "NewFormat in FormatChange differs from requested format");
834 return ERROR_INVALID_DATA;
837 WLog_Print(audin->log, WLOG_DEBUG,
"Received Format Change PDU: %u", format_change->NewFormat);
839 return CHANNEL_RC_OK;
843audin_server_incoming_data_default(audin_server_context* context,
846 audin_server* audin = (audin_server*)context;
848 WINPR_ASSERT(data_incoming);
851 WLog_Print(audin->log, WLOG_DEBUG,
"Received Incoming Data PDU");
852 return CHANNEL_RC_OK;
855static UINT audin_server_open_reply_default(audin_server_context* context,
858 audin_server* audin = (audin_server*)context;
860 WINPR_ASSERT(open_reply);
863 WLog_Print(audin->log, WLOG_DEBUG,
"Open Reply PDU: Result: %" PRIu32, open_reply->Result);
864 return CHANNEL_RC_OK;
867audin_server_context* audin_server_context_new(HANDLE vcm)
869 audin_server* audin = (audin_server*)calloc(1,
sizeof(audin_server));
873 WLog_ERR(AUDIN_TAG,
"calloc failed!");
876 audin->log = WLog_Get(AUDIN_TAG);
877 audin->context.vcm = vcm;
878 audin->context.Open = audin_server_open;
879 audin->context.IsOpen = audin_server_is_open;
880 audin->context.Close = audin_server_close;
882 audin->context.SendVersion = audin_server_send_version;
883 audin->context.SendFormats = audin_server_send_formats;
884 audin->context.SendOpen = audin_server_send_open;
885 audin->context.SendFormatChange = audin_server_send_format_change;
888 audin->context.serverVersion = SNDIN_VERSION_Version_2;
889 audin->context.ReceiveVersion = audin_server_receive_version_default;
890 audin->context.ReceiveFormats = audin_server_receive_formats_default;
891 audin->context.ReceiveFormatChange = audin_server_receive_format_change_default;
892 audin->context.IncomingData = audin_server_incoming_data_default;
893 audin->context.OpenReply = audin_server_open_reply_default;
895 return &audin->context;
898void audin_server_context_free(audin_server_context* context)
900 audin_server* audin = (audin_server*)context;
905 audin_server_close(context);
906 audio_formats_free(audin->audin_server_formats, audin->audin_n_server_formats);
907 audin->audin_server_formats =
nullptr;
911BOOL audin_server_set_formats(audin_server_context* context, SSIZE_T count,
914 audin_server* audin = (audin_server*)context;
917 audio_formats_free(audin->audin_server_formats, audin->audin_n_server_formats);
918 audin->audin_n_server_formats = 0;
919 audin->audin_server_formats =
nullptr;
920 audin->audin_negotiated_format =
nullptr;
924 const size_t audin_n_server_formats =
925 server_audin_get_formats(&audin->audin_server_formats);
926 WINPR_ASSERT(audin_n_server_formats <= UINT32_MAX);
928 audin->audin_n_server_formats = (UINT32)audin_n_server_formats;
932 const size_t scount = (size_t)count;
933 AUDIO_FORMAT* audin_server_formats = audio_formats_new(scount);
934 if (!audin_server_formats)
937 for (SSIZE_T x = 0; x < count; x++)
939 if (!audio_format_copy(&formats[x], &audin_server_formats[x]))
941 audio_formats_free(audin_server_formats, scount);
946 WINPR_ASSERT(count <= UINT32_MAX);
947 audin->audin_server_formats = audin_server_formats;
948 audin->audin_n_server_formats = (UINT32)count;
950 return audin->audin_n_server_formats > 0;
953const AUDIO_FORMAT* audin_server_get_negotiated_format(
const audin_server_context* context)
955 const audin_server* audin = (
const audin_server*)context;
958 return audin->audin_negotiated_format;