2006-01-20 12:34:02 -03:00
|
|
|
//
|
2006-04-02 11:44:08 -04:00
|
|
|
// InputNode.m
|
2006-01-20 12:34:02 -03:00
|
|
|
// Cog
|
|
|
|
//
|
2006-09-04 14:46:18 -04:00
|
|
|
// Created by Vincent Spader on 8/2/05.
|
|
|
|
// Copyright 2005 Vincent Spader. All rights reserved.
|
2006-01-20 12:34:02 -03:00
|
|
|
//
|
|
|
|
|
|
|
|
#import "InputNode.h"
|
2007-02-24 17:36:27 -03:00
|
|
|
#import "BufferChain.h"
|
2007-03-01 22:36:52 -03:00
|
|
|
#import "Plugin.h"
|
2006-01-20 12:34:02 -03:00
|
|
|
|
|
|
|
@implementation InputNode
|
|
|
|
|
2007-03-01 22:36:52 -03:00
|
|
|
- (BOOL)openURL:(NSURL *)url withSource:(id<CogSource>)source
|
2006-01-20 12:34:02 -03:00
|
|
|
{
|
2007-02-24 17:36:27 -03:00
|
|
|
NSLog(@"Opening: %@", url);
|
|
|
|
decoder = [AudioDecoder audioDecoderForURL:url];
|
|
|
|
[decoder retain];
|
|
|
|
|
|
|
|
NSLog(@"Got decoder...%@", decoder);
|
|
|
|
if (decoder == nil)
|
2006-04-12 22:51:22 -04:00
|
|
|
return NO;
|
2007-02-24 17:36:27 -03:00
|
|
|
|
2007-03-01 22:36:52 -03:00
|
|
|
if (![decoder open:source])
|
|
|
|
{
|
|
|
|
NSLog(@"Couldn't open decoder...");
|
2007-02-24 17:36:27 -03:00
|
|
|
return NO;
|
2007-03-01 22:36:52 -03:00
|
|
|
}
|
2007-02-24 17:36:27 -03:00
|
|
|
|
|
|
|
/* while (decoder == nil)
|
2006-04-12 22:51:22 -04:00
|
|
|
{
|
2007-02-24 17:36:27 -03:00
|
|
|
NSURL *nextStream = [controller invalidDecoder];
|
|
|
|
if (nextStream == nil)
|
2006-04-12 22:51:22 -04:00
|
|
|
return NO;
|
|
|
|
|
2007-02-24 17:36:27 -03:00
|
|
|
decoder = [AudioDecoder audioDecoderForURL:nextStream];
|
|
|
|
[decoder open:nextStream];
|
2006-04-12 22:51:22 -04:00
|
|
|
}
|
|
|
|
*/
|
2006-04-02 11:44:08 -04:00
|
|
|
shouldContinue = YES;
|
2006-04-02 16:03:12 -04:00
|
|
|
shouldSeek = NO;
|
2006-04-12 22:51:22 -04:00
|
|
|
|
2007-03-01 22:36:52 -03:00
|
|
|
NSLog(@"OPENED");
|
2006-04-12 22:51:22 -04:00
|
|
|
return YES;
|
2006-01-20 12:34:02 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)process
|
|
|
|
{
|
|
|
|
const int chunk_size = CHUNK_SIZE;
|
2006-04-02 16:03:12 -04:00
|
|
|
char *buf;
|
2006-01-20 12:34:02 -03:00
|
|
|
int amountRead;
|
|
|
|
|
2006-05-07 09:19:23 -04:00
|
|
|
NSLog(@"Playing file: %i", self);
|
2006-04-02 16:03:12 -04:00
|
|
|
buf = malloc(chunk_size);
|
2006-01-20 12:34:02 -03:00
|
|
|
|
2006-04-02 11:44:08 -04:00
|
|
|
while ([self shouldContinue] == YES && [self endOfStream] == NO)
|
2006-01-20 12:34:02 -03:00
|
|
|
{
|
2006-04-02 16:03:12 -04:00
|
|
|
if (shouldSeek == YES)
|
|
|
|
{
|
2006-04-13 10:47:28 -04:00
|
|
|
NSLog(@"Actually seeking");
|
2007-02-24 17:36:27 -03:00
|
|
|
[decoder seekToTime:seekTime];
|
2006-04-02 16:03:12 -04:00
|
|
|
shouldSeek = NO;
|
|
|
|
}
|
|
|
|
|
2007-02-24 17:36:27 -03:00
|
|
|
amountRead = [decoder fillBuffer:buf ofSize: chunk_size];
|
2006-01-20 12:34:02 -03:00
|
|
|
if (amountRead <= 0)
|
|
|
|
{
|
2006-04-02 11:44:08 -04:00
|
|
|
endOfStream = YES;
|
2006-04-03 21:08:21 -04:00
|
|
|
DBLog(@"END OF INPUT WAS REACHED");
|
2006-01-20 12:34:02 -03:00
|
|
|
[controller endOfInputReached];
|
2006-04-02 16:03:12 -04:00
|
|
|
break; //eof
|
2006-01-20 12:34:02 -03:00
|
|
|
}
|
|
|
|
[self writeData:buf amount:amountRead];
|
|
|
|
}
|
2006-04-02 11:44:08 -04:00
|
|
|
|
2006-04-02 16:03:12 -04:00
|
|
|
free(buf);
|
2007-02-24 17:36:27 -03:00
|
|
|
[decoder close];
|
2006-05-07 09:19:23 -04:00
|
|
|
|
|
|
|
NSLog(@"CLOSED: %i", self);
|
2006-01-20 12:34:02 -03:00
|
|
|
}
|
|
|
|
|
2006-04-02 16:03:12 -04:00
|
|
|
- (void)seek:(double)time
|
|
|
|
{
|
2006-04-13 10:47:28 -04:00
|
|
|
NSLog(@"SEEKING WEEE");
|
2006-04-02 16:03:12 -04:00
|
|
|
seekTime = time;
|
|
|
|
shouldSeek = YES;
|
|
|
|
}
|
|
|
|
|
2007-02-24 17:36:27 -03:00
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[decoder release];
|
|
|
|
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *) properties
|
2006-01-20 12:34:02 -03:00
|
|
|
{
|
2007-02-24 17:36:27 -03:00
|
|
|
return [decoder properties];
|
2006-01-20 12:34:02 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|