Title: [217933] trunk/Source/WebCore
Revision
217933
Author
[email protected]
Date
2017-06-08 10:23:53 -0700 (Thu, 08 Jun 2017)

Log Message

Take the mediaContentTypesRequiringHardwareSupport Setting into account when answering HTMLMediaElement::canPlayType()
https://bugs.webkit.org/show_bug.cgi?id=173092

Reviewed by Eric Carlson.

Pass the value of mediaContentTypesRequiringHardwareSupport into the MediaPlayer when querying canPlayType().
Then, use the existing code in AVAssetTrackUtilities to know whether to bail out early from the codec check.

Drive-by fix: FourCC was converting String -> FourCC in reverse.

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::canPlayType):
* platform/graphics/FourCC.cpp:
(WebCore::FourCC::fromString):
* platform/graphics/avfoundation/objc/AVAssetTrackUtilities.h:
* platform/graphics/avfoundation/objc/AVAssetTrackUtilities.mm:
(WebCore::contentTypesToCodecs):
(WebCore::codecsMeetHardwareDecodeRequirements):
(WebCore::contentTypeMeetsHardwareDecodeRequirements):
(WebCore::assetTrackMeetsHardwareDecodeRequirements):
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::supportsType):
* platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm:
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::supportsType):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (217932 => 217933)


--- trunk/Source/WebCore/ChangeLog	2017-06-08 17:13:16 UTC (rev 217932)
+++ trunk/Source/WebCore/ChangeLog	2017-06-08 17:23:53 UTC (rev 217933)
@@ -1,3 +1,30 @@
+2017-06-08  Jer Noble  <[email protected]>
+
+        Take the mediaContentTypesRequiringHardwareSupport Setting into account when answering HTMLMediaElement::canPlayType()
+        https://bugs.webkit.org/show_bug.cgi?id=173092
+
+        Reviewed by Eric Carlson.
+
+        Pass the value of mediaContentTypesRequiringHardwareSupport into the MediaPlayer when querying canPlayType().
+        Then, use the existing code in AVAssetTrackUtilities to know whether to bail out early from the codec check.
+
+        Drive-by fix: FourCC was converting String -> FourCC in reverse.
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::canPlayType):
+        * platform/graphics/FourCC.cpp:
+        (WebCore::FourCC::fromString):
+        * platform/graphics/avfoundation/objc/AVAssetTrackUtilities.h:
+        * platform/graphics/avfoundation/objc/AVAssetTrackUtilities.mm:
+        (WebCore::contentTypesToCodecs):
+        (WebCore::codecsMeetHardwareDecodeRequirements):
+        (WebCore::contentTypeMeetsHardwareDecodeRequirements):
+        (WebCore::assetTrackMeetsHardwareDecodeRequirements):
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::supportsType):
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm:
+        (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::supportsType):
+
 2017-06-08  Chris Dumez  <[email protected]>
 
         ASSERTION FAILED: !m_isolatedWorld->isNormal() || m_wrapper || !m_jsFunction on webrtc/ephemeral-certificates-and-cnames.html

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (217932 => 217933)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2017-06-08 17:13:16 UTC (rev 217932)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2017-06-08 17:23:53 UTC (rev 217933)
@@ -1109,6 +1109,7 @@
     MediaEngineSupportParameters parameters;
     ContentType contentType(mimeType);
     parameters.type = contentType;
+    parameters.contentTypesRequiringHardwareSupport = mediaContentTypesRequiringHardwareSupport();
     MediaPlayer::SupportsType support = MediaPlayer::supportsType(parameters, this);
     String canPlay;
 

Modified: trunk/Source/WebCore/platform/graphics/FourCC.cpp (217932 => 217933)


--- trunk/Source/WebCore/platform/graphics/FourCC.cpp	2017-06-08 17:13:16 UTC (rev 217932)
+++ trunk/Source/WebCore/platform/graphics/FourCC.cpp	2017-06-08 17:23:53 UTC (rev 217933)
@@ -36,7 +36,7 @@
 
     const char* data = ""
     ASSERT(asciiValue.data());
-    uint32_t value = data[3] << 24 | data[2] << 16 | data[1] << 8 | data[0];
+    uint32_t value = data[0] << 24 | data[1] << 16 | data[2] << 8 | data[3];
     return FourCC(value);
 }
 

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/AVAssetTrackUtilities.h (217932 => 217933)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/AVAssetTrackUtilities.h	2017-06-08 17:13:16 UTC (rev 217932)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/AVAssetTrackUtilities.h	2017-06-08 17:23:53 UTC (rev 217933)
@@ -34,6 +34,10 @@
 
 namespace WebCore {
 
+struct FourCC;
+
+bool codecsMeetHardwareDecodeRequirements(const Vector<FourCC>&, const Vector<ContentType>& contentTypesRequiringHardwareDecode);
+bool contentTypeMeetsHardwareDecodeRequirements(const ContentType&, const Vector<ContentType>& contentTypesRequiringHardwareDecode);
 bool assetTrackMeetsHardwareDecodeRequirements(AVAssetTrack *, const Vector<ContentType>& contentTypesRequiringHardwareDecode);
 
 }

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/AVAssetTrackUtilities.mm (217932 => 217933)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/AVAssetTrackUtilities.mm	2017-06-08 17:13:16 UTC (rev 217932)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/AVAssetTrackUtilities.mm	2017-06-08 17:23:53 UTC (rev 217933)
@@ -54,8 +54,28 @@
     return false;
 }
 
