[WinCairo] Support more video formats.
authorpeavo@outlook.com <peavo@outlook.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Jan 2016 21:42:25 +0000 (21:42 +0000)
committerpeavo@outlook.com <peavo@outlook.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 8 Jan 2016 21:42:25 +0000 (21:42 +0000)
https://bugs.webkit.org/show_bug.cgi?id=152890

Reviewed by Alex Christensen.

Use MediaFoundation api to detect all supported video/audio formats.

* platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp:
(WebCore::MediaPlayerPrivateMediaFoundation::getSupportedTypes):
(WebCore::MediaPlayerPrivateMediaFoundation::supportsType):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@194787 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp

index 2467217..a2860ef 100644 (file)
@@ -1,3 +1,16 @@
+2016-01-08  Per Arne Vollan  <peavo@outlook.com>
+
+        [WinCairo] Support more video formats.
+        https://bugs.webkit.org/show_bug.cgi?id=152890
+
+        Reviewed by Alex Christensen.
+
+        Use MediaFoundation api to detect all supported video/audio formats.
+
+        * platform/graphics/win/MediaPlayerPrivateMediaFoundation.cpp:
+        (WebCore::MediaPlayerPrivateMediaFoundation::getSupportedTypes):
+        (WebCore::MediaPlayerPrivateMediaFoundation::supportsType):
+
 2016-01-08  Brady Eidson  <beidson@apple.com>
 
         Modern IDB: Blocked event can fire on a delete request even after the last open connection has closed.
index 7dca060..f8a46fb 100644 (file)
@@ -41,6 +41,7 @@
 #if USE(MEDIA_FOUNDATION)
 
 #include <wtf/MainThread.h>
+#include <wtf/NeverDestroyed.h>
 
 SOFT_LINK_LIBRARY(Mf);
 SOFT_LINK_OPTIONAL(Mf, MFCreateSourceResolver, HRESULT, STDAPICALLTYPE, (IMFSourceResolver**));
@@ -51,6 +52,7 @@ SOFT_LINK_OPTIONAL(Mf, MFGetService, HRESULT, STDAPICALLTYPE, (IUnknown*, REFGUI
 SOFT_LINK_OPTIONAL(Mf, MFCreateAudioRendererActivate, HRESULT, STDAPICALLTYPE, (IMFActivate**));
 SOFT_LINK_OPTIONAL(Mf, MFCreateVideoRendererActivate, HRESULT, STDAPICALLTYPE, (HWND, IMFActivate**));
 SOFT_LINK_OPTIONAL(Mf, MFCreateSampleGrabberSinkActivate, HRESULT, STDAPICALLTYPE, (IMFMediaType*, IMFSampleGrabberSinkCallback*, IMFActivate**));
+SOFT_LINK_OPTIONAL(Mf, MFGetSupportedMimeTypes, HRESULT, STDAPICALLTYPE, (PROPVARIANT*));
 
 SOFT_LINK_LIBRARY(Mfplat);
 SOFT_LINK_OPTIONAL(Mfplat, MFStartup, HRESULT, STDAPICALLTYPE, (ULONG, DWORD));
@@ -118,9 +120,37 @@ bool MediaPlayerPrivateMediaFoundation::isAvailable()
     return true;
 }
 
+static const HashSet<String>& mimeTypeCache()
+{
+    static NeverDestroyed<HashSet<String>> cachedTypes;
+
+    if (cachedTypes.get().size() > 0)
+        return cachedTypes;
+
+    cachedTypes.get().add(String("video/mp4"));
+
+    if (!MFGetSupportedMimeTypesPtr())
+        return cachedTypes;
+
+    PROPVARIANT propVarMimeTypeArray;
+    PropVariantInit(&propVarMimeTypeArray);
+
+    HRESULT hr = MFGetSupportedMimeTypesPtr()(&propVarMimeTypeArray);
+
+    if (SUCCEEDED(hr)) {
+        CALPWSTR mimeTypeArray = propVarMimeTypeArray.calpwstr;
+        for (unsigned i = 0; i < mimeTypeArray.cElems; i++)
+            cachedTypes.get().add(mimeTypeArray.pElems[i]);
+    }
+
+    PropVariantClear(&propVarMimeTypeArray);
+
+    return cachedTypes;
+}
+
 void MediaPlayerPrivateMediaFoundation::getSupportedTypes(HashSet<String>& types)
 {
-    types.add(String("video/mp4"));
+    types = mimeTypeCache();
 }
 
 MediaPlayer::SupportsType MediaPlayerPrivateMediaFoundation::supportsType(const MediaEngineSupportParameters& parameters)
@@ -128,7 +158,7 @@ MediaPlayer::SupportsType MediaPlayerPrivateMediaFoundation::supportsType(const
     if (parameters.type.isNull() || parameters.type.isEmpty())
         return MediaPlayer::IsNotSupported;
 
-    if (parameters.type == "video/mp4")
+    if (mimeTypeCache().contains(parameters.type))
         return MediaPlayer::IsSupported;
 
     return MediaPlayer::IsNotSupported;