Allow clients to specify a list of codecs which should require hardware decode support.
authorjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 5 Jun 2017 22:40:30 +0000 (22:40 +0000)
committerjer.noble@apple.com <jer.noble@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 5 Jun 2017 22:40:30 +0000 (22:40 +0000)
https://bugs.webkit.org/show_bug.cgi?id=172787

Reviewed by Alex Christensen.

Source/WebCore:

Add a new setting, checked by HTMLMediaElement, which allows MediaPlayerPrivate implementation
to require that the specified codecs have hardware support. This requirement will be supported
in the normal media loading path and the MSE path on Cocoa ports.

* WebCore.xcodeproj/project.pbxproj:
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::mediaCodecsRequiringHardwareSupport):
* html/HTMLMediaElement.h:
* page/Settings.cpp:
(WebCore::Settings::setMediaCodecsRequiringHardwareSupport):
* page/Settings.h:
(WebCore::Settings::mediaCodecsRequiringHardwareSupport):
* platform/cocoa/VideoToolboxSoftLink.cpp:
* platform/cocoa/VideoToolboxSoftLink.h:
* platform/graphics/MediaPlayer.h:
(WebCore::MediaPlayerClient::mediaCodecsRequiringHardwareSupport):
* platform/graphics/avfoundation/objc/AVAssetTrackUtilities.h: Added.
* platform/graphics/avfoundation/objc/AVAssetTrackUtilities.mm: Added.
(WebCore::assetTrackMeetsHardwareDecodeRequirements):
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::checkPlayability):
(WebCore::MediaPlayerPrivateAVFoundationObjC::assetStatus):
* platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:
(WebCore::SourceBufferPrivateAVFObjC::didParseStreamDataAsAsset):

Source/WebKit2:

Add a WKWebPageConfiguration (and associated WebPreferences and WKPreferencesRef) properties
allowing clients to require specified codecs have hardware decode support. Also open up the
sandbox on Cocoa ports to services required to check for hardware decode availability.

* Shared/WebPreferencesDefinitions.h:
* UIProcess/API/C/WKPreferences.cpp:
(WKPreferencesSetMediaCodecsRequiringHardwareSupport):
(WKPreferencesCopyMediaCodecsRequiringHardwareSupport):
* UIProcess/API/C/WKPreferencesRefPrivate.h:
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _initializeWithConfiguration:]):
* UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
(-[WKWebViewConfiguration copyWithZone:]):
(-[WKWebViewConfiguration _mediaCodecsRequiringHardwareSupport]):
(-[WKWebViewConfiguration _setMediaCodecsRequiringHardwareSupport:]):
* UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h:
* WebProcess/com.apple.WebProcess.sb.in:

Source/WTF:

Add a couple of convenience methods:
- a String::split() that returns a vector (rather than taking an out-reference to a vector).
- A Vector::map() template which takes a Callable and returns a Vector of a different type.

* wtf/Vector.h:
(WTF::Vector::map):
* wtf/text/WTFString.h:
(WTF::String::split):

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

32 files changed:
Source/WTF/ChangeLog
Source/WTF/wtf/Vector.h
Source/WTF/wtf/text/WTFString.h
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/html/HTMLMediaElement.cpp
Source/WebCore/html/HTMLMediaElement.h
Source/WebCore/page/Settings.cpp
Source/WebCore/page/Settings.h
Source/WebCore/platform/ContentType.h
Source/WebCore/platform/cocoa/VideoToolboxSoftLink.cpp
Source/WebCore/platform/cocoa/VideoToolboxSoftLink.h
Source/WebCore/platform/graphics/FourCC.cpp [new file with mode: 0644]
Source/WebCore/platform/graphics/FourCC.h [new file with mode: 0644]
Source/WebCore/platform/graphics/MediaPlayer.cpp
Source/WebCore/platform/graphics/MediaPlayer.h
Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h
Source/WebCore/platform/graphics/avfoundation/objc/AVAssetTrackUtilities.h [new file with mode: 0644]
Source/WebCore/platform/graphics/avfoundation/objc/AVAssetTrackUtilities.mm [new file with mode: 0644]
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.h
Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm
Source/WebCore/platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm
Source/WebKit2/ChangeLog
Source/WebKit2/Shared/WebPreferencesDefinitions.h
Source/WebKit2/UIProcess/API/C/WKPreferences.cpp
Source/WebKit2/UIProcess/API/C/WKPreferencesRefPrivate.h
Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm
Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfiguration.mm
Source/WebKit2/UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h
Source/WebKit2/WebProcess/com.apple.WebProcess.sb.in

index 590954a..f7e6247 100644 (file)
@@ -1,3 +1,19 @@
+2017-06-05  Jer Noble  <jer.noble@apple.com>
+
+        Allow clients to specify a list of codecs which should require hardware decode support.
+        https://bugs.webkit.org/show_bug.cgi?id=172787
+
+        Reviewed by Alex Christensen.
+
+        Add a couple of convenience methods:
+        - a String::split() that returns a vector (rather than taking an out-reference to a vector).
+        - A Vector::map() template which takes a Callable and returns a Vector of a different type.
+
+        * wtf/Vector.h:
+        (WTF::Vector::map):
+        * wtf/text/WTFString.h:
+        (WTF::String::split):
+
 2017-06-04  Konstantin Tokarev  <annulen@yandex.ru>
 
         Fix build of Windows-specific code with ICU 59.1
index f8d47f9..e15f65c 100644 (file)
@@ -780,6 +780,8 @@ public:
 
     void checkConsistency();
 
+    template<typename MapFunction, typename R = typename std::result_of<MapFunction(const T&)>::type> Vector<R> map(MapFunction) const;
+
 private:
     void expandCapacity(size_t newMinCapacity);
     T* expandCapacity(size_t newMinCapacity, T*);
@@ -1457,6 +1459,16 @@ inline void Vector<T, inlineCapacity, OverflowHandler, minCapacity>::reverse()
         std::swap(at(i), at(m_size - 1 - i));
 }
 
