// We use threads so tasks are not always awaited. #pragma warning disable 4014 /// <inheritdoc /> public async Task ExecuteResultAsync(ActionContext context) { float playableDuration = 0; bool transmuxFailed = false; Task.Factory.StartNew(() => { transmuxFailed = TranscoderAPI.Transmux(_path, _manifest, out playableDuration) != 0; }, TaskCreationOptions.LongRunning); while (playableDuration < 10 || (!File.Exists(_manifest) && !transmuxFailed)) { await Task.Delay(10); } if (!transmuxFailed) { new PhysicalFileResult(_manifest, "application/x-mpegurl") .ExecuteResultAsync(context); } else { _logger.LogCritical("The transmuxing failed on the C library"); new StatusCodeResult(500) .ExecuteResultAsync(context); } }
/// <summary> /// Check if the C library can be used or if there is an issue with it. /// </summary> /// <param name="fastStop">Should the healthcheck be abborted if the transcoder was already initialized?</param> /// <exception cref="HealthException">If the transcoder is corrupted, this exception in thrown.</exception> public void CheckHealth(bool fastStop = false) { if (fastStop && _initialized) { return; } if (TranscoderAPI.Init() != Marshal.SizeOf <FTrack>()) { _logger.LogCritical("The transcoder library could not be initialized correctly"); throw new HealthException("The transcoder library is corrupted or invalid."); } _initialized = true; }
/// <inheritdoc /> public async Task <ICollection <Track> > ExtractInfos(Episode episode, bool reExtract) { CheckHealth(true); string dir = await _files.GetExtraDirectory(episode); if (dir == null) { throw new ArgumentException("Invalid path."); } return(await Task.Factory.StartNew( () => TranscoderAPI.ExtractInfos(episode.Path, dir, reExtract), TaskCreationOptions.LongRunning )); }