Changed DataSources to open on-demand and also for callback registration to be performed before opening
This commit is contained in:
parent
951f905516
commit
ca7abd75c1
|
|
@ -51,7 +51,6 @@ typedef enum
|
|||
AudioPlayerInternalStatePlaying = (1 << 1) | AudioPlayerInternalStateRunning,
|
||||
AudioPlayerInternalStateStartingThread = (1 << 2) | AudioPlayerInternalStateRunning,
|
||||
AudioPlayerInternalStateWaitingForData = (1 << 3) | AudioPlayerInternalStateRunning,
|
||||
AudioPlayerInternalStateWaitingForQueueToStart = (1 << 4) | AudioPlayerInternalStateRunning,
|
||||
AudioPlayerInternalStatePaused = (1 << 5) | AudioPlayerInternalStateRunning,
|
||||
AudioPlayerInternalStateRebuffering = (1 << 6) | AudioPlayerInternalStateRunning,
|
||||
AudioPlayerInternalStateFlushingAndStoppingButStillPlaying = (1 << 7) | AudioPlayerInternalStateRunning,
|
||||
|
|
|
|||
|
|
@ -42,10 +42,10 @@
|
|||
#import "libkern/OSAtomic.h"
|
||||
|
||||
#define BitRateEstimationMinPackets (64)
|
||||
#define AudioPlayerBuffersNeededToStart (8)
|
||||
#define AudioPlayerBuffersNeededToStart (16)
|
||||
#define AudioPlayerDefaultReadBufferSize (2 * 1024)
|
||||
#define AudioPlayerDefaultPacketBufferSize (4096)
|
||||
#define AudioPlayerDefaultNumberOfAudioQueueBuffers (500)
|
||||
#define AudioPlayerDefaultNumberOfAudioQueueBuffers (1024)
|
||||
|
||||
#define OSSTATUS_PARAM_ERROR (-50)
|
||||
|
||||
|
|
@ -421,7 +421,6 @@ static void AudioQueueIsRunningCallbackProc(void* userData, AudioQueueRef audioQ
|
|||
case AudioPlayerInternalStateRunning:
|
||||
case AudioPlayerInternalStateStartingThread:
|
||||
case AudioPlayerInternalStateWaitingForData:
|
||||
case AudioPlayerInternalStateWaitingForQueueToStart:
|
||||
case AudioPlayerInternalStatePlaying:
|
||||
case AudioPlayerInternalStateRebuffering:
|
||||
case AudioPlayerInternalStateFlushingAndStoppingButStillPlaying:
|
||||
|
|
@ -1211,14 +1210,13 @@ static void AudioQueueIsRunningCallbackProc(void* userData, AudioQueueRef audioQ
|
|||
if (self.internalState == AudioPlayerInternalStateStopped
|
||||
|| self.internalState == AudioPlayerInternalStateStopping
|
||||
|| self.internalState == AudioPlayerInternalStateDisposed
|
||||
|| self.internalState == AudioPlayerInternalStateError
|
||||
|| self.internalState == AudioPlayerInternalStateWaitingForQueueToStart)
|
||||
|| self.internalState == AudioPlayerInternalStateError)
|
||||
{
|
||||
signal = waiting || numberOfBuffersUsed < 8;
|
||||
signal = waiting || numberOfBuffersUsed < (AudioPlayerBuffersNeededToStart * 2);
|
||||
}
|
||||
else if (audioQueueFlushing)
|
||||
{
|
||||
signal = signal || (audioQueueFlushing && numberOfBuffersUsed < 8);
|
||||
signal = signal || (audioQueueFlushing && numberOfBuffersUsed < (AudioPlayerBuffersNeededToStart * 2));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -1228,7 +1226,7 @@ static void AudioQueueIsRunningCallbackProc(void* userData, AudioQueueRef audioQ
|
|||
}
|
||||
else
|
||||
{
|
||||
if ((waiting && numberOfBuffersUsed < audioQueueBufferCount / 2) || (numberOfBuffersUsed < 8))
|
||||
if ((waiting && numberOfBuffersUsed < audioQueueBufferCount / 2) || (numberOfBuffersUsed < (AudioPlayerBuffersNeededToStart * 2)))
|
||||
{
|
||||
signal = YES;
|
||||
}
|
||||
|
|
@ -1309,10 +1307,6 @@ static void AudioQueueIsRunningCallbackProc(void* userData, AudioQueueRef audioQ
|
|||
|
||||
pthread_mutex_unlock(&queueBuffersMutex);
|
||||
}
|
||||
else if (self.internalState == AudioPlayerInternalStateWaitingForQueueToStart)
|
||||
{
|
||||
self.internalState = AudioPlayerInternalStatePlaying;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1770,12 +1764,8 @@ static void AudioQueueIsRunningCallbackProc(void* userData, AudioQueueRef audioQ
|
|||
currentlyReadingEntry = entry;
|
||||
currentlyReadingEntry.dataSource.delegate = self;
|
||||
|
||||
if (currentlyReadingEntry.dataSource.position != 0)
|
||||
{
|
||||
[currentlyReadingEntry.dataSource seekToOffset:0];
|
||||
}
|
||||
|
||||
[currentlyReadingEntry.dataSource registerForEvents:[NSRunLoop currentRunLoop]];
|
||||
[currentlyReadingEntry.dataSource seekToOffset:0];
|
||||
|
||||
if (startPlaying)
|
||||
{
|
||||
|
|
@ -2169,8 +2159,6 @@ static void AudioQueueIsRunningCallbackProc(void* userData, AudioQueueRef audioQ
|
|||
{
|
||||
OSStatus error;
|
||||
|
||||
self.internalState = AudioPlayerInternalStateWaitingForQueueToStart;
|
||||
|
||||
AudioQueueSetParameter(audioQueue, kAudioQueueParam_Volume, 1);
|
||||
|
||||
error = AudioQueueStart(audioQueue, NULL);
|
||||
|
|
@ -2189,14 +2177,14 @@ static void AudioQueueIsRunningCallbackProc(void* userData, AudioQueueRef audioQ
|
|||
|
||||
if (audioQueue != nil)
|
||||
{
|
||||
self.internalState = AudioPlayerInternalStateWaitingForQueueToStart;
|
||||
|
||||
AudioQueueStart(audioQueue, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
[self stopSystemBackgroundTask];
|
||||
|
||||
self.internalState = AudioPlayerInternalStatePlaying;
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,5 +56,6 @@
|
|||
-(void) dataAvailable;
|
||||
-(void) eof;
|
||||
-(void) errorOccured;
|
||||
-(void) open;
|
||||
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -105,6 +105,10 @@ static void ReadStreamCallbackProc(CFReadStreamRef stream, CFStreamEventType eve
|
|||
}
|
||||
}
|
||||
|
||||
-(void) open
|
||||
{
|
||||
}
|
||||
|
||||
-(void) seekToOffset:(long long)offset
|
||||
{
|
||||
}
|
||||
|
|
|
|||
|
|
@ -294,6 +294,8 @@
|
|||
CFReadStreamSetProperty(stream, kCFStreamPropertySSLSettings, (__bridge CFTypeRef)sslSettings);
|
||||
}
|
||||
|
||||
[self reregisterForEvents];
|
||||
|
||||
// Open
|
||||
|
||||
if (!CFReadStreamOpen(stream))
|
||||
|
|
@ -308,11 +310,6 @@
|
|||
|
||||
self->isInErrorState = NO;
|
||||
|
||||
if (self->eventsRunLoop)
|
||||
{
|
||||
[self reregisterForEvents];
|
||||
}
|
||||
|
||||
CFRelease(message);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,8 +53,6 @@
|
|||
{
|
||||
self.filePath = filePathIn;
|
||||
|
||||
[self open];
|
||||
|
||||
audioFileTypeHint = [STKLocalFileDataSource audioFileTypeHintFromFileExtension:filePathIn.pathExtension];
|
||||
}
|
||||
|
||||
|
|
@ -107,6 +105,7 @@
|
|||
{
|
||||
if (stream)
|
||||
{
|
||||
[self unregisterForEvents];
|
||||
CFReadStreamClose(stream);
|
||||
|
||||
stream = 0;
|
||||
|
|
@ -117,6 +116,8 @@
|
|||
{
|
||||
if (stream)
|
||||
{
|
||||
[self unregisterForEvents];
|
||||
|
||||
CFReadStreamClose(stream);
|
||||
CFRelease(stream);
|
||||
|
||||
|
|
@ -146,6 +147,8 @@
|
|||
length = number.longLongValue;
|
||||
}
|
||||
|
||||
[self reregisterForEvents];
|
||||
|
||||
CFReadStreamOpen(stream);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue