// Token: 0x06000945 RID: 2373 RVA: 0x0001B0A0 File Offset: 0x000192A0 private long ConvertOneBuffer(IMFSinkWriter writer, int streamIndex, IWaveProvider inputProvider, long position, byte[] managedBuffer) { long num = 0L; IMFMediaBuffer imfmediaBuffer = MediaFoundationApi.CreateMemoryBuffer(managedBuffer.Length); int count; imfmediaBuffer.GetMaxLength(out count); IMFSample imfsample = MediaFoundationApi.CreateSample(); imfsample.AddBuffer(imfmediaBuffer); IntPtr destination; int num2; imfmediaBuffer.Lock(out destination, out count, out num2); int num3 = inputProvider.Read(managedBuffer, 0, count); if (num3 > 0) { num = MediaFoundationEncoder.BytesToNsPosition(num3, inputProvider.WaveFormat); Marshal.Copy(managedBuffer, 0, destination, num3); imfmediaBuffer.SetCurrentLength(num3); imfmediaBuffer.Unlock(); imfsample.SetSampleTime(position); imfsample.SetSampleDuration(num); writer.WriteSample(streamIndex, imfsample); } else { imfmediaBuffer.Unlock(); } Marshal.ReleaseComObject(imfsample); Marshal.ReleaseComObject(imfmediaBuffer); return(num); }
// Token: 0x06000A59 RID: 2649 RVA: 0x0001E1A8 File Offset: 0x0001C3A8 private IMFSample ReadFromSource() { int num = this.sourceProvider.Read(this.sourceBuffer, 0, this.sourceBuffer.Length); if (num == 0) { return(null); } IMFMediaBuffer imfmediaBuffer = MediaFoundationApi.CreateMemoryBuffer(num); IntPtr destination; int num2; int num3; imfmediaBuffer.Lock(out destination, out num2, out num3); Marshal.Copy(this.sourceBuffer, 0, destination, num); imfmediaBuffer.Unlock(); imfmediaBuffer.SetCurrentLength(num); IMFSample imfsample = MediaFoundationApi.CreateSample(); imfsample.AddBuffer(imfmediaBuffer); imfsample.SetSampleTime(this.inputPosition); long num4 = MediaFoundationTransform.BytesToNsPosition(num, this.sourceProvider.WaveFormat); imfsample.SetSampleDuration(num4); this.inputPosition += num4; Marshal.ReleaseComObject(imfmediaBuffer); return(imfsample); }
// 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); } }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <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)); } } }
// Get the buffers and sizes to be modified, then pass them // to the appropriate Update_* routine. private HResult DoWork(IMFMediaBuffer pIn) { MFError throwonhr; int cb; IntPtr pSrc; // Source buffer. int lSrcStride = 0; // Source stride. bool bLockedInputBuffer = false; IMF2DBuffer pIn2D; // While there are exceptions thrown here, they should never happen // in real life. // Lock the input buffer. Use IMF2DBuffer if available. pIn2D = pIn as IMF2DBuffer; if (pIn2D != null) { throwonhr = pIn2D.Lock2D(out pSrc, out lSrcStride); } else { int ml; throwonhr = pIn.Lock(out pSrc, out ml, out cb); lSrcStride = m_lStrideIfContiguous; } bLockedInputBuffer = true; // Invoke the image transform function. if (m_pTransformFn != null) { m_pTransformFn(pSrc, lSrcStride, m_imageWidthInPixels, m_imageHeightInPixels); } else { return(HResult.E_UNEXPECTED); } if (bLockedInputBuffer) { if (pIn2D != null) { throwonhr = pIn2D.Unlock2D(); } else { throwonhr = pIn.Unlock(); } } // Set the data size on the output buffer. throwonhr = pIn.SetCurrentLength(m_cbImageSize); return(HResult.S_OK); }
private long ConvertOneBuffer(IMFSinkWriter writer, int streamIndex, IWaveProvider inputProvider, long position, byte[] managedBuffer, int seconds, ref bool flag) { long durationConverted = 0; int maxLength; IMFMediaBuffer buffer = MediaFoundationApi.CreateMemoryBuffer(managedBuffer.Length); buffer.GetMaxLength(out maxLength); IMFSample sample = MediaFoundationApi.CreateSample(); sample.AddBuffer(buffer); IntPtr ptr; int currentLength; buffer.Lock(out ptr, out maxLength, out currentLength); int oneLength = inputProvider.WaveFormat.AverageBytesPerSecond; int read = 0; if (flag) { for (int i = 0; i < seconds; i++) { read = inputProvider.Read(managedBuffer, 0, oneLength); } flag = false; } else { read = inputProvider.Read(managedBuffer, 0, oneLength); } if (read > 0) { durationConverted = BytesToNsPosition(read, inputProvider.WaveFormat); Marshal.Copy(managedBuffer, 0, ptr, read); buffer.SetCurrentLength(read); buffer.Unlock(); sample.SetSampleTime(position); sample.SetSampleDuration(durationConverted); writer.WriteSample(streamIndex, sample); //writer.Flush(streamIndex); } else { buffer.Unlock(); } Marshal.ReleaseComObject(sample); Marshal.ReleaseComObject(buffer); return(durationConverted); }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <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)); } } }
///////////////////////////////////////////////////////////////////// // Name: ReadDataIntoBuffer // // Reads data from a byte stream and returns a media buffer that // contains the data. // // pStream: Pointer to the byte stream // cbToRead: Number of bytes to read // ppBuffer: Receives a pointer to the buffer. ///////////////////////////////////////////////////////////////////// void ReadDataIntoBuffer( IMFByteStream pStream, // Pointer to the byte stream. int cbToRead, // Number of bytes to read out IMFMediaBuffer ppBuffer // Receives a pointer to the buffer. ) { HResult hr; IntPtr pData; int cbRead; // Actual amount of data read int iMax, iCur; // Create the media buffer. This function allocates the memory. hr = MFExtern.MFCreateMemoryBuffer(cbToRead, out ppBuffer); MFError.ThrowExceptionForHR(hr); // Access the buffer. hr = ppBuffer.Lock(out pData, out iMax, out iCur); MFError.ThrowExceptionForHR(hr); try { // Read the data from the byte stream. hr = pStream.Read(pData, cbToRead, out cbRead); MFError.ThrowExceptionForHR(hr); } finally { hr = ppBuffer.Unlock(); MFError.ThrowExceptionForHR(hr); pData = IntPtr.Zero; } // Update the size of the valid data. hr = ppBuffer.SetCurrentLength(cbRead); MFError.ThrowExceptionForHR(hr); }
/// <summary>Generates the "tail" of the audio effect.</summary> /// <param name="InputMessageNumber">Message number to use with OutputSample.</param> /// <remarks> /// Generates the "tail" of the audio effect. The tail is the portion /// of the delay effect that is heard after the input stream ends. /// /// To generate the tail, the client must drain the MFT by sending /// the MFT_MESSAGE_COMMAND_DRAIN message and then call ProcessOutput /// to get the tail samples. /// </remarks> private void ProcessEffectTail(int InputMessageNumber) { IMFMediaBuffer pOutputBuffer = null; MFError throwonhr; IntPtr pbOutputData = IntPtr.Zero; // Pointer to the memory in the output buffer. int cbOutputLength = 0; // Size of the output buffer. int cbBytesProcessed = 0; // How much data we processed. IMFSample pOutSample = null; // Allocate an output buffer. throwonhr = MFExtern.MFCreateMemoryBuffer(m_cbTailSamples, out pOutputBuffer); try { throwonhr = MFExtern.MFCreateSample(out pOutSample); throwonhr = pOutSample.AddBuffer(pOutputBuffer); // Lock the output buffer. int cb; throwonhr = pOutputBuffer.Lock(out pbOutputData, out cbOutputLength, out cb); // Calculate how many audio samples we can process. cbBytesProcessed = Math.Min(m_cbTailSamples, cbOutputLength); // Round to the next lowest multiple of nBlockAlign. cbBytesProcessed -= (cbBytesProcessed % m_Alignment); // Fill the output buffer with silence, because we are also using it as the input buffer. FillBufferWithSilence(pbOutputData, cbBytesProcessed); // Process the data. ProcessAudio(pbOutputData, pbOutputData, cbBytesProcessed / m_Alignment); // Set the data length on the output buffer. throwonhr = pOutputBuffer.SetCurrentLength(cbBytesProcessed); if (m_rtTimestamp >= 0) { long hnsDuration = (cbBytesProcessed / m_AvgBytesPerSec) * UNITS; // Set the time stamp and duration on the output sample. throwonhr = pOutSample.SetSampleTime(m_rtTimestamp); throwonhr = pOutSample.SetSampleDuration(hnsDuration); } // Done. m_cbTailSamples = 0; OutputSample(pOutSample, InputMessageNumber); } catch { SafeRelease(pOutSample); throw; } finally { if (pbOutputData != IntPtr.Zero) { pOutputBuffer.Unlock(); } SafeRelease(pOutputBuffer); } }
///////////////////////////////////////////////////////////////////// // Name: ReadDataIntoBuffer // // Reads data from a byte stream and returns a media buffer that // contains the data. // // pStream: Pointer to the byte stream // cbToRead: Number of bytes to read // ppBuffer: Receives a pointer to the buffer. ///////////////////////////////////////////////////////////////////// void ReadDataIntoBuffer( IMFByteStream pStream, // Pointer to the byte stream. int cbToRead, // Number of bytes to read out IMFMediaBuffer ppBuffer // Receives a pointer to the buffer. ) { IntPtr pData; int cbRead; // Actual amount of data read int iMax, iCur; // Create the media buffer. This function allocates the memory. int hr = MFExtern.MFCreateMemoryBuffer(cbToRead, out ppBuffer); MFError.ThrowExceptionForHR(hr); // Access the buffer. hr = ppBuffer.Lock(out pData, out iMax, out iCur); MFError.ThrowExceptionForHR(hr); try { // Read the data from the byte stream. hr = pStream.Read(pData, cbToRead, out cbRead); MFError.ThrowExceptionForHR(hr); } finally { hr = ppBuffer.Unlock(); MFError.ThrowExceptionForHR(hr); pData = IntPtr.Zero; } // Update the size of the valid data. hr = ppBuffer.SetCurrentLength(cbRead); MFError.ThrowExceptionForHR(hr); }
/// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+= /// <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)); } } }