Bug 1293145 - Simulate video-decode-suspend for telemetry purposes - r=kamidphish
After a video has been playing while hidden for a certain time, count the time until it is not hidden anymore (or it has finished playing), to test-drive how much decoding time would have been saved by the video-decode-suspend feature. Note that this is done inside HTMLMediaElement by simulating what should happen in the MDSM, because instrumenting the MDSM itself and friends would have been harder and more intrusive. MozReview-Commit-ID: LdxhPtmoXeA
This commit is contained in:
@@ -48,9 +48,10 @@
|
||||
|
||||
#include "MediaError.h"
|
||||
#include "MediaDecoder.h"
|
||||
#include "nsICategoryManager.h"
|
||||
#include "MediaPrefs.h"
|
||||
#include "MediaResource.h"
|
||||
|
||||
#include "nsICategoryManager.h"
|
||||
#include "nsIContentPolicy.h"
|
||||
#include "nsContentPolicyUtils.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
@@ -2558,6 +2559,10 @@ HTMLMediaElement::~HTMLMediaElement()
|
||||
if (mProgressTimer) {
|
||||
StopProgress();
|
||||
}
|
||||
if (mVideoDecodeSuspendTimer) {
|
||||
mVideoDecodeSuspendTimer->Cancel();
|
||||
mVideoDecodeSuspendTimer = nullptr;
|
||||
}
|
||||
if (mSrcStream) {
|
||||
EndSrcMediaStreamPlayback();
|
||||
}
|
||||
@@ -3032,6 +3037,42 @@ nsresult HTMLMediaElement::BindToTree(nsIDocument* aDocument, nsIContent* aParen
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* static */
|
||||
void HTMLMediaElement::VideoDecodeSuspendTimerCallback(nsITimer* aTimer, void* aClosure)
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
auto element = static_cast<HTMLMediaElement*>(aClosure);
|
||||
element->mVideoDecodeSuspendTime.Start();
|
||||
element->mVideoDecodeSuspendTimer = nullptr;
|
||||
}
|
||||
|
||||
void HTMLMediaElement::HiddenVideoStart()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
mHiddenPlayTime.Start();
|
||||
if (mVideoDecodeSuspendTimer) {
|
||||
// Already started, just keep it running.
|
||||
return;
|
||||
}
|
||||
mVideoDecodeSuspendTimer = do_CreateInstance("@mozilla.org/timer;1");
|
||||
mVideoDecodeSuspendTimer->InitWithNamedFuncCallback(
|
||||
VideoDecodeSuspendTimerCallback, this,
|
||||
MediaPrefs::MDSMSuspendBackgroundVideoDelay(), nsITimer::TYPE_ONE_SHOT,
|
||||
"HTMLMediaElement::VideoDecodeSuspendTimerCallback");
|
||||
}
|
||||
|
||||
void HTMLMediaElement::HiddenVideoStop()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
mHiddenPlayTime.Pause();
|
||||
mVideoDecodeSuspendTime.Pause();
|
||||
if (!mVideoDecodeSuspendTimer) {
|
||||
return;
|
||||
}
|
||||
mVideoDecodeSuspendTimer->Cancel();
|
||||
mVideoDecodeSuspendTimer = nullptr;
|
||||
}
|
||||
|
||||
#ifdef MOZ_EME
|
||||
void
|
||||
HTMLMediaElement::ReportEMETelemetry()
|
||||
@@ -3118,6 +3159,7 @@ HTMLMediaElement::ReportTelemetry()
|
||||
// We have a valid video.
|
||||
double playTime = mPlayTime.Total();
|
||||
double hiddenPlayTime = mHiddenPlayTime.Total();
|
||||
double videoDecodeSuspendTime = mVideoDecodeSuspendTime.Total();
|
||||
|
||||
Telemetry::Accumulate(Telemetry::VIDEO_PLAY_TIME_MS, SECONDS_TO_MS(playTime));
|
||||
LOG(LogLevel::Debug, ("%p VIDEO_PLAY_TIME_MS = %f", this, playTime));
|
||||
@@ -3126,8 +3168,7 @@ HTMLMediaElement::ReportTelemetry()
|
||||
LOG(LogLevel::Debug, ("%p VIDEO_HIDDEN_PLAY_TIME_MS = %f", this, hiddenPlayTime));
|
||||
|
||||
if (playTime > 0.0) {
|
||||
// We have actually played something -> Report hidden/total ratio.
|
||||
uint32_t hiddenPercentage = uint32_t(hiddenPlayTime / playTime * 100.0 + 0.5);
|
||||
// We have actually played something -> Report some valid-video telemetry.
|
||||
|
||||
// Keyed by audio+video or video alone, and by a resolution range.
|
||||
nsCString key(mMediaInfo.HasAudio() ? "AV," : "V,");
|
||||
@@ -3149,6 +3190,7 @@ HTMLMediaElement::ReportTelemetry()
|
||||
}
|
||||
key.AppendASCII(resolution);
|
||||
|
||||
uint32_t hiddenPercentage = uint32_t(hiddenPlayTime / playTime * 100.0 + 0.5);
|
||||
Telemetry::Accumulate(Telemetry::VIDEO_HIDDEN_PLAY_TIME_PERCENTAGE,
|
||||
key,
|
||||
hiddenPercentage);
|
||||
@@ -3159,6 +3201,17 @@ HTMLMediaElement::ReportTelemetry()
|
||||
LOG(LogLevel::Debug, ("%p VIDEO_HIDDEN_PLAY_TIME_PERCENTAGE = %u, keys: '%s' and 'All'",
|
||||
this, hiddenPercentage, key.get()));
|
||||
|
||||
uint32_t videoDecodeSuspendPercentage =
|
||||
uint32_t(videoDecodeSuspendTime / playTime * 100.0 + 0.5);
|
||||
Telemetry::Accumulate(Telemetry::VIDEO_INFERRED_DECODE_SUSPEND_PERCENTAGE,
|
||||
key,
|
||||
videoDecodeSuspendPercentage);
|
||||
Telemetry::Accumulate(Telemetry::VIDEO_INFERRED_DECODE_SUSPEND_PERCENTAGE,
|
||||
NS_LITERAL_CSTRING("All"),
|
||||
videoDecodeSuspendPercentage);
|
||||
LOG(LogLevel::Debug, ("%p VIDEO_INFERRED_DECODE_SUSPEND_PERCENTAGE = %u, keys: '%s' and 'All'",
|
||||
this, videoDecodeSuspendPercentage, key.get()));
|
||||
|
||||
if (data.mInterKeyframeCount != 0) {
|
||||
uint32_t average_ms =
|
||||
uint32_t(std::min<uint64_t>(double(data.mInterKeyframeSum_us)
|
||||
@@ -4708,14 +4761,14 @@ nsresult HTMLMediaElement::DispatchAsyncEvent(const nsAString& aName)
|
||||
if ((aName.EqualsLiteral("play") || aName.EqualsLiteral("playing"))) {
|
||||
mPlayTime.Start();
|
||||
if (IsHidden()) {
|
||||
mHiddenPlayTime.Start();
|
||||
HiddenVideoStart();
|
||||
}
|
||||
} else if (aName.EqualsLiteral("waiting")) {
|
||||
mPlayTime.Pause();
|
||||
mHiddenPlayTime.Pause();
|
||||
HiddenVideoStop();
|
||||
} else if (aName.EqualsLiteral("pause")) {
|
||||
mPlayTime.Pause();
|
||||
mHiddenPlayTime.Pause();
|
||||
HiddenVideoStop();
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
@@ -4913,10 +4966,10 @@ HTMLMediaElement::NotifyOwnerDocumentActivityChangedInternal()
|
||||
bool visible = !IsHidden();
|
||||
if (visible) {
|
||||
// Visible -> Just pause hidden play time (no-op if already paused).
|
||||
mHiddenPlayTime.Pause();
|
||||
HiddenVideoStop();
|
||||
} else if (mPlayTime.IsStarted()) {
|
||||
// Not visible, play time is running -> Start hidden play time if needed.
|
||||
mHiddenPlayTime.Start();
|
||||
HiddenVideoStart();
|
||||
}
|
||||
|
||||
if (mDecoder && !IsBeingDestroyed()) {
|
||||
|
||||
Reference in New Issue
Block a user