Hi,
I have written an application to capture from UVC compliant cameras using Media foundation's SourceReader.
A part of the application closes down and releases the camera and then restarts it. Below are the code snippets desribing it:
Initialize Source reader:
hr = MFCreateSourceReaderFromMediaSource(_mSource, _mAttributes,&_sourceReader);
Get a frame synchronously:
hr = _sourceReader->ReadSample(MF_SOURCE_READER_FIRST_VIDEO_STREAM, 0, // Not using MF_SOURCE_READER_CONTROLF_DRAIN flag because we are not going to Buffer samples&actStreamIndex,&actStreamFlags,&timeStamp,&mediaSample);
We now clear & release the camera:
SafeRelease(&_sourceReader); SafeRelease(&_mSource); SafeRelease(&_mAttributes); SafeRelease(&_nativeMediaType); for (DWORD i = 0; i < _count; i++) { SafeRelease(&_mmDevices[i]); } CoTaskMemFree(_mmDevices);
I then re-initialize the camera with a different media type and call ReadSample again.
This work flow works with most cameras, but, with lifecam VX-3000, the ReadSample call after re-initializing returns the following failed HRESULT : 0x80070004
HRESULT_FROM_WIN32(ERROR_TOO_MANY_OPEN_FILES): The system cannot open file.
Am I missing anything while releasing the device? Thanks in advance for any ideas/suggestions on this.
Anchit