1 /*
2  *  Copyright 2013 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 // Implementation of the w3c constraints spec is the responsibility of the
12 // browser. Chrome no longer uses the constraints api declared here, and it will
13 // be removed from WebRTC.
14 // https://bugs.chromium.org/p/webrtc/issues/detail?id=9239
15 
16 #ifndef SDK_MEDIA_CONSTRAINTS_H_
17 #define SDK_MEDIA_CONSTRAINTS_H_
18 
19 #include <stddef.h>
20 #include <string>
21 #include <utility>
22 #include <vector>
23 
24 #include "api/audio_options.h"
25 #include "api/peer_connection_interface.h"
26 
27 namespace webrtc {
28 
29 // Class representing constraints, as used by the android and objc apis.
30 //
31 // Constraints may be either "mandatory", which means that unless satisfied,
32 // the method taking the constraints should fail, or "optional", which means
33 // they may not be satisfied..
34 class MediaConstraints {
35  public:
36   struct Constraint {
ConstraintConstraint37     Constraint() {}
ConstraintConstraint38     Constraint(const std::string& key, const std::string value)
39         : key(key), value(value) {}
40     std::string key;
41     std::string value;
42   };
43 
44   class Constraints : public std::vector<Constraint> {
45    public:
46     Constraints() = default;
Constraints(std::initializer_list<Constraint> l)47     Constraints(std::initializer_list<Constraint> l)
48         : std::vector<Constraint>(l) {}
49 
50     bool FindFirst(const std::string& key, std::string* value) const;
51   };
52 
53   MediaConstraints() = default;
MediaConstraints(Constraints mandatory,Constraints optional)54   MediaConstraints(Constraints mandatory, Constraints optional)
55       : mandatory_(std::move(mandatory)), optional_(std::move(optional)) {}
56 
57   // Constraint keys used by a local audio source.
58 
59   // These keys are google specific.
60   static const char kGoogEchoCancellation[];  // googEchoCancellation
61 
62   static const char kAutoGainControl[];               // googAutoGainControl
63   static const char kExperimentalAutoGainControl[];   // googAutoGainControl2
64   static const char kNoiseSuppression[];              // googNoiseSuppression
65   static const char kExperimentalNoiseSuppression[];  // googNoiseSuppression2
66   static const char kHighpassFilter[];                // googHighpassFilter
67   static const char kTypingNoiseDetection[];  // googTypingNoiseDetection
68   static const char kAudioMirroring[];        // googAudioMirroring
69   static const char
70       kAudioNetworkAdaptorConfig[];  // goodAudioNetworkAdaptorConfig
71 
72   // Constraint keys for CreateOffer / CreateAnswer
73   // Specified by the W3C PeerConnection spec
74   static const char kOfferToReceiveVideo[];     // OfferToReceiveVideo
75   static const char kOfferToReceiveAudio[];     // OfferToReceiveAudio
76   static const char kVoiceActivityDetection[];  // VoiceActivityDetection
77   static const char kIceRestart[];              // IceRestart
78   // These keys are google specific.
79   static const char kUseRtpMux[];  // googUseRtpMUX
80 
81   // Constraints values.
82   static const char kValueTrue[];   // true
83   static const char kValueFalse[];  // false
84 
85   // PeerConnection constraint keys.
86   // Temporary pseudo-constraints used to enable DTLS-SRTP
87   static const char kEnableDtlsSrtp[];  // Enable DTLS-SRTP
88   // Temporary pseudo-constraints used to enable DataChannels
89   static const char kEnableRtpDataChannels[];  // Enable RTP DataChannels
90   // Google-specific constraint keys.
91   // Temporary pseudo-constraint for enabling DSCP through JS.
92   static const char kEnableDscp[];  // googDscp
93   // Constraint to enable IPv6 through JS.
94   static const char kEnableIPv6[];  // googIPv6
95   // Temporary constraint to enable suspend below min bitrate feature.
96   static const char kEnableVideoSuspendBelowMinBitrate[];
97   // googSuspendBelowMinBitrate
98   // Constraint to enable combined audio+video bandwidth estimation.
99   static const char kCombinedAudioVideoBwe[];  // googCombinedAudioVideoBwe
100   static const char kScreencastMinBitrate[];   // googScreencastMinBitrate
101   static const char kCpuOveruseDetection[];    // googCpuOveruseDetection
102 
103   // Constraint to enable negotiating raw RTP packetization using attribute
104   // "a=packetization:<payload_type> raw" in the SDP for all video payload.
105   static const char kRawPacketizationForVideoEnabled[];
106 
107   // Specifies number of simulcast layers for all video tracks
108   // with a Plan B offer/answer
109   // (see RTCOfferAnswerOptions::num_simulcast_layers).
110   static const char kNumSimulcastLayers[];
111 
112   ~MediaConstraints() = default;
113 
GetMandatory()114   const Constraints& GetMandatory() const { return mandatory_; }
GetOptional()115   const Constraints& GetOptional() const { return optional_; }
116 
117  private:
118   const Constraints mandatory_ = {};
119   const Constraints optional_ = {};
120 };
121 
122 // Copy all relevant constraints into an RTCConfiguration object.
123 void CopyConstraintsIntoRtcConfiguration(
124     const MediaConstraints* constraints,
125     PeerConnectionInterface::RTCConfiguration* configuration);
126 
127 // Copy all relevant constraints into an AudioOptions object.
128 void CopyConstraintsIntoAudioOptions(const MediaConstraints* constraints,
129                                      cricket::AudioOptions* options);
130 
131 bool CopyConstraintsIntoOfferAnswerOptions(
132     const MediaConstraints* constraints,
133     PeerConnectionInterface::RTCOfferAnswerOptions* offer_answer_options);
134 
135 }  // namespace webrtc
136 
137 #endif  // SDK_MEDIA_CONSTRAINTS_H_
138