From f7076694f9e67241811128e0073bef2d10ed888c Mon Sep 17 00:00:00 2001 From: sr55 Date: Sun, 7 Aug 2011 14:08:52 +0000 Subject: WinGui: Add support for DTS passthru in MP4 and add smarter fallback audio encoder selection for incorrectly selected passthru tracks. git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4159 b64f7644-9d1e-0410-96f1-a4d463321fa5 --- win/CS/Controls/AudioPanel.cs | 116 +++++++++++++++++++++++++++++++----------- 1 file changed, 85 insertions(+), 31 deletions(-) (limited to 'win') diff --git a/win/CS/Controls/AudioPanel.cs b/win/CS/Controls/AudioPanel.cs index b3389fd27..41d4a8cfd 100644 --- a/win/CS/Controls/AudioPanel.cs +++ b/win/CS/Controls/AudioPanel.cs @@ -128,10 +128,10 @@ namespace Handbrake.Controls drp_audioEncoder.Items.Add(EnumHelper.GetDescription(AudioEncoder.Mp3Passthru)); drp_audioEncoder.Items.Add(EnumHelper.GetDescription(AudioEncoder.Ac3Passthrough)); drp_audioEncoder.Items.Add(EnumHelper.GetDescription(AudioEncoder.Ac3)); - + drp_audioEncoder.Items.Add(EnumHelper.GetDescription(AudioEncoder.DtsPassthrough)); + if (path.Contains("MKV")) { - drp_audioEncoder.Items.Add(EnumHelper.GetDescription(AudioEncoder.DtsPassthrough)); drp_audioEncoder.Items.Add(EnumHelper.GetDescription(AudioEncoder.DtsHDPassthrough)); drp_audioEncoder.Items.Add(EnumHelper.GetDescription(AudioEncoder.Vorbis)); } @@ -261,36 +261,12 @@ namespace Handbrake.Controls { track.ScannedTrack = drp_audioTrack.SelectedItem as Audio; - // If the track isn't AC3, and the encoder is, change it. - if (track.Encoder == AudioEncoder.Ac3Passthrough && !track.ScannedTrack.Format.Contains("AC3")) - { - // Switch to AAC - drp_audioEncoder.SelectedIndex = 0; - } - - // If the track isn't DTS, and the encoder is, change it. - if (track.Encoder == AudioEncoder.DtsPassthrough && !track.ScannedTrack.Format.Contains("DTS")) + // Correct bad passthru option + if (this.IsIncompatiblePassthru(track)) { - // Switch to AAC - drp_audioEncoder.SelectedIndex = 0; - } - - // If the track isn't AAC, and the encoder is, change it. - if (track.Encoder == AudioEncoder.AacPassthru && !track.ScannedTrack.Format.Contains("aac")) - { - // Switch to AAC - drp_audioEncoder.SelectedIndex = 0; - } - - - // If the track isn't MP3, and the encoder is, change it. - if (track.Encoder == AudioEncoder.Mp3Passthru && !track.ScannedTrack.Format.Contains("mp3")) - { - // Switch to AAC - drp_audioEncoder.SelectedIndex = 0; - } - - + AudioEncoder encoder = GetCompatiblePassthru(track); + drp_audioEncoder.SelectedItem = EnumHelper.GetDescription(encoder); + } } break; case "drp_audioEncoder": @@ -311,6 +287,12 @@ namespace Handbrake.Controls // Update an item in the Audio list if required. track.Encoder = EnumHelper.GetValue(drp_audioEncoder.Text); + // Correct bad passthru option + if (this.IsIncompatiblePassthru(track)) + { + AudioEncoder encoder = GetCompatiblePassthru(track); + drp_audioEncoder.SelectedItem = EnumHelper.GetDescription(encoder); + } break; case "drp_audioMix": SetBitrate(track.Bitrate); @@ -967,6 +949,78 @@ namespace Handbrake.Controls return false; } + /// + /// For a given Audio Track, is the chosen Passthru option supported + /// + /// + /// The track. + /// + /// + /// True if it is. + /// + private bool IsIncompatiblePassthru(AudioTrack track) + { + // If the track isn't AC3, and the encoder is, change it. + if (track.Encoder == AudioEncoder.Ac3Passthrough && !track.ScannedTrack.Format.Contains("AC3")) + { + return true; + } + + // If the track isn't DTS, and the encoder is, change it. + if (track.Encoder == AudioEncoder.DtsPassthrough && !track.ScannedTrack.Format.Contains("DTS")) + { + return true; + } + + // If the track isn't AAC, and the encoder is, change it. + if (track.Encoder == AudioEncoder.AacPassthru && !track.ScannedTrack.Format.Contains("aac")) + { + return true; + } + + // If the track isn't MP3, and the encoder is, change it. + if (track.Encoder == AudioEncoder.Mp3Passthru && !track.ScannedTrack.Format.Contains("mp3")) + { + return true; + } + + return false; + } + + /// + /// Get a compatible passthru, or default to aac. + /// + /// + /// The track. + /// + /// + /// AN Audio encoder. + /// + private AudioEncoder GetCompatiblePassthru(AudioTrack track) + { + if (track.ScannedTrack.Format.Contains("AC3")) + { + return AudioEncoder.Ac3Passthrough; + } + + if (track.ScannedTrack.Format.Contains("DTS")) + { + return AudioEncoder.DtsPassthrough; + } + + if (track.ScannedTrack.Format.Contains("aac")) + { + return AudioEncoder.AacPassthru; + } + + if (track.ScannedTrack.Format.Contains("mp3")) + { + return AudioEncoder.Mp3Passthru; + } + + return AudioEncoder.Faac; + } + #endregion private void btn_AdvancedAudio_Click(object sender, EventArgs e) -- cgit v1.2.3