private void Finish(bool keepProcessedFrames) { mFinishTime = DateTime.Now; Duration = mFinishTime - mStartTime; Compression = EncodedSize / (double)RawSize; int seconds = RawFrames.Count / VideoQualityController.AcceptFramesPerSecond; Kbps = (EncodedSize / seconds) / 1024; Fidelity = CalculateFidelity(RawFrames, ProcessedFrames); const int blocksPerFrame = (VideoConstants.Height / VideoConstants.VideoBlockSize) * (VideoConstants.Width / VideoConstants.VideoBlockSize); float totalBlocks = RawFrames.Count * blocksPerFrame; BlocksAsDelta = blocksAsDelta / totalBlocks; BlocksAsJpeg = blocksAsJpeg / totalBlocks; BlocksNotSent = (totalBlocks - (blocksAsDelta + blocksAsJpeg)) / totalBlocks; DeltaBlockSize = bytesAsDelta / (double)blocksAsDelta; JpegBlockSize = bytesAsJpeg / (double)blocksAsJpeg; // Release references to potentially large objects we won't need anymore RawFrames = null; VideoCodec = null; if (!keepProcessedFrames) { ProcessedFrames.Clear(); } KeepProcessedFrames = keepProcessedFrames; }
public void Execute(bool keepProcessedFrames) { mStartTime = DateTime.Now; foreach (var frame in RawFrames) { // Encode the frame VideoCodec.EncodeFrame(frame, 1); var dvc = VideoCodec as JpegDiffVideoCodec; if (dvc != null) { foreach (var block in dvc.EncodedBlocks) { if (block.BlockType == BlockType.Jpeg) { blocksAsJpeg++; bytesAsJpeg += block.EncodedStream.Length; } else { blocksAsDelta++; bytesAsDelta += block.EncodedStream.Length; } } } // Decode the frame bool moreChunks = true; var buffer = mVideoChunkPool.GetNext(); while (moreChunks) { buffer.Reset(); if (VideoCodec.GetNextChunk(buffer, out moreChunks)) { EncodedSize += buffer.DataLength; VideoCodec.DecodeChunk(buffer, 2); } } mVideoChunkPool.Recycle(buffer); // Retrieve the frame var processedStream = VideoCodec.GetNextFrame(); ProcessedFrames.Add(processedStream.ToArray()); } Finish(keepProcessedFrames); }