blob: a590e1d01f8b07df94c5b9304b04fa4a85e1b158 [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"
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
45using ::testing::_;
46using ::testing::Exactly;
47
48static const char kStreamLabel1[] = "local_stream_1";
49static const char kVideoTrackId[] = "video_1";
50static const char kAudioTrackId[] = "audio_1";
Peter Boström0c4e06b2015-10-07 12:23:21 +020051static const uint32_t kVideoSsrc = 98;
deadbeeffac06552015-11-25 11:26:01 -080052static const uint32_t kVideoSsrc2 = 100;
Peter Boström0c4e06b2015-10-07 12:23:21 +020053static const uint32_t kAudioSsrc = 99;
deadbeeffac06552015-11-25 11:26:01 -080054static const uint32_t kAudioSsrc2 = 101;
deadbeef70ab1a12015-09-28 16:53:55 -070055
56namespace webrtc {
57
58// Helper class to test RtpSender/RtpReceiver.
59class MockAudioProvider : public AudioProviderInterface {
60 public:
Tommif888bb52015-12-12 01:37:01 +010061 ~MockAudioProvider() override {}
62
solenbergd4cec0d2015-10-09 08:55:48 -070063 MOCK_METHOD2(SetAudioPlayout,
Peter Boström0c4e06b2015-10-07 12:23:21 +020064 void(uint32_t ssrc,
solenbergd4cec0d2015-10-09 08:55:48 -070065 bool enable));
deadbeef70ab1a12015-09-28 16:53:55 -070066 MOCK_METHOD4(SetAudioSend,
Peter Boström0c4e06b2015-10-07 12:23:21 +020067 void(uint32_t ssrc,
deadbeef70ab1a12015-09-28 16:53:55 -070068 bool enable,
69 const cricket::AudioOptions& options,
70 cricket::AudioRenderer* renderer));
Peter Boström0c4e06b2015-10-07 12:23:21 +020071 MOCK_METHOD2(SetAudioPlayoutVolume, void(uint32_t ssrc, double volume));
Tommif888bb52015-12-12 01:37:01 +010072
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_;
deadbeef70ab1a12015-09-28 16:53:55 -070080};
81
82// Helper class to test RtpSender/RtpReceiver.
83class MockVideoProvider : public VideoProviderInterface {
84 public:
85 virtual ~MockVideoProvider() {}
86 MOCK_METHOD2(SetCaptureDevice,
Peter Boström0c4e06b2015-10-07 12:23:21 +020087 bool(uint32_t ssrc, cricket::VideoCapturer* camera));
deadbeef70ab1a12015-09-28 16:53:55 -070088 MOCK_METHOD3(SetVideoPlayout,
Peter Boström0c4e06b2015-10-07 12:23:21 +020089 void(uint32_t ssrc,
deadbeef70ab1a12015-09-28 16:53:55 -070090 bool enable,
91 cricket::VideoRenderer* renderer));
92 MOCK_METHOD3(SetVideoSend,
Peter Boström0c4e06b2015-10-07 12:23:21 +020093 void(uint32_t ssrc,
deadbeef70ab1a12015-09-28 16:53:55 -070094 bool enable,
95 const cricket::VideoOptions* options));
96};
97
98class FakeVideoSource : public Notifier<VideoSourceInterface> {
99 public:
tommi6eca7e32015-12-15 04:27:11 -0800100 static rtc::scoped_refptr<FakeVideoSource> Create(bool remote) {
101 return new rtc::RefCountedObject<FakeVideoSource>(remote);
deadbeef70ab1a12015-09-28 16:53:55 -0700102 }
103 virtual cricket::VideoCapturer* GetVideoCapturer() { return &fake_capturer_; }
104 virtual void Stop() {}
105 virtual void Restart() {}
106 virtual void AddSink(cricket::VideoRenderer* output) {}
107 virtual void RemoveSink(cricket::VideoRenderer* output) {}
108 virtual SourceState state() const { return state_; }
tommi6eca7e32015-12-15 04:27:11 -0800109 virtual bool remote() const { return remote_; }
deadbeef70ab1a12015-09-28 16:53:55 -0700110 virtual const cricket::VideoOptions* options() const { return &options_; }
111 virtual cricket::VideoRenderer* FrameInput() { return NULL; }
112
113 protected:
tommi6eca7e32015-12-15 04:27:11 -0800114 explicit FakeVideoSource(bool remote) : state_(kLive), remote_(remote) {}
deadbeef70ab1a12015-09-28 16:53:55 -0700115 ~FakeVideoSource() {}
116
117 private:
118 cricket::FakeVideoCapturer fake_capturer_;
119 SourceState state_;
tommi6eca7e32015-12-15 04:27:11 -0800120 bool remote_;
deadbeef70ab1a12015-09-28 16:53:55 -0700121 cricket::VideoOptions options_;
122};
123
124class RtpSenderReceiverTest : public testing::Test {
125 public:
126 virtual void SetUp() {
127 stream_ = MediaStream::Create(kStreamLabel1);
tommi6eca7e32015-12-15 04:27:11 -0800128 }
129
130 void AddVideoTrack(bool remote) {
131 rtc::scoped_refptr<VideoSourceInterface> source(
132 FakeVideoSource::Create(remote));
deadbeef70ab1a12015-09-28 16:53:55 -0700133 video_track_ = VideoTrack::Create(kVideoTrackId, source);
134 EXPECT_TRUE(stream_->AddTrack(video_track_));
135 }
136
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, _, _));
deadbeeffac06552015-11-25 11:26:01 -0800141 audio_rtp_sender_ =
142 new AudioRtpSender(stream_->GetAudioTracks()[0], stream_->label(),
143 &audio_provider_, nullptr);
144 audio_rtp_sender_->SetSsrc(kAudioSsrc);
deadbeef70ab1a12015-09-28 16:53:55 -0700145 }
146
147 void CreateVideoRtpSender() {
tommi6eca7e32015-12-15 04:27:11 -0800148 AddVideoTrack(false);
deadbeef70ab1a12015-09-28 16:53:55 -0700149 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],
deadbeeffac06552015-11-25 11:26:01 -0800154 stream_->label(), &video_provider_);
155 video_rtp_sender_->SetSsrc(kVideoSsrc);
deadbeef70ab1a12015-09-28 16:53:55 -0700156 }
157
158 void DestroyAudioRtpSender() {
159 EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _))
160 .Times(1);
161 audio_rtp_sender_ = nullptr;
162 }
163
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
170 void CreateAudioRtpReceiver() {
tommi6eca7e32015-12-15 04:27:11 -0800171 audio_track_ = AudioTrack::Create(
Tommif888bb52015-12-12 01:37:01 +0100172 kAudioTrackId, RemoteAudioSource::Create(kAudioSsrc, NULL));
deadbeef70ab1a12015-09-28 16:53:55 -0700173 EXPECT_TRUE(stream_->AddTrack(audio_track_));
solenbergd4cec0d2015-10-09 08:55:48 -0700174 EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, true));
deadbeef70ab1a12015-09-28 16:53:55 -0700175 audio_rtp_receiver_ = new AudioRtpReceiver(stream_->GetAudioTracks()[0],
176 kAudioSsrc, &audio_provider_);
177 }
178
179 void CreateVideoRtpReceiver() {
tommi6eca7e32015-12-15 04:27:11 -0800180 AddVideoTrack(true);
deadbeef70ab1a12015-09-28 16:53:55 -0700181 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
188 void DestroyAudioRtpReceiver() {
solenbergd4cec0d2015-10-09 08:55:48 -0700189 EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, false));
deadbeef70ab1a12015-09-28 16:53:55 -0700190 audio_rtp_receiver_ = nullptr;
191 }
192
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.
212TEST_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.
219TEST_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.
226TEST_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.
233TEST_F(RtpSenderReceiverTest, AddAndDestroyVideoRtpReceiver) {
234 CreateVideoRtpReceiver();
235 DestroyVideoRtpReceiver();
236}
237
238TEST_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
250TEST_F(RtpSenderReceiverTest, RemoteAudioTrackDisable) {
251 CreateAudioRtpReceiver();
252
solenbergd4cec0d2015-10-09 08:55:48 -0700253 EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, false));
deadbeef70ab1a12015-09-28 16:53:55 -0700254 audio_track_->set_enabled(false);
255
solenbergd4cec0d2015-10-09 08:55:48 -0700256 EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, true));
deadbeef70ab1a12015-09-28 16:53:55 -0700257 audio_track_->set_enabled(true);
258
259 DestroyAudioRtpReceiver();
260}
261
262TEST_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
274TEST_F(RtpSenderReceiverTest, RemoteVideoTrackDisable) {
275 CreateVideoRtpReceiver();
276
277 video_track_->set_enabled(false);
278
279 video_track_->set_enabled(true);
280
281 DestroyVideoRtpReceiver();
282}
283
284TEST_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.
solenbergd4cec0d2015-10-09 08:55:48 -0700292 EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, false));
deadbeef70ab1a12015-09-28 16:53:55 -0700293 audio_track_->set_enabled(false);
294 audio_track_->GetSource()->SetVolume(1.0);
295
solenbergd4cec0d2015-10-09 08:55:48 -0700296 EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, true));
deadbeef70ab1a12015-09-28 16:53:55 -0700297 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
deadbeeffac06552015-11-25 11:26:01 -0800306// Test that provider methods aren't called without both a track and an SSRC.
307TEST_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.
321TEST_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.
334TEST_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.
349TEST_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.
364TEST_F(RtpSenderReceiverTest, VideoSenderEarlyWarmupSsrcThenTrack) {
tommi6eca7e32015-12-15 04:27:11 -0800365 AddVideoTrack(false);
deadbeeffac06552015-11-25 11:26:01 -0800366 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.
382TEST_F(RtpSenderReceiverTest, VideoSenderEarlyWarmupTrackThenSsrc) {
tommi6eca7e32015-12-15 04:27:11 -0800383 AddVideoTrack(false);
deadbeeffac06552015-11-25 11:26:01 -0800384 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.
400TEST_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.
418TEST_F(RtpSenderReceiverTest, VideoSenderSsrcSetToZero) {
tommi6eca7e32015-12-15 04:27:11 -0800419 AddVideoTrack(false);
deadbeeffac06552015-11-25 11:26:01 -0800420 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
438TEST_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
454TEST_F(RtpSenderReceiverTest, VideoSenderTrackSetToNull) {
tommi6eca7e32015-12-15 04:27:11 -0800455 AddVideoTrack(false);
deadbeeffac06552015-11-25 11:26:01 -0800456 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
474TEST_F(RtpSenderReceiverTest, AudioSenderSsrcChanged) {
tommi6eca7e32015-12-15 04:27:11 -0800475 AddVideoTrack(false);
deadbeeffac06552015-11-25 11:26:01 -0800476 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
491TEST_F(RtpSenderReceiverTest, VideoSenderSsrcChanged) {
tommi6eca7e32015-12-15 04:27:11 -0800492 AddVideoTrack(false);
deadbeeffac06552015-11-25 11:26:01 -0800493 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
deadbeef70ab1a12015-09-28 16:53:55 -0700514} // namespace webrtc