Bug 1535223 - part3 : add log in TextTrack and TextTrackCue. r=jya
authorAlastor Wu <alwu@mozilla.com>
Thu, 14 Mar 2019 23:25:10 +0000
changeset 521987 f0c35396d81ff7b9ae11bbe23bd424fcf5c3be8d
parent 521986 49dd1144a43d6f77373f9e1e5d33dc33a94ec461
child 521988 f32dc8409c3de7b2f7181f034df2176219a728ad
push id10870
push usernbeleuzu@mozilla.com
push dateFri, 15 Mar 2019 20:00:07 +0000
treeherdermozilla-beta@c594aee5b7a4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjya
bugs1535223
milestone67.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 1535223 - part3 : add log in TextTrack and TextTrackCue. r=jya It would be helpful if we can also print the information in `TextTrack` and `TextTrackCue`. Differential Revision: https://phabricator.services.mozilla.com/D23449
dom/html/TextTrackManager.cpp
dom/media/TextTrack.cpp
dom/media/TextTrackCue.cpp
--- a/dom/html/TextTrackManager.cpp
+++ b/dom/html/TextTrackManager.cpp
@@ -16,17 +16,17 @@
 #include "mozilla/dom/TextTrackCue.h"
 #include "nsComponentManagerUtils.h"
 #include "nsGlobalWindow.h"
 #include "nsIFrame.h"
 #include "nsIWebVTTParserWrapper.h"
 #include "nsVariant.h"
 #include "nsVideoFrame.h"
 
