Title: [267046] branches/safari-610-branch/Source
Revision
267046
Author
[email protected]
Date
2020-09-14 15:17:23 -0700 (Mon, 14 Sep 2020)

Log Message

Cherry-pick r266844. rdar://problem/68880990

    [Cocoa] PERF: Don't instantiate AVPlayer-based audio decoders or renderers if an element is initially muted.
    https://bugs.webkit.org/show_bug.cgi?id=216299

    Reviewed by Eric Carlson.

    Source/WebCore:

    When an AVPlayer is created, even if muted, it will still instantiate an audio decoder and renderer if the
    AVAsset in the current player item has an audio track. Ostensibly, this is so that an unmute operation is
    instantaneous, as it's merely applying a zero gain to the decoded audio. However for web content, there's
    many autoplaying, muted <video> elements which may never be un-muted before being destroyed.

    Implement a policy where, if an AVPlayer is initially muted, we adopt AVFoundation SPI to forcibly prevent
    audio decoding and rendering until the first time the AVPlayer is unmuted. This means the first un-mute may
    not be instantaneous, as an audio decoder will have to be created and fed before any audio is rendered.

    There's some incorrect caching of mute state at the MediaPlayer level; so MediaPlayer and MPPAVFoundationObjC
    can get their respective m_muted states out of sync. Make sure that HTMLMediaElement always sets muted state
    after creating a MediaPlayer and that, respectively, MPPAVFoundationObjC always queries it's parent MediaPlayer's
    mute state when it in turn is created.

    * html/HTMLMediaElement.cpp:
    (WebCore::HTMLMediaElement::createMediaPlayer):
    * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
    (WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC):
    (WebCore::MediaPlayerPrivateAVFoundationObjC::createAVPlayer):
    (WebCore::MediaPlayerPrivateAVFoundationObjC::setMuted):

    Source/WebCore/PAL:

    * pal/spi/cocoa/AVFoundationSPI.h:

    Source/WTF:

    * wtf/PlatformHave.h:

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266844 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Diff

Modified: branches/safari-610-branch/Source/WTF/ChangeLog (267045 => 267046)


--- branches/safari-610-branch/Source/WTF/ChangeLog	2020-09-14 22:17:19 UTC (rev 267045)
+++ branches/safari-610-branch/Source/WTF/ChangeLog	2020-09-14 22:17:23 UTC (rev 267046)
@@ -1,3 +1,55 @@
+2020-09-14  Alan Coon  <[email protected]>
+
+        Cherry-pick r266844. rdar://problem/68880990
+
+    [Cocoa] PERF: Don't instantiate AVPlayer-based audio decoders or renderers if an element is initially muted.
+    https://bugs.webkit.org/show_bug.cgi?id=216299
+    
+    Reviewed by Eric Carlson.
+    
+    Source/WebCore:
+    
+    When an AVPlayer is created, even if muted, it will still instantiate an audio decoder and renderer if the
+    AVAsset in the current player item has an audio track. Ostensibly, this is so that an unmute operation is
+    instantaneous, as it's merely applying a zero gain to the decoded audio. However for web content, there's
+    many autoplaying, muted <video> elements which may never be un-muted before being destroyed.
+    
+    Implement a policy where, if an AVPlayer is initially muted, we adopt AVFoundation SPI to forcibly prevent
+    audio decoding and rendering until the first time the AVPlayer is unmuted. This means the first un-mute may
+    not be instantaneous, as an audio decoder will have to be created and fed before any audio is rendered.
+    
+    There's some incorrect caching of mute state at the MediaPlayer level; so MediaPlayer and MPPAVFoundationObjC
+    can get their respective m_muted states out of sync. Make sure that HTMLMediaElement always sets muted state
+    after creating a MediaPlayer and that, respectively, MPPAVFoundationObjC always queries it's parent MediaPlayer's
+    mute state when it in turn is created.
+    
+    * html/HTMLMediaElement.cpp:
+    (WebCore::HTMLMediaElement::createMediaPlayer):
+    * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+    (WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC):
+    (WebCore::MediaPlayerPrivateAVFoundationObjC::createAVPlayer):
+    (WebCore::MediaPlayerPrivateAVFoundationObjC::setMuted):
+    
+    Source/WebCore/PAL:
+    
+    * pal/spi/cocoa/AVFoundationSPI.h:
+    
+    Source/WTF:
+    
+    * wtf/PlatformHave.h:
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266844 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-09-10  Jer Noble  <[email protected]>
+
+            [Cocoa] PERF: Don't instantiate AVPlayer-based audio decoders or renderers if an element is initially muted.
+            https://bugs.webkit.org/show_bug.cgi?id=216299
+
+            Reviewed by Eric Carlson.
+
+            * wtf/PlatformHave.h:
+
 2020-09-10  Alan Coon  <[email protected]>
 
         Cherry-pick r266406. rdar://problem/68652786

Modified: branches/safari-610-branch/Source/WTF/wtf/PlatformHave.h (267045 => 267046)


--- branches/safari-610-branch/Source/WTF/wtf/PlatformHave.h	2020-09-14 22:17:19 UTC (rev 267045)
+++ branches/safari-610-branch/Source/WTF/wtf/PlatformHave.h	2020-09-14 22:17:23 UTC (rev 267046)
@@ -495,6 +495,10 @@
 #define HAVE_AVPLAYER_RESOURCE_CONSERVATION_LEVEL 1
 #endif
 
+#if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 110000) || (PLATFORM(IOS_FAMILY) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 140000)
+#define HAVE_AVPLAYER_SUPRESSES_AUDIO_RENDERING 1
+#endif
+
 #if (PLATFORM(MAC) && __MAC_OS_X_VERSION_MAX_ALLOWED < 101404)
 #define HAVE_VIDEO_PERFORMANCE_METRICS 1
 #endif

Modified: branches/safari-610-branch/Source/WebCore/ChangeLog (267045 => 267046)


--- branches/safari-610-branch/Source/WebCore/ChangeLog	2020-09-14 22:17:19 UTC (rev 267045)
+++ branches/safari-610-branch/Source/WebCore/ChangeLog	2020-09-14 22:17:23 UTC (rev 267046)
@@ -1,5 +1,76 @@
 2020-09-14  Alan Coon  <[email protected]>
 
+        Cherry-pick r266844. rdar://problem/68880990
+
+    [Cocoa] PERF: Don't instantiate AVPlayer-based audio decoders or renderers if an element is initially muted.
+    https://bugs.webkit.org/show_bug.cgi?id=216299
+    
+    Reviewed by Eric Carlson.
+    
+    Source/WebCore:
+    
+    When an AVPlayer is created, even if muted, it will still instantiate an audio decoder and renderer if the
+    AVAsset in the current player item has an audio track. Ostensibly, this is so that an unmute operation is
+    instantaneous, as it's merely applying a zero gain to the decoded audio. However for web content, there's
+    many autoplaying, muted <video> elements which may never be un-muted before being destroyed.
+    
+    Implement a policy where, if an AVPlayer is initially muted, we adopt AVFoundation SPI to forcibly prevent
+    audio decoding and rendering until the first time the AVPlayer is unmuted. This means the first un-mute may
+    not be instantaneous, as an audio decoder will have to be created and fed before any audio is rendered.
+    
+    There's some incorrect caching of mute state at the MediaPlayer level; so MediaPlayer and MPPAVFoundationObjC
+    can get their respective m_muted states out of sync. Make sure that HTMLMediaElement always sets muted state
+    after creating a MediaPlayer and that, respectively, MPPAVFoundationObjC always queries it's parent MediaPlayer's
+    mute state when it in turn is created.
+    
+    * html/HTMLMediaElement.cpp:
+    (WebCore::HTMLMediaElement::createMediaPlayer):
+    * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+    (WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC):
+    (WebCore::MediaPlayerPrivateAVFoundationObjC::createAVPlayer):
+    (WebCore::MediaPlayerPrivateAVFoundationObjC::setMuted):
+    
+    Source/WebCore/PAL:
+    
+    * pal/spi/cocoa/AVFoundationSPI.h:
+    
+    Source/WTF:
+    
+    * wtf/PlatformHave.h:
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266844 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-09-10  Jer Noble  <[email protected]>
+
+            [Cocoa] PERF: Don't instantiate AVPlayer-based audio decoders or renderers if an element is initially muted.
+            https://bugs.webkit.org/show_bug.cgi?id=216299
+
+            Reviewed by Eric Carlson.
+
+            When an AVPlayer is created, even if muted, it will still instantiate an audio decoder and renderer if the
+            AVAsset in the current player item has an audio track. Ostensibly, this is so that an unmute operation is
+            instantaneous, as it's merely applying a zero gain to the decoded audio. However for web content, there's
+            many autoplaying, muted <video> elements which may never be un-muted before being destroyed.
+
+            Implement a policy where, if an AVPlayer is initially muted, we adopt AVFoundation SPI to forcibly prevent
+            audio decoding and rendering until the first time the AVPlayer is unmuted. This means the first un-mute may
+            not be instantaneous, as an audio decoder will have to be created and fed before any audio is rendered.
+
+            There's some incorrect caching of mute state at the MediaPlayer level; so MediaPlayer and MPPAVFoundationObjC
+            can get their respective m_muted states out of sync. Make sure that HTMLMediaElement always sets muted state
+            after creating a MediaPlayer and that, respectively, MPPAVFoundationObjC always queries it's parent MediaPlayer's
+            mute state when it in turn is created.
+
+            * html/HTMLMediaElement.cpp:
+            (WebCore::HTMLMediaElement::createMediaPlayer):
+            * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+            (WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC):
+            (WebCore::MediaPlayerPrivateAVFoundationObjC::createAVPlayer):
+            (WebCore::MediaPlayerPrivateAVFoundationObjC::setMuted):
+
+2020-09-14  Alan Coon  <[email protected]>
+
         Cherry-pick r266818. rdar://problem/68881035
 
     [Repaint] RenderElement::setStyle may issue redundant repaint

