Title: [292049] trunk
Revision
292049
Author
eric.carl...@apple.com
Date
2022-03-29 11:30:52 -0700 (Tue, 29 Mar 2022)

Log Message

[macOS] Muted video is sometimes paused when entering fullscreen
https://bugs.webkit.org/show_bug.cgi?id=238462
rdar://89104216

Reviewed by Jer Noble.

Source/WebCore:

Test: media/fullscreen-when-muted.html

* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::didMoveToNewDocument): Add logging.
(WebCore::HTMLMediaElement::elementIsHidden const): Consider both element fullscreen
and video fullscreen.
(WebCore::HTMLMediaElement::visibilityStateChanged): Use elementIsHidden.
(WebCore::HTMLMediaElement::shouldOverrideBackgroundPlaybackRestriction const): Add
logging for the one case that didn't have it.
(WebCore::HTMLMediaElement::updateMediaPlayer): New, wrap MediaPlayer functions
that are called frequently by RenderVideo so we can only call them when necessary.
* html/HTMLMediaElement.h:
(WebCore::HTMLMediaElement::elementIsHidden const): Deleted.

* html/MediaElementSession.cpp:
(WebCore::MediaElementSession::visibilityChanged): Just use elementIsHidden, it
already accounts for fullscreen.

* platform/graphics/MediaPlayer.cpp:
(WebCore::MediaPlayer::setVisibleInViewport): Do nothing when visibility is not changing.

* platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm:
(WebCore::MediaPlayerPrivateMediaStreamAVFObjC::setPageIsVisible): Add logging.

* rendering/RenderVideo.cpp:
(WebCore::RenderVideo::updatePlayer): Call HTMLMediaElement::updateMediaPlayer instead
of calling MediaPlayer directly.

Source/WebKit:

* WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp:
(WebKit::MediaPlayerPrivateRemote::setPageIsVisible): Track visibility and do
nothing when it doesn't change.
(WebKit::MediaPlayerPrivateRemote::setShouldMaintainAspectRatio): Ditto for aspect
ratio.
* WebProcess/GPU/media/MediaPlayerPrivateRemote.h:

LayoutTests:

* media/fullscreen-when-muted-expected.txt: Added.
* media/fullscreen-when-muted.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (292048 => 292049)


--- trunk/LayoutTests/ChangeLog	2022-03-29 18:21:36 UTC (rev 292048)
+++ trunk/LayoutTests/ChangeLog	2022-03-29 18:30:52 UTC (rev 292049)
@@ -1,3 +1,14 @@
+2022-03-29  Eric Carlson  <eric.carl...@apple.com>
+
+        [macOS] Muted video is sometimes paused when entering fullscreen
+        https://bugs.webkit.org/show_bug.cgi?id=238462
+        rdar://89104216
+
+        Reviewed by Jer Noble.
+
+        * media/fullscreen-when-muted-expected.txt: Added.
+        * media/fullscreen-when-muted.html: Added.
+
 2022-03-29  Antti Koivisto  <an...@apple.com>
 
         [CSS Container Queries] Support CSSOM

Added: trunk/LayoutTests/media/fullscreen-when-muted-expected.txt (0 => 292049)


--- trunk/LayoutTests/media/fullscreen-when-muted-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/media/fullscreen-when-muted-expected.txt	2022-03-29 18:30:52 UTC (rev 292049)
@@ -0,0 +1,13 @@
+Muted video should not pause when entering fullscreen.
+
+EVENT(canplaythrough)
+EVENT(playing)
+EXPECTED (video.muted == 'true') OK
+EXPECTED (video.paused == 'false') OK
+EVENT(webkitfullscreenchange)
+EXPECTED (document.webkitFullscreenElement == '[object HTMLHtmlElement]') OK
+EXPECTED (video.muted == 'true') OK
+EXPECTED (video.paused == 'false') OK
+EVENT(webkitfullscreenchange)
+END OF TEST
+

Added: trunk/LayoutTests/media/fullscreen-when-muted.html (0 => 292049)


