1 /*
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>
29 #include <utility>
30
31 #include "talk/app/webrtc/audiotrack.h"
32 #include "talk/app/webrtc/mediastream.h"
33 #include "talk/app/webrtc/remoteaudiosource.h"
34 #include "talk/app/webrtc/rtpreceiver.h"
35 #include "talk/app/webrtc/rtpsender.h"
36 #include "talk/app/webrtc/streamcollection.h"
37 #include "talk/app/webrtc/videosource.h"
38 #include "talk/app/webrtc/videotrack.h"
39 #include "talk/media/base/fakevideocapturer.h"
40 #include "talk/media/base/mediachannel.h"
41 #include "testing/gmock/include/gmock/gmock.h"
42 #include "testing/gtest/include/gtest/gtest.h"
43 #include "webrtc/base/gunit.h"
44
45 using ::testing::_;
46 using ::testing::Exactly;
47
48 static const char kStreamLabel1[] = "local_stream_1";
49 static const char kVideoTrackId[] = "video_1";
50 static const char kAudioTrackId[] = "audio_1";
51 static const uint32_t kVideoSsrc = 98;
52 static const uint32_t kVideoSsrc2 = 100;
53 static const uint32_t kAudioSsrc = 99;
54 static const uint32_t kAudioSsrc2 = 101;
55
56 namespace webrtc {
57
58 // Helper class to test RtpSender/RtpReceiver.
59 class MockAudioProvider : public AudioProviderInterface {
60 public:
~MockAudioProvider()61 ~MockAudioProvider() override {}
62
63 MOCK_METHOD2(SetAudioPlayout,
64 void(uint32_t ssrc,
65 bool enable));
66 MOCK_METHOD4(SetAudioSend,
67 void(uint32_t ssrc,
68 bool enable,
69 const cricket::AudioOptions& options,
70 cricket::AudioRenderer* renderer));
71 MOCK_METHOD2(SetAudioPlayoutVolume, void(uint32_t ssrc, double volume));
72
SetRawAudioSink(uint32_t,rtc::scoped_ptr<AudioSinkInterface> sink)73 void SetRawAudioSink(uint32_t,
74 rtc::scoped_ptr<AudioSinkInterface> sink) override {
75 sink_ = std::move(sink);
76 }
77
78 private:
79 rtc::scoped_ptr<AudioSinkInterface> sink_;
80 };
81
82 // Helper class to test RtpSender/RtpReceiver.
83 class MockVideoProvider : public VideoProviderInterface {
84 public:
~MockVideoProvider()85 virtual ~MockVideoProvider() {}
86 MOCK_METHOD2(SetCaptureDevice,
87 bool(uint32_t ssrc, cricket::VideoCapturer* camera));
88 MOCK_METHOD3(SetVideoPlayout,
89 void(uint32_t ssrc,
90 bool enable,
91 cricket::VideoRenderer* renderer));
92 MOCK_METHOD3(SetVideoSend,
93 void(uint32_t ssrc,
94 bool enable,
95 const cricket::VideoOptions* options));
96 };
97
98 class FakeVideoSource : public Notifier<VideoSourceInterface> {
99 public:
Create(bool remote)100 static rtc::scoped_refptr<FakeVideoSource> Create(bool remote) {
101 return new rtc::RefCountedObject<FakeVideoSource>(remote);
102 }
GetVideoCapturer()103 virtual cricket::VideoCapturer* GetVideoCapturer() { return &fake_capturer_; }
Stop()104 virtual void Stop() {}
Restart()105 virtual void Restart() {}
AddSink(cricket::VideoRenderer * output)106 virtual void AddSink(cricket::VideoRenderer* output) {}
RemoveSink(cricket::VideoRenderer * output)107 virtual void RemoveSink(cricket::VideoRenderer* output) {}
state() const108 virtual SourceState state() const { return state_; }
remote() const109 virtual bool remote() const { return remote_; }
options() const110 virtual const cricket::VideoOptions* options() const { return &options_; }
FrameInput()111 virtual cricket::VideoRenderer* FrameInput() { return NULL; }
112
113 protected:
FakeVideoSource(bool remote)114 explicit FakeVideoSource(bool remote) : state_(kLive), remote_(remote) {}
~FakeVideoSource()115 ~FakeVideoSource() {}
116
117 private:
118 cricket::FakeVideoCapturer fake_capturer_;
119 SourceState state_;
120 bool remote_;
121 cricket::VideoOptions options_;
122 };
123
124 class RtpSenderReceiverTest : public testing::Test {
125 public:
SetUp()126 virtual void SetUp() {
127 stream_ = MediaStream::Create(kStreamLabel1);
128 }
129
AddVideoTrack(bool remote)130 void AddVideoTrack(bool remote) {
131 rtc::scoped_refptr<VideoSourceInterface> source(
132 FakeVideoSource::Create(remote));
133 video_track_ = VideoTrack::Create(kVideoTrackId, source);
134 EXPECT_TRUE(stream_->AddTrack(video_track_));
135 }
136
CreateAudioRtpSender()137 void CreateAudioRtpSender() {
138 audio_track_ = AudioTrack::Create(kAudioTrackId, NULL);
139 EXPECT_TRUE(stream_->AddTrack(audio_track_));
140 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
141 audio_rtp_sender_ =
142 new AudioRtpSender(stream_->GetAudioTracks()[0], stream_->label(),
143 &audio_provider_, nullptr);
144 audio_rtp_sender_->SetSsrc(kAudioSsrc);
145 }
146
CreateVideoRtpSender()147 void CreateVideoRtpSender() {
148 AddVideoTrack(false);
149 EXPECT_CALL(video_provider_,
150 SetCaptureDevice(
151 kVideoSsrc, video_track_->GetSource()->GetVideoCapturer()));
152 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
153 video_rtp_sender_ = new VideoRtpSender(stream_->GetVideoTracks()[0],
154 stream_->label(), &video_provider_);
155 video_rtp_sender_->SetSsrc(kVideoSsrc);
156 }
157
DestroyAudioRtpSender()158 void DestroyAudioRtpSender() {
159 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _))
160 .Times(1);
161 audio_rtp_sender_ = nullptr;
162 }
163
DestroyVideoRtpSender()164 void DestroyVideoRtpSender() {
165 EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc, NULL)).Times(1);
166 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _)).Times(1);
167 video_rtp_sender_ = nullptr;
168 }
169
CreateAudioRtpReceiver()170 void CreateAudioRtpReceiver() {
171 audio_track_ = AudioTrack::Create(
172 kAudioTrackId, RemoteAudioSource::Create(kAudioSsrc, NULL));
173 EXPECT_TRUE(stream_->AddTrack(audio_track_));
174 EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, true));
175 audio_rtp_receiver_ = new AudioRtpReceiver(stream_->GetAudioTracks()[0],
176 kAudioSsrc, &audio_provider_);
177 }
178
CreateVideoRtpReceiver()179 void CreateVideoRtpReceiver() {
180 AddVideoTrack(true);
181 EXPECT_CALL(video_provider_,
182 SetVideoPlayout(kVideoSsrc, true,
183 video_track_->GetSource()->FrameInput()));
184 video_rtp_receiver_ = new VideoRtpReceiver(stream_->GetVideoTracks()[0],
185 kVideoSsrc, &video_provider_);
186 }
187
DestroyAudioRtpReceiver()188 void DestroyAudioRtpReceiver() {
189 EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, false));
190 audio_rtp_receiver_ = nullptr;
191 }
192
DestroyVideoRtpReceiver()193 void DestroyVideoRtpReceiver() {
194 EXPECT_CALL(video_provider_, SetVideoPlayout(kVideoSsrc, false, NULL));
195 video_rtp_receiver_ = nullptr;
196 }
197
198 protected:
199 MockAudioProvider audio_provider_;
200 MockVideoProvider video_provider_;
201 rtc::scoped_refptr<AudioRtpSender> audio_rtp_sender_;
202 rtc::scoped_refptr<VideoRtpSender> video_rtp_sender_;
203 rtc::scoped_refptr<AudioRtpReceiver> audio_rtp_receiver_;
204 rtc::scoped_refptr<VideoRtpReceiver> video_rtp_receiver_;
205 rtc::scoped_refptr<MediaStreamInterface> stream_;
206 rtc::scoped_refptr<VideoTrackInterface> video_track_;
207 rtc::scoped_refptr<AudioTrackInterface> audio_track_;
208 };
209
210 // Test that |audio_provider_| is notified when an audio track is associated
211 // and disassociated with an AudioRtpSender.
TEST_F(RtpSenderReceiverTest,AddAndDestroyAudioRtpSender)212 TEST_F(RtpSenderReceiverTest, AddAndDestroyAudioRtpSender) {
213 CreateAudioRtpSender();
214 DestroyAudioRtpSender();
215 }
216
217 // Test that |video_provider_| is notified when a video track is associated and
218 // disassociated with a VideoRtpSender.
TEST_F(RtpSenderReceiverTest,AddAndDestroyVideoRtpSender)219 TEST_F(RtpSenderReceiverTest, AddAndDestroyVideoRtpSender) {
220 CreateVideoRtpSender();
221 DestroyVideoRtpSender();
222 }
223
224 // Test that |audio_provider_| is notified when a remote audio and track is
225 // associated and disassociated with an AudioRtpReceiver.
TEST_F(RtpSenderReceiverTest,AddAndDestroyAudioRtpReceiver)226 TEST_F(RtpSenderReceiverTest, AddAndDestroyAudioRtpReceiver) {
227 CreateAudioRtpReceiver();
228 DestroyAudioRtpReceiver();
229 }
230
231 // Test that |video_provider_| is notified when a remote
232 // video track is associated and disassociated with a VideoRtpReceiver.
TEST_F(RtpSenderReceiverTest,AddAndDestroyVideoRtpReceiver)233 TEST_F(RtpSenderReceiverTest, AddAndDestroyVideoRtpReceiver) {
234 CreateVideoRtpReceiver();
235 DestroyVideoRtpReceiver();
236 }
237
TEST_F(RtpSenderReceiverTest,LocalAudioTrackDisable)238 TEST_F(RtpSenderReceiverTest, LocalAudioTrackDisable) {
239 CreateAudioRtpSender();
240
241 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _));
242 audio_track_->set_enabled(false);
243
244 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
245 audio_track_->set_enabled(true);
246
247 DestroyAudioRtpSender();
248 }
249
TEST_F(RtpSenderReceiverTest,RemoteAudioTrackDisable)250 TEST_F(RtpSenderReceiverTest, RemoteAudioTrackDisable) {
251 CreateAudioRtpReceiver();
252
253 EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, false));
254 audio_track_->set_enabled(false);
255
256 EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, true));
257 audio_track_->set_enabled(true);
258
259 DestroyAudioRtpReceiver();
260 }
261
TEST_F(RtpSenderReceiverTest,LocalVideoTrackDisable)262 TEST_F(RtpSenderReceiverTest, LocalVideoTrackDisable) {
263 CreateVideoRtpSender();
264
265 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _));
266 video_track_->set_enabled(false);
267
268 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
269 video_track_->set_enabled(true);
270
271 DestroyVideoRtpSender();
272 }
273
TEST_F(RtpSenderReceiverTest,RemoteVideoTrackDisable)274 TEST_F(RtpSenderReceiverTest, RemoteVideoTrackDisable) {
275 CreateVideoRtpReceiver();
276
277 video_track_->set_enabled(false);
278
279 video_track_->set_enabled(true);
280
281 DestroyVideoRtpReceiver();
282 }
283
TEST_F(RtpSenderReceiverTest,RemoteAudioTrackSetVolume)284 TEST_F(RtpSenderReceiverTest, RemoteAudioTrackSetVolume) {
285 CreateAudioRtpReceiver();
286
287 double volume = 0.5;
288 EXPECT_CALL(audio_provider_, SetAudioPlayoutVolume(kAudioSsrc, volume));
289 audio_track_->GetSource()->SetVolume(volume);
290
291 // Disable the audio track, this should prevent setting the volume.
292 EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, false));
293 audio_track_->set_enabled(false);
294 audio_track_->GetSource()->SetVolume(1.0);
295
296 EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, true));
297 audio_track_->set_enabled(true);
298
299 double new_volume = 0.8;
300 EXPECT_CALL(audio_provider_, SetAudioPlayoutVolume(kAudioSsrc, new_volume));
301 audio_track_->GetSource()->SetVolume(new_volume);
302
303 DestroyAudioRtpReceiver();
304 }
305
306 // Test that provider methods aren't called without both a track and an SSRC.
TEST_F(RtpSenderReceiverTest,AudioSenderWithoutTrackAndSsrc)307 TEST_F(RtpSenderReceiverTest, AudioSenderWithoutTrackAndSsrc) {
308 rtc::scoped_refptr<AudioRtpSender> sender =
309 new AudioRtpSender(&audio_provider_, nullptr);
310 rtc::scoped_refptr<AudioTrackInterface> track =
311 AudioTrack::Create(kAudioTrackId, nullptr);
312 EXPECT_TRUE(sender->SetTrack(track));
313 EXPECT_TRUE(sender->SetTrack(nullptr));
314 sender->SetSsrc(kAudioSsrc);
315 sender->SetSsrc(0);
316 // Just let it get destroyed and make sure it doesn't call any methods on the
317 // provider interface.
318 }
319
320 // Test that provider methods aren't called without both a track and an SSRC.
TEST_F(RtpSenderReceiverTest,VideoSenderWithoutTrackAndSsrc)321 TEST_F(RtpSenderReceiverTest, VideoSenderWithoutTrackAndSsrc) {
322 rtc::scoped_refptr<VideoRtpSender> sender =
323 new VideoRtpSender(&video_provider_);
324 EXPECT_TRUE(sender->SetTrack(video_track_));
325 EXPECT_TRUE(sender->SetTrack(nullptr));
326 sender->SetSsrc(kVideoSsrc);
327 sender->SetSsrc(0);
328 // Just let it get destroyed and make sure it doesn't call any methods on the
329 // provider interface.
330 }
331
332 // Test that an audio sender calls the expected methods on the provider once
333 // it has a track and SSRC, when the SSRC is set first.
TEST_F(RtpSenderReceiverTest,AudioSenderEarlyWarmupSsrcThenTrack)334 TEST_F(RtpSenderReceiverTest, AudioSenderEarlyWarmupSsrcThenTrack) {
335 rtc::scoped_refptr<AudioRtpSender> sender =
336 new AudioRtpSender(&audio_provider_, nullptr);
337 rtc::scoped_refptr<AudioTrackInterface> track =
338 AudioTrack::Create(kAudioTrackId, nullptr);
339 sender->SetSsrc(kAudioSsrc);
340 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
341 sender->SetTrack(track);
342
343 // Calls expected from destructor.
344 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _)).Times(1);
345 }
346
347 // Test that an audio sender calls the expected methods on the provider once
348 // it has a track and SSRC, when the SSRC is set last.
TEST_F(RtpSenderReceiverTest,AudioSenderEarlyWarmupTrackThenSsrc)349 TEST_F(RtpSenderReceiverTest, AudioSenderEarlyWarmupTrackThenSsrc) {
350 rtc::scoped_refptr<AudioRtpSender> sender =
351 new AudioRtpSender(&audio_provider_, nullptr);
352 rtc::scoped_refptr<AudioTrackInterface> track =
353 AudioTrack::Create(kAudioTrackId, nullptr);
354 sender->SetTrack(track);
355 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
356 sender->SetSsrc(kAudioSsrc);
357
358 // Calls expected from destructor.
359 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _)).Times(1);
360 }
361
362 // Test that a video sender calls the expected methods on the provider once
363 // it has a track and SSRC, when the SSRC is set first.
TEST_F(RtpSenderReceiverTest,VideoSenderEarlyWarmupSsrcThenTrack)364 TEST_F(RtpSenderReceiverTest, VideoSenderEarlyWarmupSsrcThenTrack) {
365 AddVideoTrack(false);
366 rtc::scoped_refptr<VideoRtpSender> sender =
367 new VideoRtpSender(&video_provider_);
368 sender->SetSsrc(kVideoSsrc);
369 EXPECT_CALL(video_provider_,
370 SetCaptureDevice(kVideoSsrc,
371 video_track_->GetSource()->GetVideoCapturer()));
372 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
373 sender->SetTrack(video_track_);
374
375 // Calls expected from destructor.
376 EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc, nullptr)).Times(1);
377 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _)).Times(1);
378 }
379
380 // Test that a video sender calls the expected methods on the provider once
381 // it has a track and SSRC, when the SSRC is set last.
TEST_F(RtpSenderReceiverTest,VideoSenderEarlyWarmupTrackThenSsrc)382 TEST_F(RtpSenderReceiverTest, VideoSenderEarlyWarmupTrackThenSsrc) {
383 AddVideoTrack(false);
384 rtc::scoped_refptr<VideoRtpSender> sender =
385 new VideoRtpSender(&video_provider_);
386 sender->SetTrack(video_track_);
387 EXPECT_CALL(video_provider_,
388 SetCaptureDevice(kVideoSsrc,
389 video_track_->GetSource()->GetVideoCapturer()));
390 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
391 sender->SetSsrc(kVideoSsrc);
392
393 // Calls expected from destructor.
394 EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc, nullptr)).Times(1);
395 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _)).Times(1);
396 }
397
398 // Test that the sender is disconnected from the provider when its SSRC is
399 // set to 0.
TEST_F(RtpSenderReceiverTest,AudioSenderSsrcSetToZero)400 TEST_F(RtpSenderReceiverTest, AudioSenderSsrcSetToZero) {
401 rtc::scoped_refptr<AudioTrackInterface> track =
402 AudioTrack::Create(kAudioTrackId, nullptr);
403 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
404 rtc::scoped_refptr<AudioRtpSender> sender =
405 new AudioRtpSender(track, kStreamLabel1, &audio_provider_, nullptr);
406 sender->SetSsrc(kAudioSsrc);
407
408 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, 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(audio_provider_, SetAudioSend(_, _, _, _)).Times(0);
414 }
415
416 // Test that the sender is disconnected from the provider when its SSRC is
417 // set to 0.
TEST_F(RtpSenderReceiverTest,VideoSenderSsrcSetToZero)418 TEST_F(RtpSenderReceiverTest, VideoSenderSsrcSetToZero) {
419 AddVideoTrack(false);
420 EXPECT_CALL(video_provider_,
421 SetCaptureDevice(kVideoSsrc,
422 video_track_->GetSource()->GetVideoCapturer()));
423 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
424 rtc::scoped_refptr<VideoRtpSender> sender =
425 new VideoRtpSender(video_track_, kStreamLabel1, &video_provider_);
426 sender->SetSsrc(kVideoSsrc);
427
428 EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc, nullptr)).Times(1);
429 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _)).Times(1);
430 sender->SetSsrc(0);
431
432 // Make sure it's SetSsrc that called methods on the provider, and not the
433 // destructor.
434 EXPECT_CALL(video_provider_, SetCaptureDevice(_, _)).Times(0);
435 EXPECT_CALL(video_provider_, SetVideoSend(_, _, _)).Times(0);
436 }
437
TEST_F(RtpSenderReceiverTest,AudioSenderTrackSetToNull)438 TEST_F(RtpSenderReceiverTest, AudioSenderTrackSetToNull) {
439 rtc::scoped_refptr<AudioTrackInterface> track =
440 AudioTrack::Create(kAudioTrackId, nullptr);
441 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
442 rtc::scoped_refptr<AudioRtpSender> sender =
443 new AudioRtpSender(track, kStreamLabel1, &audio_provider_, nullptr);
444 sender->SetSsrc(kAudioSsrc);
445
446 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _)).Times(1);
447 EXPECT_TRUE(sender->SetTrack(nullptr));
448
449 // Make sure it's SetTrack that called methods on the provider, and not the
450 // destructor.
451 EXPECT_CALL(audio_provider_, SetAudioSend(_, _, _, _)).Times(0);
452 }
453
TEST_F(RtpSenderReceiverTest,VideoSenderTrackSetToNull)454 TEST_F(RtpSenderReceiverTest, VideoSenderTrackSetToNull) {
455 AddVideoTrack(false);
456 EXPECT_CALL(video_provider_,
457 SetCaptureDevice(kVideoSsrc,
458 video_track_->GetSource()->GetVideoCapturer()));
459 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
460 rtc::scoped_refptr<VideoRtpSender> sender =
461 new VideoRtpSender(video_track_, kStreamLabel1, &video_provider_);
462 sender->SetSsrc(kVideoSsrc);
463
464 EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc, nullptr)).Times(1);
465 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _)).Times(1);
466 EXPECT_TRUE(sender->SetTrack(nullptr));
467
468 // Make sure it's SetTrack that called methods on the provider, and not the
469 // destructor.
470 EXPECT_CALL(video_provider_, SetCaptureDevice(_, _)).Times(0);
471 EXPECT_CALL(video_provider_, SetVideoSend(_, _, _)).Times(0);
472 }
473
TEST_F(RtpSenderReceiverTest,AudioSenderSsrcChanged)474 TEST_F(RtpSenderReceiverTest, AudioSenderSsrcChanged) {
475 AddVideoTrack(false);
476 rtc::scoped_refptr<AudioTrackInterface> track =
477 AudioTrack::Create(kAudioTrackId, nullptr);
478 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
479 rtc::scoped_refptr<AudioRtpSender> sender =
480 new AudioRtpSender(track, kStreamLabel1, &audio_provider_, nullptr);
481 sender->SetSsrc(kAudioSsrc);
482
483 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _)).Times(1);
484 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc2, true, _, _)).Times(1);
485 sender->SetSsrc(kAudioSsrc2);
486
487 // Calls expected from destructor.
488 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc2, false, _, _)).Times(1);
489 }
490
TEST_F(RtpSenderReceiverTest,VideoSenderSsrcChanged)491 TEST_F(RtpSenderReceiverTest, VideoSenderSsrcChanged) {
492 AddVideoTrack(false);
493 EXPECT_CALL(video_provider_,
494 SetCaptureDevice(kVideoSsrc,
495 video_track_->GetSource()->GetVideoCapturer()));
496 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
497 rtc::scoped_refptr<VideoRtpSender> sender =
498 new VideoRtpSender(video_track_, kStreamLabel1, &video_provider_);
499 sender->SetSsrc(kVideoSsrc);
500
501 EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc, nullptr)).Times(1);
502 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _)).Times(1);
503 EXPECT_CALL(video_provider_,
504 SetCaptureDevice(kVideoSsrc2,
505 video_track_->GetSource()->GetVideoCapturer()));
506 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc2, true, _));
507 sender->SetSsrc(kVideoSsrc2);
508
509 // Calls expected from destructor.
510 EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc2, nullptr)).Times(1);
511 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc2, false, _)).Times(1);
512 }
513
514 } // namespace webrtc
515