Skip to content

Commit

Permalink
Merge pull request #13 from bjz/fix-streams-order
Browse files Browse the repository at this point in the history
fix map streams in order
  • Loading branch information
notedit authored Oct 25, 2022
2 parents 674ccca + a9c1085 commit 93ef212
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions sdpinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

type SDPInfo struct {
version int
streams map[string]*StreamInfo
streams []*StreamInfo
medias []*MediaInfo // as we need to keep order
candidates []*CandidateInfo // keep order
ice *ICEInfo
Expand All @@ -22,7 +22,7 @@ func NewSDPInfo() *SDPInfo {

sdp := &SDPInfo{
version: 1,
streams: map[string]*StreamInfo{},
streams: []*StreamInfo{},
medias: []*MediaInfo{},
candidates: []*CandidateInfo{},
}
Expand Down Expand Up @@ -160,10 +160,15 @@ func (s *SDPInfo) GetCandidates() []*CandidateInfo {

func (s *SDPInfo) GetStream(id string) *StreamInfo {

return s.streams[id]
for _, v := range s.streams {
if id == v.GetID() {
return v
}
}
return nil
}

func (s *SDPInfo) GetStreams() map[string]*StreamInfo {
func (s *SDPInfo) GetStreams() []*StreamInfo {

return s.streams
}
Expand All @@ -177,15 +182,30 @@ func (s *SDPInfo) GetFirstStream() *StreamInfo {
}

func (s *SDPInfo) AddStream(stream *StreamInfo) {
s.streams[stream.GetID()] = stream

for idx, v := range s.streams {
if stream.GetID() == v.GetID() {
s.streams[idx] = stream
return
}
}

s.streams = append(s.streams, stream)
}

func (s *SDPInfo) RemoveStream(stream *StreamInfo) {
delete(s.streams, stream.GetID())

for idx, v := range s.streams {
if stream.GetID() == v.GetID() {
s.streams = append(s.streams[:idx], s.streams[idx+1:]...)
return
}
}
}

func (s *SDPInfo) RemoveAllStreams() {
s.streams = make(map[string]*StreamInfo)

s.streams = s.streams[:0]
}

func (s *SDPInfo) GetTrackByMediaID(mid string) *TrackInfo {
Expand Down

0 comments on commit 93ef212

Please sign in to comment.