github.com/pion/webrtc/v3@v3.2.24/rtcpmuxpolicy.go (about) 1 // SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly> 2 // SPDX-License-Identifier: MIT 3 4 package webrtc 5 6 import ( 7 "encoding/json" 8 ) 9 10 // RTCPMuxPolicy affects what ICE candidates are gathered to support 11 // non-multiplexed RTCP. 12 type RTCPMuxPolicy int 13 14 const ( 15 // RTCPMuxPolicyNegotiate indicates to gather ICE candidates for both 16 // RTP and RTCP candidates. If the remote-endpoint is capable of 17 // multiplexing RTCP, multiplex RTCP on the RTP candidates. If it is not, 18 // use both the RTP and RTCP candidates separately. 19 RTCPMuxPolicyNegotiate RTCPMuxPolicy = iota + 1 20 21 // RTCPMuxPolicyRequire indicates to gather ICE candidates only for 22 // RTP and multiplex RTCP on the RTP candidates. If the remote endpoint is 23 // not capable of rtcp-mux, session negotiation will fail. 24 RTCPMuxPolicyRequire 25 ) 26 27 // This is done this way because of a linter. 28 const ( 29 rtcpMuxPolicyNegotiateStr = "negotiate" 30 rtcpMuxPolicyRequireStr = "require" 31 ) 32 33 func newRTCPMuxPolicy(raw string) RTCPMuxPolicy { 34 switch raw { 35 case rtcpMuxPolicyNegotiateStr: 36 return RTCPMuxPolicyNegotiate 37 case rtcpMuxPolicyRequireStr: 38 return RTCPMuxPolicyRequire 39 default: 40 return RTCPMuxPolicy(Unknown) 41 } 42 } 43 44 func (t RTCPMuxPolicy) String() string { 45 switch t { 46 case RTCPMuxPolicyNegotiate: 47 return rtcpMuxPolicyNegotiateStr 48 case RTCPMuxPolicyRequire: 49 return rtcpMuxPolicyRequireStr 50 default: 51 return ErrUnknownType.Error() 52 } 53 } 54 55 // UnmarshalJSON parses the JSON-encoded data and stores the result 56 func (t *RTCPMuxPolicy) UnmarshalJSON(b []byte) error { 57 var val string 58 if err := json.Unmarshal(b, &val); err != nil { 59 return err 60 } 61 62 *t = newRTCPMuxPolicy(val) 63 return nil 64 } 65 66 // MarshalJSON returns the JSON encoding 67 func (t RTCPMuxPolicy) MarshalJSON() ([]byte, error) { 68 return json.Marshal(t.String()) 69 }