Esempio n. 1
0
        /// <returns>Ticks, NO BYTES!</returns>
        private long WriteBlock(byte[] buffer, int offset, int count, int streamIndex, long positionInTicks, int sourceBytesPerSecond)
        {
            int bytesToWrite = count;

            using (MFMediaBuffer mfBuffer = new MFMediaBuffer(MediaFoundationCore.CreateMemoryBuffer(bytesToWrite)))
            {
                using (MFSample sample = new MFSample(MediaFoundationCore.CreateEmptySample()))
                {
                    sample.AddBuffer(mfBuffer);

                    int    currentLength, maxLength;
                    IntPtr bufferPtr = mfBuffer.Lock(out maxLength, out currentLength);

                    long ticks = BytesToNanoSeconds(count, sourceBytesPerSecond);
                    Marshal.Copy(buffer, offset, bufferPtr, count);
                    mfBuffer.SetCurrentLength(count);
                    mfBuffer.Unlock();

                    sample.SetSampleTime(positionInTicks);
                    sample.SetSampleDuration(ticks);
                    _sinkWriter.WriteSample(_streamIndex, sample);

                    return(ticks);
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MFMediaBuffer"/> class with the specified maximum <paramref name="size"/>.
 /// </summary>
 /// <param name="size">The size of the <see cref="MFMediaBuffer"/> in bytes. The specified <paramref name="size"/> will be the <see cref="MaxLength"/> of the constructed <see cref="MFMediaBuffer"/>.</param>
 /// <remarks>The caller needs to release the allocated memory by disposing the <see cref="MFMediaBuffer"/>.</remarks>
 public MFMediaBuffer(int size)
     : this(MediaFoundationCore.CreateMemoryBuffer(size))
 {
 }