sdptest.cpp 11.6 KB
Newer Older
Alexandre Savard's avatar
Alexandre Savard committed
1
/*
2
 *  Copyright (C) 2004, 2005, 2006, 2008, 2009, 2010 Savoir-Faire Linux Inc.
Alexandre Savard's avatar
Alexandre Savard committed
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
 *  Author: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 *  Additional permission under GNU GPL version 3 section 7:
 *
 *  If you modify this program, or any covered work, by linking or
 *  combining it with the OpenSSL project's OpenSSL library (or a
 *  modified version of that library), containing parts covered by the
 *  terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
 *  grants you additional permission to convey the resulting work.
 *  Corresponding Source for a non-source form of such a combination
 *  shall include the source code for the parts of OpenSSL used as well
 *  as that of the covered work.
 */

Tristan Matthews's avatar
Tristan Matthews committed
31
#include "sdptest.h"
32
#include <iostream>
Tristan Matthews's avatar
Tristan Matthews committed
33
#include <cstring>
34

Tristan Matthews's avatar
Tristan Matthews committed
35
#include "audio/codecs/audiocodec.h"
Alexandre Savard's avatar
Alexandre Savard committed
36

37

38
enum session_type {
39
40
41
42
    REMOTE_OFFER,
    LOCAL_OFFER,
};

43
static const char *sdp_answer1 = "v=0\r\n"
44
45
46
47
48
49
                                 "o=bob 2890844730 2890844730 IN IP4 host.example.com\r\n"
                                 "s= \r\n"
                                 "c=IN IP4 host.example.com\r\n"
                                 "t=0 0\r\n"
                                 "m=audio 49920 RTP/AVP 0\r\n"
                                 "a=rtpmap:0 PCMU/8000\r\n"
50
#ifdef SFL_VIDEO
51
52
                                 "m=video 0 RTP/AVP 31\r\n"
                                 "m=video 53002 RTP/AVP 32\r\n"
53
54
55
                                 "a=rtpmap:32 MPV/90000\r\n"
#endif
                                 ;
56

57
static const char *sdp_offer1 = "v=0\r\n"
58
59
60
61
62
63
                                "o=bob 2890844730 2890844730 IN IP4 host.example.com\r\n"
                                "s= \r\n"
                                "c=IN IP4 host.example.com\r\n"
                                "t=0 0\r\n"
                                "m=audio 49920 RTP/AVP 0\r\n"
                                "a=rtpmap:0 PCMU/8000\r\n"
64
#ifdef SFL_VIDEO
65
66
                                "m=video 0 RTP/AVP 31\r\n"
                                "m=video 53002 RTP/AVP 32\r\n"
67
68
69
                                "a=rtpmap:32 MPV/90000\r\n"
#endif
                                ;
70

71
static const char *sdp_answer2 = "v=0\r\n"
72
73
74
75
76
77
78
79
                                 "o=bob 2890844730 2890844730 IN IP4 host.example.com\r\n"
                                 "s= \r\n"
                                 "c=IN IP4 host.example.com\r\n"
                                 "t=0 0\r\n"
                                 "m=audio 49920 RTP/AVP 3 97 9\r\n"
                                 "a=rtpmap:3 GSM/8000\r\n"
                                 "a=rtpmap:97 iLBC/8000\r\n"
                                 "a=rtpmap:9 G722/8000\r\n"
80
#ifdef SFL_VIDEO
81
82
                                 "m=video 0 RTP/AVP 31\r\n"
                                 "m=video 53002 RTP/AVP 32\r\n"
83
84
85
                                 "a=rtpmap:32 MPV/90000\r\n"
#endif
                                 ;
86

87
static const char *sdp_offer2 = "v=0\r\n"
88
89
90
91
92
93
94
95
                                "o=bob 2890844730 2890844730 IN IP4 host.example.com\r\n"
                                "s= \r\n"
                                "c=IN IP4 host.example.com\r\n"
                                "t=0 0\r\n"
                                "m=audio 49920 RTP/AVP 3 97 9\r\n"
                                "a=rtpmap:3 GSM/8000\r\n"
                                "a=rtpmap:97 iLBC/8000\r\n"
                                "a=rtpmap:9 G722/8000\r\n"
