mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-03 06:55:59 +00:00
Don't crash when recording starts with an invalid input format
AudioRecorder.startRecording crashed AVAudioEngine (IsFormatSampleRateAndChannelCountValid) when the input node reported an invalid format - e.g. a zero sample rate when no input route is available. Bail out with an error before connecting nodes or installing the tap.
This commit is contained in:
@@ -166,7 +166,15 @@ nonisolated class AudioRecorder: AudioRecorderProtocol, @unchecked Sendable {
|
|||||||
|
|
||||||
let inputNode = audioEngine.inputNode
|
let inputNode = audioEngine.inputNode
|
||||||
let inputFormat = inputNode.outputFormat(forBus: 0)
|
let inputFormat = inputNode.outputFormat(forBus: 0)
|
||||||
let hardwareSampleRate = audioEngine.inputNode.outputFormat(forBus: 0).sampleRate
|
let hardwareSampleRate = inputFormat.sampleRate
|
||||||
|
|
||||||
|
// The input format can be invalid (e.g. a zero sample rate) when no input route is
|
||||||
|
// available, which would crash AVAudioEngine when connecting nodes or installing the tap.
|
||||||
|
guard inputFormat.sampleRate > 0, inputFormat.channelCount > 0 else {
|
||||||
|
MXLog.error("Invalid input audio format, can't record: \(inputFormat)")
|
||||||
|
completion(.failure(.unsupportedAudioFormat))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Define a recording audio format. Force the sample rate to 48000 to ensure OGGEncoder won't crash
|
// Define a recording audio format. Force the sample rate to 48000 to ensure OGGEncoder won't crash
|
||||||
guard let recordingFormat = AVAudioFormat(standardFormatWithSampleRate: 48000, channels: 1) else {
|
guard let recordingFormat = AVAudioFormat(standardFormatWithSampleRate: 48000, channels: 1) else {
|
||||||
|
|||||||
Reference in New Issue
Block a user