Bug 1438956 - Add inline Start/End TimeRanges methods for C++ users. r?bz
MozReview-Commit-ID: DcLsYyKV7WX
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -2702,22 +2702,22 @@ HTMLMediaElement::SetCurrentTime(double
static bool
IsInRanges(TimeRanges& aRanges,
double aValue,
int32_t& aIntervalIndex)
{
uint32_t length = aRanges.Length();
for (uint32_t i = 0; i < length; i++) {
- double start = aRanges.Start(i, IgnoreErrors());
+ double start = aRanges.Start(i);
if (start > aValue) {
aIntervalIndex = i - 1;
return false;
}
- double end = aRanges.End(i, IgnoreErrors());
+ double end = aRanges.End(i);
if (aValue <= end) {
aIntervalIndex = i;
return true;
}
}
aIntervalIndex = length - 1;
return false;
}
@@ -2796,35 +2796,35 @@ HTMLMediaElement::Seek(double aTime,
// http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#seeking
int32_t range = 0;
bool isInRange = IsInRanges(*seekable, aTime, range);
if (!isInRange) {
if (range != -1) {
// |range + 1| can't be negative, because the only possible negative value
// for |range| is -1.
if (uint32_t(range + 1) < length) {
- double leftBound = seekable->End(range, IgnoreErrors());
- double rightBound = seekable->Start(range + 1, IgnoreErrors());
+ double leftBound = seekable->End(range);
+ double rightBound = seekable->Start(range + 1);
double distanceLeft = Abs(leftBound - aTime);
double distanceRight = Abs(rightBound - aTime);
if (distanceLeft == distanceRight) {
double currentTime = CurrentTime();
distanceLeft = Abs(leftBound - currentTime);
distanceRight = Abs(rightBound - currentTime);
}
aTime = (distanceLeft < distanceRight) ? leftBound : rightBound;
} else {
// Seek target is after the end last range in seekable data.
// Clamp the seek target to the end of the last seekable range.
- aTime = seekable->GetEndTime();
+ aTime = seekable->End(length - 1);
}
} else {
// aTime is before the first range in |seekable|, the closest point we can
// seek to is the start of the first range.
- aTime = seekable->GetStartTime();
+ aTime = seekable->Start(0);
}
}
// TODO: The spec requires us to update the current time to reflect the
// actual seek target before beginning the synchronous section, but
// that requires changing all MediaDecoderReaders to support telling
// us the fastSeek target, and it's currently not possible to get
// this information as we don't yet control the demuxer for all
@@ -2878,18 +2878,18 @@ HTMLMediaElement::Played()
{
RefPtr<TimeRanges> ranges = new TimeRanges(ToSupports(OwnerDoc()));
uint32_t timeRangeCount = 0;
if (mPlayed) {
timeRangeCount = mPlayed->Length();
}
for (uint32_t i = 0; i < timeRangeCount; i++) {
- double begin = mPlayed->Start(i, IgnoreErrors());
- double end = mPlayed->End(i, IgnoreErrors());
+ double begin = mPlayed->Start(i);
+ double end = mPlayed->End(i);
ranges->Add(begin, end);
}
if (mCurrentPlayRangeStart != -1.0) {
double now = CurrentTime();
if (mCurrentPlayRangeStart != now) {
ranges->Add(mCurrentPlayRangeStart, now);
}
@@ -4483,19 +4483,18 @@ HTMLMediaElement::ReportTelemetry()
// buffering if the last frame status was buffering and the ready state is
// HAVE_CURRENT_DATA to account for times where we are in a buffering state
// regardless of what actual data we have buffered.
bool stalled = false;
RefPtr<TimeRanges> ranges = Buffered();
const double errorMargin = 0.05;
double t = CurrentTime();
TimeRanges::index_type index = ranges->Find(t, errorMargin);
- ErrorResult ignore;
stalled = index != TimeRanges::NoIndex &&
- (ranges->End(index, ignore) - t) < errorMargin;
+ (ranges->End(index) - t) < errorMargin;
stalled |= mDecoder && NextFrameStatus() == MediaDecoderOwner::NEXT_FRAME_UNAVAILABLE_BUFFERING &&
mReadyState == HAVE_CURRENT_DATA;
if (stalled) {
state = STALLED;
}
}
Telemetry::Accumulate(Telemetry::VIDEO_UNLOAD_STATE, state);
--- a/dom/html/HTMLVideoElement.cpp
+++ b/dom/html/HTMLVideoElement.cpp
@@ -350,18 +350,18 @@ double
HTMLVideoElement::TotalPlayTime() const
{
double total = 0.0;
if (mPlayed) {
uint32_t timeRangeCount = mPlayed->Length();
for (uint32_t i = 0; i < timeRangeCount; i++) {
- double begin = mPlayed->Start(i, IgnoreErrors());
- double end = mPlayed->End(i, IgnoreErrors());
+ double begin = mPlayed->Start(i);
+ double end = mPlayed->End(i);
total += end - begin;
}
if (mCurrentPlayRangeStart != -1.0) {
double now = CurrentTime();
if (mCurrentPlayRangeStart != now) {
total += now - mCurrentPlayRangeStart;
}
--- a/dom/html/TimeRanges.cpp
+++ b/dom/html/TimeRanges.cpp
@@ -48,47 +48,46 @@ TimeRanges::TimeRanges(const media::Time
{
}
media::TimeIntervals
TimeRanges::ToTimeIntervals() const
{
media::TimeIntervals t;
for (uint32_t i = 0; i < Length(); i++) {
- ErrorResult rv;
- t += media::TimeInterval(media::TimeUnit::FromSeconds(Start(i, rv)),
- media::TimeUnit::FromSeconds(End(i, rv)));
+ t += media::TimeInterval(media::TimeUnit::FromSeconds(Start(i)),
+ media::TimeUnit::FromSeconds(End(i)));
}
return t;
}
TimeRanges::~TimeRanges()
{
}
double
TimeRanges::Start(uint32_t aIndex, ErrorResult& aRv) const
{
if (aIndex >= mRanges.Length()) {
aRv = NS_ERROR_DOM_INDEX_SIZE_ERR;
return 0;
}
- return mRanges[aIndex].mStart;
+ return Start(aIndex);
}
double
TimeRanges::End(uint32_t aIndex, ErrorResult& aRv) const
{
if (aIndex >= mRanges.Length()) {
aRv = NS_ERROR_DOM_INDEX_SIZE_ERR;
return 0;
}
- return mRanges[aIndex].mEnd;
+ return End(aIndex);
}
void
TimeRanges::Add(double aStart, double aEnd)
{
if (aStart > aEnd) {
NS_WARNING("Can't add a range if the end is older that the start.");
return;
--- a/dom/html/TimeRanges.h
+++ b/dom/html/TimeRanges.h
@@ -64,16 +64,26 @@ public:
{
return mRanges.Length();
}
double Start(uint32_t aIndex, ErrorResult& aRv) const;
double End(uint32_t aIndex, ErrorResult& aRv) const;
+ double Start(uint32_t aIndex) const
+ {
+ return mRanges[aIndex].mStart;
+ }
+
+ double End(uint32_t aIndex) const
+ {
+ return mRanges[aIndex].mEnd;
+ }
+
// Shift all values by aOffset seconds.
void Shift(double aOffset);
private:
~TimeRanges();
// Comparator which orders TimeRanges by start time. Used by Normalize().
struct TimeRange