-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathsdpMediaDesc.go
77 lines (62 loc) · 1.41 KB
/
sdpMediaDesc.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
74
75
76
77
package siprocket
/*
RFC4566 - https://tools.ietf.org/html/rfc4566#section-5.14
5.14. Media Descriptions ("m=")
m=<media> <port> <proto> <fmt> ...
A session description may contain a number of media descriptions.
Each media description starts with an "m=" field and is terminated by
either the next "m=" field or by the end of the session description.
eg:
m=audio 24414 RTP/AVP 8 18 101
*/
type sdpMediaDesc struct {
MediaType []byte // Named portion of URI
Port []byte // Port number
Proto []byte // Protocol
Fmt []byte // Fmt
Src []byte // Full source if needed
}
func parseSdpMediaDesc(v []byte, out *sdpMediaDesc) {
pos := 0
state := FIELD_MEDIA
// Init the output area
out.MediaType = nil
out.Port = nil
out.Proto = nil
out.Fmt = nil
out.Src = nil
// Keep the source line if needed
if keep_src {
out.Src = v
}
// Loop through the bytes making up the line
for pos < len(v) {
// FSM
switch state {
case FIELD_MEDIA:
if v[pos] == ' ' {
state = FIELD_PORT
pos++
continue
}
out.MediaType = append(out.MediaType, v[pos])
case FIELD_PORT:
if v[pos] == ' ' {
state = FIELD_PROTO
pos++
continue
}
out.Port = append(out.Port, v[pos])
case FIELD_PROTO:
if v[pos] == ' ' {
state = FIELD_FMT
pos++
continue
}
out.Proto = append(out.Proto, v[pos])
case FIELD_FMT:
out.Fmt = append(out.Fmt, v[pos])
}
pos++
}
}