diff options
author | Rodeo <[email protected]> | 2015-05-19 20:21:47 +0000 |
---|---|---|
committer | Rodeo <[email protected]> | 2015-05-19 20:21:47 +0000 |
commit | aef3d731cabd8a5f5a7166741b848f482246a51b (patch) | |
tree | aa6ea6d5e2954ae2f093d0afd652fa85ea4c646a /macosx/HBAudioTrack.m | |
parent | e4c5f142c7a496f3f1f40faf52d9e0defa79ff49 (diff) |
MacGui: better samplerate validation.
Not all encoders support all samplerate, so we
filter the list based on the encoder and validate
the selected samplerate when switching encoders.
Also improve bitrate validation a bit.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@7210 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'macosx/HBAudioTrack.m')
-rw-r--r-- | macosx/HBAudioTrack.m | 56 |
1 files changed, 40 insertions, 16 deletions
diff --git a/macosx/HBAudioTrack.m b/macosx/HBAudioTrack.m index 05f9789de..ed51df1af 100644 --- a/macosx/HBAudioTrack.m +++ b/macosx/HBAudioTrack.m @@ -33,7 +33,6 @@ NSString *keyAudioBitrate = @"bitrate"; static NSMutableArray *masterCodecArray = nil; static NSMutableArray *masterMixdownArray = nil; -static NSMutableArray *masterSampleRateArray = nil; static NSMutableArray *masterBitRateArray = nil; @interface NSArray (HBAudioSupport) @@ -110,20 +109,6 @@ static NSMutableArray *masterBitRateArray = nil; 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:@{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:@{keyAudioSampleRateName: @(audio_samplerate->name), - keyAudioSamplerate: @(audio_samplerate->rate)}]; - } - masterBitRateArray = [[NSMutableArray alloc] init]; // knowingly leaked for (const hb_rate_t *audio_bitrate = hb_audio_bitrate_get_next(NULL); audio_bitrate != NULL; @@ -234,6 +219,22 @@ static NSMutableArray *masterBitRateArray = nil; } } +- (void)validateSamplerate +{ + int codec = [self.codec[keyAudioCodec] intValue]; + int samplerate = [self.sampleRate[keyAudioSamplerate] intValue]; + + if (codec & HB_ACODEC_PASS_FLAG) + { + [self setSampleRateFromName:@"Auto"]; + } + else if (samplerate) + { + samplerate = hb_audio_samplerate_get_best(codec, samplerate, NULL); + [self setSampleRateFromName:@(hb_audio_samplerate_get_name(samplerate))]; + } +} + - (void) updateBitRates: (BOOL) shouldSetDefault { @@ -321,7 +322,29 @@ static NSMutableArray *masterBitRateArray = nil; - (NSArray *) sampleRates { - return masterSampleRateArray; + NSMutableArray *samplerates = [[NSMutableArray alloc] init]; + + /* + * 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. + */ + [samplerates addObject:@{keyAudioSampleRateName: @"Auto", + keyAudioSamplerate: @0}]; + + int codec = [self.codec[keyAudioCodec] intValue]; + 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)) + { + int rate = audio_samplerate->rate; + if (rate == hb_audio_samplerate_get_best(codec, rate, NULL)) + { + [samplerates addObject:@{keyAudioSampleRateName: @(audio_samplerate->name), + keyAudioSamplerate: @(rate)}]; + } + } + return samplerates; } #pragma mark - @@ -359,6 +382,7 @@ static NSMutableArray *masterBitRateArray = nil; - (void)setCodec:(NSDictionary *)codec { _codec = codec; + [self validateSamplerate]; [self updateMixdowns: YES]; [self updateBitRates: YES]; } |