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" |
Seth Hampson | 2d2c888 | 2018-05-16 16:02:32 -0700 | [diff] [blame] | 18 | #include "media/base/testutils.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 19 | #include "media/engine/fakewebrtccall.h" |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 20 | #include "p2p/base/fakedtlstransport.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 21 | #include "pc/audiotrack.h" |
| 22 | #include "pc/channelmanager.h" |
| 23 | #include "pc/localaudiosource.h" |
| 24 | #include "pc/mediastream.h" |
| 25 | #include "pc/remoteaudiosource.h" |
| 26 | #include "pc/rtpreceiver.h" |
| 27 | #include "pc/rtpsender.h" |
| 28 | #include "pc/streamcollection.h" |
| 29 | #include "pc/test/fakevideotracksource.h" |
| 30 | #include "pc/videotrack.h" |
| 31 | #include "pc/videotracksource.h" |
| 32 | #include "rtc_base/gunit.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 33 | #include "test/gmock.h" |
| 34 | #include "test/gtest.h" |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 35 | |
| 36 | using ::testing::_; |
| 37 | using ::testing::Exactly; |
deadbeef | 5dd42fd | 2016-05-02 16:20:01 -0700 | [diff] [blame] | 38 | using ::testing::InvokeWithoutArgs; |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 39 | using ::testing::Return; |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 40 | |
deadbeef | 20cb0c1 | 2017-02-01 20:27:00 -0800 | [diff] [blame] | 41 | namespace { |
| 42 | |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 43 | static const char kStreamId1[] = "local_stream_1"; |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 44 | static const char kVideoTrackId[] = "video_1"; |
| 45 | static const char kAudioTrackId[] = "audio_1"; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 46 | static const uint32_t kVideoSsrc = 98; |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 47 | static const uint32_t kVideoSsrc2 = 100; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 48 | static const uint32_t kAudioSsrc = 99; |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 49 | static const uint32_t kAudioSsrc2 = 101; |
deadbeef | 20cb0c1 | 2017-02-01 20:27:00 -0800 | [diff] [blame] | 50 | static const int kDefaultTimeout = 10000; // 10 seconds. |
deadbeef | 20cb0c1 | 2017-02-01 20:27:00 -0800 | [diff] [blame] | 51 | } // namespace |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 52 | |
| 53 | namespace webrtc { |
| 54 | |
deadbeef | 20cb0c1 | 2017-02-01 20:27:00 -0800 | [diff] [blame] | 55 | class RtpSenderReceiverTest : public testing::Test, |
| 56 | public sigslot::has_slots<> { |
tkchin | 3784b4a | 2016-06-24 19:31:47 -0700 | [diff] [blame] | 57 | public: |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 58 | RtpSenderReceiverTest() |
Steve Anton | 47136dd | 2018-01-12 10:49:35 -0800 | [diff] [blame] | 59 | : network_thread_(rtc::Thread::Current()), |
| 60 | worker_thread_(rtc::Thread::Current()), |
| 61 | // Create fake media engine/etc. so we can create channels to use to |
| 62 | // test RtpSenders/RtpReceivers. |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 63 | media_engine_(new cricket::FakeMediaEngine()), |
Steve Anton | c9e1560 | 2017-11-06 15:40:09 -0800 | [diff] [blame] | 64 | channel_manager_(rtc::WrapUnique(media_engine_), |
| 65 | rtc::MakeUnique<cricket::RtpDataEngine>(), |
Steve Anton | 47136dd | 2018-01-12 10:49:35 -0800 | [diff] [blame] | 66 | worker_thread_, |
| 67 | network_thread_), |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 68 | fake_call_(), |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 69 | local_stream_(MediaStream::Create(kStreamId1)) { |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 70 | // Create channels to be used by the RtpSenders and RtpReceivers. |
| 71 | channel_manager_.Init(); |
deadbeef | 7af91dd | 2016-12-13 11:29:11 -0800 | [diff] [blame] | 72 | bool srtp_required = true; |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 73 | rtp_dtls_transport_ = rtc::MakeUnique<cricket::FakeDtlsTransport>( |
| 74 | "fake_dtls_transport", cricket::ICE_CANDIDATE_COMPONENT_RTP); |
| 75 | rtp_transport_ = CreateDtlsSrtpTransport(); |
| 76 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 77 | voice_channel_ = channel_manager_.CreateVoiceChannel( |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 78 | &fake_call_, cricket::MediaConfig(), rtp_transport_.get(), |
| 79 | rtc::Thread::Current(), cricket::CN_AUDIO, srtp_required, |
| 80 | rtc::CryptoOptions(), cricket::AudioOptions()); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 81 | video_channel_ = channel_manager_.CreateVideoChannel( |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 82 | &fake_call_, cricket::MediaConfig(), rtp_transport_.get(), |
| 83 | rtc::Thread::Current(), cricket::CN_VIDEO, srtp_required, |
| 84 | rtc::CryptoOptions(), cricket::VideoOptions()); |
deadbeef | 20cb0c1 | 2017-02-01 20:27:00 -0800 | [diff] [blame] | 85 | voice_channel_->Enable(true); |
| 86 | video_channel_->Enable(true); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 87 | voice_media_channel_ = media_engine_->GetVoiceChannel(0); |
| 88 | video_media_channel_ = media_engine_->GetVideoChannel(0); |
| 89 | RTC_CHECK(voice_channel_); |
| 90 | RTC_CHECK(video_channel_); |
| 91 | RTC_CHECK(voice_media_channel_); |
| 92 | RTC_CHECK(video_media_channel_); |
| 93 | |
| 94 | // Create streams for predefined SSRCs. Streams need to exist in order |
| 95 | // for the senders and receievers to apply parameters to them. |
| 96 | // Normally these would be created by SetLocalDescription and |
| 97 | // SetRemoteDescription. |
| 98 | voice_media_channel_->AddSendStream( |
| 99 | cricket::StreamParams::CreateLegacy(kAudioSsrc)); |
| 100 | voice_media_channel_->AddRecvStream( |
| 101 | cricket::StreamParams::CreateLegacy(kAudioSsrc)); |
| 102 | voice_media_channel_->AddSendStream( |
| 103 | cricket::StreamParams::CreateLegacy(kAudioSsrc2)); |
| 104 | voice_media_channel_->AddRecvStream( |
| 105 | cricket::StreamParams::CreateLegacy(kAudioSsrc2)); |
| 106 | video_media_channel_->AddSendStream( |
| 107 | cricket::StreamParams::CreateLegacy(kVideoSsrc)); |
| 108 | video_media_channel_->AddRecvStream( |
| 109 | cricket::StreamParams::CreateLegacy(kVideoSsrc)); |
| 110 | video_media_channel_->AddSendStream( |
| 111 | cricket::StreamParams::CreateLegacy(kVideoSsrc2)); |
| 112 | video_media_channel_->AddRecvStream( |
| 113 | cricket::StreamParams::CreateLegacy(kVideoSsrc2)); |
tkchin | 3784b4a | 2016-06-24 19:31:47 -0700 | [diff] [blame] | 114 | } |
Taylor Brandstetter | 2d54917 | 2016-06-24 14:18:22 -0700 | [diff] [blame] | 115 | |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 116 | std::unique_ptr<webrtc::RtpTransportInternal> CreateDtlsSrtpTransport() { |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 117 | auto dtls_srtp_transport = |
Zhi Huang | 365381f | 2018-04-13 16:44:34 -0700 | [diff] [blame] | 118 | rtc::MakeUnique<webrtc::DtlsSrtpTransport>(/*rtcp_mux_required=*/true); |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 119 | dtls_srtp_transport->SetDtlsTransports(rtp_dtls_transport_.get(), |
| 120 | /*rtcp_dtls_transport=*/nullptr); |
| 121 | return dtls_srtp_transport; |
| 122 | } |
| 123 | |
deadbeef | 20cb0c1 | 2017-02-01 20:27:00 -0800 | [diff] [blame] | 124 | // Needed to use DTMF sender. |
| 125 | void AddDtmfCodec() { |
| 126 | cricket::AudioSendParameters params; |
| 127 | const cricket::AudioCodec kTelephoneEventCodec(106, "telephone-event", 8000, |
| 128 | 0, 1); |
| 129 | params.codecs.push_back(kTelephoneEventCodec); |
| 130 | voice_media_channel_->SetSendParameters(params); |
| 131 | } |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 132 | |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 133 | void AddVideoTrack() { AddVideoTrack(false); } |
| 134 | |
| 135 | void AddVideoTrack(bool is_screencast) { |
perkj | a3ede6c | 2016-03-08 01:27:48 +0100 | [diff] [blame] | 136 | rtc::scoped_refptr<VideoTrackSourceInterface> source( |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 137 | FakeVideoTrackSource::Create(is_screencast)); |
perkj | 773be36 | 2017-07-31 23:22:01 -0700 | [diff] [blame] | 138 | video_track_ = |
| 139 | VideoTrack::Create(kVideoTrackId, source, rtc::Thread::Current()); |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 140 | EXPECT_TRUE(local_stream_->AddTrack(video_track_)); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 143 | void CreateAudioRtpSender() { CreateAudioRtpSender(nullptr); } |
| 144 | |
Mirko Bonadei | c61ce0d | 2017-11-21 17:04:20 +0100 | [diff] [blame] | 145 | void CreateAudioRtpSender( |
| 146 | const rtc::scoped_refptr<LocalAudioSource>& source) { |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 147 | audio_track_ = AudioTrack::Create(kAudioTrackId, source); |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 148 | EXPECT_TRUE(local_stream_->AddTrack(audio_track_)); |
Steve Anton | 47136dd | 2018-01-12 10:49:35 -0800 | [diff] [blame] | 149 | audio_rtp_sender_ = |
| 150 | new AudioRtpSender(worker_thread_, local_stream_->GetAudioTracks()[0], |
Seth Hampson | 13b8bad | 2018-03-13 16:05:28 -0700 | [diff] [blame] | 151 | {local_stream_->id()}, nullptr); |
Steve Anton | 57858b3 | 2018-02-15 15:19:50 -0800 | [diff] [blame] | 152 | audio_rtp_sender_->SetVoiceMediaChannel(voice_media_channel_); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 153 | audio_rtp_sender_->SetSsrc(kAudioSsrc); |
deadbeef | 20cb0c1 | 2017-02-01 20:27:00 -0800 | [diff] [blame] | 154 | audio_rtp_sender_->GetOnDestroyedSignal()->connect( |
| 155 | this, &RtpSenderReceiverTest::OnAudioSenderDestroyed); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 156 | VerifyVoiceChannelInput(); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Steve Anton | 02ee47c | 2018-01-10 16:26:06 -0800 | [diff] [blame] | 159 | void CreateAudioRtpSenderWithNoTrack() { |
Steve Anton | 47136dd | 2018-01-12 10:49:35 -0800 | [diff] [blame] | 160 | audio_rtp_sender_ = new AudioRtpSender(worker_thread_, nullptr); |
Steve Anton | 57858b3 | 2018-02-15 15:19:50 -0800 | [diff] [blame] | 161 | audio_rtp_sender_->SetVoiceMediaChannel(voice_media_channel_); |
Steve Anton | 02ee47c | 2018-01-10 16:26:06 -0800 | [diff] [blame] | 162 | } |
| 163 | |
deadbeef | 20cb0c1 | 2017-02-01 20:27:00 -0800 | [diff] [blame] | 164 | void OnAudioSenderDestroyed() { audio_sender_destroyed_signal_fired_ = true; } |
| 165 | |
Seth Hampson | 2d2c888 | 2018-05-16 16:02:32 -0700 | [diff] [blame] | 166 | void CreateVideoRtpSender(uint32_t ssrc) { |
| 167 | CreateVideoRtpSender(false, ssrc); |
| 168 | } |
| 169 | |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 170 | void CreateVideoRtpSender() { CreateVideoRtpSender(false); } |
| 171 | |
Seth Hampson | 2d2c888 | 2018-05-16 16:02:32 -0700 | [diff] [blame] | 172 | void CreateVideoRtpSender(bool is_screencast, uint32_t ssrc = kVideoSsrc) { |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 173 | AddVideoTrack(is_screencast); |
Steve Anton | 47136dd | 2018-01-12 10:49:35 -0800 | [diff] [blame] | 174 | video_rtp_sender_ = |
| 175 | new VideoRtpSender(worker_thread_, local_stream_->GetVideoTracks()[0], |
Seth Hampson | 13b8bad | 2018-03-13 16:05:28 -0700 | [diff] [blame] | 176 | {local_stream_->id()}); |
Steve Anton | 57858b3 | 2018-02-15 15:19:50 -0800 | [diff] [blame] | 177 | video_rtp_sender_->SetVideoMediaChannel(video_media_channel_); |
Seth Hampson | 2d2c888 | 2018-05-16 16:02:32 -0700 | [diff] [blame] | 178 | video_rtp_sender_->SetSsrc(ssrc); |
| 179 | VerifyVideoChannelInput(ssrc); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Steve Anton | 02ee47c | 2018-01-10 16:26:06 -0800 | [diff] [blame] | 182 | void CreateVideoRtpSenderWithNoTrack() { |
Steve Anton | 47136dd | 2018-01-12 10:49:35 -0800 | [diff] [blame] | 183 | video_rtp_sender_ = new VideoRtpSender(worker_thread_); |
Steve Anton | 57858b3 | 2018-02-15 15:19:50 -0800 | [diff] [blame] | 184 | video_rtp_sender_->SetVideoMediaChannel(video_media_channel_); |
Steve Anton | 02ee47c | 2018-01-10 16:26:06 -0800 | [diff] [blame] | 185 | } |
| 186 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 187 | void DestroyAudioRtpSender() { |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 188 | audio_rtp_sender_ = nullptr; |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 189 | VerifyVoiceChannelNoInput(); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | void DestroyVideoRtpSender() { |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 193 | video_rtp_sender_ = nullptr; |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 194 | VerifyVideoChannelNoInput(); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Henrik Boström | 9e6fd2b | 2017-11-21 13:41:51 +0100 | [diff] [blame] | 197 | void CreateAudioRtpReceiver( |
| 198 | std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams = {}) { |
| 199 | audio_rtp_receiver_ = new AudioRtpReceiver( |
Steve Anton | d367921 | 2018-01-17 17:41:02 -0800 | [diff] [blame] | 200 | rtc::Thread::Current(), kAudioTrackId, std::move(streams)); |
Steve Anton | 57858b3 | 2018-02-15 15:19:50 -0800 | [diff] [blame] | 201 | audio_rtp_receiver_->SetVoiceMediaChannel(voice_media_channel_); |
Steve Anton | d367921 | 2018-01-17 17:41:02 -0800 | [diff] [blame] | 202 | audio_rtp_receiver_->SetupMediaChannel(kAudioSsrc); |
perkj | d61bf80 | 2016-03-24 03:16:19 -0700 | [diff] [blame] | 203 | audio_track_ = audio_rtp_receiver_->audio_track(); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 204 | VerifyVoiceChannelOutput(); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Henrik Boström | 9e6fd2b | 2017-11-21 13:41:51 +0100 | [diff] [blame] | 207 | void CreateVideoRtpReceiver( |
| 208 | std::vector<rtc::scoped_refptr<MediaStreamInterface>> streams = {}) { |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 209 | video_rtp_receiver_ = new VideoRtpReceiver( |
Steve Anton | d367921 | 2018-01-17 17:41:02 -0800 | [diff] [blame] | 210 | rtc::Thread::Current(), kVideoTrackId, std::move(streams)); |
Steve Anton | 57858b3 | 2018-02-15 15:19:50 -0800 | [diff] [blame] | 211 | video_rtp_receiver_->SetVideoMediaChannel(video_media_channel_); |
Steve Anton | d367921 | 2018-01-17 17:41:02 -0800 | [diff] [blame] | 212 | video_rtp_receiver_->SetupMediaChannel(kVideoSsrc); |
perkj | f0dcfe2 | 2016-03-10 18:32:00 +0100 | [diff] [blame] | 213 | video_track_ = video_rtp_receiver_->video_track(); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 214 | VerifyVideoChannelOutput(); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | void DestroyAudioRtpReceiver() { |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 218 | audio_rtp_receiver_ = nullptr; |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 219 | VerifyVoiceChannelNoOutput(); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | void DestroyVideoRtpReceiver() { |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 223 | video_rtp_receiver_ = nullptr; |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 224 | VerifyVideoChannelNoOutput(); |
| 225 | } |
| 226 | |
| 227 | void VerifyVoiceChannelInput() { VerifyVoiceChannelInput(kAudioSsrc); } |
| 228 | |
| 229 | void VerifyVoiceChannelInput(uint32_t ssrc) { |
| 230 | // Verify that the media channel has an audio source, and the stream isn't |
| 231 | // muted. |
| 232 | EXPECT_TRUE(voice_media_channel_->HasSource(ssrc)); |
| 233 | EXPECT_FALSE(voice_media_channel_->IsStreamMuted(ssrc)); |
| 234 | } |
| 235 | |
| 236 | void VerifyVideoChannelInput() { VerifyVideoChannelInput(kVideoSsrc); } |
| 237 | |
| 238 | void VerifyVideoChannelInput(uint32_t ssrc) { |
| 239 | // Verify that the media channel has a video source, |
| 240 | EXPECT_TRUE(video_media_channel_->HasSource(ssrc)); |
| 241 | } |
| 242 | |
| 243 | void VerifyVoiceChannelNoInput() { VerifyVoiceChannelNoInput(kAudioSsrc); } |
| 244 | |
| 245 | void VerifyVoiceChannelNoInput(uint32_t ssrc) { |
| 246 | // Verify that the media channel's source is reset. |
| 247 | EXPECT_FALSE(voice_media_channel_->HasSource(ssrc)); |
| 248 | } |
| 249 | |
| 250 | void VerifyVideoChannelNoInput() { VerifyVideoChannelNoInput(kVideoSsrc); } |
| 251 | |
| 252 | void VerifyVideoChannelNoInput(uint32_t ssrc) { |
| 253 | // Verify that the media channel's source is reset. |
| 254 | EXPECT_FALSE(video_media_channel_->HasSource(ssrc)); |
| 255 | } |
| 256 | |
| 257 | void VerifyVoiceChannelOutput() { |
| 258 | // Verify that the volume is initialized to 1. |
| 259 | double volume; |
| 260 | EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume)); |
| 261 | EXPECT_EQ(1, volume); |
| 262 | } |
| 263 | |
| 264 | void VerifyVideoChannelOutput() { |
| 265 | // Verify that the media channel has a sink. |
| 266 | EXPECT_TRUE(video_media_channel_->HasSink(kVideoSsrc)); |
| 267 | } |
| 268 | |
| 269 | void VerifyVoiceChannelNoOutput() { |
| 270 | // Verify that the volume is reset to 0. |
| 271 | double volume; |
| 272 | EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume)); |
| 273 | EXPECT_EQ(0, volume); |
| 274 | } |
| 275 | |
| 276 | void VerifyVideoChannelNoOutput() { |
| 277 | // Verify that the media channel's sink is reset. |
| 278 | EXPECT_FALSE(video_media_channel_->HasSink(kVideoSsrc)); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | protected: |
Steve Anton | 47136dd | 2018-01-12 10:49:35 -0800 | [diff] [blame] | 282 | rtc::Thread* const network_thread_; |
| 283 | rtc::Thread* const worker_thread_; |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 284 | webrtc::RtcEventLogNullImpl event_log_; |
Zhi Huang | e830e68 | 2018-03-30 10:48:35 -0700 | [diff] [blame] | 285 | // The |rtp_dtls_transport_| and |rtp_transport_| should be destroyed after |
| 286 | // the |channel_manager|. |
| 287 | std::unique_ptr<cricket::DtlsTransportInternal> rtp_dtls_transport_; |
| 288 | std::unique_ptr<webrtc::RtpTransportInternal> rtp_transport_; |
deadbeef | 112b2e9 | 2017-02-10 20:13:37 -0800 | [diff] [blame] | 289 | // |media_engine_| is actually owned by |channel_manager_|. |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 290 | cricket::FakeMediaEngine* media_engine_; |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 291 | cricket::ChannelManager channel_manager_; |
| 292 | cricket::FakeCall fake_call_; |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 293 | cricket::VoiceChannel* voice_channel_; |
| 294 | cricket::VideoChannel* video_channel_; |
| 295 | cricket::FakeVoiceMediaChannel* voice_media_channel_; |
| 296 | cricket::FakeVideoMediaChannel* video_media_channel_; |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 297 | rtc::scoped_refptr<AudioRtpSender> audio_rtp_sender_; |
| 298 | rtc::scoped_refptr<VideoRtpSender> video_rtp_sender_; |
| 299 | rtc::scoped_refptr<AudioRtpReceiver> audio_rtp_receiver_; |
| 300 | rtc::scoped_refptr<VideoRtpReceiver> video_rtp_receiver_; |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 301 | rtc::scoped_refptr<MediaStreamInterface> local_stream_; |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 302 | rtc::scoped_refptr<VideoTrackInterface> video_track_; |
| 303 | rtc::scoped_refptr<AudioTrackInterface> audio_track_; |
deadbeef | 20cb0c1 | 2017-02-01 20:27:00 -0800 | [diff] [blame] | 304 | bool audio_sender_destroyed_signal_fired_ = false; |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 305 | }; |
| 306 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 307 | // Test that |voice_channel_| is updated when an audio track is associated |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 308 | // and disassociated with an AudioRtpSender. |
| 309 | TEST_F(RtpSenderReceiverTest, AddAndDestroyAudioRtpSender) { |
| 310 | CreateAudioRtpSender(); |
| 311 | DestroyAudioRtpSender(); |
| 312 | } |
| 313 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 314 | // Test that |video_channel_| is updated when a video track is associated and |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 315 | // disassociated with a VideoRtpSender. |
| 316 | TEST_F(RtpSenderReceiverTest, AddAndDestroyVideoRtpSender) { |
| 317 | CreateVideoRtpSender(); |
| 318 | DestroyVideoRtpSender(); |
| 319 | } |
| 320 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 321 | // Test that |voice_channel_| is updated when a remote audio track is |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 322 | // associated and disassociated with an AudioRtpReceiver. |
| 323 | TEST_F(RtpSenderReceiverTest, AddAndDestroyAudioRtpReceiver) { |
| 324 | CreateAudioRtpReceiver(); |
| 325 | DestroyAudioRtpReceiver(); |
| 326 | } |
| 327 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 328 | // Test that |video_channel_| is updated when a remote video track is |
| 329 | // associated and disassociated with a VideoRtpReceiver. |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 330 | TEST_F(RtpSenderReceiverTest, AddAndDestroyVideoRtpReceiver) { |
| 331 | CreateVideoRtpReceiver(); |
| 332 | DestroyVideoRtpReceiver(); |
| 333 | } |
| 334 | |
Henrik Boström | 9e6fd2b | 2017-11-21 13:41:51 +0100 | [diff] [blame] | 335 | TEST_F(RtpSenderReceiverTest, AddAndDestroyAudioRtpReceiverWithStreams) { |
| 336 | CreateAudioRtpReceiver({local_stream_}); |
| 337 | DestroyAudioRtpReceiver(); |
| 338 | } |
| 339 | |
| 340 | TEST_F(RtpSenderReceiverTest, AddAndDestroyVideoRtpReceiverWithStreams) { |
| 341 | CreateVideoRtpReceiver({local_stream_}); |
| 342 | DestroyVideoRtpReceiver(); |
| 343 | } |
| 344 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 345 | // Test that the AudioRtpSender applies options from the local audio source. |
| 346 | TEST_F(RtpSenderReceiverTest, LocalAudioSourceOptionsApplied) { |
| 347 | cricket::AudioOptions options; |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 348 | options.echo_cancellation = true; |
deadbeef | 757146b | 2017-02-10 21:26:48 -0800 | [diff] [blame] | 349 | auto source = LocalAudioSource::Create(&options); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 350 | CreateAudioRtpSender(source.get()); |
Taylor Brandstetter | 2d54917 | 2016-06-24 14:18:22 -0700 | [diff] [blame] | 351 | |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 352 | EXPECT_EQ(true, voice_media_channel_->options().echo_cancellation); |
Taylor Brandstetter | 2d54917 | 2016-06-24 14:18:22 -0700 | [diff] [blame] | 353 | |
| 354 | DestroyAudioRtpSender(); |
| 355 | } |
| 356 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 357 | // Test that the stream is muted when the track is disabled, and unmuted when |
| 358 | // the track is enabled. |
| 359 | TEST_F(RtpSenderReceiverTest, LocalAudioTrackDisable) { |
| 360 | CreateAudioRtpSender(); |
| 361 | |
| 362 | audio_track_->set_enabled(false); |
| 363 | EXPECT_TRUE(voice_media_channel_->IsStreamMuted(kAudioSsrc)); |
| 364 | |
| 365 | audio_track_->set_enabled(true); |
| 366 | EXPECT_FALSE(voice_media_channel_->IsStreamMuted(kAudioSsrc)); |
| 367 | |
| 368 | DestroyAudioRtpSender(); |
| 369 | } |
| 370 | |
| 371 | // Test that the volume is set to 0 when the track is disabled, and back to |
| 372 | // 1 when the track is enabled. |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 373 | TEST_F(RtpSenderReceiverTest, RemoteAudioTrackDisable) { |
| 374 | CreateAudioRtpReceiver(); |
| 375 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 376 | double volume; |
| 377 | EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume)); |
| 378 | EXPECT_EQ(1, volume); |
Taylor Brandstetter | 2d54917 | 2016-06-24 14:18:22 -0700 | [diff] [blame] | 379 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 380 | audio_track_->set_enabled(false); |
| 381 | EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume)); |
| 382 | EXPECT_EQ(0, volume); |
| 383 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 384 | audio_track_->set_enabled(true); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 385 | EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume)); |
| 386 | EXPECT_EQ(1, volume); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 387 | |
| 388 | DestroyAudioRtpReceiver(); |
| 389 | } |
| 390 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 391 | // Currently no action is taken when a remote video track is disabled or |
| 392 | // enabled, so there's nothing to test here, other than what is normally |
| 393 | // verified in DestroyVideoRtpSender. |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 394 | TEST_F(RtpSenderReceiverTest, LocalVideoTrackDisable) { |
| 395 | CreateVideoRtpSender(); |
| 396 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 397 | video_track_->set_enabled(false); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 398 | video_track_->set_enabled(true); |
| 399 | |
| 400 | DestroyVideoRtpSender(); |
| 401 | } |
| 402 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 403 | // Test that the state of the video track created by the VideoRtpReceiver is |
| 404 | // updated when the receiver is destroyed. |
perkj | f0dcfe2 | 2016-03-10 18:32:00 +0100 | [diff] [blame] | 405 | TEST_F(RtpSenderReceiverTest, RemoteVideoTrackState) { |
| 406 | CreateVideoRtpReceiver(); |
| 407 | |
| 408 | EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track_->state()); |
| 409 | EXPECT_EQ(webrtc::MediaSourceInterface::kLive, |
| 410 | video_track_->GetSource()->state()); |
| 411 | |
| 412 | DestroyVideoRtpReceiver(); |
| 413 | |
| 414 | EXPECT_EQ(webrtc::MediaStreamTrackInterface::kEnded, video_track_->state()); |
| 415 | EXPECT_EQ(webrtc::MediaSourceInterface::kEnded, |
| 416 | video_track_->GetSource()->state()); |
| 417 | } |
| 418 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 419 | // Currently no action is taken when a remote video track is disabled or |
| 420 | // enabled, so there's nothing to test here, other than what is normally |
| 421 | // verified in DestroyVideoRtpReceiver. |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 422 | TEST_F(RtpSenderReceiverTest, RemoteVideoTrackDisable) { |
| 423 | CreateVideoRtpReceiver(); |
| 424 | |
| 425 | video_track_->set_enabled(false); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 426 | video_track_->set_enabled(true); |
| 427 | |
| 428 | DestroyVideoRtpReceiver(); |
| 429 | } |
| 430 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 431 | // Test that the AudioRtpReceiver applies volume changes from the track source |
| 432 | // to the media channel. |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 433 | TEST_F(RtpSenderReceiverTest, RemoteAudioTrackSetVolume) { |
| 434 | CreateAudioRtpReceiver(); |
| 435 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 436 | double volume; |
| 437 | audio_track_->GetSource()->SetVolume(0.5); |
| 438 | EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume)); |
| 439 | EXPECT_EQ(0.5, volume); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 440 | |
| 441 | // Disable the audio track, this should prevent setting the volume. |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 442 | audio_track_->set_enabled(false); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 443 | audio_track_->GetSource()->SetVolume(0.8); |
| 444 | EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume)); |
| 445 | EXPECT_EQ(0, volume); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 446 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 447 | // When the track is enabled, the previously set volume should take effect. |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 448 | audio_track_->set_enabled(true); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 449 | EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume)); |
| 450 | EXPECT_EQ(0.8, volume); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 451 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 452 | // Try changing volume one more time. |
| 453 | audio_track_->GetSource()->SetVolume(0.9); |
| 454 | EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume)); |
| 455 | EXPECT_EQ(0.9, volume); |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 456 | |
| 457 | DestroyAudioRtpReceiver(); |
| 458 | } |
| 459 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 460 | // Test that the media channel isn't enabled for sending if the audio sender |
| 461 | // doesn't have both a track and SSRC. |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 462 | TEST_F(RtpSenderReceiverTest, AudioSenderWithoutTrackAndSsrc) { |
Steve Anton | 02ee47c | 2018-01-10 16:26:06 -0800 | [diff] [blame] | 463 | CreateAudioRtpSenderWithNoTrack(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 464 | rtc::scoped_refptr<AudioTrackInterface> track = |
| 465 | AudioTrack::Create(kAudioTrackId, nullptr); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 466 | |
| 467 | // Track but no SSRC. |
| 468 | EXPECT_TRUE(audio_rtp_sender_->SetTrack(track)); |
| 469 | VerifyVoiceChannelNoInput(); |
| 470 | |
| 471 | // SSRC but no track. |
| 472 | EXPECT_TRUE(audio_rtp_sender_->SetTrack(nullptr)); |
| 473 | audio_rtp_sender_->SetSsrc(kAudioSsrc); |
| 474 | VerifyVoiceChannelNoInput(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 475 | } |
| 476 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 477 | // Test that the media channel isn't enabled for sending if the video sender |
| 478 | // doesn't have both a track and SSRC. |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 479 | TEST_F(RtpSenderReceiverTest, VideoSenderWithoutTrackAndSsrc) { |
Steve Anton | 02ee47c | 2018-01-10 16:26:06 -0800 | [diff] [blame] | 480 | CreateVideoRtpSenderWithNoTrack(); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 481 | |
| 482 | // Track but no SSRC. |
| 483 | EXPECT_TRUE(video_rtp_sender_->SetTrack(video_track_)); |
| 484 | VerifyVideoChannelNoInput(); |
| 485 | |
| 486 | // SSRC but no track. |
| 487 | EXPECT_TRUE(video_rtp_sender_->SetTrack(nullptr)); |
| 488 | video_rtp_sender_->SetSsrc(kVideoSsrc); |
| 489 | VerifyVideoChannelNoInput(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 490 | } |
| 491 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 492 | // Test that the media channel is enabled for sending when the audio sender |
| 493 | // has a track and SSRC, when the SSRC is set first. |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 494 | TEST_F(RtpSenderReceiverTest, AudioSenderEarlyWarmupSsrcThenTrack) { |
Steve Anton | 02ee47c | 2018-01-10 16:26:06 -0800 | [diff] [blame] | 495 | CreateAudioRtpSenderWithNoTrack(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 496 | rtc::scoped_refptr<AudioTrackInterface> track = |
| 497 | AudioTrack::Create(kAudioTrackId, nullptr); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 498 | audio_rtp_sender_->SetSsrc(kAudioSsrc); |
| 499 | audio_rtp_sender_->SetTrack(track); |
| 500 | VerifyVoiceChannelInput(); |
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 | DestroyAudioRtpSender(); |
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 audio 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, AudioSenderEarlyWarmupTrackThenSsrc) { |
Steve Anton | 02ee47c | 2018-01-10 16:26:06 -0800 | [diff] [blame] | 508 | CreateAudioRtpSenderWithNoTrack(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 509 | rtc::scoped_refptr<AudioTrackInterface> track = |
| 510 | AudioTrack::Create(kAudioTrackId, nullptr); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 511 | audio_rtp_sender_->SetTrack(track); |
| 512 | audio_rtp_sender_->SetSsrc(kAudioSsrc); |
| 513 | VerifyVoiceChannelInput(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 514 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 515 | DestroyAudioRtpSender(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 516 | } |
| 517 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 518 | // Test that the media channel is enabled for sending when the video sender |
| 519 | // has a track and SSRC, when the SSRC is set first. |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 520 | TEST_F(RtpSenderReceiverTest, VideoSenderEarlyWarmupSsrcThenTrack) { |
nisse | af510af | 2016-03-21 08:20:42 -0700 | [diff] [blame] | 521 | AddVideoTrack(); |
Steve Anton | 02ee47c | 2018-01-10 16:26:06 -0800 | [diff] [blame] | 522 | CreateVideoRtpSenderWithNoTrack(); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 523 | video_rtp_sender_->SetSsrc(kVideoSsrc); |
| 524 | video_rtp_sender_->SetTrack(video_track_); |
| 525 | VerifyVideoChannelInput(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 526 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 527 | DestroyVideoRtpSender(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 528 | } |
| 529 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 530 | // Test that the media channel is enabled for sending when the video sender |
| 531 | // has a track and SSRC, when the SSRC is set last. |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 532 | TEST_F(RtpSenderReceiverTest, VideoSenderEarlyWarmupTrackThenSsrc) { |
nisse | af510af | 2016-03-21 08:20:42 -0700 | [diff] [blame] | 533 | AddVideoTrack(); |
Steve Anton | 02ee47c | 2018-01-10 16:26:06 -0800 | [diff] [blame] | 534 | CreateVideoRtpSenderWithNoTrack(); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 535 | video_rtp_sender_->SetTrack(video_track_); |
| 536 | video_rtp_sender_->SetSsrc(kVideoSsrc); |
| 537 | VerifyVideoChannelInput(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 538 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 539 | DestroyVideoRtpSender(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 540 | } |
| 541 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 542 | // Test that the media channel stops sending when the audio sender's SSRC is set |
| 543 | // to 0. |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 544 | TEST_F(RtpSenderReceiverTest, AudioSenderSsrcSetToZero) { |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 545 | CreateAudioRtpSender(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 546 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 547 | audio_rtp_sender_->SetSsrc(0); |
| 548 | VerifyVoiceChannelNoInput(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 549 | } |
| 550 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 551 | // Test that the media channel stops sending when the video sender's SSRC is set |
| 552 | // to 0. |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 553 | TEST_F(RtpSenderReceiverTest, VideoSenderSsrcSetToZero) { |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 554 | CreateAudioRtpSender(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 555 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 556 | audio_rtp_sender_->SetSsrc(0); |
| 557 | VerifyVideoChannelNoInput(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 558 | } |
| 559 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 560 | // Test that the media channel stops sending when the audio sender's track is |
| 561 | // set to null. |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 562 | TEST_F(RtpSenderReceiverTest, AudioSenderTrackSetToNull) { |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 563 | CreateAudioRtpSender(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 564 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 565 | EXPECT_TRUE(audio_rtp_sender_->SetTrack(nullptr)); |
| 566 | VerifyVoiceChannelNoInput(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 567 | } |
| 568 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 569 | // Test that the media channel stops sending when the video sender's track is |
| 570 | // set to null. |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 571 | TEST_F(RtpSenderReceiverTest, VideoSenderTrackSetToNull) { |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 572 | CreateVideoRtpSender(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 573 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 574 | video_rtp_sender_->SetSsrc(0); |
| 575 | VerifyVideoChannelNoInput(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 576 | } |
| 577 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 578 | // Test that when the audio sender's SSRC is changed, the media channel stops |
| 579 | // sending with the old SSRC and starts sending with the new one. |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 580 | TEST_F(RtpSenderReceiverTest, AudioSenderSsrcChanged) { |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 581 | CreateAudioRtpSender(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 582 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 583 | audio_rtp_sender_->SetSsrc(kAudioSsrc2); |
| 584 | VerifyVoiceChannelNoInput(kAudioSsrc); |
| 585 | VerifyVoiceChannelInput(kAudioSsrc2); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 586 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 587 | audio_rtp_sender_ = nullptr; |
| 588 | VerifyVoiceChannelNoInput(kAudioSsrc2); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 589 | } |
| 590 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 591 | // Test that when the audio sender's SSRC is changed, the media channel stops |
| 592 | // sending with the old SSRC and starts sending with the new one. |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 593 | TEST_F(RtpSenderReceiverTest, VideoSenderSsrcChanged) { |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 594 | CreateVideoRtpSender(); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 595 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 596 | video_rtp_sender_->SetSsrc(kVideoSsrc2); |
| 597 | VerifyVideoChannelNoInput(kVideoSsrc); |
| 598 | VerifyVideoChannelInput(kVideoSsrc2); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 599 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 600 | video_rtp_sender_ = nullptr; |
| 601 | VerifyVideoChannelNoInput(kVideoSsrc2); |
deadbeef | fac0655 | 2015-11-25 11:26:01 -0800 | [diff] [blame] | 602 | } |
| 603 | |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 604 | TEST_F(RtpSenderReceiverTest, AudioSenderCanSetParameters) { |
| 605 | CreateAudioRtpSender(); |
| 606 | |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 607 | RtpParameters params = audio_rtp_sender_->GetParameters(); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 608 | EXPECT_EQ(1u, params.encodings.size()); |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 609 | EXPECT_TRUE(audio_rtp_sender_->SetParameters(params).ok()); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 610 | |
| 611 | DestroyAudioRtpSender(); |
| 612 | } |
| 613 | |
Florent Castelli | cebf50f | 2018-05-03 15:31:53 +0200 | [diff] [blame] | 614 | TEST_F(RtpSenderReceiverTest, |
| 615 | AudioSenderMustCallGetParametersBeforeSetParameters) { |
| 616 | CreateAudioRtpSender(); |
| 617 | |
| 618 | RtpParameters params; |
| 619 | RTCError result = audio_rtp_sender_->SetParameters(params); |
| 620 | EXPECT_EQ(RTCErrorType::INVALID_STATE, result.type()); |
| 621 | |
| 622 | DestroyAudioRtpSender(); |
| 623 | } |
| 624 | |
| 625 | TEST_F(RtpSenderReceiverTest, |
| 626 | AudioSenderSetParametersInvalidatesTransactionId) { |
| 627 | CreateAudioRtpSender(); |
| 628 | |
| 629 | RtpParameters params = audio_rtp_sender_->GetParameters(); |
| 630 | EXPECT_EQ(1u, params.encodings.size()); |
| 631 | EXPECT_TRUE(audio_rtp_sender_->SetParameters(params).ok()); |
| 632 | RTCError result = audio_rtp_sender_->SetParameters(params); |
| 633 | EXPECT_EQ(RTCErrorType::INVALID_STATE, result.type()); |
| 634 | |
| 635 | DestroyAudioRtpSender(); |
| 636 | } |
| 637 | |
| 638 | TEST_F(RtpSenderReceiverTest, AudioSenderDetectTransactionIdModification) { |
| 639 | CreateAudioRtpSender(); |
| 640 | |
| 641 | RtpParameters params = audio_rtp_sender_->GetParameters(); |
| 642 | params.transaction_id = ""; |
| 643 | RTCError result = audio_rtp_sender_->SetParameters(params); |
| 644 | EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, result.type()); |
| 645 | |
| 646 | DestroyAudioRtpSender(); |
| 647 | } |
| 648 | |
| 649 | TEST_F(RtpSenderReceiverTest, AudioSenderCheckTransactionIdRefresh) { |
| 650 | CreateAudioRtpSender(); |
| 651 | |
| 652 | RtpParameters params = audio_rtp_sender_->GetParameters(); |
| 653 | EXPECT_NE(params.transaction_id.size(), 0); |
| 654 | auto saved_transaction_id = params.transaction_id; |
| 655 | params = audio_rtp_sender_->GetParameters(); |
| 656 | EXPECT_NE(saved_transaction_id, params.transaction_id); |
| 657 | |
| 658 | DestroyAudioRtpSender(); |
| 659 | } |
| 660 | |
| 661 | TEST_F(RtpSenderReceiverTest, AudioSenderSetParametersOldValueFail) { |
| 662 | CreateAudioRtpSender(); |
| 663 | |
| 664 | RtpParameters params = audio_rtp_sender_->GetParameters(); |
| 665 | RtpParameters second_params = audio_rtp_sender_->GetParameters(); |
| 666 | |
| 667 | RTCError result = audio_rtp_sender_->SetParameters(params); |
| 668 | EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, result.type()); |
Seth Hampson | 2d2c888 | 2018-05-16 16:02:32 -0700 | [diff] [blame] | 669 | DestroyAudioRtpSender(); |
| 670 | } |
| 671 | |
| 672 | TEST_F(RtpSenderReceiverTest, AudioSenderCantSetUnimplementedRtpParameters) { |
| 673 | CreateAudioRtpSender(); |
| 674 | RtpParameters params = audio_rtp_sender_->GetParameters(); |
| 675 | EXPECT_EQ(1u, params.encodings.size()); |
| 676 | |
| 677 | // Unimplemented RtpParameters: mid, header_extensions, |
| 678 | // degredation_preference. |
| 679 | params.mid = "dummy_mid"; |
| 680 | EXPECT_EQ(RTCErrorType::UNSUPPORTED_PARAMETER, |
| 681 | audio_rtp_sender_->SetParameters(params).type()); |
| 682 | params = audio_rtp_sender_->GetParameters(); |
| 683 | |
Seth Hampson | 2d2c888 | 2018-05-16 16:02:32 -0700 | [diff] [blame] | 684 | ASSERT_EQ(DegradationPreference::BALANCED, params.degradation_preference); |
| 685 | params.degradation_preference = DegradationPreference::MAINTAIN_FRAMERATE; |
| 686 | EXPECT_EQ(RTCErrorType::UNSUPPORTED_PARAMETER, |
| 687 | audio_rtp_sender_->SetParameters(params).type()); |
| 688 | |
| 689 | DestroyAudioRtpSender(); |
| 690 | } |
| 691 | |
| 692 | TEST_F(RtpSenderReceiverTest, |
| 693 | AudioSenderCantSetUnimplementedRtpEncodingParameters) { |
| 694 | CreateAudioRtpSender(); |
| 695 | RtpParameters params = audio_rtp_sender_->GetParameters(); |
| 696 | EXPECT_EQ(1u, params.encodings.size()); |
| 697 | |
| 698 | // Unimplemented RtpParameters: codec_payload_type, fec, rtx, dtx, ptime, |
| 699 | // max_framerate, scale_resolution_down_by, scale_framerate_down_by, rid, |
| 700 | // dependency_rids. |
| 701 | params.encodings[0].codec_payload_type = 1; |
| 702 | EXPECT_EQ(RTCErrorType::UNSUPPORTED_PARAMETER, |
| 703 | audio_rtp_sender_->SetParameters(params).type()); |
| 704 | params = audio_rtp_sender_->GetParameters(); |
| 705 | |
| 706 | params.encodings[0].fec = RtpFecParameters(); |
| 707 | EXPECT_EQ(RTCErrorType::UNSUPPORTED_PARAMETER, |
| 708 | audio_rtp_sender_->SetParameters(params).type()); |
| 709 | params = audio_rtp_sender_->GetParameters(); |
| 710 | |
| 711 | params.encodings[0].rtx = RtpRtxParameters(); |
| 712 | EXPECT_EQ(RTCErrorType::UNSUPPORTED_PARAMETER, |
| 713 | audio_rtp_sender_->SetParameters(params).type()); |
| 714 | params = audio_rtp_sender_->GetParameters(); |
| 715 | |
| 716 | params.encodings[0].dtx = DtxStatus::ENABLED; |
| 717 | EXPECT_EQ(RTCErrorType::UNSUPPORTED_PARAMETER, |
| 718 | audio_rtp_sender_->SetParameters(params).type()); |
| 719 | params = audio_rtp_sender_->GetParameters(); |
| 720 | |
| 721 | params.encodings[0].ptime = 1; |
| 722 | EXPECT_EQ(RTCErrorType::UNSUPPORTED_PARAMETER, |
| 723 | audio_rtp_sender_->SetParameters(params).type()); |
| 724 | params = audio_rtp_sender_->GetParameters(); |
| 725 | |
| 726 | params.encodings[0].max_framerate = 1; |
| 727 | EXPECT_EQ(RTCErrorType::UNSUPPORTED_PARAMETER, |
| 728 | audio_rtp_sender_->SetParameters(params).type()); |
| 729 | params = audio_rtp_sender_->GetParameters(); |
| 730 | |
| 731 | params.encodings[0].scale_resolution_down_by = 2.0; |
| 732 | EXPECT_EQ(RTCErrorType::UNSUPPORTED_PARAMETER, |
| 733 | audio_rtp_sender_->SetParameters(params).type()); |
| 734 | params = audio_rtp_sender_->GetParameters(); |
| 735 | |
| 736 | params.encodings[0].rid = "dummy_rid"; |
| 737 | EXPECT_EQ(RTCErrorType::UNSUPPORTED_PARAMETER, |
| 738 | audio_rtp_sender_->SetParameters(params).type()); |
| 739 | params = audio_rtp_sender_->GetParameters(); |
| 740 | |
| 741 | params.encodings[0].dependency_rids.push_back("dummy_rid"); |
| 742 | EXPECT_EQ(RTCErrorType::UNSUPPORTED_PARAMETER, |
| 743 | audio_rtp_sender_->SetParameters(params).type()); |
Florent Castelli | cebf50f | 2018-05-03 15:31:53 +0200 | [diff] [blame] | 744 | |
| 745 | DestroyAudioRtpSender(); |
| 746 | } |
| 747 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 748 | TEST_F(RtpSenderReceiverTest, SetAudioMaxSendBitrate) { |
| 749 | CreateAudioRtpSender(); |
| 750 | |
| 751 | EXPECT_EQ(-1, voice_media_channel_->max_bps()); |
| 752 | webrtc::RtpParameters params = audio_rtp_sender_->GetParameters(); |
| 753 | EXPECT_EQ(1, params.encodings.size()); |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 754 | EXPECT_FALSE(params.encodings[0].max_bitrate_bps); |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 755 | params.encodings[0].max_bitrate_bps = 1000; |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 756 | EXPECT_TRUE(audio_rtp_sender_->SetParameters(params).ok()); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 757 | |
| 758 | // Read back the parameters and verify they have been changed. |
| 759 | params = audio_rtp_sender_->GetParameters(); |
| 760 | EXPECT_EQ(1, params.encodings.size()); |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 761 | EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 762 | |
| 763 | // Verify that the audio channel received the new parameters. |
| 764 | params = voice_media_channel_->GetRtpSendParameters(kAudioSsrc); |
| 765 | EXPECT_EQ(1, params.encodings.size()); |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 766 | EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 767 | |
| 768 | // Verify that the global bitrate limit has not been changed. |
| 769 | EXPECT_EQ(-1, voice_media_channel_->max_bps()); |
| 770 | |
| 771 | DestroyAudioRtpSender(); |
| 772 | } |
| 773 | |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 774 | TEST_F(RtpSenderReceiverTest, SetAudioBitratePriority) { |
| 775 | CreateAudioRtpSender(); |
| 776 | |
| 777 | webrtc::RtpParameters params = audio_rtp_sender_->GetParameters(); |
| 778 | EXPECT_EQ(1, params.encodings.size()); |
| 779 | EXPECT_EQ(webrtc::kDefaultBitratePriority, |
| 780 | params.encodings[0].bitrate_priority); |
| 781 | double new_bitrate_priority = 2.0; |
| 782 | params.encodings[0].bitrate_priority = new_bitrate_priority; |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 783 | EXPECT_TRUE(audio_rtp_sender_->SetParameters(params).ok()); |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 784 | |
| 785 | params = audio_rtp_sender_->GetParameters(); |
| 786 | EXPECT_EQ(1, params.encodings.size()); |
| 787 | EXPECT_EQ(new_bitrate_priority, params.encodings[0].bitrate_priority); |
| 788 | |
| 789 | params = voice_media_channel_->GetRtpSendParameters(kAudioSsrc); |
| 790 | EXPECT_EQ(1, params.encodings.size()); |
| 791 | EXPECT_EQ(new_bitrate_priority, params.encodings[0].bitrate_priority); |
| 792 | |
| 793 | DestroyAudioRtpSender(); |
| 794 | } |
| 795 | |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 796 | TEST_F(RtpSenderReceiverTest, VideoSenderCanSetParameters) { |
| 797 | CreateVideoRtpSender(); |
| 798 | |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 799 | RtpParameters params = video_rtp_sender_->GetParameters(); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 800 | EXPECT_EQ(1u, params.encodings.size()); |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 801 | EXPECT_TRUE(video_rtp_sender_->SetParameters(params).ok()); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 802 | |
| 803 | DestroyVideoRtpSender(); |
| 804 | } |
| 805 | |
Florent Castelli | cebf50f | 2018-05-03 15:31:53 +0200 | [diff] [blame] | 806 | TEST_F(RtpSenderReceiverTest, |
| 807 | VideoSenderMustCallGetParametersBeforeSetParameters) { |
| 808 | CreateVideoRtpSender(); |
| 809 | |
| 810 | RtpParameters params; |
| 811 | RTCError result = video_rtp_sender_->SetParameters(params); |
| 812 | EXPECT_EQ(RTCErrorType::INVALID_STATE, result.type()); |
| 813 | |
| 814 | DestroyVideoRtpSender(); |
| 815 | } |
| 816 | |
| 817 | TEST_F(RtpSenderReceiverTest, |
| 818 | VideoSenderSetParametersInvalidatesTransactionId) { |
| 819 | CreateVideoRtpSender(); |
| 820 | |
| 821 | RtpParameters params = video_rtp_sender_->GetParameters(); |
| 822 | EXPECT_EQ(1u, params.encodings.size()); |
| 823 | EXPECT_TRUE(video_rtp_sender_->SetParameters(params).ok()); |
| 824 | RTCError result = video_rtp_sender_->SetParameters(params); |
| 825 | EXPECT_EQ(RTCErrorType::INVALID_STATE, result.type()); |
| 826 | |
| 827 | DestroyVideoRtpSender(); |
| 828 | } |
| 829 | |
| 830 | TEST_F(RtpSenderReceiverTest, VideoSenderDetectTransactionIdModification) { |
| 831 | CreateVideoRtpSender(); |
| 832 | |
| 833 | RtpParameters params = video_rtp_sender_->GetParameters(); |
| 834 | params.transaction_id = ""; |
| 835 | RTCError result = video_rtp_sender_->SetParameters(params); |
| 836 | EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, result.type()); |
| 837 | |
| 838 | DestroyVideoRtpSender(); |
| 839 | } |
| 840 | |
| 841 | TEST_F(RtpSenderReceiverTest, VideoSenderCheckTransactionIdRefresh) { |
| 842 | CreateVideoRtpSender(); |
| 843 | |
| 844 | RtpParameters params = video_rtp_sender_->GetParameters(); |
| 845 | EXPECT_NE(params.transaction_id.size(), 0); |
| 846 | auto saved_transaction_id = params.transaction_id; |
| 847 | params = video_rtp_sender_->GetParameters(); |
| 848 | EXPECT_NE(saved_transaction_id, params.transaction_id); |
| 849 | |
| 850 | DestroyVideoRtpSender(); |
| 851 | } |
| 852 | |
| 853 | TEST_F(RtpSenderReceiverTest, VideoSenderSetParametersOldValueFail) { |
| 854 | CreateVideoRtpSender(); |
| 855 | |
| 856 | RtpParameters params = video_rtp_sender_->GetParameters(); |
| 857 | RtpParameters second_params = video_rtp_sender_->GetParameters(); |
| 858 | |
| 859 | RTCError result = video_rtp_sender_->SetParameters(params); |
| 860 | EXPECT_EQ(RTCErrorType::INVALID_MODIFICATION, result.type()); |
| 861 | |
| 862 | DestroyVideoRtpSender(); |
| 863 | } |
| 864 | |
Seth Hampson | 2d2c888 | 2018-05-16 16:02:32 -0700 | [diff] [blame] | 865 | TEST_F(RtpSenderReceiverTest, VideoSenderCantSetUnimplementedRtpParameters) { |
| 866 | CreateVideoRtpSender(); |
| 867 | RtpParameters params = video_rtp_sender_->GetParameters(); |
| 868 | EXPECT_EQ(1u, params.encodings.size()); |
| 869 | |
| 870 | // Unimplemented RtpParameters: mid, header_extensions, |
| 871 | // degredation_preference. |
| 872 | params.mid = "dummy_mid"; |
| 873 | EXPECT_EQ(RTCErrorType::UNSUPPORTED_PARAMETER, |
| 874 | video_rtp_sender_->SetParameters(params).type()); |
| 875 | params = video_rtp_sender_->GetParameters(); |
| 876 | |
Seth Hampson | 2d2c888 | 2018-05-16 16:02:32 -0700 | [diff] [blame] | 877 | ASSERT_EQ(DegradationPreference::BALANCED, params.degradation_preference); |
| 878 | params.degradation_preference = DegradationPreference::MAINTAIN_FRAMERATE; |
| 879 | EXPECT_EQ(RTCErrorType::UNSUPPORTED_PARAMETER, |
| 880 | video_rtp_sender_->SetParameters(params).type()); |
| 881 | |
| 882 | DestroyVideoRtpSender(); |
| 883 | } |
| 884 | |
| 885 | TEST_F(RtpSenderReceiverTest, |
| 886 | VideoSenderCantSetUnimplementedEncodingParameters) { |
| 887 | CreateVideoRtpSender(); |
| 888 | RtpParameters params = video_rtp_sender_->GetParameters(); |
| 889 | EXPECT_EQ(1u, params.encodings.size()); |
| 890 | |
| 891 | // Unimplemented RtpParameters: codec_payload_type, fec, rtx, dtx, ptime, |
| 892 | // max_framerate, scale_resolution_down_by, scale_framerate_down_by, rid, |
| 893 | // dependency_rids. |
| 894 | params.encodings[0].codec_payload_type = 1; |
| 895 | EXPECT_EQ(RTCErrorType::UNSUPPORTED_PARAMETER, |
| 896 | video_rtp_sender_->SetParameters(params).type()); |
| 897 | params = video_rtp_sender_->GetParameters(); |
| 898 | |
| 899 | params.encodings[0].fec = RtpFecParameters(); |
| 900 | EXPECT_EQ(RTCErrorType::UNSUPPORTED_PARAMETER, |
| 901 | video_rtp_sender_->SetParameters(params).type()); |
| 902 | params = video_rtp_sender_->GetParameters(); |
| 903 | |
| 904 | params.encodings[0].rtx = RtpRtxParameters(); |
| 905 | EXPECT_EQ(RTCErrorType::UNSUPPORTED_PARAMETER, |
| 906 | video_rtp_sender_->SetParameters(params).type()); |
| 907 | params = video_rtp_sender_->GetParameters(); |
| 908 | |
| 909 | params.encodings[0].dtx = DtxStatus::ENABLED; |
| 910 | EXPECT_EQ(RTCErrorType::UNSUPPORTED_PARAMETER, |
| 911 | video_rtp_sender_->SetParameters(params).type()); |
| 912 | params = video_rtp_sender_->GetParameters(); |
| 913 | |
| 914 | params.encodings[0].ptime = 1; |
| 915 | EXPECT_EQ(RTCErrorType::UNSUPPORTED_PARAMETER, |
| 916 | video_rtp_sender_->SetParameters(params).type()); |
| 917 | params = video_rtp_sender_->GetParameters(); |
| 918 | |
| 919 | params.encodings[0].max_framerate = 1; |
| 920 | EXPECT_EQ(RTCErrorType::UNSUPPORTED_PARAMETER, |
| 921 | video_rtp_sender_->SetParameters(params).type()); |
| 922 | params = video_rtp_sender_->GetParameters(); |
| 923 | |
| 924 | params.encodings[0].scale_resolution_down_by = 2.0; |
| 925 | EXPECT_EQ(RTCErrorType::UNSUPPORTED_PARAMETER, |
| 926 | video_rtp_sender_->SetParameters(params).type()); |
| 927 | params = video_rtp_sender_->GetParameters(); |
| 928 | |
| 929 | params.encodings[0].rid = "dummy_rid"; |
| 930 | EXPECT_EQ(RTCErrorType::UNSUPPORTED_PARAMETER, |
| 931 | video_rtp_sender_->SetParameters(params).type()); |
| 932 | params = video_rtp_sender_->GetParameters(); |
| 933 | |
| 934 | params.encodings[0].dependency_rids.push_back("dummy_rid"); |
| 935 | EXPECT_EQ(RTCErrorType::UNSUPPORTED_PARAMETER, |
| 936 | video_rtp_sender_->SetParameters(params).type()); |
| 937 | |
| 938 | DestroyVideoRtpSender(); |
| 939 | } |
| 940 | |
| 941 | // A video sender can have multiple simulcast layers, in which case it will |
| 942 | // contain multiple RtpEncodingParameters. This tests that if this is the case |
| 943 | // (simulcast), then we can't set the bitrate_priority, or max_bitrate_bps |
| 944 | // for any encodings besides at index 0, because these are both implemented |
| 945 | // "per-sender." |
| 946 | TEST_F(RtpSenderReceiverTest, VideoSenderCantSetPerSenderEncodingParameters) { |
| 947 | // Add a simulcast specific send stream that contains 2 encoding parameters. |
| 948 | std::vector<uint32_t> ssrcs({1, 2}); |
| 949 | cricket::StreamParams stream_params = |
| 950 | cricket::CreateSimStreamParams("cname", ssrcs); |
| 951 | video_media_channel_->AddSendStream(stream_params); |
| 952 | uint32_t primary_ssrc = stream_params.first_ssrc(); |
| 953 | CreateVideoRtpSender(primary_ssrc); |
| 954 | RtpParameters params = video_rtp_sender_->GetParameters(); |
| 955 | EXPECT_EQ(ssrcs.size(), params.encodings.size()); |
| 956 | |
| 957 | params.encodings[1].bitrate_priority = 2.0; |
| 958 | EXPECT_EQ(RTCErrorType::UNSUPPORTED_PARAMETER, |
| 959 | video_rtp_sender_->SetParameters(params).type()); |
| 960 | params = video_rtp_sender_->GetParameters(); |
| 961 | |
| 962 | params.encodings[1].max_bitrate_bps = 200000; |
| 963 | EXPECT_EQ(RTCErrorType::UNSUPPORTED_PARAMETER, |
| 964 | video_rtp_sender_->SetParameters(params).type()); |
| 965 | |
| 966 | DestroyVideoRtpSender(); |
| 967 | } |
| 968 | |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 969 | TEST_F(RtpSenderReceiverTest, SetVideoMaxSendBitrate) { |
| 970 | CreateVideoRtpSender(); |
| 971 | |
| 972 | EXPECT_EQ(-1, video_media_channel_->max_bps()); |
| 973 | webrtc::RtpParameters params = video_rtp_sender_->GetParameters(); |
| 974 | EXPECT_EQ(1, params.encodings.size()); |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 975 | EXPECT_FALSE(params.encodings[0].max_bitrate_bps); |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 976 | params.encodings[0].max_bitrate_bps = 1000; |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 977 | EXPECT_TRUE(video_rtp_sender_->SetParameters(params).ok()); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 978 | |
| 979 | // Read back the parameters and verify they have been changed. |
| 980 | params = video_rtp_sender_->GetParameters(); |
| 981 | EXPECT_EQ(1, params.encodings.size()); |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 982 | EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 983 | |
| 984 | // Verify that the video channel received the new parameters. |
| 985 | params = video_media_channel_->GetRtpSendParameters(kVideoSsrc); |
| 986 | EXPECT_EQ(1, params.encodings.size()); |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 987 | EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 988 | |
| 989 | // Verify that the global bitrate limit has not been changed. |
| 990 | EXPECT_EQ(-1, video_media_channel_->max_bps()); |
| 991 | |
| 992 | DestroyVideoRtpSender(); |
| 993 | } |
| 994 | |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 995 | TEST_F(RtpSenderReceiverTest, SetVideoBitratePriority) { |
| 996 | CreateVideoRtpSender(); |
| 997 | |
| 998 | webrtc::RtpParameters params = video_rtp_sender_->GetParameters(); |
| 999 | EXPECT_EQ(1, params.encodings.size()); |
| 1000 | EXPECT_EQ(webrtc::kDefaultBitratePriority, |
| 1001 | params.encodings[0].bitrate_priority); |
| 1002 | double new_bitrate_priority = 2.0; |
| 1003 | params.encodings[0].bitrate_priority = new_bitrate_priority; |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 1004 | EXPECT_TRUE(video_rtp_sender_->SetParameters(params).ok()); |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 1005 | |
| 1006 | params = video_rtp_sender_->GetParameters(); |
| 1007 | EXPECT_EQ(1, params.encodings.size()); |
| 1008 | EXPECT_EQ(new_bitrate_priority, params.encodings[0].bitrate_priority); |
| 1009 | |
| 1010 | params = video_media_channel_->GetRtpSendParameters(kVideoSsrc); |
| 1011 | EXPECT_EQ(1, params.encodings.size()); |
| 1012 | EXPECT_EQ(new_bitrate_priority, params.encodings[0].bitrate_priority); |
| 1013 | |
| 1014 | DestroyVideoRtpSender(); |
| 1015 | } |
| 1016 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 1017 | TEST_F(RtpSenderReceiverTest, AudioReceiverCanSetParameters) { |
| 1018 | CreateAudioRtpReceiver(); |
| 1019 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 1020 | RtpParameters params = audio_rtp_receiver_->GetParameters(); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 1021 | EXPECT_EQ(1u, params.encodings.size()); |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 1022 | EXPECT_TRUE(audio_rtp_receiver_->SetParameters(params)); |
| 1023 | |
| 1024 | DestroyAudioRtpReceiver(); |
| 1025 | } |
| 1026 | |
| 1027 | TEST_F(RtpSenderReceiverTest, VideoReceiverCanSetParameters) { |
| 1028 | CreateVideoRtpReceiver(); |
| 1029 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 1030 | RtpParameters params = video_rtp_receiver_->GetParameters(); |
Taylor Brandstetter | ba29c6a | 2016-06-27 16:30:35 -0700 | [diff] [blame] | 1031 | EXPECT_EQ(1u, params.encodings.size()); |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 1032 | EXPECT_TRUE(video_rtp_receiver_->SetParameters(params)); |
| 1033 | |
| 1034 | DestroyVideoRtpReceiver(); |
| 1035 | } |
| 1036 | |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 1037 | // Test that makes sure that a video track content hint translates to the proper |
| 1038 | // value for sources that are not screencast. |
| 1039 | TEST_F(RtpSenderReceiverTest, PropagatesVideoTrackContentHint) { |
| 1040 | CreateVideoRtpSender(); |
| 1041 | |
| 1042 | video_track_->set_enabled(true); |
| 1043 | |
| 1044 | // |video_track_| is not screencast by default. |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 1045 | EXPECT_EQ(false, video_media_channel_->options().is_screencast); |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 1046 | // No content hint should be set by default. |
| 1047 | EXPECT_EQ(VideoTrackInterface::ContentHint::kNone, |
| 1048 | video_track_->content_hint()); |
| 1049 | // Setting detailed should turn a non-screencast source into screencast mode. |
| 1050 | video_track_->set_content_hint(VideoTrackInterface::ContentHint::kDetailed); |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 1051 | EXPECT_EQ(true, video_media_channel_->options().is_screencast); |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 1052 | // Removing the content hint should turn the track back into non-screencast |
| 1053 | // mode. |
| 1054 | video_track_->set_content_hint(VideoTrackInterface::ContentHint::kNone); |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 1055 | EXPECT_EQ(false, video_media_channel_->options().is_screencast); |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 1056 | // Setting fluid should remain in non-screencast mode (its default). |
| 1057 | video_track_->set_content_hint(VideoTrackInterface::ContentHint::kFluid); |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 1058 | EXPECT_EQ(false, video_media_channel_->options().is_screencast); |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 1059 | |
| 1060 | DestroyVideoRtpSender(); |
| 1061 | } |
| 1062 | |
| 1063 | // Test that makes sure that a video track content hint translates to the proper |
| 1064 | // value for screencast sources. |
| 1065 | TEST_F(RtpSenderReceiverTest, |
| 1066 | PropagatesVideoTrackContentHintForScreencastSource) { |
| 1067 | CreateVideoRtpSender(true); |
| 1068 | |
| 1069 | video_track_->set_enabled(true); |
| 1070 | |
| 1071 | // |video_track_| with a screencast source should be screencast by default. |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 1072 | EXPECT_EQ(true, video_media_channel_->options().is_screencast); |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 1073 | // No content hint should be set by default. |
| 1074 | EXPECT_EQ(VideoTrackInterface::ContentHint::kNone, |
| 1075 | video_track_->content_hint()); |
| 1076 | // Setting fluid should turn a screencast source into non-screencast mode. |
| 1077 | video_track_->set_content_hint(VideoTrackInterface::ContentHint::kFluid); |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 1078 | EXPECT_EQ(false, video_media_channel_->options().is_screencast); |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 1079 | // Removing the content hint should turn the track back into screencast mode. |
| 1080 | video_track_->set_content_hint(VideoTrackInterface::ContentHint::kNone); |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 1081 | EXPECT_EQ(true, video_media_channel_->options().is_screencast); |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 1082 | // Setting detailed should still remain in screencast mode (its default). |
| 1083 | video_track_->set_content_hint(VideoTrackInterface::ContentHint::kDetailed); |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 1084 | EXPECT_EQ(true, video_media_channel_->options().is_screencast); |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 1085 | |
| 1086 | DestroyVideoRtpSender(); |
| 1087 | } |
| 1088 | |
| 1089 | // Test that makes sure any content hints that are set on a track before |
| 1090 | // VideoRtpSender is ready to send are still applied when it gets ready to send. |
| 1091 | TEST_F(RtpSenderReceiverTest, |
| 1092 | PropagatesVideoTrackContentHintSetBeforeEnabling) { |
| 1093 | AddVideoTrack(); |
| 1094 | // Setting detailed overrides the default non-screencast mode. This should be |
| 1095 | // applied even if the track is set on construction. |
| 1096 | video_track_->set_content_hint(VideoTrackInterface::ContentHint::kDetailed); |
Seth Hampson | 13b8bad | 2018-03-13 16:05:28 -0700 | [diff] [blame] | 1097 | video_rtp_sender_ = |
| 1098 | new VideoRtpSender(worker_thread_, local_stream_->GetVideoTracks()[0], |
| 1099 | {local_stream_->id()}); |
Steve Anton | 57858b3 | 2018-02-15 15:19:50 -0800 | [diff] [blame] | 1100 | video_rtp_sender_->SetVideoMediaChannel(video_media_channel_); |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 1101 | video_track_->set_enabled(true); |
| 1102 | |
| 1103 | // 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] | 1104 | EXPECT_EQ(rtc::nullopt, video_media_channel_->options().is_screencast); |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 1105 | |
| 1106 | // Verify that the content hint is accounted for when video_rtp_sender_ does |
| 1107 | // get enabled. |
| 1108 | video_rtp_sender_->SetSsrc(kVideoSsrc); |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 1109 | EXPECT_EQ(true, video_media_channel_->options().is_screencast); |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 1110 | |
| 1111 | // And removing the hint should go back to false (to verify that false was |
| 1112 | // default correctly). |
| 1113 | video_track_->set_content_hint(VideoTrackInterface::ContentHint::kNone); |
Oskar Sundbom | 36f8f3e | 2017-11-16 10:54:27 +0100 | [diff] [blame] | 1114 | EXPECT_EQ(false, video_media_channel_->options().is_screencast); |
pbos | 5214a0a | 2016-12-16 15:39:11 -0800 | [diff] [blame] | 1115 | |
| 1116 | DestroyVideoRtpSender(); |
| 1117 | } |
| 1118 | |
deadbeef | 20cb0c1 | 2017-02-01 20:27:00 -0800 | [diff] [blame] | 1119 | TEST_F(RtpSenderReceiverTest, AudioSenderHasDtmfSender) { |
| 1120 | CreateAudioRtpSender(); |
| 1121 | EXPECT_NE(nullptr, audio_rtp_sender_->GetDtmfSender()); |
| 1122 | } |
| 1123 | |
| 1124 | TEST_F(RtpSenderReceiverTest, VideoSenderDoesNotHaveDtmfSender) { |
| 1125 | CreateVideoRtpSender(); |
| 1126 | EXPECT_EQ(nullptr, video_rtp_sender_->GetDtmfSender()); |
| 1127 | } |
| 1128 | |
| 1129 | // Test that the DTMF sender is really using |voice_channel_|, and thus returns |
| 1130 | // true/false from CanSendDtmf based on what |voice_channel_| returns. |
| 1131 | TEST_F(RtpSenderReceiverTest, CanInsertDtmf) { |
| 1132 | AddDtmfCodec(); |
| 1133 | CreateAudioRtpSender(); |
| 1134 | auto dtmf_sender = audio_rtp_sender_->GetDtmfSender(); |
| 1135 | ASSERT_NE(nullptr, dtmf_sender); |
| 1136 | EXPECT_TRUE(dtmf_sender->CanInsertDtmf()); |
| 1137 | } |
| 1138 | |
| 1139 | TEST_F(RtpSenderReceiverTest, CanNotInsertDtmf) { |
| 1140 | CreateAudioRtpSender(); |
| 1141 | auto dtmf_sender = audio_rtp_sender_->GetDtmfSender(); |
| 1142 | ASSERT_NE(nullptr, dtmf_sender); |
| 1143 | // DTMF codec has not been added, as it was in the above test. |
| 1144 | EXPECT_FALSE(dtmf_sender->CanInsertDtmf()); |
| 1145 | } |
| 1146 | |
| 1147 | TEST_F(RtpSenderReceiverTest, InsertDtmf) { |
| 1148 | AddDtmfCodec(); |
| 1149 | CreateAudioRtpSender(); |
| 1150 | auto dtmf_sender = audio_rtp_sender_->GetDtmfSender(); |
| 1151 | ASSERT_NE(nullptr, dtmf_sender); |
| 1152 | |
| 1153 | EXPECT_EQ(0U, voice_media_channel_->dtmf_info_queue().size()); |
| 1154 | |
| 1155 | // Insert DTMF |
| 1156 | const int expected_duration = 90; |
| 1157 | dtmf_sender->InsertDtmf("012", expected_duration, 100); |
| 1158 | |
| 1159 | // Verify |
| 1160 | ASSERT_EQ_WAIT(3U, voice_media_channel_->dtmf_info_queue().size(), |
| 1161 | kDefaultTimeout); |
| 1162 | const uint32_t send_ssrc = |
| 1163 | voice_media_channel_->send_streams()[0].first_ssrc(); |
| 1164 | EXPECT_TRUE(CompareDtmfInfo(voice_media_channel_->dtmf_info_queue()[0], |
| 1165 | send_ssrc, 0, expected_duration)); |
| 1166 | EXPECT_TRUE(CompareDtmfInfo(voice_media_channel_->dtmf_info_queue()[1], |
| 1167 | send_ssrc, 1, expected_duration)); |
| 1168 | EXPECT_TRUE(CompareDtmfInfo(voice_media_channel_->dtmf_info_queue()[2], |
| 1169 | send_ssrc, 2, expected_duration)); |
| 1170 | } |
| 1171 | |
| 1172 | // Make sure the signal from "GetOnDestroyedSignal()" fires when the sender is |
| 1173 | // destroyed, which is needed for the DTMF sender. |
| 1174 | TEST_F(RtpSenderReceiverTest, TestOnDestroyedSignal) { |
| 1175 | CreateAudioRtpSender(); |
| 1176 | EXPECT_FALSE(audio_sender_destroyed_signal_fired_); |
| 1177 | audio_rtp_sender_ = nullptr; |
| 1178 | EXPECT_TRUE(audio_sender_destroyed_signal_fired_); |
| 1179 | } |
| 1180 | |
deadbeef | 70ab1a1 | 2015-09-28 16:53:55 -0700 | [diff] [blame] | 1181 | } // namespace webrtc |