2014-10-06 23:58:46 +00:00
|
|
|
|
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)
|
|
|
|
|
};
|
|
|
|
|
|
2015-12-24 20:06:52 +00:00
|
|
|
|
public static ResolutionOptions Normalize(int? inputBitrate,
|
|
|
|
|
int outputBitrate,
|
|
|
|
|
string inputCodec,
|
|
|
|
|
string outputCodec,
|
2014-10-06 23:58:46 +00:00
|
|
|
|
int? maxWidth,
|
|
|
|
|
int? maxHeight)
|
|
|
|
|
{
|
2015-12-24 20:06:52 +00:00
|
|
|
|
// If the bitrate isn't changing, then don't downlscale the resolution
|
|
|
|
|
if (inputBitrate.HasValue && outputBitrate >= inputBitrate.Value)
|
|
|
|
|
{
|
|
|
|
|
if (maxWidth.HasValue || maxHeight.HasValue)
|
|
|
|
|
{
|
|
|
|
|
return new ResolutionOptions
|
|
|
|
|
{
|
|
|
|
|
MaxWidth = maxWidth,
|
|
|
|
|
MaxHeight = maxHeight
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var config in Configurations)
|
2014-10-06 23:58:46 +00:00
|
|
|
|
{
|
2015-12-24 20:06:52 +00:00
|
|
|
|
if (outputBitrate <= config.MaxBitrate)
|
2014-10-06 23:58:46 +00:00
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|