| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2008 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2008 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "webrtc/pc/channel.h" | 29 #include "webrtc/pc/channel.h" |
| 30 #include "webrtc/test/field_trial.h" | 30 #include "webrtc/test/field_trial.h" |
| 31 #include "webrtc/test/gtest.h" | 31 #include "webrtc/test/gtest.h" |
| 32 #include "webrtc/voice_engine/transmit_mixer.h" | 32 #include "webrtc/voice_engine/transmit_mixer.h" |
| 33 | 33 |
| 34 using testing::Return; | 34 using testing::Return; |
| 35 using testing::StrictMock; | 35 using testing::StrictMock; |
| 36 | 36 |
| 37 namespace { | 37 namespace { |
| 38 | 38 |
| 39 constexpr uint32_t kMaxUnsignaledRecvStreams = 1; |
| 40 |
| 39 const cricket::AudioCodec kPcmuCodec(0, "PCMU", 8000, 64000, 1); | 41 const cricket::AudioCodec kPcmuCodec(0, "PCMU", 8000, 64000, 1); |
| 40 const cricket::AudioCodec kIsacCodec(103, "ISAC", 16000, 32000, 1); | 42 const cricket::AudioCodec kIsacCodec(103, "ISAC", 16000, 32000, 1); |
| 41 const cricket::AudioCodec kOpusCodec(111, "opus", 48000, 64000, 2); | 43 const cricket::AudioCodec kOpusCodec(111, "opus", 48000, 64000, 2); |
| 42 const cricket::AudioCodec kG722CodecVoE(9, "G722", 16000, 64000, 1); | 44 const cricket::AudioCodec kG722CodecVoE(9, "G722", 16000, 64000, 1); |
| 43 const cricket::AudioCodec kG722CodecSdp(9, "G722", 8000, 64000, 1); | 45 const cricket::AudioCodec kG722CodecSdp(9, "G722", 8000, 64000, 1); |
| 44 const cricket::AudioCodec kCn8000Codec(13, "CN", 8000, 0, 1); | 46 const cricket::AudioCodec kCn8000Codec(13, "CN", 8000, 0, 1); |
| 45 const cricket::AudioCodec kCn16000Codec(105, "CN", 16000, 0, 1); | 47 const cricket::AudioCodec kCn16000Codec(105, "CN", 16000, 0, 1); |
| 46 const cricket::AudioCodec | 48 const cricket::AudioCodec |
| 47 kTelephoneEventCodec1(106, "telephone-event", 8000, 0, 1); | 49 kTelephoneEventCodec1(106, "telephone-event", 8000, 0, 1); |
| 48 const cricket::AudioCodec | 50 const cricket::AudioCodec |
| (...skipping 2728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2777 sizeof(kPcmuFrame))); | 2779 sizeof(kPcmuFrame))); |
| 2778 } | 2780 } |
| 2779 | 2781 |
| 2780 // Test that receiving N unsignaled stream works (streams will be created), and | 2782 // Test that receiving N unsignaled stream works (streams will be created), and |
| 2781 // that packets are forwarded to them all. | 2783 // that packets are forwarded to them all. |
| 2782 TEST_F(WebRtcVoiceEngineTestFake, RecvMultipleUnsignaled) { | 2784 TEST_F(WebRtcVoiceEngineTestFake, RecvMultipleUnsignaled) { |
| 2783 EXPECT_TRUE(SetupChannel()); | 2785 EXPECT_TRUE(SetupChannel()); |
| 2784 unsigned char packet[sizeof(kPcmuFrame)]; | 2786 unsigned char packet[sizeof(kPcmuFrame)]; |
| 2785 memcpy(packet, kPcmuFrame, sizeof(kPcmuFrame)); | 2787 memcpy(packet, kPcmuFrame, sizeof(kPcmuFrame)); |
| 2786 | 2788 |
| 2787 constexpr uint32_t kMaxUnsignaledCount = 50; | |
| 2788 | |
| 2789 // Note that SSRC = 0 is not supported. | 2789 // Note that SSRC = 0 is not supported. |
| 2790 for (uint32_t ssrc = 1; ssrc < (1 + kMaxUnsignaledCount); ++ssrc) { | 2790 for (uint32_t ssrc = 1; ssrc < (1 + kMaxUnsignaledRecvStreams); ++ssrc) { |
| 2791 rtc::SetBE32(&packet[8], ssrc); | 2791 rtc::SetBE32(&packet[8], ssrc); |
| 2792 DeliverPacket(packet, sizeof(packet)); | 2792 DeliverPacket(packet, sizeof(packet)); |
| 2793 | 2793 |
| 2794 // Verify we have one new stream for each loop iteration. | 2794 // Verify we have one new stream for each loop iteration. |
| 2795 EXPECT_EQ(ssrc, call_.GetAudioReceiveStreams().size()); | 2795 EXPECT_EQ(ssrc, call_.GetAudioReceiveStreams().size()); |
| 2796 EXPECT_EQ(1, GetRecvStream(ssrc).received_packets()); | 2796 EXPECT_EQ(1, GetRecvStream(ssrc).received_packets()); |
| 2797 EXPECT_TRUE(GetRecvStream(ssrc).VerifyLastPacket(packet, sizeof(packet))); | 2797 EXPECT_TRUE(GetRecvStream(ssrc).VerifyLastPacket(packet, sizeof(packet))); |
| 2798 } | 2798 } |
| 2799 | 2799 |
| 2800 // Sending on the same SSRCs again should not create new streams. | 2800 // Sending on the same SSRCs again should not create new streams. |
| 2801 for (uint32_t ssrc = 1; ssrc < (1 + kMaxUnsignaledCount); ++ssrc) { | 2801 for (uint32_t ssrc = 1; ssrc < (1 + kMaxUnsignaledRecvStreams); ++ssrc) { |
| 2802 rtc::SetBE32(&packet[8], ssrc); | 2802 rtc::SetBE32(&packet[8], ssrc); |
| 2803 DeliverPacket(packet, sizeof(packet)); | 2803 DeliverPacket(packet, sizeof(packet)); |
| 2804 | 2804 |
| 2805 EXPECT_EQ(kMaxUnsignaledCount, call_.GetAudioReceiveStreams().size()); | 2805 EXPECT_EQ(kMaxUnsignaledRecvStreams, call_.GetAudioReceiveStreams().size()); |
| 2806 EXPECT_EQ(2, GetRecvStream(ssrc).received_packets()); | 2806 EXPECT_EQ(2, GetRecvStream(ssrc).received_packets()); |
| 2807 EXPECT_TRUE(GetRecvStream(ssrc).VerifyLastPacket(packet, sizeof(packet))); | 2807 EXPECT_TRUE(GetRecvStream(ssrc).VerifyLastPacket(packet, sizeof(packet))); |
| 2808 } | 2808 } |
| 2809 | 2809 |
| 2810 // Send on another SSRC, the oldest unsignaled stream (SSRC=1) is replaced. | 2810 // Send on another SSRC, the oldest unsignaled stream (SSRC=1) is replaced. |
| 2811 constexpr uint32_t kAnotherSsrc = 667; | 2811 constexpr uint32_t kAnotherSsrc = 667; |
| 2812 rtc::SetBE32(&packet[8], kAnotherSsrc); | 2812 rtc::SetBE32(&packet[8], kAnotherSsrc); |
| 2813 DeliverPacket(packet, sizeof(packet)); | 2813 DeliverPacket(packet, sizeof(packet)); |
| 2814 | 2814 |
| 2815 const auto& streams = call_.GetAudioReceiveStreams(); | 2815 const auto& streams = call_.GetAudioReceiveStreams(); |
| 2816 EXPECT_EQ(kMaxUnsignaledCount, streams.size()); | 2816 EXPECT_EQ(kMaxUnsignaledRecvStreams, streams.size()); |
| 2817 size_t i = 0; | 2817 size_t i = 0; |
| 2818 for (uint32_t ssrc = 2; ssrc < (1 + kMaxUnsignaledCount); ++ssrc, ++i) { | 2818 for (uint32_t ssrc = 2; ssrc < (1 + kMaxUnsignaledRecvStreams); ++ssrc, ++i) { |
| 2819 EXPECT_EQ(ssrc, streams[i]->GetConfig().rtp.remote_ssrc); | 2819 EXPECT_EQ(ssrc, streams[i]->GetConfig().rtp.remote_ssrc); |
| 2820 EXPECT_EQ(2, streams[i]->received_packets()); | 2820 EXPECT_EQ(2, streams[i]->received_packets()); |
| 2821 } | 2821 } |
| 2822 EXPECT_EQ(kAnotherSsrc, streams[i]->GetConfig().rtp.remote_ssrc); | 2822 EXPECT_EQ(kAnotherSsrc, streams[i]->GetConfig().rtp.remote_ssrc); |
| 2823 EXPECT_EQ(1, streams[i]->received_packets()); | 2823 EXPECT_EQ(1, streams[i]->received_packets()); |
| 2824 // Sanity check that we've checked all streams. | 2824 // Sanity check that we've checked all streams. |
| 2825 EXPECT_EQ(kMaxUnsignaledCount, (i + 1)); | 2825 EXPECT_EQ(kMaxUnsignaledRecvStreams, (i + 1)); |
| 2826 } | 2826 } |
| 2827 | 2827 |
| 2828 // Test that a default channel is created even after a signaled stream has been | 2828 // Test that a default channel is created even after a signaled stream has been |
| 2829 // added, and that this stream will get any packets for unknown SSRCs. | 2829 // added, and that this stream will get any packets for unknown SSRCs. |
| 2830 TEST_F(WebRtcVoiceEngineTestFake, RecvUnsignaledAfterSignaled) { | 2830 TEST_F(WebRtcVoiceEngineTestFake, RecvUnsignaledAfterSignaled) { |
| 2831 EXPECT_TRUE(SetupChannel()); | 2831 EXPECT_TRUE(SetupChannel()); |
| 2832 unsigned char packet[sizeof(kPcmuFrame)]; | 2832 unsigned char packet[sizeof(kPcmuFrame)]; |
| 2833 memcpy(packet, kPcmuFrame, sizeof(kPcmuFrame)); | 2833 memcpy(packet, kPcmuFrame, sizeof(kPcmuFrame)); |
| 2834 | 2834 |
| 2835 // Add a known stream, send packet and verify we got it. | 2835 // Add a known stream, send packet and verify we got it. |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3295 | 3295 |
| 3296 // Spawn an unsignaled stream by sending a packet - gain should be 2. | 3296 // Spawn an unsignaled stream by sending a packet - gain should be 2. |
| 3297 unsigned char pcmuFrame2[sizeof(kPcmuFrame)]; | 3297 unsigned char pcmuFrame2[sizeof(kPcmuFrame)]; |
| 3298 memcpy(pcmuFrame2, kPcmuFrame, sizeof(kPcmuFrame)); | 3298 memcpy(pcmuFrame2, kPcmuFrame, sizeof(kPcmuFrame)); |
| 3299 rtc::SetBE32(&pcmuFrame2[8], kSsrcX); | 3299 rtc::SetBE32(&pcmuFrame2[8], kSsrcX); |
| 3300 DeliverPacket(pcmuFrame2, sizeof(pcmuFrame2)); | 3300 DeliverPacket(pcmuFrame2, sizeof(pcmuFrame2)); |
| 3301 EXPECT_DOUBLE_EQ(2, GetRecvStream(kSsrcX).gain()); | 3301 EXPECT_DOUBLE_EQ(2, GetRecvStream(kSsrcX).gain()); |
| 3302 | 3302 |
| 3303 // Setting gain with SSRC=0 should affect all unsignaled streams. | 3303 // Setting gain with SSRC=0 should affect all unsignaled streams. |
| 3304 EXPECT_TRUE(channel_->SetOutputVolume(kSsrc0, 3)); | 3304 EXPECT_TRUE(channel_->SetOutputVolume(kSsrc0, 3)); |
| 3305 EXPECT_DOUBLE_EQ(3, GetRecvStream(kSsrc1).gain()); | 3305 if (kMaxUnsignaledRecvStreams > 1) { |
| 3306 EXPECT_DOUBLE_EQ(3, GetRecvStream(kSsrc1).gain()); |
| 3307 } |
| 3306 EXPECT_DOUBLE_EQ(3, GetRecvStream(kSsrcX).gain()); | 3308 EXPECT_DOUBLE_EQ(3, GetRecvStream(kSsrcX).gain()); |
| 3307 | 3309 |
| 3308 // Setting gain on an individual stream affects only that. | 3310 // Setting gain on an individual stream affects only that. |
| 3309 EXPECT_TRUE(channel_->SetOutputVolume(kSsrcX, 4)); | 3311 EXPECT_TRUE(channel_->SetOutputVolume(kSsrcX, 4)); |
| 3310 EXPECT_DOUBLE_EQ(3, GetRecvStream(kSsrc1).gain()); | 3312 if (kMaxUnsignaledRecvStreams > 1) { |
| 3313 EXPECT_DOUBLE_EQ(3, GetRecvStream(kSsrc1).gain()); |
| 3314 } |
| 3311 EXPECT_DOUBLE_EQ(4, GetRecvStream(kSsrcX).gain()); | 3315 EXPECT_DOUBLE_EQ(4, GetRecvStream(kSsrcX).gain()); |
| 3312 } | 3316 } |
| 3313 | 3317 |
| 3314 TEST_F(WebRtcVoiceEngineTestFake, SetsSyncGroupFromSyncLabel) { | 3318 TEST_F(WebRtcVoiceEngineTestFake, SetsSyncGroupFromSyncLabel) { |
| 3315 const uint32_t kAudioSsrc = 123; | 3319 const uint32_t kAudioSsrc = 123; |
| 3316 const std::string kSyncLabel = "AvSyncLabel"; | 3320 const std::string kSyncLabel = "AvSyncLabel"; |
| 3317 | 3321 |
| 3318 EXPECT_TRUE(SetupSendStream()); | 3322 EXPECT_TRUE(SetupSendStream()); |
| 3319 cricket::StreamParams sp = cricket::StreamParams::CreateLegacy(kAudioSsrc); | 3323 cricket::StreamParams sp = cricket::StreamParams::CreateLegacy(kAudioSsrc); |
| 3320 sp.sync_label = kSyncLabel; | 3324 sp.sync_label = kSyncLabel; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3487 EXPECT_TRUE(channel_->RemoveRecvStream(kSsrc1)); | 3491 EXPECT_TRUE(channel_->RemoveRecvStream(kSsrc1)); |
| 3488 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame)); | 3492 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame)); |
| 3489 EXPECT_NE(nullptr, GetRecvStream(kSsrc1).sink()); | 3493 EXPECT_NE(nullptr, GetRecvStream(kSsrc1).sink()); |
| 3490 | 3494 |
| 3491 // Spawn another unsignaled stream - it should be assigned the default sink | 3495 // Spawn another unsignaled stream - it should be assigned the default sink |
| 3492 // and the previous unsignaled stream should lose it. | 3496 // and the previous unsignaled stream should lose it. |
| 3493 unsigned char pcmuFrame2[sizeof(kPcmuFrame)]; | 3497 unsigned char pcmuFrame2[sizeof(kPcmuFrame)]; |
| 3494 memcpy(pcmuFrame2, kPcmuFrame, sizeof(kPcmuFrame)); | 3498 memcpy(pcmuFrame2, kPcmuFrame, sizeof(kPcmuFrame)); |
| 3495 rtc::SetBE32(&pcmuFrame2[8], kSsrcX); | 3499 rtc::SetBE32(&pcmuFrame2[8], kSsrcX); |
| 3496 DeliverPacket(pcmuFrame2, sizeof(pcmuFrame2)); | 3500 DeliverPacket(pcmuFrame2, sizeof(pcmuFrame2)); |
| 3497 EXPECT_EQ(nullptr, GetRecvStream(kSsrc1).sink()); | 3501 if (kMaxUnsignaledRecvStreams > 1) { |
| 3502 EXPECT_EQ(nullptr, GetRecvStream(kSsrc1).sink()); |
| 3503 } |
| 3498 EXPECT_NE(nullptr, GetRecvStream(kSsrcX).sink()); | 3504 EXPECT_NE(nullptr, GetRecvStream(kSsrcX).sink()); |
| 3499 | 3505 |
| 3500 // Reset the default sink - the second unsignaled stream should lose it. | 3506 // Reset the default sink - the second unsignaled stream should lose it. |
| 3501 channel_->SetRawAudioSink(kSsrc0, nullptr); | 3507 channel_->SetRawAudioSink(kSsrc0, nullptr); |
| 3502 EXPECT_EQ(nullptr, GetRecvStream(kSsrc1).sink()); | 3508 if (kMaxUnsignaledRecvStreams > 1) { |
| 3509 EXPECT_EQ(nullptr, GetRecvStream(kSsrc1).sink()); |
| 3510 } |
| 3503 EXPECT_EQ(nullptr, GetRecvStream(kSsrcX).sink()); | 3511 EXPECT_EQ(nullptr, GetRecvStream(kSsrcX).sink()); |
| 3504 | 3512 |
| 3505 // Try setting the default sink while two streams exists. | 3513 // Try setting the default sink while two streams exists. |
| 3506 channel_->SetRawAudioSink(kSsrc0, std::move(fake_sink_3)); | 3514 channel_->SetRawAudioSink(kSsrc0, std::move(fake_sink_3)); |
| 3507 EXPECT_EQ(nullptr, GetRecvStream(kSsrc1).sink()); | 3515 if (kMaxUnsignaledRecvStreams > 1) { |
| 3516 EXPECT_EQ(nullptr, GetRecvStream(kSsrc1).sink()); |
| 3517 } |
| 3508 EXPECT_NE(nullptr, GetRecvStream(kSsrcX).sink()); | 3518 EXPECT_NE(nullptr, GetRecvStream(kSsrcX).sink()); |
| 3509 | 3519 |
| 3510 // Try setting the sink for the first unsignaled stream using its known SSRC. | 3520 // Try setting the sink for the first unsignaled stream using its known SSRC. |
| 3511 channel_->SetRawAudioSink(kSsrc1, std::move(fake_sink_4)); | 3521 channel_->SetRawAudioSink(kSsrc1, std::move(fake_sink_4)); |
| 3512 EXPECT_NE(nullptr, GetRecvStream(kSsrc1).sink()); | 3522 if (kMaxUnsignaledRecvStreams > 1) { |
| 3523 EXPECT_NE(nullptr, GetRecvStream(kSsrc1).sink()); |
| 3524 } |
| 3513 EXPECT_NE(nullptr, GetRecvStream(kSsrcX).sink()); | 3525 EXPECT_NE(nullptr, GetRecvStream(kSsrcX).sink()); |
| 3514 EXPECT_NE(GetRecvStream(kSsrc1).sink(), GetRecvStream(kSsrcX).sink()); | 3526 if (kMaxUnsignaledRecvStreams > 1) { |
| 3527 EXPECT_NE(GetRecvStream(kSsrc1).sink(), GetRecvStream(kSsrcX).sink()); |
| 3528 } |
| 3515 } | 3529 } |
| 3516 | 3530 |
| 3517 // Test that, just like the video channel, the voice channel communicates the | 3531 // Test that, just like the video channel, the voice channel communicates the |
| 3518 // network state to the call. | 3532 // network state to the call. |
| 3519 TEST_F(WebRtcVoiceEngineTestFake, OnReadyToSendSignalsNetworkState) { | 3533 TEST_F(WebRtcVoiceEngineTestFake, OnReadyToSendSignalsNetworkState) { |
| 3520 EXPECT_TRUE(SetupChannel()); | 3534 EXPECT_TRUE(SetupChannel()); |
| 3521 | 3535 |
| 3522 EXPECT_EQ(webrtc::kNetworkUp, | 3536 EXPECT_EQ(webrtc::kNetworkUp, |
| 3523 call_.GetNetworkState(webrtc::MediaType::AUDIO)); | 3537 call_.GetNetworkState(webrtc::MediaType::AUDIO)); |
| 3524 EXPECT_EQ(webrtc::kNetworkUp, | 3538 EXPECT_EQ(webrtc::kNetworkUp, |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3795 // Without this cast, the comparison turned unsigned and, thus, failed for -1. | 3809 // Without this cast, the comparison turned unsigned and, thus, failed for -1. |
| 3796 const int num_specs = static_cast<int>(specs.size()); | 3810 const int num_specs = static_cast<int>(specs.size()); |
| 3797 EXPECT_GE(find_codec({"cn", 8000, 1}), num_specs); | 3811 EXPECT_GE(find_codec({"cn", 8000, 1}), num_specs); |
| 3798 EXPECT_GE(find_codec({"cn", 16000, 1}), num_specs); | 3812 EXPECT_GE(find_codec({"cn", 16000, 1}), num_specs); |
| 3799 EXPECT_EQ(find_codec({"cn", 32000, 1}), -1); | 3813 EXPECT_EQ(find_codec({"cn", 32000, 1}), -1); |
| 3800 EXPECT_GE(find_codec({"telephone-event", 8000, 1}), num_specs); | 3814 EXPECT_GE(find_codec({"telephone-event", 8000, 1}), num_specs); |
| 3801 EXPECT_GE(find_codec({"telephone-event", 16000, 1}), num_specs); | 3815 EXPECT_GE(find_codec({"telephone-event", 16000, 1}), num_specs); |
| 3802 EXPECT_GE(find_codec({"telephone-event", 32000, 1}), num_specs); | 3816 EXPECT_GE(find_codec({"telephone-event", 32000, 1}), num_specs); |
| 3803 EXPECT_GE(find_codec({"telephone-event", 48000, 1}), num_specs); | 3817 EXPECT_GE(find_codec({"telephone-event", 48000, 1}), num_specs); |
| 3804 } | 3818 } |
| OLD | NEW |