Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
HRESULT SetMaxFrameRate(IMFMediaSource *pSource, DWORD dwTypeIndex)
{
  IMFPresentationDescriptor *pPD = NULL;
  IMFStreamDescriptor *pSD = NULL;
  IMFMediaTypeHandler *pHandler = NULL;
  IMFMediaType *pType = NULL;

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

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

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

  hr = pHandler->GetCurrentMediaType(&pType);
  if (FAILED(hr))
  {
    goto done;
  }

  // Get the maximum frame rate for the selected capture format.

  // Note: To get the minimum frame rate, use the 
  // MF_MT_FRAME_RATE_RANGE_MIN attribute instead.

  PROPVARIANT var;
  if (SUCCEEDED(pType->GetItem(MF_MT_FRAME_RATE_RANGE_MAX, &var)))
  {
    hr = pType->SetItem(MF_MT_FRAME_RATE, var);

    PropVariantClear(&var);

    if (FAILED(hr))
    {
      goto done;
    }

    hr = pHandler->SetCurrentMediaType(pType);
  }

done:
  SafeRelease(&pPD);
  SafeRelease(&pSD);
  SafeRelease(&pHandler);
  SafeRelease(&pType);
  return hr;
}
Ejemplo n.º 3
0
HRESULT EnumerateCaptureFormats(IMFMediaSource *pSource)
{
  IMFPresentationDescriptor *pPD = NULL;
  IMFStreamDescriptor *pSD = NULL;
  IMFMediaTypeHandler *pHandler = NULL;
  IMFMediaType *pType = NULL;

  HRESULT hr = pSource->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 (DWORD i = 0; i < cTypes; i++)
  {
    hr = pHandler->GetMediaTypeByIndex(i, &pType);
    if (FAILED(hr))
    {
      goto done;
    }

    LogMediaType(pType);
    OutputDebugString(L"\n");

    SafeRelease(&pType);
  }

done:
  SafeRelease(&pPD);
  SafeRelease(&pSD);
  SafeRelease(&pHandler);
  SafeRelease(&pType);
  return hr;
}
Ejemplo n.º 4
0
// Create the topology.
HRESULT CreateTopology(IMFMediaSource *pSource, IMFActivate *pSinkActivate, IMFTopology **ppTopo)
{
    IMFTopology *pTopology = NULL;
    IMFPresentationDescriptor *pPD = NULL;
    IMFStreamDescriptor *pSD = NULL;
    IMFMediaTypeHandler *pHandler = NULL;
    IMFTopologyNode *pNode1 = NULL;
    IMFTopologyNode *pNode2 = NULL;

    HRESULT hr = S_OK;
    DWORD cStreams = 0;

    CHECK_HR(hr = MFCreateTopology(&pTopology));
    CHECK_HR(hr = pSource->CreatePresentationDescriptor(&pPD));
    CHECK_HR(hr = pPD->GetStreamDescriptorCount(&cStreams));

    for (DWORD i = 0; i < cStreams; i++) {
        // In this example, we look for audio streams and connect them to the sink.

        BOOL fSelected = FALSE;
        GUID majorType;

        CHECK_HR(hr = pPD->GetStreamDescriptorByIndex(i, &fSelected, &pSD));
        CHECK_HR(hr = pSD->GetMediaTypeHandler(&pHandler));
        CHECK_HR(hr = pHandler->GetMajorType(&majorType));

        if (majorType == MFMediaType_Video && fSelected) {
            CHECK_HR(hr = AddSourceNode(pTopology, pSource, pPD, pSD, &pNode1));
            CHECK_HR(hr = AddOutputNode(pTopology, pSinkActivate, 0, &pNode2));
            CHECK_HR(hr = pNode1->ConnectOutput(0, pNode2, 0));
            break;
        } else {
            CHECK_HR(hr = pPD->DeselectStream(i));
        }
        SafeRelease(&pSD);
        SafeRelease(&pHandler);
    }

    *ppTopo = pTopology;
    (*ppTopo)->AddRef();

done:
    SafeRelease(&pTopology);
    SafeRelease(&pNode1);
    SafeRelease(&pNode2);
    SafeRelease(&pPD);
    SafeRelease(&pSD);
    SafeRelease(&pHandler);
    return hr;
}
  //----------------------------------------------------------------------------
  long MediaFoundationVideoDevice::SetDeviceFormat(IMFMediaSource *pSource, DWORD streamIndex, DWORD dwFormatIndex)
  {
    IMFPresentationDescriptor *pPD = NULL;
    IMFStreamDescriptor *pSD = NULL;
    IMFMediaTypeHandler *pHandler = NULL;
    IMFMediaType *pType = NULL;

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

    BOOL fSelected=false;
    hr = pPD->GetStreamDescriptorByIndex(streamIndex, &fSelected, &pSD);
    if (FAILED(hr))
    {
      goto done;
    }
    if (!fSelected)
    {
      hr = pPD->SelectStream(streamIndex);
      if (FAILED(hr))
      {
        LOG_ERROR("Failed to select stream "<<streamIndex);
        goto done;
      }
    }

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

    hr = pHandler->GetMediaTypeByIndex(dwFormatIndex, &pType);
    if (FAILED(hr))
    {
      goto done;
    }

    hr = pHandler->SetCurrentMediaType(pType);

done:
    SafeRelease(&pPD);
    SafeRelease(&pSD);
    SafeRelease(&pHandler);
    SafeRelease(&pType);
    return hr;
  }
