Skip to content

Commit

Permalink
Add defer with unlockForConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
vadymmarkov committed Nov 3, 2023
1 parent 93aa033 commit 12a07ef
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Sources/PexipRTC/Internal/WebRTCAudioSession.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2022-2023 Pexip AS
// Copyright 2023 Pexip AS
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -65,6 +65,9 @@ final actor WebRTCAudioSession: AudioSessionConfigurator {
configuration: AudioConfiguration
) throws {
audioSession.lockForConfiguration()
defer {
audioSession.unlockForConfiguration()
}

let rtcConfiguration = RTCAudioSessionConfiguration.webRTC()
rtcConfiguration.mode = configuration.mode.rawValue
Expand All @@ -74,17 +77,18 @@ final actor WebRTCAudioSession: AudioSessionConfigurator {
try audioSession.setConfiguration(rtcConfiguration)
try audioSession.setActive(isActive)

audioSession.unlockForConfiguration()

self.isActive = isActive
self.configuration = configuration
}

private func overrideOutputAudioPort(_ port: AVAudioSession.PortOverride) {
audioSession.lockForConfiguration()
defer {
audioSession.unlockForConfiguration()
}

do {
audioSession.lockForConfiguration()
try self.audioSession.overrideOutputAudioPort(port)
audioSession.unlockForConfiguration()
} catch {
logger?.error("Error overriding AVAudioSession output audio port: \(error)")
}
Expand Down

0 comments on commit 12a07ef

Please sign in to comment.