Changeset 232136 in webkit


Ignore:
Timestamp:
May 23, 2018 5:00:54 PM (6 years ago)
Author:
eric.carlson@apple.com
Message:

Avoid loading AVFoundation to check supported MIME types if possible
https://bugs.webkit.org/show_bug.cgi?id=185839
<rdar://problem/40182010>

Reviewed by Jer Noble.
Source/WebCore:

Avoid loading AVFoundation to call +[AVURLAssetClass audiovisualMIMETypes] as long as possible,
and when they are loaded send the list to the UI process so it can pass it to all extant
and all new web processes so they can won't have call it at all.

  • WebCore.xcodeproj/project.pbxproj:
  • platform/graphics/ImageDecoder.cpp:

(WebCore::ImageDecoder::create): Don't call ImageDecoderAVFObjC::canDecodeType if
ImageDecoderCG can decode the type so we don't have to load AVFoundation.
(WebCore::ImageDecoder::supportsMediaType): Return as soon as a decoder class says
it supports a media type to avoid calling more than one. Call ImageDecoderAVFObjC last.

  • platform/graphics/avfoundation/objc/AVFoundationMIMETypeCache.h:

(WebCore::AVFoundationMIMETypeCache::setCacheMIMETypesCallback):

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

(WebCore::AVFoundationMIMETypeCache::singleton): Simplify.
(WebCore::AVFoundationMIMETypeCache::setSupportedTypes): Cache the supplied list of types
so we won't have to load AVFoundation when asked for types later.
(WebCore::AVFoundationMIMETypeCache::types):
(WebCore::AVFoundationMIMETypeCache::supportsContentType): New convenience routine.
(WebCore::AVFoundationMIMETypeCache::canDecodeType): Ditto.
(WebCore::AVFoundationMIMETypeCache::isAvailable const): New, check to see if AVFoundation.framework
is available without actually loading it.
(WebCore::AVFoundationMIMETypeCache::loadMIMETypes): Load types if possible.
(WebCore::AVFoundationMIMETypeCache::AVFoundationMIMETypeCache): Deleted.
(WebCore::AVFoundationMIMETypeCache::loadTypes): Deleted.

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

(WebCore::ImageDecoderAVFObjC::create): Use AVFoundationMIMETypeCache::isAvailable instead
of loading the frameworks.
(WebCore::ImageDecoderAVFObjC::supportsMediaType): Ditto.
(WebCore::ImageDecoderAVFObjC::supportsContentType): Use AVFoundationMIMETypeCache::supportsContentType.
(WebCore::ImageDecoderAVFObjC::canDecodeType): Use AVFoundationMIMETypeCache::canDecodeType.

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

(WebCore::MediaPlayerPrivateAVFoundationObjC::registerMediaEngine): ASSERT if the
AVFoundationMIMETypeCache is empty, it shouldn't be possible to get here in that state.
(WebCore::MediaPlayerPrivateAVFoundationObjC::supportsType): Use AVFoundationMIMETypeCache::supportsContentType.
(WebCore::MediaPlayerPrivateAVFoundationObjC::supportsKeySystem): Use AVFoundationMIMETypeCache::canDecodeType.

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

(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::registerMediaEngine): ASSERT if the
AVFoundationMIMETypeCache is empty, it shouldn't be possible to get here in that state.
(WebCore::MediaPlayerPrivateMediaSourceAVFObjC::supportsType): Use AVFoundationMIMETypeCache::canDecodeType.

  • platform/graphics/cg/ImageDecoderCG.cpp:

(WebCore::ImageDecoderCG::canDecodeType): New.

  • platform/graphics/cg/ImageDecoderCG.h:

Source/WebKit:

  • Shared/WebProcessCreationParameters.cpp:

(WebKit::WebProcessCreationParameters::encode const): Encode mediaMIMETypes.
(WebKit::WebProcessCreationParameters::decode): Decode mediaMIMETypes.

  • Shared/WebProcessCreationParameters.h:
  • UIProcess/Cocoa/WebProcessProxyCocoa.mm:

(WebKit::mediaTypeCache): Static Vector of media MIME types.
(WebKit::WebProcessProxy::cacheMediaMIMETypes): Cache the type list and pass it to every other
process proxy.
(WebKit::WebProcessProxy::cacheMediaMIMETypesInternal): Cache the type list and pass it to the
web process.
(WebKit::WebProcessProxy::mediaMIMETypes): Return the cached type list.

  • UIProcess/WebProcessPool.cpp:

