2013-05-21 20:14:00 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 et tw=78: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2016-03-02 21:34:02 +03:00
|
|
|
#include "mozilla/AsyncEventDispatcher.h"
|
2013-05-21 20:14:00 +04:00
|
|
|
#include "mozilla/dom/TextTrack.h"
|
|
|
|
#include "mozilla/dom/TextTrackBinding.h"
|
2014-01-27 22:10:06 +04:00
|
|
|
#include "mozilla/dom/TextTrackList.h"
|
2013-06-15 00:10:36 +04:00
|
|
|
#include "mozilla/dom/TextTrackCue.h"
|
2013-09-06 00:25:17 +04:00
|
|
|
#include "mozilla/dom/TextTrackCueList.h"
|
2013-09-14 03:44:33 +04:00
|
|
|
#include "mozilla/dom/TextTrackRegion.h"
|
2013-06-15 00:10:36 +04:00
|
|
|
#include "mozilla/dom/HTMLMediaElement.h"
|
2013-10-25 08:14:36 +04:00
|
|
|
#include "mozilla/dom/HTMLTrackElement.h"
|
2017-03-15 06:58:50 +03:00
|
|
|
#include "nsGlobalWindow.h"
|
2013-05-21 20:14:00 +04:00
|
|
|
|
2019-03-15 02:25:10 +03:00
|
|
|
extern mozilla::LazyLogModule gTextTrackLog;
|
|
|
|
|
2019-03-26 10:50:50 +03:00
|
|
|
#define WEBVTT_LOG(msg, ...) \
|
|
|
|
MOZ_LOG(gTextTrackLog, LogLevel::Debug, \
|
|
|
|
("TextTrack=%p, " msg, this, ##__VA_ARGS__))
|
2019-03-15 02:25:10 +03:00
|
|
|
|
2013-05-21 20:14:00 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2019-03-15 02:25:10 +03:00
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
2014-04-25 20:49:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(TextTrack, DOMEventTargetHelper, mCueList,
|
|
|
|
mActiveCueList, mTextTrackList,
|
|
|
|
mTrackElement)
|
2013-05-21 20:14:00 +04:00
|
|
|
|
2014-04-01 10:13:50 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(TextTrack, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(TextTrack, DOMEventTargetHelper)
|
2017-08-30 02:02:48 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TextTrack)
|
2014-04-01 10:13:50 +04:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
2013-05-21 20:14:00 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
TextTrack::TextTrack(nsPIDOMWindowInner* aOwnerWindow, TextTrackKind aKind,
|
2014-02-27 21:47:23 +04:00
|
|
|
const nsAString& aLabel, const nsAString& aLanguage,
|
2014-03-13 22:41:21 +04:00
|
|
|
TextTrackMode aMode, TextTrackReadyState aReadyState,
|
2014-02-27 21:47:23 +04:00
|
|
|
TextTrackSource aTextTrackSource)
|
2014-04-07 21:58:38 +04:00
|
|
|
: DOMEventTargetHelper(aOwnerWindow),
|
2014-03-13 22:58:08 +04:00
|
|
|
mKind(aKind),
|
|
|
|
mLabel(aLabel),
|
|
|
|
mLanguage(aLanguage),
|
|
|
|
mMode(aMode),
|
|
|
|
mReadyState(aReadyState),
|
2014-02-27 21:47:23 +04:00
|
|
|
mTextTrackSource(aTextTrackSource) {
|
2013-06-15 00:10:36 +04:00
|
|
|
SetDefaultSettings();
|
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
TextTrack::TextTrack(nsPIDOMWindowInner* aOwnerWindow,
|
2014-01-28 00:17:20 +04:00
|
|
|
TextTrackList* aTextTrackList, TextTrackKind aKind,
|
2014-02-27 21:47:23 +04:00
|
|
|
const nsAString& aLabel, const nsAString& aLanguage,
|
2014-03-13 22:41:21 +04:00
|
|
|
TextTrackMode aMode, TextTrackReadyState aReadyState,
|
2014-02-27 21:47:23 +04:00
|
|
|
TextTrackSource aTextTrackSource)
|
2014-04-07 21:58:38 +04:00
|
|
|
: DOMEventTargetHelper(aOwnerWindow),
|
2014-01-28 00:17:20 +04:00
|
|
|
mTextTrackList(aTextTrackList),
|
2014-03-13 22:58:08 +04:00
|
|
|
mKind(aKind),
|
|
|
|
mLabel(aLabel),
|
|
|
|
mLanguage(aLanguage),
|
|
|
|
mMode(aMode),
|
|
|
|
mReadyState(aReadyState),
|
2014-02-27 21:47:23 +04:00
|
|
|
mTextTrackSource(aTextTrackSource) {
|
2013-06-15 00:10:36 +04:00
|
|
|
SetDefaultSettings();
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
2014-06-15 06:53:52 +04:00
|
|
|
TextTrack::~TextTrack() {}
|
|
|
|
|
2013-06-15 00:10:36 +04:00
|
|
|
void TextTrack::SetDefaultSettings() {
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner* ownerWindow = GetOwner();
|
2014-04-07 21:58:38 +04:00
|
|
|
mCueList = new TextTrackCueList(ownerWindow);
|
|
|
|
mActiveCueList = new TextTrackCueList(ownerWindow);
|
2013-06-15 00:10:36 +04:00
|
|
|
mCuePos = 0;
|
|
|
|
mDirty = false;
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
JSObject* TextTrack::WrapObject(JSContext* aCx,
|
|
|
|
JS::Handle<JSObject*> aGivenProto) {
|
2018-06-26 00:20:54 +03:00
|
|
|
return TextTrack_Binding::Wrap(aCx, this, aGivenProto);
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextTrack::SetMode(TextTrackMode aValue) {
|
2019-03-12 03:32:21 +03:00
|
|
|
if (mMode == aValue) {
|
|
|
|
return;
|
|
|
|
}
|
2019-03-15 02:25:10 +03:00
|
|
|
WEBVTT_LOG("Set mode=%s", ToStateStr(aValue));
|
2019-03-12 03:32:21 +03:00
|
|
|
mMode = aValue;
|
|
|
|
|
|
|
|
HTMLMediaElement* mediaElement = GetMediaElement();
|
|
|
|
if (aValue == TextTrackMode::Disabled) {
|
|
|
|
for (size_t i = 0; i < mCueList->Length() && mediaElement; ++i) {
|
|
|
|
mediaElement->NotifyCueRemoved(*(*mCueList)[i]);
|
2016-06-01 08:35:53 +03:00
|
|
|
}
|
2019-03-12 03:32:21 +03:00
|
|
|
SetCuesInactive();
|
|
|
|
} else {
|
|
|
|
for (size_t i = 0; i < mCueList->Length() && mediaElement; ++i) {
|
|
|
|
mediaElement->NotifyCueAdded(*(*mCueList)[i]);
|
2013-12-18 09:19:09 +04:00
|
|
|
}
|
|
|
|
}
|
2019-03-12 03:32:21 +03:00
|
|
|
if (mediaElement) {
|
|
|
|
mediaElement->NotifyTextTrackModeChanged();
|
|
|
|
}
|
|
|
|
// Ensure the TimeMarchesOn is called in case that the mCueList
|
|
|
|
// is empty.
|
|
|
|
NotifyCueUpdated(nullptr);
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
2014-03-19 19:27:39 +04:00
|
|
|
void TextTrack::GetId(nsAString& aId) const {
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-21 20:14:00 +04:00
|
|
|
void TextTrack::AddCue(TextTrackCue& aCue) {
|
2019-03-15 02:25:10 +03:00
|
|
|
WEBVTT_LOG("AddCue %p", &aCue);
|
2016-11-24 10:30:52 +03:00
|
|
|
TextTrack* oldTextTrack = aCue.GetTrack();
|
|
|
|
if (oldTextTrack) {
|
|
|
|
ErrorResult dummy;
|
|
|
|
oldTextTrack->RemoveCue(aCue, dummy);
|
|
|
|
}
|
2013-05-21 20:14:00 +04:00
|
|
|
mCueList->AddCue(aCue);
|
2014-04-02 20:16:00 +04:00
|
|
|
aCue.SetTrack(this);
|
2019-03-08 21:22:24 +03:00
|
|
|
HTMLMediaElement* mediaElement = GetMediaElement();
|
|
|
|
if (mediaElement && (mMode != TextTrackMode::Disabled)) {
|
|
|
|
mediaElement->NotifyCueAdded(aCue);
|
2014-01-15 20:30:58 +04:00
|
|
|
}
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
2013-06-28 21:31:43 +04:00
|
|
|
void TextTrack::RemoveCue(TextTrackCue& aCue, ErrorResult& aRv) {
|
2019-03-15 02:25:10 +03:00
|
|
|
WEBVTT_LOG("RemoveCue %p", &aCue);
|
2016-09-29 12:47:35 +03:00
|
|
|
// Bug1304948, check the aCue belongs to the TextTrack.
|
2013-06-28 21:31:43 +04:00
|
|
|
mCueList->RemoveCue(aCue, aRv);
|
2016-09-29 12:47:35 +03:00
|
|
|
if (aRv.Failed()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
aCue.SetActive(false);
|
2016-06-27 05:41:20 +03:00
|
|
|
aCue.SetTrack(nullptr);
|
2019-03-08 21:22:24 +03:00
|
|
|
HTMLMediaElement* mediaElement = GetMediaElement();
|
|
|
|
if (mediaElement) {
|
|
|
|
mediaElement->NotifyCueRemoved(aCue);
|
2016-06-01 08:35:58 +03:00
|
|
|
}
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
2014-04-07 23:42:33 +04:00
|
|
|
void TextTrack::SetCuesDirty() {
|
|
|
|
for (uint32_t i = 0; i < mCueList->Length(); i++) {
|
|
|
|
((*mCueList)[i])->Reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-12 19:57:21 +04:00
|
|
|
TextTrackCueList* TextTrack::GetActiveCues() {
|
2014-02-07 22:59:26 +04:00
|
|
|
if (mMode != TextTrackMode::Disabled) {
|
|
|
|
return mActiveCueList;
|
|
|
|
}
|
|
|
|
return nullptr;
|
2013-06-15 00:10:36 +04:00
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
void TextTrack::GetActiveCueArray(nsTArray<RefPtr<TextTrackCue> >& aCues) {
|
2014-02-07 22:59:26 +04:00
|
|
|
if (mMode != TextTrackMode::Disabled) {
|
|
|
|
mActiveCueList->GetArray(aCues);
|
|
|
|
}
|
2013-12-12 19:57:21 +04:00
|
|
|
}
|
|
|
|
|
2013-10-25 08:14:36 +04:00
|
|
|
TextTrackReadyState TextTrack::ReadyState() const { return mReadyState; }
|
|
|
|
|
2014-03-14 20:13:41 +04:00
|
|
|
void TextTrack::SetReadyState(uint32_t aReadyState) {
|
|
|
|
if (aReadyState <= TextTrackReadyState::FailedToLoad) {
|
|
|
|
SetReadyState(static_cast<TextTrackReadyState>(aReadyState));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-13 22:29:32 +04:00
|
|
|
void TextTrack::SetReadyState(TextTrackReadyState aState) {
|
2019-03-15 02:25:10 +03:00
|
|
|
WEBVTT_LOG("SetReadyState=%s", ToReadyStateStr(aState));
|
2013-10-25 08:14:36 +04:00
|
|
|
mReadyState = aState;
|
2019-03-08 21:22:24 +03:00
|
|
|
HTMLMediaElement* mediaElement = GetMediaElement();
|
2014-03-13 22:29:32 +04:00
|
|
|
if (mediaElement && (mReadyState == TextTrackReadyState::Loaded ||
|
|
|
|
mReadyState == TextTrackReadyState::FailedToLoad)) {
|
2014-01-28 00:17:20 +04:00
|
|
|
mediaElement->RemoveTextTrack(this, true);
|
2017-02-21 10:44:10 +03:00
|
|
|
mediaElement->UpdateReadyState();
|
2013-10-25 08:14:36 +04:00
|
|
|
}
|
2013-10-25 08:14:36 +04:00
|
|
|
}
|
|
|
|
|
2014-01-27 22:10:06 +04:00
|
|
|
TextTrackList* TextTrack::GetTextTrackList() { return mTextTrackList; }
|
|
|
|
|
|
|
|
void TextTrack::SetTextTrackList(TextTrackList* aTextTrackList) {
|
|
|
|
mTextTrackList = aTextTrackList;
|
|
|
|
}
|
|
|
|
|
2014-02-27 23:07:39 +04:00
|
|
|
HTMLTrackElement* TextTrack::GetTrackElement() { return mTrackElement; }
|
|
|
|
|
|
|
|
void TextTrack::SetTrackElement(HTMLTrackElement* aTrackElement) {
|
|
|
|
mTrackElement = aTrackElement;
|
|
|
|
}
|
|
|
|
|
2016-06-01 08:35:53 +03:00
|
|
|
void TextTrack::SetCuesInactive() { mCueList->SetCuesInactive(); }
|
|
|
|
|
2016-06-08 11:53:30 +03:00
|
|
|
void TextTrack::NotifyCueUpdated(TextTrackCue* aCue) {
|
2019-03-15 02:25:10 +03:00
|
|
|
WEBVTT_LOG("NotifyCueUpdated, cue=%p", aCue);
|
2016-06-08 11:53:30 +03:00
|
|
|
mCueList->NotifyCueUpdated(aCue);
|
2019-03-08 21:22:24 +03:00
|
|
|
HTMLMediaElement* mediaElement = GetMediaElement();
|
|
|
|
if (mediaElement) {
|
|
|
|
mediaElement->NotifyCueUpdated(aCue);
|
2016-06-08 11:53:30 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-30 08:36:31 +03:00
|
|
|
void TextTrack::GetLabel(nsAString& aLabel) const {
|
|
|
|
if (mTrackElement) {
|
|
|
|
mTrackElement->GetLabel(aLabel);
|
|
|
|
} else {
|
|
|
|
aLabel = mLabel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void TextTrack::GetLanguage(nsAString& aLanguage) const {
|
|
|
|
if (mTrackElement) {
|
|
|
|
mTrackElement->GetSrclang(aLanguage);
|
|
|
|
} else {
|
|
|
|
aLanguage = mLanguage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-12 12:41:41 +03:00
|
|
|
void TextTrack::DispatchAsyncTrustedEvent(const nsString& aEventName) {
|
2017-03-15 06:58:50 +03:00
|
|
|
nsPIDOMWindowInner* win = GetOwner();
|
|
|
|
if (!win) {
|
|
|
|
return;
|
|
|
|
}
|
2016-07-12 12:41:41 +03:00
|
|
|
RefPtr<TextTrack> self = this;
|
2017-11-04 01:25:38 +03:00
|
|
|
nsGlobalWindowInner::Cast(win)->Dispatch(
|
2017-06-12 22:34:10 +03:00
|
|
|
TaskCategory::Other,
|
|
|
|
NS_NewRunnableFunction(
|
|
|
|
"dom::TextTrack::DispatchAsyncTrustedEvent",
|
|
|
|
[self, aEventName]() { self->DispatchTrustedEvent(aEventName); }));
|
2016-07-12 12:41:41 +03:00
|
|
|
}
|
|
|
|
|
2017-02-20 10:27:06 +03:00
|
|
|
bool TextTrack::IsLoaded() {
|
|
|
|
if (mMode == TextTrackMode::Disabled) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
// If the TrackElement's src is null, we can not block the
|
|
|
|
// MediaElement.
|
|
|
|
if (mTrackElement) {
|
|
|
|
nsAutoString src;
|
|
|
|
if (!(mTrackElement->GetAttr(kNameSpaceID_None, nsGkAtoms::src, src))) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (mReadyState >= Loaded);
|
|
|
|
}
|
|
|
|
|
2019-03-08 06:10:45 +03:00
|
|
|
void TextTrack::NotifyCueActiveStateChanged(TextTrackCue* aCue) {
|
|
|
|
MOZ_ASSERT(aCue);
|
|
|
|
if (aCue->GetActive()) {
|
|
|
|
MOZ_ASSERT(!mActiveCueList->IsCueExist(aCue));
|
2019-03-26 10:50:50 +03:00
|
|
|
WEBVTT_LOG("NotifyCueActiveStateChanged, add cue %p to the active list",
|
|
|
|
aCue);
|
2019-03-08 06:10:45 +03:00
|
|
|
mActiveCueList->AddCue(*aCue);
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(mActiveCueList->IsCueExist(aCue));
|
2019-03-26 10:50:50 +03:00
|
|
|
WEBVTT_LOG(
|
|
|
|
"NotifyCueActiveStateChanged, remove cue %p from the active list",
|
|
|
|
aCue);
|
2019-03-08 06:10:45 +03:00
|
|
|
mActiveCueList->RemoveCue(*aCue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-26 10:50:50 +03:00
|
|
|
void TextTrack::GetCurrentCuesAndOtherCues(
|
|
|
|
RefPtr<TextTrackCueList>& aCurrentCues,
|
|
|
|
RefPtr<TextTrackCueList>& aOtherCues,
|
|
|
|
const media::TimeInterval& aInterval) const {
|
2019-03-08 21:22:24 +03:00
|
|
|
const HTMLMediaElement* mediaElement = GetMediaElement();
|
2019-03-07 22:21:22 +03:00
|
|
|
if (!mediaElement) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-26 10:50:50 +03:00
|
|
|
if (Mode() == TextTrackMode::Disabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-07 22:21:22 +03:00
|
|
|
// According to `time marches on` step1, current cue list contains the cues
|
|
|
|
// 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
|
2019-03-26 10:50:50 +03:00
|
|
|
MOZ_ASSERT(aCurrentCues && aOtherCues);
|
2019-03-07 22:21:22 +03:00
|
|
|
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) {
|
2019-03-26 10:50:50 +03:00
|
|
|
WEBVTT_LOG("Add cue %p [%f:%f] to current cue list", cue,
|
|
|
|
cue->StartTime(), cue->EndTime());
|
|
|
|
aCurrentCues->AddCue(*cue);
|
|
|
|
} else {
|
2019-03-27 07:02:35 +03:00
|
|
|
// Negative length cue, which is possible because user can set cue's end
|
|
|
|
// time arbitrary.
|
|
|
|
if (cue->EndTime() < cue->StartTime()) {
|
|
|
|
WEBVTT_LOG("[BAD TIME] skip cue %p [%f:%f] with negative length", cue,
|
|
|
|
cue->StartTime(), cue->EndTime());
|
|
|
|
continue;
|
|
|
|
}
|
2019-03-26 10:50:50 +03:00
|
|
|
media::TimeInterval cueInterval(
|
|
|
|
media::TimeUnit::FromSeconds(cue->StartTime()),
|
|
|
|
media::TimeUnit::FromSeconds(cue->EndTime()));
|
|
|
|
// cues are completely outside the time interval.
|
|
|
|
if (!aInterval.Touches(cueInterval)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
// contains any cues which are overlapping within the time interval.
|
|
|
|
WEBVTT_LOG("Add cue %p [%f:%f] to other cue list", cue, cue->StartTime(),
|
|
|
|
cue->EndTime());
|
|
|
|
aOtherCues->AddCue(*cue);
|
2019-03-07 22:21:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-08 21:22:24 +03:00
|
|
|
HTMLMediaElement* TextTrack::GetMediaElement() const {
|
|
|
|
return mTextTrackList ? mTextTrackList->GetMediaElement() : nullptr;
|
|
|
|
}
|
|
|
|
|
2013-05-21 20:14:00 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|