github.com/pion/webrtc/v4@v4.0.1/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 // RTCPMuxPolicyUnknown is the enum's zero-value 16 RTCPMuxPolicyUnknown RTCPMuxPolicy = iota 17 18 // RTCPMuxPolicyNegotiate indicates to gather ICE candidates for both 19 // RTP and RTCP candidates. If the remote-endpoint is capable of 20 // multiplexing RTCP, multiplex RTCP on the RTP candidates. If it is not, 21 // use both the RTP and RTCP candidates separately. 22 RTCPMuxPolicyNegotiate 23 24 // RTCPMuxPolicyRequire indicates to gather ICE candidates only for 25 // RTP and multiplex RTCP on the RTP candidates. If the remote endpoint is 26 // not capable of rtcp-mux, session negotiation will fail. 27 RTCPMuxPolicyRequire 28 ) 29 30 // This is done this way because of a linter. 31 const ( 32 rtcpMuxPolicyNegotiateStr = "negotiate" 33 rtcpMuxPolicyRequireStr = "require" 34 ) 35 36 func newRTCPMuxPolicy(raw string) RTCPMuxPolicy { 37 switch raw { 38 case rtcpMuxPolicyNegotiateStr: 39 return RTCPMuxPolicyNegotiate 40 case rtcpMuxPolicyRequireStr: 41 return RTCPMuxPolicyRequire 42 default: 43 return RTCPMuxPolicyUnknown 44 } 45 } 46 47 func (t RTCPMuxPolicy) String() string { 48 switch t { 49 case RTCPMuxPolicyNegotiate: 50 return rtcpMuxPolicyNegotiateStr 51 case RTCPMuxPolicyRequire: 52 return rtcpMuxPolicyRequireStr 53 default: 54 return ErrUnknownType.Error() 55 } 56 } 57 58 // UnmarshalJSON parses the JSON-encoded data and stores the result 59 func (t *RTCPMuxPolicy) UnmarshalJSON(b []byte) error { 60 var val string 61 if err := json.Unmarshal(b, &val); err != nil { 62 return err 63 } 64 65 *t = newRTCPMuxPolicy(val) 66 return nil 67 } 68 69 // MarshalJSON returns the JSON encoding 70 func (t RTCPMuxPolicy) MarshalJSON() ([]byte, error) { 71 return json.Marshal(t.String()) 72 }