Пример #1
0
        /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <summary>
        /// Write the text on the output buffer
        /// </summary>
        /// <param name="outputMediaBuffer">Output buffer</param>
        /// <history>
        ///    01 Nov 18  Cynic - Ported In
        /// </history>
        private void WriteTextOnBuffer(IMFMediaBuffer outputMediaBuffer)
        {
            IntPtr destRawDataPtr = IntPtr.Zero;            // Destination buffer.
            int    destStride     = 0;                      // Destination stride.
            bool   destIs2D       = false;

            try
            {
                // Lock the output buffer. Use the IMF2DBuffer interface
                // (if available) as it is faster
                if ((outputMediaBuffer is IMF2DBuffer) == false)
                {
                    // not an IMF2DBuffer - get the raw data from the IMFMediaBuffer
                    int maxLen     = 0;
                    int currentLen = 0;
                    TantaWMFUtils.LockIMFMediaBufferAndGetRawData(outputMediaBuffer, out destRawDataPtr, out maxLen, out currentLen);
                    // the stride is always this. The Lock function does not return it
                    destStride = m_lStrideIfContiguous;
                }
                else
                {
                    // we are an IMF2DBuffer, we get the stride here as well
                    TantaWMFUtils.LockIMF2DBufferAndGetRawData((outputMediaBuffer as IMF2DBuffer), out destRawDataPtr, out destStride);
                    destIs2D = true;
                }

                // count this now. We only use this to write it on the screen
                m_FrameCount++;

                // We could eventually offer the ability to write on other formats depending on the
                // current media type. We have this hardcoded to ARGB for now
                WriteImageOfTypeARGB(destRawDataPtr,
                                     destStride,
                                     m_imageWidthInPixels,
                                     m_imageHeightInPixels);

                // Set the data size on the output buffer. It probably is already there
                // since the output buffer is the input buffer
                HResult hr = outputMediaBuffer.SetCurrentLength(m_cbImageSize);
                if (hr != HResult.S_OK)
                {
                    throw new Exception("WriteTextOnBuffer call to outputMediaBuffer.SetCurrentLength failed. Err=" + hr.ToString());
                }
            }
            finally
            {
                // we MUST unlock
                if (destIs2D == false)
                {
                    TantaWMFUtils.UnLockIMFMediaBuffer(outputMediaBuffer);
                }
                else
                {
                    TantaWMFUtils.UnLockIMF2DBuffer((outputMediaBuffer as IMF2DBuffer));
                }
            }
        }
Пример #2
0
        /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <summary>
        ///  Get the buffers and sizes to be modified, then pass them
        ///  to the appropriate Update_* routine.
        /// </summary>
        /// <param name="inputMediaBuffer">the mediaBuffer</param>
        /// <history>
        ///    01 Nov 18  Cynic - Ported over
        /// </history>
        private void DoWork(IMFMediaBuffer inputMediaBuffer)
        {
            IntPtr srcRawDataPtr = IntPtr.Zero;                     // Source buffer.
            int    srcStride;                                       // Source stride.
            bool   srcIs2D = false;

            try
            {
                // Lock the input buffer. Use the IMF2DBuffer interface
                // (if available) as it is faster
                if ((inputMediaBuffer is IMF2DBuffer) == false)
                {
                    // not an IMF2DBuffer - get the raw data from the IMFMediaBuffer
                    int maxLen     = 0;
                    int currentLen = 0;
                    TantaWMFUtils.LockIMFMediaBufferAndGetRawData(inputMediaBuffer, out srcRawDataPtr, out maxLen, out currentLen);
                    // the stride is always this. The Lock function does not return it
                    srcStride = m_lStrideIfContiguous;
                }
                else
                {
                    // we are an IMF2DBuffer, we get the stride here as well
                    TantaWMFUtils.LockIMF2DBufferAndGetRawData((inputMediaBuffer as IMF2DBuffer), out srcRawDataPtr, out srcStride);
                    srcIs2D = true;
                }
                // Invoke the image transform function.
                if (TransformImageFunction != null)
                {
                    TransformImageFunction(srcRawDataPtr, srcStride,
                                           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 = inputMediaBuffer.SetCurrentLength(m_cbImageSize);
            }
            finally
            {
                if (srcIs2D == false)
                {
                    TantaWMFUtils.UnLockIMFMediaBuffer(inputMediaBuffer);
                }
                else
                {
                    TantaWMFUtils.UnLockIMF2DBuffer((inputMediaBuffer as IMF2DBuffer));
                }
            }
        }
Пример #3
0
        /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <summary>
        /// Given the input and output media buffers, do the transform.
        /// </summary>
        /// <param name="inputMediaBuffer">Input buffer</param>
        /// <param name="outputMediaBuffer">Output buffer</param>
        /// <history>
        ///    01 Nov 18  Cynic - Ported In
        /// </history>
        private void ConvertMediaBufferToGrayscale(IMFMediaBuffer inputMediaBuffer, IMFMediaBuffer outputMediaBuffer)
        {
            IntPtr destRawDataPtr = IntPtr.Zero;            // Destination buffer.
            int    destStride     = 0;                      // Destination stride.
            bool   destIs2D       = false;

            IntPtr srcRawDataPtr = IntPtr.Zero;                     // Source buffer.
            int    srcStride;                                       // Source stride.
            bool   srcIs2D = false;

            if (TransformImageFunction == null)
            {
                throw new COMException("Transform type not set", (int)HResult.E_UNEXPECTED);
            }

            try
            {
                // Lock the output buffer. Use the IMF2DBuffer interface
                // (if available) as it is faster
                if ((outputMediaBuffer is IMF2DBuffer) == false)
                {
                    // not an IMF2DBuffer - get the raw data from the IMFMediaBuffer
                    int maxLen     = 0;
                    int currentLen = 0;
                    TantaWMFUtils.LockIMFMediaBufferAndGetRawData(outputMediaBuffer, out destRawDataPtr, out maxLen, out currentLen);
                    // the stride is always this. The Lock function does not return it
                    destStride = m_lStrideIfContiguous;
                }
                else
                {
                    // we are an IMF2DBuffer, we get the stride here as well
                    TantaWMFUtils.LockIMF2DBufferAndGetRawData((outputMediaBuffer as IMF2DBuffer), out destRawDataPtr, out destStride);
                    destIs2D = true;
                }

                // Lock the input buffer. Use the IMF2DBuffer interface
                // (if available) as it is faster
                if ((inputMediaBuffer is IMF2DBuffer) == false)
                {
                    // not an IMF2DBuffer - get the raw data from the IMFMediaBuffer
                    int maxLen     = 0;
                    int currentLen = 0;
                    TantaWMFUtils.LockIMFMediaBufferAndGetRawData(inputMediaBuffer, out srcRawDataPtr, out maxLen, out currentLen);
                    // the stride is always this. The Lock function does not return it
                    srcStride = m_lStrideIfContiguous;
                }
                else
                {
                    // we are an IMF2DBuffer, we get the stride here as well
                    TantaWMFUtils.LockIMF2DBufferAndGetRawData((inputMediaBuffer as IMF2DBuffer), out srcRawDataPtr, out srcStride);
                    srcIs2D = true;
                }

                // Invoke the image transform function.
                TransformImageFunction(destRawDataPtr,
                                       destStride,
                                       srcRawDataPtr,
                                       srcStride,
                                       m_imageWidthInPixels,
                                       m_imageHeightInPixels);

                // Set the data size on the output buffer.
                HResult hr = outputMediaBuffer.SetCurrentLength(m_cbImageSize);
                if (hr != HResult.S_OK)
                {
                    throw new Exception("ConvertMediaBufferToGrayscale call to outputMediaBuffer.SetCurrentLength failed. Err=" + hr.ToString());
                }
            }
            finally
            {
                // we MUST unlock
                if (destIs2D == false)
                {
                    TantaWMFUtils.UnLockIMFMediaBuffer(outputMediaBuffer);
                }
                else
                {
                    TantaWMFUtils.UnLockIMF2DBuffer((outputMediaBuffer as IMF2DBuffer));
                }
                if (srcIs2D == false)
                {
                    TantaWMFUtils.UnLockIMFMediaBuffer(inputMediaBuffer);
                }
                else
                {
                    TantaWMFUtils.UnLockIMF2DBuffer((inputMediaBuffer as IMF2DBuffer));
                }
            }
        }