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 | |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [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 02:51:39 -0800 | [diff] [blame] | 15 | |
Niels Möller | dac03d9 | 2019-02-13 08:52:27 +0100 | [diff] [blame] | 16 | #ifndef SDK_MEDIA_CONSTRAINTS_H_ |
| 17 | #define SDK_MEDIA_CONSTRAINTS_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 18 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 19 | #include <stddef.h> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 20 | #include <string> |
Niels Möller | dac03d9 | 2019-02-13 08:52:27 +0100 | [diff] [blame] | 21 | #include <utility> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 22 | #include <vector> |
| 23 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 24 | #include "api/audio_options.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 25 | #include "api/peer_connection_interface.h" |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 26 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 27 | namespace webrtc { |
| 28 | |
Niels Möller | dac03d9 | 2019-02-13 08:52:27 +0100 | [diff] [blame] | 29 | // Class representing constraints, as used by the android and objc apis. |
deadbeef | b10f32f | 2017-02-08 01:38:21 -0800 | [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 08:52:27 +0100 | [diff] [blame] | 34 | class MediaConstraints { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [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 15:03:05 +0200 | [diff] [blame] | 39 | : key(key), value(value) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [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 08:52:27 +0100 | [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 +0000 | [diff] [blame] | 50 | bool FindFirst(const std::string& key, std::string* value) const; |
| 51 | }; |
| 52 | |
Niels Möller | dac03d9 | 2019-02-13 08:52:27 +0100 | [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 +0000 | [diff] [blame] | 57 | // Constraint keys used by a local audio source. |
tommi | 39b3100 | 2015-06-23 09:50:47 -0700 | [diff] [blame] | 58 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 59 | // These keys are google specific. |
Tommi | 70c7fe1 | 2015-06-15 09:14:03 +0200 | [diff] [blame] | 60 | static const char kGoogEchoCancellation[]; // googEchoCancellation |
| 61 | |
Henrik Lundin | 441f634 | 2015-06-09 16:03:13 +0200 | [diff] [blame] | 62 | static const char kExtendedFilterEchoCancellation[]; // googEchoCancellation2 |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [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 +0000 | [diff] [blame] | 67 | static const char kExperimentalNoiseSuppression[]; // googNoiseSuppression2 |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 68 | static const char kHighpassFilter[]; // googHighpassFilter |
sergeyu@chromium.org | a59696b | 2013-09-13 23:48:58 +0000 | [diff] [blame] | 69 | static const char kTypingNoiseDetection[]; // googTypingNoiseDetection |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 70 | static const char kAudioMirroring[]; // googAudioMirroring |
minyue | ba41428 | 2016-12-11 02:17:52 -0800 | [diff] [blame] | 71 | static const char |
| 72 | kAudioNetworkAdaptorConfig[]; // goodAudioNetworkAdaptorConfig |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 73 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 74 | // Constraint keys for CreateOffer / CreateAnswer |
| 75 | // Specified by the W3C PeerConnection spec |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 76 | static const char kOfferToReceiveVideo[]; // OfferToReceiveVideo |
| 77 | static const char kOfferToReceiveAudio[]; // OfferToReceiveAudio |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 78 | static const char kVoiceActivityDetection[]; // VoiceActivityDetection |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 79 | static const char kIceRestart[]; // IceRestart |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 80 | // These keys are google specific. |
| 81 | static const char kUseRtpMux[]; // googUseRtpMUX |
| 82 | |
| 83 | // Constraints values. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 84 | static const char kValueTrue[]; // true |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 85 | static const char kValueFalse[]; // false |
| 86 | |
wu@webrtc.org | 1481491 | 2014-04-02 23:25:15 +0000 | [diff] [blame] | 87 | // PeerConnection constraint keys. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [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 +0000 | [diff] [blame] | 92 | // Google-specific constraint keys. |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 93 | // Temporary pseudo-constraint for enabling DSCP through JS. |
wu@webrtc.org | 1481491 | 2014-04-02 23:25:15 +0000 | [diff] [blame] | 94 | static const char kEnableDscp[]; // googDscp |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 95 | // Constraint to enable IPv6 through JS. |
wu@webrtc.org | 1481491 | 2014-04-02 23:25:15 +0000 | [diff] [blame] | 96 | static const char kEnableIPv6[]; // googIPv6 |
henrike@webrtc.org | 6e3dbc2 | 2014-03-25 17:09:47 +0000 | [diff] [blame] | 97 | // Temporary constraint to enable suspend below min bitrate feature. |
| 98 | static const char kEnableVideoSuspendBelowMinBitrate[]; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 99 | // googSuspendBelowMinBitrate |
buildbot@webrtc.org | b4c7b09 | 2014-08-25 12:11:58 +0000 | [diff] [blame] | 100 | // Constraint to enable combined audio+video bandwidth estimation. |
| 101 | static const char kCombinedAudioVideoBwe[]; // googCombinedAudioVideoBwe |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 102 | static const char kScreencastMinBitrate[]; // googScreencastMinBitrate |
| 103 | static const char kCpuOveruseDetection[]; // googCpuOveruseDetection |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 104 | |
Jonas Oreland | fc1acd2 | 2018-08-24 10:58:37 +0200 | [diff] [blame] | 105 | // Specifies number of simulcast layers for all video tracks |
| 106 | // with a Plan B offer/answer |
| 107 | // (see RTCOfferAnswerOptions::num_simulcast_layers). |
| 108 | static const char kNumSimulcastLayers[]; |
| 109 | |
Niels Möller | dac03d9 | 2019-02-13 08:52:27 +0100 | [diff] [blame] | 110 | ~MediaConstraints() = default; |
Magnus Jedvert | 3ecdd0f | 2017-11-24 11:21:14 +0100 | [diff] [blame] | 111 | |
Niels Möller | dac03d9 | 2019-02-13 08:52:27 +0100 | [diff] [blame] | 112 | const Constraints& GetMandatory() const { return mandatory_; } |
| 113 | const Constraints& GetOptional() const { return optional_; } |
| 114 | |
| 115 | private: |
| 116 | const Constraints mandatory_ = {}; |
| 117 | const Constraints optional_ = {}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 118 | }; |
| 119 | |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 120 | // Copy all relevant constraints into an RTCConfiguration object. |
| 121 | void CopyConstraintsIntoRtcConfiguration( |
Niels Möller | dac03d9 | 2019-02-13 08:52:27 +0100 | [diff] [blame] | 122 | const MediaConstraints* constraints, |
hta | a2a49d9 | 2016-03-04 02:51:39 -0800 | [diff] [blame] | 123 | PeerConnectionInterface::RTCConfiguration* configuration); |
| 124 | |
deadbeef | fe0fd41 | 2017-01-13 11:47:56 -0800 | [diff] [blame] | 125 | // Copy all relevant constraints into an AudioOptions object. |
Niels Möller | dac03d9 | 2019-02-13 08:52:27 +0100 | [diff] [blame] | 126 | void CopyConstraintsIntoAudioOptions(const MediaConstraints* constraints, |
| 127 | cricket::AudioOptions* options); |
deadbeef | fe0fd41 | 2017-01-13 11:47:56 -0800 | [diff] [blame] | 128 | |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 129 | bool CopyConstraintsIntoOfferAnswerOptions( |
Niels Möller | dac03d9 | 2019-02-13 08:52:27 +0100 | [diff] [blame] | 130 | const MediaConstraints* constraints, |
Niels Möller | f06f923 | 2018-08-07 12:32:18 +0200 | [diff] [blame] | 131 | PeerConnectionInterface::RTCOfferAnswerOptions* offer_answer_options); |
| 132 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 133 | } // namespace webrtc |
| 134 | |
Niels Möller | dac03d9 | 2019-02-13 08:52:27 +0100 | [diff] [blame] | 135 | #endif // SDK_MEDIA_CONSTRAINTS_H_ |