+template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> template<typename MapFunction, typename R>
+inline Vector<R> Vector<T, inlineCapacity, OverflowHandler, minCapacity>::map(MapFunction mapFunction) const
+{
+    Vector<R> result;
+    result.reserveInitialCapacity(size());
+    for (size_t i = 0; i < size(); ++i)
+        result.uncheckedAppend(mapFunction(at(i)));
+    return result;
+}
+
 template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity>
 inline MallocPtr<T> Vector<T, inlineCapacity, OverflowHandler, minCapacity>::releaseBuffer()
 {
index 6a2406c..dad072c 100644 (file)
@@ -370,6 +370,13 @@ public:
         split(separator, false, result);
     }
 
+    Vector<String> split(const String& separator) const
+    {
+        Vector<String> result;
+        split(separator, false, result);
+        return result;
+    }
+
     WTF_EXPORT_STRING_API int toIntStrict(bool* ok = nullptr, int base = 10) const;
     WTF_EXPORT_STRING_API unsigned toUIntStrict(bool* ok = nullptr, int base = 10) const;
     WTF_EXPORT_STRING_API int64_t toInt64Strict(bool* ok = nullptr, int base = 10) const;
index 6b2470b..6b07450 100644 (file)
@@ -1,3 +1,36 @@
+2017-06-05  Jer Noble  <jer.noble@apple.com>
+
+        Allow clients to specify a list of codecs which should require hardware decode support.
+        https://bugs.webkit.org/show_bug.cgi?id=172787
+
+        Reviewed by Alex Christensen.
+
+        Add a new setting, checked by HTMLMediaElement, which allows MediaPlayerPrivate implementation
+        to require that the specified codecs have hardware support. This requirement will be supported
+        in the normal media loading path and the MSE path on Cocoa ports.
+
+        * WebCore.xcodeproj/project.pbxproj:
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::mediaCodecsRequiringHardwareSupport):
+        * html/HTMLMediaElement.h:
+        * page/Settings.cpp:
+        (WebCore::Settings::setMediaCodecsRequiringHardwareSupport):
+        * page/Settings.h:
+        (WebCore::Settings::mediaCodecsRequiringHardwareSupport):
+        * platform/cocoa/VideoToolboxSoftLink.cpp:
+        * platform/cocoa/VideoToolboxSoftLink.h:
+        * platform/graphics/MediaPlayer.h:
+        (WebCore::MediaPlayerClient::mediaCodecsRequiringHardwareSupport):
+        * platform/graphics/avfoundation/objc/AVAssetTrackUtilities.h: Added.
+        * platform/graphics/avfoundation/objc/AVAssetTrackUtilities.mm: Added.
+        (WebCore::assetTrackMeetsHardwareDecodeRequirements):
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::checkPlayability):
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::assetStatus):
+        * platform/graphics/avfoundation/objc/SourceBufferPrivateAVFObjC.mm:
+        (WebCore::SourceBufferPrivateAVFObjC::didParseStreamDataAsAsset):
+
 2017-06-05  Dan Bernstein  <mitz@apple.com>
 
         Tried to fix the build when targrting macOS 10.12 using the macOS 10.13 developer beta SDK.
index e16ea5f..b33a228 100644 (file)
                41C760B10EDE03D300C1655F /* ScriptState.h in Headers */ = {isa = PBXBuildFile; fileRef = 41C760B00EDE03D300C1655F /* ScriptState.h */; settings = {ATTRIBUTES = (Private, ); }; };
                41CAD71E1EA090A100178164 /* VideoToolBoxEncoderFactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41CAD71C1EA0905700178164 /* VideoToolBoxEncoderFactory.cpp */; };
                41CF8BE71D46226700707DC9 /* FetchBodyConsumer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41CF8BE41D46222000707DC9 /* FetchBodyConsumer.cpp */; };
-               41D015CA0F4B5C71004A662F /* ContentType.h in Headers */ = {isa = PBXBuildFile; fileRef = 41D015C80F4B5C71004A662F /* ContentType.h */; };
+               41D015CA0F4B5C71004A662F /* ContentType.h in Headers */ = {isa = PBXBuildFile; fileRef = 41D015C80F4B5C71004A662F /* ContentType.h */; settings = {ATTRIBUTES = (Private, ); }; };
                41D015CB0F4B5C71004A662F /* ContentType.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41D015C90F4B5C71004A662F /* ContentType.cpp */; };
                41DEFCB51E56C1BD000D9E5F /* JSDOMMapLike.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41DEFCB31E56C1B9000D9E5F /* JSDOMMapLike.cpp */; };
                41DEFCB61E56C1BD000D9E5F /* JSDOMMapLike.h in Headers */ = {isa = PBXBuildFile; fileRef = 41DEFCB41E56C1B9000D9E5F /* JSDOMMapLike.h */; };
                CD5209E61B0BD9E10077184E /* HTMLMediaElementEnums.h in Headers */ = {isa = PBXBuildFile; fileRef = CD5209E51B0BD9E10077184E /* HTMLMediaElementEnums.h */; settings = {ATTRIBUTES = (Private, ); }; };
                CD52481A18E200ED0008A07D /* SleepDisabler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD52481818E200ED0008A07D /* SleepDisabler.cpp */; };
                CD52481B18E200ED0008A07D /* SleepDisabler.h in Headers */ = {isa = PBXBuildFile; fileRef = CD52481918E200ED0008A07D /* SleepDisabler.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               CD525BA31EE0B10700788DF5 /* FourCC.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD525BA11EE0B10700788DF5 /* FourCC.cpp */; };
