// Open a URL for playback. void Player_::open_url( ev::OpenURL const& openurl) { // 1. Create a new media session. // 2. Create the media source. // 3. Create the topology. // 4. Queue the topology [asynchronous] // 5. Start playback [asynchronous - does not happen in this method.] IMFTopologyPtr pTopology; IMFPresentationDescriptorPtr pSourcePD; // Create the media session. CreateSession(); // Create the media source. m_pSource = CreateMediaSource(openurl.url()); // Create the presentation descriptor for the media source. THROW_IF_ERR(m_pSource->CreatePresentationDescriptor(&pSourcePD)); // Create a partial topology. pTopology = CreatePlaybackTopology(m_pSource, pSourcePD, m_hwndVideo); // Set the topology on the media session. THROW_IF_ERR(m_pSession->SetTopology(0, pTopology.Get())); // OnOpenURL_(); // m_state = OpenPending; // If SetTopology succeeds, the media session will queue an // MESessionTopologySet event. }
void Player_::OnNewPresentation(IMFMediaEventPtr pEvent) { IMFPresentationDescriptorPtr pPD; IMFTopologyPtr pTopology; // Get the presentation descriptor from the event. THROW_IF_ERR(GetEventObject(pEvent.Get(), pPD.GetAddressOf())); // Create a partial topology. pTopology = CreatePlaybackTopology(m_pSource, pPD, m_hwndVideo); // Set the topology on the media session. THROW_IF_ERR(m_pSession->SetTopology(0, pTopology.Get())); // m_state = OpenPending; }
HRESULT CPlayer::EndOpenURL() { HRESULT hr; // 3. Create the topology. // 4. Queue the topology [asynchronous] // 5. Start playback [asynchronous - does not happen in this method.] IMFTopology *pTopology = NULL; IMFPresentationDescriptor* pSourcePD = NULL; // Create the presentation descriptor for the media source. CHECK_HR(hr = m_pSource->CreatePresentationDescriptor(&pSourcePD)); // Create a partial topology. CHECK_HR(hr = CreatePlaybackTopology(m_pSource, pSourcePD, m_hwndVideo, &pTopology, m_pEVRPresenter)); SetMediaInfo(pSourcePD); // Set the topology on the media session. CHECK_HR(hr = m_pSession->SetTopology(0, pTopology)); m_state = OpenPending; _currentVolume = 1.0f; // If SetTopology succeeds, the media session will queue an // MESessionTopologySet event. isDone = false; done: if (FAILED(hr)) { m_state = Closed; } SafeRelease(&pSourcePD); SafeRelease(&pTopology); return hr; }
HRESULT CPlayer::OpenMultipleURL(vector<const WCHAR *> &urls) { if (m_state == OpenPending) return S_FALSE; IMFTopology *pTopology = NULL; IMFPresentationDescriptor* pSourcePD = NULL; //Some lolilol for the sequencer that's coming from the outerspace (see topoEdit src code) IMFMediaSource* spSrc = NULL; IMFPresentationDescriptor* spPD = NULL; IMFMediaSourceTopologyProvider* spSrcTopoProvider = NULL; HRESULT hr = S_OK; if (_previousTopoID != 0) { hr = m_pSequencerSource->DeleteTopology(_previousTopoID); _previousTopoID = 0; } SafeRelease(&m_pSequencerSource); if (!m_pSequencerSource) { CHECK_HR(hr = MFCreateSequencerSource(NULL, &m_pSequencerSource)); CHECK_HR(hr = CreateSession()); CHECK_HR(hr = m_pSequencerSource->QueryInterface(IID_PPV_ARGS(&m_pSource))); } int nUrl = urls.size(); int nPresenters = v_EVRPresenters.size(); for (int i = nPresenters; i < nUrl; i++) { EVRCustomPresenter* presenter = new EVRCustomPresenter(hr); presenter->SetVideoWindow(m_hwndVideo); v_EVRPresenters.push_back(presenter); } // Create the media session. //SafeRelease(&m_pSource); for (int i = 0; i < nUrl; i++) { IMFMediaSource* source = NULL; const WCHAR* sURL = urls[i]; // Create the media source. CHECK_HR(hr = CreateMediaSource(sURL, &source)); return hr; //All the following code will never be reached... // Create the presentation descriptor for the media source. CHECK_HR(hr = source->CreatePresentationDescriptor(&pSourcePD)); if (i == 0) hr = CreatePlaybackTopology(source, pSourcePD, m_hwndVideo, &pTopology, v_EVRPresenters[i]); else CHECK_HR(hr = AddToPlaybackTopology(source, pSourcePD, m_hwndVideo, pTopology, v_EVRPresenters[i])); //v_sources.push_back(source); /*if (i==0) m_pSource = source; //keep one source for time tracking else */ SafeRelease(&source); SetMediaInfo(pSourcePD); SafeRelease(&pSourcePD); } MFSequencerElementId NewID; CHECK_HR(hr = m_pSequencerSource->AppendTopology(pTopology, SequencerTopologyFlags_Last, &NewID)); _previousTopoID = NewID; CHECK_HR(hr = m_pSequencerSource->QueryInterface(IID_IMFMediaSource, (void**)&spSrc)); CHECK_HR(hr = spSrc->CreatePresentationDescriptor(&spPD)); CHECK_HR(hr = m_pSequencerSource->QueryInterface(IID_IMFMediaSourceTopologyProvider, (void**)&spSrcTopoProvider)); SafeRelease(&pTopology); CHECK_HR(hr = spSrcTopoProvider->GetMediaSourceTopology(spPD, &pTopology)); //Now that we're done, we set the topolgy as it should be.... CHECK_HR(hr = m_pSession->SetTopology(0, pTopology)); m_state = OpenPending; _currentVolume = 1.0f; // If SetTopology succeeds, the media session will queue an // MESessionTopologySet event. done: if (FAILED(hr)) { m_state = Closed; } SafeRelease(&pSourcePD); SafeRelease(&pTopology); //SafeRelease(&spPD); //SafeRelease(&spSrc); //SafeRelease(&spSrcTopoProvider); //Uncoment this and get a crash in D3D shared texture.. return hr; }