Result SoundSourceMediaFoundation::tryOpen(const Mixxx::AudioSourceConfig& audioSrcCfg) { if (SUCCEEDED(m_hrCoInitialize)) { qWarning() << "Cannot reopen MediaFoundation file" << getUrlString(); return ERR; } const QString fileName(getLocalFileName()); if (sDebug) { qDebug() << "open()" << fileName; } // Initialize the COM library. m_hrCoInitialize = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); if (FAILED(m_hrCoInitialize)) { qWarning() << "SSMF: failed to initialize COM"; return ERR; } // Initialize the Media Foundation platform. m_hrMFStartup = MFStartup(MF_VERSION); if (FAILED(m_hrCoInitialize)) { qWarning() << "SSMF: failed to initialize Media Foundation"; return ERR; } QString qurlStr(fileName); // http://social.msdn.microsoft.com/Forums/en/netfxbcl/thread/35c6a451-3507-40c8-9d1c-8d4edde7c0cc // gives maximum path + file length as 248 + 260, using that -bkgood m_wcFilename = new wchar_t[248 + 260]; int wcFilenameLength(fileName.toWCharArray(m_wcFilename)); // toWCharArray does not append a null terminator to the string! m_wcFilename[wcFilenameLength] = '\0'; // Create the source reader to read the input file. HRESULT hr = MFCreateSourceReaderFromURL(m_wcFilename, NULL, &m_pReader); if (FAILED(hr)) { qWarning() << "SSMF: Error opening input file:" << fileName; return ERR; } if (!configureAudioStream(audioSrcCfg)) { qWarning() << "SSMF: Error configuring audio stream."; return ERR; } //Seek to position 0, which forces us to skip over all the header frames. //This makes sure we're ready to just let the Analyser rip and it'll //get the number of samples it expects (ie. no header frames). seekSampleFrame(0); return OK; }
int SoundSourceMediaFoundation::open() { if (sDebug) { qDebug() << "open()" << m_qFilename; } QString qurlStr(m_qFilename); int wcFilenameLength(m_qFilename.toWCharArray(m_wcFilename)); // toWCharArray does not append a null terminator to the string! m_wcFilename[wcFilenameLength] = '\0'; HRESULT hr(S_OK); // Initialize the COM library. hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); if (FAILED(hr)) { qWarning() << "SSMF: failed to initialize COM"; return ERR; } // Initialize the Media Foundation platform. hr = MFStartup(MF_VERSION); if (FAILED(hr)) { qWarning() << "SSMF: failed to initialize Media Foundation"; return ERR; } // Create the source reader to read the input file. hr = MFCreateSourceReaderFromURL(m_wcFilename, NULL, &m_pReader); if (FAILED(hr)) { qWarning() << "SSMF: Error opening input file:" << m_qFilename; return ERR; } if (!configureAudioStream()) { qWarning() << "SSMF: Error configuring audio stream."; return ERR; } if (!readProperties()) { qWarning() << "SSMF::readProperties failed"; return ERR; } //Seek to position 0, which forces us to skip over all the header frames. //This makes sure we're ready to just let the Analyser rip and it'll //get the number of samples it expects (ie. no header frames). seek(0); return OK; }