Bug 1390443. P4 - rewrite the logic about mWaitingForKey.
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
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -5739,37 +5739,43 @@ HTMLMediaElement::UpdateReadyStateIntern
if (mMediaSource) {
// readyState has changed, assuming it's following the pending mediasource
// operations. Notify the Mediasource that the operations have completed.
mMediaSource->CompletePendingTransactions();
}
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
// below.
// 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 { // 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;
}
}
if (nextFrameStatus == MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE_SEEKING) {
LOG(LogLevel::Debug, ("MediaElement %p UpdateReadyStateInternal() "
"NEXT_FRAME_UNAVAILABLE_SEEKING; Forcing HAVE_METADATA", this));
ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_METADATA);
return;
@@ -5905,17 +5911,16 @@ void HTMLMediaElement::ChangeReadyState(
DispatchAsyncEvent(NS_LITERAL_STRING("loadeddata"));
mLoadedDataFired = true;
}
if (oldState < nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA &&
mReadyState >= nsIDOMHTMLMediaElement::HAVE_FUTURE_DATA) {
DispatchAsyncEvent(NS_LITERAL_STRING("canplay"));
if (!mPaused) {
- mWaitingForKey = NOT_WAITING_FOR_KEY;
NotifyAboutPlaying();
}
}
CheckAutoplayDataReady();
if (oldState < nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA &&
mReadyState >= nsIDOMHTMLMediaElement::HAVE_ENOUGH_DATA) {