henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2013 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 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. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 11 | #include "webrtc/api/mediaconstraintsinterface.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 12 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 13 | #include "webrtc/base/stringencode.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 14 | |
| 15 | namespace webrtc { |
| 16 | |
| 17 | const char MediaConstraintsInterface::kValueTrue[] = "true"; |
| 18 | const char MediaConstraintsInterface::kValueFalse[] = "false"; |
| 19 | |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 20 | // Constraints declared as static members in mediastreaminterface.h |
| 21 | // Specified by draft-alvestrand-constraints-resolution-00b |
| 22 | const char MediaConstraintsInterface::kMinAspectRatio[] = "minAspectRatio"; |
| 23 | const char MediaConstraintsInterface::kMaxAspectRatio[] = "maxAspectRatio"; |
| 24 | const char MediaConstraintsInterface::kMaxWidth[] = "maxWidth"; |
| 25 | const char MediaConstraintsInterface::kMinWidth[] = "minWidth"; |
| 26 | const char MediaConstraintsInterface::kMaxHeight[] = "maxHeight"; |
| 27 | const char MediaConstraintsInterface::kMinHeight[] = "minHeight"; |
| 28 | const char MediaConstraintsInterface::kMaxFrameRate[] = "maxFrameRate"; |
| 29 | const char MediaConstraintsInterface::kMinFrameRate[] = "minFrameRate"; |
| 30 | |
| 31 | // Audio constraints. |
| 32 | const char MediaConstraintsInterface::kEchoCancellation[] = |
tommi | 39b3100 | 2015-06-23 09:50:47 -0700 | [diff] [blame] | 33 | "echoCancellation"; |
Tommi | 70c7fe1 | 2015-06-15 09:14:03 +0200 | [diff] [blame] | 34 | const char MediaConstraintsInterface::kGoogEchoCancellation[] = |
| 35 | "googEchoCancellation"; |
Henrik Lundin | 441f634 | 2015-06-09 16:03:13 +0200 | [diff] [blame] | 36 | const char MediaConstraintsInterface::kExtendedFilterEchoCancellation[] = |
| 37 | "googEchoCancellation2"; |
Bjorn Volcker | bf395c1 | 2015-03-25 22:45:56 +0100 | [diff] [blame] | 38 | const char MediaConstraintsInterface::kDAEchoCancellation[] = |
| 39 | "googDAEchoCancellation"; |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 40 | const char MediaConstraintsInterface::kAutoGainControl[] = |
| 41 | "googAutoGainControl"; |
| 42 | const char MediaConstraintsInterface::kExperimentalAutoGainControl[] = |
| 43 | "googAutoGainControl2"; |
| 44 | const char MediaConstraintsInterface::kNoiseSuppression[] = |
| 45 | "googNoiseSuppression"; |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 +0000 | [diff] [blame] | 46 | const char MediaConstraintsInterface::kExperimentalNoiseSuppression[] = |
| 47 | "googNoiseSuppression2"; |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 48 | const char MediaConstraintsInterface::kHighpassFilter[] = |
| 49 | "googHighpassFilter"; |
| 50 | const char MediaConstraintsInterface::kTypingNoiseDetection[] = |
| 51 | "googTypingNoiseDetection"; |
| 52 | const char MediaConstraintsInterface::kAudioMirroring[] = "googAudioMirroring"; |
| 53 | |
| 54 | // Google-specific constraint keys for a local video source (getUserMedia). |
| 55 | const char MediaConstraintsInterface::kNoiseReduction[] = "googNoiseReduction"; |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 56 | |
wu@webrtc.org | 1481491 | 2014-04-02 23:25:15 +0000 | [diff] [blame] | 57 | // Constraint keys for CreateOffer / CreateAnswer defined in W3C specification. |
| 58 | const char MediaConstraintsInterface::kOfferToReceiveAudio[] = |
| 59 | "OfferToReceiveAudio"; |
| 60 | const char MediaConstraintsInterface::kOfferToReceiveVideo[] = |
| 61 | "OfferToReceiveVideo"; |
| 62 | const char MediaConstraintsInterface::kVoiceActivityDetection[] = |
| 63 | "VoiceActivityDetection"; |
| 64 | const char MediaConstraintsInterface::kIceRestart[] = |
| 65 | "IceRestart"; |
| 66 | // Google specific constraint for BUNDLE enable/disable. |
| 67 | const char MediaConstraintsInterface::kUseRtpMux[] = |
| 68 | "googUseRtpMUX"; |
| 69 | |
| 70 | // Below constraints should be used during PeerConnection construction. |
| 71 | const char MediaConstraintsInterface::kEnableDtlsSrtp[] = |
| 72 | "DtlsSrtpKeyAgreement"; |
| 73 | const char MediaConstraintsInterface::kEnableRtpDataChannels[] = |
| 74 | "RtpDataChannels"; |
| 75 | // Google-specific constraint keys. |
| 76 | const char MediaConstraintsInterface::kEnableDscp[] = "googDscp"; |
| 77 | const char MediaConstraintsInterface::kEnableIPv6[] = "googIPv6"; |
| 78 | const char MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate[] = |
| 79 | "googSuspendBelowMinBitrate"; |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 80 | const char MediaConstraintsInterface::kCombinedAudioVideoBwe[] = |
| 81 | "googCombinedAudioVideoBwe"; |
henrike@webrtc.org | dce3feb | 2014-03-26 01:17:30 +0000 | [diff] [blame] | 82 | const char MediaConstraintsInterface::kScreencastMinBitrate[] = |
| 83 | "googScreencastMinBitrate"; |
henrike@webrtc.org | b0ecc1c | 2014-03-26 22:44:28 +0000 | [diff] [blame] | 84 | // TODO(ronghuawu): Remove once cpu overuse detection is stable. |
| 85 | const char MediaConstraintsInterface::kCpuOveruseDetection[] = |
| 86 | "googCpuOveruseDetection"; |
buildbot@webrtc.org | 44a317a | 2014-06-17 07:49:15 +0000 | [diff] [blame] | 87 | const char MediaConstraintsInterface::kPayloadPadding[] = "googPayloadPadding"; |
| 88 | |
henrike@webrtc.org | dce3feb | 2014-03-26 01:17:30 +0000 | [diff] [blame] | 89 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 90 | // Set |value| to the value associated with the first appearance of |key|, or |
| 91 | // return false if |key| is not found. |
| 92 | bool MediaConstraintsInterface::Constraints::FindFirst( |
| 93 | const std::string& key, std::string* value) const { |
| 94 | for (Constraints::const_iterator iter = begin(); iter != end(); ++iter) { |
| 95 | if (iter->key == key) { |
| 96 | *value = iter->value; |
| 97 | return true; |
| 98 | } |
| 99 | } |
| 100 | return false; |
| 101 | } |
| 102 | |
| 103 | // Find the highest-priority instance of the boolean-valued constraint) named by |
| 104 | // |key| and return its value as |value|. |constraints| can be null. |
| 105 | // If |mandatory_constraints| is non-null, it is incremented if the key appears |
| 106 | // among the mandatory constraints. |
| 107 | // Returns true if the key was found and has a valid boolean value. |
| 108 | // If the key appears multiple times as an optional constraint, appearances |
| 109 | // after the first are ignored. |
| 110 | // Note: Because this uses FindFirst, repeated optional constraints whose |
| 111 | // first instance has an unrecognized value are not handled precisely in |
| 112 | // accordance with the specification. |
| 113 | bool FindConstraint(const MediaConstraintsInterface* constraints, |
| 114 | const std::string& key, bool* value, |
| 115 | size_t* mandatory_constraints) { |
| 116 | std::string string_value; |
| 117 | if (!constraints) { |
| 118 | return false; |
| 119 | } |
| 120 | if (constraints->GetMandatory().FindFirst(key, &string_value)) { |
| 121 | if (mandatory_constraints) |
| 122 | ++*mandatory_constraints; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 123 | return rtc::FromString(string_value, value); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 124 | } |
| 125 | if (constraints->GetOptional().FindFirst(key, &string_value)) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 126 | return rtc::FromString(string_value, value); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 127 | } |
| 128 | return false; |
| 129 | } |
| 130 | |
| 131 | } // namespace webrtc |