Implemented support for multiple decoders per file name extension, with a floating point priority control per interface. In the event that more than one input is registered to a given extension, and we match that extension, it will be passed off to an instance of the multi-decoder wrapper, which will try opening the file with all of the decoders in order of priority, until either one of them accepts it, or all of them have failed. This paves the way for adding a VGMSTREAM input, so I can give it a very low priority, since it has several formats that are verified by file name extension only. All current inputs have been given a priority of 1.0, except for CoreAudio, which was given a priority of 0.5, because it contains an MP3 and AC3 decoders that I'd rather not use if I don't have to.
2013-10-21 17:54:11 +00:00
|
|
|
//
|
2015-04-13 07:39:24 +00:00
|
|
|
// CogPluginMulti.m
|
Implemented support for multiple decoders per file name extension, with a floating point priority control per interface. In the event that more than one input is registered to a given extension, and we match that extension, it will be passed off to an instance of the multi-decoder wrapper, which will try opening the file with all of the decoders in order of priority, until either one of them accepts it, or all of them have failed. This paves the way for adding a VGMSTREAM input, so I can give it a very low priority, since it has several formats that are verified by file name extension only. All current inputs have been given a priority of 1.0, except for CoreAudio, which was given a priority of 0.5, because it contains an MP3 and AC3 decoders that I'd rather not use if I don't have to.
2013-10-21 17:54:11 +00:00
|
|
|
// CogAudio
|
|
|
|
//
|
|
|
|
// Created by Christopher Snowhill on 10/21/13.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
2015-04-13 07:39:24 +00:00
|
|
|
#import "CogPluginMulti.h"
|
|
|
|
|
|
|
|
NSArray * sortClassesByPriority(NSArray * theClasses)
|
|
|
|
{
|
|
|
|
NSMutableArray *sortedClasses = [NSMutableArray arrayWithArray:theClasses];
|
|
|
|
[sortedClasses sortUsingComparator:
|
|
|
|
^NSComparisonResult(id obj1, id obj2)
|
|
|
|
{
|
|
|
|
NSString *classString1 = (NSString *)obj1;
|
|
|
|
NSString *classString2 = (NSString *)obj2;
|
|
|
|
|
|
|
|
Class class1 = NSClassFromString(classString1);
|
|
|
|
Class class2 = NSClassFromString(classString2);
|
|
|
|
|
|
|
|
float priority1 = [class1 priority];
|
|
|
|
float priority2 = [class2 priority];
|
|
|
|
|
|
|
|
if (priority1 == priority2) return NSOrderedSame;
|
|
|
|
else if (priority1 > priority2) return NSOrderedAscending;
|
|
|
|
else return NSOrderedDescending;
|
|
|
|
}];
|
|
|
|
return sortedClasses;
|
|
|
|
}
|
Implemented support for multiple decoders per file name extension, with a floating point priority control per interface. In the event that more than one input is registered to a given extension, and we match that extension, it will be passed off to an instance of the multi-decoder wrapper, which will try opening the file with all of the decoders in order of priority, until either one of them accepts it, or all of them have failed. This paves the way for adding a VGMSTREAM input, so I can give it a very low priority, since it has several formats that are verified by file name extension only. All current inputs have been given a priority of 1.0, except for CoreAudio, which was given a priority of 0.5, because it contains an MP3 and AC3 decoders that I'd rather not use if I don't have to.
2013-10-21 17:54:11 +00:00
|
|
|
|
|
|
|
@implementation CogDecoderMulti
|
|
|
|
|
|
|
|
+ (NSArray *)mimeTypes
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (NSArray *)fileTypes
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (float)priority
|
|
|
|
{
|
|
|
|
return -1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)initWithDecoders:(NSArray *)decoders
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if ( self )
|
|
|
|
{
|
2015-04-13 07:39:24 +00:00
|
|
|
theDecoders = sortClassesByPriority(decoders);
|
Implemented support for multiple decoders per file name extension, with a floating point priority control per interface. In the event that more than one input is registered to a given extension, and we match that extension, it will be passed off to an instance of the multi-decoder wrapper, which will try opening the file with all of the decoders in order of priority, until either one of them accepts it, or all of them have failed. This paves the way for adding a VGMSTREAM input, so I can give it a very low priority, since it has several formats that are verified by file name extension only. All current inputs have been given a priority of 1.0, except for CoreAudio, which was given a priority of 0.5, because it contains an MP3 and AC3 decoders that I'd rather not use if I don't have to.
2013-10-21 17:54:11 +00:00
|
|
|
theDecoder = nil;
|
2013-10-21 18:24:48 +00:00
|
|
|
cachedObservers = [[NSMutableArray alloc] init];
|
Implemented support for multiple decoders per file name extension, with a floating point priority control per interface. In the event that more than one input is registered to a given extension, and we match that extension, it will be passed off to an instance of the multi-decoder wrapper, which will try opening the file with all of the decoders in order of priority, until either one of them accepts it, or all of them have failed. This paves the way for adding a VGMSTREAM input, so I can give it a very low priority, since it has several formats that are verified by file name extension only. All current inputs have been given a priority of 1.0, except for CoreAudio, which was given a priority of 0.5, because it contains an MP3 and AC3 decoders that I'd rather not use if I don't have to.
2013-10-21 17:54:11 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *)properties
|
|
|
|
{
|
|
|
|
if ( theDecoder != nil ) return [theDecoder properties];
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int)readAudio:(void *)buffer frames:(UInt32)frames
|
|
|
|
{
|
|
|
|
if ( theDecoder != nil ) return [theDecoder readAudio:buffer frames:frames];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)open:(id<CogSource>)source
|
|
|
|
{
|
|
|
|
for (NSString *classString in theDecoders)
|
|
|
|
{
|
|
|
|
Class decoder = NSClassFromString(classString);
|
|
|
|
theDecoder = [[decoder alloc] init];
|
|
|
|
for (NSDictionary *obsItem in cachedObservers) {
|
2020-11-23 22:00:11 +00:00
|
|
|
[theDecoder addObserver:[obsItem objectForKey:@"observer"]
|
|
|
|
forKeyPath:[obsItem objectForKey:@"keyPath"]
|
|
|
|
options:[[obsItem objectForKey:@"options"] unsignedIntegerValue]
|
|
|
|
context:(__bridge void *)([obsItem objectForKey:@"context"])];
|
Implemented support for multiple decoders per file name extension, with a floating point priority control per interface. In the event that more than one input is registered to a given extension, and we match that extension, it will be passed off to an instance of the multi-decoder wrapper, which will try opening the file with all of the decoders in order of priority, until either one of them accepts it, or all of them have failed. This paves the way for adding a VGMSTREAM input, so I can give it a very low priority, since it has several formats that are verified by file name extension only. All current inputs have been given a priority of 1.0, except for CoreAudio, which was given a priority of 0.5, because it contains an MP3 and AC3 decoders that I'd rather not use if I don't have to.
2013-10-21 17:54:11 +00:00
|
|
|
}
|
|
|
|
if ([theDecoder open:source])
|
|
|
|
return YES;
|
|
|
|
for (NSDictionary *obsItem in cachedObservers) {
|
|
|
|
[theDecoder removeObserver:[obsItem objectForKey:@"observer"] forKeyPath:[obsItem objectForKey:@"keyPath"]];
|
|
|
|
}
|
2020-03-09 03:04:10 +00:00
|
|
|
if ([source seekable])
|
2020-03-08 00:09:26 +00:00
|
|
|
[source seek:0 whence:SEEK_SET];
|
Implemented support for multiple decoders per file name extension, with a floating point priority control per interface. In the event that more than one input is registered to a given extension, and we match that extension, it will be passed off to an instance of the multi-decoder wrapper, which will try opening the file with all of the decoders in order of priority, until either one of them accepts it, or all of them have failed. This paves the way for adding a VGMSTREAM input, so I can give it a very low priority, since it has several formats that are verified by file name extension only. All current inputs have been given a priority of 1.0, except for CoreAudio, which was given a priority of 0.5, because it contains an MP3 and AC3 decoders that I'd rather not use if I don't have to.
2013-10-21 17:54:11 +00:00
|
|
|
}
|
|
|
|
theDecoder = nil;
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (long)seek:(long)frame
|
|
|
|
{
|
|
|
|
if ( theDecoder != nil ) return [theDecoder seek:frame];
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)close
|
|
|
|
{
|
|
|
|
if ( theDecoder != nil ) {
|
|
|
|
[theDecoder close];
|
2013-10-21 18:24:48 +00:00
|
|
|
for (NSDictionary *obsItem in cachedObservers) {
|
|
|
|
[theDecoder removeObserver:[obsItem objectForKey:@"observer"] forKeyPath:[obsItem objectForKey:@"keyPath"]];
|
|
|
|
}
|
Implemented support for multiple decoders per file name extension, with a floating point priority control per interface. In the event that more than one input is registered to a given extension, and we match that extension, it will be passed off to an instance of the multi-decoder wrapper, which will try opening the file with all of the decoders in order of priority, until either one of them accepts it, or all of them have failed. This paves the way for adding a VGMSTREAM input, so I can give it a very low priority, since it has several formats that are verified by file name extension only. All current inputs have been given a priority of 1.0, except for CoreAudio, which was given a priority of 0.5, because it contains an MP3 and AC3 decoders that I'd rather not use if I don't have to.
2013-10-21 17:54:11 +00:00
|
|
|
theDecoder = nil;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)setTrack:(NSURL *)track
|
|
|
|
{
|
|
|
|
if ( theDecoder != nil && [theDecoder respondsToSelector: @selector(setTrack:)] ) return [theDecoder setTrack:track];
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* By the current design, the core adds its observers to decoders before they are opened */
|
|
|
|
- (void)addObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath options:(NSKeyValueObservingOptions)options context:(void *)context
|
|
|
|
{
|
2020-11-23 22:00:11 +00:00
|
|
|
if(context != nil) {
|
|
|
|
[cachedObservers addObject:[NSDictionary dictionaryWithObjectsAndKeys:observer, @"observer", keyPath, @"keyPath", @(options), @"options", context, @"context", nil]];
|
|
|
|
} else {
|
|
|
|
[cachedObservers addObject:[NSDictionary dictionaryWithObjectsAndKeys:observer, @"observer", keyPath, @"keyPath", @(options), @"options", nil]];
|
|
|
|
}
|
Implemented support for multiple decoders per file name extension, with a floating point priority control per interface. In the event that more than one input is registered to a given extension, and we match that extension, it will be passed off to an instance of the multi-decoder wrapper, which will try opening the file with all of the decoders in order of priority, until either one of them accepts it, or all of them have failed. This paves the way for adding a VGMSTREAM input, so I can give it a very low priority, since it has several formats that are verified by file name extension only. All current inputs have been given a priority of 1.0, except for CoreAudio, which was given a priority of 0.5, because it contains an MP3 and AC3 decoders that I'd rather not use if I don't have to.
2013-10-21 17:54:11 +00:00
|
|
|
}
|
|
|
|
|
2013-10-21 18:24:48 +00:00
|
|
|
/* And this is currently called after the decoder is closed */
|
Implemented support for multiple decoders per file name extension, with a floating point priority control per interface. In the event that more than one input is registered to a given extension, and we match that extension, it will be passed off to an instance of the multi-decoder wrapper, which will try opening the file with all of the decoders in order of priority, until either one of them accepts it, or all of them have failed. This paves the way for adding a VGMSTREAM input, so I can give it a very low priority, since it has several formats that are verified by file name extension only. All current inputs have been given a priority of 1.0, except for CoreAudio, which was given a priority of 0.5, because it contains an MP3 and AC3 decoders that I'd rather not use if I don't have to.
2013-10-21 17:54:11 +00:00
|
|
|
- (void)removeObserver:(NSObject *)observer forKeyPath:(NSString *)keyPath
|
|
|
|
{
|
|
|
|
for (NSDictionary *obsItem in cachedObservers)
|
|
|
|
{
|
|
|
|
if ([obsItem objectForKey:@"observer"] == observer && [keyPath isEqualToString:[obsItem objectForKey:@"keyPath"]]) {
|
|
|
|
[cachedObservers removeObject:obsItem];
|
2013-10-21 18:24:48 +00:00
|
|
|
break;
|
Implemented support for multiple decoders per file name extension, with a floating point priority control per interface. In the event that more than one input is registered to a given extension, and we match that extension, it will be passed off to an instance of the multi-decoder wrapper, which will try opening the file with all of the decoders in order of priority, until either one of them accepts it, or all of them have failed. This paves the way for adding a VGMSTREAM input, so I can give it a very low priority, since it has several formats that are verified by file name extension only. All current inputs have been given a priority of 1.0, except for CoreAudio, which was given a priority of 0.5, because it contains an MP3 and AC3 decoders that I'd rather not use if I don't have to.
2013-10-21 17:54:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
2015-04-13 07:39:24 +00:00
|
|
|
|
|
|
|
@implementation CogContainerMulti
|
|
|
|
|
|
|
|
+ (NSArray *)urlsForContainerURL:(NSURL *)url containers:(NSArray *)containers
|
|
|
|
{
|
|
|
|
NSArray * sortedContainers = sortClassesByPriority(containers);
|
|
|
|
for (NSString *classString in sortedContainers)
|
|
|
|
{
|
|
|
|
Class container = NSClassFromString(classString);
|
|
|
|
NSArray * urls = [container urlsForContainerURL:url];
|
|
|
|
if ([urls count])
|
|
|
|
return urls;
|
|
|
|
}
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation CogMetadataReaderMulti
|
|
|
|
|
|
|
|
+ (NSDictionary *)metadataForURL:(NSURL *)url readers:(NSArray *)readers
|
|
|
|
{
|
|
|
|
NSArray * sortedReaders = sortClassesByPriority(readers);
|
|
|
|
for (NSString *classString in sortedReaders)
|
|
|
|
{
|
|
|
|
Class reader = NSClassFromString(classString);
|
|
|
|
NSDictionary * data = [reader metadataForURL:url];
|
|
|
|
if ([data count])
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation CogPropertiesReaderMulti
|
|
|
|
|
|
|
|
+ (NSDictionary *)propertiesForSource:(id<CogSource>)source readers:(NSArray *)readers
|
|
|
|
{
|
|
|
|
NSArray * sortedReaders = sortClassesByPriority(readers);
|
|
|
|
for (NSString *classString in sortedReaders)
|
|
|
|
{
|
|
|
|
Class reader = NSClassFromString(classString);
|
|
|
|
NSDictionary * data = [reader propertiesForSource:source];
|
|
|
|
if ([data count])
|
|
|
|
return data;
|
2020-03-09 03:04:10 +00:00
|
|
|
if ([source seekable])
|
2020-03-08 00:09:26 +00:00
|
|
|
[source seek:0 whence:SEEK_SET];
|
2015-04-13 07:39:24 +00:00
|
|
|
}
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|