-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsdp_test.go
211 lines (180 loc) · 4.15 KB
/
sdp_test.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
package rtsp
import (
"net/url"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
func TestSdp_ParseSDP(t *testing.T) {
require := require.New(t)
data := []byte(strings.Join(
[]string{
`v=0`,
`m=audio 5004 RTP/AVP 96`,
`a=rtpmap:96 mpeg4-generic/8000/2`,
`a=fmtp:96 streamtype=5; profile-level-id=15; mode=AAC-hbr; config=1588`,
`a=control:trackID=0`,
`m=video 5006 RTP/AVP 97`,
`a=rtpmap:97 H264/90000`,
`a=fmtp:97 profile-level-id=428014;sprop-parameter-sets=Z0KAFNoFB+Q=,aM4G4g==;`,
`a=control:trackID=1`,
},
"\r\n",
))
u, _ := url.Parse("rtsp://test.local")
s, err := ParseSDP(u, data)
require.NoError(err)
c1, _ := url.Parse("rtsp://test.local/trackID=0")
c2, _ := url.Parse("rtsp://test.local/trackID=1")
expectedSdp := []*SdpItem{
{
Port: 5004,
Transport: "RTP/AVP",
Format: 96,
URL: c1,
Media: &MediaMPEG4{
ClockRate: 8000,
Mode: "AAC-hbr",
ProfileLevelID: 15,
Config: []byte{0x15, 0x88},
},
},
{
Port: 5006,
Transport: "RTP/AVP",
Format: 97,
URL: c2,
Media: &MediaH264{
ClockRate: 90000,
ProfileLevelID: []byte{0x42, 0x80, 0x14},
SPS: []byte{
0x67, 0x42, 0x80, 0x14, 0xda, 0x05, 0x07, 0xe4,
},
PPS: []byte{
0x68, 0xce, 0x06, 0xe2,
},
},
},
}
require.Equal(expectedSdp, s)
}
func TestSdp_parse_a_control(t *testing.T) {
t.Run("redefine base url", func(t *testing.T) {
require := require.New(t)
data := []byte(strings.Join(
[]string{
"v=0",
"a=control:rtsp://test.local/setup/",
"m=video 8002 RTP/AVP 31",
"a=control:trackID=1",
},
"\r\n",
))
u, _ := url.Parse("rtsp://test.local/example/")
s, err := ParseSDP(u, data)
require.NoError(err)
c1, _ := url.Parse("rtsp://test.local/setup/trackID=1")
expectedSdp := []*SdpItem{
{
Port: 8002,
Transport: "RTP/AVP",
Format: 31,
URL: c1,
},
}
require.Equal(expectedSdp, s)
})
t.Run("asterisk control", func(t *testing.T) {
require := require.New(t)
data := []byte(strings.Join(
[]string{
"v=0",
"a=control:rtsp://test.local/movie/",
"m=video 8002 RTP/AVP 31",
"a=control:*",
},
"\r\n",
))
u, _ := url.Parse("rtsp://test.local/movie/")
s, err := ParseSDP(u, data)
require.NoError(err)
expectedSdp := []*SdpItem{
{
Port: 8002,
Transport: "RTP/AVP",
Format: 31,
URL: u,
},
}
require.Equal(expectedSdp, s)
})
t.Run("absolute control", func(t *testing.T) {
require := require.New(t)
data := []byte(strings.Join(
[]string{
"v=0",
"m=video 8002 RTP/AVP 31",
"a=control:rtsp://test.local/trackID=1",
},
"\r\n",
))
u, _ := url.Parse("rtsp://test.local/example")
s, err := ParseSDP(u, data)
require.NoError(err)
c1, _ := url.Parse("rtsp://test.local/trackID=1")
expectedSdp := []*SdpItem{
{
Port: 8002,
Transport: "RTP/AVP",
Format: 31,
URL: c1,
},
}
require.Equal(expectedSdp, s)
})
t.Run("relative control", func(t *testing.T) {
require := require.New(t)
data := []byte(strings.Join(
[]string{
"v=0",
"m=video 8002 RTP/AVP 31",
"a=control:trackID=1",
},
"\r\n",
))
u, _ := url.Parse("rtsp://test.local/user=&password=&channel=1&stream=0.sdp")
s, err := ParseSDP(u, data)
require.NoError(err)
c1, _ := url.Parse("rtsp://test.local/user=&password=&channel=1&stream=0.sdp/trackID=1")
expectedSdp := []*SdpItem{
{
Port: 8002,
Transport: "RTP/AVP",
Format: 31,
URL: c1,
},
}
require.Equal(expectedSdp, s)
})
}
func TestSdp_parse_a_rtpmap(t *testing.T) {
t.Run("trailing space bug", func(t *testing.T) {
require := require.New(t)
data := []byte(strings.Join(
[]string{
`v=0`,
`m=video 5006 RTP/AVP 97`,
`a=rtpmap:97 H264/90000 `,
`a=fmtp:97 profile-level-id=428014;sprop-parameter-sets=Z0KAFNoFB+Q=,aM4G4g==;`,
`a=control:trackID=1`,
},
"\r\n",
))
u, _ := url.Parse("rtsp://test.local")
s, err := ParseSDP(u, data)
require.NoError(err)
require.Len(s, 1)
_, ok := s[0].Media.(*MediaH264)
require.True(ok)
})
}