Bug 1285419 - Record mediasource hidden play time - r=kamidphish
Note that this is a simple duration counter based on the existing (non-hidden)
play-time, but it only counts when video is playing while hidden.
There is no bucketing yet, future probes may add finer-grained information.
MozReview-Commit-ID: DUfryXjGBAN
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -3069,16 +3069,19 @@ HTMLMediaElement::ReportTelemetry()
("Reporting telemetry DROPPED_FRAMES_IN_VIDEO_PLAYBACK"));
Telemetry::Accumulate(Telemetry::VIDEO_DROPPED_FRAMES_PROPORTION,
percentage);
}
}
Telemetry::Accumulate(Telemetry::VIDEO_PLAY_TIME_MS, SECONDS_TO_MS(mPlayTime.Total()));
LOG(LogLevel::Debug, ("%p VIDEO_PLAY_TIME_MS = %f", this, mPlayTime.Total()));
+
+ Telemetry::Accumulate(Telemetry::VIDEO_HIDDEN_PLAY_TIME_MS, SECONDS_TO_MS(mHiddenPlayTime.Total()));
+ LOG(LogLevel::Debug, ("%p VIDEO_HIDDEN_PLAY_TIME_MS = %f", this, mHiddenPlayTime.Total()));
}
void HTMLMediaElement::UnbindFromTree(bool aDeep,
bool aNullParent)
{
if (!mPaused && mNetworkState != nsIDOMHTMLMediaElement::NETWORK_EMPTY) {
Pause();
}
@@ -4556,20 +4559,25 @@ nsresult HTMLMediaElement::DispatchAsync
return NS_OK;
}
nsCOMPtr<nsIRunnable> event = new nsAsyncEventRunner(aName, this);
NS_DispatchToMainThread(event);
if ((aName.EqualsLiteral("play") || aName.EqualsLiteral("playing"))) {
mPlayTime.Start();
+ if (IsHidden()) {
+ mHiddenPlayTime.Start();
+ }
} else if (aName.EqualsLiteral("waiting")) {
mPlayTime.Pause();
+ mHiddenPlayTime.Pause();
} else if (aName.EqualsLiteral("pause")) {
mPlayTime.Pause();
+ mHiddenPlayTime.Pause();
}
return NS_OK;
}
nsresult HTMLMediaElement::DispatchPendingMediaEvents()
{
NS_ASSERTION(!mEventDeliveryPaused,
@@ -4756,18 +4764,27 @@ void HTMLMediaElement::NotifyOwnerDocume
NotifyAudioChannelAgent(false);
}
}
}
bool
HTMLMediaElement::NotifyOwnerDocumentActivityChangedInternal()
{
+ bool visible = !IsHidden();
+ if (visible) {
+ // Visible -> Just pause hidden play time (no-op if already paused).
+ mHiddenPlayTime.Pause();
+ } else if (mPlayTime.IsStarted()) {
+ // Not visible, play time is running -> Start hidden play time if needed.
+ mHiddenPlayTime.Start();
+ }
+
if (mDecoder && !IsBeingDestroyed()) {
- mDecoder->NotifyOwnerActivityChanged(!IsHidden());
+ mDecoder->NotifyOwnerActivityChanged(visible);
}
bool pauseElement = !IsActive();
SuspendOrResumeElement(pauseElement, !IsActive());
if (!mPausedForInactiveDocumentOrChannel &&
mPlayBlockedBecauseHidden &&
!OwnerDoc()->Hidden()) {
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -1611,16 +1611,19 @@ public:
TimeStamp mStartTime;
TimeDuration mSum;
uint32_t mCount;
};
private:
// Total time a video has spent playing.
TimeDurationAccumulator mPlayTime;
+ // Total time a video has spent playing while hidden.
+ TimeDurationAccumulator mHiddenPlayTime;
+
// Indicates if user has interacted with the element.
// Used to block autoplay when disabled.
bool mHasUserInteraction;
// True if the first frame has been successfully loaded.
bool mFirstFrameLoaded;
// Media elements also have a default playback start position, which must