Fixed some synchronization problems.

This commit is contained in:
vspader 2007-10-20 03:24:27 +00:00
parent e78a961fa3
commit 2e44b9833e
2 changed files with 57 additions and 62 deletions

View file

@ -209,45 +209,46 @@
[self requestNextStream: nextStreamUserInfo]; [self requestNextStream: nextStreamUserInfo];
newChain = [[BufferChain alloc] initWithController:self]; newChain = [[BufferChain alloc] initWithController:self];
BufferChain *lastChain = [chainQueue lastObject]; @synchronized (chainQueue) {
if (lastChain == nil) { BufferChain *lastChain = [chainQueue lastObject];
lastChain = bufferChain; if (lastChain == nil) {
} lastChain = bufferChain;
}
if ([[nextStream scheme] isEqualToString:[[lastChain streamURL] scheme]] if ([[nextStream scheme] isEqualToString:[[lastChain streamURL] scheme]]
&& [[nextStream host] isEqualToString:[[lastChain streamURL] host]] && [[nextStream host] isEqualToString:[[lastChain streamURL] host]]
&& [[nextStream path] isEqualToString:[[lastChain streamURL] path]]) && [[nextStream path] isEqualToString:[[lastChain streamURL] path]])
{
if ([lastChain setTrack:nextStream]
&& [newChain openWithInput:[lastChain inputNode] withOutputFormat:[output format]])
{ {
[newChain setStreamURL:nextStream]; if ([lastChain setTrack:nextStream]
[newChain setUserInfo:nextStreamUserInfo]; && [newChain openWithInput:[lastChain inputNode] withOutputFormat:[output format]])
{
[newChain setStreamURL:nextStream];
[newChain setUserInfo:nextStreamUserInfo];
[self addChainToQueue:newChain];
NSLog(@"TRACK SET!!! %@", newChain);
//Keep on-playin
[newChain release];
return NO;
}
}
while (![newChain open:nextStream withOutputFormat:[output format]])
{
if (nextStream == nil)
{
return YES;
}
[self addChainToQueue:newChain];
NSLog(@"TRACK SET!!! %@", newChain);
//Keep on-playin
[newChain release]; [newChain release];
[self requestNextStream: nextStreamUserInfo];
return NO; newChain = [[BufferChain alloc] initWithController:self];
}
}
while (![newChain open:nextStream withOutputFormat:[output format]])
{
if (nextStream == nil)
{
return YES;
} }
[newChain release]; [self addChainToQueue:newChain];
[self requestNextStream: nextStreamUserInfo];
newChain = [[BufferChain alloc] initWithController:self];
} }
[self addChainToQueue:newChain];
[newChain release]; [newChain release];
return YES; return YES;
@ -255,20 +256,20 @@
- (void)endOfInputPlayed - (void)endOfInputPlayed
{ {
if ([chainQueue count] <= 0) @synchronized(chainQueue) {
{ if ([chainQueue count] <= 0)
//End of playlist {
[self stop]; //End of playlist
[self stop];
[bufferChain release];
bufferChain = nil;
return;
}
[bufferChain release]; [bufferChain release];
bufferChain = nil;
return;
}
[bufferChain release];
@synchronized(chainQueue) {
bufferChain = [chainQueue objectAtIndex:0]; bufferChain = [chainQueue objectAtIndex:0];
[bufferChain retain]; [bufferChain retain];

View file

@ -51,7 +51,7 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber
converter->callbackBuffer = malloc(amountToWrite); converter->callbackBuffer = malloc(amountToWrite);
amountRead = [converter readData:converter->callbackBuffer amount:amountToWrite]; amountRead = [converter readData:converter->callbackBuffer amount:amountToWrite];
if (amountRead == 0) if (amountRead == 0 && [converter endOfStream] == NO)
{ {
ioData->mBuffers[0].mDataByteSize = 0; ioData->mBuffers[0].mDataByteSize = 0;
*ioNumberDataPackets = 0; *ioNumberDataPackets = 0;
@ -70,20 +70,10 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber
-(void)process -(void)process
{ {
char writeBuf[CHUNK_SIZE]; char writeBuf[CHUNK_SIZE];
int amountConverted;
while ([self shouldContinue] == YES && [self endOfStream] == NO) //Need to watch EOS somehow....
while ([self shouldContinue] == YES) //Need to watch EOS somehow....
{ {
amountConverted = [self convert:writeBuf amount:CHUNK_SIZE]; int amountConverted = [self convert:writeBuf amount:CHUNK_SIZE];
// NSLog(@"Amount converted %@: %i %i", self, amountConverted, [self endOfStream]);
if (amountConverted == 0 && [self endOfStream] == YES)
{
// NSLog(@"END OF STREAM FOR ZINE DINNER!!!!");
return;
}
[self writeData:writeBuf amount:amountConverted]; [self writeData:writeBuf amount:amountConverted];
} }
} }
@ -101,12 +91,16 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber
ioData.mNumberBuffers = 1; ioData.mNumberBuffers = 1;
err = AudioConverterFillComplexBuffer(converter, ACInputProc, self, &ioNumberFrames, &ioData, NULL); err = AudioConverterFillComplexBuffer(converter, ACInputProc, self, &ioNumberFrames, &ioData, NULL);
int amountRead = ioData.mBuffers[0].mDataByteSize;
if (err == kAudioConverterErr_InvalidInputSize) //It returns insz at EOS at times...so run it again to make sure all data is converted if (err == kAudioConverterErr_InvalidInputSize) //It returns insz at EOS at times...so run it again to make sure all data is converted
{ {
return [self convert:dest amount:amount]; NSLog(@"INSIZE: %i", amountRead);
amountRead += [self convert:dest + amountRead amount:amount - amountRead];
} }
return ioData.mBuffers[0].mDataByteSize; NSLog(@"Amount read: %i/%i", amountRead, amount);
return amountRead;
} }
- (BOOL)setupWithInputFormat:(AudioStreamBasicDescription)inf outputFormat:(AudioStreamBasicDescription)outf - (BOOL)setupWithInputFormat:(AudioStreamBasicDescription)inf outputFormat:(AudioStreamBasicDescription)outf