/** Set playback topology */
FIntPoint FImfVideoPlayer::SetPlaybackTopology( FImfSampleGrabberCallback* SampleGrabberCallback )
{
	FIntPoint OutDimensions = FIntPoint( ForceInit );
	HRESULT HResult = S_OK;

	IMFPresentationDescriptor* PresentationDesc = NULL;
	HResult = MediaSource->CreatePresentationDescriptor( &PresentationDesc );
	check( SUCCEEDED( HResult ) );

	IMFTopology* Topology = NULL;
	HResult = MFCreateTopology( &Topology );
	check( SUCCEEDED( HResult ) );

	DWORD StreamCount = 0;
	HResult = PresentationDesc->GetStreamDescriptorCount( &StreamCount );
	check( SUCCEEDED( HResult ) );

	for( uint32 i = 0; i < StreamCount; i++ )
	{
		BOOL bSelected = 0;

		IMFStreamDescriptor* StreamDesc = NULL;
		HResult = PresentationDesc->GetStreamDescriptorByIndex( i, &bSelected, &StreamDesc );
		check( SUCCEEDED( HResult ) );

		if( bSelected )
		{
			FIntPoint VideoDimensions = AddStreamToTopology( Topology, PresentationDesc, StreamDesc, SampleGrabberCallback );
			if( VideoDimensions != FIntPoint( ForceInit ) )
				OutDimensions = VideoDimensions;
		}

		StreamDesc->Release( );
	}

	HResult = MediaSession->SetTopology( 0, Topology );
	check( SUCCEEDED( HResult ) );

	Topology->Release( );
	PresentationDesc->Release( );

	return OutDimensions;
}
Ejemplo n.º 7
0
HRESULT SetDeviceFormat(IMFMediaSource *pSource, DWORD dwFormatIndex)
{
  IMFPresentationDescriptor *pPD = NULL;
  IMFStreamDescriptor *pSD = NULL;
  IMFMediaTypeHandler *pHandler = NULL;
  IMFMediaType *pType = NULL;

  HRESULT hr = pSource->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;
  }

  hr = pHandler->GetMediaTypeByIndex(dwFormatIndex, &pType);
  if (FAILED(hr))
  {
    goto done;
  }

  hr = pHandler->SetCurrentMediaType(pType);

done:
  SafeRelease(&pPD);
  SafeRelease(&pSD);
  SafeRelease(&pHandler);
  SafeRelease(&pType);
  return hr;
}
  //----------------------------------------------------------------------------
  long MediaFoundationVideoDevice::EnumerateCaptureFormats(IMFMediaSource *pSource)
  {
    IMFPresentationDescriptor *pPD = NULL;
    IMFStreamDescriptor *pSD = NULL;
    IMFMediaTypeHandler *pHandler = NULL;

    HRESULT hr=-1;
    if (pSource==NULL)
    {
      goto done;
    }

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

    DWORD descriptorCount = 0;
    hr = pPD->GetStreamDescriptorCount(&descriptorCount);
    if (FAILED(hr))
    {
      goto done;
    }

    for (DWORD streamIndex = 0; streamIndex<descriptorCount; streamIndex++)
    {
      std::vector<MediaType> formats;

      BOOL fSelected = false;
      hr = pPD->GetStreamDescriptorByIndex(streamIndex, &fSelected, &pSD);
      if (FAILED(hr))
      {
        goto done;
      }
      DWORD streamId=0;
      hr = pSD->GetStreamIdentifier(&streamId);
      if (FAILED(hr))
      {
        goto done;
      }
      hr = pSD->GetMediaTypeHandler(&pHandler);
      if (FAILED(hr))
      {
        goto done;
      }
      DWORD cTypes = 0;
      hr = pHandler->GetMediaTypeCount(&cTypes);
      if (FAILED(hr))
      {
        continue;
      }
      for (DWORD i = 0; i < cTypes; i++)
      {
        IMFMediaType *pType = NULL;
        hr = pHandler->GetMediaTypeByIndex(i, &pType);
        if (SUCCEEDED(hr))
        {
          MediaType mt = FormatReader::Read(pType);\
          mt.StreamId = streamId;
          formats.push_back(mt);
        }
        SafeRelease(&pType);
      }
      this->CurrentFormats.push_back(formats);
    }

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