-static mozilla::LazyLogModule gTextTrackLog("WebVTT");
+mozilla::LazyLogModule gTextTrackLog("WebVTT");
 
 #define WEBVTT_LOG(msg, ...) \
   MOZ_LOG(gTextTrackLog, LogLevel::Debug, ("TextTrackManager=%p, " msg, this, ##__VA_ARGS__))
 #define WEBVTT_LOGV(msg, ...) \
   MOZ_LOG(gTextTrackLog, LogLevel::Verbose, ("TextTrackManager=%p, " msg, this, ##__VA_ARGS__))
 
 namespace mozilla {
 namespace dom {
--- a/dom/media/TextTrack.cpp
+++ b/dom/media/TextTrack.cpp
@@ -10,19 +10,54 @@
 #include "mozilla/dom/TextTrackList.h"
 #include "mozilla/dom/TextTrackCue.h"
 #include "mozilla/dom/TextTrackCueList.h"
 #include "mozilla/dom/TextTrackRegion.h"
 #include "mozilla/dom/HTMLMediaElement.h"
 #include "mozilla/dom/HTMLTrackElement.h"
 #include "nsGlobalWindow.h"
 
+extern mozilla::LazyLogModule gTextTrackLog;
+
+#define WEBVTT_LOG(msg, ...) \
+  MOZ_LOG(gTextTrackLog, LogLevel::Debug, ("TextTrack=%p, " msg, this, ##__VA_ARGS__))
+
 namespace mozilla {
 namespace dom {
 
+static const char* ToStateStr(const TextTrackMode aMode) {
+  switch (aMode) {
+    case TextTrackMode::Disabled:
+      return "DISABLED";
+    case TextTrackMode::Hidden:
+      return "HIDDEN";
+    case TextTrackMode::Showing:
+      return "SHOWING";
+    default:
+      MOZ_ASSERT_UNREACHABLE("Invalid state.");
+  }
+  return "Unknown";
+}
+
+static const char* ToReadyStateStr(const TextTrackReadyState aState) {
+  switch (aState) {
+    case TextTrackReadyState::NotLoaded:
+      return "NotLoaded";
+    case TextTrackReadyState::Loading:
+      return "Loading";
+    case TextTrackReadyState::Loaded:
+      return "Loaded";
+    case TextTrackReadyState::FailedToLoad:
+      return "FailedToLoad";
+    default:
+      MOZ_ASSERT_UNREACHABLE("Invalid state.");
+  }
+  return "Unknown";
+}
+
 NS_IMPL_CYCLE_COLLECTION_INHERITED(TextTrack, DOMEventTargetHelper, mCueList,
                                    mActiveCueList, mTextTrackList,
                                    mTrackElement)
 
 NS_IMPL_ADDREF_INHERITED(TextTrack, DOMEventTargetHelper)
 NS_IMPL_RELEASE_INHERITED(TextTrack, DOMEventTargetHelper)
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TextTrack)
 NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
@@ -71,16 +106,17 @@ JSObject* TextTrack::WrapObject(JSContex
                                 JS::Handle<JSObject*> aGivenProto) {
   return TextTrack_Binding::Wrap(aCx, this, aGivenProto);
 }
 
 void TextTrack::SetMode(TextTrackMode aValue) {
   if (mMode == aValue) {
     return;
   }
+  WEBVTT_LOG("Set mode=%s", ToStateStr(aValue));
   mMode = aValue;
 
   HTMLMediaElement* mediaElement = GetMediaElement();
   if (aValue == TextTrackMode::Disabled) {
     for (size_t i = 0; i < mCueList->Length() && mediaElement; ++i) {
       mediaElement->NotifyCueRemoved(*(*mCueList)[i]);
     }
     SetCuesInactive();
@@ -101,30 +137,32 @@ void TextTrack::GetId(nsAString& aId) co
   // If the track has a track element then its id should be the same as the
   // track element's id.
   if (mTrackElement) {
     mTrackElement->GetAttribute(NS_LITERAL_STRING("id"), aId);
   }
 }
 
 void TextTrack::AddCue(TextTrackCue& aCue) {
+  WEBVTT_LOG("AddCue %p", &aCue);
   TextTrack* oldTextTrack = aCue.GetTrack();
   if (oldTextTrack) {
     ErrorResult dummy;
     oldTextTrack->RemoveCue(aCue, dummy);
   }
   mCueList->AddCue(aCue);
   aCue.SetTrack(this);
   HTMLMediaElement* mediaElement = GetMediaElement();
   if (mediaElement && (mMode != TextTrackMode::Disabled)) {
     mediaElement->NotifyCueAdded(aCue);
   }
 }
 
 void TextTrack::RemoveCue(TextTrackCue& aCue, ErrorResult& aRv) {
+  WEBVTT_LOG("RemoveCue %p", &aCue);
   // Bug1304948, check the aCue belongs to the TextTrack.
   mCueList->RemoveCue(aCue, aRv);
   if (aRv.Failed()) {
     return;
   }
   aCue.SetActive(false);
   aCue.SetTrack(nullptr);
   HTMLMediaElement* mediaElement = GetMediaElement();
@@ -156,16 +194,17 @@ TextTrackReadyState TextTrack::ReadyStat
 
 void TextTrack::SetReadyState(uint32_t aReadyState) {
   if (aReadyState <= TextTrackReadyState::FailedToLoad) {
     SetReadyState(static_cast<TextTrackReadyState>(aReadyState));
   }
 }
 
 void TextTrack::SetReadyState(TextTrackReadyState aState) {
+  WEBVTT_LOG("SetReadyState=%s", ToReadyStateStr(aState));
   mReadyState = aState;
   HTMLMediaElement* mediaElement = GetMediaElement();
   if (mediaElement && (mReadyState == TextTrackReadyState::Loaded ||
                        mReadyState == TextTrackReadyState::FailedToLoad)) {
     mediaElement->RemoveTextTrack(this, true);
     mediaElement->UpdateReadyState();
   }
 }
@@ -180,16 +219,17 @@ HTMLTrackElement* TextTrack::GetTrackEle
 
 void TextTrack::SetTrackElement(HTMLTrackElement* aTrackElement) {
   mTrackElement = aTrackElement;
 }
 
 void TextTrack::SetCuesInactive() { mCueList->SetCuesInactive(); }
 
 void TextTrack::NotifyCueUpdated(TextTrackCue* aCue) {
+  WEBVTT_LOG("NotifyCueUpdated, cue=%p", aCue);
   mCueList->NotifyCueUpdated(aCue);
   HTMLMediaElement* mediaElement = GetMediaElement();
   if (mediaElement) {
     mediaElement->NotifyCueUpdated(aCue);
   }
 }
 
 void TextTrack::GetLabel(nsAString& aLabel) const {
@@ -234,19 +274,21 @@ bool TextTrack::IsLoaded() {
   }
   return (mReadyState >= Loaded);
 }
 
 void TextTrack::NotifyCueActiveStateChanged(TextTrackCue* aCue) {
   MOZ_ASSERT(aCue);
   if (aCue->GetActive()) {
     MOZ_ASSERT(!mActiveCueList->IsCueExist(aCue));
+    WEBVTT_LOG("NotifyCueActiveStateChanged, add cue %p to the active list", aCue);
     mActiveCueList->AddCue(*aCue);
   } else {
     MOZ_ASSERT(mActiveCueList->IsCueExist(aCue));
+    WEBVTT_LOG("NotifyCueActiveStateChanged, remove cue %p from the active list", aCue);
     mActiveCueList->RemoveCue(*aCue);
   }
 }
 
 void TextTrack::GetCurrentCueList(RefPtr<TextTrackCueList>& aCueList) const {
   const HTMLMediaElement* mediaElement = GetMediaElement();
   if (!mediaElement) {
     return;
@@ -256,16 +298,18 @@ void TextTrack::GetCurrentCueList(RefPtr
   // whose start times are less than or equal to the current playback position
   // and whose end times are greater than the current playback position.
   // https://html.spec.whatwg.org/multipage/media.html#time-marches-on
   MOZ_ASSERT(aCueList);
   const double playbackTime = mediaElement->CurrentTime();
   for (uint32_t idx = 0; idx < mCueList->Length(); idx++) {
     TextTrackCue* cue = (*mCueList)[idx];
     if (cue->StartTime() <= playbackTime && cue->EndTime() > playbackTime) {
+      WEBVTT_LOG("Add cue %p [%f:%f] to current cue list",
+                 cue, cue->StartTime(), cue->EndTime());
       aCueList->AddCue(*cue);
     }
   }
 }
 
 HTMLMediaElement* TextTrack::GetMediaElement() const {
   return mTextTrackList ? mTextTrackList->GetMediaElement() : nullptr;
 }
--- a/dom/media/TextTrackCue.cpp
+++ b/dom/media/TextTrackCue.cpp
@@ -5,16 +5,21 @@
 
 #include "mozilla/dom/HTMLTrackElement.h"
 #include "mozilla/dom/TextTrackCue.h"
 #include "mozilla/dom/TextTrackList.h"
 #include "mozilla/dom/TextTrackRegion.h"
 #include "nsComponentManagerUtils.h"
 #include "mozilla/ClearOnShutdown.h"
 
+extern mozilla::LazyLogModule gTextTrackLog;
+
+#define LOG(msg, ...) \
+  MOZ_LOG(gTextTrackLog, LogLevel::Debug, ("TextTrackCue=%p, " msg, this, ##__VA_ARGS__))
+
 namespace mozilla {
 namespace dom {
 
 NS_IMPL_CYCLE_COLLECTION_INHERITED(TextTrackCue, DOMEventTargetHelper,
                                    mDocument, mTrack, mTrackElement,
                                    mDisplayState, mRegion)
 
 NS_IMPL_ADDREF_INHERITED(TextTrackCue, DOMEventTargetHelper)
@@ -47,16 +52,17 @@ TextTrackCue::TextTrackCue(nsPIDOMWindow
       mStartTime(aStartTime),
       mEndTime(aEndTime),
       mPosition(0.0),
       mLine(0.0),
       mReset(false, "TextTrackCue::mReset"),
       mHaveStartedWatcher(false),
       mWatchManager(
           this, GetOwnerGlobal()->AbstractMainThreadFor(TaskCategory::Other)) {
+  LOG("create TextTrackCue");
   SetDefaultCueSettings();
   MOZ_ASSERT(aOwnerWindow);
   if (NS_FAILED(StashDocument())) {
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
   }
 }
 
 TextTrackCue::TextTrackCue(nsPIDOMWindowInner* aOwnerWindow, double aStartTime,
@@ -68,16 +74,17 @@ TextTrackCue::TextTrackCue(nsPIDOMWindow
       mEndTime(aEndTime),
       mTrackElement(aTrackElement),
       mPosition(0.0),
       mLine(0.0),
       mReset(false, "TextTrackCue::mReset"),
       mHaveStartedWatcher(false),
       mWatchManager(
           this, GetOwnerGlobal()->AbstractMainThreadFor(TaskCategory::Other)) {
+  LOG("create TextTrackCue");
   SetDefaultCueSettings();
   MOZ_ASSERT(aOwnerWindow);
   if (NS_FAILED(StashDocument())) {
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
   }
 }
 
 TextTrackCue::~TextTrackCue() {}
@@ -216,16 +223,17 @@ void TextTrackCue::NotifyDisplayStatesCh
       ->NotifyCueDisplayStatesChanged();
 }
 
 void TextTrackCue::SetActive(bool aActive) {
   if (mActive == aActive) {
     return;
   }
 
+  LOG("TextTrackCue, SetActive=%d", aActive);
   mActive = aActive;
   mDisplayState = mActive ? mDisplayState : nullptr;
   if (mTrack) {
     mTrack->NotifyCueActiveStateChanged(this);
   }
 }
 
 }  // namespace dom