summaryrefslogtreecommitdiffstats
path: root/win/CS/HandBrake.ApplicationServices/Services/Encode
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/CS/HandBrake.ApplicationServices/Services/Encode
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/CS/HandBrake.ApplicationServices/Services/Encode')
-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
2 files changed, 134 insertions, 110 deletions
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