Rediger

Del via


ISampleGrabber::GetCurrentBuffer method

[The feature associated with this page, DirectShow, is a legacy feature. It has been superseded by MediaPlayer, IMFMediaEngine, and Audio/Video Capture in Media Foundation. Those features have been optimized for Windows 10 and Windows 11. Microsoft strongly recommends that new code use MediaPlayer, IMFMediaEngine and Audio/Video Capture in Media Foundation instead of DirectShow, when possible. Microsoft suggests that existing code that uses the legacy APIs be rewritten to use the new APIs if possible.]

Note

[Deprecated. This API may be removed from future releases of Windows.]

 

The GetCurrentBuffer method retrieves a copy of the buffer associated with the most recent sample.

Syntax

HRESULT GetCurrentBuffer(
  [in, out] long *pBufferSize,
  [out]     long *pBuffer
);

Parameters

pBufferSize [in, out]

Pointer to the size of the buffer. If pBuffer is NULL, this parameter receives the required buffer size, in bytes. If pBuffer is not NULL, set this parameter equal to the size of the buffer, in bytes. On output, the parameter receives the number of bytes that were copied into the buffer. This value might be smaller than the size of the buffer.

pBuffer [out]

Pointer to an array of bytes of size pBufferSize, or NULL. If this parameter is not NULL, the current buffer is copied into the array. If this parameter is NULL, the pBufferSize parameter receives the required buffer size.

Return value

Returns one of the following values.

Return code Description
E_INVALIDARG
Samples are not being buffered. Call ISampleGrabber::SetBufferSamples.
E_OUTOFMEMORY
The specified buffer is not large enough.
E_POINTER
NULL pointer argument.
S_OK
Success.
VFW_E_NOT_CONNECTED
The filter is not connected.
VFW_E_WRONG_STATE
The filter has not received any samples yet. To deliver a sample, run or pause the graph.

 

Remarks

To activate buffering, call ISampleGrabber::SetBufferSamples with a value of TRUE.

Call this method twice. On the first call, set pBuffer to NULL. The size of the buffer is returned in pBufferSize. Then allocate an array and call the method again. On the second call, pass the size of the array in pBufferSize, and pass the address of the array in pBuffer. If the array is not large enough, the method returns E_OUTOFMEMORY.

The pBuffer parameter is typed as a long pointer, but the contents of the buffer depend on the format of the data. Call ISampleGrabber::GetConnectedMediaType to get the media type of the format.

Do not call this method while the filter graph is running. While the filter graph is running, the Sample Grabber filter overwrites the contents of the buffer whenever it receives a new sample. The best way to use this method is to use "one-shot mode," which stops the graph after receiving the first sample. To set one-shot mode, call ISampleGrabber::SetOneShot.

The filter does not buffer preroll samples, or samples in which the dwStreamId member of the AM_SAMPLE2_PROPERTIES structure is anything other than AM_STREAM_MEDIA.

Note

The header file Qedit.h is not compatible with Direct3D headers later than version 7.

 

Note

To obtain Qedit.h, download the Microsoft Windows SDK Update for Windows Vista and .NET Framework 3.0. Qedit.h is not available in the Microsoft Windows SDK for Windows 7 and .NET Framework 3.5 Service Pack 1.

 

Requirements

Requirement Value
Header
Qedit.h
Library
Strmiids.lib

See also

Using the Sample Grabber

ISampleGrabber Interface