I'm currently trying to implement webcam video capture into a project.
First I was trying Direct Show, which worked on one computer but not on another.
So now I'm trying Media Foundation.
I mostly followed the examples provided by Microsoft.
Upon calling MFCreateDeviceSource() I receive the error code 0x80070002 (-2147024894).
This error code is not really documented in this context.
I get this result for three separate webcams of two different types of webcam, all of which work with other programs using Direct Show (eg VLC).
Thank you for any hint.
Operating system: Windows7
SDK: Windows SDK v7.1
IDE: Visual Studio 2008
Code:
// MFStartup(MF_VERSION, MFSTARTUP_NOSOCKET) -- is called successfully in a previous function)
IMFMediaSource* media_source = 0;
IMFSourceReader* source_reader = 0;
IMFAttributes* pAttributes = 0;
hr = MFCreateAttributes(&pAttributes, 2);
if (FAILED(hr)) {
return false;
}
// Set the device type to video.
hr = pAttributes->SetGUID(MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE, MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID);
if (FAILED(hr)) {
return false;
}
// Set the symbolic link.
hr = pAttributes->SetString(MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK,(LPCWSTR)&device_name);
if (FAILED(hr)) {
return false;
}
// Create device source interface
hr = MFCreateDeviceSource(pAttributes, &media_source);
if (FAILED(hr)) {
// HERE I RECEIVE 0x80070002
return false;
}
// Create source reader
IMFAttributes* attr;
MFCreateAttributes(&attr,1);
attr->SetUINT32(MF_SOURCE_READER_ENABLE_VIDEO_PROCESSING,1);
hr = MFCreateSourceReaderFromMediaSource(media_source,attr,&source_reader);
if(FAILED(hr)) {
return false;
}