From 5e787c33895fbfa0e91b4b802c0ee85b6fd2c36f Mon Sep 17 00:00:00 2001 From: sr55 Date: Wed, 31 May 2017 20:56:25 +0100 Subject: WinGui: Add "None" as an option to the fallback encoder dropdown. Setting this option to none will not add a passthru track when the passthru codec does not match the source track. #623 --- .../Converters/Audio/AudioEncoderConverter.cs | 5 ++++ .../Services/Encode/Model/Models/AudioEncoder.cs | 4 +++ win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs | 30 +++++++++++++++++++--- 3 files changed, 36 insertions(+), 3 deletions(-) (limited to 'win/CS') diff --git a/win/CS/HandBrakeWPF/Converters/Audio/AudioEncoderConverter.cs b/win/CS/HandBrakeWPF/Converters/Audio/AudioEncoderConverter.cs index 7f70288ce..4c3bd59b5 100644 --- a/win/CS/HandBrakeWPF/Converters/Audio/AudioEncoderConverter.cs +++ b/win/CS/HandBrakeWPF/Converters/Audio/AudioEncoderConverter.cs @@ -56,6 +56,8 @@ namespace HandBrakeWPF.Converters.Audio List encoders = EnumHelper.GetEnumList().ToList(); EncodeTask task = values[1] as EncodeTask; + encoders.Remove(AudioEncoder.None); // Assume we never want to show this. + if (!HandBrakeEncoderHelpers.AudioEncoders.Any(a => a.ShortName.Contains("fdk"))) { encoders.Remove(AudioEncoder.fdkaac); @@ -71,6 +73,7 @@ namespace HandBrakeWPF.Converters.Audio encoders.Remove(AudioEncoder.Opus); } + // Hide the Passthru options and show the "None" option if (parameter != null && parameter.ToString() == "True") { encoders.Remove(AudioEncoder.DtsHDPassthrough); @@ -82,6 +85,8 @@ namespace HandBrakeWPF.Converters.Audio encoders.Remove(AudioEncoder.Passthrough); encoders.Remove(AudioEncoder.TrueHDPassthrough); encoders.Remove(AudioEncoder.FlacPassthru); + + encoders.Add(AudioEncoder.None); } return EnumHelper.GetEnumDisplayValuesSubset(encoders); diff --git a/win/CS/HandBrakeWPF/Services/Encode/Model/Models/AudioEncoder.cs b/win/CS/HandBrakeWPF/Services/Encode/Model/Models/AudioEncoder.cs index 2d659bd39..3f415e60e 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/Model/Models/AudioEncoder.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/Model/Models/AudioEncoder.cs @@ -16,6 +16,10 @@ namespace HandBrakeWPF.Services.Encode.Model.Models /// public enum AudioEncoder { + [DisplayName("None")] + [ShortName("none")] + None, + [DisplayName("AAC (avcodec)")] [ShortName("av_aac")] ffaac, diff --git a/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs index ff7a8376f..771267e26 100644 --- a/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs @@ -353,12 +353,18 @@ namespace HandBrakeWPF.ViewModels { case AudioTrackDefaultsMode.FirstTrack: AudioBehaviourTrack template = this.AudioBehaviours.BehaviourTracks.FirstOrDefault(); - this.Task.AudioTracks.Add(template != null ? new AudioTrack(template, track, this.Task.AllowedPassthruOptions.AudioEncoderFallback) : new AudioTrack { ScannedTrack = track }); + if (this.CanAddTrack(template, track, this.Task.AllowedPassthruOptions.AudioEncoderFallback)) + { + this.Task.AudioTracks.Add( template != null ? new AudioTrack(template, track, this.Task.AllowedPassthruOptions.AudioEncoderFallback) : new AudioTrack { ScannedTrack = track }); + } break; case AudioTrackDefaultsMode.AllTracks: foreach (AudioBehaviourTrack tmpl in this.AudioBehaviours.BehaviourTracks) { - this.Task.AudioTracks.Add(tmpl != null ? new AudioTrack(tmpl, track, this.Task.AllowedPassthruOptions.AudioEncoderFallback) : new AudioTrack { ScannedTrack = track }); + if (this.CanAddTrack(tmpl, track, this.Task.AllowedPassthruOptions.AudioEncoderFallback)) + { + this.Task.AudioTracks.Add(tmpl != null ? new AudioTrack(tmpl, track, this.Task.AllowedPassthruOptions.AudioEncoderFallback) : new AudioTrack { ScannedTrack = track }); + } } break; @@ -367,6 +373,20 @@ namespace HandBrakeWPF.ViewModels } } + private bool CanAddTrack(AudioBehaviourTrack track, Audio sourceTrack, AudioEncoder fallback) + { + if (fallback == AudioEncoder.None) + { + HBAudioEncoder encoderInfo = HandBrakeEncoderHelpers.GetAudioEncoder(EnumHelper.GetShortName(track.Encoder)); + if (track.IsPassthru && (sourceTrack.Codec & encoderInfo.Id) == 0) + { + return false; + } + } + + return true; + } + /// /// Add all source tracks that don't currently exist on the list. /// @@ -410,7 +430,11 @@ namespace HandBrakeWPF.ViewModels // Step 3, Setup the tracks from the preset foreach (AudioBehaviourTrack track in this.AudioBehaviours.BehaviourTracks) { - this.Task.AudioTracks.Add(new AudioTrack(track, this.GetPreferredAudioTrack(), this.Task.AllowedPassthruOptions.AudioEncoderFallback)); + Audio sourceTrack = this.GetPreferredAudioTrack(); + if (this.CanAddTrack(track, sourceTrack, this.Task.AllowedPassthruOptions.AudioEncoderFallback)) + { + this.Task.AudioTracks.Add(new AudioTrack(track, sourceTrack, this.Task.AllowedPassthruOptions.AudioEncoderFallback)); + } } // Step 4, Handle the default selection behaviour. -- cgit v1.2.3