blob: 560fa4a49e086b4af971c5aac7ed9b0d2649e547 [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
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öllerf06f9232018-08-07 12:32:18 +020016// 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
htaa2a49d92016-03-04 02:51:39 -080020
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#ifndef API_MEDIACONSTRAINTSINTERFACE_H_
22#define API_MEDIACONSTRAINTSINTERFACE_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000023
24#include <string>
25#include <vector>
26
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020027#include "api/peerconnectioninterface.h"
htaa2a49d92016-03-04 02:51:39 -080028
henrike@webrtc.org28e20752013-07-10 00:45:36 +000029namespace webrtc {
30
henrike@webrtc.org28e20752013-07-10 00:45:36 +000031// Interface used for passing arguments about media constraints
32// to the MediaStream and PeerConnection implementation.
deadbeefb10f32f2017-02-08 01:38:21 -080033//
34// Constraints may be either "mandatory", which means that unless satisfied,
35// the method taking the constraints should fail, or "optional", which means
36// they may not be satisfied..
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037class MediaConstraintsInterface {
38 public:
39 struct Constraint {
40 Constraint() {}
41 Constraint(const std::string& key, const std::string value)
Yves Gerey665174f2018-06-19 15:03:05 +020042 : key(key), value(value) {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +000043 std::string key;
44 std::string value;
45 };
46
47 class Constraints : public std::vector<Constraint> {
48 public:
49 bool FindFirst(const std::string& key, std::string* value) const;
50 };
51
henrike@webrtc.org28e20752013-07-10 00:45:36 +000052 // Constraint keys used by a local video source.
53 // Specified by draft-alvestrand-constraints-resolution-00b
54 static const char kMinAspectRatio[]; // minAspectRatio
55 static const char kMaxAspectRatio[]; // maxAspectRatio
Yves Gerey665174f2018-06-19 15:03:05 +020056 static const char kMaxWidth[]; // maxWidth
57 static const char kMinWidth[]; // minWidth
58 static const char kMaxHeight[]; // maxHeight
59 static const char kMinHeight[]; // minHeight
60 static const char kMaxFrameRate[]; // maxFrameRate
61 static const char kMinFrameRate[]; // minFrameRate
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062
63 // Constraint keys used by a local audio source.
tommi39b31002015-06-23 09:50:47 -070064 static const char kEchoCancellation[]; // echoCancellation
65
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066 // These keys are google specific.
Tommi70c7fe12015-06-15 09:14:03 +020067 static const char kGoogEchoCancellation[]; // googEchoCancellation
68
Henrik Lundin441f6342015-06-09 16:03:13 +020069 static const char kExtendedFilterEchoCancellation[]; // googEchoCancellation2
Yves Gerey665174f2018-06-19 15:03:05 +020070 static const char kDAEchoCancellation[]; // googDAEchoCancellation
71 static const char kAutoGainControl[]; // googAutoGainControl
72 static const char kExperimentalAutoGainControl[]; // googAutoGainControl2
73 static const char kNoiseSuppression[]; // googNoiseSuppression
sergeyu@chromium.org9cf037b2014-02-07 19:03:26 +000074 static const char kExperimentalNoiseSuppression[]; // googNoiseSuppression2
Yves Gerey665174f2018-06-19 15:03:05 +020075 static const char kHighpassFilter[]; // googHighpassFilter
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +000076 static const char kTypingNoiseDetection[]; // googTypingNoiseDetection
Yves Gerey665174f2018-06-19 15:03:05 +020077 static const char kAudioMirroring[]; // googAudioMirroring
minyueba414282016-12-11 02:17:52 -080078 static const char
79 kAudioNetworkAdaptorConfig[]; // goodAudioNetworkAdaptorConfig
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080
81 // Google-specific constraint keys for a local video source
82 static const char kNoiseReduction[]; // googNoiseReduction
henrike@webrtc.orgdce3feb2014-03-26 01:17:30 +000083
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084 // Constraint keys for CreateOffer / CreateAnswer
85 // Specified by the W3C PeerConnection spec
Yves Gerey665174f2018-06-19 15:03:05 +020086 static const char kOfferToReceiveVideo[]; // OfferToReceiveVideo
87 static const char kOfferToReceiveAudio[]; // OfferToReceiveAudio
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088 static const char kVoiceActivityDetection[]; // VoiceActivityDetection
Yves Gerey665174f2018-06-19 15:03:05 +020089 static const char kIceRestart[]; // IceRestart
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090 // These keys are google specific.
91 static const char kUseRtpMux[]; // googUseRtpMUX
92
93 // Constraints values.
Yves Gerey665174f2018-06-19 15:03:05 +020094 static const char kValueTrue[]; // true
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095 static const char kValueFalse[]; // false
96
wu@webrtc.org14814912014-04-02 23:25:15 +000097 // PeerConnection constraint keys.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000098 // Temporary pseudo-constraints used to enable DTLS-SRTP
99 static const char kEnableDtlsSrtp[]; // Enable DTLS-SRTP
100 // Temporary pseudo-constraints used to enable DataChannels
101 static const char kEnableRtpDataChannels[]; // Enable RTP DataChannels
wu@webrtc.org14814912014-04-02 23:25:15 +0000102 // Google-specific constraint keys.
wu@webrtc.orgde305012013-10-31 15:40:38 +0000103 // Temporary pseudo-constraint for enabling DSCP through JS.
wu@webrtc.org14814912014-04-02 23:25:15 +0000104 static const char kEnableDscp[]; // googDscp
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +0000105 // Constraint to enable IPv6 through JS.
wu@webrtc.org14814912014-04-02 23:25:15 +0000106 static const char kEnableIPv6[]; // googIPv6
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +0000107 // Temporary constraint to enable suspend below min bitrate feature.
108 static const char kEnableVideoSuspendBelowMinBitrate[];
Yves Gerey665174f2018-06-19 15:03:05 +0200109 // googSuspendBelowMinBitrate
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +0000110 // Constraint to enable combined audio+video bandwidth estimation.
111 static const char kCombinedAudioVideoBwe[]; // googCombinedAudioVideoBwe
Yves Gerey665174f2018-06-19 15:03:05 +0200112 static const char kScreencastMinBitrate[]; // googScreencastMinBitrate
113 static const char kCpuOveruseDetection[]; // googCpuOveruseDetection
114 static const char kPayloadPadding[]; // googPayloadPadding
buildbot@webrtc.orgd27d9ae2014-06-19 01:56:46 +0000115
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116 // The prefix of internal-only constraints whose JS set values should be
117 // stripped by Chrome before passed down to Libjingle.
118 static const char kInternalConstraintPrefix[];
119
Jonas Orelandfc1acd22018-08-24 10:58:37 +0200120 // Specifies number of simulcast layers for all video tracks
121 // with a Plan B offer/answer
122 // (see RTCOfferAnswerOptions::num_simulcast_layers).
123 static const char kNumSimulcastLayers[];
124
Magnus Jedvert3ecdd0f2017-11-24 11:21:14 +0100125 virtual ~MediaConstraintsInterface() = default;
126
127 virtual const Constraints& GetMandatory() const = 0;
128 virtual const Constraints& GetOptional() const = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000129};
130
131bool FindConstraint(const MediaConstraintsInterface* constraints,
Yves Gerey665174f2018-06-19 15:03:05 +0200132 const std::string& key,
133 bool* value,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000134 size_t* mandatory_constraints);
135
htaa2a49d92016-03-04 02:51:39 -0800136bool FindConstraint(const MediaConstraintsInterface* constraints,
137 const std::string& key,
138 int* value,
139 size_t* mandatory_constraints);
140
141// Copy all relevant constraints into an RTCConfiguration object.
142void CopyConstraintsIntoRtcConfiguration(
143 const MediaConstraintsInterface* constraints,
144 PeerConnectionInterface::RTCConfiguration* configuration);
145
deadbeeffe0fd412017-01-13 11:47:56 -0800146// Copy all relevant constraints into an AudioOptions object.
147void CopyConstraintsIntoAudioOptions(
148 const MediaConstraintsInterface* constraints,
149 cricket::AudioOptions* options);
150
Niels Möllerf06f9232018-08-07 12:32:18 +0200151bool CopyConstraintsIntoOfferAnswerOptions(
152 const MediaConstraintsInterface* constraints,
153 PeerConnectionInterface::RTCOfferAnswerOptions* offer_answer_options);
154
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000155} // namespace webrtc
156
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200157#endif // API_MEDIACONSTRAINTSINTERFACE_H_