Events IMFMediaSource::GetEvent从不获取事件 我使用Windows MediaFoundation API编写了C++应用程序。

Events IMFMediaSource::GetEvent从不获取事件 我使用Windows MediaFoundation API编写了C++应用程序。,events,audio,com,ms-media-foundation,Events,Audio,Com,Ms Media Foundation,我创建一个IMFMediaSource,创建一个PresentationDescriptor,选择一个流,然后在媒体源上调用Start 我对API文档的理解是,调用Start应该生成一个MENewStream事件。我的代码为媒体源调用GetEvent,它将永远阻塞 为什么我至少看不到新的流事件?我计划从循环内的媒体源请求音频样本,但要做到这一点,我需要新的stream事件提供的接口 IMFMediaSource *pMediaSource = <initialized from anoth

我创建一个IMFMediaSource,创建一个PresentationDescriptor,选择一个流,然后在媒体源上调用Start

我对API文档的理解是,调用Start应该生成一个MENewStream事件。我的代码为媒体源调用GetEvent,它将永远阻塞

为什么我至少看不到新的流事件?我计划从循环内的媒体源请求音频样本,但要做到这一点,我需要新的stream事件提供的接口

IMFMediaSource *pMediaSource = <initialized from another pointer>
HRESULT hr;
IMFPresentationDescriptor *pPresentationDescriptor;
IMFMediaEventGenerator *pEventGen;
IMFMediaStream *pMediaStream;
IMFMediaEvent *pMediaEvent;
DWORD streamCount;
PROPVARIANT propVar;

hr = pMediaSource->CreatePresentationDescriptor(&pPresentationDescriptor);
hr = pPresentationDescriptor->GetStreamDescriptorCount(&streamCount);

printf("The capture device has %ld streams\n",streamCount); 

hr = pPresentationDescriptor->SelectStream(0L);
hr = pMediaSource->QueryInterface(IID_IMFMediaEventGenerator,(LPVOID *)&pEventGen);

PropVariantInit(&propVar);
propVar.scode = VT_EMPTY;
hr = pMediaSource->Start(pPresentationDescriptor,NULL,&propVar);

while (1) {
    printf("Waiting for event\n"); fflush(stdout);
    hr = pMediaSource->GetEvent(0L,&pMediaEvent);
    printf("Got event\n"); fflush(stdout);
}
此循环在主应用程序线程生成的工作线程中运行。
为了简单起见,我省略了对HRESULT的错误检查

已解决:缺少MFStartup调用