Bug 1552081 - part1. Sometimes we should run 'TimeMarchesOn' only when the media element's show poster flag is false. r=jya
authorAlastor Wu <alwu@mozilla.com>
Fri, 17 May 2019 01:59:34 +0000
changeset 533098 95ccc685eb11f356e7b8c8be9ed2bea601585a4e
parent 533097 45d495a1a3a97f659451ce077d17d8e23fba7fb4
child 533099 7b72fa29c64be23ef4ac7f2373e5622adb48b337
push id11276
push userrgurzau@mozilla.com
push dateMon, 20 May 2019 13:11:24 +0000
treeherdermozilla-beta@847755a7c325 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1552081
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1552081 - part1. Sometimes we should run 'TimeMarchesOn' only when the media element's show poster flag is false. r=jya In the following situations, we should only run `TimeMarchesOn` when the media element's `show-poster` flag is false. - add cue : https://html.spec.whatwg.org/multipage/media.html#playing-the-media-resource:time-marches-on-2 - remove cue : https://html.spec.whatwg.org/multipage/media.html#playing-the-media-resource:time-marches-on-3 - track mode changes : https://html.spec.whatwg.org/multipage/media.html#text-track-model:time-marches-on - cue's startTime changes : https://html.spec.whatwg.org/multipage/media.html#text-track-api:time-marches-on - cue's endTime changes : https://html.spec.whatwg.org/multipage/media.html#text-track-api:time-marches-on-2 Differential Revision: https://phabricator.services.mozilla.com/D31376
dom/html/HTMLMediaElement.h
dom/html/TextTrackManager.cpp
dom/html/TextTrackManager.h
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -724,16 +724,18 @@ class HTMLMediaElement : public nsGeneri
     aSinkId = mSink.first();
   }
 
   // This is used to notify MediaElementAudioSourceNode that media element is
   // allowed to play when media element is used as a source for web audio, so
   // that we can start AudioContext if it was not allowed to start.
   RefPtr<GenericNonExclusivePromise> GetAllowedToPlayPromise();
 
+  bool GetShowPosterFlag() const { return mShowPoster; }
+
  protected:
   virtual ~HTMLMediaElement();
 
   class AudioChannelAgentCallback;
   class ChannelLoader;
   class ErrorSink;
   class MediaLoadListener;
   class MediaStreamTrackListener;
