Bug 1224973 - Part 2: Set MediaDecoder visibility via NotifyOwnerActivityChanged. r?cpearce, jwwang draft
authorDan Glastonbury <dan.glastonbury@gmail.com>
Tue, 12 Apr 2016 15:48:06 +1000
changeset 363157 7e893e3e6d931ddf6c254a708ce59521c6f66f52
parent 363156 199fdd2885e8e0999954be88e86967883943c946
child 363158 54ff8a1f81c1871a73826bfed6640f8cdb805e97
push id17118
push userbmo:dglastonbury@mozilla.com
push dateWed, 04 May 2016 02:49:28 +0000
reviewerscpearce, jwwang
bugs1224973
milestone49.0a1
Bug 1224973 - Part 2: Set MediaDecoder visibility via NotifyOwnerActivityChanged. r?cpearce, jwwang Make MediaDecoder::SetElementVisibility private. MozReview-Commit-ID: GjCuSNPalkE
dom/html/HTMLMediaElement.cpp
dom/media/MediaDecoder.cpp
dom/media/MediaDecoder.h
dom/media/omx/MediaOmxCommonDecoder.cpp
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -2784,17 +2784,17 @@ nsresult HTMLMediaElement::BindToTree(ns
     // It's value may have changed, so update it.
     UpdatePreloadAction();
   }
   mElementInTreeState = ELEMENT_INTREE;
 
   if (mDecoder) {
     // When the MediaElement is binding to tree, the dormant status is
     // aligned to document's hidden status.
-    mDecoder->NotifyOwnerActivityChanged();
+    mDecoder->NotifyOwnerActivityChanged(!IsHidden());
   }
 
   return rv;
 }
 
 #ifdef MOZ_EME
 void
 HTMLMediaElement::ReportEMETelemetry()
@@ -2887,17 +2887,17 @@ void HTMLMediaElement::UnbindFromTree(bo
   }
 
   mElementInTreeState = ELEMENT_NOT_INTREE_HAD_INTREE;
 
   nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
 
   if (mDecoder) {
     MOZ_ASSERT(IsHidden());
-    mDecoder->NotifyOwnerActivityChanged();
+    mDecoder->NotifyOwnerActivityChanged(false);
   }
 }
 
 /* static */
 CanPlayStatus
 HTMLMediaElement::GetCanPlay(const nsAString& aType,
                              DecoderDoctorDiagnostics* aDiagnostics)
 {
@@ -4555,20 +4555,18 @@ void HTMLMediaElement::NotifyOwnerDocume
       NotifyAudioChannelAgent(false);
     }
   }
 }
 
 bool
 HTMLMediaElement::NotifyOwnerDocumentActivityChangedInternal()
 {
-  nsIDocument* ownerDoc = OwnerDoc();
   if (mDecoder && !IsBeingDestroyed()) {
-    mDecoder->SetElementVisibility(!ownerDoc->Hidden());
-    mDecoder->NotifyOwnerActivityChanged();
+    mDecoder->NotifyOwnerActivityChanged(!IsHidden());
   }
 
   bool pauseElement = !IsActive();
   // Only pause the element when we start playing. If we pause without playing
   // audio, the resource loading would be affected unexpectedly. For example,
   // the media element is muted by default, but we don't want this behavior
   // interrupting the loading process.
   if (UseAudioChannelAPI() && mAudioChannelAgent) {
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -282,24 +282,26 @@ MediaDecoder::ResourceCallback::NotifyBy
     if (self->mDecoder) {
       self->mDecoder->NotifyBytesConsumed(aBytes, aOffset);
     }
   });
   AbstractThread::MainThread()->Dispatch(r.forget());
 }
 
 void
-MediaDecoder::NotifyOwnerActivityChanged()
+MediaDecoder::NotifyOwnerActivityChanged(bool aIsVisible)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (mShuttingDown) {
     return;
   }
 
