Diff
Modified: trunk/Source/WebCore/ChangeLog (167733 => 167734)
--- trunk/Source/WebCore/ChangeLog 2014-04-24 00:43:15 UTC (rev 167733)
+++ trunk/Source/WebCore/ChangeLog 2014-04-24 01:23:58 UTC (rev 167734)
@@ -1,3 +1,39 @@
+2014-04-23 Brent Fulgham <bfulg...@apple.com>
+
+ [Mac, iOS] Stop buffering media when on an inactive tab.
+ https://bugs.webkit.org/show_bug.cgi?id=132077
+
+ Reviewed by Eric Carlson.
+
+ * html/HTMLMediaElement.cpp: Rename 'm_isDisplaySleepDisablingSuspended'
+ to 'm_elementIsHidden'.
+ (WebCore::HTMLMediaElement::HTMLMediaElement):
+ (WebCore::HTMLMediaElement::visibilityStatusChanged): Notify the
+ media session that the element is (or is not) hidden.
+ (WebCore::HTMLMediaElement::setShouldBufferData): Added.
+ * html/HTMLMediaElement.h:
+ * platform/audio/MediaSession.cpp:
+ (WebCore::MediaSession::clientWillBeginPlayback): Tell media to
+ buffer if not hidden or playing.
+ (WebCore::MediaSession::clientWillPausePlayback): Ditto.
+ (WebCore::MediaSession::visibilityChanged): Added. Client API, just relays call
+ to updateClientDataBuffering.
+ (WebCore::MediaSession::updateClientDataBuffering): Tell client it should only
+ buffer data if it's currently playing, or not hidden.
+ * platform/audio/MediaSession.h:
+ * platform/graphics/MediaPlayer.cpp:
+ (WebCore::MediaPlayer::setShouldBufferData): Added: Just relays to
+ MediaPlayerPrivate object.
+ * platform/graphics/MediaPlayer.h:
+ * platform/graphics/MediaPlayerPrivate.h:
+ (WebCore::MediaPlayerPrivateInterface::setShouldBufferData):
+ * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h:
+ * platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm:
+ (WebCore::MediaPlayerPrivateAVFoundationObjC::MediaPlayerPrivateAVFoundationObjC):
+ (WebCore::MediaPlayerPrivateAVFoundationObjC::setShouldBufferData): Added.
+ Detach the player item from the player if we don't want to continue
+ buffering or other background tasks.
+
2014-04-23 Alexey Proskuryakov <a...@apple.com>
Eliminate internals.setMockScrollbarsEnabled()
Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (167733 => 167734)
--- trunk/Source/WebCore/html/HTMLMediaElement.cpp 2014-04-24 00:43:15 UTC (rev 167733)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp 2014-04-24 01:23:58 UTC (rev 167734)
@@ -325,7 +325,7 @@
, m_havePreparedToPlay(false)
, m_parsingInProgress(createdByParser)
#if ENABLE(PAGE_VISIBILITY_API)
- , m_isDisplaySleepDisablingSuspended(document.hidden())
+ , m_elementIsHidden(document.hidden())
#endif
#if PLATFORM(IOS)
, m_requestingPlay(false)
@@ -4716,8 +4716,9 @@
void HTMLMediaElement::visibilityStateChanged()
{
LOG(Media, "HTMLMediaElement::visibilityStateChanged");
- m_isDisplaySleepDisablingSuspended = document().hidden();
+ m_elementIsHidden = document().hidden();
updateSleepDisabling();
+ m_mediaSession->visibilityChanged();
}
#endif
@@ -5682,7 +5683,7 @@
#endif
#if ENABLE(PAGE_VISIBILITY_API)
- if (m_isDisplaySleepDisablingSuspended)
+ if (m_elementIsHidden)
return false;
#endif
@@ -6142,6 +6143,12 @@
return true;
}
+
+void HTMLMediaElement::setShouldBufferData(bool shouldBuffer)
+{
+ if (m_player)
+ return m_player->setShouldBufferData(shouldBuffer);
+}
}
Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (167733 => 167734)
--- trunk/Source/WebCore/html/HTMLMediaElement.h 2014-04-24 00:43:15 UTC (rev 167733)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h 2014-04-24 01:23:58 UTC (rev 167734)
@@ -199,6 +199,7 @@
void setLoop(bool b);
virtual void play() override;
virtual void pause() override;
+ virtual void setShouldBufferData(bool) override;
void fastSeek(double);
// captions
@@ -206,6 +207,10 @@
bool webkitClosedCaptionsVisible() const;
void setWebkitClosedCaptionsVisible(bool);
+#if ENABLE(PAGE_VISIBILITY_API)
+ virtual bool elementIsHidden() const override { return m_elementIsHidden; }
+#endif
+
#if ENABLE(MEDIA_STATISTICS)
// Statistics
unsigned webkitAudioDecodedByteCount() const;
@@ -830,7 +835,7 @@
bool m_havePreparedToPlay : 1;
bool m_parsingInProgress : 1;
#if ENABLE(PAGE_VISIBILITY_API)
- bool m_isDisplaySleepDisablingSuspended : 1;
+ bool m_elementIsHidden : 1;
#endif
#if PLATFORM(IOS)
Modified: trunk/Source/WebCore/platform/audio/MediaSession.cpp (167733 => 167734)
--- trunk/Source/WebCore/platform/audio/MediaSession.cpp 2014-04-24 00:43:15 UTC (rev 167733)
+++ trunk/Source/WebCore/platform/audio/MediaSession.cpp 2014-04-24 01:23:58 UTC (rev 167734)
@@ -105,6 +105,7 @@
{
setState(Playing);
MediaSessionManager::sharedManager().sessionWillBeginPlayback(*this);
+ updateClientDataBuffering();
return true;
}
@@ -121,6 +122,7 @@
setState(Paused);
MediaSessionManager::sharedManager().sessionWillEndPlayback(*this);
+ updateClientDataBuffering();
return true;
}
@@ -159,7 +161,20 @@
{
m_client.didReceiveRemoteControlCommand(command);
}
-
+
+#if ENABLE(PAGE_VISIBILITY_API)
+void MediaSession::visibilityChanged()
+{
+ updateClientDataBuffering();
+}
+
+void MediaSession::updateClientDataBuffering()
+{
+ bool shouldBuffer = m_state == Playing || !m_client.elementIsHidden();
+ m_client.setShouldBufferData(shouldBuffer);
+}
+#endif
+
String MediaSessionClient::mediaSessionTitle() const
{
return String();
Modified: trunk/Source/WebCore/platform/audio/MediaSession.h (167733 => 167734)
--- trunk/Source/WebCore/platform/audio/MediaSession.h 2014-04-24 00:43:15 UTC (rev 167733)
+++ trunk/Source/WebCore/platform/audio/MediaSession.h 2014-04-24 01:23:58 UTC (rev 167734)
@@ -72,6 +72,10 @@
void pauseSession();
+#if ENABLE(PAGE_VISIBILITY_API)
+ void visibilityChanged();
+#endif
+
String title() const;
double duration() const;
double currentTime() const;
@@ -94,6 +98,10 @@
MediaSessionClient& client() const { return m_client; }
private:
+#if ENABLE(PAGE_VISIBILITY_API)
+ void updateClientDataBuffering();
+#endif
+
MediaSessionClient& m_client;
State m_state;
State m_stateToRestore;
@@ -116,6 +124,9 @@
virtual bool canReceiveRemoteControlCommands() const = 0;
virtual void didReceiveRemoteControlCommand(MediaSession::RemoteControlCommandType) = 0;
+ virtual void setShouldBufferData(bool) { }
+ virtual bool elementIsHidden() const { return false; }
+
protected:
virtual ~MediaSessionClient() { }
};
Modified: trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp (167733 => 167734)
--- trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp 2014-04-24 00:43:15 UTC (rev 167733)
+++ trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp 2014-04-24 01:23:58 UTC (rev 167734)
@@ -513,6 +513,11 @@
m_private->pause();
}
+void MediaPlayer::setShouldBufferData(bool shouldBuffer)
+{
+ m_private->setShouldBufferData(shouldBuffer);
+}
+
#if ENABLE(ENCRYPTED_MEDIA)
MediaPlayer::MediaKeyException MediaPlayer::generateKeyRequest(const String& keySystem, const unsigned char* initData, unsigned initDataLength)
{
Modified: trunk/Source/WebCore/platform/graphics/MediaPlayer.h (167733 => 167734)
--- trunk/Source/WebCore/platform/graphics/MediaPlayer.h 2014-04-24 00:43:15 UTC (rev 167733)
+++ trunk/Source/WebCore/platform/graphics/MediaPlayer.h 2014-04-24 01:23:58 UTC (rev 167734)
@@ -338,6 +338,7 @@
void prepareToPlay();
void play();
void pause();
+ void setShouldBufferData(bool);
#if ENABLE(ENCRYPTED_MEDIA) || ENABLE(ENCRYPTED_MEDIA_V2)
// Represents synchronous exceptions that can be thrown from the Encrypted Media methods.
Modified: trunk/Source/WebCore/platform/graphics/MediaPlayerPrivate.h (167733 => 167734)
--- trunk/Source/WebCore/platform/graphics/MediaPlayerPrivate.h 2014-04-24 00:43:15 UTC (rev 167733)
+++ trunk/Source/WebCore/platform/graphics/MediaPlayerPrivate.h 2014-04-24 01:23:58 UTC (rev 167734)
@@ -66,6 +66,7 @@
virtual void play() = 0;
virtual void pause() = 0;
+ virtual void setShouldBufferData(bool) { }
virtual bool supportsFullscreen() const { return false; }
virtual bool supportsSave() const { return false; }
Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h (167733 => 167734)
--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h 2014-04-24 00:43:15 UTC (rev 167733)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.h 2014-04-24 01:23:58 UTC (rev 167734)
@@ -111,6 +111,8 @@
void rateDidChange(double);
void metadataDidArrive(RetainPtr<NSArray>, double);
+ virtual void setShouldBufferData(bool);
+
#if HAVE(AVFOUNDATION_VIDEO_OUTPUT)
void outputMediaDataWillChange(AVPlayerItemVideoOutput*);
#endif
@@ -326,6 +328,7 @@
bool m_cachedBufferEmpty;
bool m_cachedBufferFull;
bool m_cachedHasEnabledAudio;
+ bool m_shouldBufferData;
#if ENABLE(IOS_AIRPLAY)
mutable bool m_allowsWirelessVideoPlayback;
#endif
Modified: trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm (167733 => 167734)
--- trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm 2014-04-24 00:43:15 UTC (rev 167733)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/objc/MediaPlayerPrivateAVFoundationObjC.mm 2014-04-24 01:23:58 UTC (rev 167734)
@@ -371,6 +371,7 @@
, m_cachedBufferEmpty(false)
, m_cachedBufferFull(false)
, m_cachedHasEnabledAudio(false)
+ , m_shouldBufferData(true)
#if ENABLE(IOS_AIRPLAY)
, m_allowsWirelessVideoPlayback(true)
#endif
@@ -2274,6 +2275,23 @@
updateStates();
}
+void MediaPlayerPrivateAVFoundationObjC::setShouldBufferData(bool shouldBuffer)
+{
+ LOG(Media, "MediaPlayerPrivateAVFoundationObjC::shouldBufferData(%p) - %s", this, boolString(shouldBuffer));
+ if (m_shouldBufferData == shouldBuffer)
+ return;
+
+ m_shouldBufferData = shouldBuffer;
+
+ if (!m_avPlayer)
+ return;
+
+ if (m_shouldBufferData)
+ [m_avPlayer.get() replaceCurrentItemWithPlayerItem:m_avPlayerItem.get()];
+ else
+ [m_avPlayer.get() replaceCurrentItemWithPlayerItem:nil];
+}
+
#if ENABLE(DATACUE_VALUE)
static const AtomicString& metadataType(NSString *avMetadataKeySpace)
{