- 1 year ago
How to use `ID311VideoContext::GetDecoderBuffer()`
Comment
1 / 1
ID311VideoContext::GetDecoderBuffer()
is a method provided by the DirectShow SDK, and is used to retrieve a buffer for decoder input. Here's an example of how you can use it:
cppHRESULT GetDecoderBuffer(ID311VideoContext* pVideoContext, IMediaBuffer** ppBuffer)
{
// Check the input parameters.
if (pVideoContext == NULL || ppBuffer == NULL)
{
return E_POINTER;
}
// Get the required buffer size.
DWORD dwSize = 0;
HRESULT hr = pVideoContext->GetDecoderBufferSize(&dwSize);
if (FAILED(hr))
{
return hr;
}
// Allocate the buffer.
BYTE* pBuffer = new BYTE[dwSize];
if (pBuffer == NULL)
{
return E_OUTOFMEMORY;
}
// Create the buffer object.
hr = CreateMemoryBuffer(dwSize, &pBuffer, ppBuffer);
if (FAILED(hr))
{
delete[] pBuffer;
return hr;
}
// Get the buffer.
hr = pVideoContext->GetDecoderBuffer(*ppBuffer);
if (FAILED(hr))
{
(*ppBuffer)->Release();
*ppBuffer = NULL;
return hr;
}
return S_OK;
}
In this example, ID311VideoContext::GetDecoderBufferSize()
is used to get the required buffer size, and then a buffer is allocated using new BYTE[dwSize]
. CreateMemoryBuffer()
is a helper function that creates an IMediaBuffer
object from the allocated buffer. Finally, ID311VideoContext::GetDecoderBuffer()
is called to get the actual buffer for decoder input.
Note that the IMediaBuffer
object returned by GetDecoderBuffer()
must be released when you're done with it using the Release()
method.