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

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

Issue 2514883002: Create //webrtc/api:libjingle_peerconnection_api + refactorings. (Closed)
Patch Set: Rebase Created 4 years 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
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_enabled = false;
66 bool srtp_required = true;
67 voice_channel_ = channel_manager_.CreateVoiceChannel(
68 &fake_media_controller_, &fake_transport_controller_, cricket::CN_AUDIO,
69 nullptr, rtcp_enabled, srtp_required, cricket::AudioOptions());
70 video_channel_ = channel_manager_.CreateVideoChannel(
71 &fake_media_controller_, &fake_transport_controller_, cricket::CN_VIDEO,
72 nullptr, rtcp_enabled, srtp_required, cricket::VideoOptions());
73 voice_media_channel_ = media_engine_->GetVoiceChannel(0);
74 video_media_channel_ = media_engine_->GetVideoChannel(0);
75 RTC_CHECK(voice_channel_);
76 RTC_CHECK(video_channel_);
77 RTC_CHECK(voice_media_channel_);
78 RTC_CHECK(video_media_channel_);
79
80 // Create streams for predefined SSRCs. Streams need to exist in order
81 // for the senders and receievers to apply parameters to them.
82 // Normally these would be created by SetLocalDescription and
83 // SetRemoteDescription.
84 voice_media_channel_->AddSendStream(
85 cricket::StreamParams::CreateLegacy(kAudioSsrc));
86 voice_media_channel_->AddRecvStream(
87 cricket::StreamParams::CreateLegacy(kAudioSsrc));
88 voice_media_channel_->AddSendStream(
89 cricket::StreamParams::CreateLegacy(kAudioSsrc2));
90 voice_media_channel_->AddRecvStream(
91 cricket::StreamParams::CreateLegacy(kAudioSsrc2));
92 video_media_channel_->AddSendStream(
93 cricket::StreamParams::CreateLegacy(kVideoSsrc));
94 video_media_channel_->AddRecvStream(
95 cricket::StreamParams::CreateLegacy(kVideoSsrc));
96 video_media_channel_->AddSendStream(
97 cricket::StreamParams::CreateLegacy(kVideoSsrc2));
98 video_media_channel_->AddRecvStream(
99 cricket::StreamParams::CreateLegacy(kVideoSsrc2));
100 }
101
102 void TearDown() override { channel_manager_.Terminate(); }
103
104 void AddVideoTrack() {
105 rtc::scoped_refptr<VideoTrackSourceInterface> source(
106 FakeVideoTrackSource::Create());
107 video_track_ = VideoTrack::Create(kVideoTrackId, source);
108 EXPECT_TRUE(stream_->AddTrack(video_track_));
109 }
110
111 void CreateAudioRtpSender() { CreateAudioRtpSender(nullptr); }
112
113 void CreateAudioRtpSender(rtc::scoped_refptr<LocalAudioSource> source) {
114 audio_track_ = AudioTrack::Create(kAudioTrackId, source);
115 EXPECT_TRUE(stream_->AddTrack(audio_track_));
116 audio_rtp_sender_ =
117 new AudioRtpSender(stream_->GetAudioTracks()[0], stream_->label(),
118 voice_channel_, nullptr);
119 audio_rtp_sender_->SetSsrc(kAudioSsrc);
120 VerifyVoiceChannelInput();
121 }
122
123 void CreateVideoRtpSender() {
124 AddVideoTrack();
125 video_rtp_sender_ = new VideoRtpSender(stream_->GetVideoTracks()[0],
126 stream_->label(), video_channel_);
127 video_rtp_sender_->SetSsrc(kVideoSsrc);
128 VerifyVideoChannelInput();
129 }
130
131 void DestroyAudioRtpSender() {
132 audio_rtp_sender_ = nullptr;
133 VerifyVoiceChannelNoInput();
134 }
135
136 void DestroyVideoRtpSender() {
137 video_rtp_sender_ = nullptr;
138 VerifyVideoChannelNoInput();
139 }
140
141 void CreateAudioRtpReceiver() {
142 audio_track_ = AudioTrack::Create(
143 kAudioTrackId, RemoteAudioSource::Create(kAudioSsrc, NULL));
144 EXPECT_TRUE(stream_->AddTrack(audio_track_));
145 audio_rtp_receiver_ = new AudioRtpReceiver(stream_, kAudioTrackId,
146 kAudioSsrc, voice_channel_);
147 audio_track_ = audio_rtp_receiver_->audio_track();
148 VerifyVoiceChannelOutput();
149 }
150
151 void CreateVideoRtpReceiver() {
152 video_rtp_receiver_ =
153 new VideoRtpReceiver(stream_, kVideoTrackId, rtc::Thread::Current(),
154 kVideoSsrc, video_channel_);
155 video_track_ = video_rtp_receiver_->video_track();
156 VerifyVideoChannelOutput();
157 }
158
159 void DestroyAudioRtpReceiver() {
160 audio_rtp_receiver_ = nullptr;
161 VerifyVoiceChannelNoOutput();
162 }
163
164 void DestroyVideoRtpReceiver() {
165 video_rtp_receiver_ = nullptr;
166 VerifyVideoChannelNoOutput();
167 }
168
169 void VerifyVoiceChannelInput() { VerifyVoiceChannelInput(kAudioSsrc); }
170
171 void VerifyVoiceChannelInput(uint32_t ssrc) {
172 // Verify that the media channel has an audio source, and the stream isn't
173 // muted.
174 EXPECT_TRUE(voice_media_channel_->HasSource(ssrc));
175 EXPECT_FALSE(voice_media_channel_->IsStreamMuted(ssrc));
176 }
177
178 void VerifyVideoChannelInput() { VerifyVideoChannelInput(kVideoSsrc); }
179
180 void VerifyVideoChannelInput(uint32_t ssrc) {
181 // Verify that the media channel has a video source,
182 EXPECT_TRUE(video_media_channel_->HasSource(ssrc));
183 }
184
185 void VerifyVoiceChannelNoInput() { VerifyVoiceChannelNoInput(kAudioSsrc); }
186
187 void VerifyVoiceChannelNoInput(uint32_t ssrc) {
188 // Verify that the media channel's source is reset.
189 EXPECT_FALSE(voice_media_channel_->HasSource(ssrc));
190 }
191
192 void VerifyVideoChannelNoInput() { VerifyVideoChannelNoInput(kVideoSsrc); }
193
194 void VerifyVideoChannelNoInput(uint32_t ssrc) {
195 // Verify that the media channel's source is reset.
196 EXPECT_FALSE(video_media_channel_->HasSource(ssrc));
197 }
198
199 void VerifyVoiceChannelOutput() {
200 // Verify that the volume is initialized to 1.
201 double volume;
202 EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume));
203 EXPECT_EQ(1, volume);
204 }
205
206 void VerifyVideoChannelOutput() {
207 // Verify that the media channel has a sink.
208 EXPECT_TRUE(video_media_channel_->HasSink(kVideoSsrc));
209 }
210
211 void VerifyVoiceChannelNoOutput() {
212 // Verify that the volume is reset to 0.
213 double volume;
214 EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume));
215 EXPECT_EQ(0, volume);
216 }
217
218 void VerifyVideoChannelNoOutput() {
219 // Verify that the media channel's sink is reset.
220 EXPECT_FALSE(video_media_channel_->HasSink(kVideoSsrc));
221 }
222
223 protected:
224 webrtc::RtcEventLogNullImpl event_log_;
225 cricket::FakeMediaEngine* media_engine_;
226 cricket::FakeTransportController fake_transport_controller_;
227 cricket::ChannelManager channel_manager_;
228 cricket::FakeCall fake_call_;
229 cricket::FakeMediaController fake_media_controller_;
230 cricket::VoiceChannel* voice_channel_;
231 cricket::VideoChannel* video_channel_;
232 cricket::FakeVoiceMediaChannel* voice_media_channel_;
233 cricket::FakeVideoMediaChannel* video_media_channel_;
234 rtc::scoped_refptr<AudioRtpSender> audio_rtp_sender_;
235 rtc::scoped_refptr<VideoRtpSender> video_rtp_sender_;
236 rtc::scoped_refptr<AudioRtpReceiver> audio_rtp_receiver_;
237 rtc::scoped_refptr<VideoRtpReceiver> video_rtp_receiver_;
238 rtc::scoped_refptr<MediaStreamInterface> stream_;
239 rtc::scoped_refptr<VideoTrackInterface> video_track_;
240 rtc::scoped_refptr<AudioTrackInterface> audio_track_;
241 };
242
243 // Test that |voice_channel_| is updated when an audio track is associated
244 // and disassociated with an AudioRtpSender.
245 TEST_F(RtpSenderReceiverTest, AddAndDestroyAudioRtpSender) {
246 CreateAudioRtpSender();
247 DestroyAudioRtpSender();
248 }
249
250 // Test that |video_channel_| is updated when a video track is associated and
251 // disassociated with a VideoRtpSender.
252 TEST_F(RtpSenderReceiverTest, AddAndDestroyVideoRtpSender) {
253 CreateVideoRtpSender();
254 DestroyVideoRtpSender();
255 }
256
257 // Test that |voice_channel_| is updated when a remote audio track is
258 // associated and disassociated with an AudioRtpReceiver.
259 TEST_F(RtpSenderReceiverTest, AddAndDestroyAudioRtpReceiver) {
260 CreateAudioRtpReceiver();
261 DestroyAudioRtpReceiver();
262 }
263
264 // Test that |video_channel_| is updated when a remote video track is
265 // associated and disassociated with a VideoRtpReceiver.
266 TEST_F(RtpSenderReceiverTest, AddAndDestroyVideoRtpReceiver) {
267 CreateVideoRtpReceiver();
268 DestroyVideoRtpReceiver();
269 }
270
271 // Test that the AudioRtpSender applies options from the local audio source.
272 TEST_F(RtpSenderReceiverTest, LocalAudioSourceOptionsApplied) {
273 cricket::AudioOptions options;
274 options.echo_cancellation = rtc::Optional<bool>(true);
275 auto source = LocalAudioSource::Create(
276 PeerConnectionFactoryInterface::Options(), &options);
277 CreateAudioRtpSender(source.get());
278
279 EXPECT_EQ(rtc::Optional<bool>(true),
280 voice_media_channel_->options().echo_cancellation);
281
282 DestroyAudioRtpSender();
283 }
284
285 // Test that the stream is muted when the track is disabled, and unmuted when
286 // the track is enabled.
287 TEST_F(RtpSenderReceiverTest, LocalAudioTrackDisable) {
288 CreateAudioRtpSender();
289
290 audio_track_->set_enabled(false);
291 EXPECT_TRUE(voice_media_channel_->IsStreamMuted(kAudioSsrc));
292
293 audio_track_->set_enabled(true);
294 EXPECT_FALSE(voice_media_channel_->IsStreamMuted(kAudioSsrc));
295
296 DestroyAudioRtpSender();
297 }
298
299 // Test that the volume is set to 0 when the track is disabled, and back to
300 // 1 when the track is enabled.
301 TEST_F(RtpSenderReceiverTest, RemoteAudioTrackDisable) {
302 CreateAudioRtpReceiver();
303
304 double volume;
305 EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume));
306 EXPECT_EQ(1, volume);
307
308 audio_track_->set_enabled(false);
309 EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume));
310 EXPECT_EQ(0, volume);
311
312 audio_track_->set_enabled(true);
313 EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume));
314 EXPECT_EQ(1, volume);
315
316 DestroyAudioRtpReceiver();
317 }
318
319 // Currently no action is taken when a remote video track is disabled or
320 // enabled, so there's nothing to test here, other than what is normally
321 // verified in DestroyVideoRtpSender.
322 TEST_F(RtpSenderReceiverTest, LocalVideoTrackDisable) {
323 CreateVideoRtpSender();
324
325 video_track_->set_enabled(false);
326 video_track_->set_enabled(true);
327
328 DestroyVideoRtpSender();
329 }
330
331 // Test that the state of the video track created by the VideoRtpReceiver is
332 // updated when the receiver is destroyed.
333 TEST_F(RtpSenderReceiverTest, RemoteVideoTrackState) {
334 CreateVideoRtpReceiver();
335
336 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track_->state());
337 EXPECT_EQ(webrtc::MediaSourceInterface::kLive,
338 video_track_->GetSource()->state());
339
340 DestroyVideoRtpReceiver();
341
342 EXPECT_EQ(webrtc::MediaStreamTrackInterface::kEnded, video_track_->state());
343 EXPECT_EQ(webrtc::MediaSourceInterface::kEnded,
344 video_track_->GetSource()->state());
345 }
346
347 // Currently no action is taken when a remote video track is disabled or
348 // enabled, so there's nothing to test here, other than what is normally
349 // verified in DestroyVideoRtpReceiver.
350 TEST_F(RtpSenderReceiverTest, RemoteVideoTrackDisable) {
351 CreateVideoRtpReceiver();
352
353 video_track_->set_enabled(false);
354 video_track_->set_enabled(true);
355
356 DestroyVideoRtpReceiver();
357 }
358
359 // Test that the AudioRtpReceiver applies volume changes from the track source
360 // to the media channel.
361 TEST_F(RtpSenderReceiverTest, RemoteAudioTrackSetVolume) {
362 CreateAudioRtpReceiver();
363
364 double volume;
365 audio_track_->GetSource()->SetVolume(0.5);
366 EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume));
367 EXPECT_EQ(0.5, volume);
368
369 // Disable the audio track, this should prevent setting the volume.
370 audio_track_->set_enabled(false);
371 audio_track_->GetSource()->SetVolume(0.8);
372 EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume));
373 EXPECT_EQ(0, volume);
374
375 // When the track is enabled, the previously set volume should take effect.
376 audio_track_->set_enabled(true);
377 EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume));
378 EXPECT_EQ(0.8, volume);
379
380 // Try changing volume one more time.
381 audio_track_->GetSource()->SetVolume(0.9);
382 EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume));
383 EXPECT_EQ(0.9, volume);
384
385 DestroyAudioRtpReceiver();
386 }
387
388 // Test that the media channel isn't enabled for sending if the audio sender
389 // doesn't have both a track and SSRC.
390 TEST_F(RtpSenderReceiverTest, AudioSenderWithoutTrackAndSsrc) {
391 audio_rtp_sender_ = new AudioRtpSender(voice_channel_, nullptr);
392 rtc::scoped_refptr<AudioTrackInterface> track =
393 AudioTrack::Create(kAudioTrackId, nullptr);
394
395 // Track but no SSRC.
396 EXPECT_TRUE(audio_rtp_sender_->SetTrack(track));
397 VerifyVoiceChannelNoInput();
398
399 // SSRC but no track.
400 EXPECT_TRUE(audio_rtp_sender_->SetTrack(nullptr));
401 audio_rtp_sender_->SetSsrc(kAudioSsrc);
402 VerifyVoiceChannelNoInput();
403 }
404
405 // Test that the media channel isn't enabled for sending if the video sender
406 // doesn't have both a track and SSRC.
407 TEST_F(RtpSenderReceiverTest, VideoSenderWithoutTrackAndSsrc) {
408 video_rtp_sender_ = new VideoRtpSender(video_channel_);
409
410 // Track but no SSRC.
411 EXPECT_TRUE(video_rtp_sender_->SetTrack(video_track_));
412 VerifyVideoChannelNoInput();
413
414 // SSRC but no track.
415 EXPECT_TRUE(video_rtp_sender_->SetTrack(nullptr));
416 video_rtp_sender_->SetSsrc(kVideoSsrc);
417 VerifyVideoChannelNoInput();
418 }
419
420 // Test that the media channel is enabled for sending when the audio sender
421 // has a track and SSRC, when the SSRC is set first.
422 TEST_F(RtpSenderReceiverTest, AudioSenderEarlyWarmupSsrcThenTrack) {
423 audio_rtp_sender_ = new AudioRtpSender(voice_channel_, nullptr);
424 rtc::scoped_refptr<AudioTrackInterface> track =
425 AudioTrack::Create(kAudioTrackId, nullptr);
426 audio_rtp_sender_->SetSsrc(kAudioSsrc);
427 audio_rtp_sender_->SetTrack(track);
428 VerifyVoiceChannelInput();
429
430 DestroyAudioRtpSender();
431 }
432
433 // Test that the media channel is enabled for sending when the audio sender
434 // has a track and SSRC, when the SSRC is set last.
435 TEST_F(RtpSenderReceiverTest, AudioSenderEarlyWarmupTrackThenSsrc) {
436 audio_rtp_sender_ = new AudioRtpSender(voice_channel_, nullptr);
437 rtc::scoped_refptr<AudioTrackInterface> track =
438 AudioTrack::Create(kAudioTrackId, nullptr);
439 audio_rtp_sender_->SetTrack(track);
440 audio_rtp_sender_->SetSsrc(kAudioSsrc);
441 VerifyVoiceChannelInput();
442
443 DestroyAudioRtpSender();
444 }
445
446 // Test that the media channel is enabled for sending when the video sender
447 // has a track and SSRC, when the SSRC is set first.
448 TEST_F(RtpSenderReceiverTest, VideoSenderEarlyWarmupSsrcThenTrack) {
449 AddVideoTrack();
450 video_rtp_sender_ = new VideoRtpSender(video_channel_);
451 video_rtp_sender_->SetSsrc(kVideoSsrc);
452 video_rtp_sender_->SetTrack(video_track_);
453 VerifyVideoChannelInput();
454
455 DestroyVideoRtpSender();
456 }
457
458 // Test that the media channel is enabled for sending when the video sender
459 // has a track and SSRC, when the SSRC is set last.
460 TEST_F(RtpSenderReceiverTest, VideoSenderEarlyWarmupTrackThenSsrc) {
461 AddVideoTrack();
462 video_rtp_sender_ = new VideoRtpSender(video_channel_);
463 video_rtp_sender_->SetTrack(video_track_);
464 video_rtp_sender_->SetSsrc(kVideoSsrc);
465 VerifyVideoChannelInput();
466
467 DestroyVideoRtpSender();
468 }
469
470 // Test that the media channel stops sending when the audio sender's SSRC is set
471 // to 0.
472 TEST_F(RtpSenderReceiverTest, AudioSenderSsrcSetToZero) {
473 CreateAudioRtpSender();
474
475 audio_rtp_sender_->SetSsrc(0);
476 VerifyVoiceChannelNoInput();
477 }
478
479 // Test that the media channel stops sending when the video sender's SSRC is set
480 // to 0.
481 TEST_F(RtpSenderReceiverTest, VideoSenderSsrcSetToZero) {
482 CreateAudioRtpSender();
483
484 audio_rtp_sender_->SetSsrc(0);
485 VerifyVideoChannelNoInput();
486 }
487
488 // Test that the media channel stops sending when the audio sender's track is
489 // set to null.
490 TEST_F(RtpSenderReceiverTest, AudioSenderTrackSetToNull) {
491 CreateAudioRtpSender();
492
493 EXPECT_TRUE(audio_rtp_sender_->SetTrack(nullptr));
494 VerifyVoiceChannelNoInput();
495 }
496
497 // Test that the media channel stops sending when the video sender's track is
498 // set to null.
499 TEST_F(RtpSenderReceiverTest, VideoSenderTrackSetToNull) {
500 CreateVideoRtpSender();
501
502 video_rtp_sender_->SetSsrc(0);
503 VerifyVideoChannelNoInput();
504 }
505
506 // Test that when the audio sender's SSRC is changed, the media channel stops
507 // sending with the old SSRC and starts sending with the new one.
508 TEST_F(RtpSenderReceiverTest, AudioSenderSsrcChanged) {
509 CreateAudioRtpSender();
510
511 audio_rtp_sender_->SetSsrc(kAudioSsrc2);
512 VerifyVoiceChannelNoInput(kAudioSsrc);
513 VerifyVoiceChannelInput(kAudioSsrc2);
514
515 audio_rtp_sender_ = nullptr;
516 VerifyVoiceChannelNoInput(kAudioSsrc2);
517 }
518
519 // Test that when the audio sender's SSRC is changed, the media channel stops
520 // sending with the old SSRC and starts sending with the new one.
521 TEST_F(RtpSenderReceiverTest, VideoSenderSsrcChanged) {
522 CreateVideoRtpSender();
523
524 video_rtp_sender_->SetSsrc(kVideoSsrc2);
525 VerifyVideoChannelNoInput(kVideoSsrc);
526 VerifyVideoChannelInput(kVideoSsrc2);
527
528 video_rtp_sender_ = nullptr;
529 VerifyVideoChannelNoInput(kVideoSsrc2);
530 }
531
532 TEST_F(RtpSenderReceiverTest, AudioSenderCanSetParameters) {
533 CreateAudioRtpSender();
534
535 RtpParameters params = audio_rtp_sender_->GetParameters();
536 EXPECT_EQ(1u, params.encodings.size());
537 EXPECT_TRUE(audio_rtp_sender_->SetParameters(params));
538
539 DestroyAudioRtpSender();
540 }
541
542 TEST_F(RtpSenderReceiverTest, SetAudioMaxSendBitrate) {
543 CreateAudioRtpSender();
544
545 EXPECT_EQ(-1, voice_media_channel_->max_bps());
546 webrtc::RtpParameters params = audio_rtp_sender_->GetParameters();
547 EXPECT_EQ(1, params.encodings.size());
548 EXPECT_EQ(-1, params.encodings[0].max_bitrate_bps);
549 params.encodings[0].max_bitrate_bps = 1000;
550 EXPECT_TRUE(audio_rtp_sender_->SetParameters(params));
551
552 // Read back the parameters and verify they have been changed.
553 params = audio_rtp_sender_->GetParameters();
554 EXPECT_EQ(1, params.encodings.size());
555 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
556
557 // Verify that the audio channel received the new parameters.
558 params = voice_media_channel_->GetRtpSendParameters(kAudioSsrc);
559 EXPECT_EQ(1, params.encodings.size());
560 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
561
562 // Verify that the global bitrate limit has not been changed.
563 EXPECT_EQ(-1, voice_media_channel_->max_bps());
564
565 DestroyAudioRtpSender();
566 }
567
568 TEST_F(RtpSenderReceiverTest, VideoSenderCanSetParameters) {
569 CreateVideoRtpSender();
570
571 RtpParameters params = video_rtp_sender_->GetParameters();
572 EXPECT_EQ(1u, params.encodings.size());
573 EXPECT_TRUE(video_rtp_sender_->SetParameters(params));
574
575 DestroyVideoRtpSender();
576 }
577
578 TEST_F(RtpSenderReceiverTest, SetVideoMaxSendBitrate) {
579 CreateVideoRtpSender();
580
581 EXPECT_EQ(-1, video_media_channel_->max_bps());
582 webrtc::RtpParameters params = video_rtp_sender_->GetParameters();
583 EXPECT_EQ(1, params.encodings.size());
584 EXPECT_EQ(-1, params.encodings[0].max_bitrate_bps);
585 params.encodings[0].max_bitrate_bps = 1000;
586 EXPECT_TRUE(video_rtp_sender_->SetParameters(params));
587
588 // Read back the parameters and verify they have been changed.
589 params = video_rtp_sender_->GetParameters();
590 EXPECT_EQ(1, params.encodings.size());
591 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
592
593 // Verify that the video channel received the new parameters.
594 params = video_media_channel_->GetRtpSendParameters(kVideoSsrc);
595 EXPECT_EQ(1, params.encodings.size());
596 EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
597
598 // Verify that the global bitrate limit has not been changed.
599 EXPECT_EQ(-1, video_media_channel_->max_bps());
600
601 DestroyVideoRtpSender();
602 }
603
604 TEST_F(RtpSenderReceiverTest, AudioReceiverCanSetParameters) {
605 CreateAudioRtpReceiver();
606
607 RtpParameters params = audio_rtp_receiver_->GetParameters();
608 EXPECT_EQ(1u, params.encodings.size());
609 EXPECT_TRUE(audio_rtp_receiver_->SetParameters(params));
610
611 DestroyAudioRtpReceiver();
612 }
613
614 TEST_F(RtpSenderReceiverTest, VideoReceiverCanSetParameters) {
615 CreateVideoRtpReceiver();
616
617 RtpParameters params = video_rtp_receiver_->GetParameters();
618 EXPECT_EQ(1u, params.encodings.size());
619 EXPECT_TRUE(video_rtp_receiver_->SetParameters(params));
620
621 DestroyVideoRtpReceiver();
622 }
623
624 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698