pkg/driver/camera/camera_windows.cpp
// listResolution stores list of the device to camera*.
listResolution stores list of the device to camera*.
listResolution stores list of the device to camera * .
int listResolution(camera* cam, const char** errstr)
{
  cam->props = nullptr;
  IMoniker* moniker = nullptr;
  IBaseFilter* captureFilter = nullptr;
  ICaptureGraphBuilder2* captureGraph = nullptr;
  IAMStreamConfig* config = nullptr;
  IPin* src = nullptr;
  LPOLESTR name;
  if (!selectCamera(cam, &moniker, errstr))
  {
    goto fail;
  }
  moniker->BindToObject(0, 0, IID_IBaseFilter, (void**)&captureFilter);
  safeRelease(&moniker);
  src = getPin(captureFilter, PINDIR_OUTPUT);
  if (src == nullptr)
  {
    *errstr = errGetConfig;
    goto fail;
  }
  if (FAILED(src->QueryInterface(
          IID_IAMStreamConfig, (void**)&config)))
  {
    *errstr = errGetConfig;
    goto fail;
  }
  safeRelease(&src);
  {
    int count = 0, size = 0;
    if (FAILED(config->GetNumberOfCapabilities(&count, &size)))
    {
      *errstr = errGetConfig;
      goto fail;
    }
    cam->props = new imageProp[count];
    int iProp = 0;
    for (int i = 0; i < count; ++i)
    {
      VIDEO_STREAM_CONFIG_CAPS caps;
      AM_MEDIA_TYPE* mediaType;
      if (FAILED(config->GetStreamCaps(i, &mediaType, (BYTE*)&caps)))
        continue;
      if (mediaType->majortype != MEDIATYPE_Video ||
          mediaType->formattype != FORMAT_VideoInfo ||
          mediaType->pbFormat == nullptr)
        continue;
      VIDEOINFOHEADER* videoInfoHdr = (VIDEOINFOHEADER*)mediaType->pbFormat;
      cam->props[iProp].width = videoInfoHdr->bmiHeader.biWidth;
      cam->props[iProp].height = videoInfoHdr->bmiHeader.biHeight;
      cam->props[iProp].fcc = videoInfoHdr->bmiHeader.biCompression;
      iProp++;
    }
    cam->numProps = iProp;
  }
  safeRelease(&config);
  safeRelease(&captureGraph);
  safeRelease(&captureFilter);
  safeRelease(&moniker);
  return 0;
fail:
  safeRelease(&src);
  safeRelease(&config);
  safeRelease(&captureGraph);
  safeRelease(&captureFilter);
  safeRelease(&moniker);
  return 1;
}
int listResolution ( camera * cam , const char * * errstr ) { cam -> props = nullptr ; IMoniker * moniker = nullptr ; IBaseFilter * captureFilter = nullptr ; ICaptureGraphBuilder2 * captureGraph = nullptr ; IAMStreamConfig * config = nullptr ; IPin * src = nullptr ; LPOLESTR name ; if ( ! selectCamera ( cam , & moniker , errstr ) ) { goto fail ; } moniker -> BindToObject ( 0 , 0 , IID_IBaseFilter , ( void * * ) & captureFilter ) ; safeRelease ( & moniker ) ; src = getPin ( captureFilter , PINDIR_OUTPUT ) ; if ( src == nullptr ) { * errstr = errGetConfig ; goto fail ; } if ( FAILED ( src -> QueryInterface ( IID_IAMStreamConfig , ( void * * ) & config ) ) ) { * errstr = errGetConfig ; goto fail ; } safeRelease ( & src ) ; { int count = 0 , size = 0 ; if ( FAILED ( config -> GetNumberOfCapabilities ( & count , & size ) ) ) { * errstr = errGetConfig ; goto fail ; } cam -> props = new imageProp [ count ] ; int iProp = 0 ; for ( int i = 0 ; i < count ; ++ i ) { VIDEO_STREAM_CONFIG_CAPS caps ; AM_MEDIA_TYPE * mediaType ; if ( FAILED ( config -> GetStreamCaps ( i , & mediaType , ( BYTE * ) & caps ) ) ) continue ; if ( mediaType -> majortype != MEDIATYPE_Video || mediaType -> formattype != FORMAT_VideoInfo || mediaType -> pbFormat == nullptr ) continue ; VIDEOINFOHEADER * videoInfoHdr = ( VIDEOINFOHEADER * ) mediaType -> pbFormat ; cam -> props [ iProp ] . width = videoInfoHdr -> bmiHeader . biWidth ; cam -> props [ iProp ] . height = videoInfoHdr -> bmiHeader . biHeight ; cam -> props [ iProp ] . fcc = videoInfoHdr -> bmiHeader . biCompression ; iProp ++ ; } cam -> numProps = iProp ; } safeRelease ( & config ) ; safeRelease ( & captureGraph ) ; safeRelease ( & captureFilter ) ; safeRelease ( & moniker ) ; return 0 ; fail : safeRelease ( & src ) ; safeRelease ( & config ) ; safeRelease ( & captureGraph ) ; safeRelease ( & captureFilter ) ; safeRelease ( & moniker ) ; return 1 ; }
listResolution stores list of the device to camera*.
listResolution stores list of the device to camera * .
// Getting IAMStreamConfig is stub on Wine. Requires real Windows.