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

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

Issue 1426443007: Revert of Adding the ability to create an RtpSender without a track. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years, 1 month 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 | « talk/app/webrtc/rtpsenderinterface.h ('k') | talk/app/webrtc/test/fakemediastreamsignaling.h » ('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 * 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 30 matching lines...) Expand all
41 #include "testing/gtest/include/gtest/gtest.h" 41 #include "testing/gtest/include/gtest/gtest.h"
42 #include "webrtc/base/gunit.h" 42 #include "webrtc/base/gunit.h"
43 43
44 using ::testing::_; 44 using ::testing::_;
45 using ::testing::Exactly; 45 using ::testing::Exactly;
46 46
47 static const char kStreamLabel1[] = "local_stream_1"; 47 static const char kStreamLabel1[] = "local_stream_1";
48 static const char kVideoTrackId[] = "video_1"; 48 static const char kVideoTrackId[] = "video_1";
49 static const char kAudioTrackId[] = "audio_1"; 49 static const char kAudioTrackId[] = "audio_1";
50 static const uint32_t kVideoSsrc = 98; 50 static const uint32_t kVideoSsrc = 98;
51 static const uint32_t kVideoSsrc2 = 100;
52 static const uint32_t kAudioSsrc = 99; 51 static const uint32_t kAudioSsrc = 99;
53 static const uint32_t kAudioSsrc2 = 101;
54 52
55 namespace webrtc { 53 namespace webrtc {
56 54
57 // Helper class to test RtpSender/RtpReceiver. 55 // Helper class to test RtpSender/RtpReceiver.
58 class MockAudioProvider : public AudioProviderInterface { 56 class MockAudioProvider : public AudioProviderInterface {
59 public: 57 public:
60 virtual ~MockAudioProvider() {} 58 virtual ~MockAudioProvider() {}
61 MOCK_METHOD2(SetAudioPlayout, 59 MOCK_METHOD2(SetAudioPlayout,
62 void(uint32_t ssrc, 60 void(uint32_t ssrc,
63 bool enable)); 61 bool enable));
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 stream_ = MediaStream::Create(kStreamLabel1); 113 stream_ = MediaStream::Create(kStreamLabel1);
116 rtc::scoped_refptr<VideoSourceInterface> source(FakeVideoSource::Create()); 114 rtc::scoped_refptr<VideoSourceInterface> source(FakeVideoSource::Create());
117 video_track_ = VideoTrack::Create(kVideoTrackId, source); 115 video_track_ = VideoTrack::Create(kVideoTrackId, source);
118 EXPECT_TRUE(stream_->AddTrack(video_track_)); 116 EXPECT_TRUE(stream_->AddTrack(video_track_));
119 } 117 }
120 118
121 void CreateAudioRtpSender() { 119 void CreateAudioRtpSender() {
122 audio_track_ = AudioTrack::Create(kAudioTrackId, NULL); 120 audio_track_ = AudioTrack::Create(kAudioTrackId, NULL);
123 EXPECT_TRUE(stream_->AddTrack(audio_track_)); 121 EXPECT_TRUE(stream_->AddTrack(audio_track_));
124 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _)); 122 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
125 audio_rtp_sender_ = 123 audio_rtp_sender_ = new AudioRtpSender(stream_->GetAudioTracks()[0],
126 new AudioRtpSender(stream_->GetAudioTracks()[0], stream_->label(), 124 kAudioSsrc, &audio_provider_);
127 &audio_provider_, nullptr);
128 audio_rtp_sender_->SetSsrc(kAudioSsrc);
129 } 125 }
130 126
131 void CreateVideoRtpSender() { 127 void CreateVideoRtpSender() {
132 EXPECT_CALL(video_provider_, 128 EXPECT_CALL(video_provider_,
133 SetCaptureDevice( 129 SetCaptureDevice(
134 kVideoSsrc, video_track_->GetSource()->GetVideoCapturer())); 130 kVideoSsrc, video_track_->GetSource()->GetVideoCapturer()));
135 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _)); 131 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
136 video_rtp_sender_ = new VideoRtpSender(stream_->GetVideoTracks()[0], 132 video_rtp_sender_ = new VideoRtpSender(stream_->GetVideoTracks()[0],
137 stream_->label(), &video_provider_); 133 kVideoSsrc, &video_provider_);
138 video_rtp_sender_->SetSsrc(kVideoSsrc);
139 } 134 }
140 135
141 void DestroyAudioRtpSender() { 136 void DestroyAudioRtpSender() {
142 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _)) 137 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _))
143 .Times(1); 138 .Times(1);
144 audio_rtp_sender_ = nullptr; 139 audio_rtp_sender_ = nullptr;
145 } 140 }
146 141
147 void DestroyVideoRtpSender() { 142 void DestroyVideoRtpSender() {
148 EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc, NULL)).Times(1); 143 EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc, NULL)).Times(1);
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, true)); 273 EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, true));
279 audio_track_->set_enabled(true); 274 audio_track_->set_enabled(true);
280 275
281 double new_volume = 0.8; 276 double new_volume = 0.8;
282 EXPECT_CALL(audio_provider_, SetAudioPlayoutVolume(kAudioSsrc, new_volume)); 277 EXPECT_CALL(audio_provider_, SetAudioPlayoutVolume(kAudioSsrc, new_volume));
283 audio_track_->GetSource()->SetVolume(new_volume); 278 audio_track_->GetSource()->SetVolume(new_volume);
284 279
285 DestroyAudioRtpReceiver(); 280 DestroyAudioRtpReceiver();
286 } 281 }
287 282
288 // Test that provider methods aren't called without both a track and an SSRC.
289 TEST_F(RtpSenderReceiverTest, AudioSenderWithoutTrackAndSsrc) {
290 rtc::scoped_refptr<AudioRtpSender> sender =
291 new AudioRtpSender(&audio_provider_, nullptr);
292 rtc::scoped_refptr<AudioTrackInterface> track =
293 AudioTrack::Create(kAudioTrackId, nullptr);
294 EXPECT_TRUE(sender->SetTrack(track));
295 EXPECT_TRUE(sender->SetTrack(nullptr));
296 sender->SetSsrc(kAudioSsrc);
297 sender->SetSsrc(0);
298 // Just let it get destroyed and make sure it doesn't call any methods on the
299 // provider interface.
300 }
301
302 // Test that provider methods aren't called without both a track and an SSRC.
303 TEST_F(RtpSenderReceiverTest, VideoSenderWithoutTrackAndSsrc) {
304 rtc::scoped_refptr<VideoRtpSender> sender =
305 new VideoRtpSender(&video_provider_);
306 EXPECT_TRUE(sender->SetTrack(video_track_));
307 EXPECT_TRUE(sender->SetTrack(nullptr));
308 sender->SetSsrc(kVideoSsrc);
309 sender->SetSsrc(0);
310 // Just let it get destroyed and make sure it doesn't call any methods on the
311 // provider interface.
312 }
313
314 // Test that an audio sender calls the expected methods on the provider once
315 // it has a track and SSRC, when the SSRC is set first.
316 TEST_F(RtpSenderReceiverTest, AudioSenderEarlyWarmupSsrcThenTrack) {
317 rtc::scoped_refptr<AudioRtpSender> sender =
318 new AudioRtpSender(&audio_provider_, nullptr);
319 rtc::scoped_refptr<AudioTrackInterface> track =
320 AudioTrack::Create(kAudioTrackId, nullptr);
321 sender->SetSsrc(kAudioSsrc);
322 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
323 sender->SetTrack(track);
324
325 // Calls expected from destructor.
326 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _)).Times(1);
327 }
328
329 // Test that an audio sender calls the expected methods on the provider once
330 // it has a track and SSRC, when the SSRC is set last.
331 TEST_F(RtpSenderReceiverTest, AudioSenderEarlyWarmupTrackThenSsrc) {
332 rtc::scoped_refptr<AudioRtpSender> sender =
333 new AudioRtpSender(&audio_provider_, nullptr);
334 rtc::scoped_refptr<AudioTrackInterface> track =
335 AudioTrack::Create(kAudioTrackId, nullptr);
336 sender->SetTrack(track);
337 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
338 sender->SetSsrc(kAudioSsrc);
339
340 // Calls expected from destructor.
341 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _)).Times(1);
342 }
343
344 // Test that a video sender calls the expected methods on the provider once
345 // it has a track and SSRC, when the SSRC is set first.
346 TEST_F(RtpSenderReceiverTest, VideoSenderEarlyWarmupSsrcThenTrack) {
347 rtc::scoped_refptr<VideoRtpSender> sender =
348 new VideoRtpSender(&video_provider_);
349 sender->SetSsrc(kVideoSsrc);
350 EXPECT_CALL(video_provider_,
351 SetCaptureDevice(kVideoSsrc,
352 video_track_->GetSource()->GetVideoCapturer()));
353 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
354 sender->SetTrack(video_track_);
355
356 // Calls expected from destructor.
357 EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc, nullptr)).Times(1);
358 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _)).Times(1);
359 }
360
361 // Test that a video sender calls the expected methods on the provider once
362 // it has a track and SSRC, when the SSRC is set last.
363 TEST_F(RtpSenderReceiverTest, VideoSenderEarlyWarmupTrackThenSsrc) {
364 rtc::scoped_refptr<VideoRtpSender> sender =
365 new VideoRtpSender(&video_provider_);
366 sender->SetTrack(video_track_);
367 EXPECT_CALL(video_provider_,
368 SetCaptureDevice(kVideoSsrc,
369 video_track_->GetSource()->GetVideoCapturer()));
370 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
371 sender->SetSsrc(kVideoSsrc);
372
373 // Calls expected from destructor.
374 EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc, nullptr)).Times(1);
375 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _)).Times(1);
376 }
377
378 // Test that the sender is disconnected from the provider when its SSRC is
379 // set to 0.
380 TEST_F(RtpSenderReceiverTest, AudioSenderSsrcSetToZero) {
381 rtc::scoped_refptr<AudioTrackInterface> track =
382 AudioTrack::Create(kAudioTrackId, nullptr);
383 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
384 rtc::scoped_refptr<AudioRtpSender> sender =
385 new AudioRtpSender(track, kStreamLabel1, &audio_provider_, nullptr);
386 sender->SetSsrc(kAudioSsrc);
387
388 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _)).Times(1);
389 sender->SetSsrc(0);
390
391 // Make sure it's SetSsrc that called methods on the provider, and not the
392 // destructor.
393 EXPECT_CALL(audio_provider_, SetAudioSend(_, _, _, _)).Times(0);
394 }
395
396 // Test that the sender is disconnected from the provider when its SSRC is
397 // set to 0.
398 TEST_F(RtpSenderReceiverTest, VideoSenderSsrcSetToZero) {
399 EXPECT_CALL(video_provider_,
400 SetCaptureDevice(kVideoSsrc,
401 video_track_->GetSource()->GetVideoCapturer()));
402 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
403 rtc::scoped_refptr<VideoRtpSender> sender =
404 new VideoRtpSender(video_track_, kStreamLabel1, &video_provider_);
405 sender->SetSsrc(kVideoSsrc);
406
407 EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc, nullptr)).Times(1);
408 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _)).Times(1);
409 sender->SetSsrc(0);
410
411 // Make sure it's SetSsrc that called methods on the provider, and not the
412 // destructor.
413 EXPECT_CALL(video_provider_, SetCaptureDevice(_, _)).Times(0);
414 EXPECT_CALL(video_provider_, SetVideoSend(_, _, _)).Times(0);
415 }
416
417 TEST_F(RtpSenderReceiverTest, AudioSenderTrackSetToNull) {
418 rtc::scoped_refptr<AudioTrackInterface> track =
419 AudioTrack::Create(kAudioTrackId, nullptr);
420 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
421 rtc::scoped_refptr<AudioRtpSender> sender =
422 new AudioRtpSender(track, kStreamLabel1, &audio_provider_, nullptr);
423 sender->SetSsrc(kAudioSsrc);
424
425 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _)).Times(1);
426 EXPECT_TRUE(sender->SetTrack(nullptr));
427
428 // Make sure it's SetTrack that called methods on the provider, and not the
429 // destructor.
430 EXPECT_CALL(audio_provider_, SetAudioSend(_, _, _, _)).Times(0);
431 }
432
433 TEST_F(RtpSenderReceiverTest, VideoSenderTrackSetToNull) {
434 EXPECT_CALL(video_provider_,
435 SetCaptureDevice(kVideoSsrc,
436 video_track_->GetSource()->GetVideoCapturer()));
437 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
438 rtc::scoped_refptr<VideoRtpSender> sender =
439 new VideoRtpSender(video_track_, kStreamLabel1, &video_provider_);
440 sender->SetSsrc(kVideoSsrc);
441
442 EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc, nullptr)).Times(1);
443 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _)).Times(1);
444 EXPECT_TRUE(sender->SetTrack(nullptr));
445
446 // Make sure it's SetTrack that called methods on the provider, and not the
447 // destructor.
448 EXPECT_CALL(video_provider_, SetCaptureDevice(_, _)).Times(0);
449 EXPECT_CALL(video_provider_, SetVideoSend(_, _, _)).Times(0);
450 }
451
452 TEST_F(RtpSenderReceiverTest, AudioSenderSsrcChanged) {
453 rtc::scoped_refptr<AudioTrackInterface> track =
454 AudioTrack::Create(kAudioTrackId, nullptr);
455 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
456 rtc::scoped_refptr<AudioRtpSender> sender =
457 new AudioRtpSender(track, kStreamLabel1, &audio_provider_, nullptr);
458 sender->SetSsrc(kAudioSsrc);
459
460 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _)).Times(1);
461 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc2, true, _, _)).Times(1);
462 sender->SetSsrc(kAudioSsrc2);
463
464 // Calls expected from destructor.
465 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc2, false, _, _)).Times(1);
466 }
467
468 TEST_F(RtpSenderReceiverTest, VideoSenderSsrcChanged) {
469 EXPECT_CALL(video_provider_,
470 SetCaptureDevice(kVideoSsrc,
471 video_track_->GetSource()->GetVideoCapturer()));
472 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
473 rtc::scoped_refptr<VideoRtpSender> sender =
474 new VideoRtpSender(video_track_, kStreamLabel1, &video_provider_);
475 sender->SetSsrc(kVideoSsrc);
476
477 EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc, nullptr)).Times(1);
478 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _)).Times(1);
479 EXPECT_CALL(video_provider_,
480 SetCaptureDevice(kVideoSsrc2,
481 video_track_->GetSource()->GetVideoCapturer()));
482 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc2, true, _));
483 sender->SetSsrc(kVideoSsrc2);
484
485 // Calls expected from destructor.
486 EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc2, nullptr)).Times(1);
487 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc2, false, _)).Times(1);
488 }
489
490 } // namespace webrtc 283 } // namespace webrtc
OLDNEW
« no previous file with comments | « talk/app/webrtc/rtpsenderinterface.h ('k') | talk/app/webrtc/test/fakemediastreamsignaling.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698