Fixed up streaming a bit.

Removed debugging code for http source. Was that in 0.06? Whoops.
CQTexperiment
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;
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

View File

@ -24,6 +24,8 @@
inputNode = nil;
converterNode = nil;
converterLaunched = NO;
}
return self;
@ -47,7 +49,7 @@
[self buildChain];
id<CogSource> 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;

View File

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

View File

@ -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

View File

@ -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);

View File

@ -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];
}
}

View File

@ -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 */ = {

View File

@ -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;
}
}

View File

@ -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 */

View File

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

View File

@ -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 */

View File

@ -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;
}

View File

@ -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;

View File

@ -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);