henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 15:54:43 | [diff] [blame] | 2 | * Copyright 2013 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 15:54:43 | [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 | [diff] [blame] | 9 | */ |
| 10 | |
Niels Möller | f06f923 | 2018-08-07 10:32:18 | [diff] [blame] | 11 | // Implementation of the w3c constraints spec is the responsibility of the |
| 12 | // browser. Chrome no longer uses the constraints api declared here, and it will |
| 13 | // be removed from WebRTC. |
| 14 | // https://bugs.chromium.org/p/webrtc/issues/detail?id=9239 |
hta | a2a49d9 | 2016-03-04 10:51:39 | [diff] [blame] | 15 | |
Niels Möller | dac03d9 | 2019-02-13 07:52:27 | [diff] [blame] | 16 | #ifndef SDK_MEDIA_CONSTRAINTS_H_ |
| 17 | #define SDK_MEDIA_CONSTRAINTS_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 18 | |
Yves Gerey | 988cc08 | 2018-10-23 10:03:01 | [diff] [blame] | 19 | #include <stddef.h> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 20 | #include <string> |
Niels Möller | dac03d9 | 2019-02-13 07:52:27 | [diff] [blame] | 21 | #include <utility> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 22 | #include <vector> |
| 23 | |
Yves Gerey | 988cc08 | 2018-10-23 10:03:01 | [diff] [blame] | 24 | #include "api/audio_options.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 25 | #include "api/peer_connection_interface.h" |
hta | a2a49d9 | 2016-03-04 10:51:39 | [diff] [blame] | 26 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 27 | namespace webrtc { |
| 28 | |
Niels Möller | dac03d9 | 2019-02-13 07:52:27 | [diff] [blame] | 29 | // Class representing constraints, as used by the android and objc apis. |
deadbeef | b10f32f | 2017-02-08 09:38:21 | [diff] [blame] | 30 | // |
| 31 | // Constraints may be either "mandatory", which means that unless satisfied, |
| 32 | // the method taking the constraints should fail, or "optional", which means |
| 33 | // they may not be satisfied.. |
Niels Möller | dac03d9 | 2019-02-13 07:52:27 | [diff] [blame] | 34 | class MediaConstraints { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 35 | public: |
| 36 | struct Constraint { |
| 37 | Constraint() {} |
| 38 | Constraint(const std::string& key, const std::string value) |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 39 | : key(key), value(value) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 40 | std::string key; |
| 41 | std::string value; |
| 42 | }; |
| 43 | |
| 44 | class Constraints : public std::vector<Constraint> { |
| 45 | public: |
Niels Möller | dac03d9 | 2019-02-13 07:52:27 | [diff] [blame] | 46 | Constraints() = default; |
| 47 | Constraints(std::initializer_list<Constraint> l) |
| 48 | : std::vector<Constraint>(l) {} |
| 49 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 50 | bool FindFirst(const std::string& key, std::string* value) const; |
| 51 | }; |
| 52 | |
Niels Möller | dac03d9 | 2019-02-13 07:52:27 | [diff] [blame] | 53 | MediaConstraints() = default; |
| 54 | MediaConstraints(Constraints mandatory, Constraints optional) |
| 55 | : mandatory_(std::move(mandatory)), optional_(std::move(optional)) {} |
| 56 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 57 | // Constraint keys used by a local audio source. |
tommi | 39b3100 | 2015-06-23 16:50:47 | [diff] [blame] | 58 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 59 | // These keys are google specific. |
Tommi | 70c7fe1 | 2015-06-15 07:14:03 | [diff] [blame] | 60 | static const char kGoogEchoCancellation[]; // googEchoCancellation |
| 61 | |
Henrik Lundin | 441f634 | 2015-06-09 14:03:13 | [diff] [blame] | 62 | static const char kExtendedFilterEchoCancellation[]; // googEchoCancellation2 |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 63 | static const char kDAEchoCancellation[]; // googDAEchoCancellation |
| 64 | static const char kAutoGainControl[]; // googAutoGainControl |
| 65 | static const char kExperimentalAutoGainControl[]; // googAutoGainControl2 |
| 66 | static const char kNoiseSuppression[]; // googNoiseSuppression |
sergeyu@chromium.org | 9cf037b | 2014-02-07 19:03:26 | [diff] [blame] | 67 | static const char kExperimentalNoiseSuppression[]; // googNoiseSuppression2 |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 68 | static const char kHighpassFilter[]; // googHighpassFilter |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 | [diff] [blame] | 69 | static const char kTypingNoiseDetection[]; // googTypingNoiseDetection |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 70 | static const char kAudioMirroring[]; // googAudioMirroring |
minyue | ba41428 | 2016-12-11 10:17:52 | [diff] [blame] | 71 | static const char |
| 72 | kAudioNetworkAdaptorConfig[]; // goodAudioNetworkAdaptorConfig |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 73 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 74 | // Constraint keys for CreateOffer / CreateAnswer |
| 75 | // Specified by the W3C PeerConnection spec |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 76 | static const char kOfferToReceiveVideo[]; // OfferToReceiveVideo |
| 77 | static const char kOfferToReceiveAudio[]; // OfferToReceiveAudio |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 78 | static const char kVoiceActivityDetection[]; // VoiceActivityDetection |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 79 | static const char kIceRestart[]; // IceRestart |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 80 | // These keys are google specific. |
| 81 | static const char kUseRtpMux[]; // googUseRtpMUX |
| 82 | |
| 83 | // Constraints values. |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 84 | static const char kValueTrue[]; // true |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 85 | static const char kValueFalse[]; // false |
| 86 | |
wu@webrtc.org | 1481491 | 2014-04-02 23:25:15 | [diff] [blame] | 87 | // PeerConnection constraint keys. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 88 | // Temporary pseudo-constraints used to enable DTLS-SRTP |
| 89 | static const char kEnableDtlsSrtp[]; // Enable DTLS-SRTP |
| 90 | // Temporary pseudo-constraints used to enable DataChannels |
| 91 | static const char kEnableRtpDataChannels[]; // Enable RTP DataChannels |
wu@webrtc.org | 1481491 | 2014-04-02 23:25:15 | [diff] [blame] | 92 | // Google-specific constraint keys. |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 | [diff] [blame] | 93 | // Temporary pseudo-constraint for enabling DSCP through JS. |
wu@webrtc.org | 1481491 | 2014-04-02 23:25:15 | [diff] [blame] | 94 | static const char kEnableDscp[]; // googDscp |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 | [diff] [blame] | 95 | // Constraint to enable IPv6 through JS. |
wu@webrtc.org | 1481491 | 2014-04-02 23:25:15 | [diff] [blame] | 96 | static const char kEnableIPv6[]; // googIPv6 |
henrike@webrtc.org | 6e3dbc2 | 2014-03-25 17:09:47 | [diff] [blame] | 97 | // Temporary constraint to enable suspend below min bitrate feature. |
| 98 | static const char kEnableVideoSuspendBelowMinBitrate[]; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 99 | // googSuspendBelowMinBitrate |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 | [diff] [blame] | 100 | // Constraint to enable combined audio+video bandwidth estimation. |
| 101 | static const char kCombinedAudioVideoBwe[]; // googCombinedAudioVideoBwe |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 102 | static const char kScreencastMinBitrate[]; // googScreencastMinBitrate |
| 103 | static const char kCpuOveruseDetection[]; // googCpuOveruseDetection |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 104 | |
Mirta Dvornicic | 479a3c0 | 2019-06-04 13:38:50 | [diff] [blame] | 105 | // Constraint to enable negotiating raw RTP packetization using attribute |
| 106 | // "a=packetization:<payload_type> raw" in the SDP for all video payload. |
| 107 | static const char kRawPacketizationForVideoEnabled[]; |
| 108 | |
Jonas Oreland | fc1acd2 | 2018-08-24 08:58:37 | [diff] [blame] | 109 | // Specifies number of simulcast layers for all video tracks |
| 110 | // with a Plan B offer/answer |
| 111 | // (see RTCOfferAnswerOptions::num_simulcast_layers). |
| 112 | static const char kNumSimulcastLayers[]; |
| 113 | |
Niels Möller | dac03d9 | 2019-02-13 07:52:27 | [diff] [blame] | 114 | ~MediaConstraints() = default; |
Magnus Jedvert | 3ecdd0f | 2017-11-24 10:21:14 | [diff] [blame] | 115 | |
Niels Möller | dac03d9 | 2019-02-13 07:52:27 | [diff] [blame] | 116 | const Constraints& GetMandatory() const { return mandatory_; } |
| 117 | const Constraints& GetOptional() const { return optional_; } |
| 118 | |
| 119 | private: |
| 120 | const Constraints mandatory_ = {}; |
| 121 | const Constraints optional_ = {}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 122 | }; |
| 123 | |
hta | a2a49d9 | 2016-03-04 10:51:39 | [diff] [blame] | 124 | // Copy all relevant constraints into an RTCConfiguration object. |
| 125 | void CopyConstraintsIntoRtcConfiguration( |
Niels Möller | dac03d9 | 2019-02-13 07:52:27 | [diff] [blame] | 126 | const MediaConstraints* constraints, |
hta | a2a49d9 | 2016-03-04 10:51:39 | [diff] [blame] | 127 | PeerConnectionInterface::RTCConfiguration* configuration); |
| 128 | |
deadbeef | fe0fd41 | 2017-01-13 19:47:56 | [diff] [blame] | 129 | // Copy all relevant constraints into an AudioOptions object. |
Niels Möller | dac03d9 | 2019-02-13 07:52:27 | [diff] [blame] | 130 | void CopyConstraintsIntoAudioOptions(const MediaConstraints* constraints, |
| 131 | cricket::AudioOptions* options); |
deadbeef | fe0fd41 | 2017-01-13 19:47:56 | [diff] [blame] | 132 | |
Niels Möller | f06f923 | 2018-08-07 10:32:18 | [diff] [blame] | 133 | bool CopyConstraintsIntoOfferAnswerOptions( |
Niels Möller | dac03d9 | 2019-02-13 07:52:27 | [diff] [blame] | 134 | const MediaConstraints* constraints, |
Niels Möller | f06f923 | 2018-08-07 10:32:18 | [diff] [blame] | 135 | PeerConnectionInterface::RTCOfferAnswerOptions* offer_answer_options); |
| 136 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 137 | } // namespace webrtc |
| 138 | |
Niels Möller | dac03d9 | 2019-02-13 07:52:27 | [diff] [blame] | 139 | #endif // SDK_MEDIA_CONSTRAINTS_H_ |