Fixed some synchronization problems.
This commit is contained in:
parent
e78a961fa3
commit
2e44b9833e
2 changed files with 57 additions and 62 deletions
|
@ -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]]
|
|
||||||
&& [[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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[newChain release];
|
if ([[nextStream scheme] isEqualToString:[[lastChain streamURL] scheme]]
|
||||||
[self requestNextStream: nextStreamUserInfo];
|
&& [[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];
|
[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];
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -69,21 +69,11 @@ 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];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NSLog(@"Amount read: %i/%i", amountRead, amount);
|
||||||
|
|
||||||
return ioData.mBuffers[0].mDataByteSize;
|
return amountRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)setupWithInputFormat:(AudioStreamBasicDescription)inf outputFormat:(AudioStreamBasicDescription)outf
|
- (BOOL)setupWithInputFormat:(AudioStreamBasicDescription)inf outputFormat:(AudioStreamBasicDescription)outf
|
||||||
|
|
Loading…
Reference in a new issue