我总是让 DS 框架来处理处理速率:在主应用程序线程中,配置样本抓取器回调,然后当回调被触发时,您将获得媒体样本以及样本时间:此时您可以处理样本,如果适当的时间间隔,即 1 秒已经过去。
你是什么意思你叫睡眠一秒钟,你从哪里(哪个线程)调用它?如果您从回调内部执行此操作,您是否有效地阻止了 DirectShow 管道?也许如果你能更详细地解释你的设置,我会更有帮助。
/// Callback that is triggered per media sample
/// Note this all happens in the DirectShow streaming thread!
STDMETHODIMP SampleCB( double dSampleTime, IMediaSample * pSample )
{
// check timestamp and if one second has elapsed process sample accordingly
// else do nothing
...
// Get byte pointer
BYTE* pbData(NULL);
HRESULT hr = pSample->GetPointer(&pbData);
if (FAILED(hr))
{
return hr;
}
...
}
PS 如果您想尽快处理样本,可以在回调中将样本时间戳设置为 NULL。
// set time to NULL to allow for fast rendering since the
// the video renderer controls the rendering rate according
// to the timestamps
pSample->SetTime(NULL, NULL);