From a8296cba37357a476b279bccd8d085ce123c600a Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 6 Mar 2016 23:56:45 -0500 Subject: [PATCH] update recording stop --- .../Playback/BaseStreamingService.cs | 11 ++++++ MediaBrowser.Model/Dlna/StreamBuilder.cs | 19 +++++++++- MediaBrowser.Model/Dlna/StreamInfo.cs | 3 +- .../Session/PlaybackStopInfo.cs | 9 ++--- .../LiveTv/EmbyTV/EncodedRecorder.cs | 28 +++++++++------ .../LiveTv/LiveTvManager.cs | 9 +++-- .../Session/SessionManager.cs | 36 ++++++++++--------- Nuget/MediaBrowser.Common.Internal.nuspec | 4 +-- Nuget/MediaBrowser.Common.nuspec | 2 +- Nuget/MediaBrowser.Model.Signed.nuspec | 2 +- Nuget/MediaBrowser.Server.Core.nuspec | 4 +-- 11 files changed, 86 insertions(+), 41 deletions(-) diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index f66363da67..4db70df9c0 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -1482,6 +1482,17 @@ namespace MediaBrowser.Api.Playback videoRequest.CopyTimestamps = string.Equals("true", val, StringComparison.OrdinalIgnoreCase); } } + else if (i == 25) + { + if (!string.IsNullOrWhiteSpace(val) && videoRequest != null) + { + SubtitleDeliveryMethod method; + if (Enum.TryParse(val, out method)) + { + videoRequest.SubtitleMethod = method; + } + } + } } } diff --git a/MediaBrowser.Model/Dlna/StreamBuilder.cs b/MediaBrowser.Model/Dlna/StreamBuilder.cs index 7d7360759c..665da030d4 100644 --- a/MediaBrowser.Model/Dlna/StreamBuilder.cs +++ b/MediaBrowser.Model/Dlna/StreamBuilder.cs @@ -423,7 +423,24 @@ namespace MediaBrowser.Model.Dlna playlistItem.Container = transcodingProfile.Container; playlistItem.EstimateContentLength = transcodingProfile.EstimateContentLength; playlistItem.TranscodeSeekInfo = transcodingProfile.TranscodeSeekInfo; - playlistItem.AudioCodec = transcodingProfile.AudioCodec.Split(',')[0]; + + // TODO: We should probably preserve the full list and sent it tp the server that way + string[] supportedAudioCodecs = transcodingProfile.AudioCodec.Split(','); + string inputAudioCodec = audioStream == null ? null : audioStream.Codec; + foreach (string supportedAudioCodec in supportedAudioCodecs) + { + if (StringHelper.EqualsIgnoreCase(supportedAudioCodec, inputAudioCodec)) + { + playlistItem.AudioCodec = supportedAudioCodec; + break; + } + } + + if (string.IsNullOrEmpty(playlistItem.AudioCodec)) + { + playlistItem.AudioCodec = supportedAudioCodecs[0]; + } + playlistItem.VideoCodec = transcodingProfile.VideoCodec; playlistItem.CopyTimestamps = transcodingProfile.CopyTimestamps; playlistItem.SubProtocol = transcodingProfile.Protocol; diff --git a/MediaBrowser.Model/Dlna/StreamInfo.cs b/MediaBrowser.Model/Dlna/StreamInfo.cs index 79ee1b5c58..69733cefbc 100644 --- a/MediaBrowser.Model/Dlna/StreamInfo.cs +++ b/MediaBrowser.Model/Dlna/StreamInfo.cs @@ -234,7 +234,8 @@ namespace MediaBrowser.Model.Dlna } list.Add(new NameValuePair("CopyTimestamps", (item.CopyTimestamps).ToString().ToLower())); - + list.Add(new NameValuePair("SubtitleMethod", item.SubtitleStreamIndex.HasValue && item.SubtitleDeliveryMethod != SubtitleDeliveryMethod.External ? item.SubtitleDeliveryMethod.ToString() : string.Empty)); + return list; } diff --git a/MediaBrowser.Model/Session/PlaybackStopInfo.cs b/MediaBrowser.Model/Session/PlaybackStopInfo.cs index 80d719f037..3b4ac36a74 100644 --- a/MediaBrowser.Model/Session/PlaybackStopInfo.cs +++ b/MediaBrowser.Model/Session/PlaybackStopInfo.cs @@ -12,25 +12,21 @@ namespace MediaBrowser.Model.Session /// /// The item. public BaseItemInfo Item { get; set; } - /// /// Gets or sets the item identifier. /// /// The item identifier. public string ItemId { get; set; } - /// /// Gets or sets the session id. /// /// The session id. public string SessionId { get; set; } - /// /// Gets or sets the media version identifier. /// /// The media version identifier. public string MediaSourceId { get; set; } - /// /// Gets or sets the position ticks. /// @@ -46,5 +42,10 @@ namespace MediaBrowser.Model.Session /// /// The play session identifier. public string PlaySessionId { get; set; } + /// + /// Gets or sets a value indicating whether this is failed. + /// + /// true if failed; otherwise, false. + public bool Failed { get; set; } } } \ No newline at end of file diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs index 62c9cd171e..69cc8ebf7e 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 _taskCompletionSource = new TaskCompletionSource(); 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 abb2710e72..bb522082aa 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 08953b0be5..824e5e0e8a 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 OnPlaybackStopped(Guid userId, string userDataKey, BaseItem item, long? positionTicks) + private async Task 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; } diff --git a/Nuget/MediaBrowser.Common.Internal.nuspec b/Nuget/MediaBrowser.Common.Internal.nuspec index 0bb8c830fe..259eb6f896 100644 --- a/Nuget/MediaBrowser.Common.Internal.nuspec +++ b/Nuget/MediaBrowser.Common.Internal.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common.Internal - 3.0.642 + 3.0.643 MediaBrowser.Common.Internal Luke ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains common components shared by Emby Theater and Emby Server. Not intended for plugin developer consumption. Copyright © Emby 2013 - + diff --git a/Nuget/MediaBrowser.Common.nuspec b/Nuget/MediaBrowser.Common.nuspec index a290a424a4..d1cb66cbb5 100644 --- a/Nuget/MediaBrowser.Common.nuspec +++ b/Nuget/MediaBrowser.Common.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common - 3.0.642 + 3.0.643 MediaBrowser.Common Emby Team ebr,Luke,scottisafool diff --git a/Nuget/MediaBrowser.Model.Signed.nuspec b/Nuget/MediaBrowser.Model.Signed.nuspec index 2017cc1ae5..056359ae4e 100644 --- a/Nuget/MediaBrowser.Model.Signed.nuspec +++ b/Nuget/MediaBrowser.Model.Signed.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Model.Signed - 3.0.642 + 3.0.643 MediaBrowser.Model - Signed Edition Emby Team ebr,Luke,scottisafool diff --git a/Nuget/MediaBrowser.Server.Core.nuspec b/Nuget/MediaBrowser.Server.Core.nuspec index 36c9ff4153..6737a432f2 100644 --- a/Nuget/MediaBrowser.Server.Core.nuspec +++ b/Nuget/MediaBrowser.Server.Core.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Server.Core - 3.0.642 + 3.0.643 Media Browser.Server.Core Emby Team ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains core components required to build plugins for Emby Server. Copyright © Emby 2013 - +