private static void RoundTripTestPattern()
        {
            var stampedTestPattern = _testPattern.Clone() as System.Drawing.Image;
            int tWidth             = _testPattern.Width;
            int tHeight            = _testPattern.Height;

            AddTimeStampAndLocation(stampedTestPattern, DateTime.UtcNow.ToString("dd MMM yyyy HH:mm:ss:fff"), "Test Pattern");
            var sampleBuffer = PixelConverter.BitmapToRGBA(stampedTestPattern as System.Drawing.Bitmap, _testPattern.Width, _testPattern.Height);

            byte[] i420 = PixelConverter.RGBAtoYUV420Planar(sampleBuffer, _testPattern.Width, _testPattern.Height);

            var encodedBuffer = _vp8Encoder.Encode(i420, false);

            Console.WriteLine($"VP8 encoded buffer length {encodedBuffer.Length}.");

            List <byte[]> i420Frames = _vp8Decoder.Decode(encodedBuffer, encodedBuffer.Length, out var dWidth, out var dHeight);

            Console.WriteLine($"VP8 decoded frames count {i420Frames.Count}, first frame length {i420Frames.First().Length}, width {dWidth}, height {dHeight}.");

            byte[] rgb = i420Frames.First();

            unsafe
            {
                fixed(byte *s = rgb)
                {
                    System.Drawing.Bitmap bmpImage = new System.Drawing.Bitmap((int)dWidth, (int)dHeight, rgb.Length / (int)dHeight, PixelFormat.Format24bppRgb, (IntPtr)s);
                    bmpImage.Save("encodedroundtrip.bmp");
                    bmpImage.Dispose();
                }
            }
        }
        private static void SendTestPattern(object state)
        {
            lock (_sendTestPatternTimer)
            {
                unsafe
                {
                    if (OnTestPatternSampleReady != null)
                    {
                        var stampedTestPattern = _testPattern.Clone() as System.Drawing.Image;
                        AddTimeStampAndLocation(stampedTestPattern, DateTime.UtcNow.ToString("dd MMM yyyy HH:mm:ss:fff"), "Test Pattern");
                        var sampleBuffer = PixelConverter.BitmapToRGBA(stampedTestPattern as System.Drawing.Bitmap, _testPattern.Width, _testPattern.Height);

                        byte[] i420Buffer    = PixelConverter.RGBAtoYUV420Planar(sampleBuffer, _testPattern.Width, _testPattern.Height);
                        var    encodedBuffer = _vp8Encoder.Encode(i420Buffer, false);

                        _presentationTimestamp += VIDEO_TIMESTAMP_SPACING;

                        if (encodedBuffer != null)
                        {
                            OnTestPatternSampleReady?.Invoke(SDPMediaTypesEnum.video, VIDEO_TIMESTAMP_SPACING, encodedBuffer);
                        }

                        stampedTestPattern.Dispose();
                    }
                }
            }
        }
        private static void RoundTripTestPatternNoEncoding()
        {
            var stampedTestPattern = _testPattern.Clone() as System.Drawing.Image;
            int tWidth             = _testPattern.Width;
            int tHeight            = _testPattern.Height;

            AddTimeStampAndLocation(stampedTestPattern, DateTime.UtcNow.ToString("dd MMM yyyy HH:mm:ss:fff"), "Test Pattern");
            var sampleBuffer = PixelConverter.BitmapToRGBA(stampedTestPattern as System.Drawing.Bitmap, _testPattern.Width, _testPattern.Height);

            byte[] i420 = PixelConverter.RGBAtoYUV420Planar(sampleBuffer, _testPattern.Width, _testPattern.Height);

            byte[] rgb = PixelConverter.I420toRGB(i420, tWidth, tHeight);

            unsafe
            {
                fixed(byte *s = rgb)
                {
                    System.Drawing.Bitmap bmpImage = new System.Drawing.Bitmap(tWidth, tHeight, rgb.Length / tHeight, PixelFormat.Format24bppRgb, (IntPtr)s);
                    bmpImage.Save("roundtrip.bmp");
                    bmpImage.Dispose();
                }
            }
        }