Skip to content

Commit fc0a37c

Browse files
committed
Bug 1947814 - Ensure that we continue to issue video frame request callbacks after seeking. r=media-playback-reviewers,alwu
When a video completes, we can present the first frame again, with its original first frame ID. We tried to fix this by filtering for earlier frames which should generally work since we redecode after a seek. But if the seek produces earlier frames as well, then we can unexpectedly suppress those video frame request callbacks. As such, we now track how many frames have been presented separately from the frame ID. If we have never seeked, then these values will always been the same. Otherwise we will diverge in order to maintain the monotonically increasing requirement. Differential Revision: https://phabricator.services.mozilla.com/D239944
1 parent feea9e8 commit fc0a37c

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

dom/html/HTMLVideoElement.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ void HTMLVideoElement::TakeVideoFrameRequestCallbacks(
744744
// If all of the available images are for future compositions, we must have
745745
// fired too early. Wait for the next invalidation.
746746
if (!selected || selected->mFrameID == layers::kContainerFrameID_Invalid ||
747-
selected->mFrameID <= mLastPresentedFrameID) {
747+
selected->mFrameID == mLastPresentedFrameID) {
748748
return;
749749
}
750750

@@ -831,14 +831,27 @@ void HTMLVideoElement::TakeVideoFrameRequestCallbacks(
831831
}
832832
#endif
833833

834+
// Note that if we seek, or restart a video, we may present an earlier frame
835+
// that we already presented with the same ID. This would cause presented
836+
// frames to go backwards when it must be monotonically increasing. Presented
837+
// frames cannot simply increment by 1 each request callback because it is
838+
// also used by the caller to determine if frames were missed. As such, we
839+
// will typically use the difference between the current frame and the last
840+
// presented via the callback, but otherwise assume a single frame due to the
841+
// seek.
842+
mPresentedFrames +=
843+
selected->mFrameID > 1 && selected->mFrameID > mLastPresentedFrameID
844+
? selected->mFrameID - mLastPresentedFrameID
845+
: 1;
846+
mLastPresentedFrameID = selected->mFrameID;
847+
834848
// Presented frames is a bit of a misnomer from a rendering perspective,
835849
// because we still need to advance regardless of composition. Video elements
836850
// that are outside of the DOM, or are not visible, still advance the video in
837851
// the background, and presumably the caller still needs some way to know how
838852
// many frames we have advanced.
839-
aMd.mPresentedFrames = selected->mFrameID;
853+
aMd.mPresentedFrames = mPresentedFrames;
840854

841-
mLastPresentedFrameID = selected->mFrameID;
842855
mVideoFrameRequestManager.Take(aCallbacks);
843856

844857
NS_DispatchToMainThread(NewRunnableMethod(

dom/html/HTMLVideoElement.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ class HTMLVideoElement final : public HTMLMediaElement {
202202
VideoFrameRequestManager mVideoFrameRequestManager;
203203
layers::ContainerFrameID mLastPresentedFrameID =
204204
layers::kContainerFrameID_Invalid;
205+
uint32_t mPresentedFrames = 0;
205206

206207
public:
207208
uint32_t RequestVideoFrameCallback(VideoFrameRequestCallback& aCallback,

0 commit comments

Comments
 (0)