forked from beatgammit/rtsp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sdp.go
73 lines (69 loc) · 1.61 KB
/
sdp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package rtsp
import (
"bufio"
"errors"
"io"
"strconv"
"strings"
)
type SessionSection struct {
Version int
Originator string
SessionName string
SessionInformation string
URI string
Email string
Phone string
ConnectionInformation string
BandwidthInformation string
}
func ParseSdp(r io.Reader) (SessionSection, error) {
var packet SessionSection
s := bufio.NewScanner(r)
for s.Scan() {
parts := strings.SplitN(s.Text(), "=", 2)
if len(parts) == 2 {
if len(parts[0]) != 1 {
return packet, errors.New("SDP only allows 1-character variables")
}
switch parts[0] {
// version
case "v":
ver, err := strconv.Atoi(parts[1])
if err != nil {
return packet, err
}
packet.Version = ver
// owner/creator and session identifier
case "o":
// o=<username> <session id> <version> <network type> <address type> <address>
// TODO: parse this
packet.Originator = parts[1]
// session name
case "s":
packet.SessionName = parts[1]
// session information
case "i":
packet.SessionInformation = parts[1]
// URI of description
case "u":
packet.URI = parts[1]
// email address
case "e":
packet.Email = parts[1]
// phone number
case "p":
packet.Phone = parts[1]
// connection information - not required if included in all media
case "c":
// TODO: parse this
packet.ConnectionInformation = parts[1]
// bandwidth information
case "b":
// TODO: parse this
packet.BandwidthInformation = parts[1]
}
}
}
return packet, nil
}