Modified: branches/safari-610-branch/Source/WebCore/PAL/ChangeLog (267045 => 267046)


--- branches/safari-610-branch/Source/WebCore/PAL/ChangeLog	2020-09-14 22:17:19 UTC (rev 267045)
+++ branches/safari-610-branch/Source/WebCore/PAL/ChangeLog	2020-09-14 22:17:23 UTC (rev 267046)
@@ -1,3 +1,55 @@
+2020-09-14  Alan Coon  <[email protected]>
+
+        Cherry-pick r266844. rdar://problem/68880990
+
+    [Cocoa] PERF: Don't instantiate AVPlayer-based audio decoders or renderers if an element is initially muted.
+    https://bugs.webkit.org/show_bug.cgi?id=216299
+    
+    Reviewed by Eric Carlson.
+    
+    Source/WebCore:
+    
+    When an AVPlayer is created, even if muted, it will still instantiate an audio decoder and renderer if the
+    AVAsset in the current player item has an audio track. Ostensibly, this is so that an unmute operation is
+    instantaneous, as it's merely applying a zero gain to the decoded audio. However for web content, there's
+    many autoplaying, muted <video> elements which may never be un-muted before being destroyed.
+    
+    Implement a policy where, if an AVPlayer is initially muted, we adopt AVFoundation SPI to forcibly prevent
+    audio decoding and rendering until the first time the AVPlayer is unmuted. This means the first un-mute may
+    not be instantaneous, as an audio decoder will have to be created and fed before any audio is rendered.
+    
+    There's some incorrect caching of mute state at the MediaPlayer level; so MediaPlayer and MPPAVFoundationObjC
+    can get their respective m_muted states out of sync. Make sure that HTMLMediaElement always sets muted state
+    after creating a MediaPlayer and that, respectively, MPPAVFoundationObjC always queries it's parent MediaPlayer's
+    mute state when it in turn is created.
+    
+    * html/HTMLMediaElement.cpp:
+    (WebCore::HTMLMediaElement::createMediaPlayer):
+    * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+    (WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC):
+    (WebCore::MediaPlayerPrivateAVFoundationObjC::createAVPlayer):
+    (WebCore::MediaPlayerPrivateAVFoundationObjC::setMuted):
+    
+    Source/WebCore/PAL:
+    
+    * pal/spi/cocoa/AVFoundationSPI.h:
+    
+    Source/WTF:
+    
+    * wtf/PlatformHave.h:
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@266844 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2020-09-10  Jer Noble  <[email protected]>
+
+            [Cocoa] PERF: Don't instantiate AVPlayer-based audio decoders or renderers if an element is initially muted.
+            https://bugs.webkit.org/show_bug.cgi?id=216299
+
+            Reviewed by Eric Carlson.
+
+            * pal/spi/cocoa/AVFoundationSPI.h:
+
 2020-08-20  Per Arne Vollan  <[email protected]>
 
         [macOS] Web pages are not responding correctly to changes in "Reduce motion" setting

