blob: 3f61504cae36509b4c20fe3803e4c6f1354dec18 [file] [log] [blame]
deadbeef70ab1a12015-09-28 16:53:55 -07001/*
2 * libjingle
3 * Copyright 2012 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <string>
Tommif888bb52015-12-12 01:37:01 +010029#include <utility>
deadbeef70ab1a12015-09-28 16:53:55 -070030
31#include "talk/app/webrtc/audiotrack.h"
32#include "talk/app/webrtc/mediastream.h"
33#include "talk/app/webrtc/remoteaudiosource.h"
Tommif888bb52015-12-12 01:37:01 +010034#include "talk/app/webrtc/remoteaudiotrack.h"
deadbeef70ab1a12015-09-28 16:53:55 -070035#include "talk/app/webrtc/rtpreceiver.h"
36#include "talk/app/webrtc/rtpsender.h"
37#include "talk/app/webrtc/streamcollection.h"
38#include "talk/app/webrtc/videosource.h"
39#include "talk/app/webrtc/videotrack.h"
40#include "talk/media/base/fakevideocapturer.h"
41#include "talk/media/base/mediachannel.h"
42#include "testing/gmock/include/gmock/gmock.h"
43#include "testing/gtest/include/gtest/gtest.h"
44#include "webrtc/base/gunit.h"
45
46using ::testing::_;
47using ::testing::Exactly;
48
49static const char kStreamLabel1[] = "local_stream_1";
50static const char kVideoTrackId[] = "video_1";
51static const char kAudioTrackId[] = "audio_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +020052static const uint32_t kVideoSsrc = 98;
deadbeeffac06552015-11-25 11:26:01 -080053static const uint32_t kVideoSsrc2 = 100;
Peter Boström0c4e06b2015-10-07 12:23:21 +020054static const uint32_t kAudioSsrc = 99;
deadbeeffac06552015-11-25 11:26:01 -080055static const uint32_t kAudioSsrc2 = 101;
deadbeef70ab1a12015-09-28 16:53:55 -070056
57namespace webrtc {
58
59// Helper class to test RtpSender/RtpReceiver.
60class MockAudioProvider : public AudioProviderInterface {
61 public:
Tommif888bb52015-12-12 01:37:01 +010062 ~MockAudioProvider() override {}
63
solenbergd4cec0d2015-10-09 08:55:48 -070064 MOCK_METHOD2(SetAudioPlayout,
Peter Boström0c4e06b2015-10-07 12:23:21 +020065 void(uint32_t ssrc,
solenbergd4cec0d2015-10-09 08:55:48 -070066 bool enable));
deadbeef70ab1a12015-09-28 16:53:55 -070067 MOCK_METHOD4(SetAudioSend,
Peter Boström0c4e06b2015-10-07 12:23:21 +020068 void(uint32_t ssrc,
deadbeef70ab1a12015-09-28 16:53:55 -070069 bool enable,
70 const cricket::AudioOptions& options,
71 cricket::AudioRenderer* renderer));
Peter Boström0c4e06b2015-10-07 12:23:21 +020072 MOCK_METHOD2(SetAudioPlayoutVolume, void(uint32_t ssrc, double volume));
Tommif888bb52015-12-12 01:37:01 +010073
74 void SetRawAudioSink(uint32_t,
75 rtc::scoped_ptr<AudioSinkInterface> sink) override {
76 sink_ = std::move(sink);
77 }
78
79 private:
80 rtc::scoped_ptr<AudioSinkInterface> sink_;
deadbeef70ab1a12015-09-28 16:53:55 -070081};
82
83// Helper class to test RtpSender/RtpReceiver.
84class MockVideoProvider : public VideoProviderInterface {
85 public:
86 virtual ~MockVideoProvider() {}
87 MOCK_METHOD2(SetCaptureDevice,
Peter Boström0c4e06b2015-10-07 12:23:21 +020088 bool(uint32_t ssrc, cricket::VideoCapturer* camera));
deadbeef70ab1a12015-09-28 16:53:55 -070089 MOCK_METHOD3(SetVideoPlayout,
Peter Boström0c4e06b2015-10-07 12:23:21 +020090 void(uint32_t ssrc,
deadbeef70ab1a12015-09-28 16:53:55 -070091 bool enable,
92 cricket::VideoRenderer* renderer));
93 MOCK_METHOD3(SetVideoSend,
Peter Boström0c4e06b2015-10-07 12:23:21 +020094 void(uint32_t ssrc,
deadbeef70ab1a12015-09-28 16:53:55 -070095 bool enable,
96 const cricket::VideoOptions* options));
97};
98
99class FakeVideoSource : public Notifier<VideoSourceInterface> {
100 public:
101 static rtc::scoped_refptr<FakeVideoSource> Create() {
102 return new rtc::RefCountedObject<FakeVideoSource>();
103 }
104 virtual cricket::VideoCapturer* GetVideoCapturer() { return &fake_capturer_; }
105 virtual void Stop() {}
106 virtual void Restart() {}
107 virtual void AddSink(cricket::VideoRenderer* output) {}
108 virtual void RemoveSink(cricket::VideoRenderer* output) {}
109 virtual SourceState state() const { return state_; }
110 virtual const cricket::VideoOptions* options() const { return &options_; }
111 virtual cricket::VideoRenderer* FrameInput() { return NULL; }
112
113 protected:
114 FakeVideoSource() : state_(kLive) {}
115 ~FakeVideoSource() {}
116
117 private:
118 cricket::FakeVideoCapturer fake_capturer_;
119 SourceState state_;
120 cricket::VideoOptions options_;
121};
122
123class RtpSenderReceiverTest : public testing::Test {
124 public:
125 virtual void SetUp() {
126 stream_ = MediaStream::Create(kStreamLabel1);
127 rtc::scoped_refptr<VideoSourceInterface> source(FakeVideoSource::Create());
128 video_track_ = VideoTrack::Create(kVideoTrackId, source);
129 EXPECT_TRUE(stream_->AddTrack(video_track_));
130 }
131
132 void CreateAudioRtpSender() {
133 audio_track_ = AudioTrack::Create(kAudioTrackId, NULL);
134 EXPECT_TRUE(stream_->AddTrack(audio_track_));
135 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
deadbeeffac06552015-11-25 11:26:01 -0800136 audio_rtp_sender_ =
137 new AudioRtpSender(stream_->GetAudioTracks()[0], stream_->label(),
138 &audio_provider_, nullptr);
139 audio_rtp_sender_->SetSsrc(kAudioSsrc);
deadbeef70ab1a12015-09-28 16:53:55 -0700140 }
141
142 void CreateVideoRtpSender() {
143 EXPECT_CALL(video_provider_,
144 SetCaptureDevice(
145 kVideoSsrc, video_track_->GetSource()->GetVideoCapturer()));
146 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
147 video_rtp_sender_ = new VideoRtpSender(stream_->GetVideoTracks()[0],
deadbeeffac06552015-11-25 11:26:01 -0800148 stream_->label(), &video_provider_);
149 video_rtp_sender_->SetSsrc(kVideoSsrc);
deadbeef70ab1a12015-09-28 16:53:55 -0700150 }
151
152 void DestroyAudioRtpSender() {
153 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _))
154 .Times(1);
155 audio_rtp_sender_ = nullptr;
156 }
157
158 void DestroyVideoRtpSender() {
159 EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc, NULL)).Times(1);
160 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _)).Times(1);
161 video_rtp_sender_ = nullptr;
162 }
163
164 void CreateAudioRtpReceiver() {
Tommif888bb52015-12-12 01:37:01 +0100165 audio_track_ = RemoteAudioTrack::Create(
166 kAudioTrackId, RemoteAudioSource::Create(kAudioSsrc, NULL));
deadbeef70ab1a12015-09-28 16:53:55 -0700167 EXPECT_TRUE(stream_->AddTrack(audio_track_));
solenbergd4cec0d2015-10-09 08:55:48 -0700168 EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, true));
deadbeef70ab1a12015-09-28 16:53:55 -0700169 audio_rtp_receiver_ = new AudioRtpReceiver(stream_->GetAudioTracks()[0],
170 kAudioSsrc, &audio_provider_);
171 }
172
173 void CreateVideoRtpReceiver() {
174 EXPECT_CALL(video_provider_,
175 SetVideoPlayout(kVideoSsrc, true,
176 video_track_->GetSource()->FrameInput()));
177 video_rtp_receiver_ = new VideoRtpReceiver(stream_->GetVideoTracks()[0],
178 kVideoSsrc, &video_provider_);
179 }
180
181 void DestroyAudioRtpReceiver() {
solenbergd4cec0d2015-10-09 08:55:48 -0700182 EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, false));
deadbeef70ab1a12015-09-28 16:53:55 -0700183 audio_rtp_receiver_ = nullptr;
184 }
185
186 void DestroyVideoRtpReceiver() {
187 EXPECT_CALL(video_provider_, SetVideoPlayout(kVideoSsrc, false, NULL));
188 video_rtp_receiver_ = nullptr;
189 }
190
191 protected:
192 MockAudioProvider audio_provider_;
193 MockVideoProvider video_provider_;
194 rtc::scoped_refptr<AudioRtpSender> audio_rtp_sender_;
195 rtc::scoped_refptr<VideoRtpSender> video_rtp_sender_;
196 rtc::scoped_refptr<AudioRtpReceiver> audio_rtp_receiver_;
197 rtc::scoped_refptr<VideoRtpReceiver> video_rtp_receiver_;
198 rtc::scoped_refptr<MediaStreamInterface> stream_;
199 rtc::scoped_refptr<VideoTrackInterface> video_track_;
200 rtc::scoped_refptr<AudioTrackInterface> audio_track_;
201};
202
203// Test that |audio_provider_| is notified when an audio track is associated
204// and disassociated with an AudioRtpSender.
205TEST_F(RtpSenderReceiverTest, AddAndDestroyAudioRtpSender) {
206 CreateAudioRtpSender();
207 DestroyAudioRtpSender();
208}
209
210// Test that |video_provider_| is notified when a video track is associated and
211// disassociated with a VideoRtpSender.
212TEST_F(RtpSenderReceiverTest, AddAndDestroyVideoRtpSender) {
213 CreateVideoRtpSender();
214 DestroyVideoRtpSender();
215}
216
217// Test that |audio_provider_| is notified when a remote audio and track is
218// associated and disassociated with an AudioRtpReceiver.
219TEST_F(RtpSenderReceiverTest, AddAndDestroyAudioRtpReceiver) {
220 CreateAudioRtpReceiver();
221 DestroyAudioRtpReceiver();
222}
223
224// Test that |video_provider_| is notified when a remote
225// video track is associated and disassociated with a VideoRtpReceiver.
226TEST_F(RtpSenderReceiverTest, AddAndDestroyVideoRtpReceiver) {
227 CreateVideoRtpReceiver();
228 DestroyVideoRtpReceiver();
229}
230
231TEST_F(RtpSenderReceiverTest, LocalAudioTrackDisable) {
232 CreateAudioRtpSender();
233
234 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _));
235 audio_track_->set_enabled(false);
236
237 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
238 audio_track_->set_enabled(true);
239
240 DestroyAudioRtpSender();
241}
242
243TEST_F(RtpSenderReceiverTest, RemoteAudioTrackDisable) {
244 CreateAudioRtpReceiver();
245
solenbergd4cec0d2015-10-09 08:55:48 -0700246 EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, false));
deadbeef70ab1a12015-09-28 16:53:55 -0700247 audio_track_->set_enabled(false);
248
solenbergd4cec0d2015-10-09 08:55:48 -0700249 EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, true));
deadbeef70ab1a12015-09-28 16:53:55 -0700250 audio_track_->set_enabled(true);
251
252 DestroyAudioRtpReceiver();
253}
254
255TEST_F(RtpSenderReceiverTest, LocalVideoTrackDisable) {
256 CreateVideoRtpSender();
257
258 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _));
259 video_track_->set_enabled(false);
260
261 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
262 video_track_->set_enabled(true);
263
264 DestroyVideoRtpSender();
265}
266
267TEST_F(RtpSenderReceiverTest, RemoteVideoTrackDisable) {
268 CreateVideoRtpReceiver();
269
270 video_track_->set_enabled(false);
271
272 video_track_->set_enabled(true);
273
274 DestroyVideoRtpReceiver();
275}
276
277TEST_F(RtpSenderReceiverTest, RemoteAudioTrackSetVolume) {
278 CreateAudioRtpReceiver();
279
280 double volume = 0.5;
281 EXPECT_CALL(audio_provider_, SetAudioPlayoutVolume(kAudioSsrc, volume));
282 audio_track_->GetSource()->SetVolume(volume);
283
284 // Disable the audio track, this should prevent setting the volume.
solenbergd4cec0d2015-10-09 08:55:48 -0700285 EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, false));
deadbeef70ab1a12015-09-28 16:53:55 -0700286 audio_track_->set_enabled(false);
287 audio_track_->GetSource()->SetVolume(1.0);
288
solenbergd4cec0d2015-10-09 08:55:48 -0700289 EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, true));
deadbeef70ab1a12015-09-28 16:53:55 -0700290 audio_track_->set_enabled(true);
291
292 double new_volume = 0.8;
293 EXPECT_CALL(audio_provider_, SetAudioPlayoutVolume(kAudioSsrc, new_volume));
294 audio_track_->GetSource()->SetVolume(new_volume);
295
296 DestroyAudioRtpReceiver();
297}
298
deadbeeffac06552015-11-25 11:26:01 -0800299// Test that provider methods aren't called without both a track and an SSRC.
300TEST_F(RtpSenderReceiverTest, AudioSenderWithoutTrackAndSsrc) {
301 rtc::scoped_refptr<AudioRtpSender> sender =
302 new AudioRtpSender(&audio_provider_, nullptr);
303 rtc::scoped_refptr<AudioTrackInterface> track =
304 AudioTrack::Create(kAudioTrackId, nullptr);
305 EXPECT_TRUE(sender->SetTrack(track));
306 EXPECT_TRUE(sender->SetTrack(nullptr));
307 sender->SetSsrc(kAudioSsrc);
308 sender->SetSsrc(0);
309 // Just let it get destroyed and make sure it doesn't call any methods on the
310 // provider interface.
311}
312
313// Test that provider methods aren't called without both a track and an SSRC.
314TEST_F(RtpSenderReceiverTest, VideoSenderWithoutTrackAndSsrc) {
315 rtc::scoped_refptr<VideoRtpSender> sender =
316 new VideoRtpSender(&video_provider_);
317 EXPECT_TRUE(sender->SetTrack(video_track_));
318 EXPECT_TRUE(sender->SetTrack(nullptr));
319 sender->SetSsrc(kVideoSsrc);
320 sender->SetSsrc(0);
321 // Just let it get destroyed and make sure it doesn't call any methods on the
322 // provider interface.
323}
324
325// Test that an audio sender calls the expected methods on the provider once
326// it has a track and SSRC, when the SSRC is set first.
327TEST_F(RtpSenderReceiverTest, AudioSenderEarlyWarmupSsrcThenTrack) {
328 rtc::scoped_refptr<AudioRtpSender> sender =
329 new AudioRtpSender(&audio_provider_, nullptr);
330 rtc::scoped_refptr<AudioTrackInterface> track =
331 AudioTrack::Create(kAudioTrackId, nullptr);
332 sender->SetSsrc(kAudioSsrc);
333 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
334 sender->SetTrack(track);
335
336 // Calls expected from destructor.
337 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _)).Times(1);
338}
339
340// Test that an audio sender calls the expected methods on the provider once
341// it has a track and SSRC, when the SSRC is set last.
342TEST_F(RtpSenderReceiverTest, AudioSenderEarlyWarmupTrackThenSsrc) {
343 rtc::scoped_refptr<AudioRtpSender> sender =
344 new AudioRtpSender(&audio_provider_, nullptr);
345 rtc::scoped_refptr<AudioTrackInterface> track =
346 AudioTrack::Create(kAudioTrackId, nullptr);
347 sender->SetTrack(track);
348 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
349 sender->SetSsrc(kAudioSsrc);
350
351 // Calls expected from destructor.
352 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _)).Times(1);
353}
354
355// Test that a video sender calls the expected methods on the provider once
356// it has a track and SSRC, when the SSRC is set first.
357TEST_F(RtpSenderReceiverTest, VideoSenderEarlyWarmupSsrcThenTrack) {
358 rtc::scoped_refptr<VideoRtpSender> sender =
359 new VideoRtpSender(&video_provider_);
360 sender->SetSsrc(kVideoSsrc);
361 EXPECT_CALL(video_provider_,
362 SetCaptureDevice(kVideoSsrc,
363 video_track_->GetSource()->GetVideoCapturer()));
364 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
365 sender->SetTrack(video_track_);
366
367 // Calls expected from destructor.
368 EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc, nullptr)).Times(1);
369 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _)).Times(1);
370}
371
372// Test that a video sender calls the expected methods on the provider once
373// it has a track and SSRC, when the SSRC is set last.
374TEST_F(RtpSenderReceiverTest, VideoSenderEarlyWarmupTrackThenSsrc) {
375 rtc::scoped_refptr<VideoRtpSender> sender =
376 new VideoRtpSender(&video_provider_);
377 sender->SetTrack(video_track_);
378 EXPECT_CALL(video_provider_,
379 SetCaptureDevice(kVideoSsrc,
380 video_track_->GetSource()->GetVideoCapturer()));
381 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
382 sender->SetSsrc(kVideoSsrc);
383
384 // Calls expected from destructor.
385 EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc, nullptr)).Times(1);
386 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _)).Times(1);
387}
388
389// Test that the sender is disconnected from the provider when its SSRC is
390// set to 0.
391TEST_F(RtpSenderReceiverTest, AudioSenderSsrcSetToZero) {
392 rtc::scoped_refptr<AudioTrackInterface> track =
393 AudioTrack::Create(kAudioTrackId, nullptr);
394 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
395 rtc::scoped_refptr<AudioRtpSender> sender =
396 new AudioRtpSender(track, kStreamLabel1, &audio_provider_, nullptr);
397 sender->SetSsrc(kAudioSsrc);
398
399 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _)).Times(1);
400 sender->SetSsrc(0);
401
402 // Make sure it's SetSsrc that called methods on the provider, and not the
403 // destructor.
404 EXPECT_CALL(audio_provider_, SetAudioSend(_, _, _, _)).Times(0);
405}
406
407// Test that the sender is disconnected from the provider when its SSRC is
408// set to 0.
409TEST_F(RtpSenderReceiverTest, VideoSenderSsrcSetToZero) {
410 EXPECT_CALL(video_provider_,
411 SetCaptureDevice(kVideoSsrc,
412 video_track_->GetSource()->GetVideoCapturer()));
413 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
414 rtc::scoped_refptr<VideoRtpSender> sender =
415 new VideoRtpSender(video_track_, kStreamLabel1, &video_provider_);
416 sender->SetSsrc(kVideoSsrc);
417
418 EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc, nullptr)).Times(1);
419 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _)).Times(1);
420 sender->SetSsrc(0);
421
422 // Make sure it's SetSsrc that called methods on the provider, and not the
423 // destructor.
424 EXPECT_CALL(video_provider_, SetCaptureDevice(_, _)).Times(0);
425 EXPECT_CALL(video_provider_, SetVideoSend(_, _, _)).Times(0);
426}
427
428TEST_F(RtpSenderReceiverTest, AudioSenderTrackSetToNull) {
429 rtc::scoped_refptr<AudioTrackInterface> track =
430 AudioTrack::Create(kAudioTrackId, nullptr);
431 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
432 rtc::scoped_refptr<AudioRtpSender> sender =
433 new AudioRtpSender(track, kStreamLabel1, &audio_provider_, nullptr);
434 sender->SetSsrc(kAudioSsrc);
435
436 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _)).Times(1);
437 EXPECT_TRUE(sender->SetTrack(nullptr));
438
439 // Make sure it's SetTrack that called methods on the provider, and not the
440 // destructor.
441 EXPECT_CALL(audio_provider_, SetAudioSend(_, _, _, _)).Times(0);
442}
443
444TEST_F(RtpSenderReceiverTest, VideoSenderTrackSetToNull) {
445 EXPECT_CALL(video_provider_,
446 SetCaptureDevice(kVideoSsrc,
447 video_track_->GetSource()->GetVideoCapturer()));
448 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
449 rtc::scoped_refptr<VideoRtpSender> sender =
450 new VideoRtpSender(video_track_, kStreamLabel1, &video_provider_);
451 sender->SetSsrc(kVideoSsrc);
452
453 EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc, nullptr)).Times(1);
454 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _)).Times(1);
455 EXPECT_TRUE(sender->SetTrack(nullptr));
456
457 // Make sure it's SetTrack that called methods on the provider, and not the
458 // destructor.
459 EXPECT_CALL(video_provider_, SetCaptureDevice(_, _)).Times(0);
460 EXPECT_CALL(video_provider_, SetVideoSend(_, _, _)).Times(0);
461}
462
463TEST_F(RtpSenderReceiverTest, AudioSenderSsrcChanged) {
464 rtc::scoped_refptr<AudioTrackInterface> track =
465 AudioTrack::Create(kAudioTrackId, nullptr);
466 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
467 rtc::scoped_refptr<AudioRtpSender> sender =
468 new AudioRtpSender(track, kStreamLabel1, &audio_provider_, nullptr);
469 sender->SetSsrc(kAudioSsrc);
470
471 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _)).Times(1);
472 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc2, true, _, _)).Times(1);
473 sender->SetSsrc(kAudioSsrc2);
474
475 // Calls expected from destructor.
476 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc2, false, _, _)).Times(1);
477}
478
479TEST_F(RtpSenderReceiverTest, VideoSenderSsrcChanged) {
480 EXPECT_CALL(video_provider_,
481 SetCaptureDevice(kVideoSsrc,
482 video_track_->GetSource()->GetVideoCapturer()));
483 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
484 rtc::scoped_refptr<VideoRtpSender> sender =
485 new VideoRtpSender(video_track_, kStreamLabel1, &video_provider_);
486 sender->SetSsrc(kVideoSsrc);
487
488 EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc, nullptr)).Times(1);
489 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _)).Times(1);
490 EXPECT_CALL(video_provider_,
491 SetCaptureDevice(kVideoSsrc2,
492 video_track_->GetSource()->GetVideoCapturer()));
493 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc2, true, _));
494 sender->SetSsrc(kVideoSsrc2);
495
496 // Calls expected from destructor.
497 EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc2, nullptr)).Times(1);
498 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc2, false, _)).Times(1);
499}
500
deadbeef70ab1a12015-09-28 16:53:55 -0700501} // namespace webrtc