//----------------------------------------------------------------------------
  bool MediaFoundationVideoDevice::SetupDevice(unsigned int streamIndex, unsigned int formatIndex)
  {  
    if(this->IsSetup)
    {
      LOG_ERROR("MediaFoundationVideoDevice::SetupDevice failed: device " << this->DeviceIndex << " is already set up");
      return false;
    }

    HRESULT hr = InitDevice();
    if(FAILED(hr))
    {
      LOG_ERROR("MediaFoundationVideoDevice::SetupDevice failed: device " << this->DeviceIndex << " interface IMFMediaSource cannot be retrieved");
      return false;
    }

    this->Width = this->CurrentFormats[streamIndex][formatIndex].width; 
    this->Height = this->CurrentFormats[streamIndex][formatIndex].height;
    this->FrameRate = this->CurrentFormats[streamIndex][formatIndex].MF_MT_FRAME_RATE;
    hr = SetDeviceFormat(this->Source, (DWORD)streamIndex, (DWORD) formatIndex);
    this->IsSetup = (SUCCEEDED(hr));
    if(this->IsSetup)
    {
      LOG_DEBUG("MediaFoundationVideoDevice::SetupDevice: device " << this->DeviceIndex << " device is setup");
    }
    this->PreviousParameters = GetParameters();
    this->ActiveType = formatIndex;
    return this->IsSetup;
  }
Пример #2
0
HRESULT CMFCamCapture::chooseCaptureFormats()
{
    IMFPresentationDescriptor *pPD = NULL;
    IMFStreamDescriptor *pSD = NULL;
    IMFMediaTypeHandler *pHandler = NULL;
    IMFMediaType *pType = NULL;
    DWORD i;

    HRESULT hr = m_spSource->CreatePresentationDescriptor(&pPD);
    if (FAILED(hr)) {
        goto done;
    }

    BOOL fSelected;
    hr = pPD->GetStreamDescriptorByIndex(0, &fSelected, &pSD);
    if (FAILED(hr)) {
        goto done;
    }

    hr = pSD->GetMediaTypeHandler(&pHandler);
    if (FAILED(hr)) {
        goto done;
    }

    DWORD cTypes = 0;
    hr = pHandler->GetMediaTypeCount(&cTypes);
    if (FAILED(hr)) {
        goto done;
    }

    for (i = 0; i < cTypes; i++) {
        hr = pHandler->GetMediaTypeByIndex(i, &pType);
        if (FAILED(hr)) {
            goto done;
        }

        bool found = selectMediaType(m_spSource, pType);
        if (found) {
            LogMediaType(pType);
            OutputDebugString(L"\n");
        }
        SafeRelease(&pType);
        if (found) {            
            hr = SetDeviceFormat(m_spSource, i);
            break;
        }
    }

    if (i >= cTypes) {
        hr = E_FAIL;
    }

done:
    SafeRelease(&pPD);
    SafeRelease(&pSD);
    SafeRelease(&pHandler);
    SafeRelease(&pType);
    return hr;
}