【发布时间】:2015-01-25 01:10:38
【问题描述】:
我正在使用 Windows Media Foundation API 用 C++ 编写应用程序。
我创建一个 IMFMediaSource,创建一个 PresentationDescriptor,选择一个流,然后在媒体源上调用 Start。
我对 API 文档的阅读是对 Start 的调用应该生成一个 MENewStream 事件。我的代码为媒体源调用 GetEvent,它只会永远阻塞。
为什么我至少看不到新的直播活动?我打算从循环内的媒体源请求一个音频样本,但要做到这一点,我需要新的流事件提供的接口。
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 的错误检查。
【问题讨论】:
标签: events audio com ms-media-foundation