+               CD525BA41EE0B10700788DF5 /* FourCC.h in Headers */ = {isa = PBXBuildFile; fileRef = CD525BA21EE0B10700788DF5 /* FourCC.h */; settings = {ATTRIBUTES = (Private, ); }; };
                CD5393D3175E018600C07123 /* JSMemoryInfo.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD5393D1175E018600C07123 /* JSMemoryInfo.cpp */; };
                CD5393D4175E018600C07123 /* JSMemoryInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = CD5393D2175E018600C07123 /* JSMemoryInfo.h */; };
                CD54A762180F9F7000B076C9 /* AudioTrackPrivateMediaSourceAVFObjC.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CD54A760180F9F7000B076C9 /* AudioTrackPrivateMediaSourceAVFObjC.cpp */; };
                CDEA76351460B71A008B31F1 /* Clock.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDEA76331460B462008B31F1 /* Clock.cpp */; };
                CDEA7C841276230400B846DD /* RenderFullScreen.h in Headers */ = {isa = PBXBuildFile; fileRef = CDEA7C821276230400B846DD /* RenderFullScreen.h */; };
                CDEA7C851276230400B846DD /* RenderFullScreen.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDEA7C831276230400B846DD /* RenderFullScreen.cpp */; };
+               CDECA89A1EDF447D00DCB08B /* AVAssetTrackUtilities.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDECA8981EDF447D00DCB08B /* AVAssetTrackUtilities.mm */; };
+               CDECA89B1EDF447D00DCB08B /* AVAssetTrackUtilities.h in Headers */ = {isa = PBXBuildFile; fileRef = CDECA8991EDF447D00DCB08B /* AVAssetTrackUtilities.h */; };
                CDEE393717974259001D7580 /* PublicURLManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDEE393617974259001D7580 /* PublicURLManager.cpp */; };
                CDEF4FD717E85C8F00AEE24B /* GridLength.h in Headers */ = {isa = PBXBuildFile; fileRef = CDEF4FD617E85C8F00AEE24B /* GridLength.h */; settings = {ATTRIBUTES = (Private, ); }; };
                CDEFA2281E7669E8000AE99C /* PlatformAudioData.h in Headers */ = {isa = PBXBuildFile; fileRef = CDE667A11E4BBA4D00E8154A /* PlatformAudioData.h */; settings = {ATTRIBUTES = (Private, ); }; };
                CD5209E51B0BD9E10077184E /* HTMLMediaElementEnums.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = HTMLMediaElementEnums.h; sourceTree = "<group>"; };
                CD52481818E200ED0008A07D /* SleepDisabler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SleepDisabler.cpp; sourceTree = "<group>"; };
                CD52481918E200ED0008A07D /* SleepDisabler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SleepDisabler.h; sourceTree = "<group>"; };
+               CD525BA11EE0B10700788DF5 /* FourCC.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = FourCC.cpp; sourceTree = "<group>"; };
+               CD525BA21EE0B10700788DF5 /* FourCC.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FourCC.h; sourceTree = "<group>"; };
                CD5393CB175DCCE600C07123 /* MemoryInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MemoryInfo.h; sourceTree = "<group>"; };
                CD5393CC175DCCE600C07123 /* MemoryInfo.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = MemoryInfo.idl; sourceTree = "<group>"; };
                CD5393D1175E018600C07123 /* JSMemoryInfo.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSMemoryInfo.cpp; sourceTree = "<group>"; };
                CDEA76331460B462008B31F1 /* Clock.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Clock.cpp; sourceTree = "<group>"; };
                CDEA7C821276230400B846DD /* RenderFullScreen.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RenderFullScreen.h; sourceTree = "<group>"; };
                CDEA7C831276230400B846DD /* RenderFullScreen.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = RenderFullScreen.cpp; sourceTree = "<group>"; };
+               CDECA8981EDF447D00DCB08B /* AVAssetTrackUtilities.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = AVAssetTrackUtilities.mm; sourceTree = "<group>"; };
+               CDECA8991EDF447D00DCB08B /* AVAssetTrackUtilities.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AVAssetTrackUtilities.h; sourceTree = "<group>"; };
                CDEE393617974259001D7580 /* PublicURLManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PublicURLManager.cpp; sourceTree = "<group>"; };
                CDEE393817974274001D7580 /* URLRegistry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = URLRegistry.h; sourceTree = "<group>"; };
                CDEF4FD617E85C8F00AEE24B /* GridLength.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GridLength.h; sourceTree = "<group>"; };
                                501BAAA813950E2C00F7ACEB /* WindRule.h */,
                                379919941200DDF400EA041C /* WOFFFileFormat.cpp */,
                                379919951200DDF400EA041C /* WOFFFileFormat.h */,
+                               CD525BA11EE0B10700788DF5 /* FourCC.cpp */,
+                               CD525BA21EE0B10700788DF5 /* FourCC.h */,
                        );
                        path = graphics;
                        sourceTree = "<group>";
                                CD8B5A40180D149A008B8E65 /* VideoTrackPrivateMediaSourceAVFObjC.mm */,
                                CD7E05201651A84100C1201F /* WebCoreAVFResourceLoader.h */,
                                CD7E05211651A84100C1201F /* WebCoreAVFResourceLoader.mm */,
+                               CDECA8981EDF447D00DCB08B /* AVAssetTrackUtilities.mm */,
+                               CDECA8991EDF447D00DCB08B /* AVAssetTrackUtilities.h */,
                        );
                        path = objc;
                        sourceTree = "<group>";
                                AA7FEEA716A4E6F3004C0C33 /* JSSpeechSynthesisUtterance.h in Headers */,
                                AA7FEEA916A4E6F3004C0C33 /* JSSpeechSynthesisVoice.h in Headers */,
                                BC8243290D0CE8A200460C8F /* JSSQLError.h in Headers */,
+                               CDECA89B1EDF447D00DCB08B /* AVAssetTrackUtilities.h in Headers */,
                                B525A96511CA2340003A23A8 /* JSSQLException.h in Headers */,
                                1AE82FED0CAB07EE002237AE /* JSSQLResultSet.h in Headers */,
                                1AFE119A0CBFFCC4003017FA /* JSSQLResultSetRowList.h in Headers */,
                                0FB8890A167D2FA10010CDA5 /* ScrollingTreeStickyNode.h in Headers */,
                                7AAFE8D019CB8672000F56D8 /* ScrollLatchingState.h in Headers */,
                                F478755419983AFF0024A287 /* ScrollSnapAnimatorState.h in Headers */,
