• 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     case RtpTransceiverDirection::kStopped:
46       return direction;
47     case RtpTransceiverDirection::kSendOnly:
48       return RtpTransceiverDirection::kRecvOnly;
49     case RtpTransceiverDirection::kRecvOnly:
50       return RtpTransceiverDirection::kSendOnly;
51     default:
52       RTC_DCHECK_NOTREACHED();
53       return direction;
54   }
55 }
56 
RtpTransceiverDirectionWithSendSet(RtpTransceiverDirection direction,bool send)57 RtpTransceiverDirection RtpTransceiverDirectionWithSendSet(
58     RtpTransceiverDirection direction,
59     bool send) {
60   return RtpTransceiverDirectionFromSendRecv(
61       send, RtpTransceiverDirectionHasRecv(direction));
62 }
63 
RtpTransceiverDirectionWithRecvSet(RtpTransceiverDirection direction,bool recv)64 RtpTransceiverDirection RtpTransceiverDirectionWithRecvSet(
65     RtpTransceiverDirection direction,
66     bool recv) {
67   return RtpTransceiverDirectionFromSendRecv(
68       RtpTransceiverDirectionHasSend(direction), recv);
69 }
70 
RtpTransceiverDirectionToString(RtpTransceiverDirection direction)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";
81     case RtpTransceiverDirection::kStopped:
82       return "kStopped";
83   }
84   RTC_DCHECK_NOTREACHED();
85   return "";
86 }
87 
RtpTransceiverDirectionIntersection(RtpTransceiverDirection lhs,RtpTransceiverDirection rhs)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 
98 }  // namespace webrtc
99