Bug 1275492 - Add logs for TextTrackManager. r=jwwang
MozReview-Commit-ID: LyNTDhjj0fR
This commit is contained in:
@@ -20,6 +20,11 @@
|
||||
#include "nsTArrayHelpers.h"
|
||||
#include "nsIWebVTTParserWrapper.h"
|
||||
|
||||
|
||||
static mozilla::LazyLogModule gTextTrackLog("TextTrackManager");
|
||||
#define WEBVTT_LOG(...) MOZ_LOG(gTextTrackLog, LogLevel::Debug, (__VA_ARGS__))
|
||||
#define WEBVTT_LOGV(...) MOZ_LOG(gTextTrackLog, LogLevel::Verbose, (__VA_ARGS__))
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
@@ -104,7 +109,7 @@ TextTrackManager::TextTrackManager(HTMLMediaElement *aMediaElement)
|
||||
mMediaElement->OwnerDoc()->GetParentObject();
|
||||
|
||||
NS_ENSURE_TRUE_VOID(parentObject);
|
||||
|
||||
WEBVTT_LOG("%p Create TextTrackManager",this);
|
||||
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(parentObject);
|
||||
mNewCues = new TextTrackCueList(window);
|
||||
mLastActiveCues = new TextTrackCueList(window);
|
||||
@@ -122,6 +127,7 @@ TextTrackManager::TextTrackManager(HTMLMediaElement *aMediaElement)
|
||||
|
||||
TextTrackManager::~TextTrackManager()
|
||||
{
|
||||
WEBVTT_LOG("%p ~TextTrackManager",this);
|
||||
nsContentUtils::UnregisterShutdownObserver(mShutdownProxy);
|
||||
}
|
||||
|
||||
@@ -141,6 +147,9 @@ TextTrackManager::AddTextTrack(TextTrackKind aKind, const nsAString& aLabel,
|
||||
if (!mMediaElement || !mTextTracks) {
|
||||
return nullptr;
|
||||
}
|
||||
WEBVTT_LOG("%p AddTextTrack",this);
|
||||
WEBVTT_LOGV("AddTextTrack kind %d Label %s Language %s",aKind,
|
||||
NS_ConvertUTF16toUTF8(aLabel).get(), NS_ConvertUTF16toUTF8(aLanguage).get());
|
||||
RefPtr<TextTrack> track =
|
||||
mTextTracks->AddTextTrack(aKind, aLabel, aLanguage, aMode, aReadyState,
|
||||
aTextTrackSource, CompareTextTracks(mMediaElement));
|
||||
@@ -160,6 +169,7 @@ TextTrackManager::AddTextTrack(TextTrack* aTextTrack)
|
||||
if (!mMediaElement || !mTextTracks) {
|
||||
return;
|
||||
}
|
||||
WEBVTT_LOG("%p AddTextTrack TextTrack %p",this, aTextTrack);
|
||||
mTextTracks->AddTextTrack(aTextTrack, CompareTextTracks(mMediaElement));
|
||||
AddCues(aTextTrack);
|
||||
ReportTelemetryForTrack(aTextTrack);
|
||||
@@ -173,12 +183,14 @@ void
|
||||
TextTrackManager::AddCues(TextTrack* aTextTrack)
|
||||
{
|
||||
if (!mNewCues) {
|
||||
WEBVTT_LOG("AddCues mNewCues is null");
|
||||
return;
|
||||
}
|
||||
|
||||
TextTrackCueList* cueList = aTextTrack->GetCues();
|
||||
if (cueList) {
|
||||
bool dummy;
|
||||
WEBVTT_LOGV("AddCues cueList->Length() %d",cueList->Length());
|
||||
for (uint32_t i = 0; i < cueList->Length(); ++i) {
|
||||
mNewCues->AddCue(*cueList->IndexedGetter(i, dummy));
|
||||
}
|
||||
@@ -193,6 +205,7 @@ TextTrackManager::RemoveTextTrack(TextTrack* aTextTrack, bool aPendingListOnly)
|
||||
return;
|
||||
}
|
||||
|
||||
WEBVTT_LOG("%p RemoveTextTrack TextTrack %p", this, aTextTrack);
|
||||
mPendingTextTracks->RemoveTextTrack(aTextTrack);
|
||||
if (aPendingListOnly) {
|
||||
return;
|
||||
@@ -202,6 +215,7 @@ TextTrackManager::RemoveTextTrack(TextTrack* aTextTrack, bool aPendingListOnly)
|
||||
// Remove the cues in mNewCues belong to aTextTrack.
|
||||
TextTrackCueList* removeCueList = aTextTrack->GetCues();
|
||||
if (removeCueList) {
|
||||
WEBVTT_LOGV("RemoveTextTrack removeCueList->Length() %d", removeCueList->Length());
|
||||
for (uint32_t i = 0; i < removeCueList->Length(); ++i) {
|
||||
mNewCues->RemoveCue(*((*removeCueList)[i]));
|
||||
}
|
||||
@@ -212,11 +226,13 @@ TextTrackManager::RemoveTextTrack(TextTrack* aTextTrack, bool aPendingListOnly)
|
||||
void
|
||||
TextTrackManager::DidSeek()
|
||||
{
|
||||
WEBVTT_LOG("%p DidSeek",this);
|
||||
if (mTextTracks) {
|
||||
mTextTracks->DidSeek();
|
||||
}
|
||||
if (mMediaElement) {
|
||||
mLastTimeMarchesOnCalled = mMediaElement->CurrentTime();
|
||||
WEBVTT_LOGV("DidSeek set mLastTimeMarchesOnCalled %lf",mLastTimeMarchesOnCalled);
|
||||
}
|
||||
mHasSeeked = true;
|
||||
}
|
||||
@@ -224,6 +240,7 @@ TextTrackManager::DidSeek()
|
||||
void
|
||||
TextTrackManager::UpdateCueDisplay()
|
||||
{
|
||||
WEBVTT_LOG("UpdateCueDisplay");
|
||||
mUpdateCueDisplayDispatched = false;
|
||||
|
||||
if (!mMediaElement || !mTextTracks) {
|
||||
@@ -246,6 +263,8 @@ TextTrackManager::UpdateCueDisplay()
|
||||
mTextTracks->GetShowingCues(activeCues);
|
||||
|
||||
if (activeCues.Length() > 0) {
|
||||
WEBVTT_LOG("UpdateCueDisplay ProcessCues");
|
||||
WEBVTT_LOGV("UpdateCueDisplay activeCues.Length() %d",activeCues.Length());
|
||||
RefPtr<nsVariantCC> jsCues = new nsVariantCC();
|
||||
|
||||
jsCues->SetAsArray(nsIDataType::VTYPE_INTERFACE,
|
||||
@@ -257,6 +276,7 @@ TextTrackManager::UpdateCueDisplay()
|
||||
sParserWrapper->ProcessCues(window, jsCues, overlay, controls);
|
||||
}
|
||||
} else if (overlay->Length() > 0) {
|
||||
WEBVTT_LOG("UpdateCueDisplay EmptyString");
|
||||
nsContentUtils::SetNodeTextContent(overlay, EmptyString(), true);
|
||||
}
|
||||
}
|
||||
@@ -264,6 +284,7 @@ TextTrackManager::UpdateCueDisplay()
|
||||
void
|
||||
TextTrackManager::NotifyCueAdded(TextTrackCue& aCue)
|
||||
{
|
||||
WEBVTT_LOG("NotifyCueAdded");
|
||||
if (mNewCues) {
|
||||
mNewCues->AddCue(aCue);
|
||||
}
|
||||
@@ -274,6 +295,7 @@ TextTrackManager::NotifyCueAdded(TextTrackCue& aCue)
|
||||
void
|
||||
TextTrackManager::NotifyCueRemoved(TextTrackCue& aCue)
|
||||
{
|
||||
WEBVTT_LOG("NotifyCueRemoved");
|
||||
if (mNewCues) {
|
||||
mNewCues->RemoveCue(aCue);
|
||||
}
|
||||
@@ -321,7 +343,7 @@ TextTrackManager::HonorUserPreferencesForTrackSelection()
|
||||
if (performedTrackSelection || !mTextTracks) {
|
||||
return;
|
||||
}
|
||||
|
||||
WEBVTT_LOG("HonorUserPreferencesForTrackSelection");
|
||||
TextTrackKind ttKinds[] = { TextTrackKind::Captions,
|
||||
TextTrackKind::Subtitles };
|
||||
|
||||
@@ -371,6 +393,7 @@ TextTrackManager::PerformTrackSelection(TextTrackKind aTextTrackKinds[],
|
||||
// Step 3: If any TextTracks in candidates are showing then abort these steps.
|
||||
for (uint32_t i = 0; i < candidates.Length(); i++) {
|
||||
if (candidates[i]->Mode() == TextTrackMode::Showing) {
|
||||
WEBVTT_LOGV("PerformTrackSelection Showing return kind %d",candidates[i]->Kind());
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -382,6 +405,7 @@ TextTrackManager::PerformTrackSelection(TextTrackKind aTextTrackKinds[],
|
||||
if (TrackIsDefault(candidates[i]) &&
|
||||
candidates[i]->Mode() == TextTrackMode::Disabled) {
|
||||
candidates[i]->SetMode(TextTrackMode::Showing);
|
||||
WEBVTT_LOGV("PerformTrackSelection set Showing kind %d", candidates[i]->Kind());
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -449,6 +473,8 @@ public:
|
||||
{}
|
||||
|
||||
NS_IMETHOD Run() {
|
||||
WEBVTT_LOGV("SimpleTextTrackEvent cue %p mName %s mTime %lf",
|
||||
mCue.get(), NS_ConvertUTF16toUTF8(mName).get(), mTime);
|
||||
mCue->DispatchTrustedEvent(mName);
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -533,6 +559,7 @@ TextTrackManager::DispatchUpdateCueDisplay()
|
||||
{
|
||||
if (!mUpdateCueDisplayDispatched && !mShutdown &&
|
||||
(mMediaElement->GetHasUserInteraction() || mMediaElement->IsCurrentlyPlaying())) {
|
||||
WEBVTT_LOG("DispatchUpdateCueDisplay");
|
||||
NS_DispatchToMainThread(NewRunnableMethod(this, &TextTrackManager::UpdateCueDisplay));
|
||||
mUpdateCueDisplayDispatched = true;
|
||||
}
|
||||
@@ -547,6 +574,7 @@ TextTrackManager::DispatchTimeMarchesOn()
|
||||
// executing call upon completion will check queue for further 'work'.
|
||||
if (!mTimeMarchesOnDispatched && !mShutdown &&
|
||||
(mMediaElement->GetHasUserInteraction() || mMediaElement->IsCurrentlyPlaying())) {
|
||||
WEBVTT_LOG("DispatchTimeMarchesOn");
|
||||
NS_DispatchToMainThread(NewRunnableMethod(this, &TextTrackManager::TimeMarchesOn));
|
||||
mTimeMarchesOnDispatched = true;
|
||||
}
|
||||
@@ -557,7 +585,7 @@ void
|
||||
TextTrackManager::TimeMarchesOn()
|
||||
{
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
|
||||
WEBVTT_LOG("TimeMarchesOn");
|
||||
mTimeMarchesOnDispatched = false;
|
||||
|
||||
// Early return if we don't have any TextTracks.
|
||||
@@ -574,6 +602,7 @@ TextTrackManager::TimeMarchesOn()
|
||||
|
||||
if (mMediaElement &&
|
||||
(!(mMediaElement->GetPlayedOrSeeked()) || mMediaElement->Seeking())) {
|
||||
WEBVTT_LOG("TimeMarchesOn seeking or post return");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -581,6 +610,8 @@ TextTrackManager::TimeMarchesOn()
|
||||
double currentPlaybackTime = mMediaElement->CurrentTime();
|
||||
bool hasNormalPlayback = !mHasSeeked;
|
||||
mHasSeeked = false;
|
||||
WEBVTT_LOG("TimeMarchesOn mLastTimeMarchesOnCalled %lf currentPlaybackTime %lf hasNormalPlayback %d"
|
||||
, mLastTimeMarchesOnCalled, currentPlaybackTime, hasNormalPlayback);
|
||||
|
||||
// Step 1, 2.
|
||||
RefPtr<TextTrackCueList> currentCues =
|
||||
@@ -601,6 +632,7 @@ TextTrackManager::TimeMarchesOn()
|
||||
}
|
||||
}
|
||||
}
|
||||
WEBVTT_LOGV("TimeMarchesOn currentCues %d", currentCues->Length());
|
||||
// Populate otherCues with 'non-active" cues.
|
||||
if (hasNormalPlayback) {
|
||||
if (currentPlaybackTime < mLastTimeMarchesOnCalled) {
|
||||
@@ -619,7 +651,7 @@ TextTrackManager::TimeMarchesOn()
|
||||
TextTrackCue* cue = (*currentCues)[i];
|
||||
otherCues->RemoveCue(*cue);
|
||||
}
|
||||
|
||||
WEBVTT_LOGV("TimeMarchesOn otherCues %d", otherCues->Length());
|
||||
// Step 4.
|
||||
RefPtr<TextTrackCueList> missedCues = new TextTrackCueList(window);
|
||||
if (hasNormalPlayback) {
|
||||
@@ -631,7 +663,7 @@ TextTrackManager::TimeMarchesOn()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WEBVTT_LOGV("TimeMarchesOn missedCues %d", missedCues->Length());
|
||||
// Step 5. Empty now.
|
||||
// TODO: Step 6: fire timeupdate?
|
||||
|
||||
@@ -656,6 +688,7 @@ TextTrackManager::TimeMarchesOn()
|
||||
bool c3 = (missedCues->Length() == 0);
|
||||
if (c1 && c2 && c3) {
|
||||
mLastTimeMarchesOnCalled = currentPlaybackTime;
|
||||
WEBVTT_LOG("TimeMarchesOn step 7 return, mLastTimeMarchesOnCalled %lf", mLastTimeMarchesOnCalled);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -664,6 +697,7 @@ TextTrackManager::TimeMarchesOn()
|
||||
for (uint32_t i = 0; i < otherCues->Length(); ++i) {
|
||||
TextTrackCue* cue = (*otherCues)[i];
|
||||
if (cue && cue->PauseOnExit() && cue->GetActive()) {
|
||||
WEBVTT_LOG("TimeMarchesOn pause the MediaElement");
|
||||
mMediaElement->Pause();
|
||||
break;
|
||||
}
|
||||
@@ -671,6 +705,7 @@ TextTrackManager::TimeMarchesOn()
|
||||
for (uint32_t i = 0; i < missedCues->Length(); ++i) {
|
||||
TextTrackCue* cue = (*missedCues)[i];
|
||||
if (cue && cue->PauseOnExit()) {
|
||||
WEBVTT_LOG("TimeMarchesOn pause the MediaElement");
|
||||
mMediaElement->Pause();
|
||||
break;
|
||||
}
|
||||
@@ -759,12 +794,14 @@ void
|
||||
TextTrackManager::NotifyCueUpdated(TextTrackCue *aCue)
|
||||
{
|
||||
// TODO: Add/Reorder the cue to mNewCues if we have some optimization?
|
||||
WEBVTT_LOG("NotifyCueUpdated");
|
||||
DispatchTimeMarchesOn();
|
||||
}
|
||||
|
||||
void
|
||||
TextTrackManager::NotifyReset()
|
||||
{
|
||||
WEBVTT_LOG("NotifyReset");
|
||||
mLastTimeMarchesOnCalled = 0.0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user