content/media/webrtc/MediaTrackConstraints.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial