Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(87)

Side by Side Diff: webrtc/media/engine/webrtcvoiceengine_unittest.cc

Issue 2685893002: Support N unsignaled audio streams (Closed)
Patch Set: bad comment Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 2722 matching lines...) Expand 10 before | Expand all | Expand 10 after
2733 EXPECT_EQ(s1.received_packets(), 1); 2733 EXPECT_EQ(s1.received_packets(), 1);
2734 EXPECT_EQ(s2.received_packets(), 1); 2734 EXPECT_EQ(s2.received_packets(), 1);
2735 EXPECT_EQ(s3.received_packets(), 1); 2735 EXPECT_EQ(s3.received_packets(), 1);
2736 EXPECT_TRUE(s3.VerifyLastPacket(packets[3], sizeof(packets[3]))); 2736 EXPECT_TRUE(s3.VerifyLastPacket(packets[3], sizeof(packets[3])));
2737 2737
2738 EXPECT_TRUE(channel_->RemoveRecvStream(ssrc3)); 2738 EXPECT_TRUE(channel_->RemoveRecvStream(ssrc3));
2739 EXPECT_TRUE(channel_->RemoveRecvStream(ssrc2)); 2739 EXPECT_TRUE(channel_->RemoveRecvStream(ssrc2));
2740 EXPECT_TRUE(channel_->RemoveRecvStream(ssrc1)); 2740 EXPECT_TRUE(channel_->RemoveRecvStream(ssrc1));
2741 } 2741 }
2742 2742
2743 // Test that receiving on an unsignalled stream works (default channel will be 2743 // Test that receiving on an unsignaled stream works (a stream is created).
2744 // created). 2744 TEST_F(WebRtcVoiceEngineTestFake, RecvUnsignaled) {
2745 TEST_F(WebRtcVoiceEngineTestFake, RecvUnsignalled) {
2746 EXPECT_TRUE(SetupChannel()); 2745 EXPECT_TRUE(SetupChannel());
2747 EXPECT_EQ(0, call_.GetAudioReceiveStreams().size()); 2746 EXPECT_EQ(0, call_.GetAudioReceiveStreams().size());
2748 2747
2749 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame)); 2748 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
2750 2749
2751 EXPECT_EQ(1, call_.GetAudioReceiveStreams().size()); 2750 EXPECT_EQ(1, call_.GetAudioReceiveStreams().size());
2752 EXPECT_TRUE(GetRecvStream(1).VerifyLastPacket(kPcmuFrame, 2751 EXPECT_TRUE(GetRecvStream(1).VerifyLastPacket(kPcmuFrame,
2753 sizeof(kPcmuFrame))); 2752 sizeof(kPcmuFrame)));
2754 } 2753 }
2755 2754
2756 // Test that receiving on an unsignalled stream works (default channel will be 2755 // Test that receiving N unsignaled stream works (streams will be created), and
2757 // created), and that packets will be forwarded to the default channel 2756 // that packets are forwarded to them all.
2758 // regardless of their SSRCs. 2757 TEST_F(WebRtcVoiceEngineTestFake, RecvUnsignaledWithSsrcSwitch) {
2759 TEST_F(WebRtcVoiceEngineTestFake, RecvUnsignalledWithSsrcSwitch) {
2760 EXPECT_TRUE(SetupChannel()); 2758 EXPECT_TRUE(SetupChannel());
2761 unsigned char packet[sizeof(kPcmuFrame)]; 2759 unsigned char packet[sizeof(kPcmuFrame)];
2762 memcpy(packet, kPcmuFrame, sizeof(kPcmuFrame)); 2760 memcpy(packet, kPcmuFrame, sizeof(kPcmuFrame));
2763 2761
2764 // Note that ssrc = 0 is not supported. 2762 constexpr uint32_t kMaxUnsignaledCount = 50;
2765 uint32_t ssrc = 1; 2763
2766 for (; ssrc < 10; ++ssrc) { 2764 // Note that SSRC = 0 is not supported.
2765 for (uint32_t ssrc = 1; ssrc < (1 + kMaxUnsignaledCount); ++ssrc) {
2767 rtc::SetBE32(&packet[8], ssrc); 2766 rtc::SetBE32(&packet[8], ssrc);
2768 DeliverPacket(packet, sizeof(packet)); 2767 DeliverPacket(packet, sizeof(packet));
2769 2768
2770 // Verify we only have one default stream. 2769 // Verify we have one new stream for each loop iteration.
2771 EXPECT_EQ(1, call_.GetAudioReceiveStreams().size()); 2770 EXPECT_EQ(ssrc, call_.GetAudioReceiveStreams().size());
2772 EXPECT_EQ(1, GetRecvStream(ssrc).received_packets()); 2771 EXPECT_EQ(1, GetRecvStream(ssrc).received_packets());
2773 EXPECT_TRUE(GetRecvStream(ssrc).VerifyLastPacket(packet, sizeof(packet))); 2772 EXPECT_TRUE(GetRecvStream(ssrc).VerifyLastPacket(packet, sizeof(packet)));
2774 } 2773 }
2775 2774
2776 // Sending the same ssrc again should not create a new stream. 2775 // Send on the same SSRCs again should not create new streams.
Taylor Brandstetter 2017/02/17 08:36:15 nit: "Sending"
the sun 2017/02/17 10:10:57 Done.
2777 --ssrc; 2776 for (uint32_t ssrc = 1; ssrc < (1 + kMaxUnsignaledCount); ++ssrc) {
2777 rtc::SetBE32(&packet[8], ssrc);
2778 DeliverPacket(packet, sizeof(packet));
2779
2780 EXPECT_EQ(kMaxUnsignaledCount, call_.GetAudioReceiveStreams().size());
2781 EXPECT_EQ(2, GetRecvStream(ssrc).received_packets());
2782 EXPECT_TRUE(GetRecvStream(ssrc).VerifyLastPacket(packet, sizeof(packet)));
2783 }
2784
2785 // Send on another SSRC, the oldest unsignaled stream (SSRC=1) is replaced.
2786 constexpr uint32_t kAnotherSsrc = 667;
2787 rtc::SetBE32(&packet[8], kAnotherSsrc);
2778 DeliverPacket(packet, sizeof(packet)); 2788 DeliverPacket(packet, sizeof(packet));
2779 EXPECT_EQ(1, call_.GetAudioReceiveStreams().size()); 2789
2780 EXPECT_EQ(2, GetRecvStream(ssrc).received_packets()); 2790 const auto& streams = call_.GetAudioReceiveStreams();
2781 EXPECT_TRUE(GetRecvStream(ssrc).VerifyLastPacket(packet, sizeof(packet))); 2791 EXPECT_EQ(kMaxUnsignaledCount, streams.size());
2792 size_t i = 0;
2793 for (uint32_t ssrc = 2; ssrc < (1 + kMaxUnsignaledCount); ++ssrc, ++i) {
2794 EXPECT_EQ(ssrc, streams[i]->GetConfig().rtp.remote_ssrc);
2795 EXPECT_EQ(2, streams[i]->received_packets());
2796 }
2797 EXPECT_EQ(kAnotherSsrc, streams[i]->GetConfig().rtp.remote_ssrc);
2798 EXPECT_EQ(1, streams[i]->received_packets());
2799 ++i;
2800 EXPECT_EQ(kMaxUnsignaledCount, i);
Taylor Brandstetter 2017/02/17 08:36:15 What's the purpose of the final ++i and EXPECT_EQ?
the sun 2017/02/17 10:10:57 Yes, basically to "complete" the loop
2782 } 2801 }
2783 2802
2784 // Test that a default channel is created even after a signalled stream has been 2803 // Test that a default channel is created even after a signalled stream has been
2785 // added, and that this stream will get any packets for unknown SSRCs. 2804 // added, and that this stream will get any packets for unknown SSRCs.
2786 TEST_F(WebRtcVoiceEngineTestFake, RecvUnsignalledAfterSignalled) { 2805 TEST_F(WebRtcVoiceEngineTestFake, RecvUnsignaledAfterSignalled) {
Taylor Brandstetter 2017/02/17 08:36:15 nit: This uses both "Unsignaled" and "Unsignalled"
the sun 2017/02/17 10:10:57 Done.
2787 EXPECT_TRUE(SetupChannel()); 2806 EXPECT_TRUE(SetupChannel());
2788 unsigned char packet[sizeof(kPcmuFrame)]; 2807 unsigned char packet[sizeof(kPcmuFrame)];
2789 memcpy(packet, kPcmuFrame, sizeof(kPcmuFrame)); 2808 memcpy(packet, kPcmuFrame, sizeof(kPcmuFrame));
2790 2809
2791 // Add a known stream, send packet and verify we got it. 2810 // Add a known stream, send packet and verify we got it.
2792 const uint32_t signaled_ssrc = 1; 2811 const uint32_t signaled_ssrc = 1;
2793 rtc::SetBE32(&packet[8], signaled_ssrc); 2812 rtc::SetBE32(&packet[8], signaled_ssrc);
2794 EXPECT_TRUE(AddRecvStream(signaled_ssrc)); 2813 EXPECT_TRUE(AddRecvStream(signaled_ssrc));
2795 DeliverPacket(packet, sizeof(packet)); 2814 DeliverPacket(packet, sizeof(packet));
2796 EXPECT_TRUE(GetRecvStream(signaled_ssrc).VerifyLastPacket( 2815 EXPECT_TRUE(GetRecvStream(signaled_ssrc).VerifyLastPacket(
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
3284 EXPECT_TRUE(SetupChannel()); 3303 EXPECT_TRUE(SetupChannel());
3285 EXPECT_FALSE(channel_->SetOutputVolume(kSsrc2, 0.5)); 3304 EXPECT_FALSE(channel_->SetOutputVolume(kSsrc2, 0.5));
3286 cricket::StreamParams stream; 3305 cricket::StreamParams stream;
3287 stream.ssrcs.push_back(kSsrc2); 3306 stream.ssrcs.push_back(kSsrc2);
3288 EXPECT_TRUE(channel_->AddRecvStream(stream)); 3307 EXPECT_TRUE(channel_->AddRecvStream(stream));
3289 EXPECT_DOUBLE_EQ(1, GetRecvStream(kSsrc2).gain()); 3308 EXPECT_DOUBLE_EQ(1, GetRecvStream(kSsrc2).gain());
3290 EXPECT_TRUE(channel_->SetOutputVolume(kSsrc2, 3)); 3309 EXPECT_TRUE(channel_->SetOutputVolume(kSsrc2, 3));
3291 EXPECT_DOUBLE_EQ(3, GetRecvStream(kSsrc2).gain()); 3310 EXPECT_DOUBLE_EQ(3, GetRecvStream(kSsrc2).gain());
3292 } 3311 }
3293 3312
3294 TEST_F(WebRtcVoiceEngineTestFake, SetOutputVolumeDefaultRecvStream) { 3313 TEST_F(WebRtcVoiceEngineTestFake, SetOutputVolumeUnsignaledRecvStream) {
3295 EXPECT_TRUE(SetupChannel()); 3314 EXPECT_TRUE(SetupChannel());
3315
3316 unsigned char pcmuFrame2[sizeof(kPcmuFrame)];
3317 memcpy(pcmuFrame2, kPcmuFrame, sizeof(kPcmuFrame));
3318 rtc::SetBE32(&pcmuFrame2[8], kSsrc4);
3319
3320 // Spawn an unsignaled stream by sending a packet - gain should be 1.
3321 DeliverPacket(pcmuFrame2, sizeof(pcmuFrame2));
3322 EXPECT_DOUBLE_EQ(1, GetRecvStream(kSsrc4).gain());
3323
3324 // Should remember the volume "2" which will be set on new unsignaled streams,
3325 // and also set the gain to 2 on existing unsignaled streams.
3296 EXPECT_TRUE(channel_->SetOutputVolume(0, 2)); 3326 EXPECT_TRUE(channel_->SetOutputVolume(0, 2));
3327 EXPECT_DOUBLE_EQ(2, GetRecvStream(kSsrc4).gain());
3328
3329 // Spawn an unsignaled stream by sending a packet - gain should be 2.
3297 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame)); 3330 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
Taylor Brandstetter 2017/02/17 08:36:14 nit: May be more readable if "kPcmuFrame2" was del
the sun 2017/02/17 10:10:57 Done.
3298 EXPECT_DOUBLE_EQ(2, GetRecvStream(1).gain()); 3331 EXPECT_DOUBLE_EQ(2, GetRecvStream(1).gain());
3332
3333 // Setting gain with SSRC=0 should affect all unsignaled streams.
3299 EXPECT_TRUE(channel_->SetOutputVolume(0, 3)); 3334 EXPECT_TRUE(channel_->SetOutputVolume(0, 3));
3335 EXPECT_DOUBLE_EQ(3, GetRecvStream(kSsrc4).gain());
3300 EXPECT_DOUBLE_EQ(3, GetRecvStream(1).gain()); 3336 EXPECT_DOUBLE_EQ(3, GetRecvStream(1).gain());
3337
3338 // Setting gain on an individual stream affects only that.
3301 EXPECT_TRUE(channel_->SetOutputVolume(1, 4)); 3339 EXPECT_TRUE(channel_->SetOutputVolume(1, 4));
3340 EXPECT_DOUBLE_EQ(3, GetRecvStream(kSsrc4).gain());
3302 EXPECT_DOUBLE_EQ(4, GetRecvStream(1).gain()); 3341 EXPECT_DOUBLE_EQ(4, GetRecvStream(1).gain());
3303 } 3342 }
3304 3343
3305 TEST_F(WebRtcVoiceEngineTestFake, SetsSyncGroupFromSyncLabel) { 3344 TEST_F(WebRtcVoiceEngineTestFake, SetsSyncGroupFromSyncLabel) {
3306 const uint32_t kAudioSsrc = 123; 3345 const uint32_t kAudioSsrc = 123;
3307 const std::string kSyncLabel = "AvSyncLabel"; 3346 const std::string kSyncLabel = "AvSyncLabel";
3308 3347
3309 EXPECT_TRUE(SetupSendStream()); 3348 EXPECT_TRUE(SetupSendStream());
3310 cricket::StreamParams sp = cricket::StreamParams::CreateLegacy(kAudioSsrc); 3349 cricket::StreamParams sp = cricket::StreamParams::CreateLegacy(kAudioSsrc);
3311 sp.sync_label = kSyncLabel; 3350 sp.sync_label = kSyncLabel;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
3444 3483
3445 // Now try actually setting the sink. 3484 // Now try actually setting the sink.
3446 channel_->SetRawAudioSink(kSsrc1, std::move(fake_sink_2)); 3485 channel_->SetRawAudioSink(kSsrc1, std::move(fake_sink_2));
3447 EXPECT_NE(nullptr, GetRecvStream(kSsrc1).sink()); 3486 EXPECT_NE(nullptr, GetRecvStream(kSsrc1).sink());
3448 3487
3449 // Now try resetting it. 3488 // Now try resetting it.
3450 channel_->SetRawAudioSink(kSsrc1, nullptr); 3489 channel_->SetRawAudioSink(kSsrc1, nullptr);
3451 EXPECT_EQ(nullptr, GetRecvStream(kSsrc1).sink()); 3490 EXPECT_EQ(nullptr, GetRecvStream(kSsrc1).sink());
3452 } 3491 }
3453 3492
3454 TEST_F(WebRtcVoiceEngineTestFake, SetRawAudioSinkDefaultRecvStream) { 3493 TEST_F(WebRtcVoiceEngineTestFake, SetRawAudioSinkUnsignaledRecvStream) {
3455 EXPECT_TRUE(SetupChannel()); 3494 EXPECT_TRUE(SetupChannel());
3456 std::unique_ptr<FakeAudioSink> fake_sink_1(new FakeAudioSink()); 3495 std::unique_ptr<FakeAudioSink> fake_sink_1(new FakeAudioSink());
3457 std::unique_ptr<FakeAudioSink> fake_sink_2(new FakeAudioSink()); 3496 std::unique_ptr<FakeAudioSink> fake_sink_2(new FakeAudioSink());
3458 3497
3459 // Should be able to set a default sink even when no stream exists. 3498 // Should be able to set a default sink even when no stream exists.
3460 channel_->SetRawAudioSink(0, std::move(fake_sink_1)); 3499 channel_->SetRawAudioSink(0, std::move(fake_sink_1));
3461 3500
3462 // Create default channel and ensure it's assigned the default sink. 3501 // Create default channel and ensure it's assigned the default sink.
3463 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame)); 3502 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
3464 EXPECT_NE(nullptr, GetRecvStream(0x01).sink()); 3503 EXPECT_NE(nullptr, GetRecvStream(0x01).sink());
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
3755 // Without this cast, the comparison turned unsigned and, thus, failed for -1. 3794 // Without this cast, the comparison turned unsigned and, thus, failed for -1.
3756 const int num_specs = static_cast<int>(specs.size()); 3795 const int num_specs = static_cast<int>(specs.size());
3757 EXPECT_GE(find_codec({"cn", 8000, 1}), num_specs); 3796 EXPECT_GE(find_codec({"cn", 8000, 1}), num_specs);
3758 EXPECT_GE(find_codec({"cn", 16000, 1}), num_specs); 3797 EXPECT_GE(find_codec({"cn", 16000, 1}), num_specs);
3759 EXPECT_EQ(find_codec({"cn", 32000, 1}), -1); 3798 EXPECT_EQ(find_codec({"cn", 32000, 1}), -1);
3760 EXPECT_GE(find_codec({"telephone-event", 8000, 1}), num_specs); 3799 EXPECT_GE(find_codec({"telephone-event", 8000, 1}), num_specs);
3761 EXPECT_GE(find_codec({"telephone-event", 16000, 1}), num_specs); 3800 EXPECT_GE(find_codec({"telephone-event", 16000, 1}), num_specs);
3762 EXPECT_GE(find_codec({"telephone-event", 32000, 1}), num_specs); 3801 EXPECT_GE(find_codec({"telephone-event", 32000, 1}), num_specs);
3763 EXPECT_GE(find_codec({"telephone-event", 48000, 1}), num_specs); 3802 EXPECT_GE(find_codec({"telephone-event", 48000, 1}), num_specs);
3764 } 3803 }
OLDNEW
« webrtc/media/engine/webrtcvoiceengine.cc ('K') | « webrtc/media/engine/webrtcvoiceengine.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698