This repository has been archived by the owner on Feb 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
14a3333
commit 7199b91
Showing
7 changed files
with
157 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace VpxEncode.Output | ||
{ | ||
public abstract class OutputProcessor | ||
{ | ||
protected List<ProcessingUnit> units = new List<ProcessingUnit>(); | ||
|
||
public ProcessingUnit CreateOne() | ||
{ | ||
ProcessingUnit pu = new ProcessingUnit(); | ||
pu.OnDataReceived += pu_OnDataReceived; | ||
units.Add(pu); | ||
return pu; | ||
} | ||
|
||
protected abstract void pu_OnDataReceived(object sender, ProcessingUnitDataReceivedEventArgs e); | ||
|
||
public void Destroy(ProcessingUnit pu) | ||
{ | ||
pu.OnDataReceived -= pu_OnDataReceived; | ||
units.Remove(pu); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Text.RegularExpressions; | ||
|
||
namespace VpxEncode.Output | ||
{ | ||
public sealed class PercentedProcessor : OutputProcessor | ||
{ | ||
private Regex TimeFromLine = new Regex(@".*time=(\d{2,}:\d{2}:\d{2}.\d{2}).*"); | ||
|
||
private double TotalSeconds; | ||
|
||
public PercentedProcessor(double totalSeconds) | ||
{ | ||
TotalSeconds = totalSeconds; | ||
} | ||
|
||
protected override void pu_OnDataReceived(object sender, ProcessingUnitDataReceivedEventArgs e) | ||
{ | ||
if (e.Data == null) | ||
return; | ||
|
||
Match match = TimeFromLine.Match(e.Data); | ||
if (match.Success) | ||
{ | ||
string value = match.Groups[1].Value; | ||
double d = TimeSpan.ParseExact(value, "hh\\:mm\\:ss\\.ff", CultureInfo.InvariantCulture).TotalSeconds; | ||
double perc = 100 * d / TotalSeconds; | ||
|
||
ProcessingUnit pu = sender as ProcessingUnit; | ||
Console.SetCursorPosition(0, units.IndexOf(pu)); | ||
string str = String.Format("{0:0.00}%", perc); | ||
Console.WriteLine(str); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System; | ||
using System.Diagnostics; | ||
|
||
namespace VpxEncode.Output | ||
{ | ||
public sealed class ProcessingUnit | ||
{ | ||
public int Token { get; private set; } | ||
|
||
public event EventHandler<ProcessingUnitDataReceivedEventArgs> OnDataReceived; | ||
|
||
public ProcessingUnit() | ||
{ | ||
Token = new Random().Next(); | ||
} | ||
|
||
public void Write(string line) | ||
{ | ||
RaiseEvent(line); | ||
} | ||
|
||
public void DataReceived(object sender, DataReceivedEventArgs data) | ||
{ | ||
RaiseEvent(data.Data); | ||
} | ||
|
||
private void RaiseEvent(string text) | ||
{ | ||
var handler = OnDataReceived; | ||
if (handler != null) | ||
handler(this, new ProcessingUnitDataReceivedEventArgs(Token, text)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System; | ||
|
||
namespace VpxEncode.Output | ||
{ | ||
public sealed class ProcessingUnitDataReceivedEventArgs : EventArgs | ||
{ | ||
public string Data { get; private set; } | ||
public int Token { get; private set; } | ||
|
||
public ProcessingUnitDataReceivedEventArgs(int token, string data) | ||
: base() | ||
{ | ||
Data = data; | ||
Token = token; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
|
||
namespace VpxEncode.Output | ||
{ | ||
public sealed class SimpleProcessor : OutputProcessor | ||
{ | ||
protected override void pu_OnDataReceived(object sender, ProcessingUnitDataReceivedEventArgs e) | ||
{ | ||
string data = e.Data; | ||
if (data != null && data.Length == Console.WindowWidth) | ||
Console.Write(data); | ||
else | ||
Console.WriteLine(data); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters