CoreAudio: Don't try closing resources that aren't opened

CQTexperiment
Christopher Snowhill 2021-05-07 15:33:20 -07:00
parent 7365174b11
commit 79d12e9fc7
2 changed files with 24 additions and 8 deletions

View File

@ -33,6 +33,9 @@
AudioFileID _audioFile; AudioFileID _audioFile;
ExtAudioFileRef _in; ExtAudioFileRef _in;
BOOL _audioFile_opened;
BOOL _in_opened;
int bitrate; int bitrate;
int bitsPerSample; int bitsPerSample;
BOOL floatingPoint; BOOL floatingPoint;

View File

@ -78,14 +78,20 @@ static SInt64 getSizeProc(void* clientData) {
{ {
OSStatus err; OSStatus err;
err = ExtAudioFileDispose(_in); if (_in_opened) {
if(noErr != err) { err = ExtAudioFileDispose(_in);
DLog(@"Error closing ExtAudioFile"); if(noErr != err) {
} DLog(@"Error closing ExtAudioFile");
}
_in_opened = NO;
}
err = AudioFileClose(_audioFile); if (_audioFile_opened) {
if(noErr != err) { err = AudioFileClose(_audioFile);
DLog(@"Error closing AudioFile"); if(noErr != err) {
DLog(@"Error closing AudioFile");
}
_audioFile_opened = NO;
} }
_audioSource = nil; _audioSource = nil;
@ -100,6 +106,9 @@ static SInt64 getSizeProc(void* clientData) {
{ {
OSStatus err; OSStatus err;
_audioFile_opened = NO;
_in_opened = NO;
if (![source seekable]) if (![source seekable])
return NO; return NO;
@ -112,12 +121,16 @@ static SInt64 getSizeProc(void* clientData) {
return NO; return NO;
} }
_audioFile_opened = YES;
err = ExtAudioFileWrapAudioFileID(_audioFile, false, &_in); err = ExtAudioFileWrapAudioFileID(_audioFile, false, &_in);
if(noErr != err) { if(noErr != err) {
ALog(@"Error opening file: %d", err); ALog(@"Error opening file: %d", err);
return NO; return NO;
} }
_in_opened = YES;
return [self readInfoFromExtAudioFileRef]; return [self readInfoFromExtAudioFileRef];
} }