Added mime type support.
parent
c536ea06a5
commit
f1b9141f4b
|
@ -13,6 +13,6 @@
|
|||
@interface AudioDecoder : NSObject {
|
||||
}
|
||||
|
||||
+ (id<CogDecoder>)audioDecoderForURL:(NSURL *)url;
|
||||
+ (id<CogDecoder>)audioDecoderForSource:(id <CogSource>)source;
|
||||
|
||||
@end
|
||||
|
|
|
@ -12,9 +12,9 @@
|
|||
|
||||
@implementation AudioDecoder
|
||||
|
||||
+ (id<CogDecoder>) audioDecoderForURL:(NSURL *)url
|
||||
+ (id<CogDecoder>) audioDecoderForSource:(id <CogSource>)source
|
||||
{
|
||||
return [[PluginController sharedPluginController] audioDecoderForURL:url];
|
||||
return [[PluginController sharedPluginController] audioDecoderForSource:source];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -322,9 +322,9 @@
|
|||
PluginController *pluginController = [PluginController sharedPluginController];
|
||||
|
||||
NSArray *containerTypes = [[pluginController containers] allKeys];
|
||||
NSArray *decoderTypes = [[pluginController decoders] allKeys];
|
||||
NSArray *decoderTypes = [[pluginController decodersByExtension] allKeys];
|
||||
NSArray *metdataReaderTypes = [[pluginController metadataReaders] allKeys];
|
||||
NSArray *propertiesReaderTypes = [[pluginController propertiesReaders] allKeys];
|
||||
NSArray *propertiesReaderTypes = [[pluginController propertiesReadersByExtension] allKeys];
|
||||
|
||||
NSMutableSet *types = [NSMutableSet set];
|
||||
|
||||
|
|
|
@ -58,7 +58,7 @@
|
|||
|
||||
[converterNode setOutputFormat:outputFormat];
|
||||
|
||||
if (![inputNode openURL:url withSource:source])
|
||||
if (![inputNode openWithSource:source])
|
||||
return NO;
|
||||
|
||||
// return NO;
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
double seekTime;
|
||||
}
|
||||
|
||||
- (BOOL)openURL:(NSURL *)url withSource:(id<CogSource>)source;
|
||||
- (BOOL)openWithSource:(id<CogSource>)source;
|
||||
- (BOOL)openWithDecoder:(id<CogDecoder>) d;
|
||||
|
||||
- (void)process;
|
||||
|
|
|
@ -13,9 +13,9 @@
|
|||
|
||||
@implementation InputNode
|
||||
|
||||
- (BOOL)openURL:(NSURL *)url withSource:(id<CogSource>)source
|
||||
- (BOOL)openWithSource:(id<CogSource>)source
|
||||
{
|
||||
decoder = [AudioDecoder audioDecoderForURL:url];
|
||||
decoder = [AudioDecoder audioDecoderForSource:source];
|
||||
[decoder retain];
|
||||
|
||||
if (decoder == nil)
|
||||
|
|
|
@ -63,9 +63,10 @@
|
|||
@protocol CogPluginController <NSObject>
|
||||
- (id<CogSource>) audioSourceForURL:(NSURL *)url;
|
||||
- (NSArray *) urlsForContainerURL:(NSURL *)url;
|
||||
- (id<CogDecoder>) audioDecoderForURL:(NSURL *)url;
|
||||
- (NSDictionary *) metadataForURL:(NSURL *)url;
|
||||
- (NSDictionary *) propertiesForURL:(NSURL *)url;
|
||||
|
||||
- (id<CogDecoder>) audioDecoderForSource:(id<CogSource>)source;
|
||||
@end
|
||||
|
||||
|
||||
|
|
|
@ -9,9 +9,13 @@
|
|||
{
|
||||
NSMutableDictionary *sources;
|
||||
NSMutableDictionary *containers;
|
||||
NSMutableDictionary *decoders;
|
||||
NSMutableDictionary *metadataReaders;
|
||||
NSMutableDictionary *propertiesReaders;
|
||||
|
||||
NSMutableDictionary *propertiesReadersByExtension;
|
||||
NSMutableDictionary *propertiesReadersByMimeType;
|
||||
|
||||
NSMutableDictionary *decodersByExtension;
|
||||
NSMutableDictionary *decodersByMimeType;
|
||||
}
|
||||
|
||||
+ (PluginController *)sharedPluginController; //Use this to get the instance.
|
||||
|
@ -30,8 +34,12 @@
|
|||
|
||||
- (NSDictionary *)sources;
|
||||
- (NSDictionary *)containers;
|
||||
- (NSDictionary *)decoders;
|
||||
- (NSDictionary *)metadataReaders;
|
||||
- (NSDictionary *)propertiesReaders;
|
||||
|
||||
- (NSDictionary *)propertiesReadersByExtension;
|
||||
- (NSDictionary *)propertiesReadersByMimeType;
|
||||
|
||||
- (NSDictionary *)decodersByExtension;
|
||||
- (NSDictionary *)decodersByMimeType;
|
||||
|
||||
@end
|
||||
|
|
|
@ -60,9 +60,14 @@ static PluginController *sharedPluginController = nil;
|
|||
if (self) {
|
||||
sources = [[NSMutableDictionary alloc] init];
|
||||
containers = [[NSMutableDictionary alloc] init];
|
||||
decoders = [[NSMutableDictionary alloc] init];
|
||||
|
||||
metadataReaders = [[NSMutableDictionary alloc] init];
|
||||
propertiesReaders = [[NSMutableDictionary alloc] init];
|
||||
|
||||
propertiesReadersByExtension = [[NSMutableDictionary alloc] init];
|
||||
propertiesReadersByMimeType = [[NSMutableDictionary alloc] init];
|
||||
|
||||
decodersByExtension = [[NSMutableDictionary alloc] init];
|
||||
decodersByMimeType = [[NSMutableDictionary alloc] init];
|
||||
}
|
||||
|
||||
return self;
|
||||
|
@ -154,11 +159,20 @@ static PluginController *sharedPluginController = nil;
|
|||
{
|
||||
Class decoder = NSClassFromString(className);
|
||||
if (decoder && [decoder respondsToSelector:@selector(fileTypes)]) {
|
||||
NSEnumerator *fileTypesEnum = [[decoder fileTypes] objectEnumerator];
|
||||
id fileType;
|
||||
NSEnumerator *fileTypesEnum = [[decoder fileTypes] objectEnumerator];
|
||||
while (fileType = [fileTypesEnum nextObject])
|
||||
{
|
||||
[decoders setObject:className forKey:[fileType lowercaseString]];
|
||||
[decodersByExtension setObject:className forKey:[fileType lowercaseString]];
|
||||
}
|
||||
}
|
||||
|
||||
if (decoder && [decoder respondsToSelector:@selector(mimeTypes)]) {
|
||||
id mimeType;
|
||||
NSEnumerator *mimeTypesEnum = [[decoder mimeTypes] objectEnumerator];
|
||||
while (mimeType = [mimeTypesEnum nextObject])
|
||||
{
|
||||
[decodersByMimeType setObject:className forKey:[mimeType lowercaseString]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -184,7 +198,16 @@ static PluginController *sharedPluginController = nil;
|
|||
id fileType;
|
||||
while (fileType = [fileTypesEnum nextObject])
|
||||
{
|
||||
[propertiesReaders setObject:className forKey:[fileType lowercaseString]];
|
||||
[propertiesReadersByExtension setObject:className forKey:[fileType lowercaseString]];
|
||||
}
|
||||
}
|
||||
|
||||
if (propertiesReader && [propertiesReader respondsToSelector:@selector(mimeTypes)]) {
|
||||
id mimeType;
|
||||
NSEnumerator *mimeTypesEnum = [[propertiesReader mimeTypes] objectEnumerator];
|
||||
while (mimeType = [mimeTypesEnum nextObject])
|
||||
{
|
||||
[propertiesReadersByMimeType setObject:className forKey:[mimeType lowercaseString]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -206,9 +229,13 @@ static PluginController *sharedPluginController = nil;
|
|||
{
|
||||
NSLog(@"Sources: %@", sources);
|
||||
NSLog(@"Containers: %@", containers);
|
||||
NSLog(@"Decoders: %@", decoders);
|
||||
NSLog(@"Metadata Readers: %@", metadataReaders);
|
||||
NSLog(@"Properties Readers: %@", propertiesReaders);
|
||||
|
||||
NSLog(@"Properties Readers By Extension: %@", propertiesReadersByExtension);
|
||||
NSLog(@"Properties Readers By Mime Type: %@", propertiesReadersByMimeType);
|
||||
|
||||
NSLog(@"Decoders by Extension: %@", decodersByExtension);
|
||||
NSLog(@"Decoders by Mime Type: %@", decodersByMimeType);
|
||||
}
|
||||
|
||||
- (NSDictionary *)sources
|
||||
|
@ -221,14 +248,24 @@ static PluginController *sharedPluginController = nil;
|
|||
return containers;
|
||||
}
|
||||
|
||||
- (NSDictionary *)decoders
|
||||
- (NSDictionary *)decodersByExtension
|
||||
{
|
||||
return decoders;
|
||||
return decodersByExtension;
|
||||
}
|
||||
|
||||
- (NSDictionary *)propertiesReaders
|
||||
- (NSDictionary *)decodersByMimeType
|
||||
{
|
||||
return propertiesReaders;
|
||||
return decodersByMimeType;
|
||||
}
|
||||
|
||||
- (NSDictionary *)propertiesReadersByExtension
|
||||
{
|
||||
return propertiesReadersByExtension;
|
||||
}
|
||||
|
||||
- (NSDictionary *)propertiesReadersByMimeType
|
||||
{
|
||||
return propertiesReadersByMimeType;
|
||||
}
|
||||
|
||||
- (NSDictionary *)metadataReaders
|
||||
|
@ -255,11 +292,16 @@ static PluginController *sharedPluginController = nil;
|
|||
return [container urlsForContainerURL:url];
|
||||
}
|
||||
|
||||
- (id<CogDecoder>) audioDecoderForURL:(NSURL *)url
|
||||
//Note: Source is assumed to already be opened.
|
||||
- (id<CogDecoder>) audioDecoderForSource:(id <CogSource>)source
|
||||
{
|
||||
NSString *ext = [[url path] pathExtension];
|
||||
|
||||
Class decoder = NSClassFromString([decoders objectForKey:[ext lowercaseString]]);
|
||||
NSString *ext = [[[source url] path] pathExtension];
|
||||
NSString *classString = [decodersByExtension objectForKey:[ext lowercaseString]];
|
||||
if (!classString) {
|
||||
classString = [decodersByMimeType objectForKey:[[source mimeType] lowercaseString]];
|
||||
}
|
||||
|
||||
Class decoder = NSClassFromString(classString);
|
||||
|
||||
return [[[decoder alloc] init] autorelease];
|
||||
}
|
||||
|
@ -284,7 +326,11 @@ static PluginController *sharedPluginController = nil;
|
|||
if (![source open:url])
|
||||
return nil;
|
||||
|
||||
NSString *classString = [propertiesReaders objectForKey:[ext lowercaseString]];
|
||||
NSString *classString = [propertiesReadersByExtension objectForKey:[ext lowercaseString]];
|
||||
if (!classString) {
|
||||
classString = [propertiesReadersByMimeType objectForKey:[[source mimeType] lowercaseString]];
|
||||
}
|
||||
|
||||
if (classString)
|
||||
{
|
||||
Class propertiesReader = NSClassFromString(classString);
|
||||
|
@ -293,7 +339,8 @@ static PluginController *sharedPluginController = nil;
|
|||
}
|
||||
else
|
||||
{
|
||||
id<CogDecoder> decoder = [self audioDecoderForURL:url];
|
||||
|
||||
id<CogDecoder> decoder = [self audioDecoderForSource:source];
|
||||
if (![decoder open:source])
|
||||
{
|
||||
return nil;
|
||||
|
|
|
@ -213,7 +213,7 @@
|
|||
continue;
|
||||
|
||||
//Need a better way to determine acceptable file types than basing it on extensions.
|
||||
if (![[AudioPlayer fileTypes] containsObject:[[[url path] pathExtension] lowercaseString]])
|
||||
if ([url isFileURL] && ![[AudioPlayer fileTypes] containsObject:[[[url path] pathExtension] lowercaseString]])
|
||||
continue;
|
||||
|
||||
if (![uniqueURLs containsObject:url])
|
||||
|
|
|
@ -17,6 +17,4 @@
|
|||
NSURL *_url;
|
||||
}
|
||||
|
||||
- (void)setURL:(NSURL *)url;
|
||||
|
||||
@end
|
||||
|
|
|
@ -13,18 +13,14 @@
|
|||
|
||||
- (BOOL)open:(NSURL *)url
|
||||
{
|
||||
[self setURL:url];
|
||||
_url = url;
|
||||
[_url retain];
|
||||
|
||||
_fd = fopen([[url path] UTF8String], "r");
|
||||
|
||||
return (_fd != NULL);
|
||||
}
|
||||
|
||||
- (NSDictionary *)properties
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (BOOL)seekable
|
||||
{
|
||||
return YES;
|
||||
|
@ -47,9 +43,11 @@
|
|||
|
||||
- (void)close
|
||||
{
|
||||
[self setURL:nil];
|
||||
[_url release];
|
||||
_url = nil;
|
||||
|
||||
fclose(_fd);
|
||||
_fd = NULL;
|
||||
}
|
||||
|
||||
- (NSURL *)url
|
||||
|
@ -57,6 +55,11 @@
|
|||
return _url;
|
||||
}
|
||||
|
||||
- (NSString *)mimeType
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)setURL:(NSURL *)url
|
||||
{
|
||||
[url retain];
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
{
|
||||
_url = [url copy];
|
||||
|
||||
_responseReceived = YES;
|
||||
_responseReceived = NO;
|
||||
_connectionFinished = NO;
|
||||
_byteCount = 0;
|
||||
_data = [[NSMutableData alloc] init];
|
||||
|
@ -55,6 +55,7 @@
|
|||
|
||||
- (NSString *)mimeType
|
||||
{
|
||||
NSLog(@"Returning mimetype! %@", _mimeType);
|
||||
return _mimeType;
|
||||
}
|
||||
|
||||
|
@ -121,6 +122,9 @@
|
|||
|
||||
[_url release];
|
||||
_url = nil;
|
||||
|
||||
[_mimeType release];
|
||||
_mimeType = nil;
|
||||
|
||||
[_sem release];
|
||||
_sem = nil;
|
||||
|
@ -146,9 +150,10 @@
|
|||
|
||||
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
|
||||
{
|
||||
NSLog(@"Received response: %@", [response MIMEType]);
|
||||
_mimeType = [response MIMEType];
|
||||
_mimeType = [[response MIMEType] copy];
|
||||
_responseReceived = YES;
|
||||
|
||||
NSLog(@"Received response: %@", _mimeType);
|
||||
|
||||
[_sem signal];
|
||||
}
|
||||
|
|
|
@ -618,5 +618,10 @@ static inline signed int scale (mad_fixed_t sample)
|
|||
return [NSArray arrayWithObjects:@"mp3",nil];
|
||||
}
|
||||
|
||||
+ (NSArray *)mimeTypes
|
||||
{
|
||||
return [NSArray arrayWithObjects:@"audio/mpeg",nil];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
|
Loading…
Reference in New Issue