mirror of
https://github.com/aler9/gortsplib
synced 2025-10-06 15:46:51 +08:00
support routing ULPFEC group definitions
This commit is contained in:
@@ -2,6 +2,7 @@ package description
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
psdp "github.com/pion/sdp/v3"
|
||||
|
||||
@@ -36,15 +37,21 @@ func hasMediaWithID(medias []*Media, id string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// SessionFECGroup is a FEC group.
|
||||
type SessionFECGroup []string
|
||||
|
||||
// Session is the description of a RTSP stream.
|
||||
type Session struct {
|
||||
// base URL of the stream (read only).
|
||||
// Base URL of the stream (read only).
|
||||
BaseURL *url.URL
|
||||
|
||||
// title of the stream (optional).
|
||||
// Title of the stream (optional).
|
||||
Title string
|
||||
|
||||
// available media streams.
|
||||
// FEC groups (RFC5109).
|
||||
FECGroups []SessionFECGroup
|
||||
|
||||
// Media streams.
|
||||
Medias []*Media
|
||||
}
|
||||
|
||||
@@ -87,6 +94,20 @@ func (d *Session) Unmarshal(ssd *sdp.SessionDescription) error {
|
||||
return fmt.Errorf("media IDs sent partially")
|
||||
}
|
||||
|
||||
for _, attr := range ssd.Attributes {
|
||||
if attr.Key == "group" && strings.HasPrefix(attr.Value, "FEC ") {
|
||||
group := SessionFECGroup(strings.Split(attr.Value[len("FEC "):], " "))
|
||||
|
||||
for _, id := range group {
|
||||
if !hasMediaWithID(d.Medias, id) {
|
||||
return fmt.Errorf("FEC group points to an invalid media ID: %v", id)
|
||||
}
|
||||
}
|
||||
|
||||
d.FECGroups = append(d.FECGroups, group)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -132,5 +153,12 @@ func (d Session) Marshal(multicast bool) ([]byte, error) {
|
||||
sout.MediaDescriptions[i] = media.Marshal()
|
||||
}
|
||||
|
||||
for _, group := range d.FECGroups {
|
||||
sout.Attributes = append(sout.Attributes, psdp.Attribute{
|
||||
Key: "group",
|
||||
Value: "FEC " + strings.Join(group, " "),
|
||||
})
|
||||
}
|
||||
|
||||
return sout.Marshal()
|
||||
}
|
||||
|
Reference in New Issue
Block a user