Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: webrtc/api/mediaconstraintsinterface.cc

Issue 1717583002: Non-constraint interfaces for all constrainable interfaces (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Review comments Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 void ConstraintToOptionalBool(const MediaConstraintsInterface* constraints,
155 const std::string& key,
156 rtc::Optional<bool>* value_out) {
157 bool value;
158 bool present = FindConstraint(constraints, key, &value, nullptr);
159 if (present) {
160 *value_out = rtc::Optional<bool>(value);
161 }
162 }
163
164 void ConstraintToOptionalInt(const MediaConstraintsInterface* constraints,
165 const std::string& key,
166 rtc::Optional<int>* value_out) {
167 int value;
168 bool present = FindConstraint(constraints, key, &value, nullptr);
169 if (present) {
170 *value_out = rtc::Optional<int>(value);
171 }
172 }
173
174 void CopyConstraintsIntoRtcConfiguration(
175 const MediaConstraintsInterface* constraints,
176 PeerConnectionInterface::RTCConfiguration* configuration) {
177 // Copy info from constraints into configuration, if present.
178 if (!constraints) {
179 return;
180 }
181
182 bool value;
183 if (FindConstraint(constraints, MediaConstraintsInterface::kEnableIPv6,
184 &value, nullptr)) {
185 if (!value) {
186 configuration->disable_ipv6 = true;
187 }
188 }
189 ConstraintToOptionalBool(constraints, MediaConstraintsInterface::kEnableDscp,
190 &configuration->enable_dscp);
191 ConstraintToOptionalBool(constraints,
192 MediaConstraintsInterface::kCpuOveruseDetection,
193 &configuration->cpu_overuse_detection);
194 if (FindConstraint(constraints,
195 MediaConstraintsInterface::kEnableRtpDataChannels, &value,
196 NULL) &&
197 value) {
198 configuration->enable_rtp_data_channel = true;
199 }
200 // Find Suspend Below Min Bitrate constraint.
201 ConstraintToOptionalBool(
202 constraints,
203 MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
204 &configuration->suspend_below_min_bitrate);
205 ConstraintToOptionalInt(constraints,
206 MediaConstraintsInterface::kScreencastMinBitrate,
207 &configuration->screencast_min_bitrate);
208 ConstraintToOptionalBool(constraints,
209 MediaConstraintsInterface::kCombinedAudioVideoBwe,
210 &configuration->combined_audio_video_bwe);
211 ConstraintToOptionalBool(constraints,
212 MediaConstraintsInterface::kEnableDtlsSrtp,
213 &configuration->enable_dtls_srtp);
214 }
215
131 } // namespace webrtc 216 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/api/mediaconstraintsinterface.h ('k') | webrtc/api/mediaconstraintsinterface_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698