Title: [167776] trunk/Source/WebCore
Revision
167776
Author
[email protected]
Date
2014-04-24 14:46:19 -0700 (Thu, 24 Apr 2014)

Log Message

[Mac] don't ask for AVAssetTrack properties before they are available
https://bugs.webkit.org/show_bug.cgi?id=131902
<rdar://problem/16505076>

Reviewed by Brent Fulgham.

No new tests, the behavior this changes can not be tested with a layout test.

* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC): Initialize
    m_cachedTotalBytes.
(WebCore::MediaPlayerPrivateAVFoundationObjC::beginLoadingMetadata): Don't report that
    metadata has been loaded until the track properties we need have been loaded too.
(WebCore::MediaPlayerPrivateAVFoundationObjC::totalBytes): Cache totalBytes instead
    of recalculating it every time.
(WebCore::MediaPlayerPrivateAVFoundationObjC::tracksDidChange): Invalidate cached
    total bytes.
(WebCore::assetTrackMetadataKeyNames): Array of AVAssetTrack properties we use.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (167775 => 167776)


--- trunk/Source/WebCore/ChangeLog	2014-04-24 21:45:55 UTC (rev 167775)
+++ trunk/Source/WebCore/ChangeLog	2014-04-24 21:46:19 UTC (rev 167776)
@@ -1,3 +1,25 @@
+2014-04-24  Eric Carlson  <[email protected]>
+
+        [Mac] don't ask for AVAssetTrack properties before they are available
+        https://bugs.webkit.org/show_bug.cgi?id=131902
+        <rdar://problem/16505076>
+
+        Reviewed by Brent Fulgham.
+
+        No new tests, the behavior this changes can not be tested with a layout test.
+
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC): Initialize
+            m_cachedTotalBytes.
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::beginLoadingMetadata): Don't report that
+            metadata has been loaded until the track properties we need have been loaded too.
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::totalBytes): Cache totalBytes instead
+            of recalculating it every time.
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::tracksDidChange): Invalidate cached
+            total bytes.
+        (WebCore::assetTrackMetadataKeyNames): Array of AVAssetTrack properties we use.
+
 2014-04-24  Myles C. Maxfield  <[email protected]>
 
         Unify platformWidthForGlyph across OS X and iOS

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


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h	2014-04-24 21:45:55 UTC (rev 167775)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h	2014-04-24 21:46:19 UTC (rev 167776)
@@ -322,6 +322,7 @@
     FloatSize m_cachedPresentationSize;
     double m_cachedDuration;
     double m_cachedRate;
+    mutable long long m_cachedTotalBytes;
     unsigned m_pendingStatusChanges;
     int m_cachedItemStatus;
     bool m_cachedLikelyToKeepUp;

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


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm	2014-04-24 21:45:55 UTC (rev 167775)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm	2014-04-24 21:46:19 UTC (rev 167776)
@@ -294,6 +294,7 @@
 
 static NSArray *assetMetadataKeyNames();
 static NSArray *itemKVOProperties();
+static NSArray* assetTrackMetadataKeyNames();
 
 #if !LOG_DISABLED
 static const char *boolString(bool val)
@@ -365,6 +366,7 @@
     , m_currentTextTrack(0)
     , m_cachedDuration(MediaPlayer::invalidTime())
     , m_cachedRate(0)
+    , m_cachedTotalBytes(0)
     , m_pendingStatusChanges(0)
     , m_cachedItemStatus(MediaPlayerAVPlayerItemStatusDoesNotExist)
     , m_cachedLikelyToKeepUp(false)
@@ -784,9 +786,33 @@
 void MediaPlayerPrivateAVFoundationObjC::beginLoadingMetadata()
 {
     LOG(Media, "MediaPlayerPrivateAVFoundationObjC::beginLoadingMetadata(%p) - requesting metadata loading", this);
-    [m_avAsset.get() loadValuesAsynchronouslyForKeys:[assetMetadataKeyNames() retain] completionHandler:^{
-        [m_objcObserver.get() metadataLoaded];
+
+    dispatch_group_t metadataLoadingGroup = dispatch_group_create();
+    dispatch_group_enter(metadataLoadingGroup);
+    auto weakThis = createWeakPtr();
+    [m_avAsset.get() loadValuesAsynchronouslyForKeys:assetMetadataKeyNames() completionHandler:^{
+
+        callOnMainThread([weakThis, metadataLoadingGroup] {
+            if (weakThis && [weakThis->m_avAsset.get() statusOfValueForKey:@"tracks" error:nil] == AVKeyValueStatusLoaded) {
+                for (AVAssetTrack *track in [weakThis->m_avAsset.get() tracks]) {
+                    dispatch_group_enter(metadataLoadingGroup);
+                    [track loadValuesAsynchronouslyForKeys:assetTrackMetadataKeyNames() completionHandler:^{
+                        dispatch_group_leave(metadataLoadingGroup);
+                    }];
+                }
+            }
+            dispatch_group_leave(metadataLoadingGroup);
+        });
     }];
+
+    dispatch_group_notify(metadataLoadingGroup, dispatch_get_main_queue(), ^{
+        callOnMainThread([weakThis] {
+            if (weakThis)
+                [weakThis->m_objcObserver.get() metadataLoaded];
+        });
+
+        dispatch_release(metadataLoadingGroup);
+    });
 }
 
 MediaPlayerPrivateAVFoundation::ItemStatus MediaPlayerPrivateAVFoundationObjC::playerItemStatus() const
@@ -1131,11 +1157,13 @@
     if (!metaDataAvailable())
         return 0;
 
-    long long totalMediaSize = 0;
+    if (m_cachedTotalBytes)
+        return m_cachedTotalBytes;
+
     for (AVPlayerItemTrack *thisTrack in m_cachedTracks.get())
-        totalMediaSize += [[thisTrack assetTrack] totalSampleDataLength];
+        m_cachedTotalBytes += [[thisTrack assetTrack] totalSampleDataLength];
 
-    return totalMediaSize;
+    return m_cachedTotalBytes;
 }
 
 void MediaPlayerPrivateAVFoundationObjC::setAsset(id asset)
@@ -2361,6 +2389,7 @@
 void MediaPlayerPrivateAVFoundationObjC::tracksDidChange(RetainPtr<NSArray> tracks)
 {
     m_cachedTracks = tracks;
+    m_cachedTotalBytes = 0;
 
     tracksChanged();
     updateStates();
@@ -2442,6 +2471,13 @@
     return keys;
 }
 
+NSArray* assetTrackMetadataKeyNames()
+{
+    static NSArray* keys = [[NSArray alloc] initWithObjects:@"totalSampleDataLength", @"mediaType", nil];
+
+    return keys;
+}
+
 } // namespace WebCore
 
 @implementation WebCoreAVFMovieObserver
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to