jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 1 | /* |
kjellander | 65c7f67 | 2016-02-12 00:05:01 -0800 | [diff] [blame] | 2 | * Copyright 2009 The WebRTC project authors. All Rights Reserved. |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 3 | * |
kjellander | 65c7f67 | 2016-02-12 00:05:01 -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. |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 9 | */ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 10 | |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 11 | #include <memory> |
| 12 | |
tfarina | 5237aaf | 2015-11-10 23:44:30 -0800 | [diff] [blame] | 13 | #include "webrtc/base/arraysize.h" |
buildbot@webrtc.org | 65b98d1 | 2014-08-07 22:09:08 +0000 | [diff] [blame] | 14 | #include "webrtc/base/fileutils.h" |
| 15 | #include "webrtc/base/gunit.h" |
| 16 | #include "webrtc/base/helpers.h" |
| 17 | #include "webrtc/base/logging.h" |
| 18 | #include "webrtc/base/pathutils.h" |
| 19 | #include "webrtc/base/signalthread.h" |
| 20 | #include "webrtc/base/ssladapter.h" |
| 21 | #include "webrtc/base/sslidentity.h" |
| 22 | #include "webrtc/base/window.h" |
kjellander | a96e2d7 | 2016-02-04 23:52:28 -0800 | [diff] [blame] | 23 | #include "webrtc/media/base/fakemediaengine.h" |
| 24 | #include "webrtc/media/base/fakertp.h" |
| 25 | #include "webrtc/media/base/fakescreencapturerfactory.h" |
| 26 | #include "webrtc/media/base/fakevideocapturer.h" |
| 27 | #include "webrtc/media/base/mediachannel.h" |
| 28 | #include "webrtc/media/base/rtpdump.h" |
| 29 | #include "webrtc/media/base/screencastid.h" |
| 30 | #include "webrtc/media/base/testutils.h" |
Tommi | f888bb5 | 2015-12-12 01:37:01 +0100 | [diff] [blame] | 31 | #include "webrtc/p2p/base/faketransportcontroller.h" |
kjellander@webrtc.org | 9b8df25 | 2016-02-12 06:47:59 +0100 | [diff] [blame] | 32 | #include "webrtc/pc/channel.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 33 | |
| 34 | #define MAYBE_SKIP_TEST(feature) \ |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 35 | if (!(rtc::SSLStreamAdapter::feature())) { \ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 36 | LOG(LS_INFO) << "Feature disabled... skipping"; \ |
| 37 | return; \ |
| 38 | } |
| 39 | |
| 40 | using cricket::CA_OFFER; |
| 41 | using cricket::CA_PRANSWER; |
| 42 | using cricket::CA_ANSWER; |
| 43 | using cricket::CA_UPDATE; |
| 44 | using cricket::FakeVoiceMediaChannel; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 45 | using cricket::ScreencastId; |
| 46 | using cricket::StreamParams; |
| 47 | using cricket::TransportChannel; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 48 | using rtc::WindowId; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 49 | |
| 50 | static const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1, 0); |
| 51 | static const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1, 0); |
| 52 | static const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1, 0); |
| 53 | static const cricket::VideoCodec kH264Codec(97, "H264", 640, 400, 30, 0); |
| 54 | static const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC", 320, 200, 15, 0); |
| 55 | static const cricket::DataCodec kGoogleDataCodec(101, "google-data", 0); |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 56 | static const uint32_t kSsrc1 = 0x1111; |
| 57 | static const uint32_t kSsrc2 = 0x2222; |
| 58 | static const uint32_t kSsrc3 = 0x3333; |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 59 | static const int kAudioPts[] = {0, 8}; |
| 60 | static const int kVideoPts[] = {97, 99}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 61 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 62 | template <class ChannelT, |
| 63 | class MediaChannelT, |
| 64 | class ContentT, |
| 65 | class CodecT, |
| 66 | class MediaInfoT, |
| 67 | class OptionsT> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 68 | class Traits { |
| 69 | public: |
| 70 | typedef ChannelT Channel; |
| 71 | typedef MediaChannelT MediaChannel; |
| 72 | typedef ContentT Content; |
| 73 | typedef CodecT Codec; |
| 74 | typedef MediaInfoT MediaInfo; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 75 | typedef OptionsT Options; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 76 | }; |
| 77 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 78 | // Controls how long we wait for a session to send messages that we |
| 79 | // expect, in milliseconds. We put it high to avoid flaky tests. |
| 80 | static const int kEventTimeout = 5000; |
| 81 | |
| 82 | class VoiceTraits : public Traits<cricket::VoiceChannel, |
| 83 | cricket::FakeVoiceMediaChannel, |
| 84 | cricket::AudioContentDescription, |
| 85 | cricket::AudioCodec, |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 86 | cricket::VoiceMediaInfo, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 87 | cricket::AudioOptions> {}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 88 | |
| 89 | class VideoTraits : public Traits<cricket::VideoChannel, |
| 90 | cricket::FakeVideoMediaChannel, |
| 91 | cricket::VideoContentDescription, |
| 92 | cricket::VideoCodec, |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 93 | cricket::VideoMediaInfo, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 94 | cricket::VideoOptions> {}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 95 | |
| 96 | class DataTraits : public Traits<cricket::DataChannel, |
| 97 | cricket::FakeDataMediaChannel, |
| 98 | cricket::DataContentDescription, |
| 99 | cricket::DataCodec, |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 100 | cricket::DataMediaInfo, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 101 | cricket::DataOptions> {}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 102 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 103 | rtc::StreamInterface* Open(const std::string& path) { |
| 104 | return rtc::Filesystem::OpenFile( |
| 105 | rtc::Pathname(path), "wb"); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | // Base class for Voice/VideoChannel tests |
| 109 | template<class T> |
| 110 | class ChannelTest : public testing::Test, public sigslot::has_slots<> { |
| 111 | public: |
| 112 | enum Flags { RTCP = 0x1, RTCP_MUX = 0x2, SECURE = 0x4, SSRC_MUX = 0x8, |
| 113 | DTLS = 0x10 }; |
| 114 | |
Peter Boström | 34fbfff | 2015-09-24 19:20:30 +0200 | [diff] [blame] | 115 | ChannelTest(bool verify_playout, |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 116 | const uint8_t* rtp_data, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 117 | int rtp_len, |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 118 | const uint8_t* rtcp_data, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 119 | int rtcp_len) |
Peter Boström | 34fbfff | 2015-09-24 19:20:30 +0200 | [diff] [blame] | 120 | : verify_playout_(verify_playout), |
| 121 | transport_controller1_(cricket::ICEROLE_CONTROLLING), |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 122 | transport_controller2_(cricket::ICEROLE_CONTROLLED), |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 123 | media_channel1_(NULL), |
| 124 | media_channel2_(NULL), |
| 125 | rtp_packet_(reinterpret_cast<const char*>(rtp_data), rtp_len), |
| 126 | rtcp_packet_(reinterpret_cast<const char*>(rtcp_data), rtcp_len), |
| 127 | media_info_callbacks1_(), |
solenberg | 5b14b42 | 2015-10-01 04:10:31 -0700 | [diff] [blame] | 128 | media_info_callbacks2_() {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 129 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 130 | void CreateChannels(int flags1, int flags2) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 131 | CreateChannels(new typename T::MediaChannel(NULL, typename T::Options()), |
| 132 | new typename T::MediaChannel(NULL, typename T::Options()), |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 133 | flags1, flags2, rtc::Thread::Current()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 134 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 135 | void CreateChannels( |
| 136 | typename T::MediaChannel* ch1, typename T::MediaChannel* ch2, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 137 | int flags1, int flags2, rtc::Thread* thread) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 138 | media_channel1_ = ch1; |
| 139 | media_channel2_ = ch2; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 140 | channel1_.reset(CreateChannel(thread, &media_engine_, ch1, |
| 141 | &transport_controller1_, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 142 | (flags1 & RTCP) != 0)); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 143 | channel2_.reset(CreateChannel(thread, &media_engine_, ch2, |
| 144 | &transport_controller2_, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 145 | (flags2 & RTCP) != 0)); |
| 146 | channel1_->SignalMediaMonitor.connect( |
| 147 | this, &ChannelTest<T>::OnMediaMonitor); |
| 148 | channel2_->SignalMediaMonitor.connect( |
| 149 | this, &ChannelTest<T>::OnMediaMonitor); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 150 | if ((flags1 & DTLS) && (flags2 & DTLS)) { |
| 151 | flags1 = (flags1 & ~SECURE); |
| 152 | flags2 = (flags2 & ~SECURE); |
| 153 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 154 | CreateContent(flags1, kPcmuCodec, kH264Codec, |
| 155 | &local_media_content1_); |
| 156 | CreateContent(flags2, kPcmuCodec, kH264Codec, |
| 157 | &local_media_content2_); |
| 158 | CopyContent(local_media_content1_, &remote_media_content1_); |
| 159 | CopyContent(local_media_content2_, &remote_media_content2_); |
| 160 | |
| 161 | if (flags1 & DTLS) { |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 162 | // Confirmed to work with KT_RSA and KT_ECDSA. |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 163 | transport_controller1_.SetLocalCertificate( |
| 164 | rtc::RTCCertificate::Create(rtc::scoped_ptr<rtc::SSLIdentity>( |
| 165 | rtc::SSLIdentity::Generate("session1", rtc::KT_DEFAULT)))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 166 | } |
| 167 | if (flags2 & DTLS) { |
Torbjorn Granlund | b6d4ec4 | 2015-08-17 14:08:59 +0200 | [diff] [blame] | 168 | // Confirmed to work with KT_RSA and KT_ECDSA. |
kwiberg | 0eb15ed | 2015-12-17 03:04:15 -0800 | [diff] [blame] | 169 | transport_controller2_.SetLocalCertificate( |
| 170 | rtc::RTCCertificate::Create(rtc::scoped_ptr<rtc::SSLIdentity>( |
| 171 | rtc::SSLIdentity::Generate("session2", rtc::KT_DEFAULT)))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | // Add stream information (SSRC) to the local content but not to the remote |
| 175 | // content. This means that we per default know the SSRC of what we send but |
| 176 | // not what we receive. |
| 177 | AddLegacyStreamInContent(kSsrc1, flags1, &local_media_content1_); |
| 178 | AddLegacyStreamInContent(kSsrc2, flags2, &local_media_content2_); |
| 179 | |
| 180 | // If SSRC_MUX is used we also need to know the SSRC of the incoming stream. |
| 181 | if (flags1 & SSRC_MUX) { |
| 182 | AddLegacyStreamInContent(kSsrc1, flags1, &remote_media_content1_); |
| 183 | } |
| 184 | if (flags2 & SSRC_MUX) { |
| 185 | AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_); |
| 186 | } |
| 187 | } |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 188 | typename T::Channel* CreateChannel( |
| 189 | rtc::Thread* thread, |
| 190 | cricket::MediaEngineInterface* engine, |
| 191 | typename T::MediaChannel* ch, |
| 192 | cricket::TransportController* transport_controller, |
| 193 | bool rtcp) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 194 | typename T::Channel* channel = new typename T::Channel( |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 195 | thread, engine, ch, transport_controller, cricket::CN_AUDIO, rtcp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 196 | if (!channel->Init()) { |
| 197 | delete channel; |
| 198 | channel = NULL; |
| 199 | } |
| 200 | return channel; |
| 201 | } |
| 202 | |
| 203 | bool SendInitiate() { |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 204 | bool result = channel1_->SetLocalContent(&local_media_content1_, |
| 205 | CA_OFFER, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 206 | if (result) { |
| 207 | channel1_->Enable(true); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 208 | result = channel2_->SetRemoteContent(&remote_media_content1_, |
| 209 | CA_OFFER, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 210 | if (result) { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 211 | transport_controller1_.Connect(&transport_controller2_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 212 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 213 | result = channel2_->SetLocalContent(&local_media_content2_, |
| 214 | CA_ANSWER, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 215 | } |
| 216 | } |
| 217 | return result; |
| 218 | } |
| 219 | |
| 220 | bool SendAccept() { |
| 221 | channel2_->Enable(true); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 222 | return channel1_->SetRemoteContent(&remote_media_content2_, |
| 223 | CA_ANSWER, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | bool SendOffer() { |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 227 | bool result = channel1_->SetLocalContent(&local_media_content1_, |
| 228 | CA_OFFER, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 229 | if (result) { |
| 230 | channel1_->Enable(true); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 231 | result = channel2_->SetRemoteContent(&remote_media_content1_, |
| 232 | CA_OFFER, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 233 | } |
| 234 | return result; |
| 235 | } |
| 236 | |
| 237 | bool SendProvisionalAnswer() { |
| 238 | bool result = channel2_->SetLocalContent(&local_media_content2_, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 239 | CA_PRANSWER, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 240 | if (result) { |
| 241 | channel2_->Enable(true); |
| 242 | result = channel1_->SetRemoteContent(&remote_media_content2_, |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 243 | CA_PRANSWER, NULL); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 244 | transport_controller1_.Connect(&transport_controller2_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 245 | } |
| 246 | return result; |
| 247 | } |
| 248 | |
| 249 | bool SendFinalAnswer() { |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 250 | bool result = channel2_->SetLocalContent(&local_media_content2_, |
| 251 | CA_ANSWER, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 252 | if (result) |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 253 | result = channel1_->SetRemoteContent(&remote_media_content2_, |
| 254 | CA_ANSWER, NULL); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 255 | return result; |
| 256 | } |
| 257 | |
| 258 | bool SendTerminate() { |
| 259 | channel1_.reset(); |
| 260 | channel2_.reset(); |
| 261 | return true; |
| 262 | } |
| 263 | |
| 264 | bool AddStream1(int id) { |
| 265 | return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id)); |
| 266 | } |
| 267 | bool RemoveStream1(int id) { |
| 268 | return channel1_->RemoveRecvStream(id); |
| 269 | } |
| 270 | |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 271 | // Calling "_w" method here is ok since we only use one thread for this test |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 272 | cricket::FakeTransport* GetTransport1() { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 273 | return transport_controller1_.GetTransport_w(channel1_->content_name()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 274 | } |
| 275 | cricket::FakeTransport* GetTransport2() { |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 276 | return transport_controller2_.GetTransport_w(channel2_->content_name()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 277 | } |
| 278 | |
| 279 | bool SendRtp1() { |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 280 | return media_channel1_->SendRtp(rtp_packet_.c_str(), |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 281 | static_cast<int>(rtp_packet_.size()), |
| 282 | rtc::PacketOptions()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 283 | } |
| 284 | bool SendRtp2() { |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 285 | return media_channel2_->SendRtp(rtp_packet_.c_str(), |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 286 | static_cast<int>(rtp_packet_.size()), |
| 287 | rtc::PacketOptions()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 288 | } |
| 289 | bool SendRtcp1() { |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 290 | return media_channel1_->SendRtcp(rtcp_packet_.c_str(), |
| 291 | static_cast<int>(rtcp_packet_.size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 292 | } |
| 293 | bool SendRtcp2() { |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 294 | return media_channel2_->SendRtcp(rtcp_packet_.c_str(), |
| 295 | static_cast<int>(rtcp_packet_.size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 296 | } |
| 297 | // Methods to send custom data. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 298 | bool SendCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) { |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 299 | std::string data(CreateRtpData(ssrc, sequence_number, pl_type)); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 300 | return media_channel1_->SendRtp(data.c_str(), static_cast<int>(data.size()), |
| 301 | rtc::PacketOptions()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 302 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 303 | bool SendCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) { |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 304 | std::string data(CreateRtpData(ssrc, sequence_number, pl_type)); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 305 | return media_channel2_->SendRtp(data.c_str(), static_cast<int>(data.size()), |
| 306 | rtc::PacketOptions()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 307 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 308 | bool SendCustomRtcp1(uint32_t ssrc) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 309 | std::string data(CreateRtcpData(ssrc)); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 310 | return media_channel1_->SendRtcp(data.c_str(), |
| 311 | static_cast<int>(data.size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 312 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 313 | bool SendCustomRtcp2(uint32_t ssrc) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 314 | std::string data(CreateRtcpData(ssrc)); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 315 | return media_channel2_->SendRtcp(data.c_str(), |
| 316 | static_cast<int>(data.size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 317 | } |
| 318 | bool CheckRtp1() { |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 319 | return media_channel1_->CheckRtp(rtp_packet_.c_str(), |
| 320 | static_cast<int>(rtp_packet_.size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 321 | } |
| 322 | bool CheckRtp2() { |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 323 | return media_channel2_->CheckRtp(rtp_packet_.c_str(), |
| 324 | static_cast<int>(rtp_packet_.size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 325 | } |
| 326 | bool CheckRtcp1() { |
| 327 | return media_channel1_->CheckRtcp(rtcp_packet_.c_str(), |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 328 | static_cast<int>(rtcp_packet_.size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 329 | } |
| 330 | bool CheckRtcp2() { |
| 331 | return media_channel2_->CheckRtcp(rtcp_packet_.c_str(), |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 332 | static_cast<int>(rtcp_packet_.size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 333 | } |
| 334 | // Methods to check custom data. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 335 | bool CheckCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) { |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 336 | std::string data(CreateRtpData(ssrc, sequence_number, pl_type)); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 337 | return media_channel1_->CheckRtp(data.c_str(), |
| 338 | static_cast<int>(data.size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 339 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 340 | bool CheckCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) { |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 341 | std::string data(CreateRtpData(ssrc, sequence_number, pl_type)); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 342 | return media_channel2_->CheckRtp(data.c_str(), |
| 343 | static_cast<int>(data.size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 344 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 345 | bool CheckCustomRtcp1(uint32_t ssrc) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 346 | std::string data(CreateRtcpData(ssrc)); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 347 | return media_channel1_->CheckRtcp(data.c_str(), |
| 348 | static_cast<int>(data.size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 349 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 350 | bool CheckCustomRtcp2(uint32_t ssrc) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 351 | std::string data(CreateRtcpData(ssrc)); |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 352 | return media_channel2_->CheckRtcp(data.c_str(), |
| 353 | static_cast<int>(data.size())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 354 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 355 | std::string CreateRtpData(uint32_t ssrc, int sequence_number, int pl_type) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 356 | std::string data(rtp_packet_); |
| 357 | // Set SSRC in the rtp packet copy. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 358 | rtc::SetBE32(const_cast<char*>(data.c_str()) + 8, ssrc); |
| 359 | rtc::SetBE16(const_cast<char*>(data.c_str()) + 2, sequence_number); |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 360 | if (pl_type >= 0) { |
pkasting@chromium.org | 0e81fdf | 2015-02-02 23:54:03 +0000 | [diff] [blame] | 361 | rtc::Set8(const_cast<char*>(data.c_str()), 1, |
| 362 | static_cast<uint8_t>(pl_type)); |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 363 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 364 | return data; |
| 365 | } |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 366 | std::string CreateRtcpData(uint32_t ssrc) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 367 | std::string data(rtcp_packet_); |
| 368 | // Set SSRC in the rtcp packet copy. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 369 | rtc::SetBE32(const_cast<char*>(data.c_str()) + 4, ssrc); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 370 | return data; |
| 371 | } |
| 372 | |
| 373 | bool CheckNoRtp1() { |
| 374 | return media_channel1_->CheckNoRtp(); |
| 375 | } |
| 376 | bool CheckNoRtp2() { |
| 377 | return media_channel2_->CheckNoRtp(); |
| 378 | } |
| 379 | bool CheckNoRtcp1() { |
| 380 | return media_channel1_->CheckNoRtcp(); |
| 381 | } |
| 382 | bool CheckNoRtcp2() { |
| 383 | return media_channel2_->CheckNoRtcp(); |
| 384 | } |
| 385 | |
| 386 | void CreateContent(int flags, |
| 387 | const cricket::AudioCodec& audio_codec, |
| 388 | const cricket::VideoCodec& video_codec, |
| 389 | typename T::Content* content) { |
| 390 | // overridden in specialized classes |
| 391 | } |
| 392 | void CopyContent(const typename T::Content& source, |
| 393 | typename T::Content* content) { |
| 394 | // overridden in specialized classes |
| 395 | } |
| 396 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 397 | // Creates a cricket::SessionDescription with one MediaContent and one stream. |
| 398 | // kPcmuCodec is used as audio codec and kH264Codec is used as video codec. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 399 | cricket::SessionDescription* CreateSessionDescriptionWithStream( |
| 400 | uint32_t ssrc) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 401 | typename T::Content content; |
| 402 | cricket::SessionDescription* sdesc = new cricket::SessionDescription(); |
| 403 | CreateContent(SECURE, kPcmuCodec, kH264Codec, &content); |
| 404 | AddLegacyStreamInContent(ssrc, 0, &content); |
| 405 | sdesc->AddContent("DUMMY_CONTENT_NAME", |
| 406 | cricket::NS_JINGLE_RTP, content.Copy()); |
| 407 | return sdesc; |
| 408 | } |
| 409 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 410 | class CallThread : public rtc::SignalThread { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 411 | public: |
| 412 | typedef bool (ChannelTest<T>::*Method)(); |
| 413 | CallThread(ChannelTest<T>* obj, Method method, bool* result) |
| 414 | : obj_(obj), |
| 415 | method_(method), |
| 416 | result_(result) { |
| 417 | *result = false; |
| 418 | } |
| 419 | virtual void DoWork() { |
| 420 | bool result = (*obj_.*method_)(); |
| 421 | if (result_) { |
| 422 | *result_ = result; |
| 423 | } |
| 424 | } |
| 425 | private: |
| 426 | ChannelTest<T>* obj_; |
| 427 | Method method_; |
| 428 | bool* result_; |
| 429 | }; |
| 430 | void CallOnThread(typename CallThread::Method method, bool* result) { |
| 431 | CallThread* thread = new CallThread(this, method, result); |
| 432 | thread->Start(); |
| 433 | thread->Release(); |
| 434 | } |
| 435 | |
| 436 | void CallOnThreadAndWaitForDone(typename CallThread::Method method, |
| 437 | bool* result) { |
| 438 | CallThread* thread = new CallThread(this, method, result); |
| 439 | thread->Start(); |
| 440 | thread->Destroy(true); |
| 441 | } |
| 442 | |
| 443 | bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) { |
| 444 | return false; // overridden in specialized classes |
| 445 | } |
| 446 | |
| 447 | void OnMediaMonitor(typename T::Channel* channel, |
| 448 | const typename T::MediaInfo& info) { |
| 449 | if (channel == channel1_.get()) { |
| 450 | media_info_callbacks1_++; |
| 451 | } else if (channel == channel2_.get()) { |
| 452 | media_info_callbacks2_++; |
| 453 | } |
| 454 | } |
| 455 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 456 | void AddLegacyStreamInContent(uint32_t ssrc, |
| 457 | int flags, |
| 458 | typename T::Content* content) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 459 | // Base implementation. |
| 460 | } |
| 461 | |
| 462 | // Tests that can be used by derived classes. |
| 463 | |
| 464 | // Basic sanity check. |
| 465 | void TestInit() { |
| 466 | CreateChannels(0, 0); |
| 467 | EXPECT_FALSE(channel1_->secure()); |
| 468 | EXPECT_FALSE(media_channel1_->sending()); |
Peter Boström | 34fbfff | 2015-09-24 19:20:30 +0200 | [diff] [blame] | 469 | if (verify_playout_) { |
| 470 | EXPECT_FALSE(media_channel1_->playout()); |
| 471 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 472 | EXPECT_TRUE(media_channel1_->codecs().empty()); |
| 473 | EXPECT_TRUE(media_channel1_->recv_streams().empty()); |
| 474 | EXPECT_TRUE(media_channel1_->rtp_packets().empty()); |
| 475 | EXPECT_TRUE(media_channel1_->rtcp_packets().empty()); |
| 476 | } |
| 477 | |
| 478 | // Test that SetLocalContent and SetRemoteContent properly configure |
| 479 | // the codecs. |
| 480 | void TestSetContents() { |
| 481 | CreateChannels(0, 0); |
| 482 | typename T::Content content; |
| 483 | CreateContent(0, kPcmuCodec, kH264Codec, &content); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 484 | EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 485 | EXPECT_EQ(0U, media_channel1_->codecs().size()); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 486 | EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 487 | ASSERT_EQ(1U, media_channel1_->codecs().size()); |
| 488 | EXPECT_TRUE(CodecMatches(content.codecs()[0], |
| 489 | media_channel1_->codecs()[0])); |
| 490 | } |
| 491 | |
| 492 | // Test that SetLocalContent and SetRemoteContent properly deals |
| 493 | // with an empty offer. |
| 494 | void TestSetContentsNullOffer() { |
| 495 | CreateChannels(0, 0); |
| 496 | typename T::Content content; |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 497 | EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 498 | CreateContent(0, kPcmuCodec, kH264Codec, &content); |
| 499 | EXPECT_EQ(0U, media_channel1_->codecs().size()); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 500 | EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 501 | ASSERT_EQ(1U, media_channel1_->codecs().size()); |
| 502 | EXPECT_TRUE(CodecMatches(content.codecs()[0], |
| 503 | media_channel1_->codecs()[0])); |
| 504 | } |
| 505 | |
| 506 | // Test that SetLocalContent and SetRemoteContent properly set RTCP |
| 507 | // mux. |
| 508 | void TestSetContentsRtcpMux() { |
| 509 | CreateChannels(RTCP, RTCP); |
| 510 | EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL); |
| 511 | EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL); |
| 512 | typename T::Content content; |
| 513 | CreateContent(0, kPcmuCodec, kH264Codec, &content); |
| 514 | // Both sides agree on mux. Should no longer be a separate RTCP channel. |
| 515 | content.set_rtcp_mux(true); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 516 | EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL)); |
| 517 | EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 518 | EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL); |
| 519 | // Only initiator supports mux. Should still have a separate RTCP channel. |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 520 | EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 521 | content.set_rtcp_mux(false); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 522 | EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 523 | EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL); |
| 524 | } |
| 525 | |
| 526 | // Test that SetLocalContent and SetRemoteContent properly set RTCP |
| 527 | // mux when a provisional answer is received. |
| 528 | void TestSetContentsRtcpMuxWithPrAnswer() { |
| 529 | CreateChannels(RTCP, RTCP); |
| 530 | EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL); |
| 531 | EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL); |
| 532 | typename T::Content content; |
| 533 | CreateContent(0, kPcmuCodec, kH264Codec, &content); |
| 534 | content.set_rtcp_mux(true); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 535 | EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL)); |
| 536 | EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_PRANSWER, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 537 | EXPECT_TRUE(channel1_->rtcp_transport_channel() != NULL); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 538 | EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 539 | // Both sides agree on mux. Should no longer be a separate RTCP channel. |
| 540 | EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL); |
| 541 | // Only initiator supports mux. Should still have a separate RTCP channel. |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 542 | EXPECT_TRUE(channel2_->SetLocalContent(&content, CA_OFFER, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 543 | content.set_rtcp_mux(false); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 544 | EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_PRANSWER, NULL)); |
| 545 | EXPECT_TRUE(channel2_->SetRemoteContent(&content, CA_ANSWER, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 546 | EXPECT_TRUE(channel2_->rtcp_transport_channel() != NULL); |
| 547 | } |
| 548 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 549 | // Test that SetRemoteContent properly deals with a content update. |
| 550 | void TestSetRemoteContentUpdate() { |
| 551 | CreateChannels(0, 0); |
| 552 | typename T::Content content; |
| 553 | CreateContent(RTCP | RTCP_MUX | SECURE, |
| 554 | kPcmuCodec, kH264Codec, |
| 555 | &content); |
| 556 | EXPECT_EQ(0U, media_channel1_->codecs().size()); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 557 | EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL)); |
| 558 | EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 559 | ASSERT_EQ(1U, media_channel1_->codecs().size()); |
| 560 | EXPECT_TRUE(CodecMatches(content.codecs()[0], |
| 561 | media_channel1_->codecs()[0])); |
| 562 | // Now update with other codecs. |
| 563 | typename T::Content update_content; |
| 564 | update_content.set_partial(true); |
| 565 | CreateContent(0, kIsacCodec, kH264SvcCodec, |
| 566 | &update_content); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 567 | EXPECT_TRUE(channel1_->SetRemoteContent(&update_content, CA_UPDATE, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 568 | ASSERT_EQ(1U, media_channel1_->codecs().size()); |
| 569 | EXPECT_TRUE(CodecMatches(update_content.codecs()[0], |
| 570 | media_channel1_->codecs()[0])); |
| 571 | // Now update without any codecs. This is ignored. |
| 572 | typename T::Content empty_content; |
| 573 | empty_content.set_partial(true); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 574 | EXPECT_TRUE(channel1_->SetRemoteContent(&empty_content, CA_UPDATE, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 575 | ASSERT_EQ(1U, media_channel1_->codecs().size()); |
| 576 | EXPECT_TRUE(CodecMatches(update_content.codecs()[0], |
| 577 | media_channel1_->codecs()[0])); |
| 578 | } |
| 579 | |
| 580 | // Test that Add/RemoveStream properly forward to the media channel. |
| 581 | void TestStreams() { |
| 582 | CreateChannels(0, 0); |
| 583 | EXPECT_TRUE(AddStream1(1)); |
| 584 | EXPECT_TRUE(AddStream1(2)); |
| 585 | EXPECT_EQ(2U, media_channel1_->recv_streams().size()); |
| 586 | EXPECT_TRUE(RemoveStream1(2)); |
| 587 | EXPECT_EQ(1U, media_channel1_->recv_streams().size()); |
| 588 | EXPECT_TRUE(RemoveStream1(1)); |
| 589 | EXPECT_EQ(0U, media_channel1_->recv_streams().size()); |
| 590 | } |
| 591 | |
| 592 | // Test that SetLocalContent properly handles adding and removing StreamParams |
| 593 | // to the local content description. |
| 594 | // This test uses the CA_UPDATE action that don't require a full |
| 595 | // MediaContentDescription to do an update. |
| 596 | void TestUpdateStreamsInLocalContent() { |
| 597 | cricket::StreamParams stream1; |
| 598 | stream1.groupid = "group1"; |
| 599 | stream1.id = "stream1"; |
| 600 | stream1.ssrcs.push_back(kSsrc1); |
| 601 | stream1.cname = "stream1_cname"; |
| 602 | |
| 603 | cricket::StreamParams stream2; |
| 604 | stream2.groupid = "group2"; |
| 605 | stream2.id = "stream2"; |
| 606 | stream2.ssrcs.push_back(kSsrc2); |
| 607 | stream2.cname = "stream2_cname"; |
| 608 | |
| 609 | cricket::StreamParams stream3; |
| 610 | stream3.groupid = "group3"; |
| 611 | stream3.id = "stream3"; |
| 612 | stream3.ssrcs.push_back(kSsrc3); |
| 613 | stream3.cname = "stream3_cname"; |
| 614 | |
| 615 | CreateChannels(0, 0); |
| 616 | typename T::Content content1; |
| 617 | CreateContent(0, kPcmuCodec, kH264Codec, &content1); |
| 618 | content1.AddStream(stream1); |
| 619 | EXPECT_EQ(0u, media_channel1_->send_streams().size()); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 620 | EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 621 | |
| 622 | ASSERT_EQ(1u, media_channel1_->send_streams().size()); |
| 623 | EXPECT_EQ(stream1, media_channel1_->send_streams()[0]); |
| 624 | |
| 625 | // Update the local streams by adding another sending stream. |
| 626 | // Use a partial updated session description. |
| 627 | typename T::Content content2; |
| 628 | content2.AddStream(stream2); |
| 629 | content2.AddStream(stream3); |
| 630 | content2.set_partial(true); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 631 | EXPECT_TRUE(channel1_->SetLocalContent(&content2, CA_UPDATE, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 632 | ASSERT_EQ(3u, media_channel1_->send_streams().size()); |
| 633 | EXPECT_EQ(stream1, media_channel1_->send_streams()[0]); |
| 634 | EXPECT_EQ(stream2, media_channel1_->send_streams()[1]); |
| 635 | EXPECT_EQ(stream3, media_channel1_->send_streams()[2]); |
| 636 | |
| 637 | // Update the local streams by removing the first sending stream. |
| 638 | // This is done by removing all SSRCS for this particular stream. |
| 639 | typename T::Content content3; |
| 640 | stream1.ssrcs.clear(); |
| 641 | content3.AddStream(stream1); |
| 642 | content3.set_partial(true); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 643 | EXPECT_TRUE(channel1_->SetLocalContent(&content3, CA_UPDATE, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 644 | ASSERT_EQ(2u, media_channel1_->send_streams().size()); |
| 645 | EXPECT_EQ(stream2, media_channel1_->send_streams()[0]); |
| 646 | EXPECT_EQ(stream3, media_channel1_->send_streams()[1]); |
| 647 | |
| 648 | // Update the local streams with a stream that does not change. |
| 649 | // THe update is ignored. |
| 650 | typename T::Content content4; |
| 651 | content4.AddStream(stream2); |
| 652 | content4.set_partial(true); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 653 | EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_UPDATE, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 654 | ASSERT_EQ(2u, media_channel1_->send_streams().size()); |
| 655 | EXPECT_EQ(stream2, media_channel1_->send_streams()[0]); |
| 656 | EXPECT_EQ(stream3, media_channel1_->send_streams()[1]); |
| 657 | } |
| 658 | |
| 659 | // Test that SetRemoteContent properly handles adding and removing |
| 660 | // StreamParams to the remote content description. |
| 661 | // This test uses the CA_UPDATE action that don't require a full |
| 662 | // MediaContentDescription to do an update. |
| 663 | void TestUpdateStreamsInRemoteContent() { |
| 664 | cricket::StreamParams stream1; |
| 665 | stream1.id = "Stream1"; |
| 666 | stream1.groupid = "1"; |
| 667 | stream1.ssrcs.push_back(kSsrc1); |
| 668 | stream1.cname = "stream1_cname"; |
| 669 | |
| 670 | cricket::StreamParams stream2; |
| 671 | stream2.id = "Stream2"; |
| 672 | stream2.groupid = "2"; |
| 673 | stream2.ssrcs.push_back(kSsrc2); |
| 674 | stream2.cname = "stream2_cname"; |
| 675 | |
| 676 | cricket::StreamParams stream3; |
| 677 | stream3.id = "Stream3"; |
| 678 | stream3.groupid = "3"; |
| 679 | stream3.ssrcs.push_back(kSsrc3); |
| 680 | stream3.cname = "stream3_cname"; |
| 681 | |
| 682 | CreateChannels(0, 0); |
| 683 | typename T::Content content1; |
| 684 | CreateContent(0, kPcmuCodec, kH264Codec, &content1); |
| 685 | content1.AddStream(stream1); |
| 686 | EXPECT_EQ(0u, media_channel1_->recv_streams().size()); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 687 | EXPECT_TRUE(channel1_->SetRemoteContent(&content1, CA_OFFER, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 688 | |
| 689 | ASSERT_EQ(1u, media_channel1_->codecs().size()); |
| 690 | ASSERT_EQ(1u, media_channel1_->recv_streams().size()); |
| 691 | EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]); |
| 692 | |
| 693 | // Update the remote streams by adding another sending stream. |
| 694 | // Use a partial updated session description. |
| 695 | typename T::Content content2; |
| 696 | content2.AddStream(stream2); |
| 697 | content2.AddStream(stream3); |
| 698 | content2.set_partial(true); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 699 | EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_UPDATE, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 700 | ASSERT_EQ(3u, media_channel1_->recv_streams().size()); |
| 701 | EXPECT_EQ(stream1, media_channel1_->recv_streams()[0]); |
| 702 | EXPECT_EQ(stream2, media_channel1_->recv_streams()[1]); |
| 703 | EXPECT_EQ(stream3, media_channel1_->recv_streams()[2]); |
| 704 | |
| 705 | // Update the remote streams by removing the first stream. |
| 706 | // This is done by removing all SSRCS for this particular stream. |
| 707 | typename T::Content content3; |
| 708 | stream1.ssrcs.clear(); |
| 709 | content3.AddStream(stream1); |
| 710 | content3.set_partial(true); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 711 | EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_UPDATE, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 712 | ASSERT_EQ(2u, media_channel1_->recv_streams().size()); |
| 713 | EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]); |
| 714 | EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]); |
| 715 | |
| 716 | // Update the remote streams with a stream that does not change. |
| 717 | // The update is ignored. |
| 718 | typename T::Content content4; |
| 719 | content4.AddStream(stream2); |
| 720 | content4.set_partial(true); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 721 | EXPECT_TRUE(channel1_->SetRemoteContent(&content4, CA_UPDATE, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 722 | ASSERT_EQ(2u, media_channel1_->recv_streams().size()); |
| 723 | EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]); |
| 724 | EXPECT_EQ(stream3, media_channel1_->recv_streams()[1]); |
| 725 | } |
| 726 | |
| 727 | // Test that SetLocalContent and SetRemoteContent properly |
| 728 | // handles adding and removing StreamParams when the action is a full |
| 729 | // CA_OFFER / CA_ANSWER. |
| 730 | void TestChangeStreamParamsInContent() { |
| 731 | cricket::StreamParams stream1; |
| 732 | stream1.groupid = "group1"; |
| 733 | stream1.id = "stream1"; |
| 734 | stream1.ssrcs.push_back(kSsrc1); |
| 735 | stream1.cname = "stream1_cname"; |
| 736 | |
| 737 | cricket::StreamParams stream2; |
| 738 | stream2.groupid = "group1"; |
| 739 | stream2.id = "stream2"; |
| 740 | stream2.ssrcs.push_back(kSsrc2); |
| 741 | stream2.cname = "stream2_cname"; |
| 742 | |
| 743 | // Setup a call where channel 1 send |stream1| to channel 2. |
| 744 | CreateChannels(0, 0); |
| 745 | typename T::Content content1; |
| 746 | CreateContent(0, kPcmuCodec, kH264Codec, &content1); |
| 747 | content1.AddStream(stream1); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 748 | EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 749 | EXPECT_TRUE(channel1_->Enable(true)); |
| 750 | EXPECT_EQ(1u, media_channel1_->send_streams().size()); |
| 751 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 752 | EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 753 | EXPECT_EQ(1u, media_channel2_->recv_streams().size()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 754 | transport_controller1_.Connect(&transport_controller2_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 755 | |
| 756 | // Channel 2 do not send anything. |
| 757 | typename T::Content content2; |
| 758 | CreateContent(0, kPcmuCodec, kH264Codec, &content2); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 759 | EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 760 | EXPECT_EQ(0u, media_channel1_->recv_streams().size()); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 761 | EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 762 | EXPECT_TRUE(channel2_->Enable(true)); |
| 763 | EXPECT_EQ(0u, media_channel2_->send_streams().size()); |
| 764 | |
| 765 | EXPECT_TRUE(SendCustomRtp1(kSsrc1, 0)); |
| 766 | EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0)); |
| 767 | |
| 768 | // Let channel 2 update the content by sending |stream2| and enable SRTP. |
| 769 | typename T::Content content3; |
| 770 | CreateContent(SECURE, kPcmuCodec, kH264Codec, &content3); |
| 771 | content3.AddStream(stream2); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 772 | EXPECT_TRUE(channel2_->SetLocalContent(&content3, CA_OFFER, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 773 | ASSERT_EQ(1u, media_channel2_->send_streams().size()); |
| 774 | EXPECT_EQ(stream2, media_channel2_->send_streams()[0]); |
| 775 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 776 | EXPECT_TRUE(channel1_->SetRemoteContent(&content3, CA_OFFER, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 777 | ASSERT_EQ(1u, media_channel1_->recv_streams().size()); |
| 778 | EXPECT_EQ(stream2, media_channel1_->recv_streams()[0]); |
| 779 | |
| 780 | // Channel 1 replies but stop sending stream1. |
| 781 | typename T::Content content4; |
| 782 | CreateContent(SECURE, kPcmuCodec, kH264Codec, &content4); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 783 | EXPECT_TRUE(channel1_->SetLocalContent(&content4, CA_ANSWER, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 784 | EXPECT_EQ(0u, media_channel1_->send_streams().size()); |
| 785 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 786 | EXPECT_TRUE(channel2_->SetRemoteContent(&content4, CA_ANSWER, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 787 | EXPECT_EQ(0u, media_channel2_->recv_streams().size()); |
| 788 | |
| 789 | EXPECT_TRUE(channel1_->secure()); |
| 790 | EXPECT_TRUE(channel2_->secure()); |
| 791 | EXPECT_TRUE(SendCustomRtp2(kSsrc2, 0)); |
| 792 | EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0)); |
| 793 | } |
| 794 | |
| 795 | // Test that we only start playout and sending at the right times. |
| 796 | void TestPlayoutAndSendingStates() { |
| 797 | CreateChannels(0, 0); |
Peter Boström | 34fbfff | 2015-09-24 19:20:30 +0200 | [diff] [blame] | 798 | if (verify_playout_) { |
| 799 | EXPECT_FALSE(media_channel1_->playout()); |
| 800 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 801 | EXPECT_FALSE(media_channel1_->sending()); |
Peter Boström | 34fbfff | 2015-09-24 19:20:30 +0200 | [diff] [blame] | 802 | if (verify_playout_) { |
| 803 | EXPECT_FALSE(media_channel2_->playout()); |
| 804 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 805 | EXPECT_FALSE(media_channel2_->sending()); |
| 806 | EXPECT_TRUE(channel1_->Enable(true)); |
Peter Boström | 34fbfff | 2015-09-24 19:20:30 +0200 | [diff] [blame] | 807 | if (verify_playout_) { |
| 808 | EXPECT_FALSE(media_channel1_->playout()); |
| 809 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 810 | EXPECT_FALSE(media_channel1_->sending()); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 811 | EXPECT_TRUE(channel1_->SetLocalContent(&local_media_content1_, |
| 812 | CA_OFFER, NULL)); |
Peter Boström | 34fbfff | 2015-09-24 19:20:30 +0200 | [diff] [blame] | 813 | if (verify_playout_) { |
| 814 | EXPECT_TRUE(media_channel1_->playout()); |
| 815 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 816 | EXPECT_FALSE(media_channel1_->sending()); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 817 | EXPECT_TRUE(channel2_->SetRemoteContent(&local_media_content1_, |
| 818 | CA_OFFER, NULL)); |
Peter Boström | 34fbfff | 2015-09-24 19:20:30 +0200 | [diff] [blame] | 819 | if (verify_playout_) { |
| 820 | EXPECT_FALSE(media_channel2_->playout()); |
| 821 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 822 | EXPECT_FALSE(media_channel2_->sending()); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 823 | EXPECT_TRUE(channel2_->SetLocalContent(&local_media_content2_, |
| 824 | CA_ANSWER, NULL)); |
Peter Boström | 34fbfff | 2015-09-24 19:20:30 +0200 | [diff] [blame] | 825 | if (verify_playout_) { |
| 826 | EXPECT_FALSE(media_channel2_->playout()); |
| 827 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 828 | EXPECT_FALSE(media_channel2_->sending()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 829 | transport_controller1_.Connect(&transport_controller2_); |
Peter Boström | 34fbfff | 2015-09-24 19:20:30 +0200 | [diff] [blame] | 830 | if (verify_playout_) { |
| 831 | EXPECT_TRUE(media_channel1_->playout()); |
| 832 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 833 | EXPECT_FALSE(media_channel1_->sending()); |
Peter Boström | 34fbfff | 2015-09-24 19:20:30 +0200 | [diff] [blame] | 834 | if (verify_playout_) { |
| 835 | EXPECT_FALSE(media_channel2_->playout()); |
| 836 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 837 | EXPECT_FALSE(media_channel2_->sending()); |
| 838 | EXPECT_TRUE(channel2_->Enable(true)); |
Peter Boström | 34fbfff | 2015-09-24 19:20:30 +0200 | [diff] [blame] | 839 | if (verify_playout_) { |
| 840 | EXPECT_TRUE(media_channel2_->playout()); |
| 841 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 842 | EXPECT_TRUE(media_channel2_->sending()); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 843 | EXPECT_TRUE(channel1_->SetRemoteContent(&local_media_content2_, |
| 844 | CA_ANSWER, NULL)); |
Peter Boström | 34fbfff | 2015-09-24 19:20:30 +0200 | [diff] [blame] | 845 | if (verify_playout_) { |
| 846 | EXPECT_TRUE(media_channel1_->playout()); |
| 847 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 848 | EXPECT_TRUE(media_channel1_->sending()); |
| 849 | } |
| 850 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 851 | // Test that changing the MediaContentDirection in the local and remote |
| 852 | // session description start playout and sending at the right time. |
| 853 | void TestMediaContentDirection() { |
| 854 | CreateChannels(0, 0); |
| 855 | typename T::Content content1; |
| 856 | CreateContent(0, kPcmuCodec, kH264Codec, &content1); |
| 857 | typename T::Content content2; |
| 858 | CreateContent(0, kPcmuCodec, kH264Codec, &content2); |
| 859 | // Set |content2| to be InActive. |
| 860 | content2.set_direction(cricket::MD_INACTIVE); |
| 861 | |
| 862 | EXPECT_TRUE(channel1_->Enable(true)); |
| 863 | EXPECT_TRUE(channel2_->Enable(true)); |
Peter Boström | 34fbfff | 2015-09-24 19:20:30 +0200 | [diff] [blame] | 864 | if (verify_playout_) { |
| 865 | EXPECT_FALSE(media_channel1_->playout()); |
| 866 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 867 | EXPECT_FALSE(media_channel1_->sending()); |
Peter Boström | 34fbfff | 2015-09-24 19:20:30 +0200 | [diff] [blame] | 868 | if (verify_playout_) { |
| 869 | EXPECT_FALSE(media_channel2_->playout()); |
| 870 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 871 | EXPECT_FALSE(media_channel2_->sending()); |
| 872 | |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 873 | EXPECT_TRUE(channel1_->SetLocalContent(&content1, CA_OFFER, NULL)); |
| 874 | EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL)); |
| 875 | EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL)); |
| 876 | EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL)); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 877 | transport_controller1_.Connect(&transport_controller2_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 878 | |
Peter Boström | 34fbfff | 2015-09-24 19:20:30 +0200 | [diff] [blame] | 879 | if (verify_playout_) { |
| 880 | EXPECT_TRUE(media_channel1_->playout()); |
| 881 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 882 | EXPECT_FALSE(media_channel1_->sending()); // remote InActive |
Peter Boström | 34fbfff | 2015-09-24 19:20:30 +0200 | [diff] [blame] | 883 | if (verify_playout_) { |
| 884 | EXPECT_FALSE(media_channel2_->playout()); // local InActive |
| 885 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 886 | EXPECT_FALSE(media_channel2_->sending()); // local InActive |
| 887 | |
| 888 | // Update |content2| to be RecvOnly. |
| 889 | content2.set_direction(cricket::MD_RECVONLY); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 890 | EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL)); |
| 891 | EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 892 | |
Peter Boström | 34fbfff | 2015-09-24 19:20:30 +0200 | [diff] [blame] | 893 | if (verify_playout_) { |
| 894 | EXPECT_TRUE(media_channel1_->playout()); |
| 895 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 896 | EXPECT_TRUE(media_channel1_->sending()); |
Peter Boström | 34fbfff | 2015-09-24 19:20:30 +0200 | [diff] [blame] | 897 | if (verify_playout_) { |
| 898 | EXPECT_TRUE(media_channel2_->playout()); // local RecvOnly |
| 899 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 900 | EXPECT_FALSE(media_channel2_->sending()); // local RecvOnly |
| 901 | |
| 902 | // Update |content2| to be SendRecv. |
| 903 | content2.set_direction(cricket::MD_SENDRECV); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 904 | EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_ANSWER, NULL)); |
| 905 | EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_ANSWER, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 906 | |
Peter Boström | 34fbfff | 2015-09-24 19:20:30 +0200 | [diff] [blame] | 907 | if (verify_playout_) { |
| 908 | EXPECT_TRUE(media_channel1_->playout()); |
| 909 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 910 | EXPECT_TRUE(media_channel1_->sending()); |
Peter Boström | 34fbfff | 2015-09-24 19:20:30 +0200 | [diff] [blame] | 911 | if (verify_playout_) { |
| 912 | EXPECT_TRUE(media_channel2_->playout()); |
| 913 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 914 | EXPECT_TRUE(media_channel2_->sending()); |
| 915 | } |
| 916 | |
| 917 | // Test setting up a call. |
| 918 | void TestCallSetup() { |
| 919 | CreateChannels(0, 0); |
| 920 | EXPECT_FALSE(channel1_->secure()); |
| 921 | EXPECT_TRUE(SendInitiate()); |
Peter Boström | 34fbfff | 2015-09-24 19:20:30 +0200 | [diff] [blame] | 922 | if (verify_playout_) { |
| 923 | EXPECT_TRUE(media_channel1_->playout()); |
| 924 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 925 | EXPECT_FALSE(media_channel1_->sending()); |
| 926 | EXPECT_TRUE(SendAccept()); |
| 927 | EXPECT_FALSE(channel1_->secure()); |
| 928 | EXPECT_TRUE(media_channel1_->sending()); |
| 929 | EXPECT_EQ(1U, media_channel1_->codecs().size()); |
Peter Boström | 34fbfff | 2015-09-24 19:20:30 +0200 | [diff] [blame] | 930 | if (verify_playout_) { |
| 931 | EXPECT_TRUE(media_channel2_->playout()); |
| 932 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 933 | EXPECT_TRUE(media_channel2_->sending()); |
| 934 | EXPECT_EQ(1U, media_channel2_->codecs().size()); |
| 935 | } |
| 936 | |
| 937 | // Test that we don't crash if packets are sent during call teardown |
| 938 | // when RTCP mux is enabled. This is a regression test against a specific |
| 939 | // race condition that would only occur when a RTCP packet was sent during |
| 940 | // teardown of a channel on which RTCP mux was enabled. |
| 941 | void TestCallTeardownRtcpMux() { |
| 942 | class LastWordMediaChannel : public T::MediaChannel { |
| 943 | public: |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 944 | LastWordMediaChannel() : T::MediaChannel(NULL, typename T::Options()) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 945 | ~LastWordMediaChannel() { |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 946 | T::MediaChannel::SendRtp(kPcmuFrame, sizeof(kPcmuFrame), |
| 947 | rtc::PacketOptions()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 948 | T::MediaChannel::SendRtcp(kRtcpReport, sizeof(kRtcpReport)); |
| 949 | } |
| 950 | }; |
| 951 | CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(), |
| 952 | RTCP | RTCP_MUX, RTCP | RTCP_MUX, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 953 | rtc::Thread::Current()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 954 | EXPECT_TRUE(SendInitiate()); |
| 955 | EXPECT_TRUE(SendAccept()); |
| 956 | EXPECT_TRUE(SendTerminate()); |
| 957 | } |
| 958 | |
| 959 | // Send voice RTP data to the other side and ensure it gets there. |
| 960 | void SendRtpToRtp() { |
| 961 | CreateChannels(0, 0); |
| 962 | EXPECT_TRUE(SendInitiate()); |
| 963 | EXPECT_TRUE(SendAccept()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 964 | ASSERT_TRUE(GetTransport1()); |
| 965 | ASSERT_TRUE(GetTransport2()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 966 | EXPECT_EQ(1U, GetTransport1()->channels().size()); |
| 967 | EXPECT_EQ(1U, GetTransport2()->channels().size()); |
| 968 | EXPECT_TRUE(SendRtp1()); |
| 969 | EXPECT_TRUE(SendRtp2()); |
| 970 | EXPECT_TRUE(CheckRtp1()); |
| 971 | EXPECT_TRUE(CheckRtp2()); |
| 972 | EXPECT_TRUE(CheckNoRtp1()); |
| 973 | EXPECT_TRUE(CheckNoRtp2()); |
| 974 | } |
| 975 | |
| 976 | // Check that RTCP is not transmitted if both sides don't support RTCP. |
| 977 | void SendNoRtcpToNoRtcp() { |
| 978 | CreateChannels(0, 0); |
| 979 | EXPECT_TRUE(SendInitiate()); |
| 980 | EXPECT_TRUE(SendAccept()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 981 | ASSERT_TRUE(GetTransport1()); |
| 982 | ASSERT_TRUE(GetTransport2()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 983 | EXPECT_EQ(1U, GetTransport1()->channels().size()); |
| 984 | EXPECT_EQ(1U, GetTransport2()->channels().size()); |
| 985 | EXPECT_FALSE(SendRtcp1()); |
| 986 | EXPECT_FALSE(SendRtcp2()); |
| 987 | EXPECT_TRUE(CheckNoRtcp1()); |
| 988 | EXPECT_TRUE(CheckNoRtcp2()); |
| 989 | } |
| 990 | |
| 991 | // Check that RTCP is not transmitted if the callee doesn't support RTCP. |
| 992 | void SendNoRtcpToRtcp() { |
| 993 | CreateChannels(0, RTCP); |
| 994 | EXPECT_TRUE(SendInitiate()); |
| 995 | EXPECT_TRUE(SendAccept()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 996 | ASSERT_TRUE(GetTransport1()); |
| 997 | ASSERT_TRUE(GetTransport2()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 998 | EXPECT_EQ(1U, GetTransport1()->channels().size()); |
| 999 | EXPECT_EQ(2U, GetTransport2()->channels().size()); |
| 1000 | EXPECT_FALSE(SendRtcp1()); |
| 1001 | EXPECT_FALSE(SendRtcp2()); |
| 1002 | EXPECT_TRUE(CheckNoRtcp1()); |
| 1003 | EXPECT_TRUE(CheckNoRtcp2()); |
| 1004 | } |
| 1005 | |
| 1006 | // Check that RTCP is not transmitted if the caller doesn't support RTCP. |
| 1007 | void SendRtcpToNoRtcp() { |
| 1008 | CreateChannels(RTCP, 0); |
| 1009 | EXPECT_TRUE(SendInitiate()); |
| 1010 | EXPECT_TRUE(SendAccept()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1011 | ASSERT_TRUE(GetTransport1()); |
| 1012 | ASSERT_TRUE(GetTransport2()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1013 | EXPECT_EQ(2U, GetTransport1()->channels().size()); |
| 1014 | EXPECT_EQ(1U, GetTransport2()->channels().size()); |
| 1015 | EXPECT_FALSE(SendRtcp1()); |
| 1016 | EXPECT_FALSE(SendRtcp2()); |
| 1017 | EXPECT_TRUE(CheckNoRtcp1()); |
| 1018 | EXPECT_TRUE(CheckNoRtcp2()); |
| 1019 | } |
| 1020 | |
| 1021 | // Check that RTCP is transmitted if both sides support RTCP. |
| 1022 | void SendRtcpToRtcp() { |
| 1023 | CreateChannels(RTCP, RTCP); |
| 1024 | EXPECT_TRUE(SendInitiate()); |
| 1025 | EXPECT_TRUE(SendAccept()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1026 | ASSERT_TRUE(GetTransport1()); |
| 1027 | ASSERT_TRUE(GetTransport2()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1028 | EXPECT_EQ(2U, GetTransport1()->channels().size()); |
| 1029 | EXPECT_EQ(2U, GetTransport2()->channels().size()); |
| 1030 | EXPECT_TRUE(SendRtcp1()); |
| 1031 | EXPECT_TRUE(SendRtcp2()); |
| 1032 | EXPECT_TRUE(CheckRtcp1()); |
| 1033 | EXPECT_TRUE(CheckRtcp2()); |
| 1034 | EXPECT_TRUE(CheckNoRtcp1()); |
| 1035 | EXPECT_TRUE(CheckNoRtcp2()); |
| 1036 | } |
| 1037 | |
| 1038 | // Check that RTCP is transmitted if only the initiator supports mux. |
| 1039 | void SendRtcpMuxToRtcp() { |
| 1040 | CreateChannels(RTCP | RTCP_MUX, RTCP); |
| 1041 | EXPECT_TRUE(SendInitiate()); |
| 1042 | EXPECT_TRUE(SendAccept()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1043 | ASSERT_TRUE(GetTransport1()); |
| 1044 | ASSERT_TRUE(GetTransport2()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1045 | EXPECT_EQ(2U, GetTransport1()->channels().size()); |
| 1046 | EXPECT_EQ(2U, GetTransport2()->channels().size()); |
| 1047 | EXPECT_TRUE(SendRtcp1()); |
| 1048 | EXPECT_TRUE(SendRtcp2()); |
| 1049 | EXPECT_TRUE(CheckRtcp1()); |
| 1050 | EXPECT_TRUE(CheckRtcp2()); |
| 1051 | EXPECT_TRUE(CheckNoRtcp1()); |
| 1052 | EXPECT_TRUE(CheckNoRtcp2()); |
| 1053 | } |
| 1054 | |
| 1055 | // Check that RTP and RTCP are transmitted ok when both sides support mux. |
| 1056 | void SendRtcpMuxToRtcpMux() { |
| 1057 | CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX); |
| 1058 | EXPECT_TRUE(SendInitiate()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1059 | ASSERT_TRUE(GetTransport1()); |
| 1060 | ASSERT_TRUE(GetTransport2()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1061 | EXPECT_EQ(2U, GetTransport1()->channels().size()); |
| 1062 | EXPECT_EQ(1U, GetTransport2()->channels().size()); |
| 1063 | EXPECT_TRUE(SendAccept()); |
| 1064 | EXPECT_EQ(1U, GetTransport1()->channels().size()); |
| 1065 | EXPECT_TRUE(SendRtp1()); |
| 1066 | EXPECT_TRUE(SendRtp2()); |
| 1067 | EXPECT_TRUE(SendRtcp1()); |
| 1068 | EXPECT_TRUE(SendRtcp2()); |
| 1069 | EXPECT_TRUE(CheckRtp1()); |
| 1070 | EXPECT_TRUE(CheckRtp2()); |
| 1071 | EXPECT_TRUE(CheckNoRtp1()); |
| 1072 | EXPECT_TRUE(CheckNoRtp2()); |
| 1073 | EXPECT_TRUE(CheckRtcp1()); |
| 1074 | EXPECT_TRUE(CheckRtcp2()); |
| 1075 | EXPECT_TRUE(CheckNoRtcp1()); |
| 1076 | EXPECT_TRUE(CheckNoRtcp2()); |
| 1077 | } |
| 1078 | |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 1079 | // Check that RTP and RTCP are transmitted ok when both sides |
| 1080 | // support mux and one the offerer requires mux. |
| 1081 | void SendRequireRtcpMuxToRtcpMux() { |
| 1082 | CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX); |
| 1083 | channel1_->ActivateRtcpMux(); |
| 1084 | EXPECT_TRUE(SendInitiate()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1085 | ASSERT_TRUE(GetTransport1()); |
| 1086 | ASSERT_TRUE(GetTransport2()); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 1087 | EXPECT_EQ(1U, GetTransport1()->channels().size()); |
| 1088 | EXPECT_EQ(1U, GetTransport2()->channels().size()); |
| 1089 | EXPECT_TRUE(SendAccept()); |
| 1090 | EXPECT_TRUE(SendRtp1()); |
| 1091 | EXPECT_TRUE(SendRtp2()); |
| 1092 | EXPECT_TRUE(SendRtcp1()); |
| 1093 | EXPECT_TRUE(SendRtcp2()); |
| 1094 | EXPECT_TRUE(CheckRtp1()); |
| 1095 | EXPECT_TRUE(CheckRtp2()); |
| 1096 | EXPECT_TRUE(CheckNoRtp1()); |
| 1097 | EXPECT_TRUE(CheckNoRtp2()); |
| 1098 | EXPECT_TRUE(CheckRtcp1()); |
| 1099 | EXPECT_TRUE(CheckRtcp2()); |
| 1100 | EXPECT_TRUE(CheckNoRtcp1()); |
| 1101 | EXPECT_TRUE(CheckNoRtcp2()); |
| 1102 | } |
| 1103 | |
| 1104 | // Check that RTP and RTCP are transmitted ok when both sides |
| 1105 | // support mux and one the answerer requires rtcp mux. |
| 1106 | void SendRtcpMuxToRequireRtcpMux() { |
| 1107 | CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX); |
| 1108 | channel2_->ActivateRtcpMux(); |
| 1109 | EXPECT_TRUE(SendInitiate()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1110 | ASSERT_TRUE(GetTransport1()); |
| 1111 | ASSERT_TRUE(GetTransport2()); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 1112 | EXPECT_EQ(2U, GetTransport1()->channels().size()); |
| 1113 | EXPECT_EQ(1U, GetTransport2()->channels().size()); |
| 1114 | EXPECT_TRUE(SendAccept()); |
| 1115 | EXPECT_EQ(1U, GetTransport1()->channels().size()); |
| 1116 | EXPECT_TRUE(SendRtp1()); |
| 1117 | EXPECT_TRUE(SendRtp2()); |
| 1118 | EXPECT_TRUE(SendRtcp1()); |
| 1119 | EXPECT_TRUE(SendRtcp2()); |
| 1120 | EXPECT_TRUE(CheckRtp1()); |
| 1121 | EXPECT_TRUE(CheckRtp2()); |
| 1122 | EXPECT_TRUE(CheckNoRtp1()); |
| 1123 | EXPECT_TRUE(CheckNoRtp2()); |
| 1124 | EXPECT_TRUE(CheckRtcp1()); |
| 1125 | EXPECT_TRUE(CheckRtcp2()); |
| 1126 | EXPECT_TRUE(CheckNoRtcp1()); |
| 1127 | EXPECT_TRUE(CheckNoRtcp2()); |
| 1128 | } |
| 1129 | |
| 1130 | // Check that RTP and RTCP are transmitted ok when both sides |
| 1131 | // require mux. |
| 1132 | void SendRequireRtcpMuxToRequireRtcpMux() { |
| 1133 | CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX); |
| 1134 | channel1_->ActivateRtcpMux(); |
| 1135 | channel2_->ActivateRtcpMux(); |
| 1136 | EXPECT_TRUE(SendInitiate()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1137 | ASSERT_TRUE(GetTransport1()); |
| 1138 | ASSERT_TRUE(GetTransport2()); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 1139 | EXPECT_EQ(1U, GetTransport1()->channels().size()); |
| 1140 | EXPECT_EQ(1U, GetTransport2()->channels().size()); |
| 1141 | EXPECT_TRUE(SendAccept()); |
| 1142 | EXPECT_EQ(1U, GetTransport1()->channels().size()); |
| 1143 | EXPECT_TRUE(SendRtp1()); |
| 1144 | EXPECT_TRUE(SendRtp2()); |
| 1145 | EXPECT_TRUE(SendRtcp1()); |
| 1146 | EXPECT_TRUE(SendRtcp2()); |
| 1147 | EXPECT_TRUE(CheckRtp1()); |
| 1148 | EXPECT_TRUE(CheckRtp2()); |
| 1149 | EXPECT_TRUE(CheckNoRtp1()); |
| 1150 | EXPECT_TRUE(CheckNoRtp2()); |
| 1151 | EXPECT_TRUE(CheckRtcp1()); |
| 1152 | EXPECT_TRUE(CheckRtcp2()); |
| 1153 | EXPECT_TRUE(CheckNoRtcp1()); |
| 1154 | EXPECT_TRUE(CheckNoRtcp2()); |
| 1155 | } |
| 1156 | |
| 1157 | // Check that SendAccept fails if the answerer doesn't support mux |
| 1158 | // and the offerer requires it. |
| 1159 | void SendRequireRtcpMuxToNoRtcpMux() { |
| 1160 | CreateChannels(RTCP | RTCP_MUX, RTCP); |
| 1161 | channel1_->ActivateRtcpMux(); |
| 1162 | EXPECT_TRUE(SendInitiate()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1163 | ASSERT_TRUE(GetTransport1()); |
| 1164 | ASSERT_TRUE(GetTransport2()); |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 1165 | EXPECT_EQ(1U, GetTransport1()->channels().size()); |
| 1166 | EXPECT_EQ(2U, GetTransport2()->channels().size()); |
| 1167 | EXPECT_FALSE(SendAccept()); |
| 1168 | } |
| 1169 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1170 | // Check that RTCP data sent by the initiator before the accept is not muxed. |
| 1171 | void SendEarlyRtcpMuxToRtcp() { |
| 1172 | CreateChannels(RTCP | RTCP_MUX, RTCP); |
| 1173 | EXPECT_TRUE(SendInitiate()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1174 | ASSERT_TRUE(GetTransport1()); |
| 1175 | ASSERT_TRUE(GetTransport2()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1176 | EXPECT_EQ(2U, GetTransport1()->channels().size()); |
| 1177 | EXPECT_EQ(2U, GetTransport2()->channels().size()); |
| 1178 | |
| 1179 | // RTCP can be sent before the call is accepted, if the transport is ready. |
| 1180 | // It should not be muxed though, as the remote side doesn't support mux. |
| 1181 | EXPECT_TRUE(SendRtcp1()); |
| 1182 | EXPECT_TRUE(CheckNoRtp2()); |
| 1183 | EXPECT_TRUE(CheckRtcp2()); |
| 1184 | |
| 1185 | // Send RTCP packet from callee and verify that it is received. |
| 1186 | EXPECT_TRUE(SendRtcp2()); |
| 1187 | EXPECT_TRUE(CheckNoRtp1()); |
| 1188 | EXPECT_TRUE(CheckRtcp1()); |
| 1189 | |
| 1190 | // Complete call setup and ensure everything is still OK. |
| 1191 | EXPECT_TRUE(SendAccept()); |
| 1192 | EXPECT_EQ(2U, GetTransport1()->channels().size()); |
| 1193 | EXPECT_TRUE(SendRtcp1()); |
| 1194 | EXPECT_TRUE(CheckRtcp2()); |
| 1195 | EXPECT_TRUE(SendRtcp2()); |
| 1196 | EXPECT_TRUE(CheckRtcp1()); |
| 1197 | } |
| 1198 | |
| 1199 | |
| 1200 | // Check that RTCP data is not muxed until both sides have enabled muxing, |
| 1201 | // but that we properly demux before we get the accept message, since there |
| 1202 | // is a race between RTP data and the jingle accept. |
| 1203 | void SendEarlyRtcpMuxToRtcpMux() { |
| 1204 | CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX); |
| 1205 | EXPECT_TRUE(SendInitiate()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1206 | ASSERT_TRUE(GetTransport1()); |
| 1207 | ASSERT_TRUE(GetTransport2()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1208 | EXPECT_EQ(2U, GetTransport1()->channels().size()); |
| 1209 | EXPECT_EQ(1U, GetTransport2()->channels().size()); |
| 1210 | |
| 1211 | // RTCP can't be sent yet, since the RTCP transport isn't writable, and |
| 1212 | // we haven't yet received the accept that says we should mux. |
| 1213 | EXPECT_FALSE(SendRtcp1()); |
| 1214 | |
| 1215 | // Send muxed RTCP packet from callee and verify that it is received. |
| 1216 | EXPECT_TRUE(SendRtcp2()); |
| 1217 | EXPECT_TRUE(CheckNoRtp1()); |
| 1218 | EXPECT_TRUE(CheckRtcp1()); |
| 1219 | |
| 1220 | // Complete call setup and ensure everything is still OK. |
| 1221 | EXPECT_TRUE(SendAccept()); |
| 1222 | EXPECT_EQ(1U, GetTransport1()->channels().size()); |
| 1223 | EXPECT_TRUE(SendRtcp1()); |
| 1224 | EXPECT_TRUE(CheckRtcp2()); |
| 1225 | EXPECT_TRUE(SendRtcp2()); |
| 1226 | EXPECT_TRUE(CheckRtcp1()); |
| 1227 | } |
| 1228 | |
| 1229 | // Test that we properly send SRTP with RTCP in both directions. |
| 1230 | // You can pass in DTLS and/or RTCP_MUX as flags. |
| 1231 | void SendSrtpToSrtp(int flags1_in = 0, int flags2_in = 0) { |
| 1232 | ASSERT((flags1_in & ~(RTCP_MUX | DTLS)) == 0); |
| 1233 | ASSERT((flags2_in & ~(RTCP_MUX | DTLS)) == 0); |
| 1234 | |
| 1235 | int flags1 = RTCP | SECURE | flags1_in; |
| 1236 | int flags2 = RTCP | SECURE | flags2_in; |
| 1237 | bool dtls1 = !!(flags1_in & DTLS); |
| 1238 | bool dtls2 = !!(flags2_in & DTLS); |
| 1239 | CreateChannels(flags1, flags2); |
| 1240 | EXPECT_FALSE(channel1_->secure()); |
| 1241 | EXPECT_FALSE(channel2_->secure()); |
| 1242 | EXPECT_TRUE(SendInitiate()); |
| 1243 | EXPECT_TRUE_WAIT(channel1_->writable(), kEventTimeout); |
| 1244 | EXPECT_TRUE_WAIT(channel2_->writable(), kEventTimeout); |
| 1245 | EXPECT_TRUE(SendAccept()); |
| 1246 | EXPECT_TRUE(channel1_->secure()); |
| 1247 | EXPECT_TRUE(channel2_->secure()); |
| 1248 | EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls()); |
| 1249 | EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls()); |
| 1250 | EXPECT_TRUE(SendRtp1()); |
| 1251 | EXPECT_TRUE(SendRtp2()); |
| 1252 | EXPECT_TRUE(SendRtcp1()); |
| 1253 | EXPECT_TRUE(SendRtcp2()); |
| 1254 | EXPECT_TRUE(CheckRtp1()); |
| 1255 | EXPECT_TRUE(CheckRtp2()); |
| 1256 | EXPECT_TRUE(CheckNoRtp1()); |
| 1257 | EXPECT_TRUE(CheckNoRtp2()); |
| 1258 | EXPECT_TRUE(CheckRtcp1()); |
| 1259 | EXPECT_TRUE(CheckRtcp2()); |
| 1260 | EXPECT_TRUE(CheckNoRtcp1()); |
| 1261 | EXPECT_TRUE(CheckNoRtcp2()); |
| 1262 | } |
| 1263 | |
| 1264 | // Test that we properly handling SRTP negotiating down to RTP. |
| 1265 | void SendSrtpToRtp() { |
| 1266 | CreateChannels(RTCP | SECURE, RTCP); |
| 1267 | EXPECT_FALSE(channel1_->secure()); |
| 1268 | EXPECT_FALSE(channel2_->secure()); |
| 1269 | EXPECT_TRUE(SendInitiate()); |
| 1270 | EXPECT_TRUE(SendAccept()); |
| 1271 | EXPECT_FALSE(channel1_->secure()); |
| 1272 | EXPECT_FALSE(channel2_->secure()); |
| 1273 | EXPECT_TRUE(SendRtp1()); |
| 1274 | EXPECT_TRUE(SendRtp2()); |
| 1275 | EXPECT_TRUE(SendRtcp1()); |
| 1276 | EXPECT_TRUE(SendRtcp2()); |
| 1277 | EXPECT_TRUE(CheckRtp1()); |
| 1278 | EXPECT_TRUE(CheckRtp2()); |
| 1279 | EXPECT_TRUE(CheckNoRtp1()); |
| 1280 | EXPECT_TRUE(CheckNoRtp2()); |
| 1281 | EXPECT_TRUE(CheckRtcp1()); |
| 1282 | EXPECT_TRUE(CheckRtcp2()); |
| 1283 | EXPECT_TRUE(CheckNoRtcp1()); |
| 1284 | EXPECT_TRUE(CheckNoRtcp2()); |
| 1285 | } |
| 1286 | |
| 1287 | // Test that we can send and receive early media when a provisional answer is |
| 1288 | // sent and received. The test uses SRTP, RTCP mux and SSRC mux. |
| 1289 | void SendEarlyMediaUsingRtcpMuxSrtp() { |
| 1290 | int sequence_number1_1 = 0, sequence_number2_2 = 0; |
| 1291 | |
| 1292 | CreateChannels(SSRC_MUX | RTCP | RTCP_MUX | SECURE, |
| 1293 | SSRC_MUX | RTCP | RTCP_MUX | SECURE); |
| 1294 | EXPECT_TRUE(SendOffer()); |
| 1295 | EXPECT_TRUE(SendProvisionalAnswer()); |
| 1296 | EXPECT_TRUE(channel1_->secure()); |
| 1297 | EXPECT_TRUE(channel2_->secure()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1298 | ASSERT_TRUE(GetTransport1()); |
| 1299 | ASSERT_TRUE(GetTransport2()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1300 | EXPECT_EQ(2U, GetTransport1()->channels().size()); |
| 1301 | EXPECT_EQ(2U, GetTransport2()->channels().size()); |
| 1302 | EXPECT_TRUE(SendCustomRtcp1(kSsrc1)); |
| 1303 | EXPECT_TRUE(CheckCustomRtcp2(kSsrc1)); |
| 1304 | EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1)); |
| 1305 | EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1)); |
| 1306 | |
| 1307 | // Send packets from callee and verify that it is received. |
| 1308 | EXPECT_TRUE(SendCustomRtcp2(kSsrc2)); |
| 1309 | EXPECT_TRUE(CheckCustomRtcp1(kSsrc2)); |
| 1310 | EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2)); |
| 1311 | EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2)); |
| 1312 | |
| 1313 | // Complete call setup and ensure everything is still OK. |
| 1314 | EXPECT_TRUE(SendFinalAnswer()); |
| 1315 | EXPECT_EQ(1U, GetTransport1()->channels().size()); |
| 1316 | EXPECT_EQ(1U, GetTransport2()->channels().size()); |
| 1317 | EXPECT_TRUE(channel1_->secure()); |
| 1318 | EXPECT_TRUE(channel2_->secure()); |
| 1319 | EXPECT_TRUE(SendCustomRtcp1(kSsrc1)); |
| 1320 | EXPECT_TRUE(CheckCustomRtcp2(kSsrc1)); |
| 1321 | EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1)); |
| 1322 | EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1)); |
| 1323 | EXPECT_TRUE(SendCustomRtcp2(kSsrc2)); |
| 1324 | EXPECT_TRUE(CheckCustomRtcp1(kSsrc2)); |
| 1325 | EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2)); |
| 1326 | EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2)); |
| 1327 | } |
| 1328 | |
| 1329 | // Test that we properly send RTP without SRTP from a thread. |
| 1330 | void SendRtpToRtpOnThread() { |
buildbot@webrtc.org | 6bfd619 | 2014-05-15 16:15:59 +0000 | [diff] [blame] | 1331 | bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2; |
| 1332 | CreateChannels(RTCP, RTCP); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1333 | EXPECT_TRUE(SendInitiate()); |
| 1334 | EXPECT_TRUE(SendAccept()); |
| 1335 | CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1); |
| 1336 | CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2); |
buildbot@webrtc.org | 6bfd619 | 2014-05-15 16:15:59 +0000 | [diff] [blame] | 1337 | CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1); |
| 1338 | CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1339 | EXPECT_TRUE_WAIT(CheckRtp1(), 1000); |
| 1340 | EXPECT_TRUE_WAIT(CheckRtp2(), 1000); |
| 1341 | EXPECT_TRUE_WAIT(sent_rtp1, 1000); |
| 1342 | EXPECT_TRUE_WAIT(sent_rtp2, 1000); |
| 1343 | EXPECT_TRUE(CheckNoRtp1()); |
| 1344 | EXPECT_TRUE(CheckNoRtp2()); |
| 1345 | EXPECT_TRUE_WAIT(CheckRtcp1(), 1000); |
| 1346 | EXPECT_TRUE_WAIT(CheckRtcp2(), 1000); |
| 1347 | EXPECT_TRUE_WAIT(sent_rtcp1, 1000); |
| 1348 | EXPECT_TRUE_WAIT(sent_rtcp2, 1000); |
| 1349 | EXPECT_TRUE(CheckNoRtcp1()); |
| 1350 | EXPECT_TRUE(CheckNoRtcp2()); |
| 1351 | } |
| 1352 | |
| 1353 | // Test that we properly send SRTP with RTCP from a thread. |
| 1354 | void SendSrtpToSrtpOnThread() { |
| 1355 | bool sent_rtp1, sent_rtp2, sent_rtcp1, sent_rtcp2; |
| 1356 | CreateChannels(RTCP | SECURE, RTCP | SECURE); |
| 1357 | EXPECT_TRUE(SendInitiate()); |
| 1358 | EXPECT_TRUE(SendAccept()); |
| 1359 | CallOnThread(&ChannelTest<T>::SendRtp1, &sent_rtp1); |
| 1360 | CallOnThread(&ChannelTest<T>::SendRtp2, &sent_rtp2); |
| 1361 | CallOnThread(&ChannelTest<T>::SendRtcp1, &sent_rtcp1); |
| 1362 | CallOnThread(&ChannelTest<T>::SendRtcp2, &sent_rtcp2); |
| 1363 | EXPECT_TRUE_WAIT(CheckRtp1(), 1000); |
| 1364 | EXPECT_TRUE_WAIT(CheckRtp2(), 1000); |
| 1365 | EXPECT_TRUE_WAIT(sent_rtp1, 1000); |
| 1366 | EXPECT_TRUE_WAIT(sent_rtp2, 1000); |
| 1367 | EXPECT_TRUE(CheckNoRtp1()); |
| 1368 | EXPECT_TRUE(CheckNoRtp2()); |
| 1369 | EXPECT_TRUE_WAIT(CheckRtcp1(), 1000); |
| 1370 | EXPECT_TRUE_WAIT(CheckRtcp2(), 1000); |
| 1371 | EXPECT_TRUE_WAIT(sent_rtcp1, 1000); |
| 1372 | EXPECT_TRUE_WAIT(sent_rtcp2, 1000); |
| 1373 | EXPECT_TRUE(CheckNoRtcp1()); |
| 1374 | EXPECT_TRUE(CheckNoRtcp2()); |
| 1375 | } |
| 1376 | |
| 1377 | // Test that the mediachannel retains its sending state after the transport |
| 1378 | // becomes non-writable. |
| 1379 | void SendWithWritabilityLoss() { |
| 1380 | CreateChannels(0, 0); |
| 1381 | EXPECT_TRUE(SendInitiate()); |
| 1382 | EXPECT_TRUE(SendAccept()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1383 | ASSERT_TRUE(GetTransport1()); |
| 1384 | ASSERT_TRUE(GetTransport2()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1385 | EXPECT_EQ(1U, GetTransport1()->channels().size()); |
| 1386 | EXPECT_EQ(1U, GetTransport2()->channels().size()); |
| 1387 | EXPECT_TRUE(SendRtp1()); |
| 1388 | EXPECT_TRUE(SendRtp2()); |
| 1389 | EXPECT_TRUE(CheckRtp1()); |
| 1390 | EXPECT_TRUE(CheckRtp2()); |
| 1391 | EXPECT_TRUE(CheckNoRtp1()); |
| 1392 | EXPECT_TRUE(CheckNoRtp2()); |
| 1393 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 1394 | // Lose writability, which should fail. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1395 | GetTransport1()->SetWritable(false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1396 | EXPECT_FALSE(SendRtp1()); |
| 1397 | EXPECT_TRUE(SendRtp2()); |
| 1398 | EXPECT_TRUE(CheckRtp1()); |
| 1399 | EXPECT_TRUE(CheckNoRtp2()); |
| 1400 | |
| 1401 | // Regain writability |
| 1402 | GetTransport1()->SetWritable(true); |
| 1403 | EXPECT_TRUE(media_channel1_->sending()); |
| 1404 | EXPECT_TRUE(SendRtp1()); |
| 1405 | EXPECT_TRUE(SendRtp2()); |
| 1406 | EXPECT_TRUE(CheckRtp1()); |
| 1407 | EXPECT_TRUE(CheckRtp2()); |
| 1408 | EXPECT_TRUE(CheckNoRtp1()); |
| 1409 | EXPECT_TRUE(CheckNoRtp2()); |
| 1410 | |
| 1411 | // Lose writability completely |
| 1412 | GetTransport1()->SetDestination(NULL); |
| 1413 | EXPECT_TRUE(media_channel1_->sending()); |
| 1414 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 1415 | // Should fail also. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1416 | EXPECT_FALSE(SendRtp1()); |
| 1417 | EXPECT_TRUE(SendRtp2()); |
| 1418 | EXPECT_TRUE(CheckRtp1()); |
| 1419 | EXPECT_TRUE(CheckNoRtp2()); |
| 1420 | |
| 1421 | // Gain writability back |
| 1422 | GetTransport1()->SetDestination(GetTransport2()); |
| 1423 | EXPECT_TRUE(media_channel1_->sending()); |
| 1424 | EXPECT_TRUE(SendRtp1()); |
| 1425 | EXPECT_TRUE(SendRtp2()); |
| 1426 | EXPECT_TRUE(CheckRtp1()); |
| 1427 | EXPECT_TRUE(CheckRtp2()); |
| 1428 | EXPECT_TRUE(CheckNoRtp1()); |
| 1429 | EXPECT_TRUE(CheckNoRtp2()); |
| 1430 | } |
| 1431 | |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 1432 | void SendBundleToBundle( |
| 1433 | const int* pl_types, int len, bool rtcp_mux, bool secure) { |
| 1434 | ASSERT_EQ(2, len); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1435 | int sequence_number1_1 = 0, sequence_number2_2 = 0; |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 1436 | // Only pl_type1 was added to the bundle filter for both |channel1_| |
| 1437 | // and |channel2_|. |
| 1438 | int pl_type1 = pl_types[0]; |
| 1439 | int pl_type2 = pl_types[1]; |
| 1440 | int flags = SSRC_MUX | RTCP; |
| 1441 | if (secure) flags |= SECURE; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1442 | uint32_t expected_channels = 2U; |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 1443 | if (rtcp_mux) { |
| 1444 | flags |= RTCP_MUX; |
| 1445 | expected_channels = 1U; |
| 1446 | } |
| 1447 | CreateChannels(flags, flags); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1448 | EXPECT_TRUE(SendInitiate()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1449 | ASSERT_TRUE(GetTransport1()); |
| 1450 | ASSERT_TRUE(GetTransport2()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1451 | EXPECT_EQ(2U, GetTransport1()->channels().size()); |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 1452 | EXPECT_EQ(expected_channels, GetTransport2()->channels().size()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1453 | EXPECT_TRUE(SendAccept()); |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 1454 | EXPECT_EQ(expected_channels, GetTransport1()->channels().size()); |
| 1455 | EXPECT_EQ(expected_channels, GetTransport2()->channels().size()); |
| 1456 | EXPECT_TRUE(channel1_->bundle_filter()->FindPayloadType(pl_type1)); |
| 1457 | EXPECT_TRUE(channel2_->bundle_filter()->FindPayloadType(pl_type1)); |
| 1458 | EXPECT_FALSE(channel1_->bundle_filter()->FindPayloadType(pl_type2)); |
| 1459 | EXPECT_FALSE(channel2_->bundle_filter()->FindPayloadType(pl_type2)); |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 1460 | |
| 1461 | // Both channels can receive pl_type1 only. |
| 1462 | EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1)); |
| 1463 | EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1)); |
| 1464 | EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1)); |
| 1465 | EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1)); |
| 1466 | EXPECT_TRUE(CheckNoRtp1()); |
| 1467 | EXPECT_TRUE(CheckNoRtp2()); |
| 1468 | |
| 1469 | // RTCP test |
| 1470 | EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2)); |
| 1471 | EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2)); |
| 1472 | EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2)); |
| 1473 | EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2)); |
| 1474 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1475 | EXPECT_TRUE(SendCustomRtcp1(kSsrc1)); |
| 1476 | EXPECT_TRUE(SendCustomRtcp2(kSsrc2)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1477 | EXPECT_TRUE(CheckCustomRtcp1(kSsrc2)); |
| 1478 | EXPECT_TRUE(CheckNoRtcp1()); |
| 1479 | EXPECT_TRUE(CheckCustomRtcp2(kSsrc1)); |
| 1480 | EXPECT_TRUE(CheckNoRtcp2()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1481 | |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 1482 | EXPECT_TRUE(SendCustomRtcp1(kSsrc2)); |
| 1483 | EXPECT_TRUE(SendCustomRtcp2(kSsrc1)); |
pbos | 482b12e | 2015-11-16 10:19:58 -0800 | [diff] [blame] | 1484 | // Bundle filter shouldn't filter out any RTCP. |
| 1485 | EXPECT_TRUE(CheckCustomRtcp1(kSsrc1)); |
| 1486 | EXPECT_TRUE(CheckCustomRtcp2(kSsrc2)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | // Test that the media monitor can be run and gives timely callbacks. |
| 1490 | void TestMediaMonitor() { |
| 1491 | static const int kTimeout = 500; |
| 1492 | CreateChannels(0, 0); |
| 1493 | EXPECT_TRUE(SendInitiate()); |
| 1494 | EXPECT_TRUE(SendAccept()); |
| 1495 | channel1_->StartMediaMonitor(100); |
| 1496 | channel2_->StartMediaMonitor(100); |
| 1497 | // Ensure we get callbacks and stop. |
| 1498 | EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout); |
| 1499 | EXPECT_TRUE_WAIT(media_info_callbacks2_ > 0, kTimeout); |
| 1500 | channel1_->StopMediaMonitor(); |
| 1501 | channel2_->StopMediaMonitor(); |
| 1502 | // Ensure a restart of a stopped monitor works. |
| 1503 | channel1_->StartMediaMonitor(100); |
| 1504 | EXPECT_TRUE_WAIT(media_info_callbacks1_ > 0, kTimeout); |
| 1505 | channel1_->StopMediaMonitor(); |
| 1506 | // Ensure stopping a stopped monitor is OK. |
| 1507 | channel1_->StopMediaMonitor(); |
| 1508 | } |
| 1509 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1510 | void TestSetContentFailure() { |
| 1511 | CreateChannels(0, 0); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1512 | |
Peter Thatcher | a6d2444 | 2015-07-09 21:26:36 -0700 | [diff] [blame] | 1513 | auto sdesc = cricket::SessionDescription(); |
| 1514 | sdesc.AddContent(cricket::CN_AUDIO, cricket::NS_JINGLE_RTP, |
| 1515 | new cricket::AudioContentDescription()); |
| 1516 | sdesc.AddContent(cricket::CN_VIDEO, cricket::NS_JINGLE_RTP, |
| 1517 | new cricket::VideoContentDescription()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1518 | |
Peter Thatcher | a6d2444 | 2015-07-09 21:26:36 -0700 | [diff] [blame] | 1519 | std::string err; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1520 | media_channel1_->set_fail_set_recv_codecs(true); |
Peter Thatcher | a6d2444 | 2015-07-09 21:26:36 -0700 | [diff] [blame] | 1521 | EXPECT_FALSE(channel1_->PushdownLocalDescription( |
| 1522 | &sdesc, cricket::CA_OFFER, &err)); |
| 1523 | EXPECT_FALSE(channel1_->PushdownLocalDescription( |
| 1524 | &sdesc, cricket::CA_ANSWER, &err)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1525 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1526 | media_channel1_->set_fail_set_send_codecs(true); |
Peter Thatcher | a6d2444 | 2015-07-09 21:26:36 -0700 | [diff] [blame] | 1527 | EXPECT_FALSE(channel1_->PushdownRemoteDescription( |
| 1528 | &sdesc, cricket::CA_OFFER, &err)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1529 | media_channel1_->set_fail_set_send_codecs(true); |
Peter Thatcher | a6d2444 | 2015-07-09 21:26:36 -0700 | [diff] [blame] | 1530 | EXPECT_FALSE(channel1_->PushdownRemoteDescription( |
| 1531 | &sdesc, cricket::CA_ANSWER, &err)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1532 | } |
| 1533 | |
| 1534 | void TestSendTwoOffers() { |
| 1535 | CreateChannels(0, 0); |
| 1536 | |
Peter Thatcher | a6d2444 | 2015-07-09 21:26:36 -0700 | [diff] [blame] | 1537 | std::string err; |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1538 | std::unique_ptr<cricket::SessionDescription> sdesc1( |
Peter Thatcher | a6d2444 | 2015-07-09 21:26:36 -0700 | [diff] [blame] | 1539 | CreateSessionDescriptionWithStream(1)); |
| 1540 | EXPECT_TRUE(channel1_->PushdownLocalDescription( |
| 1541 | sdesc1.get(), cricket::CA_OFFER, &err)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1542 | EXPECT_TRUE(media_channel1_->HasSendStream(1)); |
| 1543 | |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1544 | std::unique_ptr<cricket::SessionDescription> sdesc2( |
Peter Thatcher | a6d2444 | 2015-07-09 21:26:36 -0700 | [diff] [blame] | 1545 | CreateSessionDescriptionWithStream(2)); |
| 1546 | EXPECT_TRUE(channel1_->PushdownLocalDescription( |
| 1547 | sdesc2.get(), cricket::CA_OFFER, &err)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1548 | EXPECT_FALSE(media_channel1_->HasSendStream(1)); |
| 1549 | EXPECT_TRUE(media_channel1_->HasSendStream(2)); |
| 1550 | } |
| 1551 | |
| 1552 | void TestReceiveTwoOffers() { |
| 1553 | CreateChannels(0, 0); |
| 1554 | |
Peter Thatcher | a6d2444 | 2015-07-09 21:26:36 -0700 | [diff] [blame] | 1555 | std::string err; |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1556 | std::unique_ptr<cricket::SessionDescription> sdesc1( |
Peter Thatcher | a6d2444 | 2015-07-09 21:26:36 -0700 | [diff] [blame] | 1557 | CreateSessionDescriptionWithStream(1)); |
| 1558 | EXPECT_TRUE(channel1_->PushdownRemoteDescription( |
| 1559 | sdesc1.get(), cricket::CA_OFFER, &err)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1560 | EXPECT_TRUE(media_channel1_->HasRecvStream(1)); |
| 1561 | |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1562 | std::unique_ptr<cricket::SessionDescription> sdesc2( |
Peter Thatcher | a6d2444 | 2015-07-09 21:26:36 -0700 | [diff] [blame] | 1563 | CreateSessionDescriptionWithStream(2)); |
| 1564 | EXPECT_TRUE(channel1_->PushdownRemoteDescription( |
| 1565 | sdesc2.get(), cricket::CA_OFFER, &err)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1566 | EXPECT_FALSE(media_channel1_->HasRecvStream(1)); |
| 1567 | EXPECT_TRUE(media_channel1_->HasRecvStream(2)); |
| 1568 | } |
| 1569 | |
| 1570 | void TestSendPrAnswer() { |
| 1571 | CreateChannels(0, 0); |
| 1572 | |
Peter Thatcher | a6d2444 | 2015-07-09 21:26:36 -0700 | [diff] [blame] | 1573 | std::string err; |
| 1574 | // Receive offer |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1575 | std::unique_ptr<cricket::SessionDescription> sdesc1( |
Peter Thatcher | a6d2444 | 2015-07-09 21:26:36 -0700 | [diff] [blame] | 1576 | CreateSessionDescriptionWithStream(1)); |
| 1577 | EXPECT_TRUE(channel1_->PushdownRemoteDescription( |
| 1578 | sdesc1.get(), cricket::CA_OFFER, &err)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1579 | EXPECT_TRUE(media_channel1_->HasRecvStream(1)); |
| 1580 | |
Peter Thatcher | a6d2444 | 2015-07-09 21:26:36 -0700 | [diff] [blame] | 1581 | // Send PR answer |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1582 | std::unique_ptr<cricket::SessionDescription> sdesc2( |
Peter Thatcher | a6d2444 | 2015-07-09 21:26:36 -0700 | [diff] [blame] | 1583 | CreateSessionDescriptionWithStream(2)); |
| 1584 | EXPECT_TRUE(channel1_->PushdownLocalDescription( |
| 1585 | sdesc2.get(), cricket::CA_PRANSWER, &err)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1586 | EXPECT_TRUE(media_channel1_->HasRecvStream(1)); |
| 1587 | EXPECT_TRUE(media_channel1_->HasSendStream(2)); |
| 1588 | |
Peter Thatcher | a6d2444 | 2015-07-09 21:26:36 -0700 | [diff] [blame] | 1589 | // Send answer |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1590 | std::unique_ptr<cricket::SessionDescription> sdesc3( |
Peter Thatcher | a6d2444 | 2015-07-09 21:26:36 -0700 | [diff] [blame] | 1591 | CreateSessionDescriptionWithStream(3)); |
| 1592 | EXPECT_TRUE(channel1_->PushdownLocalDescription( |
| 1593 | sdesc3.get(), cricket::CA_ANSWER, &err)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1594 | EXPECT_TRUE(media_channel1_->HasRecvStream(1)); |
| 1595 | EXPECT_FALSE(media_channel1_->HasSendStream(2)); |
| 1596 | EXPECT_TRUE(media_channel1_->HasSendStream(3)); |
| 1597 | } |
| 1598 | |
| 1599 | void TestReceivePrAnswer() { |
| 1600 | CreateChannels(0, 0); |
| 1601 | |
Peter Thatcher | a6d2444 | 2015-07-09 21:26:36 -0700 | [diff] [blame] | 1602 | std::string err; |
| 1603 | // Send offer |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1604 | std::unique_ptr<cricket::SessionDescription> sdesc1( |
Peter Thatcher | a6d2444 | 2015-07-09 21:26:36 -0700 | [diff] [blame] | 1605 | CreateSessionDescriptionWithStream(1)); |
| 1606 | EXPECT_TRUE(channel1_->PushdownLocalDescription( |
| 1607 | sdesc1.get(), cricket::CA_OFFER, &err)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1608 | EXPECT_TRUE(media_channel1_->HasSendStream(1)); |
| 1609 | |
Peter Thatcher | a6d2444 | 2015-07-09 21:26:36 -0700 | [diff] [blame] | 1610 | // Receive PR answer |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1611 | std::unique_ptr<cricket::SessionDescription> sdesc2( |
Peter Thatcher | a6d2444 | 2015-07-09 21:26:36 -0700 | [diff] [blame] | 1612 | CreateSessionDescriptionWithStream(2)); |
| 1613 | EXPECT_TRUE(channel1_->PushdownRemoteDescription( |
| 1614 | sdesc2.get(), cricket::CA_PRANSWER, &err)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1615 | EXPECT_TRUE(media_channel1_->HasSendStream(1)); |
| 1616 | EXPECT_TRUE(media_channel1_->HasRecvStream(2)); |
| 1617 | |
Peter Thatcher | a6d2444 | 2015-07-09 21:26:36 -0700 | [diff] [blame] | 1618 | // Receive answer |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1619 | std::unique_ptr<cricket::SessionDescription> sdesc3( |
Peter Thatcher | a6d2444 | 2015-07-09 21:26:36 -0700 | [diff] [blame] | 1620 | CreateSessionDescriptionWithStream(3)); |
| 1621 | EXPECT_TRUE(channel1_->PushdownRemoteDescription( |
| 1622 | sdesc3.get(), cricket::CA_ANSWER, &err)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1623 | EXPECT_TRUE(media_channel1_->HasSendStream(1)); |
| 1624 | EXPECT_FALSE(media_channel1_->HasRecvStream(2)); |
| 1625 | EXPECT_TRUE(media_channel1_->HasRecvStream(3)); |
| 1626 | } |
| 1627 | |
| 1628 | void TestFlushRtcp() { |
| 1629 | bool send_rtcp1; |
| 1630 | |
| 1631 | CreateChannels(RTCP, RTCP); |
| 1632 | EXPECT_TRUE(SendInitiate()); |
| 1633 | EXPECT_TRUE(SendAccept()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1634 | ASSERT_TRUE(GetTransport1()); |
| 1635 | ASSERT_TRUE(GetTransport2()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1636 | EXPECT_EQ(2U, GetTransport1()->channels().size()); |
| 1637 | EXPECT_EQ(2U, GetTransport2()->channels().size()); |
| 1638 | |
| 1639 | // Send RTCP1 from a different thread. |
| 1640 | CallOnThreadAndWaitForDone(&ChannelTest<T>::SendRtcp1, &send_rtcp1); |
| 1641 | EXPECT_TRUE(send_rtcp1); |
| 1642 | // The sending message is only posted. channel2_ should be empty. |
| 1643 | EXPECT_TRUE(CheckNoRtcp2()); |
| 1644 | |
| 1645 | // When channel1_ is deleted, the RTCP packet should be sent out to |
| 1646 | // channel2_. |
| 1647 | channel1_.reset(); |
| 1648 | EXPECT_TRUE(CheckRtcp2()); |
| 1649 | } |
| 1650 | |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 1651 | void TestSrtpError(int pl_type) { |
solenberg | 5b14b42 | 2015-10-01 04:10:31 -0700 | [diff] [blame] | 1652 | struct SrtpErrorHandler : public sigslot::has_slots<> { |
| 1653 | SrtpErrorHandler() : |
| 1654 | mode_(cricket::SrtpFilter::UNPROTECT), |
| 1655 | error_(cricket::SrtpFilter::ERROR_NONE) {} |
| 1656 | void OnSrtpError(uint32 ssrc, cricket::SrtpFilter::Mode mode, |
| 1657 | cricket::SrtpFilter::Error error) { |
| 1658 | mode_ = mode; |
| 1659 | error_ = error; |
| 1660 | } |
| 1661 | cricket::SrtpFilter::Mode mode_; |
| 1662 | cricket::SrtpFilter::Error error_; |
| 1663 | } error_handler; |
| 1664 | |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 1665 | // For Audio, only pl_type 0 is added to the bundle filter. |
| 1666 | // For Video, only pl_type 97 is added to the bundle filter. |
| 1667 | // So we need to pass in pl_type so that the packet can pass through |
| 1668 | // the bundle filter before it can be processed by the srtp filter. |
| 1669 | // The packet is not a valid srtp packet because it is too short. |
pbos@webrtc.org | 910473b | 2014-06-06 15:44:00 +0000 | [diff] [blame] | 1670 | unsigned const char kBadPacket[] = {0x84, |
| 1671 | static_cast<unsigned char>(pl_type), |
| 1672 | 0x00, |
| 1673 | 0x01, |
| 1674 | 0x00, |
| 1675 | 0x00, |
| 1676 | 0x00, |
| 1677 | 0x00, |
| 1678 | 0x00, |
| 1679 | 0x00, |
| 1680 | 0x00, |
| 1681 | 0x01}; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1682 | CreateChannels(RTCP | SECURE, RTCP | SECURE); |
| 1683 | EXPECT_FALSE(channel1_->secure()); |
| 1684 | EXPECT_FALSE(channel2_->secure()); |
| 1685 | EXPECT_TRUE(SendInitiate()); |
| 1686 | EXPECT_TRUE(SendAccept()); |
| 1687 | EXPECT_TRUE(channel1_->secure()); |
| 1688 | EXPECT_TRUE(channel2_->secure()); |
solenberg | 5629a1d | 2015-10-01 08:45:57 -0700 | [diff] [blame] | 1689 | channel2_->srtp_filter()->set_signal_silent_time(250); |
solenberg | 5b14b42 | 2015-10-01 04:10:31 -0700 | [diff] [blame] | 1690 | channel2_->srtp_filter()->SignalSrtpError.connect( |
| 1691 | &error_handler, &SrtpErrorHandler::OnSrtpError); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1692 | |
| 1693 | // Testing failures in sending packets. |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1694 | EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket), |
| 1695 | rtc::PacketOptions())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1696 | // The first failure will trigger an error. |
solenberg | 5b14b42 | 2015-10-01 04:10:31 -0700 | [diff] [blame] | 1697 | EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500); |
| 1698 | EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_); |
| 1699 | error_handler.error_ = cricket::SrtpFilter::ERROR_NONE; |
solenberg | 5629a1d | 2015-10-01 08:45:57 -0700 | [diff] [blame] | 1700 | error_handler.mode_ = cricket::SrtpFilter::UNPROTECT; |
| 1701 | // The next 250 ms failures will not trigger an error. |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1702 | EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket), |
| 1703 | rtc::PacketOptions())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1704 | // Wait for a while to ensure no message comes in. |
solenberg | 5629a1d | 2015-10-01 08:45:57 -0700 | [diff] [blame] | 1705 | rtc::Thread::Current()->ProcessMessages(200); |
solenberg | 5b14b42 | 2015-10-01 04:10:31 -0700 | [diff] [blame] | 1706 | EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_handler.error_); |
solenberg | 5629a1d | 2015-10-01 08:45:57 -0700 | [diff] [blame] | 1707 | EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_); |
| 1708 | // Wait for a little more - the error will be triggered again. |
| 1709 | rtc::Thread::Current()->ProcessMessages(200); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 1710 | EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket), |
| 1711 | rtc::PacketOptions())); |
solenberg | 5b14b42 | 2015-10-01 04:10:31 -0700 | [diff] [blame] | 1712 | EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500); |
| 1713 | EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1714 | |
| 1715 | // Testing failures in receiving packets. |
solenberg | 5b14b42 | 2015-10-01 04:10:31 -0700 | [diff] [blame] | 1716 | error_handler.error_ = cricket::SrtpFilter::ERROR_NONE; |
solenberg | 5629a1d | 2015-10-01 08:45:57 -0700 | [diff] [blame] | 1717 | error_handler.mode_ = cricket::SrtpFilter::UNPROTECT; |
solenberg | 5b14b42 | 2015-10-01 04:10:31 -0700 | [diff] [blame] | 1718 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1719 | cricket::TransportChannel* transport_channel = |
| 1720 | channel2_->transport_channel(); |
| 1721 | transport_channel->SignalReadPacket( |
| 1722 | transport_channel, reinterpret_cast<const char*>(kBadPacket), |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1723 | sizeof(kBadPacket), rtc::PacketTime(), 0); |
solenberg | 5b14b42 | 2015-10-01 04:10:31 -0700 | [diff] [blame] | 1724 | EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500); |
| 1725 | EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | void TestOnReadyToSend() { |
| 1729 | CreateChannels(RTCP, RTCP); |
| 1730 | TransportChannel* rtp = channel1_->transport_channel(); |
| 1731 | TransportChannel* rtcp = channel1_->rtcp_transport_channel(); |
| 1732 | EXPECT_FALSE(media_channel1_->ready_to_send()); |
| 1733 | rtp->SignalReadyToSend(rtp); |
| 1734 | EXPECT_FALSE(media_channel1_->ready_to_send()); |
| 1735 | rtcp->SignalReadyToSend(rtcp); |
| 1736 | // MediaChannel::OnReadyToSend only be called when both rtp and rtcp |
| 1737 | // channel are ready to send. |
| 1738 | EXPECT_TRUE(media_channel1_->ready_to_send()); |
| 1739 | |
| 1740 | // rtp channel becomes not ready to send will be propagated to mediachannel |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1741 | channel1_->SetReadyToSend(false, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1742 | EXPECT_FALSE(media_channel1_->ready_to_send()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1743 | channel1_->SetReadyToSend(false, true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1744 | EXPECT_TRUE(media_channel1_->ready_to_send()); |
| 1745 | |
| 1746 | // rtcp channel becomes not ready to send will be propagated to mediachannel |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1747 | channel1_->SetReadyToSend(true, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1748 | EXPECT_FALSE(media_channel1_->ready_to_send()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1749 | channel1_->SetReadyToSend(true, true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1750 | EXPECT_TRUE(media_channel1_->ready_to_send()); |
| 1751 | } |
| 1752 | |
| 1753 | void TestOnReadyToSendWithRtcpMux() { |
| 1754 | CreateChannels(RTCP, RTCP); |
| 1755 | typename T::Content content; |
| 1756 | CreateContent(0, kPcmuCodec, kH264Codec, &content); |
| 1757 | // Both sides agree on mux. Should no longer be a separate RTCP channel. |
| 1758 | content.set_rtcp_mux(true); |
sergeyu@chromium.org | 4b26e2e | 2014-01-15 23:15:54 +0000 | [diff] [blame] | 1759 | EXPECT_TRUE(channel1_->SetLocalContent(&content, CA_OFFER, NULL)); |
| 1760 | EXPECT_TRUE(channel1_->SetRemoteContent(&content, CA_ANSWER, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1761 | EXPECT_TRUE(channel1_->rtcp_transport_channel() == NULL); |
| 1762 | TransportChannel* rtp = channel1_->transport_channel(); |
| 1763 | EXPECT_FALSE(media_channel1_->ready_to_send()); |
| 1764 | // In the case of rtcp mux, the SignalReadyToSend() from rtp channel |
| 1765 | // should trigger the MediaChannel's OnReadyToSend. |
| 1766 | rtp->SignalReadyToSend(rtp); |
| 1767 | EXPECT_TRUE(media_channel1_->ready_to_send()); |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1768 | channel1_->SetReadyToSend(false, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1769 | EXPECT_FALSE(media_channel1_->ready_to_send()); |
| 1770 | } |
| 1771 | |
| 1772 | protected: |
Peter Boström | 34fbfff | 2015-09-24 19:20:30 +0200 | [diff] [blame] | 1773 | // TODO(pbos): Remove playout from all media channels and let renderers mute |
| 1774 | // themselves. |
| 1775 | const bool verify_playout_; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1776 | cricket::FakeTransportController transport_controller1_; |
| 1777 | cricket::FakeTransportController transport_controller2_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1778 | cricket::FakeMediaEngine media_engine_; |
| 1779 | // The media channels are owned by the voice channel objects below. |
| 1780 | typename T::MediaChannel* media_channel1_; |
| 1781 | typename T::MediaChannel* media_channel2_; |
kwiberg | 3102294 | 2016-03-11 14:18:21 -0800 | [diff] [blame] | 1782 | std::unique_ptr<typename T::Channel> channel1_; |
| 1783 | std::unique_ptr<typename T::Channel> channel2_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1784 | typename T::Content local_media_content1_; |
| 1785 | typename T::Content local_media_content2_; |
| 1786 | typename T::Content remote_media_content1_; |
| 1787 | typename T::Content remote_media_content2_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1788 | // The RTP and RTCP packets to send in the tests. |
| 1789 | std::string rtp_packet_; |
| 1790 | std::string rtcp_packet_; |
| 1791 | int media_info_callbacks1_; |
| 1792 | int media_info_callbacks2_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1793 | }; |
| 1794 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1795 | template<> |
| 1796 | void ChannelTest<VoiceTraits>::CreateContent( |
| 1797 | int flags, |
| 1798 | const cricket::AudioCodec& audio_codec, |
| 1799 | const cricket::VideoCodec& video_codec, |
| 1800 | cricket::AudioContentDescription* audio) { |
| 1801 | audio->AddCodec(audio_codec); |
| 1802 | audio->set_rtcp_mux((flags & RTCP_MUX) != 0); |
| 1803 | if (flags & SECURE) { |
| 1804 | audio->AddCrypto(cricket::CryptoParams( |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 1805 | 1, rtc::CS_AES_CM_128_HMAC_SHA1_32, |
| 1806 | "inline:" + rtc::CreateRandomString(40), std::string())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1807 | } |
| 1808 | } |
| 1809 | |
| 1810 | template<> |
| 1811 | void ChannelTest<VoiceTraits>::CopyContent( |
| 1812 | const cricket::AudioContentDescription& source, |
| 1813 | cricket::AudioContentDescription* audio) { |
| 1814 | *audio = source; |
| 1815 | } |
| 1816 | |
| 1817 | template<> |
| 1818 | bool ChannelTest<VoiceTraits>::CodecMatches(const cricket::AudioCodec& c1, |
| 1819 | const cricket::AudioCodec& c2) { |
| 1820 | return c1.name == c2.name && c1.clockrate == c2.clockrate && |
| 1821 | c1.bitrate == c2.bitrate && c1.channels == c2.channels; |
| 1822 | } |
| 1823 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1824 | template <> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1825 | void ChannelTest<VoiceTraits>::AddLegacyStreamInContent( |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1826 | uint32_t ssrc, |
| 1827 | int flags, |
| 1828 | cricket::AudioContentDescription* audio) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1829 | audio->AddLegacyStream(ssrc); |
| 1830 | } |
| 1831 | |
| 1832 | class VoiceChannelTest |
| 1833 | : public ChannelTest<VoiceTraits> { |
| 1834 | public: |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 1835 | typedef ChannelTest<VoiceTraits> Base; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1836 | VoiceChannelTest() |
Peter Boström | 34fbfff | 2015-09-24 19:20:30 +0200 | [diff] [blame] | 1837 | : Base(true, |
| 1838 | kPcmuFrame, |
| 1839 | sizeof(kPcmuFrame), |
| 1840 | kRtcpReport, |
| 1841 | sizeof(kRtcpReport)) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1842 | }; |
| 1843 | |
| 1844 | // override to add NULL parameter |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1845 | template <> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1846 | cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel( |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1847 | rtc::Thread* thread, |
| 1848 | cricket::MediaEngineInterface* engine, |
| 1849 | cricket::FakeVideoMediaChannel* ch, |
| 1850 | cricket::TransportController* transport_controller, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1851 | bool rtcp) { |
| 1852 | cricket::VideoChannel* channel = new cricket::VideoChannel( |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1853 | thread, ch, transport_controller, cricket::CN_VIDEO, rtcp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1854 | if (!channel->Init()) { |
| 1855 | delete channel; |
| 1856 | channel = NULL; |
| 1857 | } |
| 1858 | return channel; |
| 1859 | } |
| 1860 | |
| 1861 | // override to add 0 parameter |
| 1862 | template<> |
| 1863 | bool ChannelTest<VideoTraits>::AddStream1(int id) { |
| 1864 | return channel1_->AddRecvStream(cricket::StreamParams::CreateLegacy(id)); |
| 1865 | } |
| 1866 | |
| 1867 | template<> |
| 1868 | void ChannelTest<VideoTraits>::CreateContent( |
| 1869 | int flags, |
| 1870 | const cricket::AudioCodec& audio_codec, |
| 1871 | const cricket::VideoCodec& video_codec, |
| 1872 | cricket::VideoContentDescription* video) { |
| 1873 | video->AddCodec(video_codec); |
| 1874 | video->set_rtcp_mux((flags & RTCP_MUX) != 0); |
| 1875 | if (flags & SECURE) { |
| 1876 | video->AddCrypto(cricket::CryptoParams( |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 1877 | 1, rtc::CS_AES_CM_128_HMAC_SHA1_80, |
| 1878 | "inline:" + rtc::CreateRandomString(40), std::string())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1879 | } |
| 1880 | } |
| 1881 | |
| 1882 | template<> |
| 1883 | void ChannelTest<VideoTraits>::CopyContent( |
| 1884 | const cricket::VideoContentDescription& source, |
| 1885 | cricket::VideoContentDescription* video) { |
| 1886 | *video = source; |
| 1887 | } |
| 1888 | |
| 1889 | template<> |
| 1890 | bool ChannelTest<VideoTraits>::CodecMatches(const cricket::VideoCodec& c1, |
| 1891 | const cricket::VideoCodec& c2) { |
| 1892 | return c1.name == c2.name && c1.width == c2.width && c1.height == c2.height && |
| 1893 | c1.framerate == c2.framerate; |
| 1894 | } |
| 1895 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1896 | template <> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1897 | void ChannelTest<VideoTraits>::AddLegacyStreamInContent( |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 1898 | uint32_t ssrc, |
| 1899 | int flags, |
| 1900 | cricket::VideoContentDescription* video) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1901 | video->AddLegacyStream(ssrc); |
| 1902 | } |
| 1903 | |
| 1904 | class VideoChannelTest |
| 1905 | : public ChannelTest<VideoTraits> { |
| 1906 | public: |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 1907 | typedef ChannelTest<VideoTraits> Base; |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1908 | VideoChannelTest() |
Peter Boström | 34fbfff | 2015-09-24 19:20:30 +0200 | [diff] [blame] | 1909 | : Base(false, |
| 1910 | kH264Packet, |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 1911 | sizeof(kH264Packet), |
| 1912 | kRtcpReport, |
| 1913 | sizeof(kRtcpReport)) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1914 | }; |
| 1915 | |
| 1916 | |
| 1917 | // VoiceChannelTest |
| 1918 | |
| 1919 | TEST_F(VoiceChannelTest, TestInit) { |
| 1920 | Base::TestInit(); |
| 1921 | EXPECT_FALSE(media_channel1_->IsStreamMuted(0)); |
| 1922 | EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty()); |
| 1923 | } |
| 1924 | |
| 1925 | TEST_F(VoiceChannelTest, TestSetContents) { |
| 1926 | Base::TestSetContents(); |
| 1927 | } |
| 1928 | |
| 1929 | TEST_F(VoiceChannelTest, TestSetContentsNullOffer) { |
| 1930 | Base::TestSetContentsNullOffer(); |
| 1931 | } |
| 1932 | |
| 1933 | TEST_F(VoiceChannelTest, TestSetContentsRtcpMux) { |
| 1934 | Base::TestSetContentsRtcpMux(); |
| 1935 | } |
| 1936 | |
| 1937 | TEST_F(VoiceChannelTest, TestSetContentsRtcpMuxWithPrAnswer) { |
| 1938 | Base::TestSetContentsRtcpMux(); |
| 1939 | } |
| 1940 | |
| 1941 | TEST_F(VoiceChannelTest, TestSetRemoteContentUpdate) { |
| 1942 | Base::TestSetRemoteContentUpdate(); |
| 1943 | } |
| 1944 | |
| 1945 | TEST_F(VoiceChannelTest, TestStreams) { |
| 1946 | Base::TestStreams(); |
| 1947 | } |
| 1948 | |
| 1949 | TEST_F(VoiceChannelTest, TestUpdateStreamsInLocalContent) { |
| 1950 | Base::TestUpdateStreamsInLocalContent(); |
| 1951 | } |
| 1952 | |
| 1953 | TEST_F(VoiceChannelTest, TestUpdateRemoteStreamsInContent) { |
| 1954 | Base::TestUpdateStreamsInRemoteContent(); |
| 1955 | } |
| 1956 | |
| 1957 | TEST_F(VoiceChannelTest, TestChangeStreamParamsInContent) { |
| 1958 | Base::TestChangeStreamParamsInContent(); |
| 1959 | } |
| 1960 | |
| 1961 | TEST_F(VoiceChannelTest, TestPlayoutAndSendingStates) { |
| 1962 | Base::TestPlayoutAndSendingStates(); |
| 1963 | } |
| 1964 | |
| 1965 | TEST_F(VoiceChannelTest, TestMuteStream) { |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 1966 | CreateChannels(0, 0); |
| 1967 | // Test that we can Mute the default channel even though the sending SSRC |
| 1968 | // is unknown. |
| 1969 | EXPECT_FALSE(media_channel1_->IsStreamMuted(0)); |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 1970 | EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr)); |
solenberg | dfc8f4f | 2015-10-01 02:31:10 -0700 | [diff] [blame] | 1971 | EXPECT_TRUE(media_channel1_->IsStreamMuted(0)); |
| 1972 | EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr)); |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 1973 | EXPECT_FALSE(media_channel1_->IsStreamMuted(0)); |
| 1974 | |
| 1975 | // Test that we can not mute an unknown SSRC. |
solenberg | dfc8f4f | 2015-10-01 02:31:10 -0700 | [diff] [blame] | 1976 | EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr)); |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 1977 | |
| 1978 | SendInitiate(); |
| 1979 | // After the local session description has been set, we can mute a stream |
| 1980 | // with its SSRC. |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 1981 | EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr)); |
solenberg | dfc8f4f | 2015-10-01 02:31:10 -0700 | [diff] [blame] | 1982 | EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1)); |
| 1983 | EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr)); |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 1984 | EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1985 | } |
| 1986 | |
| 1987 | TEST_F(VoiceChannelTest, TestMediaContentDirection) { |
| 1988 | Base::TestMediaContentDirection(); |
| 1989 | } |
| 1990 | |
| 1991 | TEST_F(VoiceChannelTest, TestCallSetup) { |
| 1992 | Base::TestCallSetup(); |
| 1993 | } |
| 1994 | |
| 1995 | TEST_F(VoiceChannelTest, TestCallTeardownRtcpMux) { |
| 1996 | Base::TestCallTeardownRtcpMux(); |
| 1997 | } |
| 1998 | |
| 1999 | TEST_F(VoiceChannelTest, SendRtpToRtp) { |
| 2000 | Base::SendRtpToRtp(); |
| 2001 | } |
| 2002 | |
| 2003 | TEST_F(VoiceChannelTest, SendNoRtcpToNoRtcp) { |
| 2004 | Base::SendNoRtcpToNoRtcp(); |
| 2005 | } |
| 2006 | |
| 2007 | TEST_F(VoiceChannelTest, SendNoRtcpToRtcp) { |
| 2008 | Base::SendNoRtcpToRtcp(); |
| 2009 | } |
| 2010 | |
| 2011 | TEST_F(VoiceChannelTest, SendRtcpToNoRtcp) { |
| 2012 | Base::SendRtcpToNoRtcp(); |
| 2013 | } |
| 2014 | |
| 2015 | TEST_F(VoiceChannelTest, SendRtcpToRtcp) { |
| 2016 | Base::SendRtcpToRtcp(); |
| 2017 | } |
| 2018 | |
| 2019 | TEST_F(VoiceChannelTest, SendRtcpMuxToRtcp) { |
| 2020 | Base::SendRtcpMuxToRtcp(); |
| 2021 | } |
| 2022 | |
| 2023 | TEST_F(VoiceChannelTest, SendRtcpMuxToRtcpMux) { |
| 2024 | Base::SendRtcpMuxToRtcpMux(); |
| 2025 | } |
| 2026 | |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 2027 | TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRtcpMux) { |
| 2028 | Base::SendRequireRtcpMuxToRtcpMux(); |
| 2029 | } |
| 2030 | |
| 2031 | TEST_F(VoiceChannelTest, SendRtcpMuxToRequireRtcpMux) { |
| 2032 | Base::SendRtcpMuxToRequireRtcpMux(); |
| 2033 | } |
| 2034 | |
| 2035 | TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRequireRtcpMux) { |
| 2036 | Base::SendRequireRtcpMuxToRequireRtcpMux(); |
| 2037 | } |
| 2038 | |
| 2039 | TEST_F(VoiceChannelTest, SendRequireRtcpMuxToNoRtcpMux) { |
| 2040 | Base::SendRequireRtcpMuxToNoRtcpMux(); |
| 2041 | } |
| 2042 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2043 | TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcp) { |
| 2044 | Base::SendEarlyRtcpMuxToRtcp(); |
| 2045 | } |
| 2046 | |
| 2047 | TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcpMux) { |
| 2048 | Base::SendEarlyRtcpMuxToRtcpMux(); |
| 2049 | } |
| 2050 | |
| 2051 | TEST_F(VoiceChannelTest, SendSrtpToSrtpRtcpMux) { |
| 2052 | Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX); |
| 2053 | } |
| 2054 | |
| 2055 | TEST_F(VoiceChannelTest, SendSrtpToRtp) { |
| 2056 | Base::SendSrtpToSrtp(); |
| 2057 | } |
| 2058 | |
| 2059 | TEST_F(VoiceChannelTest, SendSrtcpMux) { |
| 2060 | Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX); |
| 2061 | } |
| 2062 | |
| 2063 | TEST_F(VoiceChannelTest, SendDtlsSrtpToSrtp) { |
| 2064 | MAYBE_SKIP_TEST(HaveDtlsSrtp); |
| 2065 | Base::SendSrtpToSrtp(DTLS, 0); |
| 2066 | } |
| 2067 | |
| 2068 | TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtp) { |
| 2069 | MAYBE_SKIP_TEST(HaveDtlsSrtp); |
| 2070 | Base::SendSrtpToSrtp(DTLS, DTLS); |
| 2071 | } |
| 2072 | |
| 2073 | TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) { |
| 2074 | MAYBE_SKIP_TEST(HaveDtlsSrtp); |
| 2075 | Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX); |
| 2076 | } |
| 2077 | |
| 2078 | TEST_F(VoiceChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) { |
| 2079 | Base::SendEarlyMediaUsingRtcpMuxSrtp(); |
| 2080 | } |
| 2081 | |
| 2082 | TEST_F(VoiceChannelTest, SendRtpToRtpOnThread) { |
| 2083 | Base::SendRtpToRtpOnThread(); |
| 2084 | } |
| 2085 | |
| 2086 | TEST_F(VoiceChannelTest, SendSrtpToSrtpOnThread) { |
| 2087 | Base::SendSrtpToSrtpOnThread(); |
| 2088 | } |
| 2089 | |
| 2090 | TEST_F(VoiceChannelTest, SendWithWritabilityLoss) { |
| 2091 | Base::SendWithWritabilityLoss(); |
| 2092 | } |
| 2093 | |
| 2094 | TEST_F(VoiceChannelTest, TestMediaMonitor) { |
| 2095 | Base::TestMediaMonitor(); |
| 2096 | } |
| 2097 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2098 | // Test that InsertDtmf properly forwards to the media channel. |
| 2099 | TEST_F(VoiceChannelTest, TestInsertDtmf) { |
| 2100 | CreateChannels(0, 0); |
| 2101 | EXPECT_TRUE(SendInitiate()); |
| 2102 | EXPECT_TRUE(SendAccept()); |
| 2103 | EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size()); |
| 2104 | |
solenberg | 1d63dd0 | 2015-12-02 12:35:09 -0800 | [diff] [blame] | 2105 | EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100)); |
| 2106 | EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110)); |
| 2107 | EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2108 | |
henrike@webrtc.org | 9de257d | 2013-07-17 14:42:53 +0000 | [diff] [blame] | 2109 | ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2110 | EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0], |
solenberg | 1d63dd0 | 2015-12-02 12:35:09 -0800 | [diff] [blame] | 2111 | 1, 3, 100)); |
henrike@webrtc.org | 9de257d | 2013-07-17 14:42:53 +0000 | [diff] [blame] | 2112 | EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1], |
solenberg | 1d63dd0 | 2015-12-02 12:35:09 -0800 | [diff] [blame] | 2113 | 2, 5, 110)); |
henrike@webrtc.org | 9de257d | 2013-07-17 14:42:53 +0000 | [diff] [blame] | 2114 | EXPECT_TRUE(CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2], |
solenberg | 1d63dd0 | 2015-12-02 12:35:09 -0800 | [diff] [blame] | 2115 | 3, 7, 120)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2116 | } |
| 2117 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2118 | TEST_F(VoiceChannelTest, TestSetContentFailure) { |
| 2119 | Base::TestSetContentFailure(); |
| 2120 | } |
| 2121 | |
| 2122 | TEST_F(VoiceChannelTest, TestSendTwoOffers) { |
| 2123 | Base::TestSendTwoOffers(); |
| 2124 | } |
| 2125 | |
| 2126 | TEST_F(VoiceChannelTest, TestReceiveTwoOffers) { |
| 2127 | Base::TestReceiveTwoOffers(); |
| 2128 | } |
| 2129 | |
| 2130 | TEST_F(VoiceChannelTest, TestSendPrAnswer) { |
| 2131 | Base::TestSendPrAnswer(); |
| 2132 | } |
| 2133 | |
| 2134 | TEST_F(VoiceChannelTest, TestReceivePrAnswer) { |
| 2135 | Base::TestReceivePrAnswer(); |
| 2136 | } |
| 2137 | |
| 2138 | TEST_F(VoiceChannelTest, TestFlushRtcp) { |
| 2139 | Base::TestFlushRtcp(); |
| 2140 | } |
| 2141 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2142 | TEST_F(VoiceChannelTest, TestSrtpError) { |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 2143 | Base::TestSrtpError(kAudioPts[0]); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2144 | } |
| 2145 | |
| 2146 | TEST_F(VoiceChannelTest, TestOnReadyToSend) { |
| 2147 | Base::TestOnReadyToSend(); |
| 2148 | } |
| 2149 | |
| 2150 | TEST_F(VoiceChannelTest, TestOnReadyToSendWithRtcpMux) { |
| 2151 | Base::TestOnReadyToSendWithRtcpMux(); |
| 2152 | } |
| 2153 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2154 | // Test that we can scale the output volume properly for 1:1 calls. |
| 2155 | TEST_F(VoiceChannelTest, TestScaleVolume1to1Call) { |
| 2156 | CreateChannels(RTCP, RTCP); |
| 2157 | EXPECT_TRUE(SendInitiate()); |
| 2158 | EXPECT_TRUE(SendAccept()); |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 2159 | double volume; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2160 | |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 2161 | // Default is (1.0). |
| 2162 | EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume)); |
| 2163 | EXPECT_DOUBLE_EQ(1.0, volume); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2164 | // invalid ssrc. |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 2165 | EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2166 | |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 2167 | // Set scale to (1.5). |
| 2168 | EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5)); |
| 2169 | EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume)); |
| 2170 | EXPECT_DOUBLE_EQ(1.5, volume); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2171 | |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 2172 | // Set scale to (0). |
| 2173 | EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0)); |
| 2174 | EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume)); |
| 2175 | EXPECT_DOUBLE_EQ(0.0, volume); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2176 | } |
| 2177 | |
| 2178 | // Test that we can scale the output volume properly for multiway calls. |
| 2179 | TEST_F(VoiceChannelTest, TestScaleVolumeMultiwayCall) { |
| 2180 | CreateChannels(RTCP, RTCP); |
| 2181 | EXPECT_TRUE(SendInitiate()); |
| 2182 | EXPECT_TRUE(SendAccept()); |
| 2183 | EXPECT_TRUE(AddStream1(1)); |
| 2184 | EXPECT_TRUE(AddStream1(2)); |
| 2185 | |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 2186 | double volume; |
| 2187 | // Default is (1.0). |
| 2188 | EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume)); |
| 2189 | EXPECT_DOUBLE_EQ(1.0, volume); |
| 2190 | EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume)); |
| 2191 | EXPECT_DOUBLE_EQ(1.0, volume); |
| 2192 | EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume)); |
| 2193 | EXPECT_DOUBLE_EQ(1.0, volume); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2194 | // invalid ssrc. |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 2195 | EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2196 | |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 2197 | // Set scale to (1.5) for ssrc = 1. |
| 2198 | EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5)); |
| 2199 | EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume)); |
| 2200 | EXPECT_DOUBLE_EQ(1.5, volume); |
| 2201 | EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume)); |
| 2202 | EXPECT_DOUBLE_EQ(1.0, volume); |
| 2203 | EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume)); |
| 2204 | EXPECT_DOUBLE_EQ(1.0, volume); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2205 | |
solenberg | 4bac9c5 | 2015-10-09 02:32:53 -0700 | [diff] [blame] | 2206 | // Set scale to (0) for all ssrcs. |
| 2207 | EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0)); |
| 2208 | EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume)); |
| 2209 | EXPECT_DOUBLE_EQ(0.0, volume); |
| 2210 | EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume)); |
| 2211 | EXPECT_DOUBLE_EQ(0.0, volume); |
| 2212 | EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume)); |
| 2213 | EXPECT_DOUBLE_EQ(0.0, volume); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2214 | } |
| 2215 | |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 2216 | TEST_F(VoiceChannelTest, SendBundleToBundle) { |
tfarina | 5237aaf | 2015-11-10 23:44:30 -0800 | [diff] [blame] | 2217 | Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2218 | } |
| 2219 | |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 2220 | TEST_F(VoiceChannelTest, SendBundleToBundleSecure) { |
tfarina | 5237aaf | 2015-11-10 23:44:30 -0800 | [diff] [blame] | 2221 | Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true); |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 2222 | } |
| 2223 | |
| 2224 | TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMux) { |
tfarina | 5237aaf | 2015-11-10 23:44:30 -0800 | [diff] [blame] | 2225 | Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false); |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 2226 | } |
| 2227 | |
| 2228 | TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMuxSecure) { |
tfarina | 5237aaf | 2015-11-10 23:44:30 -0800 | [diff] [blame] | 2229 | Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2230 | } |
| 2231 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2232 | // VideoChannelTest |
| 2233 | TEST_F(VideoChannelTest, TestInit) { |
| 2234 | Base::TestInit(); |
| 2235 | } |
| 2236 | |
| 2237 | TEST_F(VideoChannelTest, TestSetContents) { |
| 2238 | Base::TestSetContents(); |
| 2239 | } |
| 2240 | |
| 2241 | TEST_F(VideoChannelTest, TestSetContentsNullOffer) { |
| 2242 | Base::TestSetContentsNullOffer(); |
| 2243 | } |
| 2244 | |
| 2245 | TEST_F(VideoChannelTest, TestSetContentsRtcpMux) { |
| 2246 | Base::TestSetContentsRtcpMux(); |
| 2247 | } |
| 2248 | |
| 2249 | TEST_F(VideoChannelTest, TestSetContentsRtcpMuxWithPrAnswer) { |
| 2250 | Base::TestSetContentsRtcpMux(); |
| 2251 | } |
| 2252 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2253 | TEST_F(VideoChannelTest, TestSetRemoteContentUpdate) { |
| 2254 | Base::TestSetRemoteContentUpdate(); |
| 2255 | } |
| 2256 | |
| 2257 | TEST_F(VideoChannelTest, TestStreams) { |
| 2258 | Base::TestStreams(); |
| 2259 | } |
| 2260 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2261 | TEST_F(VideoChannelTest, TestUpdateStreamsInLocalContent) { |
| 2262 | Base::TestUpdateStreamsInLocalContent(); |
| 2263 | } |
| 2264 | |
| 2265 | TEST_F(VideoChannelTest, TestUpdateRemoteStreamsInContent) { |
| 2266 | Base::TestUpdateStreamsInRemoteContent(); |
| 2267 | } |
| 2268 | |
| 2269 | TEST_F(VideoChannelTest, TestChangeStreamParamsInContent) { |
| 2270 | Base::TestChangeStreamParamsInContent(); |
| 2271 | } |
| 2272 | |
| 2273 | TEST_F(VideoChannelTest, TestPlayoutAndSendingStates) { |
| 2274 | Base::TestPlayoutAndSendingStates(); |
| 2275 | } |
| 2276 | |
| 2277 | TEST_F(VideoChannelTest, TestMuteStream) { |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 2278 | CreateChannels(0, 0); |
| 2279 | // Test that we can Mute the default channel even though the sending SSRC |
| 2280 | // is unknown. |
| 2281 | EXPECT_FALSE(media_channel1_->IsStreamMuted(0)); |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 2282 | EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr)); |
solenberg | dfc8f4f | 2015-10-01 02:31:10 -0700 | [diff] [blame] | 2283 | EXPECT_TRUE(media_channel1_->IsStreamMuted(0)); |
| 2284 | EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr)); |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 2285 | EXPECT_FALSE(media_channel1_->IsStreamMuted(0)); |
| 2286 | // Test that we can not mute an unknown SSRC. |
solenberg | dfc8f4f | 2015-10-01 02:31:10 -0700 | [diff] [blame] | 2287 | EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr)); |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 2288 | SendInitiate(); |
| 2289 | // After the local session description has been set, we can mute a stream |
| 2290 | // with its SSRC. |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 2291 | EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr)); |
solenberg | dfc8f4f | 2015-10-01 02:31:10 -0700 | [diff] [blame] | 2292 | EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1)); |
| 2293 | EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr)); |
solenberg | 1dd98f3 | 2015-09-10 01:57:14 -0700 | [diff] [blame] | 2294 | EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2295 | } |
| 2296 | |
| 2297 | TEST_F(VideoChannelTest, TestMediaContentDirection) { |
| 2298 | Base::TestMediaContentDirection(); |
| 2299 | } |
| 2300 | |
| 2301 | TEST_F(VideoChannelTest, TestCallSetup) { |
| 2302 | Base::TestCallSetup(); |
| 2303 | } |
| 2304 | |
| 2305 | TEST_F(VideoChannelTest, TestCallTeardownRtcpMux) { |
| 2306 | Base::TestCallTeardownRtcpMux(); |
| 2307 | } |
| 2308 | |
| 2309 | TEST_F(VideoChannelTest, SendRtpToRtp) { |
| 2310 | Base::SendRtpToRtp(); |
| 2311 | } |
| 2312 | |
| 2313 | TEST_F(VideoChannelTest, SendNoRtcpToNoRtcp) { |
| 2314 | Base::SendNoRtcpToNoRtcp(); |
| 2315 | } |
| 2316 | |
| 2317 | TEST_F(VideoChannelTest, SendNoRtcpToRtcp) { |
| 2318 | Base::SendNoRtcpToRtcp(); |
| 2319 | } |
| 2320 | |
| 2321 | TEST_F(VideoChannelTest, SendRtcpToNoRtcp) { |
| 2322 | Base::SendRtcpToNoRtcp(); |
| 2323 | } |
| 2324 | |
| 2325 | TEST_F(VideoChannelTest, SendRtcpToRtcp) { |
| 2326 | Base::SendRtcpToRtcp(); |
| 2327 | } |
| 2328 | |
| 2329 | TEST_F(VideoChannelTest, SendRtcpMuxToRtcp) { |
| 2330 | Base::SendRtcpMuxToRtcp(); |
| 2331 | } |
| 2332 | |
| 2333 | TEST_F(VideoChannelTest, SendRtcpMuxToRtcpMux) { |
| 2334 | Base::SendRtcpMuxToRtcpMux(); |
| 2335 | } |
| 2336 | |
Peter Thatcher | af55ccc | 2015-05-21 07:48:41 -0700 | [diff] [blame] | 2337 | TEST_F(VideoChannelTest, SendRequireRtcpMuxToRtcpMux) { |
| 2338 | Base::SendRequireRtcpMuxToRtcpMux(); |
| 2339 | } |
| 2340 | |
| 2341 | TEST_F(VideoChannelTest, SendRtcpMuxToRequireRtcpMux) { |
| 2342 | Base::SendRtcpMuxToRequireRtcpMux(); |
| 2343 | } |
| 2344 | |
| 2345 | TEST_F(VideoChannelTest, SendRequireRtcpMuxToRequireRtcpMux) { |
| 2346 | Base::SendRequireRtcpMuxToRequireRtcpMux(); |
| 2347 | } |
| 2348 | |
| 2349 | TEST_F(VideoChannelTest, SendRequireRtcpMuxToNoRtcpMux) { |
| 2350 | Base::SendRequireRtcpMuxToNoRtcpMux(); |
| 2351 | } |
| 2352 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2353 | TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcp) { |
| 2354 | Base::SendEarlyRtcpMuxToRtcp(); |
| 2355 | } |
| 2356 | |
| 2357 | TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcpMux) { |
| 2358 | Base::SendEarlyRtcpMuxToRtcpMux(); |
| 2359 | } |
| 2360 | |
| 2361 | TEST_F(VideoChannelTest, SendSrtpToSrtp) { |
| 2362 | Base::SendSrtpToSrtp(); |
| 2363 | } |
| 2364 | |
| 2365 | TEST_F(VideoChannelTest, SendSrtpToRtp) { |
| 2366 | Base::SendSrtpToSrtp(); |
| 2367 | } |
| 2368 | |
| 2369 | TEST_F(VideoChannelTest, SendDtlsSrtpToSrtp) { |
| 2370 | MAYBE_SKIP_TEST(HaveDtlsSrtp); |
| 2371 | Base::SendSrtpToSrtp(DTLS, 0); |
| 2372 | } |
| 2373 | |
| 2374 | TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtp) { |
| 2375 | MAYBE_SKIP_TEST(HaveDtlsSrtp); |
| 2376 | Base::SendSrtpToSrtp(DTLS, DTLS); |
| 2377 | } |
| 2378 | |
| 2379 | TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) { |
| 2380 | MAYBE_SKIP_TEST(HaveDtlsSrtp); |
| 2381 | Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX); |
| 2382 | } |
| 2383 | |
| 2384 | TEST_F(VideoChannelTest, SendSrtcpMux) { |
| 2385 | Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX); |
| 2386 | } |
| 2387 | |
| 2388 | TEST_F(VideoChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) { |
| 2389 | Base::SendEarlyMediaUsingRtcpMuxSrtp(); |
| 2390 | } |
| 2391 | |
| 2392 | TEST_F(VideoChannelTest, SendRtpToRtpOnThread) { |
| 2393 | Base::SendRtpToRtpOnThread(); |
| 2394 | } |
| 2395 | |
| 2396 | TEST_F(VideoChannelTest, SendSrtpToSrtpOnThread) { |
| 2397 | Base::SendSrtpToSrtpOnThread(); |
| 2398 | } |
| 2399 | |
| 2400 | TEST_F(VideoChannelTest, SendWithWritabilityLoss) { |
| 2401 | Base::SendWithWritabilityLoss(); |
| 2402 | } |
| 2403 | |
| 2404 | TEST_F(VideoChannelTest, TestMediaMonitor) { |
| 2405 | Base::TestMediaMonitor(); |
| 2406 | } |
| 2407 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2408 | TEST_F(VideoChannelTest, TestSetContentFailure) { |
| 2409 | Base::TestSetContentFailure(); |
| 2410 | } |
| 2411 | |
| 2412 | TEST_F(VideoChannelTest, TestSendTwoOffers) { |
| 2413 | Base::TestSendTwoOffers(); |
| 2414 | } |
| 2415 | |
| 2416 | TEST_F(VideoChannelTest, TestReceiveTwoOffers) { |
| 2417 | Base::TestReceiveTwoOffers(); |
| 2418 | } |
| 2419 | |
| 2420 | TEST_F(VideoChannelTest, TestSendPrAnswer) { |
| 2421 | Base::TestSendPrAnswer(); |
| 2422 | } |
| 2423 | |
| 2424 | TEST_F(VideoChannelTest, TestReceivePrAnswer) { |
| 2425 | Base::TestReceivePrAnswer(); |
| 2426 | } |
| 2427 | |
| 2428 | TEST_F(VideoChannelTest, TestFlushRtcp) { |
| 2429 | Base::TestFlushRtcp(); |
| 2430 | } |
| 2431 | |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 2432 | TEST_F(VideoChannelTest, SendBundleToBundle) { |
tfarina | 5237aaf | 2015-11-10 23:44:30 -0800 | [diff] [blame] | 2433 | Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2434 | } |
| 2435 | |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 2436 | TEST_F(VideoChannelTest, SendBundleToBundleSecure) { |
tfarina | 5237aaf | 2015-11-10 23:44:30 -0800 | [diff] [blame] | 2437 | Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true); |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 2438 | } |
| 2439 | |
| 2440 | TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMux) { |
tfarina | 5237aaf | 2015-11-10 23:44:30 -0800 | [diff] [blame] | 2441 | Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false); |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 2442 | } |
| 2443 | |
| 2444 | TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMuxSecure) { |
tfarina | 5237aaf | 2015-11-10 23:44:30 -0800 | [diff] [blame] | 2445 | Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2446 | } |
| 2447 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2448 | TEST_F(VideoChannelTest, TestSrtpError) { |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 2449 | Base::TestSrtpError(kVideoPts[0]); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2450 | } |
| 2451 | |
| 2452 | TEST_F(VideoChannelTest, TestOnReadyToSend) { |
| 2453 | Base::TestOnReadyToSend(); |
| 2454 | } |
| 2455 | |
| 2456 | TEST_F(VideoChannelTest, TestOnReadyToSendWithRtcpMux) { |
| 2457 | Base::TestOnReadyToSendWithRtcpMux(); |
| 2458 | } |
| 2459 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2460 | // DataChannelTest |
| 2461 | |
| 2462 | class DataChannelTest |
| 2463 | : public ChannelTest<DataTraits> { |
| 2464 | public: |
| 2465 | typedef ChannelTest<DataTraits> |
| 2466 | Base; |
Peter Boström | 34fbfff | 2015-09-24 19:20:30 +0200 | [diff] [blame] | 2467 | DataChannelTest() |
| 2468 | : Base(true, |
| 2469 | kDataPacket, |
| 2470 | sizeof(kDataPacket), |
| 2471 | kRtcpReport, |
| 2472 | sizeof(kRtcpReport)) {} |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2473 | }; |
| 2474 | |
| 2475 | // Override to avoid engine channel parameter. |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2476 | template <> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2477 | cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel( |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2478 | rtc::Thread* thread, |
| 2479 | cricket::MediaEngineInterface* engine, |
| 2480 | cricket::FakeDataMediaChannel* ch, |
| 2481 | cricket::TransportController* transport_controller, |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2482 | bool rtcp) { |
| 2483 | cricket::DataChannel* channel = new cricket::DataChannel( |
deadbeef | cbecd35 | 2015-09-23 11:50:27 -0700 | [diff] [blame] | 2484 | thread, ch, transport_controller, cricket::CN_DATA, rtcp); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2485 | if (!channel->Init()) { |
| 2486 | delete channel; |
| 2487 | channel = NULL; |
| 2488 | } |
| 2489 | return channel; |
| 2490 | } |
| 2491 | |
| 2492 | template<> |
| 2493 | void ChannelTest<DataTraits>::CreateContent( |
| 2494 | int flags, |
| 2495 | const cricket::AudioCodec& audio_codec, |
| 2496 | const cricket::VideoCodec& video_codec, |
| 2497 | cricket::DataContentDescription* data) { |
| 2498 | data->AddCodec(kGoogleDataCodec); |
| 2499 | data->set_rtcp_mux((flags & RTCP_MUX) != 0); |
| 2500 | if (flags & SECURE) { |
| 2501 | data->AddCrypto(cricket::CryptoParams( |
Guo-wei Shieh | 456696a | 2015-09-30 21:48:54 -0700 | [diff] [blame] | 2502 | 1, rtc::CS_AES_CM_128_HMAC_SHA1_32, |
| 2503 | "inline:" + rtc::CreateRandomString(40), std::string())); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2504 | } |
| 2505 | } |
| 2506 | |
| 2507 | template<> |
| 2508 | void ChannelTest<DataTraits>::CopyContent( |
| 2509 | const cricket::DataContentDescription& source, |
| 2510 | cricket::DataContentDescription* data) { |
| 2511 | *data = source; |
| 2512 | } |
| 2513 | |
| 2514 | template<> |
| 2515 | bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1, |
| 2516 | const cricket::DataCodec& c2) { |
| 2517 | return c1.name == c2.name; |
| 2518 | } |
| 2519 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 2520 | template <> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2521 | void ChannelTest<DataTraits>::AddLegacyStreamInContent( |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 2522 | uint32_t ssrc, |
| 2523 | int flags, |
| 2524 | cricket::DataContentDescription* data) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2525 | data->AddLegacyStream(ssrc); |
| 2526 | } |
| 2527 | |
| 2528 | TEST_F(DataChannelTest, TestInit) { |
| 2529 | Base::TestInit(); |
| 2530 | EXPECT_FALSE(media_channel1_->IsStreamMuted(0)); |
| 2531 | } |
| 2532 | |
| 2533 | TEST_F(DataChannelTest, TestSetContents) { |
| 2534 | Base::TestSetContents(); |
| 2535 | } |
| 2536 | |
| 2537 | TEST_F(DataChannelTest, TestSetContentsNullOffer) { |
| 2538 | Base::TestSetContentsNullOffer(); |
| 2539 | } |
| 2540 | |
| 2541 | TEST_F(DataChannelTest, TestSetContentsRtcpMux) { |
| 2542 | Base::TestSetContentsRtcpMux(); |
| 2543 | } |
| 2544 | |
| 2545 | TEST_F(DataChannelTest, TestSetRemoteContentUpdate) { |
| 2546 | Base::TestSetRemoteContentUpdate(); |
| 2547 | } |
| 2548 | |
| 2549 | TEST_F(DataChannelTest, TestStreams) { |
| 2550 | Base::TestStreams(); |
| 2551 | } |
| 2552 | |
| 2553 | TEST_F(DataChannelTest, TestUpdateStreamsInLocalContent) { |
| 2554 | Base::TestUpdateStreamsInLocalContent(); |
| 2555 | } |
| 2556 | |
| 2557 | TEST_F(DataChannelTest, TestUpdateRemoteStreamsInContent) { |
| 2558 | Base::TestUpdateStreamsInRemoteContent(); |
| 2559 | } |
| 2560 | |
| 2561 | TEST_F(DataChannelTest, TestChangeStreamParamsInContent) { |
| 2562 | Base::TestChangeStreamParamsInContent(); |
| 2563 | } |
| 2564 | |
| 2565 | TEST_F(DataChannelTest, TestPlayoutAndSendingStates) { |
| 2566 | Base::TestPlayoutAndSendingStates(); |
| 2567 | } |
| 2568 | |
| 2569 | TEST_F(DataChannelTest, TestMediaContentDirection) { |
| 2570 | Base::TestMediaContentDirection(); |
| 2571 | } |
| 2572 | |
| 2573 | TEST_F(DataChannelTest, TestCallSetup) { |
| 2574 | Base::TestCallSetup(); |
| 2575 | } |
| 2576 | |
| 2577 | TEST_F(DataChannelTest, TestCallTeardownRtcpMux) { |
| 2578 | Base::TestCallTeardownRtcpMux(); |
| 2579 | } |
| 2580 | |
| 2581 | TEST_F(DataChannelTest, TestOnReadyToSend) { |
| 2582 | Base::TestOnReadyToSend(); |
| 2583 | } |
| 2584 | |
| 2585 | TEST_F(DataChannelTest, TestOnReadyToSendWithRtcpMux) { |
| 2586 | Base::TestOnReadyToSendWithRtcpMux(); |
| 2587 | } |
| 2588 | |
| 2589 | TEST_F(DataChannelTest, SendRtpToRtp) { |
| 2590 | Base::SendRtpToRtp(); |
| 2591 | } |
| 2592 | |
| 2593 | TEST_F(DataChannelTest, SendNoRtcpToNoRtcp) { |
| 2594 | Base::SendNoRtcpToNoRtcp(); |
| 2595 | } |
| 2596 | |
| 2597 | TEST_F(DataChannelTest, SendNoRtcpToRtcp) { |
| 2598 | Base::SendNoRtcpToRtcp(); |
| 2599 | } |
| 2600 | |
| 2601 | TEST_F(DataChannelTest, SendRtcpToNoRtcp) { |
| 2602 | Base::SendRtcpToNoRtcp(); |
| 2603 | } |
| 2604 | |
| 2605 | TEST_F(DataChannelTest, SendRtcpToRtcp) { |
| 2606 | Base::SendRtcpToRtcp(); |
| 2607 | } |
| 2608 | |
| 2609 | TEST_F(DataChannelTest, SendRtcpMuxToRtcp) { |
| 2610 | Base::SendRtcpMuxToRtcp(); |
| 2611 | } |
| 2612 | |
| 2613 | TEST_F(DataChannelTest, SendRtcpMuxToRtcpMux) { |
| 2614 | Base::SendRtcpMuxToRtcpMux(); |
| 2615 | } |
| 2616 | |
| 2617 | TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcp) { |
| 2618 | Base::SendEarlyRtcpMuxToRtcp(); |
| 2619 | } |
| 2620 | |
| 2621 | TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcpMux) { |
| 2622 | Base::SendEarlyRtcpMuxToRtcpMux(); |
| 2623 | } |
| 2624 | |
| 2625 | TEST_F(DataChannelTest, SendSrtpToSrtp) { |
| 2626 | Base::SendSrtpToSrtp(); |
| 2627 | } |
| 2628 | |
| 2629 | TEST_F(DataChannelTest, SendSrtpToRtp) { |
| 2630 | Base::SendSrtpToSrtp(); |
| 2631 | } |
| 2632 | |
| 2633 | TEST_F(DataChannelTest, SendSrtcpMux) { |
| 2634 | Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX); |
| 2635 | } |
| 2636 | |
| 2637 | TEST_F(DataChannelTest, SendRtpToRtpOnThread) { |
| 2638 | Base::SendRtpToRtpOnThread(); |
| 2639 | } |
| 2640 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2641 | TEST_F(DataChannelTest, SendSrtpToSrtpOnThread) { |
| 2642 | Base::SendSrtpToSrtpOnThread(); |
| 2643 | } |
| 2644 | |
| 2645 | TEST_F(DataChannelTest, SendWithWritabilityLoss) { |
| 2646 | Base::SendWithWritabilityLoss(); |
| 2647 | } |
| 2648 | |
| 2649 | TEST_F(DataChannelTest, TestMediaMonitor) { |
| 2650 | Base::TestMediaMonitor(); |
| 2651 | } |
| 2652 | |
| 2653 | TEST_F(DataChannelTest, TestSendData) { |
| 2654 | CreateChannels(0, 0); |
| 2655 | EXPECT_TRUE(SendInitiate()); |
| 2656 | EXPECT_TRUE(SendAccept()); |
| 2657 | |
| 2658 | cricket::SendDataParams params; |
| 2659 | params.ssrc = 42; |
| 2660 | unsigned char data[] = { |
| 2661 | 'f', 'o', 'o' |
| 2662 | }; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2663 | rtc::Buffer payload(data, 3); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 2664 | cricket::SendDataResult result; |
| 2665 | ASSERT_TRUE(media_channel1_->SendData(params, payload, &result)); |
| 2666 | EXPECT_EQ(params.ssrc, |
| 2667 | media_channel1_->last_sent_data_params().ssrc); |
| 2668 | EXPECT_EQ("foo", media_channel1_->last_sent_data()); |
| 2669 | } |
| 2670 | |
| 2671 | // TODO(pthatcher): TestSetReceiver? |