(WebKit::WebProcessPool::initializeNewWebProcess): Set parameters.mediaMIMETypes.

  • UIProcess/WebProcessProxy.h:
  • UIProcess/WebProcessProxy.messages.in: Add CacheMediaMIMETypes.
  • WebProcess/WebProcess.h:
  • WebProcess/WebProcess.messages.in: Add SetMediaMIMETypes.
  • WebProcess/cocoa/WebProcessCocoa.mm:

(WebKit::WebProcess::platformInitializeWebProcess): Cache the MIME types if the list isn't
empty, else register with AVFoundationMIMETypeCache to be notified when it loads types.
AVFoundationMIMETypeCache to
(WebKit::WebProcess::platformTerminate): Unregister with AVFoundationMIMETypeCache.
(WebKit::WebProcess::setMediaMIMETypes): Pass list of types to AVFoundationMIMETypeCache.

Source/WTF:

  • wtf/cocoa/SoftLinking.h: Add SOFT_LINK_FRAMEWORK_OPTIONAL_PREFLIGHT.
Location:
trunk/Source
Files:
23 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r232132 r232136  
     12018-05-23  Eric Carlson  <eric.carlson@apple.com>
     2
     3        Avoid loading AVFoundation to check supported MIME types if possible
     4        https://bugs.webkit.org/show_bug.cgi?id=185839
     5        <rdar://problem/40182010>
     6
     7        Reviewed by Jer Noble.
     8
     9        * wtf/cocoa/SoftLinking.h: Add SOFT_LINK_FRAMEWORK_OPTIONAL_PREFLIGHT.
     10
    1112018-05-23  Filip Pizlo  <fpizlo@apple.com>
    212
  • trunk/Source/WTF/wtf/cocoa/SoftLinking.h

    r230974 r232136  
    6464    }
    6565
     66#define SOFT_LINK_FRAMEWORK_OPTIONAL_PREFLIGHT(framework) \
     67    static bool framework##LibraryIsAvailable() \
     68    { \
     69        static bool frameworkLibraryIsAvailable = dlopen_preflight("/System/Library/Frameworks/" #framework ".framework/" #framework); \
     70        return frameworkLibraryIsAvailable; \
     71    }
     72
    6673#define SOFT_LINK_FRAMEWORK_OPTIONAL(framework) \
    6774    static void* framework##Library() \
  • trunk/Source/WebCore/ChangeLog

    r232123 r232136  
     12018-05-23  Eric Carlson  <eric.carlson@apple.com>
     2
     3        Avoid loading AVFoundation to check supported MIME types if possible
     4        https://bugs.webkit.org/show_bug.cgi?id=185839
     5        <rdar://problem/40182010>
     6
     7        Reviewed by Jer Noble.
     8
     9        Avoid loading AVFoundation to call +[AVURLAssetClass audiovisualMIMETypes] as long as possible,
     10        and when they are loaded send the list to the UI process so it can pass it to all extant
     11        and all new web processes so they can won't have call it at all.
     12
     13        * WebCore.xcodeproj/project.pbxproj:
     14        * platform/graphics/ImageDecoder.cpp:
     15        (WebCore::ImageDecoder::create): Don't call ImageDecoderAVFObjC::canDecodeType if
     16        ImageDecoderCG can decode the type so we don't have to load AVFoundation.
     17        (WebCore::ImageDecoder::supportsMediaType): Return as soon as a decoder class says
     18        it supports a media type to avoid calling more than one. Call ImageDecoderAVFObjC last.
     19
     20        * platform/graphics/avfoundation/objc/AVFoundationMIMETypeCache.h:
     21        (WebCore::AVFoundationMIMETypeCache::setCacheMIMETypesCallback):
     22        * platform/graphics/avfoundation/objc/AVFoundationMIMETypeCache.mm:
     23        (WebCore::AVFoundationMIMETypeCache::singleton): Simplify.
     24        (WebCore::AVFoundationMIMETypeCache::setSupportedTypes): Cache the supplied list of types
     25        so we won't have to load AVFoundation when asked for types later.
     26        (WebCore::AVFoundationMIMETypeCache::types):
     27        (WebCore::AVFoundationMIMETypeCache::supportsContentType): New convenience routine.
     28        (WebCore::AVFoundationMIMETypeCache::canDecodeType): Ditto.
     29        (WebCore::AVFoundationMIMETypeCache::isAvailable const): New, check to see if AVFoundation.framework
     30        is available without actually loading it.
     31        (WebCore::AVFoundationMIMETypeCache::loadMIMETypes): Load types if possible.
     32        (WebCore::AVFoundationMIMETypeCache::AVFoundationMIMETypeCache): Deleted.
     33        (WebCore::AVFoundationMIMETypeCache::loadTypes): Deleted.
     34
     35        * platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.mm:
     36        (WebCore::ImageDecoderAVFObjC::create): Use AVFoundationMIMETypeCache::isAvailable instead
     37        of loading the frameworks.
     38        (WebCore::ImageDecoderAVFObjC::supportsMediaType): Ditto.
     39        (WebCore::ImageDecoderAVFObjC::supportsContentType): Use AVFoundationMIMETypeCache::supportsContentType.
     40        (WebCore::ImageDecoderAVFObjC::canDecodeType): Use AVFoundationMIMETypeCache::canDecodeType.
     41
     42        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
     43        (WebCore::MediaPlayerPrivateAVFoundationObjC::registerMediaEngine): ASSERT if the
     44        AVFoundationMIMETypeCache is empty, it shouldn't be possible to get here in that state.
     45        (WebCore::MediaPlayerPrivateAVFoundationObjC::supportsType): Use AVFoundationMIMETypeCache::supportsContentType.
     46        (WebCore::MediaPlayerPrivateAVFoundationObjC::supportsKeySystem): Use AVFoundationMIMETypeCache::canDecodeType.
     47
     48        * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm:
     49        (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::registerMediaEngine): ASSERT if the
     50        AVFoundationMIMETypeCache is empty, it shouldn't be possible to get here in that state.
     51        (WebCore::MediaPlayerPrivateMediaSourceAVFObjC::supportsType): Use AVFoundationMIMETypeCache::canDecodeType.
     52
     53        * platform/graphics/cg/ImageDecoderCG.cpp:
     54        (WebCore::ImageDecoderCG::canDecodeType): New.
     55        * platform/graphics/cg/ImageDecoderCG.h:
     56
    1572018-05-23  Chris Dumez  <cdumez@apple.com>
    258
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r232114 r232136  
    220220                07EE76EF1BEA619800F89133 /* MockRealtimeVideoSourceMac.h in Headers */ = {isa = PBXBuildFile; fileRef = 07EE76ED1BEA619800F89133 /* MockRealtimeVideoSourceMac.h */; };
    221221                07F04A942006B1E300AE2A0A /* ApplicationStateChangeListener.h in Headers */ = {isa = PBXBuildFile; fileRef = 07F04A92200684BC00AE2A0A /* ApplicationStateChangeListener.h */; settings = {ATTRIBUTES = (Private, ); }; };
     222                07F4E93320B3587F002E3803 /* AVFoundationMIMETypeCache.h in Headers */ = {isa = PBXBuildFile; fileRef = 07C8AD121D073D630087C5CE /* AVFoundationMIMETypeCache.h */; settings = {ATTRIBUTES = (Private, ); }; };
    222223                07F876841AD580F900905849 /* MediaPlaybackTargetContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 07F876831AD4A94500905849 /* MediaPlaybackTargetContext.h */; settings = {ATTRIBUTES = (Private, ); }; };
    223224                07F944161864D046005D31CB /* PlatformMediaSessionManager.h in Headers */ = {isa = PBXBuildFile; fileRef = CDAE8C081746B95700532D78 /* PlatformMediaSessionManager.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    2712127122                                CDC675231EAEA9B700727C84 /* AVAudioSessionCaptureDeviceManager.h in Headers */,
    2712227123                                070363E2181A1CDC00C074A5 /* AVCaptureDeviceManager.h in Headers */,
     27124                                07F4E93320B3587F002E3803 /* AVFoundationMIMETypeCache.h in Headers */,
    2712327125                                070363E4181A1CDC00C074A5 /* AVMediaCaptureSource.h in Headers */,
    2712427126                                CD336F6217F9F64700DDDCD0 /* AVTrackPrivateAVFObjCImpl.h in Headers */,
  • trunk/Source/WebCore/platform/graphics/ImageDecoder.cpp

    r227631 r232136  
    4343RefPtr<ImageDecoder> ImageDecoder::create(SharedBuffer& data, const String& mimeType, AlphaOption alphaOption, GammaAndColorProfileOption gammaAndColorProfileOption)
    4444{
     45    UNUSED_PARAM(mimeType);
     46
    4547#if HAVE(AVASSETREADER)
    46     if (ImageDecoderAVFObjC::canDecodeType(mimeType))
     48    if (!ImageDecoderCG::canDecodeType(mimeType) && ImageDecoderAVFObjC::canDecodeType(mimeType))
    4749        return ImageDecoderAVFObjC::create(data, mimeType, alphaOption, gammaAndColorProfileOption);
    48 #else
    49     UNUSED_PARAM(mimeType);
    5050#endif
    5151
     
    6161bool ImageDecoder::supportsMediaType(MediaType type)
    6262{
    63     bool supports = false;
     63#if USE(CG)
     64    if (ImageDecoderCG::supportsMediaType(type))
     65        return true;
     66#elif USE(DIRECT2D)
     67    if (ImageDecoderDirect2D::supportsMediaType(type))
     68        return true;
     69#else
     70    if (ScalableImageDecoder::supportsMediaType(type))
     71        return true;
     72#endif
     73
    6474#if HAVE(AVASSETREADER)
    6575    if (ImageDecoderAVFObjC::supportsMediaType(type))
    66         supports = true;
     76        return true;
    6777#endif
    6878
    69 #if USE(CG)
    70     if (ImageDecoderCG::supportsMediaType(type))
    71         supports = true;
    72 #elif USE(DIRECT2D)
    73     if (ImageDecoderDirect2D::supportsMediaType(type))
    74         supports = true;
    75 #else
    76     if (ScalableImageDecoder::supportsMediaType(type))
    77         supports = true;
    78 #endif
    79 
    80     return supports;
     79    return false;
    8180}
    8281
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/AVFoundationMIMETypeCache.h

    r201831 r232136  
    11/*
    2  * Copyright (C) 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016-2018 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #ifndef AVFoundationMIMETypeCache_h
    27 #define AVFoundationMIMETypeCache_h
     26#pragma once
    2827
    29 #if ENABLE(VIDEO) && USE(AVFOUNDATION)
     28#if PLATFORM(COCOA)
    3029
    3130#include <wtf/Forward.h>
     
    3534namespace WebCore {
    3635
     36class ContentType;
     37
    3738class AVFoundationMIMETypeCache {
    3839public:
    39     static AVFoundationMIMETypeCache& singleton();
     40    WEBCORE_EXPORT static AVFoundationMIMETypeCache& singleton();
    4041
    41     AVFoundationMIMETypeCache();
     42    bool supportsContentType(const ContentType&);
     43    bool canDecodeType(const String&);
    4244
    43     void loadTypes();
    4445    const HashSet<String, ASCIICaseInsensitiveHash>& types();
     46    bool isEmpty();
     47    bool isAvailable() const;
     48
     49    using CacheMIMETypesCallback = std::function<void(const Vector<String>&)>;
     50    void setCacheMIMETypesCallback(CacheMIMETypesCallback&& callback) { m_cacheTypeCallback = WTFMove(callback); }
     51
     52    WEBCORE_EXPORT void setSupportedTypes(const Vector<String>&);
    4553
    4654private:
    47     enum MIMETypeLoadStatus { NotLoaded, Loading, Loaded };
     55    friend NeverDestroyed<AVFoundationMIMETypeCache>;
     56    AVFoundationMIMETypeCache() = default;
    4857
    49     MIMETypeLoadStatus m_status { NotLoaded };
    50     dispatch_queue_t m_loaderQueue;
    51     Lock m_lock;
    52     HashSet<String, ASCIICaseInsensitiveHash> m_cache;
     58    void loadMIMETypes();
     59
     60    std::optional<HashSet<String, ASCIICaseInsensitiveHash>> m_cache;
     61    CacheMIMETypesCallback m_cacheTypeCallback;
    5362};
    5463
    5564}
     65
    5666#endif
    57 #endif
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/AVFoundationMIMETypeCache.mm

    r223476 r232136  
    11/*
    2  * Copyright (C) 2016 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016-2018 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2727#import "AVFoundationMIMETypeCache.h"
    2828
    29 #if ENABLE(VIDEO) && USE(AVFOUNDATION)
     29#if PLATFORM(COCOA)
    3030
     31#import "ContentType.h"
    3132#import <AVFoundation/AVAsset.h>
    3233#import <wtf/HashSet.h>
    33 #import <wtf/Locker.h>
    34 #import <wtf/NeverDestroyed.h>
    3534
    3635#import <pal/cf/CoreMediaSoftLink.h>
    3736
     37#if ENABLE(VIDEO) && USE(AVFOUNDATION)
     38SOFT_LINK_FRAMEWORK_OPTIONAL_PREFLIGHT(AVFoundation)
    3839SOFT_LINK_FRAMEWORK_OPTIONAL(AVFoundation)
    3940SOFT_LINK_CLASS(AVFoundation, AVURLAsset)
     41#endif
    4042
    4143namespace WebCore {
    42 
    43 using namespace PAL;
    44 
    45 AVFoundationMIMETypeCache::AVFoundationMIMETypeCache()
    46 {
    47     m_loaderQueue = dispatch_queue_create("WebCoreAudioVisualMIMETypes loader queue", DISPATCH_QUEUE_SERIAL);
    48 }
    49 
    50 void AVFoundationMIMETypeCache::loadTypes()
    51 {
    52     {
    53         Locker<Lock> lock(m_lock);
    54 
    55         if (m_status != NotLoaded)
    56             return;
    57 
    58         if (!AVFoundationLibrary()) {
    59             m_status = Loaded;
    60             return;
    61         }
    62 
    63         m_status = Loading;
    64     }
    65 
    66     dispatch_async(m_loaderQueue, [this] {
    67         for (NSString *type in [getAVURLAssetClass() audiovisualMIMETypes])
    68             m_cache.add(type);
    69         m_lock.lock();
    70         m_status = Loaded;
    71         m_lock.unlock();
    72     });
    73 }
    74 
    75 const HashSet<String, ASCIICaseInsensitiveHash>& AVFoundationMIMETypeCache::types()
    76 {
    77     m_lock.lock();
    78     MIMETypeLoadStatus status = m_status;
    79     m_lock.unlock();
    80 
    81     if (status != Loaded) {
    82         loadTypes();
    83         dispatch_sync(m_loaderQueue, ^{ });
    84     }
    85 
    86     return m_cache;
    87 }
    8844
    8945AVFoundationMIMETypeCache& AVFoundationMIMETypeCache::singleton()
     
    9349}
    9450
     51void AVFoundationMIMETypeCache::setSupportedTypes(const Vector<String>& types)
     52{
     53    if (m_cache)
     54        return;
     55
     56    m_cache = HashSet<String, ASCIICaseInsensitiveHash>();
     57    for (auto& type : types)
     58        m_cache->add(type);
     59}
     60
     61const HashSet<String, ASCIICaseInsensitiveHash>& AVFoundationMIMETypeCache::types()
     62{
     63    if (!m_cache)
     64        loadMIMETypes();
     65
     66    return *m_cache;
     67}
     68
     69bool AVFoundationMIMETypeCache::supportsContentType(const ContentType& contentType)
     70{
     71    if (contentType.isEmpty())
     72        return false;
     73
     74    return types().contains(contentType.containerType());
     75}
     76
     77bool AVFoundationMIMETypeCache::canDecodeType(const String& mimeType)
     78{
     79    if (mimeType.isEmpty())
     80        return false;
     81
     82    if (!isAvailable() || !types().contains(ContentType { mimeType }.containerType()))
     83        return false;
     84
     85#if ENABLE(VIDEO) && USE(AVFOUNDATION)
     86    return [getAVURLAssetClass() isPlayableExtendedMIMEType:mimeType];
     87#endif
     88
     89    return false;
     90}
     91
     92bool AVFoundationMIMETypeCache::isAvailable() const
     93{
     94#if ENABLE(VIDEO) && USE(AVFOUNDATION)
     95    return AVFoundationLibraryIsAvailable();
     96#else
     97    return false;
     98#endif
     99}
     100
     101void AVFoundationMIMETypeCache::loadMIMETypes()
     102{
     103    m_cache = HashSet<String, ASCIICaseInsensitiveHash>();
     104
     105#if ENABLE(VIDEO) && USE(AVFOUNDATION)
     106    static std::once_flag onceFlag;
     107    std::call_once(onceFlag, [this] {
     108        if (!AVFoundationLibrary())
     109            return;
     110
     111        for (NSString* type in [getAVURLAssetClass() audiovisualMIMETypes])
     112            m_cache->add(type);
     113
     114        if (m_cacheTypeCallback)
     115            m_cacheTypeCallback(copyToVector(*m_cache));
     116    });
     117#endif
     118}
     119
    95120}
    96121
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/ImageDecoderAVFObjC.mm

    r231920 r232136  
    320320{
    321321    // AVFoundation may not be available at runtime.
    322     if (!getAVURLAssetClass())
     322    if (!AVFoundationMIMETypeCache::singleton().isAvailable())
    323323        return nullptr;
    324324
     
    351351bool ImageDecoderAVFObjC::supportsMediaType(MediaType type)
    352352{
    353     if (type == MediaType::Video)
    354         return getAVURLAssetClass() && canLoad_VideoToolbox_VTCreateCGImageFromCVPixelBuffer();
    355     return false;
     353    return type == MediaType::Video && AVFoundationMIMETypeCache::singleton().isAvailable();
    356354}
    357355
    358356bool ImageDecoderAVFObjC::supportsContentType(const ContentType& type)
    359357{
    360     if (getAVURLAssetClass() && canLoad_VideoToolbox_VTCreateCGImageFromCVPixelBuffer())
    361         return AVFoundationMIMETypeCache::singleton().types().contains(type.containerType());
    362     return false;
     358    return AVFoundationMIMETypeCache::singleton().supportsContentType(type);
    363359}
    364360
    365361bool ImageDecoderAVFObjC::canDecodeType(const String& mimeType)
    366362{
    367     if (!supportsMediaType(MediaType::Video))
    368         return nullptr;
    369 
    370     return [getAVURLAssetClass() isPlayableExtendedMIMEType:mimeType];
     363    return AVFoundationMIMETypeCache::singleton().canDecodeType(mimeType);
    371364}
    372365
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm

    r231578 r232136  
    398398    registrar([](MediaPlayer* player) { return std::make_unique<MediaPlayerPrivateAVFoundationObjC>(player); },
    399399            getSupportedTypes, supportsType, originsInMediaCache, clearMediaCache, clearMediaCacheForOrigins, supportsKeySystem);
    400     AVFoundationMIMETypeCache::singleton().loadTypes();
     400    ASSERT(AVFoundationMIMETypeCache::singleton().isAvailable());
    401401}
    402402
     
    16821682        return MediaPlayer::IsNotSupported;
    16831683
    1684     if (!staticMIMETypeList().contains(containerType) && !AVFoundationMIMETypeCache::singleton().types().contains(containerType))
     1684    if (!staticMIMETypeList().contains(containerType) && !AVFoundationMIMETypeCache::singleton().canDecodeType(containerType))
    16851685        return MediaPlayer::IsNotSupported;
    16861686
     
    17111711            return false;
    17121712
    1713         if (!mimeType.isEmpty() && !staticMIMETypeList().contains(mimeType) && !AVFoundationMIMETypeCache::singleton().types().contains(mimeType))
     1713        if (!mimeType.isEmpty() && !staticMIMETypeList().contains(mimeType) && !AVFoundationMIMETypeCache::singleton().canDecodeType(mimeType))
    17141714            return false;
    17151715
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaSourceAVFObjC.mm

    r230194 r232136  
    192192    registrar([](MediaPlayer* player) { return std::make_unique<MediaPlayerPrivateMediaSourceAVFObjC>(player); },
    193193        getSupportedTypes, supportsType, 0, 0, 0, 0);
    194     AVFoundationMIMETypeCache::singleton().loadTypes();
     194    ASSERT(AVFoundationMIMETypeCache::singleton().isAvailable());
    195195}
    196196
     
    220220#endif
    221221
    222     if (parameters.type.isEmpty() || !AVFoundationMIMETypeCache::singleton().types().contains(parameters.type.containerType()))
     222    if (parameters.type.isEmpty() || !AVFoundationMIMETypeCache::singleton().canDecodeType(parameters.type.containerType()))
    223223        return MediaPlayer::IsNotSupported;
    224224
  • trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.cpp

    r230712 r232136  
    3434#include "IntSize.h"
    3535#include "Logging.h"
     36#include "MIMETypeRegistry.h"
    3637#include "SharedBuffer.h"
    3738#include "UTIRegistry.h"
     
    481482}
    482483
     484bool ImageDecoderCG::canDecodeType(const String& mimeType)
     485{
     486    return MIMETypeRegistry::isSupportedImageMIMEType(mimeType);
     487}
     488
    483489}
    484490
  • trunk/Source/WebCore/platform/graphics/cg/ImageDecoderCG.h

    r225616 r232136  
    4141
    4242    static bool supportsMediaType(MediaType type) { return type == MediaType::Image; }
    43    
     43    static bool canDecodeType(const String&);
     44
    4445    size_t bytesDecodedToDetermineProperties() const final;
    4546
  • trunk/Source/WebKit/ChangeLog

    r232133 r232136  
     12018-05-23  Eric Carlson  <eric.carlson@apple.com>
     2
     3        Avoid loading AVFoundation to check supported MIME types if possible
     4        https://bugs.webkit.org/show_bug.cgi?id=185839
     5        <rdar://problem/40182010>
     6
     7        Reviewed by Jer Noble.
     8       
     9        * Shared/WebProcessCreationParameters.cpp:
     10        (WebKit::WebProcessCreationParameters::encode const): Encode mediaMIMETypes.
     11        (WebKit::WebProcessCreationParameters::decode): Decode mediaMIMETypes.
     12        * Shared/WebProcessCreationParameters.h:
     13
     14        * UIProcess/Cocoa/WebProcessProxyCocoa.mm:
     15        (WebKit::mediaTypeCache): Static Vector of media MIME types.
     16        (WebKit::WebProcessProxy::cacheMediaMIMETypes): Cache the type list and pass it to every other
     17        process proxy.
     18        (WebKit::WebProcessProxy::cacheMediaMIMETypesInternal): Cache the type list and pass it to the
     19        web process.
     20        (WebKit::WebProcessProxy::mediaMIMETypes): Return the cached type list.
     21
     22        * UIProcess/WebProcessPool.cpp:
     23        (WebKit::WebProcessPool::initializeNewWebProcess): Set parameters.mediaMIMETypes.
     24
     25        * UIProcess/WebProcessProxy.h:
     26        * UIProcess/WebProcessProxy.messages.in: Add CacheMediaMIMETypes.
     27
     28        * WebProcess/WebProcess.h:
     29        * WebProcess/WebProcess.messages.in: Add SetMediaMIMETypes.
     30
     31        * WebProcess/cocoa/WebProcessCocoa.mm:
     32        (WebKit::WebProcess::platformInitializeWebProcess): Cache the MIME types if the list isn't
     33        empty, else register with AVFoundationMIMETypeCache to be notified when it loads types.
     34        AVFoundationMIMETypeCache to
     35        (WebKit::WebProcess::platformTerminate): Unregister with AVFoundationMIMETypeCache.
     36        (WebKit::WebProcess::setMediaMIMETypes): Pass list of types to AVFoundationMIMETypeCache.
     37
    1382018-05-23  Brian Burg  <bburg@apple.com>
    239
  • trunk/Source/WebKit/Shared/WebProcessCreationParameters.cpp

    r232083 r232136  
    155155    encoder << shouldLogUserInteraction;
    156156#endif
     157
     158#if PLATFORM(COCOA)
     159    encoder << mediaMIMETypes;
     160#endif
    157161}
    158162
     
    402406#endif
    403407
     408#if PLATFORM(COCOA)
     409    if (!decoder.decode(parameters.mediaMIMETypes))
     410        return false;
     411#endif
     412
    404413    return true;
    405414}
  • trunk/Source/WebKit/Shared/WebProcessCreationParameters.h

    r232083 r232136  
    186186#endif
    187187
     188#if PLATFORM(COCOA)
     189    Vector<String> mediaMIMETypes;
     190#endif
     191
    188192#if HAVE(CFNETWORK_STORAGE_PARTITIONING) && !RELEASE_LOG_DISABLED
    189193    bool shouldLogUserInteraction { false };
  • trunk/Source/WebKit/UIProcess/Cocoa/WebProcessProxyCocoa.mm

    r215132 r232136  
    3232#import "WKBrowsingContextHandleInternal.h"
    3333#import "WKTypeRefWrapper.h"
     34#import "WebProcessMessages.h"
     35#import "WebProcessPool.h"
    3436#import <sys/sysctl.h>
    3537#import <wtf/NeverDestroyed.h>
     
    138140}
    139141
     142static Vector<String>& mediaTypeCache()
     143{
     144    ASSERT(RunLoop::isMain());
     145    static NeverDestroyed<Vector<String>> typeCache;
     146    return typeCache;
    140147}
     148
     149void WebProcessProxy::cacheMediaMIMETypes(const Vector<String>& types)
     150{
     151    if (!mediaTypeCache().isEmpty())
     152        return;
     153
     154    mediaTypeCache() = types;
     155    for (auto& process : processPool().processes()) {
     156        if (process != this)
     157            cacheMediaMIMETypesInternal(types);
     158    }
     159}
     160
     161void WebProcessProxy::cacheMediaMIMETypesInternal(const Vector<String>& types)
     162{
     163    if (!mediaTypeCache().isEmpty())
     164        return;
     165
     166    mediaTypeCache() = types;
     167    send(Messages::WebProcess::SetMediaMIMETypes(types), 0);
     168}
     169
     170Vector<String> WebProcessProxy::mediaMIMETypes()
     171{
     172    return mediaTypeCache();
     173}
     174
     175}
  • trunk/Source/WebKit/UIProcess/WebPageProxy.h

    r232090 r232136  
    13141314    WebCore::IntRect syncRootViewToScreen(const WebCore::IntRect& viewRect);
    13151315
     1316#if PLATFORM(COCOA)
     1317    Vector<String> mediaMIMETypes();
     1318#endif
     1319
    13161320private:
    13171321    WebPageProxy(PageClient&, WebProcessProxy&, uint64_t pageID, Ref<API::PageConfiguration>&&);
  • trunk/Source/WebKit/UIProcess/WebProcessPool.cpp

    r232133 r232136  
    940940    parameters.presentingApplicationPID = m_configuration->presentingApplicationPID();
    941941
     942#if PLATFORM(COCOA)
     943    parameters.mediaMIMETypes = process.mediaMIMETypes();
     944#endif
     945
    942946    // Add any platform specific parameters
    943947    platformInitializeWebProcess(parameters);
  • trunk/Source/WebKit/UIProcess/WebProcessProxy.h

    r231931 r232136  
    222222    void setIsInPrewarmedPool(bool isInPrewarmedPool) { m_isInPrewarmedPool = isInPrewarmedPool; }
    223223
     224#if PLATFORM(COCOA)
     225    Vector<String> mediaMIMETypes();
     226    void cacheMediaMIMETypes(const Vector<String>&);
     227#endif
     228
    224229protected:
    225230    static uint64_t generatePageID();
     
    233238    // ProcessLauncher::Client
    234239    void didFinishLaunching(ProcessLauncher*, IPC::Connection::Identifier) override;
     240
     241#if PLATFORM(COCOA)
     242    void cacheMediaMIMETypesInternal(const Vector<String>&);
     243#endif
    235244
    236245private:
  • trunk/Source/WebKit/UIProcess/WebProcessProxy.messages.in

    r230812 r232136  
    6767    DidDeliverMessagePortMessages(uint64_t messageBatchIdentifier)
    6868    DidCheckProcessLocalPortForActivity(uint64_t callbackIdentifier, bool isLocallyReachable)
     69
     70#if PLATFORM(COCOA)
     71    CacheMediaMIMETypes(Vector<String> types)
     72#endif
    6973}
  • trunk/Source/WebKit/WebProcess/WebProcess.h

    r231348 r232136  
    241241#endif
    242242
     243#if PLATFORM(COCOA)
     244    void setMediaMIMETypes(const Vector<String>);
     245#endif
     246
    243247private:
    244248    WebProcess();
  • trunk/Source/WebKit/WebProcess/WebProcess.messages.in

    r231771 r232136  
    136136#endif
    137137#endif
     138
     139#if PLATFORM(COCOA)
     140    SetMediaMIMETypes(Vector<String> types)
     141#endif
    138142}
  • trunk/Source/WebKit/WebProcess/cocoa/WebProcessCocoa.mm

    r231984 r232136  
    4949#import <JavaScriptCore/ConfigFile.h>
    5050#import <JavaScriptCore/Options.h>
     51#import <WebCore/AVFoundationMIMETypeCache.h>
    5152#import <WebCore/AXObjectCache.h>
    5253#import <WebCore/CPUMonitor.h>
     
    182183    pthread_set_fixedpriority_self();
    183184#endif
     185
     186    if (!parameters.mediaMIMETypes.isEmpty())
     187        setMediaMIMETypes(parameters.mediaMIMETypes);
     188    else {
     189        AVFoundationMIMETypeCache::singleton().setCacheMIMETypesCallback([this](const Vector<String>& types) {
     190            parentProcessConnection()->send(Messages::WebProcessProxy::CacheMediaMIMETypes(types), 0);
     191        });
     192    }
    184193}
    185194
     
    335344void WebProcess::platformTerminate()
    336345{
     346    AVFoundationMIMETypeCache::singleton().setCacheMIMETypesCallback(nullptr);
    337347}
    338348
     
    578588#endif   
    579589
     590void WebProcess::setMediaMIMETypes(const Vector<String> types)
     591{
     592    AVFoundationMIMETypeCache::singleton().setSupportedTypes(types);
     593}
     594
    580595} // namespace WebKit
Note: See TracChangeset for help on using the changeset viewer.