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

Unified Diff: talk/media/webrtc/webrtcvoiceengine_unittest.cc

Issue 1551813002: Storing raw audio sink for default audio track. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Adding unit tests for SetRawAudioSink. Created 4 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: talk/media/webrtc/webrtcvoiceengine_unittest.cc
diff --git a/talk/media/webrtc/webrtcvoiceengine_unittest.cc b/talk/media/webrtc/webrtcvoiceengine_unittest.cc
index a62bcb225fc7c6111fed44c0a43507f1ecf7b353..8b44253285e62927bc30c18a0038b14d179d6208 100644
--- a/talk/media/webrtc/webrtcvoiceengine_unittest.cc
+++ b/talk/media/webrtc/webrtcvoiceengine_unittest.cc
@@ -72,6 +72,11 @@ class FakeVoEWrapper : public cricket::VoEWrapper {
};
} // namespace
+class FakeAudioSink : public rtc::RefCountedObject<webrtc::AudioSinkInterface> {
+ public:
+ void OnData(const Data& audio) override {}
+};
+
class WebRtcVoiceEngineTestFake : public testing::Test {
public:
WebRtcVoiceEngineTestFake()
@@ -3245,3 +3250,54 @@ TEST(WebRtcVoiceEngineTest, SetRecvCodecs) {
parameters.codecs = engine.codecs();
EXPECT_TRUE(channel.SetRecvParameters(parameters));
}
+
+TEST_F(WebRtcVoiceEngineTestFake, SetRawAudioSink) {
the sun 2016/01/08 13:14:27 nit: move these tests up to the other WebRtcVoiceE
Taylor Brandstetter 2016/01/08 19:46:58 Done.
+ EXPECT_TRUE(SetupEngine());
+ rtc::scoped_refptr<FakeAudioSink> fake_sink = new FakeAudioSink();
+
+ // This should do nothing, since there's no recv stream yet.
+ channel_->SetRawAudioSink(kSsrc1, fake_sink);
+ // Ensure the ref count wasn't incremented.
+ EXPECT_TRUE(fake_sink->HasOneRef());
+
+ cricket::StreamParams stream;
+ stream.ssrcs.push_back(kSsrc1);
+ EXPECT_TRUE(channel_->AddRecvStream(stream));
the sun 2016/01/08 13:14:26 EXPECT_TRUE(channel_->AddRecvStream( cricket
Taylor Brandstetter 2016/01/08 19:46:58 Done.
+ // Now, the channel should latch on to the sink.
+ channel_->SetRawAudioSink(kSsrc1, fake_sink);
+ EXPECT_FALSE(fake_sink->HasOneRef());
+ EXPECT_EQ(fake_sink, call_.GetAudioReceiveStream(kSsrc1)->sink());
the sun 2016/01/08 13:14:26 EXPECT_EQ(fake_sink, GetRecvStream(kSsrc1).sink())
the sun 2016/01/08 13:26:19 Oops, that function isn't committed yet (https://c
Taylor Brandstetter 2016/01/08 19:46:58 Ok, copied.
+
+ // Setting a nullptr should release the reference.
+ channel_->SetRawAudioSink(kSsrc1, nullptr);
+ EXPECT_TRUE(fake_sink->HasOneRef());
+}
+
+TEST_F(WebRtcVoiceEngineTestFake, SetRawAudioSinkDefaultRecvStream) {
+ EXPECT_TRUE(SetupEngine());
+ rtc::scoped_refptr<FakeAudioSink> fake_sink_1 = new FakeAudioSink();
+ rtc::scoped_refptr<FakeAudioSink> fake_sink_2 = new FakeAudioSink();
+
+ // Should be able to set a default sink even when no stream exists.
+ channel_->SetRawAudioSink(0, fake_sink_1);
+ EXPECT_FALSE(fake_sink_1->HasOneRef());
+
the sun 2016/01/08 13:14:26 nit: Add comment: // Create default channel.
Taylor Brandstetter 2016/01/08 19:46:58 Done.
+ DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
+ EXPECT_EQ(fake_sink_1, call_.GetAudioReceiveStream(0x01)->sink());
+
+ // Should be able to set the default sink after a stream exists.
+ channel_->SetRawAudioSink(0, fake_sink_2);
+ EXPECT_TRUE(fake_sink_1->HasOneRef());
+ EXPECT_FALSE(fake_sink_2->HasOneRef());
+ EXPECT_EQ(fake_sink_2, call_.GetAudioReceiveStream(0x01)->sink());
+
+ // If we remove and add a default stream, it should get the same sink.
+ EXPECT_TRUE(channel_->RemoveRecvStream(0x01));
+ DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
+ EXPECT_FALSE(fake_sink_2->HasOneRef());
+ EXPECT_EQ(fake_sink_2, call_.GetAudioReceiveStream(0x01)->sink());
+
+ // Finally, try resetting the default sink.
+ channel_->SetRawAudioSink(0, nullptr);
+ EXPECT_TRUE(fake_sink_2->HasOneRef());
+}

Powered by Google App Engine
This is Rietveld 408576698