-bool assetTrackMeetsHardwareDecodeRequirements(AVAssetTrack *track, const Vector<ContentType>& contentTypesRequiringHardwareDecode)
+static Vector<FourCC> contentTypesToCodecs(const Vector<ContentType>& contentTypes)
 {
+    Vector<FourCC> codecs;
+    for (auto& contentType : contentTypes) {
+        auto codecStrings = contentType.codecs();
+        for (auto& codecString : codecStrings) {
+            // https://tools.ietf.org/html/rfc6381
+            // Within a 'codecs' parameter value, "." is reserved as a hierarchy delimiter
+            auto firstPeriod = codecString.find('.');
+            if (firstPeriod != notFound)
+                codecString.truncate(firstPeriod);
+
+            auto codecIdentifier = FourCC::fromString(codecString.left(4));
+            if (codecIdentifier)
+                codecs.append(codecIdentifier.value());
+        }
+    }
+    return codecs;
+}
+
+bool codecsMeetHardwareDecodeRequirements(const Vector<FourCC>& codecs, const Vector<ContentType>& contentTypesRequiringHardwareDecode)
+{
     static bool hasBattery = systemHasBattery();
 
     // If the system is exclusively wall-powered, do not require hardware support.
@@ -69,31 +89,33 @@
     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());
-        }
+    Vector<FourCC> hardwareCodecs = contentTypesToCodecs(contentTypesRequiringHardwareDecode);
+
+    for (auto& codec : codecs) {
+        if (hardwareCodecs.contains(codec) && !VTIsHardwareDecodeSupported(codec.value))
+            return false;
     }
+    return true;
+}
 
+bool contentTypeMeetsHardwareDecodeRequirements(const ContentType& contentType, const Vector<ContentType>& contentTypesRequiringHardwareDecode)
+{
+    Vector<FourCC> codecs = contentTypesToCodecs({ contentType });
+    return codecsMeetHardwareDecodeRequirements(codecs, contentTypesRequiringHardwareDecode);
+}
+
+bool assetTrackMeetsHardwareDecodeRequirements(AVAssetTrack *track, const Vector<ContentType>& contentTypesRequiringHardwareDecode)
+{
+    Vector<FourCC> codecs;
     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;
+        if (CMFormatDescriptionGetMediaType(description) == kCMMediaType_Video)
+            codecs.append(FourCC(CMFormatDescriptionGetMediaSubType(description)));
     }
-    return true;
+    return codecsMeetHardwareDecodeRequirements(codecs, contentTypesRequiringHardwareDecode);
 }
 
+
 }
 
 #endif

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm (217932 => 217933)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm	2017-06-08 17:13:16 UTC (rev 217932)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm	2017-06-08 17:23:53 UTC (rev 217933)
@@ -1728,6 +1728,9 @@
     if (parameters.type.codecs().isEmpty())
         return MediaPlayer::MayBeSupported;
 
+    if (!contentTypeMeetsHardwareDecodeRequirements(parameters.type, parameters.contentTypesRequiringHardwareSupport))
+        return MediaPlayer::IsNotSupported;
+
     NSString *typeString = [NSString stringWithFormat:@"%@; codecs=\"%@\"", (NSString *)containerType, (NSString *)parameters.type.parameter(ContentType::codecsParameter())];
     return [AVURLAsset isPlayableExtendedMIMEType:typeString] ? MediaPlayer::IsSupported : MediaPlayer::MayBeSupported;
 }

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm (217932 => 217933)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm	2017-06-08 17:13:16 UTC (rev 217932)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm	2017-06-08 17:23:53 UTC (rev 217933)
@@ -28,6 +28,7 @@
 
 #if ENABLE(MEDIA_SOURCE) && USE(AVFOUNDATION)
 
+#import "AVAssetTrackUtilities.h"
 #import "AVFoundationMIMETypeCache.h"
 #import "AVFoundationSPI.h"
 #import "CDMSessionAVStreamSession.h"
@@ -227,6 +228,9 @@
     if ([getAVStreamDataParserClass() respondsToSelector:@selector(outputMIMECodecParameterForInputMIMECodecParameter:)])
         outputCodecs = [getAVStreamDataParserClass() outputMIMECodecParameterForInputMIMECodecParameter:outputCodecs];
 
+    if (!contentTypeMeetsHardwareDecodeRequirements(parameters.type, parameters.contentTypesRequiringHardwareSupport))
+        return MediaPlayer::IsNotSupported;
+
     NSString *typeString = [NSString stringWithFormat:@"%@; codecs=\"%@\"", (NSString *)parameters.type.containerType(), (NSString *)outputCodecs];
     return [getAVURLAssetClass() isPlayableExtendedMIMEType:typeString] ? MediaPlayer::IsSupported : MediaPlayer::MayBeSupported;;
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to