From a23b14874cc0482e6700592d19dd2018aeb41cc5 Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Fri, 11 Oct 2013 16:57:44 +0200 Subject: [PATCH] WMF: allow to load media whose content doesn't match its file extension. This also allows to play streams without providing a MIME type. Task-number: QTBUG-33631 Task-number: QTBUG-33518 Change-Id: Ia106592cb5ed0a0f7ede6308dc8e2c12cf4e63b1 Reviewed-by: Christian Stromme --- src/plugins/wmf/sourceresolver.cpp | 41 ++++++++++++++++-------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/plugins/wmf/sourceresolver.cpp b/src/plugins/wmf/sourceresolver.cpp index 275fced9..3f39671f 100644 --- a/src/plugins/wmf/sourceresolver.cpp +++ b/src/plugins/wmf/sourceresolver.cpp @@ -175,19 +175,16 @@ void SourceResolver::load(QMediaResourceList& resources, QIODevice* stream) qWarning() << "Failed to create Source Resolver!"; emit error(hr); } else if (stream) { - if (resources.count() > 0) { - QMediaResource resource = resources.takeFirst(); - QUrl url = resource.url(); - m_stream = new MFStream(stream, false); - hr = m_sourceResolver->BeginCreateObjectFromByteStream(m_stream, reinterpret_cast(url.toString().utf16()), - MF_RESOLUTION_MEDIASOURCE, NULL, &m_cancelCookie, this, new State(m_sourceResolver, true)); - if (FAILED(hr)) { - qWarning() << "Unsupported stream!"; - emit error(hr); - } - } else { - hr = MF_E_UNSUPPORTED_BYTESTREAM_TYPE; - qWarning() << "Can't load stream without a hint of MIME type in a url"; + QString url; + if (!resources.isEmpty()) + url = resources.takeFirst().url().toString(); + m_stream = new MFStream(stream, false); + hr = m_sourceResolver->BeginCreateObjectFromByteStream( + m_stream, url.isEmpty() ? 0 : reinterpret_cast(url.utf16()), + MF_RESOLUTION_MEDIASOURCE | MF_RESOLUTION_CONTENT_DOES_NOT_HAVE_TO_MATCH_EXTENSION_OR_MIME_TYPE + , NULL, &m_cancelCookie, this, new State(m_sourceResolver, true)); + if (FAILED(hr)) { + qWarning() << "Unsupported stream!"; emit error(hr); } } else { @@ -203,8 +200,10 @@ void SourceResolver::load(QMediaResourceList& resources, QIODevice* stream) stream = new QFile(url.path().mid(1), this); if (stream->open(QIODevice::ReadOnly)) { m_stream = new MFStream(stream, true); - hr = m_sourceResolver->BeginCreateObjectFromByteStream(m_stream, reinterpret_cast(url.toString().utf16()), - MF_RESOLUTION_MEDIASOURCE, NULL, &m_cancelCookie, this, new State(m_sourceResolver, true)); + hr = m_sourceResolver->BeginCreateObjectFromByteStream( + m_stream, reinterpret_cast(url.toString().utf16()), + MF_RESOLUTION_MEDIASOURCE | MF_RESOLUTION_CONTENT_DOES_NOT_HAVE_TO_MATCH_EXTENSION_OR_MIME_TYPE, + NULL, &m_cancelCookie, this, new State(m_sourceResolver, true)); if (FAILED(hr)) { qWarning() << "Unsupported stream!"; emit error(hr); @@ -221,8 +220,10 @@ void SourceResolver::load(QMediaResourceList& resources, QIODevice* stream) stream = new QFile(QLatin1Char(':') + url.path(), this); if (stream->open(QIODevice::ReadOnly)) { m_stream = new MFStream(stream, true); - hr = m_sourceResolver->BeginCreateObjectFromByteStream(m_stream, reinterpret_cast(url.toString().utf16()), - MF_RESOLUTION_MEDIASOURCE, NULL, &m_cancelCookie, this, new State(m_sourceResolver, true)); + hr = m_sourceResolver->BeginCreateObjectFromByteStream( + m_stream, reinterpret_cast(url.toString().utf16()), + MF_RESOLUTION_MEDIASOURCE | MF_RESOLUTION_CONTENT_DOES_NOT_HAVE_TO_MATCH_EXTENSION_OR_MIME_TYPE, + NULL, &m_cancelCookie, this, new State(m_sourceResolver, true)); if (FAILED(hr)) { qWarning() << "Unsupported stream!"; emit error(hr); @@ -232,8 +233,10 @@ void SourceResolver::load(QMediaResourceList& resources, QIODevice* stream) emit error(QMediaPlayer::FormatError); } } else { - hr = m_sourceResolver->BeginCreateObjectFromURL(reinterpret_cast(url.toString().utf16()), - MF_RESOLUTION_MEDIASOURCE, NULL, &m_cancelCookie, this, new State(m_sourceResolver, false)); + hr = m_sourceResolver->BeginCreateObjectFromURL( + reinterpret_cast(url.toString().utf16()), + MF_RESOLUTION_MEDIASOURCE | MF_RESOLUTION_CONTENT_DOES_NOT_HAVE_TO_MATCH_EXTENSION_OR_MIME_TYPE, + NULL, &m_cancelCookie, this, new State(m_sourceResolver, false)); if (FAILED(hr)) { qWarning() << "Unsupported url scheme!"; emit error(hr);