36 #ifndef DOXYGEN_SHOULD_SKIP_THIS
38 #include <visp3/core/vpConfig.h>
39 #if (defined(VISP_HAVE_DIRECTSHOW))
41 #include <visp3/sensor/vpDirectShowGrabberImpl.h>
44 vpDirectShowDevice *vpDirectShowGrabberImpl::deviceList =
nullptr;
45 unsigned int vpDirectShowGrabberImpl::nbDevices;
50 void vpDirectShowGrabberImpl::HRtoStr(std::string &str)
52 TCHAR szErr[MAX_ERROR_TEXT_LEN];
53 DWORD res = AMGetErrorText(hr, szErr, MAX_ERROR_TEXT_LEN);
56 str =
"Unknown Error: 0x%2x";
58 char msg[MAX_ERROR_TEXT_LEN];
59 snprintf(msg, MAX_ERROR_TEXT_LEN,
"%s", szErr);
67 vpDirectShowGrabberImpl::vpDirectShowGrabberImpl()
72 if (FAILED(hr = CoInitializeEx(
nullptr, COINIT_MULTITHREADED))) {
80 if (deviceList ==
nullptr) {
81 CComPtr<IEnumMoniker> pVideoInputEnum =
nullptr;
83 if (enumerate(pVideoInputEnum)) {
84 createDeviceList(pVideoInputEnum);
87 pVideoInputEnum.Release();
95 void vpDirectShowGrabberImpl::open()
98 if (deviceList ==
nullptr) {
99 CComPtr<IEnumMoniker> pVideoInputEnum =
nullptr;
101 if (enumerate(pVideoInputEnum)) {
102 createDeviceList(pVideoInputEnum);
105 pVideoInputEnum.Release();
108 init = initDirectShow();
132 bool vpDirectShowGrabberImpl::initDirectShow()
136 currentDevice = getFirstUnusedDevice(pCapSource);
138 if (currentDevice == nbDevices)
146 if (FAILED(hr = pGraph->AddFilter(pCapSource, L
"Capture Filter")))
150 if (!createSampleGrabber(pGrabberFilter))
154 if (FAILED(hr = pGraph->AddFilter(pGrabberFilter, L
"SampleGrabber")))
158 if (!connectSourceToGrabber(pCapSource, pGrabberFilter))
162 if (FAILED(hr = pGrabberI->GetConnectedMediaType(&(sgCB.connectedMediaType))))
166 CComPtr<IMediaFilter> pMediaFilter;
168 pGraph->QueryInterface(IID_IMediaFilter, (
void **)&pMediaFilter);
169 pGraph->QueryInterface(IID_IMediaControl,
reinterpret_cast<void **
>(&pControl));
170 pGraph->QueryInterface(IID_IMediaEvent, (
void **)&pEvent);
172 pMediaFilter->SetSyncSource(
nullptr);
173 pMediaFilter.Release();
181 vpDirectShowGrabberImpl::~vpDirectShowGrabberImpl() { close(); }
188 bool vpDirectShowGrabberImpl::enumerate(CComPtr<IEnumMoniker> &ppVideoInputEnum)
190 CComPtr<ICreateDevEnum> pDevEnum =
nullptr;
194 hr = pDevEnum.CoCreateInstance(CLSID_SystemDeviceEnum,
nullptr, CLSCTX_INPROC_SERVER);
199 hr = pDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &ppVideoInputEnum, 0);
214 bool vpDirectShowGrabberImpl::createDeviceList(CComPtr<IEnumMoniker> &ppVideoInputEnum)
216 CComPtr<IMoniker> pMoniker[10];
217 unsigned long nbMoniker;
219 ppVideoInputEnum->Reset();
222 ppVideoInputEnum->Next(10,
reinterpret_cast<IMoniker **
>(&pMoniker), &nbMoniker);
228 deviceList =
new vpDirectShowDevice[nbMoniker];
230 nbDevices = (
unsigned int)nbMoniker;
236 while (i < nbDevices) {
237 if (!deviceList[i].
init(pMoniker[j])) {
253 for (
unsigned int i = 0; i < nbMoniker; i++) {
254 pMoniker[i].Release();
266 bool vpDirectShowGrabberImpl::getDevice(
unsigned int n, CComPtr<IBaseFilter> &ppDevice)
273 if (deviceList[n].getState() ==
true)
277 CComPtr<IEnumMoniker> pVideoInputEnum =
nullptr;
278 if (!enumerate(pVideoInputEnum))
281 CComPtr<IMoniker> pMoniker =
nullptr;
282 bool deviceFound =
false;
285 while (pVideoInputEnum->Next(1, &pMoniker,
nullptr) == S_OK && !deviceFound) {
287 if (deviceList[n] == vpDirectShowDevice(pMoniker)) {
289 if (SUCCEEDED(pMoniker->BindToObject(0, 0, IID_IBaseFilter, (
void **)&ppDevice))) {
291 deviceList[n].setInUse();
301 pVideoInputEnum.Release();
312 unsigned int vpDirectShowGrabberImpl::getFirstUnusedDevice(CComPtr<IBaseFilter> &ppDevice)
317 for (n = 0; n < nbDevices && !found; n++) {
319 if (!deviceList[n].getState()) {
320 if (getDevice(n, ppDevice)) {
322 deviceList[n].setInUse();
335 bool vpDirectShowGrabberImpl::createGraph()
339 hr = pBuild.CoCreateInstance(CLSID_CaptureGraphBuilder2, 0, CLSCTX_INPROC_SERVER);
343 hr = pGraph.CoCreateInstance(CLSID_FilterGraph, 0, CLSCTX_INPROC_SERVER);
347 pBuild->SetFiltergraph(pGraph);
361 bool vpDirectShowGrabberImpl::createSampleGrabber(CComPtr<IBaseFilter> &ppGrabberFilter)
364 hr = ppGrabberFilter.CoCreateInstance(CLSID_SampleGrabber,
nullptr, CLSCTX_INPROC_SERVER);
370 hr = ppGrabberFilter->QueryInterface(IID_ISampleGrabber,
reinterpret_cast<void **
>(&pGrabberI));
377 ZeroMemory(&mt,
sizeof(AM_MEDIA_TYPE));
379 mt.majortype = MEDIATYPE_Video;
382 mt.subtype = MEDIATYPE_nullptr;
384 if (FAILED(hr = pGrabberI->SetMediaType(&mt)))
388 pGrabberI->SetCallback(&sgCB, 1);
391 pGrabberI->SetOneShot(TRUE);
394 pGrabberI->SetBufferSamples(
false);
408 bool vpDirectShowGrabberImpl::checkSourceType(CComPtr<IPin> &pCapSourcePin)
412 if (FAILED(pCapSourcePin->ConnectionMediaType(&mt)))
415 if (mt.majortype != MEDIATYPE_Video)
419 if (mt.subtype == MEDIASUBTYPE_ARGB32 || mt.subtype == MEDIASUBTYPE_RGB32 || mt.subtype == MEDIASUBTYPE_RGB24 ||
420 mt.subtype == MEDIASUBTYPE_RGB555 || mt.subtype == MEDIASUBTYPE_RGB565 || mt.subtype == MEDIASUBTYPE_RGB8 ||
421 mt.subtype == MEDIASUBTYPE_RGB4 || mt.subtype == MEDIASUBTYPE_RGB1) {
423 sgCB.specialMediaType =
false;
426 else if (mt.subtype == MEDIASUBTYPE_AYUV || mt.subtype == MEDIASUBTYPE_UYVY || mt.subtype == MEDIASUBTYPE_Y411 ||
427 mt.subtype == MEDIASUBTYPE_Y41P || mt.subtype == MEDIASUBTYPE_Y211 || mt.subtype == MEDIASUBTYPE_YUY2 ||
428 mt.subtype == MEDIASUBTYPE_YVYU || mt.subtype == MEDIASUBTYPE_YUYV || mt.subtype == MEDIASUBTYPE_IF09 ||
429 mt.subtype == MEDIASUBTYPE_IYUV || mt.subtype == MEDIASUBTYPE_YV12 || mt.subtype == MEDIASUBTYPE_YVU9) {
431 sgCB.specialMediaType =
false;
436 sgCB.specialMediaType =
true;
439 VIDEOINFOHEADER *pVih =
reinterpret_cast<VIDEOINFOHEADER *
>(mt.pbFormat);
440 BITMAPINFOHEADER bmpInfo = pVih->bmiHeader;
443 format = ((bmpInfo.biCompression & 0xFF000000) >> 24) | ((bmpInfo.biCompression & 0x00FF0000) >> 8) |
444 ((bmpInfo.biCompression & 0x0000FF00) << 8) | (bmpInfo.biCompression & 0x000000FF) << 24;
446 std::cout <<
"This format is not one of the standard YUV or RGB format "
447 "supported by DirectShow.\n"
448 <<
"FourCC : " << (char)(bmpInfo.biCompression & 0x000000FF)
449 << (char)((bmpInfo.biCompression & 0x0000FF00) >> 8) << (
char)((bmpInfo.biCompression & 0x00FF0000) >> 16)
450 << (char)((bmpInfo.biCompression & 0xFF000000) >> 24) << std::endl;
454 if (format ==
'Y800') {
455 sgCB.invertedSource =
false;
459 else if (format ==
'cyuv') {
460 sgCB.invertedSource =
true;
466 std::cout <<
"Unknown FourCC compression type, assuming top-down "
467 "orientation. Image may be inverted."
469 sgCB.invertedSource =
false;
482 bool vpDirectShowGrabberImpl::connectSourceToGrabber(CComPtr<IBaseFilter> &_pCapSource,
483 CComPtr<IBaseFilter> &_pGrabberFilter)
503 if (FAILED(hr = pBuild->RenderStream(
nullptr,
nullptr, _pCapSource,
nullptr, _pGrabberFilter)))
507 CComPtr<IBaseFilter> pNull =
nullptr;
508 if (FAILED(pNull.CoCreateInstance(CLSID_NullRenderer,
nullptr, CLSCTX_INPROC_SERVER)))
511 if (FAILED(pGraph->AddFilter(pNull, L
"NullRenderer")) ||
512 FAILED(pBuild->RenderStream(
nullptr,
nullptr, _pGrabberFilter,
nullptr, pNull)))
516 CComPtr<IPin> pCapSourcePin;
517 if (FAILED(pBuild->FindPin(_pCapSource, PINDIR_OUTPUT,
nullptr,
nullptr,
false, 0, &pCapSourcePin)))
521 if (!checkSourceType(pCapSourcePin))
525 pCapSourcePin.Release();
536 bool vpDirectShowGrabberImpl::removeAll()
538 CComPtr<IEnumFilters> pEnum =
nullptr;
539 CComPtr<IBaseFilter> pFilter;
542 if (FAILED(hr = pGraph->EnumFilters(&pEnum)))
545 while (pEnum->Next(1, &pFilter, &cFetched) == S_OK) {
546 if (FAILED(hr = pGraph->RemoveFilter(pFilter)))
575 sgCB.acqRGBaDemand =
true;
582 hr = pEvent->WaitForCompletion(MAX_DELAY, &ev);
588 if (WaitForSingleObject(sgCB.copySem, MAX_DELAY) != WAIT_OBJECT_0)
611 sgCB.acqGrayDemand =
true;
618 hr = pEvent->WaitForCompletion(MAX_DELAY, &ev);
624 if (WaitForSingleObject(sgCB.copySem, MAX_DELAY) != WAIT_OBJECT_0)
634 bool vpDirectShowGrabberImpl::setDevice(
unsigned int id)
642 if (
id >= nbDevices || deviceList[
id].getState() ==
true)
653 pCapSource.Release();
656 deviceList[currentDevice].resetInUse();
659 pGraph->AddFilter(pGrabberFilter, L
"SampleGrabber");
662 if (!getDevice(
id, pCapSource))
666 if (FAILED(hr = pGraph->AddFilter(pCapSource, L
"Capture Filter")))
670 if (!connectSourceToGrabber(pCapSource, pGrabberFilter))
674 if (FAILED(hr = pGrabberI->GetConnectedMediaType(&(sgCB.connectedMediaType)))) {
679 deviceList[id].setInUse();
688 void vpDirectShowGrabberImpl::displayDevices()
690 if (deviceList ==
nullptr) {
694 for (
unsigned int i = 0; i < nbDevices; i++)
695 std::cout << i <<
" : " << deviceList[i].getName() << std::endl;
697 std::cout <<
"Current device : " << currentDevice << std::endl << std::endl;
704 void vpDirectShowGrabberImpl::close()
708 deviceList[currentDevice].resetInUse();
720 bool vpDirectShowGrabberImpl::setImageSize(
unsigned int width,
unsigned int height)
727 return setFormat(width, height,
nullptr);
733 bool vpDirectShowGrabberImpl::setFramerate(
double framerate)
740 VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER *)sgCB.connectedMediaType.pbFormat;
741 return setFormat(pVih->bmiHeader.biWidth, pVih->bmiHeader.biHeight, framerate);
746 bool vpDirectShowGrabberImpl::setFormat(
unsigned int width,
unsigned int height,
double framerate)
756 IAMStreamConfig *pConfig =
nullptr;
758 if (FAILED(hr = pBuild->FindInterface(&LOOK_UPSTREAM_ONLY,
761 IID_IAMStreamConfig, (
void **)&pConfig)))
765 IAMVideoControl *pVideoControl =
nullptr;
767 if (FAILED(hr = pBuild->FindInterface(&LOOK_UPSTREAM_ONLY,
770 IID_IAMVideoControl, (
void **)&pVideoControl)))
774 CComPtr<IPin> pCapSourcePin;
775 if (FAILED(pBuild->FindPin(pCapSource, PINDIR_OUTPUT,
nullptr,
nullptr,
false, 0, &pCapSourcePin)))
778 int iCount = 0, iSize = 0;
779 if (FAILED(hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize)))
783 if (iSize ==
sizeof(VIDEO_STREAM_CONFIG_CAPS)) {
786 for (
int iFormat = 0; iFormat < iCount; iFormat++) {
787 VIDEO_STREAM_CONFIG_CAPS scc;
788 AM_MEDIA_TYPE *pmtConfig;
789 hr = pConfig->GetStreamCaps(iFormat, &pmtConfig, (BYTE *)&scc);
791 if (SUCCEEDED(hr) && found ==
false) {
793 if ((pmtConfig->majortype == sgCB.connectedMediaType.majortype) &&
794 (pmtConfig->subtype == sgCB.connectedMediaType.subtype) &&
795 (pmtConfig->formattype == sgCB.connectedMediaType.formattype) &&
796 (pmtConfig->cbFormat >=
sizeof(VIDEOINFOHEADER)) && (pmtConfig->pbFormat !=
nullptr)) {
797 VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER *)pmtConfig->pbFormat;
799 LONG lWidth = pVih->bmiHeader.biWidth;
800 LONG lHeight = pVih->bmiHeader.biHeight;
801 if (framerate !=
nullptr) {
802 if ((
unsigned int)lWidth == width && (
unsigned int)lHeight == height) {
804 pVih->AvgTimePerFrame = (LONGLONG)(10000000 / framerate);
806 if (FAILED(hr = pConfig->SetFormat(pmtConfig)) || FAILED(hr = pGrabberI->SetMediaType(pmtConfig)))
812 if (FAILED(hr = pGrabberI->GetConnectedMediaType(&(sgCB.connectedMediaType))))
814 pVih = (VIDEOINFOHEADER *)sgCB.connectedMediaType.pbFormat;
815 LONGLONG ActualFrameDuration;
816 if (FAILED(hr = pVideoControl->GetCurrentActualFrameRate(pCapSourcePin, &ActualFrameDuration)))
817 std::cout <<
"Current format (not sure): " << width <<
" x " << height <<
" at "
818 << 10000000 / pVih->AvgTimePerFrame <<
" fps" << std::endl
821 std::cout <<
"Current format : " << width <<
" x " << height <<
" at " << 10000000 / ActualFrameDuration
822 <<
" fps" << std::endl
824 pVih->AvgTimePerFrame = ActualFrameDuration;
830 if ((
unsigned int)lWidth == width && (
unsigned int)lHeight == height) {
831 pVih->AvgTimePerFrame = scc.MinFrameInterval;
833 if (FAILED(hr = pConfig->SetFormat(pmtConfig)) || FAILED(hr = pGrabberI->SetMediaType(pmtConfig)))
836 if (FAILED(hr = pGrabberI->GetConnectedMediaType(&(sgCB.connectedMediaType))))
838 pVih = (VIDEOINFOHEADER *)sgCB.connectedMediaType.pbFormat;
840 std::cout <<
"Current format : " << width <<
" x " << height <<
" at "
841 << (10000000 / pVih->AvgTimePerFrame) <<
" fps" << std::endl
848 MyDeleteMediaType(pmtConfig);
852 if (framerate !=
nullptr)
853 std::cout <<
"The " << width <<
" x " << height <<
" at " << framerate
854 <<
" fps source image format is not available. " << std::endl
857 std::cout <<
"The " << width <<
" x " << height <<
"source image size is not available. " << std::endl
868 void vpDirectShowGrabberImpl::getFormat(
unsigned int &width,
unsigned int &height,
double &framerate)
874 VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER *)sgCB.connectedMediaType.pbFormat;
875 width = (
unsigned int)pVih->bmiHeader.biWidth;
876 height = (
unsigned int)pVih->bmiHeader.biHeight;
877 framerate = (
double)(10000000 / pVih->AvgTimePerFrame);
882 bool vpDirectShowGrabberImpl::getStreamCapabilities()
890 IAMStreamConfig *pConfig =
nullptr;
892 if (FAILED(hr = pBuild->FindInterface(&LOOK_UPSTREAM_ONLY,
895 IID_IAMStreamConfig, (
void **)&pConfig)))
898 int iCount = 0, iSize = 0;
899 if (FAILED(hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize)))
903 if (iSize ==
sizeof(VIDEO_STREAM_CONFIG_CAPS)) {
904 std::cout <<
"Available MediaTypes : " << std::endl << std::endl;
906 for (
int iFormat = 0; iFormat < iCount; iFormat++) {
907 VIDEO_STREAM_CONFIG_CAPS scc;
908 AM_MEDIA_TYPE *pmtConfig;
909 hr = pConfig->GetStreamCaps(iFormat, &pmtConfig, (BYTE *)&scc);
913 VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER *)pmtConfig->pbFormat;
915 std::cout <<
"MediaType : " << iFormat << std::endl;
917 if (pmtConfig->subtype == MEDIASUBTYPE_ARGB32)
918 std::cout <<
"subtype (not supported): MEDIASUBTYPE_ARGB32" << std::endl;
919 else if (pmtConfig->subtype == MEDIASUBTYPE_RGB32)
920 std::cout <<
"subtype : MEDIASUBTYPE_RGB32" << std::endl;
921 else if (pmtConfig->subtype == MEDIASUBTYPE_RGB24)
922 std::cout <<
"subtype : MEDIASUBTYPE_RGB24" << std::endl;
923 else if (pmtConfig->subtype == MEDIASUBTYPE_RGB555)
924 std::cout <<
"subtype (not supported): MEDIASUBTYPE_RGB555" << std::endl;
925 else if (pmtConfig->subtype == MEDIASUBTYPE_RGB565)
926 std::cout <<
"subtype (not supported): MEDIASUBTYPE_RGB565" << std::endl;
927 else if (pmtConfig->subtype == MEDIASUBTYPE_RGB8)
928 std::cout <<
"subtype (not supported): MEDIASUBTYPE_RGB8" << std::endl;
929 else if (pmtConfig->subtype == MEDIASUBTYPE_RGB4)
930 std::cout <<
"subtype (not supported): MEDIASUBTYPE_RGB4" << std::endl;
931 else if (pmtConfig->subtype == MEDIASUBTYPE_RGB1)
932 std::cout <<
"subtype (not supported): MEDIASUBTYPE_RGB1" << std::endl;
933 else if (pmtConfig->subtype == MEDIASUBTYPE_YV12)
934 std::cout <<
"subtype : MEDIASUBTYPE_YV12" << std::endl;
935 else if (pmtConfig->subtype == MEDIASUBTYPE_YVU9)
936 std::cout <<
"subtype : MEDIASUBTYPE_YVU9" << std::endl;
937 else if (pmtConfig->subtype == MEDIASUBTYPE_YUY2)
938 std::cout <<
"subtype : MEDIASUBTYPE_YUY2" << std::endl;
939 else if (pmtConfig->subtype == MEDIASUBTYPE_YUYV)
940 std::cout <<
"subtype : MEDIASUBTYPE_YUYV" << std::endl;
941 else if (pmtConfig->subtype == MEDIASUBTYPE_YVYU)
942 std::cout <<
"subtype : MEDIASUBTYPE_YVYU" << std::endl;
943 else if (pmtConfig->subtype == MEDIASUBTYPE_IYUV)
944 std::cout <<
"subtype : MEDIASUBTYPE_IYUV" << std::endl;
945 else if (pmtConfig->subtype == MEDIASUBTYPE_UYVY)
946 std::cout <<
"subtype : MEDIASUBTYPE_UYVY" << std::endl;
947 else if ((((pVih->bmiHeader.biCompression & 0xFF000000) >> 24) |
948 ((pVih->bmiHeader.biCompression & 0x00FF0000) >> 8) |
949 ((pVih->bmiHeader.biCompression & 0x0000FF00) << 8) |
950 ((pVih->bmiHeader.biCompression & 0x000000FF) << 24)) ==
'I420')
951 std::cout <<
"subtype : I420" << std::endl;
953 std::cout <<
"subtype (not supported) :" << (char)(pVih->bmiHeader.biCompression & 0x000000FF)
954 << (char)((pVih->bmiHeader.biCompression & 0x0000FF00) >> 8)
955 << (
char)((pVih->bmiHeader.biCompression & 0x00FF0000) >> 16)
956 << (char)((pVih->bmiHeader.biCompression & 0xFF000000) >> 24) << std::endl;
958 std::cout <<
"image size : " << pVih->bmiHeader.biWidth <<
" x " << pVih->bmiHeader.biHeight << std::endl;
959 std::cout <<
"framerate range: [" << 10000000 / scc.MaxFrameInterval <<
"," << 10000000 / scc.MinFrameInterval
979 MyDeleteMediaType(pmtConfig);
987 bool vpDirectShowGrabberImpl::setMediaType(
int mediaTypeID)
995 IAMStreamConfig *pConfig =
nullptr;
997 if (FAILED(hr = pBuild->FindInterface(&LOOK_UPSTREAM_ONLY,
1000 IID_IAMStreamConfig, (
void **)&pConfig)))
1003 VIDEO_STREAM_CONFIG_CAPS scc;
1004 AM_MEDIA_TYPE *pmtConfig;
1005 hr = pConfig->GetStreamCaps(mediaTypeID, &pmtConfig, (BYTE *)&scc);
1007 if (SUCCEEDED(hr)) {
1008 VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER *)pmtConfig->pbFormat;
1009 pVih->AvgTimePerFrame = scc.MinFrameInterval;
1011 if (FAILED(hr = pGrabberI->SetMediaType(pmtConfig)) || FAILED(hr = pConfig->SetFormat(pmtConfig)))
1014 if (FAILED(hr = pGrabberI->GetConnectedMediaType(&(sgCB.connectedMediaType))))
1018 MyDeleteMediaType(pmtConfig);
1026 int vpDirectShowGrabberImpl::getMediaType()
1028 if (
init ==
false) {
1033 int mediaTypeID = -1;
1034 VIDEOINFOHEADER *pVihConnected = (VIDEOINFOHEADER *)sgCB.connectedMediaType.pbFormat;
1037 IAMStreamConfig *pConfig =
nullptr;
1039 if (FAILED(hr = pBuild->FindInterface(&LOOK_UPSTREAM_ONLY,
1042 IID_IAMStreamConfig, (
void **)&pConfig)))
1045 int iCount = 0, iSize = 0;
1046 if (FAILED(hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize)))
1050 if (iSize ==
sizeof(VIDEO_STREAM_CONFIG_CAPS)) {
1052 for (
int iFormat = 0; iFormat < iCount; iFormat++) {
1053 VIDEO_STREAM_CONFIG_CAPS scc;
1054 AM_MEDIA_TYPE *pmtConfig;
1055 hr = pConfig->GetStreamCaps(iFormat, &pmtConfig, (BYTE *)&scc);
1057 if (SUCCEEDED(hr)) {
1059 if ((pmtConfig->majortype == sgCB.connectedMediaType.majortype) &&
1060 (pmtConfig->subtype == sgCB.connectedMediaType.subtype) &&
1061 (pmtConfig->formattype == sgCB.connectedMediaType.formattype) &&
1062 (pmtConfig->cbFormat >=
sizeof(VIDEOINFOHEADER)) && (pmtConfig->pbFormat !=
nullptr)) {
1063 VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER *)pmtConfig->pbFormat;
1064 if (pVih->bmiHeader.biWidth == pVihConnected->bmiHeader.biWidth &&
1065 pVih->bmiHeader.biHeight == pVihConnected->bmiHeader.biHeight)
1066 mediaTypeID = iFormat;
1070 MyDeleteMediaType(pmtConfig);
1080 void vpDirectShowGrabberImpl::MyDeleteMediaType(AM_MEDIA_TYPE *pmt)
1082 if (pmt !=
nullptr) {
1083 MyFreeMediaType(*pmt);
1091 void vpDirectShowGrabberImpl::MyFreeMediaType(AM_MEDIA_TYPE &mt)
1093 if (mt.cbFormat != 0) {
1094 CoTaskMemFree((PVOID)mt.pbFormat);
1096 mt.pbFormat =
nullptr;
1098 if (mt.pUnk !=
nullptr) {
1105 #elif !defined(VISP_BUILD_SHARED_LIBS)
1108 void dummy_vpDirectShowGrabberImpl() { };
Error that can be emitted by the vpFrameGrabber class and its derivates.
@ initializationError
Grabber initialization error.
@ otherError
Grabber returned an other error.
unsigned int getWidth() const
unsigned int getHeight() const
void init(unsigned int h, unsigned int w, Type value)