Esempio n. 1
0
        public void Disposed_ThrowsException()
        {
            var decoder = new H264Decoder(Stream.Null);

            decoder.Dispose();

            Assert.Throws <ObjectDisposedException>(() => decoder.Start());
            Assert.Throws <ObjectDisposedException>(() => decoder.FrameBuffer.CopyFramebuffer(Array.Empty <byte>()));
            Assert.Throws <ObjectDisposedException>(() => decoder.Decode());
        }
Esempio n. 2
0
        public void CopyFrameBuffer_ThrowsOnWrongSize()
        {
            using (var stream = File.OpenRead("video.h264"))
                using (var decoder = new H264Decoder(stream))
                {
                    var frameBuffer = decoder.FrameBuffer;
                    frameBuffer.FrameReceived += (sender, e) =>
                    {
                        byte[] array = new byte[20];
                        Assert.Throws <ArgumentOutOfRangeException>(() => frameBuffer.CopyFramebuffer(array));
                    };

                    decoder.Decode();
                }
        }
Esempio n. 3
0
        public unsafe void DecodeTest()
        {
            int frameCount = 0;

            var imageHashes = new List <string>();

            using (var stream = File.OpenRead("video.h264"))
                using (var decoder = new H264Decoder(stream))
                {
                    var frameBuffer = decoder.FrameBuffer;
                    frameBuffer.FrameReceived += (sender, e) =>
                    {
                        Assert.Equal(1334, frameBuffer.Height);
                        Assert.Equal(3000, frameBuffer.Stride);
                        Assert.Equal(750, frameBuffer.Width);
                        Assert.Equal(750, frameBuffer.AlignedWidth);
                        Assert.Equal(1334, frameBuffer.AlignedHeight);

                        byte[] array = new byte[frameBuffer.FrameBufferSize];
                        frameBuffer.CopyFramebuffer(array);

                        fixed(byte *ptr = array)
                        {
                            // Only reason we do this is to make sure the framebuffer data is relevant
                            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                            {
                                using (var bitmap = new Bitmap(frameBuffer.Width, frameBuffer.Height, frameBuffer.Stride, PixelFormat.Format24bppRgb, (IntPtr)ptr))
                                {
                                    bitmap.Save($"stream-frame.{frameCount}.jpg", ImageFormat.Jpeg);
                                }
                            }
                        }

                        frameCount++;
                    };

                    decoder.Decode();
                }

            Assert.Equal(5, frameCount);
        }