CoreAudio input: Optimized file size reporting to cache the file size on open, so file input isn't seeking as much

This commit is contained in:
Christopher Snowhill 2021-08-25 01:57:05 -07:00
parent a1a0bd2db4
commit 5b73336cb0
2 changed files with 5 additions and 9 deletions

View file

@ -29,6 +29,7 @@
@interface CoreAudioDecoder : NSObject <CogDecoder> @interface CoreAudioDecoder : NSObject <CogDecoder>
{ {
@public long _lastPosition; @public long _lastPosition;
@public long _fileSize;
id<CogSource> _audioSource; id<CogSource> _audioSource;
AudioFileID _audioFile; AudioFileID _audioFile;
ExtAudioFileRef _in; ExtAudioFileRef _in;

View file

@ -61,15 +61,7 @@ static SInt64 getSizeProc(void* clientData) {
NSObject* _handle = (__bridge NSObject *)(clientData); NSObject* _handle = (__bridge NSObject *)(clientData);
CoreAudioDecoder * __unsafe_unretained pSelf = (id) _handle; CoreAudioDecoder * __unsafe_unretained pSelf = (id) _handle;
id<CogSource> source = pSelf->_audioSource; return pSelf->_fileSize;
SInt64 size;
[source seek:0 whence:SEEK_END];
size = [source tell];
[source seek:pSelf->_lastPosition whence:SEEK_SET];
return size;
} }
@implementation CoreAudioDecoder @implementation CoreAudioDecoder
@ -114,6 +106,9 @@ static SInt64 getSizeProc(void* clientData) {
_audioSource = source; _audioSource = source;
_lastPosition = [source tell]; _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); err = AudioFileOpenWithCallbacks((__bridge void *)self, readProc, 0, getSizeProc, 0, 0, &_audioFile);
if(noErr != err) { if(noErr != err) {