OLD | NEW |
1 /* | 1 /* |
2 * libjingle | 2 * libjingle |
3 * Copyright 2008 Google Inc. | 3 * Copyright 2008 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 2406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2417 EXPECT_TRUE(channel_->AddSendStream( | 2417 EXPECT_TRUE(channel_->AddSendStream( |
2418 cricket::StreamParams::CreateLegacy(1234))); | 2418 cricket::StreamParams::CreateLegacy(1234))); |
2419 | 2419 |
2420 EXPECT_TRUE(call_.GetAudioSendStream(1234)); | 2420 EXPECT_TRUE(call_.GetAudioSendStream(1234)); |
2421 EXPECT_EQ(1234U, voe_.GetLocalSSRC(receive_channel_num)); | 2421 EXPECT_EQ(1234U, voe_.GetLocalSSRC(receive_channel_num)); |
2422 } | 2422 } |
2423 | 2423 |
2424 // Test that we can properly receive packets. | 2424 // Test that we can properly receive packets. |
2425 TEST_F(WebRtcVoiceEngineTestFake, Recv) { | 2425 TEST_F(WebRtcVoiceEngineTestFake, Recv) { |
2426 EXPECT_TRUE(SetupEngine()); | 2426 EXPECT_TRUE(SetupEngine()); |
| 2427 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); |
2427 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame)); | 2428 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame)); |
2428 int channel_num = voe_.GetLastChannel(); | 2429 int channel_num = voe_.GetLastChannel(); |
2429 EXPECT_TRUE(voe_.CheckPacket(channel_num, kPcmuFrame, | 2430 EXPECT_TRUE(voe_.CheckPacket(channel_num, kPcmuFrame, sizeof(kPcmuFrame))); |
2430 sizeof(kPcmuFrame))); | |
2431 } | 2431 } |
2432 | 2432 |
2433 // Test that we can properly receive packets on multiple streams. | 2433 // Test that we can properly receive packets on multiple streams. |
2434 TEST_F(WebRtcVoiceEngineTestFake, RecvWithMultipleStreams) { | 2434 TEST_F(WebRtcVoiceEngineTestFake, RecvWithMultipleStreams) { |
2435 EXPECT_TRUE(SetupEngineWithSendStream()); | 2435 EXPECT_TRUE(SetupEngine()); |
2436 EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); | |
2437 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); | 2436 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); |
2438 int channel_num1 = voe_.GetLastChannel(); | 2437 int channel_num1 = voe_.GetLastChannel(); |
2439 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); | 2438 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); |
2440 int channel_num2 = voe_.GetLastChannel(); | 2439 int channel_num2 = voe_.GetLastChannel(); |
2441 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3))); | 2440 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(3))); |
2442 int channel_num3 = voe_.GetLastChannel(); | 2441 int channel_num3 = voe_.GetLastChannel(); |
2443 // Create packets with the right SSRCs. | 2442 // Create packets with the right SSRCs. |
2444 char packets[4][sizeof(kPcmuFrame)]; | 2443 char packets[4][sizeof(kPcmuFrame)]; |
2445 for (size_t i = 0; i < arraysize(packets); ++i) { | 2444 for (size_t i = 0; i < arraysize(packets); ++i) { |
2446 memcpy(packets[i], kPcmuFrame, sizeof(kPcmuFrame)); | 2445 memcpy(packets[i], kPcmuFrame, sizeof(kPcmuFrame)); |
2447 rtc::SetBE32(packets[i] + 8, static_cast<uint32_t>(i)); | 2446 rtc::SetBE32(packets[i] + 8, static_cast<uint32_t>(i)); |
2448 } | 2447 } |
2449 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1)); | 2448 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1)); |
2450 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2)); | 2449 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2)); |
2451 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3)); | 2450 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3)); |
| 2451 |
2452 DeliverPacket(packets[0], sizeof(packets[0])); | 2452 DeliverPacket(packets[0], sizeof(packets[0])); |
2453 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1)); | 2453 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1)); |
2454 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2)); | 2454 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2)); |
2455 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3)); | 2455 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3)); |
| 2456 |
2456 DeliverPacket(packets[1], sizeof(packets[1])); | 2457 DeliverPacket(packets[1], sizeof(packets[1])); |
2457 EXPECT_TRUE(voe_.CheckPacket(channel_num1, packets[1], | 2458 EXPECT_TRUE(voe_.CheckPacket(channel_num1, packets[1], sizeof(packets[1]))); |
2458 sizeof(packets[1]))); | |
2459 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2)); | 2459 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2)); |
2460 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3)); | 2460 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3)); |
| 2461 |
2461 DeliverPacket(packets[2], sizeof(packets[2])); | 2462 DeliverPacket(packets[2], sizeof(packets[2])); |
2462 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1)); | 2463 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1)); |
2463 EXPECT_TRUE(voe_.CheckPacket(channel_num2, packets[2], | 2464 EXPECT_TRUE(voe_.CheckPacket(channel_num2, packets[2], sizeof(packets[2]))); |
2464 sizeof(packets[2]))); | |
2465 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3)); | 2465 EXPECT_TRUE(voe_.CheckNoPacket(channel_num3)); |
| 2466 |
2466 DeliverPacket(packets[3], sizeof(packets[3])); | 2467 DeliverPacket(packets[3], sizeof(packets[3])); |
2467 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1)); | 2468 EXPECT_TRUE(voe_.CheckNoPacket(channel_num1)); |
2468 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2)); | 2469 EXPECT_TRUE(voe_.CheckNoPacket(channel_num2)); |
2469 EXPECT_TRUE(voe_.CheckPacket(channel_num3, packets[3], | 2470 EXPECT_TRUE(voe_.CheckPacket(channel_num3, packets[3], sizeof(packets[3]))); |
2470 sizeof(packets[3]))); | 2471 |
2471 EXPECT_TRUE(channel_->RemoveRecvStream(3)); | 2472 EXPECT_TRUE(channel_->RemoveRecvStream(3)); |
2472 EXPECT_TRUE(channel_->RemoveRecvStream(2)); | 2473 EXPECT_TRUE(channel_->RemoveRecvStream(2)); |
2473 EXPECT_TRUE(channel_->RemoveRecvStream(1)); | 2474 EXPECT_TRUE(channel_->RemoveRecvStream(1)); |
2474 } | 2475 } |
2475 | 2476 |
| 2477 // Test that receiving on an unsignalled stream works (default channel will be |
| 2478 // created). |
| 2479 TEST_F(WebRtcVoiceEngineTestFake, RecvUnsignalled) { |
| 2480 EXPECT_TRUE(SetupEngine()); |
| 2481 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame)); |
| 2482 int channel_num = voe_.GetLastChannel(); |
| 2483 EXPECT_TRUE(voe_.CheckPacket(channel_num, kPcmuFrame, sizeof(kPcmuFrame))); |
| 2484 } |
| 2485 |
| 2486 // Test that receiving on an unsignalled stream works (default channel will be |
| 2487 // created), and that packets will be forwarded to the default channel |
| 2488 // regardless of their SSRCs. |
| 2489 TEST_F(WebRtcVoiceEngineTestFake, RecvUnsignalledWithSsrcSwitch) { |
| 2490 EXPECT_TRUE(SetupEngine()); |
| 2491 char packet[sizeof(kPcmuFrame)]; |
| 2492 memcpy(packet, kPcmuFrame, sizeof(kPcmuFrame)); |
| 2493 |
| 2494 // Note that the first unknown SSRC cannot be 0, because we only support |
| 2495 // creating receive streams for SSRC!=0. |
| 2496 DeliverPacket(packet, sizeof(packet)); |
| 2497 int channel_num = voe_.GetLastChannel(); |
| 2498 EXPECT_TRUE(voe_.CheckPacket(channel_num, packet, sizeof(packet))); |
| 2499 // Once we have the default channel, SSRC==0 will be ok. |
| 2500 for (uint32_t ssrc = 0; ssrc < 10; ++ssrc) { |
| 2501 rtc::SetBE32(&packet[8], ssrc); |
| 2502 DeliverPacket(packet, sizeof(packet)); |
| 2503 EXPECT_TRUE(voe_.CheckPacket(channel_num, packet, sizeof(packet))); |
| 2504 } |
| 2505 } |
| 2506 |
| 2507 // Test that a default channel is created even after a signalled stream has been |
| 2508 // added, and that this stream will get any packets for unknown SSRCs. |
| 2509 TEST_F(WebRtcVoiceEngineTestFake, RecvUnsignalledAfterSignalled) { |
| 2510 EXPECT_TRUE(SetupEngine()); |
| 2511 char packet[sizeof(kPcmuFrame)]; |
| 2512 memcpy(packet, kPcmuFrame, sizeof(kPcmuFrame)); |
| 2513 |
| 2514 // Add a known stream, send packet and verify we got it. |
| 2515 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); |
| 2516 int signalled_channel_num = voe_.GetLastChannel(); |
| 2517 DeliverPacket(packet, sizeof(packet)); |
| 2518 EXPECT_TRUE(voe_.CheckPacket(signalled_channel_num, packet, sizeof(packet))); |
| 2519 |
| 2520 // Note that the first unknown SSRC cannot be 0, because we only support |
| 2521 // creating receive streams for SSRC!=0. |
| 2522 rtc::SetBE32(&packet[8], 7011); |
| 2523 DeliverPacket(packet, sizeof(packet)); |
| 2524 int channel_num = voe_.GetLastChannel(); |
| 2525 EXPECT_NE(channel_num, signalled_channel_num); |
| 2526 EXPECT_TRUE(voe_.CheckPacket(channel_num, packet, sizeof(packet))); |
| 2527 // Once we have the default channel, SSRC==0 will be ok. |
| 2528 for (uint32_t ssrc = 0; ssrc < 20; ssrc += 2) { |
| 2529 rtc::SetBE32(&packet[8], ssrc); |
| 2530 DeliverPacket(packet, sizeof(packet)); |
| 2531 EXPECT_TRUE(voe_.CheckPacket(channel_num, packet, sizeof(packet))); |
| 2532 } |
| 2533 } |
| 2534 |
2476 // Test that we properly handle failures to add a receive stream. | 2535 // Test that we properly handle failures to add a receive stream. |
2477 TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamFail) { | 2536 TEST_F(WebRtcVoiceEngineTestFake, AddRecvStreamFail) { |
2478 EXPECT_TRUE(SetupEngine()); | 2537 EXPECT_TRUE(SetupEngine()); |
2479 voe_.set_fail_create_channel(true); | 2538 voe_.set_fail_create_channel(true); |
2480 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); | 2539 EXPECT_FALSE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); |
2481 } | 2540 } |
2482 | 2541 |
2483 // Test that we properly handle failures to add a send stream. | 2542 // Test that we properly handle failures to add a send stream. |
2484 TEST_F(WebRtcVoiceEngineTestFake, AddSendStreamFail) { | 2543 TEST_F(WebRtcVoiceEngineTestFake, AddSendStreamFail) { |
2485 EXPECT_TRUE(SetupEngine()); | 2544 EXPECT_TRUE(SetupEngine()); |
(...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3320 cricket::WebRtcVoiceEngine engine; | 3379 cricket::WebRtcVoiceEngine engine; |
3321 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); | 3380 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); |
3322 rtc::scoped_ptr<webrtc::Call> call( | 3381 rtc::scoped_ptr<webrtc::Call> call( |
3323 webrtc::Call::Create(webrtc::Call::Config())); | 3382 webrtc::Call::Create(webrtc::Call::Config())); |
3324 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::AudioOptions(), | 3383 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::AudioOptions(), |
3325 call.get()); | 3384 call.get()); |
3326 cricket::AudioRecvParameters parameters; | 3385 cricket::AudioRecvParameters parameters; |
3327 parameters.codecs = engine.codecs(); | 3386 parameters.codecs = engine.codecs(); |
3328 EXPECT_TRUE(channel.SetRecvParameters(parameters)); | 3387 EXPECT_TRUE(channel.SetRecvParameters(parameters)); |
3329 } | 3388 } |
OLD | NEW |