зеркало из https://github.com/mozilla/gecko-dev.git
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 --HG-- extra : rebase_source : 22f9d811371f9d609dc96a9d958645e5c634eb17 extra : intermediate-source : bdb8280da440a711c6cd51b65ead7ba9e4bb3597 extra : source : fd8c4b8656a9996eea94d2092caaf3c10fe2a835
This commit is contained in:
Родитель
77ce7192a9
Коммит
2c5f707722
|
@ -3884,11 +3884,12 @@ NS_IMPL_ISUPPORTS(HTMLMediaElement::ShutdownObserver, nsIObserver)
|
|||
HTMLMediaElement::HTMLMediaElement(
|
||||
already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
||||
: nsGenericHTMLElement(aNodeInfo)
|
||||
, mWatchManager(this, OwnerDoc()->AbstractMainThreadFor(TaskCategory::Other))
|
||||
, mMainThreadEventTarget(OwnerDoc()->EventTargetFor(TaskCategory::Other))
|
||||
, mAbstractMainThread(OwnerDoc()->AbstractMainThreadFor(TaskCategory::Other))
|
||||
, mShutdownObserver(new ShutdownObserver)
|
||||
, mPlayed(new TimeRanges(ToSupports(OwnerDoc())))
|
||||
, mPaused(true, *this)
|
||||
, mPaused(true, "HTMLMediaElement::mPaused")
|
||||
, mErrorSink(new ErrorSink(this))
|
||||
, mAudioChannelWrapper(new AudioChannelAgentCallback(this))
|
||||
{
|
||||
|
@ -3897,6 +3898,8 @@ HTMLMediaElement::HTMLMediaElement(
|
|||
|
||||
DecoderDoctorLogger::LogConstruction(this);
|
||||
|
||||
mWatchManager.Watch(mPaused, &HTMLMediaElement::UpdateWakeLock);
|
||||
|
||||
ErrorResult rv;
|
||||
|
||||
double defaultVolume = Preferences::GetFloat("media.default_volume", 1.0);
|
||||
|
@ -4180,31 +4183,20 @@ HTMLMediaElement::MaybeDoLoad()
|
|||
}
|
||||
}
|
||||
|
||||
HTMLMediaElement::WakeLockBoolWrapper&
|
||||
HTMLMediaElement::WakeLockBoolWrapper::operator=(bool val)
|
||||
{
|
||||
if (mValue == val) {
|
||||
return *this;
|
||||
}
|
||||
|
||||
mValue = val;
|
||||
UpdateWakeLock();
|
||||
return *this;
|
||||
}
|
||||
|
||||
void
|
||||
HTMLMediaElement::WakeLockBoolWrapper::UpdateWakeLock()
|
||||
HTMLMediaElement::UpdateWakeLock()
|
||||
{
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
bool playing = !mValue;
|
||||
// Ensure we have a wake lock if we're playing audibly. This ensures the
|
||||
// device doesn't sleep while playing.
|
||||
bool playing = !mPaused;
|
||||
bool isAudible =
|
||||
mOuter.Volume() > 0.0 && !mOuter.mMuted && mOuter.mIsAudioTrackAudible;
|
||||
// when playing audible media.
|
||||
Volume() > 0.0 && !mMuted && mIsAudioTrackAudible;
|
||||
// WakeLock when playing audible media.
|
||||
if (playing && isAudible) {
|
||||
mOuter.WakeLockCreate();
|
||||
WakeLockCreate();
|
||||
} else {
|
||||
mOuter.WakeLockRelease();
|
||||
WakeLockRelease();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7549,7 +7541,7 @@ HTMLMediaElement::NotifyAudioPlaybackChanged(AudibleChangedReasons aReason)
|
|||
mAudioChannelWrapper->NotifyAudioPlaybackChanged(aReason);
|
||||
}
|
||||
// only request wake lock for audible media.
|
||||
mPaused.UpdateWakeLock();
|
||||
UpdateWakeLock();
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче