- Revision
- 151609
- Author
- [email protected]
- Date
- 2013-06-14 15:40:10 -0700 (Fri, 14 Jun 2013)
Log Message
Report the memory cost of HTMLMediaElements to GC.
https://bugs.webkit.org/show_bug.cgi?id=117608
Reviewed by Darin Adler.
Report the extra memory cost of a HTMLMediaElement to the VM, in order to
encourage GC to occur after a media element is removed from the DOM.
Because we cannot know for sure the memory cost of our underlying media
framework objects, use the worst case scenario for the media memory cost:
the buffered percentage of movie * the total data length of the movie.
* html/HTMLMediaElement.cpp:
(WebCore::HTMLMediaElement::HTMLMediaElement): Initialize m_reportedExtraMemoryCost.
(WebCore::HTMLMediaElement::removedFrom): Report the extra memory cost.
* html/HTMLMediaElement.h:
* html/TimeRanges.cpp:
(TimeRanges::totalDuration): Added convenience function.
* html/TimeRanges.h:
* platform/graphics/MediaPlayer.cpp:
(WebCore::MediaPlayer::extraMemoryCost): Pass to MediaPlayerPrivate.
* platform/graphics/MediaPlayer.h:
* platform/graphics/MediaPlayerPrivate.h:
(WebCore::MediaPlayerPrivateInterface::extraMemoryCost): Default to 0.
* platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp:
(WebCore::MediaPlayerPrivateAVFoundation::extraMemoryCost): Return the percentage
loaded * total data length.
* platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (151608 => 151609)
--- trunk/Source/WebCore/ChangeLog 2013-06-14 22:27:35 UTC (rev 151608)
+++ trunk/Source/WebCore/ChangeLog 2013-06-14 22:40:10 UTC (rev 151609)
@@ -1,5 +1,36 @@
2013-06-13 Jer Noble <[email protected]>
+ Report the memory cost of HTMLMediaElements to GC.
+ https://bugs.webkit.org/show_bug.cgi?id=117608
+
+ Reviewed by Darin Adler.
+
+ Report the extra memory cost of a HTMLMediaElement to the VM, in order to
+ encourage GC to occur after a media element is removed from the DOM.
+
+ Because we cannot know for sure the memory cost of our underlying media
+ framework objects, use the worst case scenario for the media memory cost:
+ the buffered percentage of movie * the total data length of the movie.
+
+ * html/HTMLMediaElement.cpp:
+ (WebCore::HTMLMediaElement::HTMLMediaElement): Initialize m_reportedExtraMemoryCost.
+ (WebCore::HTMLMediaElement::removedFrom): Report the extra memory cost.
+ * html/HTMLMediaElement.h:
+ * html/TimeRanges.cpp:
+ (TimeRanges::totalDuration): Added convenience function.
+ * html/TimeRanges.h:
+ * platform/graphics/MediaPlayer.cpp:
+ (WebCore::MediaPlayer::extraMemoryCost): Pass to MediaPlayerPrivate.
+ * platform/graphics/MediaPlayer.h:
+ * platform/graphics/MediaPlayerPrivate.h:
+ (WebCore::MediaPlayerPrivateInterface::extraMemoryCost): Default to 0.
+ * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp:
+ (WebCore::MediaPlayerPrivateAVFoundation::extraMemoryCost): Return the percentage
+ loaded * total data length.
+ * platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h:
+
+2013-06-13 Jer Noble <[email protected]>
+
Add support for AVFoundation-backed HTMLMediaElements in the WebVideoFullScreenController.
https://bugs.webkit.org/show_bug.cgi?id=117597
Modified: trunk/Source/WebCore/html/HTMLMediaElement.cpp (151608 => 151609)
--- trunk/Source/WebCore/html/HTMLMediaElement.cpp 2013-06-14 22:27:35 UTC (rev 151608)
+++ trunk/Source/WebCore/html/HTMLMediaElement.cpp 2013-06-14 22:40:10 UTC (rev 151609)
@@ -324,6 +324,7 @@
#if USE(AUDIO_SESSION)
, m_audioSessionManagerToken(AudioSessionManagerToken::create(tagName == videoTag ? AudioSessionManager::Video : AudioSessionManager::Audio))
#endif
+ , m_reportedExtraMemoryCost(0)
{
LOG(Media, "HTMLMediaElement::HTMLMediaElement");
document->registerForMediaVolumeCallbacks(this);
@@ -613,6 +614,18 @@
pause();
if (m_isFullscreen)
exitFullscreen();
+
+ if (m_player) {
+ JSC::VM* vm = JSDOMWindowBase::commonVM();
+ JSC::JSLockHolder lock(vm);
+
+ size_t extraMemoryCost = m_player->extraMemoryCost();
+ size_t extraMemoryCostDelta = extraMemoryCost - m_reportedExtraMemoryCost;
+ m_reportedExtraMemoryCost = extraMemoryCost;
+
+ if (extraMemoryCostDelta > 0)
+ vm->heap.reportExtraMemoryCost(extraMemoryCostDelta);
+ }
}
HTMLElement::removedFrom(insertionPoint);
Modified: trunk/Source/WebCore/html/HTMLMediaElement.h (151608 => 151609)
--- trunk/Source/WebCore/html/HTMLMediaElement.h 2013-06-14 22:27:35 UTC (rev 151608)
+++ trunk/Source/WebCore/html/HTMLMediaElement.h 2013-06-14 22:40:10 UTC (rev 151609)
@@ -776,6 +776,7 @@
#endif
OwnPtr<PageActivityAssertionToken> m_activityToken;
+ size_t m_reportedExtraMemoryCost;
};
#if ENABLE(VIDEO_TRACK)
Modified: trunk/Source/WebCore/html/TimeRanges.cpp (151608 => 151609)
--- trunk/Source/WebCore/html/TimeRanges.cpp 2013-06-14 22:27:35 UTC (rev 151608)
+++ trunk/Source/WebCore/html/TimeRanges.cpp 2013-06-14 22:40:10 UTC (rev 151609)
@@ -186,3 +186,11 @@
}
return closestTime;
}
+
+double TimeRanges::totalDuration() const
+{
+ double total = 0;
+ for (unsigned n = 0; n < length(); n++)
+ total += fabs(end(n, IGNORE_EXCEPTION) - start(n, IGNORE_EXCEPTION));
+ return total;
+}
Modified: trunk/Source/WebCore/html/TimeRanges.h (151608 => 151609)
--- trunk/Source/WebCore/html/TimeRanges.h 2013-06-14 22:27:35 UTC (rev 151608)
+++ trunk/Source/WebCore/html/TimeRanges.h 2013-06-14 22:40:10 UTC (rev 151609)
@@ -61,6 +61,8 @@
double nearest(double time) const;
+ double totalDuration() const;
+
private:
TimeRanges() { }
TimeRanges(double start, double end);
Modified: trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp (151608 => 151609)
--- trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp 2013-06-14 22:27:35 UTC (rev 151608)
+++ trunk/Source/WebCore/platform/graphics/MediaPlayer.cpp 2013-06-14 22:40:10 UTC (rev 151609)
@@ -1196,6 +1196,15 @@
return m_private->languageOfPrimaryAudioTrack();
}
+
+size_t MediaPlayer::extraMemoryCost() const
+{
+ if (!m_private)
+ return 0;
+
+ return m_private->extraMemoryCost();
}
+}
+
#endif
Modified: trunk/Source/WebCore/platform/graphics/MediaPlayer.h (151608 => 151609)
--- trunk/Source/WebCore/platform/graphics/MediaPlayer.h 2013-06-14 22:27:35 UTC (rev 151608)
+++ trunk/Source/WebCore/platform/graphics/MediaPlayer.h 2013-06-14 22:40:10 UTC (rev 151609)
@@ -480,6 +480,8 @@
String languageOfPrimaryAudioTrack() const;
+ size_t extraMemoryCost() const;
+
private:
MediaPlayer(MediaPlayerClient*);
void loadWithNextMediaEngine(MediaPlayerFactory*);
Modified: trunk/Source/WebCore/platform/graphics/MediaPlayerPrivate.h (151608 => 151609)
--- trunk/Source/WebCore/platform/graphics/MediaPlayerPrivate.h 2013-06-14 22:27:35 UTC (rev 151608)
+++ trunk/Source/WebCore/platform/graphics/MediaPlayerPrivate.h 2013-06-14 22:40:10 UTC (rev 151609)
@@ -205,6 +205,8 @@
#endif
virtual String languageOfPrimaryAudioTrack() const { return emptyString(); }
+
+ virtual size_t extraMemoryCost() const { return 0; }
};
}
Modified: trunk/Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp (151608 => 151609)
--- trunk/Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp 2013-06-14 22:27:35 UTC (rev 151608)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp 2013-06-14 22:40:10 UTC (rev 151609)
@@ -874,6 +874,15 @@
}
#endif
+size_t MediaPlayerPrivateAVFoundation::extraMemoryCost() const
+{
+ double duration = this->duration();
+ if (!duration)
+ return 0;
+
+ return totalBytes() * buffered()->totalDuration() / duration;
+}
+
} // namespace WebCore
#endif
Modified: trunk/Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h (151608 => 151609)
--- trunk/Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h 2013-06-14 22:27:35 UTC (rev 151608)
+++ trunk/Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h 2013-06-14 22:40:10 UTC (rev 151609)
@@ -266,6 +266,8 @@
virtual String engineDescription() const { return "AVFoundation"; }
+ virtual size_t extraMemoryCost() const OVERRIDE;
+
#if !PLATFORM(WIN)
virtual void trackModeChanged() OVERRIDE;
Vector<RefPtr<InbandTextTrackPrivateAVF> > m_textTracks;