Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
michael@0 | 3 | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 4 | |
michael@0 | 5 | // This file should not be included by other includes, as it contains code |
michael@0 | 6 | |
michael@0 | 7 | #ifndef MEDIATRACKCONSTRAINTS_H_ |
michael@0 | 8 | #define MEDIATRACKCONSTRAINTS_H_ |
michael@0 | 9 | |
michael@0 | 10 | #include "mozilla/dom/MediaStreamTrackBinding.h" |
michael@0 | 11 | |
michael@0 | 12 | namespace mozilla { |
michael@0 | 13 | |
michael@0 | 14 | // Normalized internal version of MediaTrackConstraints to simplify downstream |
michael@0 | 15 | // processing. This implementation-only helper is included as needed by both |
michael@0 | 16 | // MediaManager (for gUM camera selection) and MediaEngine (for applyConstraints). |
michael@0 | 17 | |
michael@0 | 18 | template<typename T> |
michael@0 | 19 | class MediaTrackConstraintsN : public dom::MediaTrackConstraints |
michael@0 | 20 | { |
michael@0 | 21 | public: |
michael@0 | 22 | typedef T Kind; |
michael@0 | 23 | dom::Sequence<Kind> mRequireN; |
michael@0 | 24 | bool mUnsupportedRequirement; |
michael@0 | 25 | MediaTrackConstraintSet mRequired; |
michael@0 | 26 | dom::Sequence<MediaTrackConstraintSet> mNonrequired; |
michael@0 | 27 | |
michael@0 | 28 | MediaTrackConstraintsN(const dom::MediaTrackConstraints &aOther, |
michael@0 | 29 | const dom::EnumEntry* aStrings) |
michael@0 | 30 | : dom::MediaTrackConstraints(aOther) |
michael@0 | 31 | , mUnsupportedRequirement(false) |
michael@0 | 32 | , mStrings(aStrings) |
michael@0 | 33 | { |
michael@0 | 34 | if (mRequire.WasPassed()) { |
michael@0 | 35 | auto& array = mRequire.Value(); |
michael@0 | 36 | for (uint32_t i = 0; i < array.Length(); i++) { |
michael@0 | 37 | auto value = ToEnum(array[i]); |
michael@0 | 38 | if (value != Kind::Other) { |
michael@0 | 39 | mRequireN.AppendElement(value); |
michael@0 | 40 | } else { |
michael@0 | 41 | mUnsupportedRequirement = true; |
michael@0 | 42 | } |
michael@0 | 43 | } |
michael@0 | 44 | } |
michael@0 | 45 | } |
michael@0 | 46 | protected: |
michael@0 | 47 | MediaTrackConstraintSet& Triage(const Kind kind) { |
michael@0 | 48 | if (mRequireN.IndexOf(kind) != mRequireN.NoIndex) { |
michael@0 | 49 | return mRequired; |
michael@0 | 50 | } else { |
michael@0 | 51 | mNonrequired.AppendElement(MediaTrackConstraintSet()); |
michael@0 | 52 | return mNonrequired[mNonrequired.Length()-1]; |
michael@0 | 53 | } |
michael@0 | 54 | } |
michael@0 | 55 | private: |
michael@0 | 56 | Kind ToEnum(const nsAString& aSrc) { |
michael@0 | 57 | for (size_t i = 0; mStrings[i].value; i++) { |
michael@0 | 58 | if (aSrc.EqualsASCII(mStrings[i].value)) { |
michael@0 | 59 | return Kind(i); |
michael@0 | 60 | } |
michael@0 | 61 | } |
michael@0 | 62 | return Kind::Other; |
michael@0 | 63 | } |
michael@0 | 64 | const dom::EnumEntry* mStrings; |
michael@0 | 65 | }; |
michael@0 | 66 | |
michael@0 | 67 | struct AudioTrackConstraintsN : |
michael@0 | 68 | public MediaTrackConstraintsN<dom::SupportedAudioConstraints> |
michael@0 | 69 | { |
michael@0 | 70 | AudioTrackConstraintsN(const dom::MediaTrackConstraints &aOther) |
michael@0 | 71 | : MediaTrackConstraintsN<dom::SupportedAudioConstraints>(aOther, // B2G ICS compiler bug |
michael@0 | 72 | dom::SupportedAudioConstraintsValues::strings) {} |
michael@0 | 73 | }; |
michael@0 | 74 | |
michael@0 | 75 | struct VideoTrackConstraintsN : |
michael@0 | 76 | public MediaTrackConstraintsN<dom::SupportedVideoConstraints> |
michael@0 | 77 | { |
michael@0 | 78 | VideoTrackConstraintsN(const dom::MediaTrackConstraints &aOther) |
michael@0 | 79 | : MediaTrackConstraintsN<dom::SupportedVideoConstraints>(aOther, |
michael@0 | 80 | dom::SupportedVideoConstraintsValues::strings) { |
michael@0 | 81 | if (mFacingMode.WasPassed()) { |
michael@0 | 82 | Triage(Kind::FacingMode).mFacingMode.Construct(mFacingMode.Value()); |
michael@0 | 83 | } |
michael@0 | 84 | // Reminder: add handling for new constraints both here & SatisfyConstraintSet |
michael@0 | 85 | Triage(Kind::Width).mWidth = mWidth; |
michael@0 | 86 | Triage(Kind::Height).mHeight = mHeight; |
michael@0 | 87 | Triage(Kind::FrameRate).mFrameRate = mFrameRate; |
michael@0 | 88 | } |
michael@0 | 89 | }; |
michael@0 | 90 | |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | #endif /* MEDIATRACKCONSTRAINTS_H_ */ |