/// <summary> /// Kills the transcoding job. /// </summary> /// <param name="job">The job.</param> /// <param name="delete">The delete.</param> private void KillTranscodingJob(TranscodingJob job, Func <string, bool> delete) { lock (_activeTranscodingJobs) { _activeTranscodingJobs.Remove(job); if (!job.CancellationTokenSource.IsCancellationRequested) { job.CancellationTokenSource.Cancel(); } job.DisposeKillTimer(); } lock (job.ProcessLock) { var process = job.Process; var hasExited = true; try { hasExited = process.HasExited; } catch (Exception ex) { Logger.ErrorException("Error determining if ffmpeg process has exited for {0}", ex, job.Path); } if (!hasExited) { try { Logger.Info("Killing ffmpeg process for {0}", job.Path); //process.Kill(); process.StandardInput.WriteLine("q"); // Need to wait because killing is asynchronous process.WaitForExit(5000); } catch (Exception ex) { Logger.ErrorException("Error killing transcoding job for {0}", ex, job.Path); } } } if (delete(job.Path)) { DeletePartialStreamFiles(job.Path, job.Type, 0, 1500); } }
/// <summary> /// Kills the transcoding job. /// </summary> /// <param name="job">The job.</param> /// <param name="delete">The delete.</param> private void KillTranscodingJob(TranscodingJob job, Func <string, bool> delete) { job.DisposeKillTimer(); Logger.Debug("KillTranscodingJob - JobId {0} PlaySessionId {1}. Killing transcoding", job.Id, job.PlaySessionId); lock (_activeTranscodingJobs) { _activeTranscodingJobs.Remove(job); if (!job.CancellationTokenSource.IsCancellationRequested) { job.CancellationTokenSource.Cancel(); } } lock (job.ProcessLock) { if (job.TranscodingThrottler != null) { job.TranscodingThrottler.Stop(); } var process = job.Process; var hasExited = job.HasExited; if (!hasExited) { try { Logger.Info("Killing ffmpeg process for {0}", job.Path); //process.Kill(); process.StandardInput.WriteLine("q"); // Need to wait because killing is asynchronous process.WaitForExit(5000); } catch (Exception ex) { Logger.ErrorException("Error killing transcoding job for {0}", ex, job.Path); } } } if (delete(job.Path)) { DeletePartialStreamFiles(job.Path, job.Type, 0, 1500); } }
/// <summary> /// Kills the transcoding job. /// </summary> /// <param name="job">The job.</param> /// <param name="closeLiveStream">if set to <c>true</c> [close live stream].</param> /// <param name="delete">The delete.</param> private async void KillTranscodingJob(TranscodingJob job, bool closeLiveStream, Func<string, bool> delete) { job.DisposeKillTimer(); Logger.Debug("KillTranscodingJob - JobId {0} PlaySessionId {1}. Killing transcoding", job.Id, job.PlaySessionId); lock (_activeTranscodingJobs) { _activeTranscodingJobs.Remove(job); if (!job.CancellationTokenSource.IsCancellationRequested) { job.CancellationTokenSource.Cancel(); } } lock (job.ProcessLock) { if (job.TranscodingThrottler != null) { job.TranscodingThrottler.Stop(); } var process = job.Process; var hasExited = job.HasExited; if (!hasExited) { try { Logger.Info("Stopping ffmpeg process with q command for {0}", job.Path); //process.Kill(); process.StandardInput.WriteLine("q"); // Need to wait because killing is asynchronous if (!process.WaitForExit(5000)) { Logger.Info("Killing ffmpeg process for {0}", job.Path); process.Kill(); } } catch (Exception ex) { Logger.ErrorException("Error killing transcoding job for {0}", ex, job.Path); } } } if (delete(job.Path)) { DeletePartialStreamFiles(job.Path, job.Type, 0, 1500); } if (closeLiveStream && !string.IsNullOrWhiteSpace(job.LiveStreamId)) { try { await _mediaSourceManager.CloseLiveStream(job.LiveStreamId, CancellationToken.None).ConfigureAwait(false); } catch (Exception ex) { Logger.ErrorException("Error closing live stream for {0}", ex, job.Path); } } }
/// <summary> /// Kills the transcoding job. /// </summary> /// <param name="job">The job.</param> /// <param name="closeLiveStream">if set to <c>true</c> [close live stream].</param> /// <param name="delete">The delete.</param> private async Task KillTranscodingJob(TranscodingJob job, bool closeLiveStream, Func <string, bool> delete) { job.DisposeKillTimer(); _logger.LogDebug("KillTranscodingJob - JobId {0} PlaySessionId {1}. Killing transcoding", job.Id, job.PlaySessionId); lock (_activeTranscodingJobs) { _activeTranscodingJobs.Remove(job); if (!job.CancellationTokenSource.IsCancellationRequested) { job.CancellationTokenSource.Cancel(); } } lock (_transcodingLocks) { _transcodingLocks.Remove(job.Path); } lock (job.ProcessLock) { job.TranscodingThrottler?.Stop().GetAwaiter().GetResult(); var process = job.Process; var hasExited = job.HasExited; if (!hasExited) { try { _logger.LogInformation("Stopping ffmpeg process with q command for {Path}", job.Path); process.StandardInput.WriteLine("q"); // Need to wait because killing is asynchronous if (!process.WaitForExit(5000)) { _logger.LogInformation("Killing ffmpeg process for {Path}", job.Path); process.Kill(); } } catch (InvalidOperationException) { } } } if (delete(job.Path)) { await DeletePartialStreamFiles(job.Path, job.Type, 0, 1500).ConfigureAwait(false); } if (closeLiveStream && !string.IsNullOrWhiteSpace(job.LiveStreamId)) { try { await _mediaSourceManager.CloseLiveStream(job.LiveStreamId).ConfigureAwait(false); } catch (Exception ex) { _logger.LogError(ex, "Error closing live stream for {Path}", job.Path); } } }
/// <summary> /// Kills the transcoding job. /// </summary> /// <param name="job">The job.</param> /// <param name="delete">The delete.</param> private void KillTranscodingJob(TranscodingJob job, Func<string, bool> delete) { lock (_activeTranscodingJobs) { _activeTranscodingJobs.Remove(job); if (!job.CancellationTokenSource.IsCancellationRequested) { job.CancellationTokenSource.Cancel(); } job.DisposeKillTimer(); } lock (job.ProcessLock) { var process = job.Process; var hasExited = true; try { hasExited = process.HasExited; } catch (Exception ex) { Logger.ErrorException("Error determining if ffmpeg process has exited for {0}", ex, job.Path); } if (!hasExited) { try { Logger.Info("Killing ffmpeg process for {0}", job.Path); //process.Kill(); process.StandardInput.WriteLine("q"); // Need to wait because killing is asynchronous process.WaitForExit(5000); } catch (Exception ex) { Logger.ErrorException("Error killing transcoding job for {0}", ex, job.Path); } } } if (delete(job.Path)) { DeletePartialStreamFiles(job.Path, job.Type, 0, 1500); } }
/// <summary> /// Kills the transcoding job. /// </summary> /// <param name="job">The job.</param> /// <param name="closeLiveStream">if set to <c>true</c> [close live stream].</param> /// <param name="delete">The delete.</param> private async void KillTranscodingJob(TranscodingJob job, bool closeLiveStream, Func <string, bool> delete) { job.DisposeKillTimer(); Logger.Debug("KillTranscodingJob - JobId {0} PlaySessionId {1}. Killing transcoding", job.Id, job.PlaySessionId); lock (_activeTranscodingJobs) { _activeTranscodingJobs.Remove(job); if (!job.CancellationTokenSource.IsCancellationRequested) { job.CancellationTokenSource.Cancel(); } } lock (job.ProcessLock) { if (job.TranscodingThrottler != null) { job.TranscodingThrottler.Stop(); } var process = job.Process; var hasExited = job.HasExited; if (!hasExited) { try { Logger.Info("Stopping ffmpeg process with q command for {0}", job.Path); //process.Kill(); process.StandardInput.WriteLine("q"); // Need to wait because killing is asynchronous if (!process.WaitForExit(5000)) { Logger.Info("Killing ffmpeg process for {0}", job.Path); process.Kill(); } } catch (Exception ex) { Logger.ErrorException("Error killing transcoding job for {0}", ex, job.Path); } } } if (delete(job.Path)) { DeletePartialStreamFiles(job.Path, job.Type, 0, 1500); } if (closeLiveStream && !string.IsNullOrWhiteSpace(job.LiveStreamId)) { try { await _mediaSourceManager.CloseLiveStream(job.LiveStreamId, CancellationToken.None).ConfigureAwait(false); } catch (Exception ex) { Logger.ErrorException("Error closing live stream for {0}", ex, job.Path); } } }