github.com/pion/webrtc/v3@v3.2.24/sdpsemantics.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 // SDPSemantics determines which style of SDP offers and answers 11 // can be used 12 type SDPSemantics int 13 14 const ( 15 // SDPSemanticsUnifiedPlan uses unified-plan offers and answers 16 // (the default in Chrome since M72) 17 // https://tools.ietf.org/html/draft-roach-mmusic-unified-plan-00 18 SDPSemanticsUnifiedPlan SDPSemantics = iota 19 20 // SDPSemanticsPlanB uses plan-b offers and answers 21 // NB: This format should be considered deprecated 22 // https://tools.ietf.org/html/draft-uberti-rtcweb-plan-00 23 SDPSemanticsPlanB 24 25 // SDPSemanticsUnifiedPlanWithFallback prefers unified-plan 26 // offers and answers, but will respond to a plan-b offer 27 // with a plan-b answer 28 SDPSemanticsUnifiedPlanWithFallback 29 ) 30 31 const ( 32 sdpSemanticsUnifiedPlanWithFallback = "unified-plan-with-fallback" 33 sdpSemanticsUnifiedPlan = "unified-plan" 34 sdpSemanticsPlanB = "plan-b" 35 ) 36 37 func newSDPSemantics(raw string) SDPSemantics { 38 switch raw { 39 case sdpSemanticsUnifiedPlan: 40 return SDPSemanticsUnifiedPlan 41 case sdpSemanticsPlanB: 42 return SDPSemanticsPlanB 43 case sdpSemanticsUnifiedPlanWithFallback: 44 return SDPSemanticsUnifiedPlanWithFallback 45 default: 46 return SDPSemantics(Unknown) 47 } 48 } 49 50 func (s SDPSemantics) String() string { 51 switch s { 52 case SDPSemanticsUnifiedPlanWithFallback: 53 return sdpSemanticsUnifiedPlanWithFallback 54 case SDPSemanticsUnifiedPlan: 55 return sdpSemanticsUnifiedPlan 56 case SDPSemanticsPlanB: 57 return sdpSemanticsPlanB 58 default: 59 return ErrUnknownType.Error() 60 } 61 } 62 63 // UnmarshalJSON parses the JSON-encoded data and stores the result 64 func (s *SDPSemantics) UnmarshalJSON(b []byte) error { 65 var val string 66 if err := json.Unmarshal(b, &val); err != nil { 67 return err 68 } 69 70 *s = newSDPSemantics(val) 71 return nil 72 } 73 74 // MarshalJSON returns the JSON encoding 75 func (s SDPSemantics) MarshalJSON() ([]byte, error) { 76 return json.Marshal(s.String()) 77 }