Steve Anton | 1d03a75 | 2017-11-27 22:30:09 | [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 17:11:00 | [diff] [blame] | 11 | #include "pc/rtp_media_utils.h" |
Steve Anton | 1d03a75 | 2017-11-27 22:30:09 | [diff] [blame] | 12 | |
Yves Gerey | 3e70781 | 2018-11-28 15:47:49 | [diff] [blame] | 13 | #include "rtc_base/checks.h" |
| 14 | |
Steve Anton | 1d03a75 | 2017-11-27 22:30:09 | [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: |
Harald Alvestrand | 6060df5 | 2020-08-11 07:54:02 | [diff] [blame] | 45 | case RtpTransceiverDirection::kStopped: |
Steve Anton | 1d03a75 | 2017-11-27 22:30:09 | [diff] [blame] | 46 | return direction; |
| 47 | case RtpTransceiverDirection::kSendOnly: |
| 48 | return RtpTransceiverDirection::kRecvOnly; |
| 49 | case RtpTransceiverDirection::kRecvOnly: |
| 50 | return RtpTransceiverDirection::kSendOnly; |
Markus Handell | 45c104b | 2020-03-11 09:51:13 | [diff] [blame] | 51 | default: |
Artem Titov | d325196 | 2021-11-15 15:57:07 | [diff] [blame] | 52 | RTC_DCHECK_NOTREACHED(); |
Markus Handell | 45c104b | 2020-03-11 09:51:13 | [diff] [blame] | 53 | return direction; |
Steve Anton | 1d03a75 | 2017-11-27 22:30:09 | [diff] [blame] | 54 | } |
Steve Anton | 1d03a75 | 2017-11-27 22:30:09 | [diff] [blame] | 55 | } |
| 56 | |
Steve Anton | 22da89f | 2018-01-25 21:58:07 | [diff] [blame] | 57 | RtpTransceiverDirection RtpTransceiverDirectionWithSendSet( |
| 58 | RtpTransceiverDirection direction, |
| 59 | bool send) { |
| 60 | return RtpTransceiverDirectionFromSendRecv( |
| 61 | send, RtpTransceiverDirectionHasRecv(direction)); |
| 62 | } |
| 63 | |
| 64 | RtpTransceiverDirection RtpTransceiverDirectionWithRecvSet( |
| 65 | RtpTransceiverDirection direction, |
| 66 | bool recv) { |
| 67 | return RtpTransceiverDirectionFromSendRecv( |
| 68 | RtpTransceiverDirectionHasSend(direction), recv); |
| 69 | } |
| 70 | |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 71 | const char* RtpTransceiverDirectionToString(RtpTransceiverDirection direction) { |
| 72 | switch (direction) { |
| 73 | case RtpTransceiverDirection::kSendRecv: |
| 74 | return "kSendRecv"; |
| 75 | case RtpTransceiverDirection::kSendOnly: |
| 76 | return "kSendOnly"; |
| 77 | case RtpTransceiverDirection::kRecvOnly: |
| 78 | return "kRecvOnly"; |
| 79 | case RtpTransceiverDirection::kInactive: |
| 80 | return "kInactive"; |
Markus Handell | 45c104b | 2020-03-11 09:51:13 | [diff] [blame] | 81 | case RtpTransceiverDirection::kStopped: |
| 82 | return "kStopped"; |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 83 | } |
Artem Titov | d325196 | 2021-11-15 15:57:07 | [diff] [blame] | 84 | RTC_DCHECK_NOTREACHED(); |
Steve Anton | 4e70a72 | 2017-11-28 22:57:10 | [diff] [blame] | 85 | return ""; |
| 86 | } |
| 87 | |
Guido Urdaneta | 70c2db1 | 2019-04-16 10:24:14 | [diff] [blame] | 88 | RtpTransceiverDirection RtpTransceiverDirectionIntersection( |
| 89 | RtpTransceiverDirection lhs, |
| 90 | RtpTransceiverDirection rhs) { |
| 91 | return RtpTransceiverDirectionFromSendRecv( |
| 92 | RtpTransceiverDirectionHasSend(lhs) && |
| 93 | RtpTransceiverDirectionHasSend(rhs), |
| 94 | RtpTransceiverDirectionHasRecv(lhs) && |
| 95 | RtpTransceiverDirectionHasRecv(rhs)); |
| 96 | } |
| 97 | |
Steve Anton | 1d03a75 | 2017-11-27 22:30:09 | [diff] [blame] | 98 | } // namespace webrtc |