зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1392498 - Move TimeIntervals to dom::TimeRanges conversion into TimeRanges class. r=jya
If TimeUnits.h includes mozilla/dom/TimeRanges.h, then the build ends up pulling in the Gecko DOM bindings, which pulls in a whole lot of JavaScript and DOM bindings code. That makes it trickier to import GeckoMedia into Servo, and makes Gecko's build slower, so move the code to convert TimeIntervals into dom::TimeRanges. Also remove an extraneous "virtual" and add "const" to some functions in TimeRanges. MozReview-Commit-ID: BLeehaf9gCE --HG-- extra : rebase_source : 84ef054cf8fd5b4434dc761a1b0a39803d3231f5
This commit is contained in:
Родитель
18bae8b2e9
Коммит
4ffa31745b
|
@ -2657,7 +2657,7 @@ HTMLMediaElement::SetCurrentTime(double aCurrentTime, ErrorResult& aRv)
|
|||
* on success, and NS_ERROR_FAILURE on failure.
|
||||
*/
|
||||
static nsresult
|
||||
IsInRanges(dom::TimeRanges& aRanges,
|
||||
IsInRanges(TimeRanges& aRanges,
|
||||
double aValue,
|
||||
bool& aIsInRanges,
|
||||
int32_t& aIntervalIndex)
|
||||
|
@ -2740,13 +2740,13 @@ HTMLMediaElement::Seek(double aTime,
|
|||
}
|
||||
|
||||
// Clamp the seek target to inside the seekable ranges.
|
||||
RefPtr<dom::TimeRanges> seekable = new dom::TimeRanges(ToSupports(OwnerDoc()));
|
||||
media::TimeIntervals seekableIntervals = mDecoder->GetSeekable();
|
||||
if (seekableIntervals.IsInvalid()) {
|
||||
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); // This will reject the promise.
|
||||
return promise.forget();
|
||||
}
|
||||
seekableIntervals.ToTimeRanges(seekable);
|
||||
RefPtr<TimeRanges> seekable =
|
||||
new TimeRanges(ToSupports(OwnerDoc()), seekableIntervals);
|
||||
uint32_t length = 0;
|
||||
seekable->GetLength(&length);
|
||||
if (!length) {
|
||||
|
@ -2865,10 +2865,9 @@ NS_IMETHODIMP HTMLMediaElement::GetDuration(double* aDuration)
|
|||
already_AddRefed<TimeRanges>
|
||||
HTMLMediaElement::Seekable() const
|
||||
{
|
||||
RefPtr<TimeRanges> ranges = new TimeRanges(ToSupports(OwnerDoc()));
|
||||
if (mDecoder) {
|
||||
mDecoder->GetSeekable().ToTimeRanges(ranges);
|
||||
}
|
||||
media::TimeIntervals seekable =
|
||||
mDecoder ? mDecoder->GetSeekable() : media::TimeIntervals();
|
||||
RefPtr<TimeRanges> ranges = new TimeRanges(ToSupports(OwnerDoc()), seekable);
|
||||
return ranges.forget();
|
||||
}
|
||||
|
||||
|
@ -6549,13 +6548,9 @@ HTMLMediaElement::CopyInnerTo(Element* aDest, bool aPreallocateChildren)
|
|||
already_AddRefed<TimeRanges>
|
||||
HTMLMediaElement::Buffered() const
|
||||
{
|
||||
RefPtr<TimeRanges> ranges = new TimeRanges(ToSupports(OwnerDoc()));
|
||||
if (mDecoder) {
|
||||
media::TimeIntervals buffered = mDecoder->GetBuffered();
|
||||
if (!buffered.IsInvalid()) {
|
||||
buffered.ToTimeRanges(ranges);
|
||||
}
|
||||
}
|
||||
media::TimeIntervals buffered =
|
||||
mDecoder ? mDecoder->GetBuffered() : media::TimeIntervals();
|
||||
RefPtr<TimeRanges> ranges = new TimeRanges(ToSupports(OwnerDoc()), buffered);
|
||||
return ranges.forget();
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include "mozilla/dom/WakeLock.h"
|
||||
#include "mozilla/dom/power/PowerManagerService.h"
|
||||
#include "mozilla/dom/Performance.h"
|
||||
#include "mozilla/dom/TimeRanges.h"
|
||||
#include "mozilla/dom/VideoPlaybackQuality.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "mozilla/dom/TimeRanges.h"
|
||||
#include "mozilla/dom/TimeRangesBinding.h"
|
||||
#include "mozilla/dom/HTMLMediaElement.h"
|
||||
#include "TimeUnits.h"
|
||||
#include "nsError.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
@ -31,6 +32,35 @@ TimeRanges::TimeRanges(nsISupports* aParent)
|
|||
{
|
||||
}
|
||||
|
||||
TimeRanges::TimeRanges(nsISupports* aParent,
|
||||
const media::TimeIntervals& aTimeIntervals)
|
||||
: TimeRanges(aParent)
|
||||
{
|
||||
if (aTimeIntervals.IsInvalid()) {
|
||||
return;
|
||||
}
|
||||
for (const media::TimeInterval& interval : aTimeIntervals) {
|
||||
Add(interval.mStart.ToSeconds(), interval.mEnd.ToSeconds());
|
||||
}
|
||||
}
|
||||
|
||||
TimeRanges::TimeRanges(const media::TimeIntervals& aTimeIntervals)
|
||||
: TimeRanges(nullptr, aTimeIntervals)
|
||||
{
|
||||
}
|
||||
|
||||
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)));
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
TimeRanges::~TimeRanges()
|
||||
{
|
||||
}
|
||||
|
@ -43,7 +73,7 @@ TimeRanges::GetLength(uint32_t* aLength)
|
|||
}
|
||||
|
||||
double
|
||||
TimeRanges::Start(uint32_t aIndex, ErrorResult& aRv)
|
||||
TimeRanges::Start(uint32_t aIndex, ErrorResult& aRv) const
|
||||
{
|
||||
if (aIndex >= mRanges.Length()) {
|
||||
aRv = NS_ERROR_DOM_INDEX_SIZE_ERR;
|
||||
|
@ -62,7 +92,7 @@ TimeRanges::Start(uint32_t aIndex, double* aTime)
|
|||
}
|
||||
|
||||
double
|
||||
TimeRanges::End(uint32_t aIndex, ErrorResult& aRv)
|
||||
TimeRanges::End(uint32_t aIndex, ErrorResult& aRv) const
|
||||
{
|
||||
if (aIndex >= mRanges.Length()) {
|
||||
aRv = NS_ERROR_DOM_INDEX_SIZE_ERR;
|
||||
|
|
|
@ -13,12 +13,12 @@
|
|||
#include "nsTArray.h"
|
||||
#include "nsWrapperCache.h"
|
||||
#include "mozilla/ErrorResult.h"
|
||||
#include "TimeUnits.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
namespace dom {
|
||||
|
||||
class TimeRanges;
|
||||
|
||||
} // namespace dom
|
||||
|
||||
namespace dom {
|
||||
|
@ -35,6 +35,10 @@ public:
|
|||
|
||||
TimeRanges();
|
||||
explicit TimeRanges(nsISupports* aParent);
|
||||
explicit TimeRanges(const media::TimeIntervals& aTimeIntervals);
|
||||
TimeRanges(nsISupports* aParent, const media::TimeIntervals& aTimeIntervals);
|
||||
|
||||
media::TimeIntervals ToTimeIntervals() const;
|
||||
|
||||
void Add(double aStart, double aEnd);
|
||||
|
||||
|
@ -53,7 +57,8 @@ public:
|
|||
// Mutate this TimeRange to be the intersection of this and aOtherRanges.
|
||||
void Intersection(const TimeRanges* aOtherRanges);
|
||||
|
||||
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
||||
JSObject* WrapObject(JSContext* aCx,
|
||||
JS::Handle<JSObject*> aGivenProto) override;
|
||||
|
||||
nsISupports* GetParentObject() const;
|
||||
|
||||
|
@ -62,9 +67,9 @@ public:
|
|||
return mRanges.Length();
|
||||
}
|
||||
|
||||
virtual double Start(uint32_t aIndex, ErrorResult& aRv);
|
||||
double Start(uint32_t aIndex, ErrorResult& aRv) const;
|
||||
|
||||
virtual double End(uint32_t aIndex, ErrorResult& aRv);
|
||||
double End(uint32_t aIndex, ErrorResult& aRv) const;
|
||||
|
||||
// Shift all values by aOffset seconds.
|
||||
void Shift(double aOffset);
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
#include "mozilla/CheckedInt.h"
|
||||
#include "mozilla/FloatingPoint.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/dom/TimeRanges.h"
|
||||
#include "mozilla/TimeStamp.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
@ -19,7 +18,7 @@ namespace media {
|
|||
class TimeIntervals;
|
||||
} // namespace media
|
||||
} // namespace mozilla
|
||||
// CopyChooser specalization for nsTArray
|
||||
// CopyChooser specialization for nsTArray
|
||||
template<>
|
||||
struct nsTArray_CopyChooser<mozilla::media::TimeIntervals>
|
||||
{
|
||||
|
@ -241,34 +240,6 @@ public:
|
|||
}
|
||||
|
||||
TimeIntervals() = default;
|
||||
|
||||
// Make TimeIntervals interchangeable with dom::TimeRanges.
|
||||
explicit TimeIntervals(dom::TimeRanges* aRanges)
|
||||
{
|
||||
for (uint32_t i = 0; i < aRanges->Length(); i++) {
|
||||
ErrorResult rv;
|
||||
*this +=
|
||||
TimeInterval(TimeUnit::FromSeconds(aRanges->Start(i, rv)),
|
||||
TimeUnit::FromSeconds(aRanges->End(i, rv)));
|
||||
}
|
||||
}
|
||||
TimeIntervals& operator = (dom::TimeRanges* aRanges)
|
||||
{
|
||||
*this = TimeIntervals(aRanges);
|
||||
return *this;
|
||||
}
|
||||
|
||||
static TimeIntervals FromTimeRanges(dom::TimeRanges* aRanges)
|
||||
{
|
||||
return TimeIntervals(aRanges);
|
||||
}
|
||||
|
||||
void ToTimeRanges(dom::TimeRanges* aRanges) const
|
||||
{
|
||||
for (IndexType i = 0; i < Length(); i++) {
|
||||
aRanges->Add(Start(i).ToSeconds(), End(i).ToSeconds());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace media
|
||||
|
|
|
@ -536,8 +536,7 @@ TEST(IntervalSet, TimeRangesSeconds)
|
|||
i1.Add(media::TimeInterval(media::TimeUnit::FromSeconds(45), media::TimeUnit::FromSeconds(50)));
|
||||
|
||||
media::TimeIntervals i(i0 + i1);
|
||||
RefPtr<dom::TimeRanges> tr = new dom::TimeRanges();
|
||||
i.ToTimeRanges(tr);
|
||||
RefPtr<dom::TimeRanges> tr = new dom::TimeRanges(i);
|
||||
EXPECT_EQ(tr->Length(), i.Length());
|
||||
for (dom::TimeRanges::index_type index = 0; index < tr->Length(); index++) {
|
||||
ErrorResult rv;
|
||||
|
@ -572,22 +571,13 @@ TEST(IntervalSet, TimeRangesConversion)
|
|||
tr->Add(53, 57);
|
||||
tr->Add(45, 50);
|
||||
|
||||
// explicit copy constructor
|
||||
media::TimeIntervals i1(tr);
|
||||
// explicit copy constructor and ToTimeIntervals.
|
||||
media::TimeIntervals i1(tr->ToTimeIntervals());
|
||||
CheckTimeRanges(tr, i1);
|
||||
|
||||
// static FromTimeRanges
|
||||
media::TimeIntervals i2 = media::TimeIntervals::FromTimeRanges(tr);
|
||||
CheckTimeRanges(tr, i2);
|
||||
|
||||
media::TimeIntervals i3;
|
||||
// operator=(TimeRanges*)
|
||||
i3 = tr;
|
||||
CheckTimeRanges(tr, i3);
|
||||
|
||||
// operator= test
|
||||
i1 = tr.get();
|
||||
CheckTimeRanges(tr, i1);
|
||||
// ctor(const TimeIntervals&)
|
||||
RefPtr<dom::TimeRanges> tr2 = new dom::TimeRanges(tr->ToTimeIntervals());
|
||||
CheckTimeRanges(tr2, i1);
|
||||
}
|
||||
|
||||
TEST(IntervalSet, TimeRangesMicroseconds)
|
||||
|
@ -605,8 +595,7 @@ TEST(IntervalSet, TimeRangesMicroseconds)
|
|||
i1.Add(media::TimeInterval(media::TimeUnit::FromMicroseconds(45), media::TimeUnit::FromMicroseconds(50)));
|
||||
|
||||
media::TimeIntervals i(i0 + i1);
|
||||
RefPtr<dom::TimeRanges> tr = new dom::TimeRanges();
|
||||
i.ToTimeRanges(tr);
|
||||
RefPtr<dom::TimeRanges> tr = new dom::TimeRanges(i);
|
||||
EXPECT_EQ(tr->Length(), i.Length());
|
||||
for (dom::TimeRanges::index_type index = 0; index < tr->Length(); index++) {
|
||||
ErrorResult rv;
|
||||
|
@ -630,9 +619,8 @@ TEST(IntervalSet, TimeRangesMicroseconds)
|
|||
tr = new dom::TimeRanges();
|
||||
tr->Add(0, 30);
|
||||
tr->Add(50, std::numeric_limits<double>::infinity());
|
||||
media::TimeIntervals i_oo{media::TimeIntervals::FromTimeRanges(tr)};
|
||||
RefPtr<dom::TimeRanges> tr2 = new dom::TimeRanges();
|
||||
i_oo.ToTimeRanges(tr2);
|
||||
media::TimeIntervals i_oo = tr->ToTimeIntervals();
|
||||
RefPtr<dom::TimeRanges> tr2 = new dom::TimeRanges(i_oo);
|
||||
EXPECT_EQ(tr->Length(), tr2->Length());
|
||||
for (dom::TimeRanges::index_type index = 0; index < tr->Length(); index++) {
|
||||
ErrorResult rv;
|
||||
|
|
|
@ -114,14 +114,13 @@ SourceBuffer::GetBuffered(ErrorResult& aRv)
|
|||
media::TimeIntervals intersection = mTrackBuffersManager->Buffered();
|
||||
MSE_DEBUGV("intersection=%s", DumpTimeRanges(intersection).get());
|
||||
if (mBuffered) {
|
||||
media::TimeIntervals currentValue(mBuffered);
|
||||
media::TimeIntervals currentValue(mBuffered->ToTimeIntervals());
|
||||
rangeChanged = (intersection != currentValue);
|
||||
MSE_DEBUGV("currentValue=%s", DumpTimeRanges(currentValue).get());
|
||||
}
|
||||
// 5. If intersection ranges does not contain the exact same range information as the current value of this attribute, then update the current value of this attribute to intersection ranges.
|
||||
if (rangeChanged) {
|
||||
mBuffered = new TimeRanges(ToSupports(this));
|
||||
intersection.ToTimeRanges(mBuffered);
|
||||
mBuffered = new TimeRanges(ToSupports(this), intersection);
|
||||
}
|
||||
// 6. Return the current value of this attribute.
|
||||
return mBuffered;
|
||||
|
|
Загрузка…
Ссылка в новой задаче