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