blob: 3a151417eb2425907cdf5b0432104dfe4c395ffc [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2013 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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.org28e20752013-07-10 00:45:36 +00009 */
10
Niels Möllerf06f9232018-08-07 12:32:18 +020011// 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
htaa2a49d92016-03-04 02:51:39 -080015
Niels Möllerdac03d92019-02-13 08:52:27 +010016#ifndef SDK_MEDIA_CONSTRAINTS_H_
17#define SDK_MEDIA_CONSTRAINTS_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000018
Yves Gerey988cc082018-10-23 12:03:01 +020019#include <stddef.h>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000020#include <string>
Niels Möllerdac03d92019-02-13 08:52:27 +010021#include <utility>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000022#include <vector>
23
Yves Gerey988cc082018-10-23 12:03:01 +020024#include "api/audio_options.h"
Steve Anton10542f22019-01-11 09:11:00 -080025#include "api/peer_connection_interface.h"
htaa2a49d92016-03-04 02:51:39 -080026
henrike@webrtc.org28e20752013-07-10 00:45:36 +000027namespace webrtc {
28
Niels Möllerdac03d92019-02-13 08:52:27 +010029// Class representing constraints, as used by the android and objc apis.
deadbeefb10f32f2017-02-08 01:38:21 -080030//
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öllerdac03d92019-02-13 08:52:27 +010034class MediaConstraints {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000035 public:
36 struct Constraint {
37 Constraint() {}
38 Constraint(const std::string& key, const std::string value)
Yves Gerey665174f2018-06-19 15:03:05 +020039 : key(key), value(value) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +000040 std::string key;
41 std::string value;
42 };
43
44 class Constraints : public std::vector<Constraint> {
45 public:
Niels Möllerdac03d92019-02-13 08:52:27 +010046 Constraints() = default;
47 Constraints(std::initializer_list<Constraint> l)
48 : std::vector<Constraint>(l) {}
49
henrike@webrtc.org28e20752013-07-10 00:45:36 +000050 bool FindFirst(const std::string& key, std::string* value) const;
51 };
52
Niels Möllerdac03d92019-02-13 08:52:27 +010053 MediaConstraints() = default;
54 MediaConstraints(Constraints mandatory, Constraints optional)
55 : mandatory_(std::move(mandatory)), optional_(std::move(optional)) {}
56
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057 // Constraint keys used by a local audio source.
tommi39b31002015-06-23 09:50:47 -070058
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059 // These keys are google specific.
Tommi70c7fe12015-06-15 09:14:03 +020060 static const char kGoogEchoCancellation[]; // googEchoCancellation
61
Henrik Lundin441f6342015-06-09 16:03:13 +020062 static const char kExtendedFilterEchoCancellation[]; // googEchoCancellation2
Yves Gerey665174f2018-06-19 15:03:05 +020063 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.org9cf037b2014-02-07 19:03:26 +000067 static const char kExperimentalNoiseSuppression[]; // googNoiseSuppression2
Yves Gerey665174f2018-06-19 15:03:05 +020068 static const char kHighpassFilter[]; // googHighpassFilter
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +000069 static const char kTypingNoiseDetection[]; // googTypingNoiseDetection
Yves Gerey665174f2018-06-19 15:03:05 +020070 static const char kAudioMirroring[]; // googAudioMirroring
minyueba414282016-12-11 02:17:52 -080071 static const char
72 kAudioNetworkAdaptorConfig[]; // goodAudioNetworkAdaptorConfig
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074 // Constraint keys for CreateOffer / CreateAnswer
75 // Specified by the W3C PeerConnection spec
Yves Gerey665174f2018-06-19 15:03:05 +020076 static const char kOfferToReceiveVideo[]; // OfferToReceiveVideo
77 static const char kOfferToReceiveAudio[]; // OfferToReceiveAudio
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078 static const char kVoiceActivityDetection[]; // VoiceActivityDetection
Yves Gerey665174f2018-06-19 15:03:05 +020079 static const char kIceRestart[]; // IceRestart
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080 // These keys are google specific.
81 static const char kUseRtpMux[]; // googUseRtpMUX
82
83 // Constraints values.
Yves Gerey665174f2018-06-19 15:03:05 +020084 static const char kValueTrue[]; // true
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085 static const char kValueFalse[]; // false
86
wu@webrtc.org14814912014-04-02 23:25:15 +000087 // PeerConnection constraint keys.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088 // 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.org14814912014-04-02 23:25:15 +000092 // Google-specific constraint keys.
wu@webrtc.orgde305012013-10-31 15:40:38 +000093 // Temporary pseudo-constraint for enabling DSCP through JS.
wu@webrtc.org14814912014-04-02 23:25:15 +000094 static const char kEnableDscp[]; // googDscp
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +000095 // Constraint to enable IPv6 through JS.
wu@webrtc.org14814912014-04-02 23:25:15 +000096 static const char kEnableIPv6[]; // googIPv6
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +000097 // Temporary constraint to enable suspend below min bitrate feature.
98 static const char kEnableVideoSuspendBelowMinBitrate[];
Yves Gerey665174f2018-06-19 15:03:05 +020099 // googSuspendBelowMinBitrate
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000100 // Constraint to enable combined audio+video bandwidth estimation.
101 static const char kCombinedAudioVideoBwe[]; // googCombinedAudioVideoBwe
Yves Gerey665174f2018-06-19 15:03:05 +0200102 static const char kScreencastMinBitrate[]; // googScreencastMinBitrate
103 static const char kCpuOveruseDetection[]; // googCpuOveruseDetection
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000104
Jonas Orelandfc1acd22018-08-24 10:58:37 +0200105 // 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öllerdac03d92019-02-13 08:52:27 +0100110 ~MediaConstraints() = default;
Magnus Jedvert3ecdd0f2017-11-24 11:21:14 +0100111
Niels Möllerdac03d92019-02-13 08:52:27 +0100112 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.org28e20752013-07-10 00:45:36 +0000118};
119
htaa2a49d92016-03-04 02:51:39 -0800120// Copy all relevant constraints into an RTCConfiguration object.
121void CopyConstraintsIntoRtcConfiguration(
Niels Möllerdac03d92019-02-13 08:52:27 +0100122 const MediaConstraints* constraints,
htaa2a49d92016-03-04 02:51:39 -0800123 PeerConnectionInterface::RTCConfiguration* configuration);
124
deadbeeffe0fd412017-01-13 11:47:56 -0800125// Copy all relevant constraints into an AudioOptions object.
Niels Möllerdac03d92019-02-13 08:52:27 +0100126void CopyConstraintsIntoAudioOptions(const MediaConstraints* constraints,
127 cricket::AudioOptions* options);
deadbeeffe0fd412017-01-13 11:47:56 -0800128
Niels Möllerf06f9232018-08-07 12:32:18 +0200129bool CopyConstraintsIntoOfferAnswerOptions(
Niels Möllerdac03d92019-02-13 08:52:27 +0100130 const MediaConstraints* constraints,
Niels Möllerf06f9232018-08-07 12:32:18 +0200131 PeerConnectionInterface::RTCOfferAnswerOptions* offer_answer_options);
132
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000133} // namespace webrtc
134
Niels Möllerdac03d92019-02-13 08:52:27 +0100135#endif // SDK_MEDIA_CONSTRAINTS_H_