From 16fd474ad3e7d74cd78779350d2ee0ea7017f627 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 3 Oct 2013 10:14:40 -0400 Subject: [PATCH] safer hls kill --- MediaBrowser.Api/ApiEntryPoint.cs | 27 ++++++++++--------- .../Playback/BaseStreamingService.cs | 2 +- .../Playback/Hls/HlsSegmentService.cs | 13 +++++++++ MediaBrowser.Api/Playback/StreamRequest.cs | 3 +++ MediaBrowser.Api/UserLibrary/ItemsService.cs | 1 - .../UserLibrary/UserLibraryService.cs | 3 --- .../BaseApplicationHost.cs | 2 +- MediaBrowser.Common/IApplicationHost.cs | 7 +++++ MediaBrowser.Controller/Entities/Video.cs | 5 +--- MediaBrowser.Model/Dto/StreamOptions.cs | 6 +++++ .../Games/GameProviderFromXml.cs | 2 +- .../Games/GameSystemProviderFromXml.cs | 2 +- .../MediaInfo/FFProbeVideoInfoProvider.cs | 2 ++ .../FFMpeg/FFMpegDownloader.cs | 2 +- Nuget/MediaBrowser.Common.Internal.nuspec | 4 +-- Nuget/MediaBrowser.Common.nuspec | 2 +- Nuget/MediaBrowser.Server.Core.nuspec | 4 +-- 17 files changed, 57 insertions(+), 30 deletions(-) diff --git a/MediaBrowser.Api/ApiEntryPoint.cs b/MediaBrowser.Api/ApiEntryPoint.cs index b648e7fd3..343672877 100644 --- a/MediaBrowser.Api/ApiEntryPoint.cs +++ b/MediaBrowser.Api/ApiEntryPoint.cs @@ -85,7 +85,8 @@ namespace MediaBrowser.Api /// if set to true [is video]. /// The start time ticks. /// The source path. - public void OnTranscodeBeginning(string path, TranscodingJobType type, Process process, bool isVideo, long? startTimeTicks, string sourcePath) + /// The device id. + public void OnTranscodeBeginning(string path, TranscodingJobType type, Process process, bool isVideo, long? startTimeTicks, string sourcePath, string deviceId) { lock (_activeTranscodingJobs) { @@ -97,7 +98,8 @@ namespace MediaBrowser.Api ActiveRequestCount = 1, IsVideo = isVideo, StartTimeTicks = startTimeTicks, - SourcePath = sourcePath + SourcePath = sourcePath, + DeviceId = deviceId }); } } @@ -180,7 +182,7 @@ namespace MediaBrowser.Api if (job.ActiveRequestCount == 0) { - var timerDuration = type == TranscodingJobType.Progressive ? 1000 : 180000; + var timerDuration = type == TranscodingJobType.Progressive ? 1000 : 120000; if (job.KillTimer == null) { @@ -208,12 +210,14 @@ namespace MediaBrowser.Api /// /// Kills the single transcoding job. /// - /// The source path. - internal void KillSingleTranscodingJob(string sourcePath) + /// The device id. + /// if set to true [is video]. + /// sourcePath + internal void KillTranscodingJobs(string deviceId, bool isVideo) { - if (string.IsNullOrEmpty(sourcePath)) + if (string.IsNullOrEmpty(deviceId)) { - throw new ArgumentNullException("sourcePath"); + throw new ArgumentNullException("deviceId"); } var jobs = new List(); @@ -222,14 +226,12 @@ namespace MediaBrowser.Api { // This is really only needed for HLS. // Progressive streams can stop on their own reliably - jobs.AddRange(_activeTranscodingJobs.Where(i => string.Equals(sourcePath, i.SourcePath) && i.Type == TranscodingJobType.Hls)); + jobs.AddRange(_activeTranscodingJobs.Where(i => isVideo == i.IsVideo && string.Equals(deviceId, i.DeviceId, StringComparison.OrdinalIgnoreCase))); } - // This method of killing is a bit of a shortcut, but it saves clients from having to send a request just for that - // But we can only kill if there's one active job. If there are more we won't know which one to stop - if (jobs.Count == 1) + foreach (var job in jobs) { - KillTranscodingJob(jobs.First()); + KillTranscodingJob(job); } } @@ -405,6 +407,7 @@ namespace MediaBrowser.Api public bool IsVideo { get; set; } public long? StartTimeTicks { get; set; } public string SourcePath { get; set; } + public string DeviceId { get; set; } } /// diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index f3164ad69..1772cc547 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -624,7 +624,7 @@ namespace MediaBrowser.Api.Playback EnableRaisingEvents = true }; - ApiEntryPoint.Instance.OnTranscodeBeginning(outputPath, TranscodingJobType, process, video != null, state.Request.StartTimeTicks, state.Item.Path); + ApiEntryPoint.Instance.OnTranscodeBeginning(outputPath, TranscodingJobType, process, video != null, state.Request.StartTimeTicks, state.Item.Path, state.Request.DeviceId); Logger.Info(process.StartInfo.FileName + " " + process.StartInfo.Arguments); diff --git a/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs b/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs index f1fa86f78..be7aadec0 100644 --- a/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs +++ b/MediaBrowser.Api/Playback/Hls/HlsSegmentService.cs @@ -66,6 +66,14 @@ namespace MediaBrowser.Api.Playback.Hls public string PlaylistId { get; set; } } + [Route("/Videos", "DELETE")] + [Api(Description = "Stops an encoding process")] + public class StopEncodingProcess + { + [ApiMember(Name = "DeviceId", Description = "The device id of the client requesting. Used to stop encoding processes when needed.", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "DELETE")] + public string DeviceId { get; set; } + } + public class HlsSegmentService : BaseApiService { private readonly IServerApplicationPaths _appPaths; @@ -86,6 +94,11 @@ namespace MediaBrowser.Api.Playback.Hls return ResultFactory.GetStaticFileResult(RequestContext, file, FileShare.ReadWrite); } + public void Delete(StopEncodingProcess request) + { + ApiEntryPoint.Instance.KillTranscodingJobs(request.DeviceId, true); + } + /// /// Gets the specified request. /// diff --git a/MediaBrowser.Api/Playback/StreamRequest.cs b/MediaBrowser.Api/Playback/StreamRequest.cs index 07f9d31e9..339de0e6c 100644 --- a/MediaBrowser.Api/Playback/StreamRequest.cs +++ b/MediaBrowser.Api/Playback/StreamRequest.cs @@ -15,6 +15,9 @@ namespace MediaBrowser.Api.Playback [ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")] public string Id { get; set; } + [ApiMember(Name = "DeviceId", Description = "The device id of the client requesting. Used to stop encoding processes when needed.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "GET")] + public string DeviceId { get; set; } + /// /// Gets or sets the audio codec. /// diff --git a/MediaBrowser.Api/UserLibrary/ItemsService.cs b/MediaBrowser.Api/UserLibrary/ItemsService.cs index b588e4a85..f4976bba3 100644 --- a/MediaBrowser.Api/UserLibrary/ItemsService.cs +++ b/MediaBrowser.Api/UserLibrary/ItemsService.cs @@ -5,7 +5,6 @@ using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Localization; -using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Querying; using ServiceStack.ServiceHost; diff --git a/MediaBrowser.Api/UserLibrary/UserLibraryService.cs b/MediaBrowser.Api/UserLibrary/UserLibraryService.cs index efb1d5d43..a43ed276d 100644 --- a/MediaBrowser.Api/UserLibrary/UserLibraryService.cs +++ b/MediaBrowser.Api/UserLibrary/UserLibraryService.cs @@ -721,9 +721,6 @@ namespace MediaBrowser.Api.UserLibrary var item = _dtoService.GetItemByDtoId(request.Id, user.Id); - // Kill the encoding - ApiEntryPoint.Instance.KillSingleTranscodingJob(item.Path); - var session = GetSession(); var info = new PlaybackStopInfo diff --git a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs index 8b8e81e8a..e20258520 100644 --- a/MediaBrowser.Common.Implementations/BaseApplicationHost.cs +++ b/MediaBrowser.Common.Implementations/BaseApplicationHost.cs @@ -384,7 +384,7 @@ namespace MediaBrowser.Common.Implementations /// /// The type. /// System.Object. - protected object CreateInstance(Type type) + public object CreateInstance(Type type) { try { diff --git a/MediaBrowser.Common/IApplicationHost.cs b/MediaBrowser.Common/IApplicationHost.cs index c634871fa..177df5afa 100644 --- a/MediaBrowser.Common/IApplicationHost.cs +++ b/MediaBrowser.Common/IApplicationHost.cs @@ -125,5 +125,12 @@ namespace MediaBrowser.Common /// /// Task. Task Init(); + + /// + /// Creates the instance. + /// + /// The type. + /// System.Object. + object CreateInstance(Type type); } } diff --git a/MediaBrowser.Controller/Entities/Video.cs b/MediaBrowser.Controller/Entities/Video.cs index caf332a5b..e900dd77e 100644 --- a/MediaBrowser.Controller/Entities/Video.cs +++ b/MediaBrowser.Controller/Entities/Video.cs @@ -136,10 +136,7 @@ namespace MediaBrowser.Controller.Entities get { return Video3DFormat.HasValue; } } - public bool IsHD - { - get { return MediaStreams != null && MediaStreams.Any(i => i.Type == MediaStreamType.Video && i.Width.HasValue && i.Width.Value >= 1280); } - } + public bool IsHD { get; set; } /// /// Gets the type of the media. diff --git a/MediaBrowser.Model/Dto/StreamOptions.cs b/MediaBrowser.Model/Dto/StreamOptions.cs index 0cf59183d..17fd06cb6 100644 --- a/MediaBrowser.Model/Dto/StreamOptions.cs +++ b/MediaBrowser.Model/Dto/StreamOptions.cs @@ -151,6 +151,12 @@ /// /// The output file extension. public string OutputFileExtension { get; set; } + + /// + /// Gets or sets the device id. + /// + /// The device id. + public string DeviceId { get; set; } } /// diff --git a/MediaBrowser.Providers/Games/GameProviderFromXml.cs b/MediaBrowser.Providers/Games/GameProviderFromXml.cs index 5e498c578..f982e5658 100644 --- a/MediaBrowser.Providers/Games/GameProviderFromXml.cs +++ b/MediaBrowser.Providers/Games/GameProviderFromXml.cs @@ -92,7 +92,7 @@ namespace MediaBrowser.Providers.Games /// public override MetadataProviderPriority Priority { - get { return MetadataProviderPriority.First; } + get { return MetadataProviderPriority.Second; } } } } \ No newline at end of file diff --git a/MediaBrowser.Providers/Games/GameSystemProviderFromXml.cs b/MediaBrowser.Providers/Games/GameSystemProviderFromXml.cs index ed76d0842..526170db5 100644 --- a/MediaBrowser.Providers/Games/GameSystemProviderFromXml.cs +++ b/MediaBrowser.Providers/Games/GameSystemProviderFromXml.cs @@ -37,7 +37,7 @@ namespace MediaBrowser.Providers.Games /// The priority. public override MetadataProviderPriority Priority { - get { return MetadataProviderPriority.First; } + get { return MetadataProviderPriority.Second; } } private const string XmlFileName = "gamesystem.xml"; diff --git a/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfoProvider.cs b/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfoProvider.cs index 727768b9f..4fb65a764 100644 --- a/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfoProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfoProvider.cs @@ -323,6 +323,8 @@ namespace MediaBrowser.Providers.MediaInfo FetchWtvInfo(video, force, data); + video.IsHD = video.MediaStreams.Any(i => i.Type == MediaStreamType.Video && i.Width.HasValue && i.Width.Value >= 1270); + if (chapters.Count == 0 && video.MediaStreams.Any(i => i.Type == MediaStreamType.Video)) { AddDummyChapters(video, chapters); diff --git a/MediaBrowser.ServerApplication/FFMpeg/FFMpegDownloader.cs b/MediaBrowser.ServerApplication/FFMpeg/FFMpegDownloader.cs index 9f3d26e24..88def28db 100644 --- a/MediaBrowser.ServerApplication/FFMpeg/FFMpegDownloader.cs +++ b/MediaBrowser.ServerApplication/FFMpeg/FFMpegDownloader.cs @@ -21,7 +21,7 @@ namespace MediaBrowser.ServerApplication.FFMpeg private readonly ILogger _logger; private readonly IZipClient _zipClient; - private const string Version = "ffmpeg20130904"; + private const string Version = "ffmpeg20130904.1"; private readonly string[] _fontUrls = new[] { diff --git a/Nuget/MediaBrowser.Common.Internal.nuspec b/Nuget/MediaBrowser.Common.Internal.nuspec index 18187392a..6714bb59e 100644 --- a/Nuget/MediaBrowser.Common.Internal.nuspec +++ b/Nuget/MediaBrowser.Common.Internal.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common.Internal - 3.0.216 + 3.0.217 MediaBrowser.Common.Internal Luke ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption. Copyright © Media Browser 2013 - + diff --git a/Nuget/MediaBrowser.Common.nuspec b/Nuget/MediaBrowser.Common.nuspec index a9cc361a9..814a4cd7e 100644 --- a/Nuget/MediaBrowser.Common.nuspec +++ b/Nuget/MediaBrowser.Common.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common - 3.0.216 + 3.0.217 MediaBrowser.Common Media Browser Team ebr,Luke,scottisafool diff --git a/Nuget/MediaBrowser.Server.Core.nuspec b/Nuget/MediaBrowser.Server.Core.nuspec index 56e9222d4..894905447 100644 --- a/Nuget/MediaBrowser.Server.Core.nuspec +++ b/Nuget/MediaBrowser.Server.Core.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Server.Core - 3.0.216 + 3.0.217 Media Browser.Server.Core Media Browser Team ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains core components required to build plugins for Media Browser Server. Copyright © Media Browser 2013 - +