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

Side by Side Diff: webrtc/api/webrtcsession_unittest.cc

Issue 1741933002: Prevent a voice channel from sending data before a renderer is set. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Adding unit test for the original problem this CL solves. Created 4 years, 9 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
« no previous file with comments | « webrtc/api/webrtcsession.cc ('k') | webrtc/audio/audio_send_stream.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2012 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 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 State state() const { return state_; } 291 State state() const { return state_; }
292 292
293 protected: 293 protected:
294 ~WebRtcSessionCreateSDPObserverForTest() {} 294 ~WebRtcSessionCreateSDPObserverForTest() {}
295 295
296 private: 296 private:
297 rtc::scoped_ptr<SessionDescriptionInterface> description_; 297 rtc::scoped_ptr<SessionDescriptionInterface> description_;
298 State state_; 298 State state_;
299 }; 299 };
300 300
301 class FakeAudioRenderer : public cricket::AudioRenderer { 301 class FakeAudioSource : public cricket::AudioSource {
302 public: 302 public:
303 FakeAudioRenderer() : sink_(NULL) {} 303 FakeAudioSource() : sink_(NULL) {}
304 virtual ~FakeAudioRenderer() { 304 virtual ~FakeAudioSource() {
305 if (sink_) 305 if (sink_)
306 sink_->OnClose(); 306 sink_->OnClose();
307 } 307 }
308 308
309 void SetSink(Sink* sink) override { sink_ = sink; } 309 void SetSink(Sink* sink) override { sink_ = sink; }
310 310
311 cricket::AudioRenderer::Sink* sink() const { return sink_; } 311 cricket::AudioSource::Sink* sink() const { return sink_; }
the sun 2016/03/07 16:35:14 almost unrelated: is it possible to make the resul
312
312 private: 313 private:
313 cricket::AudioRenderer::Sink* sink_; 314 cricket::AudioSource::Sink* sink_;
314 }; 315 };
315 316
316 class WebRtcSessionTest 317 class WebRtcSessionTest
317 : public testing::TestWithParam<RTCCertificateGenerationMethod>, 318 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
318 public sigslot::has_slots<> { 319 public sigslot::has_slots<> {
319 protected: 320 protected:
320 // TODO Investigate why ChannelManager crashes, if it's created 321 // TODO Investigate why ChannelManager crashes, if it's created
321 // after stun_server. 322 // after stun_server.
322 WebRtcSessionTest() 323 WebRtcSessionTest()
323 : media_engine_(new cricket::FakeMediaEngine()), 324 : media_engine_(new cricket::FakeMediaEngine()),
(...skipping 3015 matching lines...) Expand 10 before | Expand all | Expand 10 after
3339 CreateAndSetRemoteOfferAndLocalAnswer(); 3340 CreateAndSetRemoteOfferAndLocalAnswer();
3340 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0); 3341 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3341 ASSERT_TRUE(channel != NULL); 3342 ASSERT_TRUE(channel != NULL);
3342 ASSERT_EQ(1u, channel->send_streams().size()); 3343 ASSERT_EQ(1u, channel->send_streams().size());
3343 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc(); 3344 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
3344 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc)); 3345 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3345 3346
3346 cricket::AudioOptions options; 3347 cricket::AudioOptions options;
3347 options.echo_cancellation = rtc::Optional<bool>(true); 3348 options.echo_cancellation = rtc::Optional<bool>(true);
3348 3349
3349 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer()); 3350 rtc::scoped_ptr<FakeAudioSource> source(new FakeAudioSource());
3350 session_->SetAudioSend(send_ssrc, false, options, renderer.get()); 3351 session_->SetAudioSend(send_ssrc, false, options, source.get());
3351 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc)); 3352 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3352 EXPECT_EQ(rtc::Optional<bool>(), channel->options().echo_cancellation); 3353 EXPECT_EQ(rtc::Optional<bool>(), channel->options().echo_cancellation);
3353 EXPECT_TRUE(renderer->sink() != NULL); 3354 EXPECT_TRUE(source->sink() != nullptr);
3354 3355
3355 // This will trigger SetSink(NULL) to the |renderer|. 3356 // This will trigger SetSink(nullptr) to the |source|.
3356 session_->SetAudioSend(send_ssrc, true, options, NULL); 3357 session_->SetAudioSend(send_ssrc, true, options, nullptr);
3357 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc)); 3358 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3358 EXPECT_EQ(rtc::Optional<bool>(true), channel->options().echo_cancellation); 3359 EXPECT_EQ(rtc::Optional<bool>(true), channel->options().echo_cancellation);
3359 EXPECT_TRUE(renderer->sink() == NULL); 3360 EXPECT_TRUE(source->sink() == nullptr);
3360 } 3361 }
3361 3362
3362 TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) { 3363 TEST_F(WebRtcSessionTest, AudioSourceForLocalStream) {
3363 Init(); 3364 Init();
3364 SendAudioVideoStream1(); 3365 SendAudioVideoStream1();
3365 CreateAndSetRemoteOfferAndLocalAnswer(); 3366 CreateAndSetRemoteOfferAndLocalAnswer();
3366 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0); 3367 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3367 ASSERT_TRUE(channel != NULL); 3368 ASSERT_TRUE(channel != NULL);
3368 ASSERT_EQ(1u, channel->send_streams().size()); 3369 ASSERT_EQ(1u, channel->send_streams().size());
3369 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc(); 3370 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
3370 3371
3371 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer()); 3372 rtc::scoped_ptr<FakeAudioSource> source(new FakeAudioSource());
3372 cricket::AudioOptions options; 3373 cricket::AudioOptions options;
3373 session_->SetAudioSend(send_ssrc, true, options, renderer.get()); 3374 session_->SetAudioSend(send_ssrc, true, options, source.get());
3374 EXPECT_TRUE(renderer->sink() != NULL); 3375 EXPECT_TRUE(source->sink() != nullptr);
3375 3376
3376 // Delete the |renderer| and it will trigger OnClose() to the sink, and this 3377 // Delete the |source| and it will trigger OnClose() to the sink, and this
3377 // will invalidate the |renderer_| pointer in the sink and prevent getting a 3378 // will invalidate the |source_| pointer in the sink and prevent getting a
3378 // SetSink(NULL) callback afterwards. 3379 // SetSink(nullptr) callback afterwards.
3379 renderer.reset(); 3380 source.reset();
3380 3381
3381 // This will trigger SetSink(NULL) if no OnClose() callback. 3382 // This will trigger SetSink(nullptr) if no OnClose() callback.
3382 session_->SetAudioSend(send_ssrc, true, options, NULL); 3383 session_->SetAudioSend(send_ssrc, true, options, nullptr);
3383 } 3384 }
3384 3385
3385 TEST_F(WebRtcSessionTest, SetVideoPlayout) { 3386 TEST_F(WebRtcSessionTest, SetVideoPlayout) {
3386 Init(); 3387 Init();
3387 SendAudioVideoStream1(); 3388 SendAudioVideoStream1();
3388 CreateAndSetRemoteOfferAndLocalAnswer(); 3389 CreateAndSetRemoteOfferAndLocalAnswer();
3389 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0); 3390 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3390 ASSERT_TRUE(channel != NULL); 3391 ASSERT_TRUE(channel != NULL);
3391 ASSERT_LT(0u, channel->sinks().size()); 3392 ASSERT_LT(0u, channel->sinks().size());
3392 EXPECT_TRUE(channel->sinks().begin()->second == NULL); 3393 EXPECT_TRUE(channel->sinks().begin()->second == NULL);
(...skipping 920 matching lines...) Expand 10 before | Expand all | Expand 10 after
4313 } 4314 }
4314 4315
4315 // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test 4316 // TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4316 // currently fails because upon disconnection and reconnection OnIceComplete is 4317 // currently fails because upon disconnection and reconnection OnIceComplete is
4317 // called more than once without returning to IceGatheringGathering. 4318 // called more than once without returning to IceGatheringGathering.
4318 4319
4319 INSTANTIATE_TEST_CASE_P(WebRtcSessionTests, 4320 INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4320 WebRtcSessionTest, 4321 WebRtcSessionTest,
4321 testing::Values(ALREADY_GENERATED, 4322 testing::Values(ALREADY_GENERATED,
4322 DTLS_IDENTITY_STORE)); 4323 DTLS_IDENTITY_STORE));
OLDNEW
« no previous file with comments | « webrtc/api/webrtcsession.cc ('k') | webrtc/audio/audio_send_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698