media_constraints.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. // Implementation of the w3c constraints spec is the responsibility of the
  11. // browser. Chrome no longer uses the constraints api declared here, and it will
  12. // be removed from WebRTC.
  13. // https://bugs.chromium.org/p/webrtc/issues/detail?id=9239
  14. #ifndef SDK_MEDIA_CONSTRAINTS_H_
  15. #define SDK_MEDIA_CONSTRAINTS_H_
  16. #include <stddef.h>
  17. #include <string>
  18. #include <utility>
  19. #include <vector>
  20. #include "api/audio_options.h"
  21. #include "api/peer_connection_interface.h"
  22. namespace webrtc {
  23. // Class representing constraints, as used by the android and objc apis.
  24. //
  25. // Constraints may be either "mandatory", which means that unless satisfied,
  26. // the method taking the constraints should fail, or "optional", which means
  27. // they may not be satisfied..
  28. class MediaConstraints {
  29. public:
  30. struct Constraint {
  31. Constraint() {}
  32. Constraint(const std::string& key, const std::string value)
  33. : key(key), value(value) {}
  34. std::string key;
  35. std::string value;
  36. };
  37. class Constraints : public std::vector<Constraint> {
  38. public:
  39. Constraints() = default;
  40. Constraints(std::initializer_list<Constraint> l)
  41. : std::vector<Constraint>(l) {}
  42. bool FindFirst(const std::string& key, std::string* value) const;
  43. };
  44. MediaConstraints() = default;
  45. MediaConstraints(Constraints mandatory, Constraints optional)
  46. : mandatory_(std::move(mandatory)), optional_(std::move(optional)) {}
  47. // Constraint keys used by a local audio source.
  48. // These keys are google specific.
  49. static const char kGoogEchoCancellation[]; // googEchoCancellation
  50. static const char kAutoGainControl[]; // googAutoGainControl
  51. static const char kExperimentalAutoGainControl[]; // googAutoGainControl2
  52. static const char kNoiseSuppression[]; // googNoiseSuppression
  53. static const char kExperimentalNoiseSuppression[]; // googNoiseSuppression2
  54. static const char kHighpassFilter[]; // googHighpassFilter
  55. static const char kTypingNoiseDetection[]; // googTypingNoiseDetection
  56. static const char kAudioMirroring[]; // googAudioMirroring
  57. static const char
  58. kAudioNetworkAdaptorConfig[]; // goodAudioNetworkAdaptorConfig
  59. // Constraint keys for CreateOffer / CreateAnswer
  60. // Specified by the W3C PeerConnection spec
  61. static const char kOfferToReceiveVideo[]; // OfferToReceiveVideo
  62. static const char kOfferToReceiveAudio[]; // OfferToReceiveAudio
  63. static const char kVoiceActivityDetection[]; // VoiceActivityDetection
  64. static const char kIceRestart[]; // IceRestart
  65. // These keys are google specific.
  66. static const char kUseRtpMux[]; // googUseRtpMUX
  67. // Constraints values.
  68. static const char kValueTrue[]; // true
  69. static const char kValueFalse[]; // false
  70. // PeerConnection constraint keys.
  71. // Temporary pseudo-constraints used to enable DTLS-SRTP
  72. static const char kEnableDtlsSrtp[]; // Enable DTLS-SRTP
  73. // Temporary pseudo-constraints used to enable DataChannels
  74. static const char kEnableRtpDataChannels[]; // Enable RTP DataChannels
  75. // Google-specific constraint keys.
  76. // Temporary pseudo-constraint for enabling DSCP through JS.
  77. static const char kEnableDscp[]; // googDscp
  78. // Constraint to enable IPv6 through JS.
  79. static const char kEnableIPv6[]; // googIPv6
  80. // Temporary constraint to enable suspend below min bitrate feature.
  81. static const char kEnableVideoSuspendBelowMinBitrate[];
  82. // googSuspendBelowMinBitrate
  83. // Constraint to enable combined audio+video bandwidth estimation.
  84. static const char kCombinedAudioVideoBwe[]; // googCombinedAudioVideoBwe
  85. static const char kScreencastMinBitrate[]; // googScreencastMinBitrate
  86. static const char kCpuOveruseDetection[]; // googCpuOveruseDetection
  87. // Constraint to enable negotiating raw RTP packetization using attribute
  88. // "a=packetization:<payload_type> raw" in the SDP for all video payload.
  89. static const char kRawPacketizationForVideoEnabled[];
  90. // Specifies number of simulcast layers for all video tracks
  91. // with a Plan B offer/answer
  92. // (see RTCOfferAnswerOptions::num_simulcast_layers).
  93. static const char kNumSimulcastLayers[];
  94. ~MediaConstraints() = default;
  95. const Constraints& GetMandatory() const { return mandatory_; }
  96. const Constraints& GetOptional() const { return optional_; }
  97. private:
  98. const Constraints mandatory_ = {};
  99. const Constraints optional_ = {};
  100. };
  101. // Copy all relevant constraints into an RTCConfiguration object.
  102. void CopyConstraintsIntoRtcConfiguration(
  103. const MediaConstraints* constraints,
  104. PeerConnectionInterface::RTCConfiguration* configuration);
  105. // Copy all relevant constraints into an AudioOptions object.
  106. void CopyConstraintsIntoAudioOptions(const MediaConstraints* constraints,
  107. cricket::AudioOptions* options);
  108. bool CopyConstraintsIntoOfferAnswerOptions(
  109. const MediaConstraints* constraints,
  110. PeerConnectionInterface::RTCOfferAnswerOptions* offer_answer_options);
  111. } // namespace webrtc
  112. #endif // SDK_MEDIA_CONSTRAINTS_H_