+                               CD525BA41EE0B10700788DF5 /* FourCC.h in Headers */,
                                F46729281E0DE68500ACC3D8 /* ScrollSnapOffsetsInfo.h in Headers */,
                                83C5795D1DA5C301006FACA8 /* ScrollToOptions.h in Headers */,
                                93C09C860B0657AA005ABD4D /* ScrollTypes.h in Headers */,
                                A8C4A80809D563270003AC8D /* Element.cpp in Sources */,
                                B5B7A17017C10AA800E4AA0A /* ElementData.cpp in Sources */,
                                4FFC022D1643B726004E1638 /* ElementRareData.cpp in Sources */,
+                               CD525BA31EE0B10700788DF5 /* FourCC.cpp in Sources */,
                                FBDB619B16D6032A00BB3394 /* ElementRuleCollector.cpp in Sources */,
                                A8CFF6CB0A1561CD000A4234 /* EllipsisBox.cpp in Sources */,
                                F55B3DBB1251F12D003EF269 /* EmailInputType.cpp in Sources */,
                                931CBD0C161A44E900E4C874 /* ScrollingStateNode.cpp in Sources */,
                                93EF7D551954F13900DFB71D /* ScrollingStateNode.mm in Sources */,
                                0FEA3E83191B31BF000F1B55 /* ScrollingStateOverflowScrollingNode.cpp in Sources */,
+                               CDECA89A1EDF447D00DCB08B /* AVAssetTrackUtilities.mm in Sources */,
                                931CBD0E161A44E900E4C874 /* ScrollingStateScrollingNode.cpp in Sources */,
                                0FB8890E167D30160010CDA5 /* ScrollingStateStickyNode.cpp in Sources */,
                                931CBD10161A44E900E4C874 /* ScrollingStateTree.cpp in Sources */,
index ca2b929..4bdef62 100644 (file)
@@ -4291,6 +4291,8 @@ URL HTMLMediaElement::selectNextSourceChild(ContentType* contentType, String* ke
 #if ENABLE(MEDIA_STREAM)
             parameters.isMediaStream = mediaURL.protocolIs(mediaStreamBlobProtocol);
 #endif
+            parameters.contentTypesRequiringHardwareSupport = mediaContentTypesRequiringHardwareSupport();
+
             if (!MediaPlayer::supportsType(parameters, this))
                 goto CheckAgain;
         }
@@ -6628,6 +6630,11 @@ double HTMLMediaElement::mediaPlayerRequestedPlaybackRate() const
     return potentiallyPlaying() ? requestedPlaybackRate() : 0;
 }
 
+const Vector<ContentType>& HTMLMediaElement::mediaContentTypesRequiringHardwareSupport() const
+{
+    return document().settings().mediaContentTypesRequiringHardwareSupport();
+}
+
 #if USE(GSTREAMER)
 void HTMLMediaElement::requestInstallMissingPlugins(const String& details, const String& description, MediaPlayerRequestInstallMissingPluginsCallback& callback)
 {
index adf9d27..b362b62 100644 (file)
@@ -679,6 +679,7 @@ private:
     double mediaPlayerRequestedPlaybackRate() const final;
     VideoFullscreenMode mediaPlayerFullscreenMode() const final { return fullscreenMode(); }
     bool mediaPlayerShouldDisableSleep() const final { return shouldDisableSleep() == SleepType::Display; }
+    const Vector<ContentType>& mediaContentTypesRequiringHardwareSupport() const final;
 
 #if USE(GSTREAMER)
     void requestInstallMissingPlugins(const String& details, const String& description, MediaPlayerRequestInstallMissingPluginsCallback&) final;
index 3b41344..f61dad6 100644 (file)
@@ -789,4 +789,15 @@ bool Settings::allowsAnySSLCertificate()
     return gAllowsAnySSLCertificate;
 }
 
+void Settings::setMediaContentTypesRequiringHardwareSupport(const String& contentTypes)
+{
+    m_mediaContentTypesRequiringHardwareSupport = contentTypes.split(":").map(ContentType::create);
+}
+
+void Settings::setMediaContentTypesRequiringHardwareSupport(const Vector<ContentType>& contentTypes)
+{
+    m_mediaContentTypesRequiringHardwareSupport = contentTypes;
+}
+
+
 } // namespace WebCore
index d95b6ae..91183e8 100644 (file)
@@ -27,6 +27,7 @@
 #pragma once
 
 #include "ClipboardAccessPolicy.h"
+#include "ContentType.h"
 #include "EditingBehaviorTypes.h"
 #include "IntSize.h"
 #include "SecurityOrigin.h"
@@ -325,6 +326,10 @@ public:
     WEBCORE_EXPORT static void setAllowsAnySSLCertificate(bool);
     static bool allowsAnySSLCertificate();
 
+    WEBCORE_EXPORT void setMediaContentTypesRequiringHardwareSupport(const Vector<ContentType>&);
+    WEBCORE_EXPORT void setMediaContentTypesRequiringHardwareSupport(const String&);
+    const Vector<ContentType>& mediaContentTypesRequiringHardwareSupport() const { return m_mediaContentTypesRequiringHardwareSupport; }
+
 private:
     explicit Settings(Page*);
 
@@ -424,6 +429,8 @@ private:
     static bool gLowPowerVideoAudioBufferSizeEnabled;
     static bool gResourceLoadStatisticsEnabledEnabled;
     static bool gAllowsAnySSLCertificate;
+
+    Vector<ContentType> m_mediaContentTypesRequiringHardwareSupport;
 };
 
 inline bool Settings::isPostLoadCPUUsageMeasurementEnabled()
