summaryrefslogtreecommitdiffstats
path: root/win
diff options
context:
space:
mode:
authorsr55 <[email protected]>2015-06-20 15:10:14 +0000
committersr55 <[email protected]>2015-06-20 15:10:14 +0000
commit9192276e8bfde8ac2ce798edf677be141ad5e9b5 (patch)
tree011560f3b9441bc6b0c6089c67bb1d5270514954 /win
parent726ce9731952489d69c312daf6a5ec0744f0061d (diff)
WinGui: Fetch Audio Bitrates, Bitrate Defaults, Samplerates from LibHB
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@7305 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win')
-rw-r--r--win/CS/HandBrake.ApplicationServices/Interop/HandBrakeEncoderHelpers.cs272
-rw-r--r--win/CS/HandBrake.ApplicationServices/Interop/Model/Encoding/Mixdown.cs13
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/Encode/Factories/EncodeFactory.cs4
-rw-r--r--win/CS/HandBrake.ApplicationServices/Services/Encode/Model/Models/AudioTrack.cs240
-rw-r--r--win/CS/HandBrake.ApplicationServices/Utilities/Converters.cs114
-rw-r--r--win/CS/HandBrakeWPF/Converters/Audio/AudioBitrateConverter.cs293
-rw-r--r--win/CS/HandBrakeWPF/HandBrakeWPF.csproj1
-rw-r--r--win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs2
-rw-r--r--win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs11
-rw-r--r--win/CS/HandBrakeWPF/Views/AudioView.xaml3
10 files changed, 309 insertions, 644 deletions
diff --git a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeEncoderHelpers.cs b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeEncoderHelpers.cs
index 69075a7f9..524b6b0ad 100644
--- a/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeEncoderHelpers.cs
+++ b/win/CS/HandBrake.ApplicationServices/Interop/HandBrakeEncoderHelpers.cs
@@ -33,33 +33,33 @@ namespace HandBrake.ApplicationServices.Interop
/// </summary>
private static List<HBVideoEncoder> videoEncoders;
- /// <summary>
- /// Video framerates in pts.
- /// </summary>
- private static List<HBRate> videoFramerates;
-
- /// <summary>
- /// List of HandBrake mixdowns.
+ /// <summary>
+ /// Video framerates in pts.
+ /// </summary>
+ private static List<HBRate> videoFramerates;
+
+ /// <summary>
+ /// List of HandBrake mixdowns.
/// </summary>
private static List<HBMixdown> mixdowns;
- /// <summary>
- /// List of HandBrake containers.
- /// </summary>
- private static List<HBContainer> containers;
-
- /// <summary>
- /// The audio bitrates.
+ /// <summary>
+ /// List of HandBrake containers.
+ /// </summary>
+ private static List<HBContainer> containers;
+
+ /// <summary>
+ /// The audio bitrates.
/// </summary>
private static List<int> audioBitrates;
- /// <summary>
- /// Audio sample rates in Hz.
- /// </summary>
- private static List<HBRate> audioSampleRates;
-
- /// <summary>
- /// Initializes static members of the HandBrakeEncoderHelpers class.
+ /// <summary>
+ /// Audio sample rates in Hz.
+ /// </summary>
+ private static List<HBRate> audioSampleRates;
+
+ /// <summary>
+ /// Initializes static members of the HandBrakeEncoderHelpers class.
/// </summary>
static HandBrakeEncoderHelpers()
{
@@ -109,13 +109,13 @@ namespace HandBrake.ApplicationServices.Interop
{
videoFramerates = InteropUtilities.ToListFromIterator<hb_rate_s, HBRate>(HBFunctions.hb_video_framerate_get_next, HandBrakeUnitConversionHelpers.NativeToRate);
}
-
- return videoFramerates;
- }
- }
-
- /// <summary>
- /// Gets a list of supported mixdowns.
+
+ return videoFramerates;
+ }
+ }
+
+ /// <summary>
+ /// Gets a list of supported mixdowns.
/// </summary>
public static List<HBMixdown> Mixdowns
{
@@ -257,73 +257,73 @@ namespace HandBrake.ApplicationServices.Interop
public static HBContainer GetContainer(string shortName)
{
return Containers.SingleOrDefault(c => c.ShortName == shortName);
- }
-
- /// <summary>
- /// Returns true if the subtitle source type can be set to forced only.
- /// </summary>
- /// <param name="source">The subtitle source type (SSA, VobSub, etc)</param>
- /// <returns>True if the subtitle source type can be set to forced only.</returns>
- public static bool SubtitleCanSetForcedOnly(int source)
- {
- return HBFunctions.hb_subtitle_can_force(source) > 0;
- }
-
- /// <summary>
- /// Returns true if the subtitle source type can be burned in.
- /// </summary>
- /// <param name="source">The subtitle source type (SSA, VobSub, etc)</param>
- /// <returns>True if the subtitle source type can be burned in.</returns>
- public static bool SubtitleCanBurn(int source)
- {
- return HBFunctions.hb_subtitle_can_burn(source) > 0;
- }
-
- /// <summary>
- /// Returns true if the subtitle type can be passed through using the given muxer.
- /// </summary>
- /// <param name="subtitleSourceType">The subtitle source type (SSA, VobSub, etc)</param>
- /// <param name="muxer">The ID of the muxer.</param>
- /// <returns>True if the subtitle type can be passed through with the given muxer.</returns>
- public static bool SubtitleCanPassthrough(int subtitleSourceType, int muxer)
- {
- return HBFunctions.hb_subtitle_can_pass(subtitleSourceType, muxer) > 0;
- }
-
- /// <summary>
- /// Gets the subtitle source type's name.
- /// </summary>
- /// <param name="source">The subtitle source type (SSA, VobSub, etc).</param>
- /// <returns>The name of the subtitle source.</returns>
- public static string GetSubtitleSourceName(int source)
- {
- switch ((hb_subtitle_s_subsource)source)
- {
- case hb_subtitle_s_subsource.CC608SUB:
- return "CC608";
- case hb_subtitle_s_subsource.CC708SUB:
- return "CC708";
- case hb_subtitle_s_subsource.SRTSUB:
- return "SRT";
- case hb_subtitle_s_subsource.SSASUB:
- return "SSA";
- case hb_subtitle_s_subsource.TX3GSUB:
- return "TX3G";
- case hb_subtitle_s_subsource.UTF8SUB:
- return "UTF8";
- case hb_subtitle_s_subsource.VOBSUB:
- return "VobSub";
- case hb_subtitle_s_subsource.PGSSUB:
- return "PGS";
- default:
- return string.Empty;
- }
- }
-
- /// <summary>
- /// Determines if the given encoder is compatible with the given track.
- /// </summary>
- /// <param name="codecId">
+ }
+
+ /// <summary>
+ /// Returns true if the subtitle source type can be set to forced only.
+ /// </summary>
+ /// <param name="source">The subtitle source type (SSA, VobSub, etc)</param>
+ /// <returns>True if the subtitle source type can be set to forced only.</returns>
+ public static bool SubtitleCanSetForcedOnly(int source)
+ {
+ return HBFunctions.hb_subtitle_can_force(source) > 0;
+ }
+
+ /// <summary>
+ /// Returns true if the subtitle source type can be burned in.
+ /// </summary>
+ /// <param name="source">The subtitle source type (SSA, VobSub, etc)</param>
+ /// <returns>True if the subtitle source type can be burned in.</returns>
+ public static bool SubtitleCanBurn(int source)
+ {
+ return HBFunctions.hb_subtitle_can_burn(source) > 0;
+ }
+
+ /// <summary>
+ /// Returns true if the subtitle type can be passed through using the given muxer.
+ /// </summary>
+ /// <param name="subtitleSourceType">The subtitle source type (SSA, VobSub, etc)</param>
+ /// <param name="muxer">The ID of the muxer.</param>
+ /// <returns>True if the subtitle type can be passed through with the given muxer.</returns>
+ public static bool SubtitleCanPassthrough(int subtitleSourceType, int muxer)
+ {
+ return HBFunctions.hb_subtitle_can_pass(subtitleSourceType, muxer) > 0;
+ }
+
+ /// <summary>
+ /// Gets the subtitle source type's name.
+ /// </summary>
+ /// <param name="source">The subtitle source type (SSA, VobSub, etc).</param>
+ /// <returns>The name of the subtitle source.</returns>
+ public static string GetSubtitleSourceName(int source)
+ {
+ switch ((hb_subtitle_s_subsource)source)
+ {
+ case hb_subtitle_s_subsource.CC608SUB:
+ return "CC608";
+ case hb_subtitle_s_subsource.CC708SUB:
+ return "CC708";
+ case hb_subtitle_s_subsource.SRTSUB:
+ return "SRT";
+ case hb_subtitle_s_subsource.SSASUB:
+ return "SSA";
+ case hb_subtitle_s_subsource.TX3GSUB:
+ return "TX3G";
+ case hb_subtitle_s_subsource.UTF8SUB:
+ return "UTF8";
+ case hb_subtitle_s_subsource.VOBSUB:
+ return "VobSub";
+ case hb_subtitle_s_subsource.PGSSUB:
+ return "PGS";
+ default:
+ return string.Empty;
+ }
+ }
+
+ /// <summary>
+ /// Determines if the given encoder is compatible with the given track.
+ /// </summary>
+ /// <param name="codecId">
/// The codec Id.
/// </param>
/// <param name="encoder">
@@ -368,13 +368,13 @@ namespace HandBrake.ApplicationServices.Interop
/// </param>
/// <returns>
/// True if the encoder supports the mixdown.
- /// </returns>
- public static bool MixdownHasCodecSupport(HBMixdown mixdown, HBAudioEncoder encoder)
- {
- return HBFunctions.hb_mixdown_has_codec_support(mixdown.Id, (uint)encoder.Id) > 0;
- }
-
- /// <summary>
+ /// </returns>
+ public static bool MixdownHasCodecSupport(HBMixdown mixdown, HBAudioEncoder encoder)
+ {
+ return HBFunctions.hb_mixdown_has_codec_support(mixdown.Id, (uint)encoder.Id) > 0;
+ }
+
+ /// <summary>
/// Determines if DRC can be applied to the given track with the given encoder.
/// </summary>
/// <param name="trackNumber">
@@ -489,15 +489,15 @@ namespace HandBrake.ApplicationServices.Interop
int direction = 0;
HBFunctions.hb_video_quality_get_limits((uint)encoder.Id, ref low, ref high, ref granularity, ref direction);
-
- return new VideoQualityLimits
- {
- Low = low,
- High = high,
- Granularity = granularity,
- Ascending = direction == 0
- };
- }
+
+ return new VideoQualityLimits
+ {
+ Low = low,
+ High = high,
+ Granularity = granularity,
+ Ascending = direction == 0
+ };
+ }
/// <summary>
/// Sanitizes an audio bitrate given the output codec, sample rate and mixdown.
@@ -536,13 +536,13 @@ namespace HandBrake.ApplicationServices.Interop
/// </param>
/// <returns>
/// The default bitrate for these parameters.
- /// </returns>
- public static int GetDefaultBitrate(HBAudioEncoder encoder, int sampleRate, HBMixdown mixdown)
- {
- return HBFunctions.hb_audio_bitrate_get_default((uint)encoder.Id, sampleRate, mixdown.Id);
- }
-
- /// <summary>
+ /// </returns>
+ public static int GetDefaultBitrate(HBAudioEncoder encoder, int sampleRate, HBMixdown mixdown)
+ {
+ return HBFunctions.hb_audio_bitrate_get_default((uint)encoder.Id, sampleRate, mixdown.Id);
+ }
+
+ /// <summary>
/// Gets limits on audio quality for a given encoder.
/// </summary>
/// <param name="encoderId">
@@ -556,15 +556,15 @@ namespace HandBrake.ApplicationServices.Interop
float low = 0, high = 0, granularity = 0;
int direction = 0;
HBFunctions.hb_audio_quality_get_limits((uint)encoderId, ref low, ref high, ref granularity, ref direction);
-
- return new RangeLimits
- {
- Low = low,
- High = high,
- Granularity = granularity,
- Ascending = direction == 0
- };
- }
+
+ return new RangeLimits
+ {
+ Low = low,
+ High = high,
+ Granularity = granularity,
+ Ascending = direction == 0
+ };
+ }
/// <summary>
/// Gets limits on audio compression for a given encoder.
@@ -580,14 +580,14 @@ namespace HandBrake.ApplicationServices.Interop
float low = 0, high = 0, granularity = 0;
int direction = 0;
HBFunctions.hb_audio_compression_get_limits((uint)encoderId, ref low, ref high, ref granularity, ref direction);
-
- return new RangeLimits
- {
- Low = low,
- High = high,
- Granularity = granularity,
- Ascending = direction == 0
- };
- }
+
+ return new RangeLimits
+ {
+ Low = low,
+ High = high,
+ Granularity = granularity,
+ Ascending = direction == 0
+ };
+ }
}
}
diff --git a/win/CS/HandBrake.ApplicationServices/Interop/Model/Encoding/Mixdown.cs b/win/CS/HandBrake.ApplicationServices/Interop/Model/Encoding/Mixdown.cs
index 53e4f87e2..05f554e6b 100644
--- a/win/CS/HandBrake.ApplicationServices/Interop/Model/Encoding/Mixdown.cs
+++ b/win/CS/HandBrake.ApplicationServices/Interop/Model/Encoding/Mixdown.cs
@@ -10,6 +10,7 @@
namespace HandBrake.ApplicationServices.Interop.Model.Encoding
{
using System.ComponentModel.DataAnnotations;
+ using HandBrake.ApplicationServices.Attributes;
/// <summary>
/// The Audio Mixdown Enumeration
@@ -17,39 +18,51 @@ namespace HandBrake.ApplicationServices.Interop.Model.Encoding
public enum Mixdown
{
[Display(Name = "Dolby Pro Logic II")]
+ [ShortName("dpl2")]
DolbyProLogicII = 0,
[Display(Name = "None")]
+ [ShortName("dpl2")]
None,
[Display(Name = "Automatic")]
+ [ShortName("dpl2")]
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/HandBrake.ApplicationServices/Services/Encode/Factories/EncodeFactory.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/Factories/EncodeFactory.cs
index 8554c843b..12c06f011 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/Encode/Factories/EncodeFactory.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/Encode/Factories/EncodeFactory.cs
@@ -338,8 +338,8 @@ namespace HandBrake.ApplicationServices.Services.Encode.Factories
HBAudioEncoder encoder = HandBrakeEncoderHelpers.GetAudioEncoder(ApplicationServices.Utilities.Converters.GetCliAudioEncoder(item.Encoder));
Validate.NotNull(encoder, "Unrecognized audio encoder:" + item.Encoder);
- HBMixdown mixdown = HandBrakeEncoderHelpers.GetMixdown(ApplicationServices.Utilities.Converters.GetCliMixDown(item.MixDown));
- Validate.NotNull(mixdown, "Unrecognized audio mixdown:" + ApplicationServices.Utilities.Converters.GetCliMixDown(item.MixDown));
+ HBMixdown mixdown = HandBrakeEncoderHelpers.GetMixdown(EnumHelper<Mixdown>.GetShortName(item.MixDown));
+ Validate.NotNull(mixdown, "Unrecognized audio mixdown:" + item.MixDown);
HandBrake.ApplicationServices.Interop.Json.Encode.AudioTrack audioTrack = new HandBrake.ApplicationServices.Interop.Json.Encode.AudioTrack
{
diff --git a/win/CS/HandBrake.ApplicationServices/Services/Encode/Model/Models/AudioTrack.cs b/win/CS/HandBrake.ApplicationServices/Services/Encode/Model/Models/AudioTrack.cs
index 4a020365d..d1c980e54 100644
--- a/win/CS/HandBrake.ApplicationServices/Services/Encode/Model/Models/AudioTrack.cs
+++ b/win/CS/HandBrake.ApplicationServices/Services/Encode/Model/Models/AudioTrack.cs
@@ -3,74 +3,42 @@
// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
// </copyright>
// <summary>
-// An Audio Track for the Audio Panel
+// Model of a HandBrake Audio Track and it's associated behaviours.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace HandBrake.ApplicationServices.Services.Encode.Model.Models
{
using System;
+ using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
+ using System.Linq;
+ using HandBrake.ApplicationServices.Interop;
+ using HandBrake.ApplicationServices.Interop.Model;
+ using HandBrake.ApplicationServices.Interop.Model.Encoding;
using HandBrake.ApplicationServices.Services.Scan.Model;
using HandBrake.ApplicationServices.Utilities;
- using HandBrake.ApplicationServices.Interop.Model.Encoding;
using Newtonsoft.Json;
/// <summary>
- /// An Audio Track for the Audio Panel
+ /// Model of a HandBrake Audio Track and it's associated behaviours.
/// </summary>
public class AudioTrack : PropertyChangedBase
{
- #region Constants and Fields
-
- /// <summary>
- /// The bitrate.
- /// </summary>
private int bitrate;
-
- /// <summary>
- /// The DRC Value
- /// </summary>
private double drc;
-
- /// <summary>
- /// The encoder.
- /// </summary>
private AudioEncoder encoder;
-
- /// <summary>
- /// The gain value
- /// </summary>
private int gain;
-
- /// <summary>
- /// The mix down.
- /// </summary>
private Mixdown mixDown;
-
- /// <summary>
- /// The sample rate.
- /// </summary>
private double sampleRate;
-
- /// <summary>
- /// The Scanned Audio Track
- /// </summary>
[NonSerialized]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
private Audio scannedTrack;
-
- /// <summary>
- /// The is default.
- /// </summary>
private bool isDefault;
-
- #endregion
-
- #region Constructors and Destructors
+ private IEnumerable<int> bitrates;
/// <summary>
/// Initializes a new instance of the <see cref = "AudioTrack" /> class.
@@ -85,6 +53,9 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models
this.DRC = 0;
this.ScannedTrack = new Audio();
this.TrackName = string.Empty;
+
+ // Setup Backing Properties
+ this.SetupBitrateLimits();
}
/// <summary>
@@ -110,50 +81,12 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models
this.scannedTrack = track.ScannedTrack ?? new Audio();
}
this.TrackName = track.TrackName;
- }
-
- #endregion
-
- #region Public Properties
-
- /// <summary>
- /// Gets AudioEncoderDisplayValue.
- /// </summary>
- public string AudioEncoderDisplayValue
- {
- get
- {
- return EnumHelper<AudioEncoder>.GetDisplay(this.Encoder);
- }
- }
- /// <summary>
- /// Gets AudioMixdownDisplayValue.
- /// </summary>
- public string AudioMixdownDisplayValue
- {
- get
- {
- return EnumHelper<Mixdown>.GetDisplay(this.MixDown);
- }
+ // Setup Backing Properties
+ this.SetupBitrateLimits();
}
- /// <summary>
- /// Gets the The UI display value for bit rate
- /// </summary>
- public string BitRateDisplayValue
- {
- get
- {
- if (this.Encoder == AudioEncoder.Ac3Passthrough || this.Encoder == AudioEncoder.DtsPassthrough
- || this.Encoder == AudioEncoder.DtsHDPassthrough)
- {
- return "Auto";
- }
-
- return this.Bitrate.ToString();
- }
- }
+ #region Track Properties
/// <summary>
/// Gets or sets Audio Bitrate
@@ -171,6 +104,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models
this.NotifyOfPropertyChange(() => this.Bitrate);
}
}
+
/// <summary>
/// Gets or sets Dynamic Range Compression
@@ -184,7 +118,7 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models
set
{
- if (!object.Equals(value, this.drc))
+ if (!Equals(value, this.drc))
{
this.drc = value;
this.NotifyOfPropertyChange(() => this.DRC);
@@ -193,17 +127,41 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models
}
/// <summary>
- /// Gets or sets a value indicating whether is default.
+ /// Gets or sets the Gain for the audio track
/// </summary>
- public bool IsDefault
+ public int Gain
{
get
{
- return this.isDefault;
+ return this.gain;
}
+
set
{
- this.isDefault = value;
+ if (!Equals(value, this.gain))
+ {
+ this.gain = value;
+ this.NotifyOfPropertyChange(() => this.Gain);
+ }
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets Audio Mixdown
+ /// </summary>
+ public Mixdown MixDown
+ {
+ get
+ {
+ return this.mixDown;
+ }
+
+ set
+ {
+ this.mixDown = value;
+ this.NotifyOfPropertyChange(() => this.MixDown);
+ this.SetupBitrateLimits();
+ this.NotifyOfPropertyChange(() => this.TrackReference);
}
}
@@ -223,63 +181,84 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models
this.NotifyOfPropertyChange(() => this.Encoder);
this.NotifyOfPropertyChange(() => this.IsPassthru);
this.NotifyOfPropertyChange(() => this.CannotSetBitrate);
+ this.SetupBitrateLimits();
this.NotifyOfPropertyChange(() => this.TrackReference);
}
}
/// <summary>
- /// Gets or sets the Gain for the audio track
+ /// Gets or sets Audio SampleRate
/// </summary>
- public int Gain
+ public double SampleRate
{
get
{
- return this.gain;
+ return this.sampleRate;
}
set
{
- if (!object.Equals(value, this.gain))
- {
- this.gain = value;
- this.NotifyOfPropertyChange(() => this.Gain);
- }
+ this.sampleRate = value;
+ this.NotifyOfPropertyChange(() => this.SampleRate);
+ this.SetupBitrateLimits();
+ this.NotifyOfPropertyChange(() => this.TrackReference);
}
}
+ #endregion
+
/// <summary>
- /// Gets or sets Audio Mixdown
+ /// Gets AudioEncoderDisplayValue.
/// </summary>
- public Mixdown MixDown
+ public string AudioEncoderDisplayValue
{
get
{
- return this.mixDown;
+ return EnumHelper<AudioEncoder>.GetDisplay(this.Encoder);
}
+ }
- set
+ /// <summary>
+ /// Gets AudioMixdownDisplayValue.
+ /// </summary>
+ public string AudioMixdownDisplayValue
+ {
+ get
{
- this.mixDown = value;
- this.NotifyOfPropertyChange(() => this.MixDown);
- this.NotifyOfPropertyChange(() => this.TrackReference);
+ return EnumHelper<Mixdown>.GetDisplay(this.MixDown);
}
}
/// <summary>
- /// Gets or sets Audio SampleRate
+ /// Gets the The UI display value for bit rate
/// </summary>
- public double SampleRate
+ public string BitRateDisplayValue
{
get
{
- return this.sampleRate;
+ if (this.Encoder == AudioEncoder.Ac3Passthrough || this.Encoder == AudioEncoder.DtsPassthrough
+ || this.Encoder == AudioEncoder.DtsHDPassthrough)
+ {
+ return "Auto";
+ }
+
+ return this.Bitrate.ToString();
}
+ }
+ /// <summary>
+ /// Gets or sets a value indicating whether is default.
+ /// TODO - Can this be removed? May have been added as a quick fix for a styling quirk.
+ /// </summary>
+ public bool IsDefault
+ {
+ get
+ {
+ return this.isDefault;
+ }
set
{
- this.sampleRate = value;
- this.NotifyOfPropertyChange(() => this.SampleRate);
- this.NotifyOfPropertyChange(() => this.TrackReference);
+ this.isDefault = value;
}
}
@@ -361,6 +340,17 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models
}
/// <summary>
+ /// Gets the bitrates.
+ /// </summary>
+ public IEnumerable<int> Bitrates
+ {
+ get
+ {
+ return this.bitrates;
+ }
+ }
+
+ /// <summary>
/// Gets a value indicating whether can set bitrate.
/// </summary>
public bool CannotSetBitrate
@@ -396,6 +386,40 @@ namespace HandBrake.ApplicationServices.Services.Encode.Model.Models
/// </summary>
public string TrackName { get; set; }
- #endregion
+ /// <summary>
+ /// The calculate bitrate limits.
+ /// </summary>
+ private void SetupBitrateLimits()
+ {
+ // Base set of bitrates available.
+ List<int> audioBitrates = HandBrakeEncoderHelpers.AudioBitrates;
+
+ // Defaults
+ int max = 256;
+ int low = 32;
+
+ // Based on the users settings, find the high and low bitrates.
+ HBAudioEncoder hbaenc = HandBrakeEncoderHelpers.GetAudioEncoder(EnumHelper<AudioEncoder>.GetShortName(this.Encoder));
+ HBRate rate = HandBrakeEncoderHelpers.AudioSampleRates.FirstOrDefault(t => t.Name == this.SampleRate.ToString(CultureInfo.InvariantCulture));
+ HBMixdown mixdown = HandBrakeEncoderHelpers.GetMixdown(EnumHelper<Mixdown>.GetShortName(this.MixDown));
+
+ BitrateLimits limits = HandBrakeEncoderHelpers.GetBitrateLimits(hbaenc, rate != null ? rate.Rate : 48000, mixdown);
+ if (limits != null)
+ {
+ max = limits.High;
+ low = limits.Low;
+ }
+
+ // Return the subset of available bitrates.
+ List<int> subsetBitrates = audioBitrates.Where(b => b <= max && b >= low).ToList();
+ this.bitrates = subsetBitrates;
+ this.NotifyOfPropertyChange(() => this.Bitrates);
+
+ // If the subset does not contain the current bitrate, request the default.
+ if (!subsetBitrates.Contains(this.Bitrate))
+ {
+ this.Bitrate = HandBrakeEncoderHelpers.GetDefaultBitrate(hbaenc, rate != null ? rate.Rate : 48000, mixdown);
+ }
+ }
}
} \ No newline at end of file
diff --git a/win/CS/HandBrake.ApplicationServices/Utilities/Converters.cs b/win/CS/HandBrake.ApplicationServices/Utilities/Converters.cs
index 3e61b35d8..dd38fb286 100644
--- a/win/CS/HandBrake.ApplicationServices/Utilities/Converters.cs
+++ b/win/CS/HandBrake.ApplicationServices/Utilities/Converters.cs
@@ -10,10 +10,9 @@
namespace HandBrake.ApplicationServices.Utilities
{
using System;
- using System.Text.RegularExpressions;
- using HandBrake.ApplicationServices.Services.Encode.Model.Models;
using HandBrake.ApplicationServices.Interop.Model.Encoding;
+ using HandBrake.ApplicationServices.Services.Encode.Model.Models;
/// <summary>
/// A class to convert various things to native C# objects
@@ -26,69 +25,18 @@ namespace HandBrake.ApplicationServices.Utilities
*
**/
- /// <summary>
- /// Convert HandBrakes time remaining into a TimeSpan
- /// </summary>
- /// <param name="time">
- /// The time remaining for the encode.
- /// </param>
- /// <returns>
- /// A TimepSpan object
- /// </returns>
- public static TimeSpan EncodeToTimespan(string time)
- {
- TimeSpan converted = new TimeSpan(0, 0, 0, 0);
-
- Match m = Regex.Match(time.Trim(), @"^([0-9]{2}:[0-9]{2}:[0-9]{2})");
- if (m.Success)
- {
- TimeSpan.TryParse(m.Groups[0].Value, out converted);
- }
-
- return converted;
- }
-
#region Audio
/// <summary>
/// Get the GUI equiv to a CLI mixdown
/// </summary>
- /// <param name="mixdown">The Audio Mixdown</param>
- /// <returns>The GUI representation of the mixdown</returns>
- public static string GetMixDown(string mixdown)
- {
- switch (mixdown.Trim())
- {
- case "mono":
- return "Mono";
- case "left_only":
- return "Mono (Left Only)";
- case "right_only":
- return "Mono (Right Only)";
- case "stereo":
- return "Stereo";
- case "dpl1":
- return "Dolby Surround";
- case "dpl2":
- return "Dolby Pro Logic II";
- case "5point1":
- return "5.1 Channels";
- case "6point1":
- return "6.1 Channels";
- case "7point1":
- return "7.1 Channels";
- case "5_2_lfe":
- return "7.1 (5F/2R/LFE)";
- default:
- return "Automatic";
- }
- }
-
- /// <summary>
- /// Get the GUI equiv to a CLI mixdown
- /// </summary>
- /// <param name="mixdown">The Audio Mixdown</param>
- /// <returns>The GUI representation of the mixdown</returns>
+ /// <param name="mixdown">
+ /// The Audio Mixdown
+ /// </param>
+ /// <returns>
+ /// The GUI representation of the mixdown
+ /// </returns>
+ [Obsolete("Use EnumHelper instead")]
public static Mixdown GetAudioMixDown(string mixdown)
{
switch (mixdown.Trim())
@@ -118,47 +66,15 @@ namespace HandBrake.ApplicationServices.Utilities
}
/// <summary>
- /// Return the CLI Mixdown name
- /// </summary>
- /// <param name="selectedAudio">GUI mixdown name</param>
- /// <returns>CLI mixdown name</returns>
- public static string GetCliMixDown(Mixdown selectedAudio)
- {
- switch (selectedAudio)
- {
- case Mixdown.Auto:
- case Mixdown.None:
- return "none";
- case Mixdown.Mono:
- return "mono";
- case Mixdown.LeftOnly:
- return "left_only";
- case Mixdown.RightOnly:
- return "right_only";
- case Mixdown.Stereo:
- return "stereo";
- case Mixdown.DolbySurround:
- return "dpl1";
- case Mixdown.DolbyProLogicII:
- return "dpl2";
- case Mixdown.FivePoint1Channels:
- return "5point1";
- case Mixdown.SixPoint1Channels:
- return "6point1";
- case Mixdown.SevenPoint1Channels:
- return "7point1";
- case Mixdown.Five_2_LFE:
- return "5_2_lfe";
- default:
- return "auto";
- }
- }
-
- /// <summary>
/// Get the GUI equiv to a GUI audio encoder string
/// </summary>
- /// <param name="audioEnc">The Audio Encoder</param>
- /// <returns>The GUI representation of that audio encoder</returns>
+ /// <param name="audioEnc">
+ /// The Audio Encoder
+ /// </param>
+ /// <returns>
+ /// The GUI representation of that audio encoder
+ /// </returns>
+ [Obsolete("Use EnumHelper instead")]
public static AudioEncoder GetAudioEncoder(string audioEnc)
{
switch (audioEnc)
diff --git a/win/CS/HandBrakeWPF/Converters/Audio/AudioBitrateConverter.cs b/win/CS/HandBrakeWPF/Converters/Audio/AudioBitrateConverter.cs
deleted file mode 100644
index 4e7f6069a..000000000
--- a/win/CS/HandBrakeWPF/Converters/Audio/AudioBitrateConverter.cs
+++ /dev/null
@@ -1,293 +0,0 @@
-// --------------------------------------------------------------------------------------------------------------------
-// <copyright file="AudioBitrateConverter.cs" company="HandBrake Project (http://handbrake.fr)">
-// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License.
-// </copyright>
-// <summary>
-// A Converter to provide the available audio bitrate options.
-// </summary>
-// --------------------------------------------------------------------------------------------------------------------
-
-namespace HandBrakeWPF.Converters.Audio
-{
- using System;
- using System.Globalization;
- using System.Windows.Data;
- using System.Collections.Generic;
- using System.Linq;
-
- using HandBrake.ApplicationServices.Services.Encode.Model.Models;
- using HandBrake.ApplicationServices.Interop.Model.Encoding;
-
- /// <summary>
- /// A Converter to provide the available audio bitrate options.
- /// </summary>
- public class AudioBitrateConverter : IValueConverter
- {
- /// <summary>
- /// The samplerates.
- /// </summary>
- readonly Dictionary<double, int> samplerates = new Dictionary<double, int>
- {
- { 8, 8000 },
- { 11.025, 11025 },
- { 12, 12000 },
- { 16, 16000 },
- { 22.05, 22050 },
- { 24, 24000 },
- { 32, 32000 },
- { 44.1, 44100 },
- { 48, 48000 }
- };
-
- /// <summary>
- /// Converts source values to a value for the binding target. The data binding engine calls this method when it propagates the values from source bindings to the binding target.
- /// </summary>
- /// <returns>
- /// A converted value.If the method returns null, the valid null value is used.A return value of <see cref="T:System.Windows.DependencyProperty"/>.<see cref="F:System.Windows.DependencyProperty.UnsetValue"/> indicates that the converter did not produce a value, and that the binding will use the <see cref="P:System.Windows.Data.BindingBase.FallbackValue"/> if it is available, or else will use the default value.A return value of <see cref="T:System.Windows.Data.Binding"/>.<see cref="F:System.Windows.Data.Binding.DoNothing"/> indicates that the binding does not transfer the value or use the <see cref="P:System.Windows.Data.BindingBase.FallbackValue"/> or the default value.
- /// </returns>
- /// <param name="value">
- /// The value.
- /// </param>
- /// <param name="targetType">
- /// The type of the binding target property.
- /// </param>
- /// <param name="parameter">
- /// The converter parameter to use.
- /// </param>
- /// <param name="culture">
- /// The culture to use in the converter.
- /// </param>
- public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
- {
- // Base set of bitrates available.
- List<int> bitrates = new List<int> { 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384, 448, 640, 768, 960, 1152, 1344, 1536 };
-
- int max = 160;
- int low = 32;
-
- AudioTrack track = value as AudioTrack;
- if (track != null)
- {
- int samplerate = this.GetBestSampleRate(track);
- int srShift = this.GetSamplerateShift(samplerate);
- int lfeCount = this.GetLowFreqChannelCount(track.MixDown);
- int channels = this.GetDiscreteChannelCount(track.MixDown) - lfeCount;
-
- switch (track.Encoder)
- {
- case AudioEncoder.ffaac:
- low = ((channels + lfeCount) * 32);
- max = ((channels + lfeCount) * ((192 + (64 * ((samplerate << srShift) >= 44100 ? 1 : 0))) >> srShift));
- break;
- case AudioEncoder.Lame:
- low = 8 + (24 * (srShift < 1 ? 1 : 0) );
- max = 64 + (96 * (srShift < 2 ? 1 : 0)) + (160 * (srShift < 1 ? 1 : 0));
- break;
- case AudioEncoder.Vorbis:
- low = (channels + lfeCount) * (14 + (8 * (srShift < 2 ? 1 : 0)) + (6 * (srShift < 1 ? 1 : 0)));
- max = (channels + lfeCount) * (32 + (54 * (srShift < 2 ? 1 : 0)) + (104 * (srShift < 1 ? 1 : 0)) + (50 * (samplerate >= 44100 ? 1 : 0)));
- break;
- case AudioEncoder.Ac3:
- low = 224 * channels / 5;
- max = 640;
- break;
- case AudioEncoder.Ac3Passthrough:
- case AudioEncoder.DtsPassthrough:
- case AudioEncoder.DtsHDPassthrough:
- case AudioEncoder.AacPassthru:
- case AudioEncoder.Mp3Passthru:
- case AudioEncoder.Passthrough:
- case AudioEncoder.ffflac:
- case AudioEncoder.ffflac24:
- case AudioEncoder.EAc3Passthrough:
- case AudioEncoder.TrueHDPassthrough:
- case AudioEncoder.FlacPassthru:
- max = 1536; // Since we don't care, just set it to the max.
- break;
- case AudioEncoder.fdkaac:
- low = channels * samplerate * 2 / 3000;
- max = channels * samplerate * 6 / 1000;
- break;
- case AudioEncoder.fdkheaac:
- low = (channels * (12 + (4 * (samplerate >= 44100 ? 1 : 0))));
- max = (channels - (channels > 2 ? 1 : 0)) * (48 + (16 * (samplerate >= 22050 ? 1 : 0)));
- break;
- default:
- max = 768;
- break;
- }
-
- // Bring the bitrate down in-line with the max.
- if (track.Bitrate < low)
- {
- track.Bitrate = low;
- }
-
- if (track.Bitrate > max)
- {
- track.Bitrate = max;
- }
- }
-
- return bitrates.Where(bitrate => bitrate <= max && bitrate >= low);
- }
-
- /// <summary>
- /// The get channel count.
- /// </summary>
- /// <param name="mixdown">
- /// The mixdown.
- /// </param>
- /// <returns>
- /// The System.Int32.
- /// </returns>
- private int GetDiscreteChannelCount(Mixdown mixdown)
- {
- switch (mixdown)
- {
- case Mixdown.Five_2_LFE:
- case Mixdown.SevenPoint1Channels:
- return 8;
- case Mixdown.SixPoint1Channels:
- return 7;
- case Mixdown.FivePoint1Channels:
- return 6;
- case Mixdown.Mono:
- case Mixdown.LeftOnly:
- case Mixdown.RightOnly:
- return 1;
- case Mixdown.None:
- return 0;
- default:
- return 2;
- }
- }
-
- /// <summary>
- /// The get low freq channel count.
- /// </summary>
- /// <param name="mixdown">
- /// The mixdown.
- /// </param>
- /// <returns>
- /// The System.Int32.
- /// </returns>
- private int GetLowFreqChannelCount(Mixdown mixdown)
- {
- switch (mixdown)
- {
- case Mixdown.FivePoint1Channels:
- case Mixdown.SixPoint1Channels:
- case Mixdown.SevenPoint1Channels:
- case Mixdown.Five_2_LFE:
- return 1;
- default:
- return 0;
- }
- }
-
- /// <summary>
- /// The get samplerate shift.
- /// </summary>
- /// <param name="samplerate">
- /// The samplerate.
- /// </param>
- /// <returns>
- /// The System.Int32.
- /// </returns>
- private int GetSamplerateShift(int samplerate)
- {
- /* sr_shift: 0 -> 48000, 44100, 32000 Hz
- * 1 -> 24000, 22050, 16000 Hz
- * 2 -> 12000, 11025, 8000 Hz
- *
- * also, since samplerates are sanitized downwards:
- *
- * (samplerate < 32000) implies (samplerate <= 24000)
- */
- return ((samplerate < 16000) ? 2 : (samplerate < 32000) ? 1 : 0);
- }
-
- /// <summary>
- /// The get best sample rate.
- /// </summary>
- /// <param name="track">
- /// The track.
- /// </param>
- /// <returns>
- /// The System.Double.
- /// </returns>
- private int GetBestSampleRate(AudioTrack track)
- {
- int samplerate = 48000; // Default to 48
-
- // Try get the users selected sample rate
- if (!track.SampleRate.Equals(0.0d))
- {
- samplerate = this.samplerates[track.SampleRate];
- }
- else if (track.ScannedTrack != null && track.ScannedTrack.SampleRate != 0) // If it's auto, try get the source
- {
- samplerate = track.ScannedTrack.SampleRate;
- }
-
- // THen Sanitize to make sure it's valid
- int bestSamplerate;
- if ((samplerate < 32000) && (track.Encoder == AudioEncoder.Ac3))
- {
- // AC-3 < 32 kHz suffers from poor hardware compatibility
- bestSamplerate = 32000;
- }
- else if ((samplerate < 16000) && (track.Encoder == AudioEncoder.fdkheaac))
- {
- bestSamplerate = 16000;
- }
- else
- {
- bestSamplerate = samplerate;
- foreach (KeyValuePair<double, int> item in this.samplerates)
- {
- // valid samplerate
- if (bestSamplerate.Equals(item.Value))
- break;
-
- // samplerate is higher than the next valid samplerate,
- // or lower than the lowest valid samplerate
- if (bestSamplerate > item.Value && bestSamplerate < this.samplerates.First().Value)
- {
- bestSamplerate = item.Value;
- break;
- }
- }
- }
-
- return bestSamplerate;
- }
-
- /// <summary>
- /// The convert back.
- /// </summary>
- /// <param name="value">
- /// The value.
- /// </param>
- /// <param name="targetType">
- /// The target type.
- /// </param>
- /// <param name="parameter">
- /// The parameter.
- /// </param>
- /// <param name="culture">
- /// The culture.
- /// </param>
- /// <returns>
- /// The System.Object.
- /// </returns>
- /// <exception cref="NotImplementedException">
- /// We don't use this.
- /// </exception>
- public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
- {
- throw new NotImplementedException();
- }
- }
-}
diff --git a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj
index 6304e107d..5cbc6d1b2 100644
--- a/win/CS/HandBrakeWPF/HandBrakeWPF.csproj
+++ b/win/CS/HandBrakeWPF/HandBrakeWPF.csproj
@@ -218,7 +218,6 @@
<Compile Include="Controls\StatusPanel.xaml.cs">
<DependentUpon>StatusPanel.xaml</DependentUpon>
</Compile>
- <Compile Include="Converters\Audio\AudioBitrateConverter.cs" />
<Compile Include="Converters\Audio\AudioEncoderConverter.cs" />
<Compile Include="Converters\Audio\AudioQueueDisplayConverter.cs" />
<Compile Include="Converters\BooleanToHiddenVisibilityConverter.cs" />
diff --git a/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs b/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs
index 89fd93921..82c5eb329 100644
--- a/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs
+++ b/win/CS/HandBrakeWPF/Services/Presets/Factories/JsonPresetFactory.cs
@@ -298,7 +298,7 @@ namespace HandBrakeWPF.Services.Presets.Factories
// track.CompressionLevel = audioTrack.AudioCompressionLevel;
// track.AudioDitherMethod = audioTrack.AudioDitherMethod;
track.Encoder = EnumHelper<AudioEncoder>.GetValue(audioTrack.AudioEncoder);
- track.MixDown = Converters.GetAudioMixDown(Converters.GetMixDown(audioTrack.AudioMixdown)); // TODO refactor
+ track.MixDown = EnumHelper<Mixdown>.GetValue(audioTrack.AudioMixdown);
// track.AudioNormalizeMixLevel = audioTrack.AudioNormalizeMixLevel;
track.SampleRate = audioTrack.AudioSamplerate == "auto" ? 0 : double.Parse(audioTrack.AudioSamplerate);
diff --git a/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs b/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs
index 75adf94be..be7c2bb0e 100644
--- a/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs
+++ b/win/CS/HandBrakeWPF/ViewModels/AudioViewModel.cs
@@ -16,6 +16,7 @@ namespace HandBrakeWPF.ViewModels
using Caliburn.Micro;
+ using HandBrake.ApplicationServices.Interop;
using HandBrake.ApplicationServices.Interop.Model.Encoding;
using HandBrake.ApplicationServices.Services.Encode.Model;
using HandBrake.ApplicationServices.Services.Encode.Model.Models;
@@ -72,7 +73,13 @@ namespace HandBrakeWPF.ViewModels
public AudioViewModel(IWindowManager windowManager, IUserSettingService userSettingService)
{
this.Task = new EncodeTask();
- this.SampleRates = new ObservableCollection<string> { "Auto", "48", "44.1", "32", "24", "22.05", "16", "12", "11.025", "8" };
+
+ this.SampleRates = new ObservableCollection<string> { "Auto" };
+ foreach (var item in HandBrakeEncoderHelpers.AudioSampleRates)
+ {
+ this.SampleRates.Add(item.Name);
+ }
+
this.AudioEncoders = EnumHelper<AudioEncoder>.GetEnumList();
this.AudioMixdowns = EnumHelper<Mixdown>.GetEnumList();
this.SourceTracks = new List<Audio>();
@@ -148,7 +155,7 @@ namespace HandBrakeWPF.ViewModels
/// <summary>
/// Gets or sets SampleRates.
/// </summary>
- public IEnumerable<string> SampleRates { get; set; }
+ public IList<string> SampleRates { get; set; }
/// <summary>
/// Gets or sets SourceTracks.
diff --git a/win/CS/HandBrakeWPF/Views/AudioView.xaml b/win/CS/HandBrakeWPF/Views/AudioView.xaml
index af270a557..ef8a29cf9 100644
--- a/win/CS/HandBrakeWPF/Views/AudioView.xaml
+++ b/win/CS/HandBrakeWPF/Views/AudioView.xaml
@@ -21,7 +21,6 @@
<Conveters:EnumComboConverter x:Key="enumComboConverter" />
<Conveters:BooleanToVisibilityConverter x:Key="boolToVisConverter" />
<Conveters:BooleanToHiddenVisibilityConverter x:Key="boolToHiddenVisConverter" />
- <Audio:AudioBitrateConverter x:Key="audioBitrateConverter" />
<Audio:AudioEncoderConverter x:Key="audioEncoderConverter" />
<Audio:AudioBehaviourConverter x:Key="audioBehaviourConverter" />
<Audio:AudioTrackDefaultBehaviourConverter x:Key="audioTrackDefaultBehaviourConverter" />
@@ -191,7 +190,7 @@
<TextBlock Grid.Column="4" VerticalAlignment="Center" FontWeight="Bold" Text="{x:Static Properties:ResourcesUI.AudioView_Bitrate}"
Visibility="{Binding CannotSetBitrate, Converter={StaticResource boolToVisConverter}, ConverterParameter=true}" />
- <ComboBox Grid.Column="5" Width="55" Height="22" Margin="5,0,5,0" ItemsSource="{Binding TrackReference, Converter={StaticResource audioBitrateConverter}}"
+ <ComboBox Grid.Column="5" Width="55" Height="22" Margin="5,0,5,0" ItemsSource="{Binding Bitrates}"
SelectedItem="{Binding Bitrate}"
Visibility="{Binding CannotSetBitrate, Converter={StaticResource boolToVisConverter}, ConverterParameter=true}" />