Title: [276981] trunk/Source/WebCore
Revision
276981
Author
jer.no...@apple.com
Date
2021-05-04 13:44:40 -0700 (Tue, 04 May 2021)

Log Message

[Cocoa] Cache the value of MediaPlayerPrivateAVFoundationObjC::assetStatus()
https://bugs.webkit.org/show_bug.cgi?id=225262

Reviewed by Eric Carlson.

Calling into assetStatus() requires querying the load state and value of nine different
AVAsset properties, which adds up if assetStatus() is called often. Once the assetStatus()
value reaches the Loaded state, cache that property, and that of the AVAsset.playable
property, so subsequent queries are just an ivar lookup.

* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::assetStatus const):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (276980 => 276981)


--- trunk/Source/WebCore/ChangeLog	2021-05-04 20:32:11 UTC (rev 276980)
+++ trunk/Source/WebCore/ChangeLog	2021-05-04 20:44:40 UTC (rev 276981)
@@ -1,5 +1,21 @@
 2021-05-04  Jer Noble  <jer.no...@apple.com>
 
+        [Cocoa] Cache the value of MediaPlayerPrivateAVFoundationObjC::assetStatus()
+        https://bugs.webkit.org/show_bug.cgi?id=225262
+
+        Reviewed by Eric Carlson.
+
+        Calling into assetStatus() requires querying the load state and value of nine different
+        AVAsset properties, which adds up if assetStatus() is called often. Once the assetStatus()
+        value reaches the Loaded state, cache that property, and that of the AVAsset.playable
+        property, so subsequent queries are just an ivar lookup.
+
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::assetStatus const):
+
+2021-05-04  Jer Noble  <jer.no...@apple.com>
+
         REGRESSION (r276883): [Debug] ASSERTION FAILED: index != notFound in WebCore::PlatformMediaSessionManager::setCurrentSession()
         https://bugs.webkit.org/show_bug.cgi?id=225332
         <rdar://problem/77476145>

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


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h	2021-05-04 20:32:11 UTC (rev 276980)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h	2021-05-04 20:44:40 UTC (rev 276981)
@@ -415,6 +415,8 @@
     bool m_haveBeenAskedToCreateLayer { false };
     bool m_cachedCanPlayFastForward { false };
     bool m_cachedCanPlayFastReverse { false };
+    mutable bool m_cachedAssetIsLoaded { false };
+    mutable Optional<bool> m_cachedAssetIsPlayable;
     bool m_muted { false };
     bool m_shouldObserveTimeControlStatus { false };
     mutable Optional<bool> m_tracksArePlayable;

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


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm	2021-05-04 20:32:11 UTC (rev 276980)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm	2021-05-04 20:44:40 UTC (rev 276981)
@@ -1689,21 +1689,24 @@
     if (!m_avAsset)
         return MediaPlayerAVAssetStatusDoesNotExist;
 
-    for (NSString *keyName in assetMetadataKeyNames()) {
-        NSError *error = nil;
-        AVKeyValueStatus keyStatus = [m_avAsset.get() statusOfValueForKey:keyName error:&error];
+    if (!m_cachedAssetIsLoaded) {
+        for (NSString *keyName in assetMetadataKeyNames()) {
+            NSError *error = nil;
+            AVKeyValueStatus keyStatus = [m_avAsset.get() statusOfValueForKey:keyName error:&error];
 
-        if (error)
-            ERROR_LOG(LOGIDENTIFIER, "failed for ", [keyName UTF8String], ", error = ", [[error localizedDescription] UTF8String]);
+            if (error)
+                ERROR_LOG(LOGIDENTIFIER, "failed for ", [keyName UTF8String], ", error = ", [[error localizedDescription] UTF8String]);
 
-        if (keyStatus < AVKeyValueStatusLoaded)
-            return MediaPlayerAVAssetStatusLoading;// At least one key is not loaded yet.
-        
-        if (keyStatus == AVKeyValueStatusFailed)
-            return MediaPlayerAVAssetStatusFailed; // At least one key could not be loaded.
+            if (keyStatus < AVKeyValueStatusLoaded)
+                return MediaPlayerAVAssetStatusLoading; // At least one key is not loaded yet.
 
-        if (keyStatus == AVKeyValueStatusCancelled)
-            return MediaPlayerAVAssetStatusCancelled; // Loading of at least one key was cancelled.
+            if (keyStatus == AVKeyValueStatusFailed)
+                return MediaPlayerAVAssetStatusFailed; // At least one key could not be loaded.
+
+            if (keyStatus == AVKeyValueStatusCancelled)
+                return MediaPlayerAVAssetStatusCancelled; // Loading of at least one key was cancelled.
+        }
+        m_cachedAssetIsLoaded = true;
     }
 
     if (!player()->shouldCheckHardwareSupport())
@@ -1719,7 +1722,10 @@
         }
     }
 
-    if ([[m_avAsset.get() valueForKey:@"playable"] boolValue] && m_tracksArePlayable.value())
+    if (!m_cachedAssetIsPlayable)
+        m_cachedAssetIsPlayable = [[m_avAsset.get() valueForKey:@"playable"] boolValue];
+
+    if (*m_cachedAssetIsPlayable && m_tracksArePlayable.value())
         return MediaPlayerAVAssetStatusPlayable;
 
     return MediaPlayerAVAssetStatusLoaded;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to