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