summaryrefslogtreecommitdiffstats
path: root/win/C#/Parsing
diff options
context:
space:
mode:
authorsr55 <[email protected]>2010-02-22 21:23:28 +0000
committersr55 <[email protected]>2010-02-22 21:23:28 +0000
commit0a08b6778fa3dc2c38379d72252f23671e02e3c7 (patch)
tree08fc187f64054693c8d2055d5592fd096980a265 /win/C#/Parsing
parentb1b9be20c1efd855723109051cacdf9e307f996f (diff)
WinGui:
- Some more cleanup git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@3134 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'win/C#/Parsing')
-rw-r--r--win/C#/Parsing/Parser.cs88
-rw-r--r--win/C#/Parsing/Subtitle.cs90
-rw-r--r--win/C#/Parsing/Title.cs169
3 files changed, 215 insertions, 132 deletions
diff --git a/win/C#/Parsing/Parser.cs b/win/C#/Parsing/Parser.cs
index e643d3bd9..3dd2fdeb4 100644
--- a/win/C#/Parsing/Parser.cs
+++ b/win/C#/Parsing/Parser.cs
@@ -1,8 +1,7 @@
/* Parser.cs $
-
- This file is part of the HandBrake source code.
- Homepage: <http://handbrake.fr>.
- It may be used under the terms of the GNU General Public License. */
+ This file is part of the HandBrake source code.
+ Homepage: <http://handbrake.fr>.
+ It may be used under the terms of the GNU General Public License. */
namespace Handbrake.Parsing
{
@@ -15,31 +14,29 @@ namespace Handbrake.Parsing
/// <summary>
/// A delegate to handle custom events regarding data being parsed from the buffer
/// </summary>
- /// <param name="Sender">The object which raised this delegate</param>
- /// <param name="Data">The data parsed from the stream</param>
- public delegate void DataReadEventHandler(object Sender, string Data);
+ /// <param name="sender">The object which raised this delegate</param>
+ /// <param name="data">The data parsed from the stream</param>
+ public delegate void DataReadEventHandler(object sender, string data);
/// <summary>
/// A delegate to handle events regarding progress during DVD scanning
/// </summary>
- /// <param name="Sender">The object who's raising the event</param>
- /// <param name="CurrentTitle">The title number currently being processed</param>
- /// <param name="TitleCount">The total number of titiles to be processed</param>
- public delegate void ScanProgressEventHandler(object Sender, int CurrentTitle, int TitleCount);
+ /// <param name="sender">The object who's raising the event</param>
+ /// <param name="currentTitle">The title number currently being processed</param>
+ /// <param name="titleCount">The total number of titiles to be processed</param>
+ public delegate void ScanProgressEventHandler(object sender, int currentTitle, int titleCount);
/// <summary>
/// A delegate to handle encode progress updates // EXPERIMENTAL
/// </summary>
- /// <param name="Sender">The object which raised the event</param>
- /// <param name="CurrentTask">The current task being processed from the queue</param>
- /// <param name="TaskCount">The total number of tasks in queue</param>
- /// <param name="PercentComplete">The percentage this task is complete</param>
- /// <param name="CurrentFps">The current encoding fps</param>
- /// <param name="AverageFps">The average encoding fps for this task</param>
- /// <param name="TimeRemaining">The estimated time remaining for this task to complete</param>
- public delegate void EncodeProgressEventHandler(
- object Sender, int CurrentTask, int TaskCount, float PercentComplete, float CurrentFps, float AverageFps,
- TimeSpan TimeRemaining);
+ /// <param name="sender">The object which raised the event</param>
+ /// <param name="currentTask">The current task being processed from the queue</param>
+ /// <param name="taskCount">The total number of tasks in queue</param>
+ /// <param name="percentComplete">The percentage this task is complete</param>
+ /// <param name="currentFps">The current encoding fps</param>
+ /// <param name="averageFps">The average encoding fps for this task</param>
+ /// <param name="timeRemaining">The estimated time remaining for this task to complete</param>
+ public delegate void EncodeProgressEventHandler(object sender, int currentTask, int taskCount, float percentComplete, float currentFps, float averageFps, TimeSpan timeRemaining);
/// <summary>
@@ -47,14 +44,20 @@ namespace Handbrake.Parsing
/// </summary>
internal class Parser : StreamReader
{
- private StringBuilder _buffer = new StringBuilder(string.Empty);
+ /// <summary>
+ /// The Buffer StringBuilder
+ /// </summary>
+ private StringBuilder buffer = new StringBuilder(string.Empty);
/// <summary>
- /// The output from the CLI process
+ /// Initializes a new instance of the <see cref="Parser"/> class.
+ /// Default constructor for this object
/// </summary>
- public string Buffer
+ /// <param name="baseStream">
+ /// The stream to parse from
+ /// </param>
+ public Parser(Stream baseStream) : base(baseStream)
{
- get { return _buffer.ToString(); }
}
/// <summary>
@@ -72,32 +75,30 @@ namespace Handbrake.Parsing
/// </summary>
public event ScanProgressEventHandler OnScanProgress;
- #region Experimetnal Code
-
/// <summary>
/// Raised upon the catching of a "Scanning title # of #..." in the stream
/// </summary>
public event EncodeProgressEventHandler OnEncodeProgress;
- #endregion
-
/// <summary>
- /// Initializes a new instance of the <see cref="Parser"/> class.
- /// Default constructor for this object
+ /// Gets the buffer of data that came from the CLI standard input/error
/// </summary>
- /// <param name="baseStream">
- /// The stream to parse from
- /// </param>
- public Parser(Stream baseStream)
- : base(baseStream)
+ public string Buffer
{
+ get { return buffer.ToString(); }
}
+ /// <summary>
+ /// Read a line from standard in/err
+ /// </summary>
+ /// <returns>
+ /// The read line
+ /// </returns>
public override string ReadLine()
{
string tmp = base.ReadLine();
- _buffer.Append(tmp + Environment.NewLine);
+ buffer.Append(tmp + Environment.NewLine);
Match m = null;
if (tmp.Contains("Scanning title"))
@@ -113,11 +114,17 @@ namespace Handbrake.Parsing
return tmp;
}
+ /// <summary>
+ /// Read to the end of the input stream
+ /// </summary>
+ /// <returns>
+ /// A string of the input data
+ /// </returns>
public override string ReadToEnd()
{
string tmp = base.ReadToEnd();
- _buffer.Append(tmp + Environment.NewLine);
+ buffer.Append(tmp + Environment.NewLine);
if (OnReadToEnd != null)
OnReadToEnd(this, tmp);
@@ -128,13 +135,12 @@ namespace Handbrake.Parsing
/// <summary>
/// Pase the CLI status output (from standard output)
/// </summary>
- public void readEncodeStatus()
+ public void ReadEncodeStatus()
{
CultureInfo culture = CultureInfo.CreateSpecificCulture("en-US");
string tmp = base.ReadLine();
- Match m = Regex.Match(tmp,
- @"^Encoding: task ([0-9]*) of ([0-9]*), ([0-9]*\.[0-9]*) %( \(([0-9]*\.[0-9]*) fps, avg ([0-9]*\.[0-9]*) fps, ETA ([0-9]{2})h([0-9]{2})m([0-9]{2})s\))?");
+ Match m = Regex.Match(tmp, @"^Encoding: task ([0-9]*) of ([0-9]*), ([0-9]*\.[0-9]*) %( \(([0-9]*\.[0-9]*) fps, avg ([0-9]*\.[0-9]*) fps, ETA ([0-9]{2})h([0-9]{2})m([0-9]{2})s\))?");
if (m.Success && OnEncodeProgress != null)
{
int currentTask = int.Parse(m.Groups[1].Value);
diff --git a/win/C#/Parsing/Subtitle.cs b/win/C#/Parsing/Subtitle.cs
index 178e4470d..a21040be5 100644
--- a/win/C#/Parsing/Subtitle.cs
+++ b/win/C#/Parsing/Subtitle.cs
@@ -1,8 +1,7 @@
/* Subtitle.cs $
-
- This file is part of the HandBrake source code.
- Homepage: <http://handbrake.fr>.
- It may be used under the terms of the GNU General Public License. */
+ This file is part of the HandBrake source code.
+ Homepage: <http://handbrake.fr>.
+ It may be used under the terms of the GNU General Public License. */
namespace Handbrake.Parsing
{
@@ -15,54 +14,67 @@ namespace Handbrake.Parsing
/// </summary>
public class Subtitle
{
- private string m_language;
- private int m_trackNumber;
- private string m_type;
- private string m_typecode;
+ /// <summary>
+ /// The Language
+ /// </summary>
+ private string language;
+
+ /// <summary>
+ /// The Track Number
+ /// </summary>
+ private int trackNumber;
+
+ /// <summary>
+ /// The type of subtitle
+ /// </summary>
+ private string type;
/// <summary>
- /// The track number of this Subtitle
+ /// The typecode
+ /// </summary>
+ private string typecode;
+
+ /// <summary>
+ /// Gets the track number of this Subtitle
/// </summary>
public int TrackNumber
{
- get { return m_trackNumber; }
+ get { return trackNumber; }
}
/// <summary>
- /// The language (if detected) of this Subtitle
+ /// Gets the The language (if detected) of this Subtitle
/// </summary>
public string Language
{
- get { return m_language; }
+ get { return language; }
}
/// <summary>
- /// Langauage Code
+ /// Gets the Langauage Code
/// </summary>
public string LanguageCode
{
- get { return m_typecode; }
+ get { return typecode; }
}
-
/// <summary>
- /// Subtitle Type
+ /// Gets the Subtitle Type
/// </summary>
public string Type
{
- get { return m_type; }
+ get { return type; }
}
-
/// <summary>
- /// Override of the ToString method to make this object easier to use in the UI
+ /// Parse the input strings related to subtitles
/// </summary>
- /// <returns>A string formatted as: {track #} {language}</returns>
- public override string ToString()
- {
- return string.Format("{0} {1} ({2})", m_trackNumber, m_language, m_type);
- }
-
+ /// <param name="output">
+ /// The output.
+ /// </param>
+ /// <returns>
+ /// A Subitle object
+ /// </returns>
public static Subtitle Parse(StringReader output)
{
string curLine = output.ReadLine();
@@ -72,17 +84,26 @@ namespace Handbrake.Parsing
{
var thisSubtitle = new Subtitle
{
- m_trackNumber = int.Parse(m.Groups[1].Value.Trim()),
- m_language = m.Groups[2].Value,
- m_typecode = m.Groups[3].Value,
- m_type = m.Groups[4].Value
+ trackNumber = int.Parse(m.Groups[1].Value.Trim()),
+ language = m.Groups[2].Value,
+ typecode = m.Groups[3].Value,
+ type = m.Groups[4].Value
};
return thisSubtitle;
}
return null;
}
- public static Subtitle[] ParseList(StringReader output)
+ /// <summary>
+ /// Parse a list of Subtitle tracks from an input string.
+ /// </summary>
+ /// <param name="output">
+ /// The output.
+ /// </param>
+ /// <returns>
+ /// An array of Subtitle objects
+ /// </returns>
+ public static IEnumerable<Subtitle> ParseList(StringReader output)
{
var subtitles = new List<Subtitle>();
while ((char) output.Peek() != '+')
@@ -96,5 +117,14 @@ namespace Handbrake.Parsing
}
return subtitles.ToArray();
}
+
+ /// <summary>
+ /// Override of the ToString method to make this object easier to use in the UI
+ /// </summary>
+ /// <returns>A string formatted as: {track #} {language}</returns>
+ public override string ToString()
+ {
+ return string.Format("{0} {1} ({2})", trackNumber, language, type);
+ }
}
} \ No newline at end of file
diff --git a/win/C#/Parsing/Title.cs b/win/C#/Parsing/Title.cs
index 764c7cdbd..0494f5be5 100644
--- a/win/C#/Parsing/Title.cs
+++ b/win/C#/Parsing/Title.cs
@@ -1,8 +1,7 @@
/* Title.cs $
-
- This file is part of the HandBrake source code.
- Homepage: <http://handbrake.fr>.
- It may be used under the terms of the GNU General Public License. */
+ This file is part of the HandBrake source code.
+ Homepage: <http://handbrake.fr>.
+ It may be used under the terms of the GNU General Public License. */
namespace Handbrake.Parsing
{
@@ -18,19 +17,70 @@ namespace Handbrake.Parsing
/// </summary>
public class Title
{
+ /// <summary>
+ /// The Culture Info
+ /// </summary>
private static readonly CultureInfo Culture = new CultureInfo("en-US", false);
- private readonly List<AudioTrack> m_audioTracks;
- private readonly List<Chapter> m_chapters;
- private readonly List<Subtitle> m_subtitles;
- private List<string> m_angles = new List<string>();
- private float m_aspectRatio;
- private float m_fps;
- private int[] m_autoCrop;
+
+ /// <summary>
+ /// A collection of Audio Tracks
+ /// </summary>
+ private readonly List<AudioTrack> audioTracks;
+
+ /// <summary>
+ /// A Collection of Chapters
+ /// </summary>
+ private readonly List<Chapter> chapters;
+
+ /// <summary>
+ /// A Collection of Subtitles
+ /// </summary>
+ private readonly List<Subtitle> subtitles;
+
+ /// <summary>
+ /// A collection of angles
+ /// </summary>
+ private List<string> angles = new List<string>();
+
+ /// <summary>
+ /// The source aspect ratio
+ /// </summary>
+ private float aspectRatio;
+
+ /// <summary>
+ /// The source framerate
+ /// </summary>
+ private float fps;
+
+ /// <summary>
+ /// Source autocrop values
+ /// </summary>
+ private int[] autoCrop;
+
+ /// <summary>
+ /// Source name
+ /// </summary>
private string source;
- private TimeSpan m_duration;
- private Size m_resolution;
- private int m_titleNumber;
- private Size m_parVal;
+
+ /// <summary>
+ /// The duration of the source
+ /// </summary>
+ private TimeSpan duration;
+
+ /// <summary>
+ /// The source resolution
+ /// </summary>
+ private Size resolution;
+
+ /// <summary>
+ /// The Title number
+ /// </summary>
+ private int titleNumber;
+
+ /// <summary>
+ /// The par values for this title.
+ /// </summary>
+ private Size parVal;
/// <summary>
/// Initializes a new instance of the <see cref="Title"/> class.
@@ -38,33 +88,33 @@ namespace Handbrake.Parsing
/// </summary>
public Title()
{
- m_audioTracks = new List<AudioTrack>();
- m_chapters = new List<Chapter>();
- m_subtitles = new List<Subtitle>();
+ audioTracks = new List<AudioTrack>();
+ chapters = new List<Chapter>();
+ subtitles = new List<Subtitle>();
}
/// <summary>
- /// Collection of chapters in this Title
+ /// Gets a Collection of chapters in this Title
/// </summary>
public List<Chapter> Chapters
{
- get { return m_chapters; }
+ get { return chapters; }
}
/// <summary>
- /// Collection of audio tracks associated with this Title
+ /// Gets a Collection of audio tracks associated with this Title
/// </summary>
public List<AudioTrack> AudioTracks
{
- get { return m_audioTracks; }
+ get { return audioTracks; }
}
/// <summary>
- /// Collection of subtitles associated with this Title
+ /// Gets aCollection of subtitles associated with this Title
/// </summary>
public List<Subtitle> Subtitles
{
- get { return m_subtitles; }
+ get { return subtitles; }
}
/// <summary>
@@ -72,11 +122,11 @@ namespace Handbrake.Parsing
/// </summary>
public int TitleNumber
{
- get { return m_titleNumber; }
+ get { return titleNumber; }
}
/// <summary>
- /// Source Name
+ /// Gets the Source Name
/// </summary>
public string SourceName
{
@@ -84,39 +134,39 @@ namespace Handbrake.Parsing
}
/// <summary>
- /// The length in time of this Title
+ /// Gets the length in time of this Title
/// </summary>
public TimeSpan Duration
{
- get { return m_duration; }
+ get { return duration; }
}
/// <summary>
- /// The resolution (width/height) of this Title
+ /// Gets the resolution (width/height) of this Title
/// </summary>
public Size Resolution
{
- get { return m_resolution; }
+ get { return resolution; }
}
/// <summary>
- /// The aspect ratio of this Title
+ /// Gets the aspect ratio of this Title
/// </summary>
public float AspectRatio
{
- get { return m_aspectRatio; }
+ get { return aspectRatio; }
}
/// <summary>
- /// Par Value
+ /// Gets Par Value
/// </summary>
public Size ParVal
{
- get { return m_parVal; }
+ get { return parVal; }
}
/// <summary>
- /// The automatically detected crop region for this Title.
+ /// Gets the automatically detected crop region for this Title.
/// This is an int array with 4 items in it as so:
/// 0:
/// 1:
@@ -125,23 +175,24 @@ namespace Handbrake.Parsing
/// </summary>
public int[] AutoCropDimensions
{
- get { return m_autoCrop; }
+ get { return autoCrop; }
}
/// <summary>
- /// Collection of Angles in this Title
+ /// Gets a Collection of Angles in this Title
/// </summary>
public List<string> Angles
{
- get { return m_angles; }
+ get { return angles; }
}
+
/// <summary>
- /// Collection of Angles in this Title
+ /// Gets the FPS of the source.
/// </summary>
public float Fps
{
- get { return m_fps; }
+ get { return fps; }
}
/// <summary>
@@ -150,15 +201,14 @@ namespace Handbrake.Parsing
/// <returns>A string representing this track in the format: {title #} (00:00:00)</returns>
public override string ToString()
{
- return string.Format("{0} ({1:00}:{2:00}:{3:00})", m_titleNumber, m_duration.Hours,
- m_duration.Minutes, m_duration.Seconds);
+ return string.Format("{0} ({1:00}:{2:00}:{3:00})", titleNumber, duration.Hours, duration.Minutes, duration.Seconds);
}
/// <summary>
/// Parse the Title Information
/// </summary>
- /// <param name="output"></param>
- /// <returns></returns>
+ /// <param name="output">A stingreader of output data</param>
+ /// <returns>A Title</returns>
public static Title Parse(StringReader output)
{
var thisTitle = new Title();
@@ -166,7 +216,7 @@ namespace Handbrake.Parsing
Match m = Regex.Match(output.ReadLine(), @"^\+ title ([0-9]*):");
// Match track number for this title
if (m.Success)
- thisTitle.m_titleNumber = int.Parse(m.Groups[1].Value.Trim());
+ thisTitle.titleNumber = int.Parse(m.Groups[1].Value.Trim());
// If we are scanning a groupd of files, we'll want to get the source name.
string path = output.ReadLine();
@@ -185,42 +235,39 @@ namespace Handbrake.Parsing
int.TryParse(angleList, out angleCount);
for (int i = 1; i <= angleCount; i++)
- thisTitle.m_angles.Add(i.ToString());
+ thisTitle.angles.Add(i.ToString());
}
}
// Get duration for this title
m = Regex.Match(output.ReadLine(), @"^ \+ duration: ([0-9]{2}:[0-9]{2}:[0-9]{2})");
if (m.Success)
- thisTitle.m_duration = TimeSpan.Parse(m.Groups[1].Value);
+ thisTitle.duration = TimeSpan.Parse(m.Groups[1].Value);
// Get resolution, aspect ratio and FPS for this title
- m = Regex.Match(output.ReadLine(),
- @"^ \+ size: ([0-9]*)x([0-9]*), pixel aspect: ([0-9]*)/([0-9]*), display aspect: ([0-9]*\.[0-9]*), ([0-9]*\.[0-9]*) fps");
- // size: 720x576, pixel aspect: 16/15, display aspect: 1.33, 25.000 fps
-
+ m = Regex.Match(output.ReadLine(), @"^ \+ size: ([0-9]*)x([0-9]*), pixel aspect: ([0-9]*)/([0-9]*), display aspect: ([0-9]*\.[0-9]*), ([0-9]*\.[0-9]*) fps");
if (m.Success)
{
- thisTitle.m_resolution = new Size(int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value));
- thisTitle.m_parVal = new Size(int.Parse(m.Groups[3].Value), int.Parse(m.Groups[4].Value));
- thisTitle.m_aspectRatio = float.Parse(m.Groups[5].Value, Culture);
- thisTitle.m_fps = float.Parse(m.Groups[6].Value, Culture);
+ thisTitle.resolution = new Size(int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value));
+ thisTitle.parVal = new Size(int.Parse(m.Groups[3].Value), int.Parse(m.Groups[4].Value));
+ thisTitle.aspectRatio = float.Parse(m.Groups[5].Value, Culture);
+ thisTitle.fps = float.Parse(m.Groups[6].Value, Culture);
}
// Get autocrop region for this title
m = Regex.Match(output.ReadLine(), @"^ \+ autocrop: ([0-9]*)/([0-9]*)/([0-9]*)/([0-9]*)");
if (m.Success)
- thisTitle.m_autoCrop = new[]
+ thisTitle.autoCrop = new[]
{
int.Parse(m.Groups[1].Value), int.Parse(m.Groups[2].Value),
int.Parse(m.Groups[3].Value), int.Parse(m.Groups[4].Value)
};
- thisTitle.m_chapters.AddRange(Chapter.ParseList(output));
+ thisTitle.chapters.AddRange(Chapter.ParseList(output));
- thisTitle.m_audioTracks.AddRange(AudioTrack.ParseList(output));
+ thisTitle.audioTracks.AddRange(AudioTrack.ParseList(output));
- thisTitle.m_subtitles.AddRange(Subtitle.ParseList(output));
+ thisTitle.subtitles.AddRange(Subtitle.ParseList(output));
return thisTitle;
}
@@ -228,8 +275,8 @@ namespace Handbrake.Parsing
/// <summary>
/// Return a list of parsed titles
/// </summary>
- /// <param name="output"></param>
- /// <returns></returns>
+ /// <param name="output">The Output</param>
+ /// <returns>A List of titles</returns>
public static Title[] ParseList(string output)
{
var titles = new List<Title>();