HRESULT CTranscoder::OpenFile(const WCHAR *sURL) { if (!sURL) { return E_INVALIDARG; } HRESULT hr = S_OK; // Create the media source. hr = CreateMediaSource(sURL, &m_pSource); //Create the media session. if (SUCCEEDED(hr)) { hr = MFCreateMediaSession(NULL, &m_pSession); } // Create an empty transcode profile. if (SUCCEEDED(hr)) { hr = MFCreateTranscodeProfile(&m_pProfile); } return hr; }
// 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. }
std::vector<std::vector<double>> ReadMusicFrequencyData(const WCHAR *sURL) { //CComPtr<IMFByteStream> pStream; CComPtr<IMFMediaSink> pSink; CComPtr<IMFMediaSource> pSource; CComPtr<IMFTopology> pTopology; CComPtr<IWaveDataRecorder> waveRecord; HRESULT hr=0; hr=CWavRecord::CreateInstanse(&waveRecord); //hr = MFCreateFile(MF_ACCESSMODE_WRITE, MF_OPENMODE_DELETE_IF_EXIST, MF_FILEFLAGS_NONE, sOutputFile, &pStream); if (FAILED(hr)) { wprintf(L"MFCreateFile failed!\n"); } // Create the WavSink object. if (SUCCEEDED(hr)) { hr = CreateWavSink(NULL,waveRecord, &pSink); } // Create the media source from the URL. if (SUCCEEDED(hr)) { hr = CreateMediaSource(sURL, &pSource); } // Create the topology. if (SUCCEEDED(hr)) { hr = CreateTopology(pSource, pSink, &pTopology); } // Run the media session. if (SUCCEEDED(hr)) { hr = RunMediaSession(pTopology); if (FAILED(hr)) { wprintf(L"RunMediaSession failed!\n"); } } if (pSource) { pSource->Shutdown(); } std::vector<std::vector<double>> data; if(waveRecord) waveRecord->PullOutData(&data); return data; }
// Open a URL for playback. HRESULT CPlayer::OpenURL(const WCHAR *sURL) { // 1. Create a new media session. // 2. Create the media source. HRESULT hr = S_OK; CHECK_HR(hr = CreateSession()); // Create the media source. CHECK_HR(hr = CreateMediaSource(sURL, &m_pSource)); EndOpenURL(); done: if (FAILED(hr)) m_state = Closed; return hr; }
HRESULT CPlayer::OpenURL(const WCHAR *sURL) { TRACE((L"CPlayer::OpenURL\n")); TRACE((L"URL = %s\n", sURL)); // 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.] HRESULT hr = S_OK; IMFTopology *pTopology = NULL; // Create the media session. CHECK_HR(hr = CreateSession()); // Create the media source. CHECK_HR(hr = CreateMediaSource(sURL)); // Create a partial topology. CHECK_HR(hr = CreateTopologyFromSource(&pTopology)); // Set the topology on the media session. CHECK_HR(hr = m_pSession->SetTopology(0, pTopology)); // Set our state to "open pending" m_state = OpenPending; // If SetTopology succeeded, the media session will queue an // MESessionTopologySet event. done: if (FAILED(hr)) { m_state = Closed; } SAFE_RELEASE(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; }