Files
webrtc/sessiondescription.go
OrlandoCo 3412dc6d95 Add SessionDescription Unmarshal helper
This will allow to re-use the internally parsed sdp, and prevent parsing multiple times and save some cpu cycles.
2020-10-25 00:33:08 -04:00

26 lines
646 B
Go

package webrtc
import (
"github.com/pion/sdp/v3"
)
// SessionDescription is used to expose local and remote session descriptions.
type SessionDescription struct {
Type SDPType `json:"type"`
SDP string `json:"sdp"`
// This will never be initialized by callers, internal use only
parsed *sdp.SessionDescription
}
// Unmarshal is a helper to deserialize the sdp, and re-use it internally
// if required
func (sd *SessionDescription) Unmarshal() (*sdp.SessionDescription, error) {
if sd.parsed != nil {
return sd.parsed, nil
}
sd.parsed = &sdp.SessionDescription{}
err := sd.parsed.Unmarshal([]byte(sd.SDP))
return sd.parsed, err
}