Fixed some synchronization problems.

CQTexperiment
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];
newChain = [[BufferChain alloc] initWithController:self];
BufferChain *lastChain = [chainQueue lastObject];
if (lastChain == nil) {
lastChain = bufferChain;
}
if ([[nextStream scheme] isEqualToString:[[lastChain streamURL] scheme]]
&& [[nextStream host] isEqualToString:[[lastChain streamURL] host]]
&& [[nextStream path] isEqualToString:[[lastChain streamURL] path]])
{
if ([lastChain setTrack:nextStream]
&& [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;
@synchronized (chainQueue) {
BufferChain *lastChain = [chainQueue lastObject];
if (lastChain == nil) {
lastChain = bufferChain;
}
[newChain release];
[self requestNextStream: nextStreamUserInfo];
if ([[nextStream scheme] isEqualToString:[[lastChain streamURL] scheme]]
&& [[nextStream host] isEqualToString:[[lastChain streamURL] host]]
&& [[nextStream path] isEqualToString:[[lastChain streamURL] path]])
{
if ([lastChain setTrack:nextStream]
&& [newChain openWithInput:[lastChain inputNode] withOutputFormat:[output format]])
{
[newChain setStreamURL:nextStream];
[newChain setUserInfo:nextStreamUserInfo];
newChain = [[BufferChain alloc] initWithController:self];
[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;
}
[newChain release];
[self requestNextStream: nextStreamUserInfo];
newChain = [[BufferChain alloc] initWithController:self];
}
[self addChainToQueue:newChain];
}
[self addChainToQueue:newChain];
[newChain release];
return YES;
@ -255,20 +256,20 @@
- (void)endOfInputPlayed
{
if ([chainQueue count] <= 0)
{
//End of playlist
[self stop];
@synchronized(chainQueue) {
if ([chainQueue count] <= 0)
{
//End of playlist
[self stop];
[bufferChain release];
bufferChain = nil;
return;
}
[bufferChain release];
bufferChain = nil;
return;
}
[bufferChain release];
@synchronized(chainQueue) {
bufferChain = [chainQueue objectAtIndex:0];
[bufferChain retain];

View File

@ -51,7 +51,7 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber
converter->callbackBuffer = malloc(amountToWrite);
amountRead = [converter readData:converter->callbackBuffer amount:amountToWrite];
if (amountRead == 0)
if (amountRead == 0 && [converter endOfStream] == NO)
{
ioData->mBuffers[0].mDataByteSize = 0;
*ioNumberDataPackets = 0;
@ -69,21 +69,11 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber
-(void)process
{
char writeBuf[CHUNK_SIZE];
int amountConverted;
char writeBuf[CHUNK_SIZE];
while ([self shouldContinue] == YES) //Need to watch EOS somehow....
while ([self shouldContinue] == YES && [self endOfStream] == NO) //Need to watch EOS somehow....
{
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;
}
int amountConverted = [self convert:writeBuf amount:CHUNK_SIZE];
[self writeData:writeBuf amount:amountConverted];
}
}
@ -101,12 +91,16 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber
ioData.mNumberBuffers = 1;
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
{
return [self convert:dest amount:amount];
NSLog(@"INSIZE: %i", amountRead);
amountRead += [self convert:dest + amountRead amount:amount - amountRead];
}
NSLog(@"Amount read: %i/%i", amountRead, amount);
return ioData.mBuffers[0].mDataByteSize;
return amountRead;
}
- (BOOL)setupWithInputFormat:(AudioStreamBasicDescription)inf outputFormat:(AudioStreamBasicDescription)outf