From 5b73336cb02f9246e347965a1a07af657dd0f8d3 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Wed, 25 Aug 2021 01:57:05 -0700 Subject: [PATCH] CoreAudio input: Optimized file size reporting to cache the file size on open, so file input isn't seeking as much --- Plugins/CoreAudio/CoreAudioDecoder.h | 1 + Plugins/CoreAudio/CoreAudioDecoder.m | 13 ++++--------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/Plugins/CoreAudio/CoreAudioDecoder.h b/Plugins/CoreAudio/CoreAudioDecoder.h index 700e72849..9fae5e922 100644 --- a/Plugins/CoreAudio/CoreAudioDecoder.h +++ b/Plugins/CoreAudio/CoreAudioDecoder.h @@ -29,6 +29,7 @@ @interface CoreAudioDecoder : NSObject { @public long _lastPosition; + @public long _fileSize; id _audioSource; AudioFileID _audioFile; ExtAudioFileRef _in; diff --git a/Plugins/CoreAudio/CoreAudioDecoder.m b/Plugins/CoreAudio/CoreAudioDecoder.m index 6e7c3cfee..c3b78c977 100644 --- a/Plugins/CoreAudio/CoreAudioDecoder.m +++ b/Plugins/CoreAudio/CoreAudioDecoder.m @@ -61,15 +61,7 @@ static SInt64 getSizeProc(void* clientData) { NSObject* _handle = (__bridge NSObject *)(clientData); CoreAudioDecoder * __unsafe_unretained pSelf = (id) _handle; - id source = pSelf->_audioSource; - - SInt64 size; - - [source seek:0 whence:SEEK_END]; - size = [source tell]; - [source seek:pSelf->_lastPosition whence:SEEK_SET]; - - return size; + return pSelf->_fileSize; } @implementation CoreAudioDecoder @@ -114,6 +106,9 @@ static SInt64 getSizeProc(void* clientData) { _audioSource = source; _lastPosition = [source tell]; + [source seek:0 whence:SEEK_END]; + _fileSize = [source tell]; + [source seek:_lastPosition whence:SEEK_SET]; err = AudioFileOpenWithCallbacks((__bridge void *)self, readProc, 0, getSizeProc, 0, 0, &_audioFile); if(noErr != err) {