36 #ifndef DOXYGEN_SHOULD_SKIP_THIS
38 #include <visp3/core/vpConfig.h>
39 #if (defined(VISP_HAVE_DIRECTSHOW))
41 #include <visp3/sensor/vpDirectShowGrabberImpl.h>
43 vpDirectShowDevice *vpDirectShowGrabberImpl::deviceList =
nullptr;
44 unsigned int vpDirectShowGrabberImpl::nbDevices;
49 void vpDirectShowGrabberImpl::HRtoStr(std::string &str)
51 TCHAR szErr[MAX_ERROR_TEXT_LEN];
52 DWORD res = AMGetErrorText(hr, szErr, MAX_ERROR_TEXT_LEN);
55 str =
"Unknown Error: 0x%2x";
57 char msg[MAX_ERROR_TEXT_LEN];
58 snprintf(msg, MAX_ERROR_TEXT_LEN,
"%s", szErr);
66 vpDirectShowGrabberImpl::vpDirectShowGrabberImpl()
71 if (FAILED(hr = CoInitializeEx(
nullptr, COINIT_MULTITHREADED))) {
79 if (deviceList ==
nullptr) {
80 CComPtr<IEnumMoniker> pVideoInputEnum =
nullptr;
82 if (enumerate(pVideoInputEnum)) {
83 createDeviceList(pVideoInputEnum);
86 pVideoInputEnum.Release();
94 void vpDirectShowGrabberImpl::open()
97 if (deviceList ==
nullptr) {
98 CComPtr<IEnumMoniker> pVideoInputEnum =
nullptr;
100 if (enumerate(pVideoInputEnum)) {
101 createDeviceList(pVideoInputEnum);
104 pVideoInputEnum.Release();
107 init = initDirectShow();
131 bool vpDirectShowGrabberImpl::initDirectShow()
135 currentDevice = getFirstUnusedDevice(pCapSource);
137 if (currentDevice == nbDevices)
145 if (FAILED(hr = pGraph->AddFilter(pCapSource, L
"Capture Filter")))
149 if (!createSampleGrabber(pGrabberFilter))
153 if (FAILED(hr = pGraph->AddFilter(pGrabberFilter, L
"SampleGrabber")))
157 if (!connectSourceToGrabber(pCapSource, pGrabberFilter))
161 if (FAILED(hr = pGrabberI->GetConnectedMediaType(&(sgCB.connectedMediaType))))
165 CComPtr<IMediaFilter> pMediaFilter;
167 pGraph->QueryInterface(IID_IMediaFilter, (
void **)&pMediaFilter);
168 pGraph->QueryInterface(IID_IMediaControl,
reinterpret_cast<void **
>(&pControl));
169 pGraph->QueryInterface(IID_IMediaEvent, (
void **)&pEvent);
171 pMediaFilter->SetSyncSource(
nullptr);
172 pMediaFilter.Release();
180 vpDirectShowGrabberImpl::~vpDirectShowGrabberImpl() { close(); }
187 bool vpDirectShowGrabberImpl::enumerate(CComPtr<IEnumMoniker> &ppVideoInputEnum)
189 CComPtr<ICreateDevEnum> pDevEnum =
nullptr;
193 hr = pDevEnum.CoCreateInstance(CLSID_SystemDeviceEnum,
nullptr, CLSCTX_INPROC_SERVER);
198 hr = pDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &ppVideoInputEnum, 0);
213 bool vpDirectShowGrabberImpl::createDeviceList(CComPtr<IEnumMoniker> &ppVideoInputEnum)
215 CComPtr<IMoniker> pMoniker[10];
216 unsigned long nbMoniker;
218 ppVideoInputEnum->Reset();
221 ppVideoInputEnum->Next(10,
reinterpret_cast<IMoniker **
>(&pMoniker), &nbMoniker);
227 deviceList =
new vpDirectShowDevice[nbMoniker];
229 nbDevices = (
unsigned int)nbMoniker;
235 while (i < nbDevices) {
236 if (!deviceList[i].
init(pMoniker[j])) {
251 for (
unsigned int i = 0; i < nbMoniker; i++) {
252 pMoniker[i].Release();
264 bool vpDirectShowGrabberImpl::getDevice(
unsigned int n, CComPtr<IBaseFilter> &ppDevice)
271 if (deviceList[n].getState() ==
true)
275 CComPtr<IEnumMoniker> pVideoInputEnum =
nullptr;
276 if (!enumerate(pVideoInputEnum))
279 CComPtr<IMoniker> pMoniker =
nullptr;
280 bool deviceFound =
false;
283 while (pVideoInputEnum->Next(1, &pMoniker,
nullptr) == S_OK && !deviceFound) {
285 if (deviceList[n] == vpDirectShowDevice(pMoniker)) {
287 if (SUCCEEDED(pMoniker->BindToObject(0, 0, IID_IBaseFilter, (
void **)&ppDevice))) {
289 deviceList[n].setInUse();
298 pVideoInputEnum.Release();
309 unsigned int vpDirectShowGrabberImpl::getFirstUnusedDevice(CComPtr<IBaseFilter> &ppDevice)
314 for (n = 0; n < nbDevices && !found; n++) {
316 if (!deviceList[n].getState()) {
317 if (getDevice(n, ppDevice)) {
319 deviceList[n].setInUse();
332 bool vpDirectShowGrabberImpl::createGraph()
336 hr = pBuild.CoCreateInstance(CLSID_CaptureGraphBuilder2, 0, CLSCTX_INPROC_SERVER);
340 hr = pGraph.CoCreateInstance(CLSID_FilterGraph, 0, CLSCTX_INPROC_SERVER);
344 pBuild->SetFiltergraph(pGraph);
358 bool vpDirectShowGrabberImpl::createSampleGrabber(CComPtr<IBaseFilter> &ppGrabberFilter)
361 hr = ppGrabberFilter.CoCreateInstance(CLSID_SampleGrabber,
nullptr, CLSCTX_INPROC_SERVER);
367 hr = ppGrabberFilter->QueryInterface(IID_ISampleGrabber,
reinterpret_cast<void **
>(&pGrabberI));
374 ZeroMemory(&mt,
sizeof(AM_MEDIA_TYPE));
376 mt.majortype = MEDIATYPE_Video;
379 mt.subtype = MEDIATYPE_nullptr;
381 if (FAILED(hr = pGrabberI->SetMediaType(&mt)))
385 pGrabberI->SetCallback(&sgCB, 1);
388 pGrabberI->SetOneShot(TRUE);
391 pGrabberI->SetBufferSamples(
false);
405 bool vpDirectShowGrabberImpl::checkSourceType(CComPtr<IPin> &pCapSourcePin)
409 if (FAILED(pCapSourcePin->ConnectionMediaType(&mt)))
412 if (mt.majortype != MEDIATYPE_Video)
416 if (mt.subtype == MEDIASUBTYPE_ARGB32 || mt.subtype == MEDIASUBTYPE_RGB32 || mt.subtype == MEDIASUBTYPE_RGB24 ||
417 mt.subtype == MEDIASUBTYPE_RGB555 || mt.subtype == MEDIASUBTYPE_RGB565 || mt.subtype == MEDIASUBTYPE_RGB8 ||
418 mt.subtype == MEDIASUBTYPE_RGB4 || mt.subtype == MEDIASUBTYPE_RGB1) {
420 sgCB.specialMediaType =
false;
423 else if (mt.subtype == MEDIASUBTYPE_AYUV || mt.subtype == MEDIASUBTYPE_UYVY || mt.subtype == MEDIASUBTYPE_Y411 ||
424 mt.subtype == MEDIASUBTYPE_Y41P || mt.subtype == MEDIASUBTYPE_Y211 || mt.subtype == MEDIASUBTYPE_YUY2 ||
425 mt.subtype == MEDIASUBTYPE_YVYU || mt.subtype == MEDIASUBTYPE_YUYV || mt.subtype == MEDIASUBTYPE_IF09 ||
426 mt.subtype == MEDIASUBTYPE_IYUV || mt.subtype == MEDIASUBTYPE_YV12 || mt.subtype == MEDIASUBTYPE_YVU9) {
428 sgCB.specialMediaType =
false;
433 sgCB.specialMediaType =
true;
436 VIDEOINFOHEADER *pVih =
reinterpret_cast<VIDEOINFOHEADER *
>(mt.pbFormat);
437 BITMAPINFOHEADER bmpInfo = pVih->bmiHeader;
440 format = ((bmpInfo.biCompression & 0xFF000000) >> 24) | ((bmpInfo.biCompression & 0x00FF0000) >> 8) |
441 ((bmpInfo.biCompression & 0x0000FF00) << 8) | (bmpInfo.biCompression & 0x000000FF) << 24;
443 std::cout <<
"This format is not one of the standard YUV or RGB format "
444 "supported by DirectShow.\n"
445 <<
"FourCC : " << (char)(bmpInfo.biCompression & 0x000000FF)
446 << (char)((bmpInfo.biCompression & 0x0000FF00) >> 8) << (
char)((bmpInfo.biCompression & 0x00FF0000) >> 16)
447 << (char)((bmpInfo.biCompression & 0xFF000000) >> 24) << std::endl;
451 if (format ==
'Y800') {
452 sgCB.invertedSource =
false;
456 else if (format ==
'cyuv') {
457 sgCB.invertedSource =
true;
463 std::cout <<
"Unknown FourCC compression type, assuming top-down "
464 "orientation. Image may be inverted."
466 sgCB.invertedSource =
false;
479 bool vpDirectShowGrabberImpl::connectSourceToGrabber(CComPtr<IBaseFilter> &_pCapSource,
480 CComPtr<IBaseFilter> &_pGrabberFilter)
500 if (FAILED(hr = pBuild->RenderStream(
nullptr,
nullptr, _pCapSource,
nullptr, _pGrabberFilter)))
504 CComPtr<IBaseFilter> pNull =
nullptr;
505 if (FAILED(pNull.CoCreateInstance(CLSID_NullRenderer,
nullptr, CLSCTX_INPROC_SERVER)))
508 if (FAILED(pGraph->AddFilter(pNull, L
"NullRenderer")) ||
509 FAILED(pBuild->RenderStream(
nullptr,
nullptr, _pGrabberFilter,
nullptr, pNull)))
513 CComPtr<IPin> pCapSourcePin;
514 if (FAILED(pBuild->FindPin(_pCapSource, PINDIR_OUTPUT,
nullptr,
nullptr,
false, 0, &pCapSourcePin)))
518 if (!checkSourceType(pCapSourcePin))
522 pCapSourcePin.Release();
533 bool vpDirectShowGrabberImpl::removeAll()
535 CComPtr<IEnumFilters> pEnum =
nullptr;
536 CComPtr<IBaseFilter> pFilter;
539 if (FAILED(hr = pGraph->EnumFilters(&pEnum)))
542 while (pEnum->Next(1, &pFilter, &cFetched) == S_OK) {
543 if (FAILED(hr = pGraph->RemoveFilter(pFilter)))
572 sgCB.acqRGBaDemand =
true;
579 hr = pEvent->WaitForCompletion(MAX_DELAY, &ev);
585 if (WaitForSingleObject(sgCB.copySem, MAX_DELAY) != WAIT_OBJECT_0)
608 sgCB.acqGrayDemand =
true;
615 hr = pEvent->WaitForCompletion(MAX_DELAY, &ev);
621 if (WaitForSingleObject(sgCB.copySem, MAX_DELAY) != WAIT_OBJECT_0)
631 bool vpDirectShowGrabberImpl::setDevice(
unsigned int id)
639 if (
id >= nbDevices || deviceList[
id].getState() ==
true)
650 pCapSource.Release();
653 deviceList[currentDevice].resetInUse();
656 pGraph->AddFilter(pGrabberFilter, L
"SampleGrabber");
659 if (!getDevice(
id, pCapSource))
663 if (FAILED(hr = pGraph->AddFilter(pCapSource, L
"Capture Filter")))
667 if (!connectSourceToGrabber(pCapSource, pGrabberFilter))
671 if (FAILED(hr = pGrabberI->GetConnectedMediaType(&(sgCB.connectedMediaType)))) {
676 deviceList[id].setInUse();
685 void vpDirectShowGrabberImpl::displayDevices()
687 if (deviceList ==
nullptr) {
691 for (
unsigned int i = 0; i < nbDevices; i++)
692 std::cout << i <<
" : " << deviceList[i].getName() << std::endl;
694 std::cout <<
"Current device : " << currentDevice << std::endl << std::endl;
701 void vpDirectShowGrabberImpl::close()
705 deviceList[currentDevice].resetInUse();
717 bool vpDirectShowGrabberImpl::setImageSize(
unsigned int width,
unsigned int height)
724 return setFormat(width, height,
nullptr);
730 bool vpDirectShowGrabberImpl::setFramerate(
double framerate)
737 VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER *)sgCB.connectedMediaType.pbFormat;
738 return setFormat(pVih->bmiHeader.biWidth, pVih->bmiHeader.biHeight, framerate);
743 bool vpDirectShowGrabberImpl::setFormat(
unsigned int width,
unsigned int height,
double framerate)
753 IAMStreamConfig *pConfig =
nullptr;
755 if (FAILED(hr = pBuild->FindInterface(&LOOK_UPSTREAM_ONLY,
758 IID_IAMStreamConfig, (
void **)&pConfig)))
762 IAMVideoControl *pVideoControl =
nullptr;
764 if (FAILED(hr = pBuild->FindInterface(&LOOK_UPSTREAM_ONLY,
767 IID_IAMVideoControl, (
void **)&pVideoControl)))
771 CComPtr<IPin> pCapSourcePin;
772 if (FAILED(pBuild->FindPin(pCapSource, PINDIR_OUTPUT,
nullptr,
nullptr,
false, 0, &pCapSourcePin)))
775 int iCount = 0, iSize = 0;
776 if (FAILED(hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize)))
780 if (iSize ==
sizeof(VIDEO_STREAM_CONFIG_CAPS)) {
783 for (
int iFormat = 0; iFormat < iCount; iFormat++) {
784 VIDEO_STREAM_CONFIG_CAPS scc;
785 AM_MEDIA_TYPE *pmtConfig;
786 hr = pConfig->GetStreamCaps(iFormat, &pmtConfig, (BYTE *)&scc);
788 if (SUCCEEDED(hr) && found ==
false) {
790 if ((pmtConfig->majortype == sgCB.connectedMediaType.majortype) &&
791 (pmtConfig->subtype == sgCB.connectedMediaType.subtype) &&
792 (pmtConfig->formattype == sgCB.connectedMediaType.formattype) &&
793 (pmtConfig->cbFormat >=
sizeof(VIDEOINFOHEADER)) && (pmtConfig->pbFormat !=
nullptr)) {
794 VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER *)pmtConfig->pbFormat;
796 LONG lWidth = pVih->bmiHeader.biWidth;
797 LONG lHeight = pVih->bmiHeader.biHeight;
798 if (framerate !=
nullptr) {
799 if ((
unsigned int)lWidth == width && (
unsigned int)lHeight == height) {
801 pVih->AvgTimePerFrame = (LONGLONG)(10000000 / framerate);
803 if (FAILED(hr = pConfig->SetFormat(pmtConfig)) || FAILED(hr = pGrabberI->SetMediaType(pmtConfig)))
809 if (FAILED(hr = pGrabberI->GetConnectedMediaType(&(sgCB.connectedMediaType))))
811 pVih = (VIDEOINFOHEADER *)sgCB.connectedMediaType.pbFormat;
812 LONGLONG ActualFrameDuration;
813 if (FAILED(hr = pVideoControl->GetCurrentActualFrameRate(pCapSourcePin, &ActualFrameDuration)))
814 std::cout <<
"Current format (not sure): " << width <<
" x " << height <<
" at "
815 << 10000000 / pVih->AvgTimePerFrame <<
" fps" << std::endl
818 std::cout <<
"Current format : " << width <<
" x " << height <<
" at " << 10000000 / ActualFrameDuration
819 <<
" fps" << std::endl
821 pVih->AvgTimePerFrame = ActualFrameDuration;
826 if ((
unsigned int)lWidth == width && (
unsigned int)lHeight == height) {
827 pVih->AvgTimePerFrame = scc.MinFrameInterval;
829 if (FAILED(hr = pConfig->SetFormat(pmtConfig)) || FAILED(hr = pGrabberI->SetMediaType(pmtConfig)))
832 if (FAILED(hr = pGrabberI->GetConnectedMediaType(&(sgCB.connectedMediaType))))
834 pVih = (VIDEOINFOHEADER *)sgCB.connectedMediaType.pbFormat;
836 std::cout <<
"Current format : " << width <<
" x " << height <<
" at "
837 << (10000000 / pVih->AvgTimePerFrame) <<
" fps" << std::endl
844 MyDeleteMediaType(pmtConfig);
848 if (framerate !=
nullptr)
849 std::cout <<
"The " << width <<
" x " << height <<
" at " << framerate
850 <<
" fps source image format is not available. " << std::endl
853 std::cout <<
"The " << width <<
" x " << height <<
"source image size is not available. " << std::endl
864 void vpDirectShowGrabberImpl::getFormat(
unsigned int &width,
unsigned int &height,
double &framerate)
870 VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER *)sgCB.connectedMediaType.pbFormat;
871 width = (
unsigned int)pVih->bmiHeader.biWidth;
872 height = (
unsigned int)pVih->bmiHeader.biHeight;
873 framerate = (
double)(10000000 / pVih->AvgTimePerFrame);
878 bool vpDirectShowGrabberImpl::getStreamCapabilities()
886 IAMStreamConfig *pConfig =
nullptr;
888 if (FAILED(hr = pBuild->FindInterface(&LOOK_UPSTREAM_ONLY,
891 IID_IAMStreamConfig, (
void **)&pConfig)))
894 int iCount = 0, iSize = 0;
895 if (FAILED(hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize)))
899 if (iSize ==
sizeof(VIDEO_STREAM_CONFIG_CAPS)) {
900 std::cout <<
"Available MediaTypes : " << std::endl << std::endl;
902 for (
int iFormat = 0; iFormat < iCount; iFormat++) {
903 VIDEO_STREAM_CONFIG_CAPS scc;
904 AM_MEDIA_TYPE *pmtConfig;
905 hr = pConfig->GetStreamCaps(iFormat, &pmtConfig, (BYTE *)&scc);
909 VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER *)pmtConfig->pbFormat;
911 std::cout <<
"MediaType : " << iFormat << std::endl;
913 if (pmtConfig->subtype == MEDIASUBTYPE_ARGB32)
914 std::cout <<
"subtype (not supported): MEDIASUBTYPE_ARGB32" << std::endl;
915 else if (pmtConfig->subtype == MEDIASUBTYPE_RGB32)
916 std::cout <<
"subtype : MEDIASUBTYPE_RGB32" << std::endl;
917 else if (pmtConfig->subtype == MEDIASUBTYPE_RGB24)
918 std::cout <<
"subtype : MEDIASUBTYPE_RGB24" << std::endl;
919 else if (pmtConfig->subtype == MEDIASUBTYPE_RGB555)
920 std::cout <<
"subtype (not supported): MEDIASUBTYPE_RGB555" << std::endl;
921 else if (pmtConfig->subtype == MEDIASUBTYPE_RGB565)
922 std::cout <<
"subtype (not supported): MEDIASUBTYPE_RGB565" << std::endl;
923 else if (pmtConfig->subtype == MEDIASUBTYPE_RGB8)
924 std::cout <<
"subtype (not supported): MEDIASUBTYPE_RGB8" << std::endl;
925 else if (pmtConfig->subtype == MEDIASUBTYPE_RGB4)
926 std::cout <<
"subtype (not supported): MEDIASUBTYPE_RGB4" << std::endl;
927 else if (pmtConfig->subtype == MEDIASUBTYPE_RGB1)
928 std::cout <<
"subtype (not supported): MEDIASUBTYPE_RGB1" << std::endl;
929 else if (pmtConfig->subtype == MEDIASUBTYPE_YV12)
930 std::cout <<
"subtype : MEDIASUBTYPE_YV12" << std::endl;
931 else if (pmtConfig->subtype == MEDIASUBTYPE_YVU9)
932 std::cout <<
"subtype : MEDIASUBTYPE_YVU9" << std::endl;
933 else if (pmtConfig->subtype == MEDIASUBTYPE_YUY2)
934 std::cout <<
"subtype : MEDIASUBTYPE_YUY2" << std::endl;
935 else if (pmtConfig->subtype == MEDIASUBTYPE_YUYV)
936 std::cout <<
"subtype : MEDIASUBTYPE_YUYV" << std::endl;
937 else if (pmtConfig->subtype == MEDIASUBTYPE_YVYU)
938 std::cout <<
"subtype : MEDIASUBTYPE_YVYU" << std::endl;
939 else if (pmtConfig->subtype == MEDIASUBTYPE_IYUV)
940 std::cout <<
"subtype : MEDIASUBTYPE_IYUV" << std::endl;
941 else if (pmtConfig->subtype == MEDIASUBTYPE_UYVY)
942 std::cout <<
"subtype : MEDIASUBTYPE_UYVY" << std::endl;
943 else if ((((pVih->bmiHeader.biCompression & 0xFF000000) >> 24) |
944 ((pVih->bmiHeader.biCompression & 0x00FF0000) >> 8) |
945 ((pVih->bmiHeader.biCompression & 0x0000FF00) << 8) |
946 ((pVih->bmiHeader.biCompression & 0x000000FF) << 24)) ==
'I420')
947 std::cout <<
"subtype : I420" << std::endl;
949 std::cout <<
"subtype (not supported) :" << (char)(pVih->bmiHeader.biCompression & 0x000000FF)
950 << (char)((pVih->bmiHeader.biCompression & 0x0000FF00) >> 8)
951 << (
char)((pVih->bmiHeader.biCompression & 0x00FF0000) >> 16)
952 << (char)((pVih->bmiHeader.biCompression & 0xFF000000) >> 24) << std::endl;
954 std::cout <<
"image size : " << pVih->bmiHeader.biWidth <<
" x " << pVih->bmiHeader.biHeight << std::endl;
955 std::cout <<
"framerate range: [" << 10000000 / scc.MaxFrameInterval <<
"," << 10000000 / scc.MinFrameInterval
975 MyDeleteMediaType(pmtConfig);
983 bool vpDirectShowGrabberImpl::setMediaType(
int mediaTypeID)
991 IAMStreamConfig *pConfig =
nullptr;
993 if (FAILED(hr = pBuild->FindInterface(&LOOK_UPSTREAM_ONLY,
996 IID_IAMStreamConfig, (
void **)&pConfig)))
999 VIDEO_STREAM_CONFIG_CAPS scc;
1000 AM_MEDIA_TYPE *pmtConfig;
1001 hr = pConfig->GetStreamCaps(mediaTypeID, &pmtConfig, (BYTE *)&scc);
1003 if (SUCCEEDED(hr)) {
1004 VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER *)pmtConfig->pbFormat;
1005 pVih->AvgTimePerFrame = scc.MinFrameInterval;
1007 if (FAILED(hr = pGrabberI->SetMediaType(pmtConfig)) || FAILED(hr = pConfig->SetFormat(pmtConfig)))
1010 if (FAILED(hr = pGrabberI->GetConnectedMediaType(&(sgCB.connectedMediaType))))
1014 MyDeleteMediaType(pmtConfig);
1022 int vpDirectShowGrabberImpl::getMediaType()
1024 if (
init ==
false) {
1029 int mediaTypeID = -1;
1030 VIDEOINFOHEADER *pVihConnected = (VIDEOINFOHEADER *)sgCB.connectedMediaType.pbFormat;
1033 IAMStreamConfig *pConfig =
nullptr;
1035 if (FAILED(hr = pBuild->FindInterface(&LOOK_UPSTREAM_ONLY,
1038 IID_IAMStreamConfig, (
void **)&pConfig)))
1041 int iCount = 0, iSize = 0;
1042 if (FAILED(hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize)))
1046 if (iSize ==
sizeof(VIDEO_STREAM_CONFIG_CAPS)) {
1048 for (
int iFormat = 0; iFormat < iCount; iFormat++) {
1049 VIDEO_STREAM_CONFIG_CAPS scc;
1050 AM_MEDIA_TYPE *pmtConfig;
1051 hr = pConfig->GetStreamCaps(iFormat, &pmtConfig, (BYTE *)&scc);
1053 if (SUCCEEDED(hr)) {
1055 if ((pmtConfig->majortype == sgCB.connectedMediaType.majortype) &&
1056 (pmtConfig->subtype == sgCB.connectedMediaType.subtype) &&
1057 (pmtConfig->formattype == sgCB.connectedMediaType.formattype) &&
1058 (pmtConfig->cbFormat >=
sizeof(VIDEOINFOHEADER)) && (pmtConfig->pbFormat !=
nullptr)) {
1059 VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER *)pmtConfig->pbFormat;
1060 if (pVih->bmiHeader.biWidth == pVihConnected->bmiHeader.biWidth &&
1061 pVih->bmiHeader.biHeight == pVihConnected->bmiHeader.biHeight)
1062 mediaTypeID = iFormat;
1066 MyDeleteMediaType(pmtConfig);
1076 void vpDirectShowGrabberImpl::MyDeleteMediaType(AM_MEDIA_TYPE *pmt)
1078 if (pmt !=
nullptr) {
1079 MyFreeMediaType(*pmt);
1087 void vpDirectShowGrabberImpl::MyFreeMediaType(AM_MEDIA_TYPE &mt)
1089 if (mt.cbFormat != 0) {
1090 CoTaskMemFree((PVOID)mt.pbFormat);
1092 mt.pbFormat =
nullptr;
1094 if (mt.pUnk !=
nullptr) {
1101 #elif !defined(VISP_BUILD_SHARED_LIBS)
1104 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)