deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 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. |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
kwiberg | d1fe281 | 2016-04-27 06:47:29 -0700 | [diff] [blame] | 11 | #include <memory> |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 12 | #include <string> |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 13 | #include <utility> |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 14 | |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 15 | #include "api/rtpparameters.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "media/base/fakemediaengine.h" |
Steve Anton | c9e1560 | 2017-11-06 15:40:09 -0800 | [diff] [blame] | 17 | #include "media/base/rtpdataengine.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 18 | #include "media/engine/fakewebrtccall.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "pc/audiotrack.h" |
| 20 | #include "pc/channelmanager.h" |
| 21 | #include "pc/localaudiosource.h" |
| 22 | #include "pc/mediastream.h" |
| 23 | #include "pc/remoteaudiosource.h" |
| 24 | #include "pc/rtpreceiver.h" |
| 25 | #include "pc/rtpsender.h" |
| 26 | #include "pc/streamcollection.h" |
Zhi Huang | b526158 | 2017-09-29 10:51:43 -0700 | [diff] [blame] | 27 | #include "pc/test/faketransportcontroller.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 28 | #include "pc/test/fakevideotracksource.h" |
| 29 | #include "pc/videotrack.h" |
| 30 | #include "pc/videotracksource.h" |
| 31 | #include "rtc_base/gunit.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 32 | #include "test/gmock.h" |
| 33 | #include "test/gtest.h" |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 34 | |
| 35 | using ::testing::_; |
| 36 | using ::testing::Exactly; |
deadbeef | 5dd42fd | 2016-05-02 16:20:01 -0700 | [diff] [blame] | 37 | using ::testing::InvokeWithoutArgs; |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 38 | using ::testing::Return; |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 39 | |
deadbeef | 20cb0c1 | 2017-02-01 20:27:00 -0800 | [diff] [blame] | 40 | namespace { |
| 41 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 42 | static const char kStreamLabel1[] = "local_stream_1"; |
| 43 | static const char kVideoTrackId[] = "video_1"; |
| 44 | static const char kAudioTrackId[] = "audio_1"; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 45 | static const uint32_t kVideoSsrc = 98; |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 46 | static const uint32_t kVideoSsrc2 = 100; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 47 | static const uint32_t kAudioSsrc = 99; |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 48 | static const uint32_t kAudioSsrc2 = 101; |
deadbeef | 20cb0c1 | 2017-02-01 20:27:00 -0800 | [diff] [blame] | 49 | static const int kDefaultTimeout = 10000; // 10 seconds. |
deadbeef | 20cb0c1 | 2017-02-01 20:27:00 -0800 | [diff] [blame] | 50 | } // namespace |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 51 | |
| 52 | namespace webrtc { |
| 53 | |
deadbeef | 20cb0c1 | 2017-02-01 20:27:00 -0800 | [diff] [blame] | 54 | class RtpSenderReceiverTest : public testing::Test, |
| 55 | public sigslot::has_slots<> { |
tkchin | 3784b4a | 2016-06-24 19:31:47 -0700 | [diff] [blame] | 56 | public: |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 57 | RtpSenderReceiverTest() |
| 58 | : // Create fake media engine/etc. so we can create channels to use to |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 59 | // test RtpSenders/RtpReceivers. |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 60 | media_engine_(new cricket::FakeMediaEngine()), |
Steve Anton | c9e1560 | 2017-11-06 15:40:09 -0800 | [diff] [blame] | 61 | channel_manager_(rtc::WrapUnique(media_engine_), |
| 62 | rtc::MakeUnique<cricket::RtpDataEngine>(), |
| 63 | rtc::Thread::Current(), |
| 64 | rtc::Thread::Current()), |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 65 | fake_call_(Call::Config(&event_log_)), |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 66 | local_stream_(MediaStream::Create(kStreamLabel1)) { |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 67 | // Create channels to be used by the RtpSenders and RtpReceivers. |
| 68 | channel_manager_.Init(); |
deadbeef | 7af91dd | 2016-12-13 11:29:11 -0800 | [diff] [blame] | 69 | bool srtp_required = true; |
zhihuang | b2cdd93 | 2017-01-19 16:54:25 -0800 | [diff] [blame] | 70 | cricket::DtlsTransportInternal* rtp_transport = |
| 71 | fake_transport_controller_.CreateDtlsTransport( |
zhihuang | f5b251b | 2017-01-12 19:37:48 -0800 | [diff] [blame] | 72 | cricket::CN_AUDIO, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 73 | voice_channel_ = channel_manager_.CreateVoiceChannel( |
nisse | eaabdf6 | 2017-05-05 02:23:02 -0700 | [diff] [blame] | 74 | &fake_call_, cricket::MediaConfig(), |
| 75 | rtp_transport, nullptr, rtc::Thread::Current(), |
deadbeef | 1a2183d | 2017-02-10 23:44:49 -0800 | [diff] [blame] | 76 | cricket::CN_AUDIO, srtp_required, cricket::AudioOptions()); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 77 | video_channel_ = channel_manager_.CreateVideoChannel( |
nisse | eaabdf6 | 2017-05-05 02:23:02 -0700 | [diff] [blame] | 78 | &fake_call_, cricket::MediaConfig(), |
| 79 | rtp_transport, nullptr, rtc::Thread::Current(), |
deadbeef | 1a2183d | 2017-02-10 23:44:49 -0800 | [diff] [blame] | 80 | cricket::CN_VIDEO, srtp_required, cricket::VideoOptions()); |
deadbeef | 20cb0c1 | 2017-02-01 20:27:00 -0800 | [diff] [blame] | 81 | voice_channel_->Enable(true); |
| 82 | video_channel_->Enable(true); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 83 | voice_media_channel_ = media_engine_->GetVoiceChannel(0); |
| 84 | video_media_channel_ = media_engine_->GetVideoChannel(0); |
| 85 | RTC_CHECK(voice_channel_); |
| 86 | RTC_CHECK(video_channel_); |
| 87 | RTC_CHECK(voice_media_channel_); |
| 88 | RTC_CHECK(video_media_channel_); |
| 89 | |
| 90 | // Create streams for predefined SSRCs. Streams need to exist in order |
| 91 | // for the senders and receievers to apply parameters to them. |
| 92 | // Normally these would be created by SetLocalDescription and |
| 93 | // SetRemoteDescription. |
| 94 | voice_media_channel_->AddSendStream( |
| 95 | cricket::StreamParams::CreateLegacy(kAudioSsrc)); |
| 96 | voice_media_channel_->AddRecvStream( |
| 97 | cricket::StreamParams::CreateLegacy(kAudioSsrc)); |
| 98 | voice_media_channel_->AddSendStream( |
| 99 | cricket::StreamParams::CreateLegacy(kAudioSsrc2)); |
| 100 | voice_media_channel_->AddRecvStream( |
| 101 | cricket::StreamParams::CreateLegacy(kAudioSsrc2)); |
| 102 | video_media_channel_->AddSendStream( |
| 103 | cricket::StreamParams::CreateLegacy(kVideoSsrc)); |
| 104 | video_media_channel_->AddRecvStream( |
| 105 | cricket::StreamParams::CreateLegacy(kVideoSsrc)); |
| 106 | video_media_channel_->AddSendStream( |
| 107 | cricket::StreamParams::CreateLegacy(kVideoSsrc2)); |
| 108 | video_media_channel_->AddRecvStream( |
| 109 | cricket::StreamParams::CreateLegacy(kVideoSsrc2)); |
tkchin | 3784b4a | 2016-06-24 19:31:47 -0700 | [diff] [blame] | 110 | } |
Taylor Brandstetter | 2d54917 | 2016-06-24 14:18:22 -0700 | [diff] [blame] | 111 | |
deadbeef | 20cb0c1 | 2017-02-01 20:27:00 -0800 | [diff] [blame] | 112 | // Needed to use DTMF sender. |
| 113 | void AddDtmfCodec() { |
| 114 | cricket::AudioSendParameters params; |
| 115 | const cricket::AudioCodec kTelephoneEventCodec(106, "telephone-event", 8000, |
| 116 | 0, 1); |
| 117 | params.codecs.push_back(kTelephoneEventCodec); |
| 118 | voice_media_channel_->SetSendParameters(params); |
| 119 | } |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 120 | |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 121 | void AddVideoTrack() { AddVideoTrack(false); } |
| 122 | |
| 123 | void AddVideoTrack(bool is_screencast) { |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 124 | rtc::scoped_refptr<VideoTrackSourceInterface> source( |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 125 | FakeVideoTrackSource::Create(is_screencast)); |
perkj | 773be36 | 2017-07-31 23:22:01 -0700 | [diff] [blame] | 126 | video_track_ = |
| 127 | VideoTrack::Create(kVideoTrackId, source, rtc::Thread::Current()); |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 128 | EXPECT_TRUE(local_stream_->AddTrack(video_track_)); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 131 | void CreateAudioRtpSender() { CreateAudioRtpSender(nullptr); } |
| 132 | |
Mirko Bonadei | c61ce0d | 2017-11-21 17:04:20 +0100 | [diff] [blame] | 133 | void CreateAudioRtpSender( |
| 134 | const rtc::scoped_refptr<LocalAudioSource>& source) { |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 135 | audio_track_ = AudioTrack::Create(kAudioTrackId, source); |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 136 | EXPECT_TRUE(local_stream_->AddTrack(audio_track_)); |
Steve Anton | 02ee47c | 2018-01-10 16:26:06 -0800 | [diff] [blame^] | 137 | audio_rtp_sender_ = new AudioRtpSender(local_stream_->GetAudioTracks()[0], |
| 138 | {local_stream_->label()}, nullptr); |
| 139 | audio_rtp_sender_->SetChannel(voice_channel_); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 140 | audio_rtp_sender_->SetSsrc(kAudioSsrc); |
deadbeef | 20cb0c1 | 2017-02-01 20:27:00 -0800 | [diff] [blame] | 141 | audio_rtp_sender_->GetOnDestroyedSignal()->connect( |
| 142 | this, &RtpSenderReceiverTest::OnAudioSenderDestroyed); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 143 | VerifyVoiceChannelInput(); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 144 | } |
| 145 | |
Steve Anton | 02ee47c | 2018-01-10 16:26:06 -0800 | [diff] [blame^] | 146 | void CreateAudioRtpSenderWithNoTrack() { |
| 147 | audio_rtp_sender_ = new AudioRtpSender(nullptr); |
| 148 | audio_rtp_sender_->SetChannel(voice_channel_); |
| 149 | } |
| 150 | |
deadbeef | 20cb0c1 | 2017-02-01 20:27:00 -0800 | [diff] [blame] | 151 | void OnAudioSenderDestroyed() { audio_sender_destroyed_signal_fired_ = true; } |
| 152 | |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 153 | void CreateVideoRtpSender() { CreateVideoRtpSender(false); } |
| 154 | |
| 155 | void CreateVideoRtpSender(bool is_screencast) { |
| 156 | AddVideoTrack(is_screencast); |
Steve Anton | 02ee47c | 2018-01-10 16:26:06 -0800 | [diff] [blame^] | 157 | video_rtp_sender_ = new VideoRtpSender(local_stream_->GetVideoTracks()[0], |
| 158 | {local_stream_->label()}); |
| 159 | video_rtp_sender_->SetChannel(video_channel_); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 160 | video_rtp_sender_->SetSsrc(kVideoSsrc); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 161 | VerifyVideoChannelInput(); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Steve Anton | 02ee47c | 2018-01-10 16:26:06 -0800 | [diff] [blame^] | 164 | void CreateVideoRtpSenderWithNoTrack() { |
| 165 | video_rtp_sender_ = new VideoRtpSender(); |
| 166 | video_rtp_sender_->SetChannel(video_channel_); |
| 167 | } |
| 168 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 169 | void DestroyAudioRtpSender() { |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 170 | audio_rtp_sender_ = nullptr; |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 171 | VerifyVoiceChannelNoInput(); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | void DestroyVideoRtpSender() { |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 175 | video_rtp_sender_ = nullptr; |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 176 | VerifyVideoChannelNoInput(); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Henrik Boström | 9e6fd2b | 2017-11-21 13:41:51 +0100 | [diff] [blame] | 179 | void CreateAudioRtpReceiver( |
| 180 | std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams = {}) { |
| 181 | audio_rtp_receiver_ = new AudioRtpReceiver( |
Steve Anton | 6077675 | 2018-01-10 11:51:34 -0800 | [diff] [blame] | 182 | rtc::Thread::Current(), kAudioTrackId, std::move(streams), kAudioSsrc, |
| 183 | voice_media_channel_); |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 184 | audio_track_ = audio_rtp_receiver_->audio_track(); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 185 | VerifyVoiceChannelOutput(); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Henrik Boström | 9e6fd2b | 2017-11-21 13:41:51 +0100 | [diff] [blame] | 188 | void CreateVideoRtpReceiver( |
| 189 | std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams = {}) { |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 190 | video_rtp_receiver_ = new VideoRtpReceiver( |
Steve Anton | 6077675 | 2018-01-10 11:51:34 -0800 | [diff] [blame] | 191 | rtc::Thread::Current(), kVideoTrackId, std::move(streams), kVideoSsrc, |
| 192 | video_media_channel_); |
perkj | f0dcfe2 | 2016-03-10 18:32:00 +0100 | [diff] [blame] | 193 | video_track_ = video_rtp_receiver_->video_track(); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 194 | VerifyVideoChannelOutput(); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | void DestroyAudioRtpReceiver() { |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 198 | audio_rtp_receiver_ = nullptr; |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 199 | VerifyVoiceChannelNoOutput(); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | void DestroyVideoRtpReceiver() { |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 203 | video_rtp_receiver_ = nullptr; |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 204 | VerifyVideoChannelNoOutput(); |
| 205 | } |
| 206 | |
| 207 | void VerifyVoiceChannelInput() { VerifyVoiceChannelInput(kAudioSsrc); } |
| 208 | |
| 209 | void VerifyVoiceChannelInput(uint32_t ssrc) { |
| 210 | // Verify that the media channel has an audio source, and the stream isn't |
| 211 | // muted. |
| 212 | EXPECT_TRUE(voice_media_channel_->HasSource(ssrc)); |
| 213 | EXPECT_FALSE(voice_media_channel_->IsStreamMuted(ssrc)); |
| 214 | } |
| 215 | |
| 216 | void VerifyVideoChannelInput() { VerifyVideoChannelInput(kVideoSsrc); } |
| 217 | |
| 218 | void VerifyVideoChannelInput(uint32_t ssrc) { |
| 219 | // Verify that the media channel has a video source, |
| 220 | EXPECT_TRUE(video_media_channel_->HasSource(ssrc)); |
| 221 | } |
| 222 | |
| 223 | void VerifyVoiceChannelNoInput() { VerifyVoiceChannelNoInput(kAudioSsrc); } |
| 224 | |
| 225 | void VerifyVoiceChannelNoInput(uint32_t ssrc) { |
| 226 | // Verify that the media channel's source is reset. |
| 227 | EXPECT_FALSE(voice_media_channel_->HasSource(ssrc)); |
| 228 | } |
| 229 | |
| 230 | void VerifyVideoChannelNoInput() { VerifyVideoChannelNoInput(kVideoSsrc); } |
| 231 | |
| 232 | void VerifyVideoChannelNoInput(uint32_t ssrc) { |
| 233 | // Verify that the media channel's source is reset. |
| 234 | EXPECT_FALSE(video_media_channel_->HasSource(ssrc)); |
| 235 | } |
| 236 | |
| 237 | void VerifyVoiceChannelOutput() { |
| 238 | // Verify that the volume is initialized to 1. |
| 239 | double volume; |
| 240 | EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume)); |
| 241 | EXPECT_EQ(1, volume); |
| 242 | } |
| 243 | |
| 244 | void VerifyVideoChannelOutput() { |
| 245 | // Verify that the media channel has a sink. |
| 246 | EXPECT_TRUE(video_media_channel_->HasSink(kVideoSsrc)); |
| 247 | } |
| 248 | |
| 249 | void VerifyVoiceChannelNoOutput() { |
| 250 | // Verify that the volume is reset to 0. |
| 251 | double volume; |
| 252 | EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume)); |
| 253 | EXPECT_EQ(0, volume); |
| 254 | } |
| 255 | |
| 256 | void VerifyVideoChannelNoOutput() { |
| 257 | // Verify that the media channel's sink is reset. |
| 258 | EXPECT_FALSE(video_media_channel_->HasSink(kVideoSsrc)); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | protected: |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 262 | webrtc::RtcEventLogNullImpl event_log_; |
deadbeef | 112b2e9 | 2017-02-10 20:13:37 -0800 | [diff] [blame] | 263 | // |media_engine_| is actually owned by |channel_manager_|. |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 264 | cricket::FakeMediaEngine* media_engine_; |
| 265 | cricket::FakeTransportController fake_transport_controller_; |
| 266 | cricket::ChannelManager channel_manager_; |
| 267 | cricket::FakeCall fake_call_; |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 268 | cricket::VoiceChannel* voice_channel_; |
| 269 | cricket::VideoChannel* video_channel_; |
| 270 | cricket::FakeVoiceMediaChannel* voice_media_channel_; |
| 271 | cricket::FakeVideoMediaChannel* video_media_channel_; |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 272 | rtc::scoped_refptr<AudioRtpSender> audio_rtp_sender_; |
| 273 | rtc::scoped_refptr<VideoRtpSender> video_rtp_sender_; |
| 274 | rtc::scoped_refptr<AudioRtpReceiver> audio_rtp_receiver_; |
| 275 | rtc::scoped_refptr<VideoRtpReceiver> video_rtp_receiver_; |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 276 | rtc::scoped_refptr<MediaStreamInterface> local_stream_; |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 277 | rtc::scoped_refptr<VideoTrackInterface> video_track_; |
| 278 | rtc::scoped_refptr<AudioTrackInterface> audio_track_; |
deadbeef | 20cb0c1 | 2017-02-01 20:27:00 -0800 | [diff] [blame] | 279 | bool audio_sender_destroyed_signal_fired_ = false; |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 280 | }; |
| 281 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 282 | // Test that |voice_channel_| is updated when an audio track is associated |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 283 | // and disassociated with an AudioRtpSender. |
| 284 | TEST_F(RtpSenderReceiverTest, AddAndDestroyAudioRtpSender) { |
| 285 | CreateAudioRtpSender(); |
| 286 | DestroyAudioRtpSender(); |
| 287 | } |
| 288 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 289 | // Test that |video_channel_| is updated when a video track is associated and |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 290 | // disassociated with a VideoRtpSender. |
| 291 | TEST_F(RtpSenderReceiverTest, AddAndDestroyVideoRtpSender) { |
| 292 | CreateVideoRtpSender(); |
| 293 | DestroyVideoRtpSender(); |
| 294 | } |
| 295 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 296 | // Test that |voice_channel_| is updated when a remote audio track is |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 297 | // associated and disassociated with an AudioRtpReceiver. |
| 298 | TEST_F(RtpSenderReceiverTest, AddAndDestroyAudioRtpReceiver) { |
| 299 | CreateAudioRtpReceiver(); |
| 300 | DestroyAudioRtpReceiver(); |
| 301 | } |
| 302 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 303 | // Test that |video_channel_| is updated when a remote video track is |
| 304 | // associated and disassociated with a VideoRtpReceiver. |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 305 | TEST_F(RtpSenderReceiverTest, AddAndDestroyVideoRtpReceiver) { |
| 306 | CreateVideoRtpReceiver(); |
| 307 | DestroyVideoRtpReceiver(); |
| 308 | } |
| 309 | |
Henrik Boström | 9e6fd2b | 2017-11-21 13:41:51 +0100 | [diff] [blame] | 310 | TEST_F(RtpSenderReceiverTest, AddAndDestroyAudioRtpReceiverWithStreams) { |
| 311 | CreateAudioRtpReceiver({local_stream_}); |
| 312 | DestroyAudioRtpReceiver(); |
| 313 | } |
| 314 | |
| 315 | TEST_F(RtpSenderReceiverTest, AddAndDestroyVideoRtpReceiverWithStreams) { |
| 316 | CreateVideoRtpReceiver({local_stream_}); |
| 317 | DestroyVideoRtpReceiver(); |
| 318 | } |
| 319 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 320 | // Test that the AudioRtpSender applies options from the local audio source. |
| 321 | TEST_F(RtpSenderReceiverTest, LocalAudioSourceOptionsApplied) { |
| 322 | cricket::AudioOptions options; |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 323 | options.echo_cancellation = true; |
deadbeef | 757146b | 2017-02-10 21:26:48 -0800 | [diff] [blame] | 324 | auto source = LocalAudioSource::Create(&options); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 325 | CreateAudioRtpSender(source.get()); |
Taylor Brandstetter | 2d54917 | 2016-06-24 14:18:22 -0700 | [diff] [blame] | 326 | |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 327 | EXPECT_EQ(true, voice_media_channel_->options().echo_cancellation); |
Taylor Brandstetter | 2d54917 | 2016-06-24 14:18:22 -0700 | [diff] [blame] | 328 | |
| 329 | DestroyAudioRtpSender(); |
| 330 | } |
| 331 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 332 | // Test that the stream is muted when the track is disabled, and unmuted when |
| 333 | // the track is enabled. |
| 334 | TEST_F(RtpSenderReceiverTest, LocalAudioTrackDisable) { |
| 335 | CreateAudioRtpSender(); |
| 336 | |
| 337 | audio_track_->set_enabled(false); |
| 338 | EXPECT_TRUE(voice_media_channel_->IsStreamMuted(kAudioSsrc)); |
| 339 | |
| 340 | audio_track_->set_enabled(true); |
| 341 | EXPECT_FALSE(voice_media_channel_->IsStreamMuted(kAudioSsrc)); |
| 342 | |
| 343 | DestroyAudioRtpSender(); |
| 344 | } |
| 345 | |
| 346 | // Test that the volume is set to 0 when the track is disabled, and back to |
| 347 | // 1 when the track is enabled. |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 348 | TEST_F(RtpSenderReceiverTest, RemoteAudioTrackDisable) { |
| 349 | CreateAudioRtpReceiver(); |
| 350 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 351 | double volume; |
| 352 | EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume)); |
| 353 | EXPECT_EQ(1, volume); |
Taylor Brandstetter | 2d54917 | 2016-06-24 14:18:22 -0700 | [diff] [blame] | 354 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 355 | audio_track_->set_enabled(false); |
| 356 | EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume)); |
| 357 | EXPECT_EQ(0, volume); |
| 358 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 359 | audio_track_->set_enabled(true); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 360 | EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume)); |
| 361 | EXPECT_EQ(1, volume); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 362 | |
| 363 | DestroyAudioRtpReceiver(); |
| 364 | } |
| 365 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 366 | // Currently no action is taken when a remote video track is disabled or |
| 367 | // enabled, so there's nothing to test here, other than what is normally |
| 368 | // verified in DestroyVideoRtpSender. |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 369 | TEST_F(RtpSenderReceiverTest, LocalVideoTrackDisable) { |
| 370 | CreateVideoRtpSender(); |
| 371 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 372 | video_track_->set_enabled(false); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 373 | video_track_->set_enabled(true); |
| 374 | |
| 375 | DestroyVideoRtpSender(); |
| 376 | } |
| 377 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 378 | // Test that the state of the video track created by the VideoRtpReceiver is |
| 379 | // updated when the receiver is destroyed. |
perkj | f0dcfe2 | 2016-03-10 18:32:00 +0100 | [diff] [blame] | 380 | TEST_F(RtpSenderReceiverTest, RemoteVideoTrackState) { |
| 381 | CreateVideoRtpReceiver(); |
| 382 | |
| 383 | EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track_->state()); |
| 384 | EXPECT_EQ(webrtc::MediaSourceInterface::kLive, |
| 385 | video_track_->GetSource()->state()); |
| 386 | |
| 387 | DestroyVideoRtpReceiver(); |
| 388 | |
| 389 | EXPECT_EQ(webrtc::MediaStreamTrackInterface::kEnded, video_track_->state()); |
| 390 | EXPECT_EQ(webrtc::MediaSourceInterface::kEnded, |
| 391 | video_track_->GetSource()->state()); |
| 392 | } |
| 393 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 394 | // Currently no action is taken when a remote video track is disabled or |
| 395 | // enabled, so there's nothing to test here, other than what is normally |
| 396 | // verified in DestroyVideoRtpReceiver. |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 397 | TEST_F(RtpSenderReceiverTest, RemoteVideoTrackDisable) { |
| 398 | CreateVideoRtpReceiver(); |
| 399 | |
| 400 | video_track_->set_enabled(false); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 401 | video_track_->set_enabled(true); |
| 402 | |
| 403 | DestroyVideoRtpReceiver(); |
| 404 | } |
| 405 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 406 | // Test that the AudioRtpReceiver applies volume changes from the track source |
| 407 | // to the media channel. |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 408 | TEST_F(RtpSenderReceiverTest, RemoteAudioTrackSetVolume) { |
| 409 | CreateAudioRtpReceiver(); |
| 410 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 411 | double volume; |
| 412 | audio_track_->GetSource()->SetVolume(0.5); |
| 413 | EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume)); |
| 414 | EXPECT_EQ(0.5, volume); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 415 | |
| 416 | // Disable the audio track, this should prevent setting the volume. |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 417 | audio_track_->set_enabled(false); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 418 | audio_track_->GetSource()->SetVolume(0.8); |
| 419 | EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume)); |
| 420 | EXPECT_EQ(0, volume); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 421 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 422 | // When the track is enabled, the previously set volume should take effect. |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 423 | audio_track_->set_enabled(true); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 424 | EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume)); |
| 425 | EXPECT_EQ(0.8, volume); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 426 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 427 | // Try changing volume one more time. |
| 428 | audio_track_->GetSource()->SetVolume(0.9); |
| 429 | EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume)); |
| 430 | EXPECT_EQ(0.9, volume); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 431 | |
| 432 | DestroyAudioRtpReceiver(); |
| 433 | } |
| 434 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 435 | // Test that the media channel isn't enabled for sending if the audio sender |
| 436 | // doesn't have both a track and SSRC. |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 437 | TEST_F(RtpSenderReceiverTest, AudioSenderWithoutTrackAndSsrc) { |
Steve Anton | 02ee47c | 2018-01-10 16:26:06 -0800 | [diff] [blame^] | 438 | CreateAudioRtpSenderWithNoTrack(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 439 | rtc::scoped_refptr<AudioTrackInterface> track = |
| 440 | AudioTrack::Create(kAudioTrackId, nullptr); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 441 | |
| 442 | // Track but no SSRC. |
| 443 | EXPECT_TRUE(audio_rtp_sender_->SetTrack(track)); |
| 444 | VerifyVoiceChannelNoInput(); |
| 445 | |
| 446 | // SSRC but no track. |
| 447 | EXPECT_TRUE(audio_rtp_sender_->SetTrack(nullptr)); |
| 448 | audio_rtp_sender_->SetSsrc(kAudioSsrc); |
| 449 | VerifyVoiceChannelNoInput(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 450 | } |
| 451 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 452 | // Test that the media channel isn't enabled for sending if the video sender |
| 453 | // doesn't have both a track and SSRC. |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 454 | TEST_F(RtpSenderReceiverTest, VideoSenderWithoutTrackAndSsrc) { |
Steve Anton | 02ee47c | 2018-01-10 16:26:06 -0800 | [diff] [blame^] | 455 | CreateVideoRtpSenderWithNoTrack(); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 456 | |
| 457 | // Track but no SSRC. |
| 458 | EXPECT_TRUE(video_rtp_sender_->SetTrack(video_track_)); |
| 459 | VerifyVideoChannelNoInput(); |
| 460 | |
| 461 | // SSRC but no track. |
| 462 | EXPECT_TRUE(video_rtp_sender_->SetTrack(nullptr)); |
| 463 | video_rtp_sender_->SetSsrc(kVideoSsrc); |
| 464 | VerifyVideoChannelNoInput(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 465 | } |
| 466 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 467 | // Test that the media channel is enabled for sending when the audio sender |
| 468 | // has a track and SSRC, when the SSRC is set first. |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 469 | TEST_F(RtpSenderReceiverTest, AudioSenderEarlyWarmupSsrcThenTrack) { |
Steve Anton | 02ee47c | 2018-01-10 16:26:06 -0800 | [diff] [blame^] | 470 | CreateAudioRtpSenderWithNoTrack(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 471 | rtc::scoped_refptr<AudioTrackInterface> track = |
| 472 | AudioTrack::Create(kAudioTrackId, nullptr); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 473 | audio_rtp_sender_->SetSsrc(kAudioSsrc); |
| 474 | audio_rtp_sender_->SetTrack(track); |
| 475 | VerifyVoiceChannelInput(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 476 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 477 | DestroyAudioRtpSender(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 478 | } |
| 479 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 480 | // Test that the media channel is enabled for sending when the audio sender |
| 481 | // has a track and SSRC, when the SSRC is set last. |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 482 | TEST_F(RtpSenderReceiverTest, AudioSenderEarlyWarmupTrackThenSsrc) { |
Steve Anton | 02ee47c | 2018-01-10 16:26:06 -0800 | [diff] [blame^] | 483 | CreateAudioRtpSenderWithNoTrack(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 484 | rtc::scoped_refptr<AudioTrackInterface> track = |
| 485 | AudioTrack::Create(kAudioTrackId, nullptr); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 486 | audio_rtp_sender_->SetTrack(track); |
| 487 | audio_rtp_sender_->SetSsrc(kAudioSsrc); |
| 488 | VerifyVoiceChannelInput(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 489 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 490 | DestroyAudioRtpSender(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 491 | } |
| 492 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 493 | // Test that the media channel is enabled for sending when the video sender |
| 494 | // has a track and SSRC, when the SSRC is set first. |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 495 | TEST_F(RtpSenderReceiverTest, VideoSenderEarlyWarmupSsrcThenTrack) { |
nisse | af510af | 2016-03-21 08:20:42 -0700 | [diff] [blame] | 496 | AddVideoTrack(); |
Steve Anton | 02ee47c | 2018-01-10 16:26:06 -0800 | [diff] [blame^] | 497 | CreateVideoRtpSenderWithNoTrack(); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 498 | video_rtp_sender_->SetSsrc(kVideoSsrc); |
| 499 | video_rtp_sender_->SetTrack(video_track_); |
| 500 | VerifyVideoChannelInput(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 501 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 502 | DestroyVideoRtpSender(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 503 | } |
| 504 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 505 | // Test that the media channel is enabled for sending when the video sender |
| 506 | // has a track and SSRC, when the SSRC is set last. |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 507 | TEST_F(RtpSenderReceiverTest, VideoSenderEarlyWarmupTrackThenSsrc) { |
nisse | af510af | 2016-03-21 08:20:42 -0700 | [diff] [blame] | 508 | AddVideoTrack(); |
Steve Anton | 02ee47c | 2018-01-10 16:26:06 -0800 | [diff] [blame^] | 509 | CreateVideoRtpSenderWithNoTrack(); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 510 | video_rtp_sender_->SetTrack(video_track_); |
| 511 | video_rtp_sender_->SetSsrc(kVideoSsrc); |
| 512 | VerifyVideoChannelInput(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 513 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 514 | DestroyVideoRtpSender(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 515 | } |
| 516 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 517 | // Test that the media channel stops sending when the audio sender's SSRC is set |
| 518 | // to 0. |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 519 | TEST_F(RtpSenderReceiverTest, AudioSenderSsrcSetToZero) { |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 520 | CreateAudioRtpSender(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 521 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 522 | audio_rtp_sender_->SetSsrc(0); |
| 523 | VerifyVoiceChannelNoInput(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 524 | } |
| 525 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 526 | // Test that the media channel stops sending when the video sender's SSRC is set |
| 527 | // to 0. |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 528 | TEST_F(RtpSenderReceiverTest, VideoSenderSsrcSetToZero) { |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 529 | CreateAudioRtpSender(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 530 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 531 | audio_rtp_sender_->SetSsrc(0); |
| 532 | VerifyVideoChannelNoInput(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 533 | } |
| 534 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 535 | // Test that the media channel stops sending when the audio sender's track is |
| 536 | // set to null. |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 537 | TEST_F(RtpSenderReceiverTest, AudioSenderTrackSetToNull) { |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 538 | CreateAudioRtpSender(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 539 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 540 | EXPECT_TRUE(audio_rtp_sender_->SetTrack(nullptr)); |
| 541 | VerifyVoiceChannelNoInput(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 542 | } |
| 543 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 544 | // Test that the media channel stops sending when the video sender's track is |
| 545 | // set to null. |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 546 | TEST_F(RtpSenderReceiverTest, VideoSenderTrackSetToNull) { |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 547 | CreateVideoRtpSender(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 548 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 549 | video_rtp_sender_->SetSsrc(0); |
| 550 | VerifyVideoChannelNoInput(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 551 | } |
| 552 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 553 | // Test that when the audio sender's SSRC is changed, the media channel stops |
| 554 | // sending with the old SSRC and starts sending with the new one. |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 555 | TEST_F(RtpSenderReceiverTest, AudioSenderSsrcChanged) { |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 556 | CreateAudioRtpSender(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 557 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 558 | audio_rtp_sender_->SetSsrc(kAudioSsrc2); |
| 559 | VerifyVoiceChannelNoInput(kAudioSsrc); |
| 560 | VerifyVoiceChannelInput(kAudioSsrc2); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 561 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 562 | audio_rtp_sender_ = nullptr; |
| 563 | VerifyVoiceChannelNoInput(kAudioSsrc2); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 564 | } |
| 565 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 566 | // Test that when the audio sender's SSRC is changed, the media channel stops |
| 567 | // sending with the old SSRC and starts sending with the new one. |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 568 | TEST_F(RtpSenderReceiverTest, VideoSenderSsrcChanged) { |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 569 | CreateVideoRtpSender(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 570 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 571 | video_rtp_sender_->SetSsrc(kVideoSsrc2); |
| 572 | VerifyVideoChannelNoInput(kVideoSsrc); |
| 573 | VerifyVideoChannelInput(kVideoSsrc2); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 574 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 575 | video_rtp_sender_ = nullptr; |
| 576 | VerifyVideoChannelNoInput(kVideoSsrc2); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 577 | } |
| 578 | |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 579 | TEST_F(RtpSenderReceiverTest, AudioSenderCanSetParameters) { |
| 580 | CreateAudioRtpSender(); |
| 581 | |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 582 | RtpParameters params = audio_rtp_sender_->GetParameters(); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 583 | EXPECT_EQ(1u, params.encodings.size()); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 584 | EXPECT_TRUE(audio_rtp_sender_->SetParameters(params)); |
| 585 | |
| 586 | DestroyAudioRtpSender(); |
| 587 | } |
| 588 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 589 | TEST_F(RtpSenderReceiverTest, SetAudioMaxSendBitrate) { |
| 590 | CreateAudioRtpSender(); |
| 591 | |
| 592 | EXPECT_EQ(-1, voice_media_channel_->max_bps()); |
| 593 | webrtc::RtpParameters params = audio_rtp_sender_->GetParameters(); |
| 594 | EXPECT_EQ(1, params.encodings.size()); |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 595 | EXPECT_FALSE(params.encodings[0].max_bitrate_bps); |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 596 | params.encodings[0].max_bitrate_bps = 1000; |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 597 | EXPECT_TRUE(audio_rtp_sender_->SetParameters(params)); |
| 598 | |
| 599 | // Read back the parameters and verify they have been changed. |
| 600 | params = audio_rtp_sender_->GetParameters(); |
| 601 | EXPECT_EQ(1, params.encodings.size()); |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 602 | EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 603 | |
| 604 | // Verify that the audio channel received the new parameters. |
| 605 | params = voice_media_channel_->GetRtpSendParameters(kAudioSsrc); |
| 606 | EXPECT_EQ(1, params.encodings.size()); |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 607 | EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 608 | |
| 609 | // Verify that the global bitrate limit has not been changed. |
| 610 | EXPECT_EQ(-1, voice_media_channel_->max_bps()); |
| 611 | |
| 612 | DestroyAudioRtpSender(); |
| 613 | } |
| 614 | |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 615 | TEST_F(RtpSenderReceiverTest, SetAudioBitratePriority) { |
| 616 | CreateAudioRtpSender(); |
| 617 | |
| 618 | webrtc::RtpParameters params = audio_rtp_sender_->GetParameters(); |
| 619 | EXPECT_EQ(1, params.encodings.size()); |
| 620 | EXPECT_EQ(webrtc::kDefaultBitratePriority, |
| 621 | params.encodings[0].bitrate_priority); |
| 622 | double new_bitrate_priority = 2.0; |
| 623 | params.encodings[0].bitrate_priority = new_bitrate_priority; |
| 624 | EXPECT_TRUE(audio_rtp_sender_->SetParameters(params)); |
| 625 | |
| 626 | params = audio_rtp_sender_->GetParameters(); |
| 627 | EXPECT_EQ(1, params.encodings.size()); |
| 628 | EXPECT_EQ(new_bitrate_priority, params.encodings[0].bitrate_priority); |
| 629 | |
| 630 | params = voice_media_channel_->GetRtpSendParameters(kAudioSsrc); |
| 631 | EXPECT_EQ(1, params.encodings.size()); |
| 632 | EXPECT_EQ(new_bitrate_priority, params.encodings[0].bitrate_priority); |
| 633 | |
| 634 | DestroyAudioRtpSender(); |
| 635 | } |
| 636 | |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 637 | TEST_F(RtpSenderReceiverTest, VideoSenderCanSetParameters) { |
| 638 | CreateVideoRtpSender(); |
| 639 | |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 640 | RtpParameters params = video_rtp_sender_->GetParameters(); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 641 | EXPECT_EQ(1u, params.encodings.size()); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 642 | EXPECT_TRUE(video_rtp_sender_->SetParameters(params)); |
| 643 | |
| 644 | DestroyVideoRtpSender(); |
| 645 | } |
| 646 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 647 | TEST_F(RtpSenderReceiverTest, SetVideoMaxSendBitrate) { |
| 648 | CreateVideoRtpSender(); |
| 649 | |
| 650 | EXPECT_EQ(-1, video_media_channel_->max_bps()); |
| 651 | webrtc::RtpParameters params = video_rtp_sender_->GetParameters(); |
| 652 | EXPECT_EQ(1, params.encodings.size()); |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 653 | EXPECT_FALSE(params.encodings[0].max_bitrate_bps); |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 654 | params.encodings[0].max_bitrate_bps = 1000; |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 655 | EXPECT_TRUE(video_rtp_sender_->SetParameters(params)); |
| 656 | |
| 657 | // Read back the parameters and verify they have been changed. |
| 658 | params = video_rtp_sender_->GetParameters(); |
| 659 | EXPECT_EQ(1, params.encodings.size()); |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 660 | EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 661 | |
| 662 | // Verify that the video channel received the new parameters. |
| 663 | params = video_media_channel_->GetRtpSendParameters(kVideoSsrc); |
| 664 | EXPECT_EQ(1, params.encodings.size()); |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 665 | EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 666 | |
| 667 | // Verify that the global bitrate limit has not been changed. |
| 668 | EXPECT_EQ(-1, video_media_channel_->max_bps()); |
| 669 | |
| 670 | DestroyVideoRtpSender(); |
| 671 | } |
| 672 | |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 673 | TEST_F(RtpSenderReceiverTest, SetVideoBitratePriority) { |
| 674 | CreateVideoRtpSender(); |
| 675 | |
| 676 | webrtc::RtpParameters params = video_rtp_sender_->GetParameters(); |
| 677 | EXPECT_EQ(1, params.encodings.size()); |
| 678 | EXPECT_EQ(webrtc::kDefaultBitratePriority, |
| 679 | params.encodings[0].bitrate_priority); |
| 680 | double new_bitrate_priority = 2.0; |
| 681 | params.encodings[0].bitrate_priority = new_bitrate_priority; |
| 682 | EXPECT_TRUE(video_rtp_sender_->SetParameters(params)); |
| 683 | |
| 684 | params = video_rtp_sender_->GetParameters(); |
| 685 | EXPECT_EQ(1, params.encodings.size()); |
| 686 | EXPECT_EQ(new_bitrate_priority, params.encodings[0].bitrate_priority); |
| 687 | |
| 688 | params = video_media_channel_->GetRtpSendParameters(kVideoSsrc); |
| 689 | EXPECT_EQ(1, params.encodings.size()); |
| 690 | EXPECT_EQ(new_bitrate_priority, params.encodings[0].bitrate_priority); |
| 691 | |
| 692 | DestroyVideoRtpSender(); |
| 693 | } |
| 694 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 695 | TEST_F(RtpSenderReceiverTest, AudioReceiverCanSetParameters) { |
| 696 | CreateAudioRtpReceiver(); |
| 697 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 698 | RtpParameters params = audio_rtp_receiver_->GetParameters(); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 699 | EXPECT_EQ(1u, params.encodings.size()); |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 700 | EXPECT_TRUE(audio_rtp_receiver_->SetParameters(params)); |
| 701 | |
| 702 | DestroyAudioRtpReceiver(); |
| 703 | } |
| 704 | |
| 705 | TEST_F(RtpSenderReceiverTest, VideoReceiverCanSetParameters) { |
| 706 | CreateVideoRtpReceiver(); |
| 707 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 708 | RtpParameters params = video_rtp_receiver_->GetParameters(); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 709 | EXPECT_EQ(1u, params.encodings.size()); |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 710 | EXPECT_TRUE(video_rtp_receiver_->SetParameters(params)); |
| 711 | |
| 712 | DestroyVideoRtpReceiver(); |
| 713 | } |
| 714 | |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 715 | // Test that makes sure that a video track content hint translates to the proper |
| 716 | // value for sources that are not screencast. |
| 717 | TEST_F(RtpSenderReceiverTest, PropagatesVideoTrackContentHint) { |
| 718 | CreateVideoRtpSender(); |
| 719 | |
| 720 | video_track_->set_enabled(true); |
| 721 | |
| 722 | // |video_track_| is not screencast by default. |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 723 | EXPECT_EQ(false, video_media_channel_->options().is_screencast); |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 724 | // No content hint should be set by default. |
| 725 | EXPECT_EQ(VideoTrackInterface::ContentHint::kNone, |
| 726 | video_track_->content_hint()); |
| 727 | // Setting detailed should turn a non-screencast source into screencast mode. |
| 728 | video_track_->set_content_hint(VideoTrackInterface::ContentHint::kDetailed); |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 729 | EXPECT_EQ(true, video_media_channel_->options().is_screencast); |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 730 | // Removing the content hint should turn the track back into non-screencast |
| 731 | // mode. |
| 732 | video_track_->set_content_hint(VideoTrackInterface::ContentHint::kNone); |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 733 | EXPECT_EQ(false, video_media_channel_->options().is_screencast); |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 734 | // Setting fluid should remain in non-screencast mode (its default). |
| 735 | video_track_->set_content_hint(VideoTrackInterface::ContentHint::kFluid); |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 736 | EXPECT_EQ(false, video_media_channel_->options().is_screencast); |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 737 | |
| 738 | DestroyVideoRtpSender(); |
| 739 | } |
| 740 | |
| 741 | // Test that makes sure that a video track content hint translates to the proper |
| 742 | // value for screencast sources. |
| 743 | TEST_F(RtpSenderReceiverTest, |
| 744 | PropagatesVideoTrackContentHintForScreencastSource) { |
| 745 | CreateVideoRtpSender(true); |
| 746 | |
| 747 | video_track_->set_enabled(true); |
| 748 | |
| 749 | // |video_track_| with a screencast source should be screencast by default. |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 750 | EXPECT_EQ(true, video_media_channel_->options().is_screencast); |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 751 | // No content hint should be set by default. |
| 752 | EXPECT_EQ(VideoTrackInterface::ContentHint::kNone, |
| 753 | video_track_->content_hint()); |
| 754 | // Setting fluid should turn a screencast source into non-screencast mode. |
| 755 | video_track_->set_content_hint(VideoTrackInterface::ContentHint::kFluid); |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 756 | EXPECT_EQ(false, video_media_channel_->options().is_screencast); |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 757 | // Removing the content hint should turn the track back into screencast mode. |
| 758 | video_track_->set_content_hint(VideoTrackInterface::ContentHint::kNone); |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 759 | EXPECT_EQ(true, video_media_channel_->options().is_screencast); |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 760 | // Setting detailed should still remain in screencast mode (its default). |
| 761 | video_track_->set_content_hint(VideoTrackInterface::ContentHint::kDetailed); |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 762 | EXPECT_EQ(true, video_media_channel_->options().is_screencast); |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 763 | |
| 764 | DestroyVideoRtpSender(); |
| 765 | } |
| 766 | |
| 767 | // Test that makes sure any content hints that are set on a track before |
| 768 | // VideoRtpSender is ready to send are still applied when it gets ready to send. |
| 769 | TEST_F(RtpSenderReceiverTest, |
| 770 | PropagatesVideoTrackContentHintSetBeforeEnabling) { |
| 771 | AddVideoTrack(); |
| 772 | // Setting detailed overrides the default non-screencast mode. This should be |
| 773 | // applied even if the track is set on construction. |
| 774 | video_track_->set_content_hint(VideoTrackInterface::ContentHint::kDetailed); |
Steve Anton | 02ee47c | 2018-01-10 16:26:06 -0800 | [diff] [blame^] | 775 | video_rtp_sender_ = new VideoRtpSender(local_stream_->GetVideoTracks()[0], |
| 776 | {local_stream_->label()}); |
| 777 | video_rtp_sender_->SetChannel(video_channel_); |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 778 | video_track_->set_enabled(true); |
| 779 | |
| 780 | // Sender is not ready to send (no SSRC) so no option should have been set. |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 781 | EXPECT_EQ(rtc::nullopt, video_media_channel_->options().is_screencast); |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 782 | |
| 783 | // Verify that the content hint is accounted for when video_rtp_sender_ does |
| 784 | // get enabled. |
| 785 | video_rtp_sender_->SetSsrc(kVideoSsrc); |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 786 | EXPECT_EQ(true, video_media_channel_->options().is_screencast); |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 787 | |
| 788 | // And removing the hint should go back to false (to verify that false was |
| 789 | // default correctly). |
| 790 | video_track_->set_content_hint(VideoTrackInterface::ContentHint::kNone); |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 791 | EXPECT_EQ(false, video_media_channel_->options().is_screencast); |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 792 | |
| 793 | DestroyVideoRtpSender(); |
| 794 | } |
| 795 | |
deadbeef | 20cb0c1 | 2017-02-01 20:27:00 -0800 | [diff] [blame] | 796 | TEST_F(RtpSenderReceiverTest, AudioSenderHasDtmfSender) { |
| 797 | CreateAudioRtpSender(); |
| 798 | EXPECT_NE(nullptr, audio_rtp_sender_->GetDtmfSender()); |
| 799 | } |
| 800 | |
| 801 | TEST_F(RtpSenderReceiverTest, VideoSenderDoesNotHaveDtmfSender) { |
| 802 | CreateVideoRtpSender(); |
| 803 | EXPECT_EQ(nullptr, video_rtp_sender_->GetDtmfSender()); |
| 804 | } |
| 805 | |
| 806 | // Test that the DTMF sender is really using |voice_channel_|, and thus returns |
| 807 | // true/false from CanSendDtmf based on what |voice_channel_| returns. |
| 808 | TEST_F(RtpSenderReceiverTest, CanInsertDtmf) { |
| 809 | AddDtmfCodec(); |
| 810 | CreateAudioRtpSender(); |
| 811 | auto dtmf_sender = audio_rtp_sender_->GetDtmfSender(); |
| 812 | ASSERT_NE(nullptr, dtmf_sender); |
| 813 | EXPECT_TRUE(dtmf_sender->CanInsertDtmf()); |
| 814 | } |
| 815 | |
| 816 | TEST_F(RtpSenderReceiverTest, CanNotInsertDtmf) { |
| 817 | CreateAudioRtpSender(); |
| 818 | auto dtmf_sender = audio_rtp_sender_->GetDtmfSender(); |
| 819 | ASSERT_NE(nullptr, dtmf_sender); |
| 820 | // DTMF codec has not been added, as it was in the above test. |
| 821 | EXPECT_FALSE(dtmf_sender->CanInsertDtmf()); |
| 822 | } |
| 823 | |
| 824 | TEST_F(RtpSenderReceiverTest, InsertDtmf) { |
| 825 | AddDtmfCodec(); |
| 826 | CreateAudioRtpSender(); |
| 827 | auto dtmf_sender = audio_rtp_sender_->GetDtmfSender(); |
| 828 | ASSERT_NE(nullptr, dtmf_sender); |
| 829 | |
| 830 | EXPECT_EQ(0U, voice_media_channel_->dtmf_info_queue().size()); |
| 831 | |
| 832 | // Insert DTMF |
| 833 | const int expected_duration = 90; |
| 834 | dtmf_sender->InsertDtmf("012", expected_duration, 100); |
| 835 | |
| 836 | // Verify |
| 837 | ASSERT_EQ_WAIT(3U, voice_media_channel_->dtmf_info_queue().size(), |
| 838 | kDefaultTimeout); |
| 839 | const uint32_t send_ssrc = |
| 840 | voice_media_channel_->send_streams()[0].first_ssrc(); |
| 841 | EXPECT_TRUE(CompareDtmfInfo(voice_media_channel_->dtmf_info_queue()[0], |
| 842 | send_ssrc, 0, expected_duration)); |
| 843 | EXPECT_TRUE(CompareDtmfInfo(voice_media_channel_->dtmf_info_queue()[1], |
| 844 | send_ssrc, 1, expected_duration)); |
| 845 | EXPECT_TRUE(CompareDtmfInfo(voice_media_channel_->dtmf_info_queue()[2], |
| 846 | send_ssrc, 2, expected_duration)); |
| 847 | } |
| 848 | |
| 849 | // Make sure the signal from "GetOnDestroyedSignal()" fires when the sender is |
| 850 | // destroyed, which is needed for the DTMF sender. |
| 851 | TEST_F(RtpSenderReceiverTest, TestOnDestroyedSignal) { |
| 852 | CreateAudioRtpSender(); |
| 853 | EXPECT_FALSE(audio_sender_destroyed_signal_fired_); |
| 854 | audio_rtp_sender_ = nullptr; |
| 855 | EXPECT_TRUE(audio_sender_destroyed_signal_fired_); |
| 856 | } |
| 857 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 858 | } // namespace webrtc |