Bug 1760920 - pt 10. Count only the media resources belonging to the document r=media-playback-reviewers,padenot

Differential Revision: https://phabricator.services.mozilla.com/D146893
This commit is contained in:
Paul Bone 2022-11-07 22:36:39 +00:00
Родитель a5bbf4a831
Коммит 7482f9e4fd
3 изменённых файлов: 35 добавлений и 18 удалений

Просмотреть файл

@ -115,7 +115,7 @@ class MediaMemoryTracker : public nsIMemoryReporter {
}
}
static RefPtr<MediaMemoryPromise> GetSizes() {
static RefPtr<MediaMemoryPromise> GetSizes(dom::Document* aDoc) {
MOZ_ASSERT(NS_IsMainThread());
DecodersArray& decoders = Decoders();
@ -133,9 +133,11 @@ class MediaMemoryTracker : public nsIMemoryReporter {
size_t audioSize = 0;
for (auto&& decoder : decoders) {
videoSize += decoder->SizeOfVideoQueue();
audioSize += decoder->SizeOfAudioQueue();
decoder->AddSizeOfResources(resourceSizes);
if (decoder->GetOwner()->GetDocument() == aDoc) {
videoSize += decoder->SizeOfVideoQueue();
audioSize += decoder->SizeOfAudioQueue();
decoder->AddSizeOfResources(resourceSizes);
}
}
return resourceSizes->Promise()->Then(
@ -153,8 +155,8 @@ class MediaMemoryTracker : public nsIMemoryReporter {
StaticRefPtr<MediaMemoryTracker> MediaMemoryTracker::sUniqueInstance;
RefPtr<MediaMemoryPromise> GetMediaMemorySizes() {
return MediaMemoryTracker::GetSizes();
RefPtr<MediaMemoryPromise> GetMediaMemorySizes(dom::Document* aDoc) {
return MediaMemoryTracker::GetSizes(aDoc);
}
LazyLogModule gMediaTimerLog("MediaTimer");

Просмотреть файл

@ -768,7 +768,7 @@ class MediaDecoder : public DecoderDoctorLifeLogger<MediaDecoder> {
typedef MozPromise<mozilla::dom::MediaMemoryInfo, nsresult, true>
MediaMemoryPromise;
RefPtr<MediaMemoryPromise> GetMediaMemorySizes();
RefPtr<MediaMemoryPromise> GetMediaMemorySizes(dom::Document* aDoc);
} // namespace mozilla

Просмотреть файл

@ -131,6 +131,7 @@ RefPtr<MemoryPromise> CollectMemoryInfo(
SharedSet sharedVisited;
// Getting JS-related memory usage
uint64_t jsMemUsed = 0;
nsTArray<RefPtr<MediaMemoryPromise>> mediaMemoryPromises;
for (auto* doc : *aDocGroup) {
bool unused;
nsIGlobalObject* globalObject = doc->GetScriptHandlingObject(unused);
@ -170,20 +171,34 @@ RefPtr<MemoryPromise> CollectMemoryInfo(
}
}
}
mediaMemoryPromises.AppendElement(GetMediaMemorySizes(doc));
}
// Getting Media sizes.
return GetMediaMemorySizes()->Then(
aEventTarget, __func__,
[jsMemUsed, sizes](const MediaMemoryInfo& media) {
return MemoryPromise::CreateAndResolve(
PerformanceMemoryInfo(media, sizes.mDom, sizes.mStyle, sizes.mOther,
jsMemUsed),
__func__);
},
[](const nsresult rv) {
return MemoryPromise::CreateAndReject(rv, __func__);
});
return MediaMemoryPromise::All(aEventTarget, mediaMemoryPromises)
->Then(
aEventTarget, __func__,
[jsMemUsed, sizes](const nsTArray<MediaMemoryInfo> mediaArray) {
size_t audioSize = 0;
size_t videoSize = 0;
size_t resourcesSize = 0;
for (auto media : mediaArray) {
audioSize += media.audioSize();
videoSize += media.videoSize();
resourcesSize += media.resourcesSize();
}
return MemoryPromise::CreateAndResolve(
PerformanceMemoryInfo(
MediaMemoryInfo(audioSize, videoSize, resourcesSize),
sizes.mDom, sizes.mStyle, sizes.mOther, jsMemUsed),
__func__);
},
[](const nsresult rv) {
return MemoryPromise::CreateAndReject(rv, __func__);
});
}
} // namespace mozilla