| OLD | NEW |
| 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 28 matching lines...) Expand all Loading... |
| 39 #include "core/inspector/ConsoleMessage.h" | 39 #include "core/inspector/ConsoleMessage.h" |
| 40 #include "modules/mediastream/MediaTrackConstraintSet.h" | 40 #include "modules/mediastream/MediaTrackConstraintSet.h" |
| 41 #include "platform/Logging.h" | 41 #include "platform/Logging.h" |
| 42 #include "platform/RuntimeEnabledFeatures.h" | 42 #include "platform/RuntimeEnabledFeatures.h" |
| 43 #include "wtf/HashMap.h" | 43 #include "wtf/HashMap.h" |
| 44 #include "wtf/Vector.h" | 44 #include "wtf/Vector.h" |
| 45 #include "wtf/text/StringHash.h" | 45 #include "wtf/text/StringHash.h" |
| 46 | 46 |
| 47 namespace blink { | 47 namespace blink { |
| 48 | 48 |
| 49 |
| 49 namespace MediaConstraintsImpl { | 50 namespace MediaConstraintsImpl { |
| 50 | 51 |
| 52 // Old type/value form of constraint. Used in parsing old-style constraints. |
| 53 struct WebMediaConstraint { |
| 54 WebMediaConstraint() |
| 55 { |
| 56 } |
| 57 |
| 58 WebMediaConstraint(WebString name, WebString value) |
| 59 : m_name(name) |
| 60 , m_value(value) |
| 61 { |
| 62 } |
| 63 |
| 64 WebString m_name; |
| 65 WebString m_value; |
| 66 }; |
| 67 |
| 68 |
| 69 |
| 51 // Legal constraint names. | 70 // Legal constraint names. |
| 52 // Temporary Note: Comments about source are where they are copied from. | 71 // Temporary Note: Comments about source are where they are copied from. |
| 53 // Once the chrome parts use the new-style constraint values, they will | 72 // Once the chrome parts use the new-style constraint values, they will |
| 54 // be deleted from the files mentioned. | 73 // be deleted from the files mentioned. |
| 55 // TODO(hta): remove comments before https://crbug.com/543997 is closed. | 74 // TODO(hta): remove comments before https://crbug.com/543997 is closed. |
| 56 | 75 |
| 57 // From content/renderer/media/media_stream_video_source.cc | 76 // From content/renderer/media/media_stream_video_source.cc |
| 58 const char kMinAspectRatio[] = "minAspectRatio"; | 77 const char kMinAspectRatio[] = "minAspectRatio"; |
| 59 const char kMaxAspectRatio[] = "maxAspectRatio"; | 78 const char kMaxAspectRatio[] = "maxAspectRatio"; |
| 60 const char kMaxWidth[] = "maxWidth"; | 79 const char kMaxWidth[] = "maxWidth"; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 const char kCombinedAudioVideoBwe[] = "googCombinedAudioVideoBwe"; | 135 const char kCombinedAudioVideoBwe[] = "googCombinedAudioVideoBwe"; |
| 117 const char kScreencastMinBitrate[] = "googScreencastMinBitrate"; | 136 const char kScreencastMinBitrate[] = "googScreencastMinBitrate"; |
| 118 const char kCpuOveruseDetection[] = "googCpuOveruseDetection"; | 137 const char kCpuOveruseDetection[] = "googCpuOveruseDetection"; |
| 119 const char kCpuUnderuseThreshold[] = "googCpuUnderuseThreshold"; | 138 const char kCpuUnderuseThreshold[] = "googCpuUnderuseThreshold"; |
| 120 const char kCpuOveruseThreshold[] = "googCpuOveruseThreshold"; | 139 const char kCpuOveruseThreshold[] = "googCpuOveruseThreshold"; |
| 121 const char kCpuUnderuseEncodeRsdThreshold[] = "googCpuUnderuseEncodeRsdThreshold
"; | 140 const char kCpuUnderuseEncodeRsdThreshold[] = "googCpuUnderuseEncodeRsdThreshold
"; |
| 122 const char kCpuOveruseEncodeRsdThreshold[] = "googCpuOveruseEncodeRsdThreshold"; | 141 const char kCpuOveruseEncodeRsdThreshold[] = "googCpuOveruseEncodeRsdThreshold"; |
| 123 const char kCpuOveruseEncodeUsage[] = "googCpuOveruseEncodeUsage"; | 142 const char kCpuOveruseEncodeUsage[] = "googCpuOveruseEncodeUsage"; |
| 124 const char kHighStartBitrate[] = "googHighStartBitrate"; | 143 const char kHighStartBitrate[] = "googHighStartBitrate"; |
| 125 const char kPayloadPadding[] = "googPayloadPadding"; | 144 const char kPayloadPadding[] = "googPayloadPadding"; |
| 145 // From webrtc_audio_capturer |
| 146 const char kAudioLatency[] = "latencyMs"; |
| 147 // From media_stream_video_capturer_source |
| 148 |
| 126 // End of names from libjingle | 149 // End of names from libjingle |
| 127 // Names that have been used in the past, but should now be ignored. | 150 // Names that have been used in the past, but should now be ignored. |
| 128 // Kept around for backwards compatibility. | 151 // Kept around for backwards compatibility. |
| 129 // https://crbug.com/579729 | 152 // https://crbug.com/579729 |
| 130 const char kGoogLeakyBucket[] = "googLeakyBucket"; | 153 const char kGoogLeakyBucket[] = "googLeakyBucket"; |
| 131 | 154 const char kPowerLineFrequency[] = "googPowerLineFrequency"; |
| 132 // Names used for testing. | 155 // Names used for testing. |
| 133 const char kTestConstraint1[] = "valid_and_supported_1"; | 156 const char kTestConstraint1[] = "valid_and_supported_1"; |
| 134 const char kTestConstraint2[] = "valid_and_supported_2"; | 157 const char kTestConstraint2[] = "valid_and_supported_2"; |
| 135 | 158 |
| 136 static bool parseMandatoryConstraintsDictionary(const Dictionary& mandatoryConst
raintsDictionary, WebVector<WebMediaConstraint>& mandatory) | 159 static bool parseMandatoryConstraintsDictionary(const Dictionary& mandatoryConst
raintsDictionary, WebVector<WebMediaConstraint>& mandatory) |
| 137 { | 160 { |
| 138 Vector<WebMediaConstraint> mandatoryConstraintsVector; | 161 Vector<WebMediaConstraint> mandatoryConstraintsVector; |
| 139 HashMap<String, String> mandatoryConstraintsHashMap; | 162 HashMap<String, String> mandatoryConstraintsHashMap; |
| 140 bool ok = mandatoryConstraintsDictionary.getOwnPropertiesAsStringHashMap(man
datoryConstraintsHashMap); | 163 bool ok = mandatoryConstraintsDictionary.getOwnPropertiesAsStringHashMap(man
datoryConstraintsHashMap); |
| 141 if (!ok) | 164 if (!ok) |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 result.googHighpassFilter.setExact(toBoolean(constraint.m_value)); | 331 result.googHighpassFilter.setExact(toBoolean(constraint.m_value)); |
| 309 } else if (constraint.m_name.equals(kGoogTypingNoiseDetection)) { | 332 } else if (constraint.m_name.equals(kGoogTypingNoiseDetection)) { |
| 310 result.googTypingNoiseDetection.setExact(toBoolean(constraint.m_valu
e)); | 333 result.googTypingNoiseDetection.setExact(toBoolean(constraint.m_valu
e)); |
| 311 } else if (constraint.m_name.equals(kGoogAudioMirroring)) { | 334 } else if (constraint.m_name.equals(kGoogAudioMirroring)) { |
| 312 result.googAudioMirroring.setExact(toBoolean(constraint.m_value)); | 335 result.googAudioMirroring.setExact(toBoolean(constraint.m_value)); |
| 313 } else if (constraint.m_name.equals(kDAEchoCancellation)) { | 336 } else if (constraint.m_name.equals(kDAEchoCancellation)) { |
| 314 result.googDAEchoCancellation.setExact(toBoolean(constraint.m_value)
); | 337 result.googDAEchoCancellation.setExact(toBoolean(constraint.m_value)
); |
| 315 } else if (constraint.m_name.equals(kNoiseReduction)) { | 338 } else if (constraint.m_name.equals(kNoiseReduction)) { |
| 316 result.googNoiseReduction.setExact(toBoolean(constraint.m_value)); | 339 result.googNoiseReduction.setExact(toBoolean(constraint.m_value)); |
| 317 } else if (constraint.m_name.equals(kOfferToReceiveAudio)) { | 340 } else if (constraint.m_name.equals(kOfferToReceiveAudio)) { |
| 318 result.offerToReceiveAudio.setExact(constraint.m_value); | 341 // This constraint has formerly been defined both as a boolean |
| 342 // and as an integer. Allow both forms. |
| 343 if (constraint.m_value.equals("true")) |
| 344 result.offerToReceiveAudio.setExact(1); |
| 345 else if (constraint.m_value.equals("false")) |
| 346 result.offerToReceiveAudio.setExact(0); |
| 347 else |
| 348 result.offerToReceiveAudio.setExact(atoi(constraint.m_value.utf8
().c_str())); |
| 319 } else if (constraint.m_name.equals(kOfferToReceiveVideo)) { | 349 } else if (constraint.m_name.equals(kOfferToReceiveVideo)) { |
| 320 result.offerToReceiveVideo.setExact(constraint.m_value); | 350 // This constraint has formerly been defined both as a boolean |
| 351 // and as an integer. Allow both forms. |
| 352 if (constraint.m_value.equals("true")) |
| 353 result.offerToReceiveVideo.setExact(1); |
| 354 else if (constraint.m_value.equals("false")) |
| 355 result.offerToReceiveVideo.setExact(0); |
| 356 else |
| 357 result.offerToReceiveVideo.setExact(atoi(constraint.m_value.utf8
().c_str())); |
| 321 } else if (constraint.m_name.equals(kVoiceActivityDetection)) { | 358 } else if (constraint.m_name.equals(kVoiceActivityDetection)) { |
| 322 result.voiceActivityDetection.setExact(toBoolean(constraint.m_value)
); | 359 result.voiceActivityDetection.setExact(toBoolean(constraint.m_value)
); |
| 323 } else if (constraint.m_name.equals(kIceRestart)) { | 360 } else if (constraint.m_name.equals(kIceRestart)) { |
| 324 result.iceRestart.setExact(toBoolean(constraint.m_value)); | 361 result.iceRestart.setExact(toBoolean(constraint.m_value)); |
| 325 } else if (constraint.m_name.equals(kUseRtpMux)) { | 362 } else if (constraint.m_name.equals(kUseRtpMux)) { |
| 326 result.googUseRtpMux.setExact(toBoolean(constraint.m_value)); | 363 result.googUseRtpMux.setExact(toBoolean(constraint.m_value)); |
| 327 } else if (constraint.m_name.equals(kEnableDtlsSrtp)) { | 364 } else if (constraint.m_name.equals(kEnableDtlsSrtp)) { |
| 328 result.enableDtlsSrtp.setExact(toBoolean(constraint.m_value)); | 365 result.enableDtlsSrtp.setExact(toBoolean(constraint.m_value)); |
| 329 } else if (constraint.m_name.equals(kEnableRtpDataChannels)) { | 366 } else if (constraint.m_name.equals(kEnableRtpDataChannels)) { |
| 330 result.enableRtpDataChannels.setExact(toBoolean(constraint.m_value))
; | 367 result.enableRtpDataChannels.setExact(toBoolean(constraint.m_value))
; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 349 } else if (constraint.m_name.equals(kCpuUnderuseEncodeRsdThreshold)) { | 386 } else if (constraint.m_name.equals(kCpuUnderuseEncodeRsdThreshold)) { |
| 350 result.googCpuUnderuseEncodeRsdThreshold.setExact(atoi(constraint.m_
value.utf8().c_str())); | 387 result.googCpuUnderuseEncodeRsdThreshold.setExact(atoi(constraint.m_
value.utf8().c_str())); |
| 351 } else if (constraint.m_name.equals(kCpuOveruseEncodeRsdThreshold)) { | 388 } else if (constraint.m_name.equals(kCpuOveruseEncodeRsdThreshold)) { |
| 352 result.googCpuOveruseEncodeRsdThreshold.setExact(atoi(constraint.m_v
alue.utf8().c_str())); | 389 result.googCpuOveruseEncodeRsdThreshold.setExact(atoi(constraint.m_v
alue.utf8().c_str())); |
| 353 } else if (constraint.m_name.equals(kCpuOveruseEncodeUsage)) { | 390 } else if (constraint.m_name.equals(kCpuOveruseEncodeUsage)) { |
| 354 result.googCpuOveruseEncodeUsage.setExact(toBoolean(constraint.m_val
ue)); | 391 result.googCpuOveruseEncodeUsage.setExact(toBoolean(constraint.m_val
ue)); |
| 355 } else if (constraint.m_name.equals(kHighStartBitrate)) { | 392 } else if (constraint.m_name.equals(kHighStartBitrate)) { |
| 356 result.googHighStartBitrate.setExact(atoi(constraint.m_value.utf8().
c_str())); | 393 result.googHighStartBitrate.setExact(atoi(constraint.m_value.utf8().
c_str())); |
| 357 } else if (constraint.m_name.equals(kPayloadPadding)) { | 394 } else if (constraint.m_name.equals(kPayloadPadding)) { |
| 358 result.googPayloadPadding.setExact(toBoolean(constraint.m_value)); | 395 result.googPayloadPadding.setExact(toBoolean(constraint.m_value)); |
| 396 } else if (constraint.m_name.equals(kAudioLatency)) { |
| 397 result.googLatencyMs.setExact(atoi(constraint.m_value.utf8().c_str()
)); |
| 398 } else if (constraint.m_name.equals(kPowerLineFrequency)) { |
| 399 result.googPowerLineFrequency.setExact(atoi(constraint.m_value.utf8(
).c_str())); |
| 359 } else if (constraint.m_name.equals(kGoogLeakyBucket)) { | 400 } else if (constraint.m_name.equals(kGoogLeakyBucket)) { |
| 360 context->addConsoleMessage(ConsoleMessage::create(DeprecationMessage
Source, WarningMessageLevel, | 401 context->addConsoleMessage(ConsoleMessage::create(DeprecationMessage
Source, WarningMessageLevel, |
| 361 "Obsolete constraint named " + String(constraint.m_name) | 402 "Obsolete constraint named " + String(constraint.m_name) |
| 362 + " is ignored. Please stop using it.")); | 403 + " is ignored. Please stop using it.")); |
| 363 } else if (constraint.m_name.equals(kTestConstraint1) | 404 } else if (constraint.m_name.equals(kTestConstraint1) |
| 364 || constraint.m_name.equals(kTestConstraint2)) { | 405 || constraint.m_name.equals(kTestConstraint2)) { |
| 365 // These constraints are only for testing parsing. | 406 // These constraints are only for testing parsing. |
| 366 // Values 0 and 1 are legal, all others are a ConstraintError. | 407 // Values 0 and 1 are legal, all others are a ConstraintError. |
| 367 if (!constraint.m_value.equals("0") && !constraint.m_value.equals("1
")) { | 408 if (!constraint.m_value.equals("0") && !constraint.m_value.equals("1
")) { |
| 368 errorState.throwConstraintError("Illegal value for constraint",
constraint.m_name); | 409 errorState.throwConstraintError("Illegal value for constraint",
constraint.m_name); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 387 { | 428 { |
| 388 WebMediaTrackConstraintSet basic; | 429 WebMediaTrackConstraintSet basic; |
| 389 WebMediaTrackConstraintSet advanced; | 430 WebMediaTrackConstraintSet advanced; |
| 390 WebMediaConstraints constraints; | 431 WebMediaConstraints constraints; |
| 391 parseOldStyleNames(context, mandatory, true, basic, errorState); | 432 parseOldStyleNames(context, mandatory, true, basic, errorState); |
| 392 if (errorState.hadException()) | 433 if (errorState.hadException()) |
| 393 return constraints; | 434 return constraints; |
| 394 // We ignore unknow names and syntax errors in optional constraints. | 435 // We ignore unknow names and syntax errors in optional constraints. |
| 395 MediaErrorState ignoredErrorState; | 436 MediaErrorState ignoredErrorState; |
| 396 parseOldStyleNames(context, optional, false, advanced, ignoredErrorState); | 437 parseOldStyleNames(context, optional, false, advanced, ignoredErrorState); |
| 397 WebVector<WebMediaTrackConstraintSet> advancedVector(&advanced, 1); | 438 if (advanced.isEmpty()) { |
| 398 // Use the 4-argument initializer until Chrome has been converted. | 439 WebVector<WebMediaTrackConstraintSet> emptyVector; |
| 399 constraints.initialize(optional, mandatory, basic, advancedVector); | 440 constraints.initialize(basic, emptyVector); |
| 441 } else { |
| 442 WebVector<WebMediaTrackConstraintSet> advancedVector(&advanced, 1); |
| 443 constraints.initialize(basic, advancedVector); |
| 444 } |
| 400 return constraints; | 445 return constraints; |
| 401 } | 446 } |
| 402 | 447 |
| 403 // Deprecated. | 448 // Deprecated. |
| 404 WebMediaConstraints create(ExecutionContext* context, const Dictionary& constrai
ntsDictionary, MediaErrorState& errorState) | 449 WebMediaConstraints create(ExecutionContext* context, const Dictionary& constrai
ntsDictionary, MediaErrorState& errorState) |
| 405 { | 450 { |
| 406 WebVector<WebMediaConstraint> optional; | 451 WebVector<WebMediaConstraint> optional; |
| 407 WebVector<WebMediaConstraint> mandatory; | 452 WebVector<WebMediaConstraint> mandatory; |
| 408 if (!parse(constraintsDictionary, optional, mandatory)) { | 453 if (!parse(constraintsDictionary, optional, mandatory)) { |
| 409 errorState.throwTypeError("Malformed constraints object."); | 454 errorState.throwTypeError("Malformed constraints object."); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 | 582 |
| 538 WebMediaConstraints create() | 583 WebMediaConstraints create() |
| 539 { | 584 { |
| 540 WebMediaConstraints constraints; | 585 WebMediaConstraints constraints; |
| 541 constraints.initialize(); | 586 constraints.initialize(); |
| 542 return constraints; | 587 return constraints; |
| 543 } | 588 } |
| 544 | 589 |
| 545 } // namespace MediaConstraintsImpl | 590 } // namespace MediaConstraintsImpl |
| 546 } // namespace blink | 591 } // namespace blink |
| OLD | NEW |