Fixed up streaming a bit.

Removed debugging code for http source. Was that in 0.06? Whoops.
This commit is contained in:
vspader 2007-10-12 02:55:59 +00:00
parent 5d2e4f6d4a
commit 139bab5e0e
14 changed files with 88 additions and 30 deletions

View file

@ -16,6 +16,8 @@
InputNode *inputNode; InputNode *inputNode;
ConverterNode *converterNode; ConverterNode *converterNode;
BOOL converterLaunched;
NSURL *streamURL; NSURL *streamURL;
id userInfo; id userInfo;
@ -48,9 +50,11 @@
- (void)setShouldContinue:(BOOL)s; - (void)setShouldContinue:(BOOL)s;
- (void)initialBufferFilled; - (void)initialBufferFilled:(id)sender;
- (BOOL)endOfInputReached; - (BOOL)endOfInputReached;
- (BOOL)setTrack:(NSURL *)track; - (BOOL)setTrack:(NSURL *)track;
- (void)inputFormatDidChange:(AudioStreamBasicDescription)format;
@end @end

View file

@ -24,6 +24,8 @@
inputNode = nil; inputNode = nil;
converterNode = nil; converterNode = nil;
converterLaunched = NO;
} }
return self; return self;
@ -47,7 +49,7 @@
[self buildChain]; [self buildChain];
id<CogSource> source = [AudioSource audioSourceForURL:url]; id<CogSource> source = [AudioSource audioSourceForURL:url];
NSLog(@"Opening: %@", url);
if (![source open:url]) if (![source open:url])
{ {
NSLog(@"Couldn't open source..."); NSLog(@"Couldn't open source...");
@ -55,11 +57,12 @@
} }
[converterNode setOutputFormat:outputFormat];
if (![inputNode openURL:url withSource:source]) if (![inputNode openURL:url withSource:source])
return NO; return NO;
if (![converterNode setupWithInputFormat:propertiesToASBD([inputNode properties]) outputFormat:outputFormat]) // return NO;
return NO;
return YES; return YES;
} }
@ -76,6 +79,8 @@
return NO; return NO;
NSLog(@"Buffer chain made"); NSLog(@"Buffer chain made");
[converterNode launchThread];
return YES; return YES;
} }
@ -84,7 +89,6 @@
NSLog(@"Properties: %@", [inputNode properties]); NSLog(@"Properties: %@", [inputNode properties]);
[inputNode launchThread]; [inputNode launchThread];
[converterNode launchThread];
} }
- (void)setUserInfo:(id)i - (void)setUserInfo:(id)i
@ -124,11 +128,23 @@
return [inputNode setTrack:track]; return [inputNode setTrack:track];
} }
- (void)initialBufferFilled - (void)initialBufferFilled:(id)sender
{ {
NSLog(@"INITIAL BUFFER FILLED");
[controller launchOutputThread]; [controller launchOutputThread];
} }
- (void)inputFormatDidChange:(AudioStreamBasicDescription)format
{
NSLog(@"FORMAT DID CHANGE!");
if (!converterLaunched) {
converterLaunched = YES;
[converterNode inputFormatDidChange:format];
[converterNode launchThread];
}
}
- (InputNode *)inputNode - (InputNode *)inputNode
{ {
return inputNode; return inputNode;

View file

@ -28,4 +28,8 @@
- (void)process; - (void)process;
- (int)convert:(void *)dest amount:(int)amount; - (int)convert:(void *)dest amount:(int)amount;
- (void)setOutputFormat:(AudioStreamBasicDescription)format;
- (void)inputFormatDidChange:(AudioStreamBasicDescription)format;
@end @end

View file

@ -140,9 +140,26 @@ static OSStatus ACInputProc(AudioConverterRef inAudioConverter, UInt32* ioNumber
return YES; 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 - (void)cleanUp
{ {
AudioConverterDispose(converter); if (converter)
{
AudioConverterDispose(converter);
converter = NULL;
}
} }
@end @end

View file

@ -53,6 +53,7 @@
- (void)registerObservers - (void)registerObservers
{ {
NSLog(@"REGISTERING OBSERVERS");
[decoder addObserver:self [decoder addObserver:self
forKeyPath:@"properties" forKeyPath:@"properties"
options:(NSKeyValueObservingOptionNew) options:(NSKeyValueObservingOptionNew)
@ -69,9 +70,11 @@
change:(NSDictionary *)change change:(NSDictionary *)change
context:(void *)context context:(void *)context
{ {
NSLog(@"SOMETHING CHANGED!");
if ([keyPath isEqual:@"properties"]) { if ([keyPath isEqual:@"properties"]) {
//Setup converter! //Setup converter!
//Inform something of properties change //Inform something of properties change
[controller inputFormatDidChange: propertiesToASBD([decoder properties])];
} }
else if ([keyPath isEqual:@"metadata"]) { else if ([keyPath isEqual:@"metadata"]) {
//Inform something of metadata change //Inform something of metadata change
@ -107,10 +110,10 @@
if (amountRead <= 0) if (amountRead <= 0)
{ {
if (initialBufferFilled == NO) { if (initialBufferFilled == NO) {
[controller initialBufferFilled]; [controller initialBufferFilled:self];
} }
NSLog(@"End of stream?"); NSLog(@"End of stream? %@", [self properties]);
endOfStream = YES; endOfStream = YES;
shouldClose = [controller endOfInputReached]; //Lets us know if we should keep going or not (occassionally, for track changes within a file) 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); NSLog(@"closing? is %i", shouldClose);

View file

@ -44,8 +44,8 @@
if (availOutput == 0) { if (availOutput == 0) {
if (initialBufferFilled == NO) { if (initialBufferFilled == NO) {
initialBufferFilled = YES; initialBufferFilled = YES;
if ([controller respondsToSelector:@selector(initialBufferFilled)]) if ([controller respondsToSelector:@selector(initialBufferFilled:)])
[controller performSelector:@selector(initialBufferFilled)]; [controller performSelector:@selector(initialBufferFilled:) withObject:self];
} }
} }

View file

@ -286,28 +286,28 @@
isa = PBXContainerItemProxy; isa = PBXContainerItemProxy;
containerPortal = 17C8F3C80CBED663008D969D /* GME.xcodeproj */; containerPortal = 17C8F3C80CBED663008D969D /* GME.xcodeproj */;
proxyType = 2; proxyType = 2;
remoteGlobalIDString = 8D5B49B6048680CD000E48DA /* GME.bundle */; remoteGlobalIDString = 8D5B49B6048680CD000E48DA;
remoteInfo = "GME Plugin"; remoteInfo = "GME Plugin";
}; };
17C8F44B0CBEDD37008D969D /* PBXContainerItemProxy */ = { 17C8F44B0CBEDD37008D969D /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy; isa = PBXContainerItemProxy;
containerPortal = 17C8F3C80CBED663008D969D /* GME.xcodeproj */; containerPortal = 17C8F3C80CBED663008D969D /* GME.xcodeproj */;
proxyType = 1; proxyType = 1;
remoteGlobalIDString = 8D5B49AC048680CD000E48DA /* GME Plugin */; remoteGlobalIDString = 8D5B49AC048680CD000E48DA;
remoteInfo = "GME Plugin"; remoteInfo = "GME Plugin";
}; };
17C8F7D60CBEF3E8008D969D /* PBXContainerItemProxy */ = { 17C8F7D60CBEF3E8008D969D /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy; isa = PBXContainerItemProxy;
containerPortal = 17C8F7D20CBEF3E8008D969D /* Dumb.xcodeproj */; containerPortal = 17C8F7D20CBEF3E8008D969D /* Dumb.xcodeproj */;
proxyType = 2; proxyType = 2;
remoteGlobalIDString = 8D5B49B6048680CD000E48DA /* Dumb.bundle */; remoteGlobalIDString = 8D5B49B6048680CD000E48DA;
remoteInfo = Dumb; remoteInfo = Dumb;
}; };
17C8F7D90CBEF3F9008D969D /* PBXContainerItemProxy */ = { 17C8F7D90CBEF3F9008D969D /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy; isa = PBXContainerItemProxy;
containerPortal = 17C8F7D20CBEF3E8008D969D /* Dumb.xcodeproj */; containerPortal = 17C8F7D20CBEF3E8008D969D /* Dumb.xcodeproj */;
proxyType = 1; proxyType = 1;
remoteGlobalIDString = 8D5B49AC048680CD000E48DA /* Dumb */; remoteGlobalIDString = 8D5B49AC048680CD000E48DA;
remoteInfo = Dumb; remoteInfo = Dumb;
}; };
17F3BB870CBC565100864489 /* PBXContainerItemProxy */ = { 17F3BB870CBC565100864489 /* PBXContainerItemProxy */ = {

View file

@ -87,6 +87,10 @@
trackEnd = [[properties objectForKey:@"length"] doubleValue]/1000.0; 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; return YES;
} }
} }

View file

@ -22,14 +22,14 @@
isa = PBXContainerItemProxy; isa = PBXContainerItemProxy;
containerPortal = 17C8F6990CBEE857008D969D /* Dumb.xcodeproj */; containerPortal = 17C8F6990CBEE857008D969D /* Dumb.xcodeproj */;
proxyType = 2; proxyType = 2;
remoteGlobalIDString = 8DC2EF5B0486A6940098B216 /* Dumb.framework */; remoteGlobalIDString = 8DC2EF5B0486A6940098B216;
remoteInfo = "Dumb Framework"; remoteInfo = "Dumb Framework";
}; };
17C8F6A00CBEE867008D969D /* PBXContainerItemProxy */ = { 17C8F6A00CBEE867008D969D /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy; isa = PBXContainerItemProxy;
containerPortal = 17C8F6990CBEE857008D969D /* Dumb.xcodeproj */; containerPortal = 17C8F6990CBEE857008D969D /* Dumb.xcodeproj */;
proxyType = 1; proxyType = 1;
remoteGlobalIDString = 8DC2EF4F0486A6940098B216 /* Dumb Framework */; remoteGlobalIDString = 8DC2EF4F0486A6940098B216;
remoteInfo = "Dumb Framework"; remoteInfo = "Dumb Framework";
}; };
/* End PBXContainerItemProxy section */ /* End PBXContainerItemProxy section */

View file

@ -97,6 +97,9 @@ void closeCallback(void *f)
return NO; return NO;
} }
[self willChangeValueForKey:@"properties"];
[self didChangeValueForKey:@"properties"];
return YES; return YES;
} }

View file

@ -27,14 +27,14 @@
isa = PBXContainerItemProxy; isa = PBXContainerItemProxy;
containerPortal = 17C8F3320CBED393008D969D /* GME.xcodeproj */; containerPortal = 17C8F3320CBED393008D969D /* GME.xcodeproj */;
proxyType = 2; proxyType = 2;
remoteGlobalIDString = 8DC2EF5B0486A6940098B216 /* GME.framework */; remoteGlobalIDString = 8DC2EF5B0486A6940098B216;
remoteInfo = GME; remoteInfo = GME;
}; };
17C8F4350CBEDD28008D969D /* PBXContainerItemProxy */ = { 17C8F4350CBEDD28008D969D /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy; isa = PBXContainerItemProxy;
containerPortal = 17C8F3320CBED393008D969D /* GME.xcodeproj */; containerPortal = 17C8F3320CBED393008D969D /* GME.xcodeproj */;
proxyType = 1; proxyType = 1;
remoteGlobalIDString = 8DC2EF4F0486A6940098B216 /* GME Framework */; remoteGlobalIDString = 8DC2EF4F0486A6940098B216;
remoteInfo = "GME Framework"; remoteInfo = "GME Framework";
}; };
/* End PBXContainerItemProxy section */ /* End PBXContainerItemProxy section */

View file

@ -98,6 +98,9 @@ gme_err_t readCallback( void* data, void* out, long count )
NSLog(@"Error starting track"); NSLog(@"Error starting track");
return NO; return NO;
} }
[self willChangeValueForKey:@"properties"];
[self didChangeValueForKey:@"properties"];
return YES; return YES;
} }

View file

@ -25,8 +25,9 @@
port = 80; port = 80;
_socket = [[Socket alloc] initWithHost:[url host] port:port]; _socket = [[Socket alloc] initWithHost:[url host] port:port];
NSLog(@"SOCKET?");
if (_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]; 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]]; [_socket send:(void *)[request bytes] amount:[request length]];
pastHeader = NO; pastHeader = NO;
@ -57,15 +58,17 @@
- (int)read:(void *)buffer amount:(int)amount - (int)read:(void *)buffer amount:(int)amount
{ {
NSLog(@"READING DATA: %i", amount);
if (!pastHeader) { if (!pastHeader) {
const int delimeter_size = 4; //\r\n\r\n 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]; int l = [_socket receive:buffer amount:amount];
NSLog(@"Received data: %i", l);
uint8_t *f; uint8_t *f;
while(NULL == (f = (uint8_t *)strnstr((const char *)buffer, "\r\n\r\n", l))) { 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 //Need to check for boundary conditions
memmove(buffer, (uint8_t *)buffer + (l - delimeter_size), delimeter_size); memmove(buffer, (uint8_t *)buffer + (l - delimeter_size), delimeter_size);
l = delimeter_size + [_socket receive:((uint8_t *)buffer + delimeter_size) amount:(amount - delimeter_size)]; l = delimeter_size + [_socket receive:((uint8_t *)buffer + delimeter_size) amount:(amount - delimeter_size)];
@ -79,12 +82,12 @@
//For testing only //For testing only
fwrite(buffer, 1, bufferOffset - (uint8_t *)buffer, testFout); // fwrite(buffer, 1, bufferOffset - (uint8_t *)buffer, testFout);
fclose(testFout); // fclose(testFout);
testFout = fopen("test.raw", "w"); // testFout = fopen("/Users/vspader/test.raw", "w");
fwrite(bufferOffset, 1, amountRemaining, testFout); // fwrite(bufferOffset, 1, amountRemaining, testFout);
fclose(testFout); // fclose(testFout);
memmove(buffer,bufferOffset, amountRemaining); memmove(buffer,bufferOffset, amountRemaining);
@ -96,9 +99,9 @@
//FOR TESTING ONLY //FOR TESTING ONLY
FILE *testFout = fopen("test.raw", "a"); // FILE *testFout = fopen("/Users/vspader/test.raw", "a");
fwrite(buffer, 1, l, testFout); // fwrite(buffer, 1, l, testFout);
fclose(testFout); // fclose(testFout);
if (l > 0) if (l > 0)
byteCount += l; byteCount += l;

View file

@ -512,6 +512,7 @@ static inline signed int scale (mad_fixed_t sample)
continue; continue;
} }
if (_firstFrame && ![_source seekable]) { if (_firstFrame && ![_source seekable]) {
frequency = _frame.header.samplerate; frequency = _frame.header.samplerate;
channels = MAD_NCHANNELS(&_frame.header); channels = MAD_NCHANNELS(&_frame.header);