Bug 1511181 - Reformat everything to the Google coding style r=ehsan a=clang-format
# ignore-this-changeset
This commit is contained in:
@@ -21,30 +21,26 @@
|
||||
#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__))
|
||||
#define WEBVTT_LOG(...) MOZ_LOG(gTextTrackLog, LogLevel::Debug, (__VA_ARGS__))
|
||||
#define WEBVTT_LOGV(...) \
|
||||
MOZ_LOG(gTextTrackLog, LogLevel::Verbose, (__VA_ARGS__))
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
NS_IMPL_ISUPPORTS(TextTrackManager::ShutdownObserverProxy, nsIObserver);
|
||||
|
||||
void
|
||||
TextTrackManager::ShutdownObserverProxy::Unregister()
|
||||
{
|
||||
void TextTrackManager::ShutdownObserverProxy::Unregister() {
|
||||
nsContentUtils::UnregisterShutdownObserver(this);
|
||||
mManager = nullptr;
|
||||
}
|
||||
|
||||
CompareTextTracks::CompareTextTracks(HTMLMediaElement* aMediaElement)
|
||||
{
|
||||
CompareTextTracks::CompareTextTracks(HTMLMediaElement* aMediaElement) {
|
||||
mMediaElement = aMediaElement;
|
||||
}
|
||||
|
||||
int32_t
|
||||
CompareTextTracks::TrackChildPosition(TextTrack* aTextTrack) const {
|
||||
int32_t CompareTextTracks::TrackChildPosition(TextTrack* aTextTrack) const {
|
||||
MOZ_DIAGNOSTIC_ASSERT(aTextTrack);
|
||||
HTMLTrackElement* trackElement = aTextTrack->GetTrackElement();
|
||||
if (!trackElement) {
|
||||
@@ -53,8 +49,7 @@ CompareTextTracks::TrackChildPosition(TextTrack* aTextTrack) const {
|
||||
return mMediaElement->ComputeIndexOf(trackElement);
|
||||
}
|
||||
|
||||
bool
|
||||
CompareTextTracks::Equals(TextTrack* aOne, TextTrack* aTwo) const {
|
||||
bool CompareTextTracks::Equals(TextTrack* aOne, TextTrack* aTwo) const {
|
||||
// Two tracks can never be equal. If they have corresponding TrackElements
|
||||
// they would need to occupy the same tree position (impossible) and in the
|
||||
// case of tracks coming from AddTextTrack source we put the newest at the
|
||||
@@ -62,9 +57,7 @@ CompareTextTracks::Equals(TextTrack* aOne, TextTrack* aTwo) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
CompareTextTracks::LessThan(TextTrack* aOne, TextTrack* aTwo) const
|
||||
{
|
||||
bool CompareTextTracks::LessThan(TextTrack* aOne, TextTrack* aTwo) const {
|
||||
// Protect against nullptr TextTrack objects; treat them as
|
||||
// sorting toward the end.
|
||||
if (!aOne) {
|
||||
@@ -89,9 +82,10 @@ CompareTextTracks::LessThan(TextTrack* aOne, TextTrack* aTwo) const
|
||||
positionOne < positionTwo;
|
||||
}
|
||||
case AddTextTrack:
|
||||
// For AddTextTrack sources the tracks will already be in the correct relative
|
||||
// order in the source array. Assume we're called in iteration order and can
|
||||
// therefore always report aOne < aTwo to maintain the original temporal ordering.
|
||||
// For AddTextTrack sources the tracks will already be in the correct
|
||||
// relative order in the source array. Assume we're called in iteration
|
||||
// order and can therefore always report aOne < aTwo to maintain the
|
||||
// original temporal ordering.
|
||||
return true;
|
||||
case MediaResourceSpecific:
|
||||
// No rules for Media Resource Specific tracks yet.
|
||||
@@ -101,8 +95,7 @@ CompareTextTracks::LessThan(TextTrack* aOne, TextTrack* aTwo) const
|
||||
}
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION(TextTrackManager, mMediaElement, mTextTracks,
|
||||
mPendingTextTracks, mNewCues,
|
||||
mLastActiveCues)
|
||||
mPendingTextTracks, mNewCues, mLastActiveCues)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TextTrackManager)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIDOMEventListener)
|
||||
@@ -113,21 +106,19 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(TextTrackManager)
|
||||
|
||||
StaticRefPtr<nsIWebVTTParserWrapper> TextTrackManager::sParserWrapper;
|
||||
|
||||
TextTrackManager::TextTrackManager(HTMLMediaElement *aMediaElement)
|
||||
: mMediaElement(aMediaElement)
|
||||
, mHasSeeked(false)
|
||||
, mLastTimeMarchesOnCalled(0.0)
|
||||
, mTimeMarchesOnDispatched(false)
|
||||
, mUpdateCueDisplayDispatched(false)
|
||||
, performedTrackSelection(false)
|
||||
, mCueTelemetryReported(false)
|
||||
, mShutdown(false)
|
||||
{
|
||||
nsISupports* parentObject =
|
||||
mMediaElement->OwnerDoc()->GetParentObject();
|
||||
TextTrackManager::TextTrackManager(HTMLMediaElement* aMediaElement)
|
||||
: mMediaElement(aMediaElement),
|
||||
mHasSeeked(false),
|
||||
mLastTimeMarchesOnCalled(0.0),
|
||||
mTimeMarchesOnDispatched(false),
|
||||
mUpdateCueDisplayDispatched(false),
|
||||
performedTrackSelection(false),
|
||||
mCueTelemetryReported(false),
|
||||
mShutdown(false) {
|
||||
nsISupports* parentObject = mMediaElement->OwnerDoc()->GetParentObject();
|
||||
|
||||
NS_ENSURE_TRUE_VOID(parentObject);
|
||||
WEBVTT_LOG("%p Create TextTrackManager",this);
|
||||
WEBVTT_LOG("%p Create TextTrackManager", this);
|
||||
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(parentObject);
|
||||
mNewCues = new TextTrackCueList(window);
|
||||
mLastActiveCues = new TextTrackCueList(window);
|
||||
@@ -136,7 +127,7 @@ TextTrackManager::TextTrackManager(HTMLMediaElement *aMediaElement)
|
||||
|
||||
if (!sParserWrapper) {
|
||||
nsCOMPtr<nsIWebVTTParserWrapper> parserWrapper =
|
||||
do_CreateInstance(NS_WEBVTTPARSERWRAPPER_CONTRACTID);
|
||||
do_CreateInstance(NS_WEBVTTPARSERWRAPPER_CONTRACTID);
|
||||
MOZ_ASSERT(parserWrapper, "Can't create nsIWebVTTParserWrapper");
|
||||
sParserWrapper = parserWrapper;
|
||||
ClearOnShutdown(&sParserWrapper);
|
||||
@@ -144,72 +135,58 @@ TextTrackManager::TextTrackManager(HTMLMediaElement *aMediaElement)
|
||||
mShutdownProxy = new ShutdownObserverProxy(this);
|
||||
}
|
||||
|
||||
TextTrackManager::~TextTrackManager()
|
||||
{
|
||||
WEBVTT_LOG("%p ~TextTrackManager",this);
|
||||
TextTrackManager::~TextTrackManager() {
|
||||
WEBVTT_LOG("%p ~TextTrackManager", this);
|
||||
mShutdownProxy->Unregister();
|
||||
}
|
||||
|
||||
TextTrackList*
|
||||
TextTrackManager::GetTextTracks() const
|
||||
{
|
||||
return mTextTracks;
|
||||
}
|
||||
TextTrackList* TextTrackManager::GetTextTracks() const { return mTextTracks; }
|
||||
|
||||
already_AddRefed<TextTrack>
|
||||
TextTrackManager::AddTextTrack(TextTrackKind aKind, const nsAString& aLabel,
|
||||
const nsAString& aLanguage,
|
||||
TextTrackMode aMode,
|
||||
TextTrackReadyState aReadyState,
|
||||
TextTrackSource aTextTrackSource)
|
||||
{
|
||||
already_AddRefed<TextTrack> TextTrackManager::AddTextTrack(
|
||||
TextTrackKind aKind, const nsAString& aLabel, const nsAString& aLanguage,
|
||||
TextTrackMode aMode, TextTrackReadyState aReadyState,
|
||||
TextTrackSource aTextTrackSource) {
|
||||
if (!mMediaElement || !mTextTracks) {
|
||||
return nullptr;
|
||||
}
|
||||
WEBVTT_LOG("%p AddTextTrack",this);
|
||||
WEBVTT_LOG("%p AddTextTrack", this);
|
||||
WEBVTT_LOGV("AddTextTrack kind %" PRIu32 " Label %s Language %s",
|
||||
static_cast<uint32_t>(aKind),
|
||||
NS_ConvertUTF16toUTF8(aLabel).get(), NS_ConvertUTF16toUTF8(aLanguage).get());
|
||||
RefPtr<TextTrack> track =
|
||||
mTextTracks->AddTextTrack(aKind, aLabel, aLanguage, aMode, aReadyState,
|
||||
aTextTrackSource, CompareTextTracks(mMediaElement));
|
||||
static_cast<uint32_t>(aKind), NS_ConvertUTF16toUTF8(aLabel).get(),
|
||||
NS_ConvertUTF16toUTF8(aLanguage).get());
|
||||
RefPtr<TextTrack> track = mTextTracks->AddTextTrack(
|
||||
aKind, aLabel, aLanguage, aMode, aReadyState, aTextTrackSource,
|
||||
CompareTextTracks(mMediaElement));
|
||||
AddCues(track);
|
||||
ReportTelemetryForTrack(track);
|
||||
|
||||
if (aTextTrackSource == TextTrackSource::Track) {
|
||||
RefPtr<nsIRunnable> task = NewRunnableMethod(
|
||||
"dom::TextTrackManager::HonorUserPreferencesForTrackSelection",
|
||||
this,
|
||||
&TextTrackManager::HonorUserPreferencesForTrackSelection);
|
||||
"dom::TextTrackManager::HonorUserPreferencesForTrackSelection", this,
|
||||
&TextTrackManager::HonorUserPreferencesForTrackSelection);
|
||||
nsContentUtils::RunInStableState(task.forget());
|
||||
}
|
||||
|
||||
return track.forget();
|
||||
}
|
||||
|
||||
void
|
||||
TextTrackManager::AddTextTrack(TextTrack* aTextTrack)
|
||||
{
|
||||
void TextTrackManager::AddTextTrack(TextTrack* aTextTrack) {
|
||||
if (!mMediaElement || !mTextTracks) {
|
||||
return;
|
||||
}
|
||||
WEBVTT_LOG("%p AddTextTrack TextTrack %p",this, aTextTrack);
|
||||
WEBVTT_LOG("%p AddTextTrack TextTrack %p", this, aTextTrack);
|
||||
mTextTracks->AddTextTrack(aTextTrack, CompareTextTracks(mMediaElement));
|
||||
AddCues(aTextTrack);
|
||||
ReportTelemetryForTrack(aTextTrack);
|
||||
|
||||
if (aTextTrack->GetTextTrackSource() == TextTrackSource::Track) {
|
||||
RefPtr<nsIRunnable> task = NewRunnableMethod(
|
||||
"dom::TextTrackManager::HonorUserPreferencesForTrackSelection",
|
||||
this,
|
||||
&TextTrackManager::HonorUserPreferencesForTrackSelection);
|
||||
"dom::TextTrackManager::HonorUserPreferencesForTrackSelection", this,
|
||||
&TextTrackManager::HonorUserPreferencesForTrackSelection);
|
||||
nsContentUtils::RunInStableState(task.forget());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TextTrackManager::AddCues(TextTrack* aTextTrack)
|
||||
{
|
||||
void TextTrackManager::AddCues(TextTrack* aTextTrack) {
|
||||
if (!mNewCues) {
|
||||
WEBVTT_LOG("AddCues mNewCues is null");
|
||||
return;
|
||||
@@ -218,7 +195,7 @@ TextTrackManager::AddCues(TextTrack* aTextTrack)
|
||||
TextTrackCueList* cueList = aTextTrack->GetCues();
|
||||
if (cueList) {
|
||||
bool dummy;
|
||||
WEBVTT_LOGV("AddCues cueList->Length() %d",cueList->Length());
|
||||
WEBVTT_LOGV("AddCues cueList->Length() %d", cueList->Length());
|
||||
for (uint32_t i = 0; i < cueList->Length(); ++i) {
|
||||
mNewCues->AddCue(*cueList->IndexedGetter(i, dummy));
|
||||
}
|
||||
@@ -226,9 +203,8 @@ TextTrackManager::AddCues(TextTrack* aTextTrack)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TextTrackManager::RemoveTextTrack(TextTrack* aTextTrack, bool aPendingListOnly)
|
||||
{
|
||||
void TextTrackManager::RemoveTextTrack(TextTrack* aTextTrack,
|
||||
bool aPendingListOnly) {
|
||||
if (!mPendingTextTracks || !mTextTracks) {
|
||||
return;
|
||||
}
|
||||
@@ -243,7 +219,8 @@ 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());
|
||||
WEBVTT_LOGV("RemoveTextTrack removeCueList->Length() %d",
|
||||
removeCueList->Length());
|
||||
for (uint32_t i = 0; i < removeCueList->Length(); ++i) {
|
||||
mNewCues->RemoveCue(*((*removeCueList)[i]));
|
||||
}
|
||||
@@ -251,23 +228,20 @@ TextTrackManager::RemoveTextTrack(TextTrack* aTextTrack, bool aPendingListOnly)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TextTrackManager::DidSeek()
|
||||
{
|
||||
WEBVTT_LOG("%p DidSeek",this);
|
||||
void TextTrackManager::DidSeek() {
|
||||
WEBVTT_LOG("%p DidSeek", this);
|
||||
if (mTextTracks) {
|
||||
mTextTracks->DidSeek();
|
||||
}
|
||||
if (mMediaElement) {
|
||||
mLastTimeMarchesOnCalled = mMediaElement->CurrentTime();
|
||||
WEBVTT_LOGV("DidSeek set mLastTimeMarchesOnCalled %lf",mLastTimeMarchesOnCalled);
|
||||
WEBVTT_LOGV("DidSeek set mLastTimeMarchesOnCalled %lf",
|
||||
mLastTimeMarchesOnCalled);
|
||||
}
|
||||
mHasSeeked = true;
|
||||
}
|
||||
|
||||
void
|
||||
TextTrackManager::UpdateCueDisplay()
|
||||
{
|
||||
void TextTrackManager::UpdateCueDisplay() {
|
||||
WEBVTT_LOG("UpdateCueDisplay");
|
||||
mUpdateCueDisplayDispatched = false;
|
||||
|
||||
@@ -287,16 +261,16 @@ TextTrackManager::UpdateCueDisplay()
|
||||
return;
|
||||
}
|
||||
|
||||
nsTArray<RefPtr<TextTrackCue> > showingCues;
|
||||
nsTArray<RefPtr<TextTrackCue>> showingCues;
|
||||
mTextTracks->GetShowingCues(showingCues);
|
||||
|
||||
if (showingCues.Length() > 0) {
|
||||
WEBVTT_LOG("UpdateCueDisplay ProcessCues");
|
||||
WEBVTT_LOGV("UpdateCueDisplay showingCues.Length() %zu", showingCues.Length());
|
||||
WEBVTT_LOGV("UpdateCueDisplay showingCues.Length() %zu",
|
||||
showingCues.Length());
|
||||
RefPtr<nsVariantCC> jsCues = new nsVariantCC();
|
||||
|
||||
jsCues->SetAsArray(nsIDataType::VTYPE_INTERFACE,
|
||||
&NS_GET_IID(EventTarget),
|
||||
jsCues->SetAsArray(nsIDataType::VTYPE_INTERFACE, &NS_GET_IID(EventTarget),
|
||||
showingCues.Length(),
|
||||
static_cast<void*>(showingCues.Elements()));
|
||||
nsPIDOMWindowInner* window = mMediaElement->OwnerDoc()->GetInnerWindow();
|
||||
@@ -309,9 +283,7 @@ TextTrackManager::UpdateCueDisplay()
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TextTrackManager::NotifyCueAdded(TextTrackCue& aCue)
|
||||
{
|
||||
void TextTrackManager::NotifyCueAdded(TextTrackCue& aCue) {
|
||||
WEBVTT_LOG("NotifyCueAdded");
|
||||
if (mNewCues) {
|
||||
mNewCues->AddCue(aCue);
|
||||
@@ -320,9 +292,7 @@ TextTrackManager::NotifyCueAdded(TextTrackCue& aCue)
|
||||
ReportTelemetryForCue();
|
||||
}
|
||||
|
||||
void
|
||||
TextTrackManager::NotifyCueRemoved(TextTrackCue& aCue)
|
||||
{
|
||||
void TextTrackManager::NotifyCueRemoved(TextTrackCue& aCue) {
|
||||
WEBVTT_LOG("NotifyCueRemoved");
|
||||
if (mNewCues) {
|
||||
mNewCues->RemoveCue(aCue);
|
||||
@@ -334,9 +304,7 @@ TextTrackManager::NotifyCueRemoved(TextTrackCue& aCue)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TextTrackManager::PopulatePendingList()
|
||||
{
|
||||
void TextTrackManager::PopulatePendingList() {
|
||||
if (!mTextTracks || !mPendingTextTracks || !mMediaElement) {
|
||||
return;
|
||||
}
|
||||
@@ -352,28 +320,23 @@ TextTrackManager::PopulatePendingList()
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TextTrackManager::AddListeners()
|
||||
{
|
||||
void TextTrackManager::AddListeners() {
|
||||
if (mMediaElement) {
|
||||
mMediaElement->AddEventListener(NS_LITERAL_STRING("resizevideocontrols"),
|
||||
this, false, false);
|
||||
mMediaElement->AddEventListener(NS_LITERAL_STRING("seeked"),
|
||||
this, false, false);
|
||||
mMediaElement->AddEventListener(NS_LITERAL_STRING("controlbarchange"),
|
||||
this, false, true);
|
||||
mMediaElement->AddEventListener(NS_LITERAL_STRING("seeked"), this, false,
|
||||
false);
|
||||
mMediaElement->AddEventListener(NS_LITERAL_STRING("controlbarchange"), this,
|
||||
false, true);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TextTrackManager::HonorUserPreferencesForTrackSelection()
|
||||
{
|
||||
void TextTrackManager::HonorUserPreferencesForTrackSelection() {
|
||||
if (performedTrackSelection || !mTextTracks) {
|
||||
return;
|
||||
}
|
||||
WEBVTT_LOG("HonorUserPreferencesForTrackSelection");
|
||||
TextTrackKind ttKinds[] = { TextTrackKind::Captions,
|
||||
TextTrackKind::Subtitles };
|
||||
TextTrackKind ttKinds[] = {TextTrackKind::Captions, TextTrackKind::Subtitles};
|
||||
|
||||
// Steps 1 - 3: Perform automatic track selection for different TextTrack
|
||||
// Kinds.
|
||||
@@ -394,9 +357,7 @@ TextTrackManager::HonorUserPreferencesForTrackSelection()
|
||||
performedTrackSelection = true;
|
||||
}
|
||||
|
||||
bool
|
||||
TextTrackManager::TrackIsDefault(TextTrack* aTextTrack)
|
||||
{
|
||||
bool TextTrackManager::TrackIsDefault(TextTrack* aTextTrack) {
|
||||
HTMLTrackElement* trackElement = aTextTrack->GetTrackElement();
|
||||
if (!trackElement) {
|
||||
return false;
|
||||
@@ -404,17 +365,13 @@ TextTrackManager::TrackIsDefault(TextTrack* aTextTrack)
|
||||
return trackElement->Default();
|
||||
}
|
||||
|
||||
void
|
||||
TextTrackManager::PerformTrackSelection(TextTrackKind aTextTrackKind)
|
||||
{
|
||||
TextTrackKind ttKinds[] = { aTextTrackKind };
|
||||
void TextTrackManager::PerformTrackSelection(TextTrackKind aTextTrackKind) {
|
||||
TextTrackKind ttKinds[] = {aTextTrackKind};
|
||||
PerformTrackSelection(ttKinds, ArrayLength(ttKinds));
|
||||
}
|
||||
|
||||
void
|
||||
TextTrackManager::PerformTrackSelection(TextTrackKind aTextTrackKinds[],
|
||||
uint32_t size)
|
||||
{
|
||||
void TextTrackManager::PerformTrackSelection(TextTrackKind aTextTrackKinds[],
|
||||
uint32_t size) {
|
||||
nsTArray<TextTrack*> candidates;
|
||||
GetTextTracksOfKinds(aTextTrackKinds, size, candidates);
|
||||
|
||||
@@ -441,20 +398,16 @@ TextTrackManager::PerformTrackSelection(TextTrackKind aTextTrackKinds[],
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TextTrackManager::GetTextTracksOfKinds(TextTrackKind aTextTrackKinds[],
|
||||
uint32_t size,
|
||||
nsTArray<TextTrack*>& aTextTracks)
|
||||
{
|
||||
void TextTrackManager::GetTextTracksOfKinds(TextTrackKind aTextTrackKinds[],
|
||||
uint32_t size,
|
||||
nsTArray<TextTrack*>& aTextTracks) {
|
||||
for (uint32_t i = 0; i < size; i++) {
|
||||
GetTextTracksOfKind(aTextTrackKinds[i], aTextTracks);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TextTrackManager::GetTextTracksOfKind(TextTrackKind aTextTrackKind,
|
||||
nsTArray<TextTrack*>& aTextTracks)
|
||||
{
|
||||
void TextTrackManager::GetTextTracksOfKind(TextTrackKind aTextTrackKind,
|
||||
nsTArray<TextTrack*>& aTextTracks) {
|
||||
if (!mTextTracks) {
|
||||
return;
|
||||
}
|
||||
@@ -467,8 +420,7 @@ TextTrackManager::GetTextTracksOfKind(TextTrackKind aTextTrackKind,
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
TextTrackManager::HandleEvent(Event* aEvent)
|
||||
{
|
||||
TextTrackManager::HandleEvent(Event* aEvent) {
|
||||
if (!mTextTracks) {
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -477,7 +429,7 @@ TextTrackManager::HandleEvent(Event* aEvent)
|
||||
aEvent->GetType(type);
|
||||
if (type.EqualsLiteral("resizevideocontrols") ||
|
||||
type.EqualsLiteral("seeked")) {
|
||||
for (uint32_t i = 0; i< mTextTracks->Length(); i++) {
|
||||
for (uint32_t i = 0; i < mTextTracks->Length(); i++) {
|
||||
((*mTextTracks)[i])->SetCuesDirty();
|
||||
}
|
||||
}
|
||||
@@ -489,25 +441,20 @@ TextTrackManager::HandleEvent(Event* aEvent)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
class SimpleTextTrackEvent : public Runnable
|
||||
{
|
||||
public:
|
||||
class SimpleTextTrackEvent : public Runnable {
|
||||
public:
|
||||
friend class CompareSimpleTextTrackEvents;
|
||||
SimpleTextTrackEvent(const nsAString& aEventName,
|
||||
double aTime,
|
||||
TextTrack* aTrack,
|
||||
TextTrackCue* aCue)
|
||||
: Runnable("dom::SimpleTextTrackEvent")
|
||||
, mName(aEventName)
|
||||
, mTime(aTime)
|
||||
, mTrack(aTrack)
|
||||
, mCue(aCue)
|
||||
{}
|
||||
SimpleTextTrackEvent(const nsAString& aEventName, double aTime,
|
||||
TextTrack* aTrack, TextTrackCue* aCue)
|
||||
: Runnable("dom::SimpleTextTrackEvent"),
|
||||
mName(aEventName),
|
||||
mTime(aTime),
|
||||
mTrack(aTrack),
|
||||
mCue(aCue) {}
|
||||
|
||||
NS_IMETHOD Run() override {
|
||||
WEBVTT_LOGV("SimpleTextTrackEvent cue %p mName %s mTime %lf",
|
||||
mCue.get(), NS_ConvertUTF16toUTF8(mName).get(), mTime);
|
||||
WEBVTT_LOGV("SimpleTextTrackEvent cue %p mName %s mTime %lf", mCue.get(),
|
||||
NS_ConvertUTF16toUTF8(mName).get(), mTime);
|
||||
mCue->DispatchTrustedEvent(mName);
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -520,7 +467,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
nsString mName;
|
||||
double mTime;
|
||||
TextTrack* mTrack;
|
||||
@@ -528,9 +475,8 @@ private:
|
||||
};
|
||||
|
||||
class CompareSimpleTextTrackEvents {
|
||||
private:
|
||||
int32_t TrackChildPosition(SimpleTextTrackEvent* aEvent) const
|
||||
{
|
||||
private:
|
||||
int32_t TrackChildPosition(SimpleTextTrackEvent* aEvent) const {
|
||||
if (aEvent->mTrack) {
|
||||
HTMLTrackElement* trackElement = aEvent->mTrack->GetTrackElement();
|
||||
if (trackElement) {
|
||||
@@ -540,19 +486,17 @@ private:
|
||||
return -1;
|
||||
}
|
||||
HTMLMediaElement* mMediaElement;
|
||||
public:
|
||||
explicit CompareSimpleTextTrackEvents(HTMLMediaElement* aMediaElement)
|
||||
{
|
||||
|
||||
public:
|
||||
explicit CompareSimpleTextTrackEvents(HTMLMediaElement* aMediaElement) {
|
||||
mMediaElement = aMediaElement;
|
||||
}
|
||||
|
||||
bool Equals(SimpleTextTrackEvent* aOne, SimpleTextTrackEvent* aTwo) const
|
||||
{
|
||||
bool Equals(SimpleTextTrackEvent* aOne, SimpleTextTrackEvent* aTwo) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LessThan(SimpleTextTrackEvent* aOne, SimpleTextTrackEvent* aTwo) const
|
||||
{
|
||||
bool LessThan(SimpleTextTrackEvent* aOne, SimpleTextTrackEvent* aTwo) const {
|
||||
// TimeMarchesOn step 13.1.
|
||||
if (aOne->mTime < aTwo->mTime) {
|
||||
return true;
|
||||
@@ -567,7 +511,7 @@ public:
|
||||
MOZ_ASSERT(t1, "CompareSimpleTextTrackEvents t1 is null");
|
||||
MOZ_ASSERT(t2, "CompareSimpleTextTrackEvents t2 is null");
|
||||
if (t1 != t2) {
|
||||
TextTrackList* tList= t1->GetTextTrackList();
|
||||
TextTrackList* tList = t1->GetTextTrackList();
|
||||
MOZ_ASSERT(tList, "CompareSimpleTextTrackEvents tList is null");
|
||||
nsTArray<RefPtr<TextTrack>>& textTracks = tList->GetTextTrackArray();
|
||||
auto index1 = textTracks.IndexOf(t1);
|
||||
@@ -615,49 +559,39 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
class TextTrackListInternal
|
||||
{
|
||||
public:
|
||||
class TextTrackListInternal {
|
||||
public:
|
||||
void AddTextTrack(TextTrack* aTextTrack,
|
||||
const CompareTextTracks& aCompareTT)
|
||||
{
|
||||
const CompareTextTracks& aCompareTT) {
|
||||
if (!mTextTracks.Contains(aTextTrack)) {
|
||||
mTextTracks.InsertElementSorted(aTextTrack, aCompareTT);
|
||||
}
|
||||
}
|
||||
uint32_t Length() const
|
||||
{
|
||||
return mTextTracks.Length();
|
||||
}
|
||||
TextTrack* operator[](uint32_t aIndex)
|
||||
{
|
||||
uint32_t Length() const { return mTextTracks.Length(); }
|
||||
TextTrack* operator[](uint32_t aIndex) {
|
||||
return mTextTracks.SafeElementAt(aIndex, nullptr);
|
||||
}
|
||||
private:
|
||||
|
||||
private:
|
||||
nsTArray<RefPtr<TextTrack>> mTextTracks;
|
||||
};
|
||||
|
||||
void
|
||||
TextTrackManager::DispatchUpdateCueDisplay()
|
||||
{
|
||||
void TextTrackManager::DispatchUpdateCueDisplay() {
|
||||
if (!mUpdateCueDisplayDispatched && !IsShutdown() &&
|
||||
mMediaElement->IsCurrentlyPlaying()) {
|
||||
WEBVTT_LOG("DispatchUpdateCueDisplay");
|
||||
nsPIDOMWindowInner* win = mMediaElement->OwnerDoc()->GetInnerWindow();
|
||||
if (win) {
|
||||
nsGlobalWindowInner::Cast(win)->Dispatch(
|
||||
TaskCategory::Other,
|
||||
NewRunnableMethod("dom::TextTrackManager::UpdateCueDisplay",
|
||||
this,
|
||||
&TextTrackManager::UpdateCueDisplay));
|
||||
TaskCategory::Other,
|
||||
NewRunnableMethod("dom::TextTrackManager::UpdateCueDisplay", this,
|
||||
&TextTrackManager::UpdateCueDisplay));
|
||||
mUpdateCueDisplayDispatched = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TextTrackManager::DispatchTimeMarchesOn()
|
||||
{
|
||||
void TextTrackManager::DispatchTimeMarchesOn() {
|
||||
// Run the algorithm if no previous instance is still running, otherwise
|
||||
// enqueue the current playback position and whether only that changed
|
||||
// through its usual monotonic increase during normal playback; current
|
||||
@@ -668,19 +602,16 @@ TextTrackManager::DispatchTimeMarchesOn()
|
||||
nsPIDOMWindowInner* win = mMediaElement->OwnerDoc()->GetInnerWindow();
|
||||
if (win) {
|
||||
nsGlobalWindowInner::Cast(win)->Dispatch(
|
||||
TaskCategory::Other,
|
||||
NewRunnableMethod("dom::TextTrackManager::TimeMarchesOn",
|
||||
this,
|
||||
&TextTrackManager::TimeMarchesOn));
|
||||
TaskCategory::Other,
|
||||
NewRunnableMethod("dom::TextTrackManager::TimeMarchesOn", this,
|
||||
&TextTrackManager::TimeMarchesOn));
|
||||
mTimeMarchesOnDispatched = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/embedded-content.html#time-marches-on
|
||||
void
|
||||
TextTrackManager::TimeMarchesOn()
|
||||
{
|
||||
void TextTrackManager::TimeMarchesOn() {
|
||||
NS_ASSERTION(NS_IsMainThread(), "Wrong thread!");
|
||||
WEBVTT_LOG("TimeMarchesOn");
|
||||
mTimeMarchesOnDispatched = false;
|
||||
@@ -690,8 +621,7 @@ TextTrackManager::TimeMarchesOn()
|
||||
return;
|
||||
}
|
||||
|
||||
nsISupports* parentObject =
|
||||
mMediaElement->OwnerDoc()->GetParentObject();
|
||||
nsISupports* parentObject = mMediaElement->OwnerDoc()->GetParentObject();
|
||||
if (NS_WARN_IF(!parentObject)) {
|
||||
return;
|
||||
}
|
||||
@@ -707,14 +637,14 @@ TextTrackManager::TimeMarchesOn()
|
||||
double currentPlaybackTime = mMediaElement->CurrentTime();
|
||||
bool hasNormalPlayback = !mHasSeeked;
|
||||
mHasSeeked = false;
|
||||
WEBVTT_LOG("TimeMarchesOn mLastTimeMarchesOnCalled %lf currentPlaybackTime %lf hasNormalPlayback %d"
|
||||
, mLastTimeMarchesOnCalled, currentPlaybackTime, hasNormalPlayback);
|
||||
WEBVTT_LOG(
|
||||
"TimeMarchesOn mLastTimeMarchesOnCalled %lf currentPlaybackTime %lf "
|
||||
"hasNormalPlayback %d",
|
||||
mLastTimeMarchesOnCalled, currentPlaybackTime, hasNormalPlayback);
|
||||
|
||||
// Step 1, 2.
|
||||
RefPtr<TextTrackCueList> currentCues =
|
||||
new TextTrackCueList(window);
|
||||
RefPtr<TextTrackCueList> otherCues =
|
||||
new TextTrackCueList(window);
|
||||
RefPtr<TextTrackCueList> currentCues = new TextTrackCueList(window);
|
||||
RefPtr<TextTrackCueList> otherCues = new TextTrackCueList(window);
|
||||
bool dummy;
|
||||
for (uint32_t index = 0; index < mTextTracks->Length(); ++index) {
|
||||
TextTrack* ttrack = mTextTracks->IndexedGetter(index, dummy);
|
||||
@@ -739,7 +669,8 @@ TextTrackManager::TimeMarchesOn()
|
||||
}
|
||||
media::Interval<double> interval(mLastTimeMarchesOnCalled,
|
||||
currentPlaybackTime);
|
||||
otherCues = mNewCues->GetCueListByTimeInterval(interval);;
|
||||
otherCues = mNewCues->GetCueListByTimeInterval(interval);
|
||||
;
|
||||
} else {
|
||||
// Seek case. Put the mLastActiveCues into otherCues.
|
||||
otherCues = mLastActiveCues;
|
||||
@@ -785,7 +716,8 @@ TextTrackManager::TimeMarchesOn()
|
||||
bool c3 = (missedCues->Length() == 0);
|
||||
if (c1 && c2 && c3) {
|
||||
mLastTimeMarchesOnCalled = currentPlaybackTime;
|
||||
WEBVTT_LOG("TimeMarchesOn step 7 return, mLastTimeMarchesOnCalled %lf", mLastTimeMarchesOnCalled);
|
||||
WEBVTT_LOG("TimeMarchesOn step 7 return, mLastTimeMarchesOnCalled %lf",
|
||||
mLastTimeMarchesOnCalled);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -822,13 +754,12 @@ TextTrackManager::TimeMarchesOn()
|
||||
for (uint32_t i = 0; i < missedCues->Length(); ++i) {
|
||||
TextTrackCue* cue = (*missedCues)[i];
|
||||
if (cue) {
|
||||
SimpleTextTrackEvent* event =
|
||||
new SimpleTextTrackEvent(NS_LITERAL_STRING("enter"),
|
||||
cue->StartTime(), cue->GetTrack(),
|
||||
cue);
|
||||
eventList.InsertElementSorted(event,
|
||||
CompareSimpleTextTrackEvents(mMediaElement));
|
||||
affectedTracks.AddTextTrack(cue->GetTrack(), CompareTextTracks(mMediaElement));
|
||||
SimpleTextTrackEvent* event = new SimpleTextTrackEvent(
|
||||
NS_LITERAL_STRING("enter"), cue->StartTime(), cue->GetTrack(), cue);
|
||||
eventList.InsertElementSorted(
|
||||
event, CompareSimpleTextTrackEvents(mMediaElement));
|
||||
affectedTracks.AddTextTrack(cue->GetTrack(),
|
||||
CompareTextTracks(mMediaElement));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -836,14 +767,14 @@ TextTrackManager::TimeMarchesOn()
|
||||
for (uint32_t i = 0; i < otherCues->Length(); ++i) {
|
||||
TextTrackCue* cue = (*otherCues)[i];
|
||||
if (cue->GetActive() || missedCues->IsCueExist(cue)) {
|
||||
double time = cue->StartTime() > cue->EndTime() ? cue->StartTime()
|
||||
: cue->EndTime();
|
||||
SimpleTextTrackEvent* event =
|
||||
new SimpleTextTrackEvent(NS_LITERAL_STRING("exit"), time,
|
||||
cue->GetTrack(), cue);
|
||||
eventList.InsertElementSorted(event,
|
||||
CompareSimpleTextTrackEvents(mMediaElement));
|
||||
affectedTracks.AddTextTrack(cue->GetTrack(), CompareTextTracks(mMediaElement));
|
||||
double time =
|
||||
cue->StartTime() > cue->EndTime() ? cue->StartTime() : cue->EndTime();
|
||||
SimpleTextTrackEvent* event = new SimpleTextTrackEvent(
|
||||
NS_LITERAL_STRING("exit"), time, cue->GetTrack(), cue);
|
||||
eventList.InsertElementSorted(
|
||||
event, CompareSimpleTextTrackEvents(mMediaElement));
|
||||
affectedTracks.AddTextTrack(cue->GetTrack(),
|
||||
CompareTextTracks(mMediaElement));
|
||||
}
|
||||
cue->SetActive(false);
|
||||
}
|
||||
@@ -852,13 +783,12 @@ TextTrackManager::TimeMarchesOn()
|
||||
for (uint32_t i = 0; i < currentCues->Length(); ++i) {
|
||||
TextTrackCue* cue = (*currentCues)[i];
|
||||
if (!cue->GetActive()) {
|
||||
SimpleTextTrackEvent* event =
|
||||
new SimpleTextTrackEvent(NS_LITERAL_STRING("enter"),
|
||||
cue->StartTime(), cue->GetTrack(),
|
||||
cue);
|
||||
eventList.InsertElementSorted(event,
|
||||
CompareSimpleTextTrackEvents(mMediaElement));
|
||||
affectedTracks.AddTextTrack(cue->GetTrack(), CompareTextTracks(mMediaElement));
|
||||
SimpleTextTrackEvent* event = new SimpleTextTrackEvent(
|
||||
NS_LITERAL_STRING("enter"), cue->StartTime(), cue->GetTrack(), cue);
|
||||
eventList.InsertElementSorted(
|
||||
event, CompareSimpleTextTrackEvents(mMediaElement));
|
||||
affectedTracks.AddTextTrack(cue->GetTrack(),
|
||||
CompareTextTracks(mMediaElement));
|
||||
}
|
||||
cue->SetActive(true);
|
||||
}
|
||||
@@ -887,9 +817,7 @@ TextTrackManager::TimeMarchesOn()
|
||||
UpdateCueDisplay();
|
||||
}
|
||||
|
||||
void
|
||||
TextTrackManager::NotifyCueUpdated(TextTrackCue *aCue)
|
||||
{
|
||||
void TextTrackManager::NotifyCueUpdated(TextTrackCue* aCue) {
|
||||
// TODO: Add/Reorder the cue to mNewCues if we have some optimization?
|
||||
WEBVTT_LOG("NotifyCueUpdated");
|
||||
DispatchTimeMarchesOn();
|
||||
@@ -899,16 +827,12 @@ TextTrackManager::NotifyCueUpdated(TextTrackCue *aCue)
|
||||
DispatchUpdateCueDisplay();
|
||||
}
|
||||
|
||||
void
|
||||
TextTrackManager::NotifyReset()
|
||||
{
|
||||
void TextTrackManager::NotifyReset() {
|
||||
WEBVTT_LOG("NotifyReset");
|
||||
mLastTimeMarchesOnCalled = 0.0;
|
||||
}
|
||||
|
||||
void
|
||||
TextTrackManager::ReportTelemetryForTrack(TextTrack* aTextTrack) const
|
||||
{
|
||||
void TextTrackManager::ReportTelemetryForTrack(TextTrack* aTextTrack) const {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(aTextTrack);
|
||||
MOZ_ASSERT(mTextTracks->Length() > 0);
|
||||
@@ -917,9 +841,7 @@ TextTrackManager::ReportTelemetryForTrack(TextTrack* aTextTrack) const
|
||||
Telemetry::Accumulate(Telemetry::WEBVTT_TRACK_KINDS, uint32_t(kind));
|
||||
}
|
||||
|
||||
void
|
||||
TextTrackManager::ReportTelemetryForCue()
|
||||
{
|
||||
void TextTrackManager::ReportTelemetryForCue() {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(!mNewCues->IsEmpty() || !mLastActiveCues->IsEmpty());
|
||||
|
||||
@@ -929,17 +851,13 @@ TextTrackManager::ReportTelemetryForCue()
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
TextTrackManager::IsLoaded()
|
||||
{
|
||||
bool TextTrackManager::IsLoaded() {
|
||||
return mTextTracks ? mTextTracks->AreTextTracksLoaded() : true;
|
||||
}
|
||||
|
||||
bool
|
||||
TextTrackManager::IsShutdown() const
|
||||
{
|
||||
bool TextTrackManager::IsShutdown() const {
|
||||
return (mShutdown || !sParserWrapper);
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
Reference in New Issue
Block a user