Bug 961441: Use MallocSizeOf to report decoded-audio memory. r=cpearce r=njn
authorBen Kelly <ben@wanderview.com>
Wed, 22 Jan 2014 22:14:45 -0500
changeset 180832 76f23abe25fc5da0602bc1f17e03a0987b6039e1
parent 180831 2691ac9bdbfe38b8e10f098b07add37b2575fdb2
child 180833 25d97cbba816ec15f1d50de8b57b0234dbc2dee6
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce, njn
bugs961441
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 961441: Use MallocSizeOf to report decoded-audio memory. r=cpearce r=njn
content/media/MediaDecoder.cpp
content/media/MediaDecoder.h
content/media/MediaDecoderReader.h
content/media/MediaDecoderStateMachine.h
content/media/SharedBuffer.h
--- a/content/media/MediaDecoder.cpp
+++ b/content/media/MediaDecoder.cpp
@@ -1564,19 +1564,19 @@ nsresult MediaDecoder::GetBuffered(dom::
 
 int64_t MediaDecoder::VideoQueueMemoryInUse() {
   if (mDecoderStateMachine) {
     return mDecoderStateMachine->VideoQueueMemoryInUse();
   }
   return 0;
 }
 
-int64_t MediaDecoder::AudioQueueMemoryInUse() {
+size_t MediaDecoder::SizeOfAudioQueue() {
   if (mDecoderStateMachine) {
-    return mDecoderStateMachine->AudioQueueMemoryInUse();
+    return mDecoderStateMachine->SizeOfAudioQueue();
   }
   return 0;
 }
 
 void MediaDecoder::NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset) {
   if (mDecoderStateMachine) {
     mDecoderStateMachine->NotifyDataArrived(aBuffer, aLength, aOffset);
   }
@@ -1821,17 +1821,17 @@ MediaDecoder::IsAppleMP3Enabled()
 NS_IMETHODIMP
 MediaMemoryTracker::CollectReports(nsIHandleReportCallback* aHandleReport,
                                    nsISupports* aData)
 {
   int64_t video = 0, audio = 0;
   DecodersArray& decoders = Decoders();
   for (size_t i = 0; i < decoders.Length(); ++i) {
     video += decoders[i]->VideoQueueMemoryInUse();
-    audio += decoders[i]->AudioQueueMemoryInUse();
+    audio += decoders[i]->SizeOfAudioQueue();
   }
 
 #define REPORT(_path, _amount, _desc)                                         \
   do {                                                                        \
       nsresult rv;                                                            \
       rv = aHandleReport->Callback(EmptyCString(), NS_LITERAL_CSTRING(_path), \
                                    KIND_HEAP, UNITS_BYTES, _amount,           \
                                    NS_LITERAL_CSTRING(_desc), aData);         \
--- a/content/media/MediaDecoder.h
+++ b/content/media/MediaDecoder.h
@@ -637,17 +637,17 @@ public:
 
   // Constructs the time ranges representing what segments of the media
   // are buffered and playable.
   virtual nsresult GetBuffered(dom::TimeRanges* aBuffered);
 
   // Returns the size, in bytes, of the heap memory used by the currently
   // queued decoded video and audio data.
   virtual int64_t VideoQueueMemoryInUse();
-  virtual int64_t AudioQueueMemoryInUse();
+  size_t SizeOfAudioQueue();
 
   VideoFrameContainer* GetVideoFrameContainer() MOZ_FINAL MOZ_OVERRIDE
   {
     return mVideoFrameContainer;
   }
   layers::ImageContainer* GetImageContainer() MOZ_OVERRIDE;
 
   // Sets the length of the framebuffer used in MozAudioAvailable events.
--- a/content/media/MediaDecoderReader.h
+++ b/content/media/MediaDecoderReader.h
@@ -8,16 +8,17 @@
 
 #include <nsDeque.h>
 #include "nsSize.h"
 #include "mozilla/ReentrantMonitor.h"
 #include "SharedBuffer.h"
 #include "AudioSampleFormat.h"
 #include "AbstractMediaDecoder.h"
 #include "ImageTypes.h"
+#include "nsIMemoryReporter.h"
 
 struct nsIntRect;
 
 namespace mozilla {
 
 namespace layers {
 class Image;
 class ImageContainer;
@@ -149,16 +150,24 @@ public:
     MOZ_COUNT_CTOR(AudioData);
   }
 
   ~AudioData()
   {
     MOZ_COUNT_DTOR(AudioData);
   }
 
+  size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
+    size_t size = aMallocSizeOf(this) + aMallocSizeOf(mAudioData);
+    if (mAudioBuffer) {
+      size += mAudioBuffer->SizeOfIncludingThis(aMallocSizeOf);
+    }
+    return size;
+  }
+
   // If mAudioBuffer is null, creates it from mAudioData.
   void EnsureAudioBuffer();
 
   const uint32_t mFrames;
   const uint32_t mChannels;
   // At least one of mAudioBuffer/mAudioData must be non-null.
   // mChannels channels, each with mFrames frames
   nsRefPtr<SharedBuffer> mAudioBuffer;
@@ -577,31 +586,33 @@ public:
   virtual int64_t VideoQueueMemoryInUse() {
     VideoQueueMemoryFunctor functor;
     mVideoQueue.LockedForEach(functor);
     return functor.mResult;
   }
 
   class AudioQueueMemoryFunctor : public nsDequeFunctor {
   public:
-    AudioQueueMemoryFunctor() : mResult(0) {}
+    AudioQueueMemoryFunctor() : mSize(0) {}
+
+    MOZ_DEFINE_MALLOC_SIZE_OF(MallocSizeOf);
 
     virtual void* operator()(void* anObject) {
       const AudioData* audioData = static_cast<const AudioData*>(anObject);
-      mResult += audioData->mFrames * audioData->mChannels * sizeof(AudioDataValue);
+      mSize += audioData->SizeOfIncludingThis(MallocSizeOf);
       return nullptr;
     }
 
-    int64_t mResult;
+    size_t mSize;
   };
 
-  virtual int64_t AudioQueueMemoryInUse() {
+  size_t SizeOfAudioQueue() {
     AudioQueueMemoryFunctor functor;
     mAudioQueue.LockedForEach(functor);
-    return functor.mResult;
+    return functor.mSize;
   }
 
   // Only used by WebMReader and MediaOmxReader for now, so stub here rather
   // than in every reader than inherits from MediaDecoderReader.
   virtual void NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset) {}
 
   virtual MediaQueue<AudioData>& AudioQueue() { return mAudioQueue; }
   virtual MediaQueue<VideoData>& VideoQueue() { return mVideoQueue; }
--- a/content/media/MediaDecoderStateMachine.h
+++ b/content/media/MediaDecoderStateMachine.h
@@ -262,19 +262,19 @@ public:
 
   int64_t VideoQueueMemoryInUse() {
     if (mReader) {
       return mReader->VideoQueueMemoryInUse();
     }
     return 0;
   }
 
-  int64_t AudioQueueMemoryInUse() {
+  size_t SizeOfAudioQueue() {
     if (mReader) {
-      return mReader->AudioQueueMemoryInUse();
+      return mReader->SizeOfAudioQueue();
     }
     return 0;
   }
 
   void NotifyDataArrived(const char* aBuffer, uint32_t aLength, int64_t aOffset);
 
   int64_t GetEndMediaTime() const {
     AssertCurrentThreadInMonitor();
--- a/content/media/SharedBuffer.h
+++ b/content/media/SharedBuffer.h
@@ -38,15 +38,19 @@ public:
   {
     void* m = moz_xmalloc(sizeof(SharedBuffer) + aSize);
     nsRefPtr<SharedBuffer> p = new (m) SharedBuffer();
     NS_ASSERTION((reinterpret_cast<char*>(p.get() + 1) - reinterpret_cast<char*>(p.get())) % 4 == 0,
                  "SharedBuffers should be at least 4-byte aligned");
     return p.forget();
   }
 
+  size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
+    return aMallocSizeOf(this);
+  }
+
 private:
   SharedBuffer() {}
 };
 
 }
 
 #endif /* MOZILLA_SHAREDBUFFER_H_ */