Example #1
0
        // Get the buffers and sizes to be modified, then pass them
        // to the appropriate Update_* routine.
        private void DoWork(IMFMediaBuffer pIn)
        {
            IntPtr      pSrc = IntPtr.Zero; // Source buffer.
            int         lSrcStride;         // Source stride.
            IMF2DBuffer pIn2D = null;

            try
            {
                // Lock the input buffer. Use IMF2DBuffer if available.
                Lockit(pIn, out pIn2D, out lSrcStride, out pSrc);

                // Invoke the image transform function.
                if (m_pTransformFn != null)
                {
                    m_pTransformFn(pSrc, lSrcStride,
                                   m_imageWidthInPixels, m_imageHeightInPixels);
                }
                else
                {
                    throw new COMException("Transform type not set", (int)HResult.E_UNEXPECTED);
                }

                // Set the data size on the output buffer.
                MFError throwonhr = pIn.SetCurrentLength(m_cbImageSize);
            }
            finally
            {
                UnlockIt(pSrc, pIn2D, pIn);
            }
        }
Example #2
0
        // Get the buffers and sizes to be modified, then pass them
        // to the transform routine.
        private void DoWork(IMFMediaBuffer pIn, IMFMediaBuffer pOut)
        {
            IntPtr      pSrc       = IntPtr.Zero;
            int         lSrcStride = 0;
            IMF2DBuffer pIn2D      = null;

            // Lock the input buffer. Use IMF2DBuffer if available.
            Lockit(pIn, out pIn2D, out lSrcStride, out pSrc);

            try
            {
                IntPtr  pDest;
                int     mlo;
                int     cb;
                MFError throwonhr = pOut.Lock(out pDest, out mlo, out cb);

                try
                {
                    // Invoke the image transform function.
                    YUY2_TO_RGB32(pSrc, pDest, m_imageWidthInPixels, m_imageHeightInPixels, lSrcStride);
                }
                finally
                {
                    pOut.Unlock();
                }
            }
            finally
            {
                // Ignore error
                UnlockIt(pSrc, pIn2D, pIn);
            }
        }
Example #3
0
        // Constructor
        public VideoBufferLock(IMFMediaBuffer pBuffer)
        {
            m_p2DBuffer = null;
            m_bLocked = false;
            m_pBuffer = pBuffer;

            // Query for the 2-D buffer interface. OK if this fails.
            m_p2DBuffer = pBuffer as IMF2DBuffer;
        }
Example #4
0
        // Constructor
        public VideoBufferLock(IMFMediaBuffer pBuffer)
        {
            m_p2DBuffer = null;
            m_bLocked   = false;
            m_pBuffer   = pBuffer;

            // Query for the 2-D buffer interface. OK if this fails.
            m_p2DBuffer = pBuffer as IMF2DBuffer;
        }
Example #5
0
        // Constructor
        public VideoBufferLock(IMFMediaBuffer pBuffer)
        {
            p2DBuffer = null;
            bLocked = false;
            this.pBuffer = pBuffer;

            // Query for the 2-D buffer interface. OK if this fails.
            // ReSharper disable once SuspiciousTypeConversion.Global
            p2DBuffer = pBuffer as IMF2DBuffer;
        }
Example #6
0
        public static uint GetContiguousLength(this IMF2DBuffer obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            obj.GetContiguousLength(out var length).ThrowOnError();
            return(length);
        }
Example #7
0
        // Constructor
        public VideoBufferLock(IMFMediaBuffer pBuffer)
        {
            p2DBuffer    = null;
            bLocked      = false;
            this.pBuffer = pBuffer;

            // Query for the 2-D buffer interface. OK if this fails.
            // ReSharper disable once SuspiciousTypeConversion.Global
            p2DBuffer = pBuffer as IMF2DBuffer;
        }
Example #8
0
        public void Dispose()
        {
            UnlockBuffer();
            SafeRelease(pBuffer);
            SafeRelease(p2DBuffer);

            pBuffer = null;
            p2DBuffer = null;

            GC.SuppressFinalize(this);
        }
