Exemplo n.º 1
0
        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 expr_53 = MediaFoundationApi.CreateSample();

            expr_53.AddBuffer(iMFMediaBuffer);
            expr_53.SetSampleTime(this.inputPosition);
            long num4 = MediaFoundationTransform.BytesToNsPosition(num, this.sourceProvider.WaveFormat);

            expr_53.SetSampleDuration(num4);
            this.inputPosition += num4;
            Marshal.ReleaseComObject(iMFMediaBuffer);
            return(expr_53);
        }
Exemplo n.º 2
0
        private int ReadFromTransform()
        {
            MFT_OUTPUT_DATA_BUFFER[] array = new MFT_OUTPUT_DATA_BUFFER[1];
            IMFSample      iMFSample       = MediaFoundationApi.CreateSample();
            IMFMediaBuffer iMFMediaBuffer  = MediaFoundationApi.CreateMemoryBuffer(this.outputBuffer.Length);

            iMFSample.AddBuffer(iMFMediaBuffer);
            iMFSample.SetSampleTime(this.outputPosition);
            array[0].pSample = iMFSample;
            _MFT_PROCESS_OUTPUT_STATUS mFT_PROCESS_OUTPUT_STATUS;
            int num = this.transform.ProcessOutput(_MFT_PROCESS_OUTPUT_FLAGS.None, 1, array, out mFT_PROCESS_OUTPUT_STATUS);

            if (num == -1072861838)
            {
                Marshal.ReleaseComObject(iMFMediaBuffer);
                Marshal.ReleaseComObject(iMFSample);
                return(0);
            }
            if (num != 0)
            {
                Marshal.ThrowExceptionForHR(num);
            }
            IMFMediaBuffer iMFMediaBuffer2;

            array[0].pSample.ConvertToContiguousBuffer(out iMFMediaBuffer2);
            IntPtr source;
            int    num2;
            int    num3;

            iMFMediaBuffer2.Lock(out source, out num2, out num3);
            this.outputBuffer = BufferHelpers.Ensure(this.outputBuffer, num3);
            Marshal.Copy(source, this.outputBuffer, 0, num3);
            this.outputBufferOffset = 0;
            this.outputBufferCount  = num3;
            iMFMediaBuffer2.Unlock();
            this.outputPosition += MediaFoundationTransform.BytesToNsPosition(this.outputBufferCount, this.WaveFormat);
            Marshal.ReleaseComObject(iMFMediaBuffer);
            iMFSample.RemoveAllBuffers();
            Marshal.ReleaseComObject(iMFSample);
            Marshal.ReleaseComObject(iMFMediaBuffer2);
            return(num3);
        }