Bug 1282710 - Part 1 - implement the suspend and resume logics in HTMLMediaElement.cpp according to visibility events; r=cpearce r=kamidphish
MozReview-Commit-ID: 4SyqzA1dnPB
This commit is contained in:
@@ -5820,5 +5820,71 @@ HTMLMediaElement::IsAudible() const
|
||||
return true;
|
||||
}
|
||||
|
||||
static const char* VisibilityString(Visibility aVisibility) {
|
||||
switch(aVisibility) {
|
||||
case Visibility::UNTRACKED: {
|
||||
return "UNTRACKED";
|
||||
}
|
||||
case Visibility::NONVISIBLE: {
|
||||
return "NONVISIBLE";
|
||||
}
|
||||
case Visibility::MAY_BECOME_VISIBLE: {
|
||||
return "MAY_BECOME_VISIBLE";
|
||||
}
|
||||
case Visibility::IN_DISPLAYPORT: {
|
||||
return "IN_DISPLAYPORT";
|
||||
}
|
||||
}
|
||||
|
||||
return "NAN";
|
||||
}
|
||||
|
||||
// The visibility enumeration contains three states:
|
||||
// {NONVISIBLE, MAY_BECOME_VISIBLE, IN_DISPLAYPORT}.
|
||||
// Here, I implement a conservative mechanism:
|
||||
// (1) {MAY_BECOME_VISIBLE, IN_DISPLAYPORT} -> NONVISIBLE:
|
||||
// notify the decoder to suspend.
|
||||
// (2) {NONVISIBLE, MAY_BECOME_VISIBLE} -> IN_DISPLAYPORT:
|
||||
// notify the decoder to resume.
|
||||
// (3) IN_DISPLAYPORT -> MAY_BECOME_VISIBLE:
|
||||
// do nothing here because users might scroll back immediately.
|
||||
// (4) NONVISIBLE -> MAY_BECOME_VISIBLE:
|
||||
// notify the decoder to resume because users might continue their scroll
|
||||
// direction and the video might be IN_DISPLAYPORT soon.
|
||||
void
|
||||
HTMLMediaElement::OnVisibilityChange(Visibility aOldVisibility,
|
||||
Visibility aNewVisibility)
|
||||
{
|
||||
LOG(LogLevel::Debug, ("OnVisibilityChange(): %s -> %s\n",
|
||||
VisibilityString(aOldVisibility),VisibilityString(aNewVisibility)));
|
||||
|
||||
if (!mDecoder) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (aNewVisibility) {
|
||||
case Visibility::UNTRACKED: {
|
||||
MOZ_ASSERT_UNREACHABLE("Shouldn't notify for untracked visibility");
|
||||
break;
|
||||
}
|
||||
case Visibility::NONVISIBLE: {
|
||||
mDecoder->NotifyOwnerActivityChanged(false);
|
||||
break;
|
||||
}
|
||||
case Visibility::MAY_BECOME_VISIBLE: {
|
||||
if (aOldVisibility == Visibility::NONVISIBLE) {
|
||||
mDecoder->NotifyOwnerActivityChanged(true);
|
||||
} else if (aOldVisibility == Visibility::IN_DISPLAYPORT) {
|
||||
// Do nothing.
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Visibility::IN_DISPLAYPORT: {
|
||||
mDecoder->NotifyOwnerActivityChanged(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
Reference in New Issue
Block a user