From 139bab5e0e09953a28be43ded74565eb05ff93a7 Mon Sep 17 00:00:00 2001 From: vspader Date: Fri, 12 Oct 2007 02:55:59 +0000 Subject: [PATCH] Fixed up streaming a bit. Removed debugging code for http source. Was that in 0.06? Whoops. --- Audio/Chain/BufferChain.h | 6 ++++- Audio/Chain/BufferChain.m | 26 +++++++++++++++++---- Audio/Chain/ConverterNode.h | 4 ++++ Audio/Chain/ConverterNode.m | 19 ++++++++++++++- Audio/Chain/InputNode.m | 7 ++++-- Audio/Chain/Node.m | 4 ++-- Cog.xcodeproj/project.pbxproj | 8 +++---- Plugins/CueSheet/CueSheetDecoder.m | 4 ++++ Plugins/Dumb/Dumb.xcodeproj/project.pbxproj | 4 ++-- Plugins/Dumb/DumbDecoder.m | 3 +++ Plugins/GME/GME.xcodeproj/project.pbxproj | 4 ++-- Plugins/GME/GameDecoder.m | 3 +++ Plugins/HTTPSource/HTTPSource.m | 25 +++++++++++--------- Plugins/MAD/MADDecoder.m | 1 + 14 files changed, 88 insertions(+), 30 deletions(-) diff --git a/Audio/Chain/BufferChain.h b/Audio/Chain/BufferChain.h index b46435b30..4975364f5 100644 --- a/Audio/Chain/BufferChain.h +++ b/Audio/Chain/BufferChain.h @@ -16,6 +16,8 @@ InputNode *inputNode; ConverterNode *converterNode; + BOOL converterLaunched; + NSURL *streamURL; id userInfo; @@ -48,9 +50,11 @@ - (void)setShouldContinue:(BOOL)s; -- (void)initialBufferFilled; +- (void)initialBufferFilled:(id)sender; - (BOOL)endOfInputReached; - (BOOL)setTrack:(NSURL *)track; +- (void)inputFormatDidChange:(AudioStreamBasicDescription)format; + @end diff --git a/Audio/Chain/BufferChain.m b/Audio/Chain/BufferChain.m index 159ff52bc..8d718e1e5 100644 --- a/Audio/Chain/BufferChain.m +++ b/Audio/Chain/BufferChain.m @@ -24,6 +24,8 @@ inputNode = nil; converterNode = nil; + + converterLaunched = NO; } return self; @@ -47,7 +49,7 @@ [self buildChain]; id source = [AudioSource audioSourceForURL:url]; - + NSLog(@"Opening: %@", url); if (![source open:url]) { NSLog(@"Couldn't open source..."); @@ -55,11 +57,12 @@ } + [converterNode setOutputFormat:outputFormat]; + if (![inputNode openURL:url withSource:source]) return NO; - if (![converterNode setupWithInputFormat:propertiesToASBD([inputNode properties]) outputFormat:outputFormat]) - return NO; +// return NO; return YES; } @@ -76,6 +79,8 @@ return NO; NSLog(@"Buffer chain made"); + [converterNode launchThread]; + return YES; } @@ -84,7 +89,6 @@ NSLog(@"Properties: %@", [inputNode properties]); [inputNode launchThread]; - [converterNode launchThread]; } - (void)setUserInfo:(id)i @@ -124,11 +128,23 @@ return [inputNode setTrack:track]; } -- (void)initialBufferFilled +- (void)initialBufferFilled:(id)sender { + NSLog(@"INITIAL BUFFER FILLED"); [controller launchOutputThread]; } +- (void)inputFormatDidChange:(AudioStreamBasicDescription)format +{ + NSLog(@"FORMAT DID CHANGE!"); + if (!converterLaunched) { + converterLaunched = YES; + [converterNode inputFormatDidChange:format]; + [converterNode launchThread]; + } +} + + - (InputNode *)inputNode { return inputNode; diff --git a/Audio/Chain/ConverterNode.h b/Audio/Chain/ConverterNode.h index e537e3067..1aff0bc1d 100644 --- a/Audio/Chain/ConverterNode.h +++ b/Audio/Chain/ConverterNode.h @@ -28,4 +28,8 @@ - (void)process; - (int)convert:(void *)dest amount:(int)amount; +- (void)setOutputFormat:(AudioStreamBasicDescription)format; + +- (void)inputFormatDidChange:(AudioStreamBasicDescription)format; + @end diff --git a/Audio/Chain/ConverterNode.m b/Audio/Chain/ConverterNode.m index ea04dac7c..89c183ebc 100644 --- a/Audio/Chain/ConverterNode.m +++ b/Audio/Chain/ConverterNode.m @@ -140,9 +140,26 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber return YES; } +- (void)setOutputFormat:(AudioStreamBasicDescription)format +{ + NSLog(@"SETTING OUTPUT FORMAT!"); + outputFormat = format; +} + +- (void)inputFormatDidChange:(AudioStreamBasicDescription)format +{ + NSLog(@"FORMAT CHANGED"); + [self cleanUp]; + [self setupWithInputFormat:format outputFormat:outputFormat]; +} + - (void)cleanUp { - AudioConverterDispose(converter); + if (converter) + { + AudioConverterDispose(converter); + converter = NULL; + } } @end diff --git a/Audio/Chain/InputNode.m b/Audio/Chain/InputNode.m index 73c3bef08..d91ec0fac 100644 --- a/Audio/Chain/InputNode.m +++ b/Audio/Chain/InputNode.m @@ -53,6 +53,7 @@ - (void)registerObservers { + NSLog(@"REGISTERING OBSERVERS"); [decoder addObserver:self forKeyPath:@"properties" options:(NSKeyValueObservingOptionNew) @@ -69,9 +70,11 @@ change:(NSDictionary *)change context:(void *)context { + NSLog(@"SOMETHING CHANGED!"); if ([keyPath isEqual:@"properties"]) { //Setup converter! //Inform something of properties change + [controller inputFormatDidChange: propertiesToASBD([decoder properties])]; } else if ([keyPath isEqual:@"metadata"]) { //Inform something of metadata change @@ -107,10 +110,10 @@ if (amountRead <= 0) { if (initialBufferFilled == NO) { - [controller initialBufferFilled]; + [controller initialBufferFilled:self]; } - NSLog(@"End of stream?"); + NSLog(@"End of stream? %@", [self properties]); endOfStream = YES; shouldClose = [controller endOfInputReached]; //Lets us know if we should keep going or not (occassionally, for track changes within a file) NSLog(@"closing? is %i", shouldClose); diff --git a/Audio/Chain/Node.m b/Audio/Chain/Node.m index e3b82160d..d3bde5a89 100644 --- a/Audio/Chain/Node.m +++ b/Audio/Chain/Node.m @@ -44,8 +44,8 @@ if (availOutput == 0) { if (initialBufferFilled == NO) { initialBufferFilled = YES; - if ([controller respondsToSelector:@selector(initialBufferFilled)]) - [controller performSelector:@selector(initialBufferFilled)]; + if ([controller respondsToSelector:@selector(initialBufferFilled:)]) + [controller performSelector:@selector(initialBufferFilled:) withObject:self]; } } diff --git a/Cog.xcodeproj/project.pbxproj b/Cog.xcodeproj/project.pbxproj index 02450aaca..0434ef16c 100644 --- a/Cog.xcodeproj/project.pbxproj +++ b/Cog.xcodeproj/project.pbxproj @@ -286,28 +286,28 @@ isa = PBXContainerItemProxy; containerPortal = 17C8F3C80CBED663008D969D /* GME.xcodeproj */; proxyType = 2; - remoteGlobalIDString = 8D5B49B6048680CD000E48DA /* GME.bundle */; + remoteGlobalIDString = 8D5B49B6048680CD000E48DA; remoteInfo = "GME Plugin"; }; 17C8F44B0CBEDD37008D969D /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 17C8F3C80CBED663008D969D /* GME.xcodeproj */; proxyType = 1; - remoteGlobalIDString = 8D5B49AC048680CD000E48DA /* GME Plugin */; + remoteGlobalIDString = 8D5B49AC048680CD000E48DA; remoteInfo = "GME Plugin"; }; 17C8F7D60CBEF3E8008D969D /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 17C8F7D20CBEF3E8008D969D /* Dumb.xcodeproj */; proxyType = 2; - remoteGlobalIDString = 8D5B49B6048680CD000E48DA /* Dumb.bundle */; + remoteGlobalIDString = 8D5B49B6048680CD000E48DA; remoteInfo = Dumb; }; 17C8F7D90CBEF3F9008D969D /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 17C8F7D20CBEF3E8008D969D /* Dumb.xcodeproj */; proxyType = 1; - remoteGlobalIDString = 8D5B49AC048680CD000E48DA /* Dumb */; + remoteGlobalIDString = 8D5B49AC048680CD000E48DA; remoteInfo = Dumb; }; 17F3BB870CBC565100864489 /* PBXContainerItemProxy */ = { diff --git a/Plugins/CueSheet/CueSheetDecoder.m b/Plugins/CueSheet/CueSheetDecoder.m index a1e087ab9..23b2047e1 100644 --- a/Plugins/CueSheet/CueSheetDecoder.m +++ b/Plugins/CueSheet/CueSheetDecoder.m @@ -87,6 +87,10 @@ trackEnd = [[properties objectForKey:@"length"] doubleValue]/1000.0; } + //Note: Should register for observations of the decoder, but laziness consumes all. + [self willChangeValueForKey:@"properties"]; + [self didChangeValueForKey:@"properties"]; + return YES; } } diff --git a/Plugins/Dumb/Dumb.xcodeproj/project.pbxproj b/Plugins/Dumb/Dumb.xcodeproj/project.pbxproj index 4895d9d7f..179fd0445 100644 --- a/Plugins/Dumb/Dumb.xcodeproj/project.pbxproj +++ b/Plugins/Dumb/Dumb.xcodeproj/project.pbxproj @@ -22,14 +22,14 @@ isa = PBXContainerItemProxy; containerPortal = 17C8F6990CBEE857008D969D /* Dumb.xcodeproj */; proxyType = 2; - remoteGlobalIDString = 8DC2EF5B0486A6940098B216 /* Dumb.framework */; + remoteGlobalIDString = 8DC2EF5B0486A6940098B216; remoteInfo = "Dumb Framework"; }; 17C8F6A00CBEE867008D969D /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 17C8F6990CBEE857008D969D /* Dumb.xcodeproj */; proxyType = 1; - remoteGlobalIDString = 8DC2EF4F0486A6940098B216 /* Dumb Framework */; + remoteGlobalIDString = 8DC2EF4F0486A6940098B216; remoteInfo = "Dumb Framework"; }; /* End PBXContainerItemProxy section */ diff --git a/Plugins/Dumb/DumbDecoder.m b/Plugins/Dumb/DumbDecoder.m index ae6e03aea..87f025489 100755 --- a/Plugins/Dumb/DumbDecoder.m +++ b/Plugins/Dumb/DumbDecoder.m @@ -97,6 +97,9 @@ void closeCallback(void *f) return NO; } + [self willChangeValueForKey:@"properties"]; + [self didChangeValueForKey:@"properties"]; + return YES; } diff --git a/Plugins/GME/GME.xcodeproj/project.pbxproj b/Plugins/GME/GME.xcodeproj/project.pbxproj index cdca6bc03..f9ae09e82 100644 --- a/Plugins/GME/GME.xcodeproj/project.pbxproj +++ b/Plugins/GME/GME.xcodeproj/project.pbxproj @@ -27,14 +27,14 @@ isa = PBXContainerItemProxy; containerPortal = 17C8F3320CBED393008D969D /* GME.xcodeproj */; proxyType = 2; - remoteGlobalIDString = 8DC2EF5B0486A6940098B216 /* GME.framework */; + remoteGlobalIDString = 8DC2EF5B0486A6940098B216; remoteInfo = GME; }; 17C8F4350CBEDD28008D969D /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 17C8F3320CBED393008D969D /* GME.xcodeproj */; proxyType = 1; - remoteGlobalIDString = 8DC2EF4F0486A6940098B216 /* GME Framework */; + remoteGlobalIDString = 8DC2EF4F0486A6940098B216; remoteInfo = "GME Framework"; }; /* End PBXContainerItemProxy section */ diff --git a/Plugins/GME/GameDecoder.m b/Plugins/GME/GameDecoder.m index e986efeed..f97f542c0 100755 --- a/Plugins/GME/GameDecoder.m +++ b/Plugins/GME/GameDecoder.m @@ -98,6 +98,9 @@ gme_err_t readCallback( void* data, void* out, long count ) NSLog(@"Error starting track"); return NO; } + + [self willChangeValueForKey:@"properties"]; + [self didChangeValueForKey:@"properties"]; return YES; } diff --git a/Plugins/HTTPSource/HTTPSource.m b/Plugins/HTTPSource/HTTPSource.m index c4c19a008..65d9a88b1 100644 --- a/Plugins/HTTPSource/HTTPSource.m +++ b/Plugins/HTTPSource/HTTPSource.m @@ -25,8 +25,9 @@ port = 80; _socket = [[Socket alloc] initWithHost:[url host] port:port]; - + NSLog(@"SOCKET?"); if (_socket) { + NSLog(@"WE HAVE A SOCKET!"); NSData *request = [[NSString stringWithFormat:@"GET %@ HTTP/1.0\nHOST: %@\n\n",[url path],[url host]] dataUsingEncoding:NSUTF8StringEncoding]; [_socket send:(void *)[request bytes] amount:[request length]]; pastHeader = NO; @@ -57,15 +58,17 @@ - (int)read:(void *)buffer amount:(int)amount { + NSLog(@"READING DATA: %i", amount); if (!pastHeader) { const int delimeter_size = 4; //\r\n\r\n - FILE *testFout = fopen("header.raw", "w"); +// FILE *testFout = fopen("/Users/vspader/header.raw", "w"); int l = [_socket receive:buffer amount:amount]; + NSLog(@"Received data: %i", l); uint8_t *f; while(NULL == (f = (uint8_t *)strnstr((const char *)buffer, "\r\n\r\n", l))) { - fwrite(buffer, 1,l, testFout); +// fwrite(buffer, 1,l, testFout); //Need to check for boundary conditions memmove(buffer, (uint8_t *)buffer + (l - delimeter_size), delimeter_size); l = delimeter_size + [_socket receive:((uint8_t *)buffer + delimeter_size) amount:(amount - delimeter_size)]; @@ -79,12 +82,12 @@ //For testing only - fwrite(buffer, 1, bufferOffset - (uint8_t *)buffer, testFout); - fclose(testFout); +// fwrite(buffer, 1, bufferOffset - (uint8_t *)buffer, testFout); +// fclose(testFout); - testFout = fopen("test.raw", "w"); - fwrite(bufferOffset, 1, amountRemaining, testFout); - fclose(testFout); +// testFout = fopen("/Users/vspader/test.raw", "w"); +// fwrite(bufferOffset, 1, amountRemaining, testFout); +// fclose(testFout); memmove(buffer,bufferOffset, amountRemaining); @@ -96,9 +99,9 @@ //FOR TESTING ONLY - FILE *testFout = fopen("test.raw", "a"); - fwrite(buffer, 1, l, testFout); - fclose(testFout); +// FILE *testFout = fopen("/Users/vspader/test.raw", "a"); +// fwrite(buffer, 1, l, testFout); +// fclose(testFout); if (l > 0) byteCount += l; diff --git a/Plugins/MAD/MADDecoder.m b/Plugins/MAD/MADDecoder.m index 22787a518..9456f6c83 100644 --- a/Plugins/MAD/MADDecoder.m +++ b/Plugins/MAD/MADDecoder.m @@ -512,6 +512,7 @@ static inline signed int scale (mad_fixed_t sample) continue; } + if (_firstFrame && ![_source seekable]) { frequency = _frame.header.samplerate; channels = MAD_NCHANNELS(&_frame.header);