index d8d7a05..f31ac50 100644 (file)
 
 namespace WebCore {
 
-    class ContentType {
-    public:
-        explicit ContentType(const String& type);
-        ContentType() = default;
+class ContentType {
+public:
+    static ContentType create(const String& type) { return ContentType(type); }
+    explicit ContentType(const String& type);
+    ContentType() = default;
 
-        String parameter(const String& parameterName) const;
-        String type() const;
-        Vector<String> codecs() const;
-        const String& raw() const { return m_type; }
-    private:
-        String m_type;
-    };
+    String parameter(const String& parameterName) const;
+    String type() const;
+    Vector<String> codecs() const;
+    const String& raw() const { return m_type; }
+    bool isEmpty() const { return m_type.isEmpty(); }
+private:
+    String m_type;
+};
 
 } // namespace WebCore
 
index 2c2b68d..d9fc049 100644 (file)
@@ -38,5 +38,6 @@ SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, VideoToolbox, VTDecompressionSessionWaitF
 #define VTDecompressionSessionWaitForAsynchronousFrames softLink_VideoToolbox_VTDecompressionSessionWaitForAsynchronousFrames
 SOFT_LINK_FUNCTION_FOR_SOURCE(WebCore, VideoToolbox, VTDecompressionSessionDecodeFrame, OSStatus, (VTDecompressionSessionRef session, CMSampleBufferRef sampleBuffer, VTDecodeFrameFlags decodeFlags, void* sourceFrameRefCon, VTDecodeInfoFlags* infoFlagsOut), (session, sampleBuffer, decodeFlags, sourceFrameRefCon, infoFlagsOut))
 #define VTDecompressionSessionDecodeFrame softLink_VideoToolbox_VTDecompressionSessionDecodeFrame
+SOFT_LINK_FUNCTION_MAY_FAIL_FOR_SOURCE(WebCore, VideoToolbox, VTIsHardwareDecodeSupported, Boolean, (CMVideoCodecType codecType), (codecType))
 SOFT_LINK_CONSTANT_FOR_SOURCE(WebCore, VideoToolbox, kVTVideoDecoderSpecification_EnableHardwareAcceleratedVideoDecoder, CFStringRef)
 #define kVTVideoDecoderSpecification_EnableHardwareAcceleratedVideoDecoder get_VideoToolbox_kVTVideoDecoderSpecification_EnableHardwareAcceleratedVideoDecoder()
index fb0098e..cc75383 100644 (file)
@@ -38,5 +38,7 @@ SOFT_LINK_FUNCTION_FOR_HEADER(WebCore, VideoToolbox, VTDecompressionSessionWaitF
 #define VTDecompressionSessionWaitForAsynchronousFrames softLink_VideoToolbox_VTDecompressionSessionWaitForAsynchronousFrames
 SOFT_LINK_FUNCTION_FOR_HEADER(WebCore, VideoToolbox, VTDecompressionSessionDecodeFrame, OSStatus, (VTDecompressionSessionRef session, CMSampleBufferRef sampleBuffer, VTDecodeFrameFlags decodeFlags, void* sourceFrameRefCon, VTDecodeInfoFlags* infoFlagsOut), (session, sampleBuffer, decodeFlags, sourceFrameRefCon, infoFlagsOut))
 #define VTDecompressionSessionDecodeFrame softLink_VideoToolbox_VTDecompressionSessionDecodeFrame
+SOFT_LINK_FUNCTION_MAY_FAIL_FOR_HEADER(WebCore, VideoToolbox, VTIsHardwareDecodeSupported, Boolean, (CMVideoCodecType codecType), (codecType))
+#define VTIsHardwareDecodeSupported softLink_VideoToolbox_VTIsHardwareDecodeSupported
 SOFT_LINK_CONSTANT_FOR_HEADER(WebCore, VideoToolbox, kVTVideoDecoderSpecification_EnableHardwareAcceleratedVideoDecoder, CFStringRef)
 #define kVTVideoDecoderSpecification_EnableHardwareAcceleratedVideoDecoder get_VideoToolbox_kVTVideoDecoderSpecification_EnableHardwareAcceleratedVideoDecoder()
diff --git a/Source/WebCore/platform/graphics/FourCC.cpp b/Source/WebCore/platform/graphics/FourCC.cpp
new file mode 100644 (file)
index 0000000..60ce2e2
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "FourCC.h"
+
+namespace WebCore {
+
+std::optional<FourCC> FourCC::fromString(const String& stringValue)
+{
+    auto asciiValue = stringValue.ascii();
+    if (asciiValue.length() != 4)
+        return std::nullopt;
+
+    const char* data = asciiValue.data();
+    ASSERT(asciiValue.data());
+    uint32_t value = data[3] << 24 | data[2] << 16 | data[1] << 8 | data[0];
+    return FourCC(value);
+}
+
+String FourCC::toString() const
+{
+    Vector<LChar, 4> data = {
+        LChar(value >> 24),
+        LChar((value >> 16) & 0xFF),
+        LChar((value >> 8) & 0xFF),
+        LChar(value & 0xFF),
+    };
+
+    return String::adopt(WTFMove(data));
+}
+
+}
diff --git a/Source/WebCore/platform/graphics/FourCC.h b/Source/WebCore/platform/graphics/FourCC.h
new file mode 100644 (file)
index 0000000..b137a8c
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+struct FourCC {
+    WEBCORE_EXPORT FourCC(uint32_t value) : value(value) { }
+
+    String toString() const;
+    WEBCORE_EXPORT static std::optional<FourCC> fromString(const String&);
+
+    bool operator==(const FourCC& other) const { return value == other.value; }
+
+    uint32_t value;
+};
+
+}
index a88ad5f..da09bba 100644 (file)
@@ -161,6 +161,12 @@ public:
     bool hasSingleSecurityOrigin() const override { return true; }
 };
 
