我在Windows 10上遇到问题(在服务器2016上不是问题),如果在捕获过程中拔出设备,IMFSourceReader-> ReadSample(下面代码中的reader-> ReadSample)将永远不会返回。这导致在捕获过程中拔出设备时不会引发错误。如果未拔出任何设备,一切正常。我希望会返回类似MF_E_INVALIDREQUEST之类的信息,但它会永远挂起。对于可能是问题或指导的任何想法,将不胜感激。
capture::Sample *capture::MfDeviceSampleProvider::GetNextSample(bool video) {
Sample *sample = NULL;
IMFSample *mfSample = NULL;
DWORD streamFlags;
if (reader) {
HRESULT hr = reader->ReadSample(streamIndex, 0, NULL, &streamFlags, NULL, &mfSample);
LOG_IF_FAILED(hr, "Unable to read sample from device.");
if (SUCCEEDED(hr)) {
if (streamFlags == 0) {
if (type == DeviceBase::Type::Video) {
sample = new MFVideoSample(prop.type, mfSample, prop.size.width, prop.size.height);
} else if (type == DeviceBase::Type::Audio) {
sample = new MFAudioSample(mfSample);
}
} else if (streamFlags & MF_SOURCE_READERF_STREAMTICK) {
return GetNextSample(video);
}
}
SafeRelease(&mfSample);
return sample;
}
`