/// <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); } } }
//This method returns ticks, not bytes! private long WriteBlock(byte[] buffer, int offset, int count, int streamIndex, long positionInTicks, int sourceBytesPerSecond) { using (var mfBuffer = new MFMediaBuffer(count)) { using (var sample = new MFSample()) { sample.AddBuffer(mfBuffer); using (var @lock = mfBuffer.Lock()) { Marshal.Copy(buffer, offset, @lock.Buffer, count); mfBuffer.SetCurrentLength(count); } long ticks = BytesToNanoSeconds(count, sourceBytesPerSecond); sample.SetSampleTime(positionInTicks); sample.SetSampleDuration(ticks); _sinkWriter.WriteSample(streamIndex, sample); return(ticks); } } }
/// <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; } } }
//This method returns ticks, not bytes! private long WriteBlock(byte[] buffer, int offset, int count, int streamIndex, long positionInTicks, int sourceBytesPerSecond) { using (var mfBuffer = new MFMediaBuffer(count)) { using (var sample = new MFSample()) { sample.AddBuffer(mfBuffer); using (var @lock = mfBuffer.Lock()) { Marshal.Copy(buffer, offset, @lock.Buffer, count); mfBuffer.SetCurrentLength(count); } long ticks = BytesToNanoSeconds(count, sourceBytesPerSecond); sample.SetSampleTime(positionInTicks); sample.SetSampleDuration(ticks); _sinkWriter.WriteSample(streamIndex, sample); return ticks; } } }