96
#ifdef SFL_VIDEO
97
98
                                "m=video 0 RTP/AVP 31\r\n"
                                "m=video 53002 RTP/AVP 32\r\n"
99
100
101
                                "a=rtpmap:32 MPV/90000\r\n"
#endif
                                ;
102

103
static const char *sdp_reinvite = "v=0\r\n"
104
105
106
107
108
109
                                  "o=bob 2890844730 2890844730 IN IP4 host.example.com\r\n"
                                  "s= \r\n"
                                  "c=IN IP4 host.exampleReinvite.com\r\n"
                                  "t=0 0\r\n"
                                  "m=audio 42445 RTP/AVP 0\r\n"
                                  "a=rtpmap:0 PCMU/8000\r\n"
110
#ifdef SFL_VIDEO
111
112
                                  "m=video 0 RTP/AVP 31\r\n"
                                  "m=video 53002 RTP/AVP 32\r\n"
113
114
115
                                  "a=rtpmap:32 MPV/90000\r\n"
#endif
                                  ;
Alexandre Savard's avatar
Alexandre Savard committed
116
117
118
119


void SDPTest::setUp()
{
120
    pj_caching_pool_init(&poolCache_, &pj_pool_factory_default_policy, 0);
Alexandre Savard's avatar
Alexandre Savard committed
121

122
    testPool_ = pj_pool_create(&poolCache_.factory, "sdptest", 4000, 4000, NULL);
Alexandre Savard's avatar
Alexandre Savard committed
123

124
    session_ = new Sdp(testPool_);
Alexandre Savard's avatar
Alexandre Savard committed
125
126
127
128
}

void SDPTest::tearDown()
{
129
130
131
    delete session_;
    session_ = NULL;
    pj_pool_release(testPool_);
132
133
134
}


135
void SDPTest::testInitialOfferFirstCodec()
136
{
137
    std::cout << "------------ SDPTest::testInitialOfferFirstCodec --------------" << std::endl;
138

139
140
    CPPUNIT_ASSERT(session_->getLocalIP().empty());
    CPPUNIT_ASSERT(session_->getRemoteIP().empty());
141

142
    std::vector<int> codecSelection;
143
144
    pjmedia_sdp_session *remoteAnswer;

145
146
147
    codecSelection.push_back(PAYLOAD_CODEC_ULAW);
    codecSelection.push_back(PAYLOAD_CODEC_ALAW);
    codecSelection.push_back(PAYLOAD_CODEC_G722);
148

149
#ifdef SFL_VIDEO
Rafaël Carré's avatar
Rafaël Carré committed
150
151
152
    std::vector<std::string> videoCodecs;
    videoCodecs.push_back("H264");
    videoCodecs.push_back("H263");
153
#endif
Rafaël Carré's avatar
Rafaël Carré committed
154

155
	session_->setLocalIP("127.0.0.1");
156

157
#ifdef SFL_VIDEO
158
    session_->createOffer(codecSelection, videoCodecs);
159
160
161
#else
    session_->createOffer(codecSelection);
#endif
162

163
164
    // pjmedia_sdp_parse(testPool_, test[0].offer_answer[0].sdp2, strlen(test[0].offer_answer[0].sdp2), &remoteAnswer);
    pjmedia_sdp_parse(testPool_, (char*)sdp_answer1, strlen(sdp_answer1), &remoteAnswer);
165

166
167
    session_->receivingAnswerAfterInitialOffer(remoteAnswer);
    session_->startNegotiation();
168

169
    session_->setMediaTransportInfoFromRemoteSdp();
170

171
172
    CPPUNIT_ASSERT(session_->getLocalIP() == "127.0.0.1");
    CPPUNIT_ASSERT(session_->getRemoteIP() == "host.example.com");
173
174
}

