From: sr55 Date: Sat, 9 Apr 2016 13:46:54 +0000 (+0100) Subject: WinGui: Use Mixdowns from LibHBand sanitise the choices. The GUI no longer shows... X-Git-Tag: 1.0.0~532 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=fc3324c8fa6c0aaa37c89d8d0bf098092d705932;p=handbrake WinGui: Use Mixdowns from LibHBand sanitise the choices. The GUI no longer shows invalid mixdowns. --- diff --git a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj index c3f86fb4d..8d023b901 100644 --- a/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj +++ b/win/CS/HandBrake.ApplicationServices/HandBrake.ApplicationServices.csproj @@ -169,7 +169,6 @@ - diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeEncoderHelpers.cs b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeEncoderHelpers.cs index 67f1c5483..9de57c2be 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeEncoderHelpers.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeEncoderHelpers.cs @@ -391,6 +391,22 @@ namespace HandBrake.ApplicationServices.Interop return HBFunctions.hb_mixdown_has_codec_support(mixdown.Id, (uint)encoder.Id) > 0; } + /// + /// Determines if a mixdown is available for a given track and encoder. + /// + /// + /// The mixdown to evaluate. + /// + /// + /// The encoder to evaluate. + /// + /// channel layout of the source track + /// True if available. + public static bool MixdownIsSupported(HBMixdown mixdown, HBAudioEncoder encoder, int channelLayout) + { + return HBFunctions.hb_mixdown_is_supported(mixdown.Id, (uint)encoder.Id, (uint)channelLayout) > 0; + } + /// /// Determines if DRC can be applied to the given track with the given encoder. /// diff --git a/win/CS/HandBrake.ApplicationServices/Interop/Json/Presets/AudioList.cs b/win/CS/HandBrake.ApplicationServices/Interop/Json/Presets/AudioList.cs index d77825fa6..8ad95d173 100644 --- a/win/CS/HandBrake.ApplicationServices/Interop/Json/Presets/AudioList.cs +++ b/win/CS/HandBrake.ApplicationServices/Interop/Json/Presets/AudioList.cs @@ -35,7 +35,7 @@ namespace HandBrake.ApplicationServices.Interop.Json.Presets public string AudioEncoder { get; set; } /// - /// Gets or sets the audio mixdown. + /// Gets or sets the audio mixdown. (ShortName) /// public string AudioMixdown { get; set; } diff --git a/win/CS/HandBrake.ApplicationServices/Interop/Model/Encoding/Mixdown.cs b/win/CS/HandBrake.ApplicationServices/Interop/Model/Encoding/Mixdown.cs deleted file mode 100644 index 66a2d4e1a..000000000 --- a/win/CS/HandBrake.ApplicationServices/Interop/Model/Encoding/Mixdown.cs +++ /dev/null @@ -1,68 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. -// -// -// Defines the Mixdown type. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace HandBrake.ApplicationServices.Interop.Model.Encoding -{ - using System.ComponentModel.DataAnnotations; - using HandBrake.ApplicationServices.Attributes; - - /// - /// The Audio Mixdown Enumeration - /// - public enum Mixdown - { - [Display(Name = "Dolby Pro Logic II")] - [ShortName("dpl2")] - DolbyProLogicII = 0, - - [Display(Name = "None")] - [ShortName("none")] - None, - - [Display(Name = "Automatic")] - [ShortName("none")] - Auto, - - [Display(Name = "Mono")] - [ShortName("mono")] - Mono, - - [Display(Name = "Mono (Left Only)")] - [ShortName("left_only")] - LeftOnly, - - [Display(Name = "Mono (Right Only)")] - [ShortName("right_only")] - RightOnly, - - [Display(Name = "Stereo")] - [ShortName("stereo")] - Stereo, - - [Display(Name = "Dolby Surround")] - [ShortName("dpl1")] - DolbySurround, - - [Display(Name = "5.1 Channels")] - [ShortName("5point1")] - FivePoint1Channels, - - [Display(Name = "6.1 Channels")] - [ShortName("6point1")] - SixPoint1Channels, - - [Display(Name = "7.1 Channels")] - [ShortName("7point1")] - SevenPoint1Channels, - - [Display(Name = "7.1 (5F/2R/LFE)")] - [ShortName("5_2_lfe")] - Five_2_LFE, - } -} diff --git a/win/CS/HandBrakeWPF/Converters/Audio/AudioMixdownConverter.cs b/win/CS/HandBrakeWPF/Converters/Audio/AudioMixdownConverter.cs new file mode 100644 index 000000000..e1a371743 --- /dev/null +++ b/win/CS/HandBrakeWPF/Converters/Audio/AudioMixdownConverter.cs @@ -0,0 +1,61 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Defines the AudioMixdownConverter type. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Converters.Audio +{ + using System.Globalization; + using System.Windows.Data; + using System; + + using HandBrake.ApplicationServices.Interop; + using HandBrake.ApplicationServices.Interop.Model.Encoding; + + /// + /// The audio mixdown converter. + /// Handles conversion between HBMixdown and it's shortname. + /// + public class AudioMixdownConverter : IValueConverter + { + /// + /// Converts a value. + /// + /// + /// A converted value. If the method returns null, the valid null value is used. + /// + /// The value produced by the binding source.The type of the binding target property.The converter parameter to use.The culture to use in the converter. + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + string mixdown = value as string; + if (!string.IsNullOrEmpty(mixdown)) + { + return HandBrakeEncoderHelpers.GetMixdown(mixdown); + } + + return HandBrakeEncoderHelpers.GetMixdown("dpl2"); // Default + } + + /// + /// Converts a value. + /// + /// + /// A converted value. If the method returns null, the valid null value is used. + /// + /// The value that is produced by the binding target.The type to convert to.The converter parameter to use.The culture to use in the converter. + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + HBMixdown mixdown = value as HBMixdown; + if (mixdown != null) + { + return mixdown.ShortName; + } + + return "none"; + } + } +} diff --git a/win/CS/HandBrakeWPF/Converters/Audio/AudioMixdownListConverter.cs b/win/CS/HandBrakeWPF/Converters/Audio/AudioMixdownListConverter.cs new file mode 100644 index 000000000..cad01f88a --- /dev/null +++ b/win/CS/HandBrakeWPF/Converters/Audio/AudioMixdownListConverter.cs @@ -0,0 +1,75 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// +// +// Defines the AudioMixdownListConverter type. +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeWPF.Converters.Audio +{ + using System.Globalization; + using System.Windows.Data; + using System; + using System.ComponentModel; + + using HandBrake.ApplicationServices.Interop; + using HandBrake.ApplicationServices.Interop.Model.Encoding; + + using HandBrakeWPF.Services.Encode.Model.Models; + using HandBrakeWPF.Utilities; + + /// + /// The audio mixdown converter. + /// Returns the list of available mixdowns for the given track and encoder. + /// + public class AudioMixdownListConverter : IValueConverter + { + /// + /// Converts a value. + /// + /// + /// A converted value. If the method returns null, the valid null value is used. + /// + /// The value produced by the binding source.The type of the binding target property.The converter parameter to use.The culture to use in the converter. + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + AudioTrack track = value as AudioTrack; + if (track != null && track.ScannedTrack != null) + { + HBAudioEncoder encoder = + HandBrakeEncoderHelpers.GetAudioEncoder(EnumHelper.GetShortName(track.Encoder)); + + BindingList mixdowns = new BindingList(); + foreach (HBMixdown mixdown in HandBrakeEncoderHelpers.Mixdowns) + { + if (HandBrakeEncoderHelpers.MixdownIsSupported( + mixdown, + encoder, + track.ScannedTrack.ChannelLayout)) + { + mixdowns.Add(mixdown); + } + } + + return mixdowns; + } + + return value; + } + + /// + /// Converts a value. + /// + /// + /// A converted value. If the method returns null, the valid null value is used. + /// + /// The value that is produced by the binding target.The type to convert to.The converter parameter to use.The culture to use in the converter. + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + + return value; + } + } +} diff --git a/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs b/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs index a25cd1100..b803e1126 100644 --- a/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs +++ b/win/CS/HandBrakeWPF/Converters/EnumComboConverter.cs @@ -58,10 +58,6 @@ namespace HandBrakeWPF.Converters { return EnumHelper.GetEnumDisplayValues(typeof(VideoEncoder)); } - if (value is IEnumerable) - { - return EnumHelper.GetEnumDisplayValues(typeof(Mixdown)); - } if (value is IEnumerable) { return EnumHelper.GetEnumDisplayValues(typeof(PresetPictureSettingsMode)); @@ -103,12 +99,7 @@ namespace HandBrakeWPF.Converters if (targetType == typeof(VideoEncoder) || value.GetType() == typeof(VideoEncoder)) { return EnumHelper.GetDisplay((VideoEncoder)value); - } - if (targetType == typeof(Mixdown) || value.GetType() == typeof(Mixdown)) - { - return EnumHelper.GetDisplay((Mixdown)value); - } - + } if (targetType == typeof(PresetPictureSettingsMode) || value.GetType() == typeof(PresetPictureSettingsMode)) { return EnumHelper.GetDisplay((PresetPictureSettingsMode)value); @@ -183,10 +174,6 @@ namespace HandBrakeWPF.Converters { return EnumHelper.GetValue(value.ToString()); } - if (targetType == typeof(Mixdown) || value.GetType() == typeof(Mixdown)) - { - return EnumHelper.GetValue(value.ToString()); - } if (targetType == typeof(PresetPictureSettingsMode) || value.GetType() == typeof(PresetPictureSettingsMode)) { return EnumHelper.GetValue(value.ToString()); diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj index 797663f9b..4ba16c677 100644 --- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj +++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj @@ -148,6 +148,8 @@ AlertPanel.xaml + + diff --git a/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeFactory.cs b/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeFactory.cs index cd4fbb44f..ea90a50f3 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeFactory.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/Factories/EncodeFactory.cs @@ -339,7 +339,7 @@ namespace HandBrakeWPF.Services.Encode.Factories HBAudioEncoder encoder = HandBrakeEncoderHelpers.GetAudioEncoder(EnumHelper.GetShortName(item.Encoder)); Validate.NotNull(encoder, "Unrecognized audio encoder:" + item.Encoder); - HBMixdown mixdown = HandBrakeEncoderHelpers.GetMixdown(EnumHelper.GetShortName(item.MixDown)); + HBMixdown mixdown = HandBrakeEncoderHelpers.GetMixdown(item.MixDown); Validate.NotNull(mixdown, "Unrecognized audio mixdown:" + item.MixDown); HBRate sampleRate = HandBrakeEncoderHelpers.AudioSampleRates.FirstOrDefault(s => s.Name == item.SampleRate.ToString(CultureInfo.InvariantCulture)); diff --git a/win/CS/HandBrakeWPF/Services/Encode/Model/Models/AudioTrack.cs b/win/CS/HandBrakeWPF/Services/Encode/Model/Models/AudioTrack.cs index 87e6caaaa..b875df16c 100644 --- a/win/CS/HandBrakeWPF/Services/Encode/Model/Models/AudioTrack.cs +++ b/win/CS/HandBrakeWPF/Services/Encode/Model/Models/AudioTrack.cs @@ -34,7 +34,7 @@ namespace HandBrakeWPF.Services.Encode.Model.Models private double drc; private HandBrakeWPF.Services.Encode.Model.Models.AudioEncoder encoder; private int gain; - private Mixdown mixDown; + private string mixDown; private double sampleRate; [NonSerialized] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] @@ -52,7 +52,7 @@ namespace HandBrakeWPF.Services.Encode.Model.Models { // Default Values this.Encoder = HandBrakeWPF.Services.Encode.Model.Models.AudioEncoder.ffaac; - this.MixDown = Mixdown.DolbyProLogicII; + this.MixDown = HandBrakeEncoderHelpers.Mixdowns.FirstOrDefault(m => m.ShortName == "dpl2")?.ShortName; this.SampleRate = 48; this.Bitrate = 160; this.DRC = 0; @@ -137,13 +137,13 @@ namespace HandBrakeWPF.Services.Encode.Model.Models } /// - /// Gets or sets Audio Mixdown + /// Gets or sets Audio Mixdown (ShortName) /// - public Mixdown MixDown + public string MixDown { get { - return this.IsPassthru ? Mixdown.Auto : this.mixDown; + return this.IsPassthru ? null : this.mixDown; } set @@ -151,7 +151,6 @@ namespace HandBrakeWPF.Services.Encode.Model.Models this.mixDown = value; this.NotifyOfPropertyChange(() => this.MixDown); this.SetupLimits(); - this.NotifyOfPropertyChange(() => this.TrackReference); } } @@ -173,8 +172,9 @@ namespace HandBrakeWPF.Services.Encode.Model.Models this.NotifyOfPropertyChange(() => this.IsBitrateVisible); this.NotifyOfPropertyChange(() => this.IsQualityVisible); this.NotifyOfPropertyChange(() => this.IsRateTypeVisible); - this.SetupLimits(); this.NotifyOfPropertyChange(() => this.TrackReference); + this.GetDefaultMixdownIfNull(); + this.SetupLimits(); // Refresh the available encoder rate types. this.NotifyOfPropertyChange(() => this.AudioEncoderRateTypes); @@ -200,7 +200,6 @@ namespace HandBrakeWPF.Services.Encode.Model.Models this.sampleRate = value; this.NotifyOfPropertyChange(() => this.SampleRate); this.SetupLimits(); - this.NotifyOfPropertyChange(() => this.TrackReference); } } @@ -282,18 +281,6 @@ namespace HandBrakeWPF.Services.Encode.Model.Models } } - /// - /// Gets AudioMixdownDisplayValue. - /// - [JsonIgnore] - public string AudioMixdownDisplayValue - { - get - { - return EnumHelper.GetDisplay(this.MixDown); - } - } - /// /// Gets the The UI display value for bit rate /// @@ -369,6 +356,9 @@ namespace HandBrakeWPF.Services.Encode.Model.Models { this.scannedTrack = value; this.NotifyOfPropertyChange(() => this.ScannedTrack); + this.NotifyOfPropertyChange(() => this.TrackReference); + + this.GetDefaultMixdownIfNull(); } } @@ -550,7 +540,7 @@ namespace HandBrakeWPF.Services.Encode.Model.Models // Based on the users settings, find the high and low bitrates. HBAudioEncoder hbaenc = HandBrakeEncoderHelpers.GetAudioEncoder(EnumHelper.GetShortName(this.Encoder)); HBRate rate = HandBrakeEncoderHelpers.AudioSampleRates.FirstOrDefault(t => t.Name == this.SampleRate.ToString(CultureInfo.InvariantCulture)); - HBMixdown mixdown = HandBrakeEncoderHelpers.GetMixdown(EnumHelper.GetShortName(this.MixDown)); + HBMixdown mixdown = this.mixDown != null ? HandBrakeEncoderHelpers.GetMixdown(this.mixDown) : HandBrakeEncoderHelpers.GetMixdown("dpl2"); BitrateLimits limits = HandBrakeEncoderHelpers.GetBitrateLimits(hbaenc, rate != null ? rate.Rate : 48000, mixdown); if (limits != null) @@ -632,6 +622,22 @@ namespace HandBrakeWPF.Services.Encode.Model.Models this.NotifyOfPropertyChange(() => this.EncoderQualityValues); } + /// + /// Set the default mixdown when the mixdown is null or "none" + /// + private void GetDefaultMixdownIfNull() + { + if ((this.mixDown == null || this.mixDown == "none" ) && this.ScannedTrack != null) + { + HBAudioEncoder aencoder = + HandBrakeEncoderHelpers.GetAudioEncoder(EnumHelper.GetShortName(this.encoder)); + + HBMixdown mixdown = HandBrakeEncoderHelpers.GetDefaultMixdown(aencoder, (uint)this.ScannedTrack.ChannelLayout); + + this.MixDown = mixdown.ShortName; + } + } + #endregion } } \ No newline at end of file diff --git a/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs b/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs index 7bcbc6a08..c8331076b 100644 --- a/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs +++ b/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs @@ -14,6 +14,7 @@ namespace HandBrakeWPF.Services.Presets.Factories using System.Globalization; using System.Linq; + using HandBrake.ApplicationServices.Interop; using HandBrake.ApplicationServices.Interop.Json.Presets; using HandBrake.ApplicationServices.Interop.Model; using HandBrake.ApplicationServices.Interop.Model.Encoding; @@ -399,7 +400,7 @@ namespace HandBrakeWPF.Services.Presets.Factories // track.CompressionLevel = audioTrack.AudioCompressionLevel; // track.AudioDitherMethod = audioTrack.AudioDitherMethod; track.Encoder = EnumHelper.GetValue(audioTrack.AudioEncoder); - track.MixDown = EnumHelper.GetValue(audioTrack.AudioMixdown); + track.MixDown = audioTrack.AudioMixdown; // track.AudioNormalizeMixLevel = audioTrack.AudioNormalizeMixLevel; track.SampleRate = audioTrack.AudioSamplerate == "auto" ? 0 : double.Parse(audioTrack.AudioSamplerate); @@ -540,7 +541,7 @@ namespace HandBrakeWPF.Services.Presets.Factories AudioCompressionLevel = 0, // TODO AudioDitherMethod = null, // TODO AudioEncoder = EnumHelper.GetShortName(item.Encoder), - AudioMixdown = EnumHelper.GetShortName(item.MixDown), + AudioMixdown = item.MixDown, AudioNormalizeMixLevel = false, // TODO AudioSamplerate = item.SampleRate == 0 ? "auto" : item.SampleRate.ToString(), // TODO check formatting. AudioTrackDRCSlider = item.DRC, diff --git a/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs b/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs index d72593cff..23d38af4e 100644 --- a/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs +++ b/win/CS/HandBrakeWPF/Services/Scan/LibScan.cs @@ -384,7 +384,8 @@ namespace HandBrakeWPF.Services.Scan int currentAudioTrack = 1; foreach (SourceAudioTrack track in title.AudioList) { - converted.AudioTracks.Add(new Audio(currentAudioTrack, track.Language, track.LanguageCode, track.Description, string.Empty, track.SampleRate, track.BitRate)); + + converted.AudioTracks.Add(new Audio(currentAudioTrack, track.Language, track.LanguageCode, track.Description, string.Empty, track.SampleRate, track.BitRate, track.ChannelLayout)); currentAudioTrack++; } diff --git a/win/CS/HandBrakeWPF/Services/Scan/Model/Audio.cs b/win/CS/HandBrakeWPF/Services/Scan/Model/Audio.cs index 1f0a2af98..ca2841bee 100644 --- a/win/CS/HandBrakeWPF/Services/Scan/Model/Audio.cs +++ b/win/CS/HandBrakeWPF/Services/Scan/Model/Audio.cs @@ -48,8 +48,12 @@ namespace HandBrakeWPF.Services.Scan.Model /// /// The bitrate. /// - public Audio(int trackNumber, string language, string languageCode, string description, string format, int sampleRate, int bitrate) + /// + /// The channel Layout. + /// + public Audio(int trackNumber, string language, string languageCode, string description, string format, int sampleRate, int bitrate, int channelLayout) { + this.ChannelLayout = channelLayout; this.TrackNumber = trackNumber; this.Language = language; this.LanguageCode = languageCode; @@ -94,6 +98,11 @@ namespace HandBrakeWPF.Services.Scan.Model /// public int Bitrate { get; set; } + /// + /// Gets or sets the channel layout of the source track (mixdown) + /// + public int ChannelLayout { get; set; } + /// /// Override of the ToString method to make this object easier to use in the UI /// diff --git a/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs index 8dba8fc89..04115d5b8 100644 --- a/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs +++ b/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs @@ -76,7 +76,6 @@ namespace HandBrakeWPF.ViewModels } this.AudioEncoders = EnumHelper.GetEnumList(); - this.AudioMixdowns = EnumHelper.GetEnumList(); this.SourceTracks = new List