• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/rtp_media_utils.h"
12 
13 #include "rtc_base/checks.h"
14 
15 namespace webrtc {
16 
RtpTransceiverDirectionFromSendRecv(bool send,bool recv)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 
RtpTransceiverDirectionHasSend(RtpTransceiverDirection direction)30 bool RtpTransceiverDirectionHasSend(RtpTransceiverDirection direction) {
31   return direction == RtpTransceiverDirection::kSendRecv ||
32          direction == RtpTransceiverDirection::kSendOnly;
33 }
34 
RtpTransceiverDirectionHasRecv(RtpTransceiverDirection direction)35 bool RtpTransceiverDirectionHasRecv(RtpTransceiverDirection direction) {
36   return direction == RtpTransceiverDirection::kSendRecv ||
37          direction == RtpTransceiverDirection::kRecvOnly;
38 }
39 
RtpTransceiverDirectionReversed(RtpTransceiverDirection direction)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     default:
51       RTC_NOTREACHED();
52       return direction;
53   }
54 }
55 
RtpTransceiverDirectionWithSendSet(RtpTransceiverDirection direction,bool send)56 RtpTransceiverDirection RtpTransceiverDirectionWithSendSet(
57     RtpTransceiverDirection direction,
58     bool send) {
59   return RtpTransceiverDirectionFromSendRecv(
60       send, RtpTransceiverDirectionHasRecv(direction));
61 }
62 
RtpTransceiverDirectionWithRecvSet(RtpTransceiverDirection direction,bool recv)63 RtpTransceiverDirection RtpTransceiverDirectionWithRecvSet(
64     RtpTransceiverDirection direction,
65     bool recv) {
66   return RtpTransceiverDirectionFromSendRecv(
67       RtpTransceiverDirectionHasSend(direction), recv);
68 }
69 
RtpTransceiverDirectionToString(RtpTransceiverDirection direction)70 const char* RtpTransceiverDirectionToString(RtpTransceiverDirection direction) {
71   switch (direction) {
72     case RtpTransceiverDirection::kSendRecv:
73       return "kSendRecv";
74     case RtpTransceiverDirection::kSendOnly:
75       return "kSendOnly";
76     case RtpTransceiverDirection::kRecvOnly:
77       return "kRecvOnly";
78     case RtpTransceiverDirection::kInactive:
79       return "kInactive";
80     case RtpTransceiverDirection::kStopped:
81       return "kStopped";
82   }
83   RTC_NOTREACHED();
84   return "";
85 }
86 
RtpTransceiverDirectionIntersection(RtpTransceiverDirection lhs,RtpTransceiverDirection rhs)87 RtpTransceiverDirection RtpTransceiverDirectionIntersection(
88     RtpTransceiverDirection lhs,
89     RtpTransceiverDirection rhs) {
90   return RtpTransceiverDirectionFromSendRecv(
91       RtpTransceiverDirectionHasSend(lhs) &&
92           RtpTransceiverDirectionHasSend(rhs),
93       RtpTransceiverDirectionHasRecv(lhs) &&
94           RtpTransceiverDirectionHasRecv(rhs));
95 }
96 
97 }  // namespace webrtc
98