Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(826)

Side by Side Diff: webrtc/api/rtpsenderreceiver_unittest.cc

Issue 2514883002: Create //webrtc/api:libjingle_peerconnection_api + refactorings. (Closed)
Patch Set: Rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/api/rtpsenderinterface.h ('k') | webrtc/api/sctputils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include <memory>
12 #include <string>
13 #include <utility>
14
15 #include "webrtc/api/audiotrack.h"
16 #include "webrtc/api/fakemediacontroller.h"
17 #include "webrtc/api/localaudiosource.h"
18 #include "webrtc/api/mediastream.h"
19 #include "webrtc/api/remoteaudiosource.h"
20 #include "webrtc/api/rtpreceiver.h"
21 #include "webrtc/api/rtpsender.h"
22 #include "webrtc/api/streamcollection.h"
23 #include "webrtc/api/test/fakevideotracksource.h"
24 #include "webrtc/api/videotrack.h"
25 #include "webrtc/api/videotracksource.h"
26 #include "webrtc/base/gunit.h"
27 #include "webrtc/logging/rtc_event_log/rtc_event_log.h"
28 #include "webrtc/media/base/fakemediaengine.h"
29 #include "webrtc/media/base/mediachannel.h"
30 #include "webrtc/media/engine/fakewebrtccall.h"
31 #include "webrtc/p2p/base/faketransportcontroller.h"
32 #include "webrtc/pc/channelmanager.h"
33 #include "webrtc/test/gmock.h"
34 #include "webrtc/test/gtest.h"
35
36 using ::testing::_;
37 using ::testing::Exactly;
38 using ::testing::InvokeWithoutArgs;
39 using ::testing::Return;
40
41 static const char kStreamLabel1[] = "local_stream_1";
42 static const char kVideoTrackId[] = "video_1";
43 static const char kAudioTrackId[] = "audio_1";
44 static const uint32_t kVideoSsrc = 98;
45 static const uint32_t kVideoSsrc2 = 100;
46 static const uint32_t kAudioSsrc = 99;
47 static const uint32_t kAudioSsrc2 = 101;
48
49 namespace webrtc {
50
51 class RtpSenderReceiverTest : public testing::Test {
52 public:
53 RtpSenderReceiverTest()
54 : // Create fake media engine/etc. so we can create channels to use to
55 // test RtpSenders/RtpReceivers.
56 media_engine_(new cricket::FakeMediaEngine()),
57 channel_manager_(media_engine_,
58 rtc::Thread::Current(),
59 rtc::Thread::Current()),
60 fake_call_(Call::Config(&event_log_)),
61 fake_media_controller_(&channel_manager_, &fake_call_),
62 stream_(MediaStream::Create(kStreamLabel1)) {
63 // Create channels to be used by the RtpSenders and RtpReceivers.
64 channel_manager_.Init();
65 bool rtcp_mux_required = true;
66 bool srtp_required = true;
67 cricket::DtlsTransportInternal* rtp_transport =
68 fake_transport_controller_.CreateDtlsTransport(
69 cricket::CN_AUDIO, cricket::ICE_CANDIDATE_COMPONENT_RTP);
70 voice_channel_ = channel_manager_.CreateVoiceChannel(
71 &fake_media_controller_, rtp_transport, nullptr, rtc::Thread::Current(),
72 cricket::CN_AUDIO, nullptr, rtcp_mux_required, srtp_required,
73 cricket::AudioOptions());
74 video_channel_ = channel_manager_.CreateVideoChannel(
75 &fake_media_controller_, rtp_transport, nullptr, rtc::Thread::Current(),
76 cricket::CN_VIDEO, nullptr, rtcp_mux_required, srtp_required,
77 cricket::VideoOptions());
78 voice_media_channel_ = media_engine_->GetVoiceChannel(0);
79 video_media_channel_ = media_engine_->GetVideoChannel(0);
80 RTC_CHECK(voice_channel_);
81 RTC_CHECK(video_channel_);
82 RTC_CHECK(voice_media_channel_);
83 RTC_CHECK(video_media_channel_);
84
85 // Create streams for predefined SSRCs. Streams need to exist in order
86 // for the senders and receievers to apply parameters to them.
87 // Normally these would be created by SetLocalDescription and
88 // SetRemoteDescription.
89 voice_media_channel_->AddSendStream(
90 cricket::StreamParams::CreateLegacy(kAudioSsrc));
91 voice_media_channel_->AddRecvStream(
92 cricket::StreamParams::CreateLegacy(kAudioSsrc));
93 voice_media_channel_->AddSendStream(
94 cricket::StreamParams::CreateLegacy(kAudioSsrc2));
95 voice_media_channel_->AddRecvStream(
96 cricket::StreamParams::CreateLegacy(kAudioSsrc2));
97 video_media_channel_->AddSendStream(
98 cricket::StreamParams::CreateLegacy(kVideoSsrc));
99 video_media_channel_->AddRecvStream(
100 cricket::StreamParams::CreateLegacy(kVideoSsrc));
101 video_media_channel_->AddSendStream(
102 cricket::StreamParams::CreateLegacy(kVideoSsrc2));
103 video_media_channel_->AddRecvStream(
104 cricket::StreamParams::CreateLegacy(kVideoSsrc2));
105 }
106
107 void TearDown() override { channel_manager_.Terminate(); }
108
109 void AddVideoTrack() { AddVideoTrack(false); }
110
111 void AddVideoTrack(bool is_screencast) {
112 rtc::scoped_refptr<VideoTrackSourceInterface> source(
113 FakeVideoTrackSource::Create(is_screencast));
114 video_track_ = VideoTrack::Create(kVideoTrackId, source);
115 EXPECT_TRUE(stream_->AddTrack(video_track_));
116 }
117
118 void CreateAudioRtpSender() { CreateAudioRtpSender(nullptr); }
119
120 void CreateAudioRtpSender(rtc::scoped_refptr<LocalAudioSource> source) {
121 audio_track_ = AudioTrack::Create(kAudioTrackId, source);
122 EXPECT_TRUE(stream_->AddTrack(audio_track_));
123 audio_rtp_sender_ =
124 new AudioRtpSender(stream_->GetAudioTracks()[0], stream_->label(),
125 voice_channel_, nullptr);
126 audio_rtp_sender_->SetSsrc(kAudioSsrc);
127 VerifyVoiceChannelInput();
128 }
129
130 void CreateVideoRtpSender() { CreateVideoRtpSender(false); }
131
132 void CreateVideoRtpSender(bool is_screencast) {
133 AddVideoTrack(is_screencast);
134 video_rtp_sender_ = new VideoRtpSender(stream_->GetVideoTracks()[0],
135 stream_->label(), video_channel_);
136 video_rtp_sender_->SetSsrc(kVideoSsrc);
137 VerifyVideoChannelInput();
138 }
139
140 void DestroyAudioRtpSender() {
141 audio_rtp_sender_ = nullptr;
142 VerifyVoiceChannelNoInput();
143 }
144
145 void DestroyVideoRtpSender() {
146 video_rtp_sender_ = nullptr;
147 VerifyVideoChannelNoInput();
148 }
149
150 void CreateAudioRtpReceiver() {
151 audio_track_ = AudioTrack::Create(
152 kAudioTrackId, RemoteAudioSource::Create(kAudioSsrc, NULL));
153 EXPECT_TRUE(stream_->AddTrack(audio_track_));
154 audio_rtp_receiver_ = new AudioRtpReceiver(stream_, kAudioTrackId,
155 kAudioSsrc, voice_channel_);
156 audio_track_ = audio_rtp_receiver_->audio_track();
157 VerifyVoiceChannelOutput();
158 }
159
160 void CreateVideoRtpReceiver() {
161 video_rtp_receiver_ =
162 new VideoRtpReceiver(stream_, kVideoTrackId, rtc::Thread::Current(),
163 kVideoSsrc, video_channel_);
164 video_track_ = video_rtp_receiver_->video_track();
165 VerifyVideoChannelOutput();
166 }
167
168 void DestroyAudioRtpReceiver() {
169 audio_rtp_receiver_ = nullptr;
170 VerifyVoiceChannelNoOutput();
171 }
172
173 void DestroyVideoRtpReceiver() {
174 video_rtp_receiver_ = nullptr;
175 VerifyVideoChannelNoOutput();
176 }
177
178 void VerifyVoiceChannelInput() { VerifyVoiceChannelInput(kAudioSsrc); }
179
180 void VerifyVoiceChannelInput(uint32_t ssrc) {
181 // Verify that the media channel has an audio source, and the stream isn't
182 // muted.
183 EXPECT_TRUE(voice_media_channel_->HasSource(ssrc));
184 EXPECT_FALSE(voice_media_channel_->IsStreamMuted(ssrc));
185 }
186
187 void VerifyVideoChannelInput() { VerifyVideoChannelInput(kVideoSsrc); }
188
189 void VerifyVideoChannelInput(uint32_t ssrc) {
190 // Verify that the media channel has a video source,
191 EXPECT_TRUE(video_media_channel_->HasSource(ssrc));
192 }
193
194 void VerifyVoiceChannelNoInput() { VerifyVoiceChannelNoInput(kAudioSsrc); }
195
196 void VerifyVoiceChannelNoInput(uint32_t ssrc) {
197 // Verify that the media channel's source is reset.
198 EXPECT_FALSE(voice_media_channel_->HasSource(ssrc));
199 }
200
201 void VerifyVideoChannelNoInput() { VerifyVideoChannelNoInput(kVideoSsrc); }
202
203 void VerifyVideoChannelNoInput(uint32_t ssrc) {
204 // Verify that the media channel's source is reset.
205 EXPECT_FALSE(video_media_channel_->HasSource(ssrc));
206 }
207
208 void VerifyVoiceChannelOutput() {
209 // Verify that the volume is initialized to 1.
210 double volume;
211 EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume));
212 EXPECT_EQ(1, volume);
213 }
214
215 void VerifyVideoChannelOutput() {
216 // Verify that the media channel has a sink.
217 EXPECT_TRUE(video_media_channel_->HasSink(kVideoSsrc));
218 }
219
220 void VerifyVoiceChannelNoOutput() {
221 // Verify that the volume is reset to 0.
222 double volume;
223 EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume));
224 EXPECT_EQ(0, volume);
225 }
226
227 void VerifyVideoChannelNoOutput() {
228 // Verify that the media channel's sink is reset.
229 EXPECT_FALSE(video_media_channel_->HasSink(kVideoSsrc));
230 }
231
232 protected:
233 webrtc::RtcEventLogNullImpl event_log_;
234 cricket::FakeMediaEngine* media_engine_;
235 cricket::FakeTransportController fake_transport_controller_;
236 cricket::ChannelManager channel_manager_;
237 cricket::FakeCall fake_call_;
238 cricket::FakeMediaController fake_media_controller_;
239 cricket::VoiceChannel* voice_channel_;
240 cricket::VideoChannel* video_channel_;
241 cricket::FakeVoiceMediaChannel* voice_media_channel_;
242 cricket::FakeVideoMediaChannel* video_media_channel_;
243 rtc::scoped_refptr<AudioRtpSender> audio_rtp_sender_;
244 rtc::scoped_refptr<VideoRtpSender> video_rtp_sender_;
245 rtc::scoped_refptr<AudioRtpReceiver> audio_rtp_receiver_;
246 rtc::scoped_refptr<VideoRtpReceiver> video_rtp_receiver_;
247 rtc::scoped_refptr<MediaStreamInterface> stream_;
248 rtc::scoped_refptr<VideoTrackInterface> video_track_;
249 rtc::scoped_refptr<AudioTrackInterface> audio_track_;
250 };
251
252 // Test that |voice_channel_| is updated when an audio track is associated
253 // and disassociated with an AudioRtpSender.
254 TEST_F(RtpSenderReceiverTest, AddAndDestroyAudioRtpSender) {
255 CreateAudioRtpSender();
256 DestroyAudioRtpSender();
257 }
258
259 // Test that |video_channel_| is updated when a video track is associated and
260 // disassociated with a VideoRtpSender.
261 TEST_F(RtpSenderReceiverTest, AddAndDestroyVideoRtpSender) {
262 CreateVideoRtpSender();
263 DestroyVideoRtpSender();
264 }
265
266 // Test that |voice_channel_| is updated when a remote audio track is
267 // associated and disassociated with an AudioRtpReceiver.
268 TEST_F(RtpSenderReceiverTest, AddAndDestroyAudioRtpReceiver) {
269 CreateAudioRtpReceiver();
270 DestroyAudioRtpReceiver();
271 }
272
273 // Test that |video_channel_| is updated when a remote video track is
274 // associated and disassociated with a VideoRtpReceiver.
275 TEST_F(RtpSenderReceiverTest, AddAndDestroyVideoRtpReceiver) {
276 CreateVideoRtpReceiver();
277 DestroyVideoRtpReceiver();
278 }
279
280 // Test that the AudioRtpSender applies options from the local audio source.
281 TEST_F(RtpSenderReceiverTest, LocalAudioSourceOptionsApplied) {
282 cricket::AudioOptions options;
283 options.echo_cancellation = rtc::Optional<bool>(true);
284 auto source = LocalAudioSource::Create(
285 PeerConnectionFactoryInterface::Options(), &options);
286 CreateAudioRtpSender(source.get());
287
288 EXPECT_EQ(rtc::Optional<bool>(true),
289 voice_media_channel_->options().echo_cancellation);
290
291 DestroyAudioRtpSender();
292 }
293
294 // Test that the stream is muted when the track is disabled, and unmuted when
295 // the track is enabled.
296 TEST_F(RtpSenderReceiverTest, LocalAudioTrackDisable) {
297 CreateAudioRtpSender();
298
299 audio_track_->set_enabled(false);
300 EXPECT_TRUE(voice_media_channel_->IsStreamMuted(kAudioSsrc));
301
302 audio_track_->set_enabled(true);
303 EXPECT_FALSE(voice_media_channel_->IsStreamMuted(kAudioSsrc));
304
305 DestroyAudioRtpSender();
306 }
307
308 // Test that the volume is set to 0 when the track is disabled, and back to
309 // 1 when the track is enabled.
310 TEST_F(RtpSenderReceiverTest, RemoteAudioTrackDisable) {
311 CreateAudioRtpReceiver();
312
313 double volume;
314 EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume));
315 EXPECT_EQ(1, volume);
316
317 audio_track_->set_enabled(false);
318 EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume));
319 EXPECT_EQ(0, volume);
320
321 audio_track_->set_enabled(true);
322 EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume));
323 EXPECT_EQ(1, volume);
324
325 DestroyAudioRtpReceiver();
326 }
327
328 // Currently no action is taken when a remote video track is disabled or
329 // enabled, so there's nothing to test here, other than what is normally
330 // verified in DestroyVideoRtpSender.
331 TEST_F(RtpSenderReceiverTest, LocalVideoTrackDisable) {
332 CreateVideoRtpSender();
333
334 video_track_->set_enabled(false);
335 video_track_->set_enabled(true);
336
337 DestroyVideoRtpSender();
338 }
339
340 // Test that the state of the video track created by the VideoRtpReceiver is
341 // updated when the receiver is destroyed.
342 TEST_F(RtpSenderReceiverTest, RemoteVideoTrackState) {
343 CreateVideoRtpReceiver();
344
345 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track_->state());
346 EXPECT_EQ(webrtc::MediaSourceInterface::kLive,
347 video_track_->GetSource()->state());
348
349 DestroyVideoRtpReceiver();
350
351 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kEnded, video_track_->state());
352 EXPECT_EQ(webrtc::MediaSourceInterface::kEnded,
353 video_track_->GetSource()->state());
354 }
355
356 // Currently no action is taken when a remote video track is disabled or
357 // enabled, so there's nothing to test here, other than what is normally
358 // verified in DestroyVideoRtpReceiver.
359 TEST_F(RtpSenderReceiverTest, RemoteVideoTrackDisable) {
360 CreateVideoRtpReceiver();
361
362 video_track_->set_enabled(false);
363 video_track_->set_enabled(true);
364
365 DestroyVideoRtpReceiver();
366 }
367
368 // Test that the AudioRtpReceiver applies volume changes from the track source
369 // to the media channel.
370 TEST_F(RtpSenderReceiverTest, RemoteAudioTrackSetVolume) {
371 CreateAudioRtpReceiver();
372
373 double volume;
374 audio_track_->GetSource()->SetVolume(0.5);
375 EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume));
376 EXPECT_EQ(0.5, volume);
377
378 // Disable the audio track, this should prevent setting the volume.
379 audio_track_->set_enabled(false);
380 audio_track_->GetSource()->SetVolume(0.8);
381 EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume));
382 EXPECT_EQ(0, volume);
383
384 // When the track is enabled, the previously set volume should take effect.
385 audio_track_->set_enabled(true);
386 EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume));
387 EXPECT_EQ(0.8, volume);
388
389 // Try changing volume one more time.
390 audio_track_->GetSource()->SetVolume(0.9);
391 EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume));
392 EXPECT_EQ(0.9, volume);
393
394 DestroyAudioRtpReceiver();
395 }
396
397 // Test that the media channel isn't enabled for sending if the audio sender
398 // doesn't have both a track and SSRC.
399 TEST_F(RtpSenderReceiverTest, AudioSenderWithoutTrackAndSsrc) {
400 audio_rtp_sender_ = new AudioRtpSender(voice_channel_, nullptr);
401 rtc::scoped_refptr<AudioTrackInterface> track =
402 AudioTrack::Create(kAudioTrackId, nullptr);
403
404 // Track but no SSRC.
405 EXPECT_TRUE(audio_rtp_sender_->SetTrack(track));
406 VerifyVoiceChannelNoInput();
407
408 // SSRC but no track.
409 EXPECT_TRUE(audio_rtp_sender_->SetTrack(nullptr));
410 audio_rtp_sender_->SetSsrc(kAudioSsrc);
411 VerifyVoiceChannelNoInput();
412 }
413
414 // Test that the media channel isn't enabled for sending if the video sender
415 // doesn't have both a track and SSRC.
416 TEST_F(RtpSenderReceiverTest, VideoSenderWithoutTrackAndSsrc) {
417 video_rtp_sender_ = new VideoRtpSender(video_channel_);
418
419 // Track but no SSRC.
420 EXPECT_TRUE(video_rtp_sender_->SetTrack(video_track_));
421 VerifyVideoChannelNoInput();
422
423 // SSRC but no track.
424 EXPECT_TRUE(video_rtp_sender_->SetTrack(nullptr));
425 video_rtp_sender_->SetSsrc(kVideoSsrc);
426 VerifyVideoChannelNoInput();
427 }
428
429 // Test that the media channel is enabled for sending when the audio sender
430 // has a track and SSRC, when the SSRC is set first.
431 TEST_F(RtpSenderReceiverTest, AudioSenderEarlyWarmupSsrcThenTrack) {
432 audio_rtp_sender_ = new AudioRtpSender(voice_channel_, nullptr);
433 rtc::scoped_refptr<AudioTrackInterface> track =
434 AudioTrack::Create(kAudioTrackId, nullptr);
435 audio_rtp_sender_->SetSsrc(kAudioSsrc);
436 audio_rtp_sender_->SetTrack(track);
437 VerifyVoiceChannelInput();
438
439 DestroyAudioRtpSender();
440 }
441
442 // Test that the media channel is enabled for sending when the audio sender
443 // has a track and SSRC, when the SSRC is set last.
444 TEST_F(RtpSenderReceiverTest, AudioSenderEarlyWarmupTrackThenSsrc) {
445 audio_rtp_sender_ = new AudioRtpSender(voice_channel_, nullptr);
446 rtc::scoped_refptr<AudioTrackInterface> track =
447 AudioTrack::Create(kAudioTrackId, nullptr);
448 audio_rtp_sender_->SetTrack(track);
449 audio_rtp_sender_->SetSsrc(kAudioSsrc);
450 VerifyVoiceChannelInput();
451
452 DestroyAudioRtpSender();
453 }
454
455 // Test that the media channel is enabled for sending when the video sender
456 // has a track and SSRC, when the SSRC is set first.
457 TEST_F(RtpSenderReceiverTest, VideoSenderEarlyWarmupSsrcThenTrack) {
458 AddVideoTrack();
459 video_rtp_sender_ = new VideoRtpSender(video_channel_);
460 video_rtp_sender_->SetSsrc(kVideoSsrc);
461 video_rtp_sender_->SetTrack(video_track_);
462 VerifyVideoChannelInput();
463
464 DestroyVideoRtpSender();
465 }
466
467 // Test that the media channel is enabled for sending when the video sender
468 // has a track and SSRC, when the SSRC is set last.
469 TEST_F(RtpSenderReceiverTest, VideoSenderEarlyWarmupTrackThenSsrc) {
470 AddVideoTrack();
471 video_rtp_sender_ = new VideoRtpSender(video_channel_);
472 video_rtp_sender_->SetTrack(video_track_);
473 video_rtp_sender_->SetSsrc(kVideoSsrc);
474 VerifyVideoChannelInput();
475
476 DestroyVideoRtpSender();
477 }
478
479 // Test that the media channel stops sending when the audio sender's SSRC is set
480 // to 0.
481 TEST_F(RtpSenderReceiverTest, AudioSenderSsrcSetToZero) {
482 CreateAudioRtpSender();
483
484 audio_rtp_sender_->SetSsrc(0);
485 VerifyVoiceChannelNoInput();
486 }
487
488 // Test that the media channel stops sending when the video sender's SSRC is set
489 // to 0.
490 TEST_F(RtpSenderReceiverTest, VideoSenderSsrcSetToZero) {
491 CreateAudioRtpSender();
492
493 audio_rtp_sender_->SetSsrc(0);
494 VerifyVideoChannelNoInput();
495 }
496
497 // Test that the media channel stops sending when the audio sender's track is
498 // set to null.
499 TEST_F(RtpSenderReceiverTest, AudioSenderTrackSetToNull) {
500 CreateAudioRtpSender();
501
502 EXPECT_TRUE(audio_rtp_sender_->SetTrack(nullptr));
503 VerifyVoiceChannelNoInput();
504 }
505
506 // Test that the media channel stops sending when the video sender's track is
507 // set to null.
508 TEST_F(RtpSenderReceiverTest, VideoSenderTrackSetToNull) {
509 CreateVideoRtpSender();
510
511 video_rtp_sender_->SetSsrc(0);
512 VerifyVideoChannelNoInput();
513 }
514
515 // Test that when the audio sender's SSRC is changed, the media channel stops
516 // sending with the old SSRC and starts sending with the new one.
517 TEST_F(RtpSenderReceiverTest, AudioSenderSsrcChanged) {
518 CreateAudioRtpSender();
519
520 audio_rtp_sender_->SetSsrc(kAudioSsrc2);
521 VerifyVoiceChannelNoInput(kAudioSsrc);
522 VerifyVoiceChannelInput(kAudioSsrc2);
523
524 audio_rtp_sender_ = nullptr;
525 VerifyVoiceChannelNoInput(kAudioSsrc2);
526 }
527
528 // Test that when the audio sender's SSRC is changed, the media channel stops
529 // sending with the old SSRC and starts sending with the new one.
530 TEST_F(RtpSenderReceiverTest, VideoSenderSsrcChanged) {
531 CreateVideoRtpSender();
532
533 video_rtp_sender_->SetSsrc(kVideoSsrc2);
534 VerifyVideoChannelNoInput(kVideoSsrc);
535 VerifyVideoChannelInput(kVideoSsrc2);
536
537 video_rtp_sender_ = nullptr;
538 VerifyVideoChannelNoInput(kVideoSsrc2);
539 }
540
541 TEST_F(RtpSenderReceiverTest, AudioSenderCanSetParameters) {
542 CreateAudioRtpSender();
543
544 RtpParameters params = audio_rtp_sender_->GetParameters();
545 EXPECT_EQ(1u, params.encodings.size());
546 EXPECT_TRUE(audio_rtp_sender_->SetParameters(params));
547
548 DestroyAudioRtpSender();
549 }
550
551 TEST_F(RtpSenderReceiverTest, SetAudioMaxSendBitrate) {
552 CreateAudioRtpSender();
553
554 EXPECT_EQ(-1, voice_media_channel_->max_bps());
555 webrtc::RtpParameters params = audio_rtp_sender_->GetParameters();
556 EXPECT_EQ(1, params.encodings.size());
557 EXPECT_EQ(-1, params.encodings[0].max_bitrate_bps);
558 params.encodings[0].max_bitrate_bps = 1000;
559 EXPECT_TRUE(audio_rtp_sender_->SetParameters(params));
560
561 // Read back the parameters and verify they have been changed.
562 params = audio_rtp_sender_->GetParameters();
563 EXPECT_EQ(1, params.encodings.size());
564 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
565
566 // Verify that the audio channel received the new parameters.
567 params = voice_media_channel_->GetRtpSendParameters(kAudioSsrc);
568 EXPECT_EQ(1, params.encodings.size());
569 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
570
571 // Verify that the global bitrate limit has not been changed.
572 EXPECT_EQ(-1, voice_media_channel_->max_bps());
573
574 DestroyAudioRtpSender();
575 }
576
577 TEST_F(RtpSenderReceiverTest, VideoSenderCanSetParameters) {
578 CreateVideoRtpSender();
579
580 RtpParameters params = video_rtp_sender_->GetParameters();
581 EXPECT_EQ(1u, params.encodings.size());
582 EXPECT_TRUE(video_rtp_sender_->SetParameters(params));
583
584 DestroyVideoRtpSender();
585 }
586
587 TEST_F(RtpSenderReceiverTest, SetVideoMaxSendBitrate) {
588 CreateVideoRtpSender();
589
590 EXPECT_EQ(-1, video_media_channel_->max_bps());
591 webrtc::RtpParameters params = video_rtp_sender_->GetParameters();
592 EXPECT_EQ(1, params.encodings.size());
593 EXPECT_EQ(-1, params.encodings[0].max_bitrate_bps);
594 params.encodings[0].max_bitrate_bps = 1000;
595 EXPECT_TRUE(video_rtp_sender_->SetParameters(params));
596
597 // Read back the parameters and verify they have been changed.
598 params = video_rtp_sender_->GetParameters();
599 EXPECT_EQ(1, params.encodings.size());
600 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
601
602 // Verify that the video channel received the new parameters.
603 params = video_media_channel_->GetRtpSendParameters(kVideoSsrc);
604 EXPECT_EQ(1, params.encodings.size());
605 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
606
607 // Verify that the global bitrate limit has not been changed.
608 EXPECT_EQ(-1, video_media_channel_->max_bps());
609
610 DestroyVideoRtpSender();
611 }
612
613 TEST_F(RtpSenderReceiverTest, AudioReceiverCanSetParameters) {
614 CreateAudioRtpReceiver();
615
616 RtpParameters params = audio_rtp_receiver_->GetParameters();
617 EXPECT_EQ(1u, params.encodings.size());
618 EXPECT_TRUE(audio_rtp_receiver_->SetParameters(params));
619
620 DestroyAudioRtpReceiver();
621 }
622
623 TEST_F(RtpSenderReceiverTest, VideoReceiverCanSetParameters) {
624 CreateVideoRtpReceiver();
625
626 RtpParameters params = video_rtp_receiver_->GetParameters();
627 EXPECT_EQ(1u, params.encodings.size());
628 EXPECT_TRUE(video_rtp_receiver_->SetParameters(params));
629
630 DestroyVideoRtpReceiver();
631 }
632
633 // Test that makes sure that a video track content hint translates to the proper
634 // value for sources that are not screencast.
635 TEST_F(RtpSenderReceiverTest, PropagatesVideoTrackContentHint) {
636 CreateVideoRtpSender();
637
638 video_track_->set_enabled(true);
639
640 // |video_track_| is not screencast by default.
641 EXPECT_EQ(rtc::Optional<bool>(false),
642 video_media_channel_->options().is_screencast);
643 // No content hint should be set by default.
644 EXPECT_EQ(VideoTrackInterface::ContentHint::kNone,
645 video_track_->content_hint());
646 // Setting detailed should turn a non-screencast source into screencast mode.
647 video_track_->set_content_hint(VideoTrackInterface::ContentHint::kDetailed);
648 EXPECT_EQ(rtc::Optional<bool>(true),
649 video_media_channel_->options().is_screencast);
650 // Removing the content hint should turn the track back into non-screencast
651 // mode.
652 video_track_->set_content_hint(VideoTrackInterface::ContentHint::kNone);
653 EXPECT_EQ(rtc::Optional<bool>(false),
654 video_media_channel_->options().is_screencast);
655 // Setting fluid should remain in non-screencast mode (its default).
656 video_track_->set_content_hint(VideoTrackInterface::ContentHint::kFluid);
657 EXPECT_EQ(rtc::Optional<bool>(false),
658 video_media_channel_->options().is_screencast);
659
660 DestroyVideoRtpSender();
661 }
662
663 // Test that makes sure that a video track content hint translates to the proper
664 // value for screencast sources.
665 TEST_F(RtpSenderReceiverTest,
666 PropagatesVideoTrackContentHintForScreencastSource) {
667 CreateVideoRtpSender(true);
668
669 video_track_->set_enabled(true);
670
671 // |video_track_| with a screencast source should be screencast by default.
672 EXPECT_EQ(rtc::Optional<bool>(true),
673 video_media_channel_->options().is_screencast);
674 // No content hint should be set by default.
675 EXPECT_EQ(VideoTrackInterface::ContentHint::kNone,
676 video_track_->content_hint());
677 // Setting fluid should turn a screencast source into non-screencast mode.
678 video_track_->set_content_hint(VideoTrackInterface::ContentHint::kFluid);
679 EXPECT_EQ(rtc::Optional<bool>(false),
680 video_media_channel_->options().is_screencast);
681 // Removing the content hint should turn the track back into screencast mode.
682 video_track_->set_content_hint(VideoTrackInterface::ContentHint::kNone);
683 EXPECT_EQ(rtc::Optional<bool>(true),
684 video_media_channel_->options().is_screencast);
685 // Setting detailed should still remain in screencast mode (its default).
686 video_track_->set_content_hint(VideoTrackInterface::ContentHint::kDetailed);
687 EXPECT_EQ(rtc::Optional<bool>(true),
688 video_media_channel_->options().is_screencast);
689
690 DestroyVideoRtpSender();
691 }
692
693 // Test that makes sure any content hints that are set on a track before
694 // VideoRtpSender is ready to send are still applied when it gets ready to send.
695 TEST_F(RtpSenderReceiverTest,
696 PropagatesVideoTrackContentHintSetBeforeEnabling) {
697 AddVideoTrack();
698 // Setting detailed overrides the default non-screencast mode. This should be
699 // applied even if the track is set on construction.
700 video_track_->set_content_hint(VideoTrackInterface::ContentHint::kDetailed);
701 video_rtp_sender_ = new VideoRtpSender(stream_->GetVideoTracks()[0],
702 stream_->label(), video_channel_);
703 video_track_->set_enabled(true);
704
705 // Sender is not ready to send (no SSRC) so no option should have been set.
706 EXPECT_EQ(rtc::Optional<bool>(),
707 video_media_channel_->options().is_screencast);
708
709 // Verify that the content hint is accounted for when video_rtp_sender_ does
710 // get enabled.
711 video_rtp_sender_->SetSsrc(kVideoSsrc);
712 EXPECT_EQ(rtc::Optional<bool>(true),
713 video_media_channel_->options().is_screencast);
714
715 // And removing the hint should go back to false (to verify that false was
716 // default correctly).
717 video_track_->set_content_hint(VideoTrackInterface::ContentHint::kNone);
718 EXPECT_EQ(rtc::Optional<bool>(false),
719 video_media_channel_->options().is_screencast);
720
721 DestroyVideoRtpSender();
722 }
723
724 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/api/rtpsenderinterface.h ('k') | webrtc/api/sctputils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698