43 #ifndef DOXYGEN_SHOULD_SKIP_THIS
45 #include <visp/vpConfig.h>
46 #if ( defined(VISP_HAVE_DIRECTSHOW) )
48 #include <visp/vpDirectShowGrabberImpl.h>
50 #ifndef DOXYGEN_SHOULD_SKIP_THIS
52 vpDirectShowDevice * vpDirectShowGrabberImpl::deviceList = NULL;
53 unsigned int vpDirectShowGrabberImpl::nbDevices ;
58 void vpDirectShowGrabberImpl::HRtoStr(std::string str)
60 TCHAR szErr[MAX_ERROR_TEXT_LEN];
61 DWORD res = AMGetErrorText(hr, szErr, MAX_ERROR_TEXT_LEN);
63 if (res == 0) str =
"Unknown Error: 0x%2x";
65 char msg[MAX_ERROR_TEXT_LEN];
66 sprintf(msg,
"%s",szErr);
75 vpDirectShowGrabberImpl::vpDirectShowGrabberImpl()
80 if (FAILED(hr = CoInitializeEx(NULL,COINIT_MULTITHREADED)))
86 "Can't initialize COM\n"+ err));
91 if(deviceList == NULL) {
92 CComPtr<IEnumMoniker> pVideoInputEnum = NULL;
94 if(enumerate(pVideoInputEnum)) {
95 createDeviceList(pVideoInputEnum);
98 pVideoInputEnum.Release();
106 void vpDirectShowGrabberImpl::open()
109 if(deviceList == NULL) {
110 CComPtr<IEnumMoniker> pVideoInputEnum = NULL;
112 if(enumerate(pVideoInputEnum)) {
113 createDeviceList(pVideoInputEnum);
116 pVideoInputEnum.Release();
119 init = initDirectShow();
151 bool vpDirectShowGrabberImpl::initDirectShow()
156 currentDevice = getFirstUnusedDevice(pCapSource);
158 if(currentDevice == nbDevices)
166 if(FAILED(hr = pGraph->AddFilter(pCapSource, L
"Capture Filter")))
170 if(!createSampleGrabber(pGrabberFilter))
174 if(FAILED(hr = pGraph->AddFilter(pGrabberFilter, L
"SampleGrabber")))
178 if(!connectSourceToGrabber(pCapSource, pGrabberFilter))
183 if(FAILED(hr = pGrabberI->GetConnectedMediaType(&(sgCB.connectedMediaType))))
187 CComPtr<IMediaFilter> pMediaFilter;
189 pGraph->QueryInterface(IID_IMediaFilter, (
void **)&pMediaFilter);
190 pGraph->QueryInterface(IID_IMediaControl, reinterpret_cast<void**>(&pControl));
191 pGraph->QueryInterface(IID_IMediaEvent, (
void **)&pEvent);
193 pMediaFilter->SetSyncSource(NULL);
194 pMediaFilter.Release();
202 vpDirectShowGrabberImpl::~vpDirectShowGrabberImpl()
212 bool vpDirectShowGrabberImpl::enumerate(CComPtr<IEnumMoniker>& ppVideoInputEnum)
214 CComPtr<ICreateDevEnum> pDevEnum = NULL;
218 hr = pDevEnum.CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER);
224 hr = pDevEnum->CreateClassEnumerator(
225 CLSID_VideoInputDeviceCategory,
226 &ppVideoInputEnum, 0);
228 if(hr == S_OK) res =
true;
242 bool vpDirectShowGrabberImpl::createDeviceList(CComPtr<IEnumMoniker>& ppVideoInputEnum)
244 CComPtr<IMoniker> pMoniker[10];
245 unsigned long nbMoniker;
247 ppVideoInputEnum->Reset();
250 ppVideoInputEnum->Next(10, reinterpret_cast<IMoniker **>(&pMoniker), &nbMoniker);
253 if(nbMoniker == 0)
return false;
255 deviceList =
new vpDirectShowDevice[nbMoniker];
257 nbDevices = (
unsigned int)nbMoniker;
265 if(!deviceList[i].init(pMoniker[j]))
279 if(nbDevices == 0)
return false;
282 for(
unsigned int i=0 ; i<nbMoniker ;i++)
284 pMoniker[i].Release();
297 bool vpDirectShowGrabberImpl::getDevice(
unsigned int n, CComPtr<IBaseFilter>& ppDevice)
304 if(deviceList[n].getState() ==
true)
308 CComPtr<IEnumMoniker> pVideoInputEnum = NULL;
309 if(!enumerate(pVideoInputEnum))
312 CComPtr<IMoniker> pMoniker = NULL;
313 bool deviceFound =
false;
316 while (pVideoInputEnum->Next(1, &pMoniker, NULL) == S_OK
320 if(deviceList[n] == vpDirectShowDevice(pMoniker))
323 if(SUCCEEDED(pMoniker->BindToObject(0, 0, IID_IBaseFilter, (
void**)&ppDevice)))
326 deviceList[n].setInUse();
334 pVideoInputEnum.Release();
344 unsigned int vpDirectShowGrabberImpl::getFirstUnusedDevice(CComPtr<IBaseFilter>& ppDevice)
349 for(n=0;n<nbDevices && !found; n++)
352 if(!deviceList[n].getState())
354 if(getDevice(n,ppDevice))
357 deviceList[n].setInUse();
370 bool vpDirectShowGrabberImpl::createGraph()
374 hr = pBuild.CoCreateInstance(CLSID_CaptureGraphBuilder2, 0, CLSCTX_INPROC_SERVER);
379 hr = pGraph.CoCreateInstance(CLSID_FilterGraph, 0, CLSCTX_INPROC_SERVER);
384 pBuild->SetFiltergraph(pGraph);
398 bool vpDirectShowGrabberImpl::createSampleGrabber(CComPtr<IBaseFilter>& ppGrabberFilter)
401 hr = ppGrabberFilter.CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER);
407 hr = ppGrabberFilter->QueryInterface(IID_ISampleGrabber,
408 reinterpret_cast<void**>(&pGrabberI));
415 ZeroMemory(&mt,
sizeof(AM_MEDIA_TYPE));
417 mt.majortype = MEDIATYPE_Video;
420 mt.subtype = MEDIATYPE_NULL;
422 if(FAILED(hr = pGrabberI->SetMediaType(&mt)))
426 pGrabberI->SetCallback(&sgCB,1);
429 pGrabberI->SetOneShot(TRUE);
432 pGrabberI->SetBufferSamples(
false);
446 bool vpDirectShowGrabberImpl::checkSourceType(CComPtr<IPin>& pCapSourcePin)
450 if(FAILED (pCapSourcePin->ConnectionMediaType(&mt)))
453 if(mt.majortype != MEDIATYPE_Video)
457 if(mt.subtype == MEDIASUBTYPE_ARGB32 ||
458 mt.subtype == MEDIASUBTYPE_RGB32 ||
459 mt.subtype == MEDIASUBTYPE_RGB24 ||
460 mt.subtype == MEDIASUBTYPE_RGB555 ||
461 mt.subtype == MEDIASUBTYPE_RGB565 ||
462 mt.subtype == MEDIASUBTYPE_RGB8 ||
463 mt.subtype == MEDIASUBTYPE_RGB4 ||
464 mt.subtype == MEDIASUBTYPE_RGB1 )
467 sgCB.specialMediaType =
false;
470 else if(mt.subtype == MEDIASUBTYPE_AYUV ||
471 mt.subtype == MEDIASUBTYPE_UYVY ||
472 mt.subtype == MEDIASUBTYPE_Y411 ||
473 mt.subtype == MEDIASUBTYPE_Y41P ||
474 mt.subtype == MEDIASUBTYPE_Y211 ||
475 mt.subtype == MEDIASUBTYPE_YUY2 ||
476 mt.subtype == MEDIASUBTYPE_YVYU ||
477 mt.subtype == MEDIASUBTYPE_YUYV ||
478 mt.subtype == MEDIASUBTYPE_IF09 ||
479 mt.subtype == MEDIASUBTYPE_IYUV ||
480 mt.subtype == MEDIASUBTYPE_YV12 ||
481 mt.subtype == MEDIASUBTYPE_YVU9 )
484 sgCB.specialMediaType =
false;
490 sgCB.specialMediaType =
true;
493 VIDEOINFOHEADER *pVih =
reinterpret_cast<VIDEOINFOHEADER*
>(mt.pbFormat);
494 BITMAPINFOHEADER bmpInfo = pVih->bmiHeader;
497 format = ((bmpInfo.biCompression&0xFF000000)>>24) |
498 ((bmpInfo.biCompression&0x00FF0000)>>8) |
499 ((bmpInfo.biCompression&0x0000FF00)<<8) |
500 (bmpInfo.biCompression&0x000000FF)<<24;
502 std::cout<<
"This format is not one of the standard YUV or RGB format supported by DirectShow.\n"
504 <<(char)(bmpInfo.biCompression&0x000000FF)
505 <<(char)((bmpInfo.biCompression&0x0000FF00)>>8)
506 <<(
char)((bmpInfo.biCompression&0x00FF0000)>>16)
507 <<(char)((bmpInfo.biCompression&0xFF000000)>>24)<<std::endl;
512 sgCB.invertedSource =
false;
515 else if(format ==
'cyuv')
517 sgCB.invertedSource =
true;
523 std::cout<<
"Unknown FourCC compression type, assuming top-down orientation. Image may be inverted."<<std::endl;
524 sgCB.invertedSource =
false;
537 bool vpDirectShowGrabberImpl::connectSourceToGrabber(CComPtr<IBaseFilter>& _pCapSource, CComPtr<IBaseFilter>& _pGrabberFilter)
557 if(FAILED(hr = pBuild->RenderStream(NULL,NULL, _pCapSource, NULL, _pGrabberFilter)))
567 CComPtr<IBaseFilter> pNull = NULL;
568 if (FAILED(pNull.CoCreateInstance(CLSID_NullRenderer, NULL, CLSCTX_INPROC_SERVER)))
582 if( FAILED(pGraph->AddFilter(pNull, L
"NullRenderer")) ||
583 FAILED(pBuild->RenderStream(NULL,NULL, _pGrabberFilter, NULL, pNull)))
587 CComPtr<IPin> pCapSourcePin;
588 if(FAILED(pBuild->FindPin(_pCapSource, PINDIR_OUTPUT, NULL, NULL,
false, 0, &pCapSourcePin)))
592 if(!checkSourceType(pCapSourcePin))
596 pCapSourcePin.Release();
610 bool vpDirectShowGrabberImpl::removeAll()
612 CComPtr<IEnumFilters> pEnum = NULL;
613 CComPtr<IBaseFilter> pFilter;
616 if (FAILED(hr = pGraph->EnumFilters(&pEnum)))
619 while(pEnum->Next(1, &pFilter, &cFetched) == S_OK)
621 if(FAILED(hr = pGraph->RemoveFilter(pFilter)))
return false;
645 "Initialization not done") );
651 sgCB.acqRGBaDemand =
true;
658 hr = pEvent->WaitForCompletion(MAX_DELAY, &ev);
664 if( WaitForSingleObject(sgCB.copySem,MAX_DELAY) != WAIT_OBJECT_0)
666 "Can't grab the frame, callback timeout") );
685 "Initialization not done") );
691 sgCB.acqGrayDemand =
true;
698 hr = pEvent->WaitForCompletion(MAX_DELAY, &ev);
704 if( WaitForSingleObject(sgCB.copySem,MAX_DELAY) != WAIT_OBJECT_0)
706 "Can't grab the frame, callback timeout") );
715 bool vpDirectShowGrabberImpl::setDevice(
unsigned int id)
721 "Initialization not done") );
726 if(
id>=nbDevices || deviceList[
id].getState()==
true)
733 if(!removeAll())
return false;
737 pCapSource.Release();
740 deviceList[currentDevice].resetInUse();
743 pGraph->AddFilter(pGrabberFilter,L
"SampleGrabber");
746 if(!getDevice(
id, pCapSource))
750 if(FAILED(hr = pGraph->AddFilter(pCapSource, L
"Capture Filter")))
754 if(!connectSourceToGrabber(pCapSource, pGrabberFilter))
759 if(FAILED(hr = pGrabberI->GetConnectedMediaType(&(sgCB.connectedMediaType))))
765 deviceList[id].setInUse();
774 void vpDirectShowGrabberImpl::displayDevices()
776 if(deviceList == NULL)
779 "Initialization not done") );
782 for(
unsigned int i=0 ; i<nbDevices ; i++)
783 std::cout<<i<<
" : "<< deviceList[i].getName() <<std::endl;
785 std::cout<<
"Current device : "<<currentDevice<<std::endl<<std::endl;
793 void vpDirectShowGrabberImpl::close()
797 deviceList[currentDevice].resetInUse();
809 bool vpDirectShowGrabberImpl::setImageSize(
unsigned int width,
unsigned int height)
815 "Initialization not done") );
818 return setFormat(width, height,NULL);
825 bool vpDirectShowGrabberImpl::setFramerate(
double framerate)
831 "Initialization not done") );
834 VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER*)sgCB.connectedMediaType.pbFormat;
835 return setFormat(pVih->bmiHeader.biWidth,pVih->bmiHeader.biHeight,framerate);
841 bool vpDirectShowGrabberImpl::setFormat(
unsigned int width,
unsigned int height,
double framerate)
847 "Initialization not done") );
853 IAMStreamConfig *pConfig = NULL;
855 if(FAILED(hr = pBuild->FindInterface(
859 IID_IAMStreamConfig, (
void**)&pConfig)))
863 IAMVideoControl *pVideoControl = NULL;
865 if(FAILED(hr = pBuild->FindInterface(
869 IID_IAMVideoControl, (
void**)&pVideoControl)))
873 CComPtr<IPin> pCapSourcePin;
874 if(FAILED(pBuild->FindPin(pCapSource, PINDIR_OUTPUT, NULL, NULL,
false, 0, &pCapSourcePin)))
877 int iCount = 0, iSize = 0;
878 if(FAILED(hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize)))
882 if (iSize ==
sizeof(VIDEO_STREAM_CONFIG_CAPS))
886 for (
int iFormat = 0; iFormat < iCount; iFormat++)
888 VIDEO_STREAM_CONFIG_CAPS scc;
889 AM_MEDIA_TYPE *pmtConfig;
890 hr = pConfig->GetStreamCaps(iFormat, &pmtConfig, (BYTE*)&scc);
898 if (SUCCEEDED(hr)&& found==
false)
901 if ((pmtConfig->majortype == sgCB.connectedMediaType.majortype) &&
902 (pmtConfig->subtype == sgCB.connectedMediaType.subtype) &&
903 (pmtConfig->formattype == sgCB.connectedMediaType.formattype) &&
904 (pmtConfig->cbFormat >= sizeof (VIDEOINFOHEADER)) &&
905 (pmtConfig->pbFormat != NULL))
907 VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER*)pmtConfig->pbFormat;
909 LONG lWidth = pVih->bmiHeader.biWidth;
910 LONG lHeight = pVih->bmiHeader.biHeight;
911 if(framerate != NULL)
913 if((
unsigned int)lWidth == width && (
unsigned int)lHeight == height)
916 pVih->AvgTimePerFrame = (LONGLONG)(10000000 / framerate);
918 if(FAILED(hr = pConfig->SetFormat(pmtConfig))||
919 FAILED(hr = pGrabberI->SetMediaType(pmtConfig)))
925 if(FAILED(hr = pGrabberI->GetConnectedMediaType(&(sgCB.connectedMediaType))))
927 pVih = (VIDEOINFOHEADER*)sgCB.connectedMediaType.pbFormat;
928 LONGLONG ActualFrameDuration;
929 if(FAILED(hr = pVideoControl->GetCurrentActualFrameRate(pCapSourcePin,&ActualFrameDuration)))
930 std::cout<<
"Current format (not sure): "<<width <<
" x "<< height <<
" at "<< 10000000/pVih->AvgTimePerFrame <<
" fps"<<std::endl<<std::endl;
932 std::cout<<
"Current format : "<<width <<
" x "<< height <<
" at "<< 10000000/ActualFrameDuration <<
" fps"<<std::endl<<std::endl;
933 pVih->AvgTimePerFrame = ActualFrameDuration;
940 if((
unsigned int)lWidth == width && (
unsigned int)lHeight == height)
942 pVih->AvgTimePerFrame = scc.MinFrameInterval;
944 if(FAILED(hr = pConfig->SetFormat(pmtConfig))||
945 FAILED(hr = pGrabberI->SetMediaType(pmtConfig)))
948 if(FAILED(hr = pGrabberI->GetConnectedMediaType(&(sgCB.connectedMediaType))))
950 pVih = (VIDEOINFOHEADER*)sgCB.connectedMediaType.pbFormat;
952 std::cout<<
"Current format : "<<width <<
" x "<< height <<
" at "<<(10000000 /pVih->AvgTimePerFrame) <<
" fps"<<std::endl<<std::endl;
959 MyDeleteMediaType(pmtConfig);
963 if(framerate != NULL)
964 std::cout <<
"The "<<width <<
" x "<< height <<
" at " <<framerate<<
" fps source image format is not available. "<<std::endl<<std::endl;
966 std::cout <<
"The "<<width <<
" x "<< height <<
"source image size is not available. "<<std::endl<<std::endl;
976 void vpDirectShowGrabberImpl::getFormat(
unsigned int &width,
unsigned int &height,
double &framerate)
982 "Initialization not done") );
984 VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER*)sgCB.connectedMediaType.pbFormat;
985 width = (
unsigned int)pVih->bmiHeader.biWidth;
986 height = (
unsigned int)pVih->bmiHeader.biHeight;
987 framerate = (
double)(10000000/pVih->AvgTimePerFrame);
993 bool vpDirectShowGrabberImpl::getStreamCapabilities()
999 "Initialization not done") );
1003 IAMStreamConfig *pConfig = NULL;
1005 if(FAILED(hr = pBuild->FindInterface(
1006 &LOOK_UPSTREAM_ONLY,
1009 IID_IAMStreamConfig, (
void**)&pConfig)))
1012 int iCount = 0, iSize = 0;
1013 if(FAILED(hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize)))
1017 if (iSize ==
sizeof(VIDEO_STREAM_CONFIG_CAPS))
1019 std::cout<<
"Available MediaTypes : "<<std::endl<<std::endl;
1021 for (
int iFormat = 0; iFormat < iCount; iFormat++)
1023 VIDEO_STREAM_CONFIG_CAPS scc;
1024 AM_MEDIA_TYPE *pmtConfig;
1025 hr = pConfig->GetStreamCaps(iFormat, &pmtConfig, (BYTE*)&scc);
1030 VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER*)pmtConfig->pbFormat;
1036 std::cout<<
"MediaType : "<<iFormat<<std::endl;
1038 if(pmtConfig->subtype==MEDIASUBTYPE_ARGB32)
1039 std::cout<<
"subtype (not supported): MEDIASUBTYPE_ARGB32"<<std::endl;
1040 else if(pmtConfig->subtype==MEDIASUBTYPE_RGB32)
1041 std::cout<<
"subtype : MEDIASUBTYPE_RGB32"<<std::endl;
1042 else if(pmtConfig->subtype==MEDIASUBTYPE_RGB24)
1043 std::cout<<
"subtype : MEDIASUBTYPE_RGB24"<<std::endl;
1044 else if(pmtConfig->subtype==MEDIASUBTYPE_RGB555)
1045 std::cout<<
"subtype (not supported): MEDIASUBTYPE_RGB555"<<std::endl;
1046 else if(pmtConfig->subtype==MEDIASUBTYPE_RGB565)
1047 std::cout<<
"subtype (not supported): MEDIASUBTYPE_RGB565"<<std::endl;
1048 else if(pmtConfig->subtype==MEDIASUBTYPE_RGB8)
1049 std::cout<<
"subtype (not supported): MEDIASUBTYPE_RGB8"<<std::endl;
1050 else if(pmtConfig->subtype==MEDIASUBTYPE_RGB4)
1051 std::cout<<
"subtype (not supported): MEDIASUBTYPE_RGB4"<<std::endl;
1052 else if(pmtConfig->subtype==MEDIASUBTYPE_RGB1)
1053 std::cout<<
"subtype (not supported): MEDIASUBTYPE_RGB1"<<std::endl;
1054 else if(pmtConfig->subtype==MEDIASUBTYPE_YV12)
1055 std::cout<<
"subtype : MEDIASUBTYPE_YV12"<<std::endl;
1056 else if(pmtConfig->subtype==MEDIASUBTYPE_YVU9)
1057 std::cout<<
"subtype : MEDIASUBTYPE_YVU9"<<std::endl;
1058 else if(pmtConfig->subtype==MEDIASUBTYPE_YUY2)
1059 std::cout<<
"subtype : MEDIASUBTYPE_YUY2"<<std::endl;
1060 else if(pmtConfig->subtype==MEDIASUBTYPE_YUYV)
1061 std::cout<<
"subtype : MEDIASUBTYPE_YUYV"<<std::endl;
1062 else if(pmtConfig->subtype==MEDIASUBTYPE_YVYU)
1063 std::cout<<
"subtype : MEDIASUBTYPE_YVYU"<<std::endl;
1064 else if(pmtConfig->subtype==MEDIASUBTYPE_IYUV)
1065 std::cout<<
"subtype : MEDIASUBTYPE_IYUV"<<std::endl;
1066 else if(pmtConfig->subtype==MEDIASUBTYPE_UYVY)
1067 std::cout<<
"subtype : MEDIASUBTYPE_UYVY"<<std::endl;
1068 else if((((pVih->bmiHeader.biCompression&0xFF000000)>>24) |
1069 ((pVih->bmiHeader.biCompression&0x00FF0000)>>8) |
1070 ((pVih->bmiHeader.biCompression&0x0000FF00)<<8) |
1071 ((pVih->bmiHeader.biCompression&0x000000FF)<<24)) ==
'I420')
1072 std::cout<<
"subtype : I420"<<std::endl;
1073 else std::cout<<
"subtype (not supported) :"
1074 <<(char)(pVih->bmiHeader.biCompression&0x000000FF)
1075 <<(char)((pVih->bmiHeader.biCompression&0x0000FF00)>>8)
1076 <<(
char)((pVih->bmiHeader.biCompression&0x00FF0000)>>16)
1077 <<(char)((pVih->bmiHeader.biCompression&0xFF000000)>>24)<<std::endl;
1079 std::cout<<
"image size : "<<pVih->bmiHeader.biWidth<<
" x "<<pVih->bmiHeader.biHeight<<std::endl;
1080 std::cout<<
"framerate range: ["<< 10000000/scc.MaxFrameInterval<<
","<<10000000/scc.MinFrameInterval<<
"]"<<std::endl<<std::endl;
1096 MyDeleteMediaType(pmtConfig);
1104 bool vpDirectShowGrabberImpl::setMediaType(
int mediaTypeID)
1110 "Initialization not done") );
1114 IAMStreamConfig *pConfig = NULL;
1116 if(FAILED(hr = pBuild->FindInterface(
1117 &LOOK_UPSTREAM_ONLY,
1120 IID_IAMStreamConfig, (
void**)&pConfig)))
1123 VIDEO_STREAM_CONFIG_CAPS scc;
1124 AM_MEDIA_TYPE *pmtConfig;
1125 hr = pConfig->GetStreamCaps(mediaTypeID, &pmtConfig, (BYTE*)&scc);
1130 VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER*)pmtConfig->pbFormat;
1131 pVih->AvgTimePerFrame = scc.MinFrameInterval ;
1133 if(FAILED(hr = pGrabberI->SetMediaType(pmtConfig))||
1134 FAILED(hr = pConfig->SetFormat(pmtConfig)))
1137 if(FAILED(hr = pGrabberI->GetConnectedMediaType(&(sgCB.connectedMediaType))))
1141 MyDeleteMediaType(pmtConfig);
1149 int vpDirectShowGrabberImpl::getMediaType()
1155 "Initialization not done") );
1158 int mediaTypeID = -1;
1159 VIDEOINFOHEADER *pVihConnected = (VIDEOINFOHEADER*)sgCB.connectedMediaType.pbFormat;
1162 IAMStreamConfig *pConfig = NULL;
1164 if(FAILED(hr = pBuild->FindInterface(
1165 &LOOK_UPSTREAM_ONLY,
1168 IID_IAMStreamConfig, (
void**)&pConfig)))
1171 int iCount = 0, iSize = 0;
1172 if(FAILED(hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize)))
1176 if (iSize ==
sizeof(VIDEO_STREAM_CONFIG_CAPS))
1179 for (
int iFormat = 0; iFormat < iCount; iFormat++)
1181 VIDEO_STREAM_CONFIG_CAPS scc;
1182 AM_MEDIA_TYPE *pmtConfig;
1183 hr = pConfig->GetStreamCaps(iFormat, &pmtConfig, (BYTE*)&scc);
1188 if ((pmtConfig->majortype == sgCB.connectedMediaType.majortype) &&
1189 (pmtConfig->subtype == sgCB.connectedMediaType.subtype) &&
1190 (pmtConfig->formattype == sgCB.connectedMediaType.formattype) &&
1191 (pmtConfig->cbFormat >= sizeof (VIDEOINFOHEADER)) &&
1192 (pmtConfig->pbFormat != NULL))
1194 VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER*)pmtConfig->pbFormat;
1195 if(pVih->bmiHeader.biWidth == pVihConnected->bmiHeader.biWidth &&
1196 pVih->bmiHeader.biHeight == pVihConnected->bmiHeader.biHeight)
1197 mediaTypeID = iFormat ;
1201 MyDeleteMediaType(pmtConfig);
1211 void vpDirectShowGrabberImpl::MyDeleteMediaType(AM_MEDIA_TYPE *pmt)
1215 MyFreeMediaType(*pmt);
1224 void vpDirectShowGrabberImpl::MyFreeMediaType(AM_MEDIA_TYPE& mt)
1226 if (mt.cbFormat != 0)
1228 CoTaskMemFree((PVOID)mt.pbFormat);
1232 if (mt.pUnk != NULL)
unsigned int getWidth() const
Error that can be emited by the vpFrameGrabber class and its derivates.
unsigned int getHeight() const