diff --git a/MediaTester/Properties/AssemblyInfo.cs b/MediaTester/Properties/AssemblyInfo.cs index e4492c1..c889569 100644 --- a/MediaTester/Properties/AssemblyInfo.cs +++ b/MediaTester/Properties/AssemblyInfo.cs @@ -1,5 +1,4 @@ using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following @@ -32,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.3.1.0")] -[assembly: AssemblyFileVersion("0.3.1.0")] +[assembly: AssemblyVersion("0.3.2.0")] +[assembly: AssemblyFileVersion("0.3.2.0")] diff --git a/MediaTesterLib/MediaTester.cs b/MediaTesterLib/MediaTester.cs index 6a3a4ba..f81ac8e 100644 --- a/MediaTesterLib/MediaTester.cs +++ b/MediaTesterLib/MediaTester.cs @@ -2,6 +2,8 @@ using System.Diagnostics; using System.IO; using System.Linq; +using System.Threading; +using System.Threading.Tasks; namespace MediaTesterLib { @@ -504,41 +506,58 @@ private bool VerifyTestFileDataBlock(int testFileIndex, string testFilePath, int private bool VerifyTestFileDataBlock(FileStream fileReader, int fileIndex, int dataBlockIndex, out int bytesVerified, out int bytesFailed, out long readBytesPerSecond) { + byte[] knownGoodDataBlock = null; + var thread = new Thread(() => + { + knownGoodDataBlock = GenerateDataBlock(fileIndex, dataBlockIndex, DATA_BLOCK_SIZE); + }) + { + IsBackground = true + }; + thread.Start(); + var dataBlock = ReadDataBlock(fileReader, dataBlockIndex, out readBytesPerSecond); - return VerifyDataBlock(dataBlock, fileIndex, dataBlockIndex, out bytesVerified, out bytesFailed); + while (thread.ThreadState == System.Threading.ThreadState.Running) + { + Thread.Sleep(10); + } + + return VerifyDataBlock(dataBlock, fileIndex, dataBlockIndex, out bytesVerified, out bytesFailed, knownGoodDataBlock: knownGoodDataBlock); } private byte[] ReadDataBlock(FileStream fileReader, int dataBlockIndex, out long readBytesPerSecond) { - int dataBlockStartIndex = dataBlockIndex * DATA_BLOCK_SIZE; - long dataBlockSize = fileReader.Length - dataBlockStartIndex; - if (dataBlockSize > DATA_BLOCK_SIZE) - dataBlockSize = DATA_BLOCK_SIZE; + int dataBlockStartIndex = dataBlockIndex * DATA_BLOCK_SIZE; + long dataBlockSize = fileReader.Length - dataBlockStartIndex; + if (dataBlockSize > DATA_BLOCK_SIZE) + dataBlockSize = DATA_BLOCK_SIZE; - var dataBlock = new byte[(int)dataBlockSize]; + var dataBlock = new byte[(int)dataBlockSize]; - if (fileReader.Position != dataBlockStartIndex) - fileReader.Seek(dataBlockStartIndex, SeekOrigin.Begin); + if (fileReader.Position != dataBlockStartIndex) + fileReader.Seek(dataBlockStartIndex, SeekOrigin.Begin); - var stopwatch = new Stopwatch(); - stopwatch.Start(); - int readBytes = fileReader.Read(dataBlock, 0, dataBlock.Length); - stopwatch.Stop(); - readBytesPerSecond = (long)((double)readBytes / stopwatch.Elapsed.TotalSeconds); + var stopwatch = new Stopwatch(); + stopwatch.Start(); + int readBytes = fileReader.Read(dataBlock, 0, dataBlock.Length); + stopwatch.Stop(); + readBytesPerSecond = (long)((double)readBytes / stopwatch.Elapsed.TotalSeconds); - if (readBytes != dataBlock.Length) - { - Array.Resize(ref dataBlock, readBytes); - } + if (readBytes != dataBlock.Length) + { + Array.Resize(ref dataBlock, readBytes); + } - return dataBlock; + return dataBlock; } - private bool VerifyDataBlock(byte[] dataBlock, int fileIndex, int dataBlockIndex, out int bytesVerified, out int bytesFailed) + private bool VerifyDataBlock(byte[] dataBlock, int fileIndex, int dataBlockIndex, out int bytesVerified, out int bytesFailed, byte[] knownGoodDataBlock = null) { bytesVerified = 0; bytesFailed = 0; - var knownGoodDataBlock = GenerateDataBlock(fileIndex, dataBlockIndex, dataBlock.Length); + if (knownGoodDataBlock == null || knownGoodDataBlock.Length != dataBlock.Length) + knownGoodDataBlock = GenerateDataBlock(fileIndex, dataBlockIndex, dataBlock.Length); + if (dataBlock.Length > knownGoodDataBlock.Length) { bytesFailed = dataBlock.Length;