diff -r 000000000000 -r 6474c204b198 content/media/webrtc/MediaTrackConstraints.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/content/media/webrtc/MediaTrackConstraints.h Wed Dec 31 06:09:35 2014 +0100 @@ -0,0 +1,93 @@ +/* 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_ + +#include "mozilla/dom/MediaStreamTrackBinding.h" + +namespace mozilla { + +// Normalized internal version of MediaTrackConstraints to simplify downstream +// processing. This implementation-only helper is included as needed by both +// MediaManager (for gUM camera selection) and MediaEngine (for applyConstraints). + +template +class MediaTrackConstraintsN : public dom::MediaTrackConstraints +{ +public: + typedef T Kind; + dom::Sequence mRequireN; + bool mUnsupportedRequirement; + MediaTrackConstraintSet mRequired; + dom::Sequence mNonrequired; + + MediaTrackConstraintsN(const dom::MediaTrackConstraints &aOther, + const dom::EnumEntry* aStrings) + : dom::MediaTrackConstraints(aOther) + , mUnsupportedRequirement(false) + , mStrings(aStrings) + { + if (mRequire.WasPassed()) { + auto& array = mRequire.Value(); + for (uint32_t i = 0; i < array.Length(); i++) { + auto value = ToEnum(array[i]); + if (value != Kind::Other) { + mRequireN.AppendElement(value); + } else { + mUnsupportedRequirement = true; + } + } + } + } +protected: + MediaTrackConstraintSet& Triage(const Kind kind) { + if (mRequireN.IndexOf(kind) != mRequireN.NoIndex) { + return mRequired; + } else { + mNonrequired.AppendElement(MediaTrackConstraintSet()); + return mNonrequired[mNonrequired.Length()-1]; + } + } +private: + Kind ToEnum(const nsAString& aSrc) { + for (size_t i = 0; mStrings[i].value; i++) { + if (aSrc.EqualsASCII(mStrings[i].value)) { + return Kind(i); + } + } + return Kind::Other; + } + const dom::EnumEntry* mStrings; +}; + +struct AudioTrackConstraintsN : + public MediaTrackConstraintsN +{ + AudioTrackConstraintsN(const dom::MediaTrackConstraints &aOther) + : MediaTrackConstraintsN(aOther, // B2G ICS compiler bug + dom::SupportedAudioConstraintsValues::strings) {} +}; + +struct VideoTrackConstraintsN : + public MediaTrackConstraintsN +{ + VideoTrackConstraintsN(const dom::MediaTrackConstraints &aOther) + : MediaTrackConstraintsN(aOther, + dom::SupportedVideoConstraintsValues::strings) { + if (mFacingMode.WasPassed()) { + Triage(Kind::FacingMode).mFacingMode.Construct(mFacingMode.Value()); + } + // Reminder: add handling for new constraints both here & SatisfyConstraintSet + Triage(Kind::Width).mWidth = mWidth; + Triage(Kind::Height).mHeight = mHeight; + Triage(Kind::FrameRate).mFrameRate = mFrameRate; + } +}; + +} + +#endif /* MEDIATRACKCONSTRAINTS_H_ */