Steve Anton | 1d03a75 | 2017-11-27 14:30:09 -0800 | [diff] [blame] | 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 | |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 11 | #include "pc/rtp_media_utils.h" |
Steve Anton | 1d03a75 | 2017-11-27 14:30:09 -0800 | [diff] [blame] | 12 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 13 | #include "rtc_base/checks.h" |
| 14 | |
Steve Anton | 1d03a75 | 2017-11-27 14:30:09 -0800 | [diff] [blame] | 15 | namespace webrtc { |
| 16 | |
| 17 | RtpTransceiverDirection RtpTransceiverDirectionFromSendRecv(bool send, |
| 18 | bool recv) { |
| 19 | if (send && recv) { |
| 20 | return RtpTransceiverDirection::kSendRecv; |
| 21 | } else if (send && !recv) { |
| 22 | return RtpTransceiverDirection::kSendOnly; |
| 23 | } else if (!send && recv) { |
| 24 | return RtpTransceiverDirection::kRecvOnly; |
| 25 | } else { |
| 26 | return RtpTransceiverDirection::kInactive; |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | bool RtpTransceiverDirectionHasSend(RtpTransceiverDirection direction) { |
| 31 | return direction == RtpTransceiverDirection::kSendRecv || |
| 32 | direction == RtpTransceiverDirection::kSendOnly; |
| 33 | } |
| 34 | |
| 35 | bool RtpTransceiverDirectionHasRecv(RtpTransceiverDirection direction) { |
| 36 | return direction == RtpTransceiverDirection::kSendRecv || |
| 37 | direction == RtpTransceiverDirection::kRecvOnly; |
| 38 | } |
| 39 | |
| 40 | RtpTransceiverDirection RtpTransceiverDirectionReversed( |
| 41 | RtpTransceiverDirection direction) { |
| 42 | switch (direction) { |
| 43 | case RtpTransceiverDirection::kSendRecv: |
| 44 | case RtpTransceiverDirection::kInactive: |
| 45 | return direction; |
| 46 | case RtpTransceiverDirection::kSendOnly: |
| 47 | return RtpTransceiverDirection::kRecvOnly; |
| 48 | case RtpTransceiverDirection::kRecvOnly: |
| 49 | return RtpTransceiverDirection::kSendOnly; |
| 50 | } |
| 51 | RTC_NOTREACHED(); |
| 52 | return direction; |
| 53 | } |
| 54 | |
Steve Anton | 22da89f | 2018-01-25 13:58:07 -0800 | [diff] [blame] | 55 | RtpTransceiverDirection RtpTransceiverDirectionWithSendSet( |
| 56 | RtpTransceiverDirection direction, |
| 57 | bool send) { |
| 58 | return RtpTransceiverDirectionFromSendRecv( |
| 59 | send, RtpTransceiverDirectionHasRecv(direction)); |
| 60 | } |
| 61 | |
| 62 | RtpTransceiverDirection RtpTransceiverDirectionWithRecvSet( |
| 63 | RtpTransceiverDirection direction, |
| 64 | bool recv) { |
| 65 | return RtpTransceiverDirectionFromSendRecv( |
| 66 | RtpTransceiverDirectionHasSend(direction), recv); |
| 67 | } |
| 68 | |
Steve Anton | 4e70a72 | 2017-11-28 14:57:10 -0800 | [diff] [blame] | 69 | const char* RtpTransceiverDirectionToString(RtpTransceiverDirection direction) { |
| 70 | switch (direction) { |
| 71 | case RtpTransceiverDirection::kSendRecv: |
| 72 | return "kSendRecv"; |
| 73 | case RtpTransceiverDirection::kSendOnly: |
| 74 | return "kSendOnly"; |
| 75 | case RtpTransceiverDirection::kRecvOnly: |
| 76 | return "kRecvOnly"; |
| 77 | case RtpTransceiverDirection::kInactive: |
| 78 | return "kInactive"; |
| 79 | } |
| 80 | RTC_NOTREACHED(); |
| 81 | return ""; |
| 82 | } |
| 83 | |
Guido Urdaneta | 70c2db1 | 2019-04-16 12:24:14 +0200 | [diff] [blame] | 84 | RtpTransceiverDirection RtpTransceiverDirectionIntersection( |
| 85 | RtpTransceiverDirection lhs, |
| 86 | RtpTransceiverDirection rhs) { |
| 87 | return RtpTransceiverDirectionFromSendRecv( |
| 88 | RtpTransceiverDirectionHasSend(lhs) && |
| 89 | RtpTransceiverDirectionHasSend(rhs), |
| 90 | RtpTransceiverDirectionHasRecv(lhs) && |
| 91 | RtpTransceiverDirectionHasRecv(rhs)); |
| 92 | } |
| 93 | |
Steve Anton | 1d03a75 | 2017-11-27 14:30:09 -0800 | [diff] [blame] | 94 | } // namespace webrtc |