Reputation: 199
Is there any possibility to get an information that a camera was removed during preview in IMFCaptureEngine?
I am using a code from this sample CaptureEngine video capture sample. There is an EventCallback connected to the MFCaptureEngine instance:
hr = m_pEngine->Initialize(m_pCallback, pAttributes, NULL, pUnk);
But no event is received in the callback function after the webcam is removed.
I tried to add an extra callback function for engine's IMFMediaSource, which should, as I was expecting, generate MEVideoCaptureDeviceRemoved event. Look at the code called after MFCaptureEngine instance is initialized:
m_pEngine->GetSource(&pCapSource);
pCapSource->GetCaptureDeviceSource(MF_CAPTURE_ENGINE_DEVICE_TYPE_VIDEO, &pMediaSource);
pMediaSource.QueryInterface(&m_pSourceEventGenerator);
hr = m_pSourceEventGenerator->BeginGetEvent(OnSourceCB, NULL);
The hr value is MF_E_MULTIPLE_SUBSCRIBERS, which gives me a sence, because there are mixed two callbacks objects (first for the MFCaptureEngine as a whole, second for IMediaSource only).
Why I don't get any information about the device was removed? How can I get this information?
PS. I know the WM_DEVICECHANGE message, but I would like to avoid this if possible to get an event from media foundation.
Upvotes: 2
Views: 608
Reputation: 69632
You expectedly hit MF_E_MULTIPLE_SUBSCRIBERS
because it's capture engine who is the subscriber here. The engine is supposed to handle the event internally and forward it to the owner in the form of IMFMediaEvent
of extended type MF_CAPTURE_ENGINE_ERROR
, with HRESULT
code indicated by IMFMediaEvent::GetStatus
call of MF_E_VIDEO_RECORDING_DEVICE_INVALIDATED
(0xC00D3EA2): "The video recording device is no longer present.".
You receive the event in your IMFCaptureEngineOnEventCallback
implementation supplied to capture engine on initialization step.
Upvotes: 1