diff options
-rw-r--r-- | macosx/HBAudio.h | 15 | ||||
-rw-r--r-- | macosx/HBAudio.m | 305 | ||||
-rw-r--r-- | macosx/HBAudioController.m | 44 | ||||
-rw-r--r-- | macosx/HBAudioTrackPreset.m | 51 |
4 files changed, 172 insertions, 243 deletions
diff --git a/macosx/HBAudio.h b/macosx/HBAudio.h index 65655a3a6..20ea6ccda 100644 --- a/macosx/HBAudio.h +++ b/macosx/HBAudio.h @@ -20,21 +20,6 @@ extern NSString *keyAudioBitrate; @interface HBAudio : NSObject -{ - NSDictionary * track; - NSDictionary * codec; - NSDictionary * mixdown; - NSDictionary * sampleRate; - NSDictionary * bitRate; - NSNumber * drc; - NSNumber * gain; - NSNumber * videoContainerTag; - HBAudioController * controller; - NSMutableArray * codecs; - NSMutableArray * mixdowns; - NSMutableArray * bitRates; -} - @property (nonatomic, retain) NSDictionary *track; @property (nonatomic, retain) NSDictionary *codec; @property (nonatomic, retain) NSDictionary *mixdown; diff --git a/macosx/HBAudio.m b/macosx/HBAudio.m index 91e18f9d8..4de313324 100644 --- a/macosx/HBAudio.m +++ b/macosx/HBAudio.m @@ -41,7 +41,7 @@ static NSMutableArray *masterBitRateArray = nil; while (nil != (dict = [enumerator nextObject]) && !retval) { - if (nil != (aValue = [dict objectForKey: aKey]) && [aValue isEqual: anObject]) + if (nil != (aValue = dict[aKey]) && [aValue isEqual: anObject]) { retval = dict; } @@ -78,20 +78,17 @@ static NSMutableArray *masterBitRateArray = nil; if ((audio_encoder->codec & HB_ACODEC_PASS_FLAG) && (audio_encoder->codec != HB_ACODEC_AUTO_PASS)) { - audioMustMatchTrack = [NSNumber - numberWithInt:(audio_encoder->codec & - ~HB_ACODEC_PASS_FLAG)]; + audioMustMatchTrack = @(audio_encoder->codec & + ~HB_ACODEC_PASS_FLAG); } else { - audioMustMatchTrack = [NSNumber numberWithBool:NO]; + audioMustMatchTrack = @NO; } - [masterCodecArray addObject:[NSDictionary dictionaryWithObjectsAndKeys: - [NSString stringWithUTF8String:audio_encoder->name], keyAudioCodecName, - [NSNumber numberWithInt:audio_encoder->codec], keyAudioCodec, - [NSNumber numberWithInt:audio_encoder->muxers], keyAudioSupportedMuxers, - audioMustMatchTrack, keyAudioMustMatchTrack, - nil]]; + [masterCodecArray addObject:@{keyAudioCodecName: @(audio_encoder->name), + keyAudioCodec: @(audio_encoder->codec), + keyAudioSupportedMuxers: @(audio_encoder->muxers), + keyAudioMustMatchTrack: audioMustMatchTrack}]; } masterMixdownArray = [[NSMutableArray alloc] init]; // knowingly leaked @@ -99,28 +96,22 @@ static NSMutableArray *masterBitRateArray = nil; mixdown != NULL; mixdown = hb_mixdown_get_next(mixdown)) { - [masterMixdownArray addObject:[NSDictionary dictionaryWithObjectsAndKeys: - [NSString stringWithUTF8String:mixdown->name], keyAudioMixdownName, - [NSNumber numberWithInt:mixdown->amixdown], keyAudioMixdown, - nil]]; + [masterMixdownArray addObject:@{keyAudioMixdownName: @(mixdown->name), + keyAudioMixdown: @(mixdown->amixdown)}]; } // Note that for the Auto value we use 0 for the sample rate because our controller will give back the track's // input sample rate when it finds this 0 value as the selected sample rate. We do this because the input // sample rate depends on the track, which means it depends on the title, so cannot be nicely set up here. masterSampleRateArray = [[NSMutableArray alloc] init]; // knowingly leaked - [masterSampleRateArray addObject:[NSDictionary dictionaryWithObjectsAndKeys: - @"Auto", keyAudioSampleRateName, - [NSNumber numberWithInt:0], keyAudioSamplerate, - nil]]; + [masterSampleRateArray addObject:@{keyAudioSampleRateName: @"Auto", + keyAudioSamplerate: @0}]; for (const hb_rate_t *audio_samplerate = hb_audio_samplerate_get_next(NULL); audio_samplerate != NULL; audio_samplerate = hb_audio_samplerate_get_next(audio_samplerate)) { - [masterSampleRateArray addObject:[NSDictionary dictionaryWithObjectsAndKeys: - [NSString stringWithUTF8String:audio_samplerate->name], keyAudioSampleRateName, - [NSNumber numberWithInt:audio_samplerate->rate], keyAudioSamplerate, - nil]]; + [masterSampleRateArray addObject:@{keyAudioSampleRateName: @(audio_samplerate->name), + keyAudioSamplerate: @(audio_samplerate->rate)}]; } masterBitRateArray = [[NSMutableArray alloc] init]; // knowingly leaked @@ -128,10 +119,8 @@ static NSMutableArray *masterBitRateArray = nil; audio_bitrate != NULL; audio_bitrate = hb_audio_bitrate_get_next(audio_bitrate)) { - [masterBitRateArray addObject:[NSDictionary dictionaryWithObjectsAndKeys: - [NSString stringWithUTF8String:audio_bitrate->name], keyAudioBitrateName, - [NSNumber numberWithInt:audio_bitrate->rate], keyAudioBitrate, - nil]]; + [masterBitRateArray addObject:@{keyAudioBitrateName: @(audio_bitrate->name), + keyAudioBitrate: @(audio_bitrate->rate)}]; } } } @@ -146,22 +135,22 @@ static NSMutableArray *masterBitRateArray = nil; NSDictionary *dict; // First get a list of the permitted codecs based on the internal rules - if (nil != track && [self enabled]) + if (nil != self.track && self.enabled) { BOOL goodToAdd; for (unsigned int i = 0; i < count; i++) { - dict = [masterCodecArray objectAtIndex: i]; + dict = masterCodecArray[i]; // First make sure only codecs permitted by the container are here - goodToAdd = !!([[dict objectForKey:keyAudioSupportedMuxers] intValue] & - [videoContainerTag intValue]); + goodToAdd = !!([dict[keyAudioSupportedMuxers] intValue] & + [self.videoContainerTag intValue]); // Now we make sure if DTS or AC3 is not available in the track it is not put in the codec list, but in a general way - if ([[dict objectForKey: keyAudioMustMatchTrack] boolValue]) + if ([dict[keyAudioMustMatchTrack] boolValue]) { - if ([[dict objectForKey: keyAudioMustMatchTrack] intValue] != [[[self track] objectForKey: keyAudioInputCodec] intValue]) + if ([dict[keyAudioMustMatchTrack] intValue] != [self.track[keyAudioInputCodec] intValue]) { goodToAdd = NO; } @@ -178,15 +167,15 @@ static NSMutableArray *masterBitRateArray = nil; [self setCodecs: permittedCodecs]; // Ensure our codec is on the list of permitted codecs - if (![self codec] || ![permittedCodecs containsObject: [self codec]]) + if (!self.codec || ![permittedCodecs containsObject: self.codec]) { if (0 < [permittedCodecs count]) { - [self setCodec: [permittedCodecs objectAtIndex: 0]]; // This should be defaulting to Core Audio + self.codec = permittedCodecs[0]; // This should be defaulting to Core Audio } else { - [self setCodec: nil]; + self.codec = nil; } } } @@ -198,15 +187,15 @@ static NSMutableArray *masterBitRateArray = nil; NSDictionary *dict; int currentMixdown; - unsigned long long channelLayout = [[track objectForKey: keyAudioInputChannelLayout] unsignedLongLongValue]; + unsigned long long channelLayout = [self.track[keyAudioInputChannelLayout] unsignedLongLongValue]; NSUInteger count = [masterMixdownArray count]; - int codecCodec = [[codec objectForKey: keyAudioCodec] intValue]; + int codecCodec = [self.codec[keyAudioCodec] intValue]; int theDefaultMixdown = hb_mixdown_get_default(codecCodec, channelLayout); for (unsigned int i = 0; i < count; i++) { - dict = [masterMixdownArray objectAtIndex: i]; - currentMixdown = [[dict objectForKey: keyAudioMixdown] intValue]; + dict = masterMixdownArray[i]; + currentMixdown = [dict[keyAudioMixdown] intValue]; if (hb_mixdown_is_supported(currentMixdown, codecCodec, channelLayout)) { @@ -214,24 +203,24 @@ static NSMutableArray *masterBitRateArray = nil; } } - if (![self enabled]) + if (!self.enabled) { permittedMixdowns = nil; } // Now make sure the permitted list and the actual ones matches - [self setMixdowns: permittedMixdowns]; + self.mixdowns = permittedMixdowns; // Select the proper one if (shouldSetDefault) { - [self setMixdown: [permittedMixdowns dictionaryWithObject: [NSNumber numberWithInt: theDefaultMixdown] - matchingKey: keyAudioMixdown]]; + self.mixdown = [permittedMixdowns dictionaryWithObject: @(theDefaultMixdown) + matchingKey: keyAudioMixdown]; } - if (![self mixdown] || ![permittedMixdowns containsObject: [self mixdown]]) + if (!self.mixdown || ![permittedMixdowns containsObject: self.mixdown]) { - [self setMixdown: [permittedMixdowns lastObject]]; + self.mixdown = [permittedMixdowns lastObject]; } } @@ -246,50 +235,46 @@ static NSMutableArray *masterBitRateArray = nil; BOOL shouldAdd; NSUInteger count = [masterBitRateArray count]; - int trackInputBitRate = [[[self track] objectForKey: keyAudioInputBitrate] intValue]; - int theSampleRate = [[[self sampleRate] objectForKey: keyAudioSamplerate] intValue]; + int trackInputBitRate = [self.track[keyAudioInputBitrate] intValue]; + int theSampleRate = [self.sampleRate[keyAudioSamplerate] intValue]; if (0 == theSampleRate) // this means Auto { - theSampleRate = [[[self track] objectForKey: keyAudioInputSampleRate] intValue]; + theSampleRate = [self.track[keyAudioInputSampleRate] intValue]; } - int ourCodec = [[codec objectForKey:keyAudioCodec] intValue]; - int ourMixdown = [[[self mixdown] objectForKey:keyAudioMixdown] intValue]; + int ourCodec = [self.codec[keyAudioCodec] intValue]; + int ourMixdown = [self.mixdown[keyAudioMixdown] intValue]; int theDefaultBitRate = hb_audio_bitrate_get_default(ourCodec, theSampleRate, ourMixdown); hb_audio_bitrate_get_limits(ourCodec, theSampleRate, ourMixdown, &minBitRate, &maxBitRate); - BOOL codecIsPassthru = ([[codec objectForKey: keyAudioCodec] intValue] & HB_ACODEC_PASS_FLAG) ? YES : NO; + BOOL codecIsPassthru = ([self.codec[keyAudioCodec] intValue] & HB_ACODEC_PASS_FLAG) ? YES : NO; BOOL codecIsLossless = (theDefaultBitRate == -1) ? YES : NO; if (codecIsPassthru) { - NSDictionary *sourceBitRate = [masterBitRateArray dictionaryWithObject: [NSNumber numberWithInt: trackInputBitRate] + NSDictionary *sourceBitRate = [masterBitRateArray dictionaryWithObject: @(trackInputBitRate) matchingKey: keyAudioBitrate]; if (!sourceBitRate) { // the source bitrate isn't in the master array - create it - sourceBitRate = [NSDictionary dictionaryWithObjectsAndKeys: - [NSString stringWithFormat: @"%d", trackInputBitRate], keyAudioBitrateName, - [NSNumber numberWithInt: trackInputBitRate], keyAudioBitrate, - nil]; + sourceBitRate = @{keyAudioBitrateName: [NSString stringWithFormat: @"%d", trackInputBitRate], + keyAudioBitrate: @(trackInputBitRate)}; } [permittedBitRates addObject: sourceBitRate]; } else if (codecIsLossless) { - NSDictionary *bitRateNotApplicable = [NSDictionary dictionaryWithObjectsAndKeys: - @"N/A", keyAudioBitrateName, - [NSNumber numberWithInt: -1], keyAudioBitrate, - nil]; + NSDictionary *bitRateNotApplicable = @{keyAudioBitrateName: @"N/A", + keyAudioBitrate: @-1}; [permittedBitRates addObject: bitRateNotApplicable]; } else { for (unsigned int i = 0; i < count; i++) { - dict = [masterBitRateArray objectAtIndex: i]; - currentBitRate = [[dict objectForKey: keyAudioBitrate] intValue]; + dict = masterBitRateArray[i]; + currentBitRate = [dict[keyAudioBitrate] intValue]; // First ensure the bitrate falls within range of the codec shouldAdd = (currentBitRate >= minBitRate && currentBitRate <= maxBitRate); @@ -301,13 +286,13 @@ static NSMutableArray *masterBitRateArray = nil; } } - if (![self enabled]) + if (!self.enabled) { permittedBitRates = nil; } // Make sure we are updated with the permitted list - [self setBitRates: permittedBitRates]; + self.bitRates = permittedBitRates; // Select the proper one if (shouldSetDefault) @@ -315,114 +300,92 @@ static NSMutableArray *masterBitRateArray = nil; [self setBitRateFromName: [NSString stringWithFormat:@"%d", theDefaultBitRate]]; } - if (![self bitRate] || ![permittedBitRates containsObject: [self bitRate]]) + if (!self.bitRate || ![permittedBitRates containsObject: self.bitRate]) { - [self setBitRate: [permittedBitRates lastObject]]; + self.bitRate = [permittedBitRates lastObject]; } } -- (id) init - -{ - if (self = [super init]) - { - [self addObserver: self forKeyPath: @"videoContainerTag" options: 0 context: NULL]; - [self addObserver: self forKeyPath: @"track" options: NSKeyValueObservingOptionOld context: NULL]; - [self addObserver: self forKeyPath: @"codec" options: 0 context: NULL]; - [self addObserver: self forKeyPath: @"mixdown" options: 0 context: NULL]; - [self addObserver: self forKeyPath: @"sampleRate" options: 0 context: NULL]; - } - return self; -} - #pragma mark - #pragma mark Accessors -@synthesize track; -@synthesize codec; -@synthesize mixdown; -@synthesize sampleRate; -@synthesize bitRate; -@synthesize drc; -@synthesize gain; -@synthesize videoContainerTag; -@synthesize controller; - -@synthesize codecs; -@synthesize mixdowns; -@synthesize bitRates; - - (NSArray *) sampleRates { return masterSampleRateArray; } - (void) dealloc - { - [self removeObserver: self forKeyPath: @"videoContainerTag"]; - [self removeObserver: self forKeyPath: @"track"]; - [self removeObserver: self forKeyPath: @"codec"]; - [self removeObserver: self forKeyPath: @"mixdown"]; - [self removeObserver: self forKeyPath: @"sampleRate"]; - [self setTrack: nil]; - [self setCodec: nil]; - [self setMixdown: nil]; - [self setSampleRate: nil]; - [self setBitRate: nil]; - [self setDrc: nil]; - [self setGain: nil]; - [self setVideoContainerTag: nil]; - [self setCodecs: nil]; - [self setMixdowns: nil]; - [self setBitRates: nil]; + [_track release]; + [_codec release]; + [_mixdown release]; + [_sampleRate release]; + [_bitRate release]; + [_drc release]; + [_gain release]; + [_videoContainerTag release]; + [_codecs release]; + [_mixdowns release]; + [_bitRates release]; + [super dealloc]; } #pragma mark - -#pragma mark KVO +#pragma mark Setters -- (void) observeValueForKeyPath: (NSString *) keyPath ofObject: (id) object change: (NSDictionary *) change context: (void *) context +- (void)setVideoContainerTag:(NSNumber *)videoContainerTag +{ + [_videoContainerTag autorelease]; + _videoContainerTag = [videoContainerTag retain]; + [self updateCodecs]; +} +- (void)setTrack:(NSDictionary *)track { - if ([keyPath isEqualToString: @"videoContainerTag"]) + NSDictionary *oldValue = _track; + _track = [track retain]; + if (nil != _track) { [self updateCodecs]; - } - else if ([keyPath isEqualToString: @"track"]) - { - if (nil != [self track]) + [self updateMixdowns: YES]; + if (self.enabled) { - [self updateCodecs]; - [self updateMixdowns: YES]; - if ([self enabled]) - { - [self setSampleRate: [[self sampleRates] objectAtIndex: 0]]; // default to Auto - } - if ([[controller noneTrack] isEqual: [change objectForKey: NSKeyValueChangeOldKey]]) - { - [controller switchingTrackFromNone: self]; - } - if ([[controller noneTrack] isEqual: [self track]]) - { - [controller settingTrackToNone: self]; - } + self.sampleRate = self.sampleRates[0]; // default to Auto + } + if ([self.controller.noneTrack isEqual: oldValue]) + { + [self.controller switchingTrackFromNone: self]; + } + if ([self.controller.noneTrack isEqual: self.track]) + { + [self.controller settingTrackToNone: self]; } } - else if ([keyPath isEqualToString: @"codec"]) - { - [self updateMixdowns: YES]; - [self updateBitRates: YES]; - } - else if ([keyPath isEqualToString: @"mixdown"]) - { - [self updateBitRates: YES]; - [[NSNotificationCenter defaultCenter] postNotificationName: HBMixdownChangedNotification object: self]; - } - else if ([keyPath isEqualToString: @"sampleRate"]) - { - [self updateBitRates: NO]; - } + [oldValue release]; +} + +- (void)setCodec:(NSDictionary *)codec +{ + [_codec autorelease]; + _codec = [codec retain]; + [self updateMixdowns: YES]; + [self updateBitRates: YES]; +} + +- (void)setMixdown:(NSDictionary *)mixdown +{ + [_mixdown autorelease]; + _mixdown = [mixdown retain]; + [self updateBitRates: YES]; + [[NSNotificationCenter defaultCenter] postNotificationName: HBMixdownChangedNotification object: self]; +} + +- (void)setSampleRate:(NSDictionary *)sampleRate +{ + [_sampleRate autorelease]; + _sampleRate = [sampleRate retain]; + [self updateBitRates: NO]; } #pragma mark - @@ -431,19 +394,19 @@ static NSMutableArray *masterBitRateArray = nil; - (void) setTrackFromIndex: (int) aValue { - [self setTrack: [self.controller.masterTrackArray dictionaryWithObject: [NSNumber numberWithInt: aValue] - matchingKey: keyAudioTrackIndex]]; + self.track = [self.controller.masterTrackArray dictionaryWithObject: @(aValue) + matchingKey: keyAudioTrackIndex]; } // This returns whether it is able to set the actual codec desired. - (BOOL) setCodecFromName: (NSString *) aValue { - NSDictionary *dict = [[self codecs] dictionaryWithObject: aValue matchingKey: keyAudioCodecName]; + NSDictionary *dict = [self.codecs dictionaryWithObject: aValue matchingKey: keyAudioCodecName]; if (nil != dict) { - [self setCodec: dict]; + self.codec = dict; } return (nil != dict); } @@ -451,33 +414,33 @@ static NSMutableArray *masterBitRateArray = nil; - (void) setMixdownFromName: (NSString *) aValue { - NSDictionary *dict = [[self mixdowns] dictionaryWithObject: aValue matchingKey: keyAudioMixdownName]; + NSDictionary *dict = [self.mixdowns dictionaryWithObject: aValue matchingKey: keyAudioMixdownName]; if (nil != dict) { - [self setMixdown: dict]; + self.mixdown = dict; } } - (void) setSampleRateFromName: (NSString *) aValue { - NSDictionary *dict = [[self sampleRates] dictionaryWithObject: aValue matchingKey: keyAudioSampleRateName]; + NSDictionary *dict = [self.sampleRates dictionaryWithObject: aValue matchingKey: keyAudioSampleRateName]; if (nil != dict) { - [self setSampleRate: dict]; + self.sampleRate = dict; } } - (void) setBitRateFromName: (NSString *) aValue { - NSDictionary *dict = [[self bitRates] dictionaryWithObject: aValue matchingKey: keyAudioBitrateName]; + NSDictionary *dict = [self.bitRates dictionaryWithObject: aValue matchingKey: keyAudioBitrateName]; if (nil != dict) { - [self setBitRate: dict]; + self.bitRate = dict; } } @@ -496,7 +459,7 @@ static NSMutableArray *masterBitRateArray = nil; { if (0.0 < [*ioValue floatValue] && 1.0 > [*ioValue floatValue]) { - *ioValue = [NSNumber numberWithFloat: 1.0]; + *ioValue = @1.0f; } } @@ -509,12 +472,12 @@ static NSMutableArray *masterBitRateArray = nil; - (BOOL) validateGain: (id *) ioValue error: (NSError *) outError { BOOL retval = YES; - + if (nil != *ioValue) { if (0.0 < [*ioValue floatValue] && 1.0 > [*ioValue floatValue]) { - *ioValue = [NSNumber numberWithFloat: 0.0]; + *ioValue = @0.0f; } } @@ -527,17 +490,17 @@ static NSMutableArray *masterBitRateArray = nil; - (BOOL) enabled { - return (nil != track) ? (![track isEqual: [controller noneTrack]]) : NO; + return (nil != self.track) ? (![self.track isEqual: self.controller.noneTrack]) : NO; } - (BOOL) mixdownEnabled { - BOOL retval = [self enabled]; + BOOL retval = self.enabled; if (retval) { - int myMixdown = [[[self mixdown] objectForKey: keyAudioMixdown] intValue]; + int myMixdown = [self.mixdown[keyAudioMixdown] intValue]; if (myMixdown == HB_AMIXDOWN_NONE) { // "None" mixdown (passthru) @@ -550,11 +513,11 @@ static NSMutableArray *masterBitRateArray = nil; - (BOOL) bitrateEnabled { - BOOL retval = [self enabled]; + BOOL retval = self.enabled; if (retval) { - int myCodecCodec = [[[self codec] objectForKey:keyAudioCodec] intValue]; + int myCodecCodec = [self.codec[keyAudioCodec] intValue]; int myCodecDefaultBitrate = hb_audio_bitrate_get_default(myCodecCodec, 0, 0); if (myCodecDefaultBitrate < 0) { @@ -567,13 +530,13 @@ static NSMutableArray *masterBitRateArray = nil; - (BOOL) DRCEnabled { - BOOL retval = [self enabled]; + BOOL retval = self.enabled; if (retval) { - int myTrackParam = [[[self track] objectForKey: keyAudioInputCodecParam] intValue]; - int myTrackCodec = [[[self track] objectForKey: keyAudioInputCodec] intValue]; - int myCodecCodec = [[[self codec] objectForKey: keyAudioCodec] intValue]; + int myTrackParam = [self.track[keyAudioInputCodecParam] intValue]; + int myTrackCodec = [self.track[keyAudioInputCodec] intValue]; + int myCodecCodec = [self.codec[keyAudioCodec] intValue]; if (!hb_audio_can_apply_drc(myTrackCodec, myTrackParam, myCodecCodec)) { retval = NO; @@ -585,11 +548,11 @@ static NSMutableArray *masterBitRateArray = nil; - (BOOL) PassThruDisabled { - BOOL retval = [self enabled]; + BOOL retval = self.enabled; if (retval) { - int myCodecCodec = [[[self codec] objectForKey: keyAudioCodec] intValue]; + int myCodecCodec = [self.codec[keyAudioCodec] intValue]; if (myCodecCodec & HB_ACODEC_PASS_FLAG) { retval = NO; diff --git a/macosx/HBAudioController.m b/macosx/HBAudioController.m index e63e4c82c..171f37e39 100644 --- a/macosx/HBAudioController.m +++ b/macosx/HBAudioController.m @@ -62,7 +62,7 @@ NSString *HBMixdownChangedNotification = @"HBMixdownChangedNotification"; self = [super initWithNibName:@"Audio" bundle:nil]; if (self) { - [self setVideoContainerTag: [NSNumber numberWithInt: HB_MUX_MP4]]; + [self setVideoContainerTag: @HB_MUX_MP4]; audioArray = [[NSMutableArray alloc] init]; /* register that we are interested in changes made to the video container */ @@ -178,13 +178,13 @@ NSString *HBMixdownChangedNotification = @"HBMixdownChangedNotification"; // The following is the pattern to follow, but with Audio%dTrack being the key to seek... // Can we assume that there will be no skip in the data? - for (NSDictionary *audioDict in [aQueue objectForKey:@"AudioList"]) + for (NSDictionary *audioDict in aQueue[@"AudioList"]) { HBAudio *newAudio = [[HBAudio alloc] init]; [newAudio setController: self]; [self insertObject: newAudio inAudioArrayAtIndex: [self countOfAudioArray]]; [newAudio setVideoContainerTag: [self videoContainerTag]]; - [newAudio setTrackFromIndex: audioDict[@"Track"]]; + [newAudio setTrackFromIndex: [audioDict[@"Track"] intValue] + 1]; [newAudio setCodecFromName: audioDict[@"Encoder"]]; [newAudio setMixdownFromName: audioDict[@"Mixdown"]]; [newAudio setSampleRateFromName: audioDict[@"Samplerate"]]; @@ -401,7 +401,7 @@ NSString *HBMixdownChangedNotification = @"HBMixdownChangedNotification"; for (NSUInteger i = 0; i < audioArrayCount && !retval; i++) { HBAudio *anAudio = [self objectInAudioArrayAtIndex: i]; - if ([anAudio enabled] && aCodecValue == [[[anAudio codec] objectForKey: keyAudioCodec] intValue]) + if ([anAudio enabled] && aCodecValue == [[anAudio codec][keyAudioCodec] intValue]) { retval = YES; } @@ -417,8 +417,8 @@ NSString *HBMixdownChangedNotification = @"HBMixdownChangedNotification"; [self insertObject: newAudio inAudioArrayAtIndex: [self countOfAudioArray]]; [newAudio setVideoContainerTag: [self videoContainerTag]]; [newAudio setTrack: noneTrack]; - [newAudio setDrc: [NSNumber numberWithFloat: 0.0]]; - [newAudio setGain: [NSNumber numberWithFloat: 0.0]]; + [newAudio setDrc: @0.0f]; + [newAudio setGain: @0.0f]; [newAudio release]; } @@ -472,7 +472,7 @@ NSString *HBMixdownChangedNotification = @"HBMixdownChangedNotification"; { NSDictionary *notDict = [aNotification userInfo]; - [self setVideoContainerTag: [notDict objectForKey: keyContainerTag]]; + [self setVideoContainerTag: notDict[keyContainerTag]]; // Update each of the instances because this value influences possible settings. for (HBAudio *audioObject in audioArray) @@ -489,7 +489,7 @@ NSString *HBMixdownChangedNotification = @"HBMixdownChangedNotification"; { NSDictionary *notDict = [aNotification userInfo]; - NSData *theData = [notDict objectForKey: keyTitleTag]; + NSData *theData = notDict[keyTitleTag]; hb_title_t *title = NULL; // Reinitialize the configured list of audio tracks @@ -505,25 +505,21 @@ NSString *HBMixdownChangedNotification = @"HBMixdownChangedNotification"; // Reinitialize the master list of available audio tracks from this title NSMutableArray *newTrackArray = [NSMutableArray array]; [noneTrack release]; - noneTrack = [[NSDictionary dictionaryWithObjectsAndKeys: - [NSNumber numberWithInt: 0], keyAudioTrackIndex, - NSLocalizedString(@"None", @"None"), keyAudioTrackName, - [NSNumber numberWithInt: 0], keyAudioInputCodec, - nil] retain]; + noneTrack = [@{keyAudioTrackIndex: @0, + keyAudioTrackName: NSLocalizedString(@"None", @"None"), + keyAudioInputCodec: @0} retain]; [newTrackArray addObject: noneTrack]; for (i = 0; i < count; i++) { audio = (hb_audio_config_t *) hb_list_audio_config_item(list, i); - [newTrackArray addObject: [NSDictionary dictionaryWithObjectsAndKeys: - [NSNumber numberWithInt: i + 1], keyAudioTrackIndex, - [NSString stringWithFormat: @"%d: %s", i, audio->lang.description], keyAudioTrackName, - [NSNumber numberWithInt: audio->in.bitrate / 1000], keyAudioInputBitrate, - [NSNumber numberWithInt: audio->in.samplerate], keyAudioInputSampleRate, - [NSNumber numberWithInt: audio->in.codec], keyAudioInputCodec, - [NSNumber numberWithInt: audio->in.codec_param], keyAudioInputCodecParam, - [NSNumber numberWithUnsignedLongLong: audio->in.channel_layout], keyAudioInputChannelLayout, - @(audio->lang.iso639_2), keyAudioTrackLanguageIsoCode, - nil]]; + [newTrackArray addObject: @{keyAudioTrackIndex: @(i + 1), + keyAudioTrackName: [NSString stringWithFormat: @"%d: %s", i, audio->lang.description], + keyAudioInputBitrate: @(audio->in.bitrate / 1000), + keyAudioInputSampleRate: @(audio->in.samplerate), + keyAudioInputCodec: [NSNumber numberWithUnsignedInteger: audio->in.codec], + keyAudioInputCodecParam: [NSNumber numberWithUnsignedInteger: audio->in.codec_param], + keyAudioInputChannelLayout: @(audio->in.channel_layout), + keyAudioTrackLanguageIsoCode: @(audio->lang.iso639_2)}]; } self.masterTrackArray = newTrackArray; [self switchingTrackFromNone: nil]; // this ensures there is a None track at the end of the list @@ -571,7 +567,7 @@ NSString *HBMixdownChangedNotification = @"HBMixdownChangedNotification"; - (HBAudio *) objectInAudioArrayAtIndex: (NSUInteger) index { - return [audioArray objectAtIndex: index]; + return audioArray[index]; } - (void) insertObject: (HBAudio *) audioObject inAudioArrayAtIndex: (NSUInteger) index; diff --git a/macosx/HBAudioTrackPreset.m b/macosx/HBAudioTrackPreset.m index 9f91c3ab8..dc829874b 100644 --- a/macosx/HBAudioTrackPreset.m +++ b/macosx/HBAudioTrackPreset.m @@ -24,34 +24,29 @@ static void *HBAudioEncoderContex = &HBAudioEncoderContex; _sampleRate = 0; _bitRate = 160; _mixdown = HB_AMIXDOWN_DOLBYPLII; - - // add a serie of observers to keep the tracks properties in a valid state. - [self addObserver:self forKeyPath:@"encoder" options:0 context:HBAudioEncoderContex]; - [self addObserver:self forKeyPath:@"mixdown" options:0 context:HBAudioEncoderContex]; - [self addObserver:self forKeyPath:@"sampleRate" options:0 context:HBAudioEncoderContex]; } return self; } -- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context +#pragma mark - Setters override + +- (void)setEncoder:(int)encoder { - if (context == HBAudioEncoderContex) - { - // Validate the settings - if ([keyPath isEqualToString:@"encoder"]) - { - [self validateMixdown]; - [self validateBitrate]; - } - else if ([keyPath isEqualToString:@"mixdown"] || [keyPath isEqualToString:@"sampleRate"]) - { - [self validateBitrate]; - } - } - else - { - [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; - } + _encoder = encoder; + [self validateMixdown]; + [self validateBitrate]; +} + +- (void)setMixdown:(int)mixdown +{ + _mixdown = mixdown; + [self validateBitrate]; +} + +- (void)setSampleRate:(int)sampleRate +{ + _sampleRate = sampleRate; + [self validateBitrate]; } #pragma mark - @@ -155,16 +150,6 @@ static void *HBAudioEncoderContex = &HBAudioEncoderContex; return retval; } -- (void)dealloc -{ - // Remove the KVO observers before deallocing the instance. - [self removeObserver:self forKeyPath:@"encoder"]; - [self removeObserver:self forKeyPath:@"mixdown"]; - [self removeObserver:self forKeyPath:@"sampleRate"]; - - [super dealloc]; -} - #pragma mark - Options - (NSArray *)encoders |