From 016f2791d63706de09cc77228c6282c06574d611 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 26 Feb 2015 13:24:38 -0500 Subject: [PATCH] remove dead throttle code --- .../Playback/BaseStreamingService.cs | 34 +++------ .../BaseProgressiveStreamingService.cs | 69 +++++++++---------- MediaBrowser.Api/Playback/StreamRequest.cs | 1 - .../Net/StaticResultOptions.cs | 5 -- .../Encoder/BaseEncoder.cs | 18 ----- .../HttpServer/HttpResultFactory.cs | 8 --- .../HttpServer/RangeRequestWriter.cs | 12 ---- .../HttpServer/StreamWriter.cs | 12 ---- 8 files changed, 40 insertions(+), 119 deletions(-) diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 49d5f1c8d8..bab0d1a6e4 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -877,14 +877,6 @@ namespace MediaBrowser.Api.Playback return "copy"; } - private bool SupportsThrottleWithStream - { - get - { - return false; - } - } - /// /// Gets the input argument. /// @@ -908,23 +900,15 @@ namespace MediaBrowser.Api.Playback private string GetInputPathArgument(string transcodingJobId, StreamState state) { - if (state.InputProtocol == MediaProtocol.File && - state.RunTimeTicks.HasValue && - state.VideoType == VideoType.VideoFile && - !string.Equals(state.OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase)) - { - if (state.RunTimeTicks.Value >= TimeSpan.FromMinutes(5).Ticks && state.IsInputVideo) - { - if (SupportsThrottleWithStream) - { - var url = "http://localhost:" + ServerConfigurationManager.Configuration.HttpServerPortNumber.ToString(UsCulture) + "/videos/" + state.Request.Id + "/stream?static=true&Throttle=true&mediaSourceId=" + state.Request.MediaSourceId; - - url += "&transcodingJobId=" + transcodingJobId; - - return string.Format("\"{0}\"", url); - } - } - } + //if (state.InputProtocol == MediaProtocol.File && + // state.RunTimeTicks.HasValue && + // state.VideoType == VideoType.VideoFile && + // !string.Equals(state.OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase)) + //{ + // if (state.RunTimeTicks.Value >= TimeSpan.FromMinutes(5).Ticks && state.IsInputVideo) + // { + // } + //} var protocol = state.InputProtocol; diff --git a/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs b/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs index 9dbe3389e6..09f1ab567f 100644 --- a/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs +++ b/MediaBrowser.Api/Playback/Progressive/BaseProgressiveStreamingService.cs @@ -153,49 +153,12 @@ namespace MediaBrowser.Api.Playback.Progressive using (state) { - var job = string.IsNullOrEmpty(request.TranscodingJobId) ? - null : - ApiEntryPoint.Instance.GetTranscodingJob(request.TranscodingJobId); - - var limits = new List(); - if (state.InputBitrate.HasValue) - { - // Bytes per second - limits.Add((state.InputBitrate.Value / 8)); - } - if (state.InputFileSize.HasValue && state.RunTimeTicks.HasValue) - { - var totalSeconds = TimeSpan.FromTicks(state.RunTimeTicks.Value).TotalSeconds; - - if (totalSeconds > 1) - { - var timeBasedLimit = state.InputFileSize.Value / totalSeconds; - limits.Add(Convert.ToInt64(timeBasedLimit)); - } - } - - // Take the greater of the above to methods, just to be safe - var throttleLimit = limits.Count > 0 ? limits.First() : 0; - - // Pad to play it safe - var bytesPerSecond = Convert.ToInt64(1.05 * throttleLimit); - - // Don't even start evaluating this until at least two minutes have content have been consumed - var targetGap = throttleLimit * 120; - return ResultFactory.GetStaticFileResult(Request, new StaticFileResultOptions { ResponseHeaders = responseHeaders, ContentType = contentType, IsHeadRequest = isHeadRequest, - Path = state.MediaPath, - Throttle = request.Throttle, - - ThrottleLimit = bytesPerSecond, - - MinThrottlePosition = targetGap, - - ThrottleCallback = (l1, l2) => ThrottleCallack(l1, l2, bytesPerSecond, job) + Path = state.MediaPath }); } } @@ -238,6 +201,36 @@ namespace MediaBrowser.Api.Playback.Progressive private long ThrottleCallack(long currentBytesPerSecond, long bytesWritten, long originalBytesPerSecond, TranscodingJob job) { + //var job = string.IsNullOrEmpty(request.TranscodingJobId) ? + //null : + //ApiEntryPoint.Instance.GetTranscodingJob(request.TranscodingJobId); + + //var limits = new List(); + //if (state.InputBitrate.HasValue) + //{ + // // Bytes per second + // limits.Add((state.InputBitrate.Value / 8)); + //} + //if (state.InputFileSize.HasValue && state.RunTimeTicks.HasValue) + //{ + // var totalSeconds = TimeSpan.FromTicks(state.RunTimeTicks.Value).TotalSeconds; + + // if (totalSeconds > 1) + // { + // var timeBasedLimit = state.InputFileSize.Value / totalSeconds; + // limits.Add(Convert.ToInt64(timeBasedLimit)); + // } + //} + + //// Take the greater of the above to methods, just to be safe + //var throttleLimit = limits.Count > 0 ? limits.First() : 0; + + //// Pad to play it safe + //var bytesPerSecond = Convert.ToInt64(1.05 * throttleLimit); + + //// Don't even start evaluating this until at least two minutes have content have been consumed + //var targetGap = throttleLimit * 120; + var bytesDownloaded = job.BytesDownloaded ?? 0; var transcodingPositionTicks = job.TranscodingPositionTicks ?? 0; var downloadPositionTicks = job.DownloadPositionTicks ?? 0; diff --git a/MediaBrowser.Api/Playback/StreamRequest.cs b/MediaBrowser.Api/Playback/StreamRequest.cs index dc22fc7548..907b17b244 100644 --- a/MediaBrowser.Api/Playback/StreamRequest.cs +++ b/MediaBrowser.Api/Playback/StreamRequest.cs @@ -72,7 +72,6 @@ namespace MediaBrowser.Api.Playback public string Params { get; set; } public string ClientTime { get; set; } - public bool Throttle { get; set; } public string TranscodingJobId { get; set; } } diff --git a/MediaBrowser.Controller/Net/StaticResultOptions.cs b/MediaBrowser.Controller/Net/StaticResultOptions.cs index 5bb2c9a5c3..6a104554af 100644 --- a/MediaBrowser.Controller/Net/StaticResultOptions.cs +++ b/MediaBrowser.Controller/Net/StaticResultOptions.cs @@ -18,11 +18,6 @@ namespace MediaBrowser.Controller.Net public IDictionary ResponseHeaders { get; set; } - public bool Throttle { get; set; } - public long ThrottleLimit { get; set; } - public long MinThrottlePosition { get; set; } - public Func ThrottleCallback { get; set; } - public Action OnComplete { get; set; } public StaticResultOptions() diff --git a/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs index ffae8612ed..ead080c605 100644 --- a/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs +++ b/MediaBrowser.MediaEncoding/Encoder/BaseEncoder.cs @@ -452,24 +452,6 @@ namespace MediaBrowser.MediaEncoding.Encoder private string GetInputPathArgument(EncodingJob job) { - //if (job.InputProtocol == MediaProtocol.File && - // job.RunTimeTicks.HasValue && - // job.VideoType == VideoType.VideoFile && - // !string.Equals(job.OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase)) - //{ - // if (job.RunTimeTicks.Value >= TimeSpan.FromMinutes(5).Ticks && job.IsInputVideo) - // { - // if (SupportsThrottleWithStream) - // { - // var url = "http://localhost:" + ServerConfigurationManager.Configuration.HttpServerPortNumber.ToString(UsCulture) + "/videos/" + job.Request.Id + "/stream?static=true&Throttle=true&mediaSourceId=" + job.Request.MediaSourceId; - - // url += "&transcodingJobId=" + transcodingJobId; - - // return string.Format("\"{0}\"", url); - // } - // } - //} - var protocol = job.InputProtocol; var inputPath = new[] { job.MediaPath }; diff --git a/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs b/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs index 681d3ac5e5..ecf58e4a67 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/HttpResultFactory.cs @@ -461,10 +461,6 @@ namespace MediaBrowser.Server.Implementations.HttpServer { return new RangeRequestWriter(rangeHeader, stream, contentType, isHeadRequest) { - Throttle = options.Throttle, - ThrottleLimit = options.ThrottleLimit, - MinThrottlePosition = options.MinThrottlePosition, - ThrottleCallback = options.ThrottleCallback, OnComplete = options.OnComplete }; } @@ -480,10 +476,6 @@ namespace MediaBrowser.Server.Implementations.HttpServer return new StreamWriter(stream, contentType, _logger) { - Throttle = options.Throttle, - ThrottleLimit = options.ThrottleLimit, - MinThrottlePosition = options.MinThrottlePosition, - ThrottleCallback = options.ThrottleCallback, OnComplete = options.OnComplete }; } diff --git a/MediaBrowser.Server.Implementations/HttpServer/RangeRequestWriter.cs b/MediaBrowser.Server.Implementations/HttpServer/RangeRequestWriter.cs index cdd4c6d7ca..8c72f9e7e6 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/RangeRequestWriter.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/RangeRequestWriter.cs @@ -24,10 +24,6 @@ namespace MediaBrowser.Server.Implementations.HttpServer private long RangeLength { get; set; } private long TotalContentLength { get; set; } - public bool Throttle { get; set; } - public long ThrottleLimit { get; set; } - public long MinThrottlePosition; - public Func ThrottleCallback { get; set; } public Action OnComplete { get; set; } /// @@ -165,14 +161,6 @@ namespace MediaBrowser.Server.Implementations.HttpServer /// The response stream. public void WriteTo(Stream responseStream) { - if (Throttle) - { - responseStream = new ThrottledStream(responseStream, ThrottleLimit) - { - MinThrottlePosition = MinThrottlePosition, - ThrottleCallback = ThrottleCallback - }; - } WriteToInternal(responseStream); } diff --git a/MediaBrowser.Server.Implementations/HttpServer/StreamWriter.cs b/MediaBrowser.Server.Implementations/HttpServer/StreamWriter.cs index 1db14e8878..fe662542ef 100644 --- a/MediaBrowser.Server.Implementations/HttpServer/StreamWriter.cs +++ b/MediaBrowser.Server.Implementations/HttpServer/StreamWriter.cs @@ -35,10 +35,6 @@ namespace MediaBrowser.Server.Implementations.HttpServer get { return _options; } } - public bool Throttle { get; set; } - public long ThrottleLimit { get; set; } - public long MinThrottlePosition; - public Func ThrottleCallback { get; set; } public Action OnComplete { get; set; } /// @@ -82,14 +78,6 @@ namespace MediaBrowser.Server.Implementations.HttpServer /// The response stream. public void WriteTo(Stream responseStream) { - if (Throttle) - { - responseStream = new ThrottledStream(responseStream, ThrottleLimit) - { - MinThrottlePosition = MinThrottlePosition, - ThrottleCallback = ThrottleCallback - }; - } WriteToInternal(responseStream); }