IAsyncReader :: SyncRead方法

问题描述 投票:1回答:2

如果签名是:我如何解释返回S_FALSE的“填充我的缓冲区请求”(“我可以读取您请求的一些但不是所有数据”)。

HRESULT SyncRead(LONGLONG llPosition, LONG     lLength, BYTE     *pBuffer);

具体来说,当接口返回S_FALSE时,缓冲区的有效字节数是多少?

我需要知道,对吧?也许我是愚蠢的,但我没有看到它。

c++ windows directshow multimedia
2个回答
1
投票

在微软自己的git上看到this file的这段代码:

// 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);

根据这两个记录的声明,我认为按以下方式推断字节数是非常安全的。假设您要从位置800读取70个字节:

LONGLONG total, available;
pReader->Length(&total, &available);

LONG bytesRead = 70;
LONGLONG position = 800; 
if (S_FALSE == readerPtr->SyncRead(800, bytesRead, bufferPtr))
    bytesRead = total - position;

好像它失败了,那么它可以读取的字节数仅受总大小的限制。


2
投票

IAsyncReader::SyncRead是一种同步读取的快捷方式,无需考虑数据对齐。优化良好的滤波器通常执行RequestWaitForNext异步读取,使用附加到这些样本的实际数据长度的媒体样本传输数据。在这种快捷方式中,它们似乎使事情变得更容易但只是丢失了输出参数。

好消息是你可以抓住source code of the filter(或者它的近亲,因为自从源代码作为样本发布以来,库存过滤器可能有所改变)并通过添加例如扩展过滤器来扩展过滤器。 IAsyncReader2::SyncReadEx,在您需要的时候返还丢失的价值。

© www.soinside.com 2019 - 2024. All rights reserved.