vendredi 23 janvier 2015

IMFMediaSource::GetEvent never gets an event

I'm writing an application in C++ using the Windows Media Foundation API.


I create an IMFMediaSource, create a PresentationDescriptor, select a stream, then call Start on the media source.


My reading of the API docs is that the call to Start should generate a MENewStream event. My code calls GetEvent for the media source, which just blocks forever.


Why don't I see at least the new stream event? I plan to request an audio sample from the media source inside the loop, but to do that, I need the interface provided by the new stream event.



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


This loop runs in a worker thread spawned by the main application thread. For brevity, I've omitted the error checks on the HRESULTs.


Aucun commentaire:

Enregistrer un commentaire