mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-27 07:34:20 +00:00
Bug 831193 (part 16) - Don't use NS_MEMORY_REPORTER_IMPLEMENT in media/. r=kinetik.
--HG-- extra : rebase_source : 86c334ccef76af552b64317a08d1c4cb8c3804e3
This commit is contained in:
parent
033d246768
commit
2e51adde9d
@ -1,5 +1,5 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
@ -54,15 +54,15 @@ PRLogModuleInfo* gMediaDecoderLog;
|
||||
#define LOG(type, msg)
|
||||
#endif
|
||||
|
||||
class MediaMemoryReporter
|
||||
class MediaMemoryTracker
|
||||
{
|
||||
MediaMemoryReporter();
|
||||
~MediaMemoryReporter();
|
||||
static MediaMemoryReporter* sUniqueInstance;
|
||||
MediaMemoryTracker();
|
||||
~MediaMemoryTracker();
|
||||
static MediaMemoryTracker* sUniqueInstance;
|
||||
|
||||
static MediaMemoryReporter* UniqueInstance() {
|
||||
static MediaMemoryTracker* UniqueInstance() {
|
||||
if (!sUniqueInstance) {
|
||||
sUniqueInstance = new MediaMemoryReporter;
|
||||
sUniqueInstance = new MediaMemoryTracker();
|
||||
}
|
||||
return sUniqueInstance;
|
||||
}
|
||||
@ -74,15 +74,16 @@ class MediaMemoryReporter
|
||||
|
||||
DecodersArray mDecoders;
|
||||
|
||||
nsCOMPtr<nsIMemoryReporter> mMediaDecodedVideoMemory;
|
||||
nsCOMPtr<nsIMemoryReporter> mMediaDecodedAudioMemory;
|
||||
nsCOMPtr<nsIMemoryMultiReporter> mReporter;
|
||||
|
||||
public:
|
||||
static void AddMediaDecoder(MediaDecoder* aDecoder) {
|
||||
static void AddMediaDecoder(MediaDecoder* aDecoder)
|
||||
{
|
||||
Decoders().AppendElement(aDecoder);
|
||||
}
|
||||
|
||||
static void RemoveMediaDecoder(MediaDecoder* aDecoder) {
|
||||
static void RemoveMediaDecoder(MediaDecoder* aDecoder)
|
||||
{
|
||||
DecodersArray& decoders = Decoders();
|
||||
decoders.RemoveElement(aDecoder);
|
||||
if (decoders.IsEmpty()) {
|
||||
@ -91,25 +92,20 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
static int64_t GetDecodedVideoMemory() {
|
||||
static void GetAmounts(int64_t* aVideo, int64_t* aAudio)
|
||||
{
|
||||
*aVideo = 0;
|
||||
*aAudio = 0;
|
||||
DecodersArray& decoders = Decoders();
|
||||
int64_t result = 0;
|
||||
for (size_t i = 0; i < decoders.Length(); ++i) {
|
||||
result += decoders[i]->VideoQueueMemoryInUse();
|
||||
*aVideo += decoders[i]->VideoQueueMemoryInUse();
|
||||
*aAudio += decoders[i]->AudioQueueMemoryInUse();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
static int64_t GetDecodedAudioMemory() {
|
||||
DecodersArray& decoders = Decoders();
|
||||
int64_t result = 0;
|
||||
for (size_t i = 0; i < decoders.Length(); ++i) {
|
||||
result += decoders[i]->AudioQueueMemoryInUse();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
MediaMemoryTracker* MediaMemoryTracker::sUniqueInstance = nullptr;
|
||||
|
||||
NS_IMPL_ISUPPORTS1(MediaDecoder, nsIObserver)
|
||||
|
||||
void MediaDecoder::SetDormantIfNecessary(bool aDormant)
|
||||
@ -389,7 +385,7 @@ MediaDecoder::MediaDecoder() :
|
||||
{
|
||||
MOZ_COUNT_CTOR(MediaDecoder);
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MediaMemoryReporter::AddMediaDecoder(this);
|
||||
MediaMemoryTracker::AddMediaDecoder(this);
|
||||
#ifdef PR_LOGGING
|
||||
if (!gMediaDecoderLog) {
|
||||
gMediaDecoderLog = PR_NewLogModule("MediaDecoder");
|
||||
@ -444,7 +440,7 @@ void MediaDecoder::Shutdown()
|
||||
MediaDecoder::~MediaDecoder()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MediaMemoryReporter::RemoveMediaDecoder(this);
|
||||
MediaMemoryTracker::RemoveMediaDecoder(this);
|
||||
UnpinForSeek();
|
||||
MOZ_COUNT_DTOR(MediaDecoder);
|
||||
}
|
||||
@ -1731,6 +1727,45 @@ MediaDecoder::IsWMFEnabled()
|
||||
}
|
||||
#endif
|
||||
|
||||
class MediaReporter MOZ_FINAL : public nsIMemoryMultiReporter
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD GetName(nsACString& aName)
|
||||
{
|
||||
aName.AssignLiteral("media");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD CollectReports(nsIMemoryMultiReporterCallback* aCb,
|
||||
nsISupports* aClosure)
|
||||
{
|
||||
int64_t video, audio;
|
||||
MediaMemoryTracker::GetAmounts(&video, &audio);
|
||||
|
||||
#define REPORT(_path, _amount, _desc) \
|
||||
do { \
|
||||
nsresult rv; \
|
||||
rv = aCb->Callback(EmptyCString(), NS_LITERAL_CSTRING(_path), \
|
||||
nsIMemoryReporter::KIND_HEAP, \
|
||||
nsIMemoryReporter::UNITS_BYTES, _amount, \
|
||||
NS_LITERAL_CSTRING(_desc), aClosure); \
|
||||
NS_ENSURE_SUCCESS(rv, rv); \
|
||||
} while (0)
|
||||
|
||||
REPORT("explicit/media/decoded-video", video,
|
||||
"Memory used by decoded video frames.");
|
||||
|
||||
REPORT("explicit/media/decoded-audio", audio,
|
||||
"Memory used by decoded audio chunks.");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS1(MediaReporter, nsIMemoryMultiReporter)
|
||||
|
||||
MediaDecoderOwner*
|
||||
MediaDecoder::GetOwner()
|
||||
{
|
||||
@ -1738,34 +1773,15 @@ MediaDecoder::GetOwner()
|
||||
return mOwner;
|
||||
}
|
||||
|
||||
MediaMemoryReporter* MediaMemoryReporter::sUniqueInstance;
|
||||
|
||||
NS_MEMORY_REPORTER_IMPLEMENT(MediaDecodedVideoMemory,
|
||||
"explicit/media/decoded-video",
|
||||
KIND_HEAP,
|
||||
UNITS_BYTES,
|
||||
MediaMemoryReporter::GetDecodedVideoMemory,
|
||||
"Memory used by decoded video frames.")
|
||||
|
||||
NS_MEMORY_REPORTER_IMPLEMENT(MediaDecodedAudioMemory,
|
||||
"explicit/media/decoded-audio",
|
||||
KIND_HEAP,
|
||||
UNITS_BYTES,
|
||||
MediaMemoryReporter::GetDecodedAudioMemory,
|
||||
"Memory used by decoded audio chunks.")
|
||||
|
||||
MediaMemoryReporter::MediaMemoryReporter()
|
||||
: mMediaDecodedVideoMemory(new NS_MEMORY_REPORTER_NAME(MediaDecodedVideoMemory))
|
||||
, mMediaDecodedAudioMemory(new NS_MEMORY_REPORTER_NAME(MediaDecodedAudioMemory))
|
||||
MediaMemoryTracker::MediaMemoryTracker()
|
||||
: mReporter(new MediaReporter())
|
||||
{
|
||||
NS_RegisterMemoryReporter(mMediaDecodedVideoMemory);
|
||||
NS_RegisterMemoryReporter(mMediaDecodedAudioMemory);
|
||||
NS_RegisterMemoryMultiReporter(mReporter);
|
||||
}
|
||||
|
||||
MediaMemoryReporter::~MediaMemoryReporter()
|
||||
MediaMemoryTracker::~MediaMemoryTracker()
|
||||
{
|
||||
NS_UnregisterMemoryReporter(mMediaDecodedVideoMemory);
|
||||
NS_UnregisterMemoryReporter(mMediaDecodedAudioMemory);
|
||||
NS_UnregisterMemoryMultiReporter(mReporter);
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
||||
|
Loading…
x
Reference in New Issue
Block a user