aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api
diff options
context:
space:
mode:
Diffstat (limited to 'MediaBrowser.Api')
-rw-r--r--MediaBrowser.Api/ApiEntryPoint.cs23
-rw-r--r--MediaBrowser.Api/Playback/Progressive/ProgressiveStreamWriter.cs40
-rw-r--r--MediaBrowser.Api/Reports/ReportsService.cs33
-rw-r--r--MediaBrowser.Api/UserLibrary/ItemsService.cs33
-rw-r--r--MediaBrowser.Api/UserLibrary/PlaystateService.cs7
5 files changed, 71 insertions, 65 deletions
diff --git a/MediaBrowser.Api/ApiEntryPoint.cs b/MediaBrowser.Api/ApiEntryPoint.cs
index 55f191f1a3..117ff2305d 100644
--- a/MediaBrowser.Api/ApiEntryPoint.cs
+++ b/MediaBrowser.Api/ApiEntryPoint.cs
@@ -63,6 +63,15 @@ namespace MediaBrowser.Api
_mediaSourceManager = mediaSourceManager;
Instance = this;
+ _sessionManager.PlaybackProgress += _sessionManager_PlaybackProgress;
+ }
+
+ void _sessionManager_PlaybackProgress(object sender, PlaybackProgressEventArgs e)
+ {
+ if (!string.IsNullOrWhiteSpace(e.PlaySessionId))
+ {
+ PingTranscodingJob(e.PlaySessionId, e.IsPaused);
+ }
}
/// <summary>
@@ -300,26 +309,31 @@ namespace MediaBrowser.Api
PingTimer(job, false);
}
}
- internal void PingTranscodingJob(string playSessionId)
+ internal void PingTranscodingJob(string playSessionId, bool? isUserPaused)
{
if (string.IsNullOrEmpty(playSessionId))
{
throw new ArgumentNullException("playSessionId");
}
- //Logger.Debug("PingTranscodingJob PlaySessionId={0}", playSessionId);
+ //Logger.Debug("PingTranscodingJob PlaySessionId={0} isUsedPaused: {1}", playSessionId, isUserPaused);
- var jobs = new List<TranscodingJob>();
+ List<TranscodingJob> jobs;
lock (_activeTranscodingJobs)
{
// This is really only needed for HLS.
// Progressive streams can stop on their own reliably
- jobs = jobs.Where(j => string.Equals(playSessionId, j.PlaySessionId, StringComparison.OrdinalIgnoreCase)).ToList();
+ jobs = _activeTranscodingJobs.Where(j => string.Equals(playSessionId, j.PlaySessionId, StringComparison.OrdinalIgnoreCase)).ToList();
}
foreach (var job in jobs)
{
+ if (isUserPaused.HasValue)
+ {
+ //Logger.Debug("Setting job.IsUserPaused to {0}. jobId: {1}", isUserPaused, job.Id);
+ job.IsUserPaused = isUserPaused.Value;
+ }
PingTimer(job, true);
}
}
@@ -655,6 +669,7 @@ namespace MediaBrowser.Api
public object ProcessLock = new object();
public bool HasExited { get; set; }
+ public bool IsUserPaused { get; set; }
public string Id { get; set; }
diff --git a/MediaBrowser.Api/Playback/Progressive/ProgressiveStreamWriter.cs b/MediaBrowser.Api/Playback/Progressive/ProgressiveStreamWriter.cs
index 2719b1faf5..f766f46b1f 100644
--- a/MediaBrowser.Api/Playback/Progressive/ProgressiveStreamWriter.cs
+++ b/MediaBrowser.Api/Playback/Progressive/ProgressiveStreamWriter.cs
@@ -61,8 +61,9 @@ namespace MediaBrowser.Api.Playback.Progressive
{
try
{
- new ProgressiveFileCopier(_fileSystem, _job)
- .StreamFile(Path, responseStream);
+ var task = new ProgressiveFileCopier(_fileSystem, _job, Logger).StreamFile(Path, responseStream);
+
+ Task.WaitAll(task);
}
catch (IOException)
{
@@ -91,19 +92,21 @@ namespace MediaBrowser.Api.Playback.Progressive
{
private readonly IFileSystem _fileSystem;
private readonly TranscodingJob _job;
+ private readonly ILogger _logger;
// 256k
private const int BufferSize = 262144;
-
+
private long _bytesWritten = 0;
- public ProgressiveFileCopier(IFileSystem fileSystem, TranscodingJob job)
+ public ProgressiveFileCopier(IFileSystem fileSystem, TranscodingJob job, ILogger logger)
{
_fileSystem = fileSystem;
_job = job;
+ _logger = logger;
}
- public void StreamFile(string path, Stream outputStream)
+ public async Task StreamFile(string path, Stream outputStream)
{
var eofCount = 0;
long position = 0;
@@ -126,8 +129,7 @@ namespace MediaBrowser.Api.Playback.Progressive
{
eofCount++;
}
- var task = Task.Delay(100);
- Task.WaitAll(task);
+ await Task.Delay(100).ConfigureAwait(false);
}
else
{
@@ -145,6 +147,30 @@ namespace MediaBrowser.Api.Playback.Progressive
int count;
while ((count = source.Read(array, 0, array.Length)) != 0)
{
+ //if (_job != null)
+ //{
+ // var didPause = false;
+ // var totalPauseTime = 0;
+
+ // if (_job.IsUserPaused)
+ // {
+ // _logger.Debug("Pausing writing to network stream while user has paused playback.");
+
+ // while (_job.IsUserPaused && totalPauseTime < 30000)
+ // {
+ // didPause = true;
+ // var pauseTime = 500;
+ // totalPauseTime += pauseTime;
+ // await Task.Delay(pauseTime).ConfigureAwait(false);
+ // }
+ // }
+
+ // if (didPause)
+ // {
+ // _logger.Debug("Resuming writing to network stream due to user unpausing playback.");
+ // }
+ //}
+
destination.Write(array, 0, count);
_bytesWritten += count;
diff --git a/MediaBrowser.Api/Reports/ReportsService.cs b/MediaBrowser.Api/Reports/ReportsService.cs
index 15bdf4be62..ae6fbc9e24 100644
--- a/MediaBrowser.Api/Reports/ReportsService.cs
+++ b/MediaBrowser.Api/Reports/ReportsService.cs
@@ -213,8 +213,6 @@ namespace MediaBrowser.Api.Reports
SortBy = request.GetOrderBy(),
SortOrder = request.SortOrder ?? SortOrder.Ascending,
- Filter = i => ApplyAdditionalFilters(request, i, user, _libraryManager),
-
IsFavorite = request.IsFavorite,
Limit = request.Limit,
StartIndex = request.StartIndex,
@@ -351,6 +349,15 @@ namespace MediaBrowser.Api.Reports
}
// Artists
+ if (!string.IsNullOrEmpty(request.ArtistIds))
+ {
+ var artistIds = request.ArtistIds.Split(new[] { '|', ',' });
+
+ var artistItems = artistIds.Select(_libraryManager.GetItemById).Where(i => i != null).ToList();
+ query.ArtistNames = artistItems.Select(i => i.Name).ToArray();
+ }
+
+ // Artists
if (!string.IsNullOrEmpty(request.Artists))
{
query.ArtistNames = request.Artists.Split('|');
@@ -371,28 +378,6 @@ namespace MediaBrowser.Api.Reports
return query;
}
- private bool ApplyAdditionalFilters(BaseReportRequest request, BaseItem i, User user, ILibraryManager libraryManager)
- {
- // Artists
- if (!string.IsNullOrEmpty(request.ArtistIds))
- {
- var artistIds = request.ArtistIds.Split(new[] { '|', ',' });
-
- var audio = i as IHasArtist;
-
- if (!(audio != null && artistIds.Any(id =>
- {
- var artistItem = libraryManager.GetItemById(id);
- return artistItem != null && audio.HasAnyArtist(artistItem.Name);
- })))
- {
- return false;
- }
- }
-
- return true;
- }
-
/// <summary> Gets query result. </summary>
/// <param name="request"> The request. </param>
/// <returns> The query result. </returns>
diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs
index 566b1dfd5c..ea7e16e8d6 100644
--- a/MediaBrowser.Api/UserLibrary/ItemsService.cs
+++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs
@@ -184,8 +184,6 @@ namespace MediaBrowser.Api.UserLibrary
SortBy = request.GetOrderBy(),
SortOrder = request.SortOrder ?? SortOrder.Ascending,
- Filter = i => ApplyAdditionalFilters(request, i, user, _libraryManager),
-
IsFavorite = request.IsFavorite,
Limit = request.Limit,
StartIndex = request.StartIndex,
@@ -324,6 +322,15 @@ namespace MediaBrowser.Api.UserLibrary
}
// Artists
+ if (!string.IsNullOrEmpty(request.ArtistIds))
+ {
+ var artistIds = request.ArtistIds.Split(new[] { '|', ',' });
+
+ var artistItems = artistIds.Select(_libraryManager.GetItemById).Where(i => i != null).ToList();
+ query.ArtistNames = artistItems.Select(i => i.Name).ToArray();
+ }
+
+ // Artists
if (!string.IsNullOrEmpty(request.Artists))
{
query.ArtistNames = request.Artists.Split('|');
@@ -337,28 +344,6 @@ namespace MediaBrowser.Api.UserLibrary
return query;
}
-
- private bool ApplyAdditionalFilters(GetItems request, BaseItem i, User user, ILibraryManager libraryManager)
- {
- // Artists
- if (!string.IsNullOrEmpty(request.ArtistIds))
- {
- var artistIds = request.ArtistIds.Split(new[] { '|', ',' });
-
- var audio = i as IHasArtist;
-
- if (!(audio != null && artistIds.Any(id =>
- {
- var artistItem = libraryManager.GetItemById(id);
- return artistItem != null && audio.HasAnyArtist(artistItem.Name);
- })))
- {
- return false;
- }
- }
-
- return true;
- }
}
/// <summary>
diff --git a/MediaBrowser.Api/UserLibrary/PlaystateService.cs b/MediaBrowser.Api/UserLibrary/PlaystateService.cs
index 08c6b0ba47..0a96a5b06c 100644
--- a/MediaBrowser.Api/UserLibrary/PlaystateService.cs
+++ b/MediaBrowser.Api/UserLibrary/PlaystateService.cs
@@ -335,11 +335,6 @@ namespace MediaBrowser.Api.UserLibrary
public void Post(ReportPlaybackProgress request)
{
- if (!string.IsNullOrWhiteSpace(request.PlaySessionId))
- {
- ApiEntryPoint.Instance.PingTranscodingJob(request.PlaySessionId);
- }
-
request.SessionId = GetSession().Result.Id;
var task = _sessionManager.OnPlaybackProgress(request);
@@ -349,7 +344,7 @@ namespace MediaBrowser.Api.UserLibrary
public void Post(PingPlaybackSession request)
{
- ApiEntryPoint.Instance.PingTranscodingJob(request.PlaySessionId);
+ ApiEntryPoint.Instance.PingTranscodingJob(request.PlaySessionId, null);
}
/// <summary>