Title: [240123] trunk/Source/WebCore
Revision
240123
Author
jer.no...@apple.com
Date
2019-01-17 12:24:09 -0800 (Thu, 17 Jan 2019)

Log Message

MediaPlayerPrivateAVFoundationObjC can return incorrect paused information
https://bugs.webkit.org/show_bug.cgi?id=193499

Reviewed by Eric Carlson.

MediaPlayerPrivateAVFoundation uses rate() as an indicator of whether the player
is paused or not. This is incorrect when playback is stalled waiting for more data.
For MPPAVFObjC, use the timeControlStatus as a more accurate indicator of whether
the player is playing.

Now that we have correct play state information, we can remove the handlePlaybackCommand()
path when playing remotely for a more direct approach of notifying the HTMLMediaElement
that the play state has changed.

Drive-by fix: Before throwing away the AVPlayer, clear its output context. This keeps
remote devices from keeping the AVPlayer alive.

Drive-by fix #2: The NullMediaPlayer should always return "true" for paused(), not "false",
since it can't possibly play anything.

* platform/graphics/MediaPlayer.cpp:
* platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp:
(WebCore::MediaPlayerPrivateAVFoundation::paused const):
* platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h:
(WebCore::MediaPlayerPrivateAVFoundation::platformPaused const):
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
* platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
(WebCore::MediaPlayerPrivateAVFoundationObjC::cancelLoad):
(WebCore::MediaPlayerPrivateAVFoundationObjC::platformPaused const):
(WebCore::MediaPlayerPrivateAVFoundationObjC::timeControlStatusDidChange):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (240122 => 240123)


--- trunk/Source/WebCore/ChangeLog	2019-01-17 19:34:29 UTC (rev 240122)
+++ trunk/Source/WebCore/ChangeLog	2019-01-17 20:24:09 UTC (rev 240123)
@@ -1,3 +1,36 @@
+2019-01-17  Jer Noble  <jer.no...@apple.com>
+
+        MediaPlayerPrivateAVFoundationObjC can return incorrect paused information
+        https://bugs.webkit.org/show_bug.cgi?id=193499
+
+        Reviewed by Eric Carlson.
+
+        MediaPlayerPrivateAVFoundation uses rate() as an indicator of whether the player
+        is paused or not. This is incorrect when playback is stalled waiting for more data.
+        For MPPAVFObjC, use the timeControlStatus as a more accurate indicator of whether
+        the player is playing.
+
+        Now that we have correct play state information, we can remove the handlePlaybackCommand()
+        path when playing remotely for a more direct approach of notifying the HTMLMediaElement
+        that the play state has changed.
+
+        Drive-by fix: Before throwing away the AVPlayer, clear its output context. This keeps
+        remote devices from keeping the AVPlayer alive.
+
+        Drive-by fix #2: The NullMediaPlayer should always return "true" for paused(), not "false",
+        since it can't possibly play anything.
+
+        * platform/graphics/MediaPlayer.cpp:
+        * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp:
+        (WebCore::MediaPlayerPrivateAVFoundation::paused const):
+        * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h:
+        (WebCore::MediaPlayerPrivateAVFoundation::platformPaused const):
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
+        * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::cancelLoad):
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::platformPaused const):
+        (WebCore::MediaPlayerPrivateAVFoundationObjC::timeControlStatusDidChange):
+
 2019-01-17  Jiewen Tan  <jiewen_...@apple.com>
 
         [Mac] Add a new quirk to HTMLFormControlElement::isMouseFocusable

Modified: trunk/Source/WebCore/PAL/pal/spi/mac/AVFoundationSPI.h (240122 => 240123)


--- trunk/Source/WebCore/PAL/pal/spi/mac/AVFoundationSPI.h	2019-01-17 19:34:29 UTC (rev 240122)
+++ trunk/Source/WebCore/PAL/pal/spi/mac/AVFoundationSPI.h	2019-01-17 20:24:09 UTC (rev 240123)
@@ -79,7 +79,7 @@
 
 #if !PLATFORM(IOS_FAMILY)
 @interface AVPlayer (AVPlayerExternalPlaybackSupportPrivate)
-@property (nonatomic, retain) AVOutputContext *outputContext;
+@property (nonatomic, retain, nullable) AVOutputContext *outputContext;
 @end
 #else
 typedef NS_ENUM(NSInteger, AVPlayerExternalPlaybackType) {

Modified: trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp (240122 => 240123)


--- trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp	2019-01-17 19:34:29 UTC (rev 240122)
+++ trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp	2019-01-17 20:24:09 UTC (rev 240123)
@@ -130,7 +130,7 @@
 
     void setRateDouble(double) override { }
     void setPreservesPitch(bool) override { }
-    bool paused() const override { return false; }
+    bool paused() const override { return true; }
 
     void setVolumeDouble(double) override { }
 

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp (240122 => 240123)


--- trunk/Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp	2019-01-17 19:34:29 UTC (rev 240122)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp	2019-01-17 20:24:09 UTC (rev 240123)
@@ -275,7 +275,7 @@
     if (!metaDataAvailable())
         return true;
 
-    return rate() == 0;
+    return platformPaused();
 }
 
 bool MediaPlayerPrivateAVFoundation::seeking() const

Modified: trunk/Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h (240122 => 240123)


--- trunk/Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h	2019-01-17 19:34:29 UTC (rev 240122)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h	2019-01-17 20:24:09 UTC (rev 240123)
@@ -245,6 +245,7 @@
     virtual void platformSetVisible(bool) = 0;
     virtual void platformPlay() = 0;
     virtual void platformPause() = 0;
+    virtual bool platformPaused() const { return !rate(); }
     virtual void checkPlayability() = 0;
     virtual void seekToTime(const MediaTime&, const MediaTime& negativeTolerance, const MediaTime& positiveTolerance) = 0;
     unsigned long long totalBytes() const override = 0;

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


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h	2019-01-17 19:34:29 UTC (rev 240122)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h	2019-01-17 20:24:09 UTC (rev 240123)
@@ -167,6 +167,7 @@
     void platformSetVisible(bool) override;
     void platformPlay() override;
     void platformPause() override;
+    bool platformPaused() const override;
     MediaTime currentMediaTime() const override;
     void setVolume(float) override;
 #if PLATFORM(IOS_FAMILY)

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


--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm	2019-01-17 19:34:29 UTC (rev 240122)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm	2019-01-17 20:24:09 UTC (rev 240123)
@@ -590,6 +590,9 @@
         setShouldObserveTimeControlStatus(false);
 
         [m_avPlayer replaceCurrentItemWithPlayerItem:nil];
+#if !PLATFORM(IOS_FAMILY)
+        [m_avPlayer setOutputContext:nil];
+#endif
         m_avPlayer = nil;
     }
 
@@ -1304,6 +1307,11 @@
     setPlayerRate(0);
 }
 
+bool MediaPlayerPrivateAVFoundationObjC::platformPaused() const
+{
+    return m_cachedTimeControlStatus == AVPlayerTimeControlStatusPaused;
+}
+
 MediaTime MediaPlayerPrivateAVFoundationObjC::platformDuration() const
 {
     // Do not ask the asset for duration before it has been loaded or it will fetch the
@@ -3267,8 +3275,10 @@
         return;
 
     bool playerIsPlaying = m_cachedTimeControlStatus != AVPlayerTimeControlStatusPaused;
-    if (playerIsPlaying != m_requestedPlaying)
-        player()->handlePlaybackCommand(playerIsPlaying ? PlatformMediaSession::PlayCommand : PlatformMediaSession::PauseCommand);
+    if (playerIsPlaying != m_requestedPlaying) {
+        m_requestedPlaying = playerIsPlaying;
+        player()->playbackStateChanged();
+    }
 #endif
 }
 
@@ -3354,9 +3364,10 @@
         return;
 
     m_shouldObserveTimeControlStatus = shouldObserve;
-    if (shouldObserve)
+    if (shouldObserve) {
         [m_avPlayer addObserver:m_objcObserver.get() forKeyPath:@"timeControlStatus" options:NSKeyValueObservingOptionNew context:(void *)MediaPlayerAVFoundationObservationContextPlayer];
-    else
+        timeControlStatusDidChange(m_avPlayer.get().timeControlStatus);
+    } else
         [m_avPlayer removeObserver:m_objcObserver.get() forKeyPath:@"timeControlStatus"];
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to