forked from yeung908/rtsp_rtp_server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_rtsp.c
374 lines (357 loc) · 13.4 KB
/
test_rtsp.c
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
/*
Copyright (c) 2012, Paula Roquero Fuentes <[email protected]>
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED AS IS AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdio.h>
#include <string.h>
#include "parse_rtsp.h"
#include "rtsp.h"
int main() {
int st;
int err = 0;
RTSP_REQUEST *req = 0;
RTSP_RESPONSE *res = 0;
char packed_msg[1024];
char *msg_ok[] = {
"DESCRIBE rtsp://uri/cacosa RTSP/1.0\r\n"
"CSeq: 1\r\n"
"Accept: application/sdp\r\n"
"\r\n\0",
"SETUP rtsp://uri/cacosa RTSP/1.0\r\n"
"CSeq: 2\r\n"
"Transport: RTP/AVP;unicast;client_port=9000-9001\r\n"
"\r\n\0",
"SETUP rtsp://uri/cacosa RTSP/1.0\r\n"
"CSeq: 3\r\n"
"Transport: RTP/AVP;multicast;client_port=9000-9001\r\n"
"\r\n\0",
"SETUP rtsp://uri/cacosa RTSP/1.0\r\n"
"CSeq: 4\r\n"
"Session: 10\r\n"
"Transport: RTP/AVP;multicast;client_port=9000-9001\r\n"
"\r\n\0",
"PLAY rtsp://uri/cacosa RTSP/1.0\r\n"
"CSeq: 5\r\n"
"Session: 10\r\n"
"\r\n\0",
"PAUSE rtsp://uri/cacosa RTSP/1.0\r\n"
"CSeq: 6\r\n"
"Session: 10\r\n"
"\r\n\0",
"TEARDOWN rtsp://uri/cacosa RTSP/1.0\r\n"
"CSeq: 7\r\n"
"Session: 10\r\n"
"\r\n\0",
0
};
char *res_ok[] = {
"RTSP/1.0 200\r\n"
"CSeq: 1\r\n"
"Content-Length: 141\r\n"
"\r\n"
"a=control:rtsp://uri/cacosa\r\n"
"m=audio 0 RTP/AVP 0\r\n"
"a=control:rtsp://uri/cacosa/audio\r\n"
"m=video 0 RTP/AVP 1\r\n"
"a=control:rtsp://uri/cacosa/video\r\n\0",
"RTSP/1.0 200\r\n"
"CSeq: 2\r\n"
"Transport: RTP/AVP;unicast;client_port=9000-9001;server_port=9000-9001\r\n"
"\r\n\0",
"RTSP/1.0 200\r\n"
"CSeq: 3\r\n"
"Transport: RTP/AVP;multicast;client_port=9000-9001;server_port=9000-9001\r\n"
"\r\n\0",
"RTSP/1.0 200\r\n"
"CSeq: 4\r\n"
"Session: 10\r\n"
"Transport: RTP/AVP;multicast;client_port=9000-9001;server_port=9000-9001\r\n"
"\r\n\0",
"RTSP/1.0 200\r\n"
"CSeq: 5\r\n"
"Session: 10\r\n"
"\r\n\0",
"RTSP/1.0 200\r\n"
"CSeq: 6\r\n"
"Session: 10\r\n"
"\r\n\0",
"RTSP/1.0 200\r\n"
"CSeq: 7\r\n"
"Session: 10\r\n"
"\r\n\0",
0
};
req = rtsp_describe((unsigned char *)"rtsp://uri/cacosa");
if (!req) {
err = 1;
fprintf(stderr, "Error creating describe: rtsp://uri/cacosa\n");
} else {
st = pack_rtsp_req(req, packed_msg, 1024);
if (!st) {
err = 1;
fprintf(stderr, "Error packing request:\n%s\n", msg_ok[0]);
} else {
if (strcmp(msg_ok[0], packed_msg)) {
err = 1;
fprintf(stderr, "Error, different request:\n%s\n%s\n", msg_ok[0], packed_msg);
} else {
res = rtsp_describe_res(req);
if (!res) {
err = 1;
fprintf(stderr, "Error creating describe respose: rtsp://uri/cacosa\n");
} else {
st = pack_rtsp_res(res, packed_msg, 1024);
if (!st) {
err = 1;
fprintf(stderr, "Error packing describe response:\n%s\n", msg_ok[0]);
} else {
if (strcmp(res_ok[0], packed_msg)) {
err = 1;
fprintf(stderr, "Error, different response:\n%s\n%s\n", res_ok[0], packed_msg);
}
}
}
}
}
}
if (res)
free_rtsp_res(&res);
if (req)
free_rtsp_req(&req);
req = 0;
res = 0;
req = rtsp_setup((unsigned char *)"rtsp://uri/cacosa", -1, UNICAST, 9000);
if (!req) {
err = 1;
fprintf(stderr, "Error creating setup unicast without session: rtsp://uri/cacosa\n");
} else {
st = pack_rtsp_req(req, packed_msg, 1024);
if (!st) {
err = 1;
fprintf(stderr, "Error packing request:\n%s\n", msg_ok[1]);
} else {
if (strcmp(msg_ok[1], packed_msg)) {
err = 1;
fprintf(stderr, "Error, different request:\n%s\n%s\n", msg_ok[1], packed_msg);
} else {
res = rtsp_setup_res(req, 9000, 0, 0, 0);
if (!res) {
err = 1;
fprintf(stderr, "Error creating setup unicast without session respose: rtsp://uri/cacosa\n");
} else {
st = pack_rtsp_res(res, packed_msg, 1024);
if (!st) {
err = 1;
fprintf(stderr, "Error packing setup unicast without session response:\n%s\n", msg_ok[1]);
} else {
if (strcmp(res_ok[1], packed_msg)) {
err = 1;
fprintf(stderr, "Error, different response:\n%s\n%s\n", res_ok[1], packed_msg);
}
}
}
}
}
}
if (res)
free_rtsp_res(&res);
if (req)
free_rtsp_req(&req);
res = 0;
req = 0;
req = rtsp_setup((unsigned char *)"rtsp://uri/cacosa", -1, MULTICAST, 9000);
if (!req) {
err = 1;
fprintf(stderr, "Error creating setup multicast without session: rtsp://uri/cacosa\n");
} else {
st = pack_rtsp_req(req, packed_msg, 1024);
if (!st) {
err = 1;
fprintf(stderr, "Error packing request:\n%s\n", msg_ok[2]);
} else {
if (strcmp(msg_ok[2], packed_msg)) {
err = 1;
fprintf(stderr, "Error, different request:\n%s\n%s\n", msg_ok[2], packed_msg);
} else {
res = rtsp_setup_res(req, 9000, 0, 0, 0);
if (!res) {
err = 1;
fprintf(stderr, "Error creating setup multicast without session respose: rtsp://uri/cacosa\n");
} else {
st = pack_rtsp_res(res, packed_msg, 1024);
if (!st) {
err = 1;
fprintf(stderr, "Error packing setup multicast without session response:\n%s\n", msg_ok[2]);
} else {
if (strcmp(res_ok[2], packed_msg)) {
err = 1;
fprintf(stderr, "Error, different response:\n%s\n%s\n", res_ok[2], packed_msg);
}
}
}
}
}
}
if (res)
free_rtsp_res(&res);
if (req)
free_rtsp_req(&req);
res = 0;
req = 0;
req = rtsp_setup((unsigned char *)"rtsp://uri/cacosa", 10, MULTICAST, 9000);
if (!req) {
err = 1;
fprintf(stderr, "Error creating setup multicast with session: rtsp://uri/cacosa\n");
} else {
st = pack_rtsp_req(req, packed_msg, 1024);
if (!st) {
err = 1;
fprintf(stderr, "Error packing request:\n%s\n", msg_ok[3]);
} else {
if (strcmp(msg_ok[3], packed_msg)) {
err = 1;
fprintf(stderr, "Error, different request:\n%s\n%s\n", msg_ok[3], packed_msg);
} else {
res = rtsp_setup_res(req, 9000, 0, 0, 0);
if (!res) {
err = 1;
fprintf(stderr, "Error creating setup multicast with session respose: rtsp://uri/cacosa\n");
} else {
st = pack_rtsp_res(res, packed_msg, 1024);
if (!st) {
err = 1;
fprintf(stderr, "Error packing setup multicast with session response:\n%s\n", msg_ok[3]);
} else {
if (strcmp(res_ok[3], packed_msg)) {
err = 1;
fprintf(stderr, "Error, different response:\n%s\n%s\n", res_ok[3], packed_msg);
}
}
}
}
}
}
if (res)
free_rtsp_res(&res);
if (req)
free_rtsp_req(&req);
res = 0;
req = 0;
req = rtsp_play((unsigned char *)"rtsp://uri/cacosa", 10);
if (!req) {
err = 1;
fprintf(stderr, "Error creating play with session: rtsp://uri/cacosa\n");
} else {
st = pack_rtsp_req(req, packed_msg, 1024);
if (!st) {
err = 1;
fprintf(stderr, "Error packing request:\n%s\n", msg_ok[4]);
} else {
if (strcmp(msg_ok[4], packed_msg)) {
err = 1;
fprintf(stderr, "Error, different request:\n%s\n%s\n", msg_ok[4], packed_msg);
} else {
res = rtsp_play_res(req);
if (!res) {
err = 1;
fprintf(stderr, "Error creating play with session respose: rtsp://uri/cacosa\n");
} else {
st = pack_rtsp_res(res, packed_msg, 1024);
if (!st) {
err = 1;
fprintf(stderr, "Error packing play with session response:\n%s\n", msg_ok[4]);
} else {
if (strcmp(res_ok[4], packed_msg)) {
err = 1;
fprintf(stderr, "Error, different response:\n%s\n%s\n", res_ok[4], packed_msg);
}
}
}
}
}
}
if (res)
free_rtsp_res(&res);
if (req)
free_rtsp_req(&req);
res = 0;
req = 0;
req = rtsp_pause((unsigned char *)"rtsp://uri/cacosa", 10);
if (!req) {
err = 1;
fprintf(stderr, "Error creating pause with session: rtsp://uri/cacosa\n");
} else {
st = pack_rtsp_req(req, packed_msg, 1024);
if (!st) {
err = 1;
fprintf(stderr, "Error packing request:\n%s\n", msg_ok[5]);
} else {
if (strcmp(msg_ok[5], packed_msg)) {
err = 1;
fprintf(stderr, "Error, different request:\n%s\n%s\n", msg_ok[5], packed_msg);
} else {
res = rtsp_pause_res(req);
if (!res) {
err = 1;
fprintf(stderr, "Error creating pause with session respose: rtsp://uri/cacosa\n");
} else {
st = pack_rtsp_res(res, packed_msg, 1024);
if (!st) {
err = 1;
fprintf(stderr, "Error packing pause with session response:\n%s\n", msg_ok[5]);
} else {
if (strcmp(res_ok[5], packed_msg)) {
err = 1;
fprintf(stderr, "Error, different response:\n%s\n%s\n", res_ok[5], packed_msg);
}
}
}
}
}
}
if (res)
free_rtsp_res(&res);
if (req)
free_rtsp_req(&req);
res = 0;
req = 0;
req = rtsp_teardown((unsigned char *)"rtsp://uri/cacosa", 10);
if (!req) {
err = 1;
fprintf(stderr, "Error creating teardown with session: rtsp://uri/cacosa\n");
} else {
st = pack_rtsp_req(req, packed_msg, 1024);
if (!st) {
err = 1;
fprintf(stderr, "Error packing request:\n%s\n", msg_ok[6]);
} else {
if (strcmp(msg_ok[6], packed_msg)) {
err = 1;
fprintf(stderr, "Error, different request:\n%s\n%s\n", msg_ok[6], packed_msg);
} else {
res = rtsp_teardown_res(req);
if (!res) {
err = 1;
fprintf(stderr, "Error creating teardown with session respose: rtsp://uri/cacosa\n");
} else {
st = pack_rtsp_res(res, packed_msg, 1024);
if (!st) {
err = 1;
fprintf(stderr, "Error packing teardown with session response:\n%s\n", msg_ok[6]);
} else {
if (strcmp(res_ok[6], packed_msg)) {
err = 1;
fprintf(stderr, "Error, different response:\n%s\n%s\n", res_ok[6], packed_msg);
}
}
}
}
}
}
if (res)
free_rtsp_res(&res);
if (req)
free_rtsp_req(&req);
return 0;
}