Fixed MSMF file capture error while opening the file containing unsupported video stream format

Applied in PR3260 to 2.4 branch
This commit is contained in:
Artur Wieczorek 2014-09-25 11:54:15 +02:00
parent 8f334b4e41
commit b91bd6716c

View File

@ -3848,18 +3848,25 @@ bool CvCaptureFile_MSMF::open(const char* filename)
hr = enumerateCaptureFormats(videoFileSource); hr = enumerateCaptureFormats(videoFileSource);
} }
if( captureFormats.empty() )
{
isOpened = false;
}
else
{
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
hr = ImageGrabberThread::CreateInstance(&grabberThread, videoFileSource, (unsigned int)-2, true); hr = ImageGrabberThread::CreateInstance(&grabberThread, videoFileSource, (unsigned int)-2, true);
} }
if (SUCCEEDED(hr)) isOpened = SUCCEEDED(hr);
}
if (isOpened)
{ {
grabberThread->start(); grabberThread->start();
} }
isOpened = SUCCEEDED(hr);
return isOpened; return isOpened;
} }
@ -3991,6 +3998,8 @@ HRESULT CvCaptureFile_MSMF::enumerateCaptureFormats(IMFMediaSource *pSource)
goto done; goto done;
} }
MediaType MT = FormatReader::Read(pType.Get()); MediaType MT = FormatReader::Read(pType.Get());
// We can capture only RGB video.
if( MT.MF_MT_SUBTYPE == MFVideoFormat_RGB24 )
captureFormats.push_back(MT); captureFormats.push_back(MT);
} }