commit 96a874b067dad9a5704171d9c63a5594b6d42e3d
parent 8d2c4bc42dfbbe01d8d7cfd968ca60c8048ae6f9
Author: Oliver Lowe <o@olowe.co>
Date: Sat, 10 Aug 2024 18:56:32 +1000
sdp: resolve remaining validation, documentation TODOs
No real changes, just notes. Always encode a valid timestamp when
session start time is unset but an end time is set. Document the TTL
in ConnInfo is a specific property of multicast traffic. No need to
impose more structure on session Attributes when the data is pretty
free-form anyway (similar to http.Header). Safely round times in
session repeat schedules to ensure we never write invalid decimal
places.
Diffstat:
4 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/sdp/encode.go b/sdp/encode.go
@@ -39,7 +39,6 @@ func (s Session) String() string {
fmt.Fprintln(buf, s.Bandwidth)
}
- // TODO(otl): what about the invalid case where Time[0] is zero but Time[1] is not?
if s.Time[0].IsZero() {
fmt.Fprintln(buf, "t=0 0")
} else {
diff --git a/sdp/parser.go b/sdp/parser.go
@@ -12,7 +12,6 @@ type parser struct {
*bufio.Scanner
err error
// Field name and value from the current line.
- // TODO(otl): rename? key, value is very non-specific...
key, value string
next []string // expected next field names
diff --git a/sdp/sdp.go b/sdp/sdp.go
@@ -141,7 +141,6 @@ func parseBandwidth(s string) (Bandwidth, error) {
if !ok {
return Bandwidth{}, fmt.Errorf("missing %s separator", ":")
}
- // TODO(otl): check bandwith type is actually one specified in section 5.8.
if t == "" {
return Bandwidth{}, fmt.Errorf("missing bandwidth type")
}
@@ -170,7 +169,6 @@ type Media struct {
Title string
Connection *ConnInfo
Bandwidth *Bandwidth
- // TODO(otl): store as k, v pairs
Attributes []string
}
@@ -311,9 +309,11 @@ func parseMedia(s string) (Media, error) {
// ConnInfo represents connection information.
type ConnInfo struct {
Address netip.Addr
- // TODO(otl): what are these units? seconds?
- TTL uint8 // time to live
- Count int // number of addresses after Address
+ // TTL is the time-to-live of multicast packets.
+ TTL uint8
+ // Count is the number of subsequent IP addresses after
+ // Address used in the session.
+ Count int
}
func (c *ConnInfo) String() string {
diff --git a/sdp/time.go b/sdp/time.go
@@ -3,6 +3,7 @@ package sdp
import (
"errors"
"fmt"
+ "math"
"strconv"
"strings"
"time"
@@ -44,8 +45,9 @@ type Repeat struct {
}
func (rp *Repeat) String() string {
- // TODO(otl): print with no decimal places?
- s := fmt.Sprintf("r=%f %f ", rp.Interval.Round(time.Second).Seconds(), rp.Active.Round(time.Second).Seconds())
+ interval := math.Round(rp.Interval.Round(time.Second).Seconds())
+ active := math.Round(rp.Active.Round(time.Second).Seconds())
+ s := fmt.Sprintf("r=%d %d ", int(interval), int(active))
if len(rp.Offsets) > 0 {
ss := make([]string, len(rp.Offsets))
for i := range rp.Offsets {