Fixes #5747: Only activate sound output device (#6467)
authorFelix Deimel <felix@lemonmojo.com>
Tue, 8 Sep 2020 08:55:49 +0000 (10:55 +0200)
committerakallabeth <akallabeth@users.noreply.github.com>
Tue, 1 Dec 2020 14:10:23 +0000 (15:10 +0100)
* Fixes #5747: Only activate sound output device

(cherry picked from commit 19f74a269837d62dff0b3541aa8108159bc22064)

channels/rdpsnd/client/mac/rdpsnd_mac.m

index ffdfb9f..5ccdbd6 100644 (file)
@@ -167,22 +167,14 @@ static BOOL rdpsnd_mac_open(rdpsndDevicePlugin *device, const AUDIO_FORMAT *form
        if (!mac->engine)
                return FALSE;
 
-       if (@available(macOS 10.15, *))
-       {
-               /* Setting the output audio device on 10.15 or later breaks sound playback. Do not set for
-                * now until we find a proper fix for #5747 */
-       }
-       else
+       err = AudioUnitSetProperty(mac->engine.outputNode.audioUnit,
+                                  kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0,
+                                  &outputDeviceID, sizeof(outputDeviceID));
+       if (err)
        {
-               err = AudioUnitSetProperty(mac->engine.outputNode.audioUnit,
-                                          kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global,
-                                          0, &outputDeviceID, sizeof(outputDeviceID));
-               if (err)
-               {
-                       rdpsnd_mac_release(mac);
-                       WLog_ERR(TAG, "AudioUnitSetProperty: %s", FormatError(err));
-                       return FALSE;
-               }
+               rdpsnd_mac_release(mac);
+               WLog_ERR(TAG, "AudioUnitSetProperty: %s", FormatError(err));
+               return FALSE;
        }
 
        mac->player = [[AVAudioPlayerNode alloc] init];
@@ -197,6 +189,8 @@ static BOOL rdpsnd_mac_open(rdpsndDevicePlugin *device, const AUDIO_FORMAT *form
 
        [mac->engine connect:mac->player to:mac->engine.mainMixerNode format:nil];
 
+       [mac->engine prepare];
+
        if (![mac->engine startAndReturnError:&error])
        {
                device->Close(device);
@@ -275,6 +269,19 @@ static void rdpsnd_mac_start(rdpsndDevicePlugin *device)
 
        if (!mac->isPlaying)
        {
+               if (!mac->engine.isRunning)
+               {
+                       NSError *error;
+
+                       if (![mac->engine startAndReturnError:&error])
+                       {
+                               device->Close(device);
+                               WLog_ERR(TAG, "Failed to start audio player %s",
+                                        [error.localizedDescription UTF8String]);
+                               return;
+                       }
+               }
+
                [mac->player play];
 
                mac->isPlaying = TRUE;