23 #include <freerdp/config.h>
25 #include <winpr/crt.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;
69 static 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))
84 Stream_Read_UINT32(s, pdu.Version);
86 IFCALLRET(context->ReceiveVersion, error, context, &pdu);
88 WLog_Print(audin->log, WLOG_ERROR,
"context->ReceiveVersion failed with error %" PRIu32
"",
94 static UINT audin_server_recv_formats(audin_server_context* context,
wStream* s,
97 audin_server* audin = (audin_server*)context;
99 UINT error = CHANNEL_RC_OK;
101 WINPR_ASSERT(context);
102 WINPR_ASSERT(header);
104 pdu.Header = *header;
107 if (!Stream_CheckAndLogRequiredLengthWLog(audin->log, s, 4 + 4 + 18))
108 return ERROR_NO_DATA;
110 Stream_Read_UINT32(s, pdu.NumFormats);
111 Stream_Read_UINT32(s, pdu.cbSizeFormatsPacket);
113 if (pdu.NumFormats == 0)
115 WLog_Print(audin->log, WLOG_ERROR,
"Sound Formats PDU contains no formats");
116 return ERROR_INVALID_DATA;
119 pdu.SoundFormats = audio_formats_new(pdu.NumFormats);
120 if (!pdu.SoundFormats)
122 WLog_Print(audin->log, WLOG_ERROR,
"Failed to allocate %u SoundFormats", pdu.NumFormats);
123 return ERROR_NOT_ENOUGH_MEMORY;
126 for (UINT32 i = 0; i < pdu.NumFormats; ++i)
130 if (!audio_format_read(s, format))
132 WLog_Print(audin->log, WLOG_ERROR,
"Failed to read audio format");
133 audio_formats_free(pdu.SoundFormats, i + i);
134 return ERROR_INVALID_DATA;
137 audio_format_print(audin->log, WLOG_DEBUG, format);
140 if (pdu.cbSizeFormatsPacket != Stream_GetPosition(s))
142 WLog_Print(audin->log, WLOG_WARN,
143 "cbSizeFormatsPacket is invalid! Expected: %u Got: %zu. Fixing size",
144 pdu.cbSizeFormatsPacket, Stream_GetPosition(s));
145 const size_t pos = Stream_GetPosition(s);
146 if (pos > UINT32_MAX)
148 WLog_Print(audin->log, WLOG_ERROR,
"Stream too long, %" PRIuz
" exceeds UINT32_MAX",
150 error = ERROR_INVALID_PARAMETER;
153 pdu.cbSizeFormatsPacket = (UINT32)pos;
156 pdu.ExtraDataSize = Stream_GetRemainingLength(s);
158 IFCALLRET(context->ReceiveFormats, error, context, &pdu);
160 WLog_Print(audin->log, WLOG_ERROR,
"context->ReceiveFormats failed with error %" PRIu32
"",
164 audio_formats_free(pdu.SoundFormats, pdu.NumFormats);
169 static UINT audin_server_recv_open_reply(audin_server_context* context,
wStream* s,
172 audin_server* audin = (audin_server*)context;
174 UINT error = CHANNEL_RC_OK;
176 WINPR_ASSERT(context);
177 WINPR_ASSERT(header);
179 pdu.Header = *header;
181 if (!Stream_CheckAndLogRequiredLengthWLog(audin->log, s, 4))
182 return ERROR_NO_DATA;
184 Stream_Read_UINT32(s, pdu.Result);
186 IFCALLRET(context->OpenReply, error, context, &pdu);
188 WLog_Print(audin->log, WLOG_ERROR,
"context->OpenReply failed with error %" PRIu32
"",
194 static UINT audin_server_recv_data_incoming(audin_server_context* context,
wStream* s,
197 audin_server* audin = (audin_server*)context;
199 UINT error = CHANNEL_RC_OK;
201 WINPR_ASSERT(context);
202 WINPR_ASSERT(header);
204 pdu.Header = *header;
206 IFCALLRET(context->IncomingData, error, context, &pdu);
208 WLog_Print(audin->log, WLOG_ERROR,
"context->IncomingData failed with error %" PRIu32
"",
214 static UINT audin_server_recv_data(audin_server_context* context,
wStream* s,
217 audin_server* audin = (audin_server*)context;
220 UINT error = CHANNEL_RC_OK;
222 WINPR_ASSERT(context);
223 WINPR_ASSERT(header);
225 pdu.Header = *header;
227 pdu.Data = Stream_StaticInit(&dataBuffer, Stream_Pointer(s), Stream_GetRemainingLength(s));
229 IFCALLRET(context->Data, error, context, &pdu);
231 WLog_Print(audin->log, WLOG_ERROR,
"context->Data failed with error %" PRIu32
"", error);
236 static UINT audin_server_recv_format_change(audin_server_context* context,
wStream* s,
239 audin_server* audin = (audin_server*)context;
241 UINT error = CHANNEL_RC_OK;
243 WINPR_ASSERT(context);
244 WINPR_ASSERT(header);
246 pdu.Header = *header;
248 if (!Stream_CheckAndLogRequiredLengthWLog(audin->log, s, 4))
249 return ERROR_NO_DATA;
251 Stream_Read_UINT32(s, pdu.NewFormat);
253 IFCALLRET(context->ReceiveFormatChange, error, context, &pdu);
255 WLog_Print(audin->log, WLOG_ERROR,
256 "context->ReceiveFormatChange failed with error %" PRIu32
"", error);
261 static DWORD WINAPI audin_server_thread_func(LPVOID arg)
266 HANDLE events[8] = { 0 };
268 HANDLE ChannelEvent = NULL;
269 DWORD BytesReturned = 0;
270 audin_server* audin = (audin_server*)arg;
271 UINT error = CHANNEL_RC_OK;
272 DWORD status = ERROR_INTERNAL_ERROR;
276 if (WTSVirtualChannelQuery(audin->audin_channel, WTSVirtualEventHandle, &buffer,
277 &BytesReturned) == TRUE)
279 if (BytesReturned ==
sizeof(HANDLE))
280 CopyMemory(&ChannelEvent, buffer,
sizeof(HANDLE));
282 WTSFreeMemory(buffer);
286 WLog_Print(audin->log, WLOG_ERROR,
"WTSVirtualChannelQuery failed");
287 error = ERROR_INTERNAL_ERROR;
292 events[nCount++] = audin->stopEvent;
293 events[nCount++] = ChannelEvent;
299 if ((status = WaitForMultipleObjects(nCount, events, FALSE, 100)) == WAIT_OBJECT_0)
302 if (status == WAIT_FAILED)
304 error = GetLastError();
305 WLog_Print(audin->log, WLOG_ERROR,
306 "WaitForMultipleObjects failed with error %" PRIu32
"", error);
309 if (status == WAIT_OBJECT_0)
312 if (WTSVirtualChannelQuery(audin->audin_channel, WTSVirtualChannelReady, &buffer,
313 &BytesReturned) == FALSE)
315 WLog_Print(audin->log, WLOG_ERROR,
"WTSVirtualChannelQuery failed");
316 error = ERROR_INTERNAL_ERROR;
320 ready = *((BOOL*)buffer);
321 WTSFreeMemory(buffer);
327 s = Stream_New(NULL, 4096);
331 WLog_Print(audin->log, WLOG_ERROR,
"Stream_New failed!");
332 error = CHANNEL_RC_NO_MEMORY;
340 version.Version = audin->context.serverVersion;
342 if ((error = audin->context.SendVersion(&audin->context, &version)))
344 WLog_Print(audin->log, WLOG_ERROR,
"SendVersion failed with error %" PRIu32
"!", error);
353 if ((status = WaitForMultipleObjects(nCount, events, FALSE, INFINITE)) == WAIT_OBJECT_0)
356 if (status == WAIT_FAILED)
358 error = GetLastError();
359 WLog_Print(audin->log, WLOG_ERROR,
360 "WaitForMultipleObjects failed with error %" PRIu32
"", error);
363 if (status == WAIT_OBJECT_0)
366 Stream_SetPosition(s, 0);
368 if (!WTSVirtualChannelRead(audin->audin_channel, 0, NULL, 0, &BytesReturned))
370 WLog_Print(audin->log, WLOG_ERROR,
"WTSVirtualChannelRead failed!");
371 error = ERROR_INTERNAL_ERROR;
375 if (BytesReturned < 1)
378 if (!Stream_EnsureRemainingCapacity(s, BytesReturned))
381 WINPR_ASSERT(Stream_Capacity(s) <= UINT32_MAX);
382 if (WTSVirtualChannelRead(audin->audin_channel, 0, Stream_BufferAs(s,
char),
383 (ULONG)Stream_Capacity(s), &BytesReturned) == FALSE)
385 WLog_Print(audin->log, WLOG_ERROR,
"WTSVirtualChannelRead failed!");
386 error = ERROR_INTERNAL_ERROR;
390 Stream_SetLength(s, BytesReturned);
391 if (!Stream_CheckAndLogRequiredLengthWLog(audin->log, s, SNDIN_HEADER_SIZE))
393 error = ERROR_INTERNAL_ERROR;
397 Stream_Read_UINT8(s, header.MessageId);
399 switch (header.MessageId)
401 case MSG_SNDIN_VERSION:
402 error = audin_server_recv_version(&audin->context, s, &header);
404 case MSG_SNDIN_FORMATS:
405 error = audin_server_recv_formats(&audin->context, s, &header);
407 case MSG_SNDIN_OPEN_REPLY:
408 error = audin_server_recv_open_reply(&audin->context, s, &header);
410 case MSG_SNDIN_DATA_INCOMING:
411 error = audin_server_recv_data_incoming(&audin->context, s, &header);
414 error = audin_server_recv_data(&audin->context, s, &header);
416 case MSG_SNDIN_FORMATCHANGE:
417 error = audin_server_recv_format_change(&audin->context, s, &header);
420 WLog_Print(audin->log, WLOG_ERROR,
421 "audin_server_thread_func: unknown or invalid MessageId %" PRIu8
"",
423 error = ERROR_INVALID_DATA;
431 Stream_Free(s, TRUE);
433 (void)WTSVirtualChannelClose(audin->audin_channel);
434 audin->audin_channel = NULL;
436 if (error && audin->context.rdpcontext)
437 setChannelError(audin->context.rdpcontext, error,
438 "audin_server_thread_func reported an error");
444 static BOOL audin_server_open(audin_server_context* context)
446 audin_server* audin = (audin_server*)context;
451 PULONG pSessionId = NULL;
452 DWORD BytesReturned = 0;
453 audin->SessionId = WTS_CURRENT_SESSION;
454 UINT32 channelId = 0;
457 if (WTSQuerySessionInformationA(context->vcm, WTS_CURRENT_SESSION, WTSSessionId,
458 (LPSTR*)&pSessionId, &BytesReturned))
460 audin->SessionId = (DWORD)*pSessionId;
461 WTSFreeMemory(pSessionId);
464 audin->audin_channel = WTSVirtualChannelOpenEx(audin->SessionId, AUDIN_DVC_CHANNEL_NAME,
465 WTS_CHANNEL_OPTION_DYNAMIC);
467 if (!audin->audin_channel)
469 WLog_Print(audin->log, WLOG_ERROR,
"WTSVirtualChannelOpenEx failed!");
473 channelId = WTSChannelGetIdByHandle(audin->audin_channel);
475 IFCALLRET(context->ChannelIdAssigned, status, context, channelId);
478 WLog_Print(audin->log, WLOG_ERROR,
"context->ChannelIdAssigned failed!");
482 if (!(audin->stopEvent = CreateEvent(NULL, TRUE, FALSE, NULL)))
484 WLog_Print(audin->log, WLOG_ERROR,
"CreateEvent failed!");
488 if (!(audin->thread =
489 CreateThread(NULL, 0, audin_server_thread_func, (
void*)audin, 0, NULL)))
491 WLog_Print(audin->log, WLOG_ERROR,
"CreateThread failed!");
492 (void)CloseHandle(audin->stopEvent);
493 audin->stopEvent = NULL;
500 WLog_Print(audin->log, WLOG_ERROR,
"thread already running!");
504 static BOOL audin_server_is_open(audin_server_context* context)
506 audin_server* audin = (audin_server*)context;
509 return audin->thread != NULL;
512 static BOOL audin_server_close(audin_server_context* context)
514 audin_server* audin = (audin_server*)context;
519 (void)SetEvent(audin->stopEvent);
521 if (WaitForSingleObject(audin->thread, INFINITE) == WAIT_FAILED)
523 WLog_Print(audin->log, WLOG_ERROR,
"WaitForSingleObject failed with error %" PRIu32
"",
528 (void)CloseHandle(audin->thread);
529 (void)CloseHandle(audin->stopEvent);
530 audin->thread = NULL;
531 audin->stopEvent = NULL;
534 if (audin->audin_channel)
536 (void)WTSVirtualChannelClose(audin->audin_channel);
537 audin->audin_channel = NULL;
540 audin->audin_negotiated_format = NULL;
545 static wStream* audin_server_packet_new(wLog* log,
size_t size, BYTE MessageId)
550 wStream* s = Stream_New(NULL, size + SNDIN_HEADER_SIZE);
553 WLog_Print(log, WLOG_ERROR,
"Stream_New failed!");
557 Stream_Write_UINT8(s, MessageId);
562 static UINT audin_server_packet_send(audin_server_context* context,
wStream* s)
564 audin_server* audin = (audin_server*)context;
565 UINT error = CHANNEL_RC_OK;
568 WINPR_ASSERT(context);
571 const size_t pos = Stream_GetPosition(s);
572 WINPR_ASSERT(pos <= UINT32_MAX);
573 if (!WTSVirtualChannelWrite(audin->audin_channel, Stream_BufferAs(s,
char), (UINT32)pos,
576 WLog_Print(audin->log, WLOG_ERROR,
"WTSVirtualChannelWrite failed!");
577 error = ERROR_INTERNAL_ERROR;
581 if (written < Stream_GetPosition(s))
583 WLog_Print(audin->log, WLOG_WARN,
"Unexpected bytes written: %" PRIu32
"/%" PRIuz
"",
584 written, Stream_GetPosition(s));
588 Stream_Free(s, TRUE);
592 static UINT audin_server_send_version(audin_server_context* context,
const SNDIN_VERSION* version)
594 audin_server* audin = (audin_server*)context;
596 WINPR_ASSERT(context);
597 WINPR_ASSERT(version);
599 wStream* s = audin_server_packet_new(audin->log, 4, MSG_SNDIN_VERSION);
601 return ERROR_NOT_ENOUGH_MEMORY;
603 Stream_Write_UINT32(s, version->Version);
605 return audin_server_packet_send(context, s);
608 static UINT audin_server_send_formats(audin_server_context* context,
const SNDIN_FORMATS* formats)
610 audin_server* audin = (audin_server*)context;
613 WINPR_ASSERT(formats);
615 wStream* s = audin_server_packet_new(audin->log, 4 + 4 + 18, MSG_SNDIN_FORMATS);
617 return ERROR_NOT_ENOUGH_MEMORY;
619 Stream_Write_UINT32(s, formats->NumFormats);
620 Stream_Write_UINT32(s, formats->cbSizeFormatsPacket);
622 for (UINT32 i = 0; i < formats->NumFormats; ++i)
626 if (!audio_format_write(s, format))
628 WLog_Print(audin->log, WLOG_ERROR,
"Failed to write audio format");
629 Stream_Free(s, TRUE);
630 return CHANNEL_RC_NO_MEMORY;
634 return audin_server_packet_send(context, s);
637 static UINT audin_server_send_open(audin_server_context* context,
const SNDIN_OPEN* open)
639 audin_server* audin = (audin_server*)context;
643 wStream* s = audin_server_packet_new(audin->log, 4 + 4 + 18 + 22, MSG_SNDIN_OPEN);
645 return ERROR_NOT_ENOUGH_MEMORY;
647 Stream_Write_UINT32(s, open->FramesPerPacket);
648 Stream_Write_UINT32(s, open->initialFormat);
650 Stream_Write_UINT16(s, open->captureFormat.wFormatTag);
651 Stream_Write_UINT16(s, open->captureFormat.nChannels);
652 Stream_Write_UINT32(s, open->captureFormat.nSamplesPerSec);
653 Stream_Write_UINT32(s, open->captureFormat.nAvgBytesPerSec);
654 Stream_Write_UINT16(s, open->captureFormat.nBlockAlign);
655 Stream_Write_UINT16(s, open->captureFormat.wBitsPerSample);
657 if (open->ExtraFormatData)
659 Stream_Write_UINT16(s, 22);
661 Stream_Write_UINT16(s, open->ExtraFormatData->Samples.wReserved);
662 Stream_Write_UINT32(s, open->ExtraFormatData->dwChannelMask);
664 Stream_Write_UINT32(s, open->ExtraFormatData->SubFormat.Data1);
665 Stream_Write_UINT16(s, open->ExtraFormatData->SubFormat.Data2);
666 Stream_Write_UINT16(s, open->ExtraFormatData->SubFormat.Data3);
667 Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[0]);
668 Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[1]);
669 Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[2]);
670 Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[3]);
671 Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[4]);
672 Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[5]);
673 Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[6]);
674 Stream_Write_UINT8(s, open->ExtraFormatData->SubFormat.Data4[7]);
678 WINPR_ASSERT(open->captureFormat.wFormatTag != WAVE_FORMAT_EXTENSIBLE);
680 Stream_Write_UINT16(s, 0);
683 return audin_server_packet_send(context, s);
686 static UINT audin_server_send_format_change(audin_server_context* context,
689 audin_server* audin = (audin_server*)context;
691 WINPR_ASSERT(context);
692 WINPR_ASSERT(format_change);
694 wStream* s = audin_server_packet_new(audin->log, 4, MSG_SNDIN_FORMATCHANGE);
696 return ERROR_NOT_ENOUGH_MEMORY;
698 Stream_Write_UINT32(s, format_change->NewFormat);
700 return audin_server_packet_send(context, s);
703 static UINT audin_server_receive_version_default(audin_server_context* audin_ctx,
706 audin_server* audin = (audin_server*)audin_ctx;
710 WINPR_ASSERT(version);
712 if (version->Version == 0)
714 WLog_Print(audin->log, WLOG_ERROR,
"Received invalid AUDIO_INPUT version from client");
715 return ERROR_INVALID_DATA;
718 WLog_Print(audin->log, WLOG_DEBUG,
"AUDIO_INPUT version of client: %u", version->Version);
720 formats.NumFormats = audin->audin_n_server_formats;
721 formats.SoundFormats = audin->audin_server_formats;
723 return audin->context.SendFormats(&audin->context, &formats);
726 static UINT send_open(audin_server* audin)
732 open.FramesPerPacket = 441;
733 open.initialFormat = audin->audin_client_format_idx;
734 open.captureFormat.wFormatTag = WAVE_FORMAT_PCM;
735 open.captureFormat.nChannels = 2;
736 open.captureFormat.nSamplesPerSec = 44100;
737 open.captureFormat.nAvgBytesPerSec = 44100 * 2 * 2;
738 open.captureFormat.nBlockAlign = 4;
739 open.captureFormat.wBitsPerSample = 16;
741 WINPR_ASSERT(audin->context.SendOpen);
742 return audin->context.SendOpen(&audin->context, &open);
745 static UINT audin_server_receive_formats_default(audin_server_context* context,
748 audin_server* audin = (audin_server*)context;
750 WINPR_ASSERT(formats);
752 if (audin->audin_negotiated_format)
754 WLog_Print(audin->log, WLOG_ERROR,
755 "Received client formats, but negotiation was already done");
756 return ERROR_INVALID_DATA;
759 for (UINT32 i = 0; i < audin->audin_n_server_formats; ++i)
761 for (UINT32 j = 0; j < formats->NumFormats; ++j)
763 if (audio_format_compatible(&audin->audin_server_formats[i], &formats->SoundFormats[j]))
765 audin->audin_negotiated_format = &audin->audin_server_formats[i];
766 audin->audin_client_format_idx = i;
767 return send_open(audin);
772 WLog_Print(audin->log, WLOG_ERROR,
"Could not agree on a audio format with the server");
774 return ERROR_INVALID_DATA;
777 static UINT audin_server_receive_format_change_default(audin_server_context* context,
780 audin_server* audin = (audin_server*)context;
783 WINPR_ASSERT(format_change);
785 if (format_change->NewFormat != audin->audin_client_format_idx)
787 WLog_Print(audin->log, WLOG_ERROR,
788 "NewFormat in FormatChange differs from requested format");
789 return ERROR_INVALID_DATA;
792 WLog_Print(audin->log, WLOG_DEBUG,
"Received Format Change PDU: %u", format_change->NewFormat);
794 return CHANNEL_RC_OK;
797 static UINT audin_server_incoming_data_default(audin_server_context* context,
800 audin_server* audin = (audin_server*)context;
802 WINPR_ASSERT(data_incoming);
805 WLog_Print(audin->log, WLOG_DEBUG,
"Received Incoming Data PDU");
806 return CHANNEL_RC_OK;
809 static UINT audin_server_open_reply_default(audin_server_context* context,
812 audin_server* audin = (audin_server*)context;
814 WINPR_ASSERT(open_reply);
817 WLog_Print(audin->log, WLOG_DEBUG,
"Open Reply PDU: Result: %i", open_reply->Result);
818 return CHANNEL_RC_OK;
821 audin_server_context* audin_server_context_new(HANDLE vcm)
823 audin_server* audin = (audin_server*)calloc(1,
sizeof(audin_server));
827 WLog_ERR(AUDIN_TAG,
"calloc failed!");
830 audin->log = WLog_Get(AUDIN_TAG);
831 audin->context.vcm = vcm;
832 audin->context.Open = audin_server_open;
833 audin->context.IsOpen = audin_server_is_open;
834 audin->context.Close = audin_server_close;
836 audin->context.SendVersion = audin_server_send_version;
837 audin->context.SendFormats = audin_server_send_formats;
838 audin->context.SendOpen = audin_server_send_open;
839 audin->context.SendFormatChange = audin_server_send_format_change;
842 audin->context.serverVersion = SNDIN_VERSION_Version_2;
843 audin->context.ReceiveVersion = audin_server_receive_version_default;
844 audin->context.ReceiveFormats = audin_server_receive_formats_default;
845 audin->context.ReceiveFormatChange = audin_server_receive_format_change_default;
846 audin->context.IncomingData = audin_server_incoming_data_default;
847 audin->context.OpenReply = audin_server_open_reply_default;
849 return &audin->context;
852 void audin_server_context_free(audin_server_context* context)
854 audin_server* audin = (audin_server*)context;
859 audin_server_close(context);
860 audio_formats_free(audin->audin_server_formats, audin->audin_n_server_formats);
861 audin->audin_server_formats = NULL;
865 BOOL audin_server_set_formats(audin_server_context* context, SSIZE_T count,
868 audin_server* audin = (audin_server*)context;
871 audio_formats_free(audin->audin_server_formats, audin->audin_n_server_formats);
872 audin->audin_n_server_formats = 0;
873 audin->audin_server_formats = NULL;
874 audin->audin_negotiated_format = NULL;
878 const size_t audin_n_server_formats =
879 server_audin_get_formats(&audin->audin_server_formats);
880 WINPR_ASSERT(audin_n_server_formats <= UINT32_MAX);
882 audin->audin_n_server_formats = (UINT32)audin_n_server_formats;
886 AUDIO_FORMAT* audin_server_formats = audio_formats_new(count);
887 if (!audin_server_formats)
890 for (SSIZE_T x = 0; x < count; x++)
892 if (!audio_format_copy(&formats[x], &audin_server_formats[x]))
894 audio_formats_free(audin_server_formats, count);
899 WINPR_ASSERT(count <= UINT32_MAX);
900 audin->audin_server_formats = audin_server_formats;
901 audin->audin_n_server_formats = (UINT32)count;
903 return audin->audin_n_server_formats > 0;
906 const AUDIO_FORMAT* audin_server_get_negotiated_format(
const audin_server_context* context)
908 const audin_server* audin = (
const audin_server*)context;
911 return audin->audin_negotiated_format;