175
void SDPTest::testInitialAnswerFirstCodec()
176
{
177
    std::cout << "------------ SDPTest::testInitialAnswerFirstCodec -------------" << std::endl;
178

179
180
    CPPUNIT_ASSERT(session_->getLocalIP().empty());
    CPPUNIT_ASSERT(session_->getRemoteIP().empty());
181

182
    std::vector<int> codecSelection;
183
184
    pjmedia_sdp_session *remoteOffer;

185
186
187
    codecSelection.push_back(PAYLOAD_CODEC_ULAW);
    codecSelection.push_back(PAYLOAD_CODEC_ALAW);
    codecSelection.push_back(PAYLOAD_CODEC_G722);
188

189
#ifdef SFL_VIDEO
Rafaël Carré's avatar
Rafaël Carré committed
190
191
192
    std::vector<std::string> videoCodecs;
    videoCodecs.push_back("H264");
    videoCodecs.push_back("H263");
193
#endif
Rafaël Carré's avatar
Rafaël Carré committed
194

195
    pjmedia_sdp_parse(testPool_, (char*)sdp_offer1, strlen(sdp_offer1), &remoteOffer);
196

197
    session_->setLocalIP("127.0.0.1");
198

199
#ifdef SFL_VIDEO
200
    session_->receiveOffer(remoteOffer, codecSelection, videoCodecs);
201
202
203
#else
    session_->receiveOffer(remoteOffer, codecSelection);
#endif
204

205
    session_->startNegotiation();
206

207
    session_->setMediaTransportInfoFromRemoteSdp();
208

209
210
    CPPUNIT_ASSERT(session_->getLocalIP() == "127.0.0.1");
    CPPUNIT_ASSERT(session_->getRemoteIP() == "host.example.com");
211
212
}

213
void SDPTest::testInitialOfferLastCodec()
214
{
215
    std::cout << "------------ SDPTest::testInitialOfferLastCodec --------------------" << std::endl;
216

217
218
    CPPUNIT_ASSERT(session_->getLocalIP().empty());
    CPPUNIT_ASSERT(session_->getRemoteIP().empty());
219

220
    std::vector<int> codecSelection;
221
222
    pjmedia_sdp_session *remoteAnswer;

223
224
225
    codecSelection.push_back(PAYLOAD_CODEC_ULAW);
    codecSelection.push_back(PAYLOAD_CODEC_ALAW);
    codecSelection.push_back(PAYLOAD_CODEC_G722);
226

227
#ifdef SFL_VIDEO
Rafaël Carré's avatar
Rafaël Carré committed
228
229
230
    std::vector<std::string> videoCodecs;
    videoCodecs.push_back("H264");
    videoCodecs.push_back("H263");
231
#endif
Rafaël Carré's avatar
Rafaël Carré committed
232

233
	session_->setLocalIP("127.0.0.1");
234

235
#ifdef SFL_VIDEO
236
    session_->createOffer(codecSelection, videoCodecs);
237
238
239
#else
    session_->createOffer(codecSelection);
#endif
240

241
242
    // pjmedia_sdp_parse(testPool_, test[0].offer_answer[0].sdp2, strlen(test[0].offer_answer[0].sdp2), &remoteAnswer);
    pjmedia_sdp_parse(testPool_, (char*)sdp_answer2, strlen(sdp_answer2), &remoteAnswer);
243

244
245
    session_->receivingAnswerAfterInitialOffer(remoteAnswer);
    session_->startNegotiation();
246

247
    session_->setMediaTransportInfoFromRemoteSdp();
248

249
250
    CPPUNIT_ASSERT(session_->getLocalIP() == "127.0.0.1");
    CPPUNIT_ASSERT(session_->getRemoteIP() == "host.example.com");
Alexandre Savard's avatar
Alexandre Savard committed
251
252
}

253
void SDPTest::testInitialAnswerLastCodec()
254
{
255
    std::cout << "------------ SDPTest::testInitialAnswerLastCodec ------------" << std::endl;
256

257
258
    CPPUNIT_ASSERT(session_->getLocalIP().empty());
    CPPUNIT_ASSERT(session_->getRemoteIP().empty());
259

260
    std::vector<int> codecSelection;
261
    pjmedia_sdp_session *remoteOffer;
Alexandre Savard's avatar
Alexandre Savard committed
262

263
264
265
    codecSelection.push_back(PAYLOAD_CODEC_ULAW);
    codecSelection.push_back(PAYLOAD_CODEC_ALAW);
    codecSelection.push_back(PAYLOAD_CODEC_G722);
266

267
#ifdef SFL_VIDEO
Rafaël Carré's avatar
Rafaël Carré committed
268
269
270
    std::vector<std::string> videoCodecs;
    videoCodecs.push_back("H264");
    videoCodecs.push_back("H263");
271
#endif
Rafaël Carré's avatar
Rafaël Carré committed
272

273
    pjmedia_sdp_parse(testPool_, (char*)sdp_offer2, strlen(sdp_offer2), &remoteOffer);
274

275
    session_->setLocalIP("127.0.0.1");
276

277
#ifdef SFL_VIDEO
278
    session_->receiveOffer(remoteOffer, codecSelection, videoCodecs);
279
280
281
#else
    session_->receiveOffer(remoteOffer, codecSelection);
#endif
282

283
    session_->startNegotiation();
284

285
    session_->setMediaTransportInfoFromRemoteSdp();
286

287
288
    CPPUNIT_ASSERT(session_->getLocalIP() == "127.0.0.1");
    CPPUNIT_ASSERT(session_->getRemoteIP() == "host.example.com");
289
290
291
}


292
void SDPTest::testReinvite()
Alexandre Savard's avatar
Alexandre Savard committed
293
{
294
    std::cout << "------------ SDPTest::testReinvite --------------------" << std::endl;
295

296
297
    CPPUNIT_ASSERT(session_->getLocalIP().empty());
    CPPUNIT_ASSERT(session_->getRemoteIP().empty());
Alexandre Savard's avatar
Alexandre Savard committed
298

299
    std::vector<int> codecSelection;
300
301
    pjmedia_sdp_session *remoteAnswer;
    pjmedia_sdp_session *reinviteOffer;
Alexandre Savard's avatar
Alexandre Savard committed
302
303
304
305
306

	codecSelection.push_back(PAYLOAD_CODEC_ULAW);
	codecSelection.push_back(PAYLOAD_CODEC_ALAW);
	codecSelection.push_back(PAYLOAD_CODEC_G722);

307
#ifdef SFL_VIDEO
Rafaël Carré's avatar
Rafaël Carré committed
308
309
310
    std::vector<std::string> videoCodecs;
    videoCodecs.push_back("H264");
    videoCodecs.push_back("H263");
311
#endif
Rafaël Carré's avatar
Rafaël Carré committed
312

313
	session_->setLocalIP("127.0.0.1");
314

315
#ifdef SFL_VIDEO
316
    session_->createOffer(codecSelection, videoCodecs);
317
318
319
#else
    session_->createOffer(codecSelection);
#endif
320

321
322
    // pjmedia_sdp_parse(testPool_, test[0].offer_answer[0].sdp2, strlen(test[0].offer_answer[0].sdp2), &remoteAnswer);
    pjmedia_sdp_parse(testPool_, (char*)sdp_answer1, strlen(sdp_answer1), &remoteAnswer);
323

324
325
    session_->receivingAnswerAfterInitialOffer(remoteAnswer);
    session_->startNegotiation();
326

327
    session_->setMediaTransportInfoFromRemoteSdp();
328

329
330
    CPPUNIT_ASSERT(session_->getLocalIP() == "127.0.0.1");
    CPPUNIT_ASSERT(session_->getRemoteIP() == "host.example.com");
331

332
333
    pjmedia_sdp_parse(testPool_, (char*) sdp_reinvite, strlen(sdp_reinvite), &reinviteOffer);
#ifdef SFL_VIDEO
334
    session_->receiveOffer(reinviteOffer, codecSelection, videoCodecs);
335
336
337
#else
    session_->receiveOffer(reinviteOffer, codecSelection);
#endif
338

339
340
    session_->startNegotiation();
    session_->setMediaTransportInfoFromRemoteSdp();
341

342
    CPPUNIT_ASSERT(session_->getRemoteIP() == "host.exampleReinvite.com");
Alexandre Savard's avatar
Alexandre Savard committed
343
}