Skip to content

Commit

Permalink
Bug 1344772 - set a dirty flag so we can process the notification lat…
Browse files Browse the repository at this point in the history
…er. r=jya

https://hg.mozilla.org/mozilla-central/file/34c6c2f302e7b48e3ad2cec575cbd34d423a9d32/dom/media/MediaFormatReader.cpp#l2835
NotifyDataArrived() is dispatched again if |mNotifyDataArrivedPromise.Exists()| which will then be dispatched again
recursively until mNotifyDataArrivedPromise is completed. This is a waste of CPU cycles.

We can use a dirty flag to note we should update buffer ranges again when the current update is done.

MozReview-Commit-ID: 6hInhGKnXJE

--HG--
extra : rebase_source : 71aa2c16112428c34def094515e37aa1f028a3fc
  • Loading branch information
jwwang committed Mar 15, 2017
1 parent 6226e09 commit f7aad5b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
11 changes: 7 additions & 4 deletions dom/media/MediaFormatReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -2877,10 +2878,8 @@ MediaFormatReader::NotifyDataArrived()
}

if (mNotifyDataArrivedPromise.Exists()) {
// Already one in progress. Reschedule for later.
RefPtr<nsIRunnable> 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;
}

Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions dom/media/MediaFormatReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,7 @@ class MediaFormatReader final : public MediaDecoderReader
void OnDemuxerInitFailed(const MediaResult& aError);
MozPromiseRequestHolder<MediaDataDemuxer::InitPromise> mDemuxerInitRequest;
MozPromiseRequestHolder<NotifyDataArrivedPromise> mNotifyDataArrivedPromise;
bool mPendingNotifyDataArrived;
void OnDemuxFailed(TrackType aTrack, const MediaResult &aError);

void DoDemuxVideo();
Expand Down

0 comments on commit f7aad5b

Please sign in to comment.