From d69894d09bdcb6ce8fef05c932284fa6c82b23e4 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 2 Feb 2014 10:19:29 -0500 Subject: [PATCH] added new setting to allow video upscaling --- .../Playback/BaseStreamingService.cs | 46 +++++++++++++++++++ .../Configuration/ServerConfiguration.cs | 2 + 2 files changed, 48 insertions(+) diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index c6ea91d691..81729cbc81 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -1222,6 +1222,8 @@ namespace MediaBrowser.Api.Playback state.VideoStream = GetMediaStream(mediaStreams, videoRequest.VideoStreamIndex, MediaStreamType.Video); state.SubtitleStream = GetMediaStream(mediaStreams, videoRequest.SubtitleStreamIndex, MediaStreamType.Subtitle, false); state.AudioStream = GetMediaStream(mediaStreams, videoRequest.AudioStreamIndex, MediaStreamType.Audio); + + EnforceResolutionLimit(state, videoRequest); } else { @@ -1233,6 +1235,50 @@ namespace MediaBrowser.Api.Playback return state; } + /// + /// Enforces the resolution limit. + /// + /// The state. + /// The video request. + private void EnforceResolutionLimit(StreamState state, VideoStreamRequest videoRequest) + { + int? videoWidth = null; + int? videoHeight = null; + + // Grab the values from the source video, if we have them + if (state.VideoStream != null) + { + videoWidth = state.VideoStream.Width; + videoHeight = state.VideoStream.Height; + } + + if (videoRequest.Width.HasValue && videoWidth.HasValue) + { + if (videoRequest.Width.Value > videoWidth.Value) + { + throw new ArgumentException("Video upscaling has not been enabled by the user"); + } + } + + if (videoRequest.Height.HasValue && videoHeight.HasValue) + { + if (videoRequest.Height.Value > videoHeight.Value) + { + throw new ArgumentException("Video upscaling has not been enabled by the user"); + } + } + + // We don't know the source resolution. Don't allow an exact resolution unless upscaling is allowed + if (!ServerConfigurationManager.Configuration.AllowVideoUpscaling) + { + videoRequest.MaxWidth = videoRequest.MaxWidth ?? videoRequest.Width; + videoRequest.MaxHeight = videoRequest.MaxHeight ?? videoRequest.Height; + + videoRequest.Width = null; + videoRequest.Height = null; + } + } + protected string GetInputModifier(StreamState state) { var inputModifier = string.Empty; diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index f874bdbb25..a7cc205baa 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -187,6 +187,8 @@ namespace MediaBrowser.Model.Configuration /// The encoding quality. public EncodingQuality MediaEncodingQuality { get; set; } + public bool AllowVideoUpscaling { get; set; } + public bool EnableMovieChapterImageExtraction { get; set; } public bool EnableEpisodeChapterImageExtraction { get; set; } public bool EnableOtherVideoChapterImageExtraction { get; set; }