content/media/webrtc/MediaTrackConstraints.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/webrtc/MediaTrackConstraints.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,93 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     1.6 + * You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +// This file should not be included by other includes, as it contains code
     1.9 +
    1.10 +#ifndef MEDIATRACKCONSTRAINTS_H_
    1.11 +#define MEDIATRACKCONSTRAINTS_H_
    1.12 +
    1.13 +#include "mozilla/dom/MediaStreamTrackBinding.h"
    1.14 +
    1.15 +namespace mozilla {
    1.16 +
    1.17 +// Normalized internal version of MediaTrackConstraints to simplify downstream
    1.18 +// processing. This implementation-only helper is included as needed by both
    1.19 +// MediaManager (for gUM camera selection) and MediaEngine (for applyConstraints).
    1.20 +
    1.21 +template<typename T>
    1.22 +class MediaTrackConstraintsN : public dom::MediaTrackConstraints
    1.23 +{
    1.24 +public:
    1.25 +  typedef T Kind;
    1.26 +  dom::Sequence<Kind> mRequireN;
    1.27 +  bool mUnsupportedRequirement;
    1.28 +  MediaTrackConstraintSet mRequired;
    1.29 +  dom::Sequence<MediaTrackConstraintSet> mNonrequired;
    1.30 +
    1.31 +  MediaTrackConstraintsN(const dom::MediaTrackConstraints &aOther,
    1.32 +                         const dom::EnumEntry* aStrings)
    1.33 +  : dom::MediaTrackConstraints(aOther)
    1.34 +  , mUnsupportedRequirement(false)
    1.35 +  , mStrings(aStrings)
    1.36 +  {
    1.37 +    if (mRequire.WasPassed()) {
    1.38 +      auto& array = mRequire.Value();
    1.39 +      for (uint32_t i = 0; i < array.Length(); i++) {
    1.40 +        auto value = ToEnum(array[i]);
    1.41 +        if (value != Kind::Other) {
    1.42 +          mRequireN.AppendElement(value);
    1.43 +        } else {
    1.44 +          mUnsupportedRequirement = true;
    1.45 +        }
    1.46 +      }
    1.47 +    }
    1.48 +  }
    1.49 +protected:
    1.50 +  MediaTrackConstraintSet& Triage(const Kind kind) {
    1.51 +    if (mRequireN.IndexOf(kind) != mRequireN.NoIndex) {
    1.52 +      return mRequired;
    1.53 +    } else {
    1.54 +      mNonrequired.AppendElement(MediaTrackConstraintSet());
    1.55 +      return mNonrequired[mNonrequired.Length()-1];
    1.56 +    }
    1.57 +  }
    1.58 +private:
    1.59 +  Kind ToEnum(const nsAString& aSrc) {
    1.60 +    for (size_t i = 0; mStrings[i].value; i++) {
    1.61 +      if (aSrc.EqualsASCII(mStrings[i].value)) {
    1.62 +        return Kind(i);
    1.63 +      }
    1.64 +    }
    1.65 +    return Kind::Other;
    1.66 +  }
    1.67 +  const dom::EnumEntry* mStrings;
    1.68 +};
    1.69 +
    1.70 +struct AudioTrackConstraintsN :
    1.71 +  public MediaTrackConstraintsN<dom::SupportedAudioConstraints>
    1.72 +{
    1.73 +  AudioTrackConstraintsN(const dom::MediaTrackConstraints &aOther)
    1.74 +  : MediaTrackConstraintsN<dom::SupportedAudioConstraints>(aOther, // B2G ICS compiler bug
    1.75 +                           dom::SupportedAudioConstraintsValues::strings) {}
    1.76 +};
    1.77 +
    1.78 +struct VideoTrackConstraintsN :
    1.79 +    public MediaTrackConstraintsN<dom::SupportedVideoConstraints>
    1.80 +{
    1.81 +  VideoTrackConstraintsN(const dom::MediaTrackConstraints &aOther)
    1.82 +  : MediaTrackConstraintsN<dom::SupportedVideoConstraints>(aOther,
    1.83 +                           dom::SupportedVideoConstraintsValues::strings) {
    1.84 +    if (mFacingMode.WasPassed()) {
    1.85 +      Triage(Kind::FacingMode).mFacingMode.Construct(mFacingMode.Value());
    1.86 +    }
    1.87 +    // Reminder: add handling for new constraints both here & SatisfyConstraintSet
    1.88 +    Triage(Kind::Width).mWidth = mWidth;
    1.89 +    Triage(Kind::Height).mHeight = mHeight;
    1.90 +    Triage(Kind::FrameRate).mFrameRate = mFrameRate;
    1.91 +  }
    1.92 +};
    1.93 +
    1.94 +}
    1.95 +
    1.96 +#endif /* MEDIATRACKCONSTRAINTS_H_ */

mercurial