Bug 117608 - Report the memory cost of HTMLMediaElements to GC.
Summary: Report the memory cost of HTMLMediaElements to GC.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Media (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Jer Noble
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-13 14:08 PDT by Jer Noble
Modified: 2013-06-14 15:40 PDT (History)
5 users (show)

See Also:


Attachments
Patch (7.84 KB, patch)
2013-06-13 14:14 PDT, Jer Noble
darin: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jer Noble 2013-06-13 14:08:32 PDT
Report the memory cost of HTMLMediaElements to GC.
Comment 1 Jer Noble 2013-06-13 14:14:18 PDT
Created attachment 204642 [details]
Patch
Comment 2 Darin Adler 2013-06-13 17:42:54 PDT
Comment on attachment 204642 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=204642&action=review

> Source/WebCore/html/HTMLMediaElement.cpp:622
> +            double extraMemoryCost = m_player->extraMemoryCost();
> +            double extraMemoryCostDelta = extraMemoryCost - m_reportedExtraMemoryCost;
> +            m_reportedExtraMemoryCost = extraMemoryCost;

Why the mix of double and size_t here? It seems like extraMemoryCost is returning size_t, so this should just be size_t.

> Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp:883
> +    return totalBytes() * buffered()->totalDuration() / duration;

Is there something that prevents this from overflowing a size_t?

> Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h:269
> +    virtual size_t extraMemoryCost() const OVERRIDE;

Either this class or this function should be marked FINAL too.
Comment 3 Eric Carlson 2013-06-14 07:23:33 PDT
Comment on attachment 204642 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=204642&action=review

> Source/WebCore/platform/graphics/MediaPlayerPrivate.h:209
> +    virtual size_t extraMemoryCost() const { return 0; }

Most (all?) ports will want the simple implementation you added to MediaPlayerPrivateAVFoundation.cpp - why not put it here?
Comment 4 Jer Noble 2013-06-14 15:33:51 PDT
(In reply to comment #2)
> (From update of attachment 204642 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=204642&action=review
> 
> > Source/WebCore/html/HTMLMediaElement.cpp:622
> > +            double extraMemoryCost = m_player->extraMemoryCost();
> > +            double extraMemoryCostDelta = extraMemoryCost - m_reportedExtraMemoryCost;
> > +            m_reportedExtraMemoryCost = extraMemoryCost;
> 
> Why the mix of double and size_t here? It seems like extraMemoryCost is returning size_t, so this should just be size_t.

No good reason; these should indeed be size_t.

> > Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp:883
> > +    return totalBytes() * buffered()->totalDuration() / duration;
> 
> Is there something that prevents this from overflowing a size_t?

Since totalBytes() is an unsigned, and (totalDuration() / duration) will be in the range [0..1], this can never overflow a size_t.

> > Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.h:269
> > +    virtual size_t extraMemoryCost() const OVERRIDE;
> 
> Either this class or this function should be marked FINAL too.

Sure thing.  Thanks!
Comment 5 Jer Noble 2013-06-14 15:34:27 PDT
(In reply to comment #3)
> (From update of attachment 204642 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=204642&action=review
> 
> > Source/WebCore/platform/graphics/MediaPlayerPrivate.h:209
> > +    virtual size_t extraMemoryCost() const { return 0; }
> 
> Most (all?) ports will want the simple implementation you added to MediaPlayerPrivateAVFoundation.cpp - why not put it here?

I guess that makes sense.  If any port wants their own implementation, they can just override it.
Comment 6 Jer Noble 2013-06-14 15:36:10 PDT
(In reply to comment #5)
> (In reply to comment #3)
> > (From update of attachment 204642 [details] [details])
> > View in context: https://bugs.webkit.org/attachment.cgi?id=204642&action=review
> > 
> > > Source/WebCore/platform/graphics/MediaPlayerPrivate.h:209
> > > +    virtual size_t extraMemoryCost() const { return 0; }
> > 
> > Most (all?) ports will want the simple implementation you added to MediaPlayerPrivateAVFoundation.cpp - why not put it here?
> 
> I guess that makes sense.  If any port wants their own implementation, they can just override it.

Ah, it can't go into MediaPlayerPrivate because MediaPlayerPrivate does not have a "totalBytes()" method.
Comment 7 Jer Noble 2013-06-14 15:40:40 PDT
Committed r151609: <http://trac.webkit.org/changeset/151609>