Bug 1294349 - Report VIDEO_SUSPEND_RECOVERY_TIME_MS - r=kaku draft
authorGerald Squelart <gsquelart@mozilla.com>
Thu, 11 Aug 2016 15:05:22 +0800
changeset 401000 1adf4bd168344dff39b3fb1d105902b25a778b6c
parent 400999 aba5b1960f991fe596f7a54476f784e7ab0d661d
child 528369 669dafb9f1d7f0f8ab06c60a5f1e1cd37f1ed26f
push id26331
push usergsquelart@mozilla.com
push dateTue, 16 Aug 2016 04:47:59 +0000
reviewerskaku
bugs1294349
milestone51.0a1
Bug 1294349 - Report VIDEO_SUSPEND_RECOVERY_TIME_MS - r=kaku MozReview-Commit-ID: EipANZqUhBh
dom/media/MediaDecoderStateMachine.cpp
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -1329,16 +1329,57 @@ void MediaDecoderStateMachine::PlayState
   // when the state machine notices the decoder's state change to PLAYING.
   if (mState == DECODER_STATE_BUFFERING) {
     StartDecoding();
   }
 
   ScheduleStateMachine();
 }
 
+static void
+ReportRecoveryTelemetry(const TimeStamp& aRecoveryStart,
+                        const MediaInfo& aMediaInfo,
+                        bool aIsHardwareAccelerated)
+{
+  MOZ_ASSERT(NS_IsMainThread());
+  if (!aMediaInfo.HasVideo()) {
+    return;
+  }
+
+  // Keyed by audio+video or video alone, hardware acceleration,
+  // and by a resolution range.
+  nsCString key(aMediaInfo.HasAudio() ? "AV" : "V");
+  key.AppendASCII(aIsHardwareAccelerated ? "(hw)," : ",");
+  static const struct { int32_t mH; const char* mRes; } sResolutions[] = {
+    {  240, "0-240" },
+    {  480, "241-480" },
+    {  720, "481-720" },
+    { 1080, "721-1080" },
+    { 2160, "1081-2160" }
+  };
+  const char* resolution = "2161+";
+  int32_t height = aMediaInfo.mVideo.mImage.height;
+  for (const auto& res : sResolutions) {
+    if (height <= res.mH) {
+      resolution = res.mRes;
+      break;
+    }
+  }
+  key.AppendASCII(resolution);
+
+  TimeDuration duration = TimeStamp::Now() - aRecoveryStart;
+  double duration_ms = duration.ToMilliseconds();
+  Telemetry::Accumulate(Telemetry::VIDEO_SUSPEND_RECOVERY_TIME_MS,
+                        key,
+                        uint32_t(duration_ms + 0.5));
+  Telemetry::Accumulate(Telemetry::VIDEO_SUSPEND_RECOVERY_TIME_MS,
+                        NS_LITERAL_CSTRING("All"),
+                        uint32_t(duration_ms + 0.5));
+}
+
 void MediaDecoderStateMachine::VisibilityChanged()
 {
   MOZ_ASSERT(OnTaskQueue());
   DECODER_LOG("VisibilityChanged: mIsVisible=%d, "
               "mVideoDecodeSuspended=%c, mIsReaderSuspended=%d",
               mIsVisible.Ref(), mVideoDecodeSuspended ? 'T' : 'F', mIsReaderSuspended.Ref());
 
   if (!HasVideo()) {
@@ -1376,23 +1417,31 @@ void MediaDecoderStateMachine::Visibilit
     }
 
     // If an existing seek is in flight don't bother creating a new
     // one to catch up.
     if (mSeekTask || mQueuedSeek.Exists()) {
       return;
     }
 
-    // Start video-only seek to the current time...
+    // Start counting recovery time from right now.
+    TimeStamp start = TimeStamp::Now();
+    // Local reference to mInfo, so that it will be copied in the lambda below.
+    MediaInfo& info = mInfo;
+    bool hw = mReader->VideoIsHardwareAccelerated();
+    // Start video-only seek to the current time.
     SeekJob seekJob;
     seekJob.mTarget = SeekTarget(GetMediaTime(),
                                  SeekTarget::Type::Accurate,
                                  MediaDecoderEventVisibility::Suppressed,
                                  true /* aVideoOnly */);
-    InitiateSeek(Move(seekJob));
+    InitiateSeek(Move(seekJob))
+      ->Then(AbstractThread::MainThread(), __func__,
+             [start, info, hw](){ ReportRecoveryTelemetry(start, info, hw); },
+             [](){});
   }
 }
 
 void MediaDecoderStateMachine::BufferedRangeUpdated()
 {
   MOZ_ASSERT(OnTaskQueue());
 
   // While playing an unseekable stream of unknown duration, mObservedDuration