Improve audio buffering situation
Buffer up to 20 seconds per stage, and buffer only up to 2 seconds before starting the next stage. Signed-off-by: Christopher Snowhill <kode54@gmail.com>
This commit is contained in:
parent
fb72db74f8
commit
122b6d6a6d
2 changed files with 25 additions and 19 deletions
|
@ -33,6 +33,8 @@
|
||||||
AudioStreamBasicDescription nodeFormat;
|
AudioStreamBasicDescription nodeFormat;
|
||||||
uint32_t nodeChannelConfig;
|
uint32_t nodeChannelConfig;
|
||||||
BOOL nodeLossless;
|
BOOL nodeLossless;
|
||||||
|
|
||||||
|
double durationPrebuffer;
|
||||||
}
|
}
|
||||||
- (id _Nullable)initWithController:(id _Nonnull)c previous:(id _Nullable)p;
|
- (id _Nullable)initWithController:(id _Nonnull)c previous:(id _Nullable)p;
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
- (id)initWithController:(id)c previous:(id)p {
|
- (id)initWithController:(id)c previous:(id)p {
|
||||||
self = [super init];
|
self = [super init];
|
||||||
if(self) {
|
if(self) {
|
||||||
buffer = [[ChunkList alloc] initWithMaximumDuration:1.0];
|
buffer = [[ChunkList alloc] initWithMaximumDuration:20.0];
|
||||||
semaphore = [[Semaphore alloc] init];
|
semaphore = [[Semaphore alloc] init];
|
||||||
|
|
||||||
accessLock = [[NSLock alloc] init];
|
accessLock = [[NSLock alloc] init];
|
||||||
|
@ -36,6 +36,8 @@
|
||||||
nodeChannelConfig = 0;
|
nodeChannelConfig = 0;
|
||||||
nodeLossless = NO;
|
nodeLossless = NO;
|
||||||
|
|
||||||
|
durationPrebuffer = 2.0;
|
||||||
|
|
||||||
[self setPreviousNode:p];
|
[self setPreviousNode:p];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,17 +68,18 @@
|
||||||
[chunk assignSamples:ptr frameCount:amount / nodeFormat.mBytesPerPacket];
|
[chunk assignSamples:ptr frameCount:amount / nodeFormat.mBytesPerPacket];
|
||||||
|
|
||||||
const double chunkDuration = [chunk duration];
|
const double chunkDuration = [chunk duration];
|
||||||
double durationLeft = [buffer maxDuration] - [buffer listDuration];
|
double durationList = [buffer listDuration];
|
||||||
|
double durationLeft = [buffer maxDuration] - durationList;
|
||||||
|
|
||||||
|
if(shouldContinue == YES && durationList > durationPrebuffer) {
|
||||||
|
if(initialBufferFilled == NO) {
|
||||||
|
initialBufferFilled = YES;
|
||||||
|
if([controller respondsToSelector:@selector(initialBufferFilled:)])
|
||||||
|
[controller performSelector:@selector(initialBufferFilled:) withObject:self];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
while(shouldContinue == YES && chunkDuration > durationLeft) {
|
while(shouldContinue == YES && chunkDuration > durationLeft) {
|
||||||
if(durationLeft < chunkDuration) {
|
|
||||||
if(initialBufferFilled == NO) {
|
|
||||||
initialBufferFilled = YES;
|
|
||||||
if([controller respondsToSelector:@selector(initialBufferFilled:)])
|
|
||||||
[controller performSelector:@selector(initialBufferFilled:) withObject:self];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(durationLeft < chunkDuration || shouldReset) {
|
if(durationLeft < chunkDuration || shouldReset) {
|
||||||
[accessLock unlock];
|
[accessLock unlock];
|
||||||
[semaphore wait];
|
[semaphore wait];
|
||||||
|
@ -95,17 +98,18 @@
|
||||||
[accessLock lock];
|
[accessLock lock];
|
||||||
|
|
||||||
const double chunkDuration = [chunk duration];
|
const double chunkDuration = [chunk duration];
|
||||||
double durationLeft = [buffer maxDuration] - [buffer listDuration];
|
double durationList = [buffer listDuration];
|
||||||
|
double durationLeft = [buffer maxDuration] - durationList;
|
||||||
|
|
||||||
|
if(shouldContinue == YES && durationList > durationPrebuffer) {
|
||||||
|
if(initialBufferFilled == NO) {
|
||||||
|
initialBufferFilled = YES;
|
||||||
|
if([controller respondsToSelector:@selector(initialBufferFilled:)])
|
||||||
|
[controller performSelector:@selector(initialBufferFilled:) withObject:self];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
while(shouldContinue == YES && chunkDuration > durationLeft) {
|
while(shouldContinue == YES && chunkDuration > durationLeft) {
|
||||||
if(durationLeft < chunkDuration) {
|
|
||||||
if(initialBufferFilled == NO) {
|
|
||||||
initialBufferFilled = YES;
|
|
||||||
if([controller respondsToSelector:@selector(initialBufferFilled:)])
|
|
||||||
[controller performSelector:@selector(initialBufferFilled:) withObject:self];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(durationLeft < chunkDuration || shouldReset) {
|
if(durationLeft < chunkDuration || shouldReset) {
|
||||||
[accessLock unlock];
|
[accessLock unlock];
|
||||||
[semaphore wait];
|
[semaphore wait];
|
||||||
|
|
Loading…
Reference in a new issue