diff --git a/dom/media/MediaFormatReader.cpp b/dom/media/MediaFormatReader.cpp index 3f263b0ef0db..b3d295ffdab1 100644 --- a/dom/media/MediaFormatReader.cpp +++ b/dom/media/MediaFormatReader.cpp @@ -1078,6 +1078,7 @@ MediaFormatReader::MediaFormatReader(AbstractMediaDecoder* aDecoder, Preferences::GetUint("media.video-max-decode-error", 2)) , mDemuxer(new DemuxerProxy(aDemuxer)) , mDemuxerInitDone(false) + , mPendingNotifyDataArrived(false) , mLastReportedNumDecodedFrames(0) , mPreviousDecodedKeyframeTime_us(sNoPreviousDecodedKeyframe) , mInitDone(false) @@ -2877,10 +2878,8 @@ MediaFormatReader::NotifyDataArrived() } if (mNotifyDataArrivedPromise.Exists()) { - // Already one in progress. Reschedule for later. - RefPtr task( - NewRunnableMethod(this, &MediaFormatReader::NotifyDataArrived)); - OwnerThread()->Dispatch(task.forget()); + // Already one in progress. Set the dirty flag so we can process it later. + mPendingNotifyDataArrived = true; return; } @@ -2891,6 +2890,10 @@ MediaFormatReader::NotifyDataArrived() self->mNotifyDataArrivedPromise.Complete(); self->UpdateBuffered(); self->NotifyTrackDemuxers(); + if (self->mPendingNotifyDataArrived) { + self->mPendingNotifyDataArrived = false; + self->NotifyDataArrived(); + } }, [self]() { self->mNotifyDataArrivedPromise.Complete(); }) ->Track(mNotifyDataArrivedPromise); diff --git a/dom/media/MediaFormatReader.h b/dom/media/MediaFormatReader.h index c51c02429498..bd4776a3c3cc 100644 --- a/dom/media/MediaFormatReader.h +++ b/dom/media/MediaFormatReader.h @@ -450,6 +450,7 @@ private: void OnDemuxerInitFailed(const MediaResult& aError); MozPromiseRequestHolder mDemuxerInitRequest; MozPromiseRequestHolder mNotifyDataArrivedPromise; + bool mPendingNotifyDataArrived; void OnDemuxFailed(TrackType aTrack, const MediaResult &aError); void DoDemuxVideo();