Modified: branches/safari-610-branch/Source/WebCore/PAL/pal/spi/cocoa/AVFoundationSPI.h (267045 => 267046)


--- branches/safari-610-branch/Source/WebCore/PAL/pal/spi/cocoa/AVFoundationSPI.h	2020-09-14 22:17:19 UTC (rev 267045)
+++ branches/safari-610-branch/Source/WebCore/PAL/pal/spi/cocoa/AVFoundationSPI.h	2020-09-14 22:17:23 UTC (rev 267046)
@@ -72,6 +72,12 @@
 @end
 #endif
 
+#if HAVE(AVPLAYER_SUPRESSES_AUDIO_RENDERING)
+@interface AVPlayer (AVPlayerSupressesAudioRendering)
+@property (nonatomic, getter=_suppressesAudioRendering, setter=_setSuppressesAudioRendering:) BOOL suppressesAudioRendering;
+@end
+#endif
+
 #if ENABLE(WIRELESS_PLAYBACK_TARGET) || PLATFORM(IOS_FAMILY)
 
 NS_ASSUME_NONNULL_BEGIN

Modified: branches/safari-610-branch/Source/WebCore/html/HTMLMediaElement.cpp (267045 => 267046)


--- branches/safari-610-branch/Source/WebCore/html/HTMLMediaElement.cpp	2020-09-14 22:17:19 UTC (rev 267045)
+++ branches/safari-610-branch/Source/WebCore/html/HTMLMediaElement.cpp	2020-09-14 22:17:23 UTC (rev 267046)
@@ -6546,6 +6546,7 @@
     m_player = MediaPlayer::create(*this);
     m_player->setBufferingPolicy(m_bufferingPolicy);
     m_player->setPreferredDynamicRangeMode(preferredDynamicRangeMode(document().view()));
+    m_player->setMuted(effectiveMuted());
     schedulePlaybackControlsManagerUpdate();
 
 #if ENABLE(WEB_AUDIO)

Modified: branches/safari-610-branch/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm (267045 => 267046)


--- branches/safari-610-branch/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm	2020-09-14 22:17:19 UTC (rev 267045)
+++ branches/safari-610-branch/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm	2020-09-14 22:17:23 UTC (rev 267046)
@@ -432,6 +432,7 @@
     , m_loaderDelegate(adoptNS([[WebCoreAVFLoaderDelegate alloc] initWithPlayer:makeWeakPtr(*this)]))
     , m_cachedItemStatus(MediaPlayerAVPlayerItemStatusDoesNotExist)
 {
+    m_muted = player->muted();
 }
 
 MediaPlayerPrivateAVFoundationObjC::~MediaPlayerPrivateAVFoundationObjC()
@@ -940,6 +941,10 @@
         // Clear m_muted so setMuted doesn't return without doing anything.
         m_muted = false;
         [m_avPlayer.get() setMuted:m_muted];
+
+#if HAVE(AVPLAYER_SUPRESSES_AUDIO_RENDERING)
+        m_avPlayer.get().suppressesAudioRendering = YES;
+#endif
     }
 
     if (player()->isVideoPlayer())
@@ -1324,6 +1329,10 @@
         return;
 
     [m_avPlayer.get() setMuted:m_muted];
+#if HAVE(AVPLAYER_SUPRESSES_AUDIO_RENDERING)
+    if (!m_muted)
+        m_avPlayer.get().suppressesAudioRendering = NO;
+#endif
 }
 
 void MediaPlayerPrivateAVFoundationObjC::setRateDouble(double rate)
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to