+const Vector<ContentType>& MediaPlayerClient::mediaContentTypesRequiringHardwareSupport() const
+{
+    static NeverDestroyed<Vector<ContentType>> contentTypes;
+    return contentTypes;
+}
+
 static MediaPlayerClient& nullMediaPlayerClient()
 {
     static NeverDestroyed<MediaPlayerClient> client;
@@ -1464,6 +1470,11 @@ bool MediaPlayer::shouldDisableSleep() const
     return client().mediaPlayerShouldDisableSleep();
 }
 
+const Vector<ContentType>& MediaPlayer::mediaContentTypesRequiringHardwareSupport() const
+{
+    return client().mediaContentTypesRequiringHardwareSupport();
+}
+
 }
 
 #endif
index 965b7fa..21af4ff 100644 (file)
@@ -30,6 +30,7 @@
 #include "GraphicsTypes3D.h"
 
 #include "AudioTrackPrivate.h"
+#include "ContentType.h"
 #include "LegacyCDMSession.h"
 #include "InbandTextTrackPrivate.h"
 #include "IntRect.h"
@@ -114,6 +115,7 @@ struct MediaEngineSupportParameters {
     URL url;
     bool isMediaSource { false };
     bool isMediaStream { false };
+    Vector<ContentType> contentTypesRequiringHardwareSupport;
 };
 
 extern const PlatformMedia NoPlatformMedia;
@@ -273,6 +275,7 @@ public:
 #endif
 
     virtual bool mediaPlayerShouldDisableSleep() const { return false; }
