39 #ifndef DOXYGEN_SHOULD_SKIP_THIS
41 #include <visp3/core/vpConfig.h>
42 #if ( defined(VISP_HAVE_DIRECTSHOW) )
44 #include <visp3/sensor/vpDirectShowGrabberImpl.h>
46 vpDirectShowDevice * vpDirectShowGrabberImpl::deviceList = NULL;
47 unsigned int vpDirectShowGrabberImpl::nbDevices ;
52 void vpDirectShowGrabberImpl::HRtoStr(std::string str)
54 TCHAR szErr[MAX_ERROR_TEXT_LEN];
55 DWORD res = AMGetErrorText(hr, szErr, MAX_ERROR_TEXT_LEN);
57 if (res == 0) str =
"Unknown Error: 0x%2x";
59 char msg[MAX_ERROR_TEXT_LEN];
60 sprintf(msg,
"%s",szErr);
69 vpDirectShowGrabberImpl::vpDirectShowGrabberImpl()
74 if (FAILED(hr = CoInitializeEx(NULL,COINIT_MULTITHREADED)))
80 "Can't initialize COM\n"+ err));
85 if(deviceList == NULL) {
86 CComPtr<IEnumMoniker> pVideoInputEnum = NULL;
88 if(enumerate(pVideoInputEnum)) {
89 createDeviceList(pVideoInputEnum);
92 pVideoInputEnum.Release();
100 void vpDirectShowGrabberImpl::open()
103 if(deviceList == NULL) {
104 CComPtr<IEnumMoniker> pVideoInputEnum = NULL;
106 if(enumerate(pVideoInputEnum)) {
107 createDeviceList(pVideoInputEnum);
110 pVideoInputEnum.Release();
113 init = initDirectShow();
145 bool vpDirectShowGrabberImpl::initDirectShow()
150 currentDevice = getFirstUnusedDevice(pCapSource);
152 if(currentDevice == nbDevices)
160 if(FAILED(hr = pGraph->AddFilter(pCapSource, L
"Capture Filter")))
164 if(!createSampleGrabber(pGrabberFilter))
168 if(FAILED(hr = pGraph->AddFilter(pGrabberFilter, L
"SampleGrabber")))
172 if(!connectSourceToGrabber(pCapSource, pGrabberFilter))
177 if(FAILED(hr = pGrabberI->GetConnectedMediaType(&(sgCB.connectedMediaType))))
181 CComPtr<IMediaFilter> pMediaFilter;
183 pGraph->QueryInterface(IID_IMediaFilter, (
void **)&pMediaFilter);
184 pGraph->QueryInterface(IID_IMediaControl, reinterpret_cast<void**>(&pControl));
185 pGraph->QueryInterface(IID_IMediaEvent, (
void **)&pEvent);
187 pMediaFilter->SetSyncSource(NULL);
188 pMediaFilter.Release();
196 vpDirectShowGrabberImpl::~vpDirectShowGrabberImpl()
206 bool vpDirectShowGrabberImpl::enumerate(CComPtr<IEnumMoniker>& ppVideoInputEnum)
208 CComPtr<ICreateDevEnum> pDevEnum = NULL;
212 hr = pDevEnum.CoCreateInstance(CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER);
218 hr = pDevEnum->CreateClassEnumerator(
219 CLSID_VideoInputDeviceCategory,
220 &ppVideoInputEnum, 0);
222 if(hr == S_OK) res =
true;
236 bool vpDirectShowGrabberImpl::createDeviceList(CComPtr<IEnumMoniker>& ppVideoInputEnum)
238 CComPtr<IMoniker> pMoniker[10];
239 unsigned long nbMoniker;
241 ppVideoInputEnum->Reset();
244 ppVideoInputEnum->Next(10, reinterpret_cast<IMoniker **>(&pMoniker), &nbMoniker);
247 if(nbMoniker == 0)
return false;
249 deviceList =
new vpDirectShowDevice[nbMoniker];
251 nbDevices = (
unsigned int)nbMoniker;
259 if(!deviceList[i].init(pMoniker[j]))
273 if(nbDevices == 0)
return false;
276 for(
unsigned int i=0 ; i<nbMoniker ;i++)
278 pMoniker[i].Release();
291 bool vpDirectShowGrabberImpl::getDevice(
unsigned int n, CComPtr<IBaseFilter>& ppDevice)
298 if(deviceList[n].getState() ==
true)
302 CComPtr<IEnumMoniker> pVideoInputEnum = NULL;
303 if(!enumerate(pVideoInputEnum))
306 CComPtr<IMoniker> pMoniker = NULL;
307 bool deviceFound =
false;
310 while (pVideoInputEnum->Next(1, &pMoniker, NULL) == S_OK
314 if(deviceList[n] == vpDirectShowDevice(pMoniker))
317 if(SUCCEEDED(pMoniker->BindToObject(0, 0, IID_IBaseFilter, (
void**)&ppDevice)))
320 deviceList[n].setInUse();
328 pVideoInputEnum.Release();
338 unsigned int vpDirectShowGrabberImpl::getFirstUnusedDevice(CComPtr<IBaseFilter>& ppDevice)
343 for(n=0;n<nbDevices && !found; n++)
346 if(!deviceList[n].getState())
348 if(getDevice(n,ppDevice))
351 deviceList[n].setInUse();
364 bool vpDirectShowGrabberImpl::createGraph()
368 hr = pBuild.CoCreateInstance(CLSID_CaptureGraphBuilder2, 0, CLSCTX_INPROC_SERVER);
373 hr = pGraph.CoCreateInstance(CLSID_FilterGraph, 0, CLSCTX_INPROC_SERVER);
378 pBuild->SetFiltergraph(pGraph);
392 bool vpDirectShowGrabberImpl::createSampleGrabber(CComPtr<IBaseFilter>& ppGrabberFilter)
395 hr = ppGrabberFilter.CoCreateInstance(CLSID_SampleGrabber, NULL, CLSCTX_INPROC_SERVER);
401 hr = ppGrabberFilter->QueryInterface(IID_ISampleGrabber,
402 reinterpret_cast<void**>(&pGrabberI));
409 ZeroMemory(&mt,
sizeof(AM_MEDIA_TYPE));
411 mt.majortype = MEDIATYPE_Video;
414 mt.subtype = MEDIATYPE_NULL;
416 if(FAILED(hr = pGrabberI->SetMediaType(&mt)))
420 pGrabberI->SetCallback(&sgCB,1);
423 pGrabberI->SetOneShot(TRUE);
426 pGrabberI->SetBufferSamples(
false);
440 bool vpDirectShowGrabberImpl::checkSourceType(CComPtr<IPin>& pCapSourcePin)
444 if(FAILED (pCapSourcePin->ConnectionMediaType(&mt)))
447 if(mt.majortype != MEDIATYPE_Video)
451 if(mt.subtype == MEDIASUBTYPE_ARGB32 ||
452 mt.subtype == MEDIASUBTYPE_RGB32 ||
453 mt.subtype == MEDIASUBTYPE_RGB24 ||
454 mt.subtype == MEDIASUBTYPE_RGB555 ||
455 mt.subtype == MEDIASUBTYPE_RGB565 ||
456 mt.subtype == MEDIASUBTYPE_RGB8 ||
457 mt.subtype == MEDIASUBTYPE_RGB4 ||
458 mt.subtype == MEDIASUBTYPE_RGB1 )
461 sgCB.specialMediaType =
false;
464 else if(mt.subtype == MEDIASUBTYPE_AYUV ||
465 mt.subtype == MEDIASUBTYPE_UYVY ||
466 mt.subtype == MEDIASUBTYPE_Y411 ||
467 mt.subtype == MEDIASUBTYPE_Y41P ||
468 mt.subtype == MEDIASUBTYPE_Y211 ||
469 mt.subtype == MEDIASUBTYPE_YUY2 ||
470 mt.subtype == MEDIASUBTYPE_YVYU ||
471 mt.subtype == MEDIASUBTYPE_YUYV ||
472 mt.subtype == MEDIASUBTYPE_IF09 ||
473 mt.subtype == MEDIASUBTYPE_IYUV ||
474 mt.subtype == MEDIASUBTYPE_YV12 ||
475 mt.subtype == MEDIASUBTYPE_YVU9 )
478 sgCB.specialMediaType =
false;
484 sgCB.specialMediaType =
true;
487 VIDEOINFOHEADER *pVih =
reinterpret_cast<VIDEOINFOHEADER*
>(mt.pbFormat);
488 BITMAPINFOHEADER bmpInfo = pVih->bmiHeader;
491 format = ((bmpInfo.biCompression&0xFF000000)>>24) |
492 ((bmpInfo.biCompression&0x00FF0000)>>8) |
493 ((bmpInfo.biCompression&0x0000FF00)<<8) |
494 (bmpInfo.biCompression&0x000000FF)<<24;
496 std::cout<<
"This format is not one of the standard YUV or RGB format supported by DirectShow.\n"
498 <<(char)(bmpInfo.biCompression&0x000000FF)
499 <<(char)((bmpInfo.biCompression&0x0000FF00)>>8)
500 <<(
char)((bmpInfo.biCompression&0x00FF0000)>>16)
501 <<(char)((bmpInfo.biCompression&0xFF000000)>>24)<<std::endl;
506 sgCB.invertedSource =
false;
509 else if(format ==
'cyuv')
511 sgCB.invertedSource =
true;
517 std::cout<<
"Unknown FourCC compression type, assuming top-down orientation. Image may be inverted."<<std::endl;
518 sgCB.invertedSource =
false;
531 bool vpDirectShowGrabberImpl::connectSourceToGrabber(CComPtr<IBaseFilter>& _pCapSource, CComPtr<IBaseFilter>& _pGrabberFilter)
551 if(FAILED(hr = pBuild->RenderStream(NULL,NULL, _pCapSource, NULL, _pGrabberFilter)))
561 CComPtr<IBaseFilter> pNull = NULL;
562 if (FAILED(pNull.CoCreateInstance(CLSID_NullRenderer, NULL, CLSCTX_INPROC_SERVER)))
576 if( FAILED(pGraph->AddFilter(pNull, L
"NullRenderer")) ||
577 FAILED(pBuild->RenderStream(NULL,NULL, _pGrabberFilter, NULL, pNull)))
581 CComPtr<IPin> pCapSourcePin;
582 if(FAILED(pBuild->FindPin(_pCapSource, PINDIR_OUTPUT, NULL, NULL,
false, 0, &pCapSourcePin)))
586 if(!checkSourceType(pCapSourcePin))
590 pCapSourcePin.Release();
604 bool vpDirectShowGrabberImpl::removeAll()
606 CComPtr<IEnumFilters> pEnum = NULL;
607 CComPtr<IBaseFilter> pFilter;
610 if (FAILED(hr = pGraph->EnumFilters(&pEnum)))
613 while(pEnum->Next(1, &pFilter, &cFetched) == S_OK)
615 if(FAILED(hr = pGraph->RemoveFilter(pFilter)))
return false;
639 "Initialization not done") );
645 sgCB.acqRGBaDemand =
true;
652 hr = pEvent->WaitForCompletion(MAX_DELAY, &ev);
658 if( WaitForSingleObject(sgCB.copySem,MAX_DELAY) != WAIT_OBJECT_0)
660 "Can't grab the frame, callback timeout") );
679 "Initialization not done") );
685 sgCB.acqGrayDemand =
true;
692 hr = pEvent->WaitForCompletion(MAX_DELAY, &ev);
698 if( WaitForSingleObject(sgCB.copySem,MAX_DELAY) != WAIT_OBJECT_0)
700 "Can't grab the frame, callback timeout") );
709 bool vpDirectShowGrabberImpl::setDevice(
unsigned int id)
715 "Initialization not done") );
720 if(
id>=nbDevices || deviceList[
id].getState()==
true)
727 if(!removeAll())
return false;
731 pCapSource.Release();
734 deviceList[currentDevice].resetInUse();
737 pGraph->AddFilter(pGrabberFilter,L
"SampleGrabber");
740 if(!getDevice(
id, pCapSource))
744 if(FAILED(hr = pGraph->AddFilter(pCapSource, L
"Capture Filter")))
748 if(!connectSourceToGrabber(pCapSource, pGrabberFilter))
753 if(FAILED(hr = pGrabberI->GetConnectedMediaType(&(sgCB.connectedMediaType))))
759 deviceList[id].setInUse();
768 void vpDirectShowGrabberImpl::displayDevices()
770 if(deviceList == NULL)
773 "Initialization not done") );
776 for(
unsigned int i=0 ; i<nbDevices ; i++)
777 std::cout<<i<<
" : "<< deviceList[i].getName() <<std::endl;
779 std::cout<<
"Current device : "<<currentDevice<<std::endl<<std::endl;
787 void vpDirectShowGrabberImpl::close()
791 deviceList[currentDevice].resetInUse();
803 bool vpDirectShowGrabberImpl::setImageSize(
unsigned int width,
unsigned int height)
809 "Initialization not done") );
812 return setFormat(width, height,NULL);
819 bool vpDirectShowGrabberImpl::setFramerate(
double framerate)
825 "Initialization not done") );
828 VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER*)sgCB.connectedMediaType.pbFormat;
829 return setFormat(pVih->bmiHeader.biWidth,pVih->bmiHeader.biHeight,framerate);
835 bool vpDirectShowGrabberImpl::setFormat(
unsigned int width,
unsigned int height,
double framerate)
841 "Initialization not done") );
847 IAMStreamConfig *pConfig = NULL;
849 if(FAILED(hr = pBuild->FindInterface(
853 IID_IAMStreamConfig, (
void**)&pConfig)))
857 IAMVideoControl *pVideoControl = NULL;
859 if(FAILED(hr = pBuild->FindInterface(
863 IID_IAMVideoControl, (
void**)&pVideoControl)))
867 CComPtr<IPin> pCapSourcePin;
868 if(FAILED(pBuild->FindPin(pCapSource, PINDIR_OUTPUT, NULL, NULL,
false, 0, &pCapSourcePin)))
871 int iCount = 0, iSize = 0;
872 if(FAILED(hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize)))
876 if (iSize ==
sizeof(VIDEO_STREAM_CONFIG_CAPS))
880 for (
int iFormat = 0; iFormat < iCount; iFormat++)
882 VIDEO_STREAM_CONFIG_CAPS scc;
883 AM_MEDIA_TYPE *pmtConfig;
884 hr = pConfig->GetStreamCaps(iFormat, &pmtConfig, (BYTE*)&scc);
892 if (SUCCEEDED(hr)&& found==
false)
895 if ((pmtConfig->majortype == sgCB.connectedMediaType.majortype) &&
896 (pmtConfig->subtype == sgCB.connectedMediaType.subtype) &&
897 (pmtConfig->formattype == sgCB.connectedMediaType.formattype) &&
898 (pmtConfig->cbFormat >= sizeof (VIDEOINFOHEADER)) &&
899 (pmtConfig->pbFormat != NULL))
901 VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER*)pmtConfig->pbFormat;
903 LONG lWidth = pVih->bmiHeader.biWidth;
904 LONG lHeight = pVih->bmiHeader.biHeight;
905 if(framerate != NULL)
907 if((
unsigned int)lWidth == width && (
unsigned int)lHeight == height)
910 pVih->AvgTimePerFrame = (LONGLONG)(10000000 / framerate);
912 if(FAILED(hr = pConfig->SetFormat(pmtConfig))||
913 FAILED(hr = pGrabberI->SetMediaType(pmtConfig)))
919 if(FAILED(hr = pGrabberI->GetConnectedMediaType(&(sgCB.connectedMediaType))))
921 pVih = (VIDEOINFOHEADER*)sgCB.connectedMediaType.pbFormat;
922 LONGLONG ActualFrameDuration;
923 if(FAILED(hr = pVideoControl->GetCurrentActualFrameRate(pCapSourcePin,&ActualFrameDuration)))
924 std::cout<<
"Current format (not sure): "<<width <<
" x "<< height <<
" at "<< 10000000/pVih->AvgTimePerFrame <<
" fps"<<std::endl<<std::endl;
926 std::cout<<
"Current format : "<<width <<
" x "<< height <<
" at "<< 10000000/ActualFrameDuration <<
" fps"<<std::endl<<std::endl;
927 pVih->AvgTimePerFrame = ActualFrameDuration;
934 if((
unsigned int)lWidth == width && (
unsigned int)lHeight == height)
936 pVih->AvgTimePerFrame = scc.MinFrameInterval;
938 if(FAILED(hr = pConfig->SetFormat(pmtConfig))||
939 FAILED(hr = pGrabberI->SetMediaType(pmtConfig)))
942 if(FAILED(hr = pGrabberI->GetConnectedMediaType(&(sgCB.connectedMediaType))))
944 pVih = (VIDEOINFOHEADER*)sgCB.connectedMediaType.pbFormat;
946 std::cout<<
"Current format : "<<width <<
" x "<< height <<
" at "<<(10000000 /pVih->AvgTimePerFrame) <<
" fps"<<std::endl<<std::endl;
953 MyDeleteMediaType(pmtConfig);
957 if(framerate != NULL)
958 std::cout <<
"The "<<width <<
" x "<< height <<
" at " <<framerate<<
" fps source image format is not available. "<<std::endl<<std::endl;
960 std::cout <<
"The "<<width <<
" x "<< height <<
"source image size is not available. "<<std::endl<<std::endl;
970 void vpDirectShowGrabberImpl::getFormat(
unsigned int &width,
unsigned int &height,
double &framerate)
976 "Initialization not done") );
978 VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER*)sgCB.connectedMediaType.pbFormat;
979 width = (
unsigned int)pVih->bmiHeader.biWidth;
980 height = (
unsigned int)pVih->bmiHeader.biHeight;
981 framerate = (
double)(10000000/pVih->AvgTimePerFrame);
987 bool vpDirectShowGrabberImpl::getStreamCapabilities()
993 "Initialization not done") );
997 IAMStreamConfig *pConfig = NULL;
999 if(FAILED(hr = pBuild->FindInterface(
1000 &LOOK_UPSTREAM_ONLY,
1003 IID_IAMStreamConfig, (
void**)&pConfig)))
1006 int iCount = 0, iSize = 0;
1007 if(FAILED(hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize)))
1011 if (iSize ==
sizeof(VIDEO_STREAM_CONFIG_CAPS))
1013 std::cout<<
"Available MediaTypes : "<<std::endl<<std::endl;
1015 for (
int iFormat = 0; iFormat < iCount; iFormat++)
1017 VIDEO_STREAM_CONFIG_CAPS scc;
1018 AM_MEDIA_TYPE *pmtConfig;
1019 hr = pConfig->GetStreamCaps(iFormat, &pmtConfig, (BYTE*)&scc);
1024 VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER*)pmtConfig->pbFormat;
1030 std::cout<<
"MediaType : "<<iFormat<<std::endl;
1032 if(pmtConfig->subtype==MEDIASUBTYPE_ARGB32)
1033 std::cout<<
"subtype (not supported): MEDIASUBTYPE_ARGB32"<<std::endl;
1034 else if(pmtConfig->subtype==MEDIASUBTYPE_RGB32)
1035 std::cout<<
"subtype : MEDIASUBTYPE_RGB32"<<std::endl;
1036 else if(pmtConfig->subtype==MEDIASUBTYPE_RGB24)
1037 std::cout<<
"subtype : MEDIASUBTYPE_RGB24"<<std::endl;
1038 else if(pmtConfig->subtype==MEDIASUBTYPE_RGB555)
1039 std::cout<<
"subtype (not supported): MEDIASUBTYPE_RGB555"<<std::endl;
1040 else if(pmtConfig->subtype==MEDIASUBTYPE_RGB565)
1041 std::cout<<
"subtype (not supported): MEDIASUBTYPE_RGB565"<<std::endl;
1042 else if(pmtConfig->subtype==MEDIASUBTYPE_RGB8)
1043 std::cout<<
"subtype (not supported): MEDIASUBTYPE_RGB8"<<std::endl;
1044 else if(pmtConfig->subtype==MEDIASUBTYPE_RGB4)
1045 std::cout<<
"subtype (not supported): MEDIASUBTYPE_RGB4"<<std::endl;
1046 else if(pmtConfig->subtype==MEDIASUBTYPE_RGB1)
1047 std::cout<<
"subtype (not supported): MEDIASUBTYPE_RGB1"<<std::endl;
1048 else if(pmtConfig->subtype==MEDIASUBTYPE_YV12)
1049 std::cout<<
"subtype : MEDIASUBTYPE_YV12"<<std::endl;
1050 else if(pmtConfig->subtype==MEDIASUBTYPE_YVU9)
1051 std::cout<<
"subtype : MEDIASUBTYPE_YVU9"<<std::endl;
1052 else if(pmtConfig->subtype==MEDIASUBTYPE_YUY2)
1053 std::cout<<
"subtype : MEDIASUBTYPE_YUY2"<<std::endl;
1054 else if(pmtConfig->subtype==MEDIASUBTYPE_YUYV)
1055 std::cout<<
"subtype : MEDIASUBTYPE_YUYV"<<std::endl;
1056 else if(pmtConfig->subtype==MEDIASUBTYPE_YVYU)
1057 std::cout<<
"subtype : MEDIASUBTYPE_YVYU"<<std::endl;
1058 else if(pmtConfig->subtype==MEDIASUBTYPE_IYUV)
1059 std::cout<<
"subtype : MEDIASUBTYPE_IYUV"<<std::endl;
1060 else if(pmtConfig->subtype==MEDIASUBTYPE_UYVY)
1061 std::cout<<
"subtype : MEDIASUBTYPE_UYVY"<<std::endl;
1062 else if((((pVih->bmiHeader.biCompression&0xFF000000)>>24) |
1063 ((pVih->bmiHeader.biCompression&0x00FF0000)>>8) |
1064 ((pVih->bmiHeader.biCompression&0x0000FF00)<<8) |
1065 ((pVih->bmiHeader.biCompression&0x000000FF)<<24)) ==
'I420')
1066 std::cout<<
"subtype : I420"<<std::endl;
1067 else std::cout<<
"subtype (not supported) :"
1068 <<(char)(pVih->bmiHeader.biCompression&0x000000FF)
1069 <<(char)((pVih->bmiHeader.biCompression&0x0000FF00)>>8)
1070 <<(
char)((pVih->bmiHeader.biCompression&0x00FF0000)>>16)
1071 <<(char)((pVih->bmiHeader.biCompression&0xFF000000)>>24)<<std::endl;
1073 std::cout<<
"image size : "<<pVih->bmiHeader.biWidth<<
" x "<<pVih->bmiHeader.biHeight<<std::endl;
1074 std::cout<<
"framerate range: ["<< 10000000/scc.MaxFrameInterval<<
","<<10000000/scc.MinFrameInterval<<
"]"<<std::endl<<std::endl;
1090 MyDeleteMediaType(pmtConfig);
1098 bool vpDirectShowGrabberImpl::setMediaType(
int mediaTypeID)
1104 "Initialization not done") );
1108 IAMStreamConfig *pConfig = NULL;
1110 if(FAILED(hr = pBuild->FindInterface(
1111 &LOOK_UPSTREAM_ONLY,
1114 IID_IAMStreamConfig, (
void**)&pConfig)))
1117 VIDEO_STREAM_CONFIG_CAPS scc;
1118 AM_MEDIA_TYPE *pmtConfig;
1119 hr = pConfig->GetStreamCaps(mediaTypeID, &pmtConfig, (BYTE*)&scc);
1124 VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER*)pmtConfig->pbFormat;
1125 pVih->AvgTimePerFrame = scc.MinFrameInterval ;
1127 if(FAILED(hr = pGrabberI->SetMediaType(pmtConfig))||
1128 FAILED(hr = pConfig->SetFormat(pmtConfig)))
1131 if(FAILED(hr = pGrabberI->GetConnectedMediaType(&(sgCB.connectedMediaType))))
1135 MyDeleteMediaType(pmtConfig);
1143 int vpDirectShowGrabberImpl::getMediaType()
1149 "Initialization not done") );
1152 int mediaTypeID = -1;
1153 VIDEOINFOHEADER *pVihConnected = (VIDEOINFOHEADER*)sgCB.connectedMediaType.pbFormat;
1156 IAMStreamConfig *pConfig = NULL;
1158 if(FAILED(hr = pBuild->FindInterface(
1159 &LOOK_UPSTREAM_ONLY,
1162 IID_IAMStreamConfig, (
void**)&pConfig)))
1165 int iCount = 0, iSize = 0;
1166 if(FAILED(hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize)))
1170 if (iSize ==
sizeof(VIDEO_STREAM_CONFIG_CAPS))
1173 for (
int iFormat = 0; iFormat < iCount; iFormat++)
1175 VIDEO_STREAM_CONFIG_CAPS scc;
1176 AM_MEDIA_TYPE *pmtConfig;
1177 hr = pConfig->GetStreamCaps(iFormat, &pmtConfig, (BYTE*)&scc);
1182 if ((pmtConfig->majortype == sgCB.connectedMediaType.majortype) &&
1183 (pmtConfig->subtype == sgCB.connectedMediaType.subtype) &&
1184 (pmtConfig->formattype == sgCB.connectedMediaType.formattype) &&
1185 (pmtConfig->cbFormat >= sizeof (VIDEOINFOHEADER)) &&
1186 (pmtConfig->pbFormat != NULL))
1188 VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER*)pmtConfig->pbFormat;
1189 if(pVih->bmiHeader.biWidth == pVihConnected->bmiHeader.biWidth &&
1190 pVih->bmiHeader.biHeight == pVihConnected->bmiHeader.biHeight)
1191 mediaTypeID = iFormat ;
1195 MyDeleteMediaType(pmtConfig);
1205 void vpDirectShowGrabberImpl::MyDeleteMediaType(AM_MEDIA_TYPE *pmt)
1209 MyFreeMediaType(*pmt);
1218 void vpDirectShowGrabberImpl::MyFreeMediaType(AM_MEDIA_TYPE& mt)
1220 if (mt.cbFormat != 0)
1222 CoTaskMemFree((PVOID)mt.pbFormat);
1226 if (mt.pUnk != NULL)
1234 #elif !defined(VISP_BUILD_SHARED_LIBS)
1236 void dummy_vpDirectShowGrabberImpl() {};
unsigned int getWidth() const
Error that can be emited by the vpFrameGrabber class and its derivates.
unsigned int getHeight() const