update ResolutionNormalizer

This commit is contained in:
Luke Pulverenti 2017-08-30 14:06:54 -04:00
parent b5f14258e0
commit 8de80d43ba
4 changed files with 25 additions and 66 deletions

View File

@ -418,6 +418,8 @@ namespace Emby.Server.Implementations.Dto
{
dto.Type = "Recording";
dto.CanDownload = false;
dto.RunTimeTicks = null;
if (!string.IsNullOrWhiteSpace(dto.SeriesName))
{
dto.EpisodeTitle = dto.Name;

View File

@ -487,69 +487,8 @@ namespace Emby.Server.Implementations.HttpServer
return result;
}
var compress = ShouldCompressResponse(requestContext, contentType);
var hasHeaders = await GetStaticResult(requestContext, options, compress).ConfigureAwait(false);
AddResponseHeaders(hasHeaders, options.ResponseHeaders);
return hasHeaders;
}
/// <summary>
/// Shoulds the compress response.
/// </summary>
/// <param name="requestContext">The request context.</param>
/// <param name="contentType">Type of the content.</param>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
private bool ShouldCompressResponse(IRequest requestContext, string contentType)
{
// It will take some work to support compression with byte range requests
if (!string.IsNullOrWhiteSpace(requestContext.Headers.Get("Range")))
{
return false;
}
// Don't compress media
if (contentType.StartsWith("audio/", StringComparison.OrdinalIgnoreCase) || contentType.StartsWith("video/", StringComparison.OrdinalIgnoreCase))
{
return false;
}
// Don't compress images
if (contentType.StartsWith("image/", StringComparison.OrdinalIgnoreCase))
{
return false;
}
if (contentType.StartsWith("font/", StringComparison.OrdinalIgnoreCase))
{
return false;
}
if (contentType.StartsWith("application/", StringComparison.OrdinalIgnoreCase))
{
if (string.Equals(contentType, "application/x-javascript", StringComparison.OrdinalIgnoreCase))
{
return true;
}
if (string.Equals(contentType, "application/xml", StringComparison.OrdinalIgnoreCase))
{
return true;
}
return false;
}
return true;
}
/// <summary>
/// The us culture
/// </summary>
private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
private async Task<IHasHeaders> GetStaticResult(IRequest requestContext, StaticResultOptions options, bool compress)
{
var isHeadRequest = options.IsHeadRequest;
var factoryFn = options.ContentFactory;
var contentType = options.ContentType;
var responseHeaders = options.ResponseHeaders;
//var requestedCompressionType = GetCompressionType(requestContext);
@ -558,22 +497,28 @@ namespace Emby.Server.Implementations.HttpServer
if (!isHeadRequest && !string.IsNullOrWhiteSpace(options.Path))
{
return new FileWriter(options.Path, contentType, rangeHeader, _logger, _fileSystem)
var hasHeaders = new FileWriter(options.Path, contentType, rangeHeader, _logger, _fileSystem)
{
OnComplete = options.OnComplete,
OnError = options.OnError,
FileShare = options.FileShare
};
AddResponseHeaders(hasHeaders, options.ResponseHeaders);
return hasHeaders;
}
if (!string.IsNullOrWhiteSpace(rangeHeader))
{
var stream = await factoryFn().ConfigureAwait(false);
return new RangeRequestWriter(rangeHeader, stream, contentType, isHeadRequest, _logger)
var hasHeaders = new RangeRequestWriter(rangeHeader, stream, contentType, isHeadRequest, _logger)
{
OnComplete = options.OnComplete
};
AddResponseHeaders(hasHeaders, options.ResponseHeaders);
return hasHeaders;
}
else
{
@ -588,14 +533,22 @@ namespace Emby.Server.Implementations.HttpServer
return GetHttpResult(new byte[] { }, contentType, true);
}
return new StreamWriter(stream, contentType, _logger)
var hasHeaders = new StreamWriter(stream, contentType, _logger)
{
OnComplete = options.OnComplete,
OnError = options.OnError
};
AddResponseHeaders(hasHeaders, options.ResponseHeaders);
return hasHeaders;
}
}
/// <summary>
/// The us culture
/// </summary>
private static readonly CultureInfo UsCulture = new CultureInfo("en-US");
/// <summary>
/// Adds the caching responseHeaders.
/// </summary>

View File

@ -298,7 +298,7 @@ namespace MediaBrowser.Api
/// <returns>IEnumerable{FileSystemEntryInfo}.</returns>
private IEnumerable<FileSystemEntryInfo> GetFileSystemEntries(GetDirectoryContents request)
{
var entries = _fileSystem.GetFileSystemEntries(request.Path).Where(i =>
var entries = _fileSystem.GetFileSystemEntries(request.Path).OrderBy(i => i.FullName).Where(i =>
{
if (!request.IncludeHidden && i.IsHidden)
{

View File

@ -58,12 +58,16 @@ namespace MediaBrowser.Model.Dlna
private static ResolutionConfiguration GetResolutionConfiguration(int outputBitrate)
{
ResolutionConfiguration previousOption = null;
foreach (var config in Configurations)
{
if (outputBitrate <= config.MaxBitrate)
{
return config;
return previousOption ?? config;
}
previousOption = config;
}
return null;