Bug 1483703 - part2 : add telemetry for the media which was blocked before loading metadata and ended up being without audio track. r=cpearce,francois
authoralwu <alwu@mozilla.com>
Wed, 22 Aug 2018 22:50:54 +0000
changeset 488045 3326c0e920d4c9a180a26561a1a9d49b886c0eb7
parent 488044 71ad474cdeeb928e303c2fb7eb5322402529b48b
child 488046 d915d805e9642c0e4cab3db3042bd9bdf5f2c5b7
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce, francois
bugs1483703
milestone63.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 1483703 - part2 : add telemetry for the media which was blocked before loading metadata and ended up being without audio track. r=cpearce,francois Add two telemetry scarlar, "MEDIA_BLOCKED_NO_METADATA" records how many media which was blocked because it hadn't loaded metadata yet. "MEDIA_BLOCKED_NO_METADATA_ENDUP_NO_AUDIO_TRACK" records how many media which was blocked because it hadn't loaded metadata and ended up for being no audio track. By collecting those data, we can know the proportion of media which should be autoplay but was blocked because of lacking metadata. Differential Revision: https://phabricator.services.mozilla.com/D3671
dom/html/HTMLMediaElement.cpp
dom/html/HTMLMediaElement.h
toolkit/components/telemetry/Scalars.yaml
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -1821,16 +1821,17 @@ HTMLMediaElement::AbortExistingLoads()
   mHaveQueuedSelectResource = false;
   mSuspendedForPreloadNone = false;
   mDownloadSuspendedByCache = false;
   mMediaInfo = MediaInfo();
   mIsEncrypted = false;
   mPendingEncryptedInitData.Reset();
   mWaitingForKey = NOT_WAITING_FOR_KEY;
   mSourcePointer = nullptr;
