Bug 1495064 - part2 : don't request wakelock for video without audio track. r=jya
authoralwu <alwu@mozilla.com>
Tue, 02 Oct 2018 17:55:50 +0000
changeset 498468 696f01b5d804309cedfb82debc291a822efd9072
parent 498467 9b3be971c8b013743fc9a819c641c2fb98d55c5f
child 498469 aab7bf199799d5c3c696fa5c369491bff062873f
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1495064
milestone64.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 1495064 - part2 : don't request wakelock for video without audio track. r=jya There are often websites using videos without an audio track as background image or as GIF-like image. For these cases, we don't want to hold a wakelock. Differential Revision: https://phabricator.services.mozilla.com/D7215
dom/html/HTMLMediaElement.cpp
dom/html/HTMLVideoElement.cpp
dom/html/HTMLVideoElement.h
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -7758,16 +7758,17 @@ HTMLMediaElement::SetMediaInfo(const Med
   if (aInfo.HasAudio() != oldHasAudio) {
     UpdateAudioChannelPlayingState();
     NotifyAudioPlaybackChanged(
       AudioChannelService::AudibleChangedReasons::eDataAudibleChanged);
   }
   if (mAudioChannelWrapper) {
     mAudioChannelWrapper->AudioCaptureStreamChangeIfNeeded();
   }
+  UpdateWakeLock();
 }
 
 void
 HTMLMediaElement::AudioCaptureStreamChange(bool aCapture)
 {
   // No need to capture a silence media element.
   if (!HasAudio()) {
     return;
--- a/dom/html/HTMLVideoElement.cpp
+++ b/dom/html/HTMLVideoElement.cpp
@@ -310,20 +310,29 @@ HTMLVideoElement::UpdateWakeLock()
   HTMLMediaElement::UpdateWakeLock();
   if (!mPaused) {
     CreateVideoWakeLockIfNeeded();
   } else {
     ReleaseVideoWakeLockIfExists();
   }
 }
 
+bool
+HTMLVideoElement::ShouldCreateVideoWakeLock() const
+{
+  // Make sure we only request wake lock for video with audio track, because
+  // video without audio track is often used as background image which seems no
+  // need to hold a wakelock.
+  return HasVideo() && HasAudio();
+}
+
 void
 HTMLVideoElement::CreateVideoWakeLockIfNeeded()
 {
-  if (!mScreenWakeLock && HasVideo()) {
+  if (!mScreenWakeLock && ShouldCreateVideoWakeLock()) {
     RefPtr<power::PowerManagerService> pmService =
       power::PowerManagerService::GetInstance();
     NS_ENSURE_TRUE_VOID(pmService);
 
     ErrorResult rv;
     mScreenWakeLock = pmService->NewWakeLock(NS_LITERAL_STRING("video-playing"),
                                              OwnerDoc()->GetInnerWindow(),
                                              rv);
--- a/dom/html/HTMLVideoElement.h
+++ b/dom/html/HTMLVideoElement.h
@@ -159,16 +159,17 @@ protected:
    * We create video wakelock when the video is playing and release it when
    * video pauses. Note, the actual platform wakelock will automatically be
    * released when the page is in the background, so we don't need to check the
    * video's visibility by ourselves.
    */
   void WakeLockRelease() override;
   void UpdateWakeLock() override;
 
+  bool ShouldCreateVideoWakeLock() const;
   void CreateVideoWakeLockIfNeeded();
   void ReleaseVideoWakeLockIfExists();
 
   RefPtr<WakeLock> mScreenWakeLock;
 
   bool mIsOrientationLocked;
 
 private: