michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // This file should not be included by other includes, as it contains code michael@0: michael@0: #ifndef MEDIATRACKCONSTRAINTS_H_ michael@0: #define MEDIATRACKCONSTRAINTS_H_ michael@0: michael@0: #include "mozilla/dom/MediaStreamTrackBinding.h" michael@0: michael@0: namespace mozilla { michael@0: michael@0: // Normalized internal version of MediaTrackConstraints to simplify downstream michael@0: // processing. This implementation-only helper is included as needed by both michael@0: // MediaManager (for gUM camera selection) and MediaEngine (for applyConstraints). michael@0: michael@0: template michael@0: class MediaTrackConstraintsN : public dom::MediaTrackConstraints michael@0: { michael@0: public: michael@0: typedef T Kind; michael@0: dom::Sequence mRequireN; michael@0: bool mUnsupportedRequirement; michael@0: MediaTrackConstraintSet mRequired; michael@0: dom::Sequence mNonrequired; michael@0: michael@0: MediaTrackConstraintsN(const dom::MediaTrackConstraints &aOther, michael@0: const dom::EnumEntry* aStrings) michael@0: : dom::MediaTrackConstraints(aOther) michael@0: , mUnsupportedRequirement(false) michael@0: , mStrings(aStrings) michael@0: { michael@0: if (mRequire.WasPassed()) { michael@0: auto& array = mRequire.Value(); michael@0: for (uint32_t i = 0; i < array.Length(); i++) { michael@0: auto value = ToEnum(array[i]); michael@0: if (value != Kind::Other) { michael@0: mRequireN.AppendElement(value); michael@0: } else { michael@0: mUnsupportedRequirement = true; michael@0: } michael@0: } michael@0: } michael@0: } michael@0: protected: michael@0: MediaTrackConstraintSet& Triage(const Kind kind) { michael@0: if (mRequireN.IndexOf(kind) != mRequireN.NoIndex) { michael@0: return mRequired; michael@0: } else { michael@0: mNonrequired.AppendElement(MediaTrackConstraintSet()); michael@0: return mNonrequired[mNonrequired.Length()-1]; michael@0: } michael@0: } michael@0: private: michael@0: Kind ToEnum(const nsAString& aSrc) { michael@0: for (size_t i = 0; mStrings[i].value; i++) { michael@0: if (aSrc.EqualsASCII(mStrings[i].value)) { michael@0: return Kind(i); michael@0: } michael@0: } michael@0: return Kind::Other; michael@0: } michael@0: const dom::EnumEntry* mStrings; michael@0: }; michael@0: michael@0: struct AudioTrackConstraintsN : michael@0: public MediaTrackConstraintsN michael@0: { michael@0: AudioTrackConstraintsN(const dom::MediaTrackConstraints &aOther) michael@0: : MediaTrackConstraintsN(aOther, // B2G ICS compiler bug michael@0: dom::SupportedAudioConstraintsValues::strings) {} michael@0: }; michael@0: michael@0: struct VideoTrackConstraintsN : michael@0: public MediaTrackConstraintsN michael@0: { michael@0: VideoTrackConstraintsN(const dom::MediaTrackConstraints &aOther) michael@0: : MediaTrackConstraintsN(aOther, michael@0: dom::SupportedVideoConstraintsValues::strings) { michael@0: if (mFacingMode.WasPassed()) { michael@0: Triage(Kind::FacingMode).mFacingMode.Construct(mFacingMode.Value()); michael@0: } michael@0: // Reminder: add handling for new constraints both here & SatisfyConstraintSet michael@0: Triage(Kind::Width).mWidth = mWidth; michael@0: Triage(Kind::Height).mHeight = mHeight; michael@0: Triage(Kind::FrameRate).mFrameRate = mFrameRate; michael@0: } michael@0: }; michael@0: michael@0: } michael@0: michael@0: #endif /* MEDIATRACKCONSTRAINTS_H_ */