+  mBlockedAsWithoutMetadata = false;
 
   mTags = nullptr;
   mAudioTrackSilenceStartedTime = 0.0;
 
   if (mNetworkState != NETWORK_EMPTY) {
     NS_ASSERTION(!mDecoder && !mSrcStream,
                  "How did someone setup a new stream/decoder already?");
     // ChangeNetworkState() will call UpdateAudioChannelPlayingState()
@@ -4033,25 +4034,29 @@ HTMLMediaElement::NotifyXPCOMShutdown()
 
 bool
 HTMLMediaElement::AudioChannelAgentDelayingPlayback()
 {
   return mAudioChannelWrapper && mAudioChannelWrapper->IsPlaybackBlocked();
 }
 
 void
-HTMLMediaElement::UpdateHadAudibleAutoplayState() const
+HTMLMediaElement::UpdateHadAudibleAutoplayState()
 {
   // If we're audible, and autoplaying...
   if ((Volume() > 0.0 && !Muted()) &&
       (!OwnerDoc()->HasBeenUserGestureActivated() || Autoplay())) {
     OwnerDoc()->SetDocTreeHadAudibleMedia();
     if (AutoplayPolicy::WouldBeAllowedToPlayIfAutoplayDisabled(*this)) {
       ScalarAdd(Telemetry::ScalarID::MEDIA_AUTOPLAY_WOULD_BE_ALLOWED_COUNT, 1);
     } else {
+      if (mReadyState < HAVE_METADATA) {
+        mBlockedAsWithoutMetadata = true;
+        ScalarAdd(Telemetry::ScalarID::MEDIA_BLOCKED_NO_METADATA, 1);
+      }
       if (mReadyState >= HAVE_METADATA && !HasAudio()) {
         ScalarAdd(Telemetry::ScalarID::MEDIA_BLOCKED_AUTOPLAY_NO_AUDIO_TRACK_COUNT, 1);
       }
       ScalarAdd(Telemetry::ScalarID::MEDIA_AUTOPLAY_WOULD_NOT_BE_ALLOWED_COUNT, 1);
     }
   }
 }
 
@@ -5570,16 +5575,22 @@ HTMLMediaElement::MetadataLoaded(const M
   DispatchAsyncEvent(NS_LITERAL_STRING("loadedmetadata"));
   // The play invocation which was call by script had happened before media
   // element loaded metadata.
   if ((!mPaused && OwnerDoc() && !OwnerDoc()->HasBeenUserGestureActivated()) &&
       !HasAudio() &&
       (Volume() != 0 && !Muted())) {
     ScalarAdd(Telemetry::ScalarID::MEDIA_BLOCKED_AUTOPLAY_NO_AUDIO_TRACK_COUNT, 1);
   }
+
+  if (mBlockedAsWithoutMetadata && !HasAudio()) {
+    mBlockedAsWithoutMetadata = false;
+    ScalarAdd(Telemetry::ScalarID::MEDIA_BLOCKED_NO_METADATA_ENDUP_NO_AUDIO_TRACK, 1);
+  }
+
   if (mDecoder && mDecoder->IsTransportSeekable() &&
       mDecoder->IsMediaSeekable()) {
     ProcessMediaFragmentURI();
     mDecoder->SetFragmentEndTime(mFragmentEnd);
   }
   if (mIsEncrypted) {
     // We only support playback of encrypted content via MSE by default.
     if (!mMediaSource && Preferences::GetBool("media.eme.mse-only", true)) {
--- a/dom/html/HTMLMediaElement.h
+++ b/dom/html/HTMLMediaElement.h
@@ -1756,16 +1756,19 @@ protected:
   // MediaStream.
   nsCOMPtr<nsIPrincipal> mSrcStreamVideoPrincipal;
 
   // True if UnbindFromTree() is called on the element.
   // Note this flag is false when the element is in a phase after creation and
   // before attaching to the DOM tree.
   bool mUnboundFromTree = false;
 
+  // True if the autoplay media was blocked because it hadn't loaded metadata yet.
+  bool mBlockedAsWithoutMetadata = false;
+
 public:
   // Helper class to measure times for MSE telemetry stats
   class TimeDurationAccumulator
   {
   public:
     TimeDurationAccumulator()
       : mCount(0)
     {}
@@ -1809,17 +1812,17 @@ public:
     TimeStamp mStartTime;
     TimeDuration mSum;
     uint32_t mCount;
   };
 private:
 
   already_AddRefed<PlayPromise> CreatePlayPromise(ErrorResult& aRv) const;
 
-  void UpdateHadAudibleAutoplayState() const;
+  void UpdateHadAudibleAutoplayState();
 
   /**
    * This function is called by AfterSetAttr and OnAttrSetButNotChanged.
    * It will not be called if the value is being unset.
    *
    * @param aNamespaceID the namespace of the attr being set
    * @param aName the localname of the attribute being set
    * @param aNotify Whether we plan to notify document observers.
--- a/toolkit/components/telemetry/Scalars.yaml
+++ b/toolkit/components/telemetry/Scalars.yaml
@@ -943,16 +943,48 @@ media:
       - cpearce@mozilla.com
       - alwu@mozilla.com
       - nohlmeier@mozilla.com
     release_channel_collection: opt-in
     record_in_processes:
       - main
       - content
 
+  blocked_no_metadata:
+    bug_numbers:
+      - 1483703
+    description: >
+      The number of HTMLMediaElements which we blocked because they hadn't loaded metadata yet.
+    expires: "68"
+    kind: uint
+    notification_emails:
+      - cpearce@mozilla.com
+      - alwu@mozilla.com
+      - nohlmeier@mozilla.com
+    release_channel_collection: opt-in
+    record_in_processes:
+      - main
+      - content
+
+  blocked_no_metadata_endup_no_audio_track:
+    bug_numbers:
+      - 1483703
+    description: >
+      The number of HTMLMediaElements which were blocked because they hadn't loaded metadata yet, but ended up having no audio track.
+    expires: "68"
+    kind: uint
+    notification_emails:
+      - cpearce@mozilla.com
+      - alwu@mozilla.com
+      - nohlmeier@mozilla.com
+    release_channel_collection: opt-in
+    record_in_processes:
+      - main
+      - content
+
 # The following section contains content process base counters.
 dom.contentprocess:
   buildID_mismatch:
     bug_numbers:
       - 1366808
     description: >
       The number of times the about:restartrequired page appeared due to a
       buildID mismatch between the parent and the content processes.