blob: c946e4fab1dd1a6b8585dc70f0df1b937c5a6f05 [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
Alessio Bazzica93348d82022-02-14 10:21:31 +010062 static const char kAutoGainControl[]; // googAutoGainControl
63 static const char kNoiseSuppression[]; // googNoiseSuppression
64 static const char kHighpassFilter[]; // googHighpassFilter
Yves Gerey665174f2018-06-19 15:03:05 +020065 static const char kAudioMirroring[]; // googAudioMirroring
minyueba414282016-12-11 02:17:52 -080066 static const char
Xavier Lepaul1e12f2a2022-01-13 17:06:26 +010067 kAudioNetworkAdaptorConfig[]; // googAudioNetworkAdaptorConfig
68 static const char kInitAudioRecordingOnSend[]; // InitAudioRecordingOnSend;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000069
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070 // Constraint keys for CreateOffer / CreateAnswer
71 // Specified by the W3C PeerConnection spec
Yves Gerey665174f2018-06-19 15:03:05 +020072 static const char kOfferToReceiveVideo[]; // OfferToReceiveVideo
73 static const char kOfferToReceiveAudio[]; // OfferToReceiveAudio
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074 static const char kVoiceActivityDetection[]; // VoiceActivityDetection
Yves Gerey665174f2018-06-19 15:03:05 +020075 static const char kIceRestart[]; // IceRestart
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076 // These keys are google specific.
77 static const char kUseRtpMux[]; // googUseRtpMUX
78
79 // Constraints values.
Yves Gerey665174f2018-06-19 15:03:05 +020080 static const char kValueTrue[]; // true
henrike@webrtc.org28e20752013-07-10 00:45:36 +000081 static const char kValueFalse[]; // false
82
wu@webrtc.org14814912014-04-02 23:25:15 +000083 // PeerConnection constraint keys.
wu@webrtc.org14814912014-04-02 23:25:15 +000084 // Google-specific constraint keys.
wu@webrtc.orgde305012013-10-31 15:40:38 +000085 // Temporary pseudo-constraint for enabling DSCP through JS.
wu@webrtc.org14814912014-04-02 23:25:15 +000086 static const char kEnableDscp[]; // googDscp
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +000087 // Constraint to enable IPv6 through JS.
wu@webrtc.org14814912014-04-02 23:25:15 +000088 static const char kEnableIPv6[]; // googIPv6
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +000089 // Temporary constraint to enable suspend below min bitrate feature.
90 static const char kEnableVideoSuspendBelowMinBitrate[];
Yves Gerey665174f2018-06-19 15:03:05 +020091 // googSuspendBelowMinBitrate
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +000092 // Constraint to enable combined audio+video bandwidth estimation.
93 static const char kCombinedAudioVideoBwe[]; // googCombinedAudioVideoBwe
Yves Gerey665174f2018-06-19 15:03:05 +020094 static const char kScreencastMinBitrate[]; // googScreencastMinBitrate
95 static const char kCpuOveruseDetection[]; // googCpuOveruseDetection
henrike@webrtc.org28e20752013-07-10 00:45:36 +000096
Mirta Dvornicic479a3c02019-06-04 15:38:50 +020097 // Constraint to enable negotiating raw RTP packetization using attribute
98 // "a=packetization:<payload_type> raw" in the SDP for all video payload.
99 static const char kRawPacketizationForVideoEnabled[];
100
Jonas Orelandfc1acd22018-08-24 10:58:37 +0200101 // Specifies number of simulcast layers for all video tracks
102 // with a Plan B offer/answer
103 // (see RTCOfferAnswerOptions::num_simulcast_layers).
104 static const char kNumSimulcastLayers[];
105
Niels Möllerdac03d92019-02-13 08:52:27 +0100106 ~MediaConstraints() = default;
Magnus Jedvert3ecdd0f2017-11-24 11:21:14 +0100107
Niels Möllerdac03d92019-02-13 08:52:27 +0100108 const Constraints& GetMandatory() const { return mandatory_; }
109 const Constraints& GetOptional() const { return optional_; }
110
111 private:
112 const Constraints mandatory_ = {};
113 const Constraints optional_ = {};
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000114};
115
htaa2a49d92016-03-04 02:51:39 -0800116// Copy all relevant constraints into an RTCConfiguration object.
117void CopyConstraintsIntoRtcConfiguration(
Niels Möllerdac03d92019-02-13 08:52:27 +0100118 const MediaConstraints* constraints,
htaa2a49d92016-03-04 02:51:39 -0800119 PeerConnectionInterface::RTCConfiguration* configuration);
120
deadbeeffe0fd412017-01-13 11:47:56 -0800121// Copy all relevant constraints into an AudioOptions object.
Niels Möllerdac03d92019-02-13 08:52:27 +0100122void CopyConstraintsIntoAudioOptions(const MediaConstraints* constraints,
123 cricket::AudioOptions* options);
deadbeeffe0fd412017-01-13 11:47:56 -0800124
Niels Möllerf06f9232018-08-07 12:32:18 +0200125bool CopyConstraintsIntoOfferAnswerOptions(
Niels Möllerdac03d92019-02-13 08:52:27 +0100126 const MediaConstraints* constraints,
Niels Möllerf06f9232018-08-07 12:32:18 +0200127 PeerConnectionInterface::RTCOfferAnswerOptions* offer_answer_options);
128
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000129} // namespace webrtc
130
Niels Möllerdac03d92019-02-13 08:52:27 +0100131#endif // SDK_MEDIA_CONSTRAINTS_H_