34#ifndef DOXYGEN_SHOULD_SKIP_THIS
36#include <visp3/core/vpConfig.h>
37#if (defined(VISP_HAVE_DIRECTSHOW))
39#include <visp3/sensor/vpDirectShowGrabberImpl.h>
42vpDirectShowDevice *vpDirectShowGrabberImpl::deviceList =
nullptr;
43unsigned int vpDirectShowGrabberImpl::nbDevices;
48void vpDirectShowGrabberImpl::HRtoStr(std::string &str)
50 TCHAR szErr[MAX_ERROR_TEXT_LEN];
51 DWORD res = AMGetErrorText(hr, szErr, MAX_ERROR_TEXT_LEN);
54 str =
"Unknown Error: 0x%2x";
56 char msg[MAX_ERROR_TEXT_LEN];
57 snprintf(msg, MAX_ERROR_TEXT_LEN,
"%s", szErr);
65vpDirectShowGrabberImpl::vpDirectShowGrabberImpl()
70 if (FAILED(hr = CoInitializeEx(
nullptr, COINIT_MULTITHREADED))) {
78 if (deviceList ==
nullptr) {
79 CComPtr<IEnumMoniker> pVideoInputEnum =
nullptr;
81 if (enumerate(pVideoInputEnum)) {
82 createDeviceList(pVideoInputEnum);
85 pVideoInputEnum.Release();
93void vpDirectShowGrabberImpl::open()
96 if (deviceList ==
nullptr) {
97 CComPtr<IEnumMoniker> pVideoInputEnum =
nullptr;
99 if (enumerate(pVideoInputEnum)) {
100 createDeviceList(pVideoInputEnum);
103 pVideoInputEnum.Release();
106 init = initDirectShow();
130bool vpDirectShowGrabberImpl::initDirectShow()
134 currentDevice = getFirstUnusedDevice(pCapSource);
136 if (currentDevice == nbDevices)
144 if (FAILED(hr = pGraph->AddFilter(pCapSource, L
"Capture Filter")))
148 if (!createSampleGrabber(pGrabberFilter))
152 if (FAILED(hr = pGraph->AddFilter(pGrabberFilter, L
"SampleGrabber")))
156 if (!connectSourceToGrabber(pCapSource, pGrabberFilter))
160 if (FAILED(hr = pGrabberI->GetConnectedMediaType(&(sgCB.connectedMediaType))))
164 CComPtr<IMediaFilter> pMediaFilter;
166 pGraph->QueryInterface(IID_IMediaFilter, (
void **)&pMediaFilter);
167 pGraph->QueryInterface(IID_IMediaControl,
reinterpret_cast<void **
>(&pControl));
168 pGraph->QueryInterface(IID_IMediaEvent, (
void **)&pEvent);
170 pMediaFilter->SetSyncSource(
nullptr);
171 pMediaFilter.Release();
179vpDirectShowGrabberImpl::~vpDirectShowGrabberImpl() { close(); }
186bool vpDirectShowGrabberImpl::enumerate(CComPtr<IEnumMoniker> &ppVideoInputEnum)
188 CComPtr<ICreateDevEnum> pDevEnum =
nullptr;
192 hr = pDevEnum.CoCreateInstance(CLSID_SystemDeviceEnum,
nullptr, CLSCTX_INPROC_SERVER);
197 hr = pDevEnum->CreateClassEnumerator(CLSID_VideoInputDeviceCategory, &ppVideoInputEnum, 0);
212bool vpDirectShowGrabberImpl::createDeviceList(CComPtr<IEnumMoniker> &ppVideoInputEnum)
214 CComPtr<IMoniker> pMoniker[10];
215 unsigned long nbMoniker;
217 ppVideoInputEnum->Reset();
220 ppVideoInputEnum->Next(10,
reinterpret_cast<IMoniker **
>(&pMoniker), &nbMoniker);
226 deviceList =
new vpDirectShowDevice[nbMoniker];
228 nbDevices =
static_cast<unsigned int>(nbMoniker);
234 while (i < nbDevices) {
235 if (!deviceList[i].init(pMoniker[j])) {
251 for (
unsigned int i = 0;
i < nbMoniker;
i++) {
252 pMoniker[
i].Release();
264bool 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();
299 pVideoInputEnum.Release();
310unsigned int vpDirectShowGrabberImpl::getFirstUnusedDevice(CComPtr<IBaseFilter> &ppDevice)
315 for (n = 0; n < nbDevices && !found; n++) {
317 if (!deviceList[n].getState()) {
318 if (getDevice(n, ppDevice)) {
320 deviceList[n].setInUse();
333bool vpDirectShowGrabberImpl::createGraph()
337 hr = pBuild.CoCreateInstance(CLSID_CaptureGraphBuilder2, 0, CLSCTX_INPROC_SERVER);
341 hr = pGraph.CoCreateInstance(CLSID_FilterGraph, 0, CLSCTX_INPROC_SERVER);
345 pBuild->SetFiltergraph(pGraph);
359bool vpDirectShowGrabberImpl::createSampleGrabber(CComPtr<IBaseFilter> &ppGrabberFilter)
362 hr = ppGrabberFilter.CoCreateInstance(CLSID_SampleGrabber,
nullptr, CLSCTX_INPROC_SERVER);
368 hr = ppGrabberFilter->QueryInterface(IID_ISampleGrabber,
reinterpret_cast<void **
>(&pGrabberI));
375 ZeroMemory(&mt,
sizeof(AM_MEDIA_TYPE));
377 mt.majortype = MEDIATYPE_Video;
380 mt.subtype = MEDIATYPE_nullptr;
382 if (FAILED(hr = pGrabberI->SetMediaType(&mt)))
386 pGrabberI->SetCallback(&sgCB, 1);
389 pGrabberI->SetOneShot(TRUE);
392 pGrabberI->SetBufferSamples(
false);
406bool vpDirectShowGrabberImpl::checkSourceType(CComPtr<IPin> &pCapSourcePin)
410 if (FAILED(pCapSourcePin->ConnectionMediaType(&mt)))
413 if (mt.majortype != MEDIATYPE_Video)
417 if (mt.subtype == MEDIASUBTYPE_ARGB32 || mt.subtype == MEDIASUBTYPE_RGB32 || mt.subtype == MEDIASUBTYPE_RGB24 ||
418 mt.subtype == MEDIASUBTYPE_RGB555 || mt.subtype == MEDIASUBTYPE_RGB565 || mt.subtype == MEDIASUBTYPE_RGB8 ||
419 mt.subtype == MEDIASUBTYPE_RGB4 || mt.subtype == MEDIASUBTYPE_RGB1) {
421 sgCB.specialMediaType =
false;
424 else if (mt.subtype == MEDIASUBTYPE_AYUV || mt.subtype == MEDIASUBTYPE_UYVY || mt.subtype == MEDIASUBTYPE_Y411 ||
425 mt.subtype == MEDIASUBTYPE_Y41P || mt.subtype == MEDIASUBTYPE_Y211 || mt.subtype == MEDIASUBTYPE_YUY2 ||
426 mt.subtype == MEDIASUBTYPE_YVYU || mt.subtype == MEDIASUBTYPE_YUYV || mt.subtype == MEDIASUBTYPE_IF09 ||
427 mt.subtype == MEDIASUBTYPE_IYUV || mt.subtype == MEDIASUBTYPE_YV12 || mt.subtype == MEDIASUBTYPE_YVU9) {
429 sgCB.specialMediaType =
false;
434 sgCB.specialMediaType =
true;
437 VIDEOINFOHEADER *pVih =
reinterpret_cast<VIDEOINFOHEADER *
>(mt.pbFormat);
438 BITMAPINFOHEADER bmpInfo = pVih->bmiHeader;
441 format = ((bmpInfo.biCompression & 0xFF000000) >> 24) | ((bmpInfo.biCompression & 0x00FF0000) >> 8) |
442 ((bmpInfo.biCompression & 0x0000FF00) << 8) | (bmpInfo.biCompression & 0x000000FF) << 24;
444 std::cout <<
"This format is not one of the standard YUV or RGB format "
445 "supported by DirectShow.\n"
446 <<
"FourCC : " <<
static_cast<char>(bmpInfo.biCompression & 0x000000FF)
447 <<
static_cast<char>((bmpInfo.biCompression & 0x0000FF00) >> 8)
448 <<
static_cast<char>((bmpInfo.biCompression & 0x00FF0000) >> 16)
449 <<
static_cast<char>((bmpInfo.biCompression & 0xFF000000) >> 24) << std::endl;
453 if (format ==
'Y800') {
454 sgCB.invertedSource =
false;
458 else if (format ==
'cyuv') {
459 sgCB.invertedSource =
true;
465 std::cout <<
"Unknown FourCC compression type, assuming top-down "
466 "orientation. Image may be inverted."
468 sgCB.invertedSource =
false;
481bool vpDirectShowGrabberImpl::connectSourceToGrabber(CComPtr<IBaseFilter> &_pCapSource,
482 CComPtr<IBaseFilter> &_pGrabberFilter)
502 if (FAILED(hr = pBuild->RenderStream(
nullptr,
nullptr, _pCapSource,
nullptr, _pGrabberFilter)))
506 CComPtr<IBaseFilter> pNull =
nullptr;
507 if (FAILED(pNull.CoCreateInstance(CLSID_NullRenderer,
nullptr, CLSCTX_INPROC_SERVER)))
510 if (FAILED(pGraph->AddFilter(pNull, L
"NullRenderer")) ||
511 FAILED(pBuild->RenderStream(
nullptr,
nullptr, _pGrabberFilter,
nullptr, pNull)))
515 CComPtr<IPin> pCapSourcePin;
516 if (FAILED(pBuild->FindPin(_pCapSource, PINDIR_OUTPUT,
nullptr,
nullptr,
false, 0, &pCapSourcePin)))
520 if (!checkSourceType(pCapSourcePin))
524 pCapSourcePin.Release();
535bool vpDirectShowGrabberImpl::removeAll()
537 CComPtr<IEnumFilters> pEnum =
nullptr;
538 CComPtr<IBaseFilter> pFilter;
541 if (FAILED(hr = pGraph->EnumFilters(&pEnum)))
544 while (pEnum->Next(1, &pFilter, &cFetched) == S_OK) {
545 if (FAILED(hr = pGraph->RemoveFilter(pFilter)))
574 sgCB.acqRGBaDemand =
true;
581 hr = pEvent->WaitForCompletion(MAX_DELAY, &ev);
583 width = I.getWidth();
587 if (WaitForSingleObject(sgCB.copySem, MAX_DELAY) != WAIT_OBJECT_0)
610 sgCB.acqGrayDemand =
true;
617 hr = pEvent->WaitForCompletion(MAX_DELAY, &ev);
619 width = I.getWidth();
623 if (WaitForSingleObject(sgCB.copySem, MAX_DELAY) != WAIT_OBJECT_0)
633bool vpDirectShowGrabberImpl::setDevice(
unsigned int id)
641 if (
id >= nbDevices || deviceList[
id].getState() ==
true)
652 pCapSource.Release();
655 deviceList[currentDevice].resetInUse();
658 pGraph->AddFilter(pGrabberFilter, L
"SampleGrabber");
661 if (!getDevice(
id, pCapSource))
665 if (FAILED(hr = pGraph->AddFilter(pCapSource, L
"Capture Filter")))
669 if (!connectSourceToGrabber(pCapSource, pGrabberFilter))
673 if (FAILED(hr = pGrabberI->GetConnectedMediaType(&(sgCB.connectedMediaType)))) {
678 deviceList[id].setInUse();
687void vpDirectShowGrabberImpl::displayDevices()
689 if (deviceList ==
nullptr) {
693 for (
unsigned int i = 0;
i < nbDevices;
i++)
694 std::cout << i <<
" : " << deviceList[i].getName() << std::endl;
696 std::cout <<
"Current device : " << currentDevice << std::endl << std::endl;
703void vpDirectShowGrabberImpl::close()
707 deviceList[currentDevice].resetInUse();
719bool vpDirectShowGrabberImpl::setImageSize(
unsigned int width,
unsigned int height)
726 return setFormat(width, height,
nullptr);
732bool vpDirectShowGrabberImpl::setFramerate(
double framerate)
739 VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER *)sgCB.connectedMediaType.pbFormat;
740 return setFormat(pVih->bmiHeader.biWidth, pVih->bmiHeader.biHeight, framerate);
745bool vpDirectShowGrabberImpl::setFormat(
unsigned int width,
unsigned int height,
double framerate)
755 IAMStreamConfig *pConfig =
nullptr;
757 if (FAILED(hr = pBuild->FindInterface(&LOOK_UPSTREAM_ONLY,
760 IID_IAMStreamConfig, (
void **)&pConfig)))
764 IAMVideoControl *pVideoControl =
nullptr;
766 if (FAILED(hr = pBuild->FindInterface(&LOOK_UPSTREAM_ONLY,
769 IID_IAMVideoControl, (
void **)&pVideoControl)))
773 CComPtr<IPin> pCapSourcePin;
774 if (FAILED(pBuild->FindPin(pCapSource, PINDIR_OUTPUT,
nullptr,
nullptr,
false, 0, &pCapSourcePin)))
777 int iCount = 0, iSize = 0;
778 if (FAILED(hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize)))
782 if (iSize ==
sizeof(VIDEO_STREAM_CONFIG_CAPS)) {
785 for (
int iFormat = 0; iFormat < iCount; iFormat++) {
786 VIDEO_STREAM_CONFIG_CAPS scc;
787 AM_MEDIA_TYPE *pmtConfig;
788 hr = pConfig->GetStreamCaps(iFormat, &pmtConfig, (BYTE *)&scc);
790 if (SUCCEEDED(hr) && found ==
false) {
792 if ((pmtConfig->majortype == sgCB.connectedMediaType.majortype) &&
793 (pmtConfig->subtype == sgCB.connectedMediaType.subtype) &&
794 (pmtConfig->formattype == sgCB.connectedMediaType.formattype) &&
795 (pmtConfig->cbFormat >=
sizeof(VIDEOINFOHEADER)) && (pmtConfig->pbFormat !=
nullptr)) {
796 VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER *)pmtConfig->pbFormat;
798 LONG lWidth = pVih->bmiHeader.biWidth;
799 LONG lHeight = pVih->bmiHeader.biHeight;
800 if (framerate !=
nullptr) {
801 if (
static_cast<unsigned int>(lWidth) == width &&
static_cast<unsigned int>(lHeight) == height) {
803 pVih->AvgTimePerFrame = (LONGLONG)(10000000 / framerate);
805 if (FAILED(hr = pConfig->SetFormat(pmtConfig)) || FAILED(hr = pGrabberI->SetMediaType(pmtConfig)))
811 if (FAILED(hr = pGrabberI->GetConnectedMediaType(&(sgCB.connectedMediaType))))
813 pVih = (VIDEOINFOHEADER *)sgCB.connectedMediaType.pbFormat;
814 LONGLONG ActualFrameDuration;
815 if (FAILED(hr = pVideoControl->GetCurrentActualFrameRate(pCapSourcePin, &ActualFrameDuration)))
816 std::cout <<
"Current format (not sure): " <<
width <<
" x " <<
height <<
" at "
817 << 10000000 / pVih->AvgTimePerFrame <<
" fps" << std::endl
820 std::cout <<
"Current format : " <<
width <<
" x " <<
height <<
" at " << 10000000 / ActualFrameDuration
821 <<
" fps" << std::endl
823 pVih->AvgTimePerFrame = ActualFrameDuration;
829 if (
static_cast<unsigned int>(lWidth) == width &&
static_cast<unsigned int>(lHeight) == height) {
830 pVih->AvgTimePerFrame = scc.MinFrameInterval;
832 if (FAILED(hr = pConfig->SetFormat(pmtConfig)) || FAILED(hr = pGrabberI->SetMediaType(pmtConfig)))
835 if (FAILED(hr = pGrabberI->GetConnectedMediaType(&(sgCB.connectedMediaType))))
837 pVih = (VIDEOINFOHEADER *)sgCB.connectedMediaType.pbFormat;
839 std::cout <<
"Current format : " <<
width <<
" x " <<
height <<
" at "
840 << (10000000 / pVih->AvgTimePerFrame) <<
" fps" << std::endl
847 MyDeleteMediaType(pmtConfig);
851 if (framerate !=
nullptr)
852 std::cout <<
"The " <<
width <<
" x " <<
height <<
" at " << framerate
853 <<
" fps source image format is not available. " << std::endl
856 std::cout <<
"The " <<
width <<
" x " <<
height <<
"source image size is not available. " << std::endl
867void vpDirectShowGrabberImpl::getFormat(
unsigned int &width,
unsigned int &height,
double &framerate)
873 VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER *)sgCB.connectedMediaType.pbFormat;
874 width =
static_cast<unsigned int>(pVih->bmiHeader.biWidth);
875 height =
static_cast<unsigned int>(pVih->bmiHeader.biHeight);
876 framerate =
static_cast<double>(10000000 / pVih->AvgTimePerFrame);
881bool vpDirectShowGrabberImpl::getStreamCapabilities()
889 IAMStreamConfig *pConfig =
nullptr;
891 if (FAILED(hr = pBuild->FindInterface(&LOOK_UPSTREAM_ONLY,
894 IID_IAMStreamConfig, (
void **)&pConfig)))
897 int iCount = 0, iSize = 0;
898 if (FAILED(hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize)))
902 if (iSize ==
sizeof(VIDEO_STREAM_CONFIG_CAPS)) {
903 std::cout <<
"Available MediaTypes : " << std::endl << std::endl;
905 for (
int iFormat = 0; iFormat < iCount; iFormat++) {
906 VIDEO_STREAM_CONFIG_CAPS scc;
907 AM_MEDIA_TYPE *pmtConfig;
908 hr = pConfig->GetStreamCaps(iFormat, &pmtConfig, (BYTE *)&scc);
912 VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER *)pmtConfig->pbFormat;
914 std::cout <<
"MediaType : " << iFormat << std::endl;
916 if (pmtConfig->subtype == MEDIASUBTYPE_ARGB32)
917 std::cout <<
"subtype (not supported): MEDIASUBTYPE_ARGB32" << std::endl;
918 else if (pmtConfig->subtype == MEDIASUBTYPE_RGB32)
919 std::cout <<
"subtype : MEDIASUBTYPE_RGB32" << std::endl;
920 else if (pmtConfig->subtype == MEDIASUBTYPE_RGB24)
921 std::cout <<
"subtype : MEDIASUBTYPE_RGB24" << std::endl;
922 else if (pmtConfig->subtype == MEDIASUBTYPE_RGB555)
923 std::cout <<
"subtype (not supported): MEDIASUBTYPE_RGB555" << std::endl;
924 else if (pmtConfig->subtype == MEDIASUBTYPE_RGB565)
925 std::cout <<
"subtype (not supported): MEDIASUBTYPE_RGB565" << std::endl;
926 else if (pmtConfig->subtype == MEDIASUBTYPE_RGB8)
927 std::cout <<
"subtype (not supported): MEDIASUBTYPE_RGB8" << std::endl;
928 else if (pmtConfig->subtype == MEDIASUBTYPE_RGB4)
929 std::cout <<
"subtype (not supported): MEDIASUBTYPE_RGB4" << std::endl;
930 else if (pmtConfig->subtype == MEDIASUBTYPE_RGB1)
931 std::cout <<
"subtype (not supported): MEDIASUBTYPE_RGB1" << std::endl;
932 else if (pmtConfig->subtype == MEDIASUBTYPE_YV12)
933 std::cout <<
"subtype : MEDIASUBTYPE_YV12" << std::endl;
934 else if (pmtConfig->subtype == MEDIASUBTYPE_YVU9)
935 std::cout <<
"subtype : MEDIASUBTYPE_YVU9" << std::endl;
936 else if (pmtConfig->subtype == MEDIASUBTYPE_YUY2)
937 std::cout <<
"subtype : MEDIASUBTYPE_YUY2" << std::endl;
938 else if (pmtConfig->subtype == MEDIASUBTYPE_YUYV)
939 std::cout <<
"subtype : MEDIASUBTYPE_YUYV" << std::endl;
940 else if (pmtConfig->subtype == MEDIASUBTYPE_YVYU)
941 std::cout <<
"subtype : MEDIASUBTYPE_YVYU" << std::endl;
942 else if (pmtConfig->subtype == MEDIASUBTYPE_IYUV)
943 std::cout <<
"subtype : MEDIASUBTYPE_IYUV" << std::endl;
944 else if (pmtConfig->subtype == MEDIASUBTYPE_UYVY)
945 std::cout <<
"subtype : MEDIASUBTYPE_UYVY" << std::endl;
946 else if ((((pVih->bmiHeader.biCompression & 0xFF000000) >> 24) |
947 ((pVih->bmiHeader.biCompression & 0x00FF0000) >> 8) |
948 ((pVih->bmiHeader.biCompression & 0x0000FF00) << 8) |
949 ((pVih->bmiHeader.biCompression & 0x000000FF) << 24)) ==
'I420')
950 std::cout <<
"subtype : I420" << std::endl;
952 std::cout <<
"subtype (not supported) :" <<
static_cast<char>(pVih->bmiHeader.biCompression & 0x000000FF)
953 <<
static_cast<char>((pVih->bmiHeader.biCompression & 0x0000FF00) >> 8)
954 <<
static_cast<char>((pVih->bmiHeader.biCompression & 0x00FF0000) >> 16)
955 <<
static_cast<char>((pVih->bmiHeader.biCompression & 0xFF000000) >> 24) << std::endl;
957 std::cout <<
"image size : " << pVih->bmiHeader.biWidth <<
" x " << pVih->bmiHeader.biHeight << std::endl;
958 std::cout <<
"framerate range: [" << 10000000 / scc.MaxFrameInterval <<
"," << 10000000 / scc.MinFrameInterval
963 MyDeleteMediaType(pmtConfig);
971bool vpDirectShowGrabberImpl::setMediaType(
int mediaTypeID)
979 IAMStreamConfig *pConfig =
nullptr;
981 if (FAILED(hr = pBuild->FindInterface(&LOOK_UPSTREAM_ONLY,
984 IID_IAMStreamConfig, (
void **)&pConfig)))
987 VIDEO_STREAM_CONFIG_CAPS scc;
988 AM_MEDIA_TYPE *pmtConfig;
989 hr = pConfig->GetStreamCaps(mediaTypeID, &pmtConfig, (BYTE *)&scc);
992 VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER *)pmtConfig->pbFormat;
993 pVih->AvgTimePerFrame = scc.MinFrameInterval;
995 if (FAILED(hr = pGrabberI->SetMediaType(pmtConfig)) || FAILED(hr = pConfig->SetFormat(pmtConfig)))
998 if (FAILED(hr = pGrabberI->GetConnectedMediaType(&(sgCB.connectedMediaType))))
1002 MyDeleteMediaType(pmtConfig);
1010int vpDirectShowGrabberImpl::getMediaType()
1012 if (init ==
false) {
1017 int mediaTypeID = -1;
1018 VIDEOINFOHEADER *pVihConnected = (VIDEOINFOHEADER *)sgCB.connectedMediaType.pbFormat;
1021 IAMStreamConfig *pConfig =
nullptr;
1023 if (FAILED(hr = pBuild->FindInterface(&LOOK_UPSTREAM_ONLY,
1026 IID_IAMStreamConfig, (
void **)&pConfig)))
1029 int iCount = 0, iSize = 0;
1030 if (FAILED(hr = pConfig->GetNumberOfCapabilities(&iCount, &iSize)))
1034 if (iSize ==
sizeof(VIDEO_STREAM_CONFIG_CAPS)) {
1036 for (
int iFormat = 0; iFormat < iCount; iFormat++) {
1037 VIDEO_STREAM_CONFIG_CAPS scc;
1038 AM_MEDIA_TYPE *pmtConfig;
1039 hr = pConfig->GetStreamCaps(iFormat, &pmtConfig, (BYTE *)&scc);
1041 if (SUCCEEDED(hr)) {
1043 if ((pmtConfig->majortype == sgCB.connectedMediaType.majortype) &&
1044 (pmtConfig->subtype == sgCB.connectedMediaType.subtype) &&
1045 (pmtConfig->formattype == sgCB.connectedMediaType.formattype) &&
1046 (pmtConfig->cbFormat >=
sizeof(VIDEOINFOHEADER)) && (pmtConfig->pbFormat !=
nullptr)) {
1047 VIDEOINFOHEADER *pVih = (VIDEOINFOHEADER *)pmtConfig->pbFormat;
1048 if (pVih->bmiHeader.biWidth == pVihConnected->bmiHeader.biWidth &&
1049 pVih->bmiHeader.biHeight == pVihConnected->bmiHeader.biHeight)
1050 mediaTypeID = iFormat;
1054 MyDeleteMediaType(pmtConfig);
1064void vpDirectShowGrabberImpl::MyDeleteMediaType(AM_MEDIA_TYPE *pmt)
1066 if (pmt !=
nullptr) {
1067 MyFreeMediaType(*pmt);
1075void vpDirectShowGrabberImpl::MyFreeMediaType(AM_MEDIA_TYPE &mt)
1077 if (mt.cbFormat != 0) {
1078 CoTaskMemFree((PVOID)mt.pbFormat);
1080 mt.pbFormat =
nullptr;
1082 if (mt.pUnk !=
nullptr) {
1089#elif !defined(VISP_BUILD_SHARED_LIBS)
1092void dummy_vpDirectShowGrabberImpl() { }
Error that can be emitted by the vpFrameGrabber class and its derivates.
@ initializationError
Grabber initialization error.
@ otherError
Grabber returned an other error.
Definition of the vpImage class member functions.