safer hls kill

This commit is contained in:
Luke Pulverenti 2013-10-03 10:14:40 -04:00
parent eb72c2db51
commit 16fd474ad3
17 changed files with 57 additions and 30 deletions

View File

@ -85,7 +85,8 @@ namespace MediaBrowser.Api
/// <param name="isVideo">if set to <c>true</c> [is video].</param>
/// <param name="startTimeTicks">The start time ticks.</param>
/// <param name="sourcePath">The source path.</param>
public void OnTranscodeBeginning(string path, TranscodingJobType type, Process process, bool isVideo, long? startTimeTicks, string sourcePath)
/// <param name="deviceId">The device id.</param>
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
/// <summary>
/// Kills the single transcoding job.
/// </summary>
/// <param name="sourcePath">The source path.</param>
internal void KillSingleTranscodingJob(string sourcePath)
/// <param name="deviceId">The device id.</param>
/// <param name="isVideo">if set to <c>true</c> [is video].</param>
/// <exception cref="System.ArgumentNullException">sourcePath</exception>
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<TranscodingJob>();
@ -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; }
}
/// <summary>

View File

@ -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);

View File

@ -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);
}
/// <summary>
/// Gets the specified request.
/// </summary>

View File

@ -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; }
/// <summary>
/// Gets or sets the audio codec.
/// </summary>

View File

@ -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;

View File

@ -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

View File

@ -384,7 +384,7 @@ namespace MediaBrowser.Common.Implementations
/// </summary>
/// <param name="type">The type.</param>
/// <returns>System.Object.</returns>
protected object CreateInstance(Type type)
public object CreateInstance(Type type)
{
try
{

View File

@ -125,5 +125,12 @@ namespace MediaBrowser.Common
/// </summary>
/// <returns>Task.</returns>
Task Init();
/// <summary>
/// Creates the instance.
/// </summary>
/// <param name="type">The type.</param>
/// <returns>System.Object.</returns>
object CreateInstance(Type type);
}
}

View File

@ -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; }
/// <summary>
/// Gets the type of the media.

View File

@ -151,6 +151,12 @@
/// </summary>
/// <value>The output file extension.</value>
public string OutputFileExtension { get; set; }
/// <summary>
/// Gets or sets the device id.
/// </summary>
/// <value>The device id.</value>
public string DeviceId { get; set; }
}
/// <summary>

View File

@ -92,7 +92,7 @@ namespace MediaBrowser.Providers.Games
/// </summary>
public override MetadataProviderPriority Priority
{
get { return MetadataProviderPriority.First; }
get { return MetadataProviderPriority.Second; }
}
}
}

View File

@ -37,7 +37,7 @@ namespace MediaBrowser.Providers.Games
/// <value>The priority.</value>
public override MetadataProviderPriority Priority
{
get { return MetadataProviderPriority.First; }
get { return MetadataProviderPriority.Second; }
}
private const string XmlFileName = "gamesystem.xml";

View File

@ -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);

View File

@ -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[]
{

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MediaBrowser.Common.Internal</id>
<version>3.0.216</version>
<version>3.0.217</version>
<title>MediaBrowser.Common.Internal</title>
<authors>Luke</authors>
<owners>ebr,Luke,scottisafool</owners>
@ -12,7 +12,7 @@
<description>Contains common components shared by Media Browser Theater and Media Browser Server. Not intended for plugin developer consumption.</description>
<copyright>Copyright © Media Browser 2013</copyright>
<dependencies>
<dependency id="MediaBrowser.Common" version="3.0.216" />
<dependency id="MediaBrowser.Common" version="3.0.217" />
<dependency id="NLog" version="2.0.1.2" />
<dependency id="ServiceStack.Text" version="3.9.58" />
<dependency id="SimpleInjector" version="2.3.2" />

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>MediaBrowser.Common</id>
<version>3.0.216</version>
<version>3.0.217</version>
<title>MediaBrowser.Common</title>
<authors>Media Browser Team</authors>
<owners>ebr,Luke,scottisafool</owners>

View File

@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>MediaBrowser.Server.Core</id>
<version>3.0.216</version>
<version>3.0.217</version>
<title>Media Browser.Server.Core</title>
<authors>Media Browser Team</authors>
<owners>ebr,Luke,scottisafool</owners>
@ -12,7 +12,7 @@
<description>Contains core components required to build plugins for Media Browser Server.</description>
<copyright>Copyright © Media Browser 2013</copyright>
<dependencies>
<dependency id="MediaBrowser.Common" version="3.0.216" />
<dependency id="MediaBrowser.Common" version="3.0.217" />
</dependencies>
</metadata>
<files>