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