blob: c9871864bd5618548c89efbdbb354c455868355f [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>
29
30#include "talk/app/webrtc/audiotrack.h"
31#include "talk/app/webrtc/mediastream.h"
32#include "talk/app/webrtc/remoteaudiosource.h"
33#include "talk/app/webrtc/rtpreceiver.h"
34#include "talk/app/webrtc/rtpsender.h"
35#include "talk/app/webrtc/streamcollection.h"
36#include "talk/app/webrtc/videosource.h"
37#include "talk/app/webrtc/videotrack.h"
38#include "talk/media/base/fakevideocapturer.h"
39#include "talk/media/base/mediachannel.h"
40#include "testing/gmock/include/gmock/gmock.h"
41#include "testing/gtest/include/gtest/gtest.h"
42#include "webrtc/base/gunit.h"
43
44using ::testing::_;
45using ::testing::Exactly;
46
47static const char kStreamLabel1[] = "local_stream_1";
48static const char kVideoTrackId[] = "video_1";
49static const char kAudioTrackId[] = "audio_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +020050static const uint32_t kVideoSsrc = 98;
deadbeeffac06552015-11-25 11:26:01 -080051static const uint32_t kVideoSsrc2 = 100;
Peter Boström0c4e06b2015-10-07 12:23:21 +020052static const uint32_t kAudioSsrc = 99;
deadbeeffac06552015-11-25 11:26:01 -080053static const uint32_t kAudioSsrc2 = 101;
deadbeef70ab1a12015-09-28 16:53:55 -070054
55namespace webrtc {
56
57// Helper class to test RtpSender/RtpReceiver.
58class MockAudioProvider : public AudioProviderInterface {
59 public:
60 virtual ~MockAudioProvider() {}
solenbergd4cec0d2015-10-09 08:55:48 -070061 MOCK_METHOD2(SetAudioPlayout,
Peter Boström0c4e06b2015-10-07 12:23:21 +020062 void(uint32_t ssrc,
solenbergd4cec0d2015-10-09 08:55:48 -070063 bool enable));
deadbeef70ab1a12015-09-28 16:53:55 -070064 MOCK_METHOD4(SetAudioSend,
Peter Boström0c4e06b2015-10-07 12:23:21 +020065 void(uint32_t ssrc,
deadbeef70ab1a12015-09-28 16:53:55 -070066 bool enable,
67 const cricket::AudioOptions& options,
68 cricket::AudioRenderer* renderer));
Peter Boström0c4e06b2015-10-07 12:23:21 +020069 MOCK_METHOD2(SetAudioPlayoutVolume, void(uint32_t ssrc, double volume));
deadbeef70ab1a12015-09-28 16:53:55 -070070};
71
72// Helper class to test RtpSender/RtpReceiver.
73class MockVideoProvider : public VideoProviderInterface {
74 public:
75 virtual ~MockVideoProvider() {}
76 MOCK_METHOD2(SetCaptureDevice,
Peter Boström0c4e06b2015-10-07 12:23:21 +020077 bool(uint32_t ssrc, cricket::VideoCapturer* camera));
deadbeef70ab1a12015-09-28 16:53:55 -070078 MOCK_METHOD3(SetVideoPlayout,
Peter Boström0c4e06b2015-10-07 12:23:21 +020079 void(uint32_t ssrc,
deadbeef70ab1a12015-09-28 16:53:55 -070080 bool enable,
81 cricket::VideoRenderer* renderer));
82 MOCK_METHOD3(SetVideoSend,
Peter Boström0c4e06b2015-10-07 12:23:21 +020083 void(uint32_t ssrc,
deadbeef70ab1a12015-09-28 16:53:55 -070084 bool enable,
85 const cricket::VideoOptions* options));
86};
87
88class FakeVideoSource : public Notifier<VideoSourceInterface> {
89 public:
90 static rtc::scoped_refptr<FakeVideoSource> Create() {
91 return new rtc::RefCountedObject<FakeVideoSource>();
92 }
93 virtual cricket::VideoCapturer* GetVideoCapturer() { return &fake_capturer_; }
94 virtual void Stop() {}
95 virtual void Restart() {}
96 virtual void AddSink(cricket::VideoRenderer* output) {}
97 virtual void RemoveSink(cricket::VideoRenderer* output) {}
98 virtual SourceState state() const { return state_; }
99 virtual const cricket::VideoOptions* options() const { return &options_; }
100 virtual cricket::VideoRenderer* FrameInput() { return NULL; }
101
102 protected:
103 FakeVideoSource() : state_(kLive) {}
104 ~FakeVideoSource() {}
105
106 private:
107 cricket::FakeVideoCapturer fake_capturer_;
108 SourceState state_;
109 cricket::VideoOptions options_;
110};
111
112class RtpSenderReceiverTest : public testing::Test {
113 public:
114 virtual void SetUp() {
115 stream_ = MediaStream::Create(kStreamLabel1);
116 rtc::scoped_refptr<VideoSourceInterface> source(FakeVideoSource::Create());
117 video_track_ = VideoTrack::Create(kVideoTrackId, source);
118 EXPECT_TRUE(stream_->AddTrack(video_track_));
119 }
120
121 void CreateAudioRtpSender() {
122 audio_track_ = AudioTrack::Create(kAudioTrackId, NULL);
123 EXPECT_TRUE(stream_->AddTrack(audio_track_));
124 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
deadbeeffac06552015-11-25 11:26:01 -0800125 audio_rtp_sender_ =
126 new AudioRtpSender(stream_->GetAudioTracks()[0], stream_->label(),
127 &audio_provider_, nullptr);
128 audio_rtp_sender_->SetSsrc(kAudioSsrc);
deadbeef70ab1a12015-09-28 16:53:55 -0700129 }
130
131 void CreateVideoRtpSender() {
132 EXPECT_CALL(video_provider_,
133 SetCaptureDevice(
134 kVideoSsrc, video_track_->GetSource()->GetVideoCapturer()));
135 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
136 video_rtp_sender_ = new VideoRtpSender(stream_->GetVideoTracks()[0],
deadbeeffac06552015-11-25 11:26:01 -0800137 stream_->label(), &video_provider_);
138 video_rtp_sender_->SetSsrc(kVideoSsrc);
deadbeef70ab1a12015-09-28 16:53:55 -0700139 }
140
141 void DestroyAudioRtpSender() {
142 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _))
143 .Times(1);
144 audio_rtp_sender_ = nullptr;
145 }
146
147 void DestroyVideoRtpSender() {
148 EXPECT_CALL(video_provider_, SetCaptureDevice(kVideoSsrc, NULL)).Times(1);
149 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _)).Times(1);
150 video_rtp_sender_ = nullptr;
151 }
152
153 void CreateAudioRtpReceiver() {
154 audio_track_ =
155 AudioTrack::Create(kAudioTrackId, RemoteAudioSource::Create().get());
156 EXPECT_TRUE(stream_->AddTrack(audio_track_));
solenbergd4cec0d2015-10-09 08:55:48 -0700157 EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, true));
deadbeef70ab1a12015-09-28 16:53:55 -0700158 audio_rtp_receiver_ = new AudioRtpReceiver(stream_->GetAudioTracks()[0],
159 kAudioSsrc, &audio_provider_);
160 }
161
162 void CreateVideoRtpReceiver() {
163 EXPECT_CALL(video_provider_,
164 SetVideoPlayout(kVideoSsrc, true,
165 video_track_->GetSource()->FrameInput()));
166 video_rtp_receiver_ = new VideoRtpReceiver(stream_->GetVideoTracks()[0],
167 kVideoSsrc, &video_provider_);
168 }
169
170 void DestroyAudioRtpReceiver() {
solenbergd4cec0d2015-10-09 08:55:48 -0700171 EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, false));
deadbeef70ab1a12015-09-28 16:53:55 -0700172 audio_rtp_receiver_ = nullptr;
173 }
174
175 void DestroyVideoRtpReceiver() {
176 EXPECT_CALL(video_provider_, SetVideoPlayout(kVideoSsrc, false, NULL));
177 video_rtp_receiver_ = nullptr;
178 }
179
180 protected:
181 MockAudioProvider audio_provider_;
182 MockVideoProvider video_provider_;
183 rtc::scoped_refptr<AudioRtpSender> audio_rtp_sender_;
184 rtc::scoped_refptr<VideoRtpSender> video_rtp_sender_;
185 rtc::scoped_refptr<AudioRtpReceiver> audio_rtp_receiver_;
186 rtc::scoped_refptr<VideoRtpReceiver> video_rtp_receiver_;
187 rtc::scoped_refptr<MediaStreamInterface> stream_;
188 rtc::scoped_refptr<VideoTrackInterface> video_track_;
189 rtc::scoped_refptr<AudioTrackInterface> audio_track_;
190};
191
192// Test that |audio_provider_| is notified when an audio track is associated
193// and disassociated with an AudioRtpSender.
194TEST_F(RtpSenderReceiverTest, AddAndDestroyAudioRtpSender) {
195 CreateAudioRtpSender();
196 DestroyAudioRtpSender();
197}
198
199// Test that |video_provider_| is notified when a video track is associated and
200// disassociated with a VideoRtpSender.
201TEST_F(RtpSenderReceiverTest, AddAndDestroyVideoRtpSender) {
202 CreateVideoRtpSender();
203 DestroyVideoRtpSender();
204}
205
206// Test that |audio_provider_| is notified when a remote audio and track is
207// associated and disassociated with an AudioRtpReceiver.
208TEST_F(RtpSenderReceiverTest, AddAndDestroyAudioRtpReceiver) {
209 CreateAudioRtpReceiver();
210 DestroyAudioRtpReceiver();
211}
212
213// Test that |video_provider_| is notified when a remote
214// video track is associated and disassociated with a VideoRtpReceiver.
215TEST_F(RtpSenderReceiverTest, AddAndDestroyVideoRtpReceiver) {
216 CreateVideoRtpReceiver();
217 DestroyVideoRtpReceiver();
218}
219
220TEST_F(RtpSenderReceiverTest, LocalAudioTrackDisable) {
221 CreateAudioRtpSender();
222
223 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _));
224 audio_track_->set_enabled(false);
225
226 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
227 audio_track_->set_enabled(true);
228
229 DestroyAudioRtpSender();
230}
231
232TEST_F(RtpSenderReceiverTest, RemoteAudioTrackDisable) {
233 CreateAudioRtpReceiver();
234
solenbergd4cec0d2015-10-09 08:55:48 -0700235 EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, false));
deadbeef70ab1a12015-09-28 16:53:55 -0700236 audio_track_->set_enabled(false);
237
solenbergd4cec0d2015-10-09 08:55:48 -0700238 EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, true));
deadbeef70ab1a12015-09-28 16:53:55 -0700239 audio_track_->set_enabled(true);
240
241 DestroyAudioRtpReceiver();
242}
243
244TEST_F(RtpSenderReceiverTest, LocalVideoTrackDisable) {
245 CreateVideoRtpSender();
246
247 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _));
248 video_track_->set_enabled(false);
249
250 EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _));
251 video_track_->set_enabled(true);
252
253 DestroyVideoRtpSender();
254}
255
256TEST_F(RtpSenderReceiverTest, RemoteVideoTrackDisable) {
257 CreateVideoRtpReceiver();
258
259 video_track_->set_enabled(false);
260
261 video_track_->set_enabled(true);
262
263 DestroyVideoRtpReceiver();
264}
265
266TEST_F(RtpSenderReceiverTest, RemoteAudioTrackSetVolume) {
267 CreateAudioRtpReceiver();
268
269 double volume = 0.5;
270 EXPECT_CALL(audio_provider_, SetAudioPlayoutVolume(kAudioSsrc, volume));
271 audio_track_->GetSource()->SetVolume(volume);
272
273 // Disable the audio track, this should prevent setting the volume.
solenbergd4cec0d2015-10-09 08:55:48 -0700274 EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, false));
deadbeef70ab1a12015-09-28 16:53:55 -0700275 audio_track_->set_enabled(false);
276 audio_track_->GetSource()->SetVolume(1.0);
277
solenbergd4cec0d2015-10-09 08:55:48 -0700278 EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, true));
deadbeef70ab1a12015-09-28 16:53:55 -0700279 audio_track_->set_enabled(true);
280
281 double new_volume = 0.8;
282 EXPECT_CALL(audio_provider_, SetAudioPlayoutVolume(kAudioSsrc, new_volume));
283 audio_track_->GetSource()->SetVolume(new_volume);
284
285 DestroyAudioRtpReceiver();
286}
287
deadbeeffac06552015-11-25 11:26:01 -0800288// Test that provider methods aren't called without both a track and an SSRC.
289TEST_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.
303TEST_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.
316TEST_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.
331TEST_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.
346TEST_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.
363TEST_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.
380TEST_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.
398TEST_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
417TEST_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
433TEST_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
452TEST_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
468TEST_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
deadbeef70ab1a12015-09-28 16:53:55 -0700490} // namespace webrtc