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

Side by Side Diff: third_party/WebKit/Source/modules/mediastream/MediaConstraintsImpl.cpp

Issue 1910463002: Implement MediaStreamTrack.getConstraints (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding global-interface-listing entry Created 4 years, 8 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 (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 22 matching lines...) Expand all
33 #include "bindings/core/v8/ArrayValue.h" 33 #include "bindings/core/v8/ArrayValue.h"
34 #include "bindings/core/v8/Dictionary.h" 34 #include "bindings/core/v8/Dictionary.h"
35 #include "bindings/core/v8/ExceptionState.h" 35 #include "bindings/core/v8/ExceptionState.h"
36 #include "core/dom/ExceptionCode.h" 36 #include "core/dom/ExceptionCode.h"
37 #include "core/dom/ExecutionContext.h" 37 #include "core/dom/ExecutionContext.h"
38 #include "core/frame/UseCounter.h" 38 #include "core/frame/UseCounter.h"
39 #include "core/inspector/ConsoleMessage.h" 39 #include "core/inspector/ConsoleMessage.h"
40 #include "modules/mediastream/MediaTrackConstraints.h" 40 #include "modules/mediastream/MediaTrackConstraints.h"
41 #include "platform/Logging.h" 41 #include "platform/Logging.h"
42 #include "platform/RuntimeEnabledFeatures.h" 42 #include "platform/RuntimeEnabledFeatures.h"
43 #include "wtf/Assertions.h"
43 #include "wtf/HashMap.h" 44 #include "wtf/HashMap.h"
44 #include "wtf/Vector.h" 45 #include "wtf/Vector.h"
45 #include "wtf/text/StringHash.h" 46 #include "wtf/text/StringHash.h"
46 47
47 namespace blink { 48 namespace blink {
48 49
49 50
50 namespace MediaConstraintsImpl { 51 namespace MediaConstraintsImpl {
51 52
52 // Old type/value form of constraint. Used in parsing old-style constraints. 53 // Old type/value form of constraint. Used in parsing old-style constraints.
53 struct WebMediaConstraint { 54 struct NameValueStringConstraint {
Peter Beverloo 2016/04/21 14:11:46 Have you considered using something like the follo
hta - Chromium 2016/04/24 09:58:25 Not really - this was a struct that was exposed gl
54 WebMediaConstraint() 55 NameValueStringConstraint()
55 { 56 {
56 } 57 }
57 58
58 WebMediaConstraint(WebString name, WebString value) 59 NameValueStringConstraint(WebString name, WebString value)
59 : m_name(name) 60 : m_name(name)
60 , m_value(value) 61 , m_value(value)
61 { 62 {
62 } 63 }
63 64
64 WebString m_name; 65 WebString m_name;
65 WebString m_value; 66 WebString m_value;
66 }; 67 };
67 68
68 69
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 // End of names from libjingle 150 // End of names from libjingle
150 // Names that have been used in the past, but should now be ignored. 151 // Names that have been used in the past, but should now be ignored.
151 // Kept around for backwards compatibility. 152 // Kept around for backwards compatibility.
152 // https://crbug.com/579729 153 // https://crbug.com/579729
153 const char kGoogLeakyBucket[] = "googLeakyBucket"; 154 const char kGoogLeakyBucket[] = "googLeakyBucket";
154 const char kPowerLineFrequency[] = "googPowerLineFrequency"; 155 const char kPowerLineFrequency[] = "googPowerLineFrequency";
155 // Names used for testing. 156 // Names used for testing.
156 const char kTestConstraint1[] = "valid_and_supported_1"; 157 const char kTestConstraint1[] = "valid_and_supported_1";
157 const char kTestConstraint2[] = "valid_and_supported_2"; 158 const char kTestConstraint2[] = "valid_and_supported_2";
158 159
159 static bool parseMandatoryConstraintsDictionary(const Dictionary& mandatoryConst raintsDictionary, WebVector<WebMediaConstraint>& mandatory) 160 static bool parseMandatoryConstraintsDictionary(const Dictionary& mandatoryConst raintsDictionary, WebVector<NameValueStringConstraint>& mandatory)
160 { 161 {
161 Vector<WebMediaConstraint> mandatoryConstraintsVector; 162 Vector<NameValueStringConstraint> mandatoryConstraintsVector;
162 HashMap<String, String> mandatoryConstraintsHashMap; 163 HashMap<String, String> mandatoryConstraintsHashMap;
163 bool ok = mandatoryConstraintsDictionary.getOwnPropertiesAsStringHashMap(man datoryConstraintsHashMap); 164 bool ok = mandatoryConstraintsDictionary.getOwnPropertiesAsStringHashMap(man datoryConstraintsHashMap);
164 if (!ok) 165 if (!ok)
165 return false; 166 return false;
166 167
167 for (const auto& iter : mandatoryConstraintsHashMap) 168 for (const auto& iter : mandatoryConstraintsHashMap)
168 mandatoryConstraintsVector.append(WebMediaConstraint(iter.key, iter.valu e)); 169 mandatoryConstraintsVector.append(NameValueStringConstraint(iter.key, it er.value));
169 mandatory.assign(mandatoryConstraintsVector); 170 mandatory.assign(mandatoryConstraintsVector);
170 return true; 171 return true;
171 } 172 }
172 173
173 static bool parseOptionalConstraintsVectorElement(const Dictionary& constraint, Vector<WebMediaConstraint>& optionalConstraintsVector) 174 static bool parseOptionalConstraintsVectorElement(const Dictionary& constraint, Vector<NameValueStringConstraint>& optionalConstraintsVector)
174 { 175 {
175 Vector<String> localNames; 176 Vector<String> localNames;
176 bool ok = constraint.getPropertyNames(localNames); 177 bool ok = constraint.getPropertyNames(localNames);
177 if (!ok) 178 if (!ok)
178 return false; 179 return false;
179 if (localNames.size() != 1) 180 if (localNames.size() != 1)
180 return false; 181 return false;
181 const String& key = localNames[0]; 182 const String& key = localNames[0];
182 String value; 183 String value;
183 ok = DictionaryHelper::get(constraint, key, value); 184 ok = DictionaryHelper::get(constraint, key, value);
184 if (!ok) 185 if (!ok)
185 return false; 186 return false;
186 optionalConstraintsVector.append(WebMediaConstraint(key, value)); 187 optionalConstraintsVector.append(NameValueStringConstraint(key, value));
187 return true; 188 return true;
188 } 189 }
189 190
190 // Old style parser. Deprecated. 191 // Old style parser. Deprecated.
191 static bool parse(const Dictionary& constraintsDictionary, WebVector<WebMediaCon straint>& optional, WebVector<WebMediaConstraint>& mandatory) 192 static bool parse(const Dictionary& constraintsDictionary, WebVector<NameValueSt ringConstraint>& optional, WebVector<NameValueStringConstraint>& mandatory)
Peter Beverloo 2016/04/21 14:11:46 Is there any reason to use a WebVector here and el
hta - Chromium 2016/04/24 09:58:25 Good point. It was used globally, but now it's jus
192 { 193 {
193 if (constraintsDictionary.isUndefinedOrNull()) 194 if (constraintsDictionary.isUndefinedOrNull())
194 return true; 195 return true;
195 196
196 Vector<String> names; 197 Vector<String> names;
197 bool ok = constraintsDictionary.getPropertyNames(names); 198 bool ok = constraintsDictionary.getPropertyNames(names);
198 if (!ok) 199 if (!ok)
199 return false; 200 return false;
200 201
201 String mandatoryName("mandatory"); 202 String mandatoryName("mandatory");
202 String optionalName("optional"); 203 String optionalName("optional");
203 204
204 for (Vector<String>::iterator it = names.begin(); it != names.end(); ++it) { 205 for (Vector<String>::iterator it = names.begin(); it != names.end(); ++it) {
205 if (*it != mandatoryName && *it != optionalName) 206 if (*it != mandatoryName && *it != optionalName)
206 return false; 207 return false;
207 } 208 }
208 209
209 if (names.contains(mandatoryName)) { 210 if (names.contains(mandatoryName)) {
210 Dictionary mandatoryConstraintsDictionary; 211 Dictionary mandatoryConstraintsDictionary;
211 bool ok = constraintsDictionary.get(mandatoryName, mandatoryConstraintsD ictionary); 212 bool ok = constraintsDictionary.get(mandatoryName, mandatoryConstraintsD ictionary);
212 if (!ok || mandatoryConstraintsDictionary.isUndefinedOrNull()) 213 if (!ok || mandatoryConstraintsDictionary.isUndefinedOrNull())
213 return false; 214 return false;
214 ok = parseMandatoryConstraintsDictionary(mandatoryConstraintsDictionary, mandatory); 215 ok = parseMandatoryConstraintsDictionary(mandatoryConstraintsDictionary, mandatory);
215 if (!ok) 216 if (!ok)
216 return false; 217 return false;
217 } 218 }
218 219
219 Vector<WebMediaConstraint> optionalConstraintsVector; 220 Vector<NameValueStringConstraint> optionalConstraintsVector;
220 if (names.contains(optionalName)) { 221 if (names.contains(optionalName)) {
221 ArrayValue optionalConstraints; 222 ArrayValue optionalConstraints;
222 bool ok = DictionaryHelper::get(constraintsDictionary, optionalName, opt ionalConstraints); 223 bool ok = DictionaryHelper::get(constraintsDictionary, optionalName, opt ionalConstraints);
223 if (!ok || optionalConstraints.isUndefinedOrNull()) 224 if (!ok || optionalConstraints.isUndefinedOrNull())
224 return false; 225 return false;
225 226
226 size_t numberOfConstraints; 227 size_t numberOfConstraints;
227 ok = optionalConstraints.length(numberOfConstraints); 228 ok = optionalConstraints.length(numberOfConstraints);
228 if (!ok) 229 if (!ok)
229 return false; 230 return false;
230 231
231 for (size_t i = 0; i < numberOfConstraints; ++i) { 232 for (size_t i = 0; i < numberOfConstraints; ++i) {
232 Dictionary constraint; 233 Dictionary constraint;
233 ok = optionalConstraints.get(i, constraint); 234 ok = optionalConstraints.get(i, constraint);
234 if (!ok || constraint.isUndefinedOrNull()) 235 if (!ok || constraint.isUndefinedOrNull())
235 return false; 236 return false;
236 ok = parseOptionalConstraintsVectorElement(constraint, optionalConst raintsVector); 237 ok = parseOptionalConstraintsVectorElement(constraint, optionalConst raintsVector);
237 if (!ok) 238 if (!ok)
238 return false; 239 return false;
239 } 240 }
240 optional.assign(optionalConstraintsVector); 241 optional.assign(optionalConstraintsVector);
241 } 242 }
242 243
243 return true; 244 return true;
244 } 245 }
245 246
246 static bool parse(const MediaTrackConstraints& constraintsIn, WebVector<WebMedia Constraint>& optional, WebVector<WebMediaConstraint>& mandatory) 247 static bool parse(const MediaTrackConstraints& constraintsIn, WebVector<NameValu eStringConstraint>& optional, WebVector<NameValueStringConstraint>& mandatory)
247 { 248 {
248 Vector<WebMediaConstraint> mandatoryConstraintsVector; 249 Vector<NameValueStringConstraint> mandatoryConstraintsVector;
249 if (constraintsIn.hasMandatory()) { 250 if (constraintsIn.hasMandatory()) {
250 bool ok = parseMandatoryConstraintsDictionary(constraintsIn.mandatory(), mandatory); 251 bool ok = parseMandatoryConstraintsDictionary(constraintsIn.mandatory(), mandatory);
251 if (!ok) 252 if (!ok)
252 return false; 253 return false;
253 } 254 }
254 255
255 Vector<WebMediaConstraint> optionalConstraintsVector; 256 Vector<NameValueStringConstraint> optionalConstraintsVector;
256 if (constraintsIn.hasOptional()) { 257 if (constraintsIn.hasOptional()) {
257 const Vector<Dictionary>& optionalConstraints = constraintsIn.optional() ; 258 const Vector<Dictionary>& optionalConstraints = constraintsIn.optional() ;
258 259
259 for (const auto& constraint : optionalConstraints) { 260 for (const auto& constraint : optionalConstraints) {
260 if (constraint.isUndefinedOrNull()) 261 if (constraint.isUndefinedOrNull())
261 return false; 262 return false;
262 bool ok = parseOptionalConstraintsVectorElement(constraint, optional ConstraintsVector); 263 bool ok = parseOptionalConstraintsVectorElement(constraint, optional ConstraintsVector);
263 if (!ok) 264 if (!ok)
264 return false; 265 return false;
265 } 266 }
266 optional.assign(optionalConstraintsVector); 267 optional.assign(optionalConstraintsVector);
267 } 268 }
268 return true; 269 return true;
269 } 270 }
270 271
271 static bool toBoolean(const WebString& asWebString) 272 static bool toBoolean(const WebString& asWebString)
272 { 273 {
273 return asWebString.equals("true"); 274 return asWebString.equals("true");
274 // TODO(hta): Check against "false" and return error if it's neither. 275 // TODO(hta): Check against "false" and return error if it's neither.
275 // https://crbug.com/576582 276 // https://crbug.com/576582
276 } 277 }
277 278
278 static void parseOldStyleNames(ExecutionContext* context, const WebVector<WebMed iaConstraint>& oldNames, bool reportUnknownNames, WebMediaTrackConstraintSet& re sult, MediaErrorState& errorState) 279 static void parseOldStyleNames(ExecutionContext* context, const WebVector<NameVa lueStringConstraint>& oldNames, bool reportUnknownNames, WebMediaTrackConstraint Set& result, MediaErrorState& errorState)
279 { 280 {
280 for (const WebMediaConstraint& constraint : oldNames) { 281 for (const NameValueStringConstraint& constraint : oldNames) {
281 if (constraint.m_name.equals(kMinAspectRatio)) { 282 if (constraint.m_name.equals(kMinAspectRatio)) {
282 result.aspectRatio.setMin(atof(constraint.m_value.utf8().c_str())); 283 result.aspectRatio.setMin(atof(constraint.m_value.utf8().c_str()));
283 } else if (constraint.m_name.equals(kMaxAspectRatio)) { 284 } else if (constraint.m_name.equals(kMaxAspectRatio)) {
284 result.aspectRatio.setMax(atof(constraint.m_value.utf8().c_str())); 285 result.aspectRatio.setMax(atof(constraint.m_value.utf8().c_str()));
285 } else if (constraint.m_name.equals(kMaxWidth)) { 286 } else if (constraint.m_name.equals(kMaxWidth)) {
286 result.width.setMax(atoi(constraint.m_value.utf8().c_str())); 287 result.width.setMax(atoi(constraint.m_value.utf8().c_str()));
287 } else if (constraint.m_name.equals(kMinWidth)) { 288 } else if (constraint.m_name.equals(kMinWidth)) {
288 result.width.setMin(atoi(constraint.m_value.utf8().c_str())); 289 result.width.setMin(atoi(constraint.m_value.utf8().c_str()));
289 } else if (constraint.m_name.equals(kMaxHeight)) { 290 } else if (constraint.m_name.equals(kMaxHeight)) {
290 result.height.setMax(atoi(constraint.m_value.utf8().c_str())); 291 result.height.setMax(atoi(constraint.m_value.utf8().c_str()));
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 DeprecationMessageSource, 418 DeprecationMessageSource,
418 WarningMessageLevel, 419 WarningMessageLevel,
419 "Unknown constraint named " 420 "Unknown constraint named "
420 + String(constraint.m_name) + " rejected")); 421 + String(constraint.m_name) + " rejected"));
421 errorState.throwConstraintError("Unknown name of constraint dete cted", constraint.m_name); 422 errorState.throwConstraintError("Unknown name of constraint dete cted", constraint.m_name);
422 } 423 }
423 } 424 }
424 } 425 }
425 } 426 }
426 427
427 static WebMediaConstraints createFromNamedConstraints(ExecutionContext* context, WebVector<WebMediaConstraint>& mandatory, const WebVector<WebMediaConstraint>& optional, MediaErrorState& errorState) 428 static WebMediaConstraints createFromNamedConstraints(ExecutionContext* context, WebVector<NameValueStringConstraint>& mandatory, const WebVector<NameValueStrin gConstraint>& optional, MediaErrorState& errorState)
428 { 429 {
429 WebMediaTrackConstraintSet basic; 430 WebMediaTrackConstraintSet basic;
430 WebMediaTrackConstraintSet advanced; 431 WebMediaTrackConstraintSet advanced;
431 WebMediaConstraints constraints; 432 WebMediaConstraints constraints;
432 parseOldStyleNames(context, mandatory, true, basic, errorState); 433 parseOldStyleNames(context, mandatory, true, basic, errorState);
433 if (errorState.hadException()) 434 if (errorState.hadException())
434 return constraints; 435 return constraints;
435 // We ignore unknow names and syntax errors in optional constraints. 436 // We ignore unknow names and syntax errors in optional constraints.
436 MediaErrorState ignoredErrorState; 437 MediaErrorState ignoredErrorState;
437 Vector<WebMediaTrackConstraintSet> advancedVector; 438 Vector<WebMediaTrackConstraintSet> advancedVector;
438 for (const auto& optionalConstraint : optional) { 439 for (const auto& optionalConstraint : optional) {
439 WebMediaTrackConstraintSet advancedElement; 440 WebMediaTrackConstraintSet advancedElement;
440 WebVector<WebMediaConstraint> elementAsList(&optionalConstraint, 1); 441 WebVector<NameValueStringConstraint> elementAsList(&optionalConstraint, 1);
441 parseOldStyleNames(context, elementAsList, false, advancedElement, ignor edErrorState); 442 parseOldStyleNames(context, elementAsList, false, advancedElement, ignor edErrorState);
442 if (!advancedElement.isEmpty()) 443 if (!advancedElement.isEmpty())
443 advancedVector.append(advancedElement); 444 advancedVector.append(advancedElement);
444 } 445 }
445 constraints.initialize(basic, advancedVector); 446 constraints.initialize(basic, advancedVector);
446 return constraints; 447 return constraints;
447 } 448 }
448 449
449 // Deprecated. 450 // Deprecated.
450 WebMediaConstraints create(ExecutionContext* context, const Dictionary& constrai ntsDictionary, MediaErrorState& errorState) 451 WebMediaConstraints create(ExecutionContext* context, const Dictionary& constrai ntsDictionary, MediaErrorState& errorState)
451 { 452 {
452 WebVector<WebMediaConstraint> optional; 453 WebVector<NameValueStringConstraint> optional;
453 WebVector<WebMediaConstraint> mandatory; 454 WebVector<NameValueStringConstraint> mandatory;
454 if (!parse(constraintsDictionary, optional, mandatory)) { 455 if (!parse(constraintsDictionary, optional, mandatory)) {
455 errorState.throwTypeError("Malformed constraints object."); 456 errorState.throwTypeError("Malformed constraints object.");
456 return WebMediaConstraints(); 457 return WebMediaConstraints();
457 } 458 }
458 UseCounter::count(context, UseCounter::MediaStreamConstraintsFromDictionary) ; 459 UseCounter::count(context, UseCounter::MediaStreamConstraintsFromDictionary) ;
459 return createFromNamedConstraints(context, mandatory, optional, errorState); 460 return createFromNamedConstraints(context, mandatory, optional, errorState);
460 } 461 }
461 462
462 void copyLongConstraint(const ConstrainLongRange& blinkForm, LongConstraint& web Form) 463 void copyLongConstraint(const ConstrainLongRange& blinkForm, LongConstraint& web Form)
463 { 464 {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 advancedBuffer.append(advancedElement); 568 advancedBuffer.append(advancedElement);
568 } 569 }
569 } 570 }
570 // TODO(hta): Add initialization of advanced constraints once present. 571 // TODO(hta): Add initialization of advanced constraints once present.
571 // https://crbug.com/253412 572 // https://crbug.com/253412
572 if (constraintsIn.hasOptional() || constraintsIn.hasMandatory()) { 573 if (constraintsIn.hasOptional() || constraintsIn.hasMandatory()) {
573 if (!constraintBuffer.isEmpty() || constraintsIn.hasAdvanced()) { 574 if (!constraintBuffer.isEmpty() || constraintsIn.hasAdvanced()) {
574 errorState.throwTypeError("Malformed constraint: Cannot use both opt ional/mandatory and specific or advanced constraints."); 575 errorState.throwTypeError("Malformed constraint: Cannot use both opt ional/mandatory and specific or advanced constraints.");
575 return WebMediaConstraints(); 576 return WebMediaConstraints();
576 } 577 }
577 WebVector<WebMediaConstraint> optional; 578 WebVector<NameValueStringConstraint> optional;
578 WebVector<WebMediaConstraint> mandatory; 579 WebVector<NameValueStringConstraint> mandatory;
579 if (!parse(constraintsIn, optional, mandatory)) { 580 if (!parse(constraintsIn, optional, mandatory)) {
580 errorState.throwTypeError("Malformed constraints object."); 581 errorState.throwTypeError("Malformed constraints object.");
581 return WebMediaConstraints(); 582 return WebMediaConstraints();
582 } 583 }
583 UseCounter::count(context, UseCounter::MediaStreamConstraintsNameValue); 584 UseCounter::count(context, UseCounter::MediaStreamConstraintsNameValue);
584 return createFromNamedConstraints(context, mandatory, optional, errorSta te); 585 return createFromNamedConstraints(context, mandatory, optional, errorSta te);
585 } 586 }
586 UseCounter::count(context, UseCounter::MediaStreamConstraintsConformant); 587 UseCounter::count(context, UseCounter::MediaStreamConstraintsConformant);
587 constraints.initialize(constraintBuffer, advancedBuffer); 588 constraints.initialize(constraintBuffer, advancedBuffer);
588 return constraints; 589 return constraints;
589 } 590 }
590 591
591 WebMediaConstraints create() 592 WebMediaConstraints create()
592 { 593 {
593 WebMediaConstraints constraints; 594 WebMediaConstraints constraints;
594 constraints.initialize(); 595 constraints.initialize();
595 return constraints; 596 return constraints;
596 } 597 }
597 598
599 ConstrainLongRange convertLong(const LongConstraint& input)
Peter Beverloo 2016/04/21 14:11:46 While English is not my first language, it seems t
hta - Chromium 2016/04/24 09:58:25 Not my first language either, but it is the first
600 {
601
602 ConstrainLongRange output;
603 if (input.hasExact())
604 output.setExact(input.exact());
605 if (input.hasIdeal())
606 output.setIdeal(input.ideal());
607 if (input.hasMin())
608 output.setMin(input.min());
609 if (input.hasMax())
610 output.setMax(input.max());
611 return output;
612 }
613
614 ConstrainDoubleRange convertDouble(const DoubleConstraint& input)
615 {
616
617 ConstrainDoubleRange output;
618 if (input.hasExact())
619 output.setExact(input.exact());
620 if (input.hasIdeal())
621 output.setIdeal(input.ideal());
622 if (input.hasMin())
623 output.setMin(input.min());
624 if (input.hasMax())
625 output.setMax(input.max());
626 return output;
627 }
628
629 ConstrainDOMStringParameters convertString(const StringConstraint& input)
630 {
631 ConstrainDOMStringParameters output;
632 if (input.hasIdeal()) {
633 Vector<WTF::String> buffer;
Peter Beverloo 2016/04/21 14:11:46 nit: no need to prefix with WTF::
hta - Chromium 2016/04/24 09:58:25 Done.
634 for (const auto& scanner : input.ideal())
635 buffer.append(scanner);
636 output.setIdeal(buffer);
637 }
638 if (input.hasExact()) {
639 Vector<WTF::String> buffer;
640 for (const auto& scanner : input.exact())
641 buffer.append(scanner);
642 output.setExact(buffer);
643 }
644 return output;
645 }
646
647 ConstrainBooleanParameters convertBoolean(const BooleanConstraint& input)
648 {
649
650 ConstrainBooleanParameters output;
651 if (input.hasExact())
652 output.setExact(input.exact());
653 if (input.hasIdeal())
654 output.setIdeal(input.ideal());
655 return output;
656 }
657
658 void convertConstraintSet(const WebMediaTrackConstraintSet& input, MediaTrackCon straintSet& output)
659 {
660 if (!input.width.isEmpty())
661 output.setWidth(convertLong(input.width));
662 if (!input.height.isEmpty())
663 output.setHeight(convertLong(input.height));
664 if (!input.aspectRatio.isEmpty())
665 output.setAspectRatio(convertDouble(input.aspectRatio));
666 if (!input.frameRate.isEmpty())
667 output.setFrameRate(convertDouble(input.frameRate));
668 if (!input.facingMode.isEmpty())
669 output.setFacingMode(convertString(input.facingMode));
670 if (!input.volume.isEmpty())
671 output.setVolume(convertDouble(input.volume));
672 if (!input.sampleRate.isEmpty())
673 output.setSampleRate(convertLong(input.sampleRate));
674 if (!input.sampleSize.isEmpty())
675 output.setSampleSize(convertLong(input.sampleSize));
676 if (!input.echoCancellation.isEmpty())
677 output.setEchoCancellation(convertBoolean(input.echoCancellation));
678 if (!input.latency.isEmpty())
679 output.setLatency(convertDouble(input.latency));
680 if (!input.channelCount.isEmpty())
681 output.setChannelCount(convertLong(input.channelCount));
682 if (!input.deviceId.isEmpty())
683 output.setDeviceId(convertString(input.deviceId));
684 if (!input.groupId.isEmpty())
685 output.setGroupId(convertString(input.groupId));
686 // TODO(hta): Add the non-standard names (here and in IDL).
Peter Beverloo 2016/04/21 14:11:46 These are the goog* right, or also the hotword/sin
hta - Chromium 2016/04/24 09:58:25 I think I need to moderate this remark. I'll file
687 }
688
689 void convertConstraints(const WebMediaConstraints& input, MediaTrackConstraints& output)
690 {
691 if (input.isNull())
692 return;
693 convertConstraintSet(input.basic(), output);
694 HeapVector<MediaTrackConstraintSet> advancedVector;
695 for (const auto& it : input.advanced()) {
696 MediaTrackConstraintSet element;
697 convertConstraintSet(it, element);
698 advancedVector.append(element);
699 }
700 if (!advancedVector.isEmpty())
701 output.setAdvanced(advancedVector);
702 }
703
598 } // namespace MediaConstraintsImpl 704 } // namespace MediaConstraintsImpl
599 } // namespace blink 705 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698