--- a/dom/html/TextTrackManager.cpp
+++ b/dom/html/TextTrackManager.cpp
@@ -197,17 +197,17 @@ void TextTrackManager::AddCues(TextTrack
 
   TextTrackCueList* cueList = aTextTrack->GetCues();
   if (cueList) {
     bool dummy;
     WEBVTT_LOGV("AddCues, CuesNum=%d", cueList->Length());
     for (uint32_t i = 0; i < cueList->Length(); ++i) {
       mNewCues->AddCue(*cueList->IndexedGetter(i, dummy));
     }
-    TimeMarchesOn();
+    MaybeRunTimeMarchesOn();
   }
 }
 
 void TextTrackManager::RemoveTextTrack(TextTrack* aTextTrack,
                                        bool aPendingListOnly) {
   if (!mPendingTextTracks || !mTextTracks) {
     return;
   }
@@ -221,17 +221,17 @@ void TextTrackManager::RemoveTextTrack(T
   mTextTracks->RemoveTextTrack(aTextTrack);
   // Remove the cues in mNewCues belong to aTextTrack.
   TextTrackCueList* removeCueList = aTextTrack->GetCues();
   if (removeCueList) {
     WEBVTT_LOGV("RemoveTextTrack removeCuesNum=%d", removeCueList->Length());
     for (uint32_t i = 0; i < removeCueList->Length(); ++i) {
       mNewCues->RemoveCue(*((*removeCueList)[i]));
     }
-    TimeMarchesOn();
+    MaybeRunTimeMarchesOn();
   }
 }
 
 void TextTrackManager::DidSeek() {
   WEBVTT_LOG("DidSeek");
   mHasSeeked = true;
 }
 
@@ -276,26 +276,26 @@ void TextTrackManager::UpdateCueDisplay(
   }
 }
 
 void TextTrackManager::NotifyCueAdded(TextTrackCue& aCue) {
   WEBVTT_LOG("NotifyCueAdded, cue=%p", &aCue);
   if (mNewCues) {
     mNewCues->AddCue(aCue);
   }
-  TimeMarchesOn();
+  MaybeRunTimeMarchesOn();
   ReportTelemetryForCue();
 }
 
 void TextTrackManager::NotifyCueRemoved(TextTrackCue& aCue) {
   WEBVTT_LOG("NotifyCueRemoved, cue=%p", &aCue);
   if (mNewCues) {
     mNewCues->RemoveCue(aCue);
   }
-  TimeMarchesOn();
+  MaybeRunTimeMarchesOn();
   DispatchUpdateCueDisplay();
 }
 
 void TextTrackManager::PopulatePendingList() {
   if (!mTextTracks || !mPendingTextTracks || !mMediaElement) {
     return;
   }
   uint32_t len = mTextTracks->Length();
@@ -814,17 +814,17 @@ void TextTrackManager::TimeMarchesOn() {
 
   // Step 18.
   UpdateCueDisplay();
 }
 
 void TextTrackManager::NotifyCueUpdated(TextTrackCue* aCue) {
   // TODO: Add/Reorder the cue to mNewCues if we have some optimization?
   WEBVTT_LOG("NotifyCueUpdated, cue=%p", aCue);
-  TimeMarchesOn();
+  MaybeRunTimeMarchesOn();
   // For the case "Texttrack.mode = hidden/showing", if the mode
   // changing between showing and hidden, TimeMarchesOn
   // doesn't render the cue. Call DispatchUpdateCueDisplay() explicitly.
   DispatchUpdateCueDisplay();
 }
 
 void TextTrackManager::NotifyReset() {
   // https://html.spec.whatwg.org/multipage/media.html#text-track-cue-active-flag
@@ -859,10 +859,23 @@ void TextTrackManager::ReportTelemetryFo
 bool TextTrackManager::IsLoaded() {
   return mTextTracks ? mTextTracks->AreTextTracksLoaded() : true;
 }
 
 bool TextTrackManager::IsShutdown() const {
   return (mShutdown || !sParserWrapper);
 }
 
+void TextTrackManager::MaybeRunTimeMarchesOn() {
+  MOZ_ASSERT(mMediaElement);
+  // According to spec, we should check media element's show poster flag before
+  // running `TimeMarchesOn` in following situations, (1) add cue (2) remove cue
+  // (3) cue's start time changes (4) cues's end time changes
+  // https://html.spec.whatwg.org/multipage/media.html#playing-the-media-resource:time-marches-on
+  // https://html.spec.whatwg.org/multipage/media.html#text-track-api:time-marches-on
+  if (mMediaElement->GetShowPosterFlag()) {
+    return;
+  }
+  TimeMarchesOn();
+}
+
 }  // namespace dom
 }  // namespace mozilla
--- a/dom/html/TextTrackManager.h
+++ b/dom/html/TextTrackManager.h
@@ -150,16 +150,20 @@ class TextTrackManager final : public ns
   void ReportTelemetryForCue();
 
   bool IsShutdown() const;
 
   // If there is at least one cue has been added to the cue list once, we would
   // report the usage of cue to Telemetry.
   bool mCueTelemetryReported;
 
+  // This function will check media element's show poster flag to decide whether
+  // we need to run `TimeMarchesOn`.
+  void MaybeRunTimeMarchesOn();
+
   class ShutdownObserverProxy final : public nsIObserver {
     NS_DECL_ISUPPORTS
 
    public:
     explicit ShutdownObserverProxy(TextTrackManager* aManager)
         : mManager(aManager) {
       nsContentUtils::RegisterShutdownObserver(this);
     }