From 8aa880c0ba39499ad0115255718157d5a69298cc Mon Sep 17 00:00:00 2001 From: akallabeth Date: Tue, 13 Dec 2022 15:05:07 +0100 Subject: [PATCH] [channels,rdpsnd] Callback on server format When the server sends the format list to the client call a device callback that provides the details to the audio backend. --- channels/rdpsnd/client/rdpsnd_main.c | 26 +++++++++++++++++--------- include/freerdp/client/rdpsnd.h | 3 +++ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/channels/rdpsnd/client/rdpsnd_main.c b/channels/rdpsnd/client/rdpsnd_main.c index 6f3eccbe8..334ba3b8d 100644 --- a/channels/rdpsnd/client/rdpsnd_main.c +++ b/channels/rdpsnd/client/rdpsnd_main.c @@ -180,6 +180,7 @@ static void rdpsnd_select_supported_audio_formats(rdpsndPlugin* rdpsnd) if (!audio_format_compatible(rdpsnd->fixed_format, serverFormat)) continue; + WINPR_ASSERT(rdpsnd->device->FormatSupported); if (freerdp_dsp_supports_format(serverFormat, FALSE) || rdpsnd->device->FormatSupported(rdpsnd->device, serverFormat)) { @@ -282,19 +283,26 @@ static UINT rdpsnd_recv_server_audio_formats_pdu(rdpsndPlugin* rdpsnd, wStream* if (!Stream_CheckAndLogRequiredLength(TAG, s, 14ull * wNumberOfFormats)) return ERROR_BAD_LENGTH; - rdpsnd->ServerFormats = audio_formats_new(wNumberOfFormats); - - if (!rdpsnd->ServerFormats) - return CHANNEL_RC_NO_MEMORY; - - for (index = 0; index < wNumberOfFormats; index++) + if (rdpsnd->NumberOfServerFormats > 0) { - AUDIO_FORMAT* format = &rdpsnd->ServerFormats[index]; + rdpsnd->ServerFormats = audio_formats_new(wNumberOfFormats); - if (!audio_format_read(s, format)) - goto out_fail; + if (!rdpsnd->ServerFormats) + return CHANNEL_RC_NO_MEMORY; + + for (index = 0; index < wNumberOfFormats; index++) + { + AUDIO_FORMAT* format = &rdpsnd->ServerFormats[index]; + + if (!audio_format_read(s, format)) + goto out_fail; + } } + WINPR_ASSERT(rdpsnd->device); + ret = IFCALLRESULT(CHANNEL_RC_OK, rdpsnd->device->ServerFormatAnnounce, rdpsnd->device, + rdpsnd->ServerFormats, rdpsnd->NumberOfServerFormats); + rdpsnd_select_supported_audio_formats(rdpsnd); WLog_Print(rdpsnd->log, WLOG_DEBUG, "%s Server Audio Formats", rdpsnd_is_dyn_str(rdpsnd->dynamic)); diff --git a/include/freerdp/client/rdpsnd.h b/include/freerdp/client/rdpsnd.h index 078a8a041..31708aa49 100644 --- a/include/freerdp/client/rdpsnd.h +++ b/include/freerdp/client/rdpsnd.h @@ -44,6 +44,8 @@ extern "C" typedef void (*pcFree)(rdpsndDevicePlugin* device); typedef BOOL (*pcDefaultFormat)(rdpsndDevicePlugin* device, const AUDIO_FORMAT* desired, AUDIO_FORMAT* defaultFormat); + typedef UINT (*pcServerFormatAnnounce)(rdpsndDevicePlugin* device, const AUDIO_FORMAT* formats, + size_t count); struct rdpsnd_device_plugin { @@ -58,6 +60,7 @@ extern "C" pcClose Close; pcFree Free; pcDefaultFormat DefaultFormat; + pcServerFormatAnnounce ServerFormatAnnounce; }; #define RDPSND_DEVICE_EXPORT_FUNC_NAME "freerdp_rdpsnd_client_subsystem_entry"