You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.7 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright 2019 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. #include "pc/media_protocol_names.h"
  11. namespace cricket {
  12. // There are multiple variants of the RTP protocol stack, including
  13. // UDP/TLS/RTP/SAVPF (WebRTC default), RTP/AVP, RTP/AVPF, RTP/SAVPF,
  14. // TCP/DTLS/RTP/SAVPF and so on. We accept anything that has RTP/
  15. // embedded in it somewhere as being an RTP protocol.
  16. const char kMediaProtocolRtpPrefix[] = "RTP/";
  17. const char kMediaProtocolSctp[] = "SCTP";
  18. const char kMediaProtocolDtlsSctp[] = "DTLS/SCTP";
  19. const char kMediaProtocolUdpDtlsSctp[] = "UDP/DTLS/SCTP";
  20. const char kMediaProtocolTcpDtlsSctp[] = "TCP/DTLS/SCTP";
  21. bool IsDtlsSctp(const std::string& protocol) {
  22. return protocol == kMediaProtocolDtlsSctp ||
  23. protocol == kMediaProtocolUdpDtlsSctp ||
  24. protocol == kMediaProtocolTcpDtlsSctp;
  25. }
  26. bool IsPlainSctp(const std::string& protocol) {
  27. return protocol == kMediaProtocolSctp;
  28. }
  29. bool IsRtpProtocol(const std::string& protocol) {
  30. if (protocol.empty()) {
  31. return true;
  32. }
  33. size_t pos = protocol.find(cricket::kMediaProtocolRtpPrefix);
  34. if (pos == std::string::npos) {
  35. return false;
  36. }
  37. // RTP must be at the beginning of a string or not preceded by alpha
  38. if (pos == 0 || !isalpha(protocol[pos - 1])) {
  39. return true;
  40. }
  41. return false;
  42. }
  43. bool IsSctpProtocol(const std::string& protocol) {
  44. return IsPlainSctp(protocol) || IsDtlsSctp(protocol);
  45. }
  46. } // namespace cricket