OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2013 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/api/mediaconstraintsinterface.h" | 11 #include "webrtc/api/mediaconstraintsinterface.h" |
12 | 12 |
| 13 #include "webrtc/api/peerconnectioninterface.h" |
13 #include "webrtc/base/stringencode.h" | 14 #include "webrtc/base/stringencode.h" |
14 | 15 |
15 namespace webrtc { | 16 namespace webrtc { |
16 | 17 |
17 const char MediaConstraintsInterface::kValueTrue[] = "true"; | 18 const char MediaConstraintsInterface::kValueTrue[] = "true"; |
18 const char MediaConstraintsInterface::kValueFalse[] = "false"; | 19 const char MediaConstraintsInterface::kValueFalse[] = "false"; |
19 | 20 |
20 // Constraints declared as static members in mediastreaminterface.h | 21 // Constraints declared as static members in mediastreaminterface.h |
21 // Specified by draft-alvestrand-constraints-resolution-00b | 22 // Specified by draft-alvestrand-constraints-resolution-00b |
22 const char MediaConstraintsInterface::kMinAspectRatio[] = "minAspectRatio"; | 23 const char MediaConstraintsInterface::kMinAspectRatio[] = "minAspectRatio"; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 // first instance has an unrecognized value are not handled precisely in | 112 // first instance has an unrecognized value are not handled precisely in |
112 // accordance with the specification. | 113 // accordance with the specification. |
113 bool FindConstraint(const MediaConstraintsInterface* constraints, | 114 bool FindConstraint(const MediaConstraintsInterface* constraints, |
114 const std::string& key, bool* value, | 115 const std::string& key, bool* value, |
115 size_t* mandatory_constraints) { | 116 size_t* mandatory_constraints) { |
116 std::string string_value; | 117 std::string string_value; |
117 if (!constraints) { | 118 if (!constraints) { |
118 return false; | 119 return false; |
119 } | 120 } |
120 if (constraints->GetMandatory().FindFirst(key, &string_value)) { | 121 if (constraints->GetMandatory().FindFirst(key, &string_value)) { |
121 if (mandatory_constraints) | 122 if (mandatory_constraints) { |
122 ++*mandatory_constraints; | 123 ++*mandatory_constraints; |
| 124 } |
123 return rtc::FromString(string_value, value); | 125 return rtc::FromString(string_value, value); |
124 } | 126 } |
125 if (constraints->GetOptional().FindFirst(key, &string_value)) { | 127 if (constraints->GetOptional().FindFirst(key, &string_value)) { |
| 128 return rtc::FromString(string_value, value); |
| 129 } |
| 130 return false; |
| 131 } |
| 132 |
| 133 // As above, but for integers. |
| 134 bool FindConstraint(const MediaConstraintsInterface* constraints, |
| 135 const std::string& key, |
| 136 int* value, |
| 137 size_t* mandatory_constraints) { |
| 138 std::string string_value; |
| 139 if (!constraints) { |
| 140 return false; |
| 141 } |
| 142 if (constraints->GetMandatory().FindFirst(key, &string_value)) { |
| 143 if (mandatory_constraints) { |
| 144 ++*mandatory_constraints; |
| 145 } |
| 146 return rtc::FromString(string_value, value); |
| 147 } |
| 148 if (constraints->GetOptional().FindFirst(key, &string_value)) { |
126 return rtc::FromString(string_value, value); | 149 return rtc::FromString(string_value, value); |
127 } | 150 } |
128 return false; | 151 return false; |
129 } | 152 } |
130 | 153 |
| 154 rtc::Optional<bool> ConstraintToOptionalBool( |
| 155 const MediaConstraintsInterface* constraints, |
| 156 const std::string& key) { |
| 157 bool value; |
| 158 bool present = FindConstraint(constraints, key, &value, nullptr); |
| 159 if (present) { |
| 160 return rtc::Optional<bool>(value); |
| 161 } |
| 162 return rtc::Optional<bool>(); |
| 163 } |
| 164 |
| 165 rtc::Optional<int> ConstraintToOptionalInt( |
| 166 const MediaConstraintsInterface* constraints, |
| 167 const std::string& key) { |
| 168 int value; |
| 169 bool present = FindConstraint(constraints, key, &value, nullptr); |
| 170 if (present) { |
| 171 return rtc::Optional<int>(value); |
| 172 } |
| 173 return rtc::Optional<int>(); |
| 174 } |
| 175 |
| 176 void CopyConstraintsIntoRtcConfiguration( |
| 177 const MediaConstraintsInterface* constraints, |
| 178 PeerConnectionInterface::RTCConfiguration* configuration) { |
| 179 // Copy info from constraints into configuration, if present. |
| 180 if (!constraints) { |
| 181 return; |
| 182 } |
| 183 |
| 184 bool value; |
| 185 if (FindConstraint(constraints, MediaConstraintsInterface::kEnableIPv6, |
| 186 &value, nullptr)) { |
| 187 if (!value) { |
| 188 configuration->disable_ipv6 = true; |
| 189 } |
| 190 } |
| 191 configuration->enable_dscp = ConstraintToOptionalBool( |
| 192 constraints, MediaConstraintsInterface::kEnableDscp); |
| 193 configuration->cpu_overuse_detection = ConstraintToOptionalBool( |
| 194 constraints, MediaConstraintsInterface::kCpuOveruseDetection); |
| 195 if (FindConstraint(constraints, |
| 196 MediaConstraintsInterface::kEnableRtpDataChannels, &value, |
| 197 NULL) && |
| 198 value) { |
| 199 configuration->enable_rtp_data_channel = true; |
| 200 } |
| 201 // Find Suspend Below Min Bitrate constraint. |
| 202 configuration->suspend_below_min_bitrate = ConstraintToOptionalBool( |
| 203 constraints, |
| 204 MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate); |
| 205 configuration->screencast_min_bitrate = ConstraintToOptionalInt( |
| 206 constraints, MediaConstraintsInterface::kScreencastMinBitrate); |
| 207 configuration->combined_audio_video_bwe = ConstraintToOptionalBool( |
| 208 constraints, MediaConstraintsInterface::kCombinedAudioVideoBwe); |
| 209 configuration->enable_dtls_srtp = ConstraintToOptionalBool( |
| 210 constraints, MediaConstraintsInterface::kEnableDtlsSrtp); |
| 211 } |
| 212 |
131 } // namespace webrtc | 213 } // namespace webrtc |
OLD | NEW |