aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2016-03-06 23:56:45 -0500
committerLuke Pulverenti <luke.pulverenti@gmail.com>2016-03-06 23:56:45 -0500
commita8296cba37357a476b279bccd8d085ce123c600a (patch)
tree6e147ecd0e875a13d5fc244e70a2f66b9bd29417 /MediaBrowser.Server.Implementations
parentf7e9e9f7a5da3c5fcd0e52d53c9e0daabae8b8ef (diff)
update recording stop
Diffstat (limited to 'MediaBrowser.Server.Implementations')
-rw-r--r--MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs28
-rw-r--r--MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs9
-rw-r--r--MediaBrowser.Server.Implementations/Session/SessionManager.cs36
3 files changed, 44 insertions, 29 deletions
diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs
index 62c9cd171..69cc8ebf7 100644
--- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs
+++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs
@@ -28,6 +28,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
private string _targetPath;
private Process _process;
private readonly IJsonSerializer _json;
+ private readonly TaskCompletionSource<bool> _taskCompletionSource = new TaskCompletionSource<bool>();
public EncodedRecorder(ILogger logger, IFileSystem fileSystem, IMediaEncoder mediaEncoder, IApplicationPaths appPaths, IJsonSerializer json)
{
@@ -93,11 +94,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
// Important - don't await the log task or we won't be able to kill ffmpeg when the user stops playback
StartStreamingLog(process.StandardError.BaseStream, _logFileStream);
- // Wait for the file to exist before proceeeding
- while (!_hasExited)
- {
- await Task.Delay(100, cancellationToken).ConfigureAwait(false);
- }
+ await _taskCompletionSource.Task.ConfigureAwait(false);
}
private string GetCommandLineArgs(MediaSourceInfo mediaSource, string targetFile, TimeSpan duration)
@@ -197,16 +194,27 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
{
_hasExited = true;
- _logger.Debug("Disposing stream resources");
DisposeLogStream();
try
{
- _logger.Info("FFMpeg exited with code {0}", process.ExitCode);
+ var exitCode = process.ExitCode;
+
+ _logger.Info("FFMpeg recording exited with code {0} for {1}", exitCode, _targetPath);
+
+ if (exitCode == 0)
+ {
+ _taskCompletionSource.TrySetResult(true);
+ }
+ else
+ {
+ _taskCompletionSource.TrySetException(new Exception(string.Format("Recording for {0} failed. Exit code {1}", _targetPath, exitCode)));
+ }
}
catch
{
- _logger.Error("FFMpeg exited with an error.");
+ _logger.Error("FFMpeg recording exited with an error for {0}.", _targetPath);
+ _taskCompletionSource.TrySetException(new Exception(string.Format("Recording for {0} failed", _targetPath)));
}
}
@@ -220,7 +228,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
}
catch (Exception ex)
{
- _logger.ErrorException("Error disposing log stream", ex);
+ _logger.ErrorException("Error disposing recording log stream", ex);
}
_logFileStream = null;
@@ -250,7 +258,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
}
catch (Exception ex)
{
- _logger.ErrorException("Error reading ffmpeg log", ex);
+ _logger.ErrorException("Error reading ffmpeg recording log", ex);
}
}
}
diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs
index abb2710e7..bb522082a 100644
--- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs
+++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs
@@ -865,10 +865,13 @@ namespace MediaBrowser.Server.Implementations.LiveTv
await _libraryManager.UpdateItem(item, ItemUpdateType.MetadataImport, cancellationToken).ConfigureAwait(false);
}
- _providerManager.QueueRefresh(item.Id, new MetadataRefreshOptions(_fileSystem)
+ if (info.Status != RecordingStatus.InProgress)
{
- MetadataRefreshMode = metadataRefreshMode
- });
+ _providerManager.QueueRefresh(item.Id, new MetadataRefreshOptions(_fileSystem)
+ {
+ MetadataRefreshMode = metadataRefreshMode
+ });
+ }
return item.Id;
}
diff --git a/MediaBrowser.Server.Implementations/Session/SessionManager.cs b/MediaBrowser.Server.Implementations/Session/SessionManager.cs
index 08953b0be..824e5e0e8 100644
--- a/MediaBrowser.Server.Implementations/Session/SessionManager.cs
+++ b/MediaBrowser.Server.Implementations/Session/SessionManager.cs
@@ -813,7 +813,7 @@ namespace MediaBrowser.Server.Implementations.Session
foreach (var user in users)
{
- playedToCompletion = await OnPlaybackStopped(user.Id, key, libraryItem, info.PositionTicks).ConfigureAwait(false);
+ playedToCompletion = await OnPlaybackStopped(user.Id, key, libraryItem, info.PositionTicks, info.Failed).ConfigureAwait(false);
}
}
@@ -846,25 +846,29 @@ namespace MediaBrowser.Server.Implementations.Session
await SendPlaybackStoppedNotification(session, CancellationToken.None).ConfigureAwait(false);
}
- private async Task<bool> OnPlaybackStopped(Guid userId, string userDataKey, BaseItem item, long? positionTicks)
+ private async Task<bool> OnPlaybackStopped(Guid userId, string userDataKey, BaseItem item, long? positionTicks, bool playbackFailed)
{
- var data = _userDataRepository.GetUserData(userId, userDataKey);
- bool playedToCompletion;
+ bool playedToCompletion = false;
- if (positionTicks.HasValue)
+ if (!playbackFailed)
{
- playedToCompletion = _userDataRepository.UpdatePlayState(item, data, positionTicks.Value);
- }
- else
- {
- // If the client isn't able to report this, then we'll just have to make an assumption
- data.PlayCount++;
- data.Played = true;
- data.PlaybackPositionTicks = 0;
- playedToCompletion = true;
- }
+ var data = _userDataRepository.GetUserData(userId, userDataKey);
+
+ if (positionTicks.HasValue)
+ {
+ playedToCompletion = _userDataRepository.UpdatePlayState(item, data, positionTicks.Value);
+ }
+ else
+ {
+ // If the client isn't able to report this, then we'll just have to make an assumption
+ data.PlayCount++;
+ data.Played = true;
+ data.PlaybackPositionTicks = 0;
+ playedToCompletion = true;
+ }
- await _userDataRepository.SaveUserData(userId, item, data, UserDataSaveReason.PlaybackFinished, CancellationToken.None).ConfigureAwait(false);
+ await _userDataRepository.SaveUserData(userId, item, data, UserDataSaveReason.PlaybackFinished, CancellationToken.None).ConfigureAwait(false);
+ }
return playedToCompletion;
}