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; }
/** 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; }
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 ); }