コード例 #1
0
ファイル: capture.cpp プロジェクト: goussepi/lab
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;
}
コード例 #2
0
ファイル: capture.cpp プロジェクト: cchang326/2p5D
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;
}
コード例 #3
0
HRESULT CASFManager::CreateASFSplitter (IMFByteStream *pContentByteStream,
                                        IMFASFSplitter **ppSplitter)
{
    if (!pContentByteStream || !ppSplitter)
    {
        return E_INVALIDARG;
    }

    if (!m_pContentInfo)
    {
        return MF_E_NOT_INITIALIZED;
    }

    HRESULT hr = S_OK;
    
    IMFASFSplitter *pSplitter = NULL;
    IMFPresentationDescriptor* pPD = NULL;

    UINT64 cbDataOffset = 0, cbDataLength = 0;

    CHECK_HR(hr = MFCreateASFSplitter(&pSplitter));
    
    CHECK_HR(hr = pSplitter->Initialize(m_pContentInfo));

    //Generate the presentation descriptor
    CHECK_HR(hr =  m_pContentInfo->GeneratePresentationDescriptor(&pPD));

    //Get the offset to the start of the Data Object
    CHECK_HR(hr = pPD->GetUINT64(MF_PD_ASF_DATA_START_OFFSET, &cbDataOffset));

    //Get the length of the Data Object
    CHECK_HR(hr = pPD->GetUINT64(MF_PD_ASF_DATA_LENGTH, &cbDataLength));

    m_pByteStream = pContentByteStream;
    m_pByteStream->AddRef();

    m_cbDataOffset = cbDataOffset;
    m_cbDataLength = cbDataLength;

    // Return the pointer to the caller.
    *ppSplitter = pSplitter;
    (*ppSplitter)->AddRef();

    TRACE((L"Created Splitter object.\n"));


done:

    LOG_MSG_IF_FAILED(L"CASFManager::CreateASFSplitter failed.\n", hr);

    SAFE_RELEASE(pSplitter);
    SAFE_RELEASE(pPD);

    return hr;
}
コード例 #4
0
ファイル: capture.cpp プロジェクト: goussepi/lab
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;
}
コード例 #5
0
ファイル: mfutils.cpp プロジェクト: cchang326/2p5D
// 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;
}
コード例 #6
0
  //----------------------------------------------------------------------------
  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;
  }
コード例 #7
0
double MediaPlayerPrivateMediaFoundation::durationDouble() const
{
    const double tenMegahertz = 10000000;
    if (!m_mediaSource)
        return 0;

    IMFPresentationDescriptor* descriptor;
    if (!SUCCEEDED(m_mediaSource->CreatePresentationDescriptor(&descriptor)))
        return 0;
    
    UINT64 duration;
    if (!SUCCEEDED(descriptor->GetUINT64(MF_PD_DURATION, &duration)))
        duration = 0;
    descriptor->Release();
    
    return static_cast<double>(duration) / tenMegahertz;
}
コード例 #8
0
/** 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;
}
コード例 #9
0
HRESULT CPlayer::CreateTopologyFromSource(IMFTopology **ppTopology)
{
    TRACE((L"CPlayer::CreateTopologyFromSource\n"));

    assert(m_pSession != NULL);
    assert(m_pSource != NULL);

    HRESULT hr = S_OK;

    IMFTopology *pTopology = NULL;
    IMFPresentationDescriptor* pSourcePD = NULL;
    DWORD cSourceStreams = 0;

    // Create a new topology.
    CHECK_HR(hr = MFCreateTopology(&pTopology));

    // Create the presentation descriptor for the media source.
    CHECK_HR(hr = m_pSource->CreatePresentationDescriptor(&pSourcePD));

    // Get the number of streams in the media source.
    CHECK_HR(hr = pSourcePD->GetStreamDescriptorCount(&cSourceStreams));

    TRACE((L"Stream count: %d\n", cSourceStreams));

    // For each stream, create the topology nodes and add them to the topology.
    for (DWORD i = 0; i < cSourceStreams; i++)
    {
        CHECK_HR(hr = AddBranchToPartialTopology(pTopology, pSourcePD, i));
    }

    // Return the IMFTopology pointer to the caller.
    if (SUCCEEDED(hr))
    {
        *ppTopology = pTopology;
        (*ppTopology)->AddRef();
    }

done:
    SAFE_RELEASE(pTopology);
    SAFE_RELEASE(pSourcePD);
    return hr;
}
コード例 #10
0
ファイル: capture.cpp プロジェクト: goussepi/lab
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;
}
コード例 #11
0
HRESULT CTedPlayer::GetDuration(MFTIME& hnsTime) 
{
    HRESULT hr = S_OK;
    IMFPresentationDescriptor *pPD = NULL;

    if(NULL != m_spSource.p)
    {
        IFC( m_spSource->CreatePresentationDescriptor( &pPD ) );
        IFC( pPD->GetUINT64( MF_PD_DURATION, (UINT64*) &hnsTime ) );
    }
    else
    {
        hr = E_POINTER;
    }

    
Cleanup:
    if(pPD) pPD->Release();
    
    return( hr );
}
コード例 #12
0
HRESULT CASFManager::SetFilePropertiesObject(FILE_PROPERTIES_OBJECT* fileinfo)
{
    if (! m_pContentInfo)
    {
        return MF_E_NOT_INITIALIZED;
    }

    HRESULT hr = S_OK;

    IMFPresentationDescriptor *pPD = NULL;

    UINT32 cbBlobSize = 0;

    CHECK_HR( hr =  m_pContentInfo->GeneratePresentationDescriptor(&pPD));

    //get File ID
    hr = pPD->GetGUID(MF_PD_ASF_FILEPROPERTIES_FILE_ID, &fileinfo->guidFileID);

    // get Creation Time
    hr = pPD->GetBlob(MF_PD_ASF_FILEPROPERTIES_CREATION_TIME, (BYTE *)&fileinfo->ftCreationTime, sizeof(FILETIME), &cbBlobSize);

    //get Data Packets Count
    hr = pPD->GetUINT32(MF_PD_ASF_FILEPROPERTIES_PACKETS, &fileinfo->cbPackets);

    //get Play Duration
    hr = pPD->GetUINT64(MF_PD_ASF_FILEPROPERTIES_PLAY_DURATION, &fileinfo->cbPlayDuration);

    //get presentation duration 
    hr = pPD->GetUINT64(MF_PD_DURATION, &fileinfo->cbPresentationDuration);

    //get Send Duration
    hr = pPD->GetUINT64(MF_PD_ASF_FILEPROPERTIES_SEND_DURATION, &fileinfo->cbSendDuration);

    //get preroll
    UINT64 msecspreroll = 0, hnspreroll =0;
    hr = pPD->GetUINT64(MF_PD_ASF_FILEPROPERTIES_PREROLL, &msecspreroll);
    hnspreroll = msecspreroll*10000;
    fileinfo->cbPreroll = hnspreroll;

    //get Flags
    hr = pPD->GetUINT32(MF_PD_ASF_FILEPROPERTIES_FLAGS, &fileinfo->cbFlags);

    //get Maximum Data Packet Size
    hr = pPD->GetUINT32(MF_PD_ASF_FILEPROPERTIES_MAX_PACKET_SIZE, &fileinfo->cbMaxPacketSize);

    //get Minimum Data Packet Size
    hr = pPD->GetUINT32(MF_PD_ASF_FILEPROPERTIES_MIN_PACKET_SIZE, &fileinfo->cbMinPacketSize);
    
    // get Maximum Bit rate
    hr = pPD->GetUINT32(MF_PD_ASF_FILEPROPERTIES_MAX_BITRATE, &fileinfo->cbMaxBitRate);
    

    this->m_fileinfo = fileinfo;

    TRACE((L"Read File Properties Object from the ASF Header Object.\n"));

done:

    LOG_MSG_IF_FAILED(L"CASFManager::SetFilePropertiesObject failed.\n", hr);

    SAFE_RELEASE(pPD);

    return hr;

}
コード例 #13
0
  //----------------------------------------------------------------------------
  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;
  }