mirror of
https://github.com/aler9/gortsplib
synced 2025-10-07 08:01:14 +08:00
store media IDs in description.Session
This commit is contained in:
@@ -9,6 +9,33 @@ import (
|
||||
"github.com/bluenviron/gortsplib/v4/pkg/url"
|
||||
)
|
||||
|
||||
func atLeastOneHasMID(medias []*Media) bool {
|
||||
for _, media := range medias {
|
||||
if media.ID != "" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func atLeastOneDoesntHaveMID(medias []*Media) bool {
|
||||
for _, media := range medias {
|
||||
if media.ID == "" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func hasMediaWithID(medias []*Media, id string) bool {
|
||||
for _, media := range medias {
|
||||
if media.ID == id {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Session is the description of a RTSP stream.
|
||||
type Session struct {
|
||||
// base URL of the stream (read only).
|
||||
@@ -48,9 +75,18 @@ func (d *Session) Unmarshal(ssd *sdp.SessionDescription) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("media %d is invalid: %v", i+1, err)
|
||||
}
|
||||
|
||||
if m.ID != "" && hasMediaWithID(d.Medias[:i], m.ID) {
|
||||
return fmt.Errorf("duplicate media IDs")
|
||||
}
|
||||
|
||||
d.Medias[i] = &m
|
||||
}
|
||||
|
||||
if atLeastOneHasMID(d.Medias) && atLeastOneDoesntHaveMID(d.Medias) {
|
||||
return fmt.Errorf("media IDs sent partially")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user