2014-04-18 23:16:08 +04:00
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
// This file should not be included by other includes, as it contains code
|
|
|
|
|
|
|
|
#ifndef MEDIATRACKCONSTRAINTS_H_
|
|
|
|
#define MEDIATRACKCONSTRAINTS_H_
|
|
|
|
|
2014-09-01 07:50:23 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2014-04-18 23:16:08 +04:00
|
|
|
#include "mozilla/dom/MediaStreamTrackBinding.h"
|
2015-02-21 01:06:26 +03:00
|
|
|
#include "mozilla/dom/MediaTrackConstraintSetBinding.h"
|
2015-07-02 21:21:49 +03:00
|
|
|
#include "mozilla/dom/MediaTrackSupportedConstraintsBinding.h"
|
2014-04-18 23:16:08 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2015-01-21 19:10:19 +03:00
|
|
|
template<class EnumValuesStrings, class Enum>
|
|
|
|
static const char* EnumToASCII(const EnumValuesStrings& aStrings, Enum aValue) {
|
|
|
|
return aStrings[uint32_t(aValue)].value;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<class EnumValuesStrings, class Enum>
|
2015-02-21 01:06:26 +03:00
|
|
|
static Enum StringToEnum(const EnumValuesStrings& aStrings,
|
|
|
|
const nsAString& aValue, Enum aDefaultValue) {
|
2015-01-21 19:10:19 +03:00
|
|
|
for (size_t i = 0; aStrings[i].value; i++) {
|
|
|
|
if (aValue.EqualsASCII(aStrings[i].value)) {
|
|
|
|
return Enum(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return aDefaultValue;
|
|
|
|
}
|
|
|
|
|
2015-02-21 01:06:26 +03:00
|
|
|
// Helper classes for orthogonal constraints without interdependencies.
|
|
|
|
// Instead of constraining values, constrain the constraints themselves.
|
2014-04-18 23:16:08 +04:00
|
|
|
|
2015-02-21 01:06:26 +03:00
|
|
|
struct NormalizedConstraintSet
|
2014-04-18 23:16:08 +04:00
|
|
|
{
|
2015-02-21 01:06:26 +03:00
|
|
|
template<class ValueType>
|
|
|
|
struct Range
|
2014-04-18 23:16:08 +04:00
|
|
|
{
|
2015-02-21 01:06:26 +03:00
|
|
|
ValueType mMin, mMax;
|
|
|
|
dom::Optional<ValueType> mIdeal;
|
|
|
|
|
|
|
|
Range(ValueType aMin, ValueType aMax) : mMin(aMin), mMax(aMax) {}
|
|
|
|
|
|
|
|
template<class ConstrainRange>
|
|
|
|
void SetFrom(const ConstrainRange& aOther);
|
|
|
|
ValueType Clamp(ValueType n) const { return std::max(mMin, std::min(n, mMax)); }
|
|
|
|
bool Intersects(const Range& aOther) const {
|
|
|
|
return mMax >= aOther.mMin && mMin <= aOther.mMax;
|
2014-07-08 10:01:27 +04:00
|
|
|
}
|
2015-02-21 01:06:26 +03:00
|
|
|
void Intersect(const Range& aOther) {
|
|
|
|
MOZ_ASSERT(Intersects(aOther));
|
|
|
|
mMin = std::max(mMin, aOther.mMin);
|
|
|
|
mMax = std::min(mMax, aOther.mMax);
|
2014-04-18 23:16:08 +04:00
|
|
|
}
|
2015-02-21 01:06:26 +03:00
|
|
|
};
|
2014-04-18 23:16:08 +04:00
|
|
|
|
2015-02-21 01:06:26 +03:00
|
|
|
struct LongRange : public Range<int32_t>
|
|
|
|
{
|
|
|
|
LongRange(const dom::OwningLongOrConstrainLongRange& aOther, bool advanced);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct DoubleRange : public Range<double>
|
|
|
|
{
|
|
|
|
DoubleRange(const dom::OwningDoubleOrConstrainDoubleRange& aOther,
|
|
|
|
bool advanced);
|
|
|
|
};
|
|
|
|
|
|
|
|
// Do you need to add your constraint here? Only if your code uses flattening
|
|
|
|
LongRange mWidth, mHeight;
|
|
|
|
DoubleRange mFrameRate;
|
|
|
|
|
|
|
|
NormalizedConstraintSet(const dom::MediaTrackConstraintSet& aOther,
|
|
|
|
bool advanced)
|
|
|
|
: mWidth(aOther.mWidth, advanced)
|
|
|
|
, mHeight(aOther.mHeight, advanced)
|
|
|
|
, mFrameRate(aOther.mFrameRate, advanced) {}
|
2014-04-18 23:16:08 +04:00
|
|
|
};
|
|
|
|
|
2015-02-21 01:06:26 +03:00
|
|
|
struct FlattenedConstraints : public NormalizedConstraintSet
|
2014-04-18 23:16:08 +04:00
|
|
|
{
|
2015-02-21 02:54:04 +03:00
|
|
|
explicit FlattenedConstraints(const dom::MediaTrackConstraints& aOther);
|
2014-04-18 23:16:08 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* MEDIATRACKCONSTRAINTS_H_ */
|