IMFMediaBuffer::Lock Method

Gives the caller access to the memory in the buffer, for reading or writing

Syntax

public:
HRESULT Lock(
          **ppbBuffer,
         DWORD *pcbMaxLength,
         DWORD *pcbCurrentLength
)  

Parameters

ppbBuffer
Type:  **

Receives a pointer to the start of the buffer.

pcbMaxLength
Type: DWORD *

[out, optional]

Receives the maximum amount of data that can be written to the buffer. This parameter can be NULL. The same value is returned by the IMFMediaBuffer::GetMaxLength method.

pcbCurrentLength
Type: DWORD *

[out, optional]

Receives the length of the valid data in the buffer, in bytes. This parameter can be NULL. The same value is returned by the IMFMediaBuffer::GetCurrentLength method.

Return value

Type: HRESULT 

The method returns an HRESULT. Possible values include, but are not limited to, those in the following table.

Return codes
Return code Description
S_OK The method succeeded.
D3DERR_INVALIDCALL For Direct3D surface buffers, an error occurred when locking the surface.
MF_E_INVALIDREQUEST The buffer cannot be locked at this time.

Refer to Media Foundation return codes.

Remarks

This method gives the caller access to the entire buffer, up to the maximum size returned in the pcbMaxLength parameter. The value returned in pcbCurrentLength is the size of any valid data already in the buffer, which might be less than the total buffer size.

The pointer returned in ppbBuffer is guaranteed to be valid, and can safely be accessed across the entire buffer for as long as the lock is held. When you are done accessing the buffer, call IMFMediaBuffer::Unlock to unlock the buffer. You must call Unlock once for each call to Lock. After you unlock the buffer, the pointer returned in ppbBuffer is no longer valid, and should not be used. Generally, it is best to call Lock only when you need to access the buffer memory, and not earlier.

Locking the buffer does not prevent other threads from calling Lock, so you should not rely on this method to synchronize threads.

This method does not allocate any memory, or transfer ownership of the memory to the caller. Do not release or free the memory; the media buffer will free the memory when the media buffer is destroyed.

If you modify the contents of the buffer, update the current length by calling IMFMediaBuffer::SetCurrentLength.

If the buffer supports the IMF2DBuffer interface, you should use the IMF2DBuffer::Lock2D method to lock the buffer. For 2-D buffers, the Lock2D method is more efficient than the Lock method. If the buffer is locked using Lock2D, the Lock method might return MF_E_INVALIDREQUEST.

Requirements

Header: Declared in mfobjects.h (include mfidl.h).

Library: Use mfuuid.lib.