+    virtual const Vector<ContentType>& mediaContentTypesRequiringHardwareSupport() const;
 };
 
 class MediaPlayerSupportsTypeClient {
@@ -587,6 +590,8 @@ public:
     const String& contentTypeCodecs() const { return m_contentTypeCodecs; }
     bool contentMIMETypeWasInferredFromExtension() const { return m_contentMIMETypeWasInferredFromExtension; }
 
+    const Vector<ContentType>& mediaContentTypesRequiringHardwareSupport() const;
+
 private:
     MediaPlayer(MediaPlayerClient&);
 
index 7767c14..0ad298b 100644 (file)
@@ -296,6 +296,7 @@ protected:
     const String& assetURL() const { return m_assetURL; }
 
     MediaPlayer* player() { return m_player; }
+    const MediaPlayer* player() const { return m_player; }
 
     String engineDescription() const override { return "AVFoundation"; }
     long platformErrorCode() const override { return assetErrorCode(); }
diff --git a/Source/WebCore/platform/graphics/avfoundation/objc/AVAssetTrackUtilities.h b/Source/WebCore/platform/graphics/avfoundation/objc/AVAssetTrackUtilities.h
new file mode 100644 (file)
index 0000000..2b576ce
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if ENABLE(VIDEO) && USE(AVFOUNDATION)
+
+#include "ContentType.h"
+#include <wtf/Vector.h>
+
+OBJC_CLASS AVAssetTrack;
+
+namespace WebCore {
+
+bool assetTrackMeetsHardwareDecodeRequirements(AVAssetTrack *, const Vector<ContentType>& contentTypesRequiringHardwareDecode);
+
+}
+
+#endif
diff --git a/Source/WebCore/platform/graphics/avfoundation/objc/AVAssetTrackUtilities.mm b/Source/WebCore/platform/graphics/avfoundation/objc/AVAssetTrackUtilities.mm
new file mode 100644 (file)
index 0000000..1bbbd0f
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "config.h"
+#import "AVAssetTrackUtilities.h"
+
+#if ENABLE(VIDEO) && USE(AVFOUNDATION)
+
+#import "FourCC.h"
+#import <AVFoundation/AVAssetTrack.h>
+
+#import "CoreMediaSoftLink.h"
+#import "VideoToolboxSoftLink.h"
+
+namespace WebCore {
+
+bool assetTrackMeetsHardwareDecodeRequirements(AVAssetTrack *track, const Vector<ContentType>& contentTypesRequiringHardwareDecode)
+{
+    // If we can't determine whether a codec has hardware support or not, default to true.
+    if (!canLoad_VideoToolbox_VTIsHardwareDecodeSupported())
+        return true;
+
+    if (contentTypesRequiringHardwareDecode.isEmpty())
+        return true;
+
+    Vector<FourCC> hardwareCodecs;
+    for (auto& contentType : contentTypesRequiringHardwareDecode) {
+        auto codecStrings = contentType.codecs();
+        for (auto& codecString : codecStrings) {
+            auto codecIdentifier = FourCC::fromString(codecString);
+            if (codecIdentifier)
+                hardwareCodecs.append(codecIdentifier.value());
+        }
+    }
+
+    for (NSUInteger i = 0, count = track.formatDescriptions.count; i < count; ++i) {
+        CMFormatDescriptionRef description = (CMFormatDescriptionRef)track.formatDescriptions[i];
+        if (CMFormatDescriptionGetMediaType(description) != kCMMediaType_Video)
+            continue;
+
+        CMVideoCodecType codec = CMFormatDescriptionGetMediaSubType(description);
+        if (!hardwareCodecs.contains(FourCC(codec)))
+            continue;
+
+        if (!VTIsHardwareDecodeSupported(codec))
+            return false;
+    }
+    return true;
+}
+
+}
+
+#endif
index 38c9270..ab15f64 100644 (file)
@@ -424,6 +424,7 @@ private:
     bool m_cachedCanPlayFastForward;
     bool m_cachedCanPlayFastReverse;
     bool m_muted { false };
+    mutable std::optional<bool> m_tracksArePlayable;
 #if ENABLE(WIRELESS_PLAYBACK_TARGET)
     mutable bool m_allowsWirelessVideoPlayback;
     bool m_shouldPlayToPlaybackTarget { false };
index d07a124..923fdb9 100644 (file)
@@ -28,6 +28,7 @@
 
 #if ENABLE(VIDEO) && USE(AVFOUNDATION)
 
+#import "AVAssetTrackUtilities.h"
 #import "AVFoundationMIMETypeCache.h"
 #import "AVFoundationSPI.h"
 #import "AVTrackPrivateAVFObjCImpl.h"
@@ -1146,7 +1147,7 @@ void MediaPlayerPrivateAVFoundationObjC::checkPlayability()
     LOG(Media, "MediaPlayerPrivateAVFoundationObjC::checkPlayability(%p)", this);
     auto weakThis = createWeakPtr();
 
-    [m_avAsset.get() loadValuesAsynchronouslyForKeys:[NSArray arrayWithObject:@"playable"] completionHandler:^{
+    [m_avAsset.get() loadValuesAsynchronouslyForKeys:[NSArray arrayWithObjects:@"playable", @"tracks", nil] completionHandler:^{
         callOnMainThread([weakThis] {
             if (weakThis)
                 weakThis->scheduleMainThreadNotification(MediaPlayerPrivateAVFoundation::Notification::AssetPlayabilityKnown);
@@ -1589,7 +1590,17 @@ MediaPlayerPrivateAVFoundation::AssetStatus MediaPlayerPrivateAVFoundationObjC::
             return MediaPlayerAVAssetStatusCancelled; // Loading of at least one key was cancelled.
     }
 
-    if ([[m_avAsset.get() valueForKey:@"playable"] boolValue])
+    if (!m_tracksArePlayable) {
+        m_tracksArePlayable = true;
+        for (AVAssetTrack *track in [m_avAsset tracks]) {
+            if (!assetTrackMeetsHardwareDecodeRequirements(track, player()->mediaContentTypesRequiringHardwareSupport())) {
+                m_tracksArePlayable = false;
+                break;
+            }
+        }
+    }
+
+    if ([[m_avAsset.get() valueForKey:@"playable"] boolValue] && m_tracksArePlayable.value())
         return MediaPlayerAVAssetStatusPlayable;
 
     return MediaPlayerAVAssetStatusLoaded;
index 38fef0a..7c9f2f7 100644 (file)
@@ -117,6 +117,8 @@ public:
     void keyNeeded(Uint8Array*);
 #endif
 
+    const Vector<ContentType>& mediaContentTypesRequiringHardwareSupport() const;
+
     WeakPtr<MediaPlayerPrivateMediaSourceAVFObjC> createWeakPtr() { return m_weakPtrFactory.createWeakPtr(); }
 
 private:
index 2fe8ddd..4315243 100644 (file)
@@ -948,6 +948,11 @@ void MediaPlayerPrivateMediaSourceAVFObjC::keyNeeded(Uint8Array* initData)
 }
 #endif
 
+const Vector<ContentType>& MediaPlayerPrivateMediaSourceAVFObjC::mediaContentTypesRequiringHardwareSupport() const
+{
+    return m_player->mediaContentTypesRequiringHardwareSupport();
+}
+
 void MediaPlayerPrivateMediaSourceAVFObjC::setReadyState(MediaPlayer::ReadyState readyState)
 {
     if (m_readyState == readyState)
index 55d26f6..1bdd987 100644 (file)
@@ -28,6 +28,7 @@
 
 #if ENABLE(MEDIA_SOURCE) && USE(AVFOUNDATION)
 
+#import "AVAssetTrackUtilities.h"
 #import "AVFoundationSPI.h"
 #import "AudioTrackPrivateMediaSourceAVFObjC.h"
 #import "CDMSessionAVContentKeySession.h"
@@ -431,6 +432,16 @@ void SourceBufferPrivateAVFObjC::didParseStreamDataAsAsset(AVAsset* asset)
 {
     LOG(MediaSource, "SourceBufferPrivateAVFObjC::didParseStreamDataAsAsset(%p)", this);
 
+    if (!m_mediaSource)
+        return;
+
+    for (AVAssetTrack *track in [asset tracks]) {
+        if (!assetTrackMeetsHardwareDecodeRequirements(track, m_mediaSource->player()->mediaContentTypesRequiringHardwareSupport())) {
+            m_parsingSucceeded = false;
+            return;
+        }
+    }
+
     m_asset = asset;
 
     m_videoTracks.clear();
index 2d6ec8f..e7e8f77 100644 (file)
@@ -1,3 +1,28 @@
+2017-06-05  Jer Noble  <jer.noble@apple.com>
+
+        Allow clients to specify a list of codecs which should require hardware decode support.
+        https://bugs.webkit.org/show_bug.cgi?id=172787
+
+        Reviewed by Alex Christensen.
+
+        Add a WKWebPageConfiguration (and associated WebPreferences and WKPreferencesRef) properties
+        allowing clients to require specified codecs have hardware decode support. Also open up the
+        sandbox on Cocoa ports to services required to check for hardware decode availability.
+
+        * Shared/WebPreferencesDefinitions.h:
+        * UIProcess/API/C/WKPreferences.cpp:
+        (WKPreferencesSetMediaCodecsRequiringHardwareSupport):
+        (WKPreferencesCopyMediaCodecsRequiringHardwareSupport):
+        * UIProcess/API/C/WKPreferencesRefPrivate.h:
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView _initializeWithConfiguration:]):
+        * UIProcess/API/Cocoa/WKWebViewConfiguration.mm:
+        (-[WKWebViewConfiguration copyWithZone:]):
+        (-[WKWebViewConfiguration _mediaCodecsRequiringHardwareSupport]):
+        (-[WKWebViewConfiguration _setMediaCodecsRequiringHardwareSupport:]):
+        * UIProcess/API/Cocoa/WKWebViewConfigurationPrivate.h:
+        * WebProcess/com.apple.WebProcess.sb.in:
+
 2017-06-05  Beth Dakin  <bdakin@apple.com>
 
         Modify Netflix controlsManager quirk to prevent only scrubbing
index 2e4d4e7..1eda2e4 100644 (file)
     FOR_EACH_WEBKIT_FONT_FAMILY_PREFERENCE(macro) \
     macro(DefaultTextEncodingName, defaultTextEncodingName, String, String, defaultTextEncodingNameForSystemLanguage(), "", "") \
     macro(FTPDirectoryTemplatePath, ftpDirectoryTemplatePath, String, String, "", "", "") \
+    macro(MediaContentTypesRequiringHardwareSupport, mediaContentTypesRequiringHardwareSupport, String, String, "", "", "") \
     \
 
 #define FOR_EACH_WEBKIT_STRING_PREFERENCE_NOT_IN_WEBCORE(macro) \
index ae19715..8d97aca 100644 (file)
@@ -1770,3 +1770,14 @@ bool WKPreferencesGetMediaUserGestureInheritsFromDocument(WKPreferencesRef prefe
 {
     return toImpl(preferencesRef)->mediaUserGestureInheritsFromDocument();
 }
+
+void WKPreferencesSetMediaContentTypesRequiringHardwareSupport(WKPreferencesRef preferencesRef, WKStringRef codecs)
+{
+    toImpl(preferencesRef)->setMediaContentTypesRequiringHardwareSupport(toWTFString(codecs));
+}
+
+WKStringRef WKPreferencesCopyMediaContentTypesRequiringHardwareSupport(WKPreferencesRef preferencesRef)
+{
+    return toCopiedAPI(toImpl(preferencesRef)->mediaContentTypesRequiringHardwareSupport());
+}
+
index efda825..486babc 100644 (file)
@@ -497,6 +497,10 @@ WK_EXPORT bool WKPreferencesGetInvisibleMediaAutoplayPermitted(WKPreferencesRef)
 WK_EXPORT void WKPreferencesSetMediaUserGestureInheritsFromDocument(WKPreferencesRef, bool flag);
 WK_EXPORT bool WKPreferencesGetMediaUserGestureInheritsFromDocument(WKPreferencesRef);
 
+// Defaults to an empty string
+WK_EXPORT void WKPreferencesSetMediaContentTypesRequiringHardwareSupport(WKPreferencesRef, WKStringRef);
+WK_EXPORT WKStringRef WKPreferencesCopyMediaContentTypesRequiringHardwareSupport(WKPreferencesRef);
+
 #ifdef __cplusplus
 }
 #endif
index 1923af4..649f03c 100644 (file)
@@ -504,6 +504,8 @@ static uint32_t convertSystemLayoutDirection(NSUserInterfaceLayoutDirection dire
 
     pageConfiguration->preferenceValues().set(WebKit::WebPreferencesKey::needsStorageAccessFromFileURLsQuirkKey(), WebKit::WebPreferencesStore::Value(!![_configuration _needsStorageAccessFromFileURLsQuirk]));
 
+    pageConfiguration->preferenceValues().set(WebKit::WebPreferencesKey::mediaContentTypesRequiringHardwareSupportKey(), WebKit::WebPreferencesStore::Value([_configuration _mediaContentTypesRequiringHardwareSupport]));
+
 #if PLATFORM(IOS)
     CGRect bounds = self.bounds;
     _scrollView = adoptNS([[WKScrollView alloc] initWithFrame:bounds]);
index b4bf3a9..4030d53 100644 (file)
@@ -137,6 +137,7 @@ private:
     BOOL _needsStorageAccessFromFileURLsQuirk;
 
     NSString *_overrideContentSecurityPolicy;
+    NSString *_mediaContentTypesRequiringHardwareSupport;
 }
 
 - (instancetype)init
@@ -330,6 +331,7 @@ private:
     configuration->_overrideContentSecurityPolicy = self->_overrideContentSecurityPolicy;
 
     configuration->_urlSchemeHandlers.set(adoptNS([self._urlSchemeHandlers mutableCopyWithZone:zone]));
+    configuration->_mediaContentTypesRequiringHardwareSupport = self._mediaContentTypesRequiringHardwareSupport;
 
     return configuration;
 }
@@ -816,6 +818,16 @@ static NSString *defaultApplicationNameForUserAgent()
     _overrideContentSecurityPolicy = overrideContentSecurityPolicy;
 }
 
+- (NSString *)_mediaContentTypesRequiringHardwareSupport
+{
+    return _mediaContentTypesRequiringHardwareSupport;
+}
+
+- (void)_setMediaContentTypesRequiringHardwareSupport:(NSString *)mediaContentTypesRequiringHardwareSupport
+{
+    _mediaContentTypesRequiringHardwareSupport = mediaContentTypesRequiringHardwareSupport;
+}
+
 @end
 
 @implementation WKWebViewConfiguration (WKDeprecated)
index 951bfdc..8c632c0 100644 (file)
@@ -76,6 +76,7 @@
 @property (nonatomic, setter=_setRequiresUserActionForVideoPlayback:) BOOL _requiresUserActionForVideoPlayback WK_API_DEPRECATED_WITH_REPLACEMENT("mediaTypesRequiringUserActionForPlayback", macosx(10.12, 10.12), ios(10.0, 10.0));
 
 @property (nonatomic, setter=_setOverrideContentSecurityPolicy:) NSString *_overrideContentSecurityPolicy WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
+@property (nonatomic, setter=_setMediaContentTypesRequiringHardwareSupport:) NSString *_mediaContentTypesRequiringHardwareSupport WK_API_AVAILABLE(macosx(WK_MAC_TBA), ios(WK_IOS_TBA));
 
 @end
 
index 2434c6e..11ab2d2 100644 (file)
@@ -89,7 +89,9 @@
     (iokit-property "IOGeneralInterest")
     (iokit-property "IOGLBundleName")
     (iokit-property "IOI2CTransactionTypes")
+    (iokit-property "IOGVAVTCapabilities")
     (iokit-property-regex #"^IOGVA(Codec|EncoderRestricted)")
+    (iokit-property-regex #"^IOGVA(.*)Decode$")
     (iokit-property "IOMatchCategory")
     (iokit-property-regex #"^IONameMatch(|ed)")
     (iokit-property "IOPMStrictTreeOrder")