Skip to content

Commit

Permalink
OKEGui/OKEGui/JobProcessor/CommandlineJobProcessor.cs, Video/VSPipePr…
Browse files Browse the repository at this point in the history
…ocessor.cs: properly handle `vspipe -i` failures

Signed-off-by: akarin <[email protected]>
  • Loading branch information
AkarinVS committed Dec 6, 2022
1 parent a43812d commit e4ba805
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
16 changes: 15 additions & 1 deletion OKEGui/OKEGui/JobProcessor/CommandlineJobProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ protected virtual void getErrorLine()
return;
}

private void proc_Exited2(object sender, EventArgs e)
{
Process p = sender as Process;
Logger.Debug("exitCode=", p.ExitCode);
onExited(p.ExitCode);
}


protected virtual void onExited(int exitCode)
{
return;
}

/// <summary>
/// handles the encoder process existing
/// </summary>
Expand Down Expand Up @@ -98,8 +111,9 @@ public void start()
pstart.CreateNoWindow = true;
pstart.UseShellExecute = false;
proc.StartInfo = pstart;
//proc.EnableRaisingEvents = true;
proc.EnableRaisingEvents = true;
//proc.Exited += new EventHandler(proc_Exited);
proc.Exited += new EventHandler(proc_Exited2);
bWaitForExit = false;
Logger.Info(pstart.FileName + " " + pstart.Arguments);

Expand Down
21 changes: 20 additions & 1 deletion OKEGui/OKEGui/JobProcessor/Video/VSPipeProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,18 @@ namespace OKEGui
{
public class VSPipeProcessor : CommandlineJobProcessor
{
private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
private VSVideoInfo videoInfo;
private bool videoInfoOk;
private string lastStderrLine;
private ManualResetEvent retrieved = new ManualResetEvent(false);

public VSPipeProcessor(VideoInfoJob j) : base()
{
// 获取VSPipe路径
executable = Initializer.Config.vspipePath;
videoInfo = new VSVideoInfo();
videoInfoOk = false;

StringBuilder sb = new StringBuilder();

Expand All @@ -36,7 +40,9 @@ public VSPipeProcessor(VideoInfoJob j) : base()

public override void ProcessLine(string line, StreamType stream)
{
base.ProcessLine(line, stream);
Logger.Debug(line);
if (stream == StreamType.Stderr)
lastStderrLine = line;
Regex rWidth = new Regex("Width: ([0-9]+)");
Regex rHeight = new Regex("Height: ([0-9]+)");
Regex rFrames = new Regex("Frames: ([0-9]+)");
Expand Down Expand Up @@ -127,6 +133,7 @@ public override void ProcessLine(string line, StreamType stream)
}

// 假设到这里已经获取完毕了
videoInfoOk = true;
retrieved.Set();
}
else if (line.Contains("SubSampling"))
Expand All @@ -140,10 +147,22 @@ public override void waitForFinish()
retrieved.WaitOne();
}

protected override void onExited(int exitCode)
{
if (exitCode != 0)
{
if (lastStderrLine == "")
lastStderrLine = "exitcode is " + exitCode.ToString();
retrieved.Set();
}
}

public VSVideoInfo VideoInfo
{
get {
retrieved.WaitOne();
if (!videoInfoOk)
throw new Exception("vspipe -i failed: " + lastStderrLine);
return videoInfo;
}
}
Expand Down

0 comments on commit e4ba805

Please sign in to comment.