Example #9
0
        public void Dispose()
        {
            UnlockBuffer();
            SafeRelease(pBuffer);
            SafeRelease(p2DBuffer);

            pBuffer   = null;
            p2DBuffer = null;

            GC.SuppressFinalize(this);
        }
        /// <summary>
        /// Copies data to this buffer from a MemoryBuffer that has a contiguous format.
        /// </summary>
        /// <param name="value">A valid IMF2DBuffer instance.</param>
        /// <param name="sourceBuffer">A MemoryBuffer.</param>
        /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns>
        public static HResult ContiguousCopyFrom(this IMF2DBuffer buffer, MemoryBuffer sourceBuffer)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("value");
            }

            if (sourceBuffer == null)
            {
                throw new ArgumentNullException("sourceBuffer");
            }

            return(buffer.ContiguousCopyFrom(sourceBuffer.BufferPointer, (int)sourceBuffer.ByteLength));
        }
        /// <summary>
        /// Copies this buffer into a MemoryBuffer, converting the data to contiguous format.
        /// </summary>
        /// <param name="value">A valid IMF2DBuffer instance.</param>
        /// <param name="destinationBuffer">The destination MemoryBuffer.</param>
        /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns>
        public static HResult ContiguousCopyTo(this IMF2DBuffer buffer, MemoryBuffer destinationBuffer)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("value");
            }

            if (destinationBuffer == null)
            {
                throw new ArgumentNullException("destinationBuffer");
            }

            return(buffer.ContiguousCopyTo(destinationBuffer.BufferPointer, (int)destinationBuffer.ByteLength));
        }
Example #12
0
        private static void UnlockIt(IntPtr pSrc, IMF2DBuffer pIn2D, IMFMediaBuffer pIn)
        {
            if (pSrc != IntPtr.Zero)
            {
                MFError throwonhr;

                if (pIn2D != null)
                {
                    throwonhr = pIn2D.Unlock2D();
                }
                else
                {
                    throwonhr = pIn.Unlock();
                }
            }
        }
Example #13
0
        private void Lockit(IMFMediaBuffer pOut, out IMF2DBuffer pOut2D, out int lDestStride, out IntPtr pDest)
        {
            MFError throwonhr;

            pOut2D = pOut as IMF2DBuffer;
            if (pOut2D != null)
            {
                throwonhr = pOut2D.Lock2D(out pDest, out lDestStride);
            }
            else
            {
                int ml;
                int cb;
                throwonhr   = pOut.Lock(out pDest, out ml, out cb);
                lDestStride = m_lStrideIfContiguous;
            }
        }
        /// <summary>
        /// Copies this buffer into a byte array, converting the data to contiguous format.
        /// </summary>
        /// <param name="value">A valid IMF2DBuffer instance.</param>
        /// <param name="destinationBuffer">The destination byte array.</param>
        /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns>
        public static HResult ContiguousCopyTo(this IMF2DBuffer buffer, byte[] destinationBuffer)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("value");
            }

            if (destinationBuffer == null)
            {
                throw new ArgumentNullException("destinationBuffer");
            }

            using (GCPin pinnedArray = new GCPin(destinationBuffer))
            {
                return(buffer.ContiguousCopyFrom(pinnedArray.PinnedAddress, destinationBuffer.Length));
            }
        }
Example #15
0
        // Get the buffers and sizes to be modified, then pass them
        // to the textwrite routine.
        private void DoWork(IMFMediaBuffer pIn)
        {
            IntPtr      pSrc = IntPtr.Zero; // Source buffer.
            int         lSrcStride;         // Source stride.
            IMF2DBuffer pIn2D = null;

            // Lock the input buffer. Use IMF2DBuffer if available.
            Lockit(pIn, out pIn2D, out lSrcStride, out pSrc);

            try
            {
                WriteIt(pSrc);
            }
            finally
            {
                UnlockIt(pSrc, pIn2D, pIn);
            }
        }
        /// <summary>
        /// Copies data to this buffer from a byte array segment that has a contiguous format.
        /// </summary>
        /// <param name="value">A valid IMF2DBuffer instance.</param>
        /// <param name="sourceBuffer">A byte array segment.</param>
        /// <returns>If this function succeeds, it returns the S_OK member. Otherwise, it returns another HResult's member that describe the error.</returns>
        public static HResult ContiguousCopyFrom(this IMF2DBuffer buffer, ArraySegment <byte> sourceBuffer)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("value");
            }

            if (sourceBuffer.Array == null)
            {
                throw new ArgumentNullException("sourceBuffer.Array");
            }

            using (GCPin pinnedArray = new GCPin(sourceBuffer.Array))
            {
                IntPtr startAddress = pinnedArray.PinnedAddress + sourceBuffer.Offset;
                return(buffer.ContiguousCopyFrom(startAddress, sourceBuffer.Count));
            }
        }