The Free Software Media System - Server Backend & API
improve ffmpeg killing
Luke Pulverenti17f5ae811817
diff --git a/MediaBrowser.Api/ApiEntryPoint.cs b/MediaBrowser.Api/ApiEntryPoint.csindex ef5191df18..fd7ad2cf56 100644--- a/MediaBrowser.Api/ApiEntryPoint.cs+++ b/MediaBrowser.Api/ApiEntryPoint.cs@@ -284,16 +284,19 @@ namespace MediaBrowser.Api{job.ActiveRequestCount++;- job.DisposeKillTimer();+ if (string.IsNullOrWhiteSpace(job.PlaySessionId) || job.Type == TranscodingJobType.Progressive)+ {+ job.DisposeKillTimer();+ }}public void OnTranscodeEndRequest(TranscodingJob job){job.ActiveRequestCount--;-- if (job.ActiveRequestCount == 0)+ Logger.Debug("OnTranscodeEndRequest job.ActiveRequestCount={0}", job.ActiveRequestCount);+ if (job.ActiveRequestCount <= 0){- PingTimer(job, true);+ PingTimer(job, false);}}internal void PingTranscodingJob(string deviceId, string playSessionId)@@ -323,11 +326,11 @@ namespace MediaBrowser.Apiforeach (var job in jobs){- PingTimer(job, false);+ PingTimer(job, true);}}- private void PingTimer(TranscodingJob job, bool startTimerIfNeeded)+ private void PingTimer(TranscodingJob job, bool isProgressCheckIn){// TODO: Lower this hls timeoutvar timerDuration = job.Type == TranscodingJobType.Progressive ?@@ -335,20 +338,23 @@ namespace MediaBrowser.Api1800000;// We can really reduce the timeout for apps that are using the newer api- if (!string.IsNullOrWhiteSpace(job.PlaySessionId) && job.Type == TranscodingJobType.Hls)+ if (!string.IsNullOrWhiteSpace(job.PlaySessionId) && job.Type != TranscodingJobType.Progressive){- timerDuration = 40000;+ timerDuration = 35000;}if (job.KillTimer == null){- if (startTimerIfNeeded)+ // Don't start the timer for playback checkins with progressive streaming+ if (job.Type != TranscodingJobType.Progressive || !isProgressCheckIn){+ Logger.Debug("Starting kill timer at {0}ms", timerDuration);job.KillTimer = new Timer(OnTranscodeKillTimerStopped, job, timerDuration, Timeout.Infinite);}}else{+ Logger.Debug("Changing kill timer to {0}ms", timerDuration);job.KillTimer.Change(timerDuration, Timeout.Infinite);}}@@ -439,28 +445,19 @@ namespace MediaBrowser.Apilock (job.ProcessLock){- var process = job.Process;-- var hasExited = true;-- try- {- hasExited = process.HasExited;- }- catch (Exception ex)+ if (job.TranscodingThrottler != null){- Logger.ErrorException("Error determining if ffmpeg process has exited for {0}", ex, job.Path);+ job.TranscodingThrottler.Stop();}+ var process = job.Process;++ var hasExited = job.HasExited;+if (!hasExited){try{- if (job.TranscodingThrottler != null)- {- job.TranscodingThrottler.Stop();- }-Logger.Info("Killing ffmpeg process for {0}", job.Path);//process.Kill();diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.csindex 728fea0e0b..24ee17943a 100644--- a/MediaBrowser.Api/Playback/BaseStreamingService.cs+++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs@@ -1706,7 +1706,7 @@ namespace MediaBrowser.Api.Playbackstate.OutputAudioCodec = "copy";}- if (string.Equals(state.OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase))+ if (string.Equals(state.OutputVideoCodec, "copy", StringComparison.OrdinalIgnoreCase) && TranscodingJobType == TranscodingJobType.Hls){var segmentLength = GetSegmentLength(state);if (segmentLength.HasValue)diff --git a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.csindex 98d6c9a760..455113da90 100644--- a/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs+++ b/MediaBrowser.Api/Playback/Hls/DynamicHlsService.cs@@ -144,7 +144,6 @@ namespace MediaBrowser.Api.Playback.Hlsrequest.StartTimeTicks = GetSeekPositionTicks(state, requestedIndex);job = await StartFfMpeg(state, playlistPath, cancellationTokenSource).ConfigureAwait(false);- ApiEntryPoint.Instance.OnTranscodeBeginRequest(job);}catch{@@ -154,6 +153,14 @@ namespace MediaBrowser.Api.Playback.Hlsawait WaitForMinimumSegmentCount(playlistPath, 1, cancellationTokenSource.Token).ConfigureAwait(false);}+ else+ {+ job = ApiEntryPoint.Instance.OnTranscodeBeginRequest(playlistPath, TranscodingJobType);+ if (job.TranscodingThrottler != null)+ {+ job.TranscodingThrottler.UnpauseTranscoding();+ }+ }}}finallydiff --git a/MediaBrowser.Api/Playback/TranscodingThrottler.cs b/MediaBrowser.Api/Playback/TranscodingThrottler.csindex 58cfa086e3..ece4550095 100644--- a/MediaBrowser.Api/Playback/TranscodingThrottler.cs+++ b/MediaBrowser.Api/Playback/TranscodingThrottler.cs@@ -70,7 +70,7 @@ namespace MediaBrowser.Api.Playback}}- private void UnpauseTranscoding()+ public void UnpauseTranscoding(){if (_isPaused){diff --git a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.csindex 7c4160e1ba..c309739d01 100644--- a/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs+++ b/MediaBrowser.MediaEncoding/Encoder/MediaEncoder.cs@@ -244,8 +244,8 @@ namespace MediaBrowser.MediaEncoding.Encoder{try{- stream.KeyFrames = await GetKeyFrames(inputPath, stream.Index, cancellationToken)- .ConfigureAwait(false);+ //stream.KeyFrames = await GetKeyFrames(inputPath, stream.Index, cancellationToken)+ // .ConfigureAwait(false);}catch (OperationCanceledException){diff --git a/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs b/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.csindex 7950a8d5c7..f4d8ddb1a8 100644--- a/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs+++ b/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs@@ -130,7 +130,7 @@ namespace MediaBrowser.Providers.MediaInforeturn ItemUpdateType.MetadataImport;}- private const string SchemaVersion = "3";+ private const string SchemaVersion = "4";private async Task<Model.MediaInfo.MediaInfo> GetMediaInfo(Video item,IIsoMount isoMount,@@ -145,7 +145,7 @@ namespace MediaBrowser.Providers.MediaInfotry{- //return _json.DeserializeFromFile<Model.MediaInfo.MediaInfo>(cachePath);+ return _json.DeserializeFromFile<Model.MediaInfo.MediaInfo>(cachePath);}catch (FileNotFoundException){