home
products
contribute
download
documentation
forum
Home
Forums
New posts
Search forums
What's new
New posts
All posts
Latest activity
Members
Registered members
Current visitors
Donate
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Search titles only
By:
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Language specific support
Deutsches MediaPortal Forum
Allgemein
Einsteigerforum
TS Packet Checker
Contact us
RSS
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="alexi" data-source="post: 1261439" data-attributes="member: 101499"><p>noch ein bugfix:</p><p></p><p>[code]// return (header.HasAdaptionField && (tsPacket[5] & 0x10) == 0x10);</p><p>// ISO/IEC 13818-1: "The adaptation_field_length is an 8-bit field specifying the number of bytes in the adaptation_field immediately following the adaptation_field_length.</p><p>// The value 0 is for inserting a single stuffing byte in a Transport Stream packet." -> if (adaptation_field_length > 0)</p><p> return (header.HasAdaptionField && (tsPacket[5] & 0x10) == 0x10) && (header.AdaptionFieldLength > 0);</p><p>[/code]</p><p></p><p></p><p>in PacketChecks.cs (komplett):</p><p></p><p>[code]using System;</p><p>using System.Collections.Generic;</p><p>using System.Text;</p><p></p><p>namespace TsPacketChecker</p><p>{</p><p> class PacketChecker</p><p> {</p><p> private long droppedPackets;</p><p> private long nullPackets;</p><p> private long totalCCErrors;</p><p> private long totalPcrErrors;</p><p> private long totalPtsErrors;</p><p> private long totalPayloadStartErrors;</p><p> private double diffAllowed;</p><p> private SortedDictionary<ushort, PidInfo> pids = new SortedDictionary<ushort, PidInfo>();</p><p></p><p> #region Existence checks</p><p> private bool PacketContainsPcr(TsHeader header, byte[] tsPacket)</p><p> {</p><p>// return (header.HasAdaptionField && (tsPacket[5] & 0x10) == 0x10);</p><p>// ISO/IEC 13818-1: "The adaptation_field_length is an 8-bit field specifying the number of bytes in the adaptation_field immediately following the adaptation_field_length.</p><p>// The value 0 is for inserting a single stuffing byte in a Transport Stream packet." -> if (adaptation_field_length > 0)</p><p> return (header.HasAdaptionField && (tsPacket[5] & 0x10) == 0x10) && (header.AdaptionFieldLength > 0);</p><p> }</p><p> private ulong PacketContainsPtsDts(TsHeader header, byte[] tsPacket, ref PidInfo pi)</p><p> {</p><p> if (!header.PayloadUnitStart)</p><p> return 0;</p><p> if (header.PayLoadStart > 185 && header.HasPayload)</p><p> {</p><p> totalPayloadStartErrors++;</p><p> pi.payloadStartErrorTexts.Add(" payloadStart=" + header.PayLoadStart.ToString() + " HasAdaption=" + header.HasAdaptionField.ToString() + " HasPayload=" + header.HasPayload.ToString() + " AdaptionFieldSize=" + tsPacket[4].ToString());</p><p> return 0;</p><p> }</p><p> if (!header.HasPayload)</p><p> return 0;</p><p> return header.PayLoadStart;</p><p> }</p><p> #endregion</p><p></p><p> #region Continuity checks</p><p> private bool CheckContinuityCounter(byte tsPacket3, ref PidInfo pi)</p><p> {</p><p> bool isOk = true;</p><p> byte cc = (byte)(tsPacket3 & 0xF);</p><p> if (pi.continuityCounter != 0xFF)</p><p> {</p><p> byte afc = (byte)((tsPacket3 >> 4) & 0x3);</p><p> byte expected;</p><p>// ISO/IEC 13818-1: "The continuity_counter shall not be incremented when the adaptation_field_control of the packet equals '00' or '10'." (binary)</p><p> if ((afc.Equals(0)) || (afc.Equals(2))) expected = (byte)(pi.continuityCounter);</p><p> else expected = (byte)(pi.continuityCounter + 1);</p><p> if (expected == 16) expected = 0;</p><p> if (cc != expected)</p><p> {</p><p> totalCCErrors++;</p><p> isOk = false;</p><p> }</p><p> }</p><p> pi.continuityCounter = cc;</p><p> return isOk;</p><p> }</p><p> private void CheckPcr(TsHeader header, byte[] tsPacket, ref PidInfo pi)</p><p> {</p><p> if (!pi.shouldCheck) return;</p><p> if (!PacketContainsPcr(header, tsPacket)) return;</p><p> Pcr pcr = new Pcr(tsPacket);</p><p> if (pi.lastPcr.isValid)</p><p> {</p><p> TimeSpan diff = pcr.ToDateTime() - pi.lastPcr.ToDateTime();</p><p> if (diff.TotalSeconds > diffAllowed)</p><p> {</p><p>// pi.pcrErrorTexts.Add("last pcr: " + pi.lastPcr.ToDateTime().ToString("HH:MM:ss") + " current pcr: " + pcr.ToDateTime().ToString("HH:MM:ss"));</p><p> pi.pcrErrorTexts.Add("pcr last: " + pi.lastPcr.ToDateTime().ToString("HH:MM:ss") + " current: " + pcr.ToDateTime().ToString("HH:MM:ss") + " diff: " + diff.TotalSeconds.ToString() + " seconds");</p><p> totalPcrErrors++;</p><p> }</p><p> }</p><p> pi.lastPcr = pcr;</p><p> }</p><p> private void CheckPtsDts(TsHeader header, byte[] tsPacket, ref PidInfo pi)</p><p> {</p><p> if (!pi.shouldCheck) return;</p><p> ulong offset = PacketContainsPtsDts(header, tsPacket, ref pi);</p><p> if (offset == 0) return;</p><p> Pcr pts; Pcr dts;</p><p> PcrUtils.DecodePtsDts(tsPacket, offset, out pts, out dts);</p><p> if (pi.lastPts.isValid)</p><p> {</p><p> TimeSpan diff = pts.ToDateTime() - pi.lastPts.ToDateTime();</p><p> if (diff.TotalSeconds > diffAllowed)</p><p> {</p><p>// pi.ptsErrorTexts.Add("last pts: " + pi.lastPts.ToDateTime().ToString("HH:MM:ss") + " current pts: " + pts.ToDateTime().ToString("HH:MM:ss"));</p><p> pi.ptsErrorTexts.Add("pts last: " + pi.lastPts.ToDateTime().ToString("HH:MM:ss") + " current: " + pts.ToDateTime().ToString("HH:MM:ss") + " diff: " + diff.TotalSeconds.ToString() + " seconds");</p><p> totalPtsErrors++;</p><p> }</p><p> }</p><p> pi.lastPts = pts;</p><p> }</p><p> #endregion</p><p></p><p> #region Constructor</p><p> public PacketChecker(double maxAllowedPcrDiff)</p><p> {</p><p> droppedPackets = 0;</p><p> nullPackets = 0;</p><p> totalCCErrors = 0;</p><p> totalPcrErrors = 0;</p><p> totalPtsErrors = 0;</p><p> totalPayloadStartErrors = 0;</p><p> diffAllowed = maxAllowedPcrDiff;</p><p> pids = new SortedDictionary<ushort, PidInfo>();</p><p> }</p><p> #endregion</p><p></p><p> #region Public methods</p><p> public void AddPidsToCheck(List<ushort> streamPids)</p><p> {</p><p> foreach (ushort pid in streamPids)</p><p> {</p><p> if (pids.ContainsKey(pid))</p><p> pids[pid].shouldCheck = true;</p><p> }</p><p> }</p><p> public void ProcessPacket(byte[] tsPacket,TsHeader header)</p><p> {</p><p> if (header.TransportError)</p><p> {</p><p> droppedPackets++;</p><p> return;</p><p> }</p><p> if (!pids.ContainsKey(header.Pid))</p><p> pids.Add(header.Pid, new PidInfo());</p><p></p><p> PidInfo pi = pids[header.Pid];</p><p>// ISO/IEC 13818-1: "In the case of a null packet the value of the continuity_counter is undefined."</p><p> if (header.Pid == 0x1fff) nullPackets++;</p><p> else CheckContinuityCounter((byte)(tsPacket[3]), ref pi); // check continuity_counter if no null packet</p><p> if (header.Pid > 0x1f) // don't check pids which contain SI information</p><p> {</p><p> CheckPcr(header, tsPacket, ref pi);</p><p> CheckPtsDts(header, tsPacket, ref pi);</p><p> }</p><p> pids[header.Pid] = pi;</p><p> }</p><p></p><p> public string GetStatistics()</p><p> {</p><p> return "null packets=" + nullPackets.ToString() + " dropped packets=" + droppedPackets.ToString() + " cc errors=" + totalCCErrors.ToString() + " pcr holes=" + totalPcrErrors.ToString() + " pts holes=" + totalPtsErrors.ToString() + " total payloadstart errors=" + totalPayloadStartErrors.ToString();</p><p> }</p><p> public string GetErrorDetails()</p><p> {</p><p> string log = "";</p><p> foreach (ushort pid in pids.Keys)</p><p> {</p><p> if (pids[pid].HasErrors())</p><p> {</p><p> PidInfo pi = pids[pid];</p><p> log+="Pid 0x" + pid.ToString("x")+Environment.NewLine;</p><p> if (pi.pcrErrorTexts.Count > 0)</p><p> {</p><p> log+=" - pcr errors=" + pi.pcrErrorTexts.Count.ToString()+Environment.NewLine;</p><p> foreach (string s in pi.pcrErrorTexts)</p><p>// log=" ->" + s+Environment.NewLine;</p><p> log+=" ->" + s+Environment.NewLine;</p><p> }</p><p> if (pi.ptsErrorTexts.Count > 0)</p><p> {</p><p> log+=" - pts errors=" + pi.ptsErrorTexts.Count.ToString()+Environment.NewLine;</p><p> foreach (string s in pi.ptsErrorTexts)</p><p> log+=" ->" + s+Environment.NewLine;</p><p> }</p><p> if (pi.payloadStartErrorTexts.Count > 0)</p><p> {</p><p> log+=" - payloadStart errors=" + pi.payloadStartErrorTexts.Count.ToString()+Environment.NewLine;</p><p> foreach (string s in pi.payloadStartErrorTexts)</p><p> log+=" ->" + s+Environment.NewLine;</p><p> }</p><p> }</p><p> }</p><p> return log;</p><p> }</p><p> #endregion</p><p> }</p><p>}[/code]</p><p></p><p>und eine optische Überarbeitumg in Form1.Designer.cs:</p><p></p><p>[code]namespace TsPacketChecker</p><p>{</p><p> partial class Form1</p><p> {</p><p> /// <summary></p><p> /// Required designer variable.</p><p> /// </summary></p><p> private System.ComponentModel.IContainer components = null;</p><p></p><p> /// <summary></p><p> /// Clean up any resources being used.</p><p> /// </summary></p><p> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param></p><p> protected override void Dispose(bool disposing)</p><p> {</p><p> if (disposing && (components != null))</p><p> {</p><p> components.Dispose();</p><p> }</p><p> base.Dispose(disposing);</p><p> }</p><p></p><p> #region Windows Form Designer generated code</p><p></p><p> /// <summary></p><p> /// Required method for Designer support - do not modify</p><p> /// the contents of this method with the code editor.</p><p> /// </summary></p><p> private void InitializeComponent()</p><p> {</p><p> this.splitContainer2 = new System.Windows.Forms.SplitContainer();</p><p> this.TrSections = new System.Windows.Forms.TreeView();</p><p> this.splitContainer3 = new System.Windows.Forms.SplitContainer();</p><p> this.PrBar = new System.Windows.Forms.ProgressBar();</p><p> this.btnStop = new System.Windows.Forms.Button();</p><p> this.edPcrDiff = new System.Windows.Forms.TextBox();</p><p> this.label2 = new System.Windows.Forms.Label();</p><p> this.btnAnalyze = new System.Windows.Forms.Button();</p><p> this.edLog = new System.Windows.Forms.TextBox();</p><p> this.openDlg = new System.Windows.Forms.OpenFileDialog();</p><p> this.menuStrip1 = new System.Windows.Forms.MenuStrip();</p><p> this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();</p><p> this.opentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();</p><p> this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator();</p><p> this.importFromXMLToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();</p><p> this.exportToXMLToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();</p><p> this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator();</p><p> this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();</p><p> this.saveDlg = new System.Windows.Forms.SaveFileDialog();</p><p> this.splitContainer2.Panel1.SuspendLayout();</p><p> this.splitContainer2.Panel2.SuspendLayout();</p><p> this.splitContainer2.SuspendLayout();</p><p> this.splitContainer3.Panel1.SuspendLayout();</p><p> this.splitContainer3.Panel2.SuspendLayout();</p><p> this.splitContainer3.SuspendLayout();</p><p> this.menuStrip1.SuspendLayout();</p><p> this.SuspendLayout();</p><p> //</p><p> // splitContainer2</p><p> //</p><p> this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill;</p><p> this.splitContainer2.Location = new System.Drawing.Point(0, 24);</p><p> this.splitContainer2.Name = "splitContainer2";</p><p> //</p><p> // splitContainer2.Panel1</p><p> //</p><p> this.splitContainer2.Panel1.Controls.Add(this.TrSections);</p><p> //</p><p> // splitContainer2.Panel2</p><p> //</p><p> this.splitContainer2.Panel2.Controls.Add(this.splitContainer3);</p><p> this.splitContainer2.Size = new System.Drawing.Size(1038, 654);</p><p> this.splitContainer2.SplitterDistance = 167;</p><p> this.splitContainer2.TabIndex = 0;</p><p> //</p><p> // TrSections</p><p> //</p><p> this.TrSections.Dock = System.Windows.Forms.DockStyle.Fill;</p><p> this.TrSections.Location = new System.Drawing.Point(0, 0);</p><p> this.TrSections.Name = "TrSections";</p><p> this.TrSections.Size = new System.Drawing.Size(167, 654);</p><p> this.TrSections.TabIndex = 0;</p><p> //</p><p> // splitContainer3</p><p> //</p><p> this.splitContainer3.Dock = System.Windows.Forms.DockStyle.Fill;</p><p> this.splitContainer3.FixedPanel = System.Windows.Forms.FixedPanel.Panel1;</p><p> this.splitContainer3.Location = new System.Drawing.Point(0, 0);</p><p> this.splitContainer3.Name = "splitContainer3";</p><p> this.splitContainer3.Orientation = System.Windows.Forms.Orientation.Horizontal;</p><p> //</p><p> // splitContainer3.Panel1</p><p> //</p><p> this.splitContainer3.Panel1.Controls.Add(this.PrBar);</p><p> this.splitContainer3.Panel1.Controls.Add(this.btnStop);</p><p> this.splitContainer3.Panel1.Controls.Add(this.edPcrDiff);</p><p> this.splitContainer3.Panel1.Controls.Add(this.label2);</p><p> this.splitContainer3.Panel1.Controls.Add(this.btnAnalyze);</p><p> //</p><p> // splitContainer3.Panel2</p><p> //</p><p> this.splitContainer3.Panel2.Controls.Add(this.edLog);</p><p> this.splitContainer3.Size = new System.Drawing.Size(867, 654);</p><p> this.splitContainer3.SplitterDistance = 77;</p><p> this.splitContainer3.TabIndex = 0;</p><p> //</p><p> // PrBar</p><p> //</p><p> this.PrBar.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)</p><p> | System.Windows.Forms.AnchorStyles.Right)));</p><p> this.PrBar.Location = new System.Drawing.Point(102, 43);</p><p> this.PrBar.Name = "PrBar";</p><p> this.PrBar.Size = new System.Drawing.Size(752, 23);</p><p> this.PrBar.Step = 1;</p><p> this.PrBar.TabIndex = 4;</p><p> //</p><p> // btnStop</p><p> //</p><p> this.btnStop.Location = new System.Drawing.Point(13, 43);</p><p> this.btnStop.Name = "btnStop";</p><p> this.btnStop.Size = new System.Drawing.Size(75, 23);</p><p> this.btnStop.TabIndex = 3;</p><p> this.btnStop.Text = "Stop";</p><p> this.btnStop.UseVisualStyleBackColor = true;</p><p> this.btnStop.Click += new System.EventHandler(this.btnStop_Click);</p><p> //</p><p> // edPcrDiff</p><p> //</p><p> this.edPcrDiff.Location = new System.Drawing.Point(299, 15);</p><p> this.edPcrDiff.Name = "edPcrDiff";</p><p> this.edPcrDiff.Size = new System.Drawing.Size(100, 20);</p><p> this.edPcrDiff.TabIndex = 2;</p><p> this.edPcrDiff.Text = "10";</p><p> //</p><p> // label2</p><p> //</p><p> this.label2.AutoSize = true;</p><p> this.label2.Location = new System.Drawing.Point(100, 18);</p><p> this.label2.Name = "label2";</p><p> this.label2.Size = new System.Drawing.Size(187, 13);</p><p> this.label2.TabIndex = 1;</p><p> this.label2.Text = "Max Pcr/Pts diff (clock value) [seconds]";</p><p> //</p><p> // btnAnalyze</p><p> //</p><p> this.btnAnalyze.Location = new System.Drawing.Point(13, 13);</p><p> this.btnAnalyze.Name = "btnAnalyze";</p><p> this.btnAnalyze.Size = new System.Drawing.Size(75, 23);</p><p> this.btnAnalyze.TabIndex = 0;</p><p> this.btnAnalyze.Text = "Analyze";</p><p> this.btnAnalyze.UseVisualStyleBackColor = true;</p><p> this.btnAnalyze.Click += new System.EventHandler(this.btnAnalyze_Click);</p><p> //</p><p> // edLog</p><p> //</p><p> this.edLog.Dock = System.Windows.Forms.DockStyle.Fill;</p><p> this.edLog.Location = new System.Drawing.Point(0, 0);</p><p> this.edLog.Multiline = true;</p><p> this.edLog.Name = "edLog";</p><p> this.edLog.ScrollBars = System.Windows.Forms.ScrollBars.Both;</p><p> this.edLog.Size = new System.Drawing.Size(867, 573);</p><p> this.edLog.TabIndex = 0;</p><p> //</p><p> // openDlg</p><p> //</p><p> this.openDlg.FileName = "openFileDialog1";</p><p> this.openDlg.Filter = "Ts Files (*.ts)|*.ts";</p><p> this.openDlg.RestoreDirectory = true;</p><p> //</p><p> // menuStrip1</p><p> //</p><p> this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {</p><p> this.fileToolStripMenuItem});</p><p> this.menuStrip1.Location = new System.Drawing.Point(0, 0);</p><p> this.menuStrip1.Name = "menuStrip1";</p><p> this.menuStrip1.Size = new System.Drawing.Size(1038, 24);</p><p> this.menuStrip1.TabIndex = 1;</p><p> this.menuStrip1.Text = "menuStrip1";</p><p> //</p><p> // fileToolStripMenuItem</p><p> //</p><p> this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {</p><p> this.opentsToolStripMenuItem,</p><p> this.toolStripMenuItem1,</p><p> this.importFromXMLToolStripMenuItem,</p><p> this.exportToXMLToolStripMenuItem,</p><p> this.toolStripMenuItem2,</p><p> this.exitToolStripMenuItem});</p><p> this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";</p><p> this.fileToolStripMenuItem.Size = new System.Drawing.Size(35, 20);</p><p> this.fileToolStripMenuItem.Text = "File";</p><p> //</p><p> // opentsToolStripMenuItem</p><p> //</p><p> this.opentsToolStripMenuItem.Name = "opentsToolStripMenuItem";</p><p> this.opentsToolStripMenuItem.Size = new System.Drawing.Size(164, 22);</p><p> this.opentsToolStripMenuItem.Text = "Open .ts file";</p><p> this.opentsToolStripMenuItem.Click += new System.EventHandler(this.opentsToolStripMenuItem_Click);</p><p> //</p><p> // toolStripMenuItem1</p><p> //</p><p> this.toolStripMenuItem1.Name = "toolStripMenuItem1";</p><p> this.toolStripMenuItem1.Size = new System.Drawing.Size(161, 6);</p><p> //</p><p> // importFromXMLToolStripMenuItem</p><p> //</p><p> this.importFromXMLToolStripMenuItem.Name = "importFromXMLToolStripMenuItem";</p><p> this.importFromXMLToolStripMenuItem.Size = new System.Drawing.Size(164, 22);</p><p> this.importFromXMLToolStripMenuItem.Text = "Import from XML";</p><p> this.importFromXMLToolStripMenuItem.Click += new System.EventHandler(this.importFromXMLToolStripMenuItem_Click);</p><p> //</p><p> // exportToXMLToolStripMenuItem</p><p> //</p><p> this.exportToXMLToolStripMenuItem.Name = "exportToXMLToolStripMenuItem";</p><p> this.exportToXMLToolStripMenuItem.Size = new System.Drawing.Size(164, 22);</p><p> this.exportToXMLToolStripMenuItem.Text = "Export to XML";</p><p> this.exportToXMLToolStripMenuItem.Click += new System.EventHandler(this.exportToXMLToolStripMenuItem_Click);</p><p> //</p><p> // toolStripMenuItem2</p><p> //</p><p> this.toolStripMenuItem2.Name = "toolStripMenuItem2";</p><p> this.toolStripMenuItem2.Size = new System.Drawing.Size(161, 6);</p><p> //</p><p> // exitToolStripMenuItem</p><p> //</p><p> this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";</p><p> this.exitToolStripMenuItem.Size = new System.Drawing.Size(164, 22);</p><p> this.exitToolStripMenuItem.Text = "Exit";</p><p> this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);</p><p> //</p><p> // saveDlg</p><p> //</p><p> this.saveDlg.DefaultExt = "xml";</p><p> this.saveDlg.Filter = "XML Files (*.xml)|*.xml";</p><p> this.saveDlg.RestoreDirectory = true;</p><p> //</p><p> // Form1</p><p> //</p><p> this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);</p><p> this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;</p><p> this.ClientSize = new System.Drawing.Size(1038, 678);</p><p> this.Controls.Add(this.splitContainer2);</p><p> this.Controls.Add(this.menuStrip1);</p><p> this.Name = "Form1";</p><p> this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;</p><p> this.Text = "TsPacketChecker (by gemx)";</p><p> this.splitContainer2.Panel1.ResumeLayout(false);</p><p> this.splitContainer2.Panel2.ResumeLayout(false);</p><p> this.splitContainer2.ResumeLayout(false);</p><p> this.splitContainer3.Panel1.ResumeLayout(false);</p><p> this.splitContainer3.Panel1.PerformLayout();</p><p> this.splitContainer3.Panel2.ResumeLayout(false);</p><p> this.splitContainer3.Panel2.PerformLayout();</p><p> this.splitContainer3.ResumeLayout(false);</p><p> this.menuStrip1.ResumeLayout(false);</p><p> this.menuStrip1.PerformLayout();</p><p> this.ResumeLayout(false);</p><p> this.PerformLayout();</p><p></p><p> }</p><p></p><p> #endregion</p><p></p><p> private System.Windows.Forms.OpenFileDialog openDlg;</p><p> private System.Windows.Forms.SplitContainer splitContainer2;</p><p> private System.Windows.Forms.SplitContainer splitContainer3;</p><p> private System.Windows.Forms.TextBox edPcrDiff;</p><p> private System.Windows.Forms.Label label2;</p><p> private System.Windows.Forms.Button btnAnalyze;</p><p> private System.Windows.Forms.TextBox edLog;</p><p> private System.Windows.Forms.Button btnStop;</p><p> private System.Windows.Forms.ProgressBar PrBar;</p><p> private System.Windows.Forms.TreeView TrSections;</p><p> private System.Windows.Forms.MenuStrip menuStrip1;</p><p> private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;</p><p> private System.Windows.Forms.ToolStripMenuItem opentsToolStripMenuItem;</p><p> private System.Windows.Forms.ToolStripSeparator toolStripMenuItem1;</p><p> private System.Windows.Forms.ToolStripMenuItem importFromXMLToolStripMenuItem;</p><p> private System.Windows.Forms.ToolStripMenuItem exportToXMLToolStripMenuItem;</p><p> private System.Windows.Forms.ToolStripSeparator toolStripMenuItem2;</p><p> private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;</p><p> private System.Windows.Forms.SaveFileDialog saveDlg;</p><p></p><p> }</p><p>}</p><p>[/code]</p></blockquote><p></p>
[QUOTE="alexi, post: 1261439, member: 101499"] noch ein bugfix: [code]// return (header.HasAdaptionField && (tsPacket[5] & 0x10) == 0x10); // ISO/IEC 13818-1: "The adaptation_field_length is an 8-bit field specifying the number of bytes in the adaptation_field immediately following the adaptation_field_length. // The value 0 is for inserting a single stuffing byte in a Transport Stream packet." -> if (adaptation_field_length > 0) return (header.HasAdaptionField && (tsPacket[5] & 0x10) == 0x10) && (header.AdaptionFieldLength > 0); [/code] in PacketChecks.cs (komplett): [code]using System; using System.Collections.Generic; using System.Text; namespace TsPacketChecker { class PacketChecker { private long droppedPackets; private long nullPackets; private long totalCCErrors; private long totalPcrErrors; private long totalPtsErrors; private long totalPayloadStartErrors; private double diffAllowed; private SortedDictionary<ushort, PidInfo> pids = new SortedDictionary<ushort, PidInfo>(); #region Existence checks private bool PacketContainsPcr(TsHeader header, byte[] tsPacket) { // return (header.HasAdaptionField && (tsPacket[5] & 0x10) == 0x10); // ISO/IEC 13818-1: "The adaptation_field_length is an 8-bit field specifying the number of bytes in the adaptation_field immediately following the adaptation_field_length. // The value 0 is for inserting a single stuffing byte in a Transport Stream packet." -> if (adaptation_field_length > 0) return (header.HasAdaptionField && (tsPacket[5] & 0x10) == 0x10) && (header.AdaptionFieldLength > 0); } private ulong PacketContainsPtsDts(TsHeader header, byte[] tsPacket, ref PidInfo pi) { if (!header.PayloadUnitStart) return 0; if (header.PayLoadStart > 185 && header.HasPayload) { totalPayloadStartErrors++; pi.payloadStartErrorTexts.Add(" payloadStart=" + header.PayLoadStart.ToString() + " HasAdaption=" + header.HasAdaptionField.ToString() + " HasPayload=" + header.HasPayload.ToString() + " AdaptionFieldSize=" + tsPacket[4].ToString()); return 0; } if (!header.HasPayload) return 0; return header.PayLoadStart; } #endregion #region Continuity checks private bool CheckContinuityCounter(byte tsPacket3, ref PidInfo pi) { bool isOk = true; byte cc = (byte)(tsPacket3 & 0xF); if (pi.continuityCounter != 0xFF) { byte afc = (byte)((tsPacket3 >> 4) & 0x3); byte expected; // ISO/IEC 13818-1: "The continuity_counter shall not be incremented when the adaptation_field_control of the packet equals '00' or '10'." (binary) if ((afc.Equals(0)) || (afc.Equals(2))) expected = (byte)(pi.continuityCounter); else expected = (byte)(pi.continuityCounter + 1); if (expected == 16) expected = 0; if (cc != expected) { totalCCErrors++; isOk = false; } } pi.continuityCounter = cc; return isOk; } private void CheckPcr(TsHeader header, byte[] tsPacket, ref PidInfo pi) { if (!pi.shouldCheck) return; if (!PacketContainsPcr(header, tsPacket)) return; Pcr pcr = new Pcr(tsPacket); if (pi.lastPcr.isValid) { TimeSpan diff = pcr.ToDateTime() - pi.lastPcr.ToDateTime(); if (diff.TotalSeconds > diffAllowed) { // pi.pcrErrorTexts.Add("last pcr: " + pi.lastPcr.ToDateTime().ToString("HH:MM:ss") + " current pcr: " + pcr.ToDateTime().ToString("HH:MM:ss")); pi.pcrErrorTexts.Add("pcr last: " + pi.lastPcr.ToDateTime().ToString("HH:MM:ss") + " current: " + pcr.ToDateTime().ToString("HH:MM:ss") + " diff: " + diff.TotalSeconds.ToString() + " seconds"); totalPcrErrors++; } } pi.lastPcr = pcr; } private void CheckPtsDts(TsHeader header, byte[] tsPacket, ref PidInfo pi) { if (!pi.shouldCheck) return; ulong offset = PacketContainsPtsDts(header, tsPacket, ref pi); if (offset == 0) return; Pcr pts; Pcr dts; PcrUtils.DecodePtsDts(tsPacket, offset, out pts, out dts); if (pi.lastPts.isValid) { TimeSpan diff = pts.ToDateTime() - pi.lastPts.ToDateTime(); if (diff.TotalSeconds > diffAllowed) { // pi.ptsErrorTexts.Add("last pts: " + pi.lastPts.ToDateTime().ToString("HH:MM:ss") + " current pts: " + pts.ToDateTime().ToString("HH:MM:ss")); pi.ptsErrorTexts.Add("pts last: " + pi.lastPts.ToDateTime().ToString("HH:MM:ss") + " current: " + pts.ToDateTime().ToString("HH:MM:ss") + " diff: " + diff.TotalSeconds.ToString() + " seconds"); totalPtsErrors++; } } pi.lastPts = pts; } #endregion #region Constructor public PacketChecker(double maxAllowedPcrDiff) { droppedPackets = 0; nullPackets = 0; totalCCErrors = 0; totalPcrErrors = 0; totalPtsErrors = 0; totalPayloadStartErrors = 0; diffAllowed = maxAllowedPcrDiff; pids = new SortedDictionary<ushort, PidInfo>(); } #endregion #region Public methods public void AddPidsToCheck(List<ushort> streamPids) { foreach (ushort pid in streamPids) { if (pids.ContainsKey(pid)) pids[pid].shouldCheck = true; } } public void ProcessPacket(byte[] tsPacket,TsHeader header) { if (header.TransportError) { droppedPackets++; return; } if (!pids.ContainsKey(header.Pid)) pids.Add(header.Pid, new PidInfo()); PidInfo pi = pids[header.Pid]; // ISO/IEC 13818-1: "In the case of a null packet the value of the continuity_counter is undefined." if (header.Pid == 0x1fff) nullPackets++; else CheckContinuityCounter((byte)(tsPacket[3]), ref pi); // check continuity_counter if no null packet if (header.Pid > 0x1f) // don't check pids which contain SI information { CheckPcr(header, tsPacket, ref pi); CheckPtsDts(header, tsPacket, ref pi); } pids[header.Pid] = pi; } public string GetStatistics() { return "null packets=" + nullPackets.ToString() + " dropped packets=" + droppedPackets.ToString() + " cc errors=" + totalCCErrors.ToString() + " pcr holes=" + totalPcrErrors.ToString() + " pts holes=" + totalPtsErrors.ToString() + " total payloadstart errors=" + totalPayloadStartErrors.ToString(); } public string GetErrorDetails() { string log = ""; foreach (ushort pid in pids.Keys) { if (pids[pid].HasErrors()) { PidInfo pi = pids[pid]; log+="Pid 0x" + pid.ToString("x")+Environment.NewLine; if (pi.pcrErrorTexts.Count > 0) { log+=" - pcr errors=" + pi.pcrErrorTexts.Count.ToString()+Environment.NewLine; foreach (string s in pi.pcrErrorTexts) // log=" ->" + s+Environment.NewLine; log+=" ->" + s+Environment.NewLine; } if (pi.ptsErrorTexts.Count > 0) { log+=" - pts errors=" + pi.ptsErrorTexts.Count.ToString()+Environment.NewLine; foreach (string s in pi.ptsErrorTexts) log+=" ->" + s+Environment.NewLine; } if (pi.payloadStartErrorTexts.Count > 0) { log+=" - payloadStart errors=" + pi.payloadStartErrorTexts.Count.ToString()+Environment.NewLine; foreach (string s in pi.payloadStartErrorTexts) log+=" ->" + s+Environment.NewLine; } } } return log; } #endregion } }[/code] und eine optische Überarbeitumg in Form1.Designer.cs: [code]namespace TsPacketChecker { partial class Form1 { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null; /// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { this.splitContainer2 = new System.Windows.Forms.SplitContainer(); this.TrSections = new System.Windows.Forms.TreeView(); this.splitContainer3 = new System.Windows.Forms.SplitContainer(); this.PrBar = new System.Windows.Forms.ProgressBar(); this.btnStop = new System.Windows.Forms.Button(); this.edPcrDiff = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.btnAnalyze = new System.Windows.Forms.Button(); this.edLog = new System.Windows.Forms.TextBox(); this.openDlg = new System.Windows.Forms.OpenFileDialog(); this.menuStrip1 = new System.Windows.Forms.MenuStrip(); this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.opentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator(); this.importFromXMLToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.exportToXMLToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator(); this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.saveDlg = new System.Windows.Forms.SaveFileDialog(); this.splitContainer2.Panel1.SuspendLayout(); this.splitContainer2.Panel2.SuspendLayout(); this.splitContainer2.SuspendLayout(); this.splitContainer3.Panel1.SuspendLayout(); this.splitContainer3.Panel2.SuspendLayout(); this.splitContainer3.SuspendLayout(); this.menuStrip1.SuspendLayout(); this.SuspendLayout(); // // splitContainer2 // this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill; this.splitContainer2.Location = new System.Drawing.Point(0, 24); this.splitContainer2.Name = "splitContainer2"; // // splitContainer2.Panel1 // this.splitContainer2.Panel1.Controls.Add(this.TrSections); // // splitContainer2.Panel2 // this.splitContainer2.Panel2.Controls.Add(this.splitContainer3); this.splitContainer2.Size = new System.Drawing.Size(1038, 654); this.splitContainer2.SplitterDistance = 167; this.splitContainer2.TabIndex = 0; // // TrSections // this.TrSections.Dock = System.Windows.Forms.DockStyle.Fill; this.TrSections.Location = new System.Drawing.Point(0, 0); this.TrSections.Name = "TrSections"; this.TrSections.Size = new System.Drawing.Size(167, 654); this.TrSections.TabIndex = 0; // // splitContainer3 // this.splitContainer3.Dock = System.Windows.Forms.DockStyle.Fill; this.splitContainer3.FixedPanel = System.Windows.Forms.FixedPanel.Panel1; this.splitContainer3.Location = new System.Drawing.Point(0, 0); this.splitContainer3.Name = "splitContainer3"; this.splitContainer3.Orientation = System.Windows.Forms.Orientation.Horizontal; // // splitContainer3.Panel1 // this.splitContainer3.Panel1.Controls.Add(this.PrBar); this.splitContainer3.Panel1.Controls.Add(this.btnStop); this.splitContainer3.Panel1.Controls.Add(this.edPcrDiff); this.splitContainer3.Panel1.Controls.Add(this.label2); this.splitContainer3.Panel1.Controls.Add(this.btnAnalyze); // // splitContainer3.Panel2 // this.splitContainer3.Panel2.Controls.Add(this.edLog); this.splitContainer3.Size = new System.Drawing.Size(867, 654); this.splitContainer3.SplitterDistance = 77; this.splitContainer3.TabIndex = 0; // // PrBar // this.PrBar.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.PrBar.Location = new System.Drawing.Point(102, 43); this.PrBar.Name = "PrBar"; this.PrBar.Size = new System.Drawing.Size(752, 23); this.PrBar.Step = 1; this.PrBar.TabIndex = 4; // // btnStop // this.btnStop.Location = new System.Drawing.Point(13, 43); this.btnStop.Name = "btnStop"; this.btnStop.Size = new System.Drawing.Size(75, 23); this.btnStop.TabIndex = 3; this.btnStop.Text = "Stop"; this.btnStop.UseVisualStyleBackColor = true; this.btnStop.Click += new System.EventHandler(this.btnStop_Click); // // edPcrDiff // this.edPcrDiff.Location = new System.Drawing.Point(299, 15); this.edPcrDiff.Name = "edPcrDiff"; this.edPcrDiff.Size = new System.Drawing.Size(100, 20); this.edPcrDiff.TabIndex = 2; this.edPcrDiff.Text = "10"; // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(100, 18); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(187, 13); this.label2.TabIndex = 1; this.label2.Text = "Max Pcr/Pts diff (clock value) [seconds]"; // // btnAnalyze // this.btnAnalyze.Location = new System.Drawing.Point(13, 13); this.btnAnalyze.Name = "btnAnalyze"; this.btnAnalyze.Size = new System.Drawing.Size(75, 23); this.btnAnalyze.TabIndex = 0; this.btnAnalyze.Text = "Analyze"; this.btnAnalyze.UseVisualStyleBackColor = true; this.btnAnalyze.Click += new System.EventHandler(this.btnAnalyze_Click); // // edLog // this.edLog.Dock = System.Windows.Forms.DockStyle.Fill; this.edLog.Location = new System.Drawing.Point(0, 0); this.edLog.Multiline = true; this.edLog.Name = "edLog"; this.edLog.ScrollBars = System.Windows.Forms.ScrollBars.Both; this.edLog.Size = new System.Drawing.Size(867, 573); this.edLog.TabIndex = 0; // // openDlg // this.openDlg.FileName = "openFileDialog1"; this.openDlg.Filter = "Ts Files (*.ts)|*.ts"; this.openDlg.RestoreDirectory = true; // // menuStrip1 // this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.fileToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Size = new System.Drawing.Size(1038, 24); this.menuStrip1.TabIndex = 1; this.menuStrip1.Text = "menuStrip1"; // // fileToolStripMenuItem // this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.opentsToolStripMenuItem, this.toolStripMenuItem1, this.importFromXMLToolStripMenuItem, this.exportToXMLToolStripMenuItem, this.toolStripMenuItem2, this.exitToolStripMenuItem}); this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; this.fileToolStripMenuItem.Size = new System.Drawing.Size(35, 20); this.fileToolStripMenuItem.Text = "File"; // // opentsToolStripMenuItem // this.opentsToolStripMenuItem.Name = "opentsToolStripMenuItem"; this.opentsToolStripMenuItem.Size = new System.Drawing.Size(164, 22); this.opentsToolStripMenuItem.Text = "Open .ts file"; this.opentsToolStripMenuItem.Click += new System.EventHandler(this.opentsToolStripMenuItem_Click); // // toolStripMenuItem1 // this.toolStripMenuItem1.Name = "toolStripMenuItem1"; this.toolStripMenuItem1.Size = new System.Drawing.Size(161, 6); // // importFromXMLToolStripMenuItem // this.importFromXMLToolStripMenuItem.Name = "importFromXMLToolStripMenuItem"; this.importFromXMLToolStripMenuItem.Size = new System.Drawing.Size(164, 22); this.importFromXMLToolStripMenuItem.Text = "Import from XML"; this.importFromXMLToolStripMenuItem.Click += new System.EventHandler(this.importFromXMLToolStripMenuItem_Click); // // exportToXMLToolStripMenuItem // this.exportToXMLToolStripMenuItem.Name = "exportToXMLToolStripMenuItem"; this.exportToXMLToolStripMenuItem.Size = new System.Drawing.Size(164, 22); this.exportToXMLToolStripMenuItem.Text = "Export to XML"; this.exportToXMLToolStripMenuItem.Click += new System.EventHandler(this.exportToXMLToolStripMenuItem_Click); // // toolStripMenuItem2 // this.toolStripMenuItem2.Name = "toolStripMenuItem2"; this.toolStripMenuItem2.Size = new System.Drawing.Size(161, 6); // // exitToolStripMenuItem // this.exitToolStripMenuItem.Name = "exitToolStripMenuItem"; this.exitToolStripMenuItem.Size = new System.Drawing.Size(164, 22); this.exitToolStripMenuItem.Text = "Exit"; this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click); // // saveDlg // this.saveDlg.DefaultExt = "xml"; this.saveDlg.Filter = "XML Files (*.xml)|*.xml"; this.saveDlg.RestoreDirectory = true; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(1038, 678); this.Controls.Add(this.splitContainer2); this.Controls.Add(this.menuStrip1); this.Name = "Form1"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "TsPacketChecker (by gemx)"; this.splitContainer2.Panel1.ResumeLayout(false); this.splitContainer2.Panel2.ResumeLayout(false); this.splitContainer2.ResumeLayout(false); this.splitContainer3.Panel1.ResumeLayout(false); this.splitContainer3.Panel1.PerformLayout(); this.splitContainer3.Panel2.ResumeLayout(false); this.splitContainer3.Panel2.PerformLayout(); this.splitContainer3.ResumeLayout(false); this.menuStrip1.ResumeLayout(false); this.menuStrip1.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.OpenFileDialog openDlg; private System.Windows.Forms.SplitContainer splitContainer2; private System.Windows.Forms.SplitContainer splitContainer3; private System.Windows.Forms.TextBox edPcrDiff; private System.Windows.Forms.Label label2; private System.Windows.Forms.Button btnAnalyze; private System.Windows.Forms.TextBox edLog; private System.Windows.Forms.Button btnStop; private System.Windows.Forms.ProgressBar PrBar; private System.Windows.Forms.TreeView TrSections; private System.Windows.Forms.MenuStrip menuStrip1; private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem opentsToolStripMenuItem; private System.Windows.Forms.ToolStripSeparator toolStripMenuItem1; private System.Windows.Forms.ToolStripMenuItem importFromXMLToolStripMenuItem; private System.Windows.Forms.ToolStripMenuItem exportToXMLToolStripMenuItem; private System.Windows.Forms.ToolStripSeparator toolStripMenuItem2; private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem; private System.Windows.Forms.SaveFileDialog saveDlg; } } [/code] [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Language specific support
Deutsches MediaPortal Forum
Allgemein
Einsteigerforum
TS Packet Checker
Contact us
RSS
Top
Bottom