Skip to content

Commit

Permalink
Merge pull request #8 from notedit/get-media-track
Browse files Browse the repository at this point in the history
add get audio track and video track
  • Loading branch information
notedit authored May 6, 2022
2 parents 943e13b + 51bd6d0 commit e4233c6
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions sdpinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ func (s *SDPInfo) SetICE(ice *ICEInfo) {
}

func (s *SDPInfo) AddCandidate(candidate *CandidateInfo) {

// todo check
s.candidates = append(s.candidates, candidate)
if candidate != nil {
s.candidates = append(s.candidates, candidate)
}
}

func (s *SDPInfo) AddCandidates(candidates []*CandidateInfo) {
Expand Down Expand Up @@ -211,6 +211,32 @@ func (s *SDPInfo) GetStreamByMediaID(mid string) *StreamInfo {
return nil
}

func (s *SDPInfo) GetVideoTracks() []*TrackInfo {

tracks := []*TrackInfo{}
for _, stream := range s.streams {
for _, track := range stream.GetTracks() {
if strings.ToLower(track.GetMediaType()) == "video" {
tracks = append(tracks, track)
}
}
}
return tracks
}

func (s *SDPInfo) GetAudioTracks() []*TrackInfo {

tracks := []*TrackInfo{}
for _, stream := range s.streams {
for _, track := range stream.GetTracks() {
if strings.ToLower(track.GetMediaType()) == "audio" {
tracks = append(tracks, track)
}
}
}
return tracks
}

func (s *SDPInfo) Answer(ice *ICEInfo, dtls *DTLSInfo, candidates []*CandidateInfo, medias map[string]*Capability) *SDPInfo {

sdpInfo := NewSDPInfo()
Expand Down Expand Up @@ -430,7 +456,7 @@ func (s *SDPInfo) String() string {
mediaMap.SctpMaxSize = 256 * 1024
mediaMap.RtcpMux = ""
mediaMap.RtcpRsize = ""
} else {
} else {
mediaMap.Payloads = intArrayToString(payloads, " ")
}

Expand Down Expand Up @@ -1106,7 +1132,7 @@ func Parse(sdp string) (*SDPInfo, error) {
}
group := NewSourceGroupInfo(ssrcGroupAttr.Semantics, ssrcsint)
ssrc := ssrcsint[0]
for _, source := range sources{
for _, source := range sources {
if source.ssrc == ssrc {
streamInfo := sdpInfo.GetStream(source.GetStreamID())
if streamInfo != nil && streamInfo.GetTrack(source.GetTrackID()) != nil {
Expand Down

0 comments on commit e4233c6

Please sign in to comment.