xref: /aosp_15_r20/external/webrtc/sdk/media_constraints.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1*d9f75844SAndroid Build Coastguard Worker /*
2*d9f75844SAndroid Build Coastguard Worker  *  Copyright 2013 The WebRTC project authors. All Rights Reserved.
3*d9f75844SAndroid Build Coastguard Worker  *
4*d9f75844SAndroid Build Coastguard Worker  *  Use of this source code is governed by a BSD-style license
5*d9f75844SAndroid Build Coastguard Worker  *  that can be found in the LICENSE file in the root of the source
6*d9f75844SAndroid Build Coastguard Worker  *  tree. An additional intellectual property rights grant can be found
7*d9f75844SAndroid Build Coastguard Worker  *  in the file PATENTS.  All contributing project authors may
8*d9f75844SAndroid Build Coastguard Worker  *  be found in the AUTHORS file in the root of the source tree.
9*d9f75844SAndroid Build Coastguard Worker  */
10*d9f75844SAndroid Build Coastguard Worker 
11*d9f75844SAndroid Build Coastguard Worker // Implementation of the w3c constraints spec is the responsibility of the
12*d9f75844SAndroid Build Coastguard Worker // browser. Chrome no longer uses the constraints api declared here, and it will
13*d9f75844SAndroid Build Coastguard Worker // be removed from WebRTC.
14*d9f75844SAndroid Build Coastguard Worker // https://bugs.chromium.org/p/webrtc/issues/detail?id=9239
15*d9f75844SAndroid Build Coastguard Worker 
16*d9f75844SAndroid Build Coastguard Worker #ifndef SDK_MEDIA_CONSTRAINTS_H_
17*d9f75844SAndroid Build Coastguard Worker #define SDK_MEDIA_CONSTRAINTS_H_
18*d9f75844SAndroid Build Coastguard Worker 
19*d9f75844SAndroid Build Coastguard Worker #include <stddef.h>
20*d9f75844SAndroid Build Coastguard Worker #include <string>
21*d9f75844SAndroid Build Coastguard Worker #include <utility>
22*d9f75844SAndroid Build Coastguard Worker #include <vector>
23*d9f75844SAndroid Build Coastguard Worker 
24*d9f75844SAndroid Build Coastguard Worker #include "api/audio_options.h"
25*d9f75844SAndroid Build Coastguard Worker #include "api/peer_connection_interface.h"
26*d9f75844SAndroid Build Coastguard Worker 
27*d9f75844SAndroid Build Coastguard Worker namespace webrtc {
28*d9f75844SAndroid Build Coastguard Worker 
29*d9f75844SAndroid Build Coastguard Worker // Class representing constraints, as used by the android and objc apis.
30*d9f75844SAndroid Build Coastguard Worker //
31*d9f75844SAndroid Build Coastguard Worker // Constraints may be either "mandatory", which means that unless satisfied,
32*d9f75844SAndroid Build Coastguard Worker // the method taking the constraints should fail, or "optional", which means
33*d9f75844SAndroid Build Coastguard Worker // they may not be satisfied..
34*d9f75844SAndroid Build Coastguard Worker class MediaConstraints {
35*d9f75844SAndroid Build Coastguard Worker  public:
36*d9f75844SAndroid Build Coastguard Worker   struct Constraint {
ConstraintConstraint37*d9f75844SAndroid Build Coastguard Worker     Constraint() {}
ConstraintConstraint38*d9f75844SAndroid Build Coastguard Worker     Constraint(const std::string& key, const std::string value)
39*d9f75844SAndroid Build Coastguard Worker         : key(key), value(value) {}
40*d9f75844SAndroid Build Coastguard Worker     std::string key;
41*d9f75844SAndroid Build Coastguard Worker     std::string value;
42*d9f75844SAndroid Build Coastguard Worker   };
43*d9f75844SAndroid Build Coastguard Worker 
44*d9f75844SAndroid Build Coastguard Worker   class Constraints : public std::vector<Constraint> {
45*d9f75844SAndroid Build Coastguard Worker    public:
46*d9f75844SAndroid Build Coastguard Worker     Constraints() = default;
Constraints(std::initializer_list<Constraint> l)47*d9f75844SAndroid Build Coastguard Worker     Constraints(std::initializer_list<Constraint> l)
48*d9f75844SAndroid Build Coastguard Worker         : std::vector<Constraint>(l) {}
49*d9f75844SAndroid Build Coastguard Worker 
50*d9f75844SAndroid Build Coastguard Worker     bool FindFirst(const std::string& key, std::string* value) const;
51*d9f75844SAndroid Build Coastguard Worker   };
52*d9f75844SAndroid Build Coastguard Worker 
53*d9f75844SAndroid Build Coastguard Worker   MediaConstraints() = default;
MediaConstraints(Constraints mandatory,Constraints optional)54*d9f75844SAndroid Build Coastguard Worker   MediaConstraints(Constraints mandatory, Constraints optional)
55*d9f75844SAndroid Build Coastguard Worker       : mandatory_(std::move(mandatory)), optional_(std::move(optional)) {}
56*d9f75844SAndroid Build Coastguard Worker 
57*d9f75844SAndroid Build Coastguard Worker   // Constraint keys used by a local audio source.
58*d9f75844SAndroid Build Coastguard Worker 
59*d9f75844SAndroid Build Coastguard Worker   // These keys are google specific.
60*d9f75844SAndroid Build Coastguard Worker   static const char kGoogEchoCancellation[];  // googEchoCancellation
61*d9f75844SAndroid Build Coastguard Worker 
62*d9f75844SAndroid Build Coastguard Worker   static const char kAutoGainControl[];       // googAutoGainControl
63*d9f75844SAndroid Build Coastguard Worker   static const char kNoiseSuppression[];      // googNoiseSuppression
64*d9f75844SAndroid Build Coastguard Worker   static const char kHighpassFilter[];        // googHighpassFilter
65*d9f75844SAndroid Build Coastguard Worker   static const char kAudioMirroring[];        // googAudioMirroring
66*d9f75844SAndroid Build Coastguard Worker   static const char
67*d9f75844SAndroid Build Coastguard Worker       kAudioNetworkAdaptorConfig[];  // googAudioNetworkAdaptorConfig
68*d9f75844SAndroid Build Coastguard Worker   static const char kInitAudioRecordingOnSend[];  // InitAudioRecordingOnSend;
69*d9f75844SAndroid Build Coastguard Worker 
70*d9f75844SAndroid Build Coastguard Worker   // Constraint keys for CreateOffer / CreateAnswer
71*d9f75844SAndroid Build Coastguard Worker   // Specified by the W3C PeerConnection spec
72*d9f75844SAndroid Build Coastguard Worker   static const char kOfferToReceiveVideo[];     // OfferToReceiveVideo
73*d9f75844SAndroid Build Coastguard Worker   static const char kOfferToReceiveAudio[];     // OfferToReceiveAudio
74*d9f75844SAndroid Build Coastguard Worker   static const char kVoiceActivityDetection[];  // VoiceActivityDetection
75*d9f75844SAndroid Build Coastguard Worker   static const char kIceRestart[];              // IceRestart
76*d9f75844SAndroid Build Coastguard Worker   // These keys are google specific.
77*d9f75844SAndroid Build Coastguard Worker   static const char kUseRtpMux[];  // googUseRtpMUX
78*d9f75844SAndroid Build Coastguard Worker 
79*d9f75844SAndroid Build Coastguard Worker   // Constraints values.
80*d9f75844SAndroid Build Coastguard Worker   static const char kValueTrue[];   // true
81*d9f75844SAndroid Build Coastguard Worker   static const char kValueFalse[];  // false
82*d9f75844SAndroid Build Coastguard Worker 
83*d9f75844SAndroid Build Coastguard Worker   // PeerConnection constraint keys.
84*d9f75844SAndroid Build Coastguard Worker   // Google-specific constraint keys.
85*d9f75844SAndroid Build Coastguard Worker   // Temporary pseudo-constraint for enabling DSCP through JS.
86*d9f75844SAndroid Build Coastguard Worker   static const char kEnableDscp[];  // googDscp
87*d9f75844SAndroid Build Coastguard Worker   // Constraint to enable IPv6 through JS.
88*d9f75844SAndroid Build Coastguard Worker   static const char kEnableIPv6[];  // googIPv6
89*d9f75844SAndroid Build Coastguard Worker   // Temporary constraint to enable suspend below min bitrate feature.
90*d9f75844SAndroid Build Coastguard Worker   static const char kEnableVideoSuspendBelowMinBitrate[];
91*d9f75844SAndroid Build Coastguard Worker   // googSuspendBelowMinBitrate
92*d9f75844SAndroid Build Coastguard Worker   // Constraint to enable combined audio+video bandwidth estimation.
93*d9f75844SAndroid Build Coastguard Worker   static const char kCombinedAudioVideoBwe[];  // googCombinedAudioVideoBwe
94*d9f75844SAndroid Build Coastguard Worker   static const char kScreencastMinBitrate[];   // googScreencastMinBitrate
95*d9f75844SAndroid Build Coastguard Worker   static const char kCpuOveruseDetection[];    // googCpuOveruseDetection
96*d9f75844SAndroid Build Coastguard Worker 
97*d9f75844SAndroid Build Coastguard Worker   // Constraint to enable negotiating raw RTP packetization using attribute
98*d9f75844SAndroid Build Coastguard Worker   // "a=packetization:<payload_type> raw" in the SDP for all video payload.
99*d9f75844SAndroid Build Coastguard Worker   static const char kRawPacketizationForVideoEnabled[];
100*d9f75844SAndroid Build Coastguard Worker 
101*d9f75844SAndroid Build Coastguard Worker   // Specifies number of simulcast layers for all video tracks
102*d9f75844SAndroid Build Coastguard Worker   // with a Plan B offer/answer
103*d9f75844SAndroid Build Coastguard Worker   // (see RTCOfferAnswerOptions::num_simulcast_layers).
104*d9f75844SAndroid Build Coastguard Worker   static const char kNumSimulcastLayers[];
105*d9f75844SAndroid Build Coastguard Worker 
106*d9f75844SAndroid Build Coastguard Worker   ~MediaConstraints() = default;
107*d9f75844SAndroid Build Coastguard Worker 
GetMandatory()108*d9f75844SAndroid Build Coastguard Worker   const Constraints& GetMandatory() const { return mandatory_; }
GetOptional()109*d9f75844SAndroid Build Coastguard Worker   const Constraints& GetOptional() const { return optional_; }
110*d9f75844SAndroid Build Coastguard Worker 
111*d9f75844SAndroid Build Coastguard Worker  private:
112*d9f75844SAndroid Build Coastguard Worker   const Constraints mandatory_ = {};
113*d9f75844SAndroid Build Coastguard Worker   const Constraints optional_ = {};
114*d9f75844SAndroid Build Coastguard Worker };
115*d9f75844SAndroid Build Coastguard Worker 
116*d9f75844SAndroid Build Coastguard Worker // Copy all relevant constraints into an RTCConfiguration object.
117*d9f75844SAndroid Build Coastguard Worker void CopyConstraintsIntoRtcConfiguration(
118*d9f75844SAndroid Build Coastguard Worker     const MediaConstraints* constraints,
119*d9f75844SAndroid Build Coastguard Worker     PeerConnectionInterface::RTCConfiguration* configuration);
120*d9f75844SAndroid Build Coastguard Worker 
121*d9f75844SAndroid Build Coastguard Worker // Copy all relevant constraints into an AudioOptions object.
122*d9f75844SAndroid Build Coastguard Worker void CopyConstraintsIntoAudioOptions(const MediaConstraints* constraints,
123*d9f75844SAndroid Build Coastguard Worker                                      cricket::AudioOptions* options);
124*d9f75844SAndroid Build Coastguard Worker 
125*d9f75844SAndroid Build Coastguard Worker bool CopyConstraintsIntoOfferAnswerOptions(
126*d9f75844SAndroid Build Coastguard Worker     const MediaConstraints* constraints,
127*d9f75844SAndroid Build Coastguard Worker     PeerConnectionInterface::RTCOfferAnswerOptions* offer_answer_options);
128*d9f75844SAndroid Build Coastguard Worker 
129*d9f75844SAndroid Build Coastguard Worker }  // namespace webrtc
130*d9f75844SAndroid Build Coastguard Worker 
131*d9f75844SAndroid Build Coastguard Worker #endif  // SDK_MEDIA_CONSTRAINTS_H_
132