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

Side by Side Diff: talk/app/webrtc/rtpsenderreceiver_unittest.cc

Issue 1413713003: Adding the ability to create an RtpSender without a track. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Adding some unit tests for new methods on the sender. Created 5 years, 2 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 2012 Google Inc. 3 * Copyright 2012 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 stream_ = MediaStream::Create(kStreamLabel1); 113 stream_ = MediaStream::Create(kStreamLabel1);
114 rtc::scoped_refptr<VideoSourceInterface> source(FakeVideoSource::Create()); 114 rtc::scoped_refptr<VideoSourceInterface> source(FakeVideoSource::Create());
115 video_track_ = VideoTrack::Create(kVideoTrackId, source); 115 video_track_ = VideoTrack::Create(kVideoTrackId, source);
116 EXPECT_TRUE(stream_->AddTrack(video_track_)); 116 EXPECT_TRUE(stream_->AddTrack(video_track_));
117 } 117 }
118 118
119 void CreateAudioRtpSender() { 119 void CreateAudioRtpSender() {
120 audio_track_ = AudioTrack::Create(kAudioTrackId, NULL); 120 audio_track_ = AudioTrack::Create(kAudioTrackId, NULL);
121 EXPECT_TRUE(stream_->AddTrack(audio_track_)); 121 EXPECT_TRUE(stream_->AddTrack(audio_track_));
122 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _)); 122 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
123 audio_rtp_sender_ = new AudioRtpSender(stream_->GetAudioTracks()[0], 123 audio_rtp_sender_ =
124 kAudioSsrc, &audio_provider_); 124 new AudioRtpSender(stream_->GetAudioTracks()[0], stream_->label(),
125 &audio_provider_, nullptr);
126 audio_rtp_sender_->SetSsrc(kAudioSsrc);
125 } 127 }
126 128
127 void CreateVideoRtpSender() { 129 void CreateVideoRtpSender() {
128 EXPECT_CALL(video_provider_, 130 EXPECT_CALL(video_provider_,
129 SetCaptureDevice( 131 SetCaptureDevice(
130 kVideoSsrc, video_track_->GetSource()->GetVideoCapturer())); 132 kVideoSsrc, video_track_->GetSource()->GetVideoCapturer()));
131 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _)); 133 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
132 video_rtp_sender_ = new VideoRtpSender(stream_->GetVideoTracks()[0], 134 video_rtp_sender_ = new VideoRtpSender(stream_->GetVideoTracks()[0],
133 kVideoSsrc, &video_provider_); 135 stream_->label(), &video_provider_);
136 video_rtp_sender_->SetSsrc(kVideoSsrc);
134 } 137 }
135 138
136 void DestroyAudioRtpSender() { 139 void DestroyAudioRtpSender() {
137 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _)) 140 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _))
138 .Times(1); 141 .Times(1);
139 audio_rtp_sender_ = nullptr; 142 audio_rtp_sender_ = nullptr;
140 } 143 }
141 144
142 void DestroyVideoRtpSender() { 145 void DestroyVideoRtpSender() {
143 EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc, NULL)).Times(1); 146 EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc, NULL)).Times(1);
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
273 EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, true)); 276 EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, true));
274 audio_track_->set_enabled(true); 277 audio_track_->set_enabled(true);
275 278
276 double new_volume = 0.8; 279 double new_volume = 0.8;
277 EXPECT_CALL(audio_provider_, SetAudioPlayoutVolume(kAudioSsrc, new_volume)); 280 EXPECT_CALL(audio_provider_, SetAudioPlayoutVolume(kAudioSsrc, new_volume));
278 audio_track_->GetSource()->SetVolume(new_volume); 281 audio_track_->GetSource()->SetVolume(new_volume);
279 282
280 DestroyAudioRtpReceiver(); 283 DestroyAudioRtpReceiver();
281 } 284 }
282 285
286 TEST_F(RtpSenderReceiverTest, AudioSenderWithoutTrack) {
287 rtc::scoped_refptr<AudioRtpSender> sender =
288 new AudioRtpSender(&audio_provider_, nullptr);
289 // Just let it get destroyed and make sure it doesn't call any methods on the
290 // provider interface.
291 }
292
293 TEST_F(RtpSenderReceiverTest, VideoSenderWithoutTrack) {
294 rtc::scoped_refptr<VideoRtpSender> sender =
295 new VideoRtpSender(&video_provider_);
296 // Just let it get destroyed and make sure it doesn't call any methods on the
297 // provider interface.
298 }
299
300 // Test that an audio sender calls the expected methods on the provider once
301 // it has a track and SSRC, when the SSRC is set first.
302 TEST_F(RtpSenderReceiverTest, AudioSenderEarlyWarmupSsrcThenTrack) {
303 rtc::scoped_refptr<AudioRtpSender> sender =
304 new AudioRtpSender(&audio_provider_, nullptr);
305 rtc::scoped_refptr<AudioTrackInterface> track =
306 AudioTrack::Create(kAudioTrackId, nullptr);
307 sender->SetSsrc(kAudioSsrc);
308 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
309 sender->SetTrack(track);
310
311 // Calls expected from destructor.
312 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _)).Times(1);
pthatcher1 2015/10/20 17:42:49 Should we test that this gets called even if SetTr
Taylor Brandstetter 2015/10/21 00:22:09 It shouldn't get called if SetTrack is never calle
313 }
314
315 // Test that an audio sender calls the expected methods on the provider once
316 // it has a track and SSRC, when the SSRC is set last.
317 TEST_F(RtpSenderReceiverTest, AudioSenderEarlyWarmupTrackThenSsrc) {
318 rtc::scoped_refptr<AudioRtpSender> sender =
319 new AudioRtpSender(&audio_provider_, nullptr);
320 rtc::scoped_refptr<AudioTrackInterface> track =
321 AudioTrack::Create(kAudioTrackId, nullptr);
322 sender->SetTrack(track);
323 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
324 sender->SetSsrc(kAudioSsrc);
325
326 // Calls expected from destructor.
327 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _)).Times(1);
328 }
329
330 // Test that a video sender calls the expected methods on the provider once
331 // it has a track and SSRC, when the SSRC is set first.
332 TEST_F(RtpSenderReceiverTest, VideoSenderEarlyWarmupSsrcThenTrack) {
333 rtc::scoped_refptr<VideoRtpSender> sender =
334 new VideoRtpSender(&video_provider_);
335 sender->SetSsrc(kVideoSsrc);
336 EXPECT_CALL(video_provider_,
337 SetCaptureDevice(kVideoSsrc,
338 video_track_->GetSource()->GetVideoCapturer()));
339 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
340 sender->SetTrack(video_track_);
341
342 // Calls expected from destructor.
343 EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc, nullptr)).Times(1);
344 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _)).Times(1);
345 }
346
347 // Test that a video sender calls the expected methods on the provider once
348 // it has a track and SSRC, when the SSRC is set last.
349 TEST_F(RtpSenderReceiverTest, VideoSenderEarlyWarmupTrackThenSsrc) {
350 rtc::scoped_refptr<VideoRtpSender> sender =
351 new VideoRtpSender(&video_provider_);
352 sender->SetTrack(video_track_);
353 EXPECT_CALL(video_provider_,
354 SetCaptureDevice(kVideoSsrc,
355 video_track_->GetSource()->GetVideoCapturer()));
356 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
357 sender->SetSsrc(kVideoSsrc);
358
359 // Calls expected from destructor.
360 EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc, nullptr)).Times(1);
361 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _)).Times(1);
362 }
pthatcher1 2015/10/20 17:42:49 It seems you don't have any tests for setting the
Taylor Brandstetter 2015/10/21 00:22:09 No, I just wasn't thorough enough. I added some mo
363
364 // Test that the sender is disconnected from the provider when its SSRC is
365 // set to 0.
366 TEST_F(RtpSenderReceiverTest, AudioSenderSsrcSetToZero) {
367 rtc::scoped_refptr<AudioTrackInterface> track =
368 AudioTrack::Create(kAudioTrackId, nullptr);
369 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
370 rtc::scoped_refptr<AudioRtpSender> sender =
371 new AudioRtpSender(track, kStreamLabel1, &audio_provider_, nullptr);
372 sender->SetSsrc(kAudioSsrc);
373
374 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _)).Times(1);
375 sender->SetSsrc(0);
376
377 // Make sure it's SetSsrc that called methods on the provider, and not the
378 // destructor.
379 EXPECT_CALL(audio_provider_, SetAudioSend(_, _, _, _)).Times(0);
380 }
381
382 // Test that the sender is disconnected from the provider when its SSRC is
383 // set to 0.
384 TEST_F(RtpSenderReceiverTest, VideoSenderSsrcSetToZero) {
385 EXPECT_CALL(video_provider_,
386 SetCaptureDevice(kVideoSsrc,
387 video_track_->GetSource()->GetVideoCapturer()));
388 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
389 rtc::scoped_refptr<VideoRtpSender> sender =
390 new VideoRtpSender(video_track_, kStreamLabel1, &video_provider_);
391 sender->SetSsrc(kVideoSsrc);
392
393 EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc, nullptr)).Times(1);
394 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _)).Times(1);
395 sender->SetSsrc(0);
396
397 // Make sure it's SetSsrc that called methods on the provider, and not the
398 // destructor.
399 EXPECT_CALL(video_provider_, SetCaptureDevice(_, _)).Times(0);
400 EXPECT_CALL(video_provider_, SetVideoSend(_, _, _)).Times(0);
401 }
402
283 } // namespace webrtc 403 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698