Files
gortsplib/pkg/headers/session.go
Alessandro Ros a1396206b5 convert Tracks into Medias and Formats (#155)
* split tracks from medias

* move tracks into dedicated package

* move media into dedicated package

* edit Medias.Marshal() in order to return SDP

* add medias.Find() and simplify examples

* improve coverage

* fix rebase errors

* replace TrackIDs with MediaIDs

* implement media-specific and track-specific callbacks for reading RTCP and RTP packets

* rename publish into record, read into play

* add v2 tag

* rename tracks into formats
2022-12-11 22:03:22 +01:00

72 lines
1.1 KiB
Go

package headers
import (
"fmt"
"strconv"
"strings"
"github.com/aler9/gortsplib/v2/pkg/base"
)
// Session is a Session header.
type Session struct {
// session id
Session string
// (optional) a timeout
Timeout *uint
}
// Unmarshal decodes a Session header.
func (h *Session) Unmarshal(v base.HeaderValue) error {
if len(v) == 0 {
return fmt.Errorf("value not provided")
}
if len(v) > 1 {
return fmt.Errorf("value provided multiple times (%v)", v)
}
v0 := v[0]
i := strings.IndexByte(v0, ';')
if i < 0 {
h.Session = v0
return nil
}
h.Session = v0[:i]
v0 = v0[i+1:]
v0 = strings.TrimLeft(v0, " ")
kvs, err := keyValParse(v0, ';')
if err != nil {
return err
}
for k, v := range kvs {
if k == "timeout" {
iv, err := strconv.ParseUint(v, 10, 64)
if err != nil {
return err
}
uiv := uint(iv)
h.Timeout = &uiv
}
}
return nil
}
// Marshal encodes a Session header.
func (h Session) Marshal() base.HeaderValue {
ret := h.Session
if h.Timeout != nil {
ret += ";timeout=" + strconv.FormatUint(uint64(*h.Timeout), 10)
}
return base.HeaderValue{ret}
}