OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are met: | 6 * modification, are permitted provided that the following conditions are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright notice, | 8 * 1. Redistributions of source code must retain the above copyright notice, |
9 * this list of conditions and the following disclaimer. | 9 * this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright notice, | 10 * 2. Redistributions in binary form must reproduce the above copyright notice, |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 TEST_F(RtpDataMediaChannelTest, SetUnknownCodecs) { | 169 TEST_F(RtpDataMediaChannelTest, SetUnknownCodecs) { |
170 rtc::scoped_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel()); | 170 rtc::scoped_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel()); |
171 | 171 |
172 cricket::DataCodec known_codec; | 172 cricket::DataCodec known_codec; |
173 known_codec.id = 103; | 173 known_codec.id = 103; |
174 known_codec.name = "google-data"; | 174 known_codec.name = "google-data"; |
175 cricket::DataCodec unknown_codec; | 175 cricket::DataCodec unknown_codec; |
176 unknown_codec.id = 104; | 176 unknown_codec.id = 104; |
177 unknown_codec.name = "unknown-data"; | 177 unknown_codec.name = "unknown-data"; |
178 | 178 |
179 std::vector<cricket::DataCodec> known_codecs; | 179 cricket::DataSendParameters send_parameters_known; |
180 known_codecs.push_back(known_codec); | 180 send_parameters_known.codecs.push_back(known_codec); |
| 181 cricket::DataRecvParameters recv_parameters_known; |
| 182 recv_parameters_known.codecs.push_back(known_codec); |
181 | 183 |
182 std::vector<cricket::DataCodec> unknown_codecs; | 184 cricket::DataSendParameters send_parameters_unknown; |
183 unknown_codecs.push_back(unknown_codec); | 185 send_parameters_unknown.codecs.push_back(unknown_codec); |
| 186 cricket::DataRecvParameters recv_parameters_unknown; |
| 187 recv_parameters_unknown.codecs.push_back(unknown_codec); |
184 | 188 |
185 std::vector<cricket::DataCodec> mixed_codecs; | 189 cricket::DataSendParameters send_parameters_mixed; |
186 mixed_codecs.push_back(known_codec); | 190 send_parameters_mixed.codecs.push_back(known_codec); |
187 mixed_codecs.push_back(unknown_codec); | 191 send_parameters_mixed.codecs.push_back(unknown_codec); |
| 192 cricket::DataRecvParameters recv_parameters_mixed; |
| 193 recv_parameters_mixed.codecs.push_back(known_codec); |
| 194 recv_parameters_mixed.codecs.push_back(unknown_codec); |
188 | 195 |
189 EXPECT_TRUE(dmc->SetSendCodecs(known_codecs)); | 196 EXPECT_TRUE(dmc->SetSendParameters(send_parameters_known)); |
190 EXPECT_FALSE(dmc->SetSendCodecs(unknown_codecs)); | 197 EXPECT_FALSE(dmc->SetSendParameters(send_parameters_unknown)); |
191 EXPECT_TRUE(dmc->SetSendCodecs(mixed_codecs)); | 198 EXPECT_TRUE(dmc->SetSendParameters(send_parameters_mixed)); |
192 EXPECT_TRUE(dmc->SetRecvCodecs(known_codecs)); | 199 EXPECT_TRUE(dmc->SetRecvParameters(recv_parameters_known)); |
193 EXPECT_FALSE(dmc->SetRecvCodecs(unknown_codecs)); | 200 EXPECT_FALSE(dmc->SetRecvParameters(recv_parameters_unknown)); |
194 EXPECT_FALSE(dmc->SetRecvCodecs(mixed_codecs)); | 201 EXPECT_FALSE(dmc->SetRecvParameters(recv_parameters_mixed)); |
195 } | 202 } |
196 | 203 |
197 TEST_F(RtpDataMediaChannelTest, AddRemoveSendStream) { | 204 TEST_F(RtpDataMediaChannelTest, AddRemoveSendStream) { |
198 rtc::scoped_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel()); | 205 rtc::scoped_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel()); |
199 | 206 |
200 cricket::StreamParams stream1; | 207 cricket::StreamParams stream1; |
201 stream1.add_ssrc(41); | 208 stream1.add_ssrc(41); |
202 EXPECT_TRUE(dmc->AddSendStream(stream1)); | 209 EXPECT_TRUE(dmc->AddSendStream(stream1)); |
203 cricket::StreamParams stream2; | 210 cricket::StreamParams stream2; |
204 stream2.add_ssrc(42); | 211 stream2.add_ssrc(42); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 ASSERT_TRUE(dmc->AddSendStream(stream)); | 260 ASSERT_TRUE(dmc->AddSendStream(stream)); |
254 | 261 |
255 // Unknown codec; | 262 // Unknown codec; |
256 EXPECT_FALSE(dmc->SendData(params, payload, &result)); | 263 EXPECT_FALSE(dmc->SendData(params, payload, &result)); |
257 EXPECT_EQ(cricket::SDR_ERROR, result); | 264 EXPECT_EQ(cricket::SDR_ERROR, result); |
258 EXPECT_FALSE(HasSentData(0)); | 265 EXPECT_FALSE(HasSentData(0)); |
259 | 266 |
260 cricket::DataCodec codec; | 267 cricket::DataCodec codec; |
261 codec.id = 103; | 268 codec.id = 103; |
262 codec.name = cricket::kGoogleRtpDataCodecName; | 269 codec.name = cricket::kGoogleRtpDataCodecName; |
263 std::vector<cricket::DataCodec> codecs; | 270 cricket::DataSendParameters parameters; |
264 codecs.push_back(codec); | 271 parameters.codecs.push_back(codec); |
265 ASSERT_TRUE(dmc->SetSendCodecs(codecs)); | 272 ASSERT_TRUE(dmc->SetSendParameters(parameters)); |
266 | 273 |
267 // Length too large; | 274 // Length too large; |
268 std::string x10000(10000, 'x'); | 275 std::string x10000(10000, 'x'); |
269 EXPECT_FALSE(dmc->SendData( | 276 EXPECT_FALSE(dmc->SendData( |
270 params, rtc::Buffer(x10000.data(), x10000.length()), &result)); | 277 params, rtc::Buffer(x10000.data(), x10000.length()), &result)); |
271 EXPECT_EQ(cricket::SDR_ERROR, result); | 278 EXPECT_EQ(cricket::SDR_ERROR, result); |
272 EXPECT_FALSE(HasSentData(0)); | 279 EXPECT_FALSE(HasSentData(0)); |
273 | 280 |
274 // Finally works! | 281 // Finally works! |
275 EXPECT_TRUE(dmc->SendData(params, payload, &result)); | 282 EXPECT_TRUE(dmc->SendData(params, payload, &result)); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 cricket::StreamParams stream1; | 324 cricket::StreamParams stream1; |
318 stream1.add_ssrc(41); | 325 stream1.add_ssrc(41); |
319 ASSERT_TRUE(dmc1->AddSendStream(stream1)); | 326 ASSERT_TRUE(dmc1->AddSendStream(stream1)); |
320 cricket::StreamParams stream2; | 327 cricket::StreamParams stream2; |
321 stream2.add_ssrc(42); | 328 stream2.add_ssrc(42); |
322 ASSERT_TRUE(dmc2->AddSendStream(stream2)); | 329 ASSERT_TRUE(dmc2->AddSendStream(stream2)); |
323 | 330 |
324 cricket::DataCodec codec; | 331 cricket::DataCodec codec; |
325 codec.id = 103; | 332 codec.id = 103; |
326 codec.name = cricket::kGoogleRtpDataCodecName; | 333 codec.name = cricket::kGoogleRtpDataCodecName; |
327 std::vector<cricket::DataCodec> codecs; | 334 cricket::DataSendParameters parameters; |
328 codecs.push_back(codec); | 335 parameters.codecs.push_back(codec); |
329 ASSERT_TRUE(dmc1->SetSendCodecs(codecs)); | 336 ASSERT_TRUE(dmc1->SetSendParameters(parameters)); |
330 ASSERT_TRUE(dmc2->SetSendCodecs(codecs)); | 337 ASSERT_TRUE(dmc2->SetSendParameters(parameters)); |
331 | 338 |
332 cricket::SendDataParams params1; | 339 cricket::SendDataParams params1; |
333 params1.ssrc = 41; | 340 params1.ssrc = 41; |
334 cricket::SendDataParams params2; | 341 cricket::SendDataParams params2; |
335 params2.ssrc = 42; | 342 params2.ssrc = 42; |
336 | 343 |
337 unsigned char data[] = "foo"; | 344 unsigned char data[] = "foo"; |
338 rtc::Buffer payload(data, 3); | 345 rtc::Buffer payload(data, 3); |
339 cricket::SendDataResult result; | 346 cricket::SendDataResult result; |
340 | 347 |
(...skipping 23 matching lines...) Expand all Loading... |
364 } | 371 } |
365 | 372 |
366 TEST_F(RtpDataMediaChannelTest, SendDataRate) { | 373 TEST_F(RtpDataMediaChannelTest, SendDataRate) { |
367 rtc::scoped_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel()); | 374 rtc::scoped_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel()); |
368 | 375 |
369 ASSERT_TRUE(dmc->SetSend(true)); | 376 ASSERT_TRUE(dmc->SetSend(true)); |
370 | 377 |
371 cricket::DataCodec codec; | 378 cricket::DataCodec codec; |
372 codec.id = 103; | 379 codec.id = 103; |
373 codec.name = cricket::kGoogleRtpDataCodecName; | 380 codec.name = cricket::kGoogleRtpDataCodecName; |
374 std::vector<cricket::DataCodec> codecs; | 381 cricket::DataSendParameters parameters; |
375 codecs.push_back(codec); | 382 parameters.codecs.push_back(codec); |
376 ASSERT_TRUE(dmc->SetSendCodecs(codecs)); | 383 ASSERT_TRUE(dmc->SetSendParameters(parameters)); |
377 | 384 |
378 cricket::StreamParams stream; | 385 cricket::StreamParams stream; |
379 stream.add_ssrc(42); | 386 stream.add_ssrc(42); |
380 ASSERT_TRUE(dmc->AddSendStream(stream)); | 387 ASSERT_TRUE(dmc->AddSendStream(stream)); |
381 | 388 |
382 cricket::SendDataParams params; | 389 cricket::SendDataParams params; |
383 params.ssrc = 42; | 390 params.ssrc = 42; |
384 unsigned char data[] = "food"; | 391 unsigned char data[] = "food"; |
385 rtc::Buffer payload(data, 4); | 392 rtc::Buffer payload(data, 4); |
386 cricket::SendDataResult result; | 393 cricket::SendDataResult result; |
387 | 394 |
388 // With rtp overhead of 32 bytes, each one of our packets is 36 | 395 // With rtp overhead of 32 bytes, each one of our packets is 36 |
389 // bytes, or 288 bits. So, a limit of 872bps will allow 3 packets, | 396 // bytes, or 288 bits. So, a limit of 872bps will allow 3 packets, |
390 // but not four. | 397 // but not four. |
391 dmc->SetMaxSendBandwidth(872); | 398 parameters.max_bandwidth_bps = 872; |
| 399 ASSERT_TRUE(dmc->SetSendParameters(parameters)); |
392 | 400 |
393 EXPECT_TRUE(dmc->SendData(params, payload, &result)); | 401 EXPECT_TRUE(dmc->SendData(params, payload, &result)); |
394 EXPECT_TRUE(dmc->SendData(params, payload, &result)); | 402 EXPECT_TRUE(dmc->SendData(params, payload, &result)); |
395 EXPECT_TRUE(dmc->SendData(params, payload, &result)); | 403 EXPECT_TRUE(dmc->SendData(params, payload, &result)); |
396 EXPECT_FALSE(dmc->SendData(params, payload, &result)); | 404 EXPECT_FALSE(dmc->SendData(params, payload, &result)); |
397 EXPECT_FALSE(dmc->SendData(params, payload, &result)); | 405 EXPECT_FALSE(dmc->SendData(params, payload, &result)); |
398 | 406 |
399 SetNow(0.9); | 407 SetNow(0.9); |
400 EXPECT_FALSE(dmc->SendData(params, payload, &result)); | 408 EXPECT_FALSE(dmc->SendData(params, payload, &result)); |
401 | 409 |
(...skipping 27 matching lines...) Expand all Loading... |
429 | 437 |
430 dmc->SetReceive(true); | 438 dmc->SetReceive(true); |
431 | 439 |
432 // Unknown payload id | 440 // Unknown payload id |
433 dmc->OnPacketReceived(&packet, rtc::PacketTime()); | 441 dmc->OnPacketReceived(&packet, rtc::PacketTime()); |
434 EXPECT_FALSE(HasReceivedData()); | 442 EXPECT_FALSE(HasReceivedData()); |
435 | 443 |
436 cricket::DataCodec codec; | 444 cricket::DataCodec codec; |
437 codec.id = 103; | 445 codec.id = 103; |
438 codec.name = cricket::kGoogleRtpDataCodecName; | 446 codec.name = cricket::kGoogleRtpDataCodecName; |
439 std::vector<cricket::DataCodec> codecs; | 447 cricket::DataRecvParameters parameters; |
440 codecs.push_back(codec); | 448 parameters.codecs.push_back(codec); |
441 ASSERT_TRUE(dmc->SetRecvCodecs(codecs)); | 449 ASSERT_TRUE(dmc->SetRecvParameters(parameters)); |
442 | 450 |
443 // Unknown stream | 451 // Unknown stream |
444 dmc->OnPacketReceived(&packet, rtc::PacketTime()); | 452 dmc->OnPacketReceived(&packet, rtc::PacketTime()); |
445 EXPECT_FALSE(HasReceivedData()); | 453 EXPECT_FALSE(HasReceivedData()); |
446 | 454 |
447 cricket::StreamParams stream; | 455 cricket::StreamParams stream; |
448 stream.add_ssrc(42); | 456 stream.add_ssrc(42); |
449 ASSERT_TRUE(dmc->AddRecvStream(stream)); | 457 ASSERT_TRUE(dmc->AddRecvStream(stream)); |
450 | 458 |
451 // Finally works! | 459 // Finally works! |
452 dmc->OnPacketReceived(&packet, rtc::PacketTime()); | 460 dmc->OnPacketReceived(&packet, rtc::PacketTime()); |
453 EXPECT_TRUE(HasReceivedData()); | 461 EXPECT_TRUE(HasReceivedData()); |
454 EXPECT_EQ("abcde", GetReceivedData()); | 462 EXPECT_EQ("abcde", GetReceivedData()); |
455 EXPECT_EQ(5U, GetReceivedDataLen()); | 463 EXPECT_EQ(5U, GetReceivedDataLen()); |
456 } | 464 } |
457 | 465 |
458 TEST_F(RtpDataMediaChannelTest, InvalidRtpPackets) { | 466 TEST_F(RtpDataMediaChannelTest, InvalidRtpPackets) { |
459 unsigned char data[] = { | 467 unsigned char data[] = { |
460 0x80, 0x65, 0x00, 0x02 | 468 0x80, 0x65, 0x00, 0x02 |
461 }; | 469 }; |
462 rtc::Buffer packet(data, sizeof(data)); | 470 rtc::Buffer packet(data, sizeof(data)); |
463 | 471 |
464 rtc::scoped_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel()); | 472 rtc::scoped_ptr<cricket::RtpDataMediaChannel> dmc(CreateChannel()); |
465 | 473 |
466 // Too short | 474 // Too short |
467 dmc->OnPacketReceived(&packet, rtc::PacketTime()); | 475 dmc->OnPacketReceived(&packet, rtc::PacketTime()); |
468 EXPECT_FALSE(HasReceivedData()); | 476 EXPECT_FALSE(HasReceivedData()); |
469 } | 477 } |
OLD | NEW |