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.

94 lines
3.0 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright 2017 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/rtp_media_utils.h"
  11. #include "rtc_base/checks.h"
  12. namespace webrtc {
  13. RtpTransceiverDirection RtpTransceiverDirectionFromSendRecv(bool send,
  14. bool recv) {
  15. if (send && recv) {
  16. return RtpTransceiverDirection::kSendRecv;
  17. } else if (send && !recv) {
  18. return RtpTransceiverDirection::kSendOnly;
  19. } else if (!send && recv) {
  20. return RtpTransceiverDirection::kRecvOnly;
  21. } else {
  22. return RtpTransceiverDirection::kInactive;
  23. }
  24. }
  25. bool RtpTransceiverDirectionHasSend(RtpTransceiverDirection direction) {
  26. return direction == RtpTransceiverDirection::kSendRecv ||
  27. direction == RtpTransceiverDirection::kSendOnly;
  28. }
  29. bool RtpTransceiverDirectionHasRecv(RtpTransceiverDirection direction) {
  30. return direction == RtpTransceiverDirection::kSendRecv ||
  31. direction == RtpTransceiverDirection::kRecvOnly;
  32. }
  33. RtpTransceiverDirection RtpTransceiverDirectionReversed(
  34. RtpTransceiverDirection direction) {
  35. switch (direction) {
  36. case RtpTransceiverDirection::kSendRecv:
  37. case RtpTransceiverDirection::kInactive:
  38. return direction;
  39. case RtpTransceiverDirection::kSendOnly:
  40. return RtpTransceiverDirection::kRecvOnly;
  41. case RtpTransceiverDirection::kRecvOnly:
  42. return RtpTransceiverDirection::kSendOnly;
  43. }
  44. RTC_NOTREACHED();
  45. return direction;
  46. }
  47. RtpTransceiverDirection RtpTransceiverDirectionWithSendSet(
  48. RtpTransceiverDirection direction,
  49. bool send) {
  50. return RtpTransceiverDirectionFromSendRecv(
  51. send, RtpTransceiverDirectionHasRecv(direction));
  52. }
  53. RtpTransceiverDirection RtpTransceiverDirectionWithRecvSet(
  54. RtpTransceiverDirection direction,
  55. bool recv) {
  56. return RtpTransceiverDirectionFromSendRecv(
  57. RtpTransceiverDirectionHasSend(direction), recv);
  58. }
  59. const char* RtpTransceiverDirectionToString(RtpTransceiverDirection direction) {
  60. switch (direction) {
  61. case RtpTransceiverDirection::kSendRecv:
  62. return "kSendRecv";
  63. case RtpTransceiverDirection::kSendOnly:
  64. return "kSendOnly";
  65. case RtpTransceiverDirection::kRecvOnly:
  66. return "kRecvOnly";
  67. case RtpTransceiverDirection::kInactive:
  68. return "kInactive";
  69. }
  70. RTC_NOTREACHED();
  71. return "";
  72. }
  73. RtpTransceiverDirection RtpTransceiverDirectionIntersection(
  74. RtpTransceiverDirection lhs,
  75. RtpTransceiverDirection rhs) {
  76. return RtpTransceiverDirectionFromSendRecv(
  77. RtpTransceiverDirectionHasSend(lhs) &&
  78. RtpTransceiverDirectionHasSend(rhs),
  79. RtpTransceiverDirectionHasRecv(lhs) &&
  80. RtpTransceiverDirectionHasRecv(rhs));
  81. }
  82. } // namespace webrtc