private void CloseEncoder(bool _null) { lock (locker) { if (avs != null) { if (avs.IsBusy()) { avs.stop(); } if (_null) { avs = null; } } } }
private void worker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { try { //определяем аудио потоки AudioStream instream = (AudioStream)m.inaudiostreams[m.inaudiostream]; script = AviSynthScripting.GetInfoScript(m, AviSynthScripting.ScriptMode.Normalize); script += Environment.NewLine + "Trim(0, " + vtrim + ")"; avs = new AviSynthEncoder(m, script); //Запускаем анализ avs.start(); //Выводим прогресс while (avs.IsBusy()) { if (worker.CancellationPending) { avs.stop(); } else if (avs.frame > 0) { worker.ReportProgress(avs.frame); } Thread.Sleep(100); } //Результаты if (!worker.CancellationPending) { if (!avs.IsErrors) { instream.gain = avs.gain.ToString("##0.000").Replace(",", "."); if (instream.gain == "0.000") { instream.gain = "0.0"; } instream.gaindetected = true; } else { instream.gain = "0.0"; instream.gaindetected = false; throw new Exception(avs.error_text, avs.exception_raw); } } } catch (Exception ex) { if (worker != null && !worker.CancellationPending && m != null && num_closes == 0) { //Ошибка ex.HelpLink = script; e.Result = ex; } } finally { CloseEncoder(true); } }
private void worker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { try { //определяем аудио потоки AudioStream instream = (AudioStream)m.inaudiostreams[m.inaudiostream]; script = AviSynthScripting.GetInfoScript(m, AviSynthScripting.ScriptMode.Normalize); script += Environment.NewLine + "Trim(0, " + vtrim + ")"; avs = new AviSynthEncoder(m, script); //Запускаем анализ avs.start(); //Выводим прогресс while (avs.IsBusy()) { if (worker.CancellationPending) avs.stop(); else if (avs.frame > 0) worker.ReportProgress(avs.frame); Thread.Sleep(100); } //Результаты if (!worker.CancellationPending) { if (!avs.IsErrors) { instream.gain = avs.gain.ToString("##0.000").Replace(",", "."); if (instream.gain == "0.000") instream.gain = "0.0"; instream.gaindetected = true; } else { instream.gain = "0.0"; instream.gaindetected = false; throw new Exception(avs.error_text, avs.exception_raw); } } } catch (Exception ex) { if (worker != null && !worker.CancellationPending && m != null && num_closes == 0) { //Ошибка ex.HelpLink = script; e.Result = ex; } } finally { CloseEncoder(true); } }