Changeset 202678 in webkit


Ignore:
Timestamp:
Jun 30, 2016 7:26:14 AM (8 years ago)
Author:
eric.carlson@apple.com
Message:

[Mac] Crash registering AVFoundation media engine
https://bugs.webkit.org/show_bug.cgi?id=159269
<rdar://problem/27017656>

Reviewed by Brent Fulgham.

  • platform/graphics/MediaPlayer.cpp:

(WebCore::mediaEngineVectorLock): New, return the static Lock.
(WebCore::haveMediaEnginesVector): Wrap the naked bool.
(WebCore::buildMediaEnginesVector): Assert that the lock is locked.
(WebCore::installedMediaEngines): Hold the lock while checking/rebuilding the vector.
(WebCore::MediaPlayer::resetMediaEngines): Hold the lock while clearing the vector.

Use SOFT_LINK_CLASS_FOR_SOURCE instead of SOFT_LINK_CLASS because the former uses dispatch_once
to ensure that class loading is thread safe.

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

(WebCore::MediaPlayerPrivateAVFoundationObjC::registerMediaEngine):
(WebCore::assetCacheForPath):
(WebCore::MediaPlayerPrivateAVFoundationObjC::originsInMediaCache):
(WebCore::MediaPlayerPrivateAVFoundationObjC::clearMediaCache):
(WebCore::MediaPlayerPrivateAVFoundationObjC::clearMediaCacheForOrigins):
(WebCore::MediaPlayerPrivateAVFoundationObjC::createAVPlayerLayer):
(WebCore::MediaPlayerPrivateAVFoundationObjC::createAVAssetForURL):
(WebCore::MediaPlayerPrivateAVFoundationObjC::createAVPlayer):
(WebCore::MediaPlayerPrivateAVFoundationObjC::createAVPlayerItem):
(WebCore::MediaPlayerPrivateAVFoundationObjC::createVideoOutput):
(WebCore::MediaPlayerPrivateAVFoundationObjC::createOpenGLVideoOutput):
(WebCore::MediaPlayerPrivateAVFoundationObjC::waitForVideoOutputMediaDataWillChange):
(WebCore::MediaPlayerPrivateAVFoundationObjC::outputMediaDataWillChange):
(-[WebCoreAVFPullDelegate setCallback:]):
(-[WebCoreAVFPullDelegate outputMediaDataWillChange:]):
(-[WebCoreAVFPullDelegate outputSequenceWasFlushed:]):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r202677 r202678  
     12016-06-30  Eric Carlson  <eric.carlson@apple.com>
     2
     3        [Mac] Crash registering AVFoundation media engine
     4        https://bugs.webkit.org/show_bug.cgi?id=159269
     5        <rdar://problem/27017656>
     6
     7        Reviewed by Brent Fulgham.
     8
     9        * platform/graphics/MediaPlayer.cpp:
     10        (WebCore::mediaEngineVectorLock): New, return the static Lock.
     11        (WebCore::haveMediaEnginesVector): Wrap the naked bool.
     12        (WebCore::buildMediaEnginesVector): Assert that the lock is locked.
     13        (WebCore::installedMediaEngines): Hold the lock while checking/rebuilding the vector.
     14        (WebCore::MediaPlayer::resetMediaEngines): Hold the lock while clearing the vector.
     15
     16        Use SOFT_LINK_CLASS_FOR_SOURCE instead of SOFT_LINK_CLASS because the former uses dispatch_once
     17        to ensure that class loading is thread safe.
     18        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
     19        (WebCore::MediaPlayerPrivateAVFoundationObjC::registerMediaEngine):
     20        (WebCore::assetCacheForPath):
     21        (WebCore::MediaPlayerPrivateAVFoundationObjC::originsInMediaCache):
     22        (WebCore::MediaPlayerPrivateAVFoundationObjC::clearMediaCache):
     23        (WebCore::MediaPlayerPrivateAVFoundationObjC::clearMediaCacheForOrigins):
     24        (WebCore::MediaPlayerPrivateAVFoundationObjC::createAVPlayerLayer):
     25        (WebCore::MediaPlayerPrivateAVFoundationObjC::createAVAssetForURL):
     26        (WebCore::MediaPlayerPrivateAVFoundationObjC::createAVPlayer):
     27        (WebCore::MediaPlayerPrivateAVFoundationObjC::createAVPlayerItem):
     28        (WebCore::MediaPlayerPrivateAVFoundationObjC::createVideoOutput):
     29        (WebCore::MediaPlayerPrivateAVFoundationObjC::createOpenGLVideoOutput):
     30        (WebCore::MediaPlayerPrivateAVFoundationObjC::waitForVideoOutputMediaDataWillChange):
     31        (WebCore::MediaPlayerPrivateAVFoundationObjC::outputMediaDataWillChange):
     32        (-[WebCoreAVFPullDelegate setCallback:]):
     33        (-[WebCoreAVFPullDelegate outputMediaDataWillChange:]):
     34        (-[WebCoreAVFPullDelegate outputSequenceWasFlushed:]):
     35
    1362016-06-30  Carlos Garcia Campos  <cgarcia@igalia.com>
    237
  • trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp

    r201474 r202678  
    179179static void addMediaEngine(CreateMediaEnginePlayer, MediaEngineSupportedTypes, MediaEngineSupportsType, MediaEngineOriginsInMediaCache, MediaEngineClearMediaCache, MediaEngineClearMediaCacheForOrigins, MediaEngineSupportsKeySystem);
    180180
    181 static bool haveMediaEnginesVector;
     181static Lock& mediaEngineVectorLock()
     182{
     183    static NeverDestroyed<Lock> lock;
     184    return lock;
     185}
     186
     187static bool& haveMediaEnginesVector()
     188{
     189    static bool haveVector;
     190    return haveVector;
     191}
    182192
    183193static Vector<MediaPlayerFactory>& mutableInstalledMediaEnginesVector()
     
    189199static void buildMediaEnginesVector()
    190200{
     201    ASSERT(mediaEngineVectorLock().isLocked());
     202
    191203#if USE(AVFOUNDATION)
    192204    if (Settings::isAVFoundationEnabled()) {
     
    224236#endif
    225237
    226     haveMediaEnginesVector = true;
     238    haveMediaEnginesVector() = true;
    227239}
    228240
    229241static const Vector<MediaPlayerFactory>& installedMediaEngines()
    230242{
    231     if (!haveMediaEnginesVector)
    232         buildMediaEnginesVector();
     243    {
     244        LockHolder lock(mediaEngineVectorLock());
     245        if (!haveMediaEnginesVector())
     246            buildMediaEnginesVector();
     247    }
     248
    233249    return mutableInstalledMediaEnginesVector();
    234250}
     
    13281344void MediaPlayer::resetMediaEngines()
    13291345{
     1346    LockHolder lock(mediaEngineVectorLock());
     1347
    13301348    mutableInstalledMediaEnginesVector().clear();
    1331     haveMediaEnginesVector = false;
     1349    haveMediaEnginesVector() = false;
    13321350}
    13331351
  • trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm

    r202546 r202678  
    143143typedef AVMediaSelectionGroup AVMediaSelectionGroupType;
    144144typedef AVMediaSelectionOption AVMediaSelectionOptionType;
     145typedef AVAssetCache AVAssetCacheType;
    145146
    146147#pragma mark - Soft Linking
     
    153154SOFT_LINK_FRAMEWORK_OPTIONAL(CoreImage)
    154155
    155 SOFT_LINK_CLASS(AVFoundation, AVPlayer)
    156 SOFT_LINK_CLASS(AVFoundation, AVPlayerItem)
    157 SOFT_LINK_CLASS(AVFoundation, AVPlayerItemVideoOutput)
    158 SOFT_LINK_CLASS(AVFoundation, AVPlayerLayer)
    159 SOFT_LINK_CLASS(AVFoundation, AVURLAsset)
    160 SOFT_LINK_CLASS(AVFoundation, AVAssetImageGenerator)
    161 SOFT_LINK_CLASS(AVFoundation, AVMetadataItem)
    162 SOFT_LINK_CLASS(AVFoundation, AVAssetCache)
     156SOFT_LINK_CLASS_FOR_SOURCE(WebCore, AVFoundation, AVPlayer)
     157SOFT_LINK_CLASS_FOR_SOURCE(WebCore, AVFoundation, AVPlayerItem)
     158SOFT_LINK_CLASS_FOR_SOURCE(WebCore, AVFoundation, AVPlayerItemVideoOutput)
     159SOFT_LINK_CLASS_FOR_SOURCE(WebCore, AVFoundation, AVPlayerLayer)
     160SOFT_LINK_CLASS_FOR_SOURCE(WebCore, AVFoundation, AVURLAsset)
     161SOFT_LINK_CLASS_FOR_SOURCE(WebCore, AVFoundation, AVAssetImageGenerator)
     162SOFT_LINK_CLASS_FOR_SOURCE(WebCore, AVFoundation, AVMetadataItem)
     163SOFT_LINK_CLASS_FOR_SOURCE(WebCore, AVFoundation, AVAssetCache)
    163164
    164165SOFT_LINK_CLASS(CoreImage, CIContext)
     
    183184SOFT_LINK_POINTER_OPTIONAL(AVFoundation, AVURLAssetClientBundleIdentifierKey, NSString *)
    184185
    185 #define AVPlayer getAVPlayerClass()
    186 #define AVPlayerItem getAVPlayerItemClass()
    187 #define AVPlayerLayer getAVPlayerLayerClass()
    188 #define AVURLAsset getAVURLAssetClass()
    189 #define AVAssetImageGenerator getAVAssetImageGeneratorClass()
    190 #define AVMetadataItem getAVMetadataItemClass()
     186#define AVPlayer initAVPlayer()
     187#define AVPlayerItem initAVPlayerItem()
     188#define AVPlayerLayer initAVPlayerLayer()
     189#define AVURLAsset initAVURLAsset()
     190#define AVAssetImageGenerator initAVAssetImageGenerator()
     191#define AVPlayerItemVideoOutput initAVPlayerItemVideoOutput()
     192#define AVMetadataItem initAVMetadataItem()
     193#define AVAssetCache initAVAssetCache()
    191194
    192195#define AVAudioTimePitchAlgorithmSpectral getAVAudioTimePitchAlgorithmSpectral()
     
    433436}
    434437
    435 static AVAssetCache *assetCacheForPath(const String& path)
     438static AVAssetCacheType *assetCacheForPath(const String& path)
    436439{
    437440    NSURL *assetCacheURL;
     
    442445        assetCacheURL = [NSURL fileURLWithPath:path isDirectory:YES];
    443446
    444     return [getAVAssetCacheClass() assetCacheWithURL:assetCacheURL];
     447    return [initAVAssetCache() assetCacheWithURL:assetCacheURL];
    445448}
    446449
     
    468471    LOG(Media, "MediaPlayerPrivateAVFoundationObjC::clearMediaCache()");
    469472   
    470     AVAssetCache* assetCache = assetCacheForPath(path);
     473    AVAssetCacheType* assetCache = assetCacheForPath(path);
    471474   
    472475    for (NSString *key in [assetCache allKeys]) {
     
    511514{
    512515    LOG(Media, "MediaPlayerPrivateAVFoundationObjC::clearMediaCacheForOrigins()");
    513     AVAssetCache* assetCache = assetCacheForPath(path);
     516    AVAssetCacheType* assetCache = assetCacheForPath(path);
    514517    for (NSString *key in [assetCache allKeys]) {
    515518        URL keyAsURL = URL(URL(), key);
     
    731734        return;
    732735
    733     m_videoLayer = adoptNS([allocAVPlayerLayerInstance() init]);
     736    m_videoLayer = adoptNS([[AVPlayerLayer alloc] init]);
    734737    [m_videoLayer setPlayer:m_avPlayer.get()];
    735738    [m_videoLayer setBackgroundColor:cachedCGColor(Color::black)];
     
    977980
    978981    NSURL *cocoaURL = canonicalURL(url);
    979     m_avAsset = adoptNS([allocAVURLAssetInstance() initWithURL:cocoaURL options:options.get()]);
     982    m_avAsset = adoptNS([[AVURLAsset alloc] initWithURL:cocoaURL options:options.get()]);
    980983
    981984#if HAVE(AVFOUNDATION_LOADER_DELEGATE)
     
    10271030    setDelayCallbacks(true);
    10281031
    1029     m_avPlayer = adoptNS([allocAVPlayerInstance() init]);
     1032    m_avPlayer = adoptNS([[AVPlayer alloc] init]);
    10301033    for (NSString *keyName in playerKVOProperties())
    10311034        [m_avPlayer.get() addObserver:m_objcObserver.get() forKeyPath:keyName options:NSKeyValueObservingOptionNew context:(void *)MediaPlayerAVFoundationObservationContextPlayer];
     
    10731076
    10741077    // Create the player item so we can load media data.
    1075     m_avPlayerItem = adoptNS([allocAVPlayerItemInstance() initWithAsset:m_avAsset.get()]);
     1078    m_avPlayerItem = adoptNS([[AVPlayerItem alloc] initWithAsset:m_avAsset.get()]);
    10761079
    10771080    [[NSNotificationCenter defaultCenter] addObserver:m_objcObserver.get() selector:@selector(didEnd:) name:AVPlayerItemDidPlayToEndTimeNotification object:m_avPlayerItem.get()];
     
    10901093
    10911094    RetainPtr<NSArray> subtypes = adoptNS([[NSArray alloc] initWithObjects:[NSNumber numberWithUnsignedInt:kCMSubtitleFormatType_WebVTT], nil]);
    1092     m_legibleOutput = adoptNS([allocAVPlayerItemLegibleOutputInstance() initWithMediaSubtypesForNativeRepresentation:subtypes.get()]);
     1095    m_legibleOutput = adoptNS([[AVPlayerItemLegibleOutput alloc] initWithMediaSubtypesForNativeRepresentation:subtypes.get()]);
    10931096    [m_legibleOutput.get() setSuppressesPlayerRendering:YES];
    10941097
     
    22852288                                nil];
    22862289#endif
    2287     m_videoOutput = adoptNS([allocAVPlayerItemVideoOutputInstance() initWithPixelBufferAttributes:attributes]);
     2290    m_videoOutput = adoptNS([[AVPlayerItemVideoOutput alloc] initWithPixelBufferAttributes:attributes]);
    22882291    ASSERT(m_videoOutput);
    22892292
     
    24092412    NSDictionary* attributes = @{(NSString *)kCVPixelBufferIOSurfaceOpenGLFBOCompatibilityKey: @YES};
    24102413#endif
    2411     m_openGLVideoOutput = adoptNS([allocAVPlayerItemVideoOutputInstance() initWithPixelBufferAttributes:attributes]);
     2414    m_openGLVideoOutput = adoptNS([[AVPlayerItemVideoOutput alloc] initWithPixelBufferAttributes:attributes]);
    24122415    ASSERT(m_openGLVideoOutput);
    24132416
     
    24932496}
    24942497
    2495 void MediaPlayerPrivateAVFoundationObjC::outputMediaDataWillChange(AVPlayerItemVideoOutput*)
     2498void MediaPlayerPrivateAVFoundationObjC::outputMediaDataWillChange(AVPlayerItemVideoOutputType *)
    24962499{
    24972500    dispatch_semaphore_signal(m_videoOutputSemaphore);
     
    36013604}
    36023605
    3603 - (void)outputMediaDataWillChange:(AVPlayerItemVideoOutput *)output
     3606- (void)outputMediaDataWillChange:(AVPlayerItemVideoOutputType *)output
    36043607{
    36053608    if (m_callback)
     
    36073610}
    36083611
    3609 - (void)outputSequenceWasFlushed:(AVPlayerItemVideoOutput *)output
     3612- (void)outputSequenceWasFlushed:(AVPlayerItemVideoOutputType *)output
    36103613{
    36113614    UNUSED_PARAM(output);
Note: See TracChangeset for help on using the changeset viewer.