Bug 1467350 - Make HTMLMediaElement::mPaused Watchable and update Wakelock status via a watcher. r=jya

We currently observe changes to HTMLMediaElement::mPaused via a hand-rolled
wrapper class. We can use use mozilla::Watchable<> and avoid rolling our
own equivalent here.

This also paves the way for using state watching on other observable state
in HTMLMediaElement.

MozReview-Commit-ID: 4lBlJiV15iG
This commit is contained in:
Chris Pearce
2018-05-21 14:19:47 +12:00
parent f9d2c3d5a2
commit 0041d0ec9d
2 changed files with 19 additions and 44 deletions

View File

@@ -839,26 +839,7 @@ protected:
void SetDecoder(MediaDecoder* aDecoder);
class WakeLockBoolWrapper {
public:
WakeLockBoolWrapper(bool aVal, HTMLMediaElement& aOuter)
: mValue(aVal)
, mOuter(aOuter)
{}
~WakeLockBoolWrapper() {};
MOZ_IMPLICIT operator bool() const { return mValue; }
WakeLockBoolWrapper& operator=(bool val);
bool operator !() const { return !mValue; }
void UpdateWakeLock();
private:
bool mValue;
HTMLMediaElement& mOuter;
};
void UpdateWakeLock();
// Holds references to the DOM wrappers for the MediaStreams that we're
// writing to.
@@ -896,8 +877,8 @@ protected:
void ChangeNetworkState(nsMediaNetworkState aState);
/**
* These two methods are called by the WakeLockBoolWrapper when the wakelock
* has to be created or released.
* These two methods are called when mPaused is changed to ensure we have
* a wake lock active when we're playing audibly.
*/
virtual void WakeLockCreate();
virtual void WakeLockRelease();
@@ -1373,6 +1354,8 @@ protected:
void PauseIfShouldNotBePlaying();
WatchManager<HTMLMediaElement> mWatchManager;
// The current decoder. Load() has been called on this decoder.
// At most one of mDecoder and mSrcStream can be non-null.
RefPtr<MediaDecoder> mDecoder;
@@ -1600,7 +1583,7 @@ protected:
// Playback of the video is paused either due to calling the
// 'Pause' method, or playback not yet having started.
WakeLockBoolWrapper mPaused;
Watchable<bool> mPaused;
// The following two fields are here for the private storage of the builtin
// video controls, and control 'casting' of the video to external devices