xref: /aosp_15_r20/external/webrtc/sdk/media_constraints.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright 2013 The WebRTC project authors. All Rights Reserved.
3  *
4  *  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.
9  */
10 
11 // 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
15 
16 #ifndef SDK_MEDIA_CONSTRAINTS_H_
17 #define SDK_MEDIA_CONSTRAINTS_H_
18 
19 #include <stddef.h>
20 #include <string>
21 #include <utility>
22 #include <vector>
23 
24 #include "api/audio_options.h"
25 #include "api/peer_connection_interface.h"
26 
27 namespace webrtc {
28 
29 // Class representing constraints, as used by the android and objc apis.
30 //
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..
34 class MediaConstraints {
35  public:
36   struct Constraint {
ConstraintConstraint37     Constraint() {}
ConstraintConstraint38     Constraint(const std::string& key, const std::string value)
39         : key(key), value(value) {}
40     std::string key;
41     std::string value;
42   };
43 
44   class Constraints : public std::vector<Constraint> {
45    public:
46     Constraints() = default;
Constraints(std::initializer_list<Constraint> l)47     Constraints(std::initializer_list<Constraint> l)
48         : std::vector<Constraint>(l) {}
49 
50     bool FindFirst(const std::string& key, std::string* value) const;
51   };
52 
53   MediaConstraints() = default;
MediaConstraints(Constraints mandatory,Constraints optional)54   MediaConstraints(Constraints mandatory, Constraints optional)
55       : mandatory_(std::move(mandatory)), optional_(std::move(optional)) {}
56 
57   // Constraint keys used by a local audio source.
58 
59   // These keys are google specific.
60   static const char kGoogEchoCancellation[];  // googEchoCancellation
61 
62   static const char kAutoGainControl[];       // googAutoGainControl
63   static const char kNoiseSuppression[];      // googNoiseSuppression
64   static const char kHighpassFilter[];        // googHighpassFilter
65   static const char kAudioMirroring[];        // googAudioMirroring
66   static const char
67       kAudioNetworkAdaptorConfig[];  // googAudioNetworkAdaptorConfig
68   static const char kInitAudioRecordingOnSend[];  // InitAudioRecordingOnSend;
69 
70   // Constraint keys for CreateOffer / CreateAnswer
71   // Specified by the W3C PeerConnection spec
72   static const char kOfferToReceiveVideo[];     // OfferToReceiveVideo
73   static const char kOfferToReceiveAudio[];     // OfferToReceiveAudio
74   static const char kVoiceActivityDetection[];  // VoiceActivityDetection
75   static const char kIceRestart[];              // IceRestart
76   // These keys are google specific.
77   static const char kUseRtpMux[];  // googUseRtpMUX
78 
79   // Constraints values.
80   static const char kValueTrue[];   // true
81   static const char kValueFalse[];  // false
82 
83   // PeerConnection constraint keys.
84   // Google-specific constraint keys.
85   // Temporary pseudo-constraint for enabling DSCP through JS.
86   static const char kEnableDscp[];  // googDscp
87   // Constraint to enable IPv6 through JS.
88   static const char kEnableIPv6[];  // googIPv6
89   // Temporary constraint to enable suspend below min bitrate feature.
90   static const char kEnableVideoSuspendBelowMinBitrate[];
91   // googSuspendBelowMinBitrate
92   // Constraint to enable combined audio+video bandwidth estimation.
93   static const char kCombinedAudioVideoBwe[];  // googCombinedAudioVideoBwe
94   static const char kScreencastMinBitrate[];   // googScreencastMinBitrate
95   static const char kCpuOveruseDetection[];    // googCpuOveruseDetection
96 
97   // 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 
101   // 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 
106   ~MediaConstraints() = default;
107 
GetMandatory()108   const Constraints& GetMandatory() const { return mandatory_; }
GetOptional()109   const Constraints& GetOptional() const { return optional_; }
110 
111  private:
112   const Constraints mandatory_ = {};
113   const Constraints optional_ = {};
114 };
115 
116 // Copy all relevant constraints into an RTCConfiguration object.
117 void CopyConstraintsIntoRtcConfiguration(
118     const MediaConstraints* constraints,
119     PeerConnectionInterface::RTCConfiguration* configuration);
120 
121 // Copy all relevant constraints into an AudioOptions object.
122 void CopyConstraintsIntoAudioOptions(const MediaConstraints* constraints,
123                                      cricket::AudioOptions* options);
124 
125 bool CopyConstraintsIntoOfferAnswerOptions(
126     const MediaConstraints* constraints,
127     PeerConnectionInterface::RTCOfferAnswerOptions* offer_answer_options);
128 
129 }  // namespace webrtc
130 
131 #endif  // SDK_MEDIA_CONSTRAINTS_H_
132