Title: [148064] trunk/Source/WebCore
Revision
148064
Author
jer.no...@apple.com
Date
2013-04-09 16:52:23 -0700 (Tue, 09 Apr 2013)

Log Message

hang in mediaSelectionGroupForMediaCharacteristic
https://bugs.webkit.org/show_bug.cgi?id=114054

Reviewed by Eric Carlson.

No new tests; Fixes sporadic hangs in media/ tests.

-[AVURLAsset mediaSelectionGroupForMediaCharacteristic:] can deadlock in certain situations: When AVURLAsset
posts a synchronous AVAssetResourceLoader notification to the main thread, calling -mediaSelectionGroupForMediaCharacteristic:
on the main thread requires IO to occur if the media characteristics are not yet loaded. Instead of blocking,
bail out early if the media characteristics are not yet known.

Add a new method, safeMediaSelectionGroupForLegibleMedia(), which first checks selection group availability
before calling mediaSelectionGroupForMediaCharacteristic:.

* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
(MediaPlayerPrivateAVFoundationObjC):
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::safeMediaSelectionGroupForLegibleMedia): Added.
(WebCore::MediaPlayerPrivateAVFoundationObjC::createAVPlayerItem): Use new safe method.
(WebCore::MediaPlayerPrivateAVFoundationObjC::tracksChanged): Ditto.
(WebCore::MediaPlayerPrivateAVFoundationObjC::processTextTracks): Ditto.
(WebCore::MediaPlayerPrivateAVFoundationObjC::setCurrentTrack): Ditto.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (148063 => 148064)


--- trunk/Source/WebCore/ChangeLog	2013-04-09 23:29:25 UTC (rev 148063)
+++ trunk/Source/WebCore/ChangeLog	2013-04-09 23:52:23 UTC (rev 148064)
@@ -1,3 +1,29 @@
+2013-04-09  Jer Noble  <jer.no...@apple.com>
+
+        hang in mediaSelectionGroupForMediaCharacteristic
+        https://bugs.webkit.org/show_bug.cgi?id=114054
+
+        Reviewed by Eric Carlson.
+
+        No new tests; Fixes sporadic hangs in media/ tests.
+
+        -[AVURLAsset mediaSelectionGroupForMediaCharacteristic:] can deadlock in certain situations: When AVURLAsset
+        posts a synchronous AVAssetResourceLoader notification to the main thread, calling -mediaSelectionGroupForMediaCharacteristic:
+        on the main thread requires IO to occur if the media characteristics are not yet loaded. Instead of blocking,
+        bail out early if the media characteristics are not yet known.
+        
+        Add a new method, safeMediaSelectionGroupForLegibleMedia(), which first checks selection group availability
+        before calling mediaSelectionGroupForMediaCharacteristic:.
+
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
+        (MediaPlayerPrivateAVFoundationObjC):
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::safeMediaSelectionGroupForLegibleMedia): Added.
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::createAVPlayerItem): Use new safe method.
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::tracksChanged): Ditto.
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::processTextTracks): Ditto.
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::setCurrentTrack): Ditto.
+
 2013-04-09  Chris Fleizach  <cfleiz...@apple.com>
 
         AX: Bounding paths should be made available through accessibility

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h (148063 => 148064)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h	2013-04-09 23:29:25 UTC (rev 148063)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h	2013-04-09 23:52:23 UTC (rev 148064)
@@ -32,6 +32,7 @@
 #include <wtf/HashMap.h>
 
 OBJC_CLASS AVURLAsset;
+OBJC_CLASS AVMediaSelectionGroup;
 OBJC_CLASS AVPlayer;
 OBJC_CLASS AVPlayerItem;
 OBJC_CLASS AVPlayerItemLegibleOutput;
@@ -166,6 +167,7 @@
     virtual InbandTextTrackPrivateAVF* currentTrack() OVERRIDE;
     void processTextTracks();
     void clearTextTracks();
+    AVMediaSelectionGroup* safeMediaSelectionGroupForLegibleMedia();
 #endif
 
     RetainPtr<AVURLAsset> m_avAsset;

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


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm	2013-04-09 23:29:25 UTC (rev 148063)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm	2013-04-09 23:52:23 UTC (rev 148064)
@@ -466,7 +466,7 @@
 
     // We enabled automatic media selection because we want alternate audio tracks to be enabled/disabled automatically,
     // but set the selected legible track to nil so text tracks will not be automatically configured.
-    [m_avPlayerItem.get() selectMediaOption:nil inMediaSelectionGroup:[m_avAsset.get() mediaSelectionGroupForMediaCharacteristic:AVMediaCharacteristicLegible]];
+    [m_avPlayerItem.get() selectMediaOption:nil inMediaSelectionGroup:safeMediaSelectionGroupForLegibleMedia()];
 
     [m_legibleOutput.get() setDelegate:m_objcObserver.get() queue:dispatch_get_main_queue()];
     [m_legibleOutput.get() setAdvanceIntervalForDelegateInvocation:legibleOutputAdvanceInterval];
@@ -985,7 +985,7 @@
 
 #if HAVE(AVFOUNDATION_TEXT_TRACK_SUPPORT)
     if (!hasCaptions && m_legibleOutput) {
-        AVMediaSelectionGroupType *legibleGroup = [m_avAsset.get() mediaSelectionGroupForMediaCharacteristic:AVMediaCharacteristicLegible];
+        AVMediaSelectionGroupType *legibleGroup = safeMediaSelectionGroupForLegibleMedia();
         hasCaptions = [[AVMediaSelectionGroup playableMediaSelectionOptionsFromArray:[legibleGroup options]] count];
     }
     if (hasCaptions)
@@ -1296,9 +1296,20 @@
     m_textTracks.clear();
 }
 
+AVMediaSelectionGroupType* MediaPlayerPrivateAVFoundationObjC::safeMediaSelectionGroupForLegibleMedia()
+{
+    if (!m_avAsset)
+        return nil;
+
+    if ([m_avAsset.get() statusOfValueForKey:@"availableMediaCharacteristicsWithMediaSelectionOptions" error:NULL] != AVKeyValueStatusLoaded)
+        return nil;
+
+    return [m_avAsset.get() mediaSelectionGroupForMediaCharacteristic:AVMediaCharacteristicLegible];
+}
+
 void MediaPlayerPrivateAVFoundationObjC::processTextTracks()
 {
-    AVMediaSelectionGroupType *legibleGroup = [m_avAsset.get() mediaSelectionGroupForMediaCharacteristic:AVMediaCharacteristicLegible];
+    AVMediaSelectionGroupType *legibleGroup = safeMediaSelectionGroupForLegibleMedia();
     if (!legibleGroup) {
         LOG(Media, "MediaPlayerPrivateAVFoundationObjC::processTextTracks(%p) - nil mediaSelectionGroup", this);
         return;
@@ -1368,7 +1379,7 @@
 
     LOG(Media, "MediaPlayerPrivateAVFoundationObjC::setCurrentTrack(%p) - selecting media option %p, language = %s", this, mediaSelectionOption, [[[mediaSelectionOption locale] localeIdentifier] UTF8String]);
 
-    [m_avPlayerItem.get() selectMediaOption:mediaSelectionOption inMediaSelectionGroup:[m_avAsset.get() mediaSelectionGroupForMediaCharacteristic:AVMediaCharacteristicLegible]];
+    [m_avPlayerItem.get() selectMediaOption:mediaSelectionOption inMediaSelectionGroup:safeMediaSelectionGroupForLegibleMedia()];
     m_currentTrack = trackPrivate;
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to