--- trunk/LayoutTests/media/fullscreen-when-muted.html	                        (rev 0)
+++ trunk/LayoutTests/media/fullscreen-when-muted.html	2022-03-29 18:30:52 UTC (rev 292049)
@@ -0,0 +1,45 @@
+<html>
+<head>
+    <title>Test that muted video is not paused when entering fullscreen</title>
+    <script src=""
+    <script src=""
+    <script>
+
+    window.addEventListener('load', async event => {
+        findMediaElement();
+
+        video.src = "" 'content/test');
+        await waitFor(video, 'canplaythrough');
+        failTestIn(12000);
+
+        runWithKeyDown(() => video.play());
+        await waitFor(video, 'playing');
+
+        testExpected('video.muted', true);
+        testExpected('video.paused', false);
+
+        runWithKeyDown(() => document.documentElement.webkitRequestFullscreen() );
+
+        await waitFor(document.documentElement, 'webkitfullscreenchange');
+        await sleepFor(250);
+
+        testExpected('document.webkitFullscreenElement', document.documentElement);
+        testExpected('video.muted', true);
+        testExpected('video.paused', false);
+
+        runWithKeyDown(() => document.webkitExitFullscreen() );
+        await waitFor(document.documentElement, 'webkitfullscreenchange');
+
+        endTest();
+    });
+
+    </script>
+</head>
+<body >
+    Muted video should not pause when entering fullscreen.<br>
+    <div id="parent">
+        <video controls muted></video>
+    </div>
+</body>
+</html>
+

Modified: trunk/Source/WebCore/ChangeLog (292048 => 292049)


--- trunk/Source/WebCore/ChangeLog	2022-03-29 18:21:36 UTC (rev 292048)
+++ trunk/Source/WebCore/ChangeLog	2022-03-29 18:30:52 UTC (rev 292049)
@@ -1,3 +1,39 @@
+2022-03-29  Eric Carlson  <eric.carl...@apple.com>
+
+        [macOS] Muted video is sometimes paused when entering fullscreen
+        https://bugs.webkit.org/show_bug.cgi?id=238462
+        rdar://89104216
+
+        Reviewed by Jer Noble.
+
+        Test: media/fullscreen-when-muted.html
+
+        * html/HTMLMediaElement.cpp:
+        (WebCore::HTMLMediaElement::didMoveToNewDocument): Add logging.
+        (WebCore::HTMLMediaElement::elementIsHidden const): Consider both element fullscreen
+        and video fullscreen.
+        (WebCore::HTMLMediaElement::visibilityStateChanged): Use elementIsHidden.
+        (WebCore::HTMLMediaElement::shouldOverrideBackgroundPlaybackRestriction const): Add
+        logging for the one case that didn't have it.
+        (WebCore::HTMLMediaElement::updateMediaPlayer): New, wrap MediaPlayer functions
+        that are called frequently by RenderVideo so we can only call them when necessary.
+        * html/HTMLMediaElement.h:
+        (WebCore::HTMLMediaElement::elementIsHidden const): Deleted.
+
+        * html/MediaElementSession.cpp:
+        (WebCore::MediaElementSession::visibilityChanged): Just use elementIsHidden, it 
+        already accounts for fullscreen.
+
+        * platform/graphics/MediaPlayer.cpp:
+        (WebCore::MediaPlayer::setVisibleInViewport): Do nothing when visibility is not changing.
+
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm:
+        (WebCore::MediaPlayerPrivateMediaStreamAVFObjC::setPageIsVisible): Add logging.
+
+        * rendering/RenderVideo.cpp:
+        (WebCore::RenderVideo::updatePlayer): Call HTMLMediaElement::updateMediaPlayer instead
+        of calling MediaPlayer directly.
+
 2022-03-29  Antti Koivisto  <an...@apple.com>
 
         [CSS Container Queries] Support CSSOM

Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (292048 => 292049)


--- trunk/Source/WebCore/html/HTMLMediaElement.cpp	2022-03-29 18:21:36 UTC (rev 292048)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp	2022-03-29 18:30:52 UTC (rev 292049)
@@ -692,6 +692,8 @@
 
 void HTMLMediaElement::didMoveToNewDocument(Document& oldDocument, Document& newDocument)
 {
+    ALWAYS_LOG(LOGIDENTIFIER);
+
     ASSERT_WITH_SECURITY_IMPLICATION(&document() == &newDocument);
     if (m_shouldDelayLoadEvent) {
         oldDocument.decrementLoadEventDelayCount();
@@ -6053,9 +6055,23 @@
 #endif
 }
 
+bool HTMLMediaElement::elementIsHidden() const
+{
+#if ENABLE(FULLSCREEN_API)
+    auto& fullscreenManager = document().fullscreenManager();
+    if (isVideo() && fullscreenManager.isFullscreen() && fullscreenManager.currentFullscreenElement())
+        return false;
+#endif
+
+    if (m_videoFullscreenMode != VideoFullscreenModeNone)
+        return false;
+
+    return document().hidden();
+}
+
 void HTMLMediaElement::visibilityStateChanged()
 {
-    bool elementIsHidden = document().hidden() && m_videoFullscreenMode == VideoFullscreenModeNone;
+    bool elementIsHidden = this->elementIsHidden();
     if (elementIsHidden == m_elementIsHidden)
         return;
 
@@ -8061,8 +8077,10 @@
             return true;
         }
 #if ENABLE(VIDEO_PRESENTATION_MODE)
-        if (m_videoFullscreenMode == VideoFullscreenModePictureInPicture)
+        if (m_videoFullscreenMode == VideoFullscreenModePictureInPicture) {
+            INFO_LOG(LOGIDENTIFIER, "returning true, in PiP");
             return true;
+        }
 #endif
 #if ENABLE(MEDIA_STREAM)
         if (hasMediaStreamSrcObject() && mediaState().containsAny(MediaProducerMediaState::IsPlayingAudio) && document().mediaState().containsAny(MediaProducerMediaState::HasActiveAudioCaptureDevice)) {
@@ -8328,6 +8346,7 @@
 {
     if (m_player)
         m_player->setVisibleInViewport(isVisibleInViewport());
+
     queueTaskKeepingObjectAlive(*this, TaskSource::MediaElement, [this] {
         if (isContextStopped())
             return;
@@ -8518,6 +8537,15 @@
     return *m_mediaSession;
 }
 
+void HTMLMediaElement::updateMediaPlayer(IntSize elementSize, bool shouldMaintainAspectRatio)
+{
+    ALWAYS_LOG(LOGIDENTIFIER);
+    m_player->setSize(elementSize);
+    visibilityStateChanged();
+    m_player->setVisibleInViewport(isVisibleInViewport());
+    m_player->setShouldMaintainAspectRatio(shouldMaintainAspectRatio);
+}
+
 void HTMLMediaElement::mediaPlayerQueueTaskOnEventLoop(Function<void()>&& task)
 {
     document().eventLoop().queueTask(TaskSource::MediaElement, WTFMove(task));

Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (292048 => 292049)


--- trunk/Source/WebCore/html/HTMLMediaElement.h	2022-03-29 18:21:36 UTC (rev 292048)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h	2022-03-29 18:30:52 UTC (rev 292049)
@@ -295,8 +295,6 @@
     WEBCORE_EXPORT bool webkitClosedCaptionsVisible() const;
     WEBCORE_EXPORT void setWebkitClosedCaptionsVisible(bool);
 
-    bool elementIsHidden() const { return m_elementIsHidden; }
-
 #if ENABLE(MEDIA_STATISTICS)
 // Statistics
     unsigned webkitAudioDecodedByteCount() const;
@@ -609,6 +607,9 @@
     WEBCORE_EXPORT AudioSessionCategory categoryAtMostRecentPlayback() const { return m_categoryAtMostRecentPlayback; }
 #endif
 
+    void updateMediaPlayer(IntSize, bool);
+    WEBCORE_EXPORT bool elementIsHidden() const;
+
 protected:
     HTMLMediaElement(const QualifiedName&, Document&, bool createdByParser);
     virtual ~HTMLMediaElement();
@@ -645,7 +646,6 @@
     void setChangingVideoFullscreenMode(bool value) { m_changingVideoFullscreenMode = value; }
     bool isChangingVideoFullscreenMode() const { return m_changingVideoFullscreenMode; }
 
-protected:
     void mediaPlayerEngineUpdated() override;
 
 private:

Modified: trunk/Source/WebCore/html/MediaElementSession.cpp (292048 => 292049)


--- trunk/Source/WebCore/html/MediaElementSession.cpp	2022-03-29 18:21:36 UTC (rev 292048)
+++ trunk/Source/WebCore/html/MediaElementSession.cpp	2022-03-29 18:30:52 UTC (rev 292049)
@@ -252,7 +252,7 @@
 
     bool elementIsHidden = m_element.elementIsHidden();
 
-    if (elementIsHidden && !m_element.isFullscreen())
+    if (elementIsHidden)
         m_elementIsHiddenUntilVisibleInViewport = true;
     else if (m_element.isVisibleInViewport())
         m_elementIsHiddenUntilVisibleInViewport = false;

Modified: trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp (292048 => 292049)


--- trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp	2022-03-29 18:21:36 UTC (rev 292048)
+++ trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp	2022-03-29 18:30:52 UTC (rev 292049)
@@ -1059,6 +1059,9 @@
 
 void MediaPlayer::setVisibleInViewport(bool visible)
 {
+    if (visible == m_visibleInViewport)
+        return;
+
     m_visibleInViewport = visible;
     m_private->setVisibleInViewport(visible);
 }

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm (292048 => 292049)


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm	2022-03-29 18:21:36 UTC (rev 292048)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateMediaStreamAVFObjC.mm	2022-03-29 18:30:52 UTC (rev 292049)
@@ -638,6 +638,7 @@
     if (m_isPageVisible == isVisible)
         return;
 
+    ALWAYS_LOG(LOGIDENTIFIER, isVisible);
     m_isPageVisible = isVisible;
     flushRenderers();
     reenqueueCurrentVideoFrameIfNeeded();

Modified: trunk/Source/WebCore/rendering/RenderVideo.cpp (292048 => 292049)


--- trunk/Source/WebCore/rendering/RenderVideo.cpp	2022-03-29 18:21:36 UTC (rev 292048)
+++ trunk/Source/WebCore/rendering/RenderVideo.cpp	2022-03-29 18:30:52 UTC (rev 292049)
@@ -272,18 +272,10 @@
     if (!mediaPlayer)
         return;
 
-    if (!videoElement().inActiveDocument()) {
-        mediaPlayer->setPageIsVisible(false);
-        return;
-    }
+    if (videoElement().inActiveDocument())
+        contentChanged(VideoChanged);
 
-    contentChanged(VideoChanged);
-    
-    IntRect videoBounds = videoBox(); 
-    mediaPlayer->setSize(IntSize(videoBounds.width(), videoBounds.height()));
-    mediaPlayer->setPageIsVisible(!videoElement().elementIsHidden());
-    mediaPlayer->setVisibleInViewport(videoElement().isVisibleInViewport());
-    mediaPlayer->setShouldMaintainAspectRatio(style().objectFit() != ObjectFit::Fill);
+    videoElement().updateMediaPlayer(videoBox().size(), style().objectFit() != ObjectFit::Fill);
 }
 
 LayoutUnit RenderVideo::computeReplacedLogicalWidth(ShouldComputePreferred shouldComputePreferred) const

Modified: trunk/Source/WebKit/ChangeLog (292048 => 292049)


--- trunk/Source/WebKit/ChangeLog	2022-03-29 18:21:36 UTC (rev 292048)
+++ trunk/Source/WebKit/ChangeLog	2022-03-29 18:30:52 UTC (rev 292049)
@@ -1,5 +1,20 @@
 2022-03-29  Eric Carlson  <eric.carl...@apple.com>
 
+        [macOS] Muted video is sometimes paused when entering fullscreen
+        https://bugs.webkit.org/show_bug.cgi?id=238462
+        rdar://89104216
+
+        Reviewed by Jer Noble.
+
+        * WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp:
+        (WebKit::MediaPlayerPrivateRemote::setPageIsVisible): Track visibility and do
+        nothing when it doesn't change.
+        (WebKit::MediaPlayerPrivateRemote::setShouldMaintainAspectRatio): Ditto for aspect
+        ratio.
+        * WebProcess/GPU/media/MediaPlayerPrivateRemote.h:
+
+2022-03-29  Eric Carlson  <eric.carl...@apple.com>
+
         Don't send sync RemoteMediaPlayerProxy messages that we know will fail
         https://bugs.webkit.org/show_bug.cgi?id=238467
         rdar://86662565

Modified: trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp (292048 => 292049)


--- trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp	2022-03-29 18:21:36 UTC (rev 292048)
+++ trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.cpp	2022-03-29 18:30:52 UTC (rev 292049)
@@ -565,11 +565,21 @@
 
 void MediaPlayerPrivateRemote::setPageIsVisible(bool visible)
 {
+    if (m_pageIsVisible == visible)
+        return;
+
+    ALWAYS_LOG(LOGIDENTIFIER, visible);
+
+    m_pageIsVisible = visible;
     connection().send(Messages::RemoteMediaPlayerProxy::SetPageIsVisible(visible), m_id);
 }
 
 void MediaPlayerPrivateRemote::setShouldMaintainAspectRatio(bool maintainRatio)
 {
+    if (maintainRatio == m_shouldMaintainAspectRatio)
+        return;
+
+    m_shouldMaintainAspectRatio = maintainRatio;
     connection().send(Messages::RemoteMediaPlayerProxy::SetShouldMaintainAspectRatio(maintainRatio), m_id);
 }
 

Modified: trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.h (292048 => 292049)


--- trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.h	2022-03-29 18:21:36 UTC (rev 292048)
+++ trunk/Source/WebKit/WebProcess/GPU/media/MediaPlayerPrivateRemote.h	2022-03-29 18:30:52 UTC (rev 292049)
@@ -466,6 +466,8 @@
     bool m_waitingForKey { false };
     bool m_timeIsProgressing { false };
     bool m_renderingCanBeAccelerated { false };
+    bool m_shouldMaintainAspectRatio { false };
+    bool m_pageIsVisible { false };
     RefPtr<RemoteVideoFrameProxy> m_videoFrameForCurrentTime;
 #if PLATFORM(COCOA)
     RetainPtr<CVPixelBufferRef> m_pixelBufferGatheredWithVideoFrameMetadata;
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to