SID Input: Open the files for decoding regardless
No more file handle caching, this was probably a source of crashes. Signed-off-by: Christopher Snowhill <kode54@gmail.com>CQTexperiment
parent
09bf1c7ad9
commit
b40b8521dd
|
@ -23,7 +23,6 @@
|
||||||
sidplayfp *engine;
|
sidplayfp *engine;
|
||||||
sidbuilder *builder;
|
sidbuilder *builder;
|
||||||
|
|
||||||
id<CogSource> source;
|
|
||||||
long length;
|
long length;
|
||||||
|
|
||||||
NSString *currentUrl;
|
NSString *currentUrl;
|
||||||
|
@ -36,7 +35,5 @@
|
||||||
long fadeRemain;
|
long fadeRemain;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setSource:(id<CogSource>)s;
|
|
||||||
- (id<CogSource>)source;
|
|
||||||
- (void)cleanUp;
|
- (void)cleanUp;
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -21,83 +21,18 @@
|
||||||
static const char *extListEmpty[] = { NULL };
|
static const char *extListEmpty[] = { NULL };
|
||||||
static const char *extListStr[] = { ".str", NULL };
|
static const char *extListStr[] = { ".str", NULL };
|
||||||
|
|
||||||
static NSLock *_lock = [[NSLock alloc] init];
|
|
||||||
|
|
||||||
@interface sid_file_container : NSObject {
|
|
||||||
NSLock *lock;
|
|
||||||
NSMutableDictionary *list;
|
|
||||||
}
|
|
||||||
+ (sid_file_container *)instance;
|
|
||||||
- (void)add_hint:(NSString *)path source:(id)source;
|
|
||||||
- (void)remove_hint:(NSString *)path;
|
|
||||||
- (BOOL)try_hint:(NSString *)path source:(id *)source;
|
|
||||||
@end
|
|
||||||
|
|
||||||
@implementation sid_file_container
|
|
||||||
+ (sid_file_container *)instance {
|
|
||||||
static sid_file_container *instance;
|
|
||||||
|
|
||||||
@synchronized(self) {
|
|
||||||
if(!instance) {
|
|
||||||
instance = [[self alloc] init];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return instance;
|
|
||||||
}
|
|
||||||
- (sid_file_container *)init {
|
|
||||||
if((self = [super init])) {
|
|
||||||
lock = [[NSLock alloc] init];
|
|
||||||
list = [[NSMutableDictionary alloc] initWithCapacity:0];
|
|
||||||
}
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
- (void)add_hint:(NSString *)path source:(id)source {
|
|
||||||
[lock lock];
|
|
||||||
[list setObject:source forKey:path];
|
|
||||||
[lock unlock];
|
|
||||||
}
|
|
||||||
- (void)remove_hint:(NSString *)path {
|
|
||||||
[lock lock];
|
|
||||||
[list removeObjectForKey:path];
|
|
||||||
[lock unlock];
|
|
||||||
}
|
|
||||||
- (BOOL)try_hint:(NSString *)path source:(id *)source {
|
|
||||||
[lock lock];
|
|
||||||
*source = [list objectForKey:path];
|
|
||||||
[lock unlock];
|
|
||||||
if(*source) {
|
|
||||||
[*source seek:0 whence:0];
|
|
||||||
return YES;
|
|
||||||
} else {
|
|
||||||
return NO;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@end
|
|
||||||
|
|
||||||
static void sidTuneLoader(const char *fileName, std::vector<uint8_t> &bufferRef) {
|
static void sidTuneLoader(const char *fileName, std::vector<uint8_t> &bufferRef) {
|
||||||
id<CogSource> source;
|
NSString *urlString = [NSString stringWithUTF8String:fileName];
|
||||||
BOOL usedHint = YES;
|
NSURL *url = [NSURL URLWithDataRepresentation:[urlString dataUsingEncoding:NSUTF8StringEncoding] relativeToURL:nil];
|
||||||
[_lock lock];
|
|
||||||
if(![[sid_file_container instance] try_hint:[NSString stringWithUTF8String:fileName] source:&source]) {
|
|
||||||
usedHint = NO;
|
|
||||||
|
|
||||||
NSString *urlString = [NSString stringWithUTF8String:fileName];
|
id audioSourceClass = NSClassFromString(@"AudioSource");
|
||||||
NSURL *url = [NSURL URLWithDataRepresentation:[urlString dataUsingEncoding:NSUTF8StringEncoding] relativeToURL:nil];
|
id<CogSource> source = [audioSourceClass audioSourceForURL:url];
|
||||||
|
|
||||||
id audioSourceClass = NSClassFromString(@"AudioSource");
|
if(![source open:url])
|
||||||
source = [audioSourceClass audioSourceForURL:url];
|
return;
|
||||||
|
|
||||||
if(![source open:url]) {
|
if(![source seekable])
|
||||||
[_lock unlock];
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(![source seekable]) {
|
|
||||||
[_lock unlock];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
[source seek:0 whence:SEEK_END];
|
[source seek:0 whence:SEEK_END];
|
||||||
long size = [source tell];
|
long size = [source tell];
|
||||||
|
@ -107,10 +42,7 @@ static void sidTuneLoader(const char *fileName, std::vector<uint8_t> &bufferRef)
|
||||||
|
|
||||||
[source read:&bufferRef[0] amount:size];
|
[source read:&bufferRef[0] amount:size];
|
||||||
|
|
||||||
if(!usedHint)
|
[source close];
|
||||||
[source close];
|
|
||||||
|
|
||||||
[_lock unlock];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@implementation SidDecoder
|
@implementation SidDecoder
|
||||||
|
@ -119,8 +51,6 @@ static void sidTuneLoader(const char *fileName, std::vector<uint8_t> &bufferRef)
|
||||||
if(![s seekable])
|
if(![s seekable])
|
||||||
return NO;
|
return NO;
|
||||||
|
|
||||||
[self setSource:s];
|
|
||||||
|
|
||||||
NSString *path = [[s url] absoluteString];
|
NSString *path = [[s url] absoluteString];
|
||||||
NSRange fragmentRange = [path rangeOfString:@"#" options:NSBackwardsSearch];
|
NSRange fragmentRange = [path rangeOfString:@"#" options:NSBackwardsSearch];
|
||||||
if(fragmentRange.location != NSNotFound) {
|
if(fragmentRange.location != NSNotFound) {
|
||||||
|
@ -129,9 +59,6 @@ static void sidTuneLoader(const char *fileName, std::vector<uint8_t> &bufferRef)
|
||||||
|
|
||||||
currentUrl = [path stringByRemovingPercentEncoding];
|
currentUrl = [path stringByRemovingPercentEncoding];
|
||||||
|
|
||||||
[[sid_file_container instance] add_hint:currentUrl source:s];
|
|
||||||
hintAdded = YES;
|
|
||||||
|
|
||||||
NSString *extension = [[s url] pathExtension];
|
NSString *extension = [[s url] pathExtension];
|
||||||
|
|
||||||
const char **extList = [extension isEqualToString:@"mus"] ? extListStr : extListEmpty;
|
const char **extList = [extension isEqualToString:@"mus"] ? extListStr : extListEmpty;
|
||||||
|
@ -326,11 +253,6 @@ static void sidTuneLoader(const char *fileName, std::vector<uint8_t> &bufferRef)
|
||||||
tune = NULL;
|
tune = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
source = nil;
|
|
||||||
if(hintAdded) {
|
|
||||||
[[sid_file_container instance] remove_hint:currentUrl];
|
|
||||||
hintAdded = NO;
|
|
||||||
}
|
|
||||||
currentUrl = nil;
|
currentUrl = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -342,14 +264,6 @@ static void sidTuneLoader(const char *fileName, std::vector<uint8_t> &bufferRef)
|
||||||
[self close];
|
[self close];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setSource:(id<CogSource>)s {
|
|
||||||
source = s;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id<CogSource>)source {
|
|
||||||
return source;
|
|
||||||
}
|
|
||||||
|
|
||||||
+ (NSArray *)fileTypes {
|
+ (NSArray *)fileTypes {
|
||||||
return @[@"sid", @"mus"];
|
return @[@"sid", @"mus"];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue