コード例 #1
0
        public unsafe void can_copy_frames()
        {
            const uint count  = 20u;
            uint       size   = (uint)sizeof(TwoByte1024X1024Frame);
            var        buffer = (VideoSlice) new MonoVideoSlice(count, _getBuffer);
            var        frames = BuildRandomFrames(count, size);

            for (uint i = 0; i < buffer.Count; i++)
            {
                fixed(byte *f = frames[i])
                {
                    Utility.CopyMemory(buffer[i], f, size);
                }
            }
            var buffer2 = (VideoSlice) new MonoVideoSlice(count, _getBuffer);

            Utility.CopyMemory(buffer2.FramesBuffer, buffer.FramesBuffer, buffer.FramesBufferSize);
            Assert.NotEqual(buffer.Id, buffer2.Id);
            for (uint frameIndex = 0; frameIndex < buffer2.Count; frameIndex++)
            {
                byte *bufferFrame = buffer2[frameIndex];
                fixed(byte *sourceFrame = frames[frameIndex])
                {
                    var equal = BufferTests.BufferEqual(bufferFrame, sourceFrame, (int)size);

                    Assert.True(equal);
                }
            }
        }
コード例 #2
0
        public unsafe void can_reset_framebuffer()
        {
            const uint count  = 20;
            uint       size   = (uint)sizeof(TwoByte1024X1024Frame);
            var        buffer = (VideoSlice) new MonoVideoSlice(count, _getBuffer);
            var        frames = BuildRandomFrames(count, size);

            for (uint i = 0; i < buffer.Count; i++)
            {
                fixed(byte *f = frames[i])
                {
                    Utility.CopyMemory(buffer[i], f, size);
                }
            }
            var oldId        = buffer.Id;
            var oldCount     = buffer.Count;
            var oldFrameSize = buffer.FrameSize;

            Assert.True(buffer.TryReset());

            Assert.NotEqual(oldId, buffer.Id);
            Assert.Equal(oldCount, buffer.Count);
            Assert.Equal(oldFrameSize, buffer.FrameSize);
            var empty = new byte[size];

            for (uint frameIndex = 0; frameIndex < buffer.Count; frameIndex++)
            {
                fixed(byte *e = empty)
                {
                    Assert.True(BufferTests.BufferEqual(e, buffer[frameIndex], (int)size));
                }
            }
        }
コード例 #3
0
        public unsafe void returned_buffers_are_empty_and_can_be_reused()
        {
            var mgr  = new BufferManager("test");
            var buf1 = mgr.GetBuffer(30);

            Assert.NotNull(buf1);
            var source = new byte[30];

            for (int i = 0; i < 30; i++)
            {
                source[i] = (byte)(i % 8);
            }

            fixed(byte *s = source)
            {
                Utility.CopyMemory(buf1.Buffer, s, 30); // fill the whole buffer
                Assert.True(BufferTests.BufferEqual(s, buf1.Buffer, 30));
            }

            var empty = new byte[30];
            var addr  = (long)buf1.Buffer;

            buf1.Dispose();
            buf1 = mgr.GetBuffer(30);
            Assert.Equal(addr, (long)buf1.Buffer);
            fixed(byte *e = empty)
            {
                Assert.True(BufferTests.BufferEqual(e, buf1.Buffer, 30));
            }
        }
コード例 #4
0
        public unsafe void can_get_new_buffer()
        {
            var mgr  = new BufferManager("test");
            var buf1 = mgr.GetBuffer(30);

            Assert.NotNull(buf1);
            var source = new byte[30];

            for (int i = 0; i < 30; i++)
            {
                source[i] = (byte)(i % 8);
            }

            fixed(byte *s = source)
            {
                Utility.CopyMemory(buf1.Buffer, s, 30); // fill the whole buffer
                Assert.True(BufferTests.BufferEqual(s, buf1.Buffer, 30));
            }
        }
コード例 #5
0
        public unsafe void can_align_memory()
        {
            byte[] foo    = new byte[55 + 8];
            byte[] source = new byte[55];
            var    rnd    = new Random(DateTime.Now.Millisecond);

            rnd.NextBytes(source);

            fixed(byte *f = foo)
            fixed(byte *s = source)
            {
                Assert.True(((long)f) % 8 == 0);
                for (int i = 0; i < 8; i++)
                {
                    var l = Utility.AlignTo16(f + 1);
                    Assert.True(((long)l) % 16 == 0);
                    var sourcePtr = (IntPtr)s;
                    var destPtr   = (IntPtr)l;
                    Utility.CopyMemory(destPtr, sourcePtr, 55);
                    Assert.True(BufferTests.BufferEqual(l, s, 55));
                }
            }
        }