+  SetElementVisibility(aIsVisible);
+
   UpdateDormantState(false /* aDormantTimeout */, false /* aActivity */);
   // Start dormant timer if necessary
   StartDormantTimer();
 }
 
 bool
 MediaDecoder::IsHeuristicDormantSupported() const
 {
@@ -1358,16 +1360,23 @@ MediaDecoder::DurationChanged()
   }
 
   if (CurrentPosition() > TimeUnit::FromSeconds(mDuration).ToMicroseconds()) {
     Seek(mDuration, SeekTarget::Accurate);
   }
 }
 
 void
+MediaDecoder::SetElementVisibility(bool aIsVisible)
+{
+  MOZ_ASSERT(NS_IsMainThread());
+  mIsVisible = aIsVisible;
+}
+
+void
 MediaDecoder::UpdateEstimatedMediaDuration(int64_t aDuration)
 {
   MOZ_ASSERT(NS_IsMainThread());
 
   if (mPlayState <= PLAY_STATE_LOADING) {
     return;
   }
 
--- a/dom/media/MediaDecoder.h
+++ b/dom/media/MediaDecoder.h
@@ -175,17 +175,17 @@ public:
   // called.
   virtual nsresult Play();
 
   // Notify activity of the decoder owner is changed.
   // Based on the activity, dormant state is updated.
   // Dormant state is a state to free all scarce media resources
   //  (like hw video codec), did not decoding and stay dormant.
   // It is used to share scarece media resources in system.
-  virtual void NotifyOwnerActivityChanged();
+  virtual void NotifyOwnerActivityChanged(bool aIsVisible);
 
   void UpdateDormantState(bool aDormantTimeout, bool aActivity);
 
   // Pause video playback.
   virtual void Pause();
   // Adjust the speed of the playback, optionally with pitch correction,
   virtual void SetVolume(double aVolume);
 
@@ -245,19 +245,16 @@ protected:
   // instability is expected; if the incoming duration is not significantly
   // different from the existing duration, the change request is ignored.
   // If the incoming duration is significantly different, the duration is
   // changed, this causes a durationchanged event to fire to the media
   // element.
   void UpdateEstimatedMediaDuration(int64_t aDuration) override;
 
 public:
-  // Called from HTMLMediaElement when owner document activity changes
-  virtual void SetElementVisibility(bool aIsVisible) {}
-
   // Set a flag indicating whether random seeking is supported
   void SetMediaSeekable(bool aMediaSeekable);
   // Set a flag indicating whether seeking is supported only in buffered ranges
   void SetMediaSeekableOnlyInBufferedRanges(bool aMediaSeekableOnlyInBufferedRanges);
 
   // Returns true if this media supports random seeking. False for example with
   // chained ogg files.
   bool IsMediaSeekable();
@@ -363,16 +360,19 @@ private:
 
   // Returns true if we can play the entire media through without stopping
   // to buffer, given the current download and playback rates.
   virtual bool CanPlayThrough();
 
   void SetAudioChannel(dom::AudioChannel aChannel) { mAudioChannel = aChannel; }
   dom::AudioChannel GetAudioChannel() { return mAudioChannel; }
 
+  // Called from HTMLMediaElement when owner document activity changes
+  virtual void SetElementVisibility(bool aIsVisible);
+
   /******
    * The following methods must only be called on the main
    * thread.
    ******/
 
   // Change to a new play state. This updates the mState variable and
   // notifies any thread blocking on this object's monitor of the
   // change. Call on the main thread only.
--- a/dom/media/omx/MediaOmxCommonDecoder.cpp
+++ b/dom/media/omx/MediaOmxCommonDecoder.cpp
@@ -247,16 +247,17 @@ MediaOmxCommonDecoder::CurrentPosition()
   }
   return mAudioOffloadPlayer->GetMediaTimeUs();
 }
 
 void
 MediaOmxCommonDecoder::SetElementVisibility(bool aIsVisible)
 {
   MOZ_ASSERT(NS_IsMainThread());
+  MediaDecoder::SetElementVisibility(aIsVisible);
   if (mAudioOffloadPlayer) {
     mAudioOffloadPlayer->SetElementVisibility(aIsVisible);
   }
 }
 
 MediaDecoderOwner::NextFrameStatus
 MediaOmxCommonDecoder::NextFrameStatus()
 {