From 79d12e9fc782629ab6398ce1f8cb8a4c27ed6992 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Fri, 7 May 2021 15:33:20 -0700 Subject: [PATCH] CoreAudio: Don't try closing resources that aren't opened --- Plugins/CoreAudio/CoreAudioDecoder.h | 3 +++ Plugins/CoreAudio/CoreAudioDecoder.m | 29 ++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/Plugins/CoreAudio/CoreAudioDecoder.h b/Plugins/CoreAudio/CoreAudioDecoder.h index dde98eec7..700e72849 100644 --- a/Plugins/CoreAudio/CoreAudioDecoder.h +++ b/Plugins/CoreAudio/CoreAudioDecoder.h @@ -33,6 +33,9 @@ AudioFileID _audioFile; ExtAudioFileRef _in; + BOOL _audioFile_opened; + BOOL _in_opened; + int bitrate; int bitsPerSample; BOOL floatingPoint; diff --git a/Plugins/CoreAudio/CoreAudioDecoder.m b/Plugins/CoreAudio/CoreAudioDecoder.m index 8ced2c93a..6e7c3cfee 100644 --- a/Plugins/CoreAudio/CoreAudioDecoder.m +++ b/Plugins/CoreAudio/CoreAudioDecoder.m @@ -77,15 +77,21 @@ static SInt64 getSizeProc(void* clientData) { - (void) close { OSStatus err; - - err = ExtAudioFileDispose(_in); - if(noErr != err) { - DLog(@"Error closing ExtAudioFile"); - } + + if (_in_opened) { + err = ExtAudioFileDispose(_in); + if(noErr != err) { + DLog(@"Error closing ExtAudioFile"); + } + _in_opened = NO; + } - err = AudioFileClose(_audioFile); - if(noErr != err) { - DLog(@"Error closing AudioFile"); + if (_audioFile_opened) { + err = AudioFileClose(_audioFile); + if(noErr != err) { + DLog(@"Error closing AudioFile"); + } + _audioFile_opened = NO; } _audioSource = nil; @@ -100,6 +106,9 @@ static SInt64 getSizeProc(void* clientData) { { OSStatus err; + _audioFile_opened = NO; + _in_opened = NO; + if (![source seekable]) return NO; @@ -112,11 +121,15 @@ static SInt64 getSizeProc(void* clientData) { return NO; } + _audioFile_opened = YES; + err = ExtAudioFileWrapAudioFileID(_audioFile, false, &_in); if(noErr != err) { ALog(@"Error opening file: %d", err); return NO; } + + _in_opened = YES; return [self readInfoFromExtAudioFileRef]; }