/// <summary>
        /// Draws the given frame to the video.
        /// </summary>
        /// <param name="device">The device on which the given framebuffer is created.</param>
        /// <param name="uploadedTexture">The texture which should be added to the video.</param>
        public void DrawFrame(EngineDevice device, MemoryMappedTexture32bpp uploadedTexture)
        {
            try
            {
                device.EnsureNotNull(nameof(device));
                uploadedTexture.EnsureNotNull(nameof(uploadedTexture));
                if (!m_hasStarted)
                {
                    throw new SeeingSharpGraphicsException($"{nameof(SeeingSharpVideoWriter)} is not started!");
                }
                if (m_hasFinished)
                {
                    throw new SeeingSharpGraphicsException($"{nameof(SeeingSharpVideoWriter)} has already finished before!");
                }

                // Check for correct image size
                if (m_videoSize != uploadedTexture.PixelSize)
                {
                    throw new SeeingSharpGraphicsException("Size has changed during recording!");
                }

                this.DrawFrameInternal(device, uploadedTexture);
            }
            catch (Exception ex)
            {
                m_drawException = ex;
            }
        }
Exemple #2
0
        /// <summary>
        /// Reads the next frame and puts it into the provided buffer.
        /// </summary>
        /// <param name="targetBuffer">The target buffer to write to.</param>
        public bool ReadFrame(MemoryMappedTexture32bpp targetBuffer)
        {
            this.EnsureNotNullOrDisposed("this");
            targetBuffer.EnsureNotNull(nameof(targetBuffer));
            if ((targetBuffer.Width != base.FrameSize.Width) ||
                (targetBuffer.Height != base.FrameSize.Height))
            {
                throw new SeeingSharpGraphicsException("Size of the given buffer does not match the video size!");
            }

            // Read the frame
            SeeingSharpMediaBuffer mediaSharpManaged = base.ReadFrameInternal();

            if (mediaSharpManaged == null)
            {
                return(false);
            }

            // Process the frame
            try
            {
                MF.MediaBuffer mediaBuffer = mediaSharpManaged.GetBuffer();

                int    cbMaxLength;
                int    cbCurrentLenght;
                IntPtr mediaBufferPointer = mediaBuffer.Lock(out cbMaxLength, out cbCurrentLenght);

                // Performance optimization using CopyMemory method
                //  see http://www.rolandk.de/wp/2015/05/wie-schnell-man-speicher-falsch-kopieren-kann/
                CommonTools.CopyMemory(
                    mediaBufferPointer, targetBuffer.Pointer,
                    (ulong)(base.FrameSize.Width * base.FrameSize.Height * 4));

                return(true);
            }
            finally
            {
                mediaSharpManaged.Dispose();
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="StandardTextureResource" /> class.
        /// </summary>
        internal StandardTextureResource(MemoryMappedTexture32bpp inMemoryTexture)
        {
            inMemoryTexture.EnsureNotNull(nameof(inMemoryTexture));

            m_inMemoryTexture = inMemoryTexture;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BitmapTextureResource"/> class.
        /// </summary>
        /// <param name="mappedTexture">The mapped texture.</param>
        public BitmapTextureResource(MemoryMappedTexture32bpp mappedTexture)
        {
            mappedTexture.EnsureNotNull(nameof(mappedTexture));

            m_mappedTexture = mappedTexture;
        }