Reputation: 502
How can I interpret a "fill my buffer request" that returns S_FALSE
("I could read some but not all of the data you requested"), given the signature is:
HRESULT SyncRead(LONGLONG llPosition, LONG lLength, BYTE *pBuffer);
Specifically, how many bytes of the buffer are valid when the interface returns S_FALSE
?
I need to know that, right? Perhaps I am being daft, but I do not see it.
Upvotes: 1
Views: 171
Reputation: 5710
See this piece of code from this file on Microsoft's own git:
// sync read. works in stopped state as well as run state.
// need not be aligned. Will fail if read is beyond actual total
// length.
STDMETHODIMP SyncRead(
LONGLONG llPosition, // absolute file position
LONG lLength, // nr bytes required
BYTE* pBuffer); // write data here
// return total length of stream, and currently available length.
// reads for beyond the available length but within the total length will
// normally succeed but may block for a long period.
STDMETHODIMP Length(
LONGLONG* pTotal,
LONGLONG* pAvailable);
According to these two documented declarations, I think it's pretty safe to deduce bytes count read the following way. Say you want to read 70 bytes from position 800:
LONGLONG total, available;
pReader->Length(&total, &available);
LONG bytesRead = 70;
LONGLONG position = 800;
if (S_FALSE == readerPtr->SyncRead(800, bytesRead, bufferPtr))
bytesRead = total - position;
As if it fails, then the number of bytes it could have read is only limited by the total size.
Upvotes: 1
Reputation: 69706
IAsyncReader::SyncRead
is a shortcut to read synchronously and without thinking of data alignment. Well optimized filters are typically doing Request
and WaitForNext
asynchronous reads, transferring data using media samples with actual data length attached to those sample. In this shortcut method they seemed to make things easier but simply lost that output parameter.
Good news is that you can grab source code of the filter (or its close relative since stock filter could have changed a bit since the time source code was published as a sample) and extend the filter by adding e.g. IAsyncReader2::SyncReadEx
where you return the lost value when you need it.
Upvotes: 2