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;
137 pdu.SoundFormats = audio_formats_new(pdu.NumFormats);
138 if (!pdu.SoundFormats)
140 WLog_Print(audin->log, WLOG_ERROR,
"Failed to allocate %u SoundFormats", pdu.NumFormats);
141 return ERROR_NOT_ENOUGH_MEMORY;
144 for (UINT32 i = 0; i < pdu.NumFormats; ++i)
148 if (!audio_format_read(s, format))
150 WLog_Print(audin->log, WLOG_ERROR,
"Failed to read audio format");
151 audio_formats_free(pdu.SoundFormats, i + i);
152 return ERROR_INVALID_DATA;
155 audio_format_print(audin->log, WLOG_DEBUG, format);
158 if (pdu.cbSizeFormatsPacket != Stream_GetPosition(s))
160 WLog_Print(audin->log, WLOG_WARN,
161 "cbSizeFormatsPacket is invalid! Expected: %u Got: %zu. Fixing size",
162 pdu.cbSizeFormatsPacket, Stream_GetPosition(s));
163 const size_t pos = Stream_GetPosition(s);
164 if (pos > UINT32_MAX)
166 WLog_Print(audin->log, WLOG_ERROR,
"Stream too long, %" PRIuz
" exceeds UINT32_MAX",
168 error = ERROR_INVALID_PARAMETER;
171 pdu.cbSizeFormatsPacket = (UINT32)pos;
174 pdu.ExtraDataSize = Stream_GetRemainingLength(s);
176 IFCALLRET(context->ReceiveFormats, error, context, &pdu);
178 WLog_Print(audin->log, WLOG_ERROR,
"context->ReceiveFormats failed with error %" PRIu32
"",
182 audio_formats_free(pdu.SoundFormats, pdu.NumFormats);
187static UINT audin_server_recv_open_reply(audin_server_context* context,
wStream* s,
190 audin_server* audin = (audin_server*)context;
192 UINT error = CHANNEL_RC_OK;
194 WINPR_ASSERT(context);
195 WINPR_ASSERT(header);
197 pdu.Header = *header;
199 if (!Stream_CheckAndLogRequiredLengthWLog(audin->log, s, 4))
200 return ERROR_NO_DATA;
202 Stream_Read_UINT32(s, pdu.Result);
204 IFCALLRET(context->OpenReply, error, context, &pdu);
206 WLog_Print(audin->log, WLOG_ERROR,
"context->OpenReply failed with error %" PRIu32
"",
212static UINT audin_server_recv_data_incoming(audin_server_context* context,
215 audin_server* audin = (audin_server*)context;
217 UINT error = CHANNEL_RC_OK;
219 WINPR_ASSERT(context);
220 WINPR_ASSERT(header);
222 pdu.Header = *header;
224 IFCALLRET(context->IncomingData, error, context, &pdu);
226 WLog_Print(audin->log, WLOG_ERROR,
"context->IncomingData failed with error %" PRIu32
"",
232static UINT audin_server_recv_data(audin_server_context* context,
wStream* s,
235 audin_server* audin = (audin_server*)context;
238 UINT error = CHANNEL_RC_OK;
240 WINPR_ASSERT(context);
241 WINPR_ASSERT(header);
243 pdu.Header = *header;
245 pdu.Data = Stream_StaticInit(&dataBuffer, Stream_Pointer(s), Stream_GetRemainingLength(s));
247 IFCALLRET(context->Data, error, context, &pdu);
249 WLog_Print(audin->log, WLOG_ERROR,
"context->Data failed with error %" PRIu32
"", error);
254static UINT audin_server_recv_format_change(audin_server_context* context,
wStream* s,
257 audin_server* audin = (audin_server*)context;
259 UINT error = CHANNEL_RC_OK;
261 WINPR_ASSERT(context);
262 WINPR_ASSERT(header);
264 pdu.Header = *header;
266 if (!Stream_CheckAndLogRequiredLengthWLog(audin->log, s, 4))
267 return ERROR_NO_DATA;
269 Stream_Read_UINT32(s, pdu.NewFormat);
271 IFCALLRET(context->ReceiveFormatChange, error, context, &pdu);
273 WLog_Print(audin->log, WLOG_ERROR,
274 "context->ReceiveFormatChange failed with error %" PRIu32
"", error);
279static DWORD WINAPI audin_server_thread_func(LPVOID arg)
284 HANDLE events[8] = { 0 };
286 HANDLE ChannelEvent = NULL;
287 DWORD BytesReturned = 0;
288 audin_server* audin = (audin_server*)arg;
289 UINT error = CHANNEL_RC_OK;
290 DWORD status = ERROR_INTERNAL_ERROR;
294 if (WTSVirtualChannelQuery(audin->audin_channel, WTSVirtualEventHandle, &buffer,
295 &BytesReturned) == TRUE)
297 if (BytesReturned ==
sizeof(HANDLE))
298 ChannelEvent = *(HANDLE*)buffer;
300 WTSFreeMemory(buffer);
304 WLog_Print(audin->log, WLOG_ERROR,
"WTSVirtualChannelQuery failed");
305 error = ERROR_INTERNAL_ERROR;
310 events[nCount++] = audin->stopEvent;
311 events[nCount++] = ChannelEvent;
317 status = WaitForMultipleObjects(nCount, events, FALSE, 100);
319 if (status == WAIT_FAILED)
321 error = GetLastError();
322 WLog_Print(audin->log, WLOG_ERROR,
323 "WaitForMultipleObjects failed with error %" PRIu32
"", error);
326 if (status == WAIT_OBJECT_0)
329 if (WTSVirtualChannelQuery(audin->audin_channel, WTSVirtualChannelReady, &buffer,
330 &BytesReturned) == FALSE)
332 WLog_Print(audin->log, WLOG_ERROR,
"WTSVirtualChannelQuery failed");
333 error = ERROR_INTERNAL_ERROR;
337 ready = *((BOOL*)buffer);
338 WTSFreeMemory(buffer);
344 s = Stream_New(NULL, 4096);
348 WLog_Print(audin->log, WLOG_ERROR,
"Stream_New failed!");
349 error = CHANNEL_RC_NO_MEMORY;
357 version.Version = audin->context.serverVersion;
359 if ((error = audin->context.SendVersion(&audin->context, &version)))
361 WLog_Print(audin->log, WLOG_ERROR,
"SendVersion failed with error %" PRIu32
"!", error);
370 if ((status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE)) == WAIT_OBJECT_0)
373 if (status == WAIT_FAILED)
375 error = GetLastError();
376 WLog_Print(audin->log, WLOG_ERROR,
377 "WaitForMultipleObjects failed with error %" PRIu32
"", error);
380 if (status == WAIT_OBJECT_0)
383 Stream_SetPosition(s, 0);
385 if (!WTSVirtualChannelRead(audin->audin_channel, 0, NULL, 0, &BytesReturned))
387 WLog_Print(audin->log, WLOG_ERROR,
"WTSVirtualChannelRead failed!");
388 error = ERROR_INTERNAL_ERROR;
392 if (BytesReturned < 1)
395 if (!Stream_EnsureRemainingCapacity(s, BytesReturned))
398 WINPR_ASSERT(Stream_Capacity(s) <= UINT32_MAX);
399 if (WTSVirtualChannelRead(audin->audin_channel, 0, Stream_BufferAs(s,
char),
400 (ULONG)Stream_Capacity(s), &BytesReturned) == FALSE)
402 WLog_Print(audin->log, WLOG_ERROR,
"WTSVirtualChannelRead failed!");
403 error = ERROR_INTERNAL_ERROR;
407 Stream_SetLength(s, BytesReturned);
408 if (!Stream_CheckAndLogRequiredLengthWLog(audin->log, s, SNDIN_HEADER_SIZE))
410 error = ERROR_INTERNAL_ERROR;
414 Stream_Read_UINT8(s, header.MessageId);
416 switch (header.MessageId)
418 case MSG_SNDIN_VERSION:
419 error = audin_server_recv_version(&audin->context, s, &header);
421 case MSG_SNDIN_FORMATS:
422 error = audin_server_recv_formats(&audin->context, s, &header);
424 case MSG_SNDIN_OPEN_REPLY:
425 error = audin_server_recv_open_reply(&audin->context, s, &header);
427 case MSG_SNDIN_DATA_INCOMING:
428 error = audin_server_recv_data_incoming(&audin->context, s, &header);
431 error = audin_server_recv_data(&audin->context, s, &header);
433 case MSG_SNDIN_FORMATCHANGE:
434 error = audin_server_recv_format_change(&audin->context, s, &header);
437 WLog_Print(audin->log, WLOG_ERROR,
438 "audin_server_thread_func: unknown or invalid MessageId %" PRIu8
"",
440 error = ERROR_INVALID_DATA;
448 Stream_Free(s, TRUE);
450 (void)WTSVirtualChannelClose(audin->audin_channel);
451 audin->audin_channel = NULL;
453 if (error && audin->context.rdpcontext)
454 setChannelError(audin->context.rdpcontext, error,
455 "audin_server_thread_func reported an error");
461static BOOL audin_server_open(audin_server_context* context)
463 audin_server* audin = (audin_server*)context;
468 PULONG pSessionId = NULL;
469 DWORD BytesReturned = 0;
470 audin->SessionId = WTS_CURRENT_SESSION;
471 UINT32 channelId = 0;
474 if (WTSQuerySessionInformationA(context->vcm, WTS_CURRENT_SESSION, WTSSessionId,
475 (LPSTR*)&pSessionId, &BytesReturned))
477 audin->SessionId = (DWORD)*pSessionId;
478 WTSFreeMemory(pSessionId);
481 audin->audin_channel = WTSVirtualChannelOpenEx(audin->SessionId, AUDIN_DVC_CHANNEL_NAME,
482 WTS_CHANNEL_OPTION_DYNAMIC);
484 if (!audin->audin_channel)
486 WLog_Print(audin->log, WLOG_ERROR,
"WTSVirtualChannelOpenEx failed!");
490 channelId = WTSChannelGetIdByHandle(audin->audin_channel);
492 IFCALLRET(context->ChannelIdAssigned, status, context, channelId);
495 WLog_Print(audin->log, WLOG_ERROR,
"context->ChannelIdAssigned failed!");
499 if (!(audin->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL)))
501 WLog_Print(audin->log, WLOG_ERROR,
"CreateEvent failed!");
505 if (!(audin->thread =
506 CreateThread(NULL, 0, audin_server_thread_func, (
void*)audin, 0, NULL)))
508 WLog_Print(audin->log, WLOG_ERROR,
"CreateThread failed!");
509 (void)CloseHandle(audin->stopEvent);
510 audin->stopEvent = NULL;
517 WLog_Print(audin->log, WLOG_ERROR,
"thread already running!");
521static BOOL audin_server_is_open(audin_server_context* context)
523 audin_server* audin = (audin_server*)context;
526 return audin->thread != NULL;
529static BOOL audin_server_close(audin_server_context* context)
531 audin_server* audin = (audin_server*)context;
536 (void)SetEvent(audin->stopEvent);
538 if (WaitForSingleObject(audin->thread, INFINITE) == WAIT_FAILED)
540 WLog_Print(audin->log, WLOG_ERROR,
"WaitForSingleObject failed with error %" PRIu32
"",
545 (void)CloseHandle(audin->thread);
546 (void)CloseHandle(audin->stopEvent);
547 audin->thread = NULL;
548 audin->stopEvent = NULL;
551 if (audin->audin_channel)
553 (void)WTSVirtualChannelClose(audin->audin_channel);
554 audin->audin_channel = NULL;
557 audin->audin_negotiated_format = NULL;
562static wStream* audin_server_packet_new(wLog* log,
size_t size, BYTE MessageId)
567 wStream* s = Stream_New(NULL, size + SNDIN_HEADER_SIZE);
570 WLog_Print(log, WLOG_ERROR,
"Stream_New failed!");
574 Stream_Write_UINT8(s, MessageId);
579static UINT audin_server_packet_send(audin_server_context* context,
wStream* s)
581 audin_server* audin = (audin_server*)context;
582 UINT error = CHANNEL_RC_OK;
585 WINPR_ASSERT(context);
588 const size_t pos = Stream_GetPosition(s);
589 WINPR_ASSERT(pos <= UINT32_MAX);
590 if (!WTSVirtualChannelWrite(audin->audin_channel, Stream_BufferAs(s,
char), (UINT32)pos,
593 WLog_Print(audin->log, WLOG_ERROR,
"WTSVirtualChannelWrite failed!");
594 error = ERROR_INTERNAL_ERROR;
598 if (written < Stream_GetPosition(s))
600 WLog_Print(audin->log, WLOG_WARN,
"Unexpected bytes written: %" PRIu32
"/%" PRIuz
"",
601 written, Stream_GetPosition(s));
605 Stream_Free(s, TRUE);
609static UINT audin_server_send_version(audin_server_context* context,
const SNDIN_VERSION* version)
611 audin_server* audin = (audin_server*)context;
613 WINPR_ASSERT(context);
614 WINPR_ASSERT(version);
616 wStream* s = audin_server_packet_new(audin->log, 4, MSG_SNDIN_VERSION);
618 return ERROR_NOT_ENOUGH_MEMORY;
620 Stream_Write_UINT32(s, version->Version);
622 return audin_server_packet_send(context, s);
625static UINT audin_server_send_formats(audin_server_context* context,
const SNDIN_FORMATS* formats)
627 audin_server* audin = (audin_server*)context;
630 WINPR_ASSERT(formats);
632 wStream* s = audin_server_packet_new(audin->log, 4 + 4 + 18, MSG_SNDIN_FORMATS);
634 return ERROR_NOT_ENOUGH_MEMORY;
636 Stream_Write_UINT32(s, formats->NumFormats);
637 Stream_Write_UINT32(s, formats->cbSizeFormatsPacket);
639 for (UINT32 i = 0; i < formats->NumFormats; ++i)
643 if (!audio_format_write(s, format))
645 WLog_Print(audin->log, WLOG_ERROR,
"Failed to write audio format");
646 Stream_Free(s, TRUE);
647 return CHANNEL_RC_NO_MEMORY;
651 return audin_server_packet_send(context, s);
654static UINT audin_server_send_open(audin_server_context* context,
const SNDIN_OPEN* open)
656 audin_server* audin = (audin_server*)context;
660 wStream* s = audin_server_packet_new(audin->log, 4 + 4 + 18 + 22, MSG_SNDIN_OPEN);
662 return ERROR_NOT_ENOUGH_MEMORY;
664 Stream_Write_UINT32(s, open->FramesPerPacket);
665 Stream_Write_UINT32(s, open->initialFormat);
667 Stream_Write_UINT16(s, open->captureFormat.wFormatTag);
668 Stream_Write_UINT16(s, open->captureFormat.nChannels);
669 Stream_Write_UINT32(s, open->captureFormat.nSamplesPerSec);
670 Stream_Write_UINT32(s, open->captureFormat.nAvgBytesPerSec);
671 Stream_Write_UINT16(s, open->captureFormat.nBlockAlign);
672 Stream_Write_UINT16(s, open->captureFormat.wBitsPerSample);
674 if (open->ExtraFormatData)
676 Stream_Write_UINT16(s, 22);
678 Stream_Write_UINT16(s, open->ExtraFormatData->Samples.wReserved);
679 Stream_Write_UINT32(s, open->ExtraFormatData->dwChannelMask);
681 Stream_Write_UINT32(s, open->ExtraFormatData->SubFormat.Data1);
682 Stream_Write_UINT16(s, open->ExtraFormatData->SubFormat.Data2);
683 Stream_Write_UINT16(s, open->ExtraFormatData->SubFormat.Data3);
684 Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[0]);
685 Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[1]);
686 Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[2]);
687 Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[3]);
688 Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[4]);
689 Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[5]);
690 Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[6]);
691 Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[7]);
695 WINPR_ASSERT(open->captureFormat.wFormatTag != WAVE_FORMAT_EXTENSIBLE);
697 Stream_Write_UINT16(s, 0);
700 return audin_server_packet_send(context, s);
703static UINT audin_server_send_format_change(audin_server_context* context,
706 audin_server* audin = (audin_server*)context;
708 WINPR_ASSERT(context);
709 WINPR_ASSERT(format_change);
711 wStream* s = audin_server_packet_new(audin->log, 4, MSG_SNDIN_FORMATCHANGE);
713 return ERROR_NOT_ENOUGH_MEMORY;
715 Stream_Write_UINT32(s, format_change->NewFormat);
717 return audin_server_packet_send(context, s);
720static UINT audin_server_receive_version_default(audin_server_context* audin_ctx,
723 audin_server* audin = (audin_server*)audin_ctx;
727 WINPR_ASSERT(version);
729 if (version->Version == 0)
731 WLog_Print(audin->log, WLOG_ERROR,
"Received invalid AUDIO_INPUT version from client");
732 return ERROR_INVALID_DATA;
735 WLog_Print(audin->log, WLOG_DEBUG,
"AUDIO_INPUT version of client: %u", version->Version);
737 formats.NumFormats = audin->audin_n_server_formats;
738 formats.SoundFormats = audin->audin_server_formats;
740 return audin->context.SendFormats(&audin->context, &formats);
743static UINT send_open(audin_server* audin)
749 open.FramesPerPacket = 441;
750 open.initialFormat = audin->audin_client_format_idx;
751 open.captureFormat.wFormatTag = WAVE_FORMAT_PCM;
752 open.captureFormat.nChannels = 2;
753 open.captureFormat.nSamplesPerSec = 44100;
754 open.captureFormat.nAvgBytesPerSec = 44100 * 2 * 2;
755 open.captureFormat.nBlockAlign = 4;
756 open.captureFormat.wBitsPerSample = 16;
758 WINPR_ASSERT(audin->context.SendOpen);
759 return audin->context.SendOpen(&audin->context, &open);
762static UINT audin_server_receive_formats_default(audin_server_context* context,
765 audin_server* audin = (audin_server*)context;
767 WINPR_ASSERT(formats);
769 if (audin->audin_negotiated_format)
771 WLog_Print(audin->log, WLOG_ERROR,
772 "Received client formats, but negotiation was already done");
773 return ERROR_INVALID_DATA;
776 for (UINT32 i = 0; i < audin->audin_n_server_formats; ++i)
778 for (UINT32 j = 0; j < formats->NumFormats; ++j)
780 if (audio_format_compatible(&audin->audin_server_formats[i], &formats->SoundFormats[j]))
782 audin->audin_negotiated_format = &audin->audin_server_formats[i];
783 audin->audin_client_format_idx = i;
784 return send_open(audin);
789 WLog_Print(audin->log, WLOG_ERROR,
"Could not agree on a audio format with the server");
791 return ERROR_INVALID_DATA;
794static UINT audin_server_receive_format_change_default(audin_server_context* context,
797 audin_server* audin = (audin_server*)context;
800 WINPR_ASSERT(format_change);
802 if (format_change->NewFormat != audin->audin_client_format_idx)
804 WLog_Print(audin->log, WLOG_ERROR,
805 "NewFormat in FormatChange differs from requested format");
806 return ERROR_INVALID_DATA;
809 WLog_Print(audin->log, WLOG_DEBUG,
"Received Format Change PDU: %u", format_change->NewFormat);
811 return CHANNEL_RC_OK;
815audin_server_incoming_data_default(audin_server_context* context,
818 audin_server* audin = (audin_server*)context;
820 WINPR_ASSERT(data_incoming);
823 WLog_Print(audin->log, WLOG_DEBUG,
"Received Incoming Data PDU");
824 return CHANNEL_RC_OK;
827static UINT audin_server_open_reply_default(audin_server_context* context,
830 audin_server* audin = (audin_server*)context;
832 WINPR_ASSERT(open_reply);
835 WLog_Print(audin->log, WLOG_DEBUG,
"Open Reply PDU: Result: %" PRIu32, open_reply->Result);
836 return CHANNEL_RC_OK;
839audin_server_context* audin_server_context_new(HANDLE vcm)
841 audin_server* audin = (audin_server*)calloc(1,
sizeof(audin_server));
845 WLog_ERR(AUDIN_TAG,
"calloc failed!");
848 audin->log = WLog_Get(AUDIN_TAG);
849 audin->context.vcm = vcm;
850 audin->context.Open = audin_server_open;
851 audin->context.IsOpen = audin_server_is_open;
852 audin->context.Close = audin_server_close;
854 audin->context.SendVersion = audin_server_send_version;
855 audin->context.SendFormats = audin_server_send_formats;
856 audin->context.SendOpen = audin_server_send_open;
857 audin->context.SendFormatChange = audin_server_send_format_change;
860 audin->context.serverVersion = SNDIN_VERSION_Version_2;
861 audin->context.ReceiveVersion = audin_server_receive_version_default;
862 audin->context.ReceiveFormats = audin_server_receive_formats_default;
863 audin->context.ReceiveFormatChange = audin_server_receive_format_change_default;
864 audin->context.IncomingData = audin_server_incoming_data_default;
865 audin->context.OpenReply = audin_server_open_reply_default;
867 return &audin->context;
870void audin_server_context_free(audin_server_context* context)
872 audin_server* audin = (audin_server*)context;
877 audin_server_close(context);
878 audio_formats_free(audin->audin_server_formats, audin->audin_n_server_formats);
879 audin->audin_server_formats = NULL;
883BOOL audin_server_set_formats(audin_server_context* context, SSIZE_T count,
886 audin_server* audin = (audin_server*)context;
889 audio_formats_free(audin->audin_server_formats, audin->audin_n_server_formats);
890 audin->audin_n_server_formats = 0;
891 audin->audin_server_formats = NULL;
892 audin->audin_negotiated_format = NULL;
896 const size_t audin_n_server_formats =
897 server_audin_get_formats(&audin->audin_server_formats);
898 WINPR_ASSERT(audin_n_server_formats <= UINT32_MAX);
900 audin->audin_n_server_formats = (UINT32)audin_n_server_formats;
904 const size_t scount = (size_t)count;
905 AUDIO_FORMAT* audin_server_formats = audio_formats_new(scount);
906 if (!audin_server_formats)
909 for (SSIZE_T x = 0; x < count; x++)
911 if (!audio_format_copy(&formats[x], &audin_server_formats[x]))
913 audio_formats_free(audin_server_formats, scount);
918 WINPR_ASSERT(count <= UINT32_MAX);
919 audin->audin_server_formats = audin_server_formats;
920 audin->audin_n_server_formats = (UINT32)count;
922 return audin->audin_n_server_formats > 0;
925const AUDIO_FORMAT* audin_server_get_negotiated_format(
const audin_server_context* context)
927 const audin_server* audin = (
const audin_server*)context;
930 return audin->audin_negotiated_format;