aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2015-03-30 12:16:34 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2015-03-30 12:16:34 -0400
commit5f044cfd68eecf116df1a646806fc091f3fb63aa (patch)
tree572b7a009f9c308e1b365801028738b59762a1a4 /MediaBrowser.Api
parent0bd27381e0ef5a0a17ea93bb86a752c5d2cc2e1a (diff)
add setting to control transcodng throttle
Diffstat (limited to 'MediaBrowser.Api')
-rw-r--r--MediaBrowser.Api/Playback/BaseStreamingService.cs11
-rw-r--r--MediaBrowser.Api/Playback/StreamState.cs36
-rw-r--r--MediaBrowser.Api/Playback/TranscodingThrottler.cs26
3 files changed, 61 insertions, 12 deletions
diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs
index c4cdfc9edd..8c4bcf0a31 100644
--- a/MediaBrowser.Api/Playback/BaseStreamingService.cs
+++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs
@@ -1080,7 +1080,7 @@ namespace MediaBrowser.Api.Playback
{
if (state.RunTimeTicks.Value >= TimeSpan.FromMinutes(5).Ticks && state.IsInputVideo)
{
- transcodingJob.TranscodingThrottler = state.TranscodingThrottler = new TranscodingThrottler(transcodingJob, Logger);
+ transcodingJob.TranscodingThrottler = state.TranscodingThrottler = new TranscodingThrottler(transcodingJob, Logger, ServerConfigurationManager);
state.TranscodingThrottler.Start();
}
}
@@ -2012,7 +2012,6 @@ namespace MediaBrowser.Api.Playback
}
var audioCodec = state.ActualOutputAudioCodec;
-
var videoCodec = state.ActualOutputVideoCodec;
var mediaProfile = state.VideoRequest == null ?
@@ -2033,7 +2032,9 @@ namespace MediaBrowser.Api.Playback
state.TargetTimestamp,
state.IsTargetAnamorphic,
state.IsTargetCabac,
- state.TargetRefFrames);
+ state.TargetRefFrames,
+ state.TargetVideoStreamCount,
+ state.TargetAudioStreamCount);
if (mediaProfile != null)
{
@@ -2118,7 +2119,9 @@ namespace MediaBrowser.Api.Playback
state.TranscodeSeekInfo,
state.IsTargetAnamorphic,
state.IsTargetCabac,
- state.TargetRefFrames
+ state.TargetRefFrames,
+ state.TargetVideoStreamCount,
+ state.TargetAudioStreamCount
).FirstOrDefault() ?? string.Empty;
}
diff --git a/MediaBrowser.Api/Playback/StreamState.cs b/MediaBrowser.Api/Playback/StreamState.cs
index b097f3b6af..2d1e896db0 100644
--- a/MediaBrowser.Api/Playback/StreamState.cs
+++ b/MediaBrowser.Api/Playback/StreamState.cs
@@ -346,6 +346,42 @@ namespace MediaBrowser.Api.Playback
}
}
+ public int? TargetVideoStreamCount
+ {
+ get
+ {
+ if (Request.Static)
+ {
+ return GetMediaStreamCount(MediaStreamType.Video, int.MaxValue);
+ }
+ return GetMediaStreamCount(MediaStreamType.Video, 1);
+ }
+ }
+
+ public int? TargetAudioStreamCount
+ {
+ get
+ {
+ if (Request.Static)
+ {
+ return GetMediaStreamCount(MediaStreamType.Audio, int.MaxValue);
+ }
+ return GetMediaStreamCount(MediaStreamType.Audio, 1);
+ }
+ }
+
+ private int? GetMediaStreamCount(MediaStreamType type, int limit)
+ {
+ var count = MediaSource.GetStreamCount(type);
+
+ if (count.HasValue)
+ {
+ count = Math.Min(count.Value, limit);
+ }
+
+ return count;
+ }
+
/// <summary>
/// Predicts the audio sample rate that will be in the output stream
/// </summary>
diff --git a/MediaBrowser.Api/Playback/TranscodingThrottler.cs b/MediaBrowser.Api/Playback/TranscodingThrottler.cs
index 19a9fe9343..58cfa086e3 100644
--- a/MediaBrowser.Api/Playback/TranscodingThrottler.cs
+++ b/MediaBrowser.Api/Playback/TranscodingThrottler.cs
@@ -1,4 +1,6 @@
-using MediaBrowser.Model.Logging;
+using MediaBrowser.Common.Configuration;
+using MediaBrowser.Model.Configuration;
+using MediaBrowser.Model.Logging;
using System;
using System.IO;
using System.Threading;
@@ -11,13 +13,18 @@ namespace MediaBrowser.Api.Playback
private readonly ILogger _logger;
private Timer _timer;
private bool _isPaused;
+ private readonly IConfigurationManager _config;
- private readonly long _gapLengthInTicks = TimeSpan.FromMinutes(2).Ticks;
-
- public TranscodingThrottler(TranscodingJob job, ILogger logger)
+ public TranscodingThrottler(TranscodingJob job, ILogger logger, IConfigurationManager config)
{
_job = job;
_logger = logger;
+ _config = config;
+ }
+
+ private EncodingOptions GetOptions()
+ {
+ return _config.GetConfiguration<EncodingOptions>("encoding");
}
public void Start()
@@ -33,7 +40,9 @@ namespace MediaBrowser.Api.Playback
return;
}
- if (IsThrottleAllowed(_job))
+ var options = GetOptions();
+
+ if (options.EnableThrottling && IsThrottleAllowed(_job, options.ThrottleThresholdSeconds))
{
PauseTranscoding();
}
@@ -79,19 +88,20 @@ namespace MediaBrowser.Api.Playback
}
}
- private bool IsThrottleAllowed(TranscodingJob job)
+ private bool IsThrottleAllowed(TranscodingJob job, int thresholdSeconds)
{
var bytesDownloaded = job.BytesDownloaded ?? 0;
var transcodingPositionTicks = job.TranscodingPositionTicks ?? 0;
var downloadPositionTicks = job.DownloadPositionTicks ?? 0;
var path = job.Path;
+ var gapLengthInTicks = TimeSpan.FromSeconds(thresholdSeconds).Ticks;
if (downloadPositionTicks > 0 && transcodingPositionTicks > 0)
{
// HLS - time-based consideration
- var targetGap = _gapLengthInTicks;
+ var targetGap = gapLengthInTicks;
var gap = transcodingPositionTicks - downloadPositionTicks;
if (gap < targetGap)
@@ -113,7 +123,7 @@ namespace MediaBrowser.Api.Playback
var bytesTranscoded = job.BytesTranscoded ?? new FileInfo(path).Length;
// Estimate the bytes the transcoder should be ahead
- double gapFactor = _gapLengthInTicks;
+ double gapFactor = gapLengthInTicks;
gapFactor /= transcodingPositionTicks;
var targetGap = bytesTranscoded * gapFactor;