aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Api')
-rw-r--r--MediaBrowser.Api/ApiEntryPoint.cs58
-rw-r--r--MediaBrowser.Api/ConfigurationService.cs2
-rw-r--r--MediaBrowser.Api/LiveTv/LiveTvService.cs10
-rw-r--r--MediaBrowser.Api/Playback/Dash/MpegDashService.cs14
-rw-r--r--MediaBrowser.Api/Playback/Hls/BaseHlsService.cs17
-rw-r--r--MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs3
-rw-r--r--MediaBrowser.Api/Playback/TranscodingThrottler.cs2
-rw-r--r--MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs3
-rw-r--r--MediaBrowser.Api/UserLibrary/PlaystateService.cs10
9 files changed, 87 insertions, 32 deletions
diff --git a/MediaBrowser.Api/ApiEntryPoint.cs b/MediaBrowser.Api/ApiEntryPoint.cs
index 08ac5671d5..ed5fa5bfd7 100644
--- a/MediaBrowser.Api/ApiEntryPoint.cs
+++ b/MediaBrowser.Api/ApiEntryPoint.cs
@@ -286,27 +286,65 @@ namespace MediaBrowser.Api
job.DisposeKillTimer();
}
-
+
public void OnTranscodeEndRequest(TranscodingJob job)
{
job.ActiveRequestCount--;
if (job.ActiveRequestCount == 0)
{
- // TODO: Lower this hls timeout
- var timerDuration = job.Type == TranscodingJobType.Progressive ?
- 1000 :
- 7200000;
+ PingTimer(job, true);
+ }
+ }
+ internal void PingTranscodingJob(string deviceId, string playSessionId)
+ {
+ if (string.IsNullOrEmpty(deviceId))
+ {
+ throw new ArgumentNullException("deviceId");
+ }
- if (job.KillTimer == null)
+ var jobs = new List<TranscodingJob>();
+
+ lock (_activeTranscodingJobs)
+ {
+ // This is really only needed for HLS.
+ // Progressive streams can stop on their own reliably
+ jobs = jobs.Where(j =>
{
- job.KillTimer = new Timer(OnTranscodeKillTimerStopped, job, timerDuration, Timeout.Infinite);
- }
- else
+ if (string.Equals(deviceId, j.DeviceId, StringComparison.OrdinalIgnoreCase))
+ {
+ return string.Equals(playSessionId, j.PlaySessionId, StringComparison.OrdinalIgnoreCase);
+ }
+
+ return false;
+
+ }).ToList();
+ }
+
+ foreach (var job in jobs)
+ {
+ PingTimer(job, false);
+ }
+ }
+
+ private void PingTimer(TranscodingJob job, bool startTimerIfNeeded)
+ {
+ // TODO: Lower this hls timeout
+ var timerDuration = job.Type == TranscodingJobType.Progressive ?
+ 1000 :
+ 1800000;
+
+ if (job.KillTimer == null)
+ {
+ if (startTimerIfNeeded)
{
- job.KillTimer.Change(timerDuration, Timeout.Infinite);
+ job.KillTimer = new Timer(OnTranscodeKillTimerStopped, job, timerDuration, Timeout.Infinite);
}
}
+ else
+ {
+ job.KillTimer.Change(timerDuration, Timeout.Infinite);
+ }
}
/// <summary>
diff --git a/MediaBrowser.Api/ConfigurationService.cs b/MediaBrowser.Api/ConfigurationService.cs
index d0abd18c28..9f6c07dd21 100644
--- a/MediaBrowser.Api/ConfigurationService.cs
+++ b/MediaBrowser.Api/ConfigurationService.cs
@@ -123,7 +123,7 @@ namespace MediaBrowser.Api
public void Post(AutoSetMetadataOptions request)
{
- _configurationManager.DisableMetadataService("Media Browser Xml");
+ _configurationManager.DisableMetadataService("Emby Xml");
_configurationManager.SaveConfiguration();
}
diff --git a/MediaBrowser.Api/LiveTv/LiveTvService.cs b/MediaBrowser.Api/LiveTv/LiveTvService.cs
index 24c91e172f..bb6f74f364 100644
--- a/MediaBrowser.Api/LiveTv/LiveTvService.cs
+++ b/MediaBrowser.Api/LiveTv/LiveTvService.cs
@@ -186,6 +186,9 @@ namespace MediaBrowser.Api.LiveTv
[ApiMember(Name = "IsMovie", Description = "Optional filter for movies.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET,POST")]
public bool? IsMovie { get; set; }
+ [ApiMember(Name = "IsSports", Description = "Optional filter for sports.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET,POST")]
+ public bool? IsSports { get; set; }
+
[ApiMember(Name = "StartIndex", Description = "Optional. The record index to start at. All items with a lower index will be dropped from the results.", IsRequired = false, DataType = "int", ParameterType = "query", Verb = "GET")]
public int? StartIndex { get; set; }
@@ -218,6 +221,9 @@ namespace MediaBrowser.Api.LiveTv
[ApiMember(Name = "HasAired", Description = "Optional. Filter by programs that have completed airing, or not.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
public bool? HasAired { get; set; }
+ [ApiMember(Name = "IsSports", Description = "Optional filter for sports.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET,POST")]
+ public bool? IsSports { get; set; }
+
[ApiMember(Name = "IsMovie", Description = "Optional filter for movies.", IsRequired = false, DataType = "bool", ParameterType = "query", Verb = "GET")]
public bool? IsMovie { get; set; }
}
@@ -422,6 +428,7 @@ namespace MediaBrowser.Api.LiveTv
query.SortBy = (request.SortBy ?? String.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
query.SortOrder = request.SortOrder;
query.IsMovie = request.IsMovie;
+ query.IsSports = request.IsSports;
query.Genres = (request.Genres ?? String.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
var result = await _liveTvManager.GetPrograms(query, CancellationToken.None).ConfigureAwait(false);
@@ -437,7 +444,8 @@ namespace MediaBrowser.Api.LiveTv
IsAiring = request.IsAiring,
Limit = request.Limit,
HasAired = request.HasAired,
- IsMovie = request.IsMovie
+ IsMovie = request.IsMovie,
+ IsSports = request.IsSports
};
var result = await _liveTvManager.GetRecommendedPrograms(query, CancellationToken.None).ConfigureAwait(false);
diff --git a/MediaBrowser.Api/Playback/Dash/MpegDashService.cs b/MediaBrowser.Api/Playback/Dash/MpegDashService.cs
index ba3f172579..0692c4863e 100644
--- a/MediaBrowser.Api/Playback/Dash/MpegDashService.cs
+++ b/MediaBrowser.Api/Playback/Dash/MpegDashService.cs
@@ -5,7 +5,6 @@ using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Devices;
using MediaBrowser.Controller.Dlna;
using MediaBrowser.Controller.Library;
-using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.IO;
@@ -518,25 +517,14 @@ namespace MediaBrowser.Api.Playback.Dash
private async Task WaitForSegment(string playlist, string segment, CancellationToken cancellationToken)
{
- var tmpPath = playlist + ".tmp";
-
var segmentFilename = Path.GetFileName(segment);
Logger.Debug("Waiting for {0} in {1}", segmentFilename, playlist);
while (true)
{
- FileStream fileStream;
- try
- {
- fileStream = FileSystem.GetFileStream(tmpPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, true);
- }
- catch (IOException)
- {
- fileStream = FileSystem.GetFileStream(playlist, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, true);
- }
// Need to use FileShare.ReadWrite because we're reading the file at the same time it's being written
- using (fileStream)
+ using (var fileStream = GetPlaylistFileStream(playlist))
{
using (var reader = new StreamReader(fileStream))
{
diff --git a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs
index 207bc2f679..701516b48c 100644
--- a/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs
+++ b/MediaBrowser.Api/Playback/Hls/BaseHlsService.cs
@@ -3,7 +3,6 @@ using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Devices;
using MediaBrowser.Controller.Dlna;
using MediaBrowser.Controller.Library;
-using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.IO;
@@ -186,7 +185,7 @@ namespace MediaBrowser.Api.Playback.Hls
while (true)
{
// Need to use FileShare.ReadWrite because we're reading the file at the same time it's being written
- using (var fileStream = FileSystem.GetFileStream(playlist, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, true))
+ using (var fileStream = GetPlaylistFileStream(playlist))
{
using (var reader = new StreamReader(fileStream))
{
@@ -212,6 +211,20 @@ namespace MediaBrowser.Api.Playback.Hls
}
}
+ protected Stream GetPlaylistFileStream(string path)
+ {
+ var tmpPath = path + ".tmp";
+
+ try
+ {
+ return FileSystem.GetFileStream(tmpPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, true);
+ }
+ catch (IOException)
+ {
+ return FileSystem.GetFileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, true);
+ }
+ }
+
protected override string GetCommandLineArguments(string outputPath, StreamState state, bool isEncoding)
{
var hlsVideoRequest = state.VideoRequest as GetHlsVideoStream;
diff --git a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs
index cbfadb886d..98d6c9a760 100644
--- a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs
+++ b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs
@@ -4,7 +4,6 @@ using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Devices;
using MediaBrowser.Controller.Dlna;
using MediaBrowser.Controller.Library;
-using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Dlna;
@@ -300,7 +299,7 @@ namespace MediaBrowser.Api.Playback.Hls
var segmentFilename = Path.GetFileName(segmentPath);
- using (var fileStream = FileSystem.GetFileStream(playlistPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite, true))
+ using (var fileStream = GetPlaylistFileStream(playlistPath))
{
using (var reader = new StreamReader(fileStream))
{
diff --git a/MediaBrowser.Api/Playback/TranscodingThrottler.cs b/MediaBrowser.Api/Playback/TranscodingThrottler.cs
index 58cfa086e3..ff79bb48f4 100644
--- a/MediaBrowser.Api/Playback/TranscodingThrottler.cs
+++ b/MediaBrowser.Api/Playback/TranscodingThrottler.cs
@@ -42,7 +42,7 @@ namespace MediaBrowser.Api.Playback
var options = GetOptions();
- if (options.EnableThrottling && IsThrottleAllowed(_job, options.ThrottleThresholdSeconds))
+ if (/*options.EnableThrottling &&*/ IsThrottleAllowed(_job, options.ThrottleThresholdSeconds))
{
PauseTranscoding();
}
diff --git a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs
index 609c1048f2..b2364ce3c6 100644
--- a/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs
+++ b/MediaBrowser.Api/UserLibrary/BaseItemsByNameService.cs
@@ -142,7 +142,7 @@ namespace MediaBrowser.Api.UserLibrary
}
IEnumerable<Tuple<TItemType, List<BaseItem>>> tuples;
- if (dtoOptions.Fields.Contains(ItemFields.ItemCounts) || true)
+ if (dtoOptions.Fields.Contains(ItemFields.ItemCounts))
{
tuples = ibnItems.Select(i => new Tuple<TItemType, List<BaseItem>>(i, i.GetTaggedItems(libraryItems).ToList()));
}
@@ -177,7 +177,6 @@ namespace MediaBrowser.Api.UserLibrary
return true;
}
- return true;
return options.Fields.Contains(ItemFields.ItemCounts);
}
diff --git a/MediaBrowser.Api/UserLibrary/PlaystateService.cs b/MediaBrowser.Api/UserLibrary/PlaystateService.cs
index 55e1681e0d..6c767596ea 100644
--- a/MediaBrowser.Api/UserLibrary/PlaystateService.cs
+++ b/MediaBrowser.Api/UserLibrary/PlaystateService.cs
@@ -294,6 +294,11 @@ namespace MediaBrowser.Api.UserLibrary
public void Post(ReportPlaybackProgress request)
{
+ if (!string.IsNullOrWhiteSpace(request.PlaySessionId))
+ {
+ ApiEntryPoint.Instance.PingTranscodingJob(AuthorizationContext.GetAuthorizationInfo(Request).DeviceId, request.PlaySessionId);
+ }
+
request.SessionId = GetSession().Result.Id;
var task = _sessionManager.OnPlaybackProgress(request);
@@ -317,6 +322,11 @@ namespace MediaBrowser.Api.UserLibrary
public void Post(ReportPlaybackStopped request)
{
+ if (!string.IsNullOrWhiteSpace(request.PlaySessionId))
+ {
+ ApiEntryPoint.Instance.KillTranscodingJobs(AuthorizationContext.GetAuthorizationInfo(Request).DeviceId, request.PlaySessionId, s => true);
+ }
+
request.SessionId = GetSession().Result.Id;
var task = _sessionManager.OnPlaybackStopped(request);