Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated for ARC #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file modified TPAACAudioConverter.h
100644 → 100755
Empty file.
23 changes: 4 additions & 19 deletions TPAACAudioConverter.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
NSString * TPAACAudioConverterErrorDomain = @"com.atastypixel.TPAACAudioConverterErrorDomain";


#define checkResult(result,operation) (_checkResultLite((result),(operation),__FILE__,__LINE__))

static inline BOOL _checkResultLite(OSStatus result, const char *operation, const char* file, int line) {
if ( result != noErr ) {
Expand All @@ -24,6 +23,7 @@ static inline BOOL _checkResultLite(OSStatus result, const char *operation, cons
}
return YES;
}
#define checkResult(result,operation) (_checkResultLite((result),(operation),__FILE__,__LINE__))

@interface TPAACAudioConverter () {
BOOL _processing;
Expand Down Expand Up @@ -107,12 +107,10 @@ - (id)initWithDelegate:(id<TPAACAudioConverterDelegate>)delegate dataSource:(id<
}

- (void)dealloc {
[_condition release];
self.source = nil;
self.destination = nil;
self.delegate = nil;
self.dataSource = nil;
[super dealloc];
}

-(void)start {
Expand All @@ -128,7 +126,6 @@ -(void)start {

_cancelled = NO;
_processing = YES;
[self retain];
[self performSelectorInBackground:@selector(processingThread) withObject:nil];
}

Expand All @@ -142,7 +139,6 @@ -(void)cancel {
checkResult(AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof (allowMixing), &allowMixing),
"AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers)");
}
[self autorelease];
}

- (void)interrupt {
Expand Down Expand Up @@ -171,7 +167,6 @@ - (void)reportCompletion {
checkResult(AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof (allowMixing), &allowMixing),
"AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers)");
}
[self autorelease];
}

- (void)reportErrorAndCleanup:(NSError*)error {
Expand All @@ -182,25 +177,23 @@ - (void)reportErrorAndCleanup:(NSError*)error {
checkResult(AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof (allowMixing), &allowMixing),
"AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers)");
}
[self autorelease];
[_delegate AACAudioConverter:self didFailWithError:error];
}

- (void)processingThread {
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];

[[NSThread currentThread] setThreadPriority:0.9];

ExtAudioFileRef sourceFile = NULL;
AudioStreamBasicDescription sourceFormat;
NSLog(@"Opening path for compression %@: ", [NSURL fileURLWithPath:_source]);
if ( _source ) {
if ( !checkResult(ExtAudioFileOpenURL((CFURLRef)[NSURL fileURLWithPath:_source], &sourceFile), "ExtAudioFileOpenURL") ) {
if ( !checkResult( ExtAudioFileOpenURL((__bridge CFURLRef)[NSURL fileURLWithPath:_source], &sourceFile) , "ExtAudioFileOpenURL") ) {
[self performSelectorOnMainThread:@selector(reportErrorAndCleanup:)
withObject:[NSError errorWithDomain:TPAACAudioConverterErrorDomain
code:TPAACAudioConverterFileError
userInfo:[NSDictionary dictionaryWithObject:NSLocalizedString(@"Couldn't open the source file", @"Error message") forKey:NSLocalizedDescriptionKey]]
waitUntilDone:NO];
[pool release];
_processing = NO;
return;
}
Expand All @@ -214,7 +207,6 @@ - (void)processingThread {
code:TPAACAudioConverterFormatError
userInfo:[NSDictionary dictionaryWithObject:NSLocalizedString(@"Couldn't read the source file", @"Error message") forKey:NSLocalizedDescriptionKey]]
waitUntilDone:NO];
[pool release];
_processing = NO;
return;
}
Expand All @@ -234,19 +226,17 @@ - (void)processingThread {
code:TPAACAudioConverterFormatError
userInfo:[NSDictionary dictionaryWithObject:NSLocalizedString(@"Couldn't setup destination format", @"Error message") forKey:NSLocalizedDescriptionKey]]
waitUntilDone:NO];
[pool release];
_processing = NO;
return;
}

ExtAudioFileRef destinationFile;
if ( !checkResult(ExtAudioFileCreateWithURL((CFURLRef)[NSURL fileURLWithPath:_destination], kAudioFileM4AType, &destinationFormat, NULL, kAudioFileFlags_EraseFile, &destinationFile), "ExtAudioFileCreateWithURL") ) {
if ( !checkResult(ExtAudioFileCreateWithURL((__bridge CFURLRef)[NSURL fileURLWithPath:_destination], kAudioFileM4AType, &destinationFormat, NULL, kAudioFileFlags_EraseFile, &destinationFile), "ExtAudioFileCreateWithURL") ) {
[self performSelectorOnMainThread:@selector(reportErrorAndCleanup:)
withObject:[NSError errorWithDomain:TPAACAudioConverterErrorDomain
code:TPAACAudioConverterFileError
userInfo:[NSDictionary dictionaryWithObject:NSLocalizedString(@"Couldn't open the source file", @"Error message") forKey:NSLocalizedDescriptionKey]]
waitUntilDone:NO];
[pool release];
_processing = NO;
return;
}
Expand Down Expand Up @@ -278,7 +268,6 @@ - (void)processingThread {
code:TPAACAudioConverterFormatError
userInfo:[NSDictionary dictionaryWithObject:NSLocalizedString(@"Couldn't setup intermediate conversion format", @"Error message") forKey:NSLocalizedDescriptionKey]]
waitUntilDone:NO];
[pool release];
_processing = NO;
return;
}
Expand Down Expand Up @@ -326,7 +315,6 @@ - (void)processingThread {
code:TPAACAudioConverterFormatError
userInfo:[NSDictionary dictionaryWithObject:NSLocalizedString(@"Error reading the source file", @"Error message") forKey:NSLocalizedDescriptionKey]]
waitUntilDone:NO];
[pool release];
_processing = NO;
return;
}
Expand Down Expand Up @@ -358,7 +346,6 @@ - (void)processingThread {
code:TPAACAudioConverterUnrecoverableInterruptionError
userInfo:[NSDictionary dictionaryWithObject:NSLocalizedString(@"Interrupted", @"Error message") forKey:NSLocalizedDescriptionKey]]
waitUntilDone:NO];
[pool release];
_processing = NO;
return;
}
Expand Down Expand Up @@ -399,7 +386,6 @@ - (void)processingThread {
code:TPAACAudioConverterFormatError
userInfo:[NSDictionary dictionaryWithObject:NSLocalizedString(@"Error writing the destination file", @"Error message") forKey:NSLocalizedDescriptionKey]]
waitUntilDone:NO];
[pool release];
_processing = NO;
return;
}
Expand All @@ -421,7 +407,6 @@ - (void)processingThread {

_processing = NO;

[pool release];
}

@end