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

Side by Side 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 unified diff | Download patch
OLDNEW
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 engine, // base 65 engine, // base
66 engine, // codec 66 engine, // codec
67 engine, // hw 67 engine, // hw
68 engine, // network 68 engine, // network
69 engine, // rtp 69 engine, // rtp
70 engine) { // volume 70 engine) { // volume
71 } 71 }
72 }; 72 };
73 } // namespace 73 } // namespace
74 74
75 class FakeAudioSink : public rtc::RefCountedObject<webrtc::AudioSinkInterface> {
76 public:
77 void OnData(const Data& audio) override {}
78 };
79
75 class WebRtcVoiceEngineTestFake : public testing::Test { 80 class WebRtcVoiceEngineTestFake : public testing::Test {
76 public: 81 public:
77 WebRtcVoiceEngineTestFake() 82 WebRtcVoiceEngineTestFake()
78 : call_(webrtc::Call::Config()), 83 : call_(webrtc::Call::Config()),
79 engine_(new FakeVoEWrapper(&voe_)), 84 engine_(new FakeVoEWrapper(&voe_)),
80 channel_(nullptr) { 85 channel_(nullptr) {
81 send_parameters_.codecs.push_back(kPcmuCodec); 86 send_parameters_.codecs.push_back(kPcmuCodec);
82 recv_parameters_.codecs.push_back(kPcmuCodec); 87 recv_parameters_.codecs.push_back(kPcmuCodec);
83 } 88 }
84 bool SetupEngine() { 89 bool SetupEngine() {
(...skipping 3153 matching lines...) Expand 10 before | Expand all | Expand 10 after
3238 cricket::WebRtcVoiceEngine engine; 3243 cricket::WebRtcVoiceEngine engine;
3239 EXPECT_TRUE(engine.Init(rtc::Thread::Current())); 3244 EXPECT_TRUE(engine.Init(rtc::Thread::Current()));
3240 rtc::scoped_ptr<webrtc::Call> call( 3245 rtc::scoped_ptr<webrtc::Call> call(
3241 webrtc::Call::Create(webrtc::Call::Config())); 3246 webrtc::Call::Create(webrtc::Call::Config()));
3242 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::AudioOptions(), 3247 cricket::WebRtcVoiceMediaChannel channel(&engine, cricket::AudioOptions(),
3243 call.get()); 3248 call.get());
3244 cricket::AudioRecvParameters parameters; 3249 cricket::AudioRecvParameters parameters;
3245 parameters.codecs = engine.codecs(); 3250 parameters.codecs = engine.codecs();
3246 EXPECT_TRUE(channel.SetRecvParameters(parameters)); 3251 EXPECT_TRUE(channel.SetRecvParameters(parameters));
3247 } 3252 }
3253
3254 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.
3255 EXPECT_TRUE(SetupEngine());
3256 rtc::scoped_refptr<FakeAudioSink> fake_sink = new FakeAudioSink();
3257
3258 // This should do nothing, since there's no recv stream yet.
3259 channel_->SetRawAudioSink(kSsrc1, fake_sink);
3260 // Ensure the ref count wasn't incremented.
3261 EXPECT_TRUE(fake_sink->HasOneRef());
3262
3263 cricket::StreamParams stream;
3264 stream.ssrcs.push_back(kSsrc1);
3265 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.
3266 // Now, the channel should latch on to the sink.
3267 channel_->SetRawAudioSink(kSsrc1, fake_sink);
3268 EXPECT_FALSE(fake_sink->HasOneRef());
3269 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.
3270
3271 // Setting a nullptr should release the reference.
3272 channel_->SetRawAudioSink(kSsrc1, nullptr);
3273 EXPECT_TRUE(fake_sink->HasOneRef());
3274 }
3275
3276 TEST_F(WebRtcVoiceEngineTestFake, SetRawAudioSinkDefaultRecvStream) {
3277 EXPECT_TRUE(SetupEngine());
3278 rtc::scoped_refptr<FakeAudioSink> fake_sink_1 = new FakeAudioSink();
3279 rtc::scoped_refptr<FakeAudioSink> fake_sink_2 = new FakeAudioSink();
3280
3281 // Should be able to set a default sink even when no stream exists.
3282 channel_->SetRawAudioSink(0, fake_sink_1);
3283 EXPECT_FALSE(fake_sink_1->HasOneRef());
3284
the sun 2016/01/08 13:14:26 nit: Add comment: // Create default channel.
Taylor Brandstetter 2016/01/08 19:46:58 Done.
3285 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
3286 EXPECT_EQ(fake_sink_1, call_.GetAudioReceiveStream(0x01)->sink());
3287
3288 // Should be able to set the default sink after a stream exists.
3289 channel_->SetRawAudioSink(0, fake_sink_2);
3290 EXPECT_TRUE(fake_sink_1->HasOneRef());
3291 EXPECT_FALSE(fake_sink_2->HasOneRef());
3292 EXPECT_EQ(fake_sink_2, call_.GetAudioReceiveStream(0x01)->sink());
3293
3294 // If we remove and add a default stream, it should get the same sink.
3295 EXPECT_TRUE(channel_->RemoveRecvStream(0x01));
3296 DeliverPacket(kPcmuFrame, sizeof(kPcmuFrame));
3297 EXPECT_FALSE(fake_sink_2->HasOneRef());
3298 EXPECT_EQ(fake_sink_2, call_.GetAudioReceiveStream(0x01)->sink());
3299
3300 // Finally, try resetting the default sink.
3301 channel_->SetRawAudioSink(0, nullptr);
3302 EXPECT_TRUE(fake_sink_2->HasOneRef());
3303 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698