Bug 1390443. P3 - rewrite the logic about mWaitingForKey. r=cpearce

This fixes the bug where mWaitingForKey is reset only when mPaused is false.
We should reset mWaitingForKey to NOT_WAITING_FOR_KEY when the key is
available and decoding can continue.

http://w3c.github.io/encrypted-media/#resume-playback

MozReview-Commit-ID: LjIhe9cTsdg

--HG--
extra : rebase_source : d2d351928d1994ee3ae688d4e798ab204ab1609c
extra : intermediate-source : e8700b4344aa29f6b2c52ee4d920d59db4012577
extra : source : 41e1c10f32465ca0abac61bbfd555ee89a8c67a1
This commit is contained in:
JW Wang 2017-08-17 10:47:07 +08:00
Родитель 9bfb2b1c06
Коммит 934fb866da
1 изменённых файлов: 17 добавлений и 16 удалений

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

@ -5745,18 +5745,18 @@ HTMLMediaElement::UpdateReadyStateInternal()
}
enum NextFrameStatus nextFrameStatus = NextFrameStatus();
if (nextFrameStatus == NEXT_FRAME_UNAVAILABLE ||
(nextFrameStatus == NEXT_FRAME_UNAVAILABLE_BUFFERING &&
mWaitingForKey == WAITING_FOR_KEY)) {
if (mWaitingForKey != NOT_WAITING_FOR_KEY) {
if (mWaitingForKey == NOT_WAITING_FOR_KEY) {
if (nextFrameStatus == NEXT_FRAME_UNAVAILABLE && mDecoder &&
!mDecoder->IsEnded()) {
nextFrameStatus = mDecoder->NextFrameBufferedStatus();
}
} else if (mWaitingForKey == WAITING_FOR_KEY) {
if (nextFrameStatus == NEXT_FRAME_UNAVAILABLE ||
nextFrameStatus == NEXT_FRAME_UNAVAILABLE_BUFFERING) {
// http://w3c.github.io/encrypted-media/#wait-for-key
// Continuing 7.3.4 Queue a "waitingforkey" Event
// 4. Queue a task to fire a simple event named waitingforkey
// at the media element.
if (mWaitingForKey == WAITING_FOR_KEY) {
mWaitingForKey = WAITING_FOR_KEY_DISPATCHED;
DispatchAsyncEvent(NS_LITERAL_STRING("waitingforkey"));
}
// 5. Set the readyState of media element to HAVE_METADATA.
// NOTE: We'll change to HAVE_CURRENT_DATA or HAVE_METADATA
// depending on whether we've loaded the first frame or not
@ -5764,8 +5764,15 @@ HTMLMediaElement::UpdateReadyStateInternal()
// 6. Suspend playback.
// Note: Playback will already be stalled, as the next frame is
// unavailable.
} else if (mDecoder && !mDecoder->IsEnded()) {
nextFrameStatus = mDecoder->NextFrameBufferedStatus();
mWaitingForKey = WAITING_FOR_KEY_DISPATCHED;
DispatchAsyncEvent(NS_LITERAL_STRING("waitingforkey"));
}
} else {
MOZ_ASSERT(mWaitingForKey == WAITING_FOR_KEY_DISPATCHED);
if (nextFrameStatus == NEXT_FRAME_AVAILABLE) {
// We have new frames after dispatching "waitingforkey".
// This means we've got the key and can reset mWaitingForKey now.
mWaitingForKey = NOT_WAITING_FOR_KEY;
}
}
@ -5838,12 +5845,6 @@ HTMLMediaElement::UpdateReadyStateInternal()
return;
}
if (!mPaused || mAutoplaying) {
// We only want to reset mWaitingForKey if we have played all decoded data
// or if we haven't played anything yet.
mWaitingForKey = NOT_WAITING_FOR_KEY;
}
// Now see if we should set HAVE_ENOUGH_DATA.
// If it's something we don't know the size of, then we can't
// make a real estimate, so we go straight to HAVE_ENOUGH_DATA once