From 208fbabfde4f6d4053f14a24507771b923738431 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Tue, 3 Sep 2019 14:50:05 +0200 Subject: [PATCH] Only close local audio device if rdpsnd thread closes or output format changes. Windows 7 and other older systems send one close PDU after another. This distorts audio during setup and teardown of local sound devices. --- channels/rdpsnd/client/rdpsnd_main.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/channels/rdpsnd/client/rdpsnd_main.c b/channels/rdpsnd/client/rdpsnd_main.c index 001bcd9cb..7617289e2 100644 --- a/channels/rdpsnd/client/rdpsnd_main.c +++ b/channels/rdpsnd/client/rdpsnd_main.c @@ -99,7 +99,6 @@ struct rdpsnd_plugin FREERDP_DSP_CONTEXT* dsp_context; }; -static void rdpsnd_recv_close_pdu(rdpsndPlugin* rdpsnd); static void rdpsnd_virtual_channel_event_terminated(rdpsndPlugin* rdpsnd); /** @@ -343,7 +342,8 @@ static BOOL rdpsnd_ensure_device_is_open(rdpsndPlugin* rdpsnd, UINT32 wFormatNo, BOOL rc; BOOL supported; AUDIO_FORMAT deviceFormat = *format; - rdpsnd_recv_close_pdu(rdpsnd); + + IFCALL(rdpsnd->device->Close, rdpsnd->device); supported = IFCALLRESULT(FALSE, rdpsnd->device->FormatSupported, rdpsnd->device, format); if (!supported) @@ -444,6 +444,7 @@ static UINT rdpsnd_treat_wave(rdpsndPlugin* rdpsnd, wStream* s, size_t size) UINT64 diffMS, ts; UINT latency = 0; + if (Stream_GetRemainingLength(s) < size) return ERROR_BAD_LENGTH; @@ -468,7 +469,7 @@ static UINT rdpsnd_treat_wave(rdpsndPlugin* rdpsnd, wStream* s, size_t size) else status = ERROR_INTERNAL_ERROR; - StreamPool_Return(rdpsnd->pool, pcmData); + Stream_Release(pcmData); if (status != CHANNEL_RC_OK) return status; @@ -535,9 +536,7 @@ static void rdpsnd_recv_close_pdu(rdpsndPlugin* rdpsnd) { if (rdpsnd->isOpen) { - WLog_Print(rdpsnd->log, WLOG_DEBUG, "Closing device"); - IFCALL(rdpsnd->device->Close, rdpsnd->device); - rdpsnd->isOpen = FALSE; + WLog_Print(rdpsnd->log, WLOG_DEBUG, "Closing device"); } else WLog_Print(rdpsnd->log, WLOG_DEBUG, "Device already closed"); @@ -628,7 +627,7 @@ static UINT rdpsnd_recv_pdu(rdpsndPlugin* rdpsnd, wStream* s) } out: - StreamPool_Return(rdpsnd->pool, s); + Stream_Release(s); return status; } @@ -900,7 +899,7 @@ static UINT rdpsnd_process_connect(rdpsndPlugin* rdpsnd) static void rdpsnd_process_disconnect(rdpsndPlugin* rdpsnd) { - rdpsnd_recv_close_pdu(rdpsnd); + IFCALL(rdpsnd->device->Close, rdpsnd->device); } /**