public class MFMediaBuffer : ComObject
Represents a block of memory that contains media data. Use this interface to access the data in the buffer.
MFMediaBuffer(Int32 size)
Initializes a new instance of the MFMediaBuffer class with the specified maximum size.
public void MFMediaBuffer(Int32 size)
Parameters
size
Int32The size of the MFMediaBuffer in bytes. The specified size will be the MaxLength of the constructed MFMediaBuffer.
Remarks
The caller needs to release the allocated memory by disposing the MFMediaBuffer.
MFMediaBuffer(IntPtr ptr)
Initializes a new instance of the MFMediaBuffer class.
public void MFMediaBuffer(IntPtr ptr)
Parameters
ptr
IntPtrThe native pointer of the COM object.
GetCurrentLength()
Retrieves the length of the valid data in the buffer.
GetCurrentLengthNative(Int32& currentLength)
Retrieves the length of the valid data in the buffer.
public Int32 GetCurrentLengthNative(Int32& currentLength)
Parameters
currentLength
Int32&Receives the length of the valid data, in bytes. If the buffer does not contain any valid data, the value is zero.
Returns
HRESULT
GetMaxLength()
Retrieves the allocated size of the buffer.
GetMaxLengthNative(Int32& maxlength)
Retrieves the allocated size of the buffer.
public Int32 GetMaxLengthNative(Int32& maxlength)
Parameters
maxlength
Int32&Receives the allocated size of the buffer, in bytes.
Returns
HRESULT
Lock()
Gives the caller access to the memory in the buffer, for reading or writing.
public LockDisposable Lock()
Returns
A disposable object which provides the information returned by the Lock method. Call its Dispose method to unlock the MFMediaBuffer.
Example
This example shows how to use the Lock method: partial class TestClass { public void DoStuff(MFMediaBuffer mediaBuffer) { using(var lock = mediaBuffer.Lock()) { //do some stuff } //the mediaBuffer gets automatically unlocked by the using statement after "doing your stuff" } }
Lock(Int32& maxLength, Int32& currentLength)
Gives the caller access to the memory in the buffer, for reading or writing.
public IntPtr Lock(Int32& maxLength, Int32& currentLength)
Parameters
maxLength
Int32&Receives the maximum amount of data that can be written to the buffer. The same value is returned by the GetMaxLength method.
currentLength
Int32&Receives the length of the valid data in the buffer, in bytes. The same value is returned by the GetCurrentLength method.
Returns
A pointer to the start of the buffer.
Remarks
When you are done accessing the buffer, call Unlock to unlock the buffer. You must call Unlock once for each call to Lock.
LockNative(IntPtr& buffer, Int32& maxLength, Int32& currentLength)
Gives the caller access to the memory in the buffer, for reading or writing.
public Int32 LockNative(IntPtr& buffer, Int32& maxLength, Int32& currentLength)
Parameters
buffer
IntPtr&Receives a pointer to the start of the buffer.
maxLength
Int32&Receives the maximum amount of data that can be written to the buffer. The same value is returned by the GetMaxLength method.
currentLength
Int32&Receives the length of the valid data in the buffer, in bytes. The same value is returned by the GetCurrentLength method.
Returns
HRESULT
Remarks
When you are done accessing the buffer, call Unlock to unlock the buffer. You must call Unlock once for each call to Lock.
SetCurrentLength(Int32 currentLength)
Sets the length of the valid data in the buffer.
SetCurrentLengthNative(Int32 currentLength)
Sets the length of the valid data in the buffer.
public Int32 SetCurrentLengthNative(Int32 currentLength)
Parameters
currentLength
Int32Length of the valid data, in bytes. This value cannot be greater than the allocated size of the buffer, which is returned by the GetMaxLength method.
Returns
HRESULT
See Also
Unlock()
Unlocks a buffer that was previously locked. Call this method once for every call to Lock.
UnlockNative()
Unlocks a buffer that was previously locked. Call this method once for every call to Lock.
public Int32 UnlockNative()
Returns
HRESULT
CurrentLength
Gets or sets the length of the valid data, in bytes. If the buffer does not contain any valid data, the value is zero.
public Int32 CurrentLength { get; set; }
MaxLength
Gets the allocated size of the buffer, in bytes.
public Int32 MaxLength { get; }