Skip to content

Commit

Permalink
Merge pull request #6 from jaygno/master
Browse files Browse the repository at this point in the history
fix ssrc order
  • Loading branch information
notedit authored Dec 8, 2021
2 parents 29ca576 + 38cddee commit 021823e
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions sdpinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -968,19 +968,24 @@ func Parse(sdp string) (*SDPInfo, error) {
mediaInfo.SetSimulcastInfo(simulcast)
}

sources := map[uint]*SourceInfo{}
sources := []*SourceInfo{}

if md.Ssrcs != nil {
for _, ssrcAttr := range md.Ssrcs {
ssrc := ssrcAttr.Id
key := ssrcAttr.Attribute
value := ssrcAttr.Value

source, ok := sources[ssrc]

if !ok {
var source *SourceInfo
for _, sourceInfo := range sources {
if sourceInfo.ssrc == ssrc {
source = sourceInfo
break
}
}
if source == nil {
source = NewSourceInfo(ssrc)
sources[ssrc] = source
sources = append(sources, source)
}

if strings.ToLower(key) == "cname" {
Expand Down Expand Up @@ -1040,17 +1045,17 @@ func Parse(sdp string) (*SDPInfo, error) {
stream.AddTrack(track)
}

for ssrc, source := range sources {
for _, source := range sources {

if source.GetStreamID() == "" {
source.SetStreamID(streamId)
source.SetTrackID(trackId)
track.AddSSRC(ssrc)
track.AddSSRC(source.ssrc)
}
}
}

for ssrc, source := range sources {
for _, source := range sources {

if source.GetStreamID() == "" {
streamId := source.GetCName()
Expand All @@ -1075,7 +1080,7 @@ func Parse(sdp string) (*SDPInfo, error) {
stream.AddTrack(track)
}

track.AddSSRC(ssrc)
track.AddSSRC(source.ssrc)
}
}

Expand All @@ -1089,11 +1094,14 @@ func Parse(sdp string) (*SDPInfo, error) {
}
group := NewSourceGroupInfo(ssrcGroupAttr.Semantics, ssrcsint)
ssrc := ssrcsint[0]
source := sources[ssrc]

streamInfo := sdpInfo.GetStream(source.GetStreamID())
if streamInfo != nil && streamInfo.GetTrack(source.GetTrackID()) != nil {
streamInfo.GetTrack(source.GetTrackID()).AddSourceGroup(group)
for _, source := range sources{
if source.ssrc == ssrc {
streamInfo := sdpInfo.GetStream(source.GetStreamID())
if streamInfo != nil && streamInfo.GetTrack(source.GetTrackID()) != nil {
streamInfo.GetTrack(source.GetTrackID()).AddSourceGroup(group)
}
break
}
}
}
}
Expand Down

0 comments on commit 021823e

Please sign in to comment.