Changeset 184916 in webkit


Ignore:
Timestamp:
May 27, 2015, 1:33:09 PM (11 years ago)
Author:
eric.carlson@apple.com
Message:

[Mac] short-circuit MIME type lookup when possible
https://bugs.webkit.org/show_bug.cgi?id=145362

Reviewed by Jer Noble.

  • platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:

(WebCore::isUnsupportedMIMEType): Renamed from unsupportedMIMEType. Convert type to lower case
once instead of calling equalIgnoringCase many times.
(WebCore::staticMIMETypeList): Renamed from staticMimeTypeCache. Initialize static set in a lambda,
using an array of C strings in a loop.
(WebCore::avfMIMETypes): Renamed from avfMimeTypeCache. Initialize static set in a lambda.
(WebCore::MediaPlayerPrivateAVFoundationObjC::getSupportedTypes): avfMimeTypeCache -> avfMIMETypes.
(WebCore::keySystemIsSupported): equalIgnoringCase -> equalIgnoringASCIICase.
(WebCore::MediaPlayerPrivateAVFoundationObjC::supportsType): Ditto.
(WebCore::MediaPlayerPrivateAVFoundationObjC::supportsKeySystem): unsupportedMIMEType ->
isUnsupportedMIMEType, equalIgnoringCase -> equalIgnoringASCIICase, staticMimeTypeCache ->
staticMIMETypeList, avfMimeTypeCache -> avfMIMETypes.
(WebCore::unsupportedMIMEType): Deleted.
(WebCore::staticMimeTypeCache): Deleted.
(WebCore::avfMimeTypeCache): Deleted.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r184910 r184916  
     12015-05-27  Eric Carlson  <eric.carlson@apple.com>
     2
     3        [Mac] short-circuit MIME type lookup when possible
     4        https://bugs.webkit.org/show_bug.cgi?id=145362
     5
     6        Reviewed by Jer Noble.
     7
     8        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
     9        (WebCore::isUnsupportedMIMEType): Renamed from unsupportedMIMEType. Convert type to lower case
     10        once instead of calling equalIgnoringCase many times.
     11        (WebCore::staticMIMETypeList): Renamed from staticMimeTypeCache. Initialize static set in a lambda,
     12        using an array of C strings in a loop.
     13        (WebCore::avfMIMETypes): Renamed from avfMimeTypeCache. Initialize static set in a lambda.
     14        (WebCore::MediaPlayerPrivateAVFoundationObjC::getSupportedTypes): avfMimeTypeCache -> avfMIMETypes.
     15        (WebCore::keySystemIsSupported): equalIgnoringCase -> equalIgnoringASCIICase.
     16        (WebCore::MediaPlayerPrivateAVFoundationObjC::supportsType): Ditto.
     17        (WebCore::MediaPlayerPrivateAVFoundationObjC::supportsKeySystem): unsupportedMIMEType ->
     18        isUnsupportedMIMEType, equalIgnoringCase -> equalIgnoringASCIICase, staticMimeTypeCache ->
     19        staticMIMETypeList, avfMimeTypeCache -> avfMIMETypes.
     20        (WebCore::unsupportedMIMEType): Deleted.
     21        (WebCore::staticMimeTypeCache): Deleted.
     22        (WebCore::avfMimeTypeCache): Deleted.
     23
    1242015-05-27  Eric Carlson  <eric.carlson@apple.com>
    225
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm

    r184910 r184916  
    15461546}
    15471547
    1548 static bool unsupportedMIMEType(const String& type)
    1549 {
     1548static bool isUnsupportedMIMEType(const String& type)
     1549{
     1550    String lowerCaseType = type.convertToASCIILowercase();
     1551
    15501552    // AVFoundation will return non-video MIME types which it claims to support, but which we
    15511553    // do not support in the <video> element. Reject all non video/, audio/, and application/ types.
    1552     if (!type.startsWith("video/", false) && !type.startsWith("audio/", false) && !type.startsWith("application/", false))
     1554    if (!lowerCaseType.startsWith("video/") && !lowerCaseType.startsWith("audio/") && !lowerCaseType.startsWith("application/"))
    15531555        return true;
    15541556
    15551557    // Reject types we know AVFoundation does not support that sites commonly ask about.
    1556     if (equalIgnoringCase(type, "video/webm") || equalIgnoringCase(type, "audio/webm") || equalIgnoringCase(type, "video/x-webm"))
     1558    if (lowerCaseType == "video/webm" || lowerCaseType == "audio/webm" || lowerCaseType == "video/x-webm")
    15571559        return true;
    15581560
    1559     if (equalIgnoringCase(type, "video/x-flv"))
     1561    if (lowerCaseType == "video/x-flv")
    15601562        return true;
    15611563
    1562     if (equalIgnoringCase(type, "audio/ogg") || equalIgnoringCase(type, "video/ogg") || equalIgnoringCase(type, "application/ogg"))
     1564    if (lowerCaseType == "audio/ogg" || lowerCaseType == "video/ogg" || lowerCaseType == "application/ogg")
    15631565        return true;
    15641566
    1565     if (equalIgnoringCase(type, "video/h264"))
     1567    if (lowerCaseType == "video/h264")
    15661568        return true;
    15671569
     
    15691571}
    15701572
    1571 static HashSet<String>& staticMimeTypeCache()
    1572 {
    1573     static NeverDestroyed<HashSet<String>> cache;
    1574     static bool typeListInitialized = false;
    1575 
    1576     if (typeListInitialized)
    1577         return cache;
    1578     typeListInitialized = true;
    1579 
    1580     cache.get().add("application/vnd.apple.mpegurl");
    1581     cache.get().add("application/x-mpegurl");
    1582     cache.get().add("audio/3gpp");
    1583     cache.get().add("audio/aac");
    1584     cache.get().add("audio/aacp");
    1585     cache.get().add("audio/aiff");
    1586     cache.get().add("audio/basic");
    1587     cache.get().add("audio/mp3");
    1588     cache.get().add("audio/mp4");
    1589     cache.get().add("audio/mpeg");
    1590     cache.get().add("audio/mpeg3");
    1591     cache.get().add("audio/mpegurl");
    1592     cache.get().add("audio/mpg");
    1593     cache.get().add("audio/wav");
    1594     cache.get().add("audio/wave");
    1595     cache.get().add("audio/x-aac");
    1596     cache.get().add("audio/x-aiff");
    1597     cache.get().add("audio/x-m4a");
    1598     cache.get().add("audio/x-mpegurl");
    1599     cache.get().add("audio/x-wav");
    1600     cache.get().add("video/3gpp");
    1601     cache.get().add("video/3gpp2");
    1602     cache.get().add("video/mp4");
    1603     cache.get().add("video/mpeg");
    1604     cache.get().add("video/mpeg2");
    1605     cache.get().add("video/mpg");
    1606     cache.get().add("video/quicktime");
    1607     cache.get().add("video/x-m4v");
    1608     cache.get().add("video/x-mpeg");
    1609     cache.get().add("video/x-mpg");
     1573static const HashSet<String>& staticMIMETypeList()
     1574{
     1575    static NeverDestroyed<HashSet<String>> cache = [] () {
     1576        HashSet<String> types;
     1577
     1578        static const char* typeNames[] = {
     1579            "application/vnd.apple.mpegurl",
     1580            "application/x-mpegurl",
     1581            "audio/3gpp",
     1582            "audio/aac",
     1583            "audio/aacp",
     1584            "audio/aiff",
     1585            "audio/basic",
     1586            "audio/mp3",
     1587            "audio/mp4",
     1588            "audio/mpeg",
     1589            "audio/mpeg3",
     1590            "audio/mpegurl",
     1591            "audio/mpg",
     1592            "audio/wav",
     1593            "audio/wave",
     1594            "audio/x-aac",
     1595            "audio/x-aiff",
     1596            "audio/x-m4a",
     1597            "audio/x-mpegurl",
     1598            "audio/x-wav",
     1599            "video/3gpp",
     1600            "video/3gpp2",
     1601            "video/mp4",
     1602            "video/mpeg",
     1603            "video/mpeg2",
     1604            "video/mpg",
     1605            "video/quicktime",
     1606            "video/x-m4v",
     1607            "video/x-mpeg",
     1608            "video/x-mpg",
     1609        };
     1610        for (size_t i = 0; i < WTF_ARRAY_LENGTH(typeNames); ++i)
     1611            types.add(typeNames[i]);
     1612
     1613        return types;
     1614    }();
    16101615
    16111616    return cache;
    1612 } 
    1613 
    1614 static HashSet<String>& avfMimeTypeCache()
    1615 {
    1616     static NeverDestroyed<HashSet<String>> cache;
    1617     static bool typeListInitialized = false;
    1618 
    1619     if (typeListInitialized)
    1620         return cache;
    1621     typeListInitialized = true;
    1622 
    1623     NSArray *types = [AVURLAsset audiovisualMIMETypes];
    1624     for (NSString *mimeType in types)
    1625         cache.get().add([mimeType lowercaseString]);
    1626 
     1617}
     1618
     1619static const HashSet<String>& avfMIMETypes()
     1620{
     1621    static NeverDestroyed<HashSet<String>> cache = [] () {
     1622        HashSet<String> types;
     1623
     1624        NSArray *nsTypes = [AVURLAsset audiovisualMIMETypes];
     1625        for (NSString *mimeType in nsTypes)
     1626            types.add([mimeType lowercaseString]);
     1627
     1628        return types;
     1629    }();
     1630
     1631   
    16271632    return cache;
    1628 } 
     1633}
    16291634
    16301635RetainPtr<CGImageRef> MediaPlayerPrivateAVFoundationObjC::createImageForTimeInRect(float time, const FloatRect& rect)
     
    16521657void MediaPlayerPrivateAVFoundationObjC::getSupportedTypes(HashSet<String>& supportedTypes)
    16531658{
    1654     supportedTypes = avfMimeTypeCache();
     1659    supportedTypes = avfMIMETypes();
    16551660}
    16561661
     
    16581663static bool keySystemIsSupported(const String& keySystem)
    16591664{
    1660     if (equalIgnoringCase(keySystem, "com.apple.fps") || equalIgnoringCase(keySystem, "com.apple.fps.1_0") || equalIgnoringCase(keySystem, "org.w3c.clearkey"))
     1665    if (equalIgnoringASCIICase(keySystem, "com.apple.fps") || equalIgnoringASCIICase(keySystem, "com.apple.fps.1_0") || equalIgnoringASCIICase(keySystem, "org.w3c.clearkey"))
    16611666        return true;
    16621667    return false;
     
    16741679    if (!parameters.keySystem.isNull() && !parameters.keySystem.isEmpty()) {
    16751680        // "Clear Key" is only supported with HLS:
    1676         if (equalIgnoringCase(parameters.keySystem, "org.w3c.clearkey") && !parameters.type.isEmpty() && !equalIgnoringCase(parameters.type, "application/x-mpegurl"))
     1681        if (equalIgnoringASCIICase(parameters.keySystem, "org.w3c.clearkey") && !parameters.type.isEmpty() && !equalIgnoringASCIICase(parameters.type, "application/x-mpegurl"))
    16771682            return MediaPlayer::IsNotSupported;
    16781683
     
    16931698#endif
    16941699
    1695     if (unsupportedMIMEType(parameters.type))
     1700    if (isUnsupportedMIMEType(parameters.type))
    16961701        return MediaPlayer::IsNotSupported;
    16971702
    1698     if (!staticMimeTypeCache().contains(parameters.type) && !avfMimeTypeCache().contains(parameters.type))
     1703    if (!staticMIMETypeList().contains(parameters.type) && !avfMIMETypes().contains(parameters.type))
    16991704        return MediaPlayer::IsNotSupported;
    17001705
     
    17131718    if (!keySystem.isEmpty()) {
    17141719        // "Clear Key" is only supported with HLS:
    1715         if (equalIgnoringCase(keySystem, "org.w3c.clearkey") && !mimeType.isEmpty() && !equalIgnoringCase(mimeType, "application/x-mpegurl"))
     1720        if (equalIgnoringASCIICase(keySystem, "org.w3c.clearkey") && !mimeType.isEmpty() && !equalIgnoringASCIICase(mimeType, "application/x-mpegurl"))
    17161721            return MediaPlayer::IsNotSupported;
    17171722
     
    17191724            return false;
    17201725
    1721         if (!mimeType.isEmpty() && unsupportedMIMEType(mimeType))
     1726        if (!mimeType.isEmpty() && isUnsupportedMIMEType(mimeType))
    17221727            return false;
    17231728
    1724         if (!mimeType.isEmpty() && !staticMimeTypeCache().contains(mimeType) && !avfMimeTypeCache().contains(mimeType))
     1729        if (!mimeType.isEmpty() && !staticMIMETypeList().contains(mimeType) && !avfMIMETypes().contains(mimeType))
    17251730            return false;
    17261731
Note: See TracChangeset for help on using the changeset viewer.