aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Model/Dlna/ResolutionNormalizer.cs
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2014-10-06 19:58:46 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2014-10-06 19:58:46 -0400
commitf02f3222085311b2a2cacab6642ad987a4176e65 (patch)
tree9f317e5a3f087d4b4c5e523a8d8552d7d248567e /MediaBrowser.Model/Dlna/ResolutionNormalizer.cs
parenta9eed234ba2a366fe014f0cc6f462c3764528948 (diff)
remove mono compiler directives
Diffstat (limited to 'MediaBrowser.Model/Dlna/ResolutionNormalizer.cs')
-rw-r--r--MediaBrowser.Model/Dlna/ResolutionNormalizer.cs63
1 files changed, 63 insertions, 0 deletions
diff --git a/MediaBrowser.Model/Dlna/ResolutionNormalizer.cs b/MediaBrowser.Model/Dlna/ResolutionNormalizer.cs
new file mode 100644
index 000000000..a95de8d39
--- /dev/null
+++ b/MediaBrowser.Model/Dlna/ResolutionNormalizer.cs
@@ -0,0 +1,63 @@
+using System;
+using System.Collections.Generic;
+
+namespace MediaBrowser.Model.Dlna
+{
+ public class ResolutionNormalizer
+ {
+ private static readonly List<ResolutionConfiguration> Configurations =
+ new List<ResolutionConfiguration>
+ {
+ new ResolutionConfiguration(426, 320000),
+ new ResolutionConfiguration(640, 400000),
+ new ResolutionConfiguration(720, 950000),
+ new ResolutionConfiguration(1280, 2500000)
+ };
+
+ public static ResolutionOptions Normalize(int maxBitrate,
+ string codec,
+ int? maxWidth,
+ int? maxHeight)
+ {
+ foreach (var config in Configurations)
+ {
+ if (maxBitrate <= config.MaxBitrate)
+ {
+ var originvalValue = maxWidth;
+
+ maxWidth = Math.Min(config.MaxWidth, maxWidth ?? config.MaxWidth);
+ if (!originvalValue.HasValue || originvalValue.Value != maxWidth.Value)
+ {
+ maxHeight = null;
+ }
+
+ break;
+ }
+ }
+
+ return new ResolutionOptions
+ {
+ MaxWidth = maxWidth,
+ MaxHeight = maxHeight
+ };
+ }
+ }
+
+ public class ResolutionConfiguration
+ {
+ public int MaxWidth { get; set; }
+ public int MaxBitrate { get; set; }
+
+ public ResolutionConfiguration(int maxWidth, int maxBitrate)
+ {
+ MaxWidth = maxWidth;
+ MaxBitrate = maxBitrate;
+ }
+ }
+
+ public class ResolutionOptions
+ {
+ public int? MaxWidth { get; set; }
+ public int? MaxHeight { get; set; }
+ }
+}