blob: b85dc472e01dbd4e2047849c444c7b56de4283b7 [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
Yves Gerey665174f2018-06-19 15:03:05 +020062 static const char kAutoGainControl[]; // googAutoGainControl
63 static const char kExperimentalAutoGainControl[]; // googAutoGainControl2
64 static const char kNoiseSuppression[]; // googNoiseSuppression
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +000065 static const char kExperimentalNoiseSuppression[]; // googNoiseSuppression2
Yves Gerey665174f2018-06-19 15:03:05 +020066 static const char kHighpassFilter[]; // googHighpassFilter
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +000067 static const char kTypingNoiseDetection[]; // googTypingNoiseDetection
Yves Gerey665174f2018-06-19 15:03:05 +020068 static const char kAudioMirroring[]; // googAudioMirroring
minyueba414282016-12-11 02:17:52 -080069 static const char
70 kAudioNetworkAdaptorConfig[]; // goodAudioNetworkAdaptorConfig
henrike@webrtc.org28e20752013-07-10 00:45:36 +000071
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072 // Constraint keys for CreateOffer / CreateAnswer
73 // Specified by the W3C PeerConnection spec
Yves Gerey665174f2018-06-19 15:03:05 +020074 static const char kOfferToReceiveVideo[]; // OfferToReceiveVideo
75 static const char kOfferToReceiveAudio[]; // OfferToReceiveAudio
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076 static const char kVoiceActivityDetection[]; // VoiceActivityDetection
Yves Gerey665174f2018-06-19 15:03:05 +020077 static const char kIceRestart[]; // IceRestart
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078 // These keys are google specific.
79 static const char kUseRtpMux[]; // googUseRtpMUX
80
81 // Constraints values.
Yves Gerey665174f2018-06-19 15:03:05 +020082 static const char kValueTrue[]; // true
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083 static const char kValueFalse[]; // false
84
wu@webrtc.org14814912014-04-02 23:25:15 +000085 // PeerConnection constraint keys.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086 // Temporary pseudo-constraints used to enable DTLS-SRTP
87 static const char kEnableDtlsSrtp[]; // Enable DTLS-SRTP
88 // Temporary pseudo-constraints used to enable DataChannels
89 static const char kEnableRtpDataChannels[]; // Enable RTP DataChannels
wu@webrtc.org14814912014-04-02 23:25:15 +000090 // Google-specific constraint keys.
wu@webrtc.orgde305012013-10-31 15:40:38 +000091 // Temporary pseudo-constraint for enabling DSCP through JS.
wu@webrtc.org14814912014-04-02 23:25:15 +000092 static const char kEnableDscp[]; // googDscp
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +000093 // Constraint to enable IPv6 through JS.
wu@webrtc.org14814912014-04-02 23:25:15 +000094 static const char kEnableIPv6[]; // googIPv6
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +000095 // Temporary constraint to enable suspend below min bitrate feature.
96 static const char kEnableVideoSuspendBelowMinBitrate[];
Yves Gerey665174f2018-06-19 15:03:05 +020097 // googSuspendBelowMinBitrate
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +000098 // Constraint to enable combined audio+video bandwidth estimation.
99 static const char kCombinedAudioVideoBwe[]; // googCombinedAudioVideoBwe
Yves Gerey665174f2018-06-19 15:03:05 +0200100 static const char kScreencastMinBitrate[]; // googScreencastMinBitrate
101 static const char kCpuOveruseDetection[]; // googCpuOveruseDetection
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102
Mirta Dvornicic479a3c02019-06-04 15:38:50 +0200103 // Constraint to enable negotiating raw RTP packetization using attribute
104 // "a=packetization:<payload_type> raw" in the SDP for all video payload.
105 static const char kRawPacketizationForVideoEnabled[];
106
Jonas Orelandfc1acd22018-08-24 10:58:37 +0200107 // Specifies number of simulcast layers for all video tracks
108 // with a Plan B offer/answer
109 // (see RTCOfferAnswerOptions::num_simulcast_layers).
110 static const char kNumSimulcastLayers[];
111
Niels Möllerdac03d92019-02-13 08:52:27 +0100112 ~MediaConstraints() = default;
Magnus Jedvert3ecdd0f2017-11-24 11:21:14 +0100113
Niels Möllerdac03d92019-02-13 08:52:27 +0100114 const Constraints& GetMandatory() const { return mandatory_; }
115 const Constraints& GetOptional() const { return optional_; }
116
117 private:
118 const Constraints mandatory_ = {};
119 const Constraints optional_ = {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000120};
121
htaa2a49d92016-03-04 02:51:39 -0800122// Copy all relevant constraints into an RTCConfiguration object.
123void CopyConstraintsIntoRtcConfiguration(
Niels Möllerdac03d92019-02-13 08:52:27 +0100124 const MediaConstraints* constraints,
htaa2a49d92016-03-04 02:51:39 -0800125 PeerConnectionInterface::RTCConfiguration* configuration);
126
deadbeeffe0fd412017-01-13 11:47:56 -0800127// Copy all relevant constraints into an AudioOptions object.
Niels Möllerdac03d92019-02-13 08:52:27 +0100128void CopyConstraintsIntoAudioOptions(const MediaConstraints* constraints,
129 cricket::AudioOptions* options);
deadbeeffe0fd412017-01-13 11:47:56 -0800130
Niels Möllerf06f9232018-08-07 12:32:18 +0200131bool CopyConstraintsIntoOfferAnswerOptions(
Niels Möllerdac03d92019-02-13 08:52:27 +0100132 const MediaConstraints* constraints,
Niels Möllerf06f9232018-08-07 12:32:18 +0200133 PeerConnectionInterface::RTCOfferAnswerOptions* offer_answer_options);
134
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000135} // namespace webrtc
136
Niels Möllerdac03d92019-02-13 08:52:27 +0100137#endif // SDK_MEDIA_CONSTRAINTS_H_