diff options
Diffstat (limited to 'macosx')
-rw-r--r-- | macosx/HBAudio.m | 75 | ||||
-rw-r--r-- | macosx/HBAudioController.m | 44 | ||||
-rw-r--r-- | macosx/HBPreferencesController.m | 2 |
3 files changed, 59 insertions, 62 deletions
diff --git a/macosx/HBAudio.m b/macosx/HBAudio.m index 62e0658b3..3be645456 100644 --- a/macosx/HBAudio.m +++ b/macosx/HBAudio.m @@ -14,10 +14,6 @@ NSString *keyAudioMP4 = @"keyAudioMP4"; NSString *keyAudioMKV = @"keyAudioMKV"; NSString *keyAudioSampleRateName = @"keyAudioSampleRateName"; NSString *keyAudioBitrateName = @"keyAudioBitrateName"; -NSString *keyAudioMinimumBitrate = @"keyAudioMinimumBitrate"; -NSString *keyAudioMaximumBitrate = @"keyAudioMaximumBitrate"; -NSString *keyAudioMinimumBitrate6Channel = @"keyAudioMinimumBitrate6Channel"; -NSString *keyAudioMaximumBitrate6Channel = @"keyAudioMaximumBitrate6Channel"; NSString *keyAudioMustMatchTrack = @"keyAudioMustMatchTrack"; NSString *keyAudioMixdownName = @"keyAudioMixdownName"; NSString *keyAudioMixdownLimitsToTrackBitRate = @"keyAudioMixdownLimitsToTrackBitRate"; @@ -31,8 +27,6 @@ NSString *keyAudioBitrate = @"bitrate"; static NSMutableArray *masterCodecArray = nil; static NSMutableArray *masterSampleRateArray = nil; static NSMutableArray *masterBitRateArray = nil; -static NSDictionary *defaultBitRate = nil; -static NSDictionary *bitRate384 = nil; @interface NSArray (HBAudioSupport) - (NSDictionary *) dictionaryWithObject: (id) anObject matchingKey: (NSString *) aKey; @@ -81,10 +75,6 @@ static NSDictionary *bitRate384 = nil; [NSNumber numberWithBool: YES], keyAudioMP4, [NSNumber numberWithBool: YES], keyAudioMKV, [NSNumber numberWithBool: NO], keyAudioMustMatchTrack, - [NSNumber numberWithInt: 64], keyAudioMinimumBitrate, - [NSNumber numberWithInt: 320], keyAudioMaximumBitrate, - [NSNumber numberWithInt: 128], keyAudioMinimumBitrate6Channel, - [NSNumber numberWithInt: 768], keyAudioMaximumBitrate6Channel, nil]]; [masterCodecArray addObject: [NSDictionary dictionaryWithObjectsAndKeys: NSLocalizedString(@"AAC (faac)", @"AAC (faac)"), keyAudioCodecName, @@ -92,10 +82,6 @@ static NSDictionary *bitRate384 = nil; [NSNumber numberWithBool: YES], keyAudioMP4, [NSNumber numberWithBool: YES], keyAudioMKV, [NSNumber numberWithBool: NO], keyAudioMustMatchTrack, - [NSNumber numberWithInt: 32], keyAudioMinimumBitrate, - [NSNumber numberWithInt: 320], keyAudioMaximumBitrate, - [NSNumber numberWithInt: 192], keyAudioMinimumBitrate6Channel, - [NSNumber numberWithInt: 768], keyAudioMaximumBitrate6Channel, nil]]; [masterCodecArray addObject: [NSDictionary dictionaryWithObjectsAndKeys: NSLocalizedString(@"MP3 (lame)", @"MP3 (lame)"), keyAudioCodecName, @@ -103,10 +89,6 @@ static NSDictionary *bitRate384 = nil; [NSNumber numberWithBool: YES], keyAudioMP4, [NSNumber numberWithBool: YES], keyAudioMKV, [NSNumber numberWithBool: NO], keyAudioMustMatchTrack, - [NSNumber numberWithInt: 32], keyAudioMinimumBitrate, - [NSNumber numberWithInt: 320], keyAudioMaximumBitrate, - [NSNumber numberWithInt: 32], keyAudioMinimumBitrate6Channel, - [NSNumber numberWithInt: 320], keyAudioMaximumBitrate6Channel, nil]]; [masterCodecArray addObject: [NSDictionary dictionaryWithObjectsAndKeys: NSLocalizedString(@"AC3 Passthru", @"AC3 Passthru"), keyAudioCodecName, @@ -114,10 +96,6 @@ static NSDictionary *bitRate384 = nil; [NSNumber numberWithBool: YES], keyAudioMP4, [NSNumber numberWithBool: YES], keyAudioMKV, [NSNumber numberWithInt: HB_ACODEC_AC3], keyAudioMustMatchTrack, - [NSNumber numberWithInt: 32], keyAudioMinimumBitrate, - [NSNumber numberWithInt: 384], keyAudioMaximumBitrate, - [NSNumber numberWithInt: 32], keyAudioMinimumBitrate6Channel, - [NSNumber numberWithInt: 384], keyAudioMaximumBitrate6Channel, nil]]; [masterCodecArray addObject: [NSDictionary dictionaryWithObjectsAndKeys: NSLocalizedString(@"AC3", @"AC3"), keyAudioCodecName, @@ -125,10 +103,6 @@ static NSDictionary *bitRate384 = nil; [NSNumber numberWithBool: YES], keyAudioMP4, [NSNumber numberWithBool: YES], keyAudioMKV, [NSNumber numberWithBool: NO], keyAudioMustMatchTrack, - [NSNumber numberWithInt: 32], keyAudioMinimumBitrate, - [NSNumber numberWithInt: 640], keyAudioMaximumBitrate, - [NSNumber numberWithInt: 32], keyAudioMinimumBitrate6Channel, - [NSNumber numberWithInt: 640], keyAudioMaximumBitrate6Channel, nil]]; [masterCodecArray addObject: [NSDictionary dictionaryWithObjectsAndKeys: NSLocalizedString(@"DTS Passthru", @"DTS Passthru"), keyAudioCodecName, @@ -136,10 +110,6 @@ static NSDictionary *bitRate384 = nil; [NSNumber numberWithBool: NO], keyAudioMP4, [NSNumber numberWithBool: YES], keyAudioMKV, [NSNumber numberWithInt: HB_ACODEC_DCA], keyAudioMustMatchTrack, - [NSNumber numberWithInt: 32], keyAudioMinimumBitrate, - [NSNumber numberWithInt: 384], keyAudioMaximumBitrate, - [NSNumber numberWithInt: 32], keyAudioMinimumBitrate6Channel, - [NSNumber numberWithInt: 384], keyAudioMaximumBitrate6Channel, nil]]; [masterCodecArray addObject: [NSDictionary dictionaryWithObjectsAndKeys: NSLocalizedString(@"Vorbis (vorbis)", @"Vorbis (vorbis)"), keyAudioCodecName, @@ -147,10 +117,6 @@ static NSDictionary *bitRate384 = nil; [NSNumber numberWithBool: NO], keyAudioMP4, [NSNumber numberWithBool: YES], keyAudioMKV, [NSNumber numberWithBool: NO], keyAudioMustMatchTrack, - [NSNumber numberWithInt: 48], keyAudioMinimumBitrate, - [NSNumber numberWithInt: 384], keyAudioMaximumBitrate, - [NSNumber numberWithInt: 192], keyAudioMinimumBitrate6Channel, - [NSNumber numberWithInt: 384], keyAudioMaximumBitrate6Channel, nil]]; // Note that for the Auto value we use 0 for the sample rate because our controller will give back the track's @@ -169,19 +135,12 @@ static NSDictionary *bitRate384 = nil; } masterBitRateArray = [[NSMutableArray alloc] init]; // knowingly leaked - int defaultRate = hb_audio_bitrates[hb_audio_bitrates_default].rate; for (i = 0; i < hb_audio_bitrates_count; i++) { int rate = hb_audio_bitrates[i].rate; dict = [NSDictionary dictionaryWithObjectsAndKeys: [NSString stringWithUTF8String: hb_audio_bitrates[i].string], keyAudioBitrateName, [NSNumber numberWithInt: rate], keyAudioBitrate, nil]; - if (rate == defaultRate) { - defaultBitRate = [dict retain]; // knowingly leaked - } - if (384 == rate) { - bitRate384 = [dict retain]; // knowingly leaked - } [masterBitRateArray addObject: dict]; } @@ -326,7 +285,7 @@ static NSDictionary *bitRate384 = nil; [NSString stringWithUTF8String: hb_audio_mixdowns[4].human_readable_name], keyAudioMixdownName, [NSNumber numberWithInt: hb_audio_mixdowns[4].amixdown], keyAudioMixdown, [NSNumber numberWithBool: NO], keyAudioMixdownLimitsToTrackBitRate, - [NSNumber numberWithBool: (HB_ACODEC_AC3 == trackCodec) ? NO : YES], keyAudioMixdownCanBeDefault, + [NSNumber numberWithBool: (HB_ACODEC_AC3 == codecCodec) ? YES : NO], keyAudioMixdownCanBeDefault, nil]]; } @@ -358,7 +317,8 @@ static NSDictionary *bitRate384 = nil; [self setMixdowns: retval]; // Ensure our mixdown is on the list of permitted ones - if (nil == [self mixdown] || NO == [retval containsObject: [self mixdown]]) { + if (YES == [[NSUserDefaults standardUserDefaults] boolForKey: @"CodecDefaultsMixdown"] || + nil == [self mixdown] || NO == [retval containsObject: [self mixdown]]) { [self setMixdown: [retval lastDictionaryWithObject: [NSNumber numberWithBool: YES] matchingKey: keyAudioMixdownCanBeDefault]]; } @@ -371,18 +331,27 @@ static NSDictionary *bitRate384 = nil; NSMutableArray *permittedBitRates = [NSMutableArray array]; int count; NSDictionary *dict; - BOOL has6chMixdown = (HB_AMIXDOWN_6CH == [[[self mixdown] objectForKey: keyAudioMixdown] intValue]); count = [masterBitRateArray count]; - NSString *minKey = (has6chMixdown) ? keyAudioMinimumBitrate6Channel : keyAudioMinimumBitrate; - NSString *maxKey = (has6chMixdown) ? keyAudioMaximumBitrate6Channel : keyAudioMaximumBitrate; - int minBitRate = [[codec objectForKey: minKey] intValue]; - int maxBitRate = [[codec objectForKey: maxKey] intValue]; + int minBitRate; + int maxBitRate; + NSString *defaultBitRate; int currentBitRate; int trackInputBitRate = [[[self track] objectForKey: keyAudioInputBitrate] intValue]; BOOL limitsToTrackInputBitRate = [[[self mixdown] objectForKey: keyAudioMixdownLimitsToTrackBitRate] boolValue]; BOOL shouldAdd; - + int theSampleRate = [[[self sampleRate] objectForKey: keyAudioSamplerate] intValue]; + + if (0 == theSampleRate) { // this means Auto + theSampleRate = [[[self track] objectForKey: keyAudioInputSampleRate] intValue]; + } + + int ourCodec = [[codec objectForKey: keyAudioCodec] intValue]; + int ourMixdown = [[[self mixdown] objectForKey: keyAudioMixdown] intValue]; + hb_get_audio_bitrate_limits(ourCodec, theSampleRate, ourMixdown, &minBitRate, &maxBitRate); + int theDefaultBitRate = hb_get_default_audio_bitrate(ourCodec, theSampleRate, ourMixdown); + defaultBitRate = [NSString stringWithFormat: @"%d", theDefaultBitRate]; + for (unsigned int i = 0; i < count; i++) { dict = [masterBitRateArray objectAtIndex: i]; currentBitRate = [[dict objectForKey: keyAudioBitrate] intValue]; @@ -422,12 +391,8 @@ static NSDictionary *bitRate384 = nil; [self setBitRates: permittedBitRates]; // Select the proper one - if (YES == has6chMixdown) { - [self setBitRate: bitRate384]; - } - else { - [self setBitRate: defaultBitRate]; - } + [self setBitRateFromName: defaultBitRate]; + if (nil == [self bitRate] || NO == [permittedBitRates containsObject: [self bitRate]]) { [self setBitRate: [permittedBitRates lastObject]]; } diff --git a/macosx/HBAudioController.m b/macosx/HBAudioController.m index 823dd439f..514f7b32f 100644 --- a/macosx/HBAudioController.m +++ b/macosx/HBAudioController.m @@ -253,7 +253,8 @@ NSString *HBMixdownChangedNotification = @"HBMixdownChangedNotification"; ) { key = @"AAC (CoreAudio)"; } - if (YES == [key isEqualToString: @"AC3 Passthru"]) { + if (YES == [[NSUserDefaults standardUserDefaults] boolForKey: @"AC3PassthruDefaultsToAC3"] && + YES == [key isEqualToString: @"AC3 Passthru"]) { if (NO == [newAudio setCodecFromName: key]) { key = @"AC3"; } @@ -295,6 +296,28 @@ NSString *HBMixdownChangedNotification = @"HBMixdownChangedNotification"; return retval; } +// When we add a track and we do not have a preset to use for the track we use +// this bogus preset to do the dirty work. +- (NSMutableDictionary *) _defaultPreset + +{ + static NSMutableDictionary *retval = nil; + + if (nil == retval) { + retval = [[NSMutableDictionary dictionaryWithObjectsAndKeys: + [NSArray arrayWithObject: + [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithInt: 1], @"AudioTrack", + @"AAC (faac)", @"AudioEncoder", + @"Dolby Pro Logic II", @"AudioMixdown", + @"Auto", @"AudioSamplerate", + @"160", @"AudioBitrate", + [NSNumber numberWithFloat: 0.0], @"AudioTrackDRCSlider", + nil]], @"AudioList", nil] retain]; + } + return retval; +} + - (void) addTracksFromPreset: (NSMutableDictionary *) aPreset allTracks: (BOOL) allTracks { @@ -315,8 +338,17 @@ NSString *HBMixdownChangedNotification = @"HBMixdownChangedNotification"; } } - [self switchingTrackFromNone: nil]; // see if we need to add one to the list + return; +} + +- (void) _ensureAtLeastOneNonEmptyTrackExists +{ + int count = [self countOfAudioArray]; + if (0 == count || NO == [[self objectInAudioArrayAtIndex: 0] enabled]) { + [self addTracksFromPreset: [self _defaultPreset] allTracks: NO]; + } + [self switchingTrackFromNone: nil]; // this ensures there is a None track at the end of the list return; } @@ -324,6 +356,7 @@ NSString *HBMixdownChangedNotification = @"HBMixdownChangedNotification"; { [self addTracksFromPreset: aPreset allTracks: NO]; + [self _ensureAtLeastOneNonEmptyTrackExists]; return; } @@ -331,6 +364,7 @@ NSString *HBMixdownChangedNotification = @"HBMixdownChangedNotification"; { [self addTracksFromPreset: aPreset allTracks: YES]; + [self _ensureAtLeastOneNonEmptyTrackExists]; return; } @@ -463,11 +497,7 @@ NSString *HBMixdownChangedNotification = @"HBMixdownChangedNotification"; [self _clearAudioArray]; if (NO == [myController hasValidPresetSelected]) { - NSString *preferredLanguageName = [[NSUserDefaults standardUserDefaults] stringForKey: @"DefaultLanguage"]; - int preferredLanguage = [self _trackWithTitlePrefix: preferredLanguageName defaultIfNotFound: 1]; - [self addNewAudioTrack]; - HBAudio *anAudio = [self objectInAudioArrayAtIndex: 0]; - [anAudio setTrackFromIndex: preferredLanguage]; + [self _ensureAtLeastOneNonEmptyTrackExists]; } return; } diff --git a/macosx/HBPreferencesController.m b/macosx/HBPreferencesController.m index 15653fe57..a0e7b8455 100644 --- a/macosx/HBPreferencesController.m +++ b/macosx/HBPreferencesController.m @@ -64,6 +64,8 @@ @"0.25", @"x264CqSliderFractional", @"YES", @"AlertBuiltInPresetUpdate", @"MetaX", @"SendCompletedEncodeToApp", + @"YES", @"AC3PassthruDefaultsToAC3", + @"YES", @"CodecDefaultsMixdown", nil]]; } |