Skip to content

Commit

Permalink
Merge pull request #7 from wwllww/master
Browse files Browse the repository at this point in the history
add datachannel sdp
  • Loading branch information
notedit authored Apr 11, 2022
2 parents 021823e + db4f452 commit 943e13b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
2 changes: 2 additions & 0 deletions mediainfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ type MediaInfo struct {
simulcast bool
simulcastInfo *SimulcastInfo
bitrate int
Protocal string
Payloads string
}

func NewMediaInfo(id string, mtype string) *MediaInfo {
Expand Down
16 changes: 14 additions & 2 deletions sdpinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,8 @@ func (s *SDPInfo) Answer(ice *ICEInfo, dtls *DTLSInfo, candidates []*CandidateIn
supported := medias[media.GetType()]
if supported != nil {
answer := media.AnswerCapability(supported)
answer.Payloads = media.Payloads
answer.Protocal = media.Protocal
sdpInfo.AddMedia(answer)
}
}
Expand Down Expand Up @@ -284,7 +286,7 @@ func (s *SDPInfo) String() string {
mediaMap := &transform.MediaStruct{
Type: media.GetType(),
Port: media.GetPort(),
Protocal: "UDP/TLS/RTP/SAVP",
Protocal: media.Protocal, // "UDP/TLS/RTP/SAVP",
Fmtp: []*transform.FmtpStruct{},
Rtp: []*transform.RtpStruct{},
RtcpFb: []*transform.RtcpFbStruct{},
Expand Down Expand Up @@ -422,7 +424,15 @@ func (s *SDPInfo) String() string {
payloads = append(payloads, rtp.Payload)
}

mediaMap.Payloads = intArrayToString(payloads, " ")
if strings.ToLower(media.mtype) == "application" {
mediaMap.Payloads = media.Payloads
mediaMap.SctpPort = 5000
mediaMap.SctpMaxSize = 256 * 1024
mediaMap.RtcpMux = ""
mediaMap.RtcpRsize = ""
} else {
mediaMap.Payloads = intArrayToString(payloads, " ")
}

for id, uri := range media.GetExtensions() {

Expand Down Expand Up @@ -761,6 +771,8 @@ func Parse(sdp string) (*SDPInfo, error) {
}

mediaInfo := NewMediaInfo(mid, media)
mediaInfo.Payloads = md.Payloads
mediaInfo.Protocal = md.Protocal

ufrag := md.IceUfrag
pwd := md.IcePwd
Expand Down
26 changes: 26 additions & 0 deletions transform/grammer.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,32 @@ var rulesMap map[byte][]*Rule = map[byte][]*Rule{
}
},
},

// a=sctp-port:5000
&Rule{
Name: "sctp-port",
Push: "",
Reg: regexp.MustCompile("^sctp-port:(\\d+)"),
Names: []string{},
Types: []rune{'d'},
Format: "",
FormatFunc: func(obj *gabs.Container) string {
return "sctp-port:%d"
},
},

// a=max-message-size:262144
&Rule{
Name: "sctp-max-message-size",
Push: "",
Reg: regexp.MustCompile("^max-message-size:(\\d+)"),
Names: []string{},
Types: []rune{'d'},
Format: "",
FormatFunc: func(obj *gabs.Container) string {
return "max-message-size:%d"
},
},
// a=x-google-flag:conference
&Rule{
Name: "xGoogleFlag",
Expand Down
2 changes: 2 additions & 0 deletions transform/sdpstruct.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ type MediaStruct struct {
Candidates []*CandidateStruct `json:"candidates,omitempty"`
Bandwidth []*BandwithStruct `json:"bandwidth,omitempty"`
Simulcast *SimulcastStruct `json:"simulcast,omitempty"`
SctpPort int `json:"sctp-port,omitempty"`
SctpMaxSize int `json:"sctp-max-message-size,omitempty"`
}

type SdpStruct struct {
Expand Down

0 comments on commit 943e13b

Please sign in to comment.