<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[206447] branches/safari-602-branch/Source/WebCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/206447">206447</a></dd>
<dt>Author</dt> <dd>bshafiei@apple.com</dd>
<dt>Date</dt> <dd>2016-09-27 11:10:49 -0700 (Tue, 27 Sep 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/206399">r206399</a>. rdar://problem/28457219</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari602branchSourceWebCoreChangeLog">branches/safari-602-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari602branchSourceWebCorehtmlHTMLMediaElementcpp">branches/safari-602-branch/Source/WebCore/html/HTMLMediaElement.cpp</a></li>
<li><a href="#branchessafari602branchSourceWebCorehtmlHTMLMediaElementh">branches/safari-602-branch/Source/WebCore/html/HTMLMediaElement.h</a></li>
<li><a href="#branchessafari602branchSourceWebCoreplatformaudioPlatformMediaSessionManagerh">branches/safari-602-branch/Source/WebCore/platform/audio/PlatformMediaSessionManager.h</a></li>
<li><a href="#branchessafari602branchSourceWebCoreplatformaudiomacMediaSessionManagerMach">branches/safari-602-branch/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.h</a></li>
<li><a href="#branchessafari602branchSourceWebCoreplatformaudiomacMediaSessionManagerMacmm">branches/safari-602-branch/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.mm</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari602branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebCore/ChangeLog (206446 => 206447)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebCore/ChangeLog        2016-09-27 18:03:59 UTC (rev 206446)
+++ branches/safari-602-branch/Source/WebCore/ChangeLog        2016-09-27 18:10:49 UTC (rev 206447)
</span><span class="lines">@@ -1,3 +1,52 @@
</span><ins>+2016-09-27 Babak Shafiei <bshafiei@apple.com>
+
+ Merge r206399. rdar://problem/28457219
+
+ 2016-09-26 Wenson Hsieh <wenson_hsieh@apple.com>
+
+ Seeking video doesn't update seek position
+ https://bugs.webkit.org/show_bug.cgi?id=162575
+ <rdar://problem/28457219>
+
+ Reviewed by Jer Noble.
+
+ On ToT, seeking in a video causes the playhead to stutter, and does not actually update media remote's seek
+ position. This is partly due to how we do not update media remote with new information when beginning to respond
+ to remote seek commands, so media remote continues to think that a playing video is still playing despite the
+ user attempting to seek through it.
+
+ To fix this, we introduce timer-based guards around remote seek commands, such that a seek "gesture" begins when
+ we receive the first seek command and ends when no seek command has been received in a set amount of time (this
+ is 0.5 seconds, which is approximately what other clients around the platform use).
+
+ Also, when responding to a remote seek, perform the seek with no tolerance. This prevents the playhead from
+ stuttering at the end of a seek from the final requested destination of the seek to the last actually seeked
+ time in the video.
+
+ When beginning to seek, we must pause the media. Through existing mechanisms, this causes the media session
+ manager to update its Now Playing information, which informs media remote that we are no longer playing and
+ prevents us from stuttering. However, when ending a seek, we must also trigger an additional update to again
+ refresh media remote's view of the current time. This prevents a flicker when playing media after seeking.
+
+ Unit tests to be added in a follow-up due to time constraints.
+
+ * html/HTMLMediaElement.cpp:
+ (WebCore::HTMLMediaElement::HTMLMediaElement):
+ (WebCore::HTMLMediaElement::handleSeekToPlaybackPosition):
+ (WebCore::HTMLMediaElement::seekToPlaybackPositionEndedTimerFired):
+ (WebCore::HTMLMediaElement::didReceiveRemoteControlCommand):
+ * html/HTMLMediaElement.h:
+ * platform/audio/PlatformMediaSessionManager.h:
+ (WebCore::PlatformMediaSessionManager::scheduleUpdateNowPlayingInfo):
+ (WebCore::PlatformMediaSessionManager::sessionDidEndRemoteScrubbing):
+ (WebCore::PlatformMediaSessionManager::sessions): Deleted.
+ * platform/audio/mac/MediaSessionManagerMac.h:
+ * platform/audio/mac/MediaSessionManagerMac.mm:
+ (WebCore::PlatformMediaSessionManager::updateNowPlayingInfoIfNecessary):
+ (WebCore::MediaSessionManagerMac::scheduleUpdateNowPlayingInfo):
+ (WebCore::MediaSessionManagerMac::sessionDidEndRemoteScrubbing):
+ (WebCore::MediaSessionManagerMac::updateNowPlayingInfo):
+
</ins><span class="cx"> 2016-09-26 Babak Shafiei <bshafiei@apple.com>
</span><span class="cx">
</span><span class="cx"> Merge r206375. rdar://problem/28484393
</span></span></pre></div>
<a id="branchessafari602branchSourceWebCorehtmlHTMLMediaElementcpp"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebCore/html/HTMLMediaElement.cpp (206446 => 206447)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebCore/html/HTMLMediaElement.cpp        2016-09-27 18:03:59 UTC (rev 206446)
+++ branches/safari-602-branch/Source/WebCore/html/HTMLMediaElement.cpp        2016-09-27 18:10:49 UTC (rev 206447)
</span><span class="lines">@@ -405,6 +405,7 @@
</span><span class="cx"> , m_playbackProgressTimer(*this, &HTMLMediaElement::playbackProgressTimerFired)
</span><span class="cx"> , m_scanTimer(*this, &HTMLMediaElement::scanTimerFired)
</span><span class="cx"> , m_playbackControlsManagerBehaviorRestrictionsTimer(*this, &HTMLMediaElement::playbackControlsManagerBehaviorRestrictionsTimerFired)
</span><ins>+ , m_seekToPlaybackPositionEndedTimer(*this, &HTMLMediaElement::seekToPlaybackPositionEndedTimerFired)
</ins><span class="cx"> , m_playedTimeRanges()
</span><span class="cx"> , m_asyncEventQueue(*this)
</span><span class="cx"> , m_requestedPlaybackRate(1)
</span><span class="lines">@@ -467,6 +468,7 @@
</span><span class="cx"> , m_mediaControlsDependOnPageScaleFactor(false)
</span><span class="cx"> , m_haveSetUpCaptionContainer(false)
</span><span class="cx"> #endif
</span><ins>+ , m_isScrubbingRemotely(false)
</ins><span class="cx"> #if ENABLE(VIDEO_TRACK)
</span><span class="cx"> , m_tracksAreReady(true)
</span><span class="cx"> , m_haveVisibleTextTrack(false)
</span><span class="lines">@@ -4560,6 +4562,37 @@
</span><span class="cx"> m_playbackControlsManagerBehaviorRestrictionsTimer.startOneShot(HideMediaControlsAfterEndedDelay);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void HTMLMediaElement::handleSeekToPlaybackPosition(double position)
+{
+#if PLATFORM(MAC)
+ // FIXME: This should ideally use faskSeek, but this causes MediaRemote's playhead to flicker upon release.
+ // Please see <rdar://problem/28457219> for more details.
+ seek(MediaTime::createWithDouble(position));
+ m_seekToPlaybackPositionEndedTimer.stop();
+ m_seekToPlaybackPositionEndedTimer.startOneShot(0.5);
+
+ if (!m_isScrubbingRemotely) {
+ m_isScrubbingRemotely = true;
+ if (!paused())
+ pauseInternal();
+ }
+#else
+ fastSeek(position);
+#endif
+}
+
+void HTMLMediaElement::seekToPlaybackPositionEndedTimerFired()
+{
+#if PLATFORM(MAC)
+ if (!m_isScrubbingRemotely)
+ return;
+
+ PlatformMediaSessionManager::sharedManager().sessionDidEndRemoteScrubbing(*m_mediaSession);
+ m_isScrubbingRemotely = false;
+ m_seekToPlaybackPositionEndedTimer.stop();
+#endif
+}
+
</ins><span class="cx"> void HTMLMediaElement::mediaPlayerVolumeChanged(MediaPlayer*)
</span><span class="cx"> {
</span><span class="cx"> LOG(Media, "HTMLMediaElement::mediaPlayerVolumeChanged(%p)", this);
</span><span class="lines">@@ -6992,7 +7025,7 @@
</span><span class="cx"> case PlatformMediaSession::SeekToPlaybackPositionCommand:
</span><span class="cx"> ASSERT(argument);
</span><span class="cx"> if (argument)
</span><del>- fastSeek(argument->asDouble);
</del><ins>+ handleSeekToPlaybackPosition(argument->asDouble);
</ins><span class="cx"> break;
</span><span class="cx"> default:
</span><span class="cx"> { } // Do nothing
</span></span></pre></div>
<a id="branchessafari602branchSourceWebCorehtmlHTMLMediaElementh"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebCore/html/HTMLMediaElement.h (206446 => 206447)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebCore/html/HTMLMediaElement.h        2016-09-27 18:03:59 UTC (rev 206446)
+++ branches/safari-602-branch/Source/WebCore/html/HTMLMediaElement.h        2016-09-27 18:10:49 UTC (rev 206447)
</span><span class="lines">@@ -810,6 +810,8 @@
</span><span class="cx"> void setControllerJSProperty(const char*, JSC::JSValue);
</span><span class="cx">
</span><span class="cx"> void addBehaviorRestrictionsOnEndIfNecessary();
</span><ins>+ void handleSeekToPlaybackPosition(double);
+ void seekToPlaybackPositionEndedTimerFired();
</ins><span class="cx">
</span><span class="cx"> Timer m_pendingActionTimer;
</span><span class="cx"> Timer m_progressEventTimer;
</span><span class="lines">@@ -816,6 +818,7 @@
</span><span class="cx"> Timer m_playbackProgressTimer;
</span><span class="cx"> Timer m_scanTimer;
</span><span class="cx"> Timer m_playbackControlsManagerBehaviorRestrictionsTimer;
</span><ins>+ Timer m_seekToPlaybackPositionEndedTimer;
</ins><span class="cx"> GenericTaskQueue<Timer> m_seekTaskQueue;
</span><span class="cx"> GenericTaskQueue<Timer> m_resizeTaskQueue;
</span><span class="cx"> GenericTaskQueue<Timer> m_shadowDOMTaskQueue;
</span><span class="lines">@@ -968,6 +971,8 @@
</span><span class="cx"> bool m_haveSetUpCaptionContainer : 1;
</span><span class="cx"> #endif
</span><span class="cx">
</span><ins>+ bool m_isScrubbingRemotely : 1;
+
</ins><span class="cx"> #if ENABLE(VIDEO_TRACK)
</span><span class="cx"> bool m_tracksAreReady : 1;
</span><span class="cx"> bool m_haveVisibleTextTrack : 1;
</span></span></pre></div>
<a id="branchessafari602branchSourceWebCoreplatformaudioPlatformMediaSessionManagerh"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebCore/platform/audio/PlatformMediaSessionManager.h (206446 => 206447)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebCore/platform/audio/PlatformMediaSessionManager.h        2016-09-27 18:03:59 UTC (rev 206446)
+++ branches/safari-602-branch/Source/WebCore/platform/audio/PlatformMediaSessionManager.h        2016-09-27 18:10:49 UTC (rev 206447)
</span><span class="lines">@@ -51,6 +51,7 @@
</span><span class="cx">
</span><span class="cx"> virtual ~PlatformMediaSessionManager() { }
</span><span class="cx">
</span><ins>+ virtual void scheduleUpdateNowPlayingInfo() { }
</ins><span class="cx"> bool has(PlatformMediaSession::MediaType) const;
</span><span class="cx"> int count(PlatformMediaSession::MediaType) const;
</span><span class="cx"> bool activeAudioSessionRequired() const;
</span><span class="lines">@@ -85,6 +86,7 @@
</span><span class="cx"> virtual bool sessionWillBeginPlayback(PlatformMediaSession&);
</span><span class="cx"> virtual void sessionWillEndPlayback(PlatformMediaSession&);
</span><span class="cx"> virtual bool sessionCanLoadMedia(const PlatformMediaSession&) const;
</span><ins>+ virtual void sessionDidEndRemoteScrubbing(const PlatformMediaSession&) { };
</ins><span class="cx"> virtual void clientCharacteristicsChanged(PlatformMediaSession&) { }
</span><span class="cx">
</span><span class="cx"> #if PLATFORM(IOS)
</span></span></pre></div>
<a id="branchessafari602branchSourceWebCoreplatformaudiomacMediaSessionManagerMach"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.h (206446 => 206447)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.h        2016-09-27 18:03:59 UTC (rev 206446)
+++ branches/safari-602-branch/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.h        2016-09-27 18:10:49 UTC (rev 206447)
</span><span class="lines">@@ -27,6 +27,7 @@
</span><span class="cx">
</span><span class="cx"> #if PLATFORM(MAC)
</span><span class="cx">
</span><ins>+#include "GenericTaskQueue.h"
</ins><span class="cx"> #include "PlatformMediaSessionManager.h"
</span><span class="cx"> #include <wtf/RetainPtr.h>
</span><span class="cx">
</span><span class="lines">@@ -41,10 +42,12 @@
</span><span class="cx">
</span><span class="cx"> MediaSessionManagerMac();
</span><span class="cx">
</span><ins>+ void scheduleUpdateNowPlayingInfo() override;
</ins><span class="cx"> void removeSession(PlatformMediaSession&) override;
</span><span class="cx">
</span><span class="cx"> bool sessionWillBeginPlayback(PlatformMediaSession&) override;
</span><span class="cx"> void sessionWillEndPlayback(PlatformMediaSession&) override;
</span><ins>+ void sessionDidEndRemoteScrubbing(const PlatformMediaSession&) override;
</ins><span class="cx"> void clientCharacteristicsChanged(PlatformMediaSession&) override;
</span><span class="cx">
</span><span class="cx"> void updateNowPlayingInfo();
</span><span class="lines">@@ -51,11 +54,9 @@
</span><span class="cx">
</span><span class="cx"> PlatformMediaSession* nowPlayingEligibleSession();
</span><span class="cx">
</span><del>- double m_reportedRate { 0 };
- double m_reportedDuration { 0 };
- String m_reportedTitle;
</del><span class="cx"> bool m_nowPlayingActive { false };
</span><span class="cx"> bool m_isInBackground { false };
</span><ins>+ GenericTaskQueue<Timer> m_nowPlayingUpdateTaskQueue;
</ins><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="branchessafari602branchSourceWebCoreplatformaudiomacMediaSessionManagerMacmm"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.mm (206446 => 206447)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.mm        2016-09-27 18:03:59 UTC (rev 206446)
+++ branches/safari-602-branch/Source/WebCore/platform/audio/mac/MediaSessionManagerMac.mm        2016-09-27 18:10:49 UTC (rev 206447)
</span><span class="lines">@@ -56,7 +56,7 @@
</span><span class="cx"> void PlatformMediaSessionManager::updateNowPlayingInfoIfNecessary()
</span><span class="cx"> {
</span><span class="cx"> if (auto existingManager = (MediaSessionManagerMac *)PlatformMediaSessionManager::sharedManagerIfExists())
</span><del>- existingManager->updateNowPlayingInfo();
</del><ins>+ existingManager->scheduleUpdateNowPlayingInfo();
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> MediaSessionManagerMac::MediaSessionManagerMac()
</span><span class="lines">@@ -69,6 +69,12 @@
</span><span class="cx"> {
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void MediaSessionManagerMac::scheduleUpdateNowPlayingInfo()
+{
+ if (!m_nowPlayingUpdateTaskQueue.hasPendingTasks())
+ m_nowPlayingUpdateTaskQueue.enqueueTask(std::bind(&MediaSessionManagerMac::updateNowPlayingInfo, this));
+}
+
</ins><span class="cx"> bool MediaSessionManagerMac::sessionWillBeginPlayback(PlatformMediaSession& session)
</span><span class="cx"> {
</span><span class="cx"> if (!PlatformMediaSessionManager::sessionWillBeginPlayback(session))
</span><span class="lines">@@ -79,6 +85,11 @@
</span><span class="cx"> return true;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+void MediaSessionManagerMac::sessionDidEndRemoteScrubbing(const PlatformMediaSession&)
+{
+ scheduleUpdateNowPlayingInfo();
+}
+
</ins><span class="cx"> void MediaSessionManagerMac::removeSession(PlatformMediaSession& session)
</span><span class="cx"> {
</span><span class="cx"> PlatformMediaSessionManager::removeSession(session);
</span><span class="lines">@@ -123,9 +134,6 @@
</span><span class="cx"> LOG(Media, "MediaSessionManagerMac::updateNowPlayingInfo - clearing now playing info");
</span><span class="cx"> MRMediaRemoteSetNowPlayingInfo(nullptr);
</span><span class="cx"> m_nowPlayingActive = false;
</span><del>- m_reportedTitle = "";
- m_reportedRate = 0;
- m_reportedDuration = 0;
</del><span class="cx"> MRMediaRemoteSetNowPlayingApplicationPlaybackStateForOrigin(MRMediaRemoteGetLocalOrigin(), kMRPlaybackStateStopped, dispatch_get_main_queue(), ^(MRMediaRemoteError error) {
</span><span class="cx"> #if LOG_DISABLED
</span><span class="cx"> UNUSED_PARAM(error);
</span><span class="lines">@@ -146,16 +154,6 @@
</span><span class="cx"> String title = currentSession->title();
</span><span class="cx"> double duration = currentSession->duration();
</span><span class="cx"> double rate = currentSession->state() == PlatformMediaSession::Playing ? 1 : 0;
</span><del>- if (m_reportedTitle == title && m_reportedRate == rate && m_reportedDuration == duration) {
- m_nowPlayingActive = true;
- LOG(Media, "MediaSessionManagerMac::updateNowPlayingInfo - nothing new to show");
- return;
- }
-
- m_reportedRate = rate;
- m_reportedDuration = duration;
- m_reportedTitle = title;
-
</del><span class="cx"> auto info = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 4, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks));
</span><span class="cx">
</span><span class="cx"> if (!title.isEmpty())
</span></span></